]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-3.0-3.14.4-201405131205.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.14.4-201405131205.patch
CommitLineData
4dabc3e2
PK
1diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2index b89a739..e289b9b 100644
3--- a/Documentation/dontdiff
4+++ b/Documentation/dontdiff
5@@ -2,9 +2,11 @@
6 *.aux
7 *.bin
8 *.bz2
9+*.c.[012]*.*
10 *.cis
11 *.cpio
12 *.csp
13+*.dbg
14 *.dsp
15 *.dvi
16 *.elf
17@@ -14,6 +16,7 @@
18 *.gcov
19 *.gen.S
20 *.gif
21+*.gmo
22 *.grep
23 *.grp
24 *.gz
25@@ -48,14 +51,17 @@
26 *.tab.h
27 *.tex
28 *.ver
29+*.vim
30 *.xml
31 *.xz
32 *_MODULES
33+*_reg_safe.h
34 *_vga16.c
35 *~
36 \#*#
37 *.9
38-.*
39+.[^g]*
40+.gen*
41 .*.d
42 .mm
43 53c700_d.h
44@@ -69,9 +75,11 @@ Image
45 Module.markers
46 Module.symvers
47 PENDING
48+PERF*
49 SCCS
50 System.map*
51 TAGS
52+TRACEEVENT-CFLAGS
53 aconf
54 af_names.h
55 aic7*reg.h*
56@@ -80,6 +88,7 @@ aic7*seq.h*
57 aicasm
58 aicdb.h*
59 altivec*.c
60+ashldi3.S
61 asm-offsets.h
62 asm_offsets.h
63 autoconf.h*
64@@ -92,32 +101,40 @@ bounds.h
65 bsetup
66 btfixupprep
67 build
68+builtin-policy.h
69 bvmlinux
70 bzImage*
71 capability_names.h
72 capflags.c
73 classlist.h*
74+clut_vga16.c
75+common-cmds.h
76 comp*.log
77 compile.h*
78 conf
79 config
80 config-*
81 config_data.h*
82+config.c
83 config.mak
84 config.mak.autogen
85+config.tmp
86 conmakehash
87 consolemap_deftbl.c*
88 cpustr.h
89 crc32table.h*
90 cscope.*
91 defkeymap.c
92+devicetable-offsets.h
93 devlist.h*
94 dnotify_test
95 docproc
96 dslm
97+dtc-lexer.lex.c
98 elf2ecoff
99 elfconfig.h*
100 evergreen_reg_safe.h
101+exception_policy.conf
102 fixdep
103 flask.h
104 fore200e_mkfirm
105@@ -125,12 +142,15 @@ fore200e_pca_fw.c*
106 gconf
107 gconf.glade.h
108 gen-devlist
109+gen-kdb_cmds.c
110 gen_crc32table
111 gen_init_cpio
112 generated
113 genheaders
114 genksyms
115 *_gray256.c
116+hash
117+hid-example
118 hpet_example
119 hugepage-mmap
120 hugepage-shm
121@@ -145,14 +165,14 @@ int32.c
122 int4.c
123 int8.c
124 kallsyms
125-kconfig
126+kern_constants.h
127 keywords.c
128 ksym.c*
129 ksym.h*
130 kxgettext
131 lex.c
132 lex.*.c
133-linux
134+lib1funcs.S
135 logo_*.c
136 logo_*_clut224.c
137 logo_*_mono.c
138@@ -162,14 +182,15 @@ mach-types.h
139 machtypes.h
140 map
141 map_hugetlb
142-media
143 mconf
144+mdp
145 miboot*
146 mk_elfconfig
147 mkboot
148 mkbugboot
149 mkcpustr
150 mkdep
151+mkpiggy
152 mkprep
153 mkregtable
154 mktables
155@@ -185,6 +206,8 @@ oui.c*
156 page-types
157 parse.c
158 parse.h
159+parse-events*
160+pasyms.h
161 patches*
162 pca200e.bin
163 pca200e_ecd.bin2
164@@ -194,6 +217,7 @@ perf-archive
165 piggyback
166 piggy.gzip
167 piggy.S
168+pmu-*
169 pnmtologo
170 ppc_defs.h*
171 pss_boot.h
172@@ -203,7 +227,12 @@ r200_reg_safe.h
173 r300_reg_safe.h
174 r420_reg_safe.h
175 r600_reg_safe.h
176+randomize_layout_hash.h
177+randomize_layout_seed.h
178+realmode.lds
179+realmode.relocs
180 recordmcount
181+regdb.c
182 relocs
183 rlim_names.h
184 rn50_reg_safe.h
185@@ -213,8 +242,12 @@ series
186 setup
187 setup.bin
188 setup.elf
189+signing_key*
190+size_overflow_hash.h
191 sImage
192+slabinfo
193 sm_tbl*
194+sortextable
195 split-include
196 syscalltab.h
197 tables.c
198@@ -224,6 +257,7 @@ tftpboot.img
199 timeconst.h
200 times.h*
201 trix_boot.h
202+user_constants.h
203 utsrelease.h*
204 vdso-syms.lds
205 vdso.lds
206@@ -235,13 +269,17 @@ vdso32.lds
207 vdso32.so.dbg
208 vdso64.lds
209 vdso64.so.dbg
210+vdsox32.lds
211+vdsox32-syms.lds
212 version.h*
213 vmImage
214 vmlinux
215 vmlinux-*
216 vmlinux.aout
217 vmlinux.bin.all
218+vmlinux.bin.bz2
219 vmlinux.lds
220+vmlinux.relocs
221 vmlinuz
222 voffset.h
223 vsyscall.lds
224@@ -249,9 +287,12 @@ vsyscall_32.lds
225 wanxlfw.inc
226 uImage
227 unifdef
228+utsrelease.h
229 wakeup.bin
230 wakeup.elf
231 wakeup.lds
232+x509*
233 zImage*
234 zconf.hash.c
235+zconf.lex.c
236 zoffset.h
237diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
238index 7116fda..d8ed6e8 100644
239--- a/Documentation/kernel-parameters.txt
240+++ b/Documentation/kernel-parameters.txt
241@@ -1084,6 +1084,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
242 Format: <unsigned int> such that (rxsize & ~0x1fffc0) == 0.
243 Default: 1024
244
245+ grsec_proc_gid= [GRKERNSEC_PROC_USERGROUP] Chooses GID to
246+ ignore grsecurity's /proc restrictions
247+
248+
249 hashdist= [KNL,NUMA] Large hashes allocated during boot
250 are distributed across NUMA nodes. Defaults on
251 for 64-bit NUMA, off otherwise.
252@@ -2080,6 +2084,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
253 noexec=on: enable non-executable mappings (default)
254 noexec=off: disable non-executable mappings
255
256+ nopcid [X86-64]
257+ Disable PCID (Process-Context IDentifier) even if it
258+ is supported by the processor.
259+
260 nosmap [X86]
261 Disable SMAP (Supervisor Mode Access Prevention)
262 even if it is supported by processor.
263@@ -2347,6 +2355,25 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
264 the specified number of seconds. This is to be used if
265 your oopses keep scrolling off the screen.
266
267+ pax_nouderef [X86] disables UDEREF. Most likely needed under certain
268+ virtualization environments that don't cope well with the
269+ expand down segment used by UDEREF on X86-32 or the frequent
270+ page table updates on X86-64.
271+
272+ pax_sanitize_slab=
273+ 0/1 to disable/enable slab object sanitization (enabled by
274+ default).
275+
276+ pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
277+
278+ pax_extra_latent_entropy
279+ Enable a very simple form of latent entropy extraction
280+ from the first 4GB of memory as the bootmem allocator
281+ passes the memory pages to the buddy allocator.
282+
283+ pax_weakuderef [X86-64] enables the weaker but faster form of UDEREF
284+ when the processor supports PCID.
285+
286 pcbit= [HW,ISDN]
287
288 pcd. [PARIDE]
289diff --git a/Makefile b/Makefile
290index d7c07fd..d6d4bfa 100644
291--- a/Makefile
292+++ b/Makefile
293@@ -244,8 +244,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
294
295 HOSTCC = gcc
296 HOSTCXX = g++
297-HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
298-HOSTCXXFLAGS = -O2
299+HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
300+HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
301+HOSTCXXFLAGS = -O2 -Wall -W -Wno-array-bounds
302
303 # Decide whether to build built-in, modular, or both.
304 # Normally, just do built-in.
305@@ -423,8 +424,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
306 # Rules shared between *config targets and build targets
307
308 # Basic helpers built in scripts/
309-PHONY += scripts_basic
310-scripts_basic:
311+PHONY += scripts_basic gcc-plugins
312+scripts_basic: gcc-plugins
313 $(Q)$(MAKE) $(build)=scripts/basic
314 $(Q)rm -f .tmp_quiet_recordmcount
315
316@@ -585,6 +586,72 @@ else
317 KBUILD_CFLAGS += -O2
318 endif
319
320+ifndef DISABLE_PAX_PLUGINS
321+ifeq ($(call cc-ifversion, -ge, 0408, y), y)
322+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
323+else
324+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
325+endif
326+ifneq ($(PLUGINCC),)
327+ifdef CONFIG_PAX_CONSTIFY_PLUGIN
328+CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
329+endif
330+ifdef CONFIG_PAX_MEMORY_STACKLEAK
331+STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
332+STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
333+endif
334+ifdef CONFIG_KALLOCSTAT_PLUGIN
335+KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
336+endif
337+ifdef CONFIG_PAX_KERNEXEC_PLUGIN
338+KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
339+KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
340+KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
341+endif
342+ifdef CONFIG_GRKERNSEC_RANDSTRUCT
343+RANDSTRUCT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/randomize_layout_plugin.so -DRANDSTRUCT_PLUGIN
344+ifdef CONFIG_GRKERNSEC_RANDSTRUCT_PERFORMANCE
345+RANDSTRUCT_PLUGIN_CFLAGS += -fplugin-arg-randomize_layout_plugin-performance-mode
346+endif
347+endif
348+ifdef CONFIG_CHECKER_PLUGIN
349+ifeq ($(call cc-ifversion, -ge, 0406, y), y)
350+CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
351+endif
352+endif
353+COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
354+ifdef CONFIG_PAX_SIZE_OVERFLOW
355+SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
356+endif
357+ifdef CONFIG_PAX_LATENT_ENTROPY
358+LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
359+endif
360+ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
361+STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
362+endif
363+GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
364+GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
365+GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
366+GCC_PLUGINS_CFLAGS += $(RANDSTRUCT_PLUGIN_CFLAGS)
367+GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
368+export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN LATENT_ENTROPY_PLUGIN_CFLAGS
369+ifeq ($(KBUILD_EXTMOD),)
370+gcc-plugins:
371+ $(Q)$(MAKE) $(build)=tools/gcc
372+else
373+gcc-plugins: ;
374+endif
375+else
376+gcc-plugins:
377+ifeq ($(call cc-ifversion, -ge, 0405, y), y)
378+ $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
379+else
380+ $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
381+endif
382+ $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
383+endif
384+endif
385+
386 include $(srctree)/arch/$(SRCARCH)/Makefile
387
388 ifdef CONFIG_READABLE_ASM
389@@ -779,7 +846,7 @@ export mod_sign_cmd
390
391
392 ifeq ($(KBUILD_EXTMOD),)
393-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
394+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
395
396 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
397 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
398@@ -828,6 +895,8 @@ endif
399
400 # The actual objects are generated when descending,
401 # make sure no implicit rule kicks in
402+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
403+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
404 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
405
406 # Handle descending into subdirectories listed in $(vmlinux-dirs)
407@@ -837,7 +906,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
408 # Error messages still appears in the original language
409
410 PHONY += $(vmlinux-dirs)
411-$(vmlinux-dirs): prepare scripts
412+$(vmlinux-dirs): gcc-plugins prepare scripts
413 $(Q)$(MAKE) $(build)=$@
414
415 define filechk_kernel.release
416@@ -880,10 +949,13 @@ prepare1: prepare2 $(version_h) include/generated/utsrelease.h \
417
418 archprepare: archheaders archscripts prepare1 scripts_basic
419
420+prepare0: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
421+prepare0: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
422 prepare0: archprepare FORCE
423 $(Q)$(MAKE) $(build)=.
424
425 # All the preparing..
426+prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
427 prepare: prepare0
428
429 # Generate some files
430@@ -991,6 +1063,8 @@ all: modules
431 # using awk while concatenating to the final file.
432
433 PHONY += modules
434+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
435+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
436 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
437 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
438 @$(kecho) ' Building modules, stage 2.';
439@@ -1006,7 +1080,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
440
441 # Target to prepare building external modules
442 PHONY += modules_prepare
443-modules_prepare: prepare scripts
444+modules_prepare: gcc-plugins prepare scripts
445
446 # Target to install modules
447 PHONY += modules_install
448@@ -1072,7 +1146,8 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
449 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
450 signing_key.priv signing_key.x509 x509.genkey \
451 extra_certificates signing_key.x509.keyid \
452- signing_key.x509.signer
453+ signing_key.x509.signer tools/gcc/size_overflow_hash.h \
454+ tools/gcc/randomize_layout_seed.h
455
456 # clean - Delete most, but leave enough to build external modules
457 #
458@@ -1112,6 +1187,7 @@ distclean: mrproper
459 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
460 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
461 -o -name '.*.rej' \
462+ -o -name '.*.rej' -o -name '*.so' \
463 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
464 -type f -print | xargs rm -f
465
466@@ -1273,6 +1349,8 @@ PHONY += $(module-dirs) modules
467 $(module-dirs): crmodverdir $(objtree)/Module.symvers
468 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
469
470+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
471+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
472 modules: $(module-dirs)
473 @$(kecho) ' Building modules, stage 2.';
474 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
475@@ -1412,17 +1490,21 @@ else
476 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
477 endif
478
479-%.s: %.c prepare scripts FORCE
480+%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
481+%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
482+%.s: %.c gcc-plugins prepare scripts FORCE
483 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
484 %.i: %.c prepare scripts FORCE
485 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
486-%.o: %.c prepare scripts FORCE
487+%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
488+%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
489+%.o: %.c gcc-plugins prepare scripts FORCE
490 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
491 %.lst: %.c prepare scripts FORCE
492 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
493-%.s: %.S prepare scripts FORCE
494+%.s: %.S gcc-plugins prepare scripts FORCE
495 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
496-%.o: %.S prepare scripts FORCE
497+%.o: %.S gcc-plugins prepare scripts FORCE
498 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
499 %.symtypes: %.c prepare scripts FORCE
500 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
501@@ -1432,11 +1514,15 @@ endif
502 $(cmd_crmodverdir)
503 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
504 $(build)=$(build-dir)
505-%/: prepare scripts FORCE
506+%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
507+%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
508+%/: gcc-plugins prepare scripts FORCE
509 $(cmd_crmodverdir)
510 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
511 $(build)=$(build-dir)
512-%.ko: prepare scripts FORCE
513+%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
514+%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
515+%.ko: gcc-plugins prepare scripts FORCE
516 $(cmd_crmodverdir)
517 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
518 $(build)=$(build-dir) $(@:.ko=.o)
519diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
520index 78b03ef..da28a51 100644
521--- a/arch/alpha/include/asm/atomic.h
522+++ b/arch/alpha/include/asm/atomic.h
523@@ -292,6 +292,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
524 #define atomic_dec(v) atomic_sub(1,(v))
525 #define atomic64_dec(v) atomic64_sub(1,(v))
526
527+#define atomic64_read_unchecked(v) atomic64_read(v)
528+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
529+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
530+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
531+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
532+#define atomic64_inc_unchecked(v) atomic64_inc(v)
533+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
534+#define atomic64_dec_unchecked(v) atomic64_dec(v)
535+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
536+
537 #define smp_mb__before_atomic_dec() smp_mb()
538 #define smp_mb__after_atomic_dec() smp_mb()
539 #define smp_mb__before_atomic_inc() smp_mb()
540diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
541index ad368a9..fbe0f25 100644
542--- a/arch/alpha/include/asm/cache.h
543+++ b/arch/alpha/include/asm/cache.h
544@@ -4,19 +4,19 @@
545 #ifndef __ARCH_ALPHA_CACHE_H
546 #define __ARCH_ALPHA_CACHE_H
547
548+#include <linux/const.h>
549
550 /* Bytes per L1 (data) cache line. */
551 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
552-# define L1_CACHE_BYTES 64
553 # define L1_CACHE_SHIFT 6
554 #else
555 /* Both EV4 and EV5 are write-through, read-allocate,
556 direct-mapped, physical.
557 */
558-# define L1_CACHE_BYTES 32
559 # define L1_CACHE_SHIFT 5
560 #endif
561
562+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
563 #define SMP_CACHE_BYTES L1_CACHE_BYTES
564
565 #endif
566diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
567index 968d999..d36b2df 100644
568--- a/arch/alpha/include/asm/elf.h
569+++ b/arch/alpha/include/asm/elf.h
570@@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
571
572 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
573
574+#ifdef CONFIG_PAX_ASLR
575+#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
576+
577+#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
578+#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
579+#endif
580+
581 /* $0 is set by ld.so to a pointer to a function which might be
582 registered using atexit. This provides a mean for the dynamic
583 linker to call DT_FINI functions for shared libraries that have
584diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
585index aab14a0..b4fa3e7 100644
586--- a/arch/alpha/include/asm/pgalloc.h
587+++ b/arch/alpha/include/asm/pgalloc.h
588@@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
589 pgd_set(pgd, pmd);
590 }
591
592+static inline void
593+pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
594+{
595+ pgd_populate(mm, pgd, pmd);
596+}
597+
598 extern pgd_t *pgd_alloc(struct mm_struct *mm);
599
600 static inline void
601diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
602index d8f9b7e..f6222fa 100644
603--- a/arch/alpha/include/asm/pgtable.h
604+++ b/arch/alpha/include/asm/pgtable.h
605@@ -102,6 +102,17 @@ struct vm_area_struct;
606 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
607 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
608 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
609+
610+#ifdef CONFIG_PAX_PAGEEXEC
611+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
612+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
613+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
614+#else
615+# define PAGE_SHARED_NOEXEC PAGE_SHARED
616+# define PAGE_COPY_NOEXEC PAGE_COPY
617+# define PAGE_READONLY_NOEXEC PAGE_READONLY
618+#endif
619+
620 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
621
622 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
623diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
624index 2fd00b7..cfd5069 100644
625--- a/arch/alpha/kernel/module.c
626+++ b/arch/alpha/kernel/module.c
627@@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
628
629 /* The small sections were sorted to the end of the segment.
630 The following should definitely cover them. */
631- gp = (u64)me->module_core + me->core_size - 0x8000;
632+ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
633 got = sechdrs[me->arch.gotsecindex].sh_addr;
634
635 for (i = 0; i < n; i++) {
636diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
637index 1402fcc..0b1abd2 100644
638--- a/arch/alpha/kernel/osf_sys.c
639+++ b/arch/alpha/kernel/osf_sys.c
640@@ -1298,10 +1298,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
641 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
642
643 static unsigned long
644-arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
645- unsigned long limit)
646+arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
647+ unsigned long limit, unsigned long flags)
648 {
649 struct vm_unmapped_area_info info;
650+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
651
652 info.flags = 0;
653 info.length = len;
654@@ -1309,6 +1310,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
655 info.high_limit = limit;
656 info.align_mask = 0;
657 info.align_offset = 0;
658+ info.threadstack_offset = offset;
659 return vm_unmapped_area(&info);
660 }
661
662@@ -1341,20 +1343,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
663 merely specific addresses, but regions of memory -- perhaps
664 this feature should be incorporated into all ports? */
665
666+#ifdef CONFIG_PAX_RANDMMAP
667+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
668+#endif
669+
670 if (addr) {
671- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
672+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
673 if (addr != (unsigned long) -ENOMEM)
674 return addr;
675 }
676
677 /* Next, try allocating at TASK_UNMAPPED_BASE. */
678- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
679- len, limit);
680+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
681+
682 if (addr != (unsigned long) -ENOMEM)
683 return addr;
684
685 /* Finally, try allocating in low memory. */
686- addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
687+ addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
688
689 return addr;
690 }
691diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
692index 98838a0..b304fb4 100644
693--- a/arch/alpha/mm/fault.c
694+++ b/arch/alpha/mm/fault.c
695@@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
696 __reload_thread(pcb);
697 }
698
699+#ifdef CONFIG_PAX_PAGEEXEC
700+/*
701+ * PaX: decide what to do with offenders (regs->pc = fault address)
702+ *
703+ * returns 1 when task should be killed
704+ * 2 when patched PLT trampoline was detected
705+ * 3 when unpatched PLT trampoline was detected
706+ */
707+static int pax_handle_fetch_fault(struct pt_regs *regs)
708+{
709+
710+#ifdef CONFIG_PAX_EMUPLT
711+ int err;
712+
713+ do { /* PaX: patched PLT emulation #1 */
714+ unsigned int ldah, ldq, jmp;
715+
716+ err = get_user(ldah, (unsigned int *)regs->pc);
717+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
718+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
719+
720+ if (err)
721+ break;
722+
723+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
724+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
725+ jmp == 0x6BFB0000U)
726+ {
727+ unsigned long r27, addr;
728+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
729+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
730+
731+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
732+ err = get_user(r27, (unsigned long *)addr);
733+ if (err)
734+ break;
735+
736+ regs->r27 = r27;
737+ regs->pc = r27;
738+ return 2;
739+ }
740+ } while (0);
741+
742+ do { /* PaX: patched PLT emulation #2 */
743+ unsigned int ldah, lda, br;
744+
745+ err = get_user(ldah, (unsigned int *)regs->pc);
746+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
747+ err |= get_user(br, (unsigned int *)(regs->pc+8));
748+
749+ if (err)
750+ break;
751+
752+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
753+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
754+ (br & 0xFFE00000U) == 0xC3E00000U)
755+ {
756+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
757+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
758+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
759+
760+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
761+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
762+ return 2;
763+ }
764+ } while (0);
765+
766+ do { /* PaX: unpatched PLT emulation */
767+ unsigned int br;
768+
769+ err = get_user(br, (unsigned int *)regs->pc);
770+
771+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
772+ unsigned int br2, ldq, nop, jmp;
773+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
774+
775+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
776+ err = get_user(br2, (unsigned int *)addr);
777+ err |= get_user(ldq, (unsigned int *)(addr+4));
778+ err |= get_user(nop, (unsigned int *)(addr+8));
779+ err |= get_user(jmp, (unsigned int *)(addr+12));
780+ err |= get_user(resolver, (unsigned long *)(addr+16));
781+
782+ if (err)
783+ break;
784+
785+ if (br2 == 0xC3600000U &&
786+ ldq == 0xA77B000CU &&
787+ nop == 0x47FF041FU &&
788+ jmp == 0x6B7B0000U)
789+ {
790+ regs->r28 = regs->pc+4;
791+ regs->r27 = addr+16;
792+ regs->pc = resolver;
793+ return 3;
794+ }
795+ }
796+ } while (0);
797+#endif
798+
799+ return 1;
800+}
801+
802+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
803+{
804+ unsigned long i;
805+
806+ printk(KERN_ERR "PAX: bytes at PC: ");
807+ for (i = 0; i < 5; i++) {
808+ unsigned int c;
809+ if (get_user(c, (unsigned int *)pc+i))
810+ printk(KERN_CONT "???????? ");
811+ else
812+ printk(KERN_CONT "%08x ", c);
813+ }
814+ printk("\n");
815+}
816+#endif
817
818 /*
819 * This routine handles page faults. It determines the address,
820@@ -133,8 +251,29 @@ retry:
821 good_area:
822 si_code = SEGV_ACCERR;
823 if (cause < 0) {
824- if (!(vma->vm_flags & VM_EXEC))
825+ if (!(vma->vm_flags & VM_EXEC)) {
826+
827+#ifdef CONFIG_PAX_PAGEEXEC
828+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
829+ goto bad_area;
830+
831+ up_read(&mm->mmap_sem);
832+ switch (pax_handle_fetch_fault(regs)) {
833+
834+#ifdef CONFIG_PAX_EMUPLT
835+ case 2:
836+ case 3:
837+ return;
838+#endif
839+
840+ }
841+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
842+ do_group_exit(SIGKILL);
843+#else
844 goto bad_area;
845+#endif
846+
847+ }
848 } else if (!cause) {
849 /* Allow reads even for write-only mappings */
850 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
851diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
852index 44298ad..29a20c0 100644
853--- a/arch/arm/Kconfig
854+++ b/arch/arm/Kconfig
855@@ -1862,7 +1862,7 @@ config ALIGNMENT_TRAP
856
857 config UACCESS_WITH_MEMCPY
858 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
859- depends on MMU
860+ depends on MMU && !PAX_MEMORY_UDEREF
861 default y if CPU_FEROCEON
862 help
863 Implement faster copy_to_user and clear_user methods for CPU
864@@ -2125,6 +2125,7 @@ config XIP_PHYS_ADDR
865 config KEXEC
866 bool "Kexec system call (EXPERIMENTAL)"
867 depends on (!SMP || PM_SLEEP_SMP)
868+ depends on !GRKERNSEC_KMEM
869 help
870 kexec is a system call that implements the ability to shutdown your
871 current kernel, and to start another kernel. It is like a reboot
872diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
873index 62d2cb5..09d45e3 100644
874--- a/arch/arm/include/asm/atomic.h
875+++ b/arch/arm/include/asm/atomic.h
876@@ -18,17 +18,35 @@
877 #include <asm/barrier.h>
878 #include <asm/cmpxchg.h>
879
880+#ifdef CONFIG_GENERIC_ATOMIC64
881+#include <asm-generic/atomic64.h>
882+#endif
883+
884 #define ATOMIC_INIT(i) { (i) }
885
886 #ifdef __KERNEL__
887
888+#define _ASM_EXTABLE(from, to) \
889+" .pushsection __ex_table,\"a\"\n"\
890+" .align 3\n" \
891+" .long " #from ", " #to"\n" \
892+" .popsection"
893+
894 /*
895 * On ARM, ordinary assignment (str instruction) doesn't clear the local
896 * strex/ldrex monitor on some implementations. The reason we can use it for
897 * atomic_set() is the clrex or dummy strex done on every exception return.
898 */
899 #define atomic_read(v) (*(volatile int *)&(v)->counter)
900+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
901+{
902+ return v->counter;
903+}
904 #define atomic_set(v,i) (((v)->counter) = (i))
905+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
906+{
907+ v->counter = i;
908+}
909
910 #if __LINUX_ARM_ARCH__ >= 6
911
912@@ -44,6 +62,36 @@ static inline void atomic_add(int i, atomic_t *v)
913
914 prefetchw(&v->counter);
915 __asm__ __volatile__("@ atomic_add\n"
916+"1: ldrex %1, [%3]\n"
917+" adds %0, %1, %4\n"
918+
919+#ifdef CONFIG_PAX_REFCOUNT
920+" bvc 3f\n"
921+"2: bkpt 0xf103\n"
922+"3:\n"
923+#endif
924+
925+" strex %1, %0, [%3]\n"
926+" teq %1, #0\n"
927+" bne 1b"
928+
929+#ifdef CONFIG_PAX_REFCOUNT
930+"\n4:\n"
931+ _ASM_EXTABLE(2b, 4b)
932+#endif
933+
934+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
935+ : "r" (&v->counter), "Ir" (i)
936+ : "cc");
937+}
938+
939+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
940+{
941+ unsigned long tmp;
942+ int result;
943+
944+ prefetchw(&v->counter);
945+ __asm__ __volatile__("@ atomic_add_unchecked\n"
946 "1: ldrex %0, [%3]\n"
947 " add %0, %0, %4\n"
948 " strex %1, %0, [%3]\n"
949@@ -62,6 +110,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
950 smp_mb();
951
952 __asm__ __volatile__("@ atomic_add_return\n"
953+"1: ldrex %1, [%3]\n"
954+" adds %0, %1, %4\n"
955+
956+#ifdef CONFIG_PAX_REFCOUNT
957+" bvc 3f\n"
958+" mov %0, %1\n"
959+"2: bkpt 0xf103\n"
960+"3:\n"
961+#endif
962+
963+" strex %1, %0, [%3]\n"
964+" teq %1, #0\n"
965+" bne 1b"
966+
967+#ifdef CONFIG_PAX_REFCOUNT
968+"\n4:\n"
969+ _ASM_EXTABLE(2b, 4b)
970+#endif
971+
972+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
973+ : "r" (&v->counter), "Ir" (i)
974+ : "cc");
975+
976+ smp_mb();
977+
978+ return result;
979+}
980+
981+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
982+{
983+ unsigned long tmp;
984+ int result;
985+
986+ smp_mb();
987+
988+ __asm__ __volatile__("@ atomic_add_return_unchecked\n"
989 "1: ldrex %0, [%3]\n"
990 " add %0, %0, %4\n"
991 " strex %1, %0, [%3]\n"
992@@ -83,6 +167,36 @@ static inline void atomic_sub(int i, atomic_t *v)
993
994 prefetchw(&v->counter);
995 __asm__ __volatile__("@ atomic_sub\n"
996+"1: ldrex %1, [%3]\n"
997+" subs %0, %1, %4\n"
998+
999+#ifdef CONFIG_PAX_REFCOUNT
1000+" bvc 3f\n"
1001+"2: bkpt 0xf103\n"
1002+"3:\n"
1003+#endif
1004+
1005+" strex %1, %0, [%3]\n"
1006+" teq %1, #0\n"
1007+" bne 1b"
1008+
1009+#ifdef CONFIG_PAX_REFCOUNT
1010+"\n4:\n"
1011+ _ASM_EXTABLE(2b, 4b)
1012+#endif
1013+
1014+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1015+ : "r" (&v->counter), "Ir" (i)
1016+ : "cc");
1017+}
1018+
1019+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1020+{
1021+ unsigned long tmp;
1022+ int result;
1023+
1024+ prefetchw(&v->counter);
1025+ __asm__ __volatile__("@ atomic_sub_unchecked\n"
1026 "1: ldrex %0, [%3]\n"
1027 " sub %0, %0, %4\n"
1028 " strex %1, %0, [%3]\n"
1029@@ -101,11 +215,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1030 smp_mb();
1031
1032 __asm__ __volatile__("@ atomic_sub_return\n"
1033-"1: ldrex %0, [%3]\n"
1034-" sub %0, %0, %4\n"
1035+"1: ldrex %1, [%3]\n"
1036+" subs %0, %1, %4\n"
1037+
1038+#ifdef CONFIG_PAX_REFCOUNT
1039+" bvc 3f\n"
1040+" mov %0, %1\n"
1041+"2: bkpt 0xf103\n"
1042+"3:\n"
1043+#endif
1044+
1045 " strex %1, %0, [%3]\n"
1046 " teq %1, #0\n"
1047 " bne 1b"
1048+
1049+#ifdef CONFIG_PAX_REFCOUNT
1050+"\n4:\n"
1051+ _ASM_EXTABLE(2b, 4b)
1052+#endif
1053+
1054 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1055 : "r" (&v->counter), "Ir" (i)
1056 : "cc");
1057@@ -138,6 +266,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
1058 return oldval;
1059 }
1060
1061+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1062+{
1063+ unsigned long oldval, res;
1064+
1065+ smp_mb();
1066+
1067+ do {
1068+ __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1069+ "ldrex %1, [%3]\n"
1070+ "mov %0, #0\n"
1071+ "teq %1, %4\n"
1072+ "strexeq %0, %5, [%3]\n"
1073+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1074+ : "r" (&ptr->counter), "Ir" (old), "r" (new)
1075+ : "cc");
1076+ } while (res);
1077+
1078+ smp_mb();
1079+
1080+ return oldval;
1081+}
1082+
1083 #else /* ARM_ARCH_6 */
1084
1085 #ifdef CONFIG_SMP
1086@@ -156,7 +306,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1087
1088 return val;
1089 }
1090+
1091+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1092+{
1093+ return atomic_add_return(i, v);
1094+}
1095+
1096 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1097+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1098+{
1099+ (void) atomic_add_return(i, v);
1100+}
1101
1102 static inline int atomic_sub_return(int i, atomic_t *v)
1103 {
1104@@ -171,6 +331,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1105 return val;
1106 }
1107 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1108+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1109+{
1110+ (void) atomic_sub_return(i, v);
1111+}
1112
1113 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1114 {
1115@@ -186,9 +350,18 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1116 return ret;
1117 }
1118
1119+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1120+{
1121+ return atomic_cmpxchg(v, old, new);
1122+}
1123+
1124 #endif /* __LINUX_ARM_ARCH__ */
1125
1126 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1127+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1128+{
1129+ return xchg(&v->counter, new);
1130+}
1131
1132 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1133 {
1134@@ -201,11 +374,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1135 }
1136
1137 #define atomic_inc(v) atomic_add(1, v)
1138+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1139+{
1140+ atomic_add_unchecked(1, v);
1141+}
1142 #define atomic_dec(v) atomic_sub(1, v)
1143+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1144+{
1145+ atomic_sub_unchecked(1, v);
1146+}
1147
1148 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1149+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1150+{
1151+ return atomic_add_return_unchecked(1, v) == 0;
1152+}
1153 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1154 #define atomic_inc_return(v) (atomic_add_return(1, v))
1155+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1156+{
1157+ return atomic_add_return_unchecked(1, v);
1158+}
1159 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1160 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1161
1162@@ -221,6 +410,14 @@ typedef struct {
1163 long long counter;
1164 } atomic64_t;
1165
1166+#ifdef CONFIG_PAX_REFCOUNT
1167+typedef struct {
1168+ long long counter;
1169+} atomic64_unchecked_t;
1170+#else
1171+typedef atomic64_t atomic64_unchecked_t;
1172+#endif
1173+
1174 #define ATOMIC64_INIT(i) { (i) }
1175
1176 #ifdef CONFIG_ARM_LPAE
1177@@ -237,6 +434,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1178 return result;
1179 }
1180
1181+static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1182+{
1183+ long long result;
1184+
1185+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1186+" ldrd %0, %H0, [%1]"
1187+ : "=&r" (result)
1188+ : "r" (&v->counter), "Qo" (v->counter)
1189+ );
1190+
1191+ return result;
1192+}
1193+
1194 static inline void atomic64_set(atomic64_t *v, long long i)
1195 {
1196 __asm__ __volatile__("@ atomic64_set\n"
1197@@ -245,6 +455,15 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1198 : "r" (&v->counter), "r" (i)
1199 );
1200 }
1201+
1202+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1203+{
1204+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1205+" strd %2, %H2, [%1]"
1206+ : "=Qo" (v->counter)
1207+ : "r" (&v->counter), "r" (i)
1208+ );
1209+}
1210 #else
1211 static inline long long atomic64_read(const atomic64_t *v)
1212 {
1213@@ -259,6 +478,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1214 return result;
1215 }
1216
1217+static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1218+{
1219+ long long result;
1220+
1221+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1222+" ldrexd %0, %H0, [%1]"
1223+ : "=&r" (result)
1224+ : "r" (&v->counter), "Qo" (v->counter)
1225+ );
1226+
1227+ return result;
1228+}
1229+
1230 static inline void atomic64_set(atomic64_t *v, long long i)
1231 {
1232 long long tmp;
1233@@ -273,6 +505,21 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1234 : "r" (&v->counter), "r" (i)
1235 : "cc");
1236 }
1237+
1238+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1239+{
1240+ long long tmp;
1241+
1242+ prefetchw(&v->counter);
1243+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1244+"1: ldrexd %0, %H0, [%2]\n"
1245+" strexd %0, %3, %H3, [%2]\n"
1246+" teq %0, #0\n"
1247+" bne 1b"
1248+ : "=&r" (tmp), "=Qo" (v->counter)
1249+ : "r" (&v->counter), "r" (i)
1250+ : "cc");
1251+}
1252 #endif
1253
1254 static inline void atomic64_add(long long i, atomic64_t *v)
1255@@ -284,6 +531,37 @@ static inline void atomic64_add(long long i, atomic64_t *v)
1256 __asm__ __volatile__("@ atomic64_add\n"
1257 "1: ldrexd %0, %H0, [%3]\n"
1258 " adds %Q0, %Q0, %Q4\n"
1259+" adcs %R0, %R0, %R4\n"
1260+
1261+#ifdef CONFIG_PAX_REFCOUNT
1262+" bvc 3f\n"
1263+"2: bkpt 0xf103\n"
1264+"3:\n"
1265+#endif
1266+
1267+" strexd %1, %0, %H0, [%3]\n"
1268+" teq %1, #0\n"
1269+" bne 1b"
1270+
1271+#ifdef CONFIG_PAX_REFCOUNT
1272+"\n4:\n"
1273+ _ASM_EXTABLE(2b, 4b)
1274+#endif
1275+
1276+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1277+ : "r" (&v->counter), "r" (i)
1278+ : "cc");
1279+}
1280+
1281+static inline void atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
1282+{
1283+ long long result;
1284+ unsigned long tmp;
1285+
1286+ prefetchw(&v->counter);
1287+ __asm__ __volatile__("@ atomic64_add_unchecked\n"
1288+"1: ldrexd %0, %H0, [%3]\n"
1289+" adds %Q0, %Q0, %Q4\n"
1290 " adc %R0, %R0, %R4\n"
1291 " strexd %1, %0, %H0, [%3]\n"
1292 " teq %1, #0\n"
1293@@ -303,6 +581,44 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
1294 __asm__ __volatile__("@ atomic64_add_return\n"
1295 "1: ldrexd %0, %H0, [%3]\n"
1296 " adds %Q0, %Q0, %Q4\n"
1297+" adcs %R0, %R0, %R4\n"
1298+
1299+#ifdef CONFIG_PAX_REFCOUNT
1300+" bvc 3f\n"
1301+" mov %0, %1\n"
1302+" mov %H0, %H1\n"
1303+"2: bkpt 0xf103\n"
1304+"3:\n"
1305+#endif
1306+
1307+" strexd %1, %0, %H0, [%3]\n"
1308+" teq %1, #0\n"
1309+" bne 1b"
1310+
1311+#ifdef CONFIG_PAX_REFCOUNT
1312+"\n4:\n"
1313+ _ASM_EXTABLE(2b, 4b)
1314+#endif
1315+
1316+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1317+ : "r" (&v->counter), "r" (i)
1318+ : "cc");
1319+
1320+ smp_mb();
1321+
1322+ return result;
1323+}
1324+
1325+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
1326+{
1327+ long long result;
1328+ unsigned long tmp;
1329+
1330+ smp_mb();
1331+
1332+ __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1333+"1: ldrexd %0, %H0, [%3]\n"
1334+" adds %Q0, %Q0, %Q4\n"
1335 " adc %R0, %R0, %R4\n"
1336 " strexd %1, %0, %H0, [%3]\n"
1337 " teq %1, #0\n"
1338@@ -325,6 +641,37 @@ static inline void atomic64_sub(long long i, atomic64_t *v)
1339 __asm__ __volatile__("@ atomic64_sub\n"
1340 "1: ldrexd %0, %H0, [%3]\n"
1341 " subs %Q0, %Q0, %Q4\n"
1342+" sbcs %R0, %R0, %R4\n"
1343+
1344+#ifdef CONFIG_PAX_REFCOUNT
1345+" bvc 3f\n"
1346+"2: bkpt 0xf103\n"
1347+"3:\n"
1348+#endif
1349+
1350+" strexd %1, %0, %H0, [%3]\n"
1351+" teq %1, #0\n"
1352+" bne 1b"
1353+
1354+#ifdef CONFIG_PAX_REFCOUNT
1355+"\n4:\n"
1356+ _ASM_EXTABLE(2b, 4b)
1357+#endif
1358+
1359+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1360+ : "r" (&v->counter), "r" (i)
1361+ : "cc");
1362+}
1363+
1364+static inline void atomic64_sub_unchecked(long long i, atomic64_unchecked_t *v)
1365+{
1366+ long long result;
1367+ unsigned long tmp;
1368+
1369+ prefetchw(&v->counter);
1370+ __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1371+"1: ldrexd %0, %H0, [%3]\n"
1372+" subs %Q0, %Q0, %Q4\n"
1373 " sbc %R0, %R0, %R4\n"
1374 " strexd %1, %0, %H0, [%3]\n"
1375 " teq %1, #0\n"
1376@@ -344,16 +691,29 @@ static inline long long atomic64_sub_return(long long i, atomic64_t *v)
1377 __asm__ __volatile__("@ atomic64_sub_return\n"
1378 "1: ldrexd %0, %H0, [%3]\n"
1379 " subs %Q0, %Q0, %Q4\n"
1380-" sbc %R0, %R0, %R4\n"
1381+" sbcs %R0, %R0, %R4\n"
1382+
1383+#ifdef CONFIG_PAX_REFCOUNT
1384+" bvc 3f\n"
1385+" mov %0, %1\n"
1386+" mov %H0, %H1\n"
1387+"2: bkpt 0xf103\n"
1388+"3:\n"
1389+#endif
1390+
1391 " strexd %1, %0, %H0, [%3]\n"
1392 " teq %1, #0\n"
1393 " bne 1b"
1394+
1395+#ifdef CONFIG_PAX_REFCOUNT
1396+"\n4:\n"
1397+ _ASM_EXTABLE(2b, 4b)
1398+#endif
1399+
1400 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1401 : "r" (&v->counter), "r" (i)
1402 : "cc");
1403
1404- smp_mb();
1405-
1406 return result;
1407 }
1408
1409@@ -382,6 +742,31 @@ static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1410 return oldval;
1411 }
1412
1413+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, long long old,
1414+ long long new)
1415+{
1416+ long long oldval;
1417+ unsigned long res;
1418+
1419+ smp_mb();
1420+
1421+ do {
1422+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1423+ "ldrexd %1, %H1, [%3]\n"
1424+ "mov %0, #0\n"
1425+ "teq %1, %4\n"
1426+ "teqeq %H1, %H4\n"
1427+ "strexdeq %0, %5, %H5, [%3]"
1428+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1429+ : "r" (&ptr->counter), "r" (old), "r" (new)
1430+ : "cc");
1431+ } while (res);
1432+
1433+ smp_mb();
1434+
1435+ return oldval;
1436+}
1437+
1438 static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1439 {
1440 long long result;
1441@@ -406,20 +791,34 @@ static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1442 static inline long long atomic64_dec_if_positive(atomic64_t *v)
1443 {
1444 long long result;
1445- unsigned long tmp;
1446+ u64 tmp;
1447
1448 smp_mb();
1449
1450 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1451-"1: ldrexd %0, %H0, [%3]\n"
1452-" subs %Q0, %Q0, #1\n"
1453-" sbc %R0, %R0, #0\n"
1454+"1: ldrexd %1, %H1, [%3]\n"
1455+" subs %Q0, %Q1, #1\n"
1456+" sbcs %R0, %R1, #0\n"
1457+
1458+#ifdef CONFIG_PAX_REFCOUNT
1459+" bvc 3f\n"
1460+" mov %Q0, %Q1\n"
1461+" mov %R0, %R1\n"
1462+"2: bkpt 0xf103\n"
1463+"3:\n"
1464+#endif
1465+
1466 " teq %R0, #0\n"
1467-" bmi 2f\n"
1468+" bmi 4f\n"
1469 " strexd %1, %0, %H0, [%3]\n"
1470 " teq %1, #0\n"
1471 " bne 1b\n"
1472-"2:"
1473+"4:\n"
1474+
1475+#ifdef CONFIG_PAX_REFCOUNT
1476+ _ASM_EXTABLE(2b, 4b)
1477+#endif
1478+
1479 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1480 : "r" (&v->counter)
1481 : "cc");
1482@@ -442,13 +841,25 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1483 " teq %0, %5\n"
1484 " teqeq %H0, %H5\n"
1485 " moveq %1, #0\n"
1486-" beq 2f\n"
1487+" beq 4f\n"
1488 " adds %Q0, %Q0, %Q6\n"
1489-" adc %R0, %R0, %R6\n"
1490+" adcs %R0, %R0, %R6\n"
1491+
1492+#ifdef CONFIG_PAX_REFCOUNT
1493+" bvc 3f\n"
1494+"2: bkpt 0xf103\n"
1495+"3:\n"
1496+#endif
1497+
1498 " strexd %2, %0, %H0, [%4]\n"
1499 " teq %2, #0\n"
1500 " bne 1b\n"
1501-"2:"
1502+"4:\n"
1503+
1504+#ifdef CONFIG_PAX_REFCOUNT
1505+ _ASM_EXTABLE(2b, 4b)
1506+#endif
1507+
1508 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1509 : "r" (&v->counter), "r" (u), "r" (a)
1510 : "cc");
1511@@ -461,10 +872,13 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1512
1513 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1514 #define atomic64_inc(v) atomic64_add(1LL, (v))
1515+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1516 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1517+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1518 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1519 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1520 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1521+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1522 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1523 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1524 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1525diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1526index 75fe66b..ba3dee4 100644
1527--- a/arch/arm/include/asm/cache.h
1528+++ b/arch/arm/include/asm/cache.h
1529@@ -4,8 +4,10 @@
1530 #ifndef __ASMARM_CACHE_H
1531 #define __ASMARM_CACHE_H
1532
1533+#include <linux/const.h>
1534+
1535 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1536-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1537+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1538
1539 /*
1540 * Memory returned by kmalloc() may be used for DMA, so we must make
1541@@ -24,5 +26,6 @@
1542 #endif
1543
1544 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1545+#define __read_only __attribute__ ((__section__(".data..read_only")))
1546
1547 #endif
1548diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1549index 8b8b616..d973d24 100644
1550--- a/arch/arm/include/asm/cacheflush.h
1551+++ b/arch/arm/include/asm/cacheflush.h
1552@@ -116,7 +116,7 @@ struct cpu_cache_fns {
1553 void (*dma_unmap_area)(const void *, size_t, int);
1554
1555 void (*dma_flush_range)(const void *, const void *);
1556-};
1557+} __no_const;
1558
1559 /*
1560 * Select the calling method
1561diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1562index 5233151..87a71fa 100644
1563--- a/arch/arm/include/asm/checksum.h
1564+++ b/arch/arm/include/asm/checksum.h
1565@@ -37,7 +37,19 @@ __wsum
1566 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1567
1568 __wsum
1569-csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1570+__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1571+
1572+static inline __wsum
1573+csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1574+{
1575+ __wsum ret;
1576+ pax_open_userland();
1577+ ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1578+ pax_close_userland();
1579+ return ret;
1580+}
1581+
1582+
1583
1584 /*
1585 * Fold a partial checksum without adding pseudo headers
1586diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1587index df2fbba..63fe3e1 100644
1588--- a/arch/arm/include/asm/cmpxchg.h
1589+++ b/arch/arm/include/asm/cmpxchg.h
1590@@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1591
1592 #define xchg(ptr,x) \
1593 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1594+#define xchg_unchecked(ptr,x) \
1595+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1596
1597 #include <asm-generic/cmpxchg-local.h>
1598
1599diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1600index 6ddbe44..b5e38b1 100644
1601--- a/arch/arm/include/asm/domain.h
1602+++ b/arch/arm/include/asm/domain.h
1603@@ -48,18 +48,37 @@
1604 * Domain types
1605 */
1606 #define DOMAIN_NOACCESS 0
1607-#define DOMAIN_CLIENT 1
1608 #ifdef CONFIG_CPU_USE_DOMAINS
1609+#define DOMAIN_USERCLIENT 1
1610+#define DOMAIN_KERNELCLIENT 1
1611 #define DOMAIN_MANAGER 3
1612+#define DOMAIN_VECTORS DOMAIN_USER
1613 #else
1614+
1615+#ifdef CONFIG_PAX_KERNEXEC
1616 #define DOMAIN_MANAGER 1
1617+#define DOMAIN_KERNEXEC 3
1618+#else
1619+#define DOMAIN_MANAGER 1
1620+#endif
1621+
1622+#ifdef CONFIG_PAX_MEMORY_UDEREF
1623+#define DOMAIN_USERCLIENT 0
1624+#define DOMAIN_UDEREF 1
1625+#define DOMAIN_VECTORS DOMAIN_KERNEL
1626+#else
1627+#define DOMAIN_USERCLIENT 1
1628+#define DOMAIN_VECTORS DOMAIN_USER
1629+#endif
1630+#define DOMAIN_KERNELCLIENT 1
1631+
1632 #endif
1633
1634 #define domain_val(dom,type) ((type) << (2*(dom)))
1635
1636 #ifndef __ASSEMBLY__
1637
1638-#ifdef CONFIG_CPU_USE_DOMAINS
1639+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1640 static inline void set_domain(unsigned val)
1641 {
1642 asm volatile(
1643@@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1644 isb();
1645 }
1646
1647-#define modify_domain(dom,type) \
1648- do { \
1649- struct thread_info *thread = current_thread_info(); \
1650- unsigned int domain = thread->cpu_domain; \
1651- domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1652- thread->cpu_domain = domain | domain_val(dom, type); \
1653- set_domain(thread->cpu_domain); \
1654- } while (0)
1655-
1656+extern void modify_domain(unsigned int dom, unsigned int type);
1657 #else
1658 static inline void set_domain(unsigned val) { }
1659 static inline void modify_domain(unsigned dom, unsigned type) { }
1660diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1661index f4b46d3..abc9b2b 100644
1662--- a/arch/arm/include/asm/elf.h
1663+++ b/arch/arm/include/asm/elf.h
1664@@ -114,7 +114,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1665 the loader. We need to make sure that it is out of the way of the program
1666 that it will "exec", and that there is sufficient room for the brk. */
1667
1668-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1669+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1670+
1671+#ifdef CONFIG_PAX_ASLR
1672+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1673+
1674+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1675+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1676+#endif
1677
1678 /* When the program starts, a1 contains a pointer to a function to be
1679 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1680@@ -124,10 +131,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1681 extern void elf_set_personality(const struct elf32_hdr *);
1682 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1683
1684-struct mm_struct;
1685-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1686-#define arch_randomize_brk arch_randomize_brk
1687-
1688 #ifdef CONFIG_MMU
1689 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1690 struct linux_binprm;
1691diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1692index de53547..52b9a28 100644
1693--- a/arch/arm/include/asm/fncpy.h
1694+++ b/arch/arm/include/asm/fncpy.h
1695@@ -81,7 +81,9 @@
1696 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1697 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1698 \
1699+ pax_open_kernel(); \
1700 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1701+ pax_close_kernel(); \
1702 flush_icache_range((unsigned long)(dest_buf), \
1703 (unsigned long)(dest_buf) + (size)); \
1704 \
1705diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1706index 2aff798..099eb15 100644
1707--- a/arch/arm/include/asm/futex.h
1708+++ b/arch/arm/include/asm/futex.h
1709@@ -45,6 +45,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1710 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1711 return -EFAULT;
1712
1713+ pax_open_userland();
1714+
1715 smp_mb();
1716 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1717 "1: ldrex %1, [%4]\n"
1718@@ -60,6 +62,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1719 : "cc", "memory");
1720 smp_mb();
1721
1722+ pax_close_userland();
1723+
1724 *uval = val;
1725 return ret;
1726 }
1727@@ -90,6 +94,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1728 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1729 return -EFAULT;
1730
1731+ pax_open_userland();
1732+
1733 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1734 "1: " TUSER(ldr) " %1, [%4]\n"
1735 " teq %1, %2\n"
1736@@ -100,6 +106,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1737 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1738 : "cc", "memory");
1739
1740+ pax_close_userland();
1741+
1742 *uval = val;
1743 return ret;
1744 }
1745@@ -122,6 +130,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1746 return -EFAULT;
1747
1748 pagefault_disable(); /* implies preempt_disable() */
1749+ pax_open_userland();
1750
1751 switch (op) {
1752 case FUTEX_OP_SET:
1753@@ -143,6 +152,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1754 ret = -ENOSYS;
1755 }
1756
1757+ pax_close_userland();
1758 pagefault_enable(); /* subsumes preempt_enable() */
1759
1760 if (!ret) {
1761diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1762index 83eb2f7..ed77159 100644
1763--- a/arch/arm/include/asm/kmap_types.h
1764+++ b/arch/arm/include/asm/kmap_types.h
1765@@ -4,6 +4,6 @@
1766 /*
1767 * This is the "bare minimum". AIO seems to require this.
1768 */
1769-#define KM_TYPE_NR 16
1770+#define KM_TYPE_NR 17
1771
1772 #endif
1773diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1774index 9e614a1..3302cca 100644
1775--- a/arch/arm/include/asm/mach/dma.h
1776+++ b/arch/arm/include/asm/mach/dma.h
1777@@ -22,7 +22,7 @@ struct dma_ops {
1778 int (*residue)(unsigned int, dma_t *); /* optional */
1779 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1780 const char *type;
1781-};
1782+} __do_const;
1783
1784 struct dma_struct {
1785 void *addr; /* single DMA address */
1786diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1787index f98c7f3..e5c626d 100644
1788--- a/arch/arm/include/asm/mach/map.h
1789+++ b/arch/arm/include/asm/mach/map.h
1790@@ -23,17 +23,19 @@ struct map_desc {
1791
1792 /* types 0-3 are defined in asm/io.h */
1793 enum {
1794- MT_UNCACHED = 4,
1795- MT_CACHECLEAN,
1796- MT_MINICLEAN,
1797+ MT_UNCACHED_RW = 4,
1798+ MT_CACHECLEAN_RO,
1799+ MT_MINICLEAN_RO,
1800 MT_LOW_VECTORS,
1801 MT_HIGH_VECTORS,
1802- MT_MEMORY_RWX,
1803+ __MT_MEMORY_RWX,
1804 MT_MEMORY_RW,
1805- MT_ROM,
1806- MT_MEMORY_RWX_NONCACHED,
1807+ MT_MEMORY_RX,
1808+ MT_ROM_RX,
1809+ MT_MEMORY_RW_NONCACHED,
1810+ MT_MEMORY_RX_NONCACHED,
1811 MT_MEMORY_RW_DTCM,
1812- MT_MEMORY_RWX_ITCM,
1813+ MT_MEMORY_RX_ITCM,
1814 MT_MEMORY_RW_SO,
1815 MT_MEMORY_DMA_READY,
1816 };
1817diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1818index f94784f..9a09a4a 100644
1819--- a/arch/arm/include/asm/outercache.h
1820+++ b/arch/arm/include/asm/outercache.h
1821@@ -35,7 +35,7 @@ struct outer_cache_fns {
1822 #endif
1823 void (*set_debug)(unsigned long);
1824 void (*resume)(void);
1825-};
1826+} __no_const;
1827
1828 extern struct outer_cache_fns outer_cache;
1829
1830diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1831index 4355f0e..cd9168e 100644
1832--- a/arch/arm/include/asm/page.h
1833+++ b/arch/arm/include/asm/page.h
1834@@ -23,6 +23,7 @@
1835
1836 #else
1837
1838+#include <linux/compiler.h>
1839 #include <asm/glue.h>
1840
1841 /*
1842@@ -114,7 +115,7 @@ struct cpu_user_fns {
1843 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1844 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1845 unsigned long vaddr, struct vm_area_struct *vma);
1846-};
1847+} __no_const;
1848
1849 #ifdef MULTI_USER
1850 extern struct cpu_user_fns cpu_user;
1851diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1852index 78a7793..e3dc06c 100644
1853--- a/arch/arm/include/asm/pgalloc.h
1854+++ b/arch/arm/include/asm/pgalloc.h
1855@@ -17,6 +17,7 @@
1856 #include <asm/processor.h>
1857 #include <asm/cacheflush.h>
1858 #include <asm/tlbflush.h>
1859+#include <asm/system_info.h>
1860
1861 #define check_pgt_cache() do { } while (0)
1862
1863@@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1864 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1865 }
1866
1867+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1868+{
1869+ pud_populate(mm, pud, pmd);
1870+}
1871+
1872 #else /* !CONFIG_ARM_LPAE */
1873
1874 /*
1875@@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1876 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1877 #define pmd_free(mm, pmd) do { } while (0)
1878 #define pud_populate(mm,pmd,pte) BUG()
1879+#define pud_populate_kernel(mm,pmd,pte) BUG()
1880
1881 #endif /* CONFIG_ARM_LPAE */
1882
1883@@ -128,6 +135,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1884 __free_page(pte);
1885 }
1886
1887+static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1888+{
1889+#ifdef CONFIG_ARM_LPAE
1890+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1891+#else
1892+ if (addr & SECTION_SIZE)
1893+ pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1894+ else
1895+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1896+#endif
1897+ flush_pmd_entry(pmdp);
1898+}
1899+
1900 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1901 pmdval_t prot)
1902 {
1903@@ -157,7 +177,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1904 static inline void
1905 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1906 {
1907- __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1908+ __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1909 }
1910 #define pmd_pgtable(pmd) pmd_page(pmd)
1911
1912diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1913index 5cfba15..f415e1a 100644
1914--- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1915+++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1916@@ -20,12 +20,15 @@
1917 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1918 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1919 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1920+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1921 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1922 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1923 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1924+
1925 /*
1926 * - section
1927 */
1928+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1929 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1930 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1931 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1932@@ -37,6 +40,7 @@
1933 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1934 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1935 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1936+#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1937
1938 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1939 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1940@@ -66,6 +70,7 @@
1941 * - extended small page/tiny page
1942 */
1943 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1944+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1945 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1946 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1947 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1948diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1949index 219ac88..73ec32a 100644
1950--- a/arch/arm/include/asm/pgtable-2level.h
1951+++ b/arch/arm/include/asm/pgtable-2level.h
1952@@ -126,6 +126,9 @@
1953 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1954 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1955
1956+/* Two-level page tables only have PXN in the PGD, not in the PTE. */
1957+#define L_PTE_PXN (_AT(pteval_t, 0))
1958+
1959 /*
1960 * These are the memory types, defined to be compatible with
1961 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
1962diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1963index 626989f..9d67a33 100644
1964--- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1965+++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1966@@ -75,6 +75,7 @@
1967 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1968 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1969 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1970+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1971 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1972
1973 /*
1974diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1975index 85c60ad..b0bbd7e 100644
1976--- a/arch/arm/include/asm/pgtable-3level.h
1977+++ b/arch/arm/include/asm/pgtable-3level.h
1978@@ -82,6 +82,7 @@
1979 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1980 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1981 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1982+#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1983 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1984 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1985 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1986@@ -95,6 +96,7 @@
1987 /*
1988 * To be used in assembly code with the upper page attributes.
1989 */
1990+#define L_PTE_PXN_HIGH (1 << (53 - 32))
1991 #define L_PTE_XN_HIGH (1 << (54 - 32))
1992 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1993
1994diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1995index 7d59b52..27a12f8 100644
1996--- a/arch/arm/include/asm/pgtable.h
1997+++ b/arch/arm/include/asm/pgtable.h
1998@@ -33,6 +33,9 @@
1999 #include <asm/pgtable-2level.h>
2000 #endif
2001
2002+#define ktla_ktva(addr) (addr)
2003+#define ktva_ktla(addr) (addr)
2004+
2005 /*
2006 * Just any arbitrary offset to the start of the vmalloc VM area: the
2007 * current 8MB value just means that there will be a 8MB "hole" after the
2008@@ -48,6 +51,9 @@
2009 #define LIBRARY_TEXT_START 0x0c000000
2010
2011 #ifndef __ASSEMBLY__
2012+extern pteval_t __supported_pte_mask;
2013+extern pmdval_t __supported_pmd_mask;
2014+
2015 extern void __pte_error(const char *file, int line, pte_t);
2016 extern void __pmd_error(const char *file, int line, pmd_t);
2017 extern void __pgd_error(const char *file, int line, pgd_t);
2018@@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2019 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
2020 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
2021
2022+#define __HAVE_ARCH_PAX_OPEN_KERNEL
2023+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2024+
2025+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2026+#include <asm/domain.h>
2027+#include <linux/thread_info.h>
2028+#include <linux/preempt.h>
2029+
2030+static inline int test_domain(int domain, int domaintype)
2031+{
2032+ return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2033+}
2034+#endif
2035+
2036+#ifdef CONFIG_PAX_KERNEXEC
2037+static inline unsigned long pax_open_kernel(void) {
2038+#ifdef CONFIG_ARM_LPAE
2039+ /* TODO */
2040+#else
2041+ preempt_disable();
2042+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2043+ modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2044+#endif
2045+ return 0;
2046+}
2047+
2048+static inline unsigned long pax_close_kernel(void) {
2049+#ifdef CONFIG_ARM_LPAE
2050+ /* TODO */
2051+#else
2052+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2053+ /* DOMAIN_MANAGER = "client" under KERNEXEC */
2054+ modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2055+ preempt_enable_no_resched();
2056+#endif
2057+ return 0;
2058+}
2059+#else
2060+static inline unsigned long pax_open_kernel(void) { return 0; }
2061+static inline unsigned long pax_close_kernel(void) { return 0; }
2062+#endif
2063+
2064 /*
2065 * This is the lowest virtual address we can permit any user space
2066 * mapping to be mapped at. This is particularly important for
2067@@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2068 /*
2069 * The pgprot_* and protection_map entries will be fixed up in runtime
2070 * to include the cachable and bufferable bits based on memory policy,
2071- * as well as any architecture dependent bits like global/ASID and SMP
2072- * shared mapping bits.
2073+ * as well as any architecture dependent bits like global/ASID, PXN,
2074+ * and SMP shared mapping bits.
2075 */
2076 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2077
2078@@ -262,7 +310,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2079 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2080 {
2081 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2082- L_PTE_NONE | L_PTE_VALID;
2083+ L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2084 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2085 return pte;
2086 }
2087diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2088index c4ae171..ea0c0c2 100644
2089--- a/arch/arm/include/asm/psci.h
2090+++ b/arch/arm/include/asm/psci.h
2091@@ -29,7 +29,7 @@ struct psci_operations {
2092 int (*cpu_off)(struct psci_power_state state);
2093 int (*cpu_on)(unsigned long cpuid, unsigned long entry_point);
2094 int (*migrate)(unsigned long cpuid);
2095-};
2096+} __no_const;
2097
2098 extern struct psci_operations psci_ops;
2099 extern struct smp_operations psci_smp_ops;
2100diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2101index 22a3b9b..7f214ee 100644
2102--- a/arch/arm/include/asm/smp.h
2103+++ b/arch/arm/include/asm/smp.h
2104@@ -112,7 +112,7 @@ struct smp_operations {
2105 int (*cpu_disable)(unsigned int cpu);
2106 #endif
2107 #endif
2108-};
2109+} __no_const;
2110
2111 /*
2112 * set platform specific SMP operations
2113diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2114index 71a06b2..8bb9ae1 100644
2115--- a/arch/arm/include/asm/thread_info.h
2116+++ b/arch/arm/include/asm/thread_info.h
2117@@ -88,9 +88,9 @@ struct thread_info {
2118 .flags = 0, \
2119 .preempt_count = INIT_PREEMPT_COUNT, \
2120 .addr_limit = KERNEL_DS, \
2121- .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2122- domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2123- domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2124+ .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2125+ domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2126+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2127 .restart_block = { \
2128 .fn = do_no_restart_syscall, \
2129 }, \
2130@@ -157,7 +157,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2131 #define TIF_SYSCALL_AUDIT 9
2132 #define TIF_SYSCALL_TRACEPOINT 10
2133 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2134-#define TIF_NOHZ 12 /* in adaptive nohz mode */
2135+/* within 8 bits of TIF_SYSCALL_TRACE
2136+ * to meet flexible second operand requirements
2137+ */
2138+#define TIF_GRSEC_SETXID 12
2139+#define TIF_NOHZ 13 /* in adaptive nohz mode */
2140 #define TIF_USING_IWMMXT 17
2141 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2142 #define TIF_RESTORE_SIGMASK 20
2143@@ -170,10 +174,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2144 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2145 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2146 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2147+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2148
2149 /* Checks for any syscall work in entry-common.S */
2150 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2151- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2152+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2153
2154 /*
2155 * Change these and you break ASM code in entry-common.S
2156diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2157index 72abdc5..35acac1 100644
2158--- a/arch/arm/include/asm/uaccess.h
2159+++ b/arch/arm/include/asm/uaccess.h
2160@@ -18,6 +18,7 @@
2161 #include <asm/domain.h>
2162 #include <asm/unified.h>
2163 #include <asm/compiler.h>
2164+#include <asm/pgtable.h>
2165
2166 #if __LINUX_ARM_ARCH__ < 6
2167 #include <asm-generic/uaccess-unaligned.h>
2168@@ -70,11 +71,38 @@ extern int __put_user_bad(void);
2169 static inline void set_fs(mm_segment_t fs)
2170 {
2171 current_thread_info()->addr_limit = fs;
2172- modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2173+ modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2174 }
2175
2176 #define segment_eq(a,b) ((a) == (b))
2177
2178+#define __HAVE_ARCH_PAX_OPEN_USERLAND
2179+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2180+
2181+static inline void pax_open_userland(void)
2182+{
2183+
2184+#ifdef CONFIG_PAX_MEMORY_UDEREF
2185+ if (segment_eq(get_fs(), USER_DS)) {
2186+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2187+ modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2188+ }
2189+#endif
2190+
2191+}
2192+
2193+static inline void pax_close_userland(void)
2194+{
2195+
2196+#ifdef CONFIG_PAX_MEMORY_UDEREF
2197+ if (segment_eq(get_fs(), USER_DS)) {
2198+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2199+ modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2200+ }
2201+#endif
2202+
2203+}
2204+
2205 #define __addr_ok(addr) ({ \
2206 unsigned long flag; \
2207 __asm__("cmp %2, %0; movlo %0, #0" \
2208@@ -150,8 +178,12 @@ extern int __get_user_4(void *);
2209
2210 #define get_user(x,p) \
2211 ({ \
2212+ int __e; \
2213 might_fault(); \
2214- __get_user_check(x,p); \
2215+ pax_open_userland(); \
2216+ __e = __get_user_check(x,p); \
2217+ pax_close_userland(); \
2218+ __e; \
2219 })
2220
2221 extern int __put_user_1(void *, unsigned int);
2222@@ -195,8 +227,12 @@ extern int __put_user_8(void *, unsigned long long);
2223
2224 #define put_user(x,p) \
2225 ({ \
2226+ int __e; \
2227 might_fault(); \
2228- __put_user_check(x,p); \
2229+ pax_open_userland(); \
2230+ __e = __put_user_check(x,p); \
2231+ pax_close_userland(); \
2232+ __e; \
2233 })
2234
2235 #else /* CONFIG_MMU */
2236@@ -220,6 +256,7 @@ static inline void set_fs(mm_segment_t fs)
2237
2238 #endif /* CONFIG_MMU */
2239
2240+#define access_ok_noprefault(type,addr,size) access_ok((type),(addr),(size))
2241 #define access_ok(type,addr,size) (__range_ok(addr,size) == 0)
2242
2243 #define user_addr_max() \
2244@@ -237,13 +274,17 @@ static inline void set_fs(mm_segment_t fs)
2245 #define __get_user(x,ptr) \
2246 ({ \
2247 long __gu_err = 0; \
2248+ pax_open_userland(); \
2249 __get_user_err((x),(ptr),__gu_err); \
2250+ pax_close_userland(); \
2251 __gu_err; \
2252 })
2253
2254 #define __get_user_error(x,ptr,err) \
2255 ({ \
2256+ pax_open_userland(); \
2257 __get_user_err((x),(ptr),err); \
2258+ pax_close_userland(); \
2259 (void) 0; \
2260 })
2261
2262@@ -319,13 +360,17 @@ do { \
2263 #define __put_user(x,ptr) \
2264 ({ \
2265 long __pu_err = 0; \
2266+ pax_open_userland(); \
2267 __put_user_err((x),(ptr),__pu_err); \
2268+ pax_close_userland(); \
2269 __pu_err; \
2270 })
2271
2272 #define __put_user_error(x,ptr,err) \
2273 ({ \
2274+ pax_open_userland(); \
2275 __put_user_err((x),(ptr),err); \
2276+ pax_close_userland(); \
2277 (void) 0; \
2278 })
2279
2280@@ -425,11 +470,44 @@ do { \
2281
2282
2283 #ifdef CONFIG_MMU
2284-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2285-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2286+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2287+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2288+
2289+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2290+{
2291+ unsigned long ret;
2292+
2293+ check_object_size(to, n, false);
2294+ pax_open_userland();
2295+ ret = ___copy_from_user(to, from, n);
2296+ pax_close_userland();
2297+ return ret;
2298+}
2299+
2300+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2301+{
2302+ unsigned long ret;
2303+
2304+ check_object_size(from, n, true);
2305+ pax_open_userland();
2306+ ret = ___copy_to_user(to, from, n);
2307+ pax_close_userland();
2308+ return ret;
2309+}
2310+
2311 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2312-extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2313+extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2314 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2315+
2316+static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2317+{
2318+ unsigned long ret;
2319+ pax_open_userland();
2320+ ret = ___clear_user(addr, n);
2321+ pax_close_userland();
2322+ return ret;
2323+}
2324+
2325 #else
2326 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2327 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2328@@ -438,6 +516,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2329
2330 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2331 {
2332+ if ((long)n < 0)
2333+ return n;
2334+
2335 if (access_ok(VERIFY_READ, from, n))
2336 n = __copy_from_user(to, from, n);
2337 else /* security hole - plug it */
2338@@ -447,6 +528,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2339
2340 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2341 {
2342+ if ((long)n < 0)
2343+ return n;
2344+
2345 if (access_ok(VERIFY_WRITE, to, n))
2346 n = __copy_to_user(to, from, n);
2347 return n;
2348diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2349index 5af0ed1..cea83883 100644
2350--- a/arch/arm/include/uapi/asm/ptrace.h
2351+++ b/arch/arm/include/uapi/asm/ptrace.h
2352@@ -92,7 +92,7 @@
2353 * ARMv7 groups of PSR bits
2354 */
2355 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2356-#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2357+#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2358 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2359 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2360
2361diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2362index 85e664b..419a1cd 100644
2363--- a/arch/arm/kernel/armksyms.c
2364+++ b/arch/arm/kernel/armksyms.c
2365@@ -55,7 +55,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2366
2367 /* networking */
2368 EXPORT_SYMBOL(csum_partial);
2369-EXPORT_SYMBOL(csum_partial_copy_from_user);
2370+EXPORT_SYMBOL(__csum_partial_copy_from_user);
2371 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2372 EXPORT_SYMBOL(__csum_ipv6_magic);
2373
2374@@ -91,9 +91,9 @@ EXPORT_SYMBOL(__memzero);
2375 #ifdef CONFIG_MMU
2376 EXPORT_SYMBOL(copy_page);
2377
2378-EXPORT_SYMBOL(__copy_from_user);
2379-EXPORT_SYMBOL(__copy_to_user);
2380-EXPORT_SYMBOL(__clear_user);
2381+EXPORT_SYMBOL(___copy_from_user);
2382+EXPORT_SYMBOL(___copy_to_user);
2383+EXPORT_SYMBOL(___clear_user);
2384
2385 EXPORT_SYMBOL(__get_user_1);
2386 EXPORT_SYMBOL(__get_user_2);
2387diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2388index 1879e8d..b2207fc 100644
2389--- a/arch/arm/kernel/entry-armv.S
2390+++ b/arch/arm/kernel/entry-armv.S
2391@@ -47,6 +47,87 @@
2392 9997:
2393 .endm
2394
2395+ .macro pax_enter_kernel
2396+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2397+ @ make aligned space for saved DACR
2398+ sub sp, sp, #8
2399+ @ save regs
2400+ stmdb sp!, {r1, r2}
2401+ @ read DACR from cpu_domain into r1
2402+ mov r2, sp
2403+ @ assume 8K pages, since we have to split the immediate in two
2404+ bic r2, r2, #(0x1fc0)
2405+ bic r2, r2, #(0x3f)
2406+ ldr r1, [r2, #TI_CPU_DOMAIN]
2407+ @ store old DACR on stack
2408+ str r1, [sp, #8]
2409+#ifdef CONFIG_PAX_KERNEXEC
2410+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2411+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2412+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2413+#endif
2414+#ifdef CONFIG_PAX_MEMORY_UDEREF
2415+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2416+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2417+#endif
2418+ @ write r1 to current_thread_info()->cpu_domain
2419+ str r1, [r2, #TI_CPU_DOMAIN]
2420+ @ write r1 to DACR
2421+ mcr p15, 0, r1, c3, c0, 0
2422+ @ instruction sync
2423+ instr_sync
2424+ @ restore regs
2425+ ldmia sp!, {r1, r2}
2426+#endif
2427+ .endm
2428+
2429+ .macro pax_open_userland
2430+#ifdef CONFIG_PAX_MEMORY_UDEREF
2431+ @ save regs
2432+ stmdb sp!, {r0, r1}
2433+ @ read DACR from cpu_domain into r1
2434+ mov r0, sp
2435+ @ assume 8K pages, since we have to split the immediate in two
2436+ bic r0, r0, #(0x1fc0)
2437+ bic r0, r0, #(0x3f)
2438+ ldr r1, [r0, #TI_CPU_DOMAIN]
2439+ @ set current DOMAIN_USER to DOMAIN_CLIENT
2440+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2441+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2442+ @ write r1 to current_thread_info()->cpu_domain
2443+ str r1, [r0, #TI_CPU_DOMAIN]
2444+ @ write r1 to DACR
2445+ mcr p15, 0, r1, c3, c0, 0
2446+ @ instruction sync
2447+ instr_sync
2448+ @ restore regs
2449+ ldmia sp!, {r0, r1}
2450+#endif
2451+ .endm
2452+
2453+ .macro pax_close_userland
2454+#ifdef CONFIG_PAX_MEMORY_UDEREF
2455+ @ save regs
2456+ stmdb sp!, {r0, r1}
2457+ @ read DACR from cpu_domain into r1
2458+ mov r0, sp
2459+ @ assume 8K pages, since we have to split the immediate in two
2460+ bic r0, r0, #(0x1fc0)
2461+ bic r0, r0, #(0x3f)
2462+ ldr r1, [r0, #TI_CPU_DOMAIN]
2463+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2464+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2465+ @ write r1 to current_thread_info()->cpu_domain
2466+ str r1, [r0, #TI_CPU_DOMAIN]
2467+ @ write r1 to DACR
2468+ mcr p15, 0, r1, c3, c0, 0
2469+ @ instruction sync
2470+ instr_sync
2471+ @ restore regs
2472+ ldmia sp!, {r0, r1}
2473+#endif
2474+ .endm
2475+
2476 .macro pabt_helper
2477 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2478 #ifdef MULTI_PABORT
2479@@ -89,11 +170,15 @@
2480 * Invalid mode handlers
2481 */
2482 .macro inv_entry, reason
2483+
2484+ pax_enter_kernel
2485+
2486 sub sp, sp, #S_FRAME_SIZE
2487 ARM( stmib sp, {r1 - lr} )
2488 THUMB( stmia sp, {r0 - r12} )
2489 THUMB( str sp, [sp, #S_SP] )
2490 THUMB( str lr, [sp, #S_LR] )
2491+
2492 mov r1, #\reason
2493 .endm
2494
2495@@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2496 .macro svc_entry, stack_hole=0
2497 UNWIND(.fnstart )
2498 UNWIND(.save {r0 - pc} )
2499+
2500+ pax_enter_kernel
2501+
2502 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2503+
2504 #ifdef CONFIG_THUMB2_KERNEL
2505 SPFIX( str r0, [sp] ) @ temporarily saved
2506 SPFIX( mov r0, sp )
2507@@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2508 ldmia r0, {r3 - r5}
2509 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2510 mov r6, #-1 @ "" "" "" ""
2511+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2512+ @ offset sp by 8 as done in pax_enter_kernel
2513+ add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2514+#else
2515 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2516+#endif
2517 SPFIX( addeq r2, r2, #4 )
2518 str r3, [sp, #-4]! @ save the "real" r0 copied
2519 @ from the exception stack
2520@@ -317,6 +411,9 @@ ENDPROC(__pabt_svc)
2521 .macro usr_entry
2522 UNWIND(.fnstart )
2523 UNWIND(.cantunwind ) @ don't unwind the user space
2524+
2525+ pax_enter_kernel_user
2526+
2527 sub sp, sp, #S_FRAME_SIZE
2528 ARM( stmib sp, {r1 - r12} )
2529 THUMB( stmia sp, {r0 - r12} )
2530@@ -416,7 +513,9 @@ __und_usr:
2531 tst r3, #PSR_T_BIT @ Thumb mode?
2532 bne __und_usr_thumb
2533 sub r4, r2, #4 @ ARM instr at LR - 4
2534+ pax_open_userland
2535 1: ldrt r0, [r4]
2536+ pax_close_userland
2537 ARM_BE8(rev r0, r0) @ little endian instruction
2538
2539 @ r0 = 32-bit ARM instruction which caused the exception
2540@@ -450,11 +549,15 @@ __und_usr_thumb:
2541 */
2542 .arch armv6t2
2543 #endif
2544+ pax_open_userland
2545 2: ldrht r5, [r4]
2546+ pax_close_userland
2547 ARM_BE8(rev16 r5, r5) @ little endian instruction
2548 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2549 blo __und_usr_fault_16 @ 16bit undefined instruction
2550+ pax_open_userland
2551 3: ldrht r0, [r2]
2552+ pax_close_userland
2553 ARM_BE8(rev16 r0, r0) @ little endian instruction
2554 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2555 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2556@@ -484,7 +587,8 @@ ENDPROC(__und_usr)
2557 */
2558 .pushsection .fixup, "ax"
2559 .align 2
2560-4: mov pc, r9
2561+4: pax_close_userland
2562+ mov pc, r9
2563 .popsection
2564 .pushsection __ex_table,"a"
2565 .long 1b, 4b
2566@@ -694,7 +798,7 @@ ENTRY(__switch_to)
2567 THUMB( str lr, [ip], #4 )
2568 ldr r4, [r2, #TI_TP_VALUE]
2569 ldr r5, [r2, #TI_TP_VALUE + 4]
2570-#ifdef CONFIG_CPU_USE_DOMAINS
2571+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2572 ldr r6, [r2, #TI_CPU_DOMAIN]
2573 #endif
2574 switch_tls r1, r4, r5, r3, r7
2575@@ -703,7 +807,7 @@ ENTRY(__switch_to)
2576 ldr r8, =__stack_chk_guard
2577 ldr r7, [r7, #TSK_STACK_CANARY]
2578 #endif
2579-#ifdef CONFIG_CPU_USE_DOMAINS
2580+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2581 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2582 #endif
2583 mov r5, r0
2584diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2585index a2dcafd..1048b5a 100644
2586--- a/arch/arm/kernel/entry-common.S
2587+++ b/arch/arm/kernel/entry-common.S
2588@@ -10,18 +10,46 @@
2589
2590 #include <asm/unistd.h>
2591 #include <asm/ftrace.h>
2592+#include <asm/domain.h>
2593 #include <asm/unwind.h>
2594
2595+#include "entry-header.S"
2596+
2597 #ifdef CONFIG_NEED_RET_TO_USER
2598 #include <mach/entry-macro.S>
2599 #else
2600 .macro arch_ret_to_user, tmp1, tmp2
2601+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2602+ @ save regs
2603+ stmdb sp!, {r1, r2}
2604+ @ read DACR from cpu_domain into r1
2605+ mov r2, sp
2606+ @ assume 8K pages, since we have to split the immediate in two
2607+ bic r2, r2, #(0x1fc0)
2608+ bic r2, r2, #(0x3f)
2609+ ldr r1, [r2, #TI_CPU_DOMAIN]
2610+#ifdef CONFIG_PAX_KERNEXEC
2611+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2612+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2613+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2614+#endif
2615+#ifdef CONFIG_PAX_MEMORY_UDEREF
2616+ @ set current DOMAIN_USER to DOMAIN_UDEREF
2617+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2618+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2619+#endif
2620+ @ write r1 to current_thread_info()->cpu_domain
2621+ str r1, [r2, #TI_CPU_DOMAIN]
2622+ @ write r1 to DACR
2623+ mcr p15, 0, r1, c3, c0, 0
2624+ @ instruction sync
2625+ instr_sync
2626+ @ restore regs
2627+ ldmia sp!, {r1, r2}
2628+#endif
2629 .endm
2630 #endif
2631
2632-#include "entry-header.S"
2633-
2634-
2635 .align 5
2636 /*
2637 * This is the fast syscall return path. We do as little as
2638@@ -411,6 +439,12 @@ ENTRY(vector_swi)
2639 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2640 #endif
2641
2642+ /*
2643+ * do this here to avoid a performance hit of wrapping the code above
2644+ * that directly dereferences userland to parse the SWI instruction
2645+ */
2646+ pax_enter_kernel_user
2647+
2648 adr tbl, sys_call_table @ load syscall table pointer
2649
2650 #if defined(CONFIG_OABI_COMPAT)
2651diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2652index 39f89fb..d612bd9 100644
2653--- a/arch/arm/kernel/entry-header.S
2654+++ b/arch/arm/kernel/entry-header.S
2655@@ -184,6 +184,60 @@
2656 msr cpsr_c, \rtemp @ switch back to the SVC mode
2657 .endm
2658
2659+ .macro pax_enter_kernel_user
2660+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2661+ @ save regs
2662+ stmdb sp!, {r0, r1}
2663+ @ read DACR from cpu_domain into r1
2664+ mov r0, sp
2665+ @ assume 8K pages, since we have to split the immediate in two
2666+ bic r0, r0, #(0x1fc0)
2667+ bic r0, r0, #(0x3f)
2668+ ldr r1, [r0, #TI_CPU_DOMAIN]
2669+#ifdef CONFIG_PAX_MEMORY_UDEREF
2670+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2671+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2672+#endif
2673+#ifdef CONFIG_PAX_KERNEXEC
2674+ @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2675+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2676+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2677+#endif
2678+ @ write r1 to current_thread_info()->cpu_domain
2679+ str r1, [r0, #TI_CPU_DOMAIN]
2680+ @ write r1 to DACR
2681+ mcr p15, 0, r1, c3, c0, 0
2682+ @ instruction sync
2683+ instr_sync
2684+ @ restore regs
2685+ ldmia sp!, {r0, r1}
2686+#endif
2687+ .endm
2688+
2689+ .macro pax_exit_kernel
2690+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2691+ @ save regs
2692+ stmdb sp!, {r0, r1}
2693+ @ read old DACR from stack into r1
2694+ ldr r1, [sp, #(8 + S_SP)]
2695+ sub r1, r1, #8
2696+ ldr r1, [r1]
2697+
2698+ @ write r1 to current_thread_info()->cpu_domain
2699+ mov r0, sp
2700+ @ assume 8K pages, since we have to split the immediate in two
2701+ bic r0, r0, #(0x1fc0)
2702+ bic r0, r0, #(0x3f)
2703+ str r1, [r0, #TI_CPU_DOMAIN]
2704+ @ write r1 to DACR
2705+ mcr p15, 0, r1, c3, c0, 0
2706+ @ instruction sync
2707+ instr_sync
2708+ @ restore regs
2709+ ldmia sp!, {r0, r1}
2710+#endif
2711+ .endm
2712+
2713 #ifndef CONFIG_THUMB2_KERNEL
2714 .macro svc_exit, rpsr, irq = 0
2715 .if \irq != 0
2716@@ -203,6 +257,9 @@
2717 blne trace_hardirqs_off
2718 #endif
2719 .endif
2720+
2721+ pax_exit_kernel
2722+
2723 msr spsr_cxsf, \rpsr
2724 #if defined(CONFIG_CPU_V6)
2725 ldr r0, [sp]
2726@@ -266,6 +323,9 @@
2727 blne trace_hardirqs_off
2728 #endif
2729 .endif
2730+
2731+ pax_exit_kernel
2732+
2733 ldr lr, [sp, #S_SP] @ top of the stack
2734 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2735 clrex @ clear the exclusive monitor
2736diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2737index 918875d..cd5fa27 100644
2738--- a/arch/arm/kernel/fiq.c
2739+++ b/arch/arm/kernel/fiq.c
2740@@ -87,7 +87,10 @@ void set_fiq_handler(void *start, unsigned int length)
2741 void *base = vectors_page;
2742 unsigned offset = FIQ_OFFSET;
2743
2744+ pax_open_kernel();
2745 memcpy(base + offset, start, length);
2746+ pax_close_kernel();
2747+
2748 if (!cache_is_vipt_nonaliasing())
2749 flush_icache_range((unsigned long)base + offset, offset +
2750 length);
2751diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2752index f5f381d..a6f36a1 100644
2753--- a/arch/arm/kernel/head.S
2754+++ b/arch/arm/kernel/head.S
2755@@ -437,7 +437,7 @@ __enable_mmu:
2756 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2757 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2758 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2759- domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2760+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2761 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2762 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2763 #endif
2764diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2765index 45e4781..8eac93d 100644
2766--- a/arch/arm/kernel/module.c
2767+++ b/arch/arm/kernel/module.c
2768@@ -38,12 +38,39 @@
2769 #endif
2770
2771 #ifdef CONFIG_MMU
2772-void *module_alloc(unsigned long size)
2773+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2774 {
2775+ if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2776+ return NULL;
2777 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2778- GFP_KERNEL, PAGE_KERNEL_EXEC, NUMA_NO_NODE,
2779+ GFP_KERNEL, prot, NUMA_NO_NODE,
2780 __builtin_return_address(0));
2781 }
2782+
2783+void *module_alloc(unsigned long size)
2784+{
2785+
2786+#ifdef CONFIG_PAX_KERNEXEC
2787+ return __module_alloc(size, PAGE_KERNEL);
2788+#else
2789+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2790+#endif
2791+
2792+}
2793+
2794+#ifdef CONFIG_PAX_KERNEXEC
2795+void module_free_exec(struct module *mod, void *module_region)
2796+{
2797+ module_free(mod, module_region);
2798+}
2799+EXPORT_SYMBOL(module_free_exec);
2800+
2801+void *module_alloc_exec(unsigned long size)
2802+{
2803+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2804+}
2805+EXPORT_SYMBOL(module_alloc_exec);
2806+#endif
2807 #endif
2808
2809 int
2810diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2811index 07314af..c46655c 100644
2812--- a/arch/arm/kernel/patch.c
2813+++ b/arch/arm/kernel/patch.c
2814@@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2815 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2816 int size;
2817
2818+ pax_open_kernel();
2819 if (thumb2 && __opcode_is_thumb16(insn)) {
2820 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2821 size = sizeof(u16);
2822@@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2823 *(u32 *)addr = insn;
2824 size = sizeof(u32);
2825 }
2826+ pax_close_kernel();
2827
2828 flush_icache_range((uintptr_t)(addr),
2829 (uintptr_t)(addr) + size);
2830diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2831index 92f7b15..7048500 100644
2832--- a/arch/arm/kernel/process.c
2833+++ b/arch/arm/kernel/process.c
2834@@ -217,6 +217,7 @@ void machine_power_off(void)
2835
2836 if (pm_power_off)
2837 pm_power_off();
2838+ BUG();
2839 }
2840
2841 /*
2842@@ -230,7 +231,7 @@ void machine_power_off(void)
2843 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2844 * to use. Implementing such co-ordination would be essentially impossible.
2845 */
2846-void machine_restart(char *cmd)
2847+__noreturn void machine_restart(char *cmd)
2848 {
2849 local_irq_disable();
2850 smp_send_stop();
2851@@ -253,8 +254,8 @@ void __show_regs(struct pt_regs *regs)
2852
2853 show_regs_print_info(KERN_DEFAULT);
2854
2855- print_symbol("PC is at %s\n", instruction_pointer(regs));
2856- print_symbol("LR is at %s\n", regs->ARM_lr);
2857+ printk("PC is at %pA\n", (void *)instruction_pointer(regs));
2858+ printk("LR is at %pA\n", (void *)regs->ARM_lr);
2859 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2860 "sp : %08lx ip : %08lx fp : %08lx\n",
2861 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2862@@ -425,12 +426,6 @@ unsigned long get_wchan(struct task_struct *p)
2863 return 0;
2864 }
2865
2866-unsigned long arch_randomize_brk(struct mm_struct *mm)
2867-{
2868- unsigned long range_end = mm->brk + 0x02000000;
2869- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2870-}
2871-
2872 #ifdef CONFIG_MMU
2873 #ifdef CONFIG_KUSER_HELPERS
2874 /*
2875@@ -446,7 +441,7 @@ static struct vm_area_struct gate_vma = {
2876
2877 static int __init gate_vma_init(void)
2878 {
2879- gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2880+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2881 return 0;
2882 }
2883 arch_initcall(gate_vma_init);
2884@@ -472,41 +467,16 @@ int in_gate_area_no_mm(unsigned long addr)
2885
2886 const char *arch_vma_name(struct vm_area_struct *vma)
2887 {
2888- return is_gate_vma(vma) ? "[vectors]" :
2889- (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
2890- "[sigpage]" : NULL;
2891+ return is_gate_vma(vma) ? "[vectors]" : NULL;
2892 }
2893
2894-static struct page *signal_page;
2895-extern struct page *get_signal_page(void);
2896-
2897 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2898 {
2899 struct mm_struct *mm = current->mm;
2900- unsigned long addr;
2901- int ret;
2902-
2903- if (!signal_page)
2904- signal_page = get_signal_page();
2905- if (!signal_page)
2906- return -ENOMEM;
2907
2908 down_write(&mm->mmap_sem);
2909- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
2910- if (IS_ERR_VALUE(addr)) {
2911- ret = addr;
2912- goto up_fail;
2913- }
2914-
2915- ret = install_special_mapping(mm, addr, PAGE_SIZE,
2916- VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
2917- &signal_page);
2918-
2919- if (ret == 0)
2920- mm->context.sigpage = addr;
2921-
2922- up_fail:
2923+ mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
2924 up_write(&mm->mmap_sem);
2925- return ret;
2926+ return 0;
2927 }
2928 #endif
2929diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
2930index 4693188..4596c5e 100644
2931--- a/arch/arm/kernel/psci.c
2932+++ b/arch/arm/kernel/psci.c
2933@@ -24,7 +24,7 @@
2934 #include <asm/opcodes-virt.h>
2935 #include <asm/psci.h>
2936
2937-struct psci_operations psci_ops;
2938+struct psci_operations psci_ops __read_only;
2939
2940 static int (*invoke_psci_fn)(u32, u32, u32, u32);
2941
2942diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2943index 0dd3b79..e018f64 100644
2944--- a/arch/arm/kernel/ptrace.c
2945+++ b/arch/arm/kernel/ptrace.c
2946@@ -929,10 +929,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2947 return current_thread_info()->syscall;
2948 }
2949
2950+#ifdef CONFIG_GRKERNSEC_SETXID
2951+extern void gr_delayed_cred_worker(void);
2952+#endif
2953+
2954 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2955 {
2956 current_thread_info()->syscall = scno;
2957
2958+#ifdef CONFIG_GRKERNSEC_SETXID
2959+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2960+ gr_delayed_cred_worker();
2961+#endif
2962+
2963 /* Do the secure computing check first; failures should be fast. */
2964 if (secure_computing(scno) == -1)
2965 return -1;
2966diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2967index 1e8b030..37c3022 100644
2968--- a/arch/arm/kernel/setup.c
2969+++ b/arch/arm/kernel/setup.c
2970@@ -100,21 +100,23 @@ EXPORT_SYMBOL(system_serial_high);
2971 unsigned int elf_hwcap __read_mostly;
2972 EXPORT_SYMBOL(elf_hwcap);
2973
2974+pteval_t __supported_pte_mask __read_only;
2975+pmdval_t __supported_pmd_mask __read_only;
2976
2977 #ifdef MULTI_CPU
2978-struct processor processor __read_mostly;
2979+struct processor processor __read_only;
2980 #endif
2981 #ifdef MULTI_TLB
2982-struct cpu_tlb_fns cpu_tlb __read_mostly;
2983+struct cpu_tlb_fns cpu_tlb __read_only;
2984 #endif
2985 #ifdef MULTI_USER
2986-struct cpu_user_fns cpu_user __read_mostly;
2987+struct cpu_user_fns cpu_user __read_only;
2988 #endif
2989 #ifdef MULTI_CACHE
2990-struct cpu_cache_fns cpu_cache __read_mostly;
2991+struct cpu_cache_fns cpu_cache __read_only;
2992 #endif
2993 #ifdef CONFIG_OUTER_CACHE
2994-struct outer_cache_fns outer_cache __read_mostly;
2995+struct outer_cache_fns outer_cache __read_only;
2996 EXPORT_SYMBOL(outer_cache);
2997 #endif
2998
2999@@ -247,9 +249,13 @@ static int __get_cpu_architecture(void)
3000 asm("mrc p15, 0, %0, c0, c1, 4"
3001 : "=r" (mmfr0));
3002 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3003- (mmfr0 & 0x000000f0) >= 0x00000030)
3004+ (mmfr0 & 0x000000f0) >= 0x00000030) {
3005 cpu_arch = CPU_ARCH_ARMv7;
3006- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3007+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3008+ __supported_pte_mask |= L_PTE_PXN;
3009+ __supported_pmd_mask |= PMD_PXNTABLE;
3010+ }
3011+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3012 (mmfr0 & 0x000000f0) == 0x00000020)
3013 cpu_arch = CPU_ARCH_ARMv6;
3014 else
3015diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3016index 04d6388..5115238 100644
3017--- a/arch/arm/kernel/signal.c
3018+++ b/arch/arm/kernel/signal.c
3019@@ -23,8 +23,6 @@
3020
3021 extern const unsigned long sigreturn_codes[7];
3022
3023-static unsigned long signal_return_offset;
3024-
3025 #ifdef CONFIG_CRUNCH
3026 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3027 {
3028@@ -395,8 +393,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3029 * except when the MPU has protected the vectors
3030 * page from PL0
3031 */
3032- retcode = mm->context.sigpage + signal_return_offset +
3033- (idx << 2) + thumb;
3034+ retcode = mm->context.sigpage + (idx << 2) + thumb;
3035 } else
3036 #endif
3037 {
3038@@ -600,33 +597,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3039 } while (thread_flags & _TIF_WORK_MASK);
3040 return 0;
3041 }
3042-
3043-struct page *get_signal_page(void)
3044-{
3045- unsigned long ptr;
3046- unsigned offset;
3047- struct page *page;
3048- void *addr;
3049-
3050- page = alloc_pages(GFP_KERNEL, 0);
3051-
3052- if (!page)
3053- return NULL;
3054-
3055- addr = page_address(page);
3056-
3057- /* Give the signal return code some randomness */
3058- offset = 0x200 + (get_random_int() & 0x7fc);
3059- signal_return_offset = offset;
3060-
3061- /*
3062- * Copy signal return handlers into the vector page, and
3063- * set sigreturn to be a pointer to these.
3064- */
3065- memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3066-
3067- ptr = (unsigned long)addr + offset;
3068- flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3069-
3070- return page;
3071-}
3072diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3073index b7b4c86..47c4f77 100644
3074--- a/arch/arm/kernel/smp.c
3075+++ b/arch/arm/kernel/smp.c
3076@@ -73,7 +73,7 @@ enum ipi_msg_type {
3077
3078 static DECLARE_COMPLETION(cpu_running);
3079
3080-static struct smp_operations smp_ops;
3081+static struct smp_operations smp_ops __read_only;
3082
3083 void __init smp_set_ops(struct smp_operations *ops)
3084 {
3085diff --git a/arch/arm/kernel/tcm.c b/arch/arm/kernel/tcm.c
3086index 7a3be1d..b00c7de 100644
3087--- a/arch/arm/kernel/tcm.c
3088+++ b/arch/arm/kernel/tcm.c
3089@@ -61,7 +61,7 @@ static struct map_desc itcm_iomap[] __initdata = {
3090 .virtual = ITCM_OFFSET,
3091 .pfn = __phys_to_pfn(ITCM_OFFSET),
3092 .length = 0,
3093- .type = MT_MEMORY_RWX_ITCM,
3094+ .type = MT_MEMORY_RX_ITCM,
3095 }
3096 };
3097
3098@@ -267,7 +267,9 @@ no_dtcm:
3099 start = &__sitcm_text;
3100 end = &__eitcm_text;
3101 ram = &__itcm_start;
3102+ pax_open_kernel();
3103 memcpy(start, ram, itcm_code_sz);
3104+ pax_close_kernel();
3105 pr_debug("CPU ITCM: copied code from %p - %p\n",
3106 start, end);
3107 itcm_present = true;
3108diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3109index 172ee18..ce4ec3d 100644
3110--- a/arch/arm/kernel/traps.c
3111+++ b/arch/arm/kernel/traps.c
3112@@ -62,7 +62,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3113 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3114 {
3115 #ifdef CONFIG_KALLSYMS
3116- printk("[<%08lx>] (%ps) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3117+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3118 #else
3119 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3120 #endif
3121@@ -264,6 +264,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3122 static int die_owner = -1;
3123 static unsigned int die_nest_count;
3124
3125+extern void gr_handle_kernel_exploit(void);
3126+
3127 static unsigned long oops_begin(void)
3128 {
3129 int cpu;
3130@@ -306,6 +308,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3131 panic("Fatal exception in interrupt");
3132 if (panic_on_oops)
3133 panic("Fatal exception");
3134+
3135+ gr_handle_kernel_exploit();
3136+
3137 if (signr)
3138 do_exit(signr);
3139 }
3140@@ -642,7 +647,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3141 * The user helper at 0xffff0fe0 must be used instead.
3142 * (see entry-armv.S for details)
3143 */
3144+ pax_open_kernel();
3145 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3146+ pax_close_kernel();
3147 }
3148 return 0;
3149
3150@@ -899,7 +906,11 @@ void __init early_trap_init(void *vectors_base)
3151 kuser_init(vectors_base);
3152
3153 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3154- modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3155+
3156+#ifndef CONFIG_PAX_MEMORY_UDEREF
3157+ modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3158+#endif
3159+
3160 #else /* ifndef CONFIG_CPU_V7M */
3161 /*
3162 * on V7-M there is no need to copy the vector table to a dedicated
3163diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3164index 7bcee5c..e2f3249 100644
3165--- a/arch/arm/kernel/vmlinux.lds.S
3166+++ b/arch/arm/kernel/vmlinux.lds.S
3167@@ -8,7 +8,11 @@
3168 #include <asm/thread_info.h>
3169 #include <asm/memory.h>
3170 #include <asm/page.h>
3171-
3172+
3173+#ifdef CONFIG_PAX_KERNEXEC
3174+#include <asm/pgtable.h>
3175+#endif
3176+
3177 #define PROC_INFO \
3178 . = ALIGN(4); \
3179 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3180@@ -34,7 +38,7 @@
3181 #endif
3182
3183 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3184- defined(CONFIG_GENERIC_BUG)
3185+ defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3186 #define ARM_EXIT_KEEP(x) x
3187 #define ARM_EXIT_DISCARD(x)
3188 #else
3189@@ -90,6 +94,11 @@ SECTIONS
3190 _text = .;
3191 HEAD_TEXT
3192 }
3193+
3194+#ifdef CONFIG_PAX_KERNEXEC
3195+ . = ALIGN(1<<SECTION_SHIFT);
3196+#endif
3197+
3198 .text : { /* Real text segment */
3199 _stext = .; /* Text and read-only data */
3200 __exception_text_start = .;
3201@@ -112,6 +121,8 @@ SECTIONS
3202 ARM_CPU_KEEP(PROC_INFO)
3203 }
3204
3205+ _etext = .; /* End of text section */
3206+
3207 RO_DATA(PAGE_SIZE)
3208
3209 . = ALIGN(4);
3210@@ -142,7 +153,9 @@ SECTIONS
3211
3212 NOTES
3213
3214- _etext = .; /* End of text and rodata section */
3215+#ifdef CONFIG_PAX_KERNEXEC
3216+ . = ALIGN(1<<SECTION_SHIFT);
3217+#endif
3218
3219 #ifndef CONFIG_XIP_KERNEL
3220 . = ALIGN(PAGE_SIZE);
3221@@ -220,6 +233,11 @@ SECTIONS
3222 . = PAGE_OFFSET + TEXT_OFFSET;
3223 #else
3224 __init_end = .;
3225+
3226+#ifdef CONFIG_PAX_KERNEXEC
3227+ . = ALIGN(1<<SECTION_SHIFT);
3228+#endif
3229+
3230 . = ALIGN(THREAD_SIZE);
3231 __data_loc = .;
3232 #endif
3233diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3234index bd18bb8..87ede26 100644
3235--- a/arch/arm/kvm/arm.c
3236+++ b/arch/arm/kvm/arm.c
3237@@ -57,7 +57,7 @@ static unsigned long hyp_default_vectors;
3238 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3239
3240 /* The VMID used in the VTTBR */
3241-static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3242+static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3243 static u8 kvm_next_vmid;
3244 static DEFINE_SPINLOCK(kvm_vmid_lock);
3245
3246@@ -408,7 +408,7 @@ void force_vm_exit(const cpumask_t *mask)
3247 */
3248 static bool need_new_vmid_gen(struct kvm *kvm)
3249 {
3250- return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3251+ return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3252 }
3253
3254 /**
3255@@ -441,7 +441,7 @@ static void update_vttbr(struct kvm *kvm)
3256
3257 /* First user of a new VMID generation? */
3258 if (unlikely(kvm_next_vmid == 0)) {
3259- atomic64_inc(&kvm_vmid_gen);
3260+ atomic64_inc_unchecked(&kvm_vmid_gen);
3261 kvm_next_vmid = 1;
3262
3263 /*
3264@@ -458,7 +458,7 @@ static void update_vttbr(struct kvm *kvm)
3265 kvm_call_hyp(__kvm_flush_vm_context);
3266 }
3267
3268- kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3269+ kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3270 kvm->arch.vmid = kvm_next_vmid;
3271 kvm_next_vmid++;
3272
3273diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3274index 14a0d98..7771a7d 100644
3275--- a/arch/arm/lib/clear_user.S
3276+++ b/arch/arm/lib/clear_user.S
3277@@ -12,14 +12,14 @@
3278
3279 .text
3280
3281-/* Prototype: int __clear_user(void *addr, size_t sz)
3282+/* Prototype: int ___clear_user(void *addr, size_t sz)
3283 * Purpose : clear some user memory
3284 * Params : addr - user memory address to clear
3285 * : sz - number of bytes to clear
3286 * Returns : number of bytes NOT cleared
3287 */
3288 ENTRY(__clear_user_std)
3289-WEAK(__clear_user)
3290+WEAK(___clear_user)
3291 stmfd sp!, {r1, lr}
3292 mov r2, #0
3293 cmp r1, #4
3294@@ -44,7 +44,7 @@ WEAK(__clear_user)
3295 USER( strnebt r2, [r0])
3296 mov r0, #0
3297 ldmfd sp!, {r1, pc}
3298-ENDPROC(__clear_user)
3299+ENDPROC(___clear_user)
3300 ENDPROC(__clear_user_std)
3301
3302 .pushsection .fixup,"ax"
3303diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3304index 66a477a..bee61d3 100644
3305--- a/arch/arm/lib/copy_from_user.S
3306+++ b/arch/arm/lib/copy_from_user.S
3307@@ -16,7 +16,7 @@
3308 /*
3309 * Prototype:
3310 *
3311- * size_t __copy_from_user(void *to, const void *from, size_t n)
3312+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
3313 *
3314 * Purpose:
3315 *
3316@@ -84,11 +84,11 @@
3317
3318 .text
3319
3320-ENTRY(__copy_from_user)
3321+ENTRY(___copy_from_user)
3322
3323 #include "copy_template.S"
3324
3325-ENDPROC(__copy_from_user)
3326+ENDPROC(___copy_from_user)
3327
3328 .pushsection .fixup,"ax"
3329 .align 0
3330diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3331index 6ee2f67..d1cce76 100644
3332--- a/arch/arm/lib/copy_page.S
3333+++ b/arch/arm/lib/copy_page.S
3334@@ -10,6 +10,7 @@
3335 * ASM optimised string functions
3336 */
3337 #include <linux/linkage.h>
3338+#include <linux/const.h>
3339 #include <asm/assembler.h>
3340 #include <asm/asm-offsets.h>
3341 #include <asm/cache.h>
3342diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3343index d066df6..df28194 100644
3344--- a/arch/arm/lib/copy_to_user.S
3345+++ b/arch/arm/lib/copy_to_user.S
3346@@ -16,7 +16,7 @@
3347 /*
3348 * Prototype:
3349 *
3350- * size_t __copy_to_user(void *to, const void *from, size_t n)
3351+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
3352 *
3353 * Purpose:
3354 *
3355@@ -88,11 +88,11 @@
3356 .text
3357
3358 ENTRY(__copy_to_user_std)
3359-WEAK(__copy_to_user)
3360+WEAK(___copy_to_user)
3361
3362 #include "copy_template.S"
3363
3364-ENDPROC(__copy_to_user)
3365+ENDPROC(___copy_to_user)
3366 ENDPROC(__copy_to_user_std)
3367
3368 .pushsection .fixup,"ax"
3369diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3370index 7d08b43..f7ca7ea 100644
3371--- a/arch/arm/lib/csumpartialcopyuser.S
3372+++ b/arch/arm/lib/csumpartialcopyuser.S
3373@@ -57,8 +57,8 @@
3374 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3375 */
3376
3377-#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3378-#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3379+#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3380+#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3381
3382 #include "csumpartialcopygeneric.S"
3383
3384diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3385index 5306de3..aed6d03 100644
3386--- a/arch/arm/lib/delay.c
3387+++ b/arch/arm/lib/delay.c
3388@@ -28,7 +28,7 @@
3389 /*
3390 * Default to the loop-based delay implementation.
3391 */
3392-struct arm_delay_ops arm_delay_ops = {
3393+struct arm_delay_ops arm_delay_ops __read_only = {
3394 .delay = __loop_delay,
3395 .const_udelay = __loop_const_udelay,
3396 .udelay = __loop_udelay,
3397diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3398index 3e58d71..029817c 100644
3399--- a/arch/arm/lib/uaccess_with_memcpy.c
3400+++ b/arch/arm/lib/uaccess_with_memcpy.c
3401@@ -136,7 +136,7 @@ out:
3402 }
3403
3404 unsigned long
3405-__copy_to_user(void __user *to, const void *from, unsigned long n)
3406+___copy_to_user(void __user *to, const void *from, unsigned long n)
3407 {
3408 /*
3409 * This test is stubbed out of the main function above to keep
3410@@ -190,7 +190,7 @@ out:
3411 return n;
3412 }
3413
3414-unsigned long __clear_user(void __user *addr, unsigned long n)
3415+unsigned long ___clear_user(void __user *addr, unsigned long n)
3416 {
3417 /* See rational for this in __copy_to_user() above. */
3418 if (n < 64)
3419diff --git a/arch/arm/mach-at91/setup.c b/arch/arm/mach-at91/setup.c
3420index f7ca97b..3d7e719 100644
3421--- a/arch/arm/mach-at91/setup.c
3422+++ b/arch/arm/mach-at91/setup.c
3423@@ -81,7 +81,7 @@ void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
3424
3425 desc->pfn = __phys_to_pfn(base);
3426 desc->length = length;
3427- desc->type = MT_MEMORY_RWX_NONCACHED;
3428+ desc->type = MT_MEMORY_RW_NONCACHED;
3429
3430 pr_info("AT91: sram at 0x%lx of 0x%x mapped at 0x%lx\n",
3431 base, length, desc->virtual);
3432diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3433index f3407a5..bd4256f 100644
3434--- a/arch/arm/mach-kirkwood/common.c
3435+++ b/arch/arm/mach-kirkwood/common.c
3436@@ -156,7 +156,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3437 clk_gate_ops.disable(hw);
3438 }
3439
3440-static struct clk_ops clk_gate_fn_ops;
3441+static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3442+{
3443+ return clk_gate_ops.is_enabled(hw);
3444+}
3445+
3446+static struct clk_ops clk_gate_fn_ops = {
3447+ .enable = clk_gate_fn_enable,
3448+ .disable = clk_gate_fn_disable,
3449+ .is_enabled = clk_gate_fn_is_enabled,
3450+};
3451
3452 static struct clk __init *clk_register_gate_fn(struct device *dev,
3453 const char *name,
3454@@ -190,14 +199,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3455 gate_fn->fn_en = fn_en;
3456 gate_fn->fn_dis = fn_dis;
3457
3458- /* ops is the gate ops, but with our enable/disable functions */
3459- if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3460- clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3461- clk_gate_fn_ops = clk_gate_ops;
3462- clk_gate_fn_ops.enable = clk_gate_fn_enable;
3463- clk_gate_fn_ops.disable = clk_gate_fn_disable;
3464- }
3465-
3466 clk = clk_register(dev, &gate_fn->gate.hw);
3467
3468 if (IS_ERR(clk))
3469diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3470index aead77a..a2253fa 100644
3471--- a/arch/arm/mach-omap2/board-n8x0.c
3472+++ b/arch/arm/mach-omap2/board-n8x0.c
3473@@ -568,7 +568,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3474 }
3475 #endif
3476
3477-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3478+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3479 .late_init = n8x0_menelaus_late_init,
3480 };
3481
3482diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3483index ab43755..ccfa231 100644
3484--- a/arch/arm/mach-omap2/gpmc.c
3485+++ b/arch/arm/mach-omap2/gpmc.c
3486@@ -148,7 +148,6 @@ struct omap3_gpmc_regs {
3487 };
3488
3489 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3490-static struct irq_chip gpmc_irq_chip;
3491 static int gpmc_irq_start;
3492
3493 static struct resource gpmc_mem_root;
3494@@ -716,6 +715,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3495
3496 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3497
3498+static struct irq_chip gpmc_irq_chip = {
3499+ .name = "gpmc",
3500+ .irq_startup = gpmc_irq_noop_ret,
3501+ .irq_enable = gpmc_irq_enable,
3502+ .irq_disable = gpmc_irq_disable,
3503+ .irq_shutdown = gpmc_irq_noop,
3504+ .irq_ack = gpmc_irq_noop,
3505+ .irq_mask = gpmc_irq_noop,
3506+ .irq_unmask = gpmc_irq_noop,
3507+
3508+};
3509+
3510 static int gpmc_setup_irq(void)
3511 {
3512 int i;
3513@@ -730,15 +741,6 @@ static int gpmc_setup_irq(void)
3514 return gpmc_irq_start;
3515 }
3516
3517- gpmc_irq_chip.name = "gpmc";
3518- gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3519- gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3520- gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3521- gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3522- gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3523- gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3524- gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3525-
3526 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3527 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3528
3529diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3530index 667915d..2ee1219 100644
3531--- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3532+++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3533@@ -84,7 +84,7 @@ struct cpu_pm_ops {
3534 int (*finish_suspend)(unsigned long cpu_state);
3535 void (*resume)(void);
3536 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3537-};
3538+} __no_const;
3539
3540 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3541 static struct powerdomain *mpuss_pd;
3542@@ -102,7 +102,7 @@ static void dummy_cpu_resume(void)
3543 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3544 {}
3545
3546-struct cpu_pm_ops omap_pm_ops = {
3547+static struct cpu_pm_ops omap_pm_ops __read_only = {
3548 .finish_suspend = default_finish_suspend,
3549 .resume = dummy_cpu_resume,
3550 .scu_prepare = dummy_scu_prepare,
3551diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3552index 3664562..72f85c6 100644
3553--- a/arch/arm/mach-omap2/omap-wakeupgen.c
3554+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3555@@ -343,7 +343,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3556 return NOTIFY_OK;
3557 }
3558
3559-static struct notifier_block __refdata irq_hotplug_notifier = {
3560+static struct notifier_block irq_hotplug_notifier = {
3561 .notifier_call = irq_cpu_hotplug_notify,
3562 };
3563
3564diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3565index 01ef59d..32ae28a8 100644
3566--- a/arch/arm/mach-omap2/omap_device.c
3567+++ b/arch/arm/mach-omap2/omap_device.c
3568@@ -510,7 +510,7 @@ void omap_device_delete(struct omap_device *od)
3569 struct platform_device __init *omap_device_build(const char *pdev_name,
3570 int pdev_id,
3571 struct omap_hwmod *oh,
3572- void *pdata, int pdata_len)
3573+ const void *pdata, int pdata_len)
3574 {
3575 struct omap_hwmod *ohs[] = { oh };
3576
3577@@ -538,7 +538,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3578 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3579 int pdev_id,
3580 struct omap_hwmod **ohs,
3581- int oh_cnt, void *pdata,
3582+ int oh_cnt, const void *pdata,
3583 int pdata_len)
3584 {
3585 int ret = -ENOMEM;
3586diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3587index 78c02b3..c94109a 100644
3588--- a/arch/arm/mach-omap2/omap_device.h
3589+++ b/arch/arm/mach-omap2/omap_device.h
3590@@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
3591 /* Core code interface */
3592
3593 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3594- struct omap_hwmod *oh, void *pdata,
3595+ struct omap_hwmod *oh, const void *pdata,
3596 int pdata_len);
3597
3598 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3599 struct omap_hwmod **oh, int oh_cnt,
3600- void *pdata, int pdata_len);
3601+ const void *pdata, int pdata_len);
3602
3603 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3604 struct omap_hwmod **ohs, int oh_cnt);
3605diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3606index 66c60fe..c78950d 100644
3607--- a/arch/arm/mach-omap2/omap_hwmod.c
3608+++ b/arch/arm/mach-omap2/omap_hwmod.c
3609@@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3610 int (*init_clkdm)(struct omap_hwmod *oh);
3611 void (*update_context_lost)(struct omap_hwmod *oh);
3612 int (*get_context_lost)(struct omap_hwmod *oh);
3613-};
3614+} __no_const;
3615
3616 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3617-static struct omap_hwmod_soc_ops soc_ops;
3618+static struct omap_hwmod_soc_ops soc_ops __read_only;
3619
3620 /* omap_hwmod_list contains all registered struct omap_hwmods */
3621 static LIST_HEAD(omap_hwmod_list);
3622diff --git a/arch/arm/mach-omap2/powerdomains43xx_data.c b/arch/arm/mach-omap2/powerdomains43xx_data.c
3623index 95fee54..cfa9cf1 100644
3624--- a/arch/arm/mach-omap2/powerdomains43xx_data.c
3625+++ b/arch/arm/mach-omap2/powerdomains43xx_data.c
3626@@ -10,6 +10,7 @@
3627
3628 #include <linux/kernel.h>
3629 #include <linux/init.h>
3630+#include <asm/pgtable.h>
3631
3632 #include "powerdomain.h"
3633
3634@@ -129,7 +130,9 @@ static int am43xx_check_vcvp(void)
3635
3636 void __init am43xx_powerdomains_init(void)
3637 {
3638- omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3639+ pax_open_kernel();
3640+ *(void **)&omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3641+ pax_close_kernel();
3642 pwrdm_register_platform_funcs(&omap4_pwrdm_operations);
3643 pwrdm_register_pwrdms(powerdomains_am43xx);
3644 pwrdm_complete_init();
3645diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3646index d15c7bb..b2d1f0c 100644
3647--- a/arch/arm/mach-omap2/wd_timer.c
3648+++ b/arch/arm/mach-omap2/wd_timer.c
3649@@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3650 struct omap_hwmod *oh;
3651 char *oh_name = "wd_timer2";
3652 char *dev_name = "omap_wdt";
3653- struct omap_wd_timer_platform_data pdata;
3654+ static struct omap_wd_timer_platform_data pdata = {
3655+ .read_reset_sources = prm_read_reset_sources
3656+ };
3657
3658 if (!cpu_class_is_omap2() || of_have_populated_dt())
3659 return 0;
3660@@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3661 return -EINVAL;
3662 }
3663
3664- pdata.read_reset_sources = prm_read_reset_sources;
3665-
3666 pdev = omap_device_build(dev_name, id, oh, &pdata,
3667 sizeof(struct omap_wd_timer_platform_data));
3668 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3669diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3670index b82dcae..44ee5b6 100644
3671--- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3672+++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3673@@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3674 bool entered_lp2 = false;
3675
3676 if (tegra_pending_sgi())
3677- ACCESS_ONCE(abort_flag) = true;
3678+ ACCESS_ONCE_RW(abort_flag) = true;
3679
3680 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3681
3682diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3683index 2dea8b5..6499da2 100644
3684--- a/arch/arm/mach-ux500/setup.h
3685+++ b/arch/arm/mach-ux500/setup.h
3686@@ -33,13 +33,6 @@ extern void ux500_timer_init(void);
3687 .type = MT_DEVICE, \
3688 }
3689
3690-#define __MEM_DEV_DESC(x, sz) { \
3691- .virtual = IO_ADDRESS(x), \
3692- .pfn = __phys_to_pfn(x), \
3693- .length = sz, \
3694- .type = MT_MEMORY_RWX, \
3695-}
3696-
3697 extern struct smp_operations ux500_smp_ops;
3698 extern void ux500_cpu_die(unsigned int cpu);
3699
3700diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3701index ca8ecde..58ba893 100644
3702--- a/arch/arm/mm/Kconfig
3703+++ b/arch/arm/mm/Kconfig
3704@@ -446,6 +446,7 @@ config CPU_32v5
3705
3706 config CPU_32v6
3707 bool
3708+ select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3709 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3710
3711 config CPU_32v6K
3712@@ -600,6 +601,7 @@ config CPU_CP15_MPU
3713
3714 config CPU_USE_DOMAINS
3715 bool
3716+ depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3717 help
3718 This option enables or disables the use of domain switching
3719 via the set_fs() function.
3720@@ -799,6 +801,7 @@ config NEED_KUSER_HELPERS
3721 config KUSER_HELPERS
3722 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3723 default y
3724+ depends on !(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND
3725 help
3726 Warning: disabling this option may break user programs.
3727
3728@@ -811,7 +814,7 @@ config KUSER_HELPERS
3729 See Documentation/arm/kernel_user_helpers.txt for details.
3730
3731 However, the fixed address nature of these helpers can be used
3732- by ROP (return orientated programming) authors when creating
3733+ by ROP (Return Oriented Programming) authors when creating
3734 exploits.
3735
3736 If all of the binaries and libraries which run on your platform
3737diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3738index 9240364..a2b8cf3 100644
3739--- a/arch/arm/mm/alignment.c
3740+++ b/arch/arm/mm/alignment.c
3741@@ -212,10 +212,12 @@ union offset_union {
3742 #define __get16_unaligned_check(ins,val,addr) \
3743 do { \
3744 unsigned int err = 0, v, a = addr; \
3745+ pax_open_userland(); \
3746 __get8_unaligned_check(ins,v,a,err); \
3747 val = v << ((BE) ? 8 : 0); \
3748 __get8_unaligned_check(ins,v,a,err); \
3749 val |= v << ((BE) ? 0 : 8); \
3750+ pax_close_userland(); \
3751 if (err) \
3752 goto fault; \
3753 } while (0)
3754@@ -229,6 +231,7 @@ union offset_union {
3755 #define __get32_unaligned_check(ins,val,addr) \
3756 do { \
3757 unsigned int err = 0, v, a = addr; \
3758+ pax_open_userland(); \
3759 __get8_unaligned_check(ins,v,a,err); \
3760 val = v << ((BE) ? 24 : 0); \
3761 __get8_unaligned_check(ins,v,a,err); \
3762@@ -237,6 +240,7 @@ union offset_union {
3763 val |= v << ((BE) ? 8 : 16); \
3764 __get8_unaligned_check(ins,v,a,err); \
3765 val |= v << ((BE) ? 0 : 24); \
3766+ pax_close_userland(); \
3767 if (err) \
3768 goto fault; \
3769 } while (0)
3770@@ -250,6 +254,7 @@ union offset_union {
3771 #define __put16_unaligned_check(ins,val,addr) \
3772 do { \
3773 unsigned int err = 0, v = val, a = addr; \
3774+ pax_open_userland(); \
3775 __asm__( FIRST_BYTE_16 \
3776 ARM( "1: "ins" %1, [%2], #1\n" ) \
3777 THUMB( "1: "ins" %1, [%2]\n" ) \
3778@@ -269,6 +274,7 @@ union offset_union {
3779 " .popsection\n" \
3780 : "=r" (err), "=&r" (v), "=&r" (a) \
3781 : "0" (err), "1" (v), "2" (a)); \
3782+ pax_close_userland(); \
3783 if (err) \
3784 goto fault; \
3785 } while (0)
3786@@ -282,6 +288,7 @@ union offset_union {
3787 #define __put32_unaligned_check(ins,val,addr) \
3788 do { \
3789 unsigned int err = 0, v = val, a = addr; \
3790+ pax_open_userland(); \
3791 __asm__( FIRST_BYTE_32 \
3792 ARM( "1: "ins" %1, [%2], #1\n" ) \
3793 THUMB( "1: "ins" %1, [%2]\n" ) \
3794@@ -311,6 +318,7 @@ union offset_union {
3795 " .popsection\n" \
3796 : "=r" (err), "=&r" (v), "=&r" (a) \
3797 : "0" (err), "1" (v), "2" (a)); \
3798+ pax_close_userland(); \
3799 if (err) \
3800 goto fault; \
3801 } while (0)
3802diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
3803index 7abde2c..9df495f 100644
3804--- a/arch/arm/mm/cache-l2x0.c
3805+++ b/arch/arm/mm/cache-l2x0.c
3806@@ -46,7 +46,7 @@ struct l2x0_of_data {
3807 void (*setup)(const struct device_node *, u32 *, u32 *);
3808 void (*save)(void);
3809 struct outer_cache_fns outer_cache;
3810-};
3811+} __do_const;
3812
3813 static bool of_init = false;
3814
3815diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3816index 6eb97b3..ac509f6 100644
3817--- a/arch/arm/mm/context.c
3818+++ b/arch/arm/mm/context.c
3819@@ -43,7 +43,7 @@
3820 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3821
3822 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3823-static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3824+static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3825 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3826
3827 static DEFINE_PER_CPU(atomic64_t, active_asids);
3828@@ -182,7 +182,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3829 {
3830 static u32 cur_idx = 1;
3831 u64 asid = atomic64_read(&mm->context.id);
3832- u64 generation = atomic64_read(&asid_generation);
3833+ u64 generation = atomic64_read_unchecked(&asid_generation);
3834
3835 if (asid != 0 && is_reserved_asid(asid)) {
3836 /*
3837@@ -203,7 +203,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3838 */
3839 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, cur_idx);
3840 if (asid == NUM_USER_ASIDS) {
3841- generation = atomic64_add_return(ASID_FIRST_VERSION,
3842+ generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
3843 &asid_generation);
3844 flush_context(cpu);
3845 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3846@@ -234,14 +234,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3847 cpu_set_reserved_ttbr0();
3848
3849 asid = atomic64_read(&mm->context.id);
3850- if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
3851+ if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
3852 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
3853 goto switch_mm_fastpath;
3854
3855 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
3856 /* Check that our ASID belongs to the current generation. */
3857 asid = atomic64_read(&mm->context.id);
3858- if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
3859+ if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
3860 asid = new_context(mm, cpu);
3861 atomic64_set(&mm->context.id, asid);
3862 }
3863diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3864index eb8830a..5360ce7 100644
3865--- a/arch/arm/mm/fault.c
3866+++ b/arch/arm/mm/fault.c
3867@@ -25,6 +25,7 @@
3868 #include <asm/system_misc.h>
3869 #include <asm/system_info.h>
3870 #include <asm/tlbflush.h>
3871+#include <asm/sections.h>
3872
3873 #include "fault.h"
3874
3875@@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3876 if (fixup_exception(regs))
3877 return;
3878
3879+#ifdef CONFIG_PAX_MEMORY_UDEREF
3880+ if (addr < TASK_SIZE) {
3881+ if (current->signal->curr_ip)
3882+ 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),
3883+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3884+ else
3885+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3886+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3887+ }
3888+#endif
3889+
3890+#ifdef CONFIG_PAX_KERNEXEC
3891+ if ((fsr & FSR_WRITE) &&
3892+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3893+ (MODULES_VADDR <= addr && addr < MODULES_END)))
3894+ {
3895+ if (current->signal->curr_ip)
3896+ 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),
3897+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3898+ else
3899+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3900+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3901+ }
3902+#endif
3903+
3904 /*
3905 * No handler, we'll have to terminate things with extreme prejudice.
3906 */
3907@@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3908 }
3909 #endif
3910
3911+#ifdef CONFIG_PAX_PAGEEXEC
3912+ if (fsr & FSR_LNX_PF) {
3913+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3914+ do_group_exit(SIGKILL);
3915+ }
3916+#endif
3917+
3918 tsk->thread.address = addr;
3919 tsk->thread.error_code = fsr;
3920 tsk->thread.trap_no = 14;
3921@@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3922 }
3923 #endif /* CONFIG_MMU */
3924
3925+#ifdef CONFIG_PAX_PAGEEXEC
3926+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3927+{
3928+ long i;
3929+
3930+ printk(KERN_ERR "PAX: bytes at PC: ");
3931+ for (i = 0; i < 20; i++) {
3932+ unsigned char c;
3933+ if (get_user(c, (__force unsigned char __user *)pc+i))
3934+ printk(KERN_CONT "?? ");
3935+ else
3936+ printk(KERN_CONT "%02x ", c);
3937+ }
3938+ printk("\n");
3939+
3940+ printk(KERN_ERR "PAX: bytes at SP-4: ");
3941+ for (i = -1; i < 20; i++) {
3942+ unsigned long c;
3943+ if (get_user(c, (__force unsigned long __user *)sp+i))
3944+ printk(KERN_CONT "???????? ");
3945+ else
3946+ printk(KERN_CONT "%08lx ", c);
3947+ }
3948+ printk("\n");
3949+}
3950+#endif
3951+
3952 /*
3953 * First Level Translation Fault Handler
3954 *
3955@@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3956 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3957 struct siginfo info;
3958
3959+#ifdef CONFIG_PAX_MEMORY_UDEREF
3960+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3961+ if (current->signal->curr_ip)
3962+ 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),
3963+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3964+ else
3965+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3966+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3967+ goto die;
3968+ }
3969+#endif
3970+
3971 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3972 return;
3973
3974+die:
3975 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3976 inf->name, fsr, addr);
3977
3978@@ -574,15 +647,98 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
3979 ifsr_info[nr].name = name;
3980 }
3981
3982+asmlinkage int sys_sigreturn(struct pt_regs *regs);
3983+asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
3984+
3985 asmlinkage void __exception
3986 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3987 {
3988 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3989 struct siginfo info;
3990+ unsigned long pc = instruction_pointer(regs);
3991+
3992+ if (user_mode(regs)) {
3993+ unsigned long sigpage = current->mm->context.sigpage;
3994+
3995+ if (sigpage <= pc && pc < sigpage + 7*4) {
3996+ if (pc < sigpage + 3*4)
3997+ sys_sigreturn(regs);
3998+ else
3999+ sys_rt_sigreturn(regs);
4000+ return;
4001+ }
4002+ if (pc == 0xffff0f60UL) {
4003+ /*
4004+ * PaX: __kuser_cmpxchg64 emulation
4005+ */
4006+ // TODO
4007+ //regs->ARM_pc = regs->ARM_lr;
4008+ //return;
4009+ }
4010+ if (pc == 0xffff0fa0UL) {
4011+ /*
4012+ * PaX: __kuser_memory_barrier emulation
4013+ */
4014+ // dmb(); implied by the exception
4015+ regs->ARM_pc = regs->ARM_lr;
4016+ return;
4017+ }
4018+ if (pc == 0xffff0fc0UL) {
4019+ /*
4020+ * PaX: __kuser_cmpxchg emulation
4021+ */
4022+ // TODO
4023+ //long new;
4024+ //int op;
4025+
4026+ //op = FUTEX_OP_SET << 28;
4027+ //new = futex_atomic_op_inuser(op, regs->ARM_r2);
4028+ //regs->ARM_r0 = old != new;
4029+ //regs->ARM_pc = regs->ARM_lr;
4030+ //return;
4031+ }
4032+ if (pc == 0xffff0fe0UL) {
4033+ /*
4034+ * PaX: __kuser_get_tls emulation
4035+ */
4036+ regs->ARM_r0 = current_thread_info()->tp_value[0];
4037+ regs->ARM_pc = regs->ARM_lr;
4038+ return;
4039+ }
4040+ }
4041+
4042+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4043+ else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
4044+ if (current->signal->curr_ip)
4045+ 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),
4046+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4047+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4048+ else
4049+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
4050+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4051+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4052+ goto die;
4053+ }
4054+#endif
4055+
4056+#ifdef CONFIG_PAX_REFCOUNT
4057+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
4058+ unsigned int bkpt;
4059+
4060+ if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
4061+ current->thread.error_code = ifsr;
4062+ current->thread.trap_no = 0;
4063+ pax_report_refcount_overflow(regs);
4064+ fixup_exception(regs);
4065+ return;
4066+ }
4067+ }
4068+#endif
4069
4070 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
4071 return;
4072
4073+die:
4074 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4075 inf->name, ifsr, addr);
4076
4077diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4078index cf08bdf..772656c 100644
4079--- a/arch/arm/mm/fault.h
4080+++ b/arch/arm/mm/fault.h
4081@@ -3,6 +3,7 @@
4082
4083 /*
4084 * Fault status register encodings. We steal bit 31 for our own purposes.
4085+ * Set when the FSR value is from an instruction fault.
4086 */
4087 #define FSR_LNX_PF (1 << 31)
4088 #define FSR_WRITE (1 << 11)
4089@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4090 }
4091 #endif
4092
4093+/* valid for LPAE and !LPAE */
4094+static inline int is_xn_fault(unsigned int fsr)
4095+{
4096+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
4097+}
4098+
4099+static inline int is_domain_fault(unsigned int fsr)
4100+{
4101+ return ((fsr_fs(fsr) & 0xD) == 0x9);
4102+}
4103+
4104 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4105 unsigned long search_exception_table(unsigned long addr);
4106
4107diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4108index 804d615..fcec50a 100644
4109--- a/arch/arm/mm/init.c
4110+++ b/arch/arm/mm/init.c
4111@@ -30,6 +30,8 @@
4112 #include <asm/setup.h>
4113 #include <asm/tlb.h>
4114 #include <asm/fixmap.h>
4115+#include <asm/system_info.h>
4116+#include <asm/cp15.h>
4117
4118 #include <asm/mach/arch.h>
4119 #include <asm/mach/map.h>
4120@@ -625,7 +627,46 @@ void free_initmem(void)
4121 {
4122 #ifdef CONFIG_HAVE_TCM
4123 extern char __tcm_start, __tcm_end;
4124+#endif
4125
4126+#ifdef CONFIG_PAX_KERNEXEC
4127+ unsigned long addr;
4128+ pgd_t *pgd;
4129+ pud_t *pud;
4130+ pmd_t *pmd;
4131+ int cpu_arch = cpu_architecture();
4132+ unsigned int cr = get_cr();
4133+
4134+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4135+ /* make pages tables, etc before .text NX */
4136+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4137+ pgd = pgd_offset_k(addr);
4138+ pud = pud_offset(pgd, addr);
4139+ pmd = pmd_offset(pud, addr);
4140+ __section_update(pmd, addr, PMD_SECT_XN);
4141+ }
4142+ /* make init NX */
4143+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4144+ pgd = pgd_offset_k(addr);
4145+ pud = pud_offset(pgd, addr);
4146+ pmd = pmd_offset(pud, addr);
4147+ __section_update(pmd, addr, PMD_SECT_XN);
4148+ }
4149+ /* make kernel code/rodata RX */
4150+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4151+ pgd = pgd_offset_k(addr);
4152+ pud = pud_offset(pgd, addr);
4153+ pmd = pmd_offset(pud, addr);
4154+#ifdef CONFIG_ARM_LPAE
4155+ __section_update(pmd, addr, PMD_SECT_RDONLY);
4156+#else
4157+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4158+#endif
4159+ }
4160+ }
4161+#endif
4162+
4163+#ifdef CONFIG_HAVE_TCM
4164 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4165 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4166 #endif
4167diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4168index f9c32ba..8540068 100644
4169--- a/arch/arm/mm/ioremap.c
4170+++ b/arch/arm/mm/ioremap.c
4171@@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4172 unsigned int mtype;
4173
4174 if (cached)
4175- mtype = MT_MEMORY_RWX;
4176+ mtype = MT_MEMORY_RX;
4177 else
4178- mtype = MT_MEMORY_RWX_NONCACHED;
4179+ mtype = MT_MEMORY_RX_NONCACHED;
4180
4181 return __arm_ioremap_caller(phys_addr, size, mtype,
4182 __builtin_return_address(0));
4183diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4184index 5e85ed3..b10a7ed 100644
4185--- a/arch/arm/mm/mmap.c
4186+++ b/arch/arm/mm/mmap.c
4187@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4188 struct vm_area_struct *vma;
4189 int do_align = 0;
4190 int aliasing = cache_is_vipt_aliasing();
4191+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4192 struct vm_unmapped_area_info info;
4193
4194 /*
4195@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4196 if (len > TASK_SIZE)
4197 return -ENOMEM;
4198
4199+#ifdef CONFIG_PAX_RANDMMAP
4200+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4201+#endif
4202+
4203 if (addr) {
4204 if (do_align)
4205 addr = COLOUR_ALIGN(addr, pgoff);
4206@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4207 addr = PAGE_ALIGN(addr);
4208
4209 vma = find_vma(mm, addr);
4210- if (TASK_SIZE - len >= addr &&
4211- (!vma || addr + len <= vma->vm_start))
4212+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4213 return addr;
4214 }
4215
4216@@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4217 info.high_limit = TASK_SIZE;
4218 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4219 info.align_offset = pgoff << PAGE_SHIFT;
4220+ info.threadstack_offset = offset;
4221 return vm_unmapped_area(&info);
4222 }
4223
4224@@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4225 unsigned long addr = addr0;
4226 int do_align = 0;
4227 int aliasing = cache_is_vipt_aliasing();
4228+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4229 struct vm_unmapped_area_info info;
4230
4231 /*
4232@@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4233 return addr;
4234 }
4235
4236+#ifdef CONFIG_PAX_RANDMMAP
4237+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4238+#endif
4239+
4240 /* requesting a specific address */
4241 if (addr) {
4242 if (do_align)
4243@@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4244 else
4245 addr = PAGE_ALIGN(addr);
4246 vma = find_vma(mm, addr);
4247- if (TASK_SIZE - len >= addr &&
4248- (!vma || addr + len <= vma->vm_start))
4249+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4250 return addr;
4251 }
4252
4253@@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4254 info.high_limit = mm->mmap_base;
4255 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4256 info.align_offset = pgoff << PAGE_SHIFT;
4257+ info.threadstack_offset = offset;
4258 addr = vm_unmapped_area(&info);
4259
4260 /*
4261@@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4262 {
4263 unsigned long random_factor = 0UL;
4264
4265+#ifdef CONFIG_PAX_RANDMMAP
4266+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4267+#endif
4268+
4269 /* 8 bits of randomness in 20 address space bits */
4270 if ((current->flags & PF_RANDOMIZE) &&
4271 !(current->personality & ADDR_NO_RANDOMIZE))
4272@@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4273
4274 if (mmap_is_legacy()) {
4275 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4276+
4277+#ifdef CONFIG_PAX_RANDMMAP
4278+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4279+ mm->mmap_base += mm->delta_mmap;
4280+#endif
4281+
4282 mm->get_unmapped_area = arch_get_unmapped_area;
4283 } else {
4284 mm->mmap_base = mmap_base(random_factor);
4285+
4286+#ifdef CONFIG_PAX_RANDMMAP
4287+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4288+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4289+#endif
4290+
4291 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4292 }
4293 }
4294diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4295index b68c6b2..f66c492 100644
4296--- a/arch/arm/mm/mmu.c
4297+++ b/arch/arm/mm/mmu.c
4298@@ -39,6 +39,22 @@
4299 #include "mm.h"
4300 #include "tcm.h"
4301
4302+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4303+void modify_domain(unsigned int dom, unsigned int type)
4304+{
4305+ struct thread_info *thread = current_thread_info();
4306+ unsigned int domain = thread->cpu_domain;
4307+ /*
4308+ * DOMAIN_MANAGER might be defined to some other value,
4309+ * use the arch-defined constant
4310+ */
4311+ domain &= ~domain_val(dom, 3);
4312+ thread->cpu_domain = domain | domain_val(dom, type);
4313+ set_domain(thread->cpu_domain);
4314+}
4315+EXPORT_SYMBOL(modify_domain);
4316+#endif
4317+
4318 /*
4319 * empty_zero_page is a special page that is used for
4320 * zero-initialized data and COW.
4321@@ -235,7 +251,15 @@ __setup("noalign", noalign_setup);
4322 #define PROT_PTE_S2_DEVICE PROT_PTE_DEVICE
4323 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4324
4325-static struct mem_type mem_types[] = {
4326+#ifdef CONFIG_PAX_KERNEXEC
4327+#define L_PTE_KERNEXEC L_PTE_RDONLY
4328+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4329+#else
4330+#define L_PTE_KERNEXEC L_PTE_DIRTY
4331+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4332+#endif
4333+
4334+static struct mem_type mem_types[] __read_only = {
4335 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4336 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4337 L_PTE_SHARED,
4338@@ -264,19 +288,19 @@ static struct mem_type mem_types[] = {
4339 .prot_sect = PROT_SECT_DEVICE,
4340 .domain = DOMAIN_IO,
4341 },
4342- [MT_UNCACHED] = {
4343+ [MT_UNCACHED_RW] = {
4344 .prot_pte = PROT_PTE_DEVICE,
4345 .prot_l1 = PMD_TYPE_TABLE,
4346 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4347 .domain = DOMAIN_IO,
4348 },
4349- [MT_CACHECLEAN] = {
4350- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4351+ [MT_CACHECLEAN_RO] = {
4352+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_RDONLY,
4353 .domain = DOMAIN_KERNEL,
4354 },
4355 #ifndef CONFIG_ARM_LPAE
4356- [MT_MINICLEAN] = {
4357- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4358+ [MT_MINICLEAN_RO] = {
4359+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_XN | PMD_SECT_RDONLY,
4360 .domain = DOMAIN_KERNEL,
4361 },
4362 #endif
4363@@ -284,15 +308,15 @@ static struct mem_type mem_types[] = {
4364 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4365 L_PTE_RDONLY,
4366 .prot_l1 = PMD_TYPE_TABLE,
4367- .domain = DOMAIN_USER,
4368+ .domain = DOMAIN_VECTORS,
4369 },
4370 [MT_HIGH_VECTORS] = {
4371 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4372 L_PTE_USER | L_PTE_RDONLY,
4373 .prot_l1 = PMD_TYPE_TABLE,
4374- .domain = DOMAIN_USER,
4375+ .domain = DOMAIN_VECTORS,
4376 },
4377- [MT_MEMORY_RWX] = {
4378+ [__MT_MEMORY_RWX] = {
4379 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4380 .prot_l1 = PMD_TYPE_TABLE,
4381 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4382@@ -305,17 +329,30 @@ static struct mem_type mem_types[] = {
4383 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4384 .domain = DOMAIN_KERNEL,
4385 },
4386- [MT_ROM] = {
4387- .prot_sect = PMD_TYPE_SECT,
4388+ [MT_MEMORY_RX] = {
4389+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4390+ .prot_l1 = PMD_TYPE_TABLE,
4391+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4392+ .domain = DOMAIN_KERNEL,
4393+ },
4394+ [MT_ROM_RX] = {
4395+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4396 .domain = DOMAIN_KERNEL,
4397 },
4398- [MT_MEMORY_RWX_NONCACHED] = {
4399+ [MT_MEMORY_RW_NONCACHED] = {
4400 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4401 L_PTE_MT_BUFFERABLE,
4402 .prot_l1 = PMD_TYPE_TABLE,
4403 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4404 .domain = DOMAIN_KERNEL,
4405 },
4406+ [MT_MEMORY_RX_NONCACHED] = {
4407+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4408+ L_PTE_MT_BUFFERABLE,
4409+ .prot_l1 = PMD_TYPE_TABLE,
4410+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4411+ .domain = DOMAIN_KERNEL,
4412+ },
4413 [MT_MEMORY_RW_DTCM] = {
4414 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4415 L_PTE_XN,
4416@@ -323,9 +360,10 @@ static struct mem_type mem_types[] = {
4417 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4418 .domain = DOMAIN_KERNEL,
4419 },
4420- [MT_MEMORY_RWX_ITCM] = {
4421- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4422+ [MT_MEMORY_RX_ITCM] = {
4423+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4424 .prot_l1 = PMD_TYPE_TABLE,
4425+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4426 .domain = DOMAIN_KERNEL,
4427 },
4428 [MT_MEMORY_RW_SO] = {
4429@@ -534,9 +572,14 @@ static void __init build_mem_type_table(void)
4430 * Mark cache clean areas and XIP ROM read only
4431 * from SVC mode and no access from userspace.
4432 */
4433- mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4434- mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4435- mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4436+ mem_types[MT_ROM_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4437+#ifdef CONFIG_PAX_KERNEXEC
4438+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4439+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4440+ mem_types[MT_MEMORY_RX_ITCM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4441+#endif
4442+ mem_types[MT_MINICLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4443+ mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4444 #endif
4445
4446 if (is_smp()) {
4447@@ -552,13 +595,17 @@ static void __init build_mem_type_table(void)
4448 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4449 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4450 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4451- mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4452- mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4453+ mem_types[__MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4454+ mem_types[__MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4455 mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4456 mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4457+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4458+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4459 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4460- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_S;
4461- mem_types[MT_MEMORY_RWX_NONCACHED].prot_pte |= L_PTE_SHARED;
4462+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_S;
4463+ mem_types[MT_MEMORY_RW_NONCACHED].prot_pte |= L_PTE_SHARED;
4464+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_S;
4465+ mem_types[MT_MEMORY_RX_NONCACHED].prot_pte |= L_PTE_SHARED;
4466 }
4467 }
4468
4469@@ -569,15 +616,20 @@ static void __init build_mem_type_table(void)
4470 if (cpu_arch >= CPU_ARCH_ARMv6) {
4471 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4472 /* Non-cacheable Normal is XCB = 001 */
4473- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4474+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4475+ PMD_SECT_BUFFERED;
4476+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4477 PMD_SECT_BUFFERED;
4478 } else {
4479 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4480- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4481+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4482+ PMD_SECT_TEX(1);
4483+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4484 PMD_SECT_TEX(1);
4485 }
4486 } else {
4487- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4488+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4489+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4490 }
4491
4492 #ifdef CONFIG_ARM_LPAE
4493@@ -593,6 +645,8 @@ static void __init build_mem_type_table(void)
4494 vecs_pgprot |= PTE_EXT_AF;
4495 #endif
4496
4497+ user_pgprot |= __supported_pte_mask;
4498+
4499 for (i = 0; i < 16; i++) {
4500 pteval_t v = pgprot_val(protection_map[i]);
4501 protection_map[i] = __pgprot(v | user_pgprot);
4502@@ -610,21 +664,24 @@ static void __init build_mem_type_table(void)
4503
4504 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4505 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4506- mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4507- mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4508+ mem_types[__MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4509+ mem_types[__MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4510 mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4511 mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4512+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4513+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4514 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4515- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= ecc_mask;
4516- mem_types[MT_ROM].prot_sect |= cp->pmd;
4517+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= ecc_mask;
4518+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= ecc_mask;
4519+ mem_types[MT_ROM_RX].prot_sect |= cp->pmd;
4520
4521 switch (cp->pmd) {
4522 case PMD_SECT_WT:
4523- mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WT;
4524+ mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WT;
4525 break;
4526 case PMD_SECT_WB:
4527 case PMD_SECT_WBWA:
4528- mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WB;
4529+ mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WB;
4530 break;
4531 }
4532 pr_info("Memory policy: %sData cache %s\n",
4533@@ -842,7 +899,7 @@ static void __init create_mapping(struct map_desc *md)
4534 return;
4535 }
4536
4537- if ((md->type == MT_DEVICE || md->type == MT_ROM) &&
4538+ if ((md->type == MT_DEVICE || md->type == MT_ROM_RX) &&
4539 md->virtual >= PAGE_OFFSET &&
4540 (md->virtual < VMALLOC_START || md->virtual >= VMALLOC_END)) {
4541 printk(KERN_WARNING "BUG: mapping for 0x%08llx"
4542@@ -1257,18 +1314,15 @@ void __init arm_mm_memblock_reserve(void)
4543 * called function. This means you can't use any function or debugging
4544 * method which may touch any device, otherwise the kernel _will_ crash.
4545 */
4546+
4547+static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4548+
4549 static void __init devicemaps_init(const struct machine_desc *mdesc)
4550 {
4551 struct map_desc map;
4552 unsigned long addr;
4553- void *vectors;
4554
4555- /*
4556- * Allocate the vector page early.
4557- */
4558- vectors = early_alloc(PAGE_SIZE * 2);
4559-
4560- early_trap_init(vectors);
4561+ early_trap_init(&vectors);
4562
4563 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4564 pmd_clear(pmd_off_k(addr));
4565@@ -1281,7 +1335,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4566 map.pfn = __phys_to_pfn(CONFIG_XIP_PHYS_ADDR & SECTION_MASK);
4567 map.virtual = MODULES_VADDR;
4568 map.length = ((unsigned long)_etext - map.virtual + ~SECTION_MASK) & SECTION_MASK;
4569- map.type = MT_ROM;
4570+ map.type = MT_ROM_RX;
4571 create_mapping(&map);
4572 #endif
4573
4574@@ -1292,14 +1346,14 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4575 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS);
4576 map.virtual = FLUSH_BASE;
4577 map.length = SZ_1M;
4578- map.type = MT_CACHECLEAN;
4579+ map.type = MT_CACHECLEAN_RO;
4580 create_mapping(&map);
4581 #endif
4582 #ifdef FLUSH_BASE_MINICACHE
4583 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS + SZ_1M);
4584 map.virtual = FLUSH_BASE_MINICACHE;
4585 map.length = SZ_1M;
4586- map.type = MT_MINICLEAN;
4587+ map.type = MT_MINICLEAN_RO;
4588 create_mapping(&map);
4589 #endif
4590
4591@@ -1308,7 +1362,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4592 * location (0xffff0000). If we aren't using high-vectors, also
4593 * create a mapping at the low-vectors virtual address.
4594 */
4595- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4596+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4597 map.virtual = 0xffff0000;
4598 map.length = PAGE_SIZE;
4599 #ifdef CONFIG_KUSER_HELPERS
4600@@ -1365,8 +1419,10 @@ static void __init kmap_init(void)
4601 static void __init map_lowmem(void)
4602 {
4603 struct memblock_region *reg;
4604+#ifndef CONFIG_PAX_KERNEXEC
4605 unsigned long kernel_x_start = round_down(__pa(_stext), SECTION_SIZE);
4606 unsigned long kernel_x_end = round_up(__pa(__init_end), SECTION_SIZE);
4607+#endif
4608
4609 /* Map all the lowmem memory banks. */
4610 for_each_memblock(memory, reg) {
4611@@ -1379,11 +1435,48 @@ static void __init map_lowmem(void)
4612 if (start >= end)
4613 break;
4614
4615+#ifdef CONFIG_PAX_KERNEXEC
4616+ map.pfn = __phys_to_pfn(start);
4617+ map.virtual = __phys_to_virt(start);
4618+ map.length = end - start;
4619+
4620+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4621+ struct map_desc kernel;
4622+ struct map_desc initmap;
4623+
4624+ /* when freeing initmem we will make this RW */
4625+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4626+ initmap.virtual = (unsigned long)__init_begin;
4627+ initmap.length = _sdata - __init_begin;
4628+ initmap.type = __MT_MEMORY_RWX;
4629+ create_mapping(&initmap);
4630+
4631+ /* when freeing initmem we will make this RX */
4632+ kernel.pfn = __phys_to_pfn(__pa(_stext));
4633+ kernel.virtual = (unsigned long)_stext;
4634+ kernel.length = __init_begin - _stext;
4635+ kernel.type = __MT_MEMORY_RWX;
4636+ create_mapping(&kernel);
4637+
4638+ if (map.virtual < (unsigned long)_stext) {
4639+ map.length = (unsigned long)_stext - map.virtual;
4640+ map.type = __MT_MEMORY_RWX;
4641+ create_mapping(&map);
4642+ }
4643+
4644+ map.pfn = __phys_to_pfn(__pa(_sdata));
4645+ map.virtual = (unsigned long)_sdata;
4646+ map.length = end - __pa(_sdata);
4647+ }
4648+
4649+ map.type = MT_MEMORY_RW;
4650+ create_mapping(&map);
4651+#else
4652 if (end < kernel_x_start || start >= kernel_x_end) {
4653 map.pfn = __phys_to_pfn(start);
4654 map.virtual = __phys_to_virt(start);
4655 map.length = end - start;
4656- map.type = MT_MEMORY_RWX;
4657+ map.type = __MT_MEMORY_RWX;
4658
4659 create_mapping(&map);
4660 } else {
4661@@ -1400,7 +1493,7 @@ static void __init map_lowmem(void)
4662 map.pfn = __phys_to_pfn(kernel_x_start);
4663 map.virtual = __phys_to_virt(kernel_x_start);
4664 map.length = kernel_x_end - kernel_x_start;
4665- map.type = MT_MEMORY_RWX;
4666+ map.type = __MT_MEMORY_RWX;
4667
4668 create_mapping(&map);
4669
4670@@ -1413,6 +1506,7 @@ static void __init map_lowmem(void)
4671 create_mapping(&map);
4672 }
4673 }
4674+#endif
4675 }
4676 }
4677
4678diff --git a/arch/arm/plat-iop/setup.c b/arch/arm/plat-iop/setup.c
4679index 5b217f4..c23f40e 100644
4680--- a/arch/arm/plat-iop/setup.c
4681+++ b/arch/arm/plat-iop/setup.c
4682@@ -24,7 +24,7 @@ static struct map_desc iop3xx_std_desc[] __initdata = {
4683 .virtual = IOP3XX_PERIPHERAL_VIRT_BASE,
4684 .pfn = __phys_to_pfn(IOP3XX_PERIPHERAL_PHYS_BASE),
4685 .length = IOP3XX_PERIPHERAL_SIZE,
4686- .type = MT_UNCACHED,
4687+ .type = MT_UNCACHED_RW,
4688 },
4689 };
4690
4691diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4692index a5bc92d..0bb4730 100644
4693--- a/arch/arm/plat-omap/sram.c
4694+++ b/arch/arm/plat-omap/sram.c
4695@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4696 * Looks like we need to preserve some bootloader code at the
4697 * beginning of SRAM for jumping to flash for reboot to work...
4698 */
4699+ pax_open_kernel();
4700 memset_io(omap_sram_base + omap_sram_skip, 0,
4701 omap_sram_size - omap_sram_skip);
4702+ pax_close_kernel();
4703 }
4704diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4705index ce6d763..cfea917 100644
4706--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4707+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4708@@ -47,7 +47,7 @@ struct samsung_dma_ops {
4709 int (*started)(unsigned ch);
4710 int (*flush)(unsigned ch);
4711 int (*stop)(unsigned ch);
4712-};
4713+} __no_const;
4714
4715 extern void *samsung_dmadev_get_ops(void);
4716 extern void *s3c_dma_get_ops(void);
4717diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
4718index 6c0f684..5faea9d 100644
4719--- a/arch/arm64/include/asm/uaccess.h
4720+++ b/arch/arm64/include/asm/uaccess.h
4721@@ -99,6 +99,7 @@ static inline void set_fs(mm_segment_t fs)
4722 flag; \
4723 })
4724
4725+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
4726 #define access_ok(type, addr, size) __range_ok(addr, size)
4727 #define user_addr_max get_fs
4728
4729diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4730index c3a58a1..78fbf54 100644
4731--- a/arch/avr32/include/asm/cache.h
4732+++ b/arch/avr32/include/asm/cache.h
4733@@ -1,8 +1,10 @@
4734 #ifndef __ASM_AVR32_CACHE_H
4735 #define __ASM_AVR32_CACHE_H
4736
4737+#include <linux/const.h>
4738+
4739 #define L1_CACHE_SHIFT 5
4740-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4741+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4742
4743 /*
4744 * Memory returned by kmalloc() may be used for DMA, so we must make
4745diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4746index d232888..87c8df1 100644
4747--- a/arch/avr32/include/asm/elf.h
4748+++ b/arch/avr32/include/asm/elf.h
4749@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4750 the loader. We need to make sure that it is out of the way of the program
4751 that it will "exec", and that there is sufficient room for the brk. */
4752
4753-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4754+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4755
4756+#ifdef CONFIG_PAX_ASLR
4757+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4758+
4759+#define PAX_DELTA_MMAP_LEN 15
4760+#define PAX_DELTA_STACK_LEN 15
4761+#endif
4762
4763 /* This yields a mask that user programs can use to figure out what
4764 instruction set this CPU supports. This could be done in user space,
4765diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4766index 479330b..53717a8 100644
4767--- a/arch/avr32/include/asm/kmap_types.h
4768+++ b/arch/avr32/include/asm/kmap_types.h
4769@@ -2,9 +2,9 @@
4770 #define __ASM_AVR32_KMAP_TYPES_H
4771
4772 #ifdef CONFIG_DEBUG_HIGHMEM
4773-# define KM_TYPE_NR 29
4774+# define KM_TYPE_NR 30
4775 #else
4776-# define KM_TYPE_NR 14
4777+# define KM_TYPE_NR 15
4778 #endif
4779
4780 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4781diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4782index 0eca933..eb78c7b 100644
4783--- a/arch/avr32/mm/fault.c
4784+++ b/arch/avr32/mm/fault.c
4785@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4786
4787 int exception_trace = 1;
4788
4789+#ifdef CONFIG_PAX_PAGEEXEC
4790+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4791+{
4792+ unsigned long i;
4793+
4794+ printk(KERN_ERR "PAX: bytes at PC: ");
4795+ for (i = 0; i < 20; i++) {
4796+ unsigned char c;
4797+ if (get_user(c, (unsigned char *)pc+i))
4798+ printk(KERN_CONT "???????? ");
4799+ else
4800+ printk(KERN_CONT "%02x ", c);
4801+ }
4802+ printk("\n");
4803+}
4804+#endif
4805+
4806 /*
4807 * This routine handles page faults. It determines the address and the
4808 * problem, and then passes it off to one of the appropriate routines.
4809@@ -176,6 +193,16 @@ bad_area:
4810 up_read(&mm->mmap_sem);
4811
4812 if (user_mode(regs)) {
4813+
4814+#ifdef CONFIG_PAX_PAGEEXEC
4815+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4816+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4817+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4818+ do_group_exit(SIGKILL);
4819+ }
4820+ }
4821+#endif
4822+
4823 if (exception_trace && printk_ratelimit())
4824 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4825 "sp %08lx ecr %lu\n",
4826diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4827index 568885a..f8008df 100644
4828--- a/arch/blackfin/include/asm/cache.h
4829+++ b/arch/blackfin/include/asm/cache.h
4830@@ -7,6 +7,7 @@
4831 #ifndef __ARCH_BLACKFIN_CACHE_H
4832 #define __ARCH_BLACKFIN_CACHE_H
4833
4834+#include <linux/const.h>
4835 #include <linux/linkage.h> /* for asmlinkage */
4836
4837 /*
4838@@ -14,7 +15,7 @@
4839 * Blackfin loads 32 bytes for cache
4840 */
4841 #define L1_CACHE_SHIFT 5
4842-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4843+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4844 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4845
4846 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4847diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4848index aea2718..3639a60 100644
4849--- a/arch/cris/include/arch-v10/arch/cache.h
4850+++ b/arch/cris/include/arch-v10/arch/cache.h
4851@@ -1,8 +1,9 @@
4852 #ifndef _ASM_ARCH_CACHE_H
4853 #define _ASM_ARCH_CACHE_H
4854
4855+#include <linux/const.h>
4856 /* Etrax 100LX have 32-byte cache-lines. */
4857-#define L1_CACHE_BYTES 32
4858 #define L1_CACHE_SHIFT 5
4859+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4860
4861 #endif /* _ASM_ARCH_CACHE_H */
4862diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4863index 7caf25d..ee65ac5 100644
4864--- a/arch/cris/include/arch-v32/arch/cache.h
4865+++ b/arch/cris/include/arch-v32/arch/cache.h
4866@@ -1,11 +1,12 @@
4867 #ifndef _ASM_CRIS_ARCH_CACHE_H
4868 #define _ASM_CRIS_ARCH_CACHE_H
4869
4870+#include <linux/const.h>
4871 #include <arch/hwregs/dma.h>
4872
4873 /* A cache-line is 32 bytes. */
4874-#define L1_CACHE_BYTES 32
4875 #define L1_CACHE_SHIFT 5
4876+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4877
4878 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4879
4880diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4881index b86329d..6709906 100644
4882--- a/arch/frv/include/asm/atomic.h
4883+++ b/arch/frv/include/asm/atomic.h
4884@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4885 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4886 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4887
4888+#define atomic64_read_unchecked(v) atomic64_read(v)
4889+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4890+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4891+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4892+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4893+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4894+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4895+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4896+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4897+
4898 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4899 {
4900 int c, old;
4901diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4902index 2797163..c2a401d 100644
4903--- a/arch/frv/include/asm/cache.h
4904+++ b/arch/frv/include/asm/cache.h
4905@@ -12,10 +12,11 @@
4906 #ifndef __ASM_CACHE_H
4907 #define __ASM_CACHE_H
4908
4909+#include <linux/const.h>
4910
4911 /* bytes per L1 cache line */
4912 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4913-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4914+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4915
4916 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4917 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4918diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4919index 43901f2..0d8b865 100644
4920--- a/arch/frv/include/asm/kmap_types.h
4921+++ b/arch/frv/include/asm/kmap_types.h
4922@@ -2,6 +2,6 @@
4923 #ifndef _ASM_KMAP_TYPES_H
4924 #define _ASM_KMAP_TYPES_H
4925
4926-#define KM_TYPE_NR 17
4927+#define KM_TYPE_NR 18
4928
4929 #endif
4930diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4931index 836f147..4cf23f5 100644
4932--- a/arch/frv/mm/elf-fdpic.c
4933+++ b/arch/frv/mm/elf-fdpic.c
4934@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4935 {
4936 struct vm_area_struct *vma;
4937 struct vm_unmapped_area_info info;
4938+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4939
4940 if (len > TASK_SIZE)
4941 return -ENOMEM;
4942@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4943 if (addr) {
4944 addr = PAGE_ALIGN(addr);
4945 vma = find_vma(current->mm, addr);
4946- if (TASK_SIZE - len >= addr &&
4947- (!vma || addr + len <= vma->vm_start))
4948+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4949 goto success;
4950 }
4951
4952@@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4953 info.high_limit = (current->mm->start_stack - 0x00200000);
4954 info.align_mask = 0;
4955 info.align_offset = 0;
4956+ info.threadstack_offset = offset;
4957 addr = vm_unmapped_area(&info);
4958 if (!(addr & ~PAGE_MASK))
4959 goto success;
4960diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4961index f4ca594..adc72fd6 100644
4962--- a/arch/hexagon/include/asm/cache.h
4963+++ b/arch/hexagon/include/asm/cache.h
4964@@ -21,9 +21,11 @@
4965 #ifndef __ASM_CACHE_H
4966 #define __ASM_CACHE_H
4967
4968+#include <linux/const.h>
4969+
4970 /* Bytes per L1 cache line */
4971-#define L1_CACHE_SHIFT (5)
4972-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4973+#define L1_CACHE_SHIFT 5
4974+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4975
4976 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4977 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4978diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
4979index 0c8e553..112d734 100644
4980--- a/arch/ia64/Kconfig
4981+++ b/arch/ia64/Kconfig
4982@@ -544,6 +544,7 @@ source "drivers/sn/Kconfig"
4983 config KEXEC
4984 bool "kexec system call"
4985 depends on !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
4986+ depends on !GRKERNSEC_KMEM
4987 help
4988 kexec is a system call that implements the ability to shutdown your
4989 current kernel, and to start another kernel. It is like a reboot
4990diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4991index 6e6fe18..a6ae668 100644
4992--- a/arch/ia64/include/asm/atomic.h
4993+++ b/arch/ia64/include/asm/atomic.h
4994@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4995 #define atomic64_inc(v) atomic64_add(1, (v))
4996 #define atomic64_dec(v) atomic64_sub(1, (v))
4997
4998+#define atomic64_read_unchecked(v) atomic64_read(v)
4999+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5000+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5001+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5002+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5003+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5004+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5005+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5006+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5007+
5008 /* Atomic operations are already serializing */
5009 #define smp_mb__before_atomic_dec() barrier()
5010 #define smp_mb__after_atomic_dec() barrier()
5011diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
5012index 988254a..e1ee885 100644
5013--- a/arch/ia64/include/asm/cache.h
5014+++ b/arch/ia64/include/asm/cache.h
5015@@ -1,6 +1,7 @@
5016 #ifndef _ASM_IA64_CACHE_H
5017 #define _ASM_IA64_CACHE_H
5018
5019+#include <linux/const.h>
5020
5021 /*
5022 * Copyright (C) 1998-2000 Hewlett-Packard Co
5023@@ -9,7 +10,7 @@
5024
5025 /* Bytes per L1 (data) cache line. */
5026 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
5027-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5028+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5029
5030 #ifdef CONFIG_SMP
5031 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5032diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
5033index 5a83c5c..4d7f553 100644
5034--- a/arch/ia64/include/asm/elf.h
5035+++ b/arch/ia64/include/asm/elf.h
5036@@ -42,6 +42,13 @@
5037 */
5038 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
5039
5040+#ifdef CONFIG_PAX_ASLR
5041+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
5042+
5043+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5044+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5045+#endif
5046+
5047 #define PT_IA_64_UNWIND 0x70000001
5048
5049 /* IA-64 relocations: */
5050diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
5051index 5767cdf..7462574 100644
5052--- a/arch/ia64/include/asm/pgalloc.h
5053+++ b/arch/ia64/include/asm/pgalloc.h
5054@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5055 pgd_val(*pgd_entry) = __pa(pud);
5056 }
5057
5058+static inline void
5059+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5060+{
5061+ pgd_populate(mm, pgd_entry, pud);
5062+}
5063+
5064 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
5065 {
5066 return quicklist_alloc(0, GFP_KERNEL, NULL);
5067@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5068 pud_val(*pud_entry) = __pa(pmd);
5069 }
5070
5071+static inline void
5072+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5073+{
5074+ pud_populate(mm, pud_entry, pmd);
5075+}
5076+
5077 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5078 {
5079 return quicklist_alloc(0, GFP_KERNEL, NULL);
5080diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
5081index 7935115..c0eca6a 100644
5082--- a/arch/ia64/include/asm/pgtable.h
5083+++ b/arch/ia64/include/asm/pgtable.h
5084@@ -12,7 +12,7 @@
5085 * David Mosberger-Tang <davidm@hpl.hp.com>
5086 */
5087
5088-
5089+#include <linux/const.h>
5090 #include <asm/mman.h>
5091 #include <asm/page.h>
5092 #include <asm/processor.h>
5093@@ -142,6 +142,17 @@
5094 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5095 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5096 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
5097+
5098+#ifdef CONFIG_PAX_PAGEEXEC
5099+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
5100+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5101+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5102+#else
5103+# define PAGE_SHARED_NOEXEC PAGE_SHARED
5104+# define PAGE_READONLY_NOEXEC PAGE_READONLY
5105+# define PAGE_COPY_NOEXEC PAGE_COPY
5106+#endif
5107+
5108 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
5109 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
5110 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
5111diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
5112index 45698cd..e8e2dbc 100644
5113--- a/arch/ia64/include/asm/spinlock.h
5114+++ b/arch/ia64/include/asm/spinlock.h
5115@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
5116 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
5117
5118 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
5119- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
5120+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
5121 }
5122
5123 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
5124diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
5125index 449c8c0..3d4b1e9 100644
5126--- a/arch/ia64/include/asm/uaccess.h
5127+++ b/arch/ia64/include/asm/uaccess.h
5128@@ -70,6 +70,7 @@
5129 && ((segment).seg == KERNEL_DS.seg \
5130 || likely(REGION_OFFSET((unsigned long) (addr)) < RGN_MAP_LIMIT))); \
5131 })
5132+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
5133 #define access_ok(type, addr, size) __access_ok((addr), (size), get_fs())
5134
5135 /*
5136@@ -240,12 +241,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
5137 static inline unsigned long
5138 __copy_to_user (void __user *to, const void *from, unsigned long count)
5139 {
5140+ if (count > INT_MAX)
5141+ return count;
5142+
5143+ if (!__builtin_constant_p(count))
5144+ check_object_size(from, count, true);
5145+
5146 return __copy_user(to, (__force void __user *) from, count);
5147 }
5148
5149 static inline unsigned long
5150 __copy_from_user (void *to, const void __user *from, unsigned long count)
5151 {
5152+ if (count > INT_MAX)
5153+ return count;
5154+
5155+ if (!__builtin_constant_p(count))
5156+ check_object_size(to, count, false);
5157+
5158 return __copy_user((__force void __user *) to, from, count);
5159 }
5160
5161@@ -255,10 +268,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5162 ({ \
5163 void __user *__cu_to = (to); \
5164 const void *__cu_from = (from); \
5165- long __cu_len = (n); \
5166+ unsigned long __cu_len = (n); \
5167 \
5168- if (__access_ok(__cu_to, __cu_len, get_fs())) \
5169+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5170+ if (!__builtin_constant_p(n)) \
5171+ check_object_size(__cu_from, __cu_len, true); \
5172 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5173+ } \
5174 __cu_len; \
5175 })
5176
5177@@ -266,11 +282,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5178 ({ \
5179 void *__cu_to = (to); \
5180 const void __user *__cu_from = (from); \
5181- long __cu_len = (n); \
5182+ unsigned long __cu_len = (n); \
5183 \
5184 __chk_user_ptr(__cu_from); \
5185- if (__access_ok(__cu_from, __cu_len, get_fs())) \
5186+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5187+ if (!__builtin_constant_p(n)) \
5188+ check_object_size(__cu_to, __cu_len, false); \
5189 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5190+ } \
5191 __cu_len; \
5192 })
5193
5194diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5195index 24603be..948052d 100644
5196--- a/arch/ia64/kernel/module.c
5197+++ b/arch/ia64/kernel/module.c
5198@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5199 void
5200 module_free (struct module *mod, void *module_region)
5201 {
5202- if (mod && mod->arch.init_unw_table &&
5203- module_region == mod->module_init) {
5204+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5205 unw_remove_unwind_table(mod->arch.init_unw_table);
5206 mod->arch.init_unw_table = NULL;
5207 }
5208@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5209 }
5210
5211 static inline int
5212+in_init_rx (const struct module *mod, uint64_t addr)
5213+{
5214+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5215+}
5216+
5217+static inline int
5218+in_init_rw (const struct module *mod, uint64_t addr)
5219+{
5220+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5221+}
5222+
5223+static inline int
5224 in_init (const struct module *mod, uint64_t addr)
5225 {
5226- return addr - (uint64_t) mod->module_init < mod->init_size;
5227+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5228+}
5229+
5230+static inline int
5231+in_core_rx (const struct module *mod, uint64_t addr)
5232+{
5233+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5234+}
5235+
5236+static inline int
5237+in_core_rw (const struct module *mod, uint64_t addr)
5238+{
5239+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5240 }
5241
5242 static inline int
5243 in_core (const struct module *mod, uint64_t addr)
5244 {
5245- return addr - (uint64_t) mod->module_core < mod->core_size;
5246+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5247 }
5248
5249 static inline int
5250@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5251 break;
5252
5253 case RV_BDREL:
5254- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5255+ if (in_init_rx(mod, val))
5256+ val -= (uint64_t) mod->module_init_rx;
5257+ else if (in_init_rw(mod, val))
5258+ val -= (uint64_t) mod->module_init_rw;
5259+ else if (in_core_rx(mod, val))
5260+ val -= (uint64_t) mod->module_core_rx;
5261+ else if (in_core_rw(mod, val))
5262+ val -= (uint64_t) mod->module_core_rw;
5263 break;
5264
5265 case RV_LTV:
5266@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5267 * addresses have been selected...
5268 */
5269 uint64_t gp;
5270- if (mod->core_size > MAX_LTOFF)
5271+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5272 /*
5273 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5274 * at the end of the module.
5275 */
5276- gp = mod->core_size - MAX_LTOFF / 2;
5277+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5278 else
5279- gp = mod->core_size / 2;
5280- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5281+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5282+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5283 mod->arch.gp = gp;
5284 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5285 }
5286diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5287index ab33328..f39506c 100644
5288--- a/arch/ia64/kernel/palinfo.c
5289+++ b/arch/ia64/kernel/palinfo.c
5290@@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5291 return NOTIFY_OK;
5292 }
5293
5294-static struct notifier_block __refdata palinfo_cpu_notifier =
5295+static struct notifier_block palinfo_cpu_notifier =
5296 {
5297 .notifier_call = palinfo_cpu_callback,
5298 .priority = 0,
5299diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5300index 41e33f8..65180b2a 100644
5301--- a/arch/ia64/kernel/sys_ia64.c
5302+++ b/arch/ia64/kernel/sys_ia64.c
5303@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5304 unsigned long align_mask = 0;
5305 struct mm_struct *mm = current->mm;
5306 struct vm_unmapped_area_info info;
5307+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5308
5309 if (len > RGN_MAP_LIMIT)
5310 return -ENOMEM;
5311@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5312 if (REGION_NUMBER(addr) == RGN_HPAGE)
5313 addr = 0;
5314 #endif
5315+
5316+#ifdef CONFIG_PAX_RANDMMAP
5317+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5318+ addr = mm->free_area_cache;
5319+ else
5320+#endif
5321+
5322 if (!addr)
5323 addr = TASK_UNMAPPED_BASE;
5324
5325@@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5326 info.high_limit = TASK_SIZE;
5327 info.align_mask = align_mask;
5328 info.align_offset = 0;
5329+ info.threadstack_offset = offset;
5330 return vm_unmapped_area(&info);
5331 }
5332
5333diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5334index 84f8a52..7c76178 100644
5335--- a/arch/ia64/kernel/vmlinux.lds.S
5336+++ b/arch/ia64/kernel/vmlinux.lds.S
5337@@ -192,7 +192,7 @@ SECTIONS {
5338 /* Per-cpu data: */
5339 . = ALIGN(PERCPU_PAGE_SIZE);
5340 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5341- __phys_per_cpu_start = __per_cpu_load;
5342+ __phys_per_cpu_start = per_cpu_load;
5343 /*
5344 * ensure percpu data fits
5345 * into percpu page size
5346diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5347index 7225dad..2a7c8256 100644
5348--- a/arch/ia64/mm/fault.c
5349+++ b/arch/ia64/mm/fault.c
5350@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5351 return pte_present(pte);
5352 }
5353
5354+#ifdef CONFIG_PAX_PAGEEXEC
5355+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5356+{
5357+ unsigned long i;
5358+
5359+ printk(KERN_ERR "PAX: bytes at PC: ");
5360+ for (i = 0; i < 8; i++) {
5361+ unsigned int c;
5362+ if (get_user(c, (unsigned int *)pc+i))
5363+ printk(KERN_CONT "???????? ");
5364+ else
5365+ printk(KERN_CONT "%08x ", c);
5366+ }
5367+ printk("\n");
5368+}
5369+#endif
5370+
5371 # define VM_READ_BIT 0
5372 # define VM_WRITE_BIT 1
5373 # define VM_EXEC_BIT 2
5374@@ -151,8 +168,21 @@ retry:
5375 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5376 goto bad_area;
5377
5378- if ((vma->vm_flags & mask) != mask)
5379+ if ((vma->vm_flags & mask) != mask) {
5380+
5381+#ifdef CONFIG_PAX_PAGEEXEC
5382+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5383+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5384+ goto bad_area;
5385+
5386+ up_read(&mm->mmap_sem);
5387+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5388+ do_group_exit(SIGKILL);
5389+ }
5390+#endif
5391+
5392 goto bad_area;
5393+ }
5394
5395 /*
5396 * If for any reason at all we couldn't handle the fault, make
5397diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5398index 68232db..6ca80af 100644
5399--- a/arch/ia64/mm/hugetlbpage.c
5400+++ b/arch/ia64/mm/hugetlbpage.c
5401@@ -154,6 +154,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5402 unsigned long pgoff, unsigned long flags)
5403 {
5404 struct vm_unmapped_area_info info;
5405+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5406
5407 if (len > RGN_MAP_LIMIT)
5408 return -ENOMEM;
5409@@ -177,6 +178,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5410 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5411 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5412 info.align_offset = 0;
5413+ info.threadstack_offset = offset;
5414 return vm_unmapped_area(&info);
5415 }
5416
5417diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5418index 25c3502..560dae7 100644
5419--- a/arch/ia64/mm/init.c
5420+++ b/arch/ia64/mm/init.c
5421@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5422 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5423 vma->vm_end = vma->vm_start + PAGE_SIZE;
5424 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5425+
5426+#ifdef CONFIG_PAX_PAGEEXEC
5427+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5428+ vma->vm_flags &= ~VM_EXEC;
5429+
5430+#ifdef CONFIG_PAX_MPROTECT
5431+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
5432+ vma->vm_flags &= ~VM_MAYEXEC;
5433+#endif
5434+
5435+ }
5436+#endif
5437+
5438 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5439 down_write(&current->mm->mmap_sem);
5440 if (insert_vm_struct(current->mm, vma)) {
5441diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5442index 40b3ee9..8c2c112 100644
5443--- a/arch/m32r/include/asm/cache.h
5444+++ b/arch/m32r/include/asm/cache.h
5445@@ -1,8 +1,10 @@
5446 #ifndef _ASM_M32R_CACHE_H
5447 #define _ASM_M32R_CACHE_H
5448
5449+#include <linux/const.h>
5450+
5451 /* L1 cache line size */
5452 #define L1_CACHE_SHIFT 4
5453-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5454+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5455
5456 #endif /* _ASM_M32R_CACHE_H */
5457diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5458index 82abd15..d95ae5d 100644
5459--- a/arch/m32r/lib/usercopy.c
5460+++ b/arch/m32r/lib/usercopy.c
5461@@ -14,6 +14,9 @@
5462 unsigned long
5463 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5464 {
5465+ if ((long)n < 0)
5466+ return n;
5467+
5468 prefetch(from);
5469 if (access_ok(VERIFY_WRITE, to, n))
5470 __copy_user(to,from,n);
5471@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5472 unsigned long
5473 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5474 {
5475+ if ((long)n < 0)
5476+ return n;
5477+
5478 prefetchw(to);
5479 if (access_ok(VERIFY_READ, from, n))
5480 __copy_user_zeroing(to,from,n);
5481diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5482index 0395c51..5f26031 100644
5483--- a/arch/m68k/include/asm/cache.h
5484+++ b/arch/m68k/include/asm/cache.h
5485@@ -4,9 +4,11 @@
5486 #ifndef __ARCH_M68K_CACHE_H
5487 #define __ARCH_M68K_CACHE_H
5488
5489+#include <linux/const.h>
5490+
5491 /* bytes per L1 cache line */
5492 #define L1_CACHE_SHIFT 4
5493-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5494+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5495
5496 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5497
5498diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5499index 0424315..defcca9 100644
5500--- a/arch/metag/mm/hugetlbpage.c
5501+++ b/arch/metag/mm/hugetlbpage.c
5502@@ -205,6 +205,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5503 info.high_limit = TASK_SIZE;
5504 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5505 info.align_offset = 0;
5506+ info.threadstack_offset = 0;
5507 return vm_unmapped_area(&info);
5508 }
5509
5510diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5511index 4efe96a..60e8699 100644
5512--- a/arch/microblaze/include/asm/cache.h
5513+++ b/arch/microblaze/include/asm/cache.h
5514@@ -13,11 +13,12 @@
5515 #ifndef _ASM_MICROBLAZE_CACHE_H
5516 #define _ASM_MICROBLAZE_CACHE_H
5517
5518+#include <linux/const.h>
5519 #include <asm/registers.h>
5520
5521 #define L1_CACHE_SHIFT 5
5522 /* word-granular cache in microblaze */
5523-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5524+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5525
5526 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5527
5528diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
5529index 95fa1f1..56a6fa2 100644
5530--- a/arch/mips/Kconfig
5531+++ b/arch/mips/Kconfig
5532@@ -2298,6 +2298,7 @@ source "kernel/Kconfig.preempt"
5533
5534 config KEXEC
5535 bool "Kexec system call"
5536+ depends on !GRKERNSEC_KMEM
5537 help
5538 kexec is a system call that implements the ability to shutdown your
5539 current kernel, and to start another kernel. It is like a reboot
5540diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
5541index 02f2444..506969c 100644
5542--- a/arch/mips/cavium-octeon/dma-octeon.c
5543+++ b/arch/mips/cavium-octeon/dma-octeon.c
5544@@ -199,7 +199,7 @@ static void octeon_dma_free_coherent(struct device *dev, size_t size,
5545 if (dma_release_from_coherent(dev, order, vaddr))
5546 return;
5547
5548- swiotlb_free_coherent(dev, size, vaddr, dma_handle);
5549+ swiotlb_free_coherent(dev, size, vaddr, dma_handle, attrs);
5550 }
5551
5552 static dma_addr_t octeon_unity_phys_to_dma(struct device *dev, phys_addr_t paddr)
5553diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5554index 7eed2f2..c4e385d 100644
5555--- a/arch/mips/include/asm/atomic.h
5556+++ b/arch/mips/include/asm/atomic.h
5557@@ -21,15 +21,39 @@
5558 #include <asm/cmpxchg.h>
5559 #include <asm/war.h>
5560
5561+#ifdef CONFIG_GENERIC_ATOMIC64
5562+#include <asm-generic/atomic64.h>
5563+#endif
5564+
5565 #define ATOMIC_INIT(i) { (i) }
5566
5567+#ifdef CONFIG_64BIT
5568+#define _ASM_EXTABLE(from, to) \
5569+" .section __ex_table,\"a\"\n" \
5570+" .dword " #from ", " #to"\n" \
5571+" .previous\n"
5572+#else
5573+#define _ASM_EXTABLE(from, to) \
5574+" .section __ex_table,\"a\"\n" \
5575+" .word " #from ", " #to"\n" \
5576+" .previous\n"
5577+#endif
5578+
5579 /*
5580 * atomic_read - read atomic variable
5581 * @v: pointer of type atomic_t
5582 *
5583 * Atomically reads the value of @v.
5584 */
5585-#define atomic_read(v) (*(volatile int *)&(v)->counter)
5586+static inline int atomic_read(const atomic_t *v)
5587+{
5588+ return (*(volatile const int *) &v->counter);
5589+}
5590+
5591+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5592+{
5593+ return (*(volatile const int *) &v->counter);
5594+}
5595
5596 /*
5597 * atomic_set - set atomic variable
5598@@ -38,7 +62,15 @@
5599 *
5600 * Atomically sets the value of @v to @i.
5601 */
5602-#define atomic_set(v, i) ((v)->counter = (i))
5603+static inline void atomic_set(atomic_t *v, int i)
5604+{
5605+ v->counter = i;
5606+}
5607+
5608+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5609+{
5610+ v->counter = i;
5611+}
5612
5613 /*
5614 * atomic_add - add integer to atomic variable
5615@@ -47,7 +79,67 @@
5616 *
5617 * Atomically adds @i to @v.
5618 */
5619-static __inline__ void atomic_add(int i, atomic_t * v)
5620+static __inline__ void atomic_add(int i, atomic_t *v)
5621+{
5622+ int temp;
5623+
5624+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5625+ __asm__ __volatile__(
5626+ " .set mips3 \n"
5627+ "1: ll %0, %1 # atomic_add \n"
5628+#ifdef CONFIG_PAX_REFCOUNT
5629+ /* Exception on overflow. */
5630+ "2: add %0, %2 \n"
5631+#else
5632+ " addu %0, %2 \n"
5633+#endif
5634+ " sc %0, %1 \n"
5635+ " beqzl %0, 1b \n"
5636+#ifdef CONFIG_PAX_REFCOUNT
5637+ "3: \n"
5638+ _ASM_EXTABLE(2b, 3b)
5639+#endif
5640+ " .set mips0 \n"
5641+ : "=&r" (temp), "+m" (v->counter)
5642+ : "Ir" (i));
5643+ } else if (kernel_uses_llsc) {
5644+ __asm__ __volatile__(
5645+ " .set mips3 \n"
5646+ "1: ll %0, %1 # atomic_add \n"
5647+#ifdef CONFIG_PAX_REFCOUNT
5648+ /* Exception on overflow. */
5649+ "2: add %0, %2 \n"
5650+#else
5651+ " addu %0, %2 \n"
5652+#endif
5653+ " sc %0, %1 \n"
5654+ " beqz %0, 1b \n"
5655+#ifdef CONFIG_PAX_REFCOUNT
5656+ "3: \n"
5657+ _ASM_EXTABLE(2b, 3b)
5658+#endif
5659+ " .set mips0 \n"
5660+ : "=&r" (temp), "+m" (v->counter)
5661+ : "Ir" (i));
5662+ } else {
5663+ unsigned long flags;
5664+
5665+ raw_local_irq_save(flags);
5666+ __asm__ __volatile__(
5667+#ifdef CONFIG_PAX_REFCOUNT
5668+ /* Exception on overflow. */
5669+ "1: add %0, %1 \n"
5670+ "2: \n"
5671+ _ASM_EXTABLE(1b, 2b)
5672+#else
5673+ " addu %0, %1 \n"
5674+#endif
5675+ : "+r" (v->counter) : "Ir" (i));
5676+ raw_local_irq_restore(flags);
5677+ }
5678+}
5679+
5680+static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
5681 {
5682 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5683 int temp;
5684@@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
5685 *
5686 * Atomically subtracts @i from @v.
5687 */
5688-static __inline__ void atomic_sub(int i, atomic_t * v)
5689+static __inline__ void atomic_sub(int i, atomic_t *v)
5690+{
5691+ int temp;
5692+
5693+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5694+ __asm__ __volatile__(
5695+ " .set mips3 \n"
5696+ "1: ll %0, %1 # atomic64_sub \n"
5697+#ifdef CONFIG_PAX_REFCOUNT
5698+ /* Exception on overflow. */
5699+ "2: sub %0, %2 \n"
5700+#else
5701+ " subu %0, %2 \n"
5702+#endif
5703+ " sc %0, %1 \n"
5704+ " beqzl %0, 1b \n"
5705+#ifdef CONFIG_PAX_REFCOUNT
5706+ "3: \n"
5707+ _ASM_EXTABLE(2b, 3b)
5708+#endif
5709+ " .set mips0 \n"
5710+ : "=&r" (temp), "+m" (v->counter)
5711+ : "Ir" (i));
5712+ } else if (kernel_uses_llsc) {
5713+ __asm__ __volatile__(
5714+ " .set mips3 \n"
5715+ "1: ll %0, %1 # atomic64_sub \n"
5716+#ifdef CONFIG_PAX_REFCOUNT
5717+ /* Exception on overflow. */
5718+ "2: sub %0, %2 \n"
5719+#else
5720+ " subu %0, %2 \n"
5721+#endif
5722+ " sc %0, %1 \n"
5723+ " beqz %0, 1b \n"
5724+#ifdef CONFIG_PAX_REFCOUNT
5725+ "3: \n"
5726+ _ASM_EXTABLE(2b, 3b)
5727+#endif
5728+ " .set mips0 \n"
5729+ : "=&r" (temp), "+m" (v->counter)
5730+ : "Ir" (i));
5731+ } else {
5732+ unsigned long flags;
5733+
5734+ raw_local_irq_save(flags);
5735+ __asm__ __volatile__(
5736+#ifdef CONFIG_PAX_REFCOUNT
5737+ /* Exception on overflow. */
5738+ "1: sub %0, %1 \n"
5739+ "2: \n"
5740+ _ASM_EXTABLE(1b, 2b)
5741+#else
5742+ " subu %0, %1 \n"
5743+#endif
5744+ : "+r" (v->counter) : "Ir" (i));
5745+ raw_local_irq_restore(flags);
5746+ }
5747+}
5748+
5749+static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
5750 {
5751 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5752 int temp;
5753@@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
5754 /*
5755 * Same as above, but return the result value
5756 */
5757-static __inline__ int atomic_add_return(int i, atomic_t * v)
5758+static __inline__ int atomic_add_return(int i, atomic_t *v)
5759+{
5760+ int result;
5761+ int temp;
5762+
5763+ smp_mb__before_llsc();
5764+
5765+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5766+ __asm__ __volatile__(
5767+ " .set mips3 \n"
5768+ "1: ll %1, %2 # atomic_add_return \n"
5769+#ifdef CONFIG_PAX_REFCOUNT
5770+ "2: add %0, %1, %3 \n"
5771+#else
5772+ " addu %0, %1, %3 \n"
5773+#endif
5774+ " sc %0, %2 \n"
5775+ " beqzl %0, 1b \n"
5776+#ifdef CONFIG_PAX_REFCOUNT
5777+ " b 4f \n"
5778+ " .set noreorder \n"
5779+ "3: b 5f \n"
5780+ " move %0, %1 \n"
5781+ " .set reorder \n"
5782+ _ASM_EXTABLE(2b, 3b)
5783+#endif
5784+ "4: addu %0, %1, %3 \n"
5785+#ifdef CONFIG_PAX_REFCOUNT
5786+ "5: \n"
5787+#endif
5788+ " .set mips0 \n"
5789+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5790+ : "Ir" (i));
5791+ } else if (kernel_uses_llsc) {
5792+ __asm__ __volatile__(
5793+ " .set mips3 \n"
5794+ "1: ll %1, %2 # atomic_add_return \n"
5795+#ifdef CONFIG_PAX_REFCOUNT
5796+ "2: add %0, %1, %3 \n"
5797+#else
5798+ " addu %0, %1, %3 \n"
5799+#endif
5800+ " sc %0, %2 \n"
5801+ " bnez %0, 4f \n"
5802+ " b 1b \n"
5803+#ifdef CONFIG_PAX_REFCOUNT
5804+ " .set noreorder \n"
5805+ "3: b 5f \n"
5806+ " move %0, %1 \n"
5807+ " .set reorder \n"
5808+ _ASM_EXTABLE(2b, 3b)
5809+#endif
5810+ "4: addu %0, %1, %3 \n"
5811+#ifdef CONFIG_PAX_REFCOUNT
5812+ "5: \n"
5813+#endif
5814+ " .set mips0 \n"
5815+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5816+ : "Ir" (i));
5817+ } else {
5818+ unsigned long flags;
5819+
5820+ raw_local_irq_save(flags);
5821+ __asm__ __volatile__(
5822+ " lw %0, %1 \n"
5823+#ifdef CONFIG_PAX_REFCOUNT
5824+ /* Exception on overflow. */
5825+ "1: add %0, %2 \n"
5826+#else
5827+ " addu %0, %2 \n"
5828+#endif
5829+ " sw %0, %1 \n"
5830+#ifdef CONFIG_PAX_REFCOUNT
5831+ /* Note: Dest reg is not modified on overflow */
5832+ "2: \n"
5833+ _ASM_EXTABLE(1b, 2b)
5834+#endif
5835+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5836+ raw_local_irq_restore(flags);
5837+ }
5838+
5839+ smp_llsc_mb();
5840+
5841+ return result;
5842+}
5843+
5844+static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5845 {
5846 int result;
5847
5848@@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
5849 return result;
5850 }
5851
5852-static __inline__ int atomic_sub_return(int i, atomic_t * v)
5853+static __inline__ int atomic_sub_return(int i, atomic_t *v)
5854+{
5855+ int result;
5856+ int temp;
5857+
5858+ smp_mb__before_llsc();
5859+
5860+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5861+ __asm__ __volatile__(
5862+ " .set mips3 \n"
5863+ "1: ll %1, %2 # atomic_sub_return \n"
5864+#ifdef CONFIG_PAX_REFCOUNT
5865+ "2: sub %0, %1, %3 \n"
5866+#else
5867+ " subu %0, %1, %3 \n"
5868+#endif
5869+ " sc %0, %2 \n"
5870+ " beqzl %0, 1b \n"
5871+#ifdef CONFIG_PAX_REFCOUNT
5872+ " b 4f \n"
5873+ " .set noreorder \n"
5874+ "3: b 5f \n"
5875+ " move %0, %1 \n"
5876+ " .set reorder \n"
5877+ _ASM_EXTABLE(2b, 3b)
5878+#endif
5879+ "4: subu %0, %1, %3 \n"
5880+#ifdef CONFIG_PAX_REFCOUNT
5881+ "5: \n"
5882+#endif
5883+ " .set mips0 \n"
5884+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
5885+ : "Ir" (i), "m" (v->counter)
5886+ : "memory");
5887+ } else if (kernel_uses_llsc) {
5888+ __asm__ __volatile__(
5889+ " .set mips3 \n"
5890+ "1: ll %1, %2 # atomic_sub_return \n"
5891+#ifdef CONFIG_PAX_REFCOUNT
5892+ "2: sub %0, %1, %3 \n"
5893+#else
5894+ " subu %0, %1, %3 \n"
5895+#endif
5896+ " sc %0, %2 \n"
5897+ " bnez %0, 4f \n"
5898+ " b 1b \n"
5899+#ifdef CONFIG_PAX_REFCOUNT
5900+ " .set noreorder \n"
5901+ "3: b 5f \n"
5902+ " move %0, %1 \n"
5903+ " .set reorder \n"
5904+ _ASM_EXTABLE(2b, 3b)
5905+#endif
5906+ "4: subu %0, %1, %3 \n"
5907+#ifdef CONFIG_PAX_REFCOUNT
5908+ "5: \n"
5909+#endif
5910+ " .set mips0 \n"
5911+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5912+ : "Ir" (i));
5913+ } else {
5914+ unsigned long flags;
5915+
5916+ raw_local_irq_save(flags);
5917+ __asm__ __volatile__(
5918+ " lw %0, %1 \n"
5919+#ifdef CONFIG_PAX_REFCOUNT
5920+ /* Exception on overflow. */
5921+ "1: sub %0, %2 \n"
5922+#else
5923+ " subu %0, %2 \n"
5924+#endif
5925+ " sw %0, %1 \n"
5926+#ifdef CONFIG_PAX_REFCOUNT
5927+ /* Note: Dest reg is not modified on overflow */
5928+ "2: \n"
5929+ _ASM_EXTABLE(1b, 2b)
5930+#endif
5931+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5932+ raw_local_irq_restore(flags);
5933+ }
5934+
5935+ smp_llsc_mb();
5936+
5937+ return result;
5938+}
5939+static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
5940 {
5941 int result;
5942
5943@@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
5944 * Atomically test @v and subtract @i if @v is greater or equal than @i.
5945 * The function returns the old value of @v minus @i.
5946 */
5947-static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5948+static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
5949 {
5950 int result;
5951
5952@@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5953 return result;
5954 }
5955
5956-#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5957-#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
5958+static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
5959+{
5960+ return cmpxchg(&v->counter, old, new);
5961+}
5962+
5963+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
5964+ int new)
5965+{
5966+ return cmpxchg(&(v->counter), old, new);
5967+}
5968+
5969+static inline int atomic_xchg(atomic_t *v, int new)
5970+{
5971+ return xchg(&v->counter, new);
5972+}
5973+
5974+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5975+{
5976+ return xchg(&(v->counter), new);
5977+}
5978
5979 /**
5980 * __atomic_add_unless - add unless the number is a given value
5981@@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5982
5983 #define atomic_dec_return(v) atomic_sub_return(1, (v))
5984 #define atomic_inc_return(v) atomic_add_return(1, (v))
5985+static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5986+{
5987+ return atomic_add_return_unchecked(1, v);
5988+}
5989
5990 /*
5991 * atomic_sub_and_test - subtract value from variable and test result
5992@@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5993 * other cases.
5994 */
5995 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5996+static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5997+{
5998+ return atomic_add_return_unchecked(1, v) == 0;
5999+}
6000
6001 /*
6002 * atomic_dec_and_test - decrement by 1 and test
6003@@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6004 * Atomically increments @v by 1.
6005 */
6006 #define atomic_inc(v) atomic_add(1, (v))
6007+static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
6008+{
6009+ atomic_add_unchecked(1, v);
6010+}
6011
6012 /*
6013 * atomic_dec - decrement and test
6014@@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6015 * Atomically decrements @v by 1.
6016 */
6017 #define atomic_dec(v) atomic_sub(1, (v))
6018+static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
6019+{
6020+ atomic_sub_unchecked(1, v);
6021+}
6022
6023 /*
6024 * atomic_add_negative - add and test if negative
6025@@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6026 * @v: pointer of type atomic64_t
6027 *
6028 */
6029-#define atomic64_read(v) (*(volatile long *)&(v)->counter)
6030+static inline long atomic64_read(const atomic64_t *v)
6031+{
6032+ return (*(volatile const long *) &v->counter);
6033+}
6034+
6035+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
6036+{
6037+ return (*(volatile const long *) &v->counter);
6038+}
6039
6040 /*
6041 * atomic64_set - set atomic variable
6042 * @v: pointer of type atomic64_t
6043 * @i: required value
6044 */
6045-#define atomic64_set(v, i) ((v)->counter = (i))
6046+static inline void atomic64_set(atomic64_t *v, long i)
6047+{
6048+ v->counter = i;
6049+}
6050+
6051+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
6052+{
6053+ v->counter = i;
6054+}
6055
6056 /*
6057 * atomic64_add - add integer to atomic variable
6058@@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6059 *
6060 * Atomically adds @i to @v.
6061 */
6062-static __inline__ void atomic64_add(long i, atomic64_t * v)
6063+static __inline__ void atomic64_add(long i, atomic64_t *v)
6064+{
6065+ long temp;
6066+
6067+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6068+ __asm__ __volatile__(
6069+ " .set mips3 \n"
6070+ "1: lld %0, %1 # atomic64_add \n"
6071+#ifdef CONFIG_PAX_REFCOUNT
6072+ /* Exception on overflow. */
6073+ "2: dadd %0, %2 \n"
6074+#else
6075+ " daddu %0, %2 \n"
6076+#endif
6077+ " scd %0, %1 \n"
6078+ " beqzl %0, 1b \n"
6079+#ifdef CONFIG_PAX_REFCOUNT
6080+ "3: \n"
6081+ _ASM_EXTABLE(2b, 3b)
6082+#endif
6083+ " .set mips0 \n"
6084+ : "=&r" (temp), "+m" (v->counter)
6085+ : "Ir" (i));
6086+ } else if (kernel_uses_llsc) {
6087+ __asm__ __volatile__(
6088+ " .set mips3 \n"
6089+ "1: lld %0, %1 # atomic64_add \n"
6090+#ifdef CONFIG_PAX_REFCOUNT
6091+ /* Exception on overflow. */
6092+ "2: dadd %0, %2 \n"
6093+#else
6094+ " daddu %0, %2 \n"
6095+#endif
6096+ " scd %0, %1 \n"
6097+ " beqz %0, 1b \n"
6098+#ifdef CONFIG_PAX_REFCOUNT
6099+ "3: \n"
6100+ _ASM_EXTABLE(2b, 3b)
6101+#endif
6102+ " .set mips0 \n"
6103+ : "=&r" (temp), "+m" (v->counter)
6104+ : "Ir" (i));
6105+ } else {
6106+ unsigned long flags;
6107+
6108+ raw_local_irq_save(flags);
6109+ __asm__ __volatile__(
6110+#ifdef CONFIG_PAX_REFCOUNT
6111+ /* Exception on overflow. */
6112+ "1: dadd %0, %1 \n"
6113+ "2: \n"
6114+ _ASM_EXTABLE(1b, 2b)
6115+#else
6116+ " daddu %0, %1 \n"
6117+#endif
6118+ : "+r" (v->counter) : "Ir" (i));
6119+ raw_local_irq_restore(flags);
6120+ }
6121+}
6122+static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
6123 {
6124 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6125 long temp;
6126@@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
6127 *
6128 * Atomically subtracts @i from @v.
6129 */
6130-static __inline__ void atomic64_sub(long i, atomic64_t * v)
6131+static __inline__ void atomic64_sub(long i, atomic64_t *v)
6132+{
6133+ long temp;
6134+
6135+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6136+ __asm__ __volatile__(
6137+ " .set mips3 \n"
6138+ "1: lld %0, %1 # atomic64_sub \n"
6139+#ifdef CONFIG_PAX_REFCOUNT
6140+ /* Exception on overflow. */
6141+ "2: dsub %0, %2 \n"
6142+#else
6143+ " dsubu %0, %2 \n"
6144+#endif
6145+ " scd %0, %1 \n"
6146+ " beqzl %0, 1b \n"
6147+#ifdef CONFIG_PAX_REFCOUNT
6148+ "3: \n"
6149+ _ASM_EXTABLE(2b, 3b)
6150+#endif
6151+ " .set mips0 \n"
6152+ : "=&r" (temp), "+m" (v->counter)
6153+ : "Ir" (i));
6154+ } else if (kernel_uses_llsc) {
6155+ __asm__ __volatile__(
6156+ " .set mips3 \n"
6157+ "1: lld %0, %1 # atomic64_sub \n"
6158+#ifdef CONFIG_PAX_REFCOUNT
6159+ /* Exception on overflow. */
6160+ "2: dsub %0, %2 \n"
6161+#else
6162+ " dsubu %0, %2 \n"
6163+#endif
6164+ " scd %0, %1 \n"
6165+ " beqz %0, 1b \n"
6166+#ifdef CONFIG_PAX_REFCOUNT
6167+ "3: \n"
6168+ _ASM_EXTABLE(2b, 3b)
6169+#endif
6170+ " .set mips0 \n"
6171+ : "=&r" (temp), "+m" (v->counter)
6172+ : "Ir" (i));
6173+ } else {
6174+ unsigned long flags;
6175+
6176+ raw_local_irq_save(flags);
6177+ __asm__ __volatile__(
6178+#ifdef CONFIG_PAX_REFCOUNT
6179+ /* Exception on overflow. */
6180+ "1: dsub %0, %1 \n"
6181+ "2: \n"
6182+ _ASM_EXTABLE(1b, 2b)
6183+#else
6184+ " dsubu %0, %1 \n"
6185+#endif
6186+ : "+r" (v->counter) : "Ir" (i));
6187+ raw_local_irq_restore(flags);
6188+ }
6189+}
6190+
6191+static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
6192 {
6193 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6194 long temp;
6195@@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
6196 /*
6197 * Same as above, but return the result value
6198 */
6199-static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6200+static __inline__ long atomic64_add_return(long i, atomic64_t *v)
6201+{
6202+ long result;
6203+ long temp;
6204+
6205+ smp_mb__before_llsc();
6206+
6207+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6208+ __asm__ __volatile__(
6209+ " .set mips3 \n"
6210+ "1: lld %1, %2 # atomic64_add_return \n"
6211+#ifdef CONFIG_PAX_REFCOUNT
6212+ "2: dadd %0, %1, %3 \n"
6213+#else
6214+ " daddu %0, %1, %3 \n"
6215+#endif
6216+ " scd %0, %2 \n"
6217+ " beqzl %0, 1b \n"
6218+#ifdef CONFIG_PAX_REFCOUNT
6219+ " b 4f \n"
6220+ " .set noreorder \n"
6221+ "3: b 5f \n"
6222+ " move %0, %1 \n"
6223+ " .set reorder \n"
6224+ _ASM_EXTABLE(2b, 3b)
6225+#endif
6226+ "4: daddu %0, %1, %3 \n"
6227+#ifdef CONFIG_PAX_REFCOUNT
6228+ "5: \n"
6229+#endif
6230+ " .set mips0 \n"
6231+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6232+ : "Ir" (i));
6233+ } else if (kernel_uses_llsc) {
6234+ __asm__ __volatile__(
6235+ " .set mips3 \n"
6236+ "1: lld %1, %2 # atomic64_add_return \n"
6237+#ifdef CONFIG_PAX_REFCOUNT
6238+ "2: dadd %0, %1, %3 \n"
6239+#else
6240+ " daddu %0, %1, %3 \n"
6241+#endif
6242+ " scd %0, %2 \n"
6243+ " bnez %0, 4f \n"
6244+ " b 1b \n"
6245+#ifdef CONFIG_PAX_REFCOUNT
6246+ " .set noreorder \n"
6247+ "3: b 5f \n"
6248+ " move %0, %1 \n"
6249+ " .set reorder \n"
6250+ _ASM_EXTABLE(2b, 3b)
6251+#endif
6252+ "4: daddu %0, %1, %3 \n"
6253+#ifdef CONFIG_PAX_REFCOUNT
6254+ "5: \n"
6255+#endif
6256+ " .set mips0 \n"
6257+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6258+ : "Ir" (i), "m" (v->counter)
6259+ : "memory");
6260+ } else {
6261+ unsigned long flags;
6262+
6263+ raw_local_irq_save(flags);
6264+ __asm__ __volatile__(
6265+ " ld %0, %1 \n"
6266+#ifdef CONFIG_PAX_REFCOUNT
6267+ /* Exception on overflow. */
6268+ "1: dadd %0, %2 \n"
6269+#else
6270+ " daddu %0, %2 \n"
6271+#endif
6272+ " sd %0, %1 \n"
6273+#ifdef CONFIG_PAX_REFCOUNT
6274+ /* Note: Dest reg is not modified on overflow */
6275+ "2: \n"
6276+ _ASM_EXTABLE(1b, 2b)
6277+#endif
6278+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6279+ raw_local_irq_restore(flags);
6280+ }
6281+
6282+ smp_llsc_mb();
6283+
6284+ return result;
6285+}
6286+static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6287 {
6288 long result;
6289
6290@@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6291 return result;
6292 }
6293
6294-static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6295+static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6296+{
6297+ long result;
6298+ long temp;
6299+
6300+ smp_mb__before_llsc();
6301+
6302+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6303+ long temp;
6304+
6305+ __asm__ __volatile__(
6306+ " .set mips3 \n"
6307+ "1: lld %1, %2 # atomic64_sub_return \n"
6308+#ifdef CONFIG_PAX_REFCOUNT
6309+ "2: dsub %0, %1, %3 \n"
6310+#else
6311+ " dsubu %0, %1, %3 \n"
6312+#endif
6313+ " scd %0, %2 \n"
6314+ " beqzl %0, 1b \n"
6315+#ifdef CONFIG_PAX_REFCOUNT
6316+ " b 4f \n"
6317+ " .set noreorder \n"
6318+ "3: b 5f \n"
6319+ " move %0, %1 \n"
6320+ " .set reorder \n"
6321+ _ASM_EXTABLE(2b, 3b)
6322+#endif
6323+ "4: dsubu %0, %1, %3 \n"
6324+#ifdef CONFIG_PAX_REFCOUNT
6325+ "5: \n"
6326+#endif
6327+ " .set mips0 \n"
6328+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6329+ : "Ir" (i), "m" (v->counter)
6330+ : "memory");
6331+ } else if (kernel_uses_llsc) {
6332+ __asm__ __volatile__(
6333+ " .set mips3 \n"
6334+ "1: lld %1, %2 # atomic64_sub_return \n"
6335+#ifdef CONFIG_PAX_REFCOUNT
6336+ "2: dsub %0, %1, %3 \n"
6337+#else
6338+ " dsubu %0, %1, %3 \n"
6339+#endif
6340+ " scd %0, %2 \n"
6341+ " bnez %0, 4f \n"
6342+ " b 1b \n"
6343+#ifdef CONFIG_PAX_REFCOUNT
6344+ " .set noreorder \n"
6345+ "3: b 5f \n"
6346+ " move %0, %1 \n"
6347+ " .set reorder \n"
6348+ _ASM_EXTABLE(2b, 3b)
6349+#endif
6350+ "4: dsubu %0, %1, %3 \n"
6351+#ifdef CONFIG_PAX_REFCOUNT
6352+ "5: \n"
6353+#endif
6354+ " .set mips0 \n"
6355+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6356+ : "Ir" (i), "m" (v->counter)
6357+ : "memory");
6358+ } else {
6359+ unsigned long flags;
6360+
6361+ raw_local_irq_save(flags);
6362+ __asm__ __volatile__(
6363+ " ld %0, %1 \n"
6364+#ifdef CONFIG_PAX_REFCOUNT
6365+ /* Exception on overflow. */
6366+ "1: dsub %0, %2 \n"
6367+#else
6368+ " dsubu %0, %2 \n"
6369+#endif
6370+ " sd %0, %1 \n"
6371+#ifdef CONFIG_PAX_REFCOUNT
6372+ /* Note: Dest reg is not modified on overflow */
6373+ "2: \n"
6374+ _ASM_EXTABLE(1b, 2b)
6375+#endif
6376+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6377+ raw_local_irq_restore(flags);
6378+ }
6379+
6380+ smp_llsc_mb();
6381+
6382+ return result;
6383+}
6384+
6385+static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6386 {
6387 long result;
6388
6389@@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6390 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6391 * The function returns the old value of @v minus @i.
6392 */
6393-static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6394+static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6395 {
6396 long result;
6397
6398@@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6399 return result;
6400 }
6401
6402-#define atomic64_cmpxchg(v, o, n) \
6403- ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6404-#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6405+static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6406+{
6407+ return cmpxchg(&v->counter, old, new);
6408+}
6409+
6410+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6411+ long new)
6412+{
6413+ return cmpxchg(&(v->counter), old, new);
6414+}
6415+
6416+static inline long atomic64_xchg(atomic64_t *v, long new)
6417+{
6418+ return xchg(&v->counter, new);
6419+}
6420+
6421+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6422+{
6423+ return xchg(&(v->counter), new);
6424+}
6425
6426 /**
6427 * atomic64_add_unless - add unless the number is a given value
6428@@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6429
6430 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6431 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6432+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6433
6434 /*
6435 * atomic64_sub_and_test - subtract value from variable and test result
6436@@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6437 * other cases.
6438 */
6439 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6440+#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6441
6442 /*
6443 * atomic64_dec_and_test - decrement by 1 and test
6444@@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6445 * Atomically increments @v by 1.
6446 */
6447 #define atomic64_inc(v) atomic64_add(1, (v))
6448+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6449
6450 /*
6451 * atomic64_dec - decrement and test
6452@@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6453 * Atomically decrements @v by 1.
6454 */
6455 #define atomic64_dec(v) atomic64_sub(1, (v))
6456+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6457
6458 /*
6459 * atomic64_add_negative - add and test if negative
6460diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6461index b4db69f..8f3b093 100644
6462--- a/arch/mips/include/asm/cache.h
6463+++ b/arch/mips/include/asm/cache.h
6464@@ -9,10 +9,11 @@
6465 #ifndef _ASM_CACHE_H
6466 #define _ASM_CACHE_H
6467
6468+#include <linux/const.h>
6469 #include <kmalloc.h>
6470
6471 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6472-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6473+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6474
6475 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6476 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6477diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6478index d414405..6bb4ba2 100644
6479--- a/arch/mips/include/asm/elf.h
6480+++ b/arch/mips/include/asm/elf.h
6481@@ -398,13 +398,16 @@ extern const char *__elf_platform;
6482 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6483 #endif
6484
6485+#ifdef CONFIG_PAX_ASLR
6486+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6487+
6488+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6489+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6490+#endif
6491+
6492 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6493 struct linux_binprm;
6494 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6495 int uses_interp);
6496
6497-struct mm_struct;
6498-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6499-#define arch_randomize_brk arch_randomize_brk
6500-
6501 #endif /* _ASM_ELF_H */
6502diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6503index c1f6afa..38cc6e9 100644
6504--- a/arch/mips/include/asm/exec.h
6505+++ b/arch/mips/include/asm/exec.h
6506@@ -12,6 +12,6 @@
6507 #ifndef _ASM_EXEC_H
6508 #define _ASM_EXEC_H
6509
6510-extern unsigned long arch_align_stack(unsigned long sp);
6511+#define arch_align_stack(x) ((x) & ~0xfUL)
6512
6513 #endif /* _ASM_EXEC_H */
6514diff --git a/arch/mips/include/asm/hw_irq.h b/arch/mips/include/asm/hw_irq.h
6515index 9e8ef59..1139d6b 100644
6516--- a/arch/mips/include/asm/hw_irq.h
6517+++ b/arch/mips/include/asm/hw_irq.h
6518@@ -10,7 +10,7 @@
6519
6520 #include <linux/atomic.h>
6521
6522-extern atomic_t irq_err_count;
6523+extern atomic_unchecked_t irq_err_count;
6524
6525 /*
6526 * interrupt-retrigger: NOP for now. This may not be appropriate for all
6527diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6528index d44622c..64990d2 100644
6529--- a/arch/mips/include/asm/local.h
6530+++ b/arch/mips/include/asm/local.h
6531@@ -12,15 +12,25 @@ typedef struct
6532 atomic_long_t a;
6533 } local_t;
6534
6535+typedef struct {
6536+ atomic_long_unchecked_t a;
6537+} local_unchecked_t;
6538+
6539 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6540
6541 #define local_read(l) atomic_long_read(&(l)->a)
6542+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6543 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6544+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6545
6546 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6547+#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6548 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6549+#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6550 #define local_inc(l) atomic_long_inc(&(l)->a)
6551+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6552 #define local_dec(l) atomic_long_dec(&(l)->a)
6553+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6554
6555 /*
6556 * Same as above, but return the result value
6557@@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6558 return result;
6559 }
6560
6561+static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6562+{
6563+ unsigned long result;
6564+
6565+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6566+ unsigned long temp;
6567+
6568+ __asm__ __volatile__(
6569+ " .set mips3 \n"
6570+ "1:" __LL "%1, %2 # local_add_return \n"
6571+ " addu %0, %1, %3 \n"
6572+ __SC "%0, %2 \n"
6573+ " beqzl %0, 1b \n"
6574+ " addu %0, %1, %3 \n"
6575+ " .set mips0 \n"
6576+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6577+ : "Ir" (i), "m" (l->a.counter)
6578+ : "memory");
6579+ } else if (kernel_uses_llsc) {
6580+ unsigned long temp;
6581+
6582+ __asm__ __volatile__(
6583+ " .set mips3 \n"
6584+ "1:" __LL "%1, %2 # local_add_return \n"
6585+ " addu %0, %1, %3 \n"
6586+ __SC "%0, %2 \n"
6587+ " beqz %0, 1b \n"
6588+ " addu %0, %1, %3 \n"
6589+ " .set mips0 \n"
6590+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6591+ : "Ir" (i), "m" (l->a.counter)
6592+ : "memory");
6593+ } else {
6594+ unsigned long flags;
6595+
6596+ local_irq_save(flags);
6597+ result = l->a.counter;
6598+ result += i;
6599+ l->a.counter = result;
6600+ local_irq_restore(flags);
6601+ }
6602+
6603+ return result;
6604+}
6605+
6606 static __inline__ long local_sub_return(long i, local_t * l)
6607 {
6608 unsigned long result;
6609@@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6610
6611 #define local_cmpxchg(l, o, n) \
6612 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6613+#define local_cmpxchg_unchecked(l, o, n) \
6614+ ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6615 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6616
6617 /**
6618diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6619index 5e08bcc..cfedefc 100644
6620--- a/arch/mips/include/asm/page.h
6621+++ b/arch/mips/include/asm/page.h
6622@@ -120,7 +120,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6623 #ifdef CONFIG_CPU_MIPS32
6624 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6625 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6626- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6627+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6628 #else
6629 typedef struct { unsigned long long pte; } pte_t;
6630 #define pte_val(x) ((x).pte)
6631diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6632index b336037..5b874cc 100644
6633--- a/arch/mips/include/asm/pgalloc.h
6634+++ b/arch/mips/include/asm/pgalloc.h
6635@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6636 {
6637 set_pud(pud, __pud((unsigned long)pmd));
6638 }
6639+
6640+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6641+{
6642+ pud_populate(mm, pud, pmd);
6643+}
6644 #endif
6645
6646 /*
6647diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtable.h
6648index 008324d..f67c239 100644
6649--- a/arch/mips/include/asm/pgtable.h
6650+++ b/arch/mips/include/asm/pgtable.h
6651@@ -20,6 +20,9 @@
6652 #include <asm/io.h>
6653 #include <asm/pgtable-bits.h>
6654
6655+#define ktla_ktva(addr) (addr)
6656+#define ktva_ktla(addr) (addr)
6657+
6658 struct mm_struct;
6659 struct vm_area_struct;
6660
6661diff --git a/arch/mips/include/asm/smtc_proc.h b/arch/mips/include/asm/smtc_proc.h
6662index 25da651..ae2a259 100644
6663--- a/arch/mips/include/asm/smtc_proc.h
6664+++ b/arch/mips/include/asm/smtc_proc.h
6665@@ -18,6 +18,6 @@ extern struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6666
6667 /* Count of number of recoveries of "stolen" FPU access rights on 34K */
6668
6669-extern atomic_t smtc_fpu_recoveries;
6670+extern atomic_unchecked_t smtc_fpu_recoveries;
6671
6672 #endif /* __ASM_SMTC_PROC_H */
6673diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6674index 24846f9..61c49f0 100644
6675--- a/arch/mips/include/asm/thread_info.h
6676+++ b/arch/mips/include/asm/thread_info.h
6677@@ -116,6 +116,8 @@ static inline struct thread_info *current_thread_info(void)
6678 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
6679 #define TIF_SYSCALL_TRACEPOINT 26 /* syscall tracepoint instrumentation */
6680 #define TIF_32BIT_FPREGS 27 /* 32-bit floating point registers */
6681+/* li takes a 32bit immediate */
6682+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
6683 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
6684
6685 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6686@@ -134,13 +136,14 @@ static inline struct thread_info *current_thread_info(void)
6687 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
6688 #define _TIF_32BIT_FPREGS (1<<TIF_32BIT_FPREGS)
6689 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6690+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6691
6692 #define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6693- _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6694+ _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6695
6696 /* work to do in syscall_trace_leave() */
6697 #define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6698- _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6699+ _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6700
6701 /* work to do on interrupt/exception return */
6702 #define _TIF_WORK_MASK \
6703@@ -148,7 +151,7 @@ static inline struct thread_info *current_thread_info(void)
6704 /* work to do on any return to u-space */
6705 #define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6706 _TIF_WORK_SYSCALL_EXIT | \
6707- _TIF_SYSCALL_TRACEPOINT)
6708+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6709
6710 /*
6711 * We stash processor id into a COP0 register to retrieve it fast
6712diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
6713index f3fa375..3af6637 100644
6714--- a/arch/mips/include/asm/uaccess.h
6715+++ b/arch/mips/include/asm/uaccess.h
6716@@ -128,6 +128,7 @@ extern u64 __ua_limit;
6717 __ok == 0; \
6718 })
6719
6720+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
6721 #define access_ok(type, addr, size) \
6722 likely(__access_ok((addr), (size), __access_mask))
6723
6724diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6725index 1188e00..41cf144 100644
6726--- a/arch/mips/kernel/binfmt_elfn32.c
6727+++ b/arch/mips/kernel/binfmt_elfn32.c
6728@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6729 #undef ELF_ET_DYN_BASE
6730 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6731
6732+#ifdef CONFIG_PAX_ASLR
6733+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6734+
6735+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6736+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6737+#endif
6738+
6739 #include <asm/processor.h>
6740 #include <linux/module.h>
6741 #include <linux/elfcore.h>
6742diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6743index 7faf5f2..f3d3cf4 100644
6744--- a/arch/mips/kernel/binfmt_elfo32.c
6745+++ b/arch/mips/kernel/binfmt_elfo32.c
6746@@ -70,6 +70,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6747 #undef ELF_ET_DYN_BASE
6748 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6749
6750+#ifdef CONFIG_PAX_ASLR
6751+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6752+
6753+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6754+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6755+#endif
6756+
6757 #include <asm/processor.h>
6758
6759 /*
6760diff --git a/arch/mips/kernel/i8259.c b/arch/mips/kernel/i8259.c
6761index 2b91fe8..fe4f6b4 100644
6762--- a/arch/mips/kernel/i8259.c
6763+++ b/arch/mips/kernel/i8259.c
6764@@ -205,7 +205,7 @@ spurious_8259A_irq:
6765 printk(KERN_DEBUG "spurious 8259A interrupt: IRQ%d.\n", irq);
6766 spurious_irq_mask |= irqmask;
6767 }
6768- atomic_inc(&irq_err_count);
6769+ atomic_inc_unchecked(&irq_err_count);
6770 /*
6771 * Theoretically we do not have to handle this IRQ,
6772 * but in Linux this does not cause problems and is
6773diff --git a/arch/mips/kernel/irq-gt641xx.c b/arch/mips/kernel/irq-gt641xx.c
6774index 44a1f79..2bd6aa3 100644
6775--- a/arch/mips/kernel/irq-gt641xx.c
6776+++ b/arch/mips/kernel/irq-gt641xx.c
6777@@ -110,7 +110,7 @@ void gt641xx_irq_dispatch(void)
6778 }
6779 }
6780
6781- atomic_inc(&irq_err_count);
6782+ atomic_inc_unchecked(&irq_err_count);
6783 }
6784
6785 void __init gt641xx_irq_init(void)
6786diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
6787index d1fea7a..2e591b0 100644
6788--- a/arch/mips/kernel/irq.c
6789+++ b/arch/mips/kernel/irq.c
6790@@ -77,17 +77,17 @@ void ack_bad_irq(unsigned int irq)
6791 printk("unexpected IRQ # %d\n", irq);
6792 }
6793
6794-atomic_t irq_err_count;
6795+atomic_unchecked_t irq_err_count;
6796
6797 int arch_show_interrupts(struct seq_file *p, int prec)
6798 {
6799- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
6800+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
6801 return 0;
6802 }
6803
6804 asmlinkage void spurious_interrupt(void)
6805 {
6806- atomic_inc(&irq_err_count);
6807+ atomic_inc_unchecked(&irq_err_count);
6808 }
6809
6810 void __init init_IRQ(void)
6811@@ -110,7 +110,10 @@ void __init init_IRQ(void)
6812 #endif
6813 }
6814
6815+
6816 #ifdef DEBUG_STACKOVERFLOW
6817+extern void gr_handle_kernel_exploit(void);
6818+
6819 static inline void check_stack_overflow(void)
6820 {
6821 unsigned long sp;
6822@@ -126,6 +129,7 @@ static inline void check_stack_overflow(void)
6823 printk("do_IRQ: stack overflow: %ld\n",
6824 sp - sizeof(struct thread_info));
6825 dump_stack();
6826+ gr_handle_kernel_exploit();
6827 }
6828 }
6829 #else
6830diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6831index 6ae540e..b7396dc 100644
6832--- a/arch/mips/kernel/process.c
6833+++ b/arch/mips/kernel/process.c
6834@@ -562,15 +562,3 @@ unsigned long get_wchan(struct task_struct *task)
6835 out:
6836 return pc;
6837 }
6838-
6839-/*
6840- * Don't forget that the stack pointer must be aligned on a 8 bytes
6841- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6842- */
6843-unsigned long arch_align_stack(unsigned long sp)
6844-{
6845- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6846- sp -= get_random_int() & ~PAGE_MASK;
6847-
6848- return sp & ALMASK;
6849-}
6850diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6851index 7da9b76..21578be 100644
6852--- a/arch/mips/kernel/ptrace.c
6853+++ b/arch/mips/kernel/ptrace.c
6854@@ -658,6 +658,10 @@ long arch_ptrace(struct task_struct *child, long request,
6855 return ret;
6856 }
6857
6858+#ifdef CONFIG_GRKERNSEC_SETXID
6859+extern void gr_delayed_cred_worker(void);
6860+#endif
6861+
6862 /*
6863 * Notification of system call entry/exit
6864 * - triggered by current->work.syscall_trace
6865@@ -674,6 +678,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
6866 tracehook_report_syscall_entry(regs))
6867 ret = -1;
6868
6869+#ifdef CONFIG_GRKERNSEC_SETXID
6870+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6871+ gr_delayed_cred_worker();
6872+#endif
6873+
6874 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6875 trace_sys_enter(regs, regs->regs[2]);
6876
6877diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
6878index 07fc524..b9d7f28 100644
6879--- a/arch/mips/kernel/reset.c
6880+++ b/arch/mips/kernel/reset.c
6881@@ -13,6 +13,7 @@
6882 #include <linux/reboot.h>
6883
6884 #include <asm/reboot.h>
6885+#include <asm/bug.h>
6886
6887 /*
6888 * Urgs ... Too many MIPS machines to handle this in a generic way.
6889@@ -29,16 +30,19 @@ void machine_restart(char *command)
6890 {
6891 if (_machine_restart)
6892 _machine_restart(command);
6893+ BUG();
6894 }
6895
6896 void machine_halt(void)
6897 {
6898 if (_machine_halt)
6899 _machine_halt();
6900+ BUG();
6901 }
6902
6903 void machine_power_off(void)
6904 {
6905 if (pm_power_off)
6906 pm_power_off();
6907+ BUG();
6908 }
6909diff --git a/arch/mips/kernel/smtc-proc.c b/arch/mips/kernel/smtc-proc.c
6910index c10aa84..9ec2e60 100644
6911--- a/arch/mips/kernel/smtc-proc.c
6912+++ b/arch/mips/kernel/smtc-proc.c
6913@@ -31,7 +31,7 @@ unsigned long selfipis[NR_CPUS];
6914
6915 struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6916
6917-atomic_t smtc_fpu_recoveries;
6918+atomic_unchecked_t smtc_fpu_recoveries;
6919
6920 static int smtc_proc_show(struct seq_file *m, void *v)
6921 {
6922@@ -48,7 +48,7 @@ static int smtc_proc_show(struct seq_file *m, void *v)
6923 for(i = 0; i < NR_CPUS; i++)
6924 seq_printf(m, "%d: %ld\n", i, smtc_cpu_stats[i].selfipis);
6925 seq_printf(m, "%d Recoveries of \"stolen\" FPU\n",
6926- atomic_read(&smtc_fpu_recoveries));
6927+ atomic_read_unchecked(&smtc_fpu_recoveries));
6928 return 0;
6929 }
6930
6931@@ -73,7 +73,7 @@ void init_smtc_stats(void)
6932 smtc_cpu_stats[i].selfipis = 0;
6933 }
6934
6935- atomic_set(&smtc_fpu_recoveries, 0);
6936+ atomic_set_unchecked(&smtc_fpu_recoveries, 0);
6937
6938 proc_create("smtc", 0444, NULL, &smtc_proc_fops);
6939 }
6940diff --git a/arch/mips/kernel/smtc.c b/arch/mips/kernel/smtc.c
6941index dfc1b91..11a2c07 100644
6942--- a/arch/mips/kernel/smtc.c
6943+++ b/arch/mips/kernel/smtc.c
6944@@ -1359,7 +1359,7 @@ void smtc_soft_dump(void)
6945 }
6946 smtc_ipi_qdump();
6947 printk("%d Recoveries of \"stolen\" FPU\n",
6948- atomic_read(&smtc_fpu_recoveries));
6949+ atomic_read_unchecked(&smtc_fpu_recoveries));
6950 }
6951
6952
6953diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
6954index c24ad5f..9983ab2 100644
6955--- a/arch/mips/kernel/sync-r4k.c
6956+++ b/arch/mips/kernel/sync-r4k.c
6957@@ -20,8 +20,8 @@
6958 #include <asm/mipsregs.h>
6959
6960 static atomic_t count_start_flag = ATOMIC_INIT(0);
6961-static atomic_t count_count_start = ATOMIC_INIT(0);
6962-static atomic_t count_count_stop = ATOMIC_INIT(0);
6963+static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
6964+static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
6965 static atomic_t count_reference = ATOMIC_INIT(0);
6966
6967 #define COUNTON 100
6968@@ -68,13 +68,13 @@ void synchronise_count_master(int cpu)
6969
6970 for (i = 0; i < NR_LOOPS; i++) {
6971 /* slaves loop on '!= 2' */
6972- while (atomic_read(&count_count_start) != 1)
6973+ while (atomic_read_unchecked(&count_count_start) != 1)
6974 mb();
6975- atomic_set(&count_count_stop, 0);
6976+ atomic_set_unchecked(&count_count_stop, 0);
6977 smp_wmb();
6978
6979 /* this lets the slaves write their count register */
6980- atomic_inc(&count_count_start);
6981+ atomic_inc_unchecked(&count_count_start);
6982
6983 /*
6984 * Everyone initialises count in the last loop:
6985@@ -85,11 +85,11 @@ void synchronise_count_master(int cpu)
6986 /*
6987 * Wait for all slaves to leave the synchronization point:
6988 */
6989- while (atomic_read(&count_count_stop) != 1)
6990+ while (atomic_read_unchecked(&count_count_stop) != 1)
6991 mb();
6992- atomic_set(&count_count_start, 0);
6993+ atomic_set_unchecked(&count_count_start, 0);
6994 smp_wmb();
6995- atomic_inc(&count_count_stop);
6996+ atomic_inc_unchecked(&count_count_stop);
6997 }
6998 /* Arrange for an interrupt in a short while */
6999 write_c0_compare(read_c0_count() + COUNTON);
7000@@ -130,8 +130,8 @@ void synchronise_count_slave(int cpu)
7001 initcount = atomic_read(&count_reference);
7002
7003 for (i = 0; i < NR_LOOPS; i++) {
7004- atomic_inc(&count_count_start);
7005- while (atomic_read(&count_count_start) != 2)
7006+ atomic_inc_unchecked(&count_count_start);
7007+ while (atomic_read_unchecked(&count_count_start) != 2)
7008 mb();
7009
7010 /*
7011@@ -140,8 +140,8 @@ void synchronise_count_slave(int cpu)
7012 if (i == NR_LOOPS-1)
7013 write_c0_count(initcount);
7014
7015- atomic_inc(&count_count_stop);
7016- while (atomic_read(&count_count_stop) != 2)
7017+ atomic_inc_unchecked(&count_count_stop);
7018+ while (atomic_read_unchecked(&count_count_stop) != 2)
7019 mb();
7020 }
7021 /* Arrange for an interrupt in a short while */
7022diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
7023index e0b4996..6b43ce7 100644
7024--- a/arch/mips/kernel/traps.c
7025+++ b/arch/mips/kernel/traps.c
7026@@ -691,7 +691,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
7027 siginfo_t info;
7028
7029 prev_state = exception_enter();
7030- die_if_kernel("Integer overflow", regs);
7031+ if (unlikely(!user_mode(regs))) {
7032+
7033+#ifdef CONFIG_PAX_REFCOUNT
7034+ if (fixup_exception(regs)) {
7035+ pax_report_refcount_overflow(regs);
7036+ exception_exit(prev_state);
7037+ return;
7038+ }
7039+#endif
7040+
7041+ die("Integer overflow", regs);
7042+ }
7043
7044 info.si_code = FPE_INTOVF;
7045 info.si_signo = SIGFPE;
7046diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
7047index becc42b..9e43d4b 100644
7048--- a/arch/mips/mm/fault.c
7049+++ b/arch/mips/mm/fault.c
7050@@ -28,6 +28,23 @@
7051 #include <asm/highmem.h> /* For VMALLOC_END */
7052 #include <linux/kdebug.h>
7053
7054+#ifdef CONFIG_PAX_PAGEEXEC
7055+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7056+{
7057+ unsigned long i;
7058+
7059+ printk(KERN_ERR "PAX: bytes at PC: ");
7060+ for (i = 0; i < 5; i++) {
7061+ unsigned int c;
7062+ if (get_user(c, (unsigned int *)pc+i))
7063+ printk(KERN_CONT "???????? ");
7064+ else
7065+ printk(KERN_CONT "%08x ", c);
7066+ }
7067+ printk("\n");
7068+}
7069+#endif
7070+
7071 /*
7072 * This routine handles page faults. It determines the address,
7073 * and the problem, and then passes it off to one of the appropriate
7074@@ -199,6 +216,14 @@ bad_area:
7075 bad_area_nosemaphore:
7076 /* User mode accesses just cause a SIGSEGV */
7077 if (user_mode(regs)) {
7078+
7079+#ifdef CONFIG_PAX_PAGEEXEC
7080+ if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
7081+ pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
7082+ do_group_exit(SIGKILL);
7083+ }
7084+#endif
7085+
7086 tsk->thread.cp0_badvaddr = address;
7087 tsk->thread.error_code = write;
7088 #if 0
7089diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
7090index f1baadd..5472dca 100644
7091--- a/arch/mips/mm/mmap.c
7092+++ b/arch/mips/mm/mmap.c
7093@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7094 struct vm_area_struct *vma;
7095 unsigned long addr = addr0;
7096 int do_color_align;
7097+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7098 struct vm_unmapped_area_info info;
7099
7100 if (unlikely(len > TASK_SIZE))
7101@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7102 do_color_align = 1;
7103
7104 /* requesting a specific address */
7105+
7106+#ifdef CONFIG_PAX_RANDMMAP
7107+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
7108+#endif
7109+
7110 if (addr) {
7111 if (do_color_align)
7112 addr = COLOUR_ALIGN(addr, pgoff);
7113@@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7114 addr = PAGE_ALIGN(addr);
7115
7116 vma = find_vma(mm, addr);
7117- if (TASK_SIZE - len >= addr &&
7118- (!vma || addr + len <= vma->vm_start))
7119+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7120 return addr;
7121 }
7122
7123 info.length = len;
7124 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
7125 info.align_offset = pgoff << PAGE_SHIFT;
7126+ info.threadstack_offset = offset;
7127
7128 if (dir == DOWN) {
7129 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
7130@@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7131 {
7132 unsigned long random_factor = 0UL;
7133
7134+#ifdef CONFIG_PAX_RANDMMAP
7135+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7136+#endif
7137+
7138 if (current->flags & PF_RANDOMIZE) {
7139 random_factor = get_random_int();
7140 random_factor = random_factor << PAGE_SHIFT;
7141@@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7142
7143 if (mmap_is_legacy()) {
7144 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
7145+
7146+#ifdef CONFIG_PAX_RANDMMAP
7147+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7148+ mm->mmap_base += mm->delta_mmap;
7149+#endif
7150+
7151 mm->get_unmapped_area = arch_get_unmapped_area;
7152 } else {
7153 mm->mmap_base = mmap_base(random_factor);
7154+
7155+#ifdef CONFIG_PAX_RANDMMAP
7156+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7157+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7158+#endif
7159+
7160 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7161 }
7162 }
7163
7164-static inline unsigned long brk_rnd(void)
7165-{
7166- unsigned long rnd = get_random_int();
7167-
7168- rnd = rnd << PAGE_SHIFT;
7169- /* 8MB for 32bit, 256MB for 64bit */
7170- if (TASK_IS_32BIT_ADDR)
7171- rnd = rnd & 0x7ffffful;
7172- else
7173- rnd = rnd & 0xffffffful;
7174-
7175- return rnd;
7176-}
7177-
7178-unsigned long arch_randomize_brk(struct mm_struct *mm)
7179-{
7180- unsigned long base = mm->brk;
7181- unsigned long ret;
7182-
7183- ret = PAGE_ALIGN(base + brk_rnd());
7184-
7185- if (ret < mm->brk)
7186- return mm->brk;
7187-
7188- return ret;
7189-}
7190-
7191 int __virt_addr_valid(const volatile void *kaddr)
7192 {
7193 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
7194diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
7195index 59cccd9..f39ac2f 100644
7196--- a/arch/mips/pci/pci-octeon.c
7197+++ b/arch/mips/pci/pci-octeon.c
7198@@ -327,8 +327,8 @@ static int octeon_write_config(struct pci_bus *bus, unsigned int devfn,
7199
7200
7201 static struct pci_ops octeon_pci_ops = {
7202- octeon_read_config,
7203- octeon_write_config,
7204+ .read = octeon_read_config,
7205+ .write = octeon_write_config,
7206 };
7207
7208 static struct resource octeon_pci_mem_resource = {
7209diff --git a/arch/mips/pci/pcie-octeon.c b/arch/mips/pci/pcie-octeon.c
7210index 5e36c33..eb4a17b 100644
7211--- a/arch/mips/pci/pcie-octeon.c
7212+++ b/arch/mips/pci/pcie-octeon.c
7213@@ -1792,8 +1792,8 @@ static int octeon_dummy_write_config(struct pci_bus *bus, unsigned int devfn,
7214 }
7215
7216 static struct pci_ops octeon_pcie0_ops = {
7217- octeon_pcie0_read_config,
7218- octeon_pcie0_write_config,
7219+ .read = octeon_pcie0_read_config,
7220+ .write = octeon_pcie0_write_config,
7221 };
7222
7223 static struct resource octeon_pcie0_mem_resource = {
7224@@ -1813,8 +1813,8 @@ static struct pci_controller octeon_pcie0_controller = {
7225 };
7226
7227 static struct pci_ops octeon_pcie1_ops = {
7228- octeon_pcie1_read_config,
7229- octeon_pcie1_write_config,
7230+ .read = octeon_pcie1_read_config,
7231+ .write = octeon_pcie1_write_config,
7232 };
7233
7234 static struct resource octeon_pcie1_mem_resource = {
7235@@ -1834,8 +1834,8 @@ static struct pci_controller octeon_pcie1_controller = {
7236 };
7237
7238 static struct pci_ops octeon_dummy_ops = {
7239- octeon_dummy_read_config,
7240- octeon_dummy_write_config,
7241+ .read = octeon_dummy_read_config,
7242+ .write = octeon_dummy_write_config,
7243 };
7244
7245 static struct resource octeon_dummy_mem_resource = {
7246diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
7247index a2358b4..7cead4f 100644
7248--- a/arch/mips/sgi-ip27/ip27-nmi.c
7249+++ b/arch/mips/sgi-ip27/ip27-nmi.c
7250@@ -187,9 +187,9 @@ void
7251 cont_nmi_dump(void)
7252 {
7253 #ifndef REAL_NMI_SIGNAL
7254- static atomic_t nmied_cpus = ATOMIC_INIT(0);
7255+ static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
7256
7257- atomic_inc(&nmied_cpus);
7258+ atomic_inc_unchecked(&nmied_cpus);
7259 #endif
7260 /*
7261 * Only allow 1 cpu to proceed
7262@@ -233,7 +233,7 @@ cont_nmi_dump(void)
7263 udelay(10000);
7264 }
7265 #else
7266- while (atomic_read(&nmied_cpus) != num_online_cpus());
7267+ while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
7268 #endif
7269
7270 /*
7271diff --git a/arch/mips/sni/rm200.c b/arch/mips/sni/rm200.c
7272index a046b30..6799527 100644
7273--- a/arch/mips/sni/rm200.c
7274+++ b/arch/mips/sni/rm200.c
7275@@ -270,7 +270,7 @@ spurious_8259A_irq:
7276 "spurious RM200 8259A interrupt: IRQ%d.\n", irq);
7277 spurious_irq_mask |= irqmask;
7278 }
7279- atomic_inc(&irq_err_count);
7280+ atomic_inc_unchecked(&irq_err_count);
7281 /*
7282 * Theoretically we do not have to handle this IRQ,
7283 * but in Linux this does not cause problems and is
7284diff --git a/arch/mips/vr41xx/common/icu.c b/arch/mips/vr41xx/common/icu.c
7285index 41e873b..34d33a7 100644
7286--- a/arch/mips/vr41xx/common/icu.c
7287+++ b/arch/mips/vr41xx/common/icu.c
7288@@ -653,7 +653,7 @@ static int icu_get_irq(unsigned int irq)
7289
7290 printk(KERN_ERR "spurious ICU interrupt: %04x,%04x\n", pend1, pend2);
7291
7292- atomic_inc(&irq_err_count);
7293+ atomic_inc_unchecked(&irq_err_count);
7294
7295 return -1;
7296 }
7297diff --git a/arch/mips/vr41xx/common/irq.c b/arch/mips/vr41xx/common/irq.c
7298index ae0e4ee..e8f0692 100644
7299--- a/arch/mips/vr41xx/common/irq.c
7300+++ b/arch/mips/vr41xx/common/irq.c
7301@@ -64,7 +64,7 @@ static void irq_dispatch(unsigned int irq)
7302 irq_cascade_t *cascade;
7303
7304 if (irq >= NR_IRQS) {
7305- atomic_inc(&irq_err_count);
7306+ atomic_inc_unchecked(&irq_err_count);
7307 return;
7308 }
7309
7310@@ -84,7 +84,7 @@ static void irq_dispatch(unsigned int irq)
7311 ret = cascade->get_irq(irq);
7312 irq = ret;
7313 if (ret < 0)
7314- atomic_inc(&irq_err_count);
7315+ atomic_inc_unchecked(&irq_err_count);
7316 else
7317 irq_dispatch(irq);
7318 if (!irqd_irq_disabled(idata) && chip->irq_unmask)
7319diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7320index 967d144..db12197 100644
7321--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
7322+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7323@@ -11,12 +11,14 @@
7324 #ifndef _ASM_PROC_CACHE_H
7325 #define _ASM_PROC_CACHE_H
7326
7327+#include <linux/const.h>
7328+
7329 /* L1 cache */
7330
7331 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7332 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
7333-#define L1_CACHE_BYTES 16 /* bytes per entry */
7334 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
7335+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7336 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
7337
7338 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7339diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7340index bcb5df2..84fabd2 100644
7341--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7342+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7343@@ -16,13 +16,15 @@
7344 #ifndef _ASM_PROC_CACHE_H
7345 #define _ASM_PROC_CACHE_H
7346
7347+#include <linux/const.h>
7348+
7349 /*
7350 * L1 cache
7351 */
7352 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7353 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
7354-#define L1_CACHE_BYTES 32 /* bytes per entry */
7355 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
7356+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7357 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
7358
7359 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7360diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
7361index 4ce7a01..449202a 100644
7362--- a/arch/openrisc/include/asm/cache.h
7363+++ b/arch/openrisc/include/asm/cache.h
7364@@ -19,11 +19,13 @@
7365 #ifndef __ASM_OPENRISC_CACHE_H
7366 #define __ASM_OPENRISC_CACHE_H
7367
7368+#include <linux/const.h>
7369+
7370 /* FIXME: How can we replace these with values from the CPU...
7371 * they shouldn't be hard-coded!
7372 */
7373
7374-#define L1_CACHE_BYTES 16
7375 #define L1_CACHE_SHIFT 4
7376+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7377
7378 #endif /* __ASM_OPENRISC_CACHE_H */
7379diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7380index 472886c..00e7df9 100644
7381--- a/arch/parisc/include/asm/atomic.h
7382+++ b/arch/parisc/include/asm/atomic.h
7383@@ -252,6 +252,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7384 return dec;
7385 }
7386
7387+#define atomic64_read_unchecked(v) atomic64_read(v)
7388+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7389+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7390+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7391+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7392+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7393+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7394+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7395+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7396+
7397 #endif /* !CONFIG_64BIT */
7398
7399
7400diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7401index 47f11c7..3420df2 100644
7402--- a/arch/parisc/include/asm/cache.h
7403+++ b/arch/parisc/include/asm/cache.h
7404@@ -5,6 +5,7 @@
7405 #ifndef __ARCH_PARISC_CACHE_H
7406 #define __ARCH_PARISC_CACHE_H
7407
7408+#include <linux/const.h>
7409
7410 /*
7411 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7412@@ -15,13 +16,13 @@
7413 * just ruin performance.
7414 */
7415 #ifdef CONFIG_PA20
7416-#define L1_CACHE_BYTES 64
7417 #define L1_CACHE_SHIFT 6
7418 #else
7419-#define L1_CACHE_BYTES 32
7420 #define L1_CACHE_SHIFT 5
7421 #endif
7422
7423+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7424+
7425 #ifndef __ASSEMBLY__
7426
7427 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7428diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7429index 3391d06..c23a2cc 100644
7430--- a/arch/parisc/include/asm/elf.h
7431+++ b/arch/parisc/include/asm/elf.h
7432@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7433
7434 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7435
7436+#ifdef CONFIG_PAX_ASLR
7437+#define PAX_ELF_ET_DYN_BASE 0x10000UL
7438+
7439+#define PAX_DELTA_MMAP_LEN 16
7440+#define PAX_DELTA_STACK_LEN 16
7441+#endif
7442+
7443 /* This yields a mask that user programs can use to figure out what
7444 instruction set this CPU supports. This could be done in user space,
7445 but it's not easy, and we've already done it here. */
7446diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7447index f213f5b..0af3e8e 100644
7448--- a/arch/parisc/include/asm/pgalloc.h
7449+++ b/arch/parisc/include/asm/pgalloc.h
7450@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7451 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7452 }
7453
7454+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7455+{
7456+ pgd_populate(mm, pgd, pmd);
7457+}
7458+
7459 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7460 {
7461 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7462@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7463 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7464 #define pmd_free(mm, x) do { } while (0)
7465 #define pgd_populate(mm, pmd, pte) BUG()
7466+#define pgd_populate_kernel(mm, pmd, pte) BUG()
7467
7468 #endif
7469
7470diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7471index 22b89d1..ce34230 100644
7472--- a/arch/parisc/include/asm/pgtable.h
7473+++ b/arch/parisc/include/asm/pgtable.h
7474@@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7475 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7476 #define PAGE_COPY PAGE_EXECREAD
7477 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7478+
7479+#ifdef CONFIG_PAX_PAGEEXEC
7480+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7481+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7482+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7483+#else
7484+# define PAGE_SHARED_NOEXEC PAGE_SHARED
7485+# define PAGE_COPY_NOEXEC PAGE_COPY
7486+# define PAGE_READONLY_NOEXEC PAGE_READONLY
7487+#endif
7488+
7489 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7490 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7491 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7492diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7493index 4006964..fcb3cc2 100644
7494--- a/arch/parisc/include/asm/uaccess.h
7495+++ b/arch/parisc/include/asm/uaccess.h
7496@@ -246,10 +246,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7497 const void __user *from,
7498 unsigned long n)
7499 {
7500- int sz = __compiletime_object_size(to);
7501+ size_t sz = __compiletime_object_size(to);
7502 int ret = -EFAULT;
7503
7504- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7505+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7506 ret = __copy_from_user(to, from, n);
7507 else
7508 copy_from_user_overflow();
7509diff --git a/arch/parisc/include/uapi/asm/resource.h b/arch/parisc/include/uapi/asm/resource.h
7510index 8b06343..090483c 100644
7511--- a/arch/parisc/include/uapi/asm/resource.h
7512+++ b/arch/parisc/include/uapi/asm/resource.h
7513@@ -1,7 +1,6 @@
7514 #ifndef _ASM_PARISC_RESOURCE_H
7515 #define _ASM_PARISC_RESOURCE_H
7516
7517-#define _STK_LIM_MAX 10 * _STK_LIM
7518 #include <asm-generic/resource.h>
7519
7520 #endif
7521diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7522index 50dfafc..b9fc230 100644
7523--- a/arch/parisc/kernel/module.c
7524+++ b/arch/parisc/kernel/module.c
7525@@ -98,16 +98,38 @@
7526
7527 /* three functions to determine where in the module core
7528 * or init pieces the location is */
7529+static inline int in_init_rx(struct module *me, void *loc)
7530+{
7531+ return (loc >= me->module_init_rx &&
7532+ loc < (me->module_init_rx + me->init_size_rx));
7533+}
7534+
7535+static inline int in_init_rw(struct module *me, void *loc)
7536+{
7537+ return (loc >= me->module_init_rw &&
7538+ loc < (me->module_init_rw + me->init_size_rw));
7539+}
7540+
7541 static inline int in_init(struct module *me, void *loc)
7542 {
7543- return (loc >= me->module_init &&
7544- loc <= (me->module_init + me->init_size));
7545+ return in_init_rx(me, loc) || in_init_rw(me, loc);
7546+}
7547+
7548+static inline int in_core_rx(struct module *me, void *loc)
7549+{
7550+ return (loc >= me->module_core_rx &&
7551+ loc < (me->module_core_rx + me->core_size_rx));
7552+}
7553+
7554+static inline int in_core_rw(struct module *me, void *loc)
7555+{
7556+ return (loc >= me->module_core_rw &&
7557+ loc < (me->module_core_rw + me->core_size_rw));
7558 }
7559
7560 static inline int in_core(struct module *me, void *loc)
7561 {
7562- return (loc >= me->module_core &&
7563- loc <= (me->module_core + me->core_size));
7564+ return in_core_rx(me, loc) || in_core_rw(me, loc);
7565 }
7566
7567 static inline int in_local(struct module *me, void *loc)
7568@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7569 }
7570
7571 /* align things a bit */
7572- me->core_size = ALIGN(me->core_size, 16);
7573- me->arch.got_offset = me->core_size;
7574- me->core_size += gots * sizeof(struct got_entry);
7575+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7576+ me->arch.got_offset = me->core_size_rw;
7577+ me->core_size_rw += gots * sizeof(struct got_entry);
7578
7579- me->core_size = ALIGN(me->core_size, 16);
7580- me->arch.fdesc_offset = me->core_size;
7581- me->core_size += fdescs * sizeof(Elf_Fdesc);
7582+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7583+ me->arch.fdesc_offset = me->core_size_rw;
7584+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7585
7586 me->arch.got_max = gots;
7587 me->arch.fdesc_max = fdescs;
7588@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7589
7590 BUG_ON(value == 0);
7591
7592- got = me->module_core + me->arch.got_offset;
7593+ got = me->module_core_rw + me->arch.got_offset;
7594 for (i = 0; got[i].addr; i++)
7595 if (got[i].addr == value)
7596 goto out;
7597@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7598 #ifdef CONFIG_64BIT
7599 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7600 {
7601- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7602+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7603
7604 if (!value) {
7605 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7606@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7607
7608 /* Create new one */
7609 fdesc->addr = value;
7610- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7611+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7612 return (Elf_Addr)fdesc;
7613 }
7614 #endif /* CONFIG_64BIT */
7615@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7616
7617 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7618 end = table + sechdrs[me->arch.unwind_section].sh_size;
7619- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7620+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7621
7622 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7623 me->arch.unwind_section, table, end, gp);
7624diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7625index b7cadc4..bf4a32d 100644
7626--- a/arch/parisc/kernel/sys_parisc.c
7627+++ b/arch/parisc/kernel/sys_parisc.c
7628@@ -89,6 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7629 unsigned long task_size = TASK_SIZE;
7630 int do_color_align, last_mmap;
7631 struct vm_unmapped_area_info info;
7632+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7633
7634 if (len > task_size)
7635 return -ENOMEM;
7636@@ -106,6 +107,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7637 goto found_addr;
7638 }
7639
7640+#ifdef CONFIG_PAX_RANDMMAP
7641+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7642+#endif
7643+
7644 if (addr) {
7645 if (do_color_align && last_mmap)
7646 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7647@@ -124,6 +129,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7648 info.high_limit = mmap_upper_limit();
7649 info.align_mask = last_mmap ? (PAGE_MASK & (SHMLBA - 1)) : 0;
7650 info.align_offset = shared_align_offset(last_mmap, pgoff);
7651+ info.threadstack_offset = offset;
7652 addr = vm_unmapped_area(&info);
7653
7654 found_addr:
7655@@ -143,6 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7656 unsigned long addr = addr0;
7657 int do_color_align, last_mmap;
7658 struct vm_unmapped_area_info info;
7659+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7660
7661 #ifdef CONFIG_64BIT
7662 /* This should only ever run for 32-bit processes. */
7663@@ -167,6 +174,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7664 }
7665
7666 /* requesting a specific address */
7667+#ifdef CONFIG_PAX_RANDMMAP
7668+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7669+#endif
7670+
7671 if (addr) {
7672 if (do_color_align && last_mmap)
7673 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7674@@ -184,6 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7675 info.high_limit = mm->mmap_base;
7676 info.align_mask = last_mmap ? (PAGE_MASK & (SHMLBA - 1)) : 0;
7677 info.align_offset = shared_align_offset(last_mmap, pgoff);
7678+ info.threadstack_offset = offset;
7679 addr = vm_unmapped_area(&info);
7680 if (!(addr & ~PAGE_MASK))
7681 goto found_addr;
7682@@ -249,6 +261,13 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7683 mm->mmap_legacy_base = mmap_legacy_base();
7684 mm->mmap_base = mmap_upper_limit();
7685
7686+#ifdef CONFIG_PAX_RANDMMAP
7687+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
7688+ mm->mmap_legacy_base += mm->delta_mmap;
7689+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7690+ }
7691+#endif
7692+
7693 if (mmap_is_legacy()) {
7694 mm->mmap_base = mm->mmap_legacy_base;
7695 mm->get_unmapped_area = arch_get_unmapped_area;
7696diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7697index 1cd1d0c..44ec918 100644
7698--- a/arch/parisc/kernel/traps.c
7699+++ b/arch/parisc/kernel/traps.c
7700@@ -722,9 +722,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7701
7702 down_read(&current->mm->mmap_sem);
7703 vma = find_vma(current->mm,regs->iaoq[0]);
7704- if (vma && (regs->iaoq[0] >= vma->vm_start)
7705- && (vma->vm_flags & VM_EXEC)) {
7706-
7707+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7708 fault_address = regs->iaoq[0];
7709 fault_space = regs->iasq[0];
7710
7711diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7712index 9d08c71..e2b4d20 100644
7713--- a/arch/parisc/mm/fault.c
7714+++ b/arch/parisc/mm/fault.c
7715@@ -15,6 +15,7 @@
7716 #include <linux/sched.h>
7717 #include <linux/interrupt.h>
7718 #include <linux/module.h>
7719+#include <linux/unistd.h>
7720
7721 #include <asm/uaccess.h>
7722 #include <asm/traps.h>
7723@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
7724 static unsigned long
7725 parisc_acctyp(unsigned long code, unsigned int inst)
7726 {
7727- if (code == 6 || code == 16)
7728+ if (code == 6 || code == 7 || code == 16)
7729 return VM_EXEC;
7730
7731 switch (inst & 0xf0000000) {
7732@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7733 }
7734 #endif
7735
7736+#ifdef CONFIG_PAX_PAGEEXEC
7737+/*
7738+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7739+ *
7740+ * returns 1 when task should be killed
7741+ * 2 when rt_sigreturn trampoline was detected
7742+ * 3 when unpatched PLT trampoline was detected
7743+ */
7744+static int pax_handle_fetch_fault(struct pt_regs *regs)
7745+{
7746+
7747+#ifdef CONFIG_PAX_EMUPLT
7748+ int err;
7749+
7750+ do { /* PaX: unpatched PLT emulation */
7751+ unsigned int bl, depwi;
7752+
7753+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7754+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7755+
7756+ if (err)
7757+ break;
7758+
7759+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7760+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7761+
7762+ err = get_user(ldw, (unsigned int *)addr);
7763+ err |= get_user(bv, (unsigned int *)(addr+4));
7764+ err |= get_user(ldw2, (unsigned int *)(addr+8));
7765+
7766+ if (err)
7767+ break;
7768+
7769+ if (ldw == 0x0E801096U &&
7770+ bv == 0xEAC0C000U &&
7771+ ldw2 == 0x0E881095U)
7772+ {
7773+ unsigned int resolver, map;
7774+
7775+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7776+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7777+ if (err)
7778+ break;
7779+
7780+ regs->gr[20] = instruction_pointer(regs)+8;
7781+ regs->gr[21] = map;
7782+ regs->gr[22] = resolver;
7783+ regs->iaoq[0] = resolver | 3UL;
7784+ regs->iaoq[1] = regs->iaoq[0] + 4;
7785+ return 3;
7786+ }
7787+ }
7788+ } while (0);
7789+#endif
7790+
7791+#ifdef CONFIG_PAX_EMUTRAMP
7792+
7793+#ifndef CONFIG_PAX_EMUSIGRT
7794+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7795+ return 1;
7796+#endif
7797+
7798+ do { /* PaX: rt_sigreturn emulation */
7799+ unsigned int ldi1, ldi2, bel, nop;
7800+
7801+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7802+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7803+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7804+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7805+
7806+ if (err)
7807+ break;
7808+
7809+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7810+ ldi2 == 0x3414015AU &&
7811+ bel == 0xE4008200U &&
7812+ nop == 0x08000240U)
7813+ {
7814+ regs->gr[25] = (ldi1 & 2) >> 1;
7815+ regs->gr[20] = __NR_rt_sigreturn;
7816+ regs->gr[31] = regs->iaoq[1] + 16;
7817+ regs->sr[0] = regs->iasq[1];
7818+ regs->iaoq[0] = 0x100UL;
7819+ regs->iaoq[1] = regs->iaoq[0] + 4;
7820+ regs->iasq[0] = regs->sr[2];
7821+ regs->iasq[1] = regs->sr[2];
7822+ return 2;
7823+ }
7824+ } while (0);
7825+#endif
7826+
7827+ return 1;
7828+}
7829+
7830+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7831+{
7832+ unsigned long i;
7833+
7834+ printk(KERN_ERR "PAX: bytes at PC: ");
7835+ for (i = 0; i < 5; i++) {
7836+ unsigned int c;
7837+ if (get_user(c, (unsigned int *)pc+i))
7838+ printk(KERN_CONT "???????? ");
7839+ else
7840+ printk(KERN_CONT "%08x ", c);
7841+ }
7842+ printk("\n");
7843+}
7844+#endif
7845+
7846 int fixup_exception(struct pt_regs *regs)
7847 {
7848 const struct exception_table_entry *fix;
7849@@ -210,8 +321,33 @@ retry:
7850
7851 good_area:
7852
7853- if ((vma->vm_flags & acc_type) != acc_type)
7854+ if ((vma->vm_flags & acc_type) != acc_type) {
7855+
7856+#ifdef CONFIG_PAX_PAGEEXEC
7857+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7858+ (address & ~3UL) == instruction_pointer(regs))
7859+ {
7860+ up_read(&mm->mmap_sem);
7861+ switch (pax_handle_fetch_fault(regs)) {
7862+
7863+#ifdef CONFIG_PAX_EMUPLT
7864+ case 3:
7865+ return;
7866+#endif
7867+
7868+#ifdef CONFIG_PAX_EMUTRAMP
7869+ case 2:
7870+ return;
7871+#endif
7872+
7873+ }
7874+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
7875+ do_group_exit(SIGKILL);
7876+ }
7877+#endif
7878+
7879 goto bad_area;
7880+ }
7881
7882 /*
7883 * If for any reason at all we couldn't handle the fault, make
7884diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
7885index 957bf34..3430cc8 100644
7886--- a/arch/powerpc/Kconfig
7887+++ b/arch/powerpc/Kconfig
7888@@ -393,6 +393,7 @@ config PPC64_SUPPORTS_MEMORY_FAILURE
7889 config KEXEC
7890 bool "kexec system call"
7891 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
7892+ depends on !GRKERNSEC_KMEM
7893 help
7894 kexec is a system call that implements the ability to shutdown your
7895 current kernel, and to start another kernel. It is like a reboot
7896diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
7897index e3b1d41..8e81edf 100644
7898--- a/arch/powerpc/include/asm/atomic.h
7899+++ b/arch/powerpc/include/asm/atomic.h
7900@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
7901 return t1;
7902 }
7903
7904+#define atomic64_read_unchecked(v) atomic64_read(v)
7905+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7906+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7907+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7908+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7909+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7910+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7911+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7912+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7913+
7914 #endif /* __powerpc64__ */
7915
7916 #endif /* __KERNEL__ */
7917diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
7918index ed0afc1..0332825 100644
7919--- a/arch/powerpc/include/asm/cache.h
7920+++ b/arch/powerpc/include/asm/cache.h
7921@@ -3,6 +3,7 @@
7922
7923 #ifdef __KERNEL__
7924
7925+#include <linux/const.h>
7926
7927 /* bytes per L1 cache line */
7928 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
7929@@ -22,7 +23,7 @@
7930 #define L1_CACHE_SHIFT 7
7931 #endif
7932
7933-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7934+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7935
7936 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7937
7938diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
7939index 935b5e7..7001d2d 100644
7940--- a/arch/powerpc/include/asm/elf.h
7941+++ b/arch/powerpc/include/asm/elf.h
7942@@ -28,8 +28,19 @@
7943 the loader. We need to make sure that it is out of the way of the program
7944 that it will "exec", and that there is sufficient room for the brk. */
7945
7946-extern unsigned long randomize_et_dyn(unsigned long base);
7947-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
7948+#define ELF_ET_DYN_BASE (0x20000000)
7949+
7950+#ifdef CONFIG_PAX_ASLR
7951+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
7952+
7953+#ifdef __powerpc64__
7954+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
7955+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
7956+#else
7957+#define PAX_DELTA_MMAP_LEN 15
7958+#define PAX_DELTA_STACK_LEN 15
7959+#endif
7960+#endif
7961
7962 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
7963
7964@@ -127,10 +138,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
7965 (0x7ff >> (PAGE_SHIFT - 12)) : \
7966 (0x3ffff >> (PAGE_SHIFT - 12)))
7967
7968-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7969-#define arch_randomize_brk arch_randomize_brk
7970-
7971-
7972 #ifdef CONFIG_SPU_BASE
7973 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
7974 #define NT_SPU 1
7975diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
7976index 8196e9c..d83a9f3 100644
7977--- a/arch/powerpc/include/asm/exec.h
7978+++ b/arch/powerpc/include/asm/exec.h
7979@@ -4,6 +4,6 @@
7980 #ifndef _ASM_POWERPC_EXEC_H
7981 #define _ASM_POWERPC_EXEC_H
7982
7983-extern unsigned long arch_align_stack(unsigned long sp);
7984+#define arch_align_stack(x) ((x) & ~0xfUL)
7985
7986 #endif /* _ASM_POWERPC_EXEC_H */
7987diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
7988index 5acabbd..7ea14fa 100644
7989--- a/arch/powerpc/include/asm/kmap_types.h
7990+++ b/arch/powerpc/include/asm/kmap_types.h
7991@@ -10,7 +10,7 @@
7992 * 2 of the License, or (at your option) any later version.
7993 */
7994
7995-#define KM_TYPE_NR 16
7996+#define KM_TYPE_NR 17
7997
7998 #endif /* __KERNEL__ */
7999 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
8000diff --git a/arch/powerpc/include/asm/local.h b/arch/powerpc/include/asm/local.h
8001index b8da913..60b608a 100644
8002--- a/arch/powerpc/include/asm/local.h
8003+++ b/arch/powerpc/include/asm/local.h
8004@@ -9,15 +9,26 @@ typedef struct
8005 atomic_long_t a;
8006 } local_t;
8007
8008+typedef struct
8009+{
8010+ atomic_long_unchecked_t a;
8011+} local_unchecked_t;
8012+
8013 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
8014
8015 #define local_read(l) atomic_long_read(&(l)->a)
8016+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
8017 #define local_set(l,i) atomic_long_set(&(l)->a, (i))
8018+#define local_set_unchecked(l,i) atomic_long_set_unchecked(&(l)->a, (i))
8019
8020 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
8021+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
8022 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
8023+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
8024 #define local_inc(l) atomic_long_inc(&(l)->a)
8025+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
8026 #define local_dec(l) atomic_long_dec(&(l)->a)
8027+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
8028
8029 static __inline__ long local_add_return(long a, local_t *l)
8030 {
8031@@ -35,6 +46,7 @@ static __inline__ long local_add_return(long a, local_t *l)
8032
8033 return t;
8034 }
8035+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
8036
8037 #define local_add_negative(a, l) (local_add_return((a), (l)) < 0)
8038
8039@@ -54,6 +66,7 @@ static __inline__ long local_sub_return(long a, local_t *l)
8040
8041 return t;
8042 }
8043+#define local_sub_return_unchecked(i, l) atomic_long_sub_return_unchecked((i), (&(l)->a))
8044
8045 static __inline__ long local_inc_return(local_t *l)
8046 {
8047@@ -101,6 +114,8 @@ static __inline__ long local_dec_return(local_t *l)
8048
8049 #define local_cmpxchg(l, o, n) \
8050 (cmpxchg_local(&((l)->a.counter), (o), (n)))
8051+#define local_cmpxchg_unchecked(l, o, n) \
8052+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
8053 #define local_xchg(l, n) (xchg_local(&((l)->a.counter), (n)))
8054
8055 /**
8056diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
8057index 8565c25..2865190 100644
8058--- a/arch/powerpc/include/asm/mman.h
8059+++ b/arch/powerpc/include/asm/mman.h
8060@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
8061 }
8062 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
8063
8064-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
8065+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
8066 {
8067 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
8068 }
8069diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
8070index 32e4e21..62afb12 100644
8071--- a/arch/powerpc/include/asm/page.h
8072+++ b/arch/powerpc/include/asm/page.h
8073@@ -230,8 +230,9 @@ extern long long virt_phys_offset;
8074 * and needs to be executable. This means the whole heap ends
8075 * up being executable.
8076 */
8077-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8078- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8079+#define VM_DATA_DEFAULT_FLAGS32 \
8080+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8081+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8082
8083 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8084 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8085@@ -259,6 +260,9 @@ extern long long virt_phys_offset;
8086 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
8087 #endif
8088
8089+#define ktla_ktva(addr) (addr)
8090+#define ktva_ktla(addr) (addr)
8091+
8092 #ifndef CONFIG_PPC_BOOK3S_64
8093 /*
8094 * Use the top bit of the higher-level page table entries to indicate whether
8095diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
8096index 88693ce..ac6f9ab 100644
8097--- a/arch/powerpc/include/asm/page_64.h
8098+++ b/arch/powerpc/include/asm/page_64.h
8099@@ -153,15 +153,18 @@ do { \
8100 * stack by default, so in the absence of a PT_GNU_STACK program header
8101 * we turn execute permission off.
8102 */
8103-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8104- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8105+#define VM_STACK_DEFAULT_FLAGS32 \
8106+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8107+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8108
8109 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8110 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8111
8112+#ifndef CONFIG_PAX_PAGEEXEC
8113 #define VM_STACK_DEFAULT_FLAGS \
8114 (is_32bit_task() ? \
8115 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
8116+#endif
8117
8118 #include <asm-generic/getorder.h>
8119
8120diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
8121index 4b0be20..c15a27d 100644
8122--- a/arch/powerpc/include/asm/pgalloc-64.h
8123+++ b/arch/powerpc/include/asm/pgalloc-64.h
8124@@ -54,6 +54,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
8125 #ifndef CONFIG_PPC_64K_PAGES
8126
8127 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
8128+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
8129
8130 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
8131 {
8132@@ -71,6 +72,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8133 pud_set(pud, (unsigned long)pmd);
8134 }
8135
8136+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8137+{
8138+ pud_populate(mm, pud, pmd);
8139+}
8140+
8141 #define pmd_populate(mm, pmd, pte_page) \
8142 pmd_populate_kernel(mm, pmd, page_address(pte_page))
8143 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
8144@@ -173,6 +179,7 @@ extern void __tlb_remove_table(void *_table);
8145 #endif
8146
8147 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
8148+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
8149
8150 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
8151 pte_t *pte)
8152diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
8153index 3ebb188..e17dddf 100644
8154--- a/arch/powerpc/include/asm/pgtable.h
8155+++ b/arch/powerpc/include/asm/pgtable.h
8156@@ -2,6 +2,7 @@
8157 #define _ASM_POWERPC_PGTABLE_H
8158 #ifdef __KERNEL__
8159
8160+#include <linux/const.h>
8161 #ifndef __ASSEMBLY__
8162 #include <linux/mmdebug.h>
8163 #include <asm/processor.h> /* For TASK_SIZE */
8164diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
8165index 4aad413..85d86bf 100644
8166--- a/arch/powerpc/include/asm/pte-hash32.h
8167+++ b/arch/powerpc/include/asm/pte-hash32.h
8168@@ -21,6 +21,7 @@
8169 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
8170 #define _PAGE_USER 0x004 /* usermode access allowed */
8171 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
8172+#define _PAGE_EXEC _PAGE_GUARDED
8173 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
8174 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
8175 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
8176diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
8177index ce17815..c5574cc 100644
8178--- a/arch/powerpc/include/asm/reg.h
8179+++ b/arch/powerpc/include/asm/reg.h
8180@@ -249,6 +249,7 @@
8181 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
8182 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
8183 #define DSISR_NOHPTE 0x40000000 /* no translation found */
8184+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
8185 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
8186 #define DSISR_ISSTORE 0x02000000 /* access was a store */
8187 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
8188diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
8189index 084e080..9415a3d 100644
8190--- a/arch/powerpc/include/asm/smp.h
8191+++ b/arch/powerpc/include/asm/smp.h
8192@@ -51,7 +51,7 @@ struct smp_ops_t {
8193 int (*cpu_disable)(void);
8194 void (*cpu_die)(unsigned int nr);
8195 int (*cpu_bootable)(unsigned int nr);
8196-};
8197+} __no_const;
8198
8199 extern void smp_send_debugger_break(void);
8200 extern void start_secondary_resume(void);
8201diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
8202index b034ecd..af7e31f 100644
8203--- a/arch/powerpc/include/asm/thread_info.h
8204+++ b/arch/powerpc/include/asm/thread_info.h
8205@@ -107,6 +107,8 @@ static inline struct thread_info *current_thread_info(void)
8206 #if defined(CONFIG_PPC64)
8207 #define TIF_ELF2ABI 18 /* function descriptors must die! */
8208 #endif
8209+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
8210+#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
8211
8212 /* as above, but as bit values */
8213 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
8214@@ -125,9 +127,10 @@ static inline struct thread_info *current_thread_info(void)
8215 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8216 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
8217 #define _TIF_NOHZ (1<<TIF_NOHZ)
8218+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8219 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
8220 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
8221- _TIF_NOHZ)
8222+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
8223
8224 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
8225 _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
8226diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
8227index 9485b43..3bd3c16 100644
8228--- a/arch/powerpc/include/asm/uaccess.h
8229+++ b/arch/powerpc/include/asm/uaccess.h
8230@@ -58,6 +58,7 @@
8231
8232 #endif
8233
8234+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
8235 #define access_ok(type, addr, size) \
8236 (__chk_user_ptr(addr), \
8237 __access_ok((__force unsigned long)(addr), (size), get_fs()))
8238@@ -318,52 +319,6 @@ do { \
8239 extern unsigned long __copy_tofrom_user(void __user *to,
8240 const void __user *from, unsigned long size);
8241
8242-#ifndef __powerpc64__
8243-
8244-static inline unsigned long copy_from_user(void *to,
8245- const void __user *from, unsigned long n)
8246-{
8247- unsigned long over;
8248-
8249- if (access_ok(VERIFY_READ, from, n))
8250- return __copy_tofrom_user((__force void __user *)to, from, n);
8251- if ((unsigned long)from < TASK_SIZE) {
8252- over = (unsigned long)from + n - TASK_SIZE;
8253- return __copy_tofrom_user((__force void __user *)to, from,
8254- n - over) + over;
8255- }
8256- return n;
8257-}
8258-
8259-static inline unsigned long copy_to_user(void __user *to,
8260- const void *from, unsigned long n)
8261-{
8262- unsigned long over;
8263-
8264- if (access_ok(VERIFY_WRITE, to, n))
8265- return __copy_tofrom_user(to, (__force void __user *)from, n);
8266- if ((unsigned long)to < TASK_SIZE) {
8267- over = (unsigned long)to + n - TASK_SIZE;
8268- return __copy_tofrom_user(to, (__force void __user *)from,
8269- n - over) + over;
8270- }
8271- return n;
8272-}
8273-
8274-#else /* __powerpc64__ */
8275-
8276-#define __copy_in_user(to, from, size) \
8277- __copy_tofrom_user((to), (from), (size))
8278-
8279-extern unsigned long copy_from_user(void *to, const void __user *from,
8280- unsigned long n);
8281-extern unsigned long copy_to_user(void __user *to, const void *from,
8282- unsigned long n);
8283-extern unsigned long copy_in_user(void __user *to, const void __user *from,
8284- unsigned long n);
8285-
8286-#endif /* __powerpc64__ */
8287-
8288 static inline unsigned long __copy_from_user_inatomic(void *to,
8289 const void __user *from, unsigned long n)
8290 {
8291@@ -387,6 +342,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
8292 if (ret == 0)
8293 return 0;
8294 }
8295+
8296+ if (!__builtin_constant_p(n))
8297+ check_object_size(to, n, false);
8298+
8299 return __copy_tofrom_user((__force void __user *)to, from, n);
8300 }
8301
8302@@ -413,6 +372,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
8303 if (ret == 0)
8304 return 0;
8305 }
8306+
8307+ if (!__builtin_constant_p(n))
8308+ check_object_size(from, n, true);
8309+
8310 return __copy_tofrom_user(to, (__force const void __user *)from, n);
8311 }
8312
8313@@ -430,6 +393,92 @@ static inline unsigned long __copy_to_user(void __user *to,
8314 return __copy_to_user_inatomic(to, from, size);
8315 }
8316
8317+#ifndef __powerpc64__
8318+
8319+static inline unsigned long __must_check copy_from_user(void *to,
8320+ const void __user *from, unsigned long n)
8321+{
8322+ unsigned long over;
8323+
8324+ if ((long)n < 0)
8325+ return n;
8326+
8327+ if (access_ok(VERIFY_READ, from, n)) {
8328+ if (!__builtin_constant_p(n))
8329+ check_object_size(to, n, false);
8330+ return __copy_tofrom_user((__force void __user *)to, from, n);
8331+ }
8332+ if ((unsigned long)from < TASK_SIZE) {
8333+ over = (unsigned long)from + n - TASK_SIZE;
8334+ if (!__builtin_constant_p(n - over))
8335+ check_object_size(to, n - over, false);
8336+ return __copy_tofrom_user((__force void __user *)to, from,
8337+ n - over) + over;
8338+ }
8339+ return n;
8340+}
8341+
8342+static inline unsigned long __must_check copy_to_user(void __user *to,
8343+ const void *from, unsigned long n)
8344+{
8345+ unsigned long over;
8346+
8347+ if ((long)n < 0)
8348+ return n;
8349+
8350+ if (access_ok(VERIFY_WRITE, to, n)) {
8351+ if (!__builtin_constant_p(n))
8352+ check_object_size(from, n, true);
8353+ return __copy_tofrom_user(to, (__force void __user *)from, n);
8354+ }
8355+ if ((unsigned long)to < TASK_SIZE) {
8356+ over = (unsigned long)to + n - TASK_SIZE;
8357+ if (!__builtin_constant_p(n))
8358+ check_object_size(from, n - over, true);
8359+ return __copy_tofrom_user(to, (__force void __user *)from,
8360+ n - over) + over;
8361+ }
8362+ return n;
8363+}
8364+
8365+#else /* __powerpc64__ */
8366+
8367+#define __copy_in_user(to, from, size) \
8368+ __copy_tofrom_user((to), (from), (size))
8369+
8370+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
8371+{
8372+ if ((long)n < 0 || n > INT_MAX)
8373+ return n;
8374+
8375+ if (!__builtin_constant_p(n))
8376+ check_object_size(to, n, false);
8377+
8378+ if (likely(access_ok(VERIFY_READ, from, n)))
8379+ n = __copy_from_user(to, from, n);
8380+ else
8381+ memset(to, 0, n);
8382+ return n;
8383+}
8384+
8385+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
8386+{
8387+ if ((long)n < 0 || n > INT_MAX)
8388+ return n;
8389+
8390+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
8391+ if (!__builtin_constant_p(n))
8392+ check_object_size(from, n, true);
8393+ n = __copy_to_user(to, from, n);
8394+ }
8395+ return n;
8396+}
8397+
8398+extern unsigned long copy_in_user(void __user *to, const void __user *from,
8399+ unsigned long n);
8400+
8401+#endif /* __powerpc64__ */
8402+
8403 extern unsigned long __clear_user(void __user *addr, unsigned long size);
8404
8405 static inline unsigned long clear_user(void __user *addr, unsigned long size)
8406diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
8407index fcc9a89..07be2bb 100644
8408--- a/arch/powerpc/kernel/Makefile
8409+++ b/arch/powerpc/kernel/Makefile
8410@@ -26,6 +26,8 @@ CFLAGS_REMOVE_ftrace.o = -pg -mno-sched-epilog
8411 CFLAGS_REMOVE_time.o = -pg -mno-sched-epilog
8412 endif
8413
8414+CFLAGS_REMOVE_prom_init.o += $(LATENT_ENTROPY_PLUGIN_CFLAGS)
8415+
8416 obj-y := cputable.o ptrace.o syscalls.o \
8417 irq.o align.o signal_32.o pmc.o vdso.o \
8418 process.o systbl.o idle.o \
8419diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
8420index 063b65d..7a26e9d 100644
8421--- a/arch/powerpc/kernel/exceptions-64e.S
8422+++ b/arch/powerpc/kernel/exceptions-64e.S
8423@@ -771,6 +771,7 @@ storage_fault_common:
8424 std r14,_DAR(r1)
8425 std r15,_DSISR(r1)
8426 addi r3,r1,STACK_FRAME_OVERHEAD
8427+ bl .save_nvgprs
8428 mr r4,r14
8429 mr r5,r15
8430 ld r14,PACA_EXGEN+EX_R14(r13)
8431@@ -779,8 +780,7 @@ storage_fault_common:
8432 cmpdi r3,0
8433 bne- 1f
8434 b .ret_from_except_lite
8435-1: bl .save_nvgprs
8436- mr r5,r3
8437+1: mr r5,r3
8438 addi r3,r1,STACK_FRAME_OVERHEAD
8439 ld r4,_DAR(r1)
8440 bl .bad_page_fault
8441diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
8442index 38d5073..f00af8d 100644
8443--- a/arch/powerpc/kernel/exceptions-64s.S
8444+++ b/arch/powerpc/kernel/exceptions-64s.S
8445@@ -1584,10 +1584,10 @@ handle_page_fault:
8446 11: ld r4,_DAR(r1)
8447 ld r5,_DSISR(r1)
8448 addi r3,r1,STACK_FRAME_OVERHEAD
8449+ bl .save_nvgprs
8450 bl .do_page_fault
8451 cmpdi r3,0
8452 beq+ 12f
8453- bl .save_nvgprs
8454 mr r5,r3
8455 addi r3,r1,STACK_FRAME_OVERHEAD
8456 lwz r4,_DAR(r1)
8457diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
8458index 1d0848b..d74685f 100644
8459--- a/arch/powerpc/kernel/irq.c
8460+++ b/arch/powerpc/kernel/irq.c
8461@@ -447,6 +447,8 @@ void migrate_irqs(void)
8462 }
8463 #endif
8464
8465+extern void gr_handle_kernel_exploit(void);
8466+
8467 static inline void check_stack_overflow(void)
8468 {
8469 #ifdef CONFIG_DEBUG_STACKOVERFLOW
8470@@ -459,6 +461,7 @@ static inline void check_stack_overflow(void)
8471 printk("do_IRQ: stack overflow: %ld\n",
8472 sp - sizeof(struct thread_info));
8473 dump_stack();
8474+ gr_handle_kernel_exploit();
8475 }
8476 #endif
8477 }
8478diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
8479index 6cff040..74ac5d1 100644
8480--- a/arch/powerpc/kernel/module_32.c
8481+++ b/arch/powerpc/kernel/module_32.c
8482@@ -161,7 +161,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
8483 me->arch.core_plt_section = i;
8484 }
8485 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
8486- printk("Module doesn't contain .plt or .init.plt sections.\n");
8487+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
8488 return -ENOEXEC;
8489 }
8490
8491@@ -191,11 +191,16 @@ static uint32_t do_plt_call(void *location,
8492
8493 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
8494 /* Init, or core PLT? */
8495- if (location >= mod->module_core
8496- && location < mod->module_core + mod->core_size)
8497+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
8498+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
8499 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
8500- else
8501+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
8502+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
8503 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
8504+ else {
8505+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
8506+ return ~0UL;
8507+ }
8508
8509 /* Find this entry, or if that fails, the next avail. entry */
8510 while (entry->jump[0]) {
8511@@ -299,7 +304,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
8512 }
8513 #ifdef CONFIG_DYNAMIC_FTRACE
8514 module->arch.tramp =
8515- do_plt_call(module->module_core,
8516+ do_plt_call(module->module_core_rx,
8517 (unsigned long)ftrace_caller,
8518 sechdrs, module);
8519 #endif
8520diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
8521index 31d0215..206af70 100644
8522--- a/arch/powerpc/kernel/process.c
8523+++ b/arch/powerpc/kernel/process.c
8524@@ -1031,8 +1031,8 @@ void show_regs(struct pt_regs * regs)
8525 * Lookup NIP late so we have the best change of getting the
8526 * above info out without failing
8527 */
8528- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
8529- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
8530+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
8531+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
8532 #endif
8533 show_stack(current, (unsigned long *) regs->gpr[1]);
8534 if (!user_mode(regs))
8535@@ -1554,10 +1554,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8536 newsp = stack[0];
8537 ip = stack[STACK_FRAME_LR_SAVE];
8538 if (!firstframe || ip != lr) {
8539- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
8540+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
8541 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8542 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
8543- printk(" (%pS)",
8544+ printk(" (%pA)",
8545 (void *)current->ret_stack[curr_frame].ret);
8546 curr_frame--;
8547 }
8548@@ -1577,7 +1577,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8549 struct pt_regs *regs = (struct pt_regs *)
8550 (sp + STACK_FRAME_OVERHEAD);
8551 lr = regs->link;
8552- printk("--- Exception: %lx at %pS\n LR = %pS\n",
8553+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
8554 regs->trap, (void *)regs->nip, (void *)lr);
8555 firstframe = 1;
8556 }
8557@@ -1613,58 +1613,3 @@ void notrace __ppc64_runlatch_off(void)
8558 mtspr(SPRN_CTRLT, ctrl);
8559 }
8560 #endif /* CONFIG_PPC64 */
8561-
8562-unsigned long arch_align_stack(unsigned long sp)
8563-{
8564- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8565- sp -= get_random_int() & ~PAGE_MASK;
8566- return sp & ~0xf;
8567-}
8568-
8569-static inline unsigned long brk_rnd(void)
8570-{
8571- unsigned long rnd = 0;
8572-
8573- /* 8MB for 32bit, 1GB for 64bit */
8574- if (is_32bit_task())
8575- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
8576- else
8577- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
8578-
8579- return rnd << PAGE_SHIFT;
8580-}
8581-
8582-unsigned long arch_randomize_brk(struct mm_struct *mm)
8583-{
8584- unsigned long base = mm->brk;
8585- unsigned long ret;
8586-
8587-#ifdef CONFIG_PPC_STD_MMU_64
8588- /*
8589- * If we are using 1TB segments and we are allowed to randomise
8590- * the heap, we can put it above 1TB so it is backed by a 1TB
8591- * segment. Otherwise the heap will be in the bottom 1TB
8592- * which always uses 256MB segments and this may result in a
8593- * performance penalty.
8594- */
8595- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
8596- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
8597-#endif
8598-
8599- ret = PAGE_ALIGN(base + brk_rnd());
8600-
8601- if (ret < mm->brk)
8602- return mm->brk;
8603-
8604- return ret;
8605-}
8606-
8607-unsigned long randomize_et_dyn(unsigned long base)
8608-{
8609- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8610-
8611- if (ret < base)
8612- return base;
8613-
8614- return ret;
8615-}
8616diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
8617index 2e3d2bf..35df241 100644
8618--- a/arch/powerpc/kernel/ptrace.c
8619+++ b/arch/powerpc/kernel/ptrace.c
8620@@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
8621 return ret;
8622 }
8623
8624+#ifdef CONFIG_GRKERNSEC_SETXID
8625+extern void gr_delayed_cred_worker(void);
8626+#endif
8627+
8628 /*
8629 * We must return the syscall number to actually look up in the table.
8630 * This can be -1L to skip running any syscall at all.
8631@@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
8632
8633 secure_computing_strict(regs->gpr[0]);
8634
8635+#ifdef CONFIG_GRKERNSEC_SETXID
8636+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8637+ gr_delayed_cred_worker();
8638+#endif
8639+
8640 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
8641 tracehook_report_syscall_entry(regs))
8642 /*
8643@@ -1808,6 +1817,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
8644 {
8645 int step;
8646
8647+#ifdef CONFIG_GRKERNSEC_SETXID
8648+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8649+ gr_delayed_cred_worker();
8650+#endif
8651+
8652 audit_syscall_exit(regs);
8653
8654 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8655diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
8656index 4e47db6..6dcc96e 100644
8657--- a/arch/powerpc/kernel/signal_32.c
8658+++ b/arch/powerpc/kernel/signal_32.c
8659@@ -1013,7 +1013,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
8660 /* Save user registers on the stack */
8661 frame = &rt_sf->uc.uc_mcontext;
8662 addr = frame;
8663- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
8664+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8665 sigret = 0;
8666 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
8667 } else {
8668diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
8669index d501dc4..e5a0de0 100644
8670--- a/arch/powerpc/kernel/signal_64.c
8671+++ b/arch/powerpc/kernel/signal_64.c
8672@@ -760,7 +760,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
8673 current->thread.fp_state.fpscr = 0;
8674
8675 /* Set up to return from userspace. */
8676- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
8677+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8678 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
8679 } else {
8680 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
8681diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
8682index 33cd7a0..d615344 100644
8683--- a/arch/powerpc/kernel/traps.c
8684+++ b/arch/powerpc/kernel/traps.c
8685@@ -142,6 +142,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
8686 return flags;
8687 }
8688
8689+extern void gr_handle_kernel_exploit(void);
8690+
8691 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8692 int signr)
8693 {
8694@@ -191,6 +193,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8695 panic("Fatal exception in interrupt");
8696 if (panic_on_oops)
8697 panic("Fatal exception");
8698+
8699+ gr_handle_kernel_exploit();
8700+
8701 do_exit(signr);
8702 }
8703
8704diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
8705index 094e45c..d82b848 100644
8706--- a/arch/powerpc/kernel/vdso.c
8707+++ b/arch/powerpc/kernel/vdso.c
8708@@ -35,6 +35,7 @@
8709 #include <asm/vdso.h>
8710 #include <asm/vdso_datapage.h>
8711 #include <asm/setup.h>
8712+#include <asm/mman.h>
8713
8714 #undef DEBUG
8715
8716@@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8717 vdso_base = VDSO32_MBASE;
8718 #endif
8719
8720- current->mm->context.vdso_base = 0;
8721+ current->mm->context.vdso_base = ~0UL;
8722
8723 /* vDSO has a problem and was disabled, just don't "enable" it for the
8724 * process
8725@@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8726 vdso_base = get_unmapped_area(NULL, vdso_base,
8727 (vdso_pages << PAGE_SHIFT) +
8728 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
8729- 0, 0);
8730+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
8731 if (IS_ERR_VALUE(vdso_base)) {
8732 rc = vdso_base;
8733 goto fail_mmapsem;
8734diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
8735index 3cf541a..ab2d825 100644
8736--- a/arch/powerpc/kvm/powerpc.c
8737+++ b/arch/powerpc/kvm/powerpc.c
8738@@ -1153,7 +1153,7 @@ void kvmppc_init_lpid(unsigned long nr_lpids_param)
8739 }
8740 EXPORT_SYMBOL_GPL(kvmppc_init_lpid);
8741
8742-int kvm_arch_init(void *opaque)
8743+int kvm_arch_init(const void *opaque)
8744 {
8745 return 0;
8746 }
8747diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
8748index 5eea6f3..5d10396 100644
8749--- a/arch/powerpc/lib/usercopy_64.c
8750+++ b/arch/powerpc/lib/usercopy_64.c
8751@@ -9,22 +9,6 @@
8752 #include <linux/module.h>
8753 #include <asm/uaccess.h>
8754
8755-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8756-{
8757- if (likely(access_ok(VERIFY_READ, from, n)))
8758- n = __copy_from_user(to, from, n);
8759- else
8760- memset(to, 0, n);
8761- return n;
8762-}
8763-
8764-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8765-{
8766- if (likely(access_ok(VERIFY_WRITE, to, n)))
8767- n = __copy_to_user(to, from, n);
8768- return n;
8769-}
8770-
8771 unsigned long copy_in_user(void __user *to, const void __user *from,
8772 unsigned long n)
8773 {
8774@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
8775 return n;
8776 }
8777
8778-EXPORT_SYMBOL(copy_from_user);
8779-EXPORT_SYMBOL(copy_to_user);
8780 EXPORT_SYMBOL(copy_in_user);
8781
8782diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
8783index 51ab9e7..7d3c78b 100644
8784--- a/arch/powerpc/mm/fault.c
8785+++ b/arch/powerpc/mm/fault.c
8786@@ -33,6 +33,10 @@
8787 #include <linux/magic.h>
8788 #include <linux/ratelimit.h>
8789 #include <linux/context_tracking.h>
8790+#include <linux/slab.h>
8791+#include <linux/pagemap.h>
8792+#include <linux/compiler.h>
8793+#include <linux/unistd.h>
8794
8795 #include <asm/firmware.h>
8796 #include <asm/page.h>
8797@@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
8798 }
8799 #endif
8800
8801+#ifdef CONFIG_PAX_PAGEEXEC
8802+/*
8803+ * PaX: decide what to do with offenders (regs->nip = fault address)
8804+ *
8805+ * returns 1 when task should be killed
8806+ */
8807+static int pax_handle_fetch_fault(struct pt_regs *regs)
8808+{
8809+ return 1;
8810+}
8811+
8812+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8813+{
8814+ unsigned long i;
8815+
8816+ printk(KERN_ERR "PAX: bytes at PC: ");
8817+ for (i = 0; i < 5; i++) {
8818+ unsigned int c;
8819+ if (get_user(c, (unsigned int __user *)pc+i))
8820+ printk(KERN_CONT "???????? ");
8821+ else
8822+ printk(KERN_CONT "%08x ", c);
8823+ }
8824+ printk("\n");
8825+}
8826+#endif
8827+
8828 /*
8829 * Check whether the instruction at regs->nip is a store using
8830 * an update addressing form which will update r1.
8831@@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
8832 * indicate errors in DSISR but can validly be set in SRR1.
8833 */
8834 if (trap == 0x400)
8835- error_code &= 0x48200000;
8836+ error_code &= 0x58200000;
8837 else
8838 is_write = error_code & DSISR_ISSTORE;
8839 #else
8840@@ -378,7 +409,7 @@ good_area:
8841 * "undefined". Of those that can be set, this is the only
8842 * one which seems bad.
8843 */
8844- if (error_code & 0x10000000)
8845+ if (error_code & DSISR_GUARDED)
8846 /* Guarded storage error. */
8847 goto bad_area;
8848 #endif /* CONFIG_8xx */
8849@@ -393,7 +424,7 @@ good_area:
8850 * processors use the same I/D cache coherency mechanism
8851 * as embedded.
8852 */
8853- if (error_code & DSISR_PROTFAULT)
8854+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
8855 goto bad_area;
8856 #endif /* CONFIG_PPC_STD_MMU */
8857
8858@@ -483,6 +514,23 @@ bad_area:
8859 bad_area_nosemaphore:
8860 /* User mode accesses cause a SIGSEGV */
8861 if (user_mode(regs)) {
8862+
8863+#ifdef CONFIG_PAX_PAGEEXEC
8864+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
8865+#ifdef CONFIG_PPC_STD_MMU
8866+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
8867+#else
8868+ if (is_exec && regs->nip == address) {
8869+#endif
8870+ switch (pax_handle_fetch_fault(regs)) {
8871+ }
8872+
8873+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
8874+ do_group_exit(SIGKILL);
8875+ }
8876+ }
8877+#endif
8878+
8879 _exception(SIGSEGV, regs, code, address);
8880 goto bail;
8881 }
8882diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
8883index cb8bdbe..cde4bc7 100644
8884--- a/arch/powerpc/mm/mmap.c
8885+++ b/arch/powerpc/mm/mmap.c
8886@@ -53,10 +53,14 @@ static inline int mmap_is_legacy(void)
8887 return sysctl_legacy_va_layout;
8888 }
8889
8890-static unsigned long mmap_rnd(void)
8891+static unsigned long mmap_rnd(struct mm_struct *mm)
8892 {
8893 unsigned long rnd = 0;
8894
8895+#ifdef CONFIG_PAX_RANDMMAP
8896+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8897+#endif
8898+
8899 if (current->flags & PF_RANDOMIZE) {
8900 /* 8MB for 32bit, 1GB for 64bit */
8901 if (is_32bit_task())
8902@@ -67,7 +71,7 @@ static unsigned long mmap_rnd(void)
8903 return rnd << PAGE_SHIFT;
8904 }
8905
8906-static inline unsigned long mmap_base(void)
8907+static inline unsigned long mmap_base(struct mm_struct *mm)
8908 {
8909 unsigned long gap = rlimit(RLIMIT_STACK);
8910
8911@@ -76,7 +80,7 @@ static inline unsigned long mmap_base(void)
8912 else if (gap > MAX_GAP)
8913 gap = MAX_GAP;
8914
8915- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
8916+ return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd(mm));
8917 }
8918
8919 /*
8920@@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8921 */
8922 if (mmap_is_legacy()) {
8923 mm->mmap_base = TASK_UNMAPPED_BASE;
8924+
8925+#ifdef CONFIG_PAX_RANDMMAP
8926+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8927+ mm->mmap_base += mm->delta_mmap;
8928+#endif
8929+
8930 mm->get_unmapped_area = arch_get_unmapped_area;
8931 } else {
8932- mm->mmap_base = mmap_base();
8933+ mm->mmap_base = mmap_base(mm);
8934+
8935+#ifdef CONFIG_PAX_RANDMMAP
8936+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8937+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8938+#endif
8939+
8940 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8941 }
8942 }
8943diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
8944index b0c75cc..ef7fb93 100644
8945--- a/arch/powerpc/mm/slice.c
8946+++ b/arch/powerpc/mm/slice.c
8947@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
8948 if ((mm->task_size - len) < addr)
8949 return 0;
8950 vma = find_vma(mm, addr);
8951- return (!vma || (addr + len) <= vma->vm_start);
8952+ return check_heap_stack_gap(vma, addr, len, 0);
8953 }
8954
8955 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
8956@@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
8957 info.align_offset = 0;
8958
8959 addr = TASK_UNMAPPED_BASE;
8960+
8961+#ifdef CONFIG_PAX_RANDMMAP
8962+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8963+ addr += mm->delta_mmap;
8964+#endif
8965+
8966 while (addr < TASK_SIZE) {
8967 info.low_limit = addr;
8968 if (!slice_scan_available(addr, available, 1, &addr))
8969@@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
8970 if (fixed && addr > (mm->task_size - len))
8971 return -ENOMEM;
8972
8973+#ifdef CONFIG_PAX_RANDMMAP
8974+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
8975+ addr = 0;
8976+#endif
8977+
8978 /* If hint, make sure it matches our alignment restrictions */
8979 if (!fixed && addr) {
8980 addr = _ALIGN_UP(addr, 1ul << pshift);
8981diff --git a/arch/powerpc/platforms/cell/celleb_scc_pciex.c b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
8982index 4278acf..67fd0e6 100644
8983--- a/arch/powerpc/platforms/cell/celleb_scc_pciex.c
8984+++ b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
8985@@ -400,8 +400,8 @@ static int scc_pciex_write_config(struct pci_bus *bus, unsigned int devfn,
8986 }
8987
8988 static struct pci_ops scc_pciex_pci_ops = {
8989- scc_pciex_read_config,
8990- scc_pciex_write_config,
8991+ .read = scc_pciex_read_config,
8992+ .write = scc_pciex_write_config,
8993 };
8994
8995 static void pciex_clear_intr_all(unsigned int __iomem *base)
8996diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
8997index 9098692..3d54cd1 100644
8998--- a/arch/powerpc/platforms/cell/spufs/file.c
8999+++ b/arch/powerpc/platforms/cell/spufs/file.c
9000@@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9001 return VM_FAULT_NOPAGE;
9002 }
9003
9004-static int spufs_mem_mmap_access(struct vm_area_struct *vma,
9005+static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
9006 unsigned long address,
9007- void *buf, int len, int write)
9008+ void *buf, size_t len, int write)
9009 {
9010 struct spu_context *ctx = vma->vm_file->private_data;
9011 unsigned long offset = address - vma->vm_start;
9012diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
9013index 1d47061..0714963 100644
9014--- a/arch/s390/include/asm/atomic.h
9015+++ b/arch/s390/include/asm/atomic.h
9016@@ -412,6 +412,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
9017 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
9018 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9019
9020+#define atomic64_read_unchecked(v) atomic64_read(v)
9021+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
9022+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
9023+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
9024+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
9025+#define atomic64_inc_unchecked(v) atomic64_inc(v)
9026+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
9027+#define atomic64_dec_unchecked(v) atomic64_dec(v)
9028+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
9029+
9030 #define smp_mb__before_atomic_dec() smp_mb()
9031 #define smp_mb__after_atomic_dec() smp_mb()
9032 #define smp_mb__before_atomic_inc() smp_mb()
9033diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
9034index 4d7ccac..d03d0ad 100644
9035--- a/arch/s390/include/asm/cache.h
9036+++ b/arch/s390/include/asm/cache.h
9037@@ -9,8 +9,10 @@
9038 #ifndef __ARCH_S390_CACHE_H
9039 #define __ARCH_S390_CACHE_H
9040
9041-#define L1_CACHE_BYTES 256
9042+#include <linux/const.h>
9043+
9044 #define L1_CACHE_SHIFT 8
9045+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9046 #define NET_SKB_PAD 32
9047
9048 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9049diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
9050index 78f4f87..598ce39 100644
9051--- a/arch/s390/include/asm/elf.h
9052+++ b/arch/s390/include/asm/elf.h
9053@@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
9054 the loader. We need to make sure that it is out of the way of the program
9055 that it will "exec", and that there is sufficient room for the brk. */
9056
9057-extern unsigned long randomize_et_dyn(unsigned long base);
9058-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
9059+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
9060+
9061+#ifdef CONFIG_PAX_ASLR
9062+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
9063+
9064+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9065+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9066+#endif
9067
9068 /* This yields a mask that user programs can use to figure out what
9069 instruction set this CPU supports. */
9070@@ -222,9 +228,6 @@ struct linux_binprm;
9071 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
9072 int arch_setup_additional_pages(struct linux_binprm *, int);
9073
9074-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
9075-#define arch_randomize_brk arch_randomize_brk
9076-
9077 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
9078
9079 #endif
9080diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
9081index c4a93d6..4d2a9b4 100644
9082--- a/arch/s390/include/asm/exec.h
9083+++ b/arch/s390/include/asm/exec.h
9084@@ -7,6 +7,6 @@
9085 #ifndef __ASM_EXEC_H
9086 #define __ASM_EXEC_H
9087
9088-extern unsigned long arch_align_stack(unsigned long sp);
9089+#define arch_align_stack(x) ((x) & ~0xfUL)
9090
9091 #endif /* __ASM_EXEC_H */
9092diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
9093index 79330af..254cf37 100644
9094--- a/arch/s390/include/asm/uaccess.h
9095+++ b/arch/s390/include/asm/uaccess.h
9096@@ -59,6 +59,7 @@ static inline int __range_ok(unsigned long addr, unsigned long size)
9097 __range_ok((unsigned long)(addr), (size)); \
9098 })
9099
9100+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
9101 #define access_ok(type, addr, size) __access_ok(addr, size)
9102
9103 /*
9104@@ -245,6 +246,10 @@ static inline unsigned long __must_check
9105 copy_to_user(void __user *to, const void *from, unsigned long n)
9106 {
9107 might_fault();
9108+
9109+ if ((long)n < 0)
9110+ return n;
9111+
9112 return __copy_to_user(to, from, n);
9113 }
9114
9115@@ -268,6 +273,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
9116 static inline unsigned long __must_check
9117 __copy_from_user(void *to, const void __user *from, unsigned long n)
9118 {
9119+ if ((long)n < 0)
9120+ return n;
9121+
9122 return uaccess.copy_from_user(n, from, to);
9123 }
9124
9125@@ -296,10 +304,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
9126 static inline unsigned long __must_check
9127 copy_from_user(void *to, const void __user *from, unsigned long n)
9128 {
9129- unsigned int sz = __compiletime_object_size(to);
9130+ size_t sz = __compiletime_object_size(to);
9131
9132 might_fault();
9133- if (unlikely(sz != -1 && sz < n)) {
9134+
9135+ if ((long)n < 0)
9136+ return n;
9137+
9138+ if (unlikely(sz != (size_t)-1 && sz < n)) {
9139 copy_from_user_overflow();
9140 return n;
9141 }
9142diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
9143index b89b591..fd9609d 100644
9144--- a/arch/s390/kernel/module.c
9145+++ b/arch/s390/kernel/module.c
9146@@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
9147
9148 /* Increase core size by size of got & plt and set start
9149 offsets for got and plt. */
9150- me->core_size = ALIGN(me->core_size, 4);
9151- me->arch.got_offset = me->core_size;
9152- me->core_size += me->arch.got_size;
9153- me->arch.plt_offset = me->core_size;
9154- me->core_size += me->arch.plt_size;
9155+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
9156+ me->arch.got_offset = me->core_size_rw;
9157+ me->core_size_rw += me->arch.got_size;
9158+ me->arch.plt_offset = me->core_size_rx;
9159+ me->core_size_rx += me->arch.plt_size;
9160 return 0;
9161 }
9162
9163@@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9164 if (info->got_initialized == 0) {
9165 Elf_Addr *gotent;
9166
9167- gotent = me->module_core + me->arch.got_offset +
9168+ gotent = me->module_core_rw + me->arch.got_offset +
9169 info->got_offset;
9170 *gotent = val;
9171 info->got_initialized = 1;
9172@@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9173 rc = apply_rela_bits(loc, val, 0, 64, 0);
9174 else if (r_type == R_390_GOTENT ||
9175 r_type == R_390_GOTPLTENT) {
9176- val += (Elf_Addr) me->module_core - loc;
9177+ val += (Elf_Addr) me->module_core_rw - loc;
9178 rc = apply_rela_bits(loc, val, 1, 32, 1);
9179 }
9180 break;
9181@@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9182 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
9183 if (info->plt_initialized == 0) {
9184 unsigned int *ip;
9185- ip = me->module_core + me->arch.plt_offset +
9186+ ip = me->module_core_rx + me->arch.plt_offset +
9187 info->plt_offset;
9188 #ifndef CONFIG_64BIT
9189 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
9190@@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9191 val - loc + 0xffffUL < 0x1ffffeUL) ||
9192 (r_type == R_390_PLT32DBL &&
9193 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
9194- val = (Elf_Addr) me->module_core +
9195+ val = (Elf_Addr) me->module_core_rx +
9196 me->arch.plt_offset +
9197 info->plt_offset;
9198 val += rela->r_addend - loc;
9199@@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9200 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
9201 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
9202 val = val + rela->r_addend -
9203- ((Elf_Addr) me->module_core + me->arch.got_offset);
9204+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
9205 if (r_type == R_390_GOTOFF16)
9206 rc = apply_rela_bits(loc, val, 0, 16, 0);
9207 else if (r_type == R_390_GOTOFF32)
9208@@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9209 break;
9210 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
9211 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
9212- val = (Elf_Addr) me->module_core + me->arch.got_offset +
9213+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
9214 rela->r_addend - loc;
9215 if (r_type == R_390_GOTPC)
9216 rc = apply_rela_bits(loc, val, 1, 32, 0);
9217diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
9218index dd14532..1dfc145 100644
9219--- a/arch/s390/kernel/process.c
9220+++ b/arch/s390/kernel/process.c
9221@@ -242,37 +242,3 @@ unsigned long get_wchan(struct task_struct *p)
9222 }
9223 return 0;
9224 }
9225-
9226-unsigned long arch_align_stack(unsigned long sp)
9227-{
9228- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9229- sp -= get_random_int() & ~PAGE_MASK;
9230- return sp & ~0xf;
9231-}
9232-
9233-static inline unsigned long brk_rnd(void)
9234-{
9235- /* 8MB for 32bit, 1GB for 64bit */
9236- if (is_32bit_task())
9237- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
9238- else
9239- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
9240-}
9241-
9242-unsigned long arch_randomize_brk(struct mm_struct *mm)
9243-{
9244- unsigned long ret;
9245-
9246- ret = PAGE_ALIGN(mm->brk + brk_rnd());
9247- return (ret > mm->brk) ? ret : mm->brk;
9248-}
9249-
9250-unsigned long randomize_et_dyn(unsigned long base)
9251-{
9252- unsigned long ret;
9253-
9254- if (!(current->flags & PF_RANDOMIZE))
9255- return base;
9256- ret = PAGE_ALIGN(base + brk_rnd());
9257- return (ret > base) ? ret : base;
9258-}
9259diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
9260index 9b436c2..54fbf0a 100644
9261--- a/arch/s390/mm/mmap.c
9262+++ b/arch/s390/mm/mmap.c
9263@@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9264 */
9265 if (mmap_is_legacy()) {
9266 mm->mmap_base = mmap_base_legacy();
9267+
9268+#ifdef CONFIG_PAX_RANDMMAP
9269+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9270+ mm->mmap_base += mm->delta_mmap;
9271+#endif
9272+
9273 mm->get_unmapped_area = arch_get_unmapped_area;
9274 } else {
9275 mm->mmap_base = mmap_base();
9276+
9277+#ifdef CONFIG_PAX_RANDMMAP
9278+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9279+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9280+#endif
9281+
9282 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9283 }
9284 }
9285@@ -170,9 +182,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9286 */
9287 if (mmap_is_legacy()) {
9288 mm->mmap_base = mmap_base_legacy();
9289+
9290+#ifdef CONFIG_PAX_RANDMMAP
9291+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9292+ mm->mmap_base += mm->delta_mmap;
9293+#endif
9294+
9295 mm->get_unmapped_area = s390_get_unmapped_area;
9296 } else {
9297 mm->mmap_base = mmap_base();
9298+
9299+#ifdef CONFIG_PAX_RANDMMAP
9300+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9301+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9302+#endif
9303+
9304 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
9305 }
9306 }
9307diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
9308index ae3d59f..f65f075 100644
9309--- a/arch/score/include/asm/cache.h
9310+++ b/arch/score/include/asm/cache.h
9311@@ -1,7 +1,9 @@
9312 #ifndef _ASM_SCORE_CACHE_H
9313 #define _ASM_SCORE_CACHE_H
9314
9315+#include <linux/const.h>
9316+
9317 #define L1_CACHE_SHIFT 4
9318-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9319+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9320
9321 #endif /* _ASM_SCORE_CACHE_H */
9322diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
9323index f9f3cd5..58ff438 100644
9324--- a/arch/score/include/asm/exec.h
9325+++ b/arch/score/include/asm/exec.h
9326@@ -1,6 +1,6 @@
9327 #ifndef _ASM_SCORE_EXEC_H
9328 #define _ASM_SCORE_EXEC_H
9329
9330-extern unsigned long arch_align_stack(unsigned long sp);
9331+#define arch_align_stack(x) (x)
9332
9333 #endif /* _ASM_SCORE_EXEC_H */
9334diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
9335index a1519ad3..e8ac1ff 100644
9336--- a/arch/score/kernel/process.c
9337+++ b/arch/score/kernel/process.c
9338@@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
9339
9340 return task_pt_regs(task)->cp0_epc;
9341 }
9342-
9343-unsigned long arch_align_stack(unsigned long sp)
9344-{
9345- return sp;
9346-}
9347diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
9348index ef9e555..331bd29 100644
9349--- a/arch/sh/include/asm/cache.h
9350+++ b/arch/sh/include/asm/cache.h
9351@@ -9,10 +9,11 @@
9352 #define __ASM_SH_CACHE_H
9353 #ifdef __KERNEL__
9354
9355+#include <linux/const.h>
9356 #include <linux/init.h>
9357 #include <cpu/cache.h>
9358
9359-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9360+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9361
9362 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9363
9364diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
9365index 6777177..cb5e44f 100644
9366--- a/arch/sh/mm/mmap.c
9367+++ b/arch/sh/mm/mmap.c
9368@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9369 struct mm_struct *mm = current->mm;
9370 struct vm_area_struct *vma;
9371 int do_colour_align;
9372+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9373 struct vm_unmapped_area_info info;
9374
9375 if (flags & MAP_FIXED) {
9376@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9377 if (filp || (flags & MAP_SHARED))
9378 do_colour_align = 1;
9379
9380+#ifdef CONFIG_PAX_RANDMMAP
9381+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9382+#endif
9383+
9384 if (addr) {
9385 if (do_colour_align)
9386 addr = COLOUR_ALIGN(addr, pgoff);
9387@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9388 addr = PAGE_ALIGN(addr);
9389
9390 vma = find_vma(mm, addr);
9391- if (TASK_SIZE - len >= addr &&
9392- (!vma || addr + len <= vma->vm_start))
9393+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9394 return addr;
9395 }
9396
9397 info.flags = 0;
9398 info.length = len;
9399- info.low_limit = TASK_UNMAPPED_BASE;
9400+ info.low_limit = mm->mmap_base;
9401 info.high_limit = TASK_SIZE;
9402 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
9403 info.align_offset = pgoff << PAGE_SHIFT;
9404@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9405 struct mm_struct *mm = current->mm;
9406 unsigned long addr = addr0;
9407 int do_colour_align;
9408+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9409 struct vm_unmapped_area_info info;
9410
9411 if (flags & MAP_FIXED) {
9412@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9413 if (filp || (flags & MAP_SHARED))
9414 do_colour_align = 1;
9415
9416+#ifdef CONFIG_PAX_RANDMMAP
9417+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9418+#endif
9419+
9420 /* requesting a specific address */
9421 if (addr) {
9422 if (do_colour_align)
9423@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9424 addr = PAGE_ALIGN(addr);
9425
9426 vma = find_vma(mm, addr);
9427- if (TASK_SIZE - len >= addr &&
9428- (!vma || addr + len <= vma->vm_start))
9429+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9430 return addr;
9431 }
9432
9433@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9434 VM_BUG_ON(addr != -ENOMEM);
9435 info.flags = 0;
9436 info.low_limit = TASK_UNMAPPED_BASE;
9437+
9438+#ifdef CONFIG_PAX_RANDMMAP
9439+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9440+ info.low_limit += mm->delta_mmap;
9441+#endif
9442+
9443 info.high_limit = TASK_SIZE;
9444 addr = vm_unmapped_area(&info);
9445 }
9446diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
9447index be56a24..443328f 100644
9448--- a/arch/sparc/include/asm/atomic_64.h
9449+++ b/arch/sparc/include/asm/atomic_64.h
9450@@ -14,18 +14,40 @@
9451 #define ATOMIC64_INIT(i) { (i) }
9452
9453 #define atomic_read(v) (*(volatile int *)&(v)->counter)
9454+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9455+{
9456+ return v->counter;
9457+}
9458 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
9459+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9460+{
9461+ return v->counter;
9462+}
9463
9464 #define atomic_set(v, i) (((v)->counter) = i)
9465+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9466+{
9467+ v->counter = i;
9468+}
9469 #define atomic64_set(v, i) (((v)->counter) = i)
9470+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9471+{
9472+ v->counter = i;
9473+}
9474
9475 extern void atomic_add(int, atomic_t *);
9476+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
9477 extern void atomic64_add(long, atomic64_t *);
9478+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
9479 extern void atomic_sub(int, atomic_t *);
9480+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
9481 extern void atomic64_sub(long, atomic64_t *);
9482+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
9483
9484 extern int atomic_add_ret(int, atomic_t *);
9485+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
9486 extern long atomic64_add_ret(long, atomic64_t *);
9487+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
9488 extern int atomic_sub_ret(int, atomic_t *);
9489 extern long atomic64_sub_ret(long, atomic64_t *);
9490
9491@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9492 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
9493
9494 #define atomic_inc_return(v) atomic_add_ret(1, v)
9495+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9496+{
9497+ return atomic_add_ret_unchecked(1, v);
9498+}
9499 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
9500+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9501+{
9502+ return atomic64_add_ret_unchecked(1, v);
9503+}
9504
9505 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
9506 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
9507
9508 #define atomic_add_return(i, v) atomic_add_ret(i, v)
9509+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9510+{
9511+ return atomic_add_ret_unchecked(i, v);
9512+}
9513 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
9514+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9515+{
9516+ return atomic64_add_ret_unchecked(i, v);
9517+}
9518
9519 /*
9520 * atomic_inc_and_test - increment and test
9521@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9522 * other cases.
9523 */
9524 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
9525+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9526+{
9527+ return atomic_inc_return_unchecked(v) == 0;
9528+}
9529 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
9530
9531 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
9532@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9533 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
9534
9535 #define atomic_inc(v) atomic_add(1, v)
9536+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9537+{
9538+ atomic_add_unchecked(1, v);
9539+}
9540 #define atomic64_inc(v) atomic64_add(1, v)
9541+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9542+{
9543+ atomic64_add_unchecked(1, v);
9544+}
9545
9546 #define atomic_dec(v) atomic_sub(1, v)
9547+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9548+{
9549+ atomic_sub_unchecked(1, v);
9550+}
9551 #define atomic64_dec(v) atomic64_sub(1, v)
9552+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9553+{
9554+ atomic64_sub_unchecked(1, v);
9555+}
9556
9557 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
9558 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
9559
9560 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
9561+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9562+{
9563+ return cmpxchg(&v->counter, old, new);
9564+}
9565 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
9566+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9567+{
9568+ return xchg(&v->counter, new);
9569+}
9570
9571 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9572 {
9573- int c, old;
9574+ int c, old, new;
9575 c = atomic_read(v);
9576 for (;;) {
9577- if (unlikely(c == (u)))
9578+ if (unlikely(c == u))
9579 break;
9580- old = atomic_cmpxchg((v), c, c + (a));
9581+
9582+ asm volatile("addcc %2, %0, %0\n"
9583+
9584+#ifdef CONFIG_PAX_REFCOUNT
9585+ "tvs %%icc, 6\n"
9586+#endif
9587+
9588+ : "=r" (new)
9589+ : "0" (c), "ir" (a)
9590+ : "cc");
9591+
9592+ old = atomic_cmpxchg(v, c, new);
9593 if (likely(old == c))
9594 break;
9595 c = old;
9596@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9597 #define atomic64_cmpxchg(v, o, n) \
9598 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
9599 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
9600+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
9601+{
9602+ return xchg(&v->counter, new);
9603+}
9604
9605 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9606 {
9607- long c, old;
9608+ long c, old, new;
9609 c = atomic64_read(v);
9610 for (;;) {
9611- if (unlikely(c == (u)))
9612+ if (unlikely(c == u))
9613 break;
9614- old = atomic64_cmpxchg((v), c, c + (a));
9615+
9616+ asm volatile("addcc %2, %0, %0\n"
9617+
9618+#ifdef CONFIG_PAX_REFCOUNT
9619+ "tvs %%xcc, 6\n"
9620+#endif
9621+
9622+ : "=r" (new)
9623+ : "0" (c), "ir" (a)
9624+ : "cc");
9625+
9626+ old = atomic64_cmpxchg(v, c, new);
9627 if (likely(old == c))
9628 break;
9629 c = old;
9630 }
9631- return c != (u);
9632+ return c != u;
9633 }
9634
9635 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9636diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
9637index 5bb6991..5c2132e 100644
9638--- a/arch/sparc/include/asm/cache.h
9639+++ b/arch/sparc/include/asm/cache.h
9640@@ -7,10 +7,12 @@
9641 #ifndef _SPARC_CACHE_H
9642 #define _SPARC_CACHE_H
9643
9644+#include <linux/const.h>
9645+
9646 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
9647
9648 #define L1_CACHE_SHIFT 5
9649-#define L1_CACHE_BYTES 32
9650+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9651
9652 #ifdef CONFIG_SPARC32
9653 #define SMP_CACHE_BYTES_SHIFT 5
9654diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
9655index a24e41f..47677ff 100644
9656--- a/arch/sparc/include/asm/elf_32.h
9657+++ b/arch/sparc/include/asm/elf_32.h
9658@@ -114,6 +114,13 @@ typedef struct {
9659
9660 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
9661
9662+#ifdef CONFIG_PAX_ASLR
9663+#define PAX_ELF_ET_DYN_BASE 0x10000UL
9664+
9665+#define PAX_DELTA_MMAP_LEN 16
9666+#define PAX_DELTA_STACK_LEN 16
9667+#endif
9668+
9669 /* This yields a mask that user programs can use to figure out what
9670 instruction set this cpu supports. This can NOT be done in userspace
9671 on Sparc. */
9672diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
9673index 370ca1e..d4f4a98 100644
9674--- a/arch/sparc/include/asm/elf_64.h
9675+++ b/arch/sparc/include/asm/elf_64.h
9676@@ -189,6 +189,13 @@ typedef struct {
9677 #define ELF_ET_DYN_BASE 0x0000010000000000UL
9678 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
9679
9680+#ifdef CONFIG_PAX_ASLR
9681+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
9682+
9683+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
9684+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
9685+#endif
9686+
9687 extern unsigned long sparc64_elf_hwcap;
9688 #define ELF_HWCAP sparc64_elf_hwcap
9689
9690diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
9691index 9b1c36d..209298b 100644
9692--- a/arch/sparc/include/asm/pgalloc_32.h
9693+++ b/arch/sparc/include/asm/pgalloc_32.h
9694@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
9695 }
9696
9697 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
9698+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
9699
9700 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
9701 unsigned long address)
9702diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
9703index bcfe063..b333142 100644
9704--- a/arch/sparc/include/asm/pgalloc_64.h
9705+++ b/arch/sparc/include/asm/pgalloc_64.h
9706@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9707 }
9708
9709 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
9710+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
9711
9712 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
9713 {
9714diff --git a/arch/sparc/include/asm/pgtable.h b/arch/sparc/include/asm/pgtable.h
9715index 59ba6f6..4518128 100644
9716--- a/arch/sparc/include/asm/pgtable.h
9717+++ b/arch/sparc/include/asm/pgtable.h
9718@@ -5,4 +5,8 @@
9719 #else
9720 #include <asm/pgtable_32.h>
9721 #endif
9722+
9723+#define ktla_ktva(addr) (addr)
9724+#define ktva_ktla(addr) (addr)
9725+
9726 #endif
9727diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
9728index 502f632..da1917f 100644
9729--- a/arch/sparc/include/asm/pgtable_32.h
9730+++ b/arch/sparc/include/asm/pgtable_32.h
9731@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
9732 #define PAGE_SHARED SRMMU_PAGE_SHARED
9733 #define PAGE_COPY SRMMU_PAGE_COPY
9734 #define PAGE_READONLY SRMMU_PAGE_RDONLY
9735+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
9736+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
9737+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
9738 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
9739
9740 /* Top-level page directory - dummy used by init-mm.
9741@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
9742
9743 /* xwr */
9744 #define __P000 PAGE_NONE
9745-#define __P001 PAGE_READONLY
9746-#define __P010 PAGE_COPY
9747-#define __P011 PAGE_COPY
9748+#define __P001 PAGE_READONLY_NOEXEC
9749+#define __P010 PAGE_COPY_NOEXEC
9750+#define __P011 PAGE_COPY_NOEXEC
9751 #define __P100 PAGE_READONLY
9752 #define __P101 PAGE_READONLY
9753 #define __P110 PAGE_COPY
9754 #define __P111 PAGE_COPY
9755
9756 #define __S000 PAGE_NONE
9757-#define __S001 PAGE_READONLY
9758-#define __S010 PAGE_SHARED
9759-#define __S011 PAGE_SHARED
9760+#define __S001 PAGE_READONLY_NOEXEC
9761+#define __S010 PAGE_SHARED_NOEXEC
9762+#define __S011 PAGE_SHARED_NOEXEC
9763 #define __S100 PAGE_READONLY
9764 #define __S101 PAGE_READONLY
9765 #define __S110 PAGE_SHARED
9766diff --git a/arch/sparc/include/asm/pgtable_64.h b/arch/sparc/include/asm/pgtable_64.h
9767index 0f9e945..a949e55 100644
9768--- a/arch/sparc/include/asm/pgtable_64.h
9769+++ b/arch/sparc/include/asm/pgtable_64.h
9770@@ -71,6 +71,23 @@
9771
9772 #include <linux/sched.h>
9773
9774+extern unsigned long sparc64_valid_addr_bitmap[];
9775+
9776+/* Needs to be defined here and not in linux/mm.h, as it is arch dependent */
9777+static inline bool __kern_addr_valid(unsigned long paddr)
9778+{
9779+ if ((paddr >> MAX_PHYS_ADDRESS_BITS) != 0UL)
9780+ return false;
9781+ return test_bit(paddr >> ILOG2_4MB, sparc64_valid_addr_bitmap);
9782+}
9783+
9784+static inline bool kern_addr_valid(unsigned long addr)
9785+{
9786+ unsigned long paddr = __pa(addr);
9787+
9788+ return __kern_addr_valid(paddr);
9789+}
9790+
9791 /* Entries per page directory level. */
9792 #define PTRS_PER_PTE (1UL << (PAGE_SHIFT-3))
9793 #define PTRS_PER_PMD (1UL << PMD_BITS)
9794@@ -79,9 +96,12 @@
9795 /* Kernel has a separate 44bit address space. */
9796 #define FIRST_USER_ADDRESS 0
9797
9798-#define pte_ERROR(e) __builtin_trap()
9799-#define pmd_ERROR(e) __builtin_trap()
9800-#define pgd_ERROR(e) __builtin_trap()
9801+#define pmd_ERROR(e) \
9802+ pr_err("%s:%d: bad pmd %p(%016lx) seen at (%pS)\n", \
9803+ __FILE__, __LINE__, &(e), pmd_val(e), __builtin_return_address(0))
9804+#define pgd_ERROR(e) \
9805+ pr_err("%s:%d: bad pgd %p(%016lx) seen at (%pS)\n", \
9806+ __FILE__, __LINE__, &(e), pgd_val(e), __builtin_return_address(0))
9807
9808 #endif /* !(__ASSEMBLY__) */
9809
9810@@ -633,7 +653,7 @@ static inline unsigned long pmd_large(pmd_t pmd)
9811 {
9812 pte_t pte = __pte(pmd_val(pmd));
9813
9814- return (pte_val(pte) & _PAGE_PMD_HUGE) && pte_present(pte);
9815+ return pte_val(pte) & _PAGE_PMD_HUGE;
9816 }
9817
9818 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
9819@@ -719,20 +739,6 @@ static inline pmd_t pmd_mkwrite(pmd_t pmd)
9820 return __pmd(pte_val(pte));
9821 }
9822
9823-static inline pmd_t pmd_mknotpresent(pmd_t pmd)
9824-{
9825- unsigned long mask;
9826-
9827- if (tlb_type == hypervisor)
9828- mask = _PAGE_PRESENT_4V;
9829- else
9830- mask = _PAGE_PRESENT_4U;
9831-
9832- pmd_val(pmd) &= ~mask;
9833-
9834- return pmd;
9835-}
9836-
9837 static inline pmd_t pmd_mksplitting(pmd_t pmd)
9838 {
9839 pte_t pte = __pte(pmd_val(pmd));
9840@@ -757,6 +763,20 @@ static inline int pmd_present(pmd_t pmd)
9841
9842 #define pmd_none(pmd) (!pmd_val(pmd))
9843
9844+/* pmd_bad() is only called on non-trans-huge PMDs. Our encoding is
9845+ * very simple, it's just the physical address. PTE tables are of
9846+ * size PAGE_SIZE so make sure the sub-PAGE_SIZE bits are clear and
9847+ * the top bits outside of the range of any physical address size we
9848+ * support are clear as well. We also validate the physical itself.
9849+ */
9850+#define pmd_bad(pmd) ((pmd_val(pmd) & ~PAGE_MASK) || \
9851+ !__kern_addr_valid(pmd_val(pmd)))
9852+
9853+#define pud_none(pud) (!pud_val(pud))
9854+
9855+#define pud_bad(pud) ((pud_val(pud) & ~PAGE_MASK) || \
9856+ !__kern_addr_valid(pud_val(pud)))
9857+
9858 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
9859 extern void set_pmd_at(struct mm_struct *mm, unsigned long addr,
9860 pmd_t *pmdp, pmd_t pmd);
9861@@ -790,10 +810,7 @@ static inline unsigned long __pmd_page(pmd_t pmd)
9862 #define pud_page_vaddr(pud) \
9863 ((unsigned long) __va(pud_val(pud)))
9864 #define pud_page(pud) virt_to_page((void *)pud_page_vaddr(pud))
9865-#define pmd_bad(pmd) (0)
9866 #define pmd_clear(pmdp) (pmd_val(*(pmdp)) = 0UL)
9867-#define pud_none(pud) (!pud_val(pud))
9868-#define pud_bad(pud) (0)
9869 #define pud_present(pud) (pud_val(pud) != 0U)
9870 #define pud_clear(pudp) (pud_val(*(pudp)) = 0UL)
9871
9872@@ -893,6 +910,10 @@ extern void update_mmu_cache(struct vm_area_struct *, unsigned long, pte_t *);
9873 extern void update_mmu_cache_pmd(struct vm_area_struct *vma, unsigned long addr,
9874 pmd_t *pmd);
9875
9876+#define __HAVE_ARCH_PMDP_INVALIDATE
9877+extern void pmdp_invalidate(struct vm_area_struct *vma, unsigned long address,
9878+ pmd_t *pmdp);
9879+
9880 #define __HAVE_ARCH_PGTABLE_DEPOSIT
9881 extern void pgtable_trans_huge_deposit(struct mm_struct *mm, pmd_t *pmdp,
9882 pgtable_t pgtable);
9883@@ -919,18 +940,6 @@ extern unsigned long pte_file(pte_t);
9884 extern pte_t pgoff_to_pte(unsigned long);
9885 #define PTE_FILE_MAX_BITS (64UL - PAGE_SHIFT - 1UL)
9886
9887-extern unsigned long sparc64_valid_addr_bitmap[];
9888-
9889-/* Needs to be defined here and not in linux/mm.h, as it is arch dependent */
9890-static inline bool kern_addr_valid(unsigned long addr)
9891-{
9892- unsigned long paddr = __pa(addr);
9893-
9894- if ((paddr >> 41UL) != 0UL)
9895- return false;
9896- return test_bit(paddr >> 22, sparc64_valid_addr_bitmap);
9897-}
9898-
9899 extern int page_in_phys_avail(unsigned long paddr);
9900
9901 /*
9902diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
9903index 79da178..c2eede8 100644
9904--- a/arch/sparc/include/asm/pgtsrmmu.h
9905+++ b/arch/sparc/include/asm/pgtsrmmu.h
9906@@ -115,6 +115,11 @@
9907 SRMMU_EXEC | SRMMU_REF)
9908 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
9909 SRMMU_EXEC | SRMMU_REF)
9910+
9911+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
9912+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9913+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9914+
9915 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
9916 SRMMU_DIRTY | SRMMU_REF)
9917
9918diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
9919index 9689176..63c18ea 100644
9920--- a/arch/sparc/include/asm/spinlock_64.h
9921+++ b/arch/sparc/include/asm/spinlock_64.h
9922@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
9923
9924 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
9925
9926-static void inline arch_read_lock(arch_rwlock_t *lock)
9927+static inline void arch_read_lock(arch_rwlock_t *lock)
9928 {
9929 unsigned long tmp1, tmp2;
9930
9931 __asm__ __volatile__ (
9932 "1: ldsw [%2], %0\n"
9933 " brlz,pn %0, 2f\n"
9934-"4: add %0, 1, %1\n"
9935+"4: addcc %0, 1, %1\n"
9936+
9937+#ifdef CONFIG_PAX_REFCOUNT
9938+" tvs %%icc, 6\n"
9939+#endif
9940+
9941 " cas [%2], %0, %1\n"
9942 " cmp %0, %1\n"
9943 " bne,pn %%icc, 1b\n"
9944@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
9945 " .previous"
9946 : "=&r" (tmp1), "=&r" (tmp2)
9947 : "r" (lock)
9948- : "memory");
9949+ : "memory", "cc");
9950 }
9951
9952-static int inline arch_read_trylock(arch_rwlock_t *lock)
9953+static inline int arch_read_trylock(arch_rwlock_t *lock)
9954 {
9955 int tmp1, tmp2;
9956
9957@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9958 "1: ldsw [%2], %0\n"
9959 " brlz,a,pn %0, 2f\n"
9960 " mov 0, %0\n"
9961-" add %0, 1, %1\n"
9962+" addcc %0, 1, %1\n"
9963+
9964+#ifdef CONFIG_PAX_REFCOUNT
9965+" tvs %%icc, 6\n"
9966+#endif
9967+
9968 " cas [%2], %0, %1\n"
9969 " cmp %0, %1\n"
9970 " bne,pn %%icc, 1b\n"
9971@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9972 return tmp1;
9973 }
9974
9975-static void inline arch_read_unlock(arch_rwlock_t *lock)
9976+static inline void arch_read_unlock(arch_rwlock_t *lock)
9977 {
9978 unsigned long tmp1, tmp2;
9979
9980 __asm__ __volatile__(
9981 "1: lduw [%2], %0\n"
9982-" sub %0, 1, %1\n"
9983+" subcc %0, 1, %1\n"
9984+
9985+#ifdef CONFIG_PAX_REFCOUNT
9986+" tvs %%icc, 6\n"
9987+#endif
9988+
9989 " cas [%2], %0, %1\n"
9990 " cmp %0, %1\n"
9991 " bne,pn %%xcc, 1b\n"
9992@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
9993 : "memory");
9994 }
9995
9996-static void inline arch_write_lock(arch_rwlock_t *lock)
9997+static inline void arch_write_lock(arch_rwlock_t *lock)
9998 {
9999 unsigned long mask, tmp1, tmp2;
10000
10001@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
10002 : "memory");
10003 }
10004
10005-static void inline arch_write_unlock(arch_rwlock_t *lock)
10006+static inline void arch_write_unlock(arch_rwlock_t *lock)
10007 {
10008 __asm__ __volatile__(
10009 " stw %%g0, [%0]"
10010@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
10011 : "memory");
10012 }
10013
10014-static int inline arch_write_trylock(arch_rwlock_t *lock)
10015+static inline int arch_write_trylock(arch_rwlock_t *lock)
10016 {
10017 unsigned long mask, tmp1, tmp2, result;
10018
10019diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
10020index 96efa7a..16858bf 100644
10021--- a/arch/sparc/include/asm/thread_info_32.h
10022+++ b/arch/sparc/include/asm/thread_info_32.h
10023@@ -49,6 +49,8 @@ struct thread_info {
10024 unsigned long w_saved;
10025
10026 struct restart_block restart_block;
10027+
10028+ unsigned long lowest_stack;
10029 };
10030
10031 /*
10032diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
10033index a5f01ac..703b554 100644
10034--- a/arch/sparc/include/asm/thread_info_64.h
10035+++ b/arch/sparc/include/asm/thread_info_64.h
10036@@ -63,6 +63,8 @@ struct thread_info {
10037 struct pt_regs *kern_una_regs;
10038 unsigned int kern_una_insn;
10039
10040+ unsigned long lowest_stack;
10041+
10042 unsigned long fpregs[0] __attribute__ ((aligned(64)));
10043 };
10044
10045@@ -188,12 +190,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
10046 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
10047 /* flag bit 4 is available */
10048 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
10049-/* flag bit 6 is available */
10050+#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
10051 #define TIF_32BIT 7 /* 32-bit binary */
10052 #define TIF_NOHZ 8 /* in adaptive nohz mode */
10053 #define TIF_SECCOMP 9 /* secure computing */
10054 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
10055 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
10056+
10057 /* NOTE: Thread flags >= 12 should be ones we have no interest
10058 * in using in assembly, else we can't use the mask as
10059 * an immediate value in instructions such as andcc.
10060@@ -213,12 +216,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
10061 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
10062 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
10063 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
10064+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
10065
10066 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
10067 _TIF_DO_NOTIFY_RESUME_MASK | \
10068 _TIF_NEED_RESCHED)
10069 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
10070
10071+#define _TIF_WORK_SYSCALL \
10072+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
10073+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
10074+
10075+
10076 /*
10077 * Thread-synchronous status.
10078 *
10079diff --git a/arch/sparc/include/asm/tsb.h b/arch/sparc/include/asm/tsb.h
10080index 2230f80..90916f9 100644
10081--- a/arch/sparc/include/asm/tsb.h
10082+++ b/arch/sparc/include/asm/tsb.h
10083@@ -171,7 +171,8 @@ extern struct tsb_phys_patch_entry __tsb_phys_patch, __tsb_phys_patch_end;
10084 andcc REG1, REG2, %g0; \
10085 be,pt %xcc, 700f; \
10086 sethi %hi(4 * 1024 * 1024), REG2; \
10087- andn REG1, REG2, REG1; \
10088+ brgez,pn REG1, FAIL_LABEL; \
10089+ andn REG1, REG2, REG1; \
10090 and VADDR, REG2, REG2; \
10091 brlz,pt REG1, PTE_LABEL; \
10092 or REG1, REG2, REG1; \
10093diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
10094index 0167d26..767bb0c 100644
10095--- a/arch/sparc/include/asm/uaccess.h
10096+++ b/arch/sparc/include/asm/uaccess.h
10097@@ -1,5 +1,6 @@
10098 #ifndef ___ASM_SPARC_UACCESS_H
10099 #define ___ASM_SPARC_UACCESS_H
10100+
10101 #if defined(__sparc__) && defined(__arch64__)
10102 #include <asm/uaccess_64.h>
10103 #else
10104diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
10105index 53a28dd..50c38c3 100644
10106--- a/arch/sparc/include/asm/uaccess_32.h
10107+++ b/arch/sparc/include/asm/uaccess_32.h
10108@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
10109
10110 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
10111 {
10112- if (n && __access_ok((unsigned long) to, n))
10113+ if ((long)n < 0)
10114+ return n;
10115+
10116+ if (n && __access_ok((unsigned long) to, n)) {
10117+ if (!__builtin_constant_p(n))
10118+ check_object_size(from, n, true);
10119 return __copy_user(to, (__force void __user *) from, n);
10120- else
10121+ } else
10122 return n;
10123 }
10124
10125 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
10126 {
10127+ if ((long)n < 0)
10128+ return n;
10129+
10130+ if (!__builtin_constant_p(n))
10131+ check_object_size(from, n, true);
10132+
10133 return __copy_user(to, (__force void __user *) from, n);
10134 }
10135
10136 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
10137 {
10138- if (n && __access_ok((unsigned long) from, n))
10139+ if ((long)n < 0)
10140+ return n;
10141+
10142+ if (n && __access_ok((unsigned long) from, n)) {
10143+ if (!__builtin_constant_p(n))
10144+ check_object_size(to, n, false);
10145 return __copy_user((__force void __user *) to, from, n);
10146- else
10147+ } else
10148 return n;
10149 }
10150
10151 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
10152 {
10153+ if ((long)n < 0)
10154+ return n;
10155+
10156 return __copy_user((__force void __user *) to, from, n);
10157 }
10158
10159diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
10160index ad7e178..c9e7423 100644
10161--- a/arch/sparc/include/asm/uaccess_64.h
10162+++ b/arch/sparc/include/asm/uaccess_64.h
10163@@ -10,6 +10,7 @@
10164 #include <linux/compiler.h>
10165 #include <linux/string.h>
10166 #include <linux/thread_info.h>
10167+#include <linux/kernel.h>
10168 #include <asm/asi.h>
10169 #include <asm/spitfire.h>
10170 #include <asm-generic/uaccess-unaligned.h>
10171@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
10172 static inline unsigned long __must_check
10173 copy_from_user(void *to, const void __user *from, unsigned long size)
10174 {
10175- unsigned long ret = ___copy_from_user(to, from, size);
10176+ unsigned long ret;
10177
10178+ if ((long)size < 0 || size > INT_MAX)
10179+ return size;
10180+
10181+ if (!__builtin_constant_p(size))
10182+ check_object_size(to, size, false);
10183+
10184+ ret = ___copy_from_user(to, from, size);
10185 if (unlikely(ret))
10186 ret = copy_from_user_fixup(to, from, size);
10187
10188@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
10189 static inline unsigned long __must_check
10190 copy_to_user(void __user *to, const void *from, unsigned long size)
10191 {
10192- unsigned long ret = ___copy_to_user(to, from, size);
10193+ unsigned long ret;
10194
10195+ if ((long)size < 0 || size > INT_MAX)
10196+ return size;
10197+
10198+ if (!__builtin_constant_p(size))
10199+ check_object_size(from, size, true);
10200+
10201+ ret = ___copy_to_user(to, from, size);
10202 if (unlikely(ret))
10203 ret = copy_to_user_fixup(to, from, size);
10204 return ret;
10205diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
10206index d15cc17..d0ae796 100644
10207--- a/arch/sparc/kernel/Makefile
10208+++ b/arch/sparc/kernel/Makefile
10209@@ -4,7 +4,7 @@
10210 #
10211
10212 asflags-y := -ansi
10213-ccflags-y := -Werror
10214+#ccflags-y := -Werror
10215
10216 extra-y := head_$(BITS).o
10217
10218diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
10219index 510baec..9ff2607 100644
10220--- a/arch/sparc/kernel/process_32.c
10221+++ b/arch/sparc/kernel/process_32.c
10222@@ -115,14 +115,14 @@ void show_regs(struct pt_regs *r)
10223
10224 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
10225 r->psr, r->pc, r->npc, r->y, print_tainted());
10226- printk("PC: <%pS>\n", (void *) r->pc);
10227+ printk("PC: <%pA>\n", (void *) r->pc);
10228 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10229 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
10230 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
10231 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10232 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
10233 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
10234- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
10235+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
10236
10237 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10238 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
10239@@ -159,7 +159,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10240 rw = (struct reg_window32 *) fp;
10241 pc = rw->ins[7];
10242 printk("[%08lx : ", pc);
10243- printk("%pS ] ", (void *) pc);
10244+ printk("%pA ] ", (void *) pc);
10245 fp = rw->ins[6];
10246 } while (++count < 16);
10247 printk("\n");
10248diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
10249index d7b4967..2edf827 100644
10250--- a/arch/sparc/kernel/process_64.c
10251+++ b/arch/sparc/kernel/process_64.c
10252@@ -161,7 +161,7 @@ static void show_regwindow(struct pt_regs *regs)
10253 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
10254 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
10255 if (regs->tstate & TSTATE_PRIV)
10256- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
10257+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
10258 }
10259
10260 void show_regs(struct pt_regs *regs)
10261@@ -170,7 +170,7 @@ void show_regs(struct pt_regs *regs)
10262
10263 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
10264 regs->tpc, regs->tnpc, regs->y, print_tainted());
10265- printk("TPC: <%pS>\n", (void *) regs->tpc);
10266+ printk("TPC: <%pA>\n", (void *) regs->tpc);
10267 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
10268 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
10269 regs->u_regs[3]);
10270@@ -183,7 +183,7 @@ void show_regs(struct pt_regs *regs)
10271 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
10272 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
10273 regs->u_regs[15]);
10274- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
10275+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
10276 show_regwindow(regs);
10277 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
10278 }
10279@@ -272,7 +272,7 @@ void arch_trigger_all_cpu_backtrace(void)
10280 ((tp && tp->task) ? tp->task->pid : -1));
10281
10282 if (gp->tstate & TSTATE_PRIV) {
10283- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
10284+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
10285 (void *) gp->tpc,
10286 (void *) gp->o7,
10287 (void *) gp->i7,
10288diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
10289index 79cc0d1..ec62734 100644
10290--- a/arch/sparc/kernel/prom_common.c
10291+++ b/arch/sparc/kernel/prom_common.c
10292@@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
10293
10294 unsigned int prom_early_allocated __initdata;
10295
10296-static struct of_pdt_ops prom_sparc_ops __initdata = {
10297+static struct of_pdt_ops prom_sparc_ops __initconst = {
10298 .nextprop = prom_common_nextprop,
10299 .getproplen = prom_getproplen,
10300 .getproperty = prom_getproperty,
10301diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
10302index c13c9f2..d572c34 100644
10303--- a/arch/sparc/kernel/ptrace_64.c
10304+++ b/arch/sparc/kernel/ptrace_64.c
10305@@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
10306 return ret;
10307 }
10308
10309+#ifdef CONFIG_GRKERNSEC_SETXID
10310+extern void gr_delayed_cred_worker(void);
10311+#endif
10312+
10313 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10314 {
10315 int ret = 0;
10316@@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10317 if (test_thread_flag(TIF_NOHZ))
10318 user_exit();
10319
10320+#ifdef CONFIG_GRKERNSEC_SETXID
10321+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10322+ gr_delayed_cred_worker();
10323+#endif
10324+
10325 if (test_thread_flag(TIF_SYSCALL_TRACE))
10326 ret = tracehook_report_syscall_entry(regs);
10327
10328@@ -1093,6 +1102,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
10329 if (test_thread_flag(TIF_NOHZ))
10330 user_exit();
10331
10332+#ifdef CONFIG_GRKERNSEC_SETXID
10333+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10334+ gr_delayed_cred_worker();
10335+#endif
10336+
10337 audit_syscall_exit(regs);
10338
10339 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
10340diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
10341index b085311..6f885f7 100644
10342--- a/arch/sparc/kernel/smp_64.c
10343+++ b/arch/sparc/kernel/smp_64.c
10344@@ -870,8 +870,8 @@ extern unsigned long xcall_flush_dcache_page_cheetah;
10345 extern unsigned long xcall_flush_dcache_page_spitfire;
10346
10347 #ifdef CONFIG_DEBUG_DCFLUSH
10348-extern atomic_t dcpage_flushes;
10349-extern atomic_t dcpage_flushes_xcall;
10350+extern atomic_unchecked_t dcpage_flushes;
10351+extern atomic_unchecked_t dcpage_flushes_xcall;
10352 #endif
10353
10354 static inline void __local_flush_dcache_page(struct page *page)
10355@@ -895,7 +895,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10356 return;
10357
10358 #ifdef CONFIG_DEBUG_DCFLUSH
10359- atomic_inc(&dcpage_flushes);
10360+ atomic_inc_unchecked(&dcpage_flushes);
10361 #endif
10362
10363 this_cpu = get_cpu();
10364@@ -919,7 +919,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10365 xcall_deliver(data0, __pa(pg_addr),
10366 (u64) pg_addr, cpumask_of(cpu));
10367 #ifdef CONFIG_DEBUG_DCFLUSH
10368- atomic_inc(&dcpage_flushes_xcall);
10369+ atomic_inc_unchecked(&dcpage_flushes_xcall);
10370 #endif
10371 }
10372 }
10373@@ -938,7 +938,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10374 preempt_disable();
10375
10376 #ifdef CONFIG_DEBUG_DCFLUSH
10377- atomic_inc(&dcpage_flushes);
10378+ atomic_inc_unchecked(&dcpage_flushes);
10379 #endif
10380 data0 = 0;
10381 pg_addr = page_address(page);
10382@@ -955,7 +955,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10383 xcall_deliver(data0, __pa(pg_addr),
10384 (u64) pg_addr, cpu_online_mask);
10385 #ifdef CONFIG_DEBUG_DCFLUSH
10386- atomic_inc(&dcpage_flushes_xcall);
10387+ atomic_inc_unchecked(&dcpage_flushes_xcall);
10388 #endif
10389 }
10390 __local_flush_dcache_page(page);
10391diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
10392index 3a8d184..49498a8 100644
10393--- a/arch/sparc/kernel/sys_sparc_32.c
10394+++ b/arch/sparc/kernel/sys_sparc_32.c
10395@@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10396 if (len > TASK_SIZE - PAGE_SIZE)
10397 return -ENOMEM;
10398 if (!addr)
10399- addr = TASK_UNMAPPED_BASE;
10400+ addr = current->mm->mmap_base;
10401
10402 info.flags = 0;
10403 info.length = len;
10404diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
10405index beb0b5a..5a153f7 100644
10406--- a/arch/sparc/kernel/sys_sparc_64.c
10407+++ b/arch/sparc/kernel/sys_sparc_64.c
10408@@ -88,13 +88,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10409 struct vm_area_struct * vma;
10410 unsigned long task_size = TASK_SIZE;
10411 int do_color_align;
10412+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10413 struct vm_unmapped_area_info info;
10414
10415 if (flags & MAP_FIXED) {
10416 /* We do not accept a shared mapping if it would violate
10417 * cache aliasing constraints.
10418 */
10419- if ((flags & MAP_SHARED) &&
10420+ if ((filp || (flags & MAP_SHARED)) &&
10421 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10422 return -EINVAL;
10423 return addr;
10424@@ -109,6 +110,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10425 if (filp || (flags & MAP_SHARED))
10426 do_color_align = 1;
10427
10428+#ifdef CONFIG_PAX_RANDMMAP
10429+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10430+#endif
10431+
10432 if (addr) {
10433 if (do_color_align)
10434 addr = COLOR_ALIGN(addr, pgoff);
10435@@ -116,22 +121,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10436 addr = PAGE_ALIGN(addr);
10437
10438 vma = find_vma(mm, addr);
10439- if (task_size - len >= addr &&
10440- (!vma || addr + len <= vma->vm_start))
10441+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10442 return addr;
10443 }
10444
10445 info.flags = 0;
10446 info.length = len;
10447- info.low_limit = TASK_UNMAPPED_BASE;
10448+ info.low_limit = mm->mmap_base;
10449 info.high_limit = min(task_size, VA_EXCLUDE_START);
10450 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10451 info.align_offset = pgoff << PAGE_SHIFT;
10452+ info.threadstack_offset = offset;
10453 addr = vm_unmapped_area(&info);
10454
10455 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
10456 VM_BUG_ON(addr != -ENOMEM);
10457 info.low_limit = VA_EXCLUDE_END;
10458+
10459+#ifdef CONFIG_PAX_RANDMMAP
10460+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10461+ info.low_limit += mm->delta_mmap;
10462+#endif
10463+
10464 info.high_limit = task_size;
10465 addr = vm_unmapped_area(&info);
10466 }
10467@@ -149,6 +160,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10468 unsigned long task_size = STACK_TOP32;
10469 unsigned long addr = addr0;
10470 int do_color_align;
10471+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10472 struct vm_unmapped_area_info info;
10473
10474 /* This should only ever run for 32-bit processes. */
10475@@ -158,7 +170,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10476 /* We do not accept a shared mapping if it would violate
10477 * cache aliasing constraints.
10478 */
10479- if ((flags & MAP_SHARED) &&
10480+ if ((filp || (flags & MAP_SHARED)) &&
10481 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10482 return -EINVAL;
10483 return addr;
10484@@ -171,6 +183,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10485 if (filp || (flags & MAP_SHARED))
10486 do_color_align = 1;
10487
10488+#ifdef CONFIG_PAX_RANDMMAP
10489+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10490+#endif
10491+
10492 /* requesting a specific address */
10493 if (addr) {
10494 if (do_color_align)
10495@@ -179,8 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10496 addr = PAGE_ALIGN(addr);
10497
10498 vma = find_vma(mm, addr);
10499- if (task_size - len >= addr &&
10500- (!vma || addr + len <= vma->vm_start))
10501+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10502 return addr;
10503 }
10504
10505@@ -190,6 +205,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10506 info.high_limit = mm->mmap_base;
10507 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10508 info.align_offset = pgoff << PAGE_SHIFT;
10509+ info.threadstack_offset = offset;
10510 addr = vm_unmapped_area(&info);
10511
10512 /*
10513@@ -202,6 +218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10514 VM_BUG_ON(addr != -ENOMEM);
10515 info.flags = 0;
10516 info.low_limit = TASK_UNMAPPED_BASE;
10517+
10518+#ifdef CONFIG_PAX_RANDMMAP
10519+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10520+ info.low_limit += mm->delta_mmap;
10521+#endif
10522+
10523 info.high_limit = STACK_TOP32;
10524 addr = vm_unmapped_area(&info);
10525 }
10526@@ -258,10 +280,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
10527 EXPORT_SYMBOL(get_fb_unmapped_area);
10528
10529 /* Essentially the same as PowerPC. */
10530-static unsigned long mmap_rnd(void)
10531+static unsigned long mmap_rnd(struct mm_struct *mm)
10532 {
10533 unsigned long rnd = 0UL;
10534
10535+#ifdef CONFIG_PAX_RANDMMAP
10536+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10537+#endif
10538+
10539 if (current->flags & PF_RANDOMIZE) {
10540 unsigned long val = get_random_int();
10541 if (test_thread_flag(TIF_32BIT))
10542@@ -274,7 +300,7 @@ static unsigned long mmap_rnd(void)
10543
10544 void arch_pick_mmap_layout(struct mm_struct *mm)
10545 {
10546- unsigned long random_factor = mmap_rnd();
10547+ unsigned long random_factor = mmap_rnd(mm);
10548 unsigned long gap;
10549
10550 /*
10551@@ -287,6 +313,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10552 gap == RLIM_INFINITY ||
10553 sysctl_legacy_va_layout) {
10554 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
10555+
10556+#ifdef CONFIG_PAX_RANDMMAP
10557+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10558+ mm->mmap_base += mm->delta_mmap;
10559+#endif
10560+
10561 mm->get_unmapped_area = arch_get_unmapped_area;
10562 } else {
10563 /* We know it's 32-bit */
10564@@ -298,6 +330,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10565 gap = (task_size / 6 * 5);
10566
10567 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
10568+
10569+#ifdef CONFIG_PAX_RANDMMAP
10570+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10571+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
10572+#endif
10573+
10574 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
10575 }
10576 }
10577diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
10578index 33a17e7..d87fb1f 100644
10579--- a/arch/sparc/kernel/syscalls.S
10580+++ b/arch/sparc/kernel/syscalls.S
10581@@ -52,7 +52,7 @@ sys32_rt_sigreturn:
10582 #endif
10583 .align 32
10584 1: ldx [%g6 + TI_FLAGS], %l5
10585- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10586+ andcc %l5, _TIF_WORK_SYSCALL, %g0
10587 be,pt %icc, rtrap
10588 nop
10589 call syscall_trace_leave
10590@@ -184,7 +184,7 @@ linux_sparc_syscall32:
10591
10592 srl %i3, 0, %o3 ! IEU0
10593 srl %i2, 0, %o2 ! IEU0 Group
10594- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10595+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10596 bne,pn %icc, linux_syscall_trace32 ! CTI
10597 mov %i0, %l5 ! IEU1
10598 5: call %l7 ! CTI Group brk forced
10599@@ -208,7 +208,7 @@ linux_sparc_syscall:
10600
10601 mov %i3, %o3 ! IEU1
10602 mov %i4, %o4 ! IEU0 Group
10603- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10604+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10605 bne,pn %icc, linux_syscall_trace ! CTI Group
10606 mov %i0, %l5 ! IEU0
10607 2: call %l7 ! CTI Group brk forced
10608@@ -223,7 +223,7 @@ ret_sys_call:
10609
10610 cmp %o0, -ERESTART_RESTARTBLOCK
10611 bgeu,pn %xcc, 1f
10612- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10613+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10614 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
10615
10616 2:
10617diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
10618index 6629829..036032d 100644
10619--- a/arch/sparc/kernel/traps_32.c
10620+++ b/arch/sparc/kernel/traps_32.c
10621@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
10622 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
10623 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
10624
10625+extern void gr_handle_kernel_exploit(void);
10626+
10627 void die_if_kernel(char *str, struct pt_regs *regs)
10628 {
10629 static int die_counter;
10630@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10631 count++ < 30 &&
10632 (((unsigned long) rw) >= PAGE_OFFSET) &&
10633 !(((unsigned long) rw) & 0x7)) {
10634- printk("Caller[%08lx]: %pS\n", rw->ins[7],
10635+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
10636 (void *) rw->ins[7]);
10637 rw = (struct reg_window32 *)rw->ins[6];
10638 }
10639 }
10640 printk("Instruction DUMP:");
10641 instruction_dump ((unsigned long *) regs->pc);
10642- if(regs->psr & PSR_PS)
10643+ if(regs->psr & PSR_PS) {
10644+ gr_handle_kernel_exploit();
10645 do_exit(SIGKILL);
10646+ }
10647 do_exit(SIGSEGV);
10648 }
10649
10650diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
10651index 4ced92f..965eeed 100644
10652--- a/arch/sparc/kernel/traps_64.c
10653+++ b/arch/sparc/kernel/traps_64.c
10654@@ -77,7 +77,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
10655 i + 1,
10656 p->trapstack[i].tstate, p->trapstack[i].tpc,
10657 p->trapstack[i].tnpc, p->trapstack[i].tt);
10658- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
10659+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
10660 }
10661 }
10662
10663@@ -97,6 +97,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
10664
10665 lvl -= 0x100;
10666 if (regs->tstate & TSTATE_PRIV) {
10667+
10668+#ifdef CONFIG_PAX_REFCOUNT
10669+ if (lvl == 6)
10670+ pax_report_refcount_overflow(regs);
10671+#endif
10672+
10673 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
10674 die_if_kernel(buffer, regs);
10675 }
10676@@ -115,11 +121,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
10677 void bad_trap_tl1(struct pt_regs *regs, long lvl)
10678 {
10679 char buffer[32];
10680-
10681+
10682 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
10683 0, lvl, SIGTRAP) == NOTIFY_STOP)
10684 return;
10685
10686+#ifdef CONFIG_PAX_REFCOUNT
10687+ if (lvl == 6)
10688+ pax_report_refcount_overflow(regs);
10689+#endif
10690+
10691 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
10692
10693 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
10694@@ -1149,7 +1160,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
10695 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
10696 printk("%s" "ERROR(%d): ",
10697 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
10698- printk("TPC<%pS>\n", (void *) regs->tpc);
10699+ printk("TPC<%pA>\n", (void *) regs->tpc);
10700 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
10701 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
10702 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
10703@@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10704 smp_processor_id(),
10705 (type & 0x1) ? 'I' : 'D',
10706 regs->tpc);
10707- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
10708+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
10709 panic("Irrecoverable Cheetah+ parity error.");
10710 }
10711
10712@@ -1764,7 +1775,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10713 smp_processor_id(),
10714 (type & 0x1) ? 'I' : 'D',
10715 regs->tpc);
10716- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
10717+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
10718 }
10719
10720 struct sun4v_error_entry {
10721@@ -1837,8 +1848,8 @@ struct sun4v_error_entry {
10722 /*0x38*/u64 reserved_5;
10723 };
10724
10725-static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10726-static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10727+static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10728+static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10729
10730 static const char *sun4v_err_type_to_str(u8 type)
10731 {
10732@@ -1930,7 +1941,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
10733 }
10734
10735 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10736- int cpu, const char *pfx, atomic_t *ocnt)
10737+ int cpu, const char *pfx, atomic_unchecked_t *ocnt)
10738 {
10739 u64 *raw_ptr = (u64 *) ent;
10740 u32 attrs;
10741@@ -1988,8 +1999,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10742
10743 show_regs(regs);
10744
10745- if ((cnt = atomic_read(ocnt)) != 0) {
10746- atomic_set(ocnt, 0);
10747+ if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
10748+ atomic_set_unchecked(ocnt, 0);
10749 wmb();
10750 printk("%s: Queue overflowed %d times.\n",
10751 pfx, cnt);
10752@@ -2046,7 +2057,7 @@ out:
10753 */
10754 void sun4v_resum_overflow(struct pt_regs *regs)
10755 {
10756- atomic_inc(&sun4v_resum_oflow_cnt);
10757+ atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
10758 }
10759
10760 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
10761@@ -2099,7 +2110,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
10762 /* XXX Actually even this can make not that much sense. Perhaps
10763 * XXX we should just pull the plug and panic directly from here?
10764 */
10765- atomic_inc(&sun4v_nonresum_oflow_cnt);
10766+ atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
10767 }
10768
10769 unsigned long sun4v_err_itlb_vaddr;
10770@@ -2114,9 +2125,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
10771
10772 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
10773 regs->tpc, tl);
10774- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
10775+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
10776 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10777- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
10778+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
10779 (void *) regs->u_regs[UREG_I7]);
10780 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
10781 "pte[%lx] error[%lx]\n",
10782@@ -2138,9 +2149,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
10783
10784 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
10785 regs->tpc, tl);
10786- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
10787+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
10788 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10789- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
10790+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
10791 (void *) regs->u_regs[UREG_I7]);
10792 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
10793 "pte[%lx] error[%lx]\n",
10794@@ -2359,13 +2370,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10795 fp = (unsigned long)sf->fp + STACK_BIAS;
10796 }
10797
10798- printk(" [%016lx] %pS\n", pc, (void *) pc);
10799+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10800 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
10801 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
10802 int index = tsk->curr_ret_stack;
10803 if (tsk->ret_stack && index >= graph) {
10804 pc = tsk->ret_stack[index - graph].ret;
10805- printk(" [%016lx] %pS\n", pc, (void *) pc);
10806+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10807 graph++;
10808 }
10809 }
10810@@ -2383,6 +2394,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
10811 return (struct reg_window *) (fp + STACK_BIAS);
10812 }
10813
10814+extern void gr_handle_kernel_exploit(void);
10815+
10816 void die_if_kernel(char *str, struct pt_regs *regs)
10817 {
10818 static int die_counter;
10819@@ -2411,7 +2424,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10820 while (rw &&
10821 count++ < 30 &&
10822 kstack_valid(tp, (unsigned long) rw)) {
10823- printk("Caller[%016lx]: %pS\n", rw->ins[7],
10824+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
10825 (void *) rw->ins[7]);
10826
10827 rw = kernel_stack_up(rw);
10828@@ -2424,8 +2437,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10829 }
10830 user_instruction_dump ((unsigned int __user *) regs->tpc);
10831 }
10832- if (regs->tstate & TSTATE_PRIV)
10833+ if (regs->tstate & TSTATE_PRIV) {
10834+ gr_handle_kernel_exploit();
10835 do_exit(SIGKILL);
10836+ }
10837 do_exit(SIGSEGV);
10838 }
10839 EXPORT_SYMBOL(die_if_kernel);
10840diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
10841index 3c1a7cb..9046547 100644
10842--- a/arch/sparc/kernel/unaligned_64.c
10843+++ b/arch/sparc/kernel/unaligned_64.c
10844@@ -166,17 +166,23 @@ static unsigned long *fetch_reg_addr(unsigned int reg, struct pt_regs *regs)
10845 unsigned long compute_effective_address(struct pt_regs *regs,
10846 unsigned int insn, unsigned int rd)
10847 {
10848+ int from_kernel = (regs->tstate & TSTATE_PRIV) != 0;
10849 unsigned int rs1 = (insn >> 14) & 0x1f;
10850 unsigned int rs2 = insn & 0x1f;
10851- int from_kernel = (regs->tstate & TSTATE_PRIV) != 0;
10852+ unsigned long addr;
10853
10854 if (insn & 0x2000) {
10855 maybe_flush_windows(rs1, 0, rd, from_kernel);
10856- return (fetch_reg(rs1, regs) + sign_extend_imm13(insn));
10857+ addr = (fetch_reg(rs1, regs) + sign_extend_imm13(insn));
10858 } else {
10859 maybe_flush_windows(rs1, rs2, rd, from_kernel);
10860- return (fetch_reg(rs1, regs) + fetch_reg(rs2, regs));
10861+ addr = (fetch_reg(rs1, regs) + fetch_reg(rs2, regs));
10862 }
10863+
10864+ if (!from_kernel && test_thread_flag(TIF_32BIT))
10865+ addr &= 0xffffffff;
10866+
10867+ return addr;
10868 }
10869
10870 /* This is just to make gcc think die_if_kernel does return... */
10871@@ -289,7 +295,7 @@ static void log_unaligned(struct pt_regs *regs)
10872 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
10873
10874 if (__ratelimit(&ratelimit)) {
10875- printk("Kernel unaligned access at TPC[%lx] %pS\n",
10876+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
10877 regs->tpc, (void *) regs->tpc);
10878 }
10879 }
10880diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
10881index dbe119b..089c7c1 100644
10882--- a/arch/sparc/lib/Makefile
10883+++ b/arch/sparc/lib/Makefile
10884@@ -2,7 +2,7 @@
10885 #
10886
10887 asflags-y := -ansi -DST_DIV0=0x02
10888-ccflags-y := -Werror
10889+#ccflags-y := -Werror
10890
10891 lib-$(CONFIG_SPARC32) += ashrdi3.o
10892 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
10893diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
10894index 85c233d..68500e0 100644
10895--- a/arch/sparc/lib/atomic_64.S
10896+++ b/arch/sparc/lib/atomic_64.S
10897@@ -17,7 +17,12 @@
10898 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10899 BACKOFF_SETUP(%o2)
10900 1: lduw [%o1], %g1
10901- add %g1, %o0, %g7
10902+ addcc %g1, %o0, %g7
10903+
10904+#ifdef CONFIG_PAX_REFCOUNT
10905+ tvs %icc, 6
10906+#endif
10907+
10908 cas [%o1], %g1, %g7
10909 cmp %g1, %g7
10910 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10911@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10912 2: BACKOFF_SPIN(%o2, %o3, 1b)
10913 ENDPROC(atomic_add)
10914
10915+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10916+ BACKOFF_SETUP(%o2)
10917+1: lduw [%o1], %g1
10918+ add %g1, %o0, %g7
10919+ cas [%o1], %g1, %g7
10920+ cmp %g1, %g7
10921+ bne,pn %icc, 2f
10922+ nop
10923+ retl
10924+ nop
10925+2: BACKOFF_SPIN(%o2, %o3, 1b)
10926+ENDPROC(atomic_add_unchecked)
10927+
10928 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10929 BACKOFF_SETUP(%o2)
10930 1: lduw [%o1], %g1
10931- sub %g1, %o0, %g7
10932+ subcc %g1, %o0, %g7
10933+
10934+#ifdef CONFIG_PAX_REFCOUNT
10935+ tvs %icc, 6
10936+#endif
10937+
10938 cas [%o1], %g1, %g7
10939 cmp %g1, %g7
10940 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10941@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10942 2: BACKOFF_SPIN(%o2, %o3, 1b)
10943 ENDPROC(atomic_sub)
10944
10945+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10946+ BACKOFF_SETUP(%o2)
10947+1: lduw [%o1], %g1
10948+ sub %g1, %o0, %g7
10949+ cas [%o1], %g1, %g7
10950+ cmp %g1, %g7
10951+ bne,pn %icc, 2f
10952+ nop
10953+ retl
10954+ nop
10955+2: BACKOFF_SPIN(%o2, %o3, 1b)
10956+ENDPROC(atomic_sub_unchecked)
10957+
10958 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10959 BACKOFF_SETUP(%o2)
10960 1: lduw [%o1], %g1
10961- add %g1, %o0, %g7
10962+ addcc %g1, %o0, %g7
10963+
10964+#ifdef CONFIG_PAX_REFCOUNT
10965+ tvs %icc, 6
10966+#endif
10967+
10968 cas [%o1], %g1, %g7
10969 cmp %g1, %g7
10970 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10971@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10972 2: BACKOFF_SPIN(%o2, %o3, 1b)
10973 ENDPROC(atomic_add_ret)
10974
10975+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10976+ BACKOFF_SETUP(%o2)
10977+1: lduw [%o1], %g1
10978+ addcc %g1, %o0, %g7
10979+ cas [%o1], %g1, %g7
10980+ cmp %g1, %g7
10981+ bne,pn %icc, 2f
10982+ add %g7, %o0, %g7
10983+ sra %g7, 0, %o0
10984+ retl
10985+ nop
10986+2: BACKOFF_SPIN(%o2, %o3, 1b)
10987+ENDPROC(atomic_add_ret_unchecked)
10988+
10989 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10990 BACKOFF_SETUP(%o2)
10991 1: lduw [%o1], %g1
10992- sub %g1, %o0, %g7
10993+ subcc %g1, %o0, %g7
10994+
10995+#ifdef CONFIG_PAX_REFCOUNT
10996+ tvs %icc, 6
10997+#endif
10998+
10999 cas [%o1], %g1, %g7
11000 cmp %g1, %g7
11001 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11002@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
11003 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
11004 BACKOFF_SETUP(%o2)
11005 1: ldx [%o1], %g1
11006- add %g1, %o0, %g7
11007+ addcc %g1, %o0, %g7
11008+
11009+#ifdef CONFIG_PAX_REFCOUNT
11010+ tvs %xcc, 6
11011+#endif
11012+
11013 casx [%o1], %g1, %g7
11014 cmp %g1, %g7
11015 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11016@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
11017 2: BACKOFF_SPIN(%o2, %o3, 1b)
11018 ENDPROC(atomic64_add)
11019
11020+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11021+ BACKOFF_SETUP(%o2)
11022+1: ldx [%o1], %g1
11023+ addcc %g1, %o0, %g7
11024+ casx [%o1], %g1, %g7
11025+ cmp %g1, %g7
11026+ bne,pn %xcc, 2f
11027+ nop
11028+ retl
11029+ nop
11030+2: BACKOFF_SPIN(%o2, %o3, 1b)
11031+ENDPROC(atomic64_add_unchecked)
11032+
11033 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11034 BACKOFF_SETUP(%o2)
11035 1: ldx [%o1], %g1
11036- sub %g1, %o0, %g7
11037+ subcc %g1, %o0, %g7
11038+
11039+#ifdef CONFIG_PAX_REFCOUNT
11040+ tvs %xcc, 6
11041+#endif
11042+
11043 casx [%o1], %g1, %g7
11044 cmp %g1, %g7
11045 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11046@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11047 2: BACKOFF_SPIN(%o2, %o3, 1b)
11048 ENDPROC(atomic64_sub)
11049
11050+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
11051+ BACKOFF_SETUP(%o2)
11052+1: ldx [%o1], %g1
11053+ subcc %g1, %o0, %g7
11054+ casx [%o1], %g1, %g7
11055+ cmp %g1, %g7
11056+ bne,pn %xcc, 2f
11057+ nop
11058+ retl
11059+ nop
11060+2: BACKOFF_SPIN(%o2, %o3, 1b)
11061+ENDPROC(atomic64_sub_unchecked)
11062+
11063 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11064 BACKOFF_SETUP(%o2)
11065 1: ldx [%o1], %g1
11066- add %g1, %o0, %g7
11067+ addcc %g1, %o0, %g7
11068+
11069+#ifdef CONFIG_PAX_REFCOUNT
11070+ tvs %xcc, 6
11071+#endif
11072+
11073 casx [%o1], %g1, %g7
11074 cmp %g1, %g7
11075 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11076@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11077 2: BACKOFF_SPIN(%o2, %o3, 1b)
11078 ENDPROC(atomic64_add_ret)
11079
11080+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11081+ BACKOFF_SETUP(%o2)
11082+1: ldx [%o1], %g1
11083+ addcc %g1, %o0, %g7
11084+ casx [%o1], %g1, %g7
11085+ cmp %g1, %g7
11086+ bne,pn %xcc, 2f
11087+ add %g7, %o0, %g7
11088+ mov %g7, %o0
11089+ retl
11090+ nop
11091+2: BACKOFF_SPIN(%o2, %o3, 1b)
11092+ENDPROC(atomic64_add_ret_unchecked)
11093+
11094 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
11095 BACKOFF_SETUP(%o2)
11096 1: ldx [%o1], %g1
11097- sub %g1, %o0, %g7
11098+ subcc %g1, %o0, %g7
11099+
11100+#ifdef CONFIG_PAX_REFCOUNT
11101+ tvs %xcc, 6
11102+#endif
11103+
11104 casx [%o1], %g1, %g7
11105 cmp %g1, %g7
11106 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11107diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
11108index 323335b..ed85ea2 100644
11109--- a/arch/sparc/lib/ksyms.c
11110+++ b/arch/sparc/lib/ksyms.c
11111@@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
11112
11113 /* Atomic counter implementation. */
11114 EXPORT_SYMBOL(atomic_add);
11115+EXPORT_SYMBOL(atomic_add_unchecked);
11116 EXPORT_SYMBOL(atomic_add_ret);
11117+EXPORT_SYMBOL(atomic_add_ret_unchecked);
11118 EXPORT_SYMBOL(atomic_sub);
11119+EXPORT_SYMBOL(atomic_sub_unchecked);
11120 EXPORT_SYMBOL(atomic_sub_ret);
11121 EXPORT_SYMBOL(atomic64_add);
11122+EXPORT_SYMBOL(atomic64_add_unchecked);
11123 EXPORT_SYMBOL(atomic64_add_ret);
11124+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
11125 EXPORT_SYMBOL(atomic64_sub);
11126+EXPORT_SYMBOL(atomic64_sub_unchecked);
11127 EXPORT_SYMBOL(atomic64_sub_ret);
11128 EXPORT_SYMBOL(atomic64_dec_if_positive);
11129
11130diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
11131index 30c3ecc..736f015 100644
11132--- a/arch/sparc/mm/Makefile
11133+++ b/arch/sparc/mm/Makefile
11134@@ -2,7 +2,7 @@
11135 #
11136
11137 asflags-y := -ansi
11138-ccflags-y := -Werror
11139+#ccflags-y := -Werror
11140
11141 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
11142 obj-y += fault_$(BITS).o
11143diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
11144index 59dbd46..1dd7f5e 100644
11145--- a/arch/sparc/mm/fault_32.c
11146+++ b/arch/sparc/mm/fault_32.c
11147@@ -21,6 +21,9 @@
11148 #include <linux/perf_event.h>
11149 #include <linux/interrupt.h>
11150 #include <linux/kdebug.h>
11151+#include <linux/slab.h>
11152+#include <linux/pagemap.h>
11153+#include <linux/compiler.h>
11154
11155 #include <asm/page.h>
11156 #include <asm/pgtable.h>
11157@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
11158 return safe_compute_effective_address(regs, insn);
11159 }
11160
11161+#ifdef CONFIG_PAX_PAGEEXEC
11162+#ifdef CONFIG_PAX_DLRESOLVE
11163+static void pax_emuplt_close(struct vm_area_struct *vma)
11164+{
11165+ vma->vm_mm->call_dl_resolve = 0UL;
11166+}
11167+
11168+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11169+{
11170+ unsigned int *kaddr;
11171+
11172+ vmf->page = alloc_page(GFP_HIGHUSER);
11173+ if (!vmf->page)
11174+ return VM_FAULT_OOM;
11175+
11176+ kaddr = kmap(vmf->page);
11177+ memset(kaddr, 0, PAGE_SIZE);
11178+ kaddr[0] = 0x9DE3BFA8U; /* save */
11179+ flush_dcache_page(vmf->page);
11180+ kunmap(vmf->page);
11181+ return VM_FAULT_MAJOR;
11182+}
11183+
11184+static const struct vm_operations_struct pax_vm_ops = {
11185+ .close = pax_emuplt_close,
11186+ .fault = pax_emuplt_fault
11187+};
11188+
11189+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11190+{
11191+ int ret;
11192+
11193+ INIT_LIST_HEAD(&vma->anon_vma_chain);
11194+ vma->vm_mm = current->mm;
11195+ vma->vm_start = addr;
11196+ vma->vm_end = addr + PAGE_SIZE;
11197+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11198+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11199+ vma->vm_ops = &pax_vm_ops;
11200+
11201+ ret = insert_vm_struct(current->mm, vma);
11202+ if (ret)
11203+ return ret;
11204+
11205+ ++current->mm->total_vm;
11206+ return 0;
11207+}
11208+#endif
11209+
11210+/*
11211+ * PaX: decide what to do with offenders (regs->pc = fault address)
11212+ *
11213+ * returns 1 when task should be killed
11214+ * 2 when patched PLT trampoline was detected
11215+ * 3 when unpatched PLT trampoline was detected
11216+ */
11217+static int pax_handle_fetch_fault(struct pt_regs *regs)
11218+{
11219+
11220+#ifdef CONFIG_PAX_EMUPLT
11221+ int err;
11222+
11223+ do { /* PaX: patched PLT emulation #1 */
11224+ unsigned int sethi1, sethi2, jmpl;
11225+
11226+ err = get_user(sethi1, (unsigned int *)regs->pc);
11227+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
11228+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
11229+
11230+ if (err)
11231+ break;
11232+
11233+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11234+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
11235+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
11236+ {
11237+ unsigned int addr;
11238+
11239+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11240+ addr = regs->u_regs[UREG_G1];
11241+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11242+ regs->pc = addr;
11243+ regs->npc = addr+4;
11244+ return 2;
11245+ }
11246+ } while (0);
11247+
11248+ do { /* PaX: patched PLT emulation #2 */
11249+ unsigned int ba;
11250+
11251+ err = get_user(ba, (unsigned int *)regs->pc);
11252+
11253+ if (err)
11254+ break;
11255+
11256+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11257+ unsigned int addr;
11258+
11259+ if ((ba & 0xFFC00000U) == 0x30800000U)
11260+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11261+ else
11262+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11263+ regs->pc = addr;
11264+ regs->npc = addr+4;
11265+ return 2;
11266+ }
11267+ } while (0);
11268+
11269+ do { /* PaX: patched PLT emulation #3 */
11270+ unsigned int sethi, bajmpl, nop;
11271+
11272+ err = get_user(sethi, (unsigned int *)regs->pc);
11273+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
11274+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
11275+
11276+ if (err)
11277+ break;
11278+
11279+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11280+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11281+ nop == 0x01000000U)
11282+ {
11283+ unsigned int addr;
11284+
11285+ addr = (sethi & 0x003FFFFFU) << 10;
11286+ regs->u_regs[UREG_G1] = addr;
11287+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11288+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11289+ else
11290+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11291+ regs->pc = addr;
11292+ regs->npc = addr+4;
11293+ return 2;
11294+ }
11295+ } while (0);
11296+
11297+ do { /* PaX: unpatched PLT emulation step 1 */
11298+ unsigned int sethi, ba, nop;
11299+
11300+ err = get_user(sethi, (unsigned int *)regs->pc);
11301+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
11302+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
11303+
11304+ if (err)
11305+ break;
11306+
11307+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11308+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11309+ nop == 0x01000000U)
11310+ {
11311+ unsigned int addr, save, call;
11312+
11313+ if ((ba & 0xFFC00000U) == 0x30800000U)
11314+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11315+ else
11316+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11317+
11318+ err = get_user(save, (unsigned int *)addr);
11319+ err |= get_user(call, (unsigned int *)(addr+4));
11320+ err |= get_user(nop, (unsigned int *)(addr+8));
11321+ if (err)
11322+ break;
11323+
11324+#ifdef CONFIG_PAX_DLRESOLVE
11325+ if (save == 0x9DE3BFA8U &&
11326+ (call & 0xC0000000U) == 0x40000000U &&
11327+ nop == 0x01000000U)
11328+ {
11329+ struct vm_area_struct *vma;
11330+ unsigned long call_dl_resolve;
11331+
11332+ down_read(&current->mm->mmap_sem);
11333+ call_dl_resolve = current->mm->call_dl_resolve;
11334+ up_read(&current->mm->mmap_sem);
11335+ if (likely(call_dl_resolve))
11336+ goto emulate;
11337+
11338+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11339+
11340+ down_write(&current->mm->mmap_sem);
11341+ if (current->mm->call_dl_resolve) {
11342+ call_dl_resolve = current->mm->call_dl_resolve;
11343+ up_write(&current->mm->mmap_sem);
11344+ if (vma)
11345+ kmem_cache_free(vm_area_cachep, vma);
11346+ goto emulate;
11347+ }
11348+
11349+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11350+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11351+ up_write(&current->mm->mmap_sem);
11352+ if (vma)
11353+ kmem_cache_free(vm_area_cachep, vma);
11354+ return 1;
11355+ }
11356+
11357+ if (pax_insert_vma(vma, call_dl_resolve)) {
11358+ up_write(&current->mm->mmap_sem);
11359+ kmem_cache_free(vm_area_cachep, vma);
11360+ return 1;
11361+ }
11362+
11363+ current->mm->call_dl_resolve = call_dl_resolve;
11364+ up_write(&current->mm->mmap_sem);
11365+
11366+emulate:
11367+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11368+ regs->pc = call_dl_resolve;
11369+ regs->npc = addr+4;
11370+ return 3;
11371+ }
11372+#endif
11373+
11374+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11375+ if ((save & 0xFFC00000U) == 0x05000000U &&
11376+ (call & 0xFFFFE000U) == 0x85C0A000U &&
11377+ nop == 0x01000000U)
11378+ {
11379+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11380+ regs->u_regs[UREG_G2] = addr + 4;
11381+ addr = (save & 0x003FFFFFU) << 10;
11382+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11383+ regs->pc = addr;
11384+ regs->npc = addr+4;
11385+ return 3;
11386+ }
11387+ }
11388+ } while (0);
11389+
11390+ do { /* PaX: unpatched PLT emulation step 2 */
11391+ unsigned int save, call, nop;
11392+
11393+ err = get_user(save, (unsigned int *)(regs->pc-4));
11394+ err |= get_user(call, (unsigned int *)regs->pc);
11395+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
11396+ if (err)
11397+ break;
11398+
11399+ if (save == 0x9DE3BFA8U &&
11400+ (call & 0xC0000000U) == 0x40000000U &&
11401+ nop == 0x01000000U)
11402+ {
11403+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
11404+
11405+ regs->u_regs[UREG_RETPC] = regs->pc;
11406+ regs->pc = dl_resolve;
11407+ regs->npc = dl_resolve+4;
11408+ return 3;
11409+ }
11410+ } while (0);
11411+#endif
11412+
11413+ return 1;
11414+}
11415+
11416+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11417+{
11418+ unsigned long i;
11419+
11420+ printk(KERN_ERR "PAX: bytes at PC: ");
11421+ for (i = 0; i < 8; i++) {
11422+ unsigned int c;
11423+ if (get_user(c, (unsigned int *)pc+i))
11424+ printk(KERN_CONT "???????? ");
11425+ else
11426+ printk(KERN_CONT "%08x ", c);
11427+ }
11428+ printk("\n");
11429+}
11430+#endif
11431+
11432 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
11433 int text_fault)
11434 {
11435@@ -229,6 +503,24 @@ good_area:
11436 if (!(vma->vm_flags & VM_WRITE))
11437 goto bad_area;
11438 } else {
11439+
11440+#ifdef CONFIG_PAX_PAGEEXEC
11441+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
11442+ up_read(&mm->mmap_sem);
11443+ switch (pax_handle_fetch_fault(regs)) {
11444+
11445+#ifdef CONFIG_PAX_EMUPLT
11446+ case 2:
11447+ case 3:
11448+ return;
11449+#endif
11450+
11451+ }
11452+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
11453+ do_group_exit(SIGKILL);
11454+ }
11455+#endif
11456+
11457 /* Allow reads even for write-only mappings */
11458 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
11459 goto bad_area;
11460diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
11461index 69bb818..3542236 100644
11462--- a/arch/sparc/mm/fault_64.c
11463+++ b/arch/sparc/mm/fault_64.c
11464@@ -22,6 +22,9 @@
11465 #include <linux/kdebug.h>
11466 #include <linux/percpu.h>
11467 #include <linux/context_tracking.h>
11468+#include <linux/slab.h>
11469+#include <linux/pagemap.h>
11470+#include <linux/compiler.h>
11471
11472 #include <asm/page.h>
11473 #include <asm/pgtable.h>
11474@@ -75,7 +78,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
11475 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
11476 regs->tpc);
11477 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
11478- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
11479+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
11480 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
11481 dump_stack();
11482 unhandled_fault(regs->tpc, current, regs);
11483@@ -96,38 +99,51 @@ static unsigned int get_user_insn(unsigned long tpc)
11484 pte_t *ptep, pte;
11485 unsigned long pa;
11486 u32 insn = 0;
11487- unsigned long pstate;
11488
11489- if (pgd_none(*pgdp))
11490- goto outret;
11491+ if (pgd_none(*pgdp) || unlikely(pgd_bad(*pgdp)))
11492+ goto out;
11493 pudp = pud_offset(pgdp, tpc);
11494- if (pud_none(*pudp))
11495- goto outret;
11496- pmdp = pmd_offset(pudp, tpc);
11497- if (pmd_none(*pmdp))
11498- goto outret;
11499+ if (pud_none(*pudp) || unlikely(pud_bad(*pudp)))
11500+ goto out;
11501
11502 /* This disables preemption for us as well. */
11503- __asm__ __volatile__("rdpr %%pstate, %0" : "=r" (pstate));
11504- __asm__ __volatile__("wrpr %0, %1, %%pstate"
11505- : : "r" (pstate), "i" (PSTATE_IE));
11506- ptep = pte_offset_map(pmdp, tpc);
11507- pte = *ptep;
11508- if (!pte_present(pte))
11509- goto out;
11510+ local_irq_disable();
11511
11512- pa = (pte_pfn(pte) << PAGE_SHIFT);
11513- pa += (tpc & ~PAGE_MASK);
11514+ pmdp = pmd_offset(pudp, tpc);
11515+ if (pmd_none(*pmdp) || unlikely(pmd_bad(*pmdp)))
11516+ goto out_irq_enable;
11517
11518- /* Use phys bypass so we don't pollute dtlb/dcache. */
11519- __asm__ __volatile__("lduwa [%1] %2, %0"
11520- : "=r" (insn)
11521- : "r" (pa), "i" (ASI_PHYS_USE_EC));
11522+#ifdef CONFIG_TRANSPARENT_HUGEPAGE
11523+ if (pmd_trans_huge(*pmdp)) {
11524+ if (pmd_trans_splitting(*pmdp))
11525+ goto out_irq_enable;
11526
11527+ pa = pmd_pfn(*pmdp) << PAGE_SHIFT;
11528+ pa += tpc & ~HPAGE_MASK;
11529+
11530+ /* Use phys bypass so we don't pollute dtlb/dcache. */
11531+ __asm__ __volatile__("lduwa [%1] %2, %0"
11532+ : "=r" (insn)
11533+ : "r" (pa), "i" (ASI_PHYS_USE_EC));
11534+ } else
11535+#endif
11536+ {
11537+ ptep = pte_offset_map(pmdp, tpc);
11538+ pte = *ptep;
11539+ if (pte_present(pte)) {
11540+ pa = (pte_pfn(pte) << PAGE_SHIFT);
11541+ pa += (tpc & ~PAGE_MASK);
11542+
11543+ /* Use phys bypass so we don't pollute dtlb/dcache. */
11544+ __asm__ __volatile__("lduwa [%1] %2, %0"
11545+ : "=r" (insn)
11546+ : "r" (pa), "i" (ASI_PHYS_USE_EC));
11547+ }
11548+ pte_unmap(ptep);
11549+ }
11550+out_irq_enable:
11551+ local_irq_enable();
11552 out:
11553- pte_unmap(ptep);
11554- __asm__ __volatile__("wrpr %0, 0x0, %%pstate" : : "r" (pstate));
11555-outret:
11556 return insn;
11557 }
11558
11559@@ -153,7 +169,8 @@ show_signal_msg(struct pt_regs *regs, int sig, int code,
11560 }
11561
11562 static void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
11563- unsigned int insn, int fault_code)
11564+ unsigned long fault_addr, unsigned int insn,
11565+ int fault_code)
11566 {
11567 unsigned long addr;
11568 siginfo_t info;
11569@@ -161,10 +178,18 @@ static void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
11570 info.si_code = code;
11571 info.si_signo = sig;
11572 info.si_errno = 0;
11573- if (fault_code & FAULT_CODE_ITLB)
11574+ if (fault_code & FAULT_CODE_ITLB) {
11575 addr = regs->tpc;
11576- else
11577- addr = compute_effective_address(regs, insn, 0);
11578+ } else {
11579+ /* If we were able to probe the faulting instruction, use it
11580+ * to compute a precise fault address. Otherwise use the fault
11581+ * time provided address which may only have page granularity.
11582+ */
11583+ if (insn)
11584+ addr = compute_effective_address(regs, insn, 0);
11585+ else
11586+ addr = fault_addr;
11587+ }
11588 info.si_addr = (void __user *) addr;
11589 info.si_trapno = 0;
11590
11591@@ -239,7 +264,7 @@ static void __kprobes do_kernel_fault(struct pt_regs *regs, int si_code,
11592 /* The si_code was set to make clear whether
11593 * this was a SEGV_MAPERR or SEGV_ACCERR fault.
11594 */
11595- do_fault_siginfo(si_code, SIGSEGV, regs, insn, fault_code);
11596+ do_fault_siginfo(si_code, SIGSEGV, regs, address, insn, fault_code);
11597 return;
11598 }
11599
11600@@ -271,6 +296,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
11601 show_regs(regs);
11602 }
11603
11604+#ifdef CONFIG_PAX_PAGEEXEC
11605+#ifdef CONFIG_PAX_DLRESOLVE
11606+static void pax_emuplt_close(struct vm_area_struct *vma)
11607+{
11608+ vma->vm_mm->call_dl_resolve = 0UL;
11609+}
11610+
11611+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11612+{
11613+ unsigned int *kaddr;
11614+
11615+ vmf->page = alloc_page(GFP_HIGHUSER);
11616+ if (!vmf->page)
11617+ return VM_FAULT_OOM;
11618+
11619+ kaddr = kmap(vmf->page);
11620+ memset(kaddr, 0, PAGE_SIZE);
11621+ kaddr[0] = 0x9DE3BFA8U; /* save */
11622+ flush_dcache_page(vmf->page);
11623+ kunmap(vmf->page);
11624+ return VM_FAULT_MAJOR;
11625+}
11626+
11627+static const struct vm_operations_struct pax_vm_ops = {
11628+ .close = pax_emuplt_close,
11629+ .fault = pax_emuplt_fault
11630+};
11631+
11632+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11633+{
11634+ int ret;
11635+
11636+ INIT_LIST_HEAD(&vma->anon_vma_chain);
11637+ vma->vm_mm = current->mm;
11638+ vma->vm_start = addr;
11639+ vma->vm_end = addr + PAGE_SIZE;
11640+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11641+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11642+ vma->vm_ops = &pax_vm_ops;
11643+
11644+ ret = insert_vm_struct(current->mm, vma);
11645+ if (ret)
11646+ return ret;
11647+
11648+ ++current->mm->total_vm;
11649+ return 0;
11650+}
11651+#endif
11652+
11653+/*
11654+ * PaX: decide what to do with offenders (regs->tpc = fault address)
11655+ *
11656+ * returns 1 when task should be killed
11657+ * 2 when patched PLT trampoline was detected
11658+ * 3 when unpatched PLT trampoline was detected
11659+ */
11660+static int pax_handle_fetch_fault(struct pt_regs *regs)
11661+{
11662+
11663+#ifdef CONFIG_PAX_EMUPLT
11664+ int err;
11665+
11666+ do { /* PaX: patched PLT emulation #1 */
11667+ unsigned int sethi1, sethi2, jmpl;
11668+
11669+ err = get_user(sethi1, (unsigned int *)regs->tpc);
11670+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
11671+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
11672+
11673+ if (err)
11674+ break;
11675+
11676+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11677+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
11678+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
11679+ {
11680+ unsigned long addr;
11681+
11682+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11683+ addr = regs->u_regs[UREG_G1];
11684+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11685+
11686+ if (test_thread_flag(TIF_32BIT))
11687+ addr &= 0xFFFFFFFFUL;
11688+
11689+ regs->tpc = addr;
11690+ regs->tnpc = addr+4;
11691+ return 2;
11692+ }
11693+ } while (0);
11694+
11695+ do { /* PaX: patched PLT emulation #2 */
11696+ unsigned int ba;
11697+
11698+ err = get_user(ba, (unsigned int *)regs->tpc);
11699+
11700+ if (err)
11701+ break;
11702+
11703+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11704+ unsigned long addr;
11705+
11706+ if ((ba & 0xFFC00000U) == 0x30800000U)
11707+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11708+ else
11709+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11710+
11711+ if (test_thread_flag(TIF_32BIT))
11712+ addr &= 0xFFFFFFFFUL;
11713+
11714+ regs->tpc = addr;
11715+ regs->tnpc = addr+4;
11716+ return 2;
11717+ }
11718+ } while (0);
11719+
11720+ do { /* PaX: patched PLT emulation #3 */
11721+ unsigned int sethi, bajmpl, nop;
11722+
11723+ err = get_user(sethi, (unsigned int *)regs->tpc);
11724+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
11725+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11726+
11727+ if (err)
11728+ break;
11729+
11730+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11731+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11732+ nop == 0x01000000U)
11733+ {
11734+ unsigned long addr;
11735+
11736+ addr = (sethi & 0x003FFFFFU) << 10;
11737+ regs->u_regs[UREG_G1] = addr;
11738+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11739+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11740+ else
11741+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11742+
11743+ if (test_thread_flag(TIF_32BIT))
11744+ addr &= 0xFFFFFFFFUL;
11745+
11746+ regs->tpc = addr;
11747+ regs->tnpc = addr+4;
11748+ return 2;
11749+ }
11750+ } while (0);
11751+
11752+ do { /* PaX: patched PLT emulation #4 */
11753+ unsigned int sethi, mov1, call, mov2;
11754+
11755+ err = get_user(sethi, (unsigned int *)regs->tpc);
11756+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
11757+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
11758+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
11759+
11760+ if (err)
11761+ break;
11762+
11763+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11764+ mov1 == 0x8210000FU &&
11765+ (call & 0xC0000000U) == 0x40000000U &&
11766+ mov2 == 0x9E100001U)
11767+ {
11768+ unsigned long addr;
11769+
11770+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
11771+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11772+
11773+ if (test_thread_flag(TIF_32BIT))
11774+ addr &= 0xFFFFFFFFUL;
11775+
11776+ regs->tpc = addr;
11777+ regs->tnpc = addr+4;
11778+ return 2;
11779+ }
11780+ } while (0);
11781+
11782+ do { /* PaX: patched PLT emulation #5 */
11783+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
11784+
11785+ err = get_user(sethi, (unsigned int *)regs->tpc);
11786+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11787+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11788+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
11789+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
11790+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
11791+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
11792+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
11793+
11794+ if (err)
11795+ break;
11796+
11797+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11798+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
11799+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11800+ (or1 & 0xFFFFE000U) == 0x82106000U &&
11801+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
11802+ sllx == 0x83287020U &&
11803+ jmpl == 0x81C04005U &&
11804+ nop == 0x01000000U)
11805+ {
11806+ unsigned long addr;
11807+
11808+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11809+ regs->u_regs[UREG_G1] <<= 32;
11810+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11811+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11812+ regs->tpc = addr;
11813+ regs->tnpc = addr+4;
11814+ return 2;
11815+ }
11816+ } while (0);
11817+
11818+ do { /* PaX: patched PLT emulation #6 */
11819+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
11820+
11821+ err = get_user(sethi, (unsigned int *)regs->tpc);
11822+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11823+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11824+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
11825+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
11826+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
11827+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
11828+
11829+ if (err)
11830+ break;
11831+
11832+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11833+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
11834+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11835+ sllx == 0x83287020U &&
11836+ (or & 0xFFFFE000U) == 0x8A116000U &&
11837+ jmpl == 0x81C04005U &&
11838+ nop == 0x01000000U)
11839+ {
11840+ unsigned long addr;
11841+
11842+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
11843+ regs->u_regs[UREG_G1] <<= 32;
11844+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
11845+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11846+ regs->tpc = addr;
11847+ regs->tnpc = addr+4;
11848+ return 2;
11849+ }
11850+ } while (0);
11851+
11852+ do { /* PaX: unpatched PLT emulation step 1 */
11853+ unsigned int sethi, ba, nop;
11854+
11855+ err = get_user(sethi, (unsigned int *)regs->tpc);
11856+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11857+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11858+
11859+ if (err)
11860+ break;
11861+
11862+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11863+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11864+ nop == 0x01000000U)
11865+ {
11866+ unsigned long addr;
11867+ unsigned int save, call;
11868+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
11869+
11870+ if ((ba & 0xFFC00000U) == 0x30800000U)
11871+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11872+ else
11873+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11874+
11875+ if (test_thread_flag(TIF_32BIT))
11876+ addr &= 0xFFFFFFFFUL;
11877+
11878+ err = get_user(save, (unsigned int *)addr);
11879+ err |= get_user(call, (unsigned int *)(addr+4));
11880+ err |= get_user(nop, (unsigned int *)(addr+8));
11881+ if (err)
11882+ break;
11883+
11884+#ifdef CONFIG_PAX_DLRESOLVE
11885+ if (save == 0x9DE3BFA8U &&
11886+ (call & 0xC0000000U) == 0x40000000U &&
11887+ nop == 0x01000000U)
11888+ {
11889+ struct vm_area_struct *vma;
11890+ unsigned long call_dl_resolve;
11891+
11892+ down_read(&current->mm->mmap_sem);
11893+ call_dl_resolve = current->mm->call_dl_resolve;
11894+ up_read(&current->mm->mmap_sem);
11895+ if (likely(call_dl_resolve))
11896+ goto emulate;
11897+
11898+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11899+
11900+ down_write(&current->mm->mmap_sem);
11901+ if (current->mm->call_dl_resolve) {
11902+ call_dl_resolve = current->mm->call_dl_resolve;
11903+ up_write(&current->mm->mmap_sem);
11904+ if (vma)
11905+ kmem_cache_free(vm_area_cachep, vma);
11906+ goto emulate;
11907+ }
11908+
11909+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11910+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11911+ up_write(&current->mm->mmap_sem);
11912+ if (vma)
11913+ kmem_cache_free(vm_area_cachep, vma);
11914+ return 1;
11915+ }
11916+
11917+ if (pax_insert_vma(vma, call_dl_resolve)) {
11918+ up_write(&current->mm->mmap_sem);
11919+ kmem_cache_free(vm_area_cachep, vma);
11920+ return 1;
11921+ }
11922+
11923+ current->mm->call_dl_resolve = call_dl_resolve;
11924+ up_write(&current->mm->mmap_sem);
11925+
11926+emulate:
11927+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11928+ regs->tpc = call_dl_resolve;
11929+ regs->tnpc = addr+4;
11930+ return 3;
11931+ }
11932+#endif
11933+
11934+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11935+ if ((save & 0xFFC00000U) == 0x05000000U &&
11936+ (call & 0xFFFFE000U) == 0x85C0A000U &&
11937+ nop == 0x01000000U)
11938+ {
11939+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11940+ regs->u_regs[UREG_G2] = addr + 4;
11941+ addr = (save & 0x003FFFFFU) << 10;
11942+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11943+
11944+ if (test_thread_flag(TIF_32BIT))
11945+ addr &= 0xFFFFFFFFUL;
11946+
11947+ regs->tpc = addr;
11948+ regs->tnpc = addr+4;
11949+ return 3;
11950+ }
11951+
11952+ /* PaX: 64-bit PLT stub */
11953+ err = get_user(sethi1, (unsigned int *)addr);
11954+ err |= get_user(sethi2, (unsigned int *)(addr+4));
11955+ err |= get_user(or1, (unsigned int *)(addr+8));
11956+ err |= get_user(or2, (unsigned int *)(addr+12));
11957+ err |= get_user(sllx, (unsigned int *)(addr+16));
11958+ err |= get_user(add, (unsigned int *)(addr+20));
11959+ err |= get_user(jmpl, (unsigned int *)(addr+24));
11960+ err |= get_user(nop, (unsigned int *)(addr+28));
11961+ if (err)
11962+ break;
11963+
11964+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
11965+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11966+ (or1 & 0xFFFFE000U) == 0x88112000U &&
11967+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
11968+ sllx == 0x89293020U &&
11969+ add == 0x8A010005U &&
11970+ jmpl == 0x89C14000U &&
11971+ nop == 0x01000000U)
11972+ {
11973+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11974+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11975+ regs->u_regs[UREG_G4] <<= 32;
11976+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11977+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
11978+ regs->u_regs[UREG_G4] = addr + 24;
11979+ addr = regs->u_regs[UREG_G5];
11980+ regs->tpc = addr;
11981+ regs->tnpc = addr+4;
11982+ return 3;
11983+ }
11984+ }
11985+ } while (0);
11986+
11987+#ifdef CONFIG_PAX_DLRESOLVE
11988+ do { /* PaX: unpatched PLT emulation step 2 */
11989+ unsigned int save, call, nop;
11990+
11991+ err = get_user(save, (unsigned int *)(regs->tpc-4));
11992+ err |= get_user(call, (unsigned int *)regs->tpc);
11993+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
11994+ if (err)
11995+ break;
11996+
11997+ if (save == 0x9DE3BFA8U &&
11998+ (call & 0xC0000000U) == 0x40000000U &&
11999+ nop == 0x01000000U)
12000+ {
12001+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
12002+
12003+ if (test_thread_flag(TIF_32BIT))
12004+ dl_resolve &= 0xFFFFFFFFUL;
12005+
12006+ regs->u_regs[UREG_RETPC] = regs->tpc;
12007+ regs->tpc = dl_resolve;
12008+ regs->tnpc = dl_resolve+4;
12009+ return 3;
12010+ }
12011+ } while (0);
12012+#endif
12013+
12014+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
12015+ unsigned int sethi, ba, nop;
12016+
12017+ err = get_user(sethi, (unsigned int *)regs->tpc);
12018+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
12019+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
12020+
12021+ if (err)
12022+ break;
12023+
12024+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
12025+ (ba & 0xFFF00000U) == 0x30600000U &&
12026+ nop == 0x01000000U)
12027+ {
12028+ unsigned long addr;
12029+
12030+ addr = (sethi & 0x003FFFFFU) << 10;
12031+ regs->u_regs[UREG_G1] = addr;
12032+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12033+
12034+ if (test_thread_flag(TIF_32BIT))
12035+ addr &= 0xFFFFFFFFUL;
12036+
12037+ regs->tpc = addr;
12038+ regs->tnpc = addr+4;
12039+ return 2;
12040+ }
12041+ } while (0);
12042+
12043+#endif
12044+
12045+ return 1;
12046+}
12047+
12048+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
12049+{
12050+ unsigned long i;
12051+
12052+ printk(KERN_ERR "PAX: bytes at PC: ");
12053+ for (i = 0; i < 8; i++) {
12054+ unsigned int c;
12055+ if (get_user(c, (unsigned int *)pc+i))
12056+ printk(KERN_CONT "???????? ");
12057+ else
12058+ printk(KERN_CONT "%08x ", c);
12059+ }
12060+ printk("\n");
12061+}
12062+#endif
12063+
12064 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
12065 {
12066 enum ctx_state prev_state = exception_enter();
12067@@ -344,6 +829,29 @@ retry:
12068 if (!vma)
12069 goto bad_area;
12070
12071+#ifdef CONFIG_PAX_PAGEEXEC
12072+ /* PaX: detect ITLB misses on non-exec pages */
12073+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
12074+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
12075+ {
12076+ if (address != regs->tpc)
12077+ goto good_area;
12078+
12079+ up_read(&mm->mmap_sem);
12080+ switch (pax_handle_fetch_fault(regs)) {
12081+
12082+#ifdef CONFIG_PAX_EMUPLT
12083+ case 2:
12084+ case 3:
12085+ return;
12086+#endif
12087+
12088+ }
12089+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
12090+ do_group_exit(SIGKILL);
12091+ }
12092+#endif
12093+
12094 /* Pure DTLB misses do not tell us whether the fault causing
12095 * load/store/atomic was a write or not, it only says that there
12096 * was no match. So in such a case we (carefully) read the
12097@@ -525,7 +1033,7 @@ do_sigbus:
12098 * Send a sigbus, regardless of whether we were in kernel
12099 * or user mode.
12100 */
12101- do_fault_siginfo(BUS_ADRERR, SIGBUS, regs, insn, fault_code);
12102+ do_fault_siginfo(BUS_ADRERR, SIGBUS, regs, address, insn, fault_code);
12103
12104 /* Kernel mode? Handle exceptions or die */
12105 if (regs->tstate & TSTATE_PRIV)
12106diff --git a/arch/sparc/mm/gup.c b/arch/sparc/mm/gup.c
12107index c4d3da6..1aed043 100644
12108--- a/arch/sparc/mm/gup.c
12109+++ b/arch/sparc/mm/gup.c
12110@@ -73,7 +73,7 @@ static int gup_huge_pmd(pmd_t *pmdp, pmd_t pmd, unsigned long addr,
12111 struct page *head, *page, *tail;
12112 int refs;
12113
12114- if (!pmd_large(pmd))
12115+ if (!(pmd_val(pmd) & _PAGE_VALID))
12116 return 0;
12117
12118 if (write && !pmd_write(pmd))
12119diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
12120index 9bd9ce8..dc84852 100644
12121--- a/arch/sparc/mm/hugetlbpage.c
12122+++ b/arch/sparc/mm/hugetlbpage.c
12123@@ -25,8 +25,10 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12124 unsigned long addr,
12125 unsigned long len,
12126 unsigned long pgoff,
12127- unsigned long flags)
12128+ unsigned long flags,
12129+ unsigned long offset)
12130 {
12131+ struct mm_struct *mm = current->mm;
12132 unsigned long task_size = TASK_SIZE;
12133 struct vm_unmapped_area_info info;
12134
12135@@ -35,15 +37,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12136
12137 info.flags = 0;
12138 info.length = len;
12139- info.low_limit = TASK_UNMAPPED_BASE;
12140+ info.low_limit = mm->mmap_base;
12141 info.high_limit = min(task_size, VA_EXCLUDE_START);
12142 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
12143 info.align_offset = 0;
12144+ info.threadstack_offset = offset;
12145 addr = vm_unmapped_area(&info);
12146
12147 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
12148 VM_BUG_ON(addr != -ENOMEM);
12149 info.low_limit = VA_EXCLUDE_END;
12150+
12151+#ifdef CONFIG_PAX_RANDMMAP
12152+ if (mm->pax_flags & MF_PAX_RANDMMAP)
12153+ info.low_limit += mm->delta_mmap;
12154+#endif
12155+
12156 info.high_limit = task_size;
12157 addr = vm_unmapped_area(&info);
12158 }
12159@@ -55,7 +64,8 @@ static unsigned long
12160 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12161 const unsigned long len,
12162 const unsigned long pgoff,
12163- const unsigned long flags)
12164+ const unsigned long flags,
12165+ const unsigned long offset)
12166 {
12167 struct mm_struct *mm = current->mm;
12168 unsigned long addr = addr0;
12169@@ -70,6 +80,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12170 info.high_limit = mm->mmap_base;
12171 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
12172 info.align_offset = 0;
12173+ info.threadstack_offset = offset;
12174 addr = vm_unmapped_area(&info);
12175
12176 /*
12177@@ -82,6 +93,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12178 VM_BUG_ON(addr != -ENOMEM);
12179 info.flags = 0;
12180 info.low_limit = TASK_UNMAPPED_BASE;
12181+
12182+#ifdef CONFIG_PAX_RANDMMAP
12183+ if (mm->pax_flags & MF_PAX_RANDMMAP)
12184+ info.low_limit += mm->delta_mmap;
12185+#endif
12186+
12187 info.high_limit = STACK_TOP32;
12188 addr = vm_unmapped_area(&info);
12189 }
12190@@ -96,6 +113,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12191 struct mm_struct *mm = current->mm;
12192 struct vm_area_struct *vma;
12193 unsigned long task_size = TASK_SIZE;
12194+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
12195
12196 if (test_thread_flag(TIF_32BIT))
12197 task_size = STACK_TOP32;
12198@@ -111,19 +129,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12199 return addr;
12200 }
12201
12202+#ifdef CONFIG_PAX_RANDMMAP
12203+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
12204+#endif
12205+
12206 if (addr) {
12207 addr = ALIGN(addr, HPAGE_SIZE);
12208 vma = find_vma(mm, addr);
12209- if (task_size - len >= addr &&
12210- (!vma || addr + len <= vma->vm_start))
12211+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
12212 return addr;
12213 }
12214 if (mm->get_unmapped_area == arch_get_unmapped_area)
12215 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
12216- pgoff, flags);
12217+ pgoff, flags, offset);
12218 else
12219 return hugetlb_get_unmapped_area_topdown(file, addr, len,
12220- pgoff, flags);
12221+ pgoff, flags, offset);
12222 }
12223
12224 pte_t *huge_pte_alloc(struct mm_struct *mm,
12225diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
12226index eafbc65..5a8070d 100644
12227--- a/arch/sparc/mm/init_64.c
12228+++ b/arch/sparc/mm/init_64.c
12229@@ -188,9 +188,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
12230 int num_kernel_image_mappings;
12231
12232 #ifdef CONFIG_DEBUG_DCFLUSH
12233-atomic_t dcpage_flushes = ATOMIC_INIT(0);
12234+atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
12235 #ifdef CONFIG_SMP
12236-atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12237+atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12238 #endif
12239 #endif
12240
12241@@ -198,7 +198,7 @@ inline void flush_dcache_page_impl(struct page *page)
12242 {
12243 BUG_ON(tlb_type == hypervisor);
12244 #ifdef CONFIG_DEBUG_DCFLUSH
12245- atomic_inc(&dcpage_flushes);
12246+ atomic_inc_unchecked(&dcpage_flushes);
12247 #endif
12248
12249 #ifdef DCACHE_ALIASING_POSSIBLE
12250@@ -466,10 +466,10 @@ void mmu_info(struct seq_file *m)
12251
12252 #ifdef CONFIG_DEBUG_DCFLUSH
12253 seq_printf(m, "DCPageFlushes\t: %d\n",
12254- atomic_read(&dcpage_flushes));
12255+ atomic_read_unchecked(&dcpage_flushes));
12256 #ifdef CONFIG_SMP
12257 seq_printf(m, "DCPageFlushesXC\t: %d\n",
12258- atomic_read(&dcpage_flushes_xcall));
12259+ atomic_read_unchecked(&dcpage_flushes_xcall));
12260 #endif /* CONFIG_SMP */
12261 #endif /* CONFIG_DEBUG_DCFLUSH */
12262 }
12263diff --git a/arch/sparc/mm/tlb.c b/arch/sparc/mm/tlb.c
12264index b12cb5e..b89aba2 100644
12265--- a/arch/sparc/mm/tlb.c
12266+++ b/arch/sparc/mm/tlb.c
12267@@ -134,7 +134,7 @@ no_cache_flush:
12268
12269 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
12270 static void tlb_batch_pmd_scan(struct mm_struct *mm, unsigned long vaddr,
12271- pmd_t pmd, bool exec)
12272+ pmd_t pmd)
12273 {
12274 unsigned long end;
12275 pte_t *pte;
12276@@ -142,8 +142,11 @@ static void tlb_batch_pmd_scan(struct mm_struct *mm, unsigned long vaddr,
12277 pte = pte_offset_map(&pmd, vaddr);
12278 end = vaddr + HPAGE_SIZE;
12279 while (vaddr < end) {
12280- if (pte_val(*pte) & _PAGE_VALID)
12281+ if (pte_val(*pte) & _PAGE_VALID) {
12282+ bool exec = pte_exec(*pte);
12283+
12284 tlb_batch_add_one(mm, vaddr, exec);
12285+ }
12286 pte++;
12287 vaddr += PAGE_SIZE;
12288 }
12289@@ -177,19 +180,30 @@ void set_pmd_at(struct mm_struct *mm, unsigned long addr,
12290 }
12291
12292 if (!pmd_none(orig)) {
12293- pte_t orig_pte = __pte(pmd_val(orig));
12294- bool exec = pte_exec(orig_pte);
12295-
12296 addr &= HPAGE_MASK;
12297 if (pmd_trans_huge(orig)) {
12298+ pte_t orig_pte = __pte(pmd_val(orig));
12299+ bool exec = pte_exec(orig_pte);
12300+
12301 tlb_batch_add_one(mm, addr, exec);
12302 tlb_batch_add_one(mm, addr + REAL_HPAGE_SIZE, exec);
12303 } else {
12304- tlb_batch_pmd_scan(mm, addr, orig, exec);
12305+ tlb_batch_pmd_scan(mm, addr, orig);
12306 }
12307 }
12308 }
12309
12310+void pmdp_invalidate(struct vm_area_struct *vma, unsigned long address,
12311+ pmd_t *pmdp)
12312+{
12313+ pmd_t entry = *pmdp;
12314+
12315+ pmd_val(entry) &= ~_PAGE_VALID;
12316+
12317+ set_pmd_at(vma->vm_mm, address, pmdp, entry);
12318+ flush_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
12319+}
12320+
12321 void pgtable_trans_huge_deposit(struct mm_struct *mm, pmd_t *pmdp,
12322 pgtable_t pgtable)
12323 {
12324diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
12325index b3692ce..e4517c9 100644
12326--- a/arch/tile/Kconfig
12327+++ b/arch/tile/Kconfig
12328@@ -184,6 +184,7 @@ source "kernel/Kconfig.hz"
12329
12330 config KEXEC
12331 bool "kexec system call"
12332+ depends on !GRKERNSEC_KMEM
12333 ---help---
12334 kexec is a system call that implements the ability to shutdown your
12335 current kernel, and to start another kernel. It is like a reboot
12336diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
12337index ad220ee..2f537b3 100644
12338--- a/arch/tile/include/asm/atomic_64.h
12339+++ b/arch/tile/include/asm/atomic_64.h
12340@@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
12341
12342 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
12343
12344+#define atomic64_read_unchecked(v) atomic64_read(v)
12345+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
12346+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
12347+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
12348+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
12349+#define atomic64_inc_unchecked(v) atomic64_inc(v)
12350+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
12351+#define atomic64_dec_unchecked(v) atomic64_dec(v)
12352+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
12353+
12354 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
12355 #define smp_mb__before_atomic_dec() smp_mb()
12356 #define smp_mb__after_atomic_dec() smp_mb()
12357diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
12358index 6160761..00cac88 100644
12359--- a/arch/tile/include/asm/cache.h
12360+++ b/arch/tile/include/asm/cache.h
12361@@ -15,11 +15,12 @@
12362 #ifndef _ASM_TILE_CACHE_H
12363 #define _ASM_TILE_CACHE_H
12364
12365+#include <linux/const.h>
12366 #include <arch/chip.h>
12367
12368 /* bytes per L1 data cache line */
12369 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
12370-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12371+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12372
12373 /* bytes per L2 cache line */
12374 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
12375diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
12376index b6cde32..c0cb736 100644
12377--- a/arch/tile/include/asm/uaccess.h
12378+++ b/arch/tile/include/asm/uaccess.h
12379@@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
12380 const void __user *from,
12381 unsigned long n)
12382 {
12383- int sz = __compiletime_object_size(to);
12384+ size_t sz = __compiletime_object_size(to);
12385
12386- if (likely(sz == -1 || sz >= n))
12387+ if (likely(sz == (size_t)-1 || sz >= n))
12388 n = _copy_from_user(to, from, n);
12389 else
12390 copy_from_user_overflow();
12391diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
12392index 0cb3bba..7338b2d 100644
12393--- a/arch/tile/mm/hugetlbpage.c
12394+++ b/arch/tile/mm/hugetlbpage.c
12395@@ -212,6 +212,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
12396 info.high_limit = TASK_SIZE;
12397 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12398 info.align_offset = 0;
12399+ info.threadstack_offset = 0;
12400 return vm_unmapped_area(&info);
12401 }
12402
12403@@ -229,6 +230,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
12404 info.high_limit = current->mm->mmap_base;
12405 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12406 info.align_offset = 0;
12407+ info.threadstack_offset = 0;
12408 addr = vm_unmapped_area(&info);
12409
12410 /*
12411diff --git a/arch/um/Makefile b/arch/um/Makefile
12412index 36e658a..71a5c5a 100644
12413--- a/arch/um/Makefile
12414+++ b/arch/um/Makefile
12415@@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
12416 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
12417 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
12418
12419+ifdef CONSTIFY_PLUGIN
12420+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12421+endif
12422+
12423 #This will adjust *FLAGS accordingly to the platform.
12424 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
12425
12426diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
12427index 19e1bdd..3665b77 100644
12428--- a/arch/um/include/asm/cache.h
12429+++ b/arch/um/include/asm/cache.h
12430@@ -1,6 +1,7 @@
12431 #ifndef __UM_CACHE_H
12432 #define __UM_CACHE_H
12433
12434+#include <linux/const.h>
12435
12436 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
12437 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12438@@ -12,6 +13,6 @@
12439 # define L1_CACHE_SHIFT 5
12440 #endif
12441
12442-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12443+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12444
12445 #endif
12446diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
12447index 2e0a6b1..a64d0f5 100644
12448--- a/arch/um/include/asm/kmap_types.h
12449+++ b/arch/um/include/asm/kmap_types.h
12450@@ -8,6 +8,6 @@
12451
12452 /* No more #include "asm/arch/kmap_types.h" ! */
12453
12454-#define KM_TYPE_NR 14
12455+#define KM_TYPE_NR 15
12456
12457 #endif
12458diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
12459index 5ff53d9..5850cdf 100644
12460--- a/arch/um/include/asm/page.h
12461+++ b/arch/um/include/asm/page.h
12462@@ -14,6 +14,9 @@
12463 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
12464 #define PAGE_MASK (~(PAGE_SIZE-1))
12465
12466+#define ktla_ktva(addr) (addr)
12467+#define ktva_ktla(addr) (addr)
12468+
12469 #ifndef __ASSEMBLY__
12470
12471 struct page;
12472diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
12473index 0032f92..cd151e0 100644
12474--- a/arch/um/include/asm/pgtable-3level.h
12475+++ b/arch/um/include/asm/pgtable-3level.h
12476@@ -58,6 +58,7 @@
12477 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
12478 #define pud_populate(mm, pud, pmd) \
12479 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
12480+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
12481
12482 #ifdef CONFIG_64BIT
12483 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
12484diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
12485index eecc414..48adb87 100644
12486--- a/arch/um/kernel/process.c
12487+++ b/arch/um/kernel/process.c
12488@@ -356,22 +356,6 @@ int singlestepping(void * t)
12489 return 2;
12490 }
12491
12492-/*
12493- * Only x86 and x86_64 have an arch_align_stack().
12494- * All other arches have "#define arch_align_stack(x) (x)"
12495- * in their asm/system.h
12496- * As this is included in UML from asm-um/system-generic.h,
12497- * we can use it to behave as the subarch does.
12498- */
12499-#ifndef arch_align_stack
12500-unsigned long arch_align_stack(unsigned long sp)
12501-{
12502- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
12503- sp -= get_random_int() % 8192;
12504- return sp & ~0xf;
12505-}
12506-#endif
12507-
12508 unsigned long get_wchan(struct task_struct *p)
12509 {
12510 unsigned long stack_page, sp, ip;
12511diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
12512index ad8f795..2c7eec6 100644
12513--- a/arch/unicore32/include/asm/cache.h
12514+++ b/arch/unicore32/include/asm/cache.h
12515@@ -12,8 +12,10 @@
12516 #ifndef __UNICORE_CACHE_H__
12517 #define __UNICORE_CACHE_H__
12518
12519-#define L1_CACHE_SHIFT (5)
12520-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12521+#include <linux/const.h>
12522+
12523+#define L1_CACHE_SHIFT 5
12524+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12525
12526 /*
12527 * Memory returned by kmalloc() may be used for DMA, so we must make
12528diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
12529index 0af5250..59f9597 100644
12530--- a/arch/x86/Kconfig
12531+++ b/arch/x86/Kconfig
12532@@ -126,7 +126,7 @@ config X86
12533 select RTC_LIB
12534 select HAVE_DEBUG_STACKOVERFLOW
12535 select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64
12536- select HAVE_CC_STACKPROTECTOR
12537+ select HAVE_CC_STACKPROTECTOR if X86_64 || !PAX_MEMORY_UDEREF
12538
12539 config INSTRUCTION_DECODER
12540 def_bool y
12541@@ -251,7 +251,7 @@ config X86_HT
12542
12543 config X86_32_LAZY_GS
12544 def_bool y
12545- depends on X86_32 && !CC_STACKPROTECTOR
12546+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
12547
12548 config ARCH_HWEIGHT_CFLAGS
12549 string
12550@@ -589,6 +589,7 @@ config SCHED_OMIT_FRAME_POINTER
12551
12552 menuconfig HYPERVISOR_GUEST
12553 bool "Linux guest support"
12554+ depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_GUEST || (GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_XEN)
12555 ---help---
12556 Say Y here to enable options for running Linux under various hyper-
12557 visors. This option enables basic hypervisor detection and platform
12558@@ -1111,7 +1112,7 @@ choice
12559
12560 config NOHIGHMEM
12561 bool "off"
12562- depends on !X86_NUMAQ
12563+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12564 ---help---
12565 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
12566 However, the address space of 32-bit x86 processors is only 4
12567@@ -1148,7 +1149,7 @@ config NOHIGHMEM
12568
12569 config HIGHMEM4G
12570 bool "4GB"
12571- depends on !X86_NUMAQ
12572+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12573 ---help---
12574 Select this if you have a 32-bit processor and between 1 and 4
12575 gigabytes of physical RAM.
12576@@ -1201,7 +1202,7 @@ config PAGE_OFFSET
12577 hex
12578 default 0xB0000000 if VMSPLIT_3G_OPT
12579 default 0x80000000 if VMSPLIT_2G
12580- default 0x78000000 if VMSPLIT_2G_OPT
12581+ default 0x70000000 if VMSPLIT_2G_OPT
12582 default 0x40000000 if VMSPLIT_1G
12583 default 0xC0000000
12584 depends on X86_32
12585@@ -1605,6 +1606,7 @@ source kernel/Kconfig.hz
12586
12587 config KEXEC
12588 bool "kexec system call"
12589+ depends on !GRKERNSEC_KMEM
12590 ---help---
12591 kexec is a system call that implements the ability to shutdown your
12592 current kernel, and to start another kernel. It is like a reboot
12593@@ -1756,7 +1758,9 @@ config X86_NEED_RELOCS
12594
12595 config PHYSICAL_ALIGN
12596 hex "Alignment value to which kernel should be aligned"
12597- default "0x200000"
12598+ default "0x1000000"
12599+ range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
12600+ range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
12601 range 0x2000 0x1000000 if X86_32
12602 range 0x200000 0x1000000 if X86_64
12603 ---help---
12604@@ -1836,9 +1840,10 @@ config DEBUG_HOTPLUG_CPU0
12605 If unsure, say N.
12606
12607 config COMPAT_VDSO
12608- def_bool y
12609+ def_bool n
12610 prompt "Compat VDSO support"
12611 depends on X86_32 || IA32_EMULATION
12612+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
12613 ---help---
12614 Map the 32-bit VDSO to the predictable old-style address too.
12615
12616diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
12617index f3aaf23..a1d3c49 100644
12618--- a/arch/x86/Kconfig.cpu
12619+++ b/arch/x86/Kconfig.cpu
12620@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
12621
12622 config X86_F00F_BUG
12623 def_bool y
12624- depends on M586MMX || M586TSC || M586 || M486
12625+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
12626
12627 config X86_INVD_BUG
12628 def_bool y
12629@@ -327,7 +327,7 @@ config X86_INVD_BUG
12630
12631 config X86_ALIGNMENT_16
12632 def_bool y
12633- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12634+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12635
12636 config X86_INTEL_USERCOPY
12637 def_bool y
12638@@ -369,7 +369,7 @@ config X86_CMPXCHG64
12639 # generates cmov.
12640 config X86_CMOV
12641 def_bool y
12642- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12643+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12644
12645 config X86_MINIMUM_CPU_FAMILY
12646 int
12647diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
12648index 321a52c..3d51a5e 100644
12649--- a/arch/x86/Kconfig.debug
12650+++ b/arch/x86/Kconfig.debug
12651@@ -84,7 +84,7 @@ config X86_PTDUMP
12652 config DEBUG_RODATA
12653 bool "Write protect kernel read-only data structures"
12654 default y
12655- depends on DEBUG_KERNEL
12656+ depends on DEBUG_KERNEL && BROKEN
12657 ---help---
12658 Mark the kernel read-only data as write-protected in the pagetables,
12659 in order to catch accidental (and incorrect) writes to such const
12660@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
12661
12662 config DEBUG_SET_MODULE_RONX
12663 bool "Set loadable kernel module data as NX and text as RO"
12664- depends on MODULES
12665+ depends on MODULES && BROKEN
12666 ---help---
12667 This option helps catch unintended modifications to loadable
12668 kernel module's text and read-only data. It also prevents execution
12669diff --git a/arch/x86/Makefile b/arch/x86/Makefile
12670index 0dd99ea..e893775 100644
12671--- a/arch/x86/Makefile
12672+++ b/arch/x86/Makefile
12673@@ -71,15 +71,12 @@ ifeq ($(CONFIG_X86_32),y)
12674 # CPU-specific tuning. Anything which can be shared with UML should go here.
12675 include $(srctree)/arch/x86/Makefile_32.cpu
12676 KBUILD_CFLAGS += $(cflags-y)
12677-
12678- # temporary until string.h is fixed
12679- KBUILD_CFLAGS += -ffreestanding
12680 else
12681 BITS := 64
12682 UTS_MACHINE := x86_64
12683 CHECKFLAGS += -D__x86_64__ -m64
12684
12685- biarch := -m64
12686+ biarch := $(call cc-option,-m64)
12687 KBUILD_AFLAGS += -m64
12688 KBUILD_CFLAGS += -m64
12689
12690@@ -112,6 +109,9 @@ else
12691 KBUILD_CFLAGS += -maccumulate-outgoing-args
12692 endif
12693
12694+# temporary until string.h is fixed
12695+KBUILD_CFLAGS += -ffreestanding
12696+
12697 # Make sure compiler does not have buggy stack-protector support.
12698 ifdef CONFIG_CC_STACKPROTECTOR
12699 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
12700@@ -269,3 +269,12 @@ define archhelp
12701 echo ' FDINITRD=file initrd for the booted kernel'
12702 echo ' kvmconfig - Enable additional options for guest kernel support'
12703 endef
12704+
12705+define OLD_LD
12706+
12707+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
12708+*** Please upgrade your binutils to 2.18 or newer
12709+endef
12710+
12711+archprepare:
12712+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
12713diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
12714index 878df7e..a803913 100644
12715--- a/arch/x86/boot/Makefile
12716+++ b/arch/x86/boot/Makefile
12717@@ -52,6 +52,9 @@ $(obj)/cpustr.h: $(obj)/mkcpustr FORCE
12718 # ---------------------------------------------------------------------------
12719
12720 KBUILD_CFLAGS := $(USERINCLUDE) $(REALMODE_CFLAGS) -D_SETUP
12721+ifdef CONSTIFY_PLUGIN
12722+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12723+endif
12724 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12725 GCOV_PROFILE := n
12726
12727diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
12728index 878e4b9..20537ab 100644
12729--- a/arch/x86/boot/bitops.h
12730+++ b/arch/x86/boot/bitops.h
12731@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12732 u8 v;
12733 const u32 *p = (const u32 *)addr;
12734
12735- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12736+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12737 return v;
12738 }
12739
12740@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12741
12742 static inline void set_bit(int nr, void *addr)
12743 {
12744- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12745+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12746 }
12747
12748 #endif /* BOOT_BITOPS_H */
12749diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
12750index 50f8c5e..4f84fff 100644
12751--- a/arch/x86/boot/boot.h
12752+++ b/arch/x86/boot/boot.h
12753@@ -84,7 +84,7 @@ static inline void io_delay(void)
12754 static inline u16 ds(void)
12755 {
12756 u16 seg;
12757- asm("movw %%ds,%0" : "=rm" (seg));
12758+ asm volatile("movw %%ds,%0" : "=rm" (seg));
12759 return seg;
12760 }
12761
12762@@ -180,7 +180,7 @@ static inline void wrgs32(u32 v, addr_t addr)
12763 static inline int memcmp(const void *s1, const void *s2, size_t len)
12764 {
12765 u8 diff;
12766- asm("repe; cmpsb; setnz %0"
12767+ asm volatile("repe; cmpsb; setnz %0"
12768 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
12769 return diff;
12770 }
12771diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
12772index 0fcd913..3bb5c42 100644
12773--- a/arch/x86/boot/compressed/Makefile
12774+++ b/arch/x86/boot/compressed/Makefile
12775@@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
12776 KBUILD_CFLAGS += -mno-mmx -mno-sse
12777 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
12778 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
12779+ifdef CONSTIFY_PLUGIN
12780+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12781+endif
12782
12783 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12784 GCOV_PROFILE := n
12785diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
12786index a53440e..c3dbf1e 100644
12787--- a/arch/x86/boot/compressed/efi_stub_32.S
12788+++ b/arch/x86/boot/compressed/efi_stub_32.S
12789@@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
12790 * parameter 2, ..., param n. To make things easy, we save the return
12791 * address of efi_call_phys in a global variable.
12792 */
12793- popl %ecx
12794- movl %ecx, saved_return_addr(%edx)
12795- /* get the function pointer into ECX*/
12796- popl %ecx
12797- movl %ecx, efi_rt_function_ptr(%edx)
12798+ popl saved_return_addr(%edx)
12799+ popl efi_rt_function_ptr(%edx)
12800
12801 /*
12802 * 3. Call the physical function.
12803 */
12804- call *%ecx
12805+ call *efi_rt_function_ptr(%edx)
12806
12807 /*
12808 * 4. Balance the stack. And because EAX contain the return value,
12809@@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
12810 1: popl %edx
12811 subl $1b, %edx
12812
12813- movl efi_rt_function_ptr(%edx), %ecx
12814- pushl %ecx
12815+ pushl efi_rt_function_ptr(%edx)
12816
12817 /*
12818 * 10. Push the saved return address onto the stack and return.
12819 */
12820- movl saved_return_addr(%edx), %ecx
12821- pushl %ecx
12822- ret
12823+ jmpl *saved_return_addr(%edx)
12824 ENDPROC(efi_call_phys)
12825 .previous
12826
12827diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
12828index f45ab7a..ebc015f 100644
12829--- a/arch/x86/boot/compressed/head_32.S
12830+++ b/arch/x86/boot/compressed/head_32.S
12831@@ -119,10 +119,10 @@ preferred_addr:
12832 addl %eax, %ebx
12833 notl %eax
12834 andl %eax, %ebx
12835- cmpl $LOAD_PHYSICAL_ADDR, %ebx
12836+ cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12837 jge 1f
12838 #endif
12839- movl $LOAD_PHYSICAL_ADDR, %ebx
12840+ movl $____LOAD_PHYSICAL_ADDR, %ebx
12841 1:
12842
12843 /* Target address to relocate to for decompression */
12844diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
12845index b10fa66..5ee0472 100644
12846--- a/arch/x86/boot/compressed/head_64.S
12847+++ b/arch/x86/boot/compressed/head_64.S
12848@@ -94,10 +94,10 @@ ENTRY(startup_32)
12849 addl %eax, %ebx
12850 notl %eax
12851 andl %eax, %ebx
12852- cmpl $LOAD_PHYSICAL_ADDR, %ebx
12853+ cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12854 jge 1f
12855 #endif
12856- movl $LOAD_PHYSICAL_ADDR, %ebx
12857+ movl $____LOAD_PHYSICAL_ADDR, %ebx
12858 1:
12859
12860 /* Target address to relocate to for decompression */
12861@@ -268,10 +268,10 @@ preferred_addr:
12862 addq %rax, %rbp
12863 notq %rax
12864 andq %rax, %rbp
12865- cmpq $LOAD_PHYSICAL_ADDR, %rbp
12866+ cmpq $____LOAD_PHYSICAL_ADDR, %rbp
12867 jge 1f
12868 #endif
12869- movq $LOAD_PHYSICAL_ADDR, %rbp
12870+ movq $____LOAD_PHYSICAL_ADDR, %rbp
12871 1:
12872
12873 /* Target address to relocate to for decompression */
12874@@ -363,8 +363,8 @@ gdt:
12875 .long gdt
12876 .word 0
12877 .quad 0x0000000000000000 /* NULL descriptor */
12878- .quad 0x00af9a000000ffff /* __KERNEL_CS */
12879- .quad 0x00cf92000000ffff /* __KERNEL_DS */
12880+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
12881+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
12882 .quad 0x0080890000000000 /* TS descriptor */
12883 .quad 0x0000000000000000 /* TS continued */
12884 gdt_end:
12885diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
12886index 196eaf3..c96716d 100644
12887--- a/arch/x86/boot/compressed/misc.c
12888+++ b/arch/x86/boot/compressed/misc.c
12889@@ -218,7 +218,7 @@ void __putstr(const char *s)
12890
12891 void *memset(void *s, int c, size_t n)
12892 {
12893- int i;
12894+ size_t i;
12895 char *ss = s;
12896
12897 for (i = 0; i < n; i++)
12898@@ -277,7 +277,7 @@ static void handle_relocations(void *output, unsigned long output_len)
12899 * Calculate the delta between where vmlinux was linked to load
12900 * and where it was actually loaded.
12901 */
12902- delta = min_addr - LOAD_PHYSICAL_ADDR;
12903+ delta = min_addr - ____LOAD_PHYSICAL_ADDR;
12904 if (!delta) {
12905 debug_putstr("No relocation needed... ");
12906 return;
12907@@ -347,7 +347,7 @@ static void parse_elf(void *output)
12908 Elf32_Ehdr ehdr;
12909 Elf32_Phdr *phdrs, *phdr;
12910 #endif
12911- void *dest;
12912+ void *dest, *prev;
12913 int i;
12914
12915 memcpy(&ehdr, output, sizeof(ehdr));
12916@@ -374,13 +374,16 @@ static void parse_elf(void *output)
12917 case PT_LOAD:
12918 #ifdef CONFIG_RELOCATABLE
12919 dest = output;
12920- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
12921+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
12922 #else
12923 dest = (void *)(phdr->p_paddr);
12924 #endif
12925 memcpy(dest,
12926 output + phdr->p_offset,
12927 phdr->p_filesz);
12928+ if (i)
12929+ memset(prev, 0xff, dest - prev);
12930+ prev = dest + phdr->p_filesz;
12931 break;
12932 default: /* Ignore other PT_* */ break;
12933 }
12934@@ -430,7 +433,7 @@ asmlinkage void *decompress_kernel(void *rmode, memptr heap,
12935 error("Destination address too large");
12936 #endif
12937 #ifndef CONFIG_RELOCATABLE
12938- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
12939+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
12940 error("Wrong destination address");
12941 #endif
12942
12943diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
12944index 100a9a1..bb3bdb0 100644
12945--- a/arch/x86/boot/cpucheck.c
12946+++ b/arch/x86/boot/cpucheck.c
12947@@ -117,9 +117,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12948 u32 ecx = MSR_K7_HWCR;
12949 u32 eax, edx;
12950
12951- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12952+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12953 eax &= ~(1 << 15);
12954- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12955+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12956
12957 get_cpuflags(); /* Make sure it really did something */
12958 err = check_cpuflags();
12959@@ -132,9 +132,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12960 u32 ecx = MSR_VIA_FCR;
12961 u32 eax, edx;
12962
12963- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12964+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12965 eax |= (1<<1)|(1<<7);
12966- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12967+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12968
12969 set_bit(X86_FEATURE_CX8, cpu.flags);
12970 err = check_cpuflags();
12971@@ -145,12 +145,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12972 u32 eax, edx;
12973 u32 level = 1;
12974
12975- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12976- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12977- asm("cpuid"
12978+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12979+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12980+ asm volatile("cpuid"
12981 : "+a" (level), "=d" (cpu.flags[0])
12982 : : "ecx", "ebx");
12983- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12984+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12985
12986 err = check_cpuflags();
12987 }
12988diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
12989index ec3b8ba..6a0db1f 100644
12990--- a/arch/x86/boot/header.S
12991+++ b/arch/x86/boot/header.S
12992@@ -416,10 +416,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
12993 # single linked list of
12994 # struct setup_data
12995
12996-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
12997+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
12998
12999 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
13000+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13001+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
13002+#else
13003 #define VO_INIT_SIZE (VO__end - VO__text)
13004+#endif
13005 #if ZO_INIT_SIZE > VO_INIT_SIZE
13006 #define INIT_SIZE ZO_INIT_SIZE
13007 #else
13008diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
13009index db75d07..8e6d0af 100644
13010--- a/arch/x86/boot/memory.c
13011+++ b/arch/x86/boot/memory.c
13012@@ -19,7 +19,7 @@
13013
13014 static int detect_memory_e820(void)
13015 {
13016- int count = 0;
13017+ unsigned int count = 0;
13018 struct biosregs ireg, oreg;
13019 struct e820entry *desc = boot_params.e820_map;
13020 static struct e820entry buf; /* static so it is zeroed */
13021diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
13022index 11e8c6e..fdbb1ed 100644
13023--- a/arch/x86/boot/video-vesa.c
13024+++ b/arch/x86/boot/video-vesa.c
13025@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
13026
13027 boot_params.screen_info.vesapm_seg = oreg.es;
13028 boot_params.screen_info.vesapm_off = oreg.di;
13029+ boot_params.screen_info.vesapm_size = oreg.cx;
13030 }
13031
13032 /*
13033diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
13034index 43eda28..5ab5fdb 100644
13035--- a/arch/x86/boot/video.c
13036+++ b/arch/x86/boot/video.c
13037@@ -96,7 +96,7 @@ static void store_mode_params(void)
13038 static unsigned int get_entry(void)
13039 {
13040 char entry_buf[4];
13041- int i, len = 0;
13042+ unsigned int i, len = 0;
13043 int key;
13044 unsigned int v;
13045
13046diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
13047index 9105655..41779c1 100644
13048--- a/arch/x86/crypto/aes-x86_64-asm_64.S
13049+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
13050@@ -8,6 +8,8 @@
13051 * including this sentence is retained in full.
13052 */
13053
13054+#include <asm/alternative-asm.h>
13055+
13056 .extern crypto_ft_tab
13057 .extern crypto_it_tab
13058 .extern crypto_fl_tab
13059@@ -70,6 +72,8 @@
13060 je B192; \
13061 leaq 32(r9),r9;
13062
13063+#define ret pax_force_retaddr; ret
13064+
13065 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
13066 movq r1,r2; \
13067 movq r3,r4; \
13068diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
13069index 477e9d7..c92c7d8 100644
13070--- a/arch/x86/crypto/aesni-intel_asm.S
13071+++ b/arch/x86/crypto/aesni-intel_asm.S
13072@@ -31,6 +31,7 @@
13073
13074 #include <linux/linkage.h>
13075 #include <asm/inst.h>
13076+#include <asm/alternative-asm.h>
13077
13078 #ifdef __x86_64__
13079 .data
13080@@ -205,7 +206,7 @@ enc: .octa 0x2
13081 * num_initial_blocks = b mod 4
13082 * encrypt the initial num_initial_blocks blocks and apply ghash on
13083 * the ciphertext
13084-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13085+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13086 * are clobbered
13087 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13088 */
13089@@ -214,8 +215,8 @@ enc: .octa 0x2
13090 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13091 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13092 mov arg7, %r10 # %r10 = AAD
13093- mov arg8, %r12 # %r12 = aadLen
13094- mov %r12, %r11
13095+ mov arg8, %r15 # %r15 = aadLen
13096+ mov %r15, %r11
13097 pxor %xmm\i, %xmm\i
13098 _get_AAD_loop\num_initial_blocks\operation:
13099 movd (%r10), \TMP1
13100@@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13101 psrldq $4, %xmm\i
13102 pxor \TMP1, %xmm\i
13103 add $4, %r10
13104- sub $4, %r12
13105+ sub $4, %r15
13106 jne _get_AAD_loop\num_initial_blocks\operation
13107 cmp $16, %r11
13108 je _get_AAD_loop2_done\num_initial_blocks\operation
13109- mov $16, %r12
13110+ mov $16, %r15
13111 _get_AAD_loop2\num_initial_blocks\operation:
13112 psrldq $4, %xmm\i
13113- sub $4, %r12
13114- cmp %r11, %r12
13115+ sub $4, %r15
13116+ cmp %r11, %r15
13117 jne _get_AAD_loop2\num_initial_blocks\operation
13118 _get_AAD_loop2_done\num_initial_blocks\operation:
13119 movdqa SHUF_MASK(%rip), %xmm14
13120@@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
13121 * num_initial_blocks = b mod 4
13122 * encrypt the initial num_initial_blocks blocks and apply ghash on
13123 * the ciphertext
13124-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13125+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13126 * are clobbered
13127 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13128 */
13129@@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
13130 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13131 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13132 mov arg7, %r10 # %r10 = AAD
13133- mov arg8, %r12 # %r12 = aadLen
13134- mov %r12, %r11
13135+ mov arg8, %r15 # %r15 = aadLen
13136+ mov %r15, %r11
13137 pxor %xmm\i, %xmm\i
13138 _get_AAD_loop\num_initial_blocks\operation:
13139 movd (%r10), \TMP1
13140@@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13141 psrldq $4, %xmm\i
13142 pxor \TMP1, %xmm\i
13143 add $4, %r10
13144- sub $4, %r12
13145+ sub $4, %r15
13146 jne _get_AAD_loop\num_initial_blocks\operation
13147 cmp $16, %r11
13148 je _get_AAD_loop2_done\num_initial_blocks\operation
13149- mov $16, %r12
13150+ mov $16, %r15
13151 _get_AAD_loop2\num_initial_blocks\operation:
13152 psrldq $4, %xmm\i
13153- sub $4, %r12
13154- cmp %r11, %r12
13155+ sub $4, %r15
13156+ cmp %r11, %r15
13157 jne _get_AAD_loop2\num_initial_blocks\operation
13158 _get_AAD_loop2_done\num_initial_blocks\operation:
13159 movdqa SHUF_MASK(%rip), %xmm14
13160@@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
13161 *
13162 *****************************************************************************/
13163 ENTRY(aesni_gcm_dec)
13164- push %r12
13165+ push %r15
13166 push %r13
13167 push %r14
13168 mov %rsp, %r14
13169@@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
13170 */
13171 sub $VARIABLE_OFFSET, %rsp
13172 and $~63, %rsp # align rsp to 64 bytes
13173- mov %arg6, %r12
13174- movdqu (%r12), %xmm13 # %xmm13 = HashKey
13175+ mov %arg6, %r15
13176+ movdqu (%r15), %xmm13 # %xmm13 = HashKey
13177 movdqa SHUF_MASK(%rip), %xmm2
13178 PSHUFB_XMM %xmm2, %xmm13
13179
13180@@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
13181 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
13182 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
13183 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
13184- mov %r13, %r12
13185- and $(3<<4), %r12
13186+ mov %r13, %r15
13187+ and $(3<<4), %r15
13188 jz _initial_num_blocks_is_0_decrypt
13189- cmp $(2<<4), %r12
13190+ cmp $(2<<4), %r15
13191 jb _initial_num_blocks_is_1_decrypt
13192 je _initial_num_blocks_is_2_decrypt
13193 _initial_num_blocks_is_3_decrypt:
13194@@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
13195 sub $16, %r11
13196 add %r13, %r11
13197 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
13198- lea SHIFT_MASK+16(%rip), %r12
13199- sub %r13, %r12
13200+ lea SHIFT_MASK+16(%rip), %r15
13201+ sub %r13, %r15
13202 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
13203 # (%r13 is the number of bytes in plaintext mod 16)
13204- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13205+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13206 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
13207
13208 movdqa %xmm1, %xmm2
13209 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
13210- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13211+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13212 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
13213 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
13214 pand %xmm1, %xmm2
13215@@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
13216 sub $1, %r13
13217 jne _less_than_8_bytes_left_decrypt
13218 _multiple_of_16_bytes_decrypt:
13219- mov arg8, %r12 # %r13 = aadLen (number of bytes)
13220- shl $3, %r12 # convert into number of bits
13221- movd %r12d, %xmm15 # len(A) in %xmm15
13222+ mov arg8, %r15 # %r13 = aadLen (number of bytes)
13223+ shl $3, %r15 # convert into number of bits
13224+ movd %r15d, %xmm15 # len(A) in %xmm15
13225 shl $3, %arg4 # len(C) in bits (*128)
13226 MOVQ_R64_XMM %arg4, %xmm1
13227 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13228@@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
13229 mov %r14, %rsp
13230 pop %r14
13231 pop %r13
13232- pop %r12
13233+ pop %r15
13234+ pax_force_retaddr
13235 ret
13236 ENDPROC(aesni_gcm_dec)
13237
13238@@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
13239 * poly = x^128 + x^127 + x^126 + x^121 + 1
13240 ***************************************************************************/
13241 ENTRY(aesni_gcm_enc)
13242- push %r12
13243+ push %r15
13244 push %r13
13245 push %r14
13246 mov %rsp, %r14
13247@@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
13248 #
13249 sub $VARIABLE_OFFSET, %rsp
13250 and $~63, %rsp
13251- mov %arg6, %r12
13252- movdqu (%r12), %xmm13
13253+ mov %arg6, %r15
13254+ movdqu (%r15), %xmm13
13255 movdqa SHUF_MASK(%rip), %xmm2
13256 PSHUFB_XMM %xmm2, %xmm13
13257
13258@@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
13259 movdqa %xmm13, HashKey(%rsp)
13260 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
13261 and $-16, %r13
13262- mov %r13, %r12
13263+ mov %r13, %r15
13264
13265 # Encrypt first few blocks
13266
13267- and $(3<<4), %r12
13268+ and $(3<<4), %r15
13269 jz _initial_num_blocks_is_0_encrypt
13270- cmp $(2<<4), %r12
13271+ cmp $(2<<4), %r15
13272 jb _initial_num_blocks_is_1_encrypt
13273 je _initial_num_blocks_is_2_encrypt
13274 _initial_num_blocks_is_3_encrypt:
13275@@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
13276 sub $16, %r11
13277 add %r13, %r11
13278 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
13279- lea SHIFT_MASK+16(%rip), %r12
13280- sub %r13, %r12
13281+ lea SHIFT_MASK+16(%rip), %r15
13282+ sub %r13, %r15
13283 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
13284 # (%r13 is the number of bytes in plaintext mod 16)
13285- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13286+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13287 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
13288 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
13289- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13290+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13291 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
13292 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
13293 movdqa SHUF_MASK(%rip), %xmm10
13294@@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
13295 sub $1, %r13
13296 jne _less_than_8_bytes_left_encrypt
13297 _multiple_of_16_bytes_encrypt:
13298- mov arg8, %r12 # %r12 = addLen (number of bytes)
13299- shl $3, %r12
13300- movd %r12d, %xmm15 # len(A) in %xmm15
13301+ mov arg8, %r15 # %r15 = addLen (number of bytes)
13302+ shl $3, %r15
13303+ movd %r15d, %xmm15 # len(A) in %xmm15
13304 shl $3, %arg4 # len(C) in bits (*128)
13305 MOVQ_R64_XMM %arg4, %xmm1
13306 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13307@@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
13308 mov %r14, %rsp
13309 pop %r14
13310 pop %r13
13311- pop %r12
13312+ pop %r15
13313+ pax_force_retaddr
13314 ret
13315 ENDPROC(aesni_gcm_enc)
13316
13317@@ -1722,6 +1725,7 @@ _key_expansion_256a:
13318 pxor %xmm1, %xmm0
13319 movaps %xmm0, (TKEYP)
13320 add $0x10, TKEYP
13321+ pax_force_retaddr
13322 ret
13323 ENDPROC(_key_expansion_128)
13324 ENDPROC(_key_expansion_256a)
13325@@ -1748,6 +1752,7 @@ _key_expansion_192a:
13326 shufps $0b01001110, %xmm2, %xmm1
13327 movaps %xmm1, 0x10(TKEYP)
13328 add $0x20, TKEYP
13329+ pax_force_retaddr
13330 ret
13331 ENDPROC(_key_expansion_192a)
13332
13333@@ -1768,6 +1773,7 @@ _key_expansion_192b:
13334
13335 movaps %xmm0, (TKEYP)
13336 add $0x10, TKEYP
13337+ pax_force_retaddr
13338 ret
13339 ENDPROC(_key_expansion_192b)
13340
13341@@ -1781,6 +1787,7 @@ _key_expansion_256b:
13342 pxor %xmm1, %xmm2
13343 movaps %xmm2, (TKEYP)
13344 add $0x10, TKEYP
13345+ pax_force_retaddr
13346 ret
13347 ENDPROC(_key_expansion_256b)
13348
13349@@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
13350 #ifndef __x86_64__
13351 popl KEYP
13352 #endif
13353+ pax_force_retaddr
13354 ret
13355 ENDPROC(aesni_set_key)
13356
13357@@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
13358 popl KLEN
13359 popl KEYP
13360 #endif
13361+ pax_force_retaddr
13362 ret
13363 ENDPROC(aesni_enc)
13364
13365@@ -1974,6 +1983,7 @@ _aesni_enc1:
13366 AESENC KEY STATE
13367 movaps 0x70(TKEYP), KEY
13368 AESENCLAST KEY STATE
13369+ pax_force_retaddr
13370 ret
13371 ENDPROC(_aesni_enc1)
13372
13373@@ -2083,6 +2093,7 @@ _aesni_enc4:
13374 AESENCLAST KEY STATE2
13375 AESENCLAST KEY STATE3
13376 AESENCLAST KEY STATE4
13377+ pax_force_retaddr
13378 ret
13379 ENDPROC(_aesni_enc4)
13380
13381@@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
13382 popl KLEN
13383 popl KEYP
13384 #endif
13385+ pax_force_retaddr
13386 ret
13387 ENDPROC(aesni_dec)
13388
13389@@ -2164,6 +2176,7 @@ _aesni_dec1:
13390 AESDEC KEY STATE
13391 movaps 0x70(TKEYP), KEY
13392 AESDECLAST KEY STATE
13393+ pax_force_retaddr
13394 ret
13395 ENDPROC(_aesni_dec1)
13396
13397@@ -2273,6 +2286,7 @@ _aesni_dec4:
13398 AESDECLAST KEY STATE2
13399 AESDECLAST KEY STATE3
13400 AESDECLAST KEY STATE4
13401+ pax_force_retaddr
13402 ret
13403 ENDPROC(_aesni_dec4)
13404
13405@@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
13406 popl KEYP
13407 popl LEN
13408 #endif
13409+ pax_force_retaddr
13410 ret
13411 ENDPROC(aesni_ecb_enc)
13412
13413@@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
13414 popl KEYP
13415 popl LEN
13416 #endif
13417+ pax_force_retaddr
13418 ret
13419 ENDPROC(aesni_ecb_dec)
13420
13421@@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
13422 popl LEN
13423 popl IVP
13424 #endif
13425+ pax_force_retaddr
13426 ret
13427 ENDPROC(aesni_cbc_enc)
13428
13429@@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
13430 popl LEN
13431 popl IVP
13432 #endif
13433+ pax_force_retaddr
13434 ret
13435 ENDPROC(aesni_cbc_dec)
13436
13437@@ -2550,6 +2568,7 @@ _aesni_inc_init:
13438 mov $1, TCTR_LOW
13439 MOVQ_R64_XMM TCTR_LOW INC
13440 MOVQ_R64_XMM CTR TCTR_LOW
13441+ pax_force_retaddr
13442 ret
13443 ENDPROC(_aesni_inc_init)
13444
13445@@ -2579,6 +2598,7 @@ _aesni_inc:
13446 .Linc_low:
13447 movaps CTR, IV
13448 PSHUFB_XMM BSWAP_MASK IV
13449+ pax_force_retaddr
13450 ret
13451 ENDPROC(_aesni_inc)
13452
13453@@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
13454 .Lctr_enc_ret:
13455 movups IV, (IVP)
13456 .Lctr_enc_just_ret:
13457+ pax_force_retaddr
13458 ret
13459 ENDPROC(aesni_ctr_enc)
13460
13461@@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
13462 pxor INC, STATE4
13463 movdqu STATE4, 0x70(OUTP)
13464
13465+ pax_force_retaddr
13466 ret
13467 ENDPROC(aesni_xts_crypt8)
13468
13469diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13470index 246c670..466e2d6 100644
13471--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
13472+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13473@@ -21,6 +21,7 @@
13474 */
13475
13476 #include <linux/linkage.h>
13477+#include <asm/alternative-asm.h>
13478
13479 .file "blowfish-x86_64-asm.S"
13480 .text
13481@@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
13482 jnz .L__enc_xor;
13483
13484 write_block();
13485+ pax_force_retaddr
13486 ret;
13487 .L__enc_xor:
13488 xor_block();
13489+ pax_force_retaddr
13490 ret;
13491 ENDPROC(__blowfish_enc_blk)
13492
13493@@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
13494
13495 movq %r11, %rbp;
13496
13497+ pax_force_retaddr
13498 ret;
13499 ENDPROC(blowfish_dec_blk)
13500
13501@@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
13502
13503 popq %rbx;
13504 popq %rbp;
13505+ pax_force_retaddr
13506 ret;
13507
13508 .L__enc_xor4:
13509@@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
13510
13511 popq %rbx;
13512 popq %rbp;
13513+ pax_force_retaddr
13514 ret;
13515 ENDPROC(__blowfish_enc_blk_4way)
13516
13517@@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
13518 popq %rbx;
13519 popq %rbp;
13520
13521+ pax_force_retaddr
13522 ret;
13523 ENDPROC(blowfish_dec_blk_4way)
13524diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13525index ce71f92..1dce7ec 100644
13526--- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13527+++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13528@@ -16,6 +16,7 @@
13529 */
13530
13531 #include <linux/linkage.h>
13532+#include <asm/alternative-asm.h>
13533
13534 #define CAMELLIA_TABLE_BYTE_LEN 272
13535
13536@@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13537 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
13538 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
13539 %rcx, (%r9));
13540+ pax_force_retaddr
13541 ret;
13542 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13543
13544@@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13545 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
13546 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
13547 %rax, (%r9));
13548+ pax_force_retaddr
13549 ret;
13550 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13551
13552@@ -780,6 +783,7 @@ __camellia_enc_blk16:
13553 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13554 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
13555
13556+ pax_force_retaddr
13557 ret;
13558
13559 .align 8
13560@@ -865,6 +869,7 @@ __camellia_dec_blk16:
13561 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13562 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
13563
13564+ pax_force_retaddr
13565 ret;
13566
13567 .align 8
13568@@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
13569 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13570 %xmm8, %rsi);
13571
13572+ pax_force_retaddr
13573 ret;
13574 ENDPROC(camellia_ecb_enc_16way)
13575
13576@@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
13577 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13578 %xmm8, %rsi);
13579
13580+ pax_force_retaddr
13581 ret;
13582 ENDPROC(camellia_ecb_dec_16way)
13583
13584@@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
13585 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13586 %xmm8, %rsi);
13587
13588+ pax_force_retaddr
13589 ret;
13590 ENDPROC(camellia_cbc_dec_16way)
13591
13592@@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
13593 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13594 %xmm8, %rsi);
13595
13596+ pax_force_retaddr
13597 ret;
13598 ENDPROC(camellia_ctr_16way)
13599
13600@@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
13601 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13602 %xmm8, %rsi);
13603
13604+ pax_force_retaddr
13605 ret;
13606 ENDPROC(camellia_xts_crypt_16way)
13607
13608diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13609index 0e0b886..5a3123c 100644
13610--- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13611+++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13612@@ -11,6 +11,7 @@
13613 */
13614
13615 #include <linux/linkage.h>
13616+#include <asm/alternative-asm.h>
13617
13618 #define CAMELLIA_TABLE_BYTE_LEN 272
13619
13620@@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13621 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
13622 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
13623 %rcx, (%r9));
13624+ pax_force_retaddr
13625 ret;
13626 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13627
13628@@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13629 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
13630 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
13631 %rax, (%r9));
13632+ pax_force_retaddr
13633 ret;
13634 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13635
13636@@ -820,6 +823,7 @@ __camellia_enc_blk32:
13637 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13638 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
13639
13640+ pax_force_retaddr
13641 ret;
13642
13643 .align 8
13644@@ -905,6 +909,7 @@ __camellia_dec_blk32:
13645 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13646 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
13647
13648+ pax_force_retaddr
13649 ret;
13650
13651 .align 8
13652@@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
13653
13654 vzeroupper;
13655
13656+ pax_force_retaddr
13657 ret;
13658 ENDPROC(camellia_ecb_enc_32way)
13659
13660@@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
13661
13662 vzeroupper;
13663
13664+ pax_force_retaddr
13665 ret;
13666 ENDPROC(camellia_ecb_dec_32way)
13667
13668@@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
13669
13670 vzeroupper;
13671
13672+ pax_force_retaddr
13673 ret;
13674 ENDPROC(camellia_cbc_dec_32way)
13675
13676@@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
13677
13678 vzeroupper;
13679
13680+ pax_force_retaddr
13681 ret;
13682 ENDPROC(camellia_ctr_32way)
13683
13684@@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
13685
13686 vzeroupper;
13687
13688+ pax_force_retaddr
13689 ret;
13690 ENDPROC(camellia_xts_crypt_32way)
13691
13692diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
13693index 310319c..db3d7b5 100644
13694--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
13695+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
13696@@ -21,6 +21,7 @@
13697 */
13698
13699 #include <linux/linkage.h>
13700+#include <asm/alternative-asm.h>
13701
13702 .file "camellia-x86_64-asm_64.S"
13703 .text
13704@@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
13705 enc_outunpack(mov, RT1);
13706
13707 movq RRBP, %rbp;
13708+ pax_force_retaddr
13709 ret;
13710
13711 .L__enc_xor:
13712 enc_outunpack(xor, RT1);
13713
13714 movq RRBP, %rbp;
13715+ pax_force_retaddr
13716 ret;
13717 ENDPROC(__camellia_enc_blk)
13718
13719@@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
13720 dec_outunpack();
13721
13722 movq RRBP, %rbp;
13723+ pax_force_retaddr
13724 ret;
13725 ENDPROC(camellia_dec_blk)
13726
13727@@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
13728
13729 movq RRBP, %rbp;
13730 popq %rbx;
13731+ pax_force_retaddr
13732 ret;
13733
13734 .L__enc2_xor:
13735@@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
13736
13737 movq RRBP, %rbp;
13738 popq %rbx;
13739+ pax_force_retaddr
13740 ret;
13741 ENDPROC(__camellia_enc_blk_2way)
13742
13743@@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
13744
13745 movq RRBP, %rbp;
13746 movq RXOR, %rbx;
13747+ pax_force_retaddr
13748 ret;
13749 ENDPROC(camellia_dec_blk_2way)
13750diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13751index c35fd5d..2d8c7db 100644
13752--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13753+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13754@@ -24,6 +24,7 @@
13755 */
13756
13757 #include <linux/linkage.h>
13758+#include <asm/alternative-asm.h>
13759
13760 .file "cast5-avx-x86_64-asm_64.S"
13761
13762@@ -281,6 +282,7 @@ __cast5_enc_blk16:
13763 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13764 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13765
13766+ pax_force_retaddr
13767 ret;
13768 ENDPROC(__cast5_enc_blk16)
13769
13770@@ -352,6 +354,7 @@ __cast5_dec_blk16:
13771 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13772 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13773
13774+ pax_force_retaddr
13775 ret;
13776
13777 .L__skip_dec:
13778@@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
13779 vmovdqu RR4, (6*4*4)(%r11);
13780 vmovdqu RL4, (7*4*4)(%r11);
13781
13782+ pax_force_retaddr
13783 ret;
13784 ENDPROC(cast5_ecb_enc_16way)
13785
13786@@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
13787 vmovdqu RR4, (6*4*4)(%r11);
13788 vmovdqu RL4, (7*4*4)(%r11);
13789
13790+ pax_force_retaddr
13791 ret;
13792 ENDPROC(cast5_ecb_dec_16way)
13793
13794@@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
13795 * %rdx: src
13796 */
13797
13798- pushq %r12;
13799+ pushq %r14;
13800
13801 movq %rsi, %r11;
13802- movq %rdx, %r12;
13803+ movq %rdx, %r14;
13804
13805 vmovdqu (0*16)(%rdx), RL1;
13806 vmovdqu (1*16)(%rdx), RR1;
13807@@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
13808 call __cast5_dec_blk16;
13809
13810 /* xor with src */
13811- vmovq (%r12), RX;
13812+ vmovq (%r14), RX;
13813 vpshufd $0x4f, RX, RX;
13814 vpxor RX, RR1, RR1;
13815- vpxor 0*16+8(%r12), RL1, RL1;
13816- vpxor 1*16+8(%r12), RR2, RR2;
13817- vpxor 2*16+8(%r12), RL2, RL2;
13818- vpxor 3*16+8(%r12), RR3, RR3;
13819- vpxor 4*16+8(%r12), RL3, RL3;
13820- vpxor 5*16+8(%r12), RR4, RR4;
13821- vpxor 6*16+8(%r12), RL4, RL4;
13822+ vpxor 0*16+8(%r14), RL1, RL1;
13823+ vpxor 1*16+8(%r14), RR2, RR2;
13824+ vpxor 2*16+8(%r14), RL2, RL2;
13825+ vpxor 3*16+8(%r14), RR3, RR3;
13826+ vpxor 4*16+8(%r14), RL3, RL3;
13827+ vpxor 5*16+8(%r14), RR4, RR4;
13828+ vpxor 6*16+8(%r14), RL4, RL4;
13829
13830 vmovdqu RR1, (0*16)(%r11);
13831 vmovdqu RL1, (1*16)(%r11);
13832@@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
13833 vmovdqu RR4, (6*16)(%r11);
13834 vmovdqu RL4, (7*16)(%r11);
13835
13836- popq %r12;
13837+ popq %r14;
13838
13839+ pax_force_retaddr
13840 ret;
13841 ENDPROC(cast5_cbc_dec_16way)
13842
13843@@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
13844 * %rcx: iv (big endian, 64bit)
13845 */
13846
13847- pushq %r12;
13848+ pushq %r14;
13849
13850 movq %rsi, %r11;
13851- movq %rdx, %r12;
13852+ movq %rdx, %r14;
13853
13854 vpcmpeqd RTMP, RTMP, RTMP;
13855 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
13856@@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
13857 call __cast5_enc_blk16;
13858
13859 /* dst = src ^ iv */
13860- vpxor (0*16)(%r12), RR1, RR1;
13861- vpxor (1*16)(%r12), RL1, RL1;
13862- vpxor (2*16)(%r12), RR2, RR2;
13863- vpxor (3*16)(%r12), RL2, RL2;
13864- vpxor (4*16)(%r12), RR3, RR3;
13865- vpxor (5*16)(%r12), RL3, RL3;
13866- vpxor (6*16)(%r12), RR4, RR4;
13867- vpxor (7*16)(%r12), RL4, RL4;
13868+ vpxor (0*16)(%r14), RR1, RR1;
13869+ vpxor (1*16)(%r14), RL1, RL1;
13870+ vpxor (2*16)(%r14), RR2, RR2;
13871+ vpxor (3*16)(%r14), RL2, RL2;
13872+ vpxor (4*16)(%r14), RR3, RR3;
13873+ vpxor (5*16)(%r14), RL3, RL3;
13874+ vpxor (6*16)(%r14), RR4, RR4;
13875+ vpxor (7*16)(%r14), RL4, RL4;
13876 vmovdqu RR1, (0*16)(%r11);
13877 vmovdqu RL1, (1*16)(%r11);
13878 vmovdqu RR2, (2*16)(%r11);
13879@@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
13880 vmovdqu RR4, (6*16)(%r11);
13881 vmovdqu RL4, (7*16)(%r11);
13882
13883- popq %r12;
13884+ popq %r14;
13885
13886+ pax_force_retaddr
13887 ret;
13888 ENDPROC(cast5_ctr_16way)
13889diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13890index e3531f8..e123f35 100644
13891--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13892+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13893@@ -24,6 +24,7 @@
13894 */
13895
13896 #include <linux/linkage.h>
13897+#include <asm/alternative-asm.h>
13898 #include "glue_helper-asm-avx.S"
13899
13900 .file "cast6-avx-x86_64-asm_64.S"
13901@@ -295,6 +296,7 @@ __cast6_enc_blk8:
13902 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13903 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13904
13905+ pax_force_retaddr
13906 ret;
13907 ENDPROC(__cast6_enc_blk8)
13908
13909@@ -340,6 +342,7 @@ __cast6_dec_blk8:
13910 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13911 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13912
13913+ pax_force_retaddr
13914 ret;
13915 ENDPROC(__cast6_dec_blk8)
13916
13917@@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
13918
13919 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13920
13921+ pax_force_retaddr
13922 ret;
13923 ENDPROC(cast6_ecb_enc_8way)
13924
13925@@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
13926
13927 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13928
13929+ pax_force_retaddr
13930 ret;
13931 ENDPROC(cast6_ecb_dec_8way)
13932
13933@@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
13934 * %rdx: src
13935 */
13936
13937- pushq %r12;
13938+ pushq %r14;
13939
13940 movq %rsi, %r11;
13941- movq %rdx, %r12;
13942+ movq %rdx, %r14;
13943
13944 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13945
13946 call __cast6_dec_blk8;
13947
13948- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13949+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13950
13951- popq %r12;
13952+ popq %r14;
13953
13954+ pax_force_retaddr
13955 ret;
13956 ENDPROC(cast6_cbc_dec_8way)
13957
13958@@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
13959 * %rcx: iv (little endian, 128bit)
13960 */
13961
13962- pushq %r12;
13963+ pushq %r14;
13964
13965 movq %rsi, %r11;
13966- movq %rdx, %r12;
13967+ movq %rdx, %r14;
13968
13969 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13970 RD2, RX, RKR, RKM);
13971
13972 call __cast6_enc_blk8;
13973
13974- store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13975+ store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13976
13977- popq %r12;
13978+ popq %r14;
13979
13980+ pax_force_retaddr
13981 ret;
13982 ENDPROC(cast6_ctr_8way)
13983
13984@@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
13985 /* dst <= regs xor IVs(in dst) */
13986 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13987
13988+ pax_force_retaddr
13989 ret;
13990 ENDPROC(cast6_xts_enc_8way)
13991
13992@@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
13993 /* dst <= regs xor IVs(in dst) */
13994 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13995
13996+ pax_force_retaddr
13997 ret;
13998 ENDPROC(cast6_xts_dec_8way)
13999diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
14000index dbc4339..de6e120 100644
14001--- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
14002+++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
14003@@ -45,6 +45,7 @@
14004
14005 #include <asm/inst.h>
14006 #include <linux/linkage.h>
14007+#include <asm/alternative-asm.h>
14008
14009 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
14010
14011@@ -312,6 +313,7 @@ do_return:
14012 popq %rsi
14013 popq %rdi
14014 popq %rbx
14015+ pax_force_retaddr
14016 ret
14017
14018 ################################################################
14019diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
14020index 185fad4..ff4cd36 100644
14021--- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
14022+++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
14023@@ -18,6 +18,7 @@
14024
14025 #include <linux/linkage.h>
14026 #include <asm/inst.h>
14027+#include <asm/alternative-asm.h>
14028
14029 .data
14030
14031@@ -89,6 +90,7 @@ __clmul_gf128mul_ble:
14032 psrlq $1, T2
14033 pxor T2, T1
14034 pxor T1, DATA
14035+ pax_force_retaddr
14036 ret
14037 ENDPROC(__clmul_gf128mul_ble)
14038
14039@@ -101,6 +103,7 @@ ENTRY(clmul_ghash_mul)
14040 call __clmul_gf128mul_ble
14041 PSHUFB_XMM BSWAP DATA
14042 movups DATA, (%rdi)
14043+ pax_force_retaddr
14044 ret
14045 ENDPROC(clmul_ghash_mul)
14046
14047@@ -128,5 +131,6 @@ ENTRY(clmul_ghash_update)
14048 PSHUFB_XMM BSWAP DATA
14049 movups DATA, (%rdi)
14050 .Lupdate_just_ret:
14051+ pax_force_retaddr
14052 ret
14053 ENDPROC(clmul_ghash_update)
14054diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14055index 9279e0b..c4b3d2c 100644
14056--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
14057+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14058@@ -1,4 +1,5 @@
14059 #include <linux/linkage.h>
14060+#include <asm/alternative-asm.h>
14061
14062 # enter salsa20_encrypt_bytes
14063 ENTRY(salsa20_encrypt_bytes)
14064@@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
14065 add %r11,%rsp
14066 mov %rdi,%rax
14067 mov %rsi,%rdx
14068+ pax_force_retaddr
14069 ret
14070 # bytesatleast65:
14071 ._bytesatleast65:
14072@@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
14073 add %r11,%rsp
14074 mov %rdi,%rax
14075 mov %rsi,%rdx
14076+ pax_force_retaddr
14077 ret
14078 ENDPROC(salsa20_keysetup)
14079
14080@@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
14081 add %r11,%rsp
14082 mov %rdi,%rax
14083 mov %rsi,%rdx
14084+ pax_force_retaddr
14085 ret
14086 ENDPROC(salsa20_ivsetup)
14087diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14088index 2f202f4..d9164d6 100644
14089--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14090+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14091@@ -24,6 +24,7 @@
14092 */
14093
14094 #include <linux/linkage.h>
14095+#include <asm/alternative-asm.h>
14096 #include "glue_helper-asm-avx.S"
14097
14098 .file "serpent-avx-x86_64-asm_64.S"
14099@@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
14100 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14101 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14102
14103+ pax_force_retaddr
14104 ret;
14105 ENDPROC(__serpent_enc_blk8_avx)
14106
14107@@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
14108 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14109 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14110
14111+ pax_force_retaddr
14112 ret;
14113 ENDPROC(__serpent_dec_blk8_avx)
14114
14115@@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
14116
14117 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14118
14119+ pax_force_retaddr
14120 ret;
14121 ENDPROC(serpent_ecb_enc_8way_avx)
14122
14123@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
14124
14125 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14126
14127+ pax_force_retaddr
14128 ret;
14129 ENDPROC(serpent_ecb_dec_8way_avx)
14130
14131@@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
14132
14133 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14134
14135+ pax_force_retaddr
14136 ret;
14137 ENDPROC(serpent_cbc_dec_8way_avx)
14138
14139@@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
14140
14141 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14142
14143+ pax_force_retaddr
14144 ret;
14145 ENDPROC(serpent_ctr_8way_avx)
14146
14147@@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
14148 /* dst <= regs xor IVs(in dst) */
14149 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14150
14151+ pax_force_retaddr
14152 ret;
14153 ENDPROC(serpent_xts_enc_8way_avx)
14154
14155@@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
14156 /* dst <= regs xor IVs(in dst) */
14157 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14158
14159+ pax_force_retaddr
14160 ret;
14161 ENDPROC(serpent_xts_dec_8way_avx)
14162diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
14163index b222085..abd483c 100644
14164--- a/arch/x86/crypto/serpent-avx2-asm_64.S
14165+++ b/arch/x86/crypto/serpent-avx2-asm_64.S
14166@@ -15,6 +15,7 @@
14167 */
14168
14169 #include <linux/linkage.h>
14170+#include <asm/alternative-asm.h>
14171 #include "glue_helper-asm-avx2.S"
14172
14173 .file "serpent-avx2-asm_64.S"
14174@@ -610,6 +611,7 @@ __serpent_enc_blk16:
14175 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14176 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14177
14178+ pax_force_retaddr
14179 ret;
14180 ENDPROC(__serpent_enc_blk16)
14181
14182@@ -664,6 +666,7 @@ __serpent_dec_blk16:
14183 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14184 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14185
14186+ pax_force_retaddr
14187 ret;
14188 ENDPROC(__serpent_dec_blk16)
14189
14190@@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
14191
14192 vzeroupper;
14193
14194+ pax_force_retaddr
14195 ret;
14196 ENDPROC(serpent_ecb_enc_16way)
14197
14198@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
14199
14200 vzeroupper;
14201
14202+ pax_force_retaddr
14203 ret;
14204 ENDPROC(serpent_ecb_dec_16way)
14205
14206@@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
14207
14208 vzeroupper;
14209
14210+ pax_force_retaddr
14211 ret;
14212 ENDPROC(serpent_cbc_dec_16way)
14213
14214@@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
14215
14216 vzeroupper;
14217
14218+ pax_force_retaddr
14219 ret;
14220 ENDPROC(serpent_ctr_16way)
14221
14222@@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
14223
14224 vzeroupper;
14225
14226+ pax_force_retaddr
14227 ret;
14228 ENDPROC(serpent_xts_enc_16way)
14229
14230@@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
14231
14232 vzeroupper;
14233
14234+ pax_force_retaddr
14235 ret;
14236 ENDPROC(serpent_xts_dec_16way)
14237diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14238index acc066c..1559cc4 100644
14239--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14240+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14241@@ -25,6 +25,7 @@
14242 */
14243
14244 #include <linux/linkage.h>
14245+#include <asm/alternative-asm.h>
14246
14247 .file "serpent-sse2-x86_64-asm_64.S"
14248 .text
14249@@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
14250 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14251 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14252
14253+ pax_force_retaddr
14254 ret;
14255
14256 .L__enc_xor8:
14257 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14258 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14259
14260+ pax_force_retaddr
14261 ret;
14262 ENDPROC(__serpent_enc_blk_8way)
14263
14264@@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
14265 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14266 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14267
14268+ pax_force_retaddr
14269 ret;
14270 ENDPROC(serpent_dec_blk_8way)
14271diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
14272index a410950..9dfe7ad 100644
14273--- a/arch/x86/crypto/sha1_ssse3_asm.S
14274+++ b/arch/x86/crypto/sha1_ssse3_asm.S
14275@@ -29,6 +29,7 @@
14276 */
14277
14278 #include <linux/linkage.h>
14279+#include <asm/alternative-asm.h>
14280
14281 #define CTX %rdi // arg1
14282 #define BUF %rsi // arg2
14283@@ -75,9 +76,9 @@
14284
14285 push %rbx
14286 push %rbp
14287- push %r12
14288+ push %r14
14289
14290- mov %rsp, %r12
14291+ mov %rsp, %r14
14292 sub $64, %rsp # allocate workspace
14293 and $~15, %rsp # align stack
14294
14295@@ -99,11 +100,12 @@
14296 xor %rax, %rax
14297 rep stosq
14298
14299- mov %r12, %rsp # deallocate workspace
14300+ mov %r14, %rsp # deallocate workspace
14301
14302- pop %r12
14303+ pop %r14
14304 pop %rbp
14305 pop %rbx
14306+ pax_force_retaddr
14307 ret
14308
14309 ENDPROC(\name)
14310diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
14311index 642f156..51a513c 100644
14312--- a/arch/x86/crypto/sha256-avx-asm.S
14313+++ b/arch/x86/crypto/sha256-avx-asm.S
14314@@ -49,6 +49,7 @@
14315
14316 #ifdef CONFIG_AS_AVX
14317 #include <linux/linkage.h>
14318+#include <asm/alternative-asm.h>
14319
14320 ## assume buffers not aligned
14321 #define VMOVDQ vmovdqu
14322@@ -460,6 +461,7 @@ done_hash:
14323 popq %r13
14324 popq %rbp
14325 popq %rbx
14326+ pax_force_retaddr
14327 ret
14328 ENDPROC(sha256_transform_avx)
14329
14330diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
14331index 9e86944..3795e6a 100644
14332--- a/arch/x86/crypto/sha256-avx2-asm.S
14333+++ b/arch/x86/crypto/sha256-avx2-asm.S
14334@@ -50,6 +50,7 @@
14335
14336 #ifdef CONFIG_AS_AVX2
14337 #include <linux/linkage.h>
14338+#include <asm/alternative-asm.h>
14339
14340 ## assume buffers not aligned
14341 #define VMOVDQ vmovdqu
14342@@ -720,6 +721,7 @@ done_hash:
14343 popq %r12
14344 popq %rbp
14345 popq %rbx
14346+ pax_force_retaddr
14347 ret
14348 ENDPROC(sha256_transform_rorx)
14349
14350diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
14351index f833b74..8c62a9e 100644
14352--- a/arch/x86/crypto/sha256-ssse3-asm.S
14353+++ b/arch/x86/crypto/sha256-ssse3-asm.S
14354@@ -47,6 +47,7 @@
14355 ########################################################################
14356
14357 #include <linux/linkage.h>
14358+#include <asm/alternative-asm.h>
14359
14360 ## assume buffers not aligned
14361 #define MOVDQ movdqu
14362@@ -471,6 +472,7 @@ done_hash:
14363 popq %rbp
14364 popq %rbx
14365
14366+ pax_force_retaddr
14367 ret
14368 ENDPROC(sha256_transform_ssse3)
14369
14370diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
14371index 974dde9..a823ff9 100644
14372--- a/arch/x86/crypto/sha512-avx-asm.S
14373+++ b/arch/x86/crypto/sha512-avx-asm.S
14374@@ -49,6 +49,7 @@
14375
14376 #ifdef CONFIG_AS_AVX
14377 #include <linux/linkage.h>
14378+#include <asm/alternative-asm.h>
14379
14380 .text
14381
14382@@ -364,6 +365,7 @@ updateblock:
14383 mov frame_RSPSAVE(%rsp), %rsp
14384
14385 nowork:
14386+ pax_force_retaddr
14387 ret
14388 ENDPROC(sha512_transform_avx)
14389
14390diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
14391index 568b961..ed20c37 100644
14392--- a/arch/x86/crypto/sha512-avx2-asm.S
14393+++ b/arch/x86/crypto/sha512-avx2-asm.S
14394@@ -51,6 +51,7 @@
14395
14396 #ifdef CONFIG_AS_AVX2
14397 #include <linux/linkage.h>
14398+#include <asm/alternative-asm.h>
14399
14400 .text
14401
14402@@ -678,6 +679,7 @@ done_hash:
14403
14404 # Restore Stack Pointer
14405 mov frame_RSPSAVE(%rsp), %rsp
14406+ pax_force_retaddr
14407 ret
14408 ENDPROC(sha512_transform_rorx)
14409
14410diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
14411index fb56855..6edd768 100644
14412--- a/arch/x86/crypto/sha512-ssse3-asm.S
14413+++ b/arch/x86/crypto/sha512-ssse3-asm.S
14414@@ -48,6 +48,7 @@
14415 ########################################################################
14416
14417 #include <linux/linkage.h>
14418+#include <asm/alternative-asm.h>
14419
14420 .text
14421
14422@@ -363,6 +364,7 @@ updateblock:
14423 mov frame_RSPSAVE(%rsp), %rsp
14424
14425 nowork:
14426+ pax_force_retaddr
14427 ret
14428 ENDPROC(sha512_transform_ssse3)
14429
14430diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14431index 0505813..b067311 100644
14432--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14433+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14434@@ -24,6 +24,7 @@
14435 */
14436
14437 #include <linux/linkage.h>
14438+#include <asm/alternative-asm.h>
14439 #include "glue_helper-asm-avx.S"
14440
14441 .file "twofish-avx-x86_64-asm_64.S"
14442@@ -284,6 +285,7 @@ __twofish_enc_blk8:
14443 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
14444 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
14445
14446+ pax_force_retaddr
14447 ret;
14448 ENDPROC(__twofish_enc_blk8)
14449
14450@@ -324,6 +326,7 @@ __twofish_dec_blk8:
14451 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
14452 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
14453
14454+ pax_force_retaddr
14455 ret;
14456 ENDPROC(__twofish_dec_blk8)
14457
14458@@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
14459
14460 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14461
14462+ pax_force_retaddr
14463 ret;
14464 ENDPROC(twofish_ecb_enc_8way)
14465
14466@@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
14467
14468 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14469
14470+ pax_force_retaddr
14471 ret;
14472 ENDPROC(twofish_ecb_dec_8way)
14473
14474@@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
14475 * %rdx: src
14476 */
14477
14478- pushq %r12;
14479+ pushq %r14;
14480
14481 movq %rsi, %r11;
14482- movq %rdx, %r12;
14483+ movq %rdx, %r14;
14484
14485 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14486
14487 call __twofish_dec_blk8;
14488
14489- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14490+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14491
14492- popq %r12;
14493+ popq %r14;
14494
14495+ pax_force_retaddr
14496 ret;
14497 ENDPROC(twofish_cbc_dec_8way)
14498
14499@@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
14500 * %rcx: iv (little endian, 128bit)
14501 */
14502
14503- pushq %r12;
14504+ pushq %r14;
14505
14506 movq %rsi, %r11;
14507- movq %rdx, %r12;
14508+ movq %rdx, %r14;
14509
14510 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14511 RD2, RX0, RX1, RY0);
14512
14513 call __twofish_enc_blk8;
14514
14515- store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14516+ store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14517
14518- popq %r12;
14519+ popq %r14;
14520
14521+ pax_force_retaddr
14522 ret;
14523 ENDPROC(twofish_ctr_8way)
14524
14525@@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
14526 /* dst <= regs xor IVs(in dst) */
14527 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14528
14529+ pax_force_retaddr
14530 ret;
14531 ENDPROC(twofish_xts_enc_8way)
14532
14533@@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
14534 /* dst <= regs xor IVs(in dst) */
14535 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14536
14537+ pax_force_retaddr
14538 ret;
14539 ENDPROC(twofish_xts_dec_8way)
14540diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14541index 1c3b7ce..02f578d 100644
14542--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14543+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14544@@ -21,6 +21,7 @@
14545 */
14546
14547 #include <linux/linkage.h>
14548+#include <asm/alternative-asm.h>
14549
14550 .file "twofish-x86_64-asm-3way.S"
14551 .text
14552@@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
14553 popq %r13;
14554 popq %r14;
14555 popq %r15;
14556+ pax_force_retaddr
14557 ret;
14558
14559 .L__enc_xor3:
14560@@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
14561 popq %r13;
14562 popq %r14;
14563 popq %r15;
14564+ pax_force_retaddr
14565 ret;
14566 ENDPROC(__twofish_enc_blk_3way)
14567
14568@@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
14569 popq %r13;
14570 popq %r14;
14571 popq %r15;
14572+ pax_force_retaddr
14573 ret;
14574 ENDPROC(twofish_dec_blk_3way)
14575diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
14576index a039d21..524b8b2 100644
14577--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
14578+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
14579@@ -22,6 +22,7 @@
14580
14581 #include <linux/linkage.h>
14582 #include <asm/asm-offsets.h>
14583+#include <asm/alternative-asm.h>
14584
14585 #define a_offset 0
14586 #define b_offset 4
14587@@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
14588
14589 popq R1
14590 movq $1,%rax
14591+ pax_force_retaddr
14592 ret
14593 ENDPROC(twofish_enc_blk)
14594
14595@@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
14596
14597 popq R1
14598 movq $1,%rax
14599+ pax_force_retaddr
14600 ret
14601 ENDPROC(twofish_dec_blk)
14602diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
14603index d21ff89..6da8e6e 100644
14604--- a/arch/x86/ia32/ia32_aout.c
14605+++ b/arch/x86/ia32/ia32_aout.c
14606@@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
14607 unsigned long dump_start, dump_size;
14608 struct user32 dump;
14609
14610+ memset(&dump, 0, sizeof(dump));
14611+
14612 fs = get_fs();
14613 set_fs(KERNEL_DS);
14614 has_dumped = 1;
14615diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
14616index 2206757..85cbcfa 100644
14617--- a/arch/x86/ia32/ia32_signal.c
14618+++ b/arch/x86/ia32/ia32_signal.c
14619@@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
14620 if (__get_user(set.sig[0], &frame->sc.oldmask)
14621 || (_COMPAT_NSIG_WORDS > 1
14622 && __copy_from_user((((char *) &set.sig) + 4),
14623- &frame->extramask,
14624+ frame->extramask,
14625 sizeof(frame->extramask))))
14626 goto badframe;
14627
14628@@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
14629 sp -= frame_size;
14630 /* Align the stack pointer according to the i386 ABI,
14631 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
14632- sp = ((sp + 4) & -16ul) - 4;
14633+ sp = ((sp - 12) & -16ul) - 4;
14634 return (void __user *) sp;
14635 }
14636
14637@@ -386,7 +386,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14638 restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14639 sigreturn);
14640 else
14641- restorer = &frame->retcode;
14642+ restorer = frame->retcode;
14643 }
14644
14645 put_user_try {
14646@@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14647 * These are actually not used anymore, but left because some
14648 * gdb versions depend on them as a marker.
14649 */
14650- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14651+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14652 } put_user_catch(err);
14653
14654 if (err)
14655@@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14656 0xb8,
14657 __NR_ia32_rt_sigreturn,
14658 0x80cd,
14659- 0,
14660+ 0
14661 };
14662
14663 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
14664@@ -461,16 +461,18 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14665
14666 if (ksig->ka.sa.sa_flags & SA_RESTORER)
14667 restorer = ksig->ka.sa.sa_restorer;
14668+ else if (current->mm->context.vdso)
14669+ /* Return stub is in 32bit vsyscall page */
14670+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
14671 else
14672- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14673- rt_sigreturn);
14674+ restorer = frame->retcode;
14675 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
14676
14677 /*
14678 * Not actually used anymore, but left because some gdb
14679 * versions need it.
14680 */
14681- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14682+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14683 } put_user_catch(err);
14684
14685 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
14686diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
14687index 4299eb0..c0687a7 100644
14688--- a/arch/x86/ia32/ia32entry.S
14689+++ b/arch/x86/ia32/ia32entry.S
14690@@ -15,8 +15,10 @@
14691 #include <asm/irqflags.h>
14692 #include <asm/asm.h>
14693 #include <asm/smap.h>
14694+#include <asm/pgtable.h>
14695 #include <linux/linkage.h>
14696 #include <linux/err.h>
14697+#include <asm/alternative-asm.h>
14698
14699 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14700 #include <linux/elf-em.h>
14701@@ -62,12 +64,12 @@
14702 */
14703 .macro LOAD_ARGS32 offset, _r9=0
14704 .if \_r9
14705- movl \offset+16(%rsp),%r9d
14706+ movl \offset+R9(%rsp),%r9d
14707 .endif
14708- movl \offset+40(%rsp),%ecx
14709- movl \offset+48(%rsp),%edx
14710- movl \offset+56(%rsp),%esi
14711- movl \offset+64(%rsp),%edi
14712+ movl \offset+RCX(%rsp),%ecx
14713+ movl \offset+RDX(%rsp),%edx
14714+ movl \offset+RSI(%rsp),%esi
14715+ movl \offset+RDI(%rsp),%edi
14716 movl %eax,%eax /* zero extension */
14717 .endm
14718
14719@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
14720 ENDPROC(native_irq_enable_sysexit)
14721 #endif
14722
14723+ .macro pax_enter_kernel_user
14724+ pax_set_fptr_mask
14725+#ifdef CONFIG_PAX_MEMORY_UDEREF
14726+ call pax_enter_kernel_user
14727+#endif
14728+ .endm
14729+
14730+ .macro pax_exit_kernel_user
14731+#ifdef CONFIG_PAX_MEMORY_UDEREF
14732+ call pax_exit_kernel_user
14733+#endif
14734+#ifdef CONFIG_PAX_RANDKSTACK
14735+ pushq %rax
14736+ pushq %r11
14737+ call pax_randomize_kstack
14738+ popq %r11
14739+ popq %rax
14740+#endif
14741+ .endm
14742+
14743+ .macro pax_erase_kstack
14744+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14745+ call pax_erase_kstack
14746+#endif
14747+ .endm
14748+
14749 /*
14750 * 32bit SYSENTER instruction entry.
14751 *
14752@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
14753 CFI_REGISTER rsp,rbp
14754 SWAPGS_UNSAFE_STACK
14755 movq PER_CPU_VAR(kernel_stack), %rsp
14756- addq $(KERNEL_STACK_OFFSET),%rsp
14757- /*
14758- * No need to follow this irqs on/off section: the syscall
14759- * disabled irqs, here we enable it straight after entry:
14760- */
14761- ENABLE_INTERRUPTS(CLBR_NONE)
14762 movl %ebp,%ebp /* zero extension */
14763 pushq_cfi $__USER32_DS
14764 /*CFI_REL_OFFSET ss,0*/
14765@@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
14766 CFI_REL_OFFSET rsp,0
14767 pushfq_cfi
14768 /*CFI_REL_OFFSET rflags,0*/
14769- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
14770- CFI_REGISTER rip,r10
14771+ orl $X86_EFLAGS_IF,(%rsp)
14772+ GET_THREAD_INFO(%r11)
14773+ movl TI_sysenter_return(%r11), %r11d
14774+ CFI_REGISTER rip,r11
14775 pushq_cfi $__USER32_CS
14776 /*CFI_REL_OFFSET cs,0*/
14777 movl %eax, %eax
14778- pushq_cfi %r10
14779+ pushq_cfi %r11
14780 CFI_REL_OFFSET rip,0
14781 pushq_cfi %rax
14782 cld
14783 SAVE_ARGS 0,1,0
14784+ pax_enter_kernel_user
14785+
14786+#ifdef CONFIG_PAX_RANDKSTACK
14787+ pax_erase_kstack
14788+#endif
14789+
14790+ /*
14791+ * No need to follow this irqs on/off section: the syscall
14792+ * disabled irqs, here we enable it straight after entry:
14793+ */
14794+ ENABLE_INTERRUPTS(CLBR_NONE)
14795 /* no need to do an access_ok check here because rbp has been
14796 32bit zero extended */
14797+
14798+#ifdef CONFIG_PAX_MEMORY_UDEREF
14799+ addq pax_user_shadow_base,%rbp
14800+ ASM_PAX_OPEN_USERLAND
14801+#endif
14802+
14803 ASM_STAC
14804 1: movl (%rbp),%ebp
14805 _ASM_EXTABLE(1b,ia32_badarg)
14806 ASM_CLAC
14807- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14808- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14809+
14810+#ifdef CONFIG_PAX_MEMORY_UDEREF
14811+ ASM_PAX_CLOSE_USERLAND
14812+#endif
14813+
14814+ GET_THREAD_INFO(%r11)
14815+ orl $TS_COMPAT,TI_status(%r11)
14816+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14817 CFI_REMEMBER_STATE
14818 jnz sysenter_tracesys
14819 cmpq $(IA32_NR_syscalls-1),%rax
14820@@ -162,15 +209,18 @@ sysenter_do_call:
14821 sysenter_dispatch:
14822 call *ia32_sys_call_table(,%rax,8)
14823 movq %rax,RAX-ARGOFFSET(%rsp)
14824+ GET_THREAD_INFO(%r11)
14825 DISABLE_INTERRUPTS(CLBR_NONE)
14826 TRACE_IRQS_OFF
14827- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14828+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14829 jnz sysexit_audit
14830 sysexit_from_sys_call:
14831- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14832+ pax_exit_kernel_user
14833+ pax_erase_kstack
14834+ andl $~TS_COMPAT,TI_status(%r11)
14835 /* clear IF, that popfq doesn't enable interrupts early */
14836- andl $~0x200,EFLAGS-R11(%rsp)
14837- movl RIP-R11(%rsp),%edx /* User %eip */
14838+ andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
14839+ movl RIP(%rsp),%edx /* User %eip */
14840 CFI_REGISTER rip,rdx
14841 RESTORE_ARGS 0,24,0,0,0,0
14842 xorq %r8,%r8
14843@@ -193,6 +243,9 @@ sysexit_from_sys_call:
14844 movl %eax,%esi /* 2nd arg: syscall number */
14845 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
14846 call __audit_syscall_entry
14847+
14848+ pax_erase_kstack
14849+
14850 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
14851 cmpq $(IA32_NR_syscalls-1),%rax
14852 ja ia32_badsys
14853@@ -204,7 +257,7 @@ sysexit_from_sys_call:
14854 .endm
14855
14856 .macro auditsys_exit exit
14857- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14858+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14859 jnz ia32_ret_from_sys_call
14860 TRACE_IRQS_ON
14861 ENABLE_INTERRUPTS(CLBR_NONE)
14862@@ -215,11 +268,12 @@ sysexit_from_sys_call:
14863 1: setbe %al /* 1 if error, 0 if not */
14864 movzbl %al,%edi /* zero-extend that into %edi */
14865 call __audit_syscall_exit
14866+ GET_THREAD_INFO(%r11)
14867 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
14868 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
14869 DISABLE_INTERRUPTS(CLBR_NONE)
14870 TRACE_IRQS_OFF
14871- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14872+ testl %edi,TI_flags(%r11)
14873 jz \exit
14874 CLEAR_RREGS -ARGOFFSET
14875 jmp int_with_check
14876@@ -237,7 +291,7 @@ sysexit_audit:
14877
14878 sysenter_tracesys:
14879 #ifdef CONFIG_AUDITSYSCALL
14880- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14881+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14882 jz sysenter_auditsys
14883 #endif
14884 SAVE_REST
14885@@ -249,6 +303,9 @@ sysenter_tracesys:
14886 RESTORE_REST
14887 cmpq $(IA32_NR_syscalls-1),%rax
14888 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
14889+
14890+ pax_erase_kstack
14891+
14892 jmp sysenter_do_call
14893 CFI_ENDPROC
14894 ENDPROC(ia32_sysenter_target)
14895@@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
14896 ENTRY(ia32_cstar_target)
14897 CFI_STARTPROC32 simple
14898 CFI_SIGNAL_FRAME
14899- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
14900+ CFI_DEF_CFA rsp,0
14901 CFI_REGISTER rip,rcx
14902 /*CFI_REGISTER rflags,r11*/
14903 SWAPGS_UNSAFE_STACK
14904 movl %esp,%r8d
14905 CFI_REGISTER rsp,r8
14906 movq PER_CPU_VAR(kernel_stack),%rsp
14907+ SAVE_ARGS 8*6,0,0
14908+ pax_enter_kernel_user
14909+
14910+#ifdef CONFIG_PAX_RANDKSTACK
14911+ pax_erase_kstack
14912+#endif
14913+
14914 /*
14915 * No need to follow this irqs on/off section: the syscall
14916 * disabled irqs and here we enable it straight after entry:
14917 */
14918 ENABLE_INTERRUPTS(CLBR_NONE)
14919- SAVE_ARGS 8,0,0
14920 movl %eax,%eax /* zero extension */
14921 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14922 movq %rcx,RIP-ARGOFFSET(%rsp)
14923@@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
14924 /* no need to do an access_ok check here because r8 has been
14925 32bit zero extended */
14926 /* hardware stack frame is complete now */
14927+
14928+#ifdef CONFIG_PAX_MEMORY_UDEREF
14929+ ASM_PAX_OPEN_USERLAND
14930+ movq pax_user_shadow_base,%r8
14931+ addq RSP-ARGOFFSET(%rsp),%r8
14932+#endif
14933+
14934 ASM_STAC
14935 1: movl (%r8),%r9d
14936 _ASM_EXTABLE(1b,ia32_badarg)
14937 ASM_CLAC
14938- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14939- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14940+
14941+#ifdef CONFIG_PAX_MEMORY_UDEREF
14942+ ASM_PAX_CLOSE_USERLAND
14943+#endif
14944+
14945+ GET_THREAD_INFO(%r11)
14946+ orl $TS_COMPAT,TI_status(%r11)
14947+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14948 CFI_REMEMBER_STATE
14949 jnz cstar_tracesys
14950 cmpq $IA32_NR_syscalls-1,%rax
14951@@ -319,13 +395,16 @@ cstar_do_call:
14952 cstar_dispatch:
14953 call *ia32_sys_call_table(,%rax,8)
14954 movq %rax,RAX-ARGOFFSET(%rsp)
14955+ GET_THREAD_INFO(%r11)
14956 DISABLE_INTERRUPTS(CLBR_NONE)
14957 TRACE_IRQS_OFF
14958- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14959+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14960 jnz sysretl_audit
14961 sysretl_from_sys_call:
14962- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14963- RESTORE_ARGS 0,-ARG_SKIP,0,0,0
14964+ pax_exit_kernel_user
14965+ pax_erase_kstack
14966+ andl $~TS_COMPAT,TI_status(%r11)
14967+ RESTORE_ARGS 0,-ORIG_RAX,0,0,0
14968 movl RIP-ARGOFFSET(%rsp),%ecx
14969 CFI_REGISTER rip,rcx
14970 movl EFLAGS-ARGOFFSET(%rsp),%r11d
14971@@ -352,7 +431,7 @@ sysretl_audit:
14972
14973 cstar_tracesys:
14974 #ifdef CONFIG_AUDITSYSCALL
14975- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14976+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14977 jz cstar_auditsys
14978 #endif
14979 xchgl %r9d,%ebp
14980@@ -366,11 +445,19 @@ cstar_tracesys:
14981 xchgl %ebp,%r9d
14982 cmpq $(IA32_NR_syscalls-1),%rax
14983 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
14984+
14985+ pax_erase_kstack
14986+
14987 jmp cstar_do_call
14988 END(ia32_cstar_target)
14989
14990 ia32_badarg:
14991 ASM_CLAC
14992+
14993+#ifdef CONFIG_PAX_MEMORY_UDEREF
14994+ ASM_PAX_CLOSE_USERLAND
14995+#endif
14996+
14997 movq $-EFAULT,%rax
14998 jmp ia32_sysret
14999 CFI_ENDPROC
15000@@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
15001 CFI_REL_OFFSET rip,RIP-RIP
15002 PARAVIRT_ADJUST_EXCEPTION_FRAME
15003 SWAPGS
15004- /*
15005- * No need to follow this irqs on/off section: the syscall
15006- * disabled irqs and here we enable it straight after entry:
15007- */
15008- ENABLE_INTERRUPTS(CLBR_NONE)
15009 movl %eax,%eax
15010 pushq_cfi %rax
15011 cld
15012 /* note the registers are not zero extended to the sf.
15013 this could be a problem. */
15014 SAVE_ARGS 0,1,0
15015- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15016- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15017+ pax_enter_kernel_user
15018+
15019+#ifdef CONFIG_PAX_RANDKSTACK
15020+ pax_erase_kstack
15021+#endif
15022+
15023+ /*
15024+ * No need to follow this irqs on/off section: the syscall
15025+ * disabled irqs and here we enable it straight after entry:
15026+ */
15027+ ENABLE_INTERRUPTS(CLBR_NONE)
15028+ GET_THREAD_INFO(%r11)
15029+ orl $TS_COMPAT,TI_status(%r11)
15030+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
15031 jnz ia32_tracesys
15032 cmpq $(IA32_NR_syscalls-1),%rax
15033 ja ia32_badsys
15034@@ -442,6 +536,9 @@ ia32_tracesys:
15035 RESTORE_REST
15036 cmpq $(IA32_NR_syscalls-1),%rax
15037 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
15038+
15039+ pax_erase_kstack
15040+
15041 jmp ia32_do_call
15042 END(ia32_syscall)
15043
15044diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
15045index 8e0ceec..af13504 100644
15046--- a/arch/x86/ia32/sys_ia32.c
15047+++ b/arch/x86/ia32/sys_ia32.c
15048@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
15049 */
15050 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
15051 {
15052- typeof(ubuf->st_uid) uid = 0;
15053- typeof(ubuf->st_gid) gid = 0;
15054+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
15055+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
15056 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
15057 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
15058 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
15059diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
15060index 372231c..51b537d 100644
15061--- a/arch/x86/include/asm/alternative-asm.h
15062+++ b/arch/x86/include/asm/alternative-asm.h
15063@@ -18,6 +18,45 @@
15064 .endm
15065 #endif
15066
15067+#ifdef KERNEXEC_PLUGIN
15068+ .macro pax_force_retaddr_bts rip=0
15069+ btsq $63,\rip(%rsp)
15070+ .endm
15071+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
15072+ .macro pax_force_retaddr rip=0, reload=0
15073+ btsq $63,\rip(%rsp)
15074+ .endm
15075+ .macro pax_force_fptr ptr
15076+ btsq $63,\ptr
15077+ .endm
15078+ .macro pax_set_fptr_mask
15079+ .endm
15080+#endif
15081+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15082+ .macro pax_force_retaddr rip=0, reload=0
15083+ .if \reload
15084+ pax_set_fptr_mask
15085+ .endif
15086+ orq %r12,\rip(%rsp)
15087+ .endm
15088+ .macro pax_force_fptr ptr
15089+ orq %r12,\ptr
15090+ .endm
15091+ .macro pax_set_fptr_mask
15092+ movabs $0x8000000000000000,%r12
15093+ .endm
15094+#endif
15095+#else
15096+ .macro pax_force_retaddr rip=0, reload=0
15097+ .endm
15098+ .macro pax_force_fptr ptr
15099+ .endm
15100+ .macro pax_force_retaddr_bts rip=0
15101+ .endm
15102+ .macro pax_set_fptr_mask
15103+ .endm
15104+#endif
15105+
15106 .macro altinstruction_entry orig alt feature orig_len alt_len
15107 .long \orig - .
15108 .long \alt - .
15109diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
15110index 0a3f9c9..c9d081d 100644
15111--- a/arch/x86/include/asm/alternative.h
15112+++ b/arch/x86/include/asm/alternative.h
15113@@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15114 ".pushsection .discard,\"aw\",@progbits\n" \
15115 DISCARD_ENTRY(1) \
15116 ".popsection\n" \
15117- ".pushsection .altinstr_replacement, \"ax\"\n" \
15118+ ".pushsection .altinstr_replacement, \"a\"\n" \
15119 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
15120 ".popsection"
15121
15122@@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15123 DISCARD_ENTRY(1) \
15124 DISCARD_ENTRY(2) \
15125 ".popsection\n" \
15126- ".pushsection .altinstr_replacement, \"ax\"\n" \
15127+ ".pushsection .altinstr_replacement, \"a\"\n" \
15128 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
15129 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
15130 ".popsection"
15131diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
15132index 1d2091a..f5074c1 100644
15133--- a/arch/x86/include/asm/apic.h
15134+++ b/arch/x86/include/asm/apic.h
15135@@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
15136
15137 #ifdef CONFIG_X86_LOCAL_APIC
15138
15139-extern unsigned int apic_verbosity;
15140+extern int apic_verbosity;
15141 extern int local_apic_timer_c2_ok;
15142
15143 extern int disable_apic;
15144diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
15145index 20370c6..a2eb9b0 100644
15146--- a/arch/x86/include/asm/apm.h
15147+++ b/arch/x86/include/asm/apm.h
15148@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
15149 __asm__ __volatile__(APM_DO_ZERO_SEGS
15150 "pushl %%edi\n\t"
15151 "pushl %%ebp\n\t"
15152- "lcall *%%cs:apm_bios_entry\n\t"
15153+ "lcall *%%ss:apm_bios_entry\n\t"
15154 "setc %%al\n\t"
15155 "popl %%ebp\n\t"
15156 "popl %%edi\n\t"
15157@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
15158 __asm__ __volatile__(APM_DO_ZERO_SEGS
15159 "pushl %%edi\n\t"
15160 "pushl %%ebp\n\t"
15161- "lcall *%%cs:apm_bios_entry\n\t"
15162+ "lcall *%%ss:apm_bios_entry\n\t"
15163 "setc %%bl\n\t"
15164 "popl %%ebp\n\t"
15165 "popl %%edi\n\t"
15166diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
15167index b17f4f4..9620151 100644
15168--- a/arch/x86/include/asm/atomic.h
15169+++ b/arch/x86/include/asm/atomic.h
15170@@ -23,7 +23,18 @@
15171 */
15172 static inline int atomic_read(const atomic_t *v)
15173 {
15174- return (*(volatile int *)&(v)->counter);
15175+ return (*(volatile const int *)&(v)->counter);
15176+}
15177+
15178+/**
15179+ * atomic_read_unchecked - read atomic variable
15180+ * @v: pointer of type atomic_unchecked_t
15181+ *
15182+ * Atomically reads the value of @v.
15183+ */
15184+static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
15185+{
15186+ return (*(volatile const int *)&(v)->counter);
15187 }
15188
15189 /**
15190@@ -39,6 +50,18 @@ static inline void atomic_set(atomic_t *v, int i)
15191 }
15192
15193 /**
15194+ * atomic_set_unchecked - set atomic variable
15195+ * @v: pointer of type atomic_unchecked_t
15196+ * @i: required value
15197+ *
15198+ * Atomically sets the value of @v to @i.
15199+ */
15200+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
15201+{
15202+ v->counter = i;
15203+}
15204+
15205+/**
15206 * atomic_add - add integer to atomic variable
15207 * @i: integer value to add
15208 * @v: pointer of type atomic_t
15209@@ -47,7 +70,29 @@ static inline void atomic_set(atomic_t *v, int i)
15210 */
15211 static inline void atomic_add(int i, atomic_t *v)
15212 {
15213- asm volatile(LOCK_PREFIX "addl %1,%0"
15214+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
15215+
15216+#ifdef CONFIG_PAX_REFCOUNT
15217+ "jno 0f\n"
15218+ LOCK_PREFIX "subl %1,%0\n"
15219+ "int $4\n0:\n"
15220+ _ASM_EXTABLE(0b, 0b)
15221+#endif
15222+
15223+ : "+m" (v->counter)
15224+ : "ir" (i));
15225+}
15226+
15227+/**
15228+ * atomic_add_unchecked - add integer to atomic variable
15229+ * @i: integer value to add
15230+ * @v: pointer of type atomic_unchecked_t
15231+ *
15232+ * Atomically adds @i to @v.
15233+ */
15234+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
15235+{
15236+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
15237 : "+m" (v->counter)
15238 : "ir" (i));
15239 }
15240@@ -61,7 +106,29 @@ static inline void atomic_add(int i, atomic_t *v)
15241 */
15242 static inline void atomic_sub(int i, atomic_t *v)
15243 {
15244- asm volatile(LOCK_PREFIX "subl %1,%0"
15245+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
15246+
15247+#ifdef CONFIG_PAX_REFCOUNT
15248+ "jno 0f\n"
15249+ LOCK_PREFIX "addl %1,%0\n"
15250+ "int $4\n0:\n"
15251+ _ASM_EXTABLE(0b, 0b)
15252+#endif
15253+
15254+ : "+m" (v->counter)
15255+ : "ir" (i));
15256+}
15257+
15258+/**
15259+ * atomic_sub_unchecked - subtract integer from atomic variable
15260+ * @i: integer value to subtract
15261+ * @v: pointer of type atomic_unchecked_t
15262+ *
15263+ * Atomically subtracts @i from @v.
15264+ */
15265+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
15266+{
15267+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
15268 : "+m" (v->counter)
15269 : "ir" (i));
15270 }
15271@@ -77,7 +144,7 @@ static inline void atomic_sub(int i, atomic_t *v)
15272 */
15273 static inline int atomic_sub_and_test(int i, atomic_t *v)
15274 {
15275- GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
15276+ GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
15277 }
15278
15279 /**
15280@@ -88,7 +155,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
15281 */
15282 static inline void atomic_inc(atomic_t *v)
15283 {
15284- asm volatile(LOCK_PREFIX "incl %0"
15285+ asm volatile(LOCK_PREFIX "incl %0\n"
15286+
15287+#ifdef CONFIG_PAX_REFCOUNT
15288+ "jno 0f\n"
15289+ LOCK_PREFIX "decl %0\n"
15290+ "int $4\n0:\n"
15291+ _ASM_EXTABLE(0b, 0b)
15292+#endif
15293+
15294+ : "+m" (v->counter));
15295+}
15296+
15297+/**
15298+ * atomic_inc_unchecked - increment atomic variable
15299+ * @v: pointer of type atomic_unchecked_t
15300+ *
15301+ * Atomically increments @v by 1.
15302+ */
15303+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
15304+{
15305+ asm volatile(LOCK_PREFIX "incl %0\n"
15306 : "+m" (v->counter));
15307 }
15308
15309@@ -100,7 +187,27 @@ static inline void atomic_inc(atomic_t *v)
15310 */
15311 static inline void atomic_dec(atomic_t *v)
15312 {
15313- asm volatile(LOCK_PREFIX "decl %0"
15314+ asm volatile(LOCK_PREFIX "decl %0\n"
15315+
15316+#ifdef CONFIG_PAX_REFCOUNT
15317+ "jno 0f\n"
15318+ LOCK_PREFIX "incl %0\n"
15319+ "int $4\n0:\n"
15320+ _ASM_EXTABLE(0b, 0b)
15321+#endif
15322+
15323+ : "+m" (v->counter));
15324+}
15325+
15326+/**
15327+ * atomic_dec_unchecked - decrement atomic variable
15328+ * @v: pointer of type atomic_unchecked_t
15329+ *
15330+ * Atomically decrements @v by 1.
15331+ */
15332+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
15333+{
15334+ asm volatile(LOCK_PREFIX "decl %0\n"
15335 : "+m" (v->counter));
15336 }
15337
15338@@ -114,7 +221,7 @@ static inline void atomic_dec(atomic_t *v)
15339 */
15340 static inline int atomic_dec_and_test(atomic_t *v)
15341 {
15342- GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
15343+ GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
15344 }
15345
15346 /**
15347@@ -127,7 +234,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
15348 */
15349 static inline int atomic_inc_and_test(atomic_t *v)
15350 {
15351- GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
15352+ GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
15353+}
15354+
15355+/**
15356+ * atomic_inc_and_test_unchecked - increment and test
15357+ * @v: pointer of type atomic_unchecked_t
15358+ *
15359+ * Atomically increments @v by 1
15360+ * and returns true if the result is zero, or false for all
15361+ * other cases.
15362+ */
15363+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
15364+{
15365+ GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
15366 }
15367
15368 /**
15369@@ -141,7 +261,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
15370 */
15371 static inline int atomic_add_negative(int i, atomic_t *v)
15372 {
15373- GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
15374+ GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
15375 }
15376
15377 /**
15378@@ -153,6 +273,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
15379 */
15380 static inline int atomic_add_return(int i, atomic_t *v)
15381 {
15382+ return i + xadd_check_overflow(&v->counter, i);
15383+}
15384+
15385+/**
15386+ * atomic_add_return_unchecked - add integer and return
15387+ * @i: integer value to add
15388+ * @v: pointer of type atomic_unchecked_t
15389+ *
15390+ * Atomically adds @i to @v and returns @i + @v
15391+ */
15392+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
15393+{
15394 return i + xadd(&v->counter, i);
15395 }
15396
15397@@ -169,9 +301,18 @@ static inline int atomic_sub_return(int i, atomic_t *v)
15398 }
15399
15400 #define atomic_inc_return(v) (atomic_add_return(1, v))
15401+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
15402+{
15403+ return atomic_add_return_unchecked(1, v);
15404+}
15405 #define atomic_dec_return(v) (atomic_sub_return(1, v))
15406
15407-static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
15408+static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
15409+{
15410+ return cmpxchg(&v->counter, old, new);
15411+}
15412+
15413+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
15414 {
15415 return cmpxchg(&v->counter, old, new);
15416 }
15417@@ -181,6 +322,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
15418 return xchg(&v->counter, new);
15419 }
15420
15421+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
15422+{
15423+ return xchg(&v->counter, new);
15424+}
15425+
15426 /**
15427 * __atomic_add_unless - add unless the number is already a given value
15428 * @v: pointer of type atomic_t
15429@@ -190,14 +336,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
15430 * Atomically adds @a to @v, so long as @v was not already @u.
15431 * Returns the old value of @v.
15432 */
15433-static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15434+static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
15435 {
15436- int c, old;
15437+ int c, old, new;
15438 c = atomic_read(v);
15439 for (;;) {
15440- if (unlikely(c == (u)))
15441+ if (unlikely(c == u))
15442 break;
15443- old = atomic_cmpxchg((v), c, c + (a));
15444+
15445+ asm volatile("addl %2,%0\n"
15446+
15447+#ifdef CONFIG_PAX_REFCOUNT
15448+ "jno 0f\n"
15449+ "subl %2,%0\n"
15450+ "int $4\n0:\n"
15451+ _ASM_EXTABLE(0b, 0b)
15452+#endif
15453+
15454+ : "=r" (new)
15455+ : "0" (c), "ir" (a));
15456+
15457+ old = atomic_cmpxchg(v, c, new);
15458 if (likely(old == c))
15459 break;
15460 c = old;
15461@@ -206,6 +365,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15462 }
15463
15464 /**
15465+ * atomic_inc_not_zero_hint - increment if not null
15466+ * @v: pointer of type atomic_t
15467+ * @hint: probable value of the atomic before the increment
15468+ *
15469+ * This version of atomic_inc_not_zero() gives a hint of probable
15470+ * value of the atomic. This helps processor to not read the memory
15471+ * before doing the atomic read/modify/write cycle, lowering
15472+ * number of bus transactions on some arches.
15473+ *
15474+ * Returns: 0 if increment was not done, 1 otherwise.
15475+ */
15476+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
15477+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
15478+{
15479+ int val, c = hint, new;
15480+
15481+ /* sanity test, should be removed by compiler if hint is a constant */
15482+ if (!hint)
15483+ return __atomic_add_unless(v, 1, 0);
15484+
15485+ do {
15486+ asm volatile("incl %0\n"
15487+
15488+#ifdef CONFIG_PAX_REFCOUNT
15489+ "jno 0f\n"
15490+ "decl %0\n"
15491+ "int $4\n0:\n"
15492+ _ASM_EXTABLE(0b, 0b)
15493+#endif
15494+
15495+ : "=r" (new)
15496+ : "0" (c));
15497+
15498+ val = atomic_cmpxchg(v, c, new);
15499+ if (val == c)
15500+ return 1;
15501+ c = val;
15502+ } while (c);
15503+
15504+ return 0;
15505+}
15506+
15507+/**
15508 * atomic_inc_short - increment of a short integer
15509 * @v: pointer to type int
15510 *
15511@@ -234,14 +436,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
15512 #endif
15513
15514 /* These are x86-specific, used by some header files */
15515-#define atomic_clear_mask(mask, addr) \
15516- asm volatile(LOCK_PREFIX "andl %0,%1" \
15517- : : "r" (~(mask)), "m" (*(addr)) : "memory")
15518+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
15519+{
15520+ asm volatile(LOCK_PREFIX "andl %1,%0"
15521+ : "+m" (v->counter)
15522+ : "r" (~(mask))
15523+ : "memory");
15524+}
15525
15526-#define atomic_set_mask(mask, addr) \
15527- asm volatile(LOCK_PREFIX "orl %0,%1" \
15528- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
15529- : "memory")
15530+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15531+{
15532+ asm volatile(LOCK_PREFIX "andl %1,%0"
15533+ : "+m" (v->counter)
15534+ : "r" (~(mask))
15535+ : "memory");
15536+}
15537+
15538+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
15539+{
15540+ asm volatile(LOCK_PREFIX "orl %1,%0"
15541+ : "+m" (v->counter)
15542+ : "r" (mask)
15543+ : "memory");
15544+}
15545+
15546+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15547+{
15548+ asm volatile(LOCK_PREFIX "orl %1,%0"
15549+ : "+m" (v->counter)
15550+ : "r" (mask)
15551+ : "memory");
15552+}
15553
15554 /* Atomic operations are already serializing on x86 */
15555 #define smp_mb__before_atomic_dec() barrier()
15556diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
15557index b154de7..bf18a5a 100644
15558--- a/arch/x86/include/asm/atomic64_32.h
15559+++ b/arch/x86/include/asm/atomic64_32.h
15560@@ -12,6 +12,14 @@ typedef struct {
15561 u64 __aligned(8) counter;
15562 } atomic64_t;
15563
15564+#ifdef CONFIG_PAX_REFCOUNT
15565+typedef struct {
15566+ u64 __aligned(8) counter;
15567+} atomic64_unchecked_t;
15568+#else
15569+typedef atomic64_t atomic64_unchecked_t;
15570+#endif
15571+
15572 #define ATOMIC64_INIT(val) { (val) }
15573
15574 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
15575@@ -37,21 +45,31 @@ typedef struct {
15576 ATOMIC64_DECL_ONE(sym##_386)
15577
15578 ATOMIC64_DECL_ONE(add_386);
15579+ATOMIC64_DECL_ONE(add_unchecked_386);
15580 ATOMIC64_DECL_ONE(sub_386);
15581+ATOMIC64_DECL_ONE(sub_unchecked_386);
15582 ATOMIC64_DECL_ONE(inc_386);
15583+ATOMIC64_DECL_ONE(inc_unchecked_386);
15584 ATOMIC64_DECL_ONE(dec_386);
15585+ATOMIC64_DECL_ONE(dec_unchecked_386);
15586 #endif
15587
15588 #define alternative_atomic64(f, out, in...) \
15589 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
15590
15591 ATOMIC64_DECL(read);
15592+ATOMIC64_DECL(read_unchecked);
15593 ATOMIC64_DECL(set);
15594+ATOMIC64_DECL(set_unchecked);
15595 ATOMIC64_DECL(xchg);
15596 ATOMIC64_DECL(add_return);
15597+ATOMIC64_DECL(add_return_unchecked);
15598 ATOMIC64_DECL(sub_return);
15599+ATOMIC64_DECL(sub_return_unchecked);
15600 ATOMIC64_DECL(inc_return);
15601+ATOMIC64_DECL(inc_return_unchecked);
15602 ATOMIC64_DECL(dec_return);
15603+ATOMIC64_DECL(dec_return_unchecked);
15604 ATOMIC64_DECL(dec_if_positive);
15605 ATOMIC64_DECL(inc_not_zero);
15606 ATOMIC64_DECL(add_unless);
15607@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
15608 }
15609
15610 /**
15611+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
15612+ * @p: pointer to type atomic64_unchecked_t
15613+ * @o: expected value
15614+ * @n: new value
15615+ *
15616+ * Atomically sets @v to @n if it was equal to @o and returns
15617+ * the old value.
15618+ */
15619+
15620+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
15621+{
15622+ return cmpxchg64(&v->counter, o, n);
15623+}
15624+
15625+/**
15626 * atomic64_xchg - xchg atomic64 variable
15627 * @v: pointer to type atomic64_t
15628 * @n: value to assign
15629@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
15630 }
15631
15632 /**
15633+ * atomic64_set_unchecked - set atomic64 variable
15634+ * @v: pointer to type atomic64_unchecked_t
15635+ * @n: value to assign
15636+ *
15637+ * Atomically sets the value of @v to @n.
15638+ */
15639+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
15640+{
15641+ unsigned high = (unsigned)(i >> 32);
15642+ unsigned low = (unsigned)i;
15643+ alternative_atomic64(set, /* no output */,
15644+ "S" (v), "b" (low), "c" (high)
15645+ : "eax", "edx", "memory");
15646+}
15647+
15648+/**
15649 * atomic64_read - read atomic64 variable
15650 * @v: pointer to type atomic64_t
15651 *
15652@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
15653 }
15654
15655 /**
15656+ * atomic64_read_unchecked - read atomic64 variable
15657+ * @v: pointer to type atomic64_unchecked_t
15658+ *
15659+ * Atomically reads the value of @v and returns it.
15660+ */
15661+static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
15662+{
15663+ long long r;
15664+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
15665+ return r;
15666+ }
15667+
15668+/**
15669 * atomic64_add_return - add and return
15670 * @i: integer value to add
15671 * @v: pointer to type atomic64_t
15672@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
15673 return i;
15674 }
15675
15676+/**
15677+ * atomic64_add_return_unchecked - add and return
15678+ * @i: integer value to add
15679+ * @v: pointer to type atomic64_unchecked_t
15680+ *
15681+ * Atomically adds @i to @v and returns @i + *@v
15682+ */
15683+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
15684+{
15685+ alternative_atomic64(add_return_unchecked,
15686+ ASM_OUTPUT2("+A" (i), "+c" (v)),
15687+ ASM_NO_INPUT_CLOBBER("memory"));
15688+ return i;
15689+}
15690+
15691 /*
15692 * Other variants with different arithmetic operators:
15693 */
15694@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
15695 return a;
15696 }
15697
15698+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15699+{
15700+ long long a;
15701+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
15702+ "S" (v) : "memory", "ecx");
15703+ return a;
15704+}
15705+
15706 static inline long long atomic64_dec_return(atomic64_t *v)
15707 {
15708 long long a;
15709@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
15710 }
15711
15712 /**
15713+ * atomic64_add_unchecked - add integer to atomic64 variable
15714+ * @i: integer value to add
15715+ * @v: pointer to type atomic64_unchecked_t
15716+ *
15717+ * Atomically adds @i to @v.
15718+ */
15719+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
15720+{
15721+ __alternative_atomic64(add_unchecked, add_return_unchecked,
15722+ ASM_OUTPUT2("+A" (i), "+c" (v)),
15723+ ASM_NO_INPUT_CLOBBER("memory"));
15724+ return i;
15725+}
15726+
15727+/**
15728 * atomic64_sub - subtract the atomic64 variable
15729 * @i: integer value to subtract
15730 * @v: pointer to type atomic64_t
15731diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
15732index 46e9052..ae45136 100644
15733--- a/arch/x86/include/asm/atomic64_64.h
15734+++ b/arch/x86/include/asm/atomic64_64.h
15735@@ -18,7 +18,19 @@
15736 */
15737 static inline long atomic64_read(const atomic64_t *v)
15738 {
15739- return (*(volatile long *)&(v)->counter);
15740+ return (*(volatile const long *)&(v)->counter);
15741+}
15742+
15743+/**
15744+ * atomic64_read_unchecked - read atomic64 variable
15745+ * @v: pointer of type atomic64_unchecked_t
15746+ *
15747+ * Atomically reads the value of @v.
15748+ * Doesn't imply a read memory barrier.
15749+ */
15750+static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
15751+{
15752+ return (*(volatile const long *)&(v)->counter);
15753 }
15754
15755 /**
15756@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
15757 }
15758
15759 /**
15760+ * atomic64_set_unchecked - set atomic64 variable
15761+ * @v: pointer to type atomic64_unchecked_t
15762+ * @i: required value
15763+ *
15764+ * Atomically sets the value of @v to @i.
15765+ */
15766+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
15767+{
15768+ v->counter = i;
15769+}
15770+
15771+/**
15772 * atomic64_add - add integer to atomic64 variable
15773 * @i: integer value to add
15774 * @v: pointer to type atomic64_t
15775@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
15776 */
15777 static inline void atomic64_add(long i, atomic64_t *v)
15778 {
15779+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
15780+
15781+#ifdef CONFIG_PAX_REFCOUNT
15782+ "jno 0f\n"
15783+ LOCK_PREFIX "subq %1,%0\n"
15784+ "int $4\n0:\n"
15785+ _ASM_EXTABLE(0b, 0b)
15786+#endif
15787+
15788+ : "=m" (v->counter)
15789+ : "er" (i), "m" (v->counter));
15790+}
15791+
15792+/**
15793+ * atomic64_add_unchecked - add integer to atomic64 variable
15794+ * @i: integer value to add
15795+ * @v: pointer to type atomic64_unchecked_t
15796+ *
15797+ * Atomically adds @i to @v.
15798+ */
15799+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
15800+{
15801 asm volatile(LOCK_PREFIX "addq %1,%0"
15802 : "=m" (v->counter)
15803 : "er" (i), "m" (v->counter));
15804@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
15805 */
15806 static inline void atomic64_sub(long i, atomic64_t *v)
15807 {
15808- asm volatile(LOCK_PREFIX "subq %1,%0"
15809+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
15810+
15811+#ifdef CONFIG_PAX_REFCOUNT
15812+ "jno 0f\n"
15813+ LOCK_PREFIX "addq %1,%0\n"
15814+ "int $4\n0:\n"
15815+ _ASM_EXTABLE(0b, 0b)
15816+#endif
15817+
15818+ : "=m" (v->counter)
15819+ : "er" (i), "m" (v->counter));
15820+}
15821+
15822+/**
15823+ * atomic64_sub_unchecked - subtract the atomic64 variable
15824+ * @i: integer value to subtract
15825+ * @v: pointer to type atomic64_unchecked_t
15826+ *
15827+ * Atomically subtracts @i from @v.
15828+ */
15829+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
15830+{
15831+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
15832 : "=m" (v->counter)
15833 : "er" (i), "m" (v->counter));
15834 }
15835@@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
15836 */
15837 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15838 {
15839- GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
15840+ GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
15841 }
15842
15843 /**
15844@@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15845 */
15846 static inline void atomic64_inc(atomic64_t *v)
15847 {
15848+ asm volatile(LOCK_PREFIX "incq %0\n"
15849+
15850+#ifdef CONFIG_PAX_REFCOUNT
15851+ "jno 0f\n"
15852+ LOCK_PREFIX "decq %0\n"
15853+ "int $4\n0:\n"
15854+ _ASM_EXTABLE(0b, 0b)
15855+#endif
15856+
15857+ : "=m" (v->counter)
15858+ : "m" (v->counter));
15859+}
15860+
15861+/**
15862+ * atomic64_inc_unchecked - increment atomic64 variable
15863+ * @v: pointer to type atomic64_unchecked_t
15864+ *
15865+ * Atomically increments @v by 1.
15866+ */
15867+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
15868+{
15869 asm volatile(LOCK_PREFIX "incq %0"
15870 : "=m" (v->counter)
15871 : "m" (v->counter));
15872@@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
15873 */
15874 static inline void atomic64_dec(atomic64_t *v)
15875 {
15876- asm volatile(LOCK_PREFIX "decq %0"
15877+ asm volatile(LOCK_PREFIX "decq %0\n"
15878+
15879+#ifdef CONFIG_PAX_REFCOUNT
15880+ "jno 0f\n"
15881+ LOCK_PREFIX "incq %0\n"
15882+ "int $4\n0:\n"
15883+ _ASM_EXTABLE(0b, 0b)
15884+#endif
15885+
15886+ : "=m" (v->counter)
15887+ : "m" (v->counter));
15888+}
15889+
15890+/**
15891+ * atomic64_dec_unchecked - decrement atomic64 variable
15892+ * @v: pointer to type atomic64_t
15893+ *
15894+ * Atomically decrements @v by 1.
15895+ */
15896+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
15897+{
15898+ asm volatile(LOCK_PREFIX "decq %0\n"
15899 : "=m" (v->counter)
15900 : "m" (v->counter));
15901 }
15902@@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
15903 */
15904 static inline int atomic64_dec_and_test(atomic64_t *v)
15905 {
15906- GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
15907+ GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
15908 }
15909
15910 /**
15911@@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
15912 */
15913 static inline int atomic64_inc_and_test(atomic64_t *v)
15914 {
15915- GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
15916+ GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
15917 }
15918
15919 /**
15920@@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
15921 */
15922 static inline int atomic64_add_negative(long i, atomic64_t *v)
15923 {
15924- GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
15925+ GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
15926 }
15927
15928 /**
15929@@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
15930 */
15931 static inline long atomic64_add_return(long i, atomic64_t *v)
15932 {
15933+ return i + xadd_check_overflow(&v->counter, i);
15934+}
15935+
15936+/**
15937+ * atomic64_add_return_unchecked - add and return
15938+ * @i: integer value to add
15939+ * @v: pointer to type atomic64_unchecked_t
15940+ *
15941+ * Atomically adds @i to @v and returns @i + @v
15942+ */
15943+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
15944+{
15945 return i + xadd(&v->counter, i);
15946 }
15947
15948@@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
15949 }
15950
15951 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
15952+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15953+{
15954+ return atomic64_add_return_unchecked(1, v);
15955+}
15956 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
15957
15958 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15959@@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15960 return cmpxchg(&v->counter, old, new);
15961 }
15962
15963+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
15964+{
15965+ return cmpxchg(&v->counter, old, new);
15966+}
15967+
15968 static inline long atomic64_xchg(atomic64_t *v, long new)
15969 {
15970 return xchg(&v->counter, new);
15971@@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
15972 */
15973 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
15974 {
15975- long c, old;
15976+ long c, old, new;
15977 c = atomic64_read(v);
15978 for (;;) {
15979- if (unlikely(c == (u)))
15980+ if (unlikely(c == u))
15981 break;
15982- old = atomic64_cmpxchg((v), c, c + (a));
15983+
15984+ asm volatile("add %2,%0\n"
15985+
15986+#ifdef CONFIG_PAX_REFCOUNT
15987+ "jno 0f\n"
15988+ "sub %2,%0\n"
15989+ "int $4\n0:\n"
15990+ _ASM_EXTABLE(0b, 0b)
15991+#endif
15992+
15993+ : "=r" (new)
15994+ : "0" (c), "ir" (a));
15995+
15996+ old = atomic64_cmpxchg(v, c, new);
15997 if (likely(old == c))
15998 break;
15999 c = old;
16000 }
16001- return c != (u);
16002+ return c != u;
16003 }
16004
16005 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
16006diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
16007index 9fc1af7..fc71228 100644
16008--- a/arch/x86/include/asm/bitops.h
16009+++ b/arch/x86/include/asm/bitops.h
16010@@ -49,7 +49,7 @@
16011 * a mask operation on a byte.
16012 */
16013 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
16014-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
16015+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
16016 #define CONST_MASK(nr) (1 << ((nr) & 7))
16017
16018 /**
16019@@ -205,7 +205,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
16020 */
16021 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
16022 {
16023- GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16024+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16025 }
16026
16027 /**
16028@@ -251,7 +251,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
16029 */
16030 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
16031 {
16032- GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16033+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16034 }
16035
16036 /**
16037@@ -304,7 +304,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
16038 */
16039 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
16040 {
16041- GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16042+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16043 }
16044
16045 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
16046@@ -345,7 +345,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
16047 *
16048 * Undefined if no bit exists, so code should check against 0 first.
16049 */
16050-static inline unsigned long __ffs(unsigned long word)
16051+static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
16052 {
16053 asm("rep; bsf %1,%0"
16054 : "=r" (word)
16055@@ -359,7 +359,7 @@ static inline unsigned long __ffs(unsigned long word)
16056 *
16057 * Undefined if no zero exists, so code should check against ~0UL first.
16058 */
16059-static inline unsigned long ffz(unsigned long word)
16060+static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
16061 {
16062 asm("rep; bsf %1,%0"
16063 : "=r" (word)
16064@@ -373,7 +373,7 @@ static inline unsigned long ffz(unsigned long word)
16065 *
16066 * Undefined if no set bit exists, so code should check against 0 first.
16067 */
16068-static inline unsigned long __fls(unsigned long word)
16069+static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
16070 {
16071 asm("bsr %1,%0"
16072 : "=r" (word)
16073@@ -436,7 +436,7 @@ static inline int ffs(int x)
16074 * set bit if value is nonzero. The last (most significant) bit is
16075 * at position 32.
16076 */
16077-static inline int fls(int x)
16078+static inline int __intentional_overflow(-1) fls(int x)
16079 {
16080 int r;
16081
16082@@ -478,7 +478,7 @@ static inline int fls(int x)
16083 * at position 64.
16084 */
16085 #ifdef CONFIG_X86_64
16086-static __always_inline int fls64(__u64 x)
16087+static __always_inline long fls64(__u64 x)
16088 {
16089 int bitpos = -1;
16090 /*
16091diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
16092index 4fa687a..60f2d39 100644
16093--- a/arch/x86/include/asm/boot.h
16094+++ b/arch/x86/include/asm/boot.h
16095@@ -6,10 +6,15 @@
16096 #include <uapi/asm/boot.h>
16097
16098 /* Physical address where kernel should be loaded. */
16099-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16100+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16101 + (CONFIG_PHYSICAL_ALIGN - 1)) \
16102 & ~(CONFIG_PHYSICAL_ALIGN - 1))
16103
16104+#ifndef __ASSEMBLY__
16105+extern unsigned char __LOAD_PHYSICAL_ADDR[];
16106+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
16107+#endif
16108+
16109 /* Minimum kernel alignment, as a power of two */
16110 #ifdef CONFIG_X86_64
16111 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
16112diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
16113index 48f99f1..d78ebf9 100644
16114--- a/arch/x86/include/asm/cache.h
16115+++ b/arch/x86/include/asm/cache.h
16116@@ -5,12 +5,13 @@
16117
16118 /* L1 cache line size */
16119 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
16120-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
16121+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
16122
16123 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
16124+#define __read_only __attribute__((__section__(".data..read_only")))
16125
16126 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
16127-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
16128+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
16129
16130 #ifdef CONFIG_X86_VSMP
16131 #ifdef CONFIG_SMP
16132diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
16133index 9863ee3..4a1f8e1 100644
16134--- a/arch/x86/include/asm/cacheflush.h
16135+++ b/arch/x86/include/asm/cacheflush.h
16136@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
16137 unsigned long pg_flags = pg->flags & _PGMT_MASK;
16138
16139 if (pg_flags == _PGMT_DEFAULT)
16140- return -1;
16141+ return ~0UL;
16142 else if (pg_flags == _PGMT_WC)
16143 return _PAGE_CACHE_WC;
16144 else if (pg_flags == _PGMT_UC_MINUS)
16145diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
16146index cb4c73b..c473c29 100644
16147--- a/arch/x86/include/asm/calling.h
16148+++ b/arch/x86/include/asm/calling.h
16149@@ -82,103 +82,113 @@ For 32-bit we have the following conventions - kernel is built with
16150 #define RSP 152
16151 #define SS 160
16152
16153-#define ARGOFFSET R11
16154-#define SWFRAME ORIG_RAX
16155+#define ARGOFFSET R15
16156
16157 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
16158- subq $9*8+\addskip, %rsp
16159- CFI_ADJUST_CFA_OFFSET 9*8+\addskip
16160- movq_cfi rdi, 8*8
16161- movq_cfi rsi, 7*8
16162- movq_cfi rdx, 6*8
16163+ subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
16164+ CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
16165+ movq_cfi rdi, RDI
16166+ movq_cfi rsi, RSI
16167+ movq_cfi rdx, RDX
16168
16169 .if \save_rcx
16170- movq_cfi rcx, 5*8
16171+ movq_cfi rcx, RCX
16172 .endif
16173
16174- movq_cfi rax, 4*8
16175+ movq_cfi rax, RAX
16176
16177 .if \save_r891011
16178- movq_cfi r8, 3*8
16179- movq_cfi r9, 2*8
16180- movq_cfi r10, 1*8
16181- movq_cfi r11, 0*8
16182+ movq_cfi r8, R8
16183+ movq_cfi r9, R9
16184+ movq_cfi r10, R10
16185+ movq_cfi r11, R11
16186 .endif
16187
16188+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16189+ movq_cfi r12, R12
16190+#endif
16191+
16192 .endm
16193
16194-#define ARG_SKIP (9*8)
16195+#define ARG_SKIP ORIG_RAX
16196
16197 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
16198 rstor_r8910=1, rstor_rdx=1
16199+
16200+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16201+ movq_cfi_restore R12, r12
16202+#endif
16203+
16204 .if \rstor_r11
16205- movq_cfi_restore 0*8, r11
16206+ movq_cfi_restore R11, r11
16207 .endif
16208
16209 .if \rstor_r8910
16210- movq_cfi_restore 1*8, r10
16211- movq_cfi_restore 2*8, r9
16212- movq_cfi_restore 3*8, r8
16213+ movq_cfi_restore R10, r10
16214+ movq_cfi_restore R9, r9
16215+ movq_cfi_restore R8, r8
16216 .endif
16217
16218 .if \rstor_rax
16219- movq_cfi_restore 4*8, rax
16220+ movq_cfi_restore RAX, rax
16221 .endif
16222
16223 .if \rstor_rcx
16224- movq_cfi_restore 5*8, rcx
16225+ movq_cfi_restore RCX, rcx
16226 .endif
16227
16228 .if \rstor_rdx
16229- movq_cfi_restore 6*8, rdx
16230+ movq_cfi_restore RDX, rdx
16231 .endif
16232
16233- movq_cfi_restore 7*8, rsi
16234- movq_cfi_restore 8*8, rdi
16235+ movq_cfi_restore RSI, rsi
16236+ movq_cfi_restore RDI, rdi
16237
16238- .if ARG_SKIP+\addskip > 0
16239- addq $ARG_SKIP+\addskip, %rsp
16240- CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
16241+ .if ORIG_RAX+\addskip > 0
16242+ addq $ORIG_RAX+\addskip, %rsp
16243+ CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
16244 .endif
16245 .endm
16246
16247- .macro LOAD_ARGS offset, skiprax=0
16248- movq \offset(%rsp), %r11
16249- movq \offset+8(%rsp), %r10
16250- movq \offset+16(%rsp), %r9
16251- movq \offset+24(%rsp), %r8
16252- movq \offset+40(%rsp), %rcx
16253- movq \offset+48(%rsp), %rdx
16254- movq \offset+56(%rsp), %rsi
16255- movq \offset+64(%rsp), %rdi
16256+ .macro LOAD_ARGS skiprax=0
16257+ movq R11(%rsp), %r11
16258+ movq R10(%rsp), %r10
16259+ movq R9(%rsp), %r9
16260+ movq R8(%rsp), %r8
16261+ movq RCX(%rsp), %rcx
16262+ movq RDX(%rsp), %rdx
16263+ movq RSI(%rsp), %rsi
16264+ movq RDI(%rsp), %rdi
16265 .if \skiprax
16266 .else
16267- movq \offset+72(%rsp), %rax
16268+ movq RAX(%rsp), %rax
16269 .endif
16270 .endm
16271
16272-#define REST_SKIP (6*8)
16273-
16274 .macro SAVE_REST
16275- subq $REST_SKIP, %rsp
16276- CFI_ADJUST_CFA_OFFSET REST_SKIP
16277- movq_cfi rbx, 5*8
16278- movq_cfi rbp, 4*8
16279- movq_cfi r12, 3*8
16280- movq_cfi r13, 2*8
16281- movq_cfi r14, 1*8
16282- movq_cfi r15, 0*8
16283+ movq_cfi rbx, RBX
16284+ movq_cfi rbp, RBP
16285+
16286+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16287+ movq_cfi r12, R12
16288+#endif
16289+
16290+ movq_cfi r13, R13
16291+ movq_cfi r14, R14
16292+ movq_cfi r15, R15
16293 .endm
16294
16295 .macro RESTORE_REST
16296- movq_cfi_restore 0*8, r15
16297- movq_cfi_restore 1*8, r14
16298- movq_cfi_restore 2*8, r13
16299- movq_cfi_restore 3*8, r12
16300- movq_cfi_restore 4*8, rbp
16301- movq_cfi_restore 5*8, rbx
16302- addq $REST_SKIP, %rsp
16303- CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
16304+ movq_cfi_restore R15, r15
16305+ movq_cfi_restore R14, r14
16306+ movq_cfi_restore R13, r13
16307+
16308+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16309+ movq_cfi_restore R12, r12
16310+#endif
16311+
16312+ movq_cfi_restore RBP, rbp
16313+ movq_cfi_restore RBX, rbx
16314 .endm
16315
16316 .macro SAVE_ALL
16317diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
16318index f50de69..2b0a458 100644
16319--- a/arch/x86/include/asm/checksum_32.h
16320+++ b/arch/x86/include/asm/checksum_32.h
16321@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
16322 int len, __wsum sum,
16323 int *src_err_ptr, int *dst_err_ptr);
16324
16325+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
16326+ int len, __wsum sum,
16327+ int *src_err_ptr, int *dst_err_ptr);
16328+
16329+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
16330+ int len, __wsum sum,
16331+ int *src_err_ptr, int *dst_err_ptr);
16332+
16333 /*
16334 * Note: when you get a NULL pointer exception here this means someone
16335 * passed in an incorrect kernel address to one of these functions.
16336@@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
16337
16338 might_sleep();
16339 stac();
16340- ret = csum_partial_copy_generic((__force void *)src, dst,
16341+ ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
16342 len, sum, err_ptr, NULL);
16343 clac();
16344
16345@@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
16346 might_sleep();
16347 if (access_ok(VERIFY_WRITE, dst, len)) {
16348 stac();
16349- ret = csum_partial_copy_generic(src, (__force void *)dst,
16350+ ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
16351 len, sum, NULL, err_ptr);
16352 clac();
16353 return ret;
16354diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
16355index d47786a..2d8883e 100644
16356--- a/arch/x86/include/asm/cmpxchg.h
16357+++ b/arch/x86/include/asm/cmpxchg.h
16358@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
16359 __compiletime_error("Bad argument size for cmpxchg");
16360 extern void __xadd_wrong_size(void)
16361 __compiletime_error("Bad argument size for xadd");
16362+extern void __xadd_check_overflow_wrong_size(void)
16363+ __compiletime_error("Bad argument size for xadd_check_overflow");
16364 extern void __add_wrong_size(void)
16365 __compiletime_error("Bad argument size for add");
16366+extern void __add_check_overflow_wrong_size(void)
16367+ __compiletime_error("Bad argument size for add_check_overflow");
16368
16369 /*
16370 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
16371@@ -67,6 +71,38 @@ extern void __add_wrong_size(void)
16372 __ret; \
16373 })
16374
16375+#ifdef CONFIG_PAX_REFCOUNT
16376+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
16377+ ({ \
16378+ __typeof__ (*(ptr)) __ret = (arg); \
16379+ switch (sizeof(*(ptr))) { \
16380+ case __X86_CASE_L: \
16381+ asm volatile (lock #op "l %0, %1\n" \
16382+ "jno 0f\n" \
16383+ "mov %0,%1\n" \
16384+ "int $4\n0:\n" \
16385+ _ASM_EXTABLE(0b, 0b) \
16386+ : "+r" (__ret), "+m" (*(ptr)) \
16387+ : : "memory", "cc"); \
16388+ break; \
16389+ case __X86_CASE_Q: \
16390+ asm volatile (lock #op "q %q0, %1\n" \
16391+ "jno 0f\n" \
16392+ "mov %0,%1\n" \
16393+ "int $4\n0:\n" \
16394+ _ASM_EXTABLE(0b, 0b) \
16395+ : "+r" (__ret), "+m" (*(ptr)) \
16396+ : : "memory", "cc"); \
16397+ break; \
16398+ default: \
16399+ __ ## op ## _check_overflow_wrong_size(); \
16400+ } \
16401+ __ret; \
16402+ })
16403+#else
16404+#define __xchg_op_check_overflow(ptr, arg, op, lock) __xchg_op(ptr, arg, op, lock)
16405+#endif
16406+
16407 /*
16408 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
16409 * Since this is generally used to protect other memory information, we
16410@@ -167,6 +203,9 @@ extern void __add_wrong_size(void)
16411 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
16412 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
16413
16414+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
16415+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
16416+
16417 #define __add(ptr, inc, lock) \
16418 ({ \
16419 __typeof__ (*(ptr)) __ret = (inc); \
16420diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
16421index 59c6c40..5e0b22c 100644
16422--- a/arch/x86/include/asm/compat.h
16423+++ b/arch/x86/include/asm/compat.h
16424@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
16425 typedef u32 compat_uint_t;
16426 typedef u32 compat_ulong_t;
16427 typedef u64 __attribute__((aligned(4))) compat_u64;
16428-typedef u32 compat_uptr_t;
16429+typedef u32 __user compat_uptr_t;
16430
16431 struct compat_timespec {
16432 compat_time_t tv_sec;
16433diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
16434index 5f12968..a383517 100644
16435--- a/arch/x86/include/asm/cpufeature.h
16436+++ b/arch/x86/include/asm/cpufeature.h
16437@@ -203,7 +203,7 @@
16438 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
16439 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
16440 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
16441-
16442+#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
16443
16444 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
16445 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
16446@@ -211,7 +211,7 @@
16447 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
16448 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
16449 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
16450-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
16451+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
16452 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
16453 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
16454 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
16455@@ -358,6 +358,7 @@ extern const char * const x86_power_flags[32];
16456 #undef cpu_has_centaur_mcr
16457 #define cpu_has_centaur_mcr 0
16458
16459+#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
16460 #endif /* CONFIG_X86_64 */
16461
16462 #if __GNUC__ >= 4
16463@@ -410,7 +411,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16464
16465 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
16466 t_warn:
16467- warn_pre_alternatives();
16468+ if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
16469+ warn_pre_alternatives();
16470 return false;
16471 #endif
16472
16473@@ -430,7 +432,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16474 ".section .discard,\"aw\",@progbits\n"
16475 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16476 ".previous\n"
16477- ".section .altinstr_replacement,\"ax\"\n"
16478+ ".section .altinstr_replacement,\"a\"\n"
16479 "3: movb $1,%0\n"
16480 "4:\n"
16481 ".previous\n"
16482@@ -467,7 +469,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16483 " .byte 2b - 1b\n" /* src len */
16484 " .byte 4f - 3f\n" /* repl len */
16485 ".previous\n"
16486- ".section .altinstr_replacement,\"ax\"\n"
16487+ ".section .altinstr_replacement,\"a\"\n"
16488 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
16489 "4:\n"
16490 ".previous\n"
16491@@ -500,7 +502,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16492 ".section .discard,\"aw\",@progbits\n"
16493 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16494 ".previous\n"
16495- ".section .altinstr_replacement,\"ax\"\n"
16496+ ".section .altinstr_replacement,\"a\"\n"
16497 "3: movb $0,%0\n"
16498 "4:\n"
16499 ".previous\n"
16500@@ -514,7 +516,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16501 ".section .discard,\"aw\",@progbits\n"
16502 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
16503 ".previous\n"
16504- ".section .altinstr_replacement,\"ax\"\n"
16505+ ".section .altinstr_replacement,\"a\"\n"
16506 "5: movb $1,%0\n"
16507 "6:\n"
16508 ".previous\n"
16509diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
16510index 50d033a..37deb26 100644
16511--- a/arch/x86/include/asm/desc.h
16512+++ b/arch/x86/include/asm/desc.h
16513@@ -4,6 +4,7 @@
16514 #include <asm/desc_defs.h>
16515 #include <asm/ldt.h>
16516 #include <asm/mmu.h>
16517+#include <asm/pgtable.h>
16518
16519 #include <linux/smp.h>
16520 #include <linux/percpu.h>
16521@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16522
16523 desc->type = (info->read_exec_only ^ 1) << 1;
16524 desc->type |= info->contents << 2;
16525+ desc->type |= info->seg_not_present ^ 1;
16526
16527 desc->s = 1;
16528 desc->dpl = 0x3;
16529@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16530 }
16531
16532 extern struct desc_ptr idt_descr;
16533-extern gate_desc idt_table[];
16534-extern struct desc_ptr debug_idt_descr;
16535-extern gate_desc debug_idt_table[];
16536-
16537-struct gdt_page {
16538- struct desc_struct gdt[GDT_ENTRIES];
16539-} __attribute__((aligned(PAGE_SIZE)));
16540-
16541-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
16542+extern gate_desc idt_table[IDT_ENTRIES];
16543+extern const struct desc_ptr debug_idt_descr;
16544+extern gate_desc debug_idt_table[IDT_ENTRIES];
16545
16546+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
16547 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
16548 {
16549- return per_cpu(gdt_page, cpu).gdt;
16550+ return cpu_gdt_table[cpu];
16551 }
16552
16553 #ifdef CONFIG_X86_64
16554@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
16555 unsigned long base, unsigned dpl, unsigned flags,
16556 unsigned short seg)
16557 {
16558- gate->a = (seg << 16) | (base & 0xffff);
16559- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
16560+ gate->gate.offset_low = base;
16561+ gate->gate.seg = seg;
16562+ gate->gate.reserved = 0;
16563+ gate->gate.type = type;
16564+ gate->gate.s = 0;
16565+ gate->gate.dpl = dpl;
16566+ gate->gate.p = 1;
16567+ gate->gate.offset_high = base >> 16;
16568 }
16569
16570 #endif
16571@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
16572
16573 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
16574 {
16575+ pax_open_kernel();
16576 memcpy(&idt[entry], gate, sizeof(*gate));
16577+ pax_close_kernel();
16578 }
16579
16580 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
16581 {
16582+ pax_open_kernel();
16583 memcpy(&ldt[entry], desc, 8);
16584+ pax_close_kernel();
16585 }
16586
16587 static inline void
16588@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
16589 default: size = sizeof(*gdt); break;
16590 }
16591
16592+ pax_open_kernel();
16593 memcpy(&gdt[entry], desc, size);
16594+ pax_close_kernel();
16595 }
16596
16597 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
16598@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
16599
16600 static inline void native_load_tr_desc(void)
16601 {
16602+ pax_open_kernel();
16603 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
16604+ pax_close_kernel();
16605 }
16606
16607 static inline void native_load_gdt(const struct desc_ptr *dtr)
16608@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
16609 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
16610 unsigned int i;
16611
16612+ pax_open_kernel();
16613 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
16614 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
16615+ pax_close_kernel();
16616 }
16617
16618 #define _LDT_empty(info) \
16619@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
16620 preempt_enable();
16621 }
16622
16623-static inline unsigned long get_desc_base(const struct desc_struct *desc)
16624+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
16625 {
16626 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
16627 }
16628@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
16629 }
16630
16631 #ifdef CONFIG_X86_64
16632-static inline void set_nmi_gate(int gate, void *addr)
16633+static inline void set_nmi_gate(int gate, const void *addr)
16634 {
16635 gate_desc s;
16636
16637@@ -321,14 +334,14 @@ static inline void set_nmi_gate(int gate, void *addr)
16638 #endif
16639
16640 #ifdef CONFIG_TRACING
16641-extern struct desc_ptr trace_idt_descr;
16642-extern gate_desc trace_idt_table[];
16643+extern const struct desc_ptr trace_idt_descr;
16644+extern gate_desc trace_idt_table[IDT_ENTRIES];
16645 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16646 {
16647 write_idt_entry(trace_idt_table, entry, gate);
16648 }
16649
16650-static inline void _trace_set_gate(int gate, unsigned type, void *addr,
16651+static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
16652 unsigned dpl, unsigned ist, unsigned seg)
16653 {
16654 gate_desc s;
16655@@ -348,7 +361,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16656 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
16657 #endif
16658
16659-static inline void _set_gate(int gate, unsigned type, void *addr,
16660+static inline void _set_gate(int gate, unsigned type, const void *addr,
16661 unsigned dpl, unsigned ist, unsigned seg)
16662 {
16663 gate_desc s;
16664@@ -371,9 +384,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
16665 #define set_intr_gate(n, addr) \
16666 do { \
16667 BUG_ON((unsigned)n > 0xFF); \
16668- _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
16669+ _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
16670 __KERNEL_CS); \
16671- _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
16672+ _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
16673 0, 0, __KERNEL_CS); \
16674 } while (0)
16675
16676@@ -401,19 +414,19 @@ static inline void alloc_system_vector(int vector)
16677 /*
16678 * This routine sets up an interrupt gate at directory privilege level 3.
16679 */
16680-static inline void set_system_intr_gate(unsigned int n, void *addr)
16681+static inline void set_system_intr_gate(unsigned int n, const void *addr)
16682 {
16683 BUG_ON((unsigned)n > 0xFF);
16684 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
16685 }
16686
16687-static inline void set_system_trap_gate(unsigned int n, void *addr)
16688+static inline void set_system_trap_gate(unsigned int n, const void *addr)
16689 {
16690 BUG_ON((unsigned)n > 0xFF);
16691 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
16692 }
16693
16694-static inline void set_trap_gate(unsigned int n, void *addr)
16695+static inline void set_trap_gate(unsigned int n, const void *addr)
16696 {
16697 BUG_ON((unsigned)n > 0xFF);
16698 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
16699@@ -422,16 +435,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
16700 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
16701 {
16702 BUG_ON((unsigned)n > 0xFF);
16703- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
16704+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
16705 }
16706
16707-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
16708+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
16709 {
16710 BUG_ON((unsigned)n > 0xFF);
16711 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
16712 }
16713
16714-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
16715+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
16716 {
16717 BUG_ON((unsigned)n > 0xFF);
16718 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
16719@@ -503,4 +516,17 @@ static inline void load_current_idt(void)
16720 else
16721 load_idt((const struct desc_ptr *)&idt_descr);
16722 }
16723+
16724+#ifdef CONFIG_X86_32
16725+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
16726+{
16727+ struct desc_struct d;
16728+
16729+ if (likely(limit))
16730+ limit = (limit - 1UL) >> PAGE_SHIFT;
16731+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
16732+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
16733+}
16734+#endif
16735+
16736 #endif /* _ASM_X86_DESC_H */
16737diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
16738index 278441f..b95a174 100644
16739--- a/arch/x86/include/asm/desc_defs.h
16740+++ b/arch/x86/include/asm/desc_defs.h
16741@@ -31,6 +31,12 @@ struct desc_struct {
16742 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
16743 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
16744 };
16745+ struct {
16746+ u16 offset_low;
16747+ u16 seg;
16748+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
16749+ unsigned offset_high: 16;
16750+ } gate;
16751 };
16752 } __attribute__((packed));
16753
16754diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
16755index ced283a..ffe04cc 100644
16756--- a/arch/x86/include/asm/div64.h
16757+++ b/arch/x86/include/asm/div64.h
16758@@ -39,7 +39,7 @@
16759 __mod; \
16760 })
16761
16762-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16763+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16764 {
16765 union {
16766 u64 v64;
16767diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
16768index 9c999c1..3860cb8 100644
16769--- a/arch/x86/include/asm/elf.h
16770+++ b/arch/x86/include/asm/elf.h
16771@@ -243,7 +243,25 @@ extern int force_personality32;
16772 the loader. We need to make sure that it is out of the way of the program
16773 that it will "exec", and that there is sufficient room for the brk. */
16774
16775+#ifdef CONFIG_PAX_SEGMEXEC
16776+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
16777+#else
16778 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
16779+#endif
16780+
16781+#ifdef CONFIG_PAX_ASLR
16782+#ifdef CONFIG_X86_32
16783+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
16784+
16785+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16786+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16787+#else
16788+#define PAX_ELF_ET_DYN_BASE 0x400000UL
16789+
16790+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16791+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16792+#endif
16793+#endif
16794
16795 /* This yields a mask that user programs can use to figure out what
16796 instruction set this CPU supports. This could be done in user space,
16797@@ -296,16 +314,12 @@ do { \
16798
16799 #define ARCH_DLINFO \
16800 do { \
16801- if (vdso_enabled) \
16802- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16803- (unsigned long)current->mm->context.vdso); \
16804+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16805 } while (0)
16806
16807 #define ARCH_DLINFO_X32 \
16808 do { \
16809- if (vdso_enabled) \
16810- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16811- (unsigned long)current->mm->context.vdso); \
16812+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16813 } while (0)
16814
16815 #define AT_SYSINFO 32
16816@@ -320,7 +334,7 @@ else \
16817
16818 #endif /* !CONFIG_X86_32 */
16819
16820-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
16821+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
16822
16823 #define VDSO_ENTRY \
16824 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
16825@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
16826 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
16827 #define compat_arch_setup_additional_pages syscall32_setup_pages
16828
16829-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
16830-#define arch_randomize_brk arch_randomize_brk
16831-
16832 /*
16833 * True on X86_32 or when emulating IA32 on X86_64
16834 */
16835diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
16836index 77a99ac..39ff7f5 100644
16837--- a/arch/x86/include/asm/emergency-restart.h
16838+++ b/arch/x86/include/asm/emergency-restart.h
16839@@ -1,6 +1,6 @@
16840 #ifndef _ASM_X86_EMERGENCY_RESTART_H
16841 #define _ASM_X86_EMERGENCY_RESTART_H
16842
16843-extern void machine_emergency_restart(void);
16844+extern void machine_emergency_restart(void) __noreturn;
16845
16846 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
16847diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
16848index d3d7469..677ef72 100644
16849--- a/arch/x86/include/asm/floppy.h
16850+++ b/arch/x86/include/asm/floppy.h
16851@@ -229,18 +229,18 @@ static struct fd_routine_l {
16852 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
16853 } fd_routine[] = {
16854 {
16855- request_dma,
16856- free_dma,
16857- get_dma_residue,
16858- dma_mem_alloc,
16859- hard_dma_setup
16860+ ._request_dma = request_dma,
16861+ ._free_dma = free_dma,
16862+ ._get_dma_residue = get_dma_residue,
16863+ ._dma_mem_alloc = dma_mem_alloc,
16864+ ._dma_setup = hard_dma_setup
16865 },
16866 {
16867- vdma_request_dma,
16868- vdma_nop,
16869- vdma_get_dma_residue,
16870- vdma_mem_alloc,
16871- vdma_dma_setup
16872+ ._request_dma = vdma_request_dma,
16873+ ._free_dma = vdma_nop,
16874+ ._get_dma_residue = vdma_get_dma_residue,
16875+ ._dma_mem_alloc = vdma_mem_alloc,
16876+ ._dma_setup = vdma_dma_setup
16877 }
16878 };
16879
16880diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
16881index cea1c76..6c0d79b 100644
16882--- a/arch/x86/include/asm/fpu-internal.h
16883+++ b/arch/x86/include/asm/fpu-internal.h
16884@@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16885 #define user_insn(insn, output, input...) \
16886 ({ \
16887 int err; \
16888+ pax_open_userland(); \
16889 asm volatile(ASM_STAC "\n" \
16890- "1:" #insn "\n\t" \
16891+ "1:" \
16892+ __copyuser_seg \
16893+ #insn "\n\t" \
16894 "2: " ASM_CLAC "\n" \
16895 ".section .fixup,\"ax\"\n" \
16896 "3: movl $-1,%[err]\n" \
16897@@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16898 _ASM_EXTABLE(1b, 3b) \
16899 : [err] "=r" (err), output \
16900 : "0"(0), input); \
16901+ pax_close_userland(); \
16902 err; \
16903 })
16904
16905@@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
16906 "fnclex\n\t"
16907 "emms\n\t"
16908 "fildl %P[addr]" /* set F?P to defined value */
16909- : : [addr] "m" (tsk->thread.fpu.has_fpu));
16910+ : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
16911 }
16912
16913 return fpu_restore_checking(&tsk->thread.fpu);
16914diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
16915index b4c1f54..e290c08 100644
16916--- a/arch/x86/include/asm/futex.h
16917+++ b/arch/x86/include/asm/futex.h
16918@@ -12,6 +12,7 @@
16919 #include <asm/smap.h>
16920
16921 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
16922+ typecheck(u32 __user *, uaddr); \
16923 asm volatile("\t" ASM_STAC "\n" \
16924 "1:\t" insn "\n" \
16925 "2:\t" ASM_CLAC "\n" \
16926@@ -20,15 +21,16 @@
16927 "\tjmp\t2b\n" \
16928 "\t.previous\n" \
16929 _ASM_EXTABLE(1b, 3b) \
16930- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
16931+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
16932 : "i" (-EFAULT), "0" (oparg), "1" (0))
16933
16934 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
16935+ typecheck(u32 __user *, uaddr); \
16936 asm volatile("\t" ASM_STAC "\n" \
16937 "1:\tmovl %2, %0\n" \
16938 "\tmovl\t%0, %3\n" \
16939 "\t" insn "\n" \
16940- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
16941+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
16942 "\tjnz\t1b\n" \
16943 "3:\t" ASM_CLAC "\n" \
16944 "\t.section .fixup,\"ax\"\n" \
16945@@ -38,7 +40,7 @@
16946 _ASM_EXTABLE(1b, 4b) \
16947 _ASM_EXTABLE(2b, 4b) \
16948 : "=&a" (oldval), "=&r" (ret), \
16949- "+m" (*uaddr), "=&r" (tem) \
16950+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
16951 : "r" (oparg), "i" (-EFAULT), "1" (0))
16952
16953 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16954@@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16955
16956 pagefault_disable();
16957
16958+ pax_open_userland();
16959 switch (op) {
16960 case FUTEX_OP_SET:
16961- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
16962+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
16963 break;
16964 case FUTEX_OP_ADD:
16965- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
16966+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
16967 uaddr, oparg);
16968 break;
16969 case FUTEX_OP_OR:
16970@@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16971 default:
16972 ret = -ENOSYS;
16973 }
16974+ pax_close_userland();
16975
16976 pagefault_enable();
16977
16978diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
16979index 67d69b8..50e4b77 100644
16980--- a/arch/x86/include/asm/hw_irq.h
16981+++ b/arch/x86/include/asm/hw_irq.h
16982@@ -165,8 +165,8 @@ extern void setup_ioapic_dest(void);
16983 extern void enable_IO_APIC(void);
16984
16985 /* Statistics */
16986-extern atomic_t irq_err_count;
16987-extern atomic_t irq_mis_count;
16988+extern atomic_unchecked_t irq_err_count;
16989+extern atomic_unchecked_t irq_mis_count;
16990
16991 /* EISA */
16992 extern void eisa_set_level_irq(unsigned int irq);
16993diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
16994index a203659..9889f1c 100644
16995--- a/arch/x86/include/asm/i8259.h
16996+++ b/arch/x86/include/asm/i8259.h
16997@@ -62,7 +62,7 @@ struct legacy_pic {
16998 void (*init)(int auto_eoi);
16999 int (*irq_pending)(unsigned int irq);
17000 void (*make_irq)(unsigned int irq);
17001-};
17002+} __do_const;
17003
17004 extern struct legacy_pic *legacy_pic;
17005 extern struct legacy_pic null_legacy_pic;
17006diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
17007index 91d9c69..dfae7d0 100644
17008--- a/arch/x86/include/asm/io.h
17009+++ b/arch/x86/include/asm/io.h
17010@@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
17011 "m" (*(volatile type __force *)addr) barrier); }
17012
17013 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
17014-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
17015-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
17016+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
17017+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
17018
17019 build_mmio_read(__readb, "b", unsigned char, "=q", )
17020-build_mmio_read(__readw, "w", unsigned short, "=r", )
17021-build_mmio_read(__readl, "l", unsigned int, "=r", )
17022+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
17023+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
17024
17025 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
17026 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
17027@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
17028 return ioremap_nocache(offset, size);
17029 }
17030
17031-extern void iounmap(volatile void __iomem *addr);
17032+extern void iounmap(const volatile void __iomem *addr);
17033
17034 extern void set_iounmap_nonlazy(void);
17035
17036@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
17037
17038 #include <linux/vmalloc.h>
17039
17040+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
17041+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
17042+{
17043+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17044+}
17045+
17046+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
17047+{
17048+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17049+}
17050+
17051 /*
17052 * Convert a virtual cached pointer to an uncached pointer
17053 */
17054diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
17055index bba3cf8..06bc8da 100644
17056--- a/arch/x86/include/asm/irqflags.h
17057+++ b/arch/x86/include/asm/irqflags.h
17058@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
17059 sti; \
17060 sysexit
17061
17062+#define GET_CR0_INTO_RDI mov %cr0, %rdi
17063+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
17064+#define GET_CR3_INTO_RDI mov %cr3, %rdi
17065+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
17066+
17067 #else
17068 #define INTERRUPT_RETURN iret
17069 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
17070diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
17071index 9454c16..e4100e3 100644
17072--- a/arch/x86/include/asm/kprobes.h
17073+++ b/arch/x86/include/asm/kprobes.h
17074@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
17075 #define RELATIVEJUMP_SIZE 5
17076 #define RELATIVECALL_OPCODE 0xe8
17077 #define RELATIVE_ADDR_SIZE 4
17078-#define MAX_STACK_SIZE 64
17079-#define MIN_STACK_SIZE(ADDR) \
17080- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
17081- THREAD_SIZE - (unsigned long)(ADDR))) \
17082- ? (MAX_STACK_SIZE) \
17083- : (((unsigned long)current_thread_info()) + \
17084- THREAD_SIZE - (unsigned long)(ADDR)))
17085+#define MAX_STACK_SIZE 64UL
17086+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
17087
17088 #define flush_insn_slot(p) do { } while (0)
17089
17090diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
17091index 4ad6560..75c7bdd 100644
17092--- a/arch/x86/include/asm/local.h
17093+++ b/arch/x86/include/asm/local.h
17094@@ -10,33 +10,97 @@ typedef struct {
17095 atomic_long_t a;
17096 } local_t;
17097
17098+typedef struct {
17099+ atomic_long_unchecked_t a;
17100+} local_unchecked_t;
17101+
17102 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
17103
17104 #define local_read(l) atomic_long_read(&(l)->a)
17105+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
17106 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
17107+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
17108
17109 static inline void local_inc(local_t *l)
17110 {
17111- asm volatile(_ASM_INC "%0"
17112+ asm volatile(_ASM_INC "%0\n"
17113+
17114+#ifdef CONFIG_PAX_REFCOUNT
17115+ "jno 0f\n"
17116+ _ASM_DEC "%0\n"
17117+ "int $4\n0:\n"
17118+ _ASM_EXTABLE(0b, 0b)
17119+#endif
17120+
17121+ : "+m" (l->a.counter));
17122+}
17123+
17124+static inline void local_inc_unchecked(local_unchecked_t *l)
17125+{
17126+ asm volatile(_ASM_INC "%0\n"
17127 : "+m" (l->a.counter));
17128 }
17129
17130 static inline void local_dec(local_t *l)
17131 {
17132- asm volatile(_ASM_DEC "%0"
17133+ asm volatile(_ASM_DEC "%0\n"
17134+
17135+#ifdef CONFIG_PAX_REFCOUNT
17136+ "jno 0f\n"
17137+ _ASM_INC "%0\n"
17138+ "int $4\n0:\n"
17139+ _ASM_EXTABLE(0b, 0b)
17140+#endif
17141+
17142+ : "+m" (l->a.counter));
17143+}
17144+
17145+static inline void local_dec_unchecked(local_unchecked_t *l)
17146+{
17147+ asm volatile(_ASM_DEC "%0\n"
17148 : "+m" (l->a.counter));
17149 }
17150
17151 static inline void local_add(long i, local_t *l)
17152 {
17153- asm volatile(_ASM_ADD "%1,%0"
17154+ asm volatile(_ASM_ADD "%1,%0\n"
17155+
17156+#ifdef CONFIG_PAX_REFCOUNT
17157+ "jno 0f\n"
17158+ _ASM_SUB "%1,%0\n"
17159+ "int $4\n0:\n"
17160+ _ASM_EXTABLE(0b, 0b)
17161+#endif
17162+
17163+ : "+m" (l->a.counter)
17164+ : "ir" (i));
17165+}
17166+
17167+static inline void local_add_unchecked(long i, local_unchecked_t *l)
17168+{
17169+ asm volatile(_ASM_ADD "%1,%0\n"
17170 : "+m" (l->a.counter)
17171 : "ir" (i));
17172 }
17173
17174 static inline void local_sub(long i, local_t *l)
17175 {
17176- asm volatile(_ASM_SUB "%1,%0"
17177+ asm volatile(_ASM_SUB "%1,%0\n"
17178+
17179+#ifdef CONFIG_PAX_REFCOUNT
17180+ "jno 0f\n"
17181+ _ASM_ADD "%1,%0\n"
17182+ "int $4\n0:\n"
17183+ _ASM_EXTABLE(0b, 0b)
17184+#endif
17185+
17186+ : "+m" (l->a.counter)
17187+ : "ir" (i));
17188+}
17189+
17190+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
17191+{
17192+ asm volatile(_ASM_SUB "%1,%0\n"
17193 : "+m" (l->a.counter)
17194 : "ir" (i));
17195 }
17196@@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
17197 */
17198 static inline int local_sub_and_test(long i, local_t *l)
17199 {
17200- GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
17201+ GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
17202 }
17203
17204 /**
17205@@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
17206 */
17207 static inline int local_dec_and_test(local_t *l)
17208 {
17209- GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
17210+ GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
17211 }
17212
17213 /**
17214@@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
17215 */
17216 static inline int local_inc_and_test(local_t *l)
17217 {
17218- GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
17219+ GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
17220 }
17221
17222 /**
17223@@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
17224 */
17225 static inline int local_add_negative(long i, local_t *l)
17226 {
17227- GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
17228+ GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
17229 }
17230
17231 /**
17232@@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
17233 static inline long local_add_return(long i, local_t *l)
17234 {
17235 long __i = i;
17236+ asm volatile(_ASM_XADD "%0, %1\n"
17237+
17238+#ifdef CONFIG_PAX_REFCOUNT
17239+ "jno 0f\n"
17240+ _ASM_MOV "%0,%1\n"
17241+ "int $4\n0:\n"
17242+ _ASM_EXTABLE(0b, 0b)
17243+#endif
17244+
17245+ : "+r" (i), "+m" (l->a.counter)
17246+ : : "memory");
17247+ return i + __i;
17248+}
17249+
17250+/**
17251+ * local_add_return_unchecked - add and return
17252+ * @i: integer value to add
17253+ * @l: pointer to type local_unchecked_t
17254+ *
17255+ * Atomically adds @i to @l and returns @i + @l
17256+ */
17257+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
17258+{
17259+ long __i = i;
17260 asm volatile(_ASM_XADD "%0, %1;"
17261 : "+r" (i), "+m" (l->a.counter)
17262 : : "memory");
17263@@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
17264
17265 #define local_cmpxchg(l, o, n) \
17266 (cmpxchg_local(&((l)->a.counter), (o), (n)))
17267+#define local_cmpxchg_unchecked(l, o, n) \
17268+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
17269 /* Always has a lock prefix */
17270 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
17271
17272diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
17273new file mode 100644
17274index 0000000..2bfd3ba
17275--- /dev/null
17276+++ b/arch/x86/include/asm/mman.h
17277@@ -0,0 +1,15 @@
17278+#ifndef _X86_MMAN_H
17279+#define _X86_MMAN_H
17280+
17281+#include <uapi/asm/mman.h>
17282+
17283+#ifdef __KERNEL__
17284+#ifndef __ASSEMBLY__
17285+#ifdef CONFIG_X86_32
17286+#define arch_mmap_check i386_mmap_check
17287+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
17288+#endif
17289+#endif
17290+#endif
17291+
17292+#endif /* X86_MMAN_H */
17293diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
17294index 5f55e69..e20bfb1 100644
17295--- a/arch/x86/include/asm/mmu.h
17296+++ b/arch/x86/include/asm/mmu.h
17297@@ -9,7 +9,7 @@
17298 * we put the segment information here.
17299 */
17300 typedef struct {
17301- void *ldt;
17302+ struct desc_struct *ldt;
17303 int size;
17304
17305 #ifdef CONFIG_X86_64
17306@@ -18,7 +18,19 @@ typedef struct {
17307 #endif
17308
17309 struct mutex lock;
17310- void *vdso;
17311+ unsigned long vdso;
17312+
17313+#ifdef CONFIG_X86_32
17314+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17315+ unsigned long user_cs_base;
17316+ unsigned long user_cs_limit;
17317+
17318+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17319+ cpumask_t cpu_user_cs_mask;
17320+#endif
17321+
17322+#endif
17323+#endif
17324 } mm_context_t;
17325
17326 #ifdef CONFIG_SMP
17327diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
17328index be12c53..4d24039 100644
17329--- a/arch/x86/include/asm/mmu_context.h
17330+++ b/arch/x86/include/asm/mmu_context.h
17331@@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
17332
17333 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
17334 {
17335+
17336+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17337+ if (!(static_cpu_has(X86_FEATURE_PCID))) {
17338+ unsigned int i;
17339+ pgd_t *pgd;
17340+
17341+ pax_open_kernel();
17342+ pgd = get_cpu_pgd(smp_processor_id(), kernel);
17343+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
17344+ set_pgd_batched(pgd+i, native_make_pgd(0));
17345+ pax_close_kernel();
17346+ }
17347+#endif
17348+
17349 #ifdef CONFIG_SMP
17350 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
17351 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
17352@@ -34,16 +48,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17353 struct task_struct *tsk)
17354 {
17355 unsigned cpu = smp_processor_id();
17356+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17357+ int tlbstate = TLBSTATE_OK;
17358+#endif
17359
17360 if (likely(prev != next)) {
17361 #ifdef CONFIG_SMP
17362+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17363+ tlbstate = this_cpu_read(cpu_tlbstate.state);
17364+#endif
17365 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17366 this_cpu_write(cpu_tlbstate.active_mm, next);
17367 #endif
17368 cpumask_set_cpu(cpu, mm_cpumask(next));
17369
17370 /* Re-load page tables */
17371+#ifdef CONFIG_PAX_PER_CPU_PGD
17372+ pax_open_kernel();
17373+
17374+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17375+ if (static_cpu_has(X86_FEATURE_PCID))
17376+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17377+ else
17378+#endif
17379+
17380+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17381+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17382+ pax_close_kernel();
17383+ 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));
17384+
17385+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17386+ if (static_cpu_has(X86_FEATURE_PCID)) {
17387+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17388+ u64 descriptor[2];
17389+ descriptor[0] = PCID_USER;
17390+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17391+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17392+ descriptor[0] = PCID_KERNEL;
17393+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17394+ }
17395+ } else {
17396+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17397+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17398+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17399+ else
17400+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17401+ }
17402+ } else
17403+#endif
17404+
17405+ load_cr3(get_cpu_pgd(cpu, kernel));
17406+#else
17407 load_cr3(next->pgd);
17408+#endif
17409
17410 /* Stop flush ipis for the previous mm */
17411 cpumask_clear_cpu(cpu, mm_cpumask(prev));
17412@@ -51,9 +108,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17413 /* Load the LDT, if the LDT is different: */
17414 if (unlikely(prev->context.ldt != next->context.ldt))
17415 load_LDT_nolock(&next->context);
17416+
17417+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17418+ if (!(__supported_pte_mask & _PAGE_NX)) {
17419+ smp_mb__before_clear_bit();
17420+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
17421+ smp_mb__after_clear_bit();
17422+ cpu_set(cpu, next->context.cpu_user_cs_mask);
17423+ }
17424+#endif
17425+
17426+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17427+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
17428+ prev->context.user_cs_limit != next->context.user_cs_limit))
17429+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17430+#ifdef CONFIG_SMP
17431+ else if (unlikely(tlbstate != TLBSTATE_OK))
17432+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17433+#endif
17434+#endif
17435+
17436 }
17437+ else {
17438+
17439+#ifdef CONFIG_PAX_PER_CPU_PGD
17440+ pax_open_kernel();
17441+
17442+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17443+ if (static_cpu_has(X86_FEATURE_PCID))
17444+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17445+ else
17446+#endif
17447+
17448+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17449+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17450+ pax_close_kernel();
17451+ 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));
17452+
17453+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17454+ if (static_cpu_has(X86_FEATURE_PCID)) {
17455+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17456+ u64 descriptor[2];
17457+ descriptor[0] = PCID_USER;
17458+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17459+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17460+ descriptor[0] = PCID_KERNEL;
17461+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17462+ }
17463+ } else {
17464+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17465+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17466+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17467+ else
17468+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17469+ }
17470+ } else
17471+#endif
17472+
17473+ load_cr3(get_cpu_pgd(cpu, kernel));
17474+#endif
17475+
17476 #ifdef CONFIG_SMP
17477- else {
17478 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17479 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
17480
17481@@ -70,11 +185,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17482 * tlb flush IPI delivery. We must reload CR3
17483 * to make sure to use no freed page tables.
17484 */
17485+
17486+#ifndef CONFIG_PAX_PER_CPU_PGD
17487 load_cr3(next->pgd);
17488+#endif
17489+
17490 load_LDT_nolock(&next->context);
17491+
17492+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17493+ if (!(__supported_pte_mask & _PAGE_NX))
17494+ cpu_set(cpu, next->context.cpu_user_cs_mask);
17495+#endif
17496+
17497+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17498+#ifdef CONFIG_PAX_PAGEEXEC
17499+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
17500+#endif
17501+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17502+#endif
17503+
17504 }
17505+#endif
17506 }
17507-#endif
17508 }
17509
17510 #define activate_mm(prev, next) \
17511diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
17512index e3b7819..b257c64 100644
17513--- a/arch/x86/include/asm/module.h
17514+++ b/arch/x86/include/asm/module.h
17515@@ -5,6 +5,7 @@
17516
17517 #ifdef CONFIG_X86_64
17518 /* X86_64 does not define MODULE_PROC_FAMILY */
17519+#define MODULE_PROC_FAMILY ""
17520 #elif defined CONFIG_M486
17521 #define MODULE_PROC_FAMILY "486 "
17522 #elif defined CONFIG_M586
17523@@ -57,8 +58,20 @@
17524 #error unknown processor family
17525 #endif
17526
17527-#ifdef CONFIG_X86_32
17528-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
17529+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
17530+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
17531+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
17532+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
17533+#else
17534+#define MODULE_PAX_KERNEXEC ""
17535 #endif
17536
17537+#ifdef CONFIG_PAX_MEMORY_UDEREF
17538+#define MODULE_PAX_UDEREF "UDEREF "
17539+#else
17540+#define MODULE_PAX_UDEREF ""
17541+#endif
17542+
17543+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
17544+
17545 #endif /* _ASM_X86_MODULE_H */
17546diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
17547index 86f9301..b365cda 100644
17548--- a/arch/x86/include/asm/nmi.h
17549+++ b/arch/x86/include/asm/nmi.h
17550@@ -40,11 +40,11 @@ struct nmiaction {
17551 nmi_handler_t handler;
17552 unsigned long flags;
17553 const char *name;
17554-};
17555+} __do_const;
17556
17557 #define register_nmi_handler(t, fn, fg, n, init...) \
17558 ({ \
17559- static struct nmiaction init fn##_na = { \
17560+ static const struct nmiaction init fn##_na = { \
17561 .handler = (fn), \
17562 .name = (n), \
17563 .flags = (fg), \
17564@@ -52,7 +52,7 @@ struct nmiaction {
17565 __register_nmi_handler((t), &fn##_na); \
17566 })
17567
17568-int __register_nmi_handler(unsigned int, struct nmiaction *);
17569+int __register_nmi_handler(unsigned int, const struct nmiaction *);
17570
17571 void unregister_nmi_handler(unsigned int, const char *);
17572
17573diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
17574index 775873d..de5f0304 100644
17575--- a/arch/x86/include/asm/page.h
17576+++ b/arch/x86/include/asm/page.h
17577@@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17578 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
17579
17580 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
17581+#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
17582
17583 #define __boot_va(x) __va(x)
17584 #define __boot_pa(x) __pa(x)
17585diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
17586index 0f1ddee..e2fc3d1 100644
17587--- a/arch/x86/include/asm/page_64.h
17588+++ b/arch/x86/include/asm/page_64.h
17589@@ -7,9 +7,9 @@
17590
17591 /* duplicated to the one in bootmem.h */
17592 extern unsigned long max_pfn;
17593-extern unsigned long phys_base;
17594+extern const unsigned long phys_base;
17595
17596-static inline unsigned long __phys_addr_nodebug(unsigned long x)
17597+static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
17598 {
17599 unsigned long y = x - __START_KERNEL_map;
17600
17601diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
17602index cd6e1610..70f4418 100644
17603--- a/arch/x86/include/asm/paravirt.h
17604+++ b/arch/x86/include/asm/paravirt.h
17605@@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
17606 return (pmd_t) { ret };
17607 }
17608
17609-static inline pmdval_t pmd_val(pmd_t pmd)
17610+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
17611 {
17612 pmdval_t ret;
17613
17614@@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
17615 val);
17616 }
17617
17618+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17619+{
17620+ pgdval_t val = native_pgd_val(pgd);
17621+
17622+ if (sizeof(pgdval_t) > sizeof(long))
17623+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
17624+ val, (u64)val >> 32);
17625+ else
17626+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
17627+ val);
17628+}
17629+
17630 static inline void pgd_clear(pgd_t *pgdp)
17631 {
17632 set_pgd(pgdp, __pgd(0));
17633@@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
17634 pv_mmu_ops.set_fixmap(idx, phys, flags);
17635 }
17636
17637+#ifdef CONFIG_PAX_KERNEXEC
17638+static inline unsigned long pax_open_kernel(void)
17639+{
17640+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
17641+}
17642+
17643+static inline unsigned long pax_close_kernel(void)
17644+{
17645+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
17646+}
17647+#else
17648+static inline unsigned long pax_open_kernel(void) { return 0; }
17649+static inline unsigned long pax_close_kernel(void) { return 0; }
17650+#endif
17651+
17652 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
17653
17654 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
17655@@ -906,7 +933,7 @@ extern void default_banner(void);
17656
17657 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
17658 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
17659-#define PARA_INDIRECT(addr) *%cs:addr
17660+#define PARA_INDIRECT(addr) *%ss:addr
17661 #endif
17662
17663 #define INTERRUPT_RETURN \
17664@@ -981,6 +1008,21 @@ extern void default_banner(void);
17665 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
17666 CLBR_NONE, \
17667 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
17668+
17669+#define GET_CR0_INTO_RDI \
17670+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
17671+ mov %rax,%rdi
17672+
17673+#define SET_RDI_INTO_CR0 \
17674+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
17675+
17676+#define GET_CR3_INTO_RDI \
17677+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
17678+ mov %rax,%rdi
17679+
17680+#define SET_RDI_INTO_CR3 \
17681+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
17682+
17683 #endif /* CONFIG_X86_32 */
17684
17685 #endif /* __ASSEMBLY__ */
17686diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
17687index 7549b8b..f0edfda 100644
17688--- a/arch/x86/include/asm/paravirt_types.h
17689+++ b/arch/x86/include/asm/paravirt_types.h
17690@@ -84,7 +84,7 @@ struct pv_init_ops {
17691 */
17692 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
17693 unsigned long addr, unsigned len);
17694-};
17695+} __no_const __no_randomize_layout;
17696
17697
17698 struct pv_lazy_ops {
17699@@ -92,13 +92,13 @@ struct pv_lazy_ops {
17700 void (*enter)(void);
17701 void (*leave)(void);
17702 void (*flush)(void);
17703-};
17704+} __no_randomize_layout;
17705
17706 struct pv_time_ops {
17707 unsigned long long (*sched_clock)(void);
17708 unsigned long long (*steal_clock)(int cpu);
17709 unsigned long (*get_tsc_khz)(void);
17710-};
17711+} __no_const __no_randomize_layout;
17712
17713 struct pv_cpu_ops {
17714 /* hooks for various privileged instructions */
17715@@ -192,7 +192,7 @@ struct pv_cpu_ops {
17716
17717 void (*start_context_switch)(struct task_struct *prev);
17718 void (*end_context_switch)(struct task_struct *next);
17719-};
17720+} __no_const __no_randomize_layout;
17721
17722 struct pv_irq_ops {
17723 /*
17724@@ -215,7 +215,7 @@ struct pv_irq_ops {
17725 #ifdef CONFIG_X86_64
17726 void (*adjust_exception_frame)(void);
17727 #endif
17728-};
17729+} __no_randomize_layout;
17730
17731 struct pv_apic_ops {
17732 #ifdef CONFIG_X86_LOCAL_APIC
17733@@ -223,7 +223,7 @@ struct pv_apic_ops {
17734 unsigned long start_eip,
17735 unsigned long start_esp);
17736 #endif
17737-};
17738+} __no_const __no_randomize_layout;
17739
17740 struct pv_mmu_ops {
17741 unsigned long (*read_cr2)(void);
17742@@ -313,6 +313,7 @@ struct pv_mmu_ops {
17743 struct paravirt_callee_save make_pud;
17744
17745 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
17746+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
17747 #endif /* PAGETABLE_LEVELS == 4 */
17748 #endif /* PAGETABLE_LEVELS >= 3 */
17749
17750@@ -324,7 +325,13 @@ struct pv_mmu_ops {
17751 an mfn. We can tell which is which from the index. */
17752 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
17753 phys_addr_t phys, pgprot_t flags);
17754-};
17755+
17756+#ifdef CONFIG_PAX_KERNEXEC
17757+ unsigned long (*pax_open_kernel)(void);
17758+ unsigned long (*pax_close_kernel)(void);
17759+#endif
17760+
17761+} __no_randomize_layout;
17762
17763 struct arch_spinlock;
17764 #ifdef CONFIG_SMP
17765@@ -336,11 +343,14 @@ typedef u16 __ticket_t;
17766 struct pv_lock_ops {
17767 struct paravirt_callee_save lock_spinning;
17768 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
17769-};
17770+} __no_randomize_layout;
17771
17772 /* This contains all the paravirt structures: we get a convenient
17773 * number for each function using the offset which we use to indicate
17774- * what to patch. */
17775+ * what to patch.
17776+ * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
17777+ */
17778+
17779 struct paravirt_patch_template {
17780 struct pv_init_ops pv_init_ops;
17781 struct pv_time_ops pv_time_ops;
17782@@ -349,7 +359,7 @@ struct paravirt_patch_template {
17783 struct pv_apic_ops pv_apic_ops;
17784 struct pv_mmu_ops pv_mmu_ops;
17785 struct pv_lock_ops pv_lock_ops;
17786-};
17787+} __no_randomize_layout;
17788
17789 extern struct pv_info pv_info;
17790 extern struct pv_init_ops pv_init_ops;
17791diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
17792index c4412e9..90e88c5 100644
17793--- a/arch/x86/include/asm/pgalloc.h
17794+++ b/arch/x86/include/asm/pgalloc.h
17795@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
17796 pmd_t *pmd, pte_t *pte)
17797 {
17798 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17799+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
17800+}
17801+
17802+static inline void pmd_populate_user(struct mm_struct *mm,
17803+ pmd_t *pmd, pte_t *pte)
17804+{
17805+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17806 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
17807 }
17808
17809@@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
17810
17811 #ifdef CONFIG_X86_PAE
17812 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
17813+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
17814+{
17815+ pud_populate(mm, pudp, pmd);
17816+}
17817 #else /* !CONFIG_X86_PAE */
17818 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17819 {
17820 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17821 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
17822 }
17823+
17824+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17825+{
17826+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17827+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
17828+}
17829 #endif /* CONFIG_X86_PAE */
17830
17831 #if PAGETABLE_LEVELS > 3
17832@@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17833 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
17834 }
17835
17836+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17837+{
17838+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
17839+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
17840+}
17841+
17842 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
17843 {
17844 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
17845diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
17846index 0d193e2..bf59aeb 100644
17847--- a/arch/x86/include/asm/pgtable-2level.h
17848+++ b/arch/x86/include/asm/pgtable-2level.h
17849@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
17850
17851 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17852 {
17853+ pax_open_kernel();
17854 *pmdp = pmd;
17855+ pax_close_kernel();
17856 }
17857
17858 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17859diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
17860index 81bb91b..9392125 100644
17861--- a/arch/x86/include/asm/pgtable-3level.h
17862+++ b/arch/x86/include/asm/pgtable-3level.h
17863@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17864
17865 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17866 {
17867+ pax_open_kernel();
17868 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
17869+ pax_close_kernel();
17870 }
17871
17872 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17873 {
17874+ pax_open_kernel();
17875 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
17876+ pax_close_kernel();
17877 }
17878
17879 /*
17880diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
17881index bbc8b12..f228861 100644
17882--- a/arch/x86/include/asm/pgtable.h
17883+++ b/arch/x86/include/asm/pgtable.h
17884@@ -45,6 +45,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17885
17886 #ifndef __PAGETABLE_PUD_FOLDED
17887 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
17888+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
17889 #define pgd_clear(pgd) native_pgd_clear(pgd)
17890 #endif
17891
17892@@ -82,12 +83,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17893
17894 #define arch_end_context_switch(prev) do {} while(0)
17895
17896+#define pax_open_kernel() native_pax_open_kernel()
17897+#define pax_close_kernel() native_pax_close_kernel()
17898 #endif /* CONFIG_PARAVIRT */
17899
17900+#define __HAVE_ARCH_PAX_OPEN_KERNEL
17901+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
17902+
17903+#ifdef CONFIG_PAX_KERNEXEC
17904+static inline unsigned long native_pax_open_kernel(void)
17905+{
17906+ unsigned long cr0;
17907+
17908+ preempt_disable();
17909+ barrier();
17910+ cr0 = read_cr0() ^ X86_CR0_WP;
17911+ BUG_ON(cr0 & X86_CR0_WP);
17912+ write_cr0(cr0);
17913+ return cr0 ^ X86_CR0_WP;
17914+}
17915+
17916+static inline unsigned long native_pax_close_kernel(void)
17917+{
17918+ unsigned long cr0;
17919+
17920+ cr0 = read_cr0() ^ X86_CR0_WP;
17921+ BUG_ON(!(cr0 & X86_CR0_WP));
17922+ write_cr0(cr0);
17923+ barrier();
17924+ preempt_enable_no_resched();
17925+ return cr0 ^ X86_CR0_WP;
17926+}
17927+#else
17928+static inline unsigned long native_pax_open_kernel(void) { return 0; }
17929+static inline unsigned long native_pax_close_kernel(void) { return 0; }
17930+#endif
17931+
17932 /*
17933 * The following only work if pte_present() is true.
17934 * Undefined behaviour if not..
17935 */
17936+static inline int pte_user(pte_t pte)
17937+{
17938+ return pte_val(pte) & _PAGE_USER;
17939+}
17940+
17941 static inline int pte_dirty(pte_t pte)
17942 {
17943 return pte_flags(pte) & _PAGE_DIRTY;
17944@@ -148,6 +188,11 @@ static inline unsigned long pud_pfn(pud_t pud)
17945 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
17946 }
17947
17948+static inline unsigned long pgd_pfn(pgd_t pgd)
17949+{
17950+ return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
17951+}
17952+
17953 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
17954
17955 static inline int pmd_large(pmd_t pte)
17956@@ -201,9 +246,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
17957 return pte_clear_flags(pte, _PAGE_RW);
17958 }
17959
17960+static inline pte_t pte_mkread(pte_t pte)
17961+{
17962+ return __pte(pte_val(pte) | _PAGE_USER);
17963+}
17964+
17965 static inline pte_t pte_mkexec(pte_t pte)
17966 {
17967- return pte_clear_flags(pte, _PAGE_NX);
17968+#ifdef CONFIG_X86_PAE
17969+ if (__supported_pte_mask & _PAGE_NX)
17970+ return pte_clear_flags(pte, _PAGE_NX);
17971+ else
17972+#endif
17973+ return pte_set_flags(pte, _PAGE_USER);
17974+}
17975+
17976+static inline pte_t pte_exprotect(pte_t pte)
17977+{
17978+#ifdef CONFIG_X86_PAE
17979+ if (__supported_pte_mask & _PAGE_NX)
17980+ return pte_set_flags(pte, _PAGE_NX);
17981+ else
17982+#endif
17983+ return pte_clear_flags(pte, _PAGE_USER);
17984 }
17985
17986 static inline pte_t pte_mkdirty(pte_t pte)
17987@@ -430,6 +495,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
17988 #endif
17989
17990 #ifndef __ASSEMBLY__
17991+
17992+#ifdef CONFIG_PAX_PER_CPU_PGD
17993+extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
17994+enum cpu_pgd_type {kernel = 0, user = 1};
17995+static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
17996+{
17997+ return cpu_pgd[cpu][type];
17998+}
17999+#endif
18000+
18001 #include <linux/mm_types.h>
18002 #include <linux/mmdebug.h>
18003 #include <linux/log2.h>
18004@@ -570,7 +645,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
18005 * Currently stuck as a macro due to indirect forward reference to
18006 * linux/mmzone.h's __section_mem_map_addr() definition:
18007 */
18008-#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
18009+#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
18010
18011 /* Find an entry in the second-level page table.. */
18012 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
18013@@ -610,7 +685,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
18014 * Currently stuck as a macro due to indirect forward reference to
18015 * linux/mmzone.h's __section_mem_map_addr() definition:
18016 */
18017-#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
18018+#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
18019
18020 /* to find an entry in a page-table-directory. */
18021 static inline unsigned long pud_index(unsigned long address)
18022@@ -625,7 +700,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
18023
18024 static inline int pgd_bad(pgd_t pgd)
18025 {
18026- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
18027+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
18028 }
18029
18030 static inline int pgd_none(pgd_t pgd)
18031@@ -648,7 +723,12 @@ static inline int pgd_none(pgd_t pgd)
18032 * pgd_offset() returns a (pgd_t *)
18033 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
18034 */
18035-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
18036+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
18037+
18038+#ifdef CONFIG_PAX_PER_CPU_PGD
18039+#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
18040+#endif
18041+
18042 /*
18043 * a shortcut which implies the use of the kernel's pgd, instead
18044 * of a process's
18045@@ -659,6 +739,23 @@ static inline int pgd_none(pgd_t pgd)
18046 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
18047 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
18048
18049+#ifdef CONFIG_X86_32
18050+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
18051+#else
18052+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
18053+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
18054+
18055+#ifdef CONFIG_PAX_MEMORY_UDEREF
18056+#ifdef __ASSEMBLY__
18057+#define pax_user_shadow_base pax_user_shadow_base(%rip)
18058+#else
18059+extern unsigned long pax_user_shadow_base;
18060+extern pgdval_t clone_pgd_mask;
18061+#endif
18062+#endif
18063+
18064+#endif
18065+
18066 #ifndef __ASSEMBLY__
18067
18068 extern int direct_gbpages;
18069@@ -825,11 +922,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
18070 * dst and src can be on the same page, but the range must not overlap,
18071 * and must not cross a page boundary.
18072 */
18073-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
18074+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
18075 {
18076- memcpy(dst, src, count * sizeof(pgd_t));
18077+ pax_open_kernel();
18078+ while (count--)
18079+ *dst++ = *src++;
18080+ pax_close_kernel();
18081 }
18082
18083+#ifdef CONFIG_PAX_PER_CPU_PGD
18084+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
18085+#endif
18086+
18087+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18088+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
18089+#else
18090+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
18091+#endif
18092+
18093 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
18094 static inline int page_level_shift(enum pg_level level)
18095 {
18096diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
18097index 9ee3221..b979c6b 100644
18098--- a/arch/x86/include/asm/pgtable_32.h
18099+++ b/arch/x86/include/asm/pgtable_32.h
18100@@ -25,9 +25,6 @@
18101 struct mm_struct;
18102 struct vm_area_struct;
18103
18104-extern pgd_t swapper_pg_dir[1024];
18105-extern pgd_t initial_page_table[1024];
18106-
18107 static inline void pgtable_cache_init(void) { }
18108 static inline void check_pgt_cache(void) { }
18109 void paging_init(void);
18110@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
18111 # include <asm/pgtable-2level.h>
18112 #endif
18113
18114+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
18115+extern pgd_t initial_page_table[PTRS_PER_PGD];
18116+#ifdef CONFIG_X86_PAE
18117+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
18118+#endif
18119+
18120 #if defined(CONFIG_HIGHPTE)
18121 #define pte_offset_map(dir, address) \
18122 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
18123@@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
18124 /* Clear a kernel PTE and flush it from the TLB */
18125 #define kpte_clear_flush(ptep, vaddr) \
18126 do { \
18127+ pax_open_kernel(); \
18128 pte_clear(&init_mm, (vaddr), (ptep)); \
18129+ pax_close_kernel(); \
18130 __flush_tlb_one((vaddr)); \
18131 } while (0)
18132
18133 #endif /* !__ASSEMBLY__ */
18134
18135+#define HAVE_ARCH_UNMAPPED_AREA
18136+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
18137+
18138 /*
18139 * kern_addr_valid() is (1) for FLATMEM and (0) for
18140 * SPARSEMEM and DISCONTIGMEM
18141diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
18142index ed5903b..c7fe163 100644
18143--- a/arch/x86/include/asm/pgtable_32_types.h
18144+++ b/arch/x86/include/asm/pgtable_32_types.h
18145@@ -8,7 +8,7 @@
18146 */
18147 #ifdef CONFIG_X86_PAE
18148 # include <asm/pgtable-3level_types.h>
18149-# define PMD_SIZE (1UL << PMD_SHIFT)
18150+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
18151 # define PMD_MASK (~(PMD_SIZE - 1))
18152 #else
18153 # include <asm/pgtable-2level_types.h>
18154@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
18155 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
18156 #endif
18157
18158+#ifdef CONFIG_PAX_KERNEXEC
18159+#ifndef __ASSEMBLY__
18160+extern unsigned char MODULES_EXEC_VADDR[];
18161+extern unsigned char MODULES_EXEC_END[];
18162+#endif
18163+#include <asm/boot.h>
18164+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
18165+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
18166+#else
18167+#define ktla_ktva(addr) (addr)
18168+#define ktva_ktla(addr) (addr)
18169+#endif
18170+
18171 #define MODULES_VADDR VMALLOC_START
18172 #define MODULES_END VMALLOC_END
18173 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
18174diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
18175index e22c1db..23a625a 100644
18176--- a/arch/x86/include/asm/pgtable_64.h
18177+++ b/arch/x86/include/asm/pgtable_64.h
18178@@ -16,10 +16,14 @@
18179
18180 extern pud_t level3_kernel_pgt[512];
18181 extern pud_t level3_ident_pgt[512];
18182+extern pud_t level3_vmalloc_start_pgt[512];
18183+extern pud_t level3_vmalloc_end_pgt[512];
18184+extern pud_t level3_vmemmap_pgt[512];
18185+extern pud_t level2_vmemmap_pgt[512];
18186 extern pmd_t level2_kernel_pgt[512];
18187 extern pmd_t level2_fixmap_pgt[512];
18188-extern pmd_t level2_ident_pgt[512];
18189-extern pgd_t init_level4_pgt[];
18190+extern pmd_t level2_ident_pgt[512*2];
18191+extern pgd_t init_level4_pgt[512];
18192
18193 #define swapper_pg_dir init_level4_pgt
18194
18195@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18196
18197 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18198 {
18199+ pax_open_kernel();
18200 *pmdp = pmd;
18201+ pax_close_kernel();
18202 }
18203
18204 static inline void native_pmd_clear(pmd_t *pmd)
18205@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
18206
18207 static inline void native_set_pud(pud_t *pudp, pud_t pud)
18208 {
18209+ pax_open_kernel();
18210 *pudp = pud;
18211+ pax_close_kernel();
18212 }
18213
18214 static inline void native_pud_clear(pud_t *pud)
18215@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
18216
18217 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
18218 {
18219+ pax_open_kernel();
18220+ *pgdp = pgd;
18221+ pax_close_kernel();
18222+}
18223+
18224+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
18225+{
18226 *pgdp = pgd;
18227 }
18228
18229diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
18230index c883bf7..19970b3 100644
18231--- a/arch/x86/include/asm/pgtable_64_types.h
18232+++ b/arch/x86/include/asm/pgtable_64_types.h
18233@@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
18234 #define MODULES_VADDR (__START_KERNEL_map + KERNEL_IMAGE_SIZE)
18235 #define MODULES_END _AC(0xffffffffff000000, UL)
18236 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
18237+#define MODULES_EXEC_VADDR MODULES_VADDR
18238+#define MODULES_EXEC_END MODULES_END
18239+
18240+#define ktla_ktva(addr) (addr)
18241+#define ktva_ktla(addr) (addr)
18242
18243 #define EARLY_DYNAMIC_PAGE_TABLES 64
18244
18245diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
18246index 94e40f1..ebd03e4 100644
18247--- a/arch/x86/include/asm/pgtable_types.h
18248+++ b/arch/x86/include/asm/pgtable_types.h
18249@@ -16,13 +16,12 @@
18250 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
18251 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
18252 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
18253-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
18254+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
18255 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
18256 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
18257 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
18258-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
18259-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
18260-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
18261+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
18262+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
18263 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
18264
18265 /* If _PAGE_BIT_PRESENT is clear, we use these: */
18266@@ -40,7 +39,6 @@
18267 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
18268 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
18269 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
18270-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
18271 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
18272 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
18273 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
18274@@ -87,8 +85,10 @@
18275
18276 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
18277 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
18278-#else
18279+#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
18280 #define _PAGE_NX (_AT(pteval_t, 0))
18281+#else
18282+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
18283 #endif
18284
18285 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
18286@@ -147,6 +147,9 @@
18287 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
18288 _PAGE_ACCESSED)
18289
18290+#define PAGE_READONLY_NOEXEC PAGE_READONLY
18291+#define PAGE_SHARED_NOEXEC PAGE_SHARED
18292+
18293 #define __PAGE_KERNEL_EXEC \
18294 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
18295 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
18296@@ -157,7 +160,7 @@
18297 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
18298 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
18299 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
18300-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
18301+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
18302 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
18303 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
18304 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
18305@@ -219,8 +222,8 @@
18306 * bits are combined, this will alow user to access the high address mapped
18307 * VDSO in the presence of CONFIG_COMPAT_VDSO
18308 */
18309-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
18310-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
18311+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18312+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18313 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
18314 #endif
18315
18316@@ -258,7 +261,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
18317 {
18318 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
18319 }
18320+#endif
18321
18322+#if PAGETABLE_LEVELS == 3
18323+#include <asm-generic/pgtable-nopud.h>
18324+#endif
18325+
18326+#if PAGETABLE_LEVELS == 2
18327+#include <asm-generic/pgtable-nopmd.h>
18328+#endif
18329+
18330+#ifndef __ASSEMBLY__
18331 #if PAGETABLE_LEVELS > 3
18332 typedef struct { pudval_t pud; } pud_t;
18333
18334@@ -272,8 +285,6 @@ static inline pudval_t native_pud_val(pud_t pud)
18335 return pud.pud;
18336 }
18337 #else
18338-#include <asm-generic/pgtable-nopud.h>
18339-
18340 static inline pudval_t native_pud_val(pud_t pud)
18341 {
18342 return native_pgd_val(pud.pgd);
18343@@ -293,8 +304,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
18344 return pmd.pmd;
18345 }
18346 #else
18347-#include <asm-generic/pgtable-nopmd.h>
18348-
18349 static inline pmdval_t native_pmd_val(pmd_t pmd)
18350 {
18351 return native_pgd_val(pmd.pud.pgd);
18352@@ -334,7 +343,6 @@ typedef struct page *pgtable_t;
18353
18354 extern pteval_t __supported_pte_mask;
18355 extern void set_nx(void);
18356-extern int nx_enabled;
18357
18358 #define pgprot_writecombine pgprot_writecombine
18359 extern pgprot_t pgprot_writecombine(pgprot_t prot);
18360diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
18361index c8b0519..fd29e73 100644
18362--- a/arch/x86/include/asm/preempt.h
18363+++ b/arch/x86/include/asm/preempt.h
18364@@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
18365 */
18366 static __always_inline bool __preempt_count_dec_and_test(void)
18367 {
18368- GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
18369+ GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
18370 }
18371
18372 /*
18373diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
18374index fdedd38..95c02c2 100644
18375--- a/arch/x86/include/asm/processor.h
18376+++ b/arch/x86/include/asm/processor.h
18377@@ -128,7 +128,7 @@ struct cpuinfo_x86 {
18378 /* Index into per_cpu list: */
18379 u16 cpu_index;
18380 u32 microcode;
18381-} __attribute__((__aligned__(SMP_CACHE_BYTES)));
18382+} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
18383
18384 #define X86_VENDOR_INTEL 0
18385 #define X86_VENDOR_CYRIX 1
18386@@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
18387 : "memory");
18388 }
18389
18390+/* invpcid (%rdx),%rax */
18391+#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
18392+
18393+#define INVPCID_SINGLE_ADDRESS 0UL
18394+#define INVPCID_SINGLE_CONTEXT 1UL
18395+#define INVPCID_ALL_GLOBAL 2UL
18396+#define INVPCID_ALL_MONGLOBAL 3UL
18397+
18398+#define PCID_KERNEL 0UL
18399+#define PCID_USER 1UL
18400+#define PCID_NOFLUSH (1UL << 63)
18401+
18402 static inline void load_cr3(pgd_t *pgdir)
18403 {
18404- write_cr3(__pa(pgdir));
18405+ write_cr3(__pa(pgdir) | PCID_KERNEL);
18406 }
18407
18408 #ifdef CONFIG_X86_32
18409@@ -283,7 +295,7 @@ struct tss_struct {
18410
18411 } ____cacheline_aligned;
18412
18413-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
18414+extern struct tss_struct init_tss[NR_CPUS];
18415
18416 /*
18417 * Save the original ist values for checking stack pointers during debugging
18418@@ -470,6 +482,7 @@ struct thread_struct {
18419 unsigned short ds;
18420 unsigned short fsindex;
18421 unsigned short gsindex;
18422+ unsigned short ss;
18423 #endif
18424 #ifdef CONFIG_X86_32
18425 unsigned long ip;
18426@@ -579,29 +592,8 @@ static inline void load_sp0(struct tss_struct *tss,
18427 extern unsigned long mmu_cr4_features;
18428 extern u32 *trampoline_cr4_features;
18429
18430-static inline void set_in_cr4(unsigned long mask)
18431-{
18432- unsigned long cr4;
18433-
18434- mmu_cr4_features |= mask;
18435- if (trampoline_cr4_features)
18436- *trampoline_cr4_features = mmu_cr4_features;
18437- cr4 = read_cr4();
18438- cr4 |= mask;
18439- write_cr4(cr4);
18440-}
18441-
18442-static inline void clear_in_cr4(unsigned long mask)
18443-{
18444- unsigned long cr4;
18445-
18446- mmu_cr4_features &= ~mask;
18447- if (trampoline_cr4_features)
18448- *trampoline_cr4_features = mmu_cr4_features;
18449- cr4 = read_cr4();
18450- cr4 &= ~mask;
18451- write_cr4(cr4);
18452-}
18453+extern void set_in_cr4(unsigned long mask);
18454+extern void clear_in_cr4(unsigned long mask);
18455
18456 typedef struct {
18457 unsigned long seg;
18458@@ -827,11 +819,18 @@ static inline void spin_lock_prefetch(const void *x)
18459 */
18460 #define TASK_SIZE PAGE_OFFSET
18461 #define TASK_SIZE_MAX TASK_SIZE
18462+
18463+#ifdef CONFIG_PAX_SEGMEXEC
18464+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
18465+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
18466+#else
18467 #define STACK_TOP TASK_SIZE
18468-#define STACK_TOP_MAX STACK_TOP
18469+#endif
18470+
18471+#define STACK_TOP_MAX TASK_SIZE
18472
18473 #define INIT_THREAD { \
18474- .sp0 = sizeof(init_stack) + (long)&init_stack, \
18475+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18476 .vm86_info = NULL, \
18477 .sysenter_cs = __KERNEL_CS, \
18478 .io_bitmap_ptr = NULL, \
18479@@ -845,7 +844,7 @@ static inline void spin_lock_prefetch(const void *x)
18480 */
18481 #define INIT_TSS { \
18482 .x86_tss = { \
18483- .sp0 = sizeof(init_stack) + (long)&init_stack, \
18484+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18485 .ss0 = __KERNEL_DS, \
18486 .ss1 = __KERNEL_CS, \
18487 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
18488@@ -856,11 +855,7 @@ static inline void spin_lock_prefetch(const void *x)
18489 extern unsigned long thread_saved_pc(struct task_struct *tsk);
18490
18491 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
18492-#define KSTK_TOP(info) \
18493-({ \
18494- unsigned long *__ptr = (unsigned long *)(info); \
18495- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
18496-})
18497+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
18498
18499 /*
18500 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
18501@@ -875,7 +870,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18502 #define task_pt_regs(task) \
18503 ({ \
18504 struct pt_regs *__regs__; \
18505- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
18506+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
18507 __regs__ - 1; \
18508 })
18509
18510@@ -885,13 +880,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18511 /*
18512 * User space process size. 47bits minus one guard page.
18513 */
18514-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
18515+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
18516
18517 /* This decides where the kernel will search for a free chunk of vm
18518 * space during mmap's.
18519 */
18520 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
18521- 0xc0000000 : 0xFFFFe000)
18522+ 0xc0000000 : 0xFFFFf000)
18523
18524 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
18525 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
18526@@ -902,11 +897,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18527 #define STACK_TOP_MAX TASK_SIZE_MAX
18528
18529 #define INIT_THREAD { \
18530- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18531+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18532 }
18533
18534 #define INIT_TSS { \
18535- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18536+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18537 }
18538
18539 /*
18540@@ -934,6 +929,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
18541 */
18542 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
18543
18544+#ifdef CONFIG_PAX_SEGMEXEC
18545+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
18546+#endif
18547+
18548 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
18549
18550 /* Get/set a process' ability to use the timestamp counter instruction */
18551@@ -960,7 +959,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
18552 return 0;
18553 }
18554
18555-extern unsigned long arch_align_stack(unsigned long sp);
18556+#define arch_align_stack(x) ((x) & ~0xfUL)
18557 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
18558
18559 void default_idle(void);
18560@@ -970,6 +969,6 @@ bool xen_set_default_idle(void);
18561 #define xen_set_default_idle 0
18562 #endif
18563
18564-void stop_this_cpu(void *dummy);
18565+void stop_this_cpu(void *dummy) __noreturn;
18566 void df_debug(struct pt_regs *regs, long error_code);
18567 #endif /* _ASM_X86_PROCESSOR_H */
18568diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
18569index 14fd6fd..6740420 100644
18570--- a/arch/x86/include/asm/ptrace.h
18571+++ b/arch/x86/include/asm/ptrace.h
18572@@ -84,28 +84,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
18573 }
18574
18575 /*
18576- * user_mode_vm(regs) determines whether a register set came from user mode.
18577+ * user_mode(regs) determines whether a register set came from user mode.
18578 * This is true if V8086 mode was enabled OR if the register set was from
18579 * protected mode with RPL-3 CS value. This tricky test checks that with
18580 * one comparison. Many places in the kernel can bypass this full check
18581- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
18582+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
18583+ * be used.
18584 */
18585-static inline int user_mode(struct pt_regs *regs)
18586+static inline int user_mode_novm(struct pt_regs *regs)
18587 {
18588 #ifdef CONFIG_X86_32
18589 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
18590 #else
18591- return !!(regs->cs & 3);
18592+ return !!(regs->cs & SEGMENT_RPL_MASK);
18593 #endif
18594 }
18595
18596-static inline int user_mode_vm(struct pt_regs *regs)
18597+static inline int user_mode(struct pt_regs *regs)
18598 {
18599 #ifdef CONFIG_X86_32
18600 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
18601 USER_RPL;
18602 #else
18603- return user_mode(regs);
18604+ return user_mode_novm(regs);
18605 #endif
18606 }
18607
18608@@ -121,15 +122,16 @@ static inline int v8086_mode(struct pt_regs *regs)
18609 #ifdef CONFIG_X86_64
18610 static inline bool user_64bit_mode(struct pt_regs *regs)
18611 {
18612+ unsigned long cs = regs->cs & 0xffff;
18613 #ifndef CONFIG_PARAVIRT
18614 /*
18615 * On non-paravirt systems, this is the only long mode CPL 3
18616 * selector. We do not allow long mode selectors in the LDT.
18617 */
18618- return regs->cs == __USER_CS;
18619+ return cs == __USER_CS;
18620 #else
18621 /* Headers are too twisted for this to go in paravirt.h. */
18622- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
18623+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
18624 #endif
18625 }
18626
18627@@ -180,9 +182,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
18628 * Traps from the kernel do not save sp and ss.
18629 * Use the helper function to retrieve sp.
18630 */
18631- if (offset == offsetof(struct pt_regs, sp) &&
18632- regs->cs == __KERNEL_CS)
18633- return kernel_stack_pointer(regs);
18634+ if (offset == offsetof(struct pt_regs, sp)) {
18635+ unsigned long cs = regs->cs & 0xffff;
18636+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
18637+ return kernel_stack_pointer(regs);
18638+ }
18639 #endif
18640 return *(unsigned long *)((unsigned long)regs + offset);
18641 }
18642diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
18643index 9c6b890..5305f53 100644
18644--- a/arch/x86/include/asm/realmode.h
18645+++ b/arch/x86/include/asm/realmode.h
18646@@ -22,16 +22,14 @@ struct real_mode_header {
18647 #endif
18648 /* APM/BIOS reboot */
18649 u32 machine_real_restart_asm;
18650-#ifdef CONFIG_X86_64
18651 u32 machine_real_restart_seg;
18652-#endif
18653 };
18654
18655 /* This must match data at trampoline_32/64.S */
18656 struct trampoline_header {
18657 #ifdef CONFIG_X86_32
18658 u32 start;
18659- u16 gdt_pad;
18660+ u16 boot_cs;
18661 u16 gdt_limit;
18662 u32 gdt_base;
18663 #else
18664diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
18665index a82c4f1..ac45053 100644
18666--- a/arch/x86/include/asm/reboot.h
18667+++ b/arch/x86/include/asm/reboot.h
18668@@ -6,13 +6,13 @@
18669 struct pt_regs;
18670
18671 struct machine_ops {
18672- void (*restart)(char *cmd);
18673- void (*halt)(void);
18674- void (*power_off)(void);
18675+ void (* __noreturn restart)(char *cmd);
18676+ void (* __noreturn halt)(void);
18677+ void (* __noreturn power_off)(void);
18678 void (*shutdown)(void);
18679 void (*crash_shutdown)(struct pt_regs *);
18680- void (*emergency_restart)(void);
18681-};
18682+ void (* __noreturn emergency_restart)(void);
18683+} __no_const;
18684
18685 extern struct machine_ops machine_ops;
18686
18687diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
18688index 8f7866a..e442f20 100644
18689--- a/arch/x86/include/asm/rmwcc.h
18690+++ b/arch/x86/include/asm/rmwcc.h
18691@@ -3,7 +3,34 @@
18692
18693 #ifdef CC_HAVE_ASM_GOTO
18694
18695-#define __GEN_RMWcc(fullop, var, cc, ...) \
18696+#ifdef CONFIG_PAX_REFCOUNT
18697+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18698+do { \
18699+ asm_volatile_goto (fullop \
18700+ ";jno 0f\n" \
18701+ fullantiop \
18702+ ";int $4\n0:\n" \
18703+ _ASM_EXTABLE(0b, 0b) \
18704+ ";j" cc " %l[cc_label]" \
18705+ : : "m" (var), ## __VA_ARGS__ \
18706+ : "memory" : cc_label); \
18707+ return 0; \
18708+cc_label: \
18709+ return 1; \
18710+} while (0)
18711+#else
18712+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18713+do { \
18714+ asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
18715+ : : "m" (var), ## __VA_ARGS__ \
18716+ : "memory" : cc_label); \
18717+ return 0; \
18718+cc_label: \
18719+ return 1; \
18720+} while (0)
18721+#endif
18722+
18723+#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18724 do { \
18725 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
18726 : : "m" (var), ## __VA_ARGS__ \
18727@@ -13,15 +40,46 @@ cc_label: \
18728 return 1; \
18729 } while (0)
18730
18731-#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18732- __GEN_RMWcc(op " " arg0, var, cc)
18733+#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18734+ __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18735
18736-#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18737- __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
18738+#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18739+ __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18740+
18741+#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18742+ __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
18743+
18744+#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18745+ __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
18746
18747 #else /* !CC_HAVE_ASM_GOTO */
18748
18749-#define __GEN_RMWcc(fullop, var, cc, ...) \
18750+#ifdef CONFIG_PAX_REFCOUNT
18751+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18752+do { \
18753+ char c; \
18754+ asm volatile (fullop \
18755+ ";jno 0f\n" \
18756+ fullantiop \
18757+ ";int $4\n0:\n" \
18758+ _ASM_EXTABLE(0b, 0b) \
18759+ "; set" cc " %1" \
18760+ : "+m" (var), "=qm" (c) \
18761+ : __VA_ARGS__ : "memory"); \
18762+ return c != 0; \
18763+} while (0)
18764+#else
18765+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18766+do { \
18767+ char c; \
18768+ asm volatile (fullop "; set" cc " %1" \
18769+ : "+m" (var), "=qm" (c) \
18770+ : __VA_ARGS__ : "memory"); \
18771+ return c != 0; \
18772+} while (0)
18773+#endif
18774+
18775+#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18776 do { \
18777 char c; \
18778 asm volatile (fullop "; set" cc " %1" \
18779@@ -30,11 +88,17 @@ do { \
18780 return c != 0; \
18781 } while (0)
18782
18783-#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18784- __GEN_RMWcc(op " " arg0, var, cc)
18785+#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18786+ __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18787+
18788+#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18789+ __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18790+
18791+#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18792+ __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
18793
18794-#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18795- __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
18796+#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18797+ __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
18798
18799 #endif /* CC_HAVE_ASM_GOTO */
18800
18801diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
18802index cad82c9..2e5c5c1 100644
18803--- a/arch/x86/include/asm/rwsem.h
18804+++ b/arch/x86/include/asm/rwsem.h
18805@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
18806 {
18807 asm volatile("# beginning down_read\n\t"
18808 LOCK_PREFIX _ASM_INC "(%1)\n\t"
18809+
18810+#ifdef CONFIG_PAX_REFCOUNT
18811+ "jno 0f\n"
18812+ LOCK_PREFIX _ASM_DEC "(%1)\n"
18813+ "int $4\n0:\n"
18814+ _ASM_EXTABLE(0b, 0b)
18815+#endif
18816+
18817 /* adds 0x00000001 */
18818 " jns 1f\n"
18819 " call call_rwsem_down_read_failed\n"
18820@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
18821 "1:\n\t"
18822 " mov %1,%2\n\t"
18823 " add %3,%2\n\t"
18824+
18825+#ifdef CONFIG_PAX_REFCOUNT
18826+ "jno 0f\n"
18827+ "sub %3,%2\n"
18828+ "int $4\n0:\n"
18829+ _ASM_EXTABLE(0b, 0b)
18830+#endif
18831+
18832 " jle 2f\n\t"
18833 LOCK_PREFIX " cmpxchg %2,%0\n\t"
18834 " jnz 1b\n\t"
18835@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
18836 long tmp;
18837 asm volatile("# beginning down_write\n\t"
18838 LOCK_PREFIX " xadd %1,(%2)\n\t"
18839+
18840+#ifdef CONFIG_PAX_REFCOUNT
18841+ "jno 0f\n"
18842+ "mov %1,(%2)\n"
18843+ "int $4\n0:\n"
18844+ _ASM_EXTABLE(0b, 0b)
18845+#endif
18846+
18847 /* adds 0xffff0001, returns the old value */
18848 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
18849 /* was the active mask 0 before? */
18850@@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
18851 long tmp;
18852 asm volatile("# beginning __up_read\n\t"
18853 LOCK_PREFIX " xadd %1,(%2)\n\t"
18854+
18855+#ifdef CONFIG_PAX_REFCOUNT
18856+ "jno 0f\n"
18857+ "mov %1,(%2)\n"
18858+ "int $4\n0:\n"
18859+ _ASM_EXTABLE(0b, 0b)
18860+#endif
18861+
18862 /* subtracts 1, returns the old value */
18863 " jns 1f\n\t"
18864 " call call_rwsem_wake\n" /* expects old value in %edx */
18865@@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
18866 long tmp;
18867 asm volatile("# beginning __up_write\n\t"
18868 LOCK_PREFIX " xadd %1,(%2)\n\t"
18869+
18870+#ifdef CONFIG_PAX_REFCOUNT
18871+ "jno 0f\n"
18872+ "mov %1,(%2)\n"
18873+ "int $4\n0:\n"
18874+ _ASM_EXTABLE(0b, 0b)
18875+#endif
18876+
18877 /* subtracts 0xffff0001, returns the old value */
18878 " jns 1f\n\t"
18879 " call call_rwsem_wake\n" /* expects old value in %edx */
18880@@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18881 {
18882 asm volatile("# beginning __downgrade_write\n\t"
18883 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
18884+
18885+#ifdef CONFIG_PAX_REFCOUNT
18886+ "jno 0f\n"
18887+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
18888+ "int $4\n0:\n"
18889+ _ASM_EXTABLE(0b, 0b)
18890+#endif
18891+
18892 /*
18893 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
18894 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
18895@@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18896 */
18897 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18898 {
18899- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
18900+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
18901+
18902+#ifdef CONFIG_PAX_REFCOUNT
18903+ "jno 0f\n"
18904+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
18905+ "int $4\n0:\n"
18906+ _ASM_EXTABLE(0b, 0b)
18907+#endif
18908+
18909 : "+m" (sem->count)
18910 : "er" (delta));
18911 }
18912@@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18913 */
18914 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
18915 {
18916- return delta + xadd(&sem->count, delta);
18917+ return delta + xadd_check_overflow(&sem->count, delta);
18918 }
18919
18920 #endif /* __KERNEL__ */
18921diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
18922index 6f1c3a8..7744f19 100644
18923--- a/arch/x86/include/asm/segment.h
18924+++ b/arch/x86/include/asm/segment.h
18925@@ -64,10 +64,15 @@
18926 * 26 - ESPFIX small SS
18927 * 27 - per-cpu [ offset to per-cpu data area ]
18928 * 28 - stack_canary-20 [ for stack protector ]
18929- * 29 - unused
18930- * 30 - unused
18931+ * 29 - PCI BIOS CS
18932+ * 30 - PCI BIOS DS
18933 * 31 - TSS for double fault handler
18934 */
18935+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
18936+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
18937+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
18938+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
18939+
18940 #define GDT_ENTRY_TLS_MIN 6
18941 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
18942
18943@@ -79,6 +84,8 @@
18944
18945 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
18946
18947+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
18948+
18949 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
18950
18951 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
18952@@ -104,6 +111,12 @@
18953 #define __KERNEL_STACK_CANARY 0
18954 #endif
18955
18956+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
18957+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
18958+
18959+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
18960+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
18961+
18962 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
18963
18964 /*
18965@@ -141,7 +154,7 @@
18966 */
18967
18968 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
18969-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
18970+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
18971
18972
18973 #else
18974@@ -165,6 +178,8 @@
18975 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
18976 #define __USER32_DS __USER_DS
18977
18978+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
18979+
18980 #define GDT_ENTRY_TSS 8 /* needs two entries */
18981 #define GDT_ENTRY_LDT 10 /* needs two entries */
18982 #define GDT_ENTRY_TLS_MIN 12
18983@@ -173,6 +188,8 @@
18984 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
18985 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
18986
18987+#define GDT_ENTRY_UDEREF_KERNEL_DS 16
18988+
18989 /* TLS indexes for 64bit - hardcoded in arch_prctl */
18990 #define FS_TLS 0
18991 #define GS_TLS 1
18992@@ -180,12 +197,14 @@
18993 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
18994 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
18995
18996-#define GDT_ENTRIES 16
18997+#define GDT_ENTRIES 17
18998
18999 #endif
19000
19001 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
19002+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
19003 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
19004+#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
19005 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
19006 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
19007 #ifndef CONFIG_PARAVIRT
19008@@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
19009 {
19010 unsigned long __limit;
19011 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
19012- return __limit + 1;
19013+ return __limit;
19014 }
19015
19016 #endif /* !__ASSEMBLY__ */
19017diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
19018index 8d3120f..352b440 100644
19019--- a/arch/x86/include/asm/smap.h
19020+++ b/arch/x86/include/asm/smap.h
19021@@ -25,11 +25,40 @@
19022
19023 #include <asm/alternative-asm.h>
19024
19025+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19026+#define ASM_PAX_OPEN_USERLAND \
19027+ 661: jmp 663f; \
19028+ .pushsection .altinstr_replacement, "a" ; \
19029+ 662: pushq %rax; nop; \
19030+ .popsection ; \
19031+ .pushsection .altinstructions, "a" ; \
19032+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19033+ .popsection ; \
19034+ call __pax_open_userland; \
19035+ popq %rax; \
19036+ 663:
19037+
19038+#define ASM_PAX_CLOSE_USERLAND \
19039+ 661: jmp 663f; \
19040+ .pushsection .altinstr_replacement, "a" ; \
19041+ 662: pushq %rax; nop; \
19042+ .popsection; \
19043+ .pushsection .altinstructions, "a" ; \
19044+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19045+ .popsection; \
19046+ call __pax_close_userland; \
19047+ popq %rax; \
19048+ 663:
19049+#else
19050+#define ASM_PAX_OPEN_USERLAND
19051+#define ASM_PAX_CLOSE_USERLAND
19052+#endif
19053+
19054 #ifdef CONFIG_X86_SMAP
19055
19056 #define ASM_CLAC \
19057 661: ASM_NOP3 ; \
19058- .pushsection .altinstr_replacement, "ax" ; \
19059+ .pushsection .altinstr_replacement, "a" ; \
19060 662: __ASM_CLAC ; \
19061 .popsection ; \
19062 .pushsection .altinstructions, "a" ; \
19063@@ -38,7 +67,7 @@
19064
19065 #define ASM_STAC \
19066 661: ASM_NOP3 ; \
19067- .pushsection .altinstr_replacement, "ax" ; \
19068+ .pushsection .altinstr_replacement, "a" ; \
19069 662: __ASM_STAC ; \
19070 .popsection ; \
19071 .pushsection .altinstructions, "a" ; \
19072@@ -56,6 +85,37 @@
19073
19074 #include <asm/alternative.h>
19075
19076+#define __HAVE_ARCH_PAX_OPEN_USERLAND
19077+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
19078+
19079+extern void __pax_open_userland(void);
19080+static __always_inline unsigned long pax_open_userland(void)
19081+{
19082+
19083+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19084+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
19085+ :
19086+ : [open] "i" (__pax_open_userland)
19087+ : "memory", "rax");
19088+#endif
19089+
19090+ return 0;
19091+}
19092+
19093+extern void __pax_close_userland(void);
19094+static __always_inline unsigned long pax_close_userland(void)
19095+{
19096+
19097+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19098+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
19099+ :
19100+ : [close] "i" (__pax_close_userland)
19101+ : "memory", "rax");
19102+#endif
19103+
19104+ return 0;
19105+}
19106+
19107 #ifdef CONFIG_X86_SMAP
19108
19109 static __always_inline void clac(void)
19110diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
19111index 8cd27e0..7f05ec8 100644
19112--- a/arch/x86/include/asm/smp.h
19113+++ b/arch/x86/include/asm/smp.h
19114@@ -35,7 +35,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
19115 /* cpus sharing the last level cache: */
19116 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
19117 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
19118-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
19119+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
19120
19121 static inline struct cpumask *cpu_sibling_mask(int cpu)
19122 {
19123@@ -78,7 +78,7 @@ struct smp_ops {
19124
19125 void (*send_call_func_ipi)(const struct cpumask *mask);
19126 void (*send_call_func_single_ipi)(int cpu);
19127-};
19128+} __no_const;
19129
19130 /* Globals due to paravirt */
19131 extern void set_cpu_sibling_map(int cpu);
19132@@ -190,14 +190,8 @@ extern unsigned disabled_cpus;
19133 extern int safe_smp_processor_id(void);
19134
19135 #elif defined(CONFIG_X86_64_SMP)
19136-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19137-
19138-#define stack_smp_processor_id() \
19139-({ \
19140- struct thread_info *ti; \
19141- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
19142- ti->cpu; \
19143-})
19144+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19145+#define stack_smp_processor_id() raw_smp_processor_id()
19146 #define safe_smp_processor_id() smp_processor_id()
19147
19148 #endif
19149diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
19150index 0f62f54..cb5d0dd 100644
19151--- a/arch/x86/include/asm/spinlock.h
19152+++ b/arch/x86/include/asm/spinlock.h
19153@@ -222,6 +222,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
19154 static inline void arch_read_lock(arch_rwlock_t *rw)
19155 {
19156 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
19157+
19158+#ifdef CONFIG_PAX_REFCOUNT
19159+ "jno 0f\n"
19160+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
19161+ "int $4\n0:\n"
19162+ _ASM_EXTABLE(0b, 0b)
19163+#endif
19164+
19165 "jns 1f\n"
19166 "call __read_lock_failed\n\t"
19167 "1:\n"
19168@@ -231,6 +239,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
19169 static inline void arch_write_lock(arch_rwlock_t *rw)
19170 {
19171 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
19172+
19173+#ifdef CONFIG_PAX_REFCOUNT
19174+ "jno 0f\n"
19175+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
19176+ "int $4\n0:\n"
19177+ _ASM_EXTABLE(0b, 0b)
19178+#endif
19179+
19180 "jz 1f\n"
19181 "call __write_lock_failed\n\t"
19182 "1:\n"
19183@@ -260,13 +276,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
19184
19185 static inline void arch_read_unlock(arch_rwlock_t *rw)
19186 {
19187- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
19188+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
19189+
19190+#ifdef CONFIG_PAX_REFCOUNT
19191+ "jno 0f\n"
19192+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
19193+ "int $4\n0:\n"
19194+ _ASM_EXTABLE(0b, 0b)
19195+#endif
19196+
19197 :"+m" (rw->lock) : : "memory");
19198 }
19199
19200 static inline void arch_write_unlock(arch_rwlock_t *rw)
19201 {
19202- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
19203+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
19204+
19205+#ifdef CONFIG_PAX_REFCOUNT
19206+ "jno 0f\n"
19207+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
19208+ "int $4\n0:\n"
19209+ _ASM_EXTABLE(0b, 0b)
19210+#endif
19211+
19212 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
19213 }
19214
19215diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
19216index 6a99859..03cb807 100644
19217--- a/arch/x86/include/asm/stackprotector.h
19218+++ b/arch/x86/include/asm/stackprotector.h
19219@@ -47,7 +47,7 @@
19220 * head_32 for boot CPU and setup_per_cpu_areas() for others.
19221 */
19222 #define GDT_STACK_CANARY_INIT \
19223- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
19224+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
19225
19226 /*
19227 * Initialize the stackprotector canary value.
19228@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
19229
19230 static inline void load_stack_canary_segment(void)
19231 {
19232-#ifdef CONFIG_X86_32
19233+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
19234 asm volatile ("mov %0, %%gs" : : "r" (0));
19235 #endif
19236 }
19237diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
19238index 70bbe39..4ae2bd4 100644
19239--- a/arch/x86/include/asm/stacktrace.h
19240+++ b/arch/x86/include/asm/stacktrace.h
19241@@ -11,28 +11,20 @@
19242
19243 extern int kstack_depth_to_print;
19244
19245-struct thread_info;
19246+struct task_struct;
19247 struct stacktrace_ops;
19248
19249-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
19250- unsigned long *stack,
19251- unsigned long bp,
19252- const struct stacktrace_ops *ops,
19253- void *data,
19254- unsigned long *end,
19255- int *graph);
19256+typedef unsigned long walk_stack_t(struct task_struct *task,
19257+ void *stack_start,
19258+ unsigned long *stack,
19259+ unsigned long bp,
19260+ const struct stacktrace_ops *ops,
19261+ void *data,
19262+ unsigned long *end,
19263+ int *graph);
19264
19265-extern unsigned long
19266-print_context_stack(struct thread_info *tinfo,
19267- unsigned long *stack, unsigned long bp,
19268- const struct stacktrace_ops *ops, void *data,
19269- unsigned long *end, int *graph);
19270-
19271-extern unsigned long
19272-print_context_stack_bp(struct thread_info *tinfo,
19273- unsigned long *stack, unsigned long bp,
19274- const struct stacktrace_ops *ops, void *data,
19275- unsigned long *end, int *graph);
19276+extern walk_stack_t print_context_stack;
19277+extern walk_stack_t print_context_stack_bp;
19278
19279 /* Generic stack tracer with callbacks */
19280
19281@@ -40,7 +32,7 @@ struct stacktrace_ops {
19282 void (*address)(void *data, unsigned long address, int reliable);
19283 /* On negative return stop dumping */
19284 int (*stack)(void *data, char *name);
19285- walk_stack_t walk_stack;
19286+ walk_stack_t *walk_stack;
19287 };
19288
19289 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
19290diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
19291index d7f3b3b..3cc39f1 100644
19292--- a/arch/x86/include/asm/switch_to.h
19293+++ b/arch/x86/include/asm/switch_to.h
19294@@ -108,7 +108,7 @@ do { \
19295 "call __switch_to\n\t" \
19296 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
19297 __switch_canary \
19298- "movq %P[thread_info](%%rsi),%%r8\n\t" \
19299+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
19300 "movq %%rax,%%rdi\n\t" \
19301 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
19302 "jnz ret_from_fork\n\t" \
19303@@ -119,7 +119,7 @@ do { \
19304 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
19305 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
19306 [_tif_fork] "i" (_TIF_FORK), \
19307- [thread_info] "i" (offsetof(struct task_struct, stack)), \
19308+ [thread_info] "m" (current_tinfo), \
19309 [current_task] "m" (current_task) \
19310 __switch_canary_iparam \
19311 : "memory", "cc" __EXTRA_CLOBBER)
19312diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
19313index e1940c0..ac50dd8 100644
19314--- a/arch/x86/include/asm/thread_info.h
19315+++ b/arch/x86/include/asm/thread_info.h
19316@@ -10,6 +10,7 @@
19317 #include <linux/compiler.h>
19318 #include <asm/page.h>
19319 #include <asm/types.h>
19320+#include <asm/percpu.h>
19321
19322 /*
19323 * low level task data that entry.S needs immediate access to
19324@@ -23,7 +24,6 @@ struct exec_domain;
19325 #include <linux/atomic.h>
19326
19327 struct thread_info {
19328- struct task_struct *task; /* main task structure */
19329 struct exec_domain *exec_domain; /* execution domain */
19330 __u32 flags; /* low level flags */
19331 __u32 status; /* thread synchronous flags */
19332@@ -32,19 +32,13 @@ struct thread_info {
19333 mm_segment_t addr_limit;
19334 struct restart_block restart_block;
19335 void __user *sysenter_return;
19336-#ifdef CONFIG_X86_32
19337- unsigned long previous_esp; /* ESP of the previous stack in
19338- case of nested (IRQ) stacks
19339- */
19340- __u8 supervisor_stack[0];
19341-#endif
19342+ unsigned long lowest_stack;
19343 unsigned int sig_on_uaccess_error:1;
19344 unsigned int uaccess_err:1; /* uaccess failed */
19345 };
19346
19347-#define INIT_THREAD_INFO(tsk) \
19348+#define INIT_THREAD_INFO \
19349 { \
19350- .task = &tsk, \
19351 .exec_domain = &default_exec_domain, \
19352 .flags = 0, \
19353 .cpu = 0, \
19354@@ -55,7 +49,7 @@ struct thread_info {
19355 }, \
19356 }
19357
19358-#define init_thread_info (init_thread_union.thread_info)
19359+#define init_thread_info (init_thread_union.stack)
19360 #define init_stack (init_thread_union.stack)
19361
19362 #else /* !__ASSEMBLY__ */
19363@@ -95,6 +89,7 @@ struct thread_info {
19364 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
19365 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
19366 #define TIF_X32 30 /* 32-bit native x86-64 binary */
19367+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
19368
19369 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
19370 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
19371@@ -118,17 +113,18 @@ struct thread_info {
19372 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
19373 #define _TIF_ADDR32 (1 << TIF_ADDR32)
19374 #define _TIF_X32 (1 << TIF_X32)
19375+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
19376
19377 /* work to do in syscall_trace_enter() */
19378 #define _TIF_WORK_SYSCALL_ENTRY \
19379 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
19380 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
19381- _TIF_NOHZ)
19382+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
19383
19384 /* work to do in syscall_trace_leave() */
19385 #define _TIF_WORK_SYSCALL_EXIT \
19386 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
19387- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
19388+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
19389
19390 /* work to do on interrupt/exception return */
19391 #define _TIF_WORK_MASK \
19392@@ -139,7 +135,7 @@ struct thread_info {
19393 /* work to do on any return to user space */
19394 #define _TIF_ALLWORK_MASK \
19395 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
19396- _TIF_NOHZ)
19397+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
19398
19399 /* Only used for 64 bit */
19400 #define _TIF_DO_NOTIFY_MASK \
19401@@ -153,6 +149,23 @@ struct thread_info {
19402 #define _TIF_WORK_CTXSW_PREV (_TIF_WORK_CTXSW|_TIF_USER_RETURN_NOTIFY)
19403 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
19404
19405+#ifdef __ASSEMBLY__
19406+/* how to get the thread information struct from ASM */
19407+#define GET_THREAD_INFO(reg) \
19408+ mov PER_CPU_VAR(current_tinfo), reg
19409+
19410+/* use this one if reg already contains %esp */
19411+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
19412+#else
19413+/* how to get the thread information struct from C */
19414+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
19415+
19416+static __always_inline struct thread_info *current_thread_info(void)
19417+{
19418+ return this_cpu_read_stable(current_tinfo);
19419+}
19420+#endif
19421+
19422 #ifdef CONFIG_X86_32
19423
19424 #define STACK_WARN (THREAD_SIZE/8)
19425@@ -169,31 +182,10 @@ struct thread_info {
19426 sp; \
19427 })
19428
19429-/* how to get the thread information struct from C */
19430-static inline struct thread_info *current_thread_info(void)
19431-{
19432- return (struct thread_info *)
19433- (current_stack_pointer & ~(THREAD_SIZE - 1));
19434-}
19435-
19436-#else /* !__ASSEMBLY__ */
19437-
19438-/* how to get the thread information struct from ASM */
19439-#define GET_THREAD_INFO(reg) \
19440- movl $-THREAD_SIZE, reg; \
19441- andl %esp, reg
19442-
19443-/* use this one if reg already contains %esp */
19444-#define GET_THREAD_INFO_WITH_ESP(reg) \
19445- andl $-THREAD_SIZE, reg
19446-
19447 #endif
19448
19449 #else /* X86_32 */
19450
19451-#include <asm/percpu.h>
19452-#define KERNEL_STACK_OFFSET (5*8)
19453-
19454 /*
19455 * macros/functions for gaining access to the thread information structure
19456 * preempt_count needs to be 1 initially, until the scheduler is functional.
19457@@ -201,27 +193,8 @@ static inline struct thread_info *current_thread_info(void)
19458 #ifndef __ASSEMBLY__
19459 DECLARE_PER_CPU(unsigned long, kernel_stack);
19460
19461-static inline struct thread_info *current_thread_info(void)
19462-{
19463- struct thread_info *ti;
19464- ti = (void *)(this_cpu_read_stable(kernel_stack) +
19465- KERNEL_STACK_OFFSET - THREAD_SIZE);
19466- return ti;
19467-}
19468-
19469-#else /* !__ASSEMBLY__ */
19470-
19471-/* how to get the thread information struct from ASM */
19472-#define GET_THREAD_INFO(reg) \
19473- movq PER_CPU_VAR(kernel_stack),reg ; \
19474- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
19475-
19476-/*
19477- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
19478- * a certain register (to be used in assembler memory operands).
19479- */
19480-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
19481-
19482+/* how to get the current stack pointer from C */
19483+register unsigned long current_stack_pointer asm("rsp") __used;
19484 #endif
19485
19486 #endif /* !X86_32 */
19487@@ -280,5 +253,12 @@ static inline bool is_ia32_task(void)
19488 extern void arch_task_cache_init(void);
19489 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
19490 extern void arch_release_task_struct(struct task_struct *tsk);
19491+
19492+#define __HAVE_THREAD_FUNCTIONS
19493+#define task_thread_info(task) (&(task)->tinfo)
19494+#define task_stack_page(task) ((task)->stack)
19495+#define setup_thread_stack(p, org) do {} while (0)
19496+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
19497+
19498 #endif
19499 #endif /* _ASM_X86_THREAD_INFO_H */
19500diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
19501index 04905bf..49203ca 100644
19502--- a/arch/x86/include/asm/tlbflush.h
19503+++ b/arch/x86/include/asm/tlbflush.h
19504@@ -17,18 +17,44 @@
19505
19506 static inline void __native_flush_tlb(void)
19507 {
19508+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19509+ u64 descriptor[2];
19510+
19511+ descriptor[0] = PCID_KERNEL;
19512+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
19513+ return;
19514+ }
19515+
19516+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19517+ if (static_cpu_has(X86_FEATURE_PCID)) {
19518+ unsigned int cpu = raw_get_cpu();
19519+
19520+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
19521+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
19522+ raw_put_cpu_no_resched();
19523+ return;
19524+ }
19525+#endif
19526+
19527 native_write_cr3(native_read_cr3());
19528 }
19529
19530 static inline void __native_flush_tlb_global_irq_disabled(void)
19531 {
19532- unsigned long cr4;
19533+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19534+ u64 descriptor[2];
19535
19536- cr4 = native_read_cr4();
19537- /* clear PGE */
19538- native_write_cr4(cr4 & ~X86_CR4_PGE);
19539- /* write old PGE again and flush TLBs */
19540- native_write_cr4(cr4);
19541+ descriptor[0] = PCID_KERNEL;
19542+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
19543+ } else {
19544+ unsigned long cr4;
19545+
19546+ cr4 = native_read_cr4();
19547+ /* clear PGE */
19548+ native_write_cr4(cr4 & ~X86_CR4_PGE);
19549+ /* write old PGE again and flush TLBs */
19550+ native_write_cr4(cr4);
19551+ }
19552 }
19553
19554 static inline void __native_flush_tlb_global(void)
19555@@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
19556
19557 static inline void __native_flush_tlb_single(unsigned long addr)
19558 {
19559+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19560+ u64 descriptor[2];
19561+
19562+ descriptor[0] = PCID_KERNEL;
19563+ descriptor[1] = addr;
19564+
19565+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19566+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
19567+ if (addr < TASK_SIZE_MAX)
19568+ descriptor[1] += pax_user_shadow_base;
19569+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19570+ }
19571+
19572+ descriptor[0] = PCID_USER;
19573+ descriptor[1] = addr;
19574+#endif
19575+
19576+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19577+ return;
19578+ }
19579+
19580+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19581+ if (static_cpu_has(X86_FEATURE_PCID)) {
19582+ unsigned int cpu = raw_get_cpu();
19583+
19584+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
19585+ asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19586+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
19587+ raw_put_cpu_no_resched();
19588+
19589+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
19590+ addr += pax_user_shadow_base;
19591+ }
19592+#endif
19593+
19594 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19595 }
19596
19597diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
19598index 0d592e0..f58a222 100644
19599--- a/arch/x86/include/asm/uaccess.h
19600+++ b/arch/x86/include/asm/uaccess.h
19601@@ -7,6 +7,7 @@
19602 #include <linux/compiler.h>
19603 #include <linux/thread_info.h>
19604 #include <linux/string.h>
19605+#include <linux/spinlock.h>
19606 #include <asm/asm.h>
19607 #include <asm/page.h>
19608 #include <asm/smap.h>
19609@@ -29,7 +30,12 @@
19610
19611 #define get_ds() (KERNEL_DS)
19612 #define get_fs() (current_thread_info()->addr_limit)
19613+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19614+void __set_fs(mm_segment_t x);
19615+void set_fs(mm_segment_t x);
19616+#else
19617 #define set_fs(x) (current_thread_info()->addr_limit = (x))
19618+#endif
19619
19620 #define segment_eq(a, b) ((a).seg == (b).seg)
19621
19622@@ -85,8 +91,34 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un
19623 * checks that the pointer is in the user space range - after calling
19624 * this function, memory access functions may still return -EFAULT.
19625 */
19626-#define access_ok(type, addr, size) \
19627- likely(!__range_not_ok(addr, size, user_addr_max()))
19628+extern int _cond_resched(void);
19629+#define access_ok_noprefault(type, addr, size) (likely(!__range_not_ok(addr, size, user_addr_max())))
19630+#define access_ok(type, addr, size) \
19631+({ \
19632+ long __size = size; \
19633+ unsigned long __addr = (unsigned long)addr; \
19634+ unsigned long __addr_ao = __addr & PAGE_MASK; \
19635+ unsigned long __end_ao = __addr + __size - 1; \
19636+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
19637+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
19638+ while(__addr_ao <= __end_ao) { \
19639+ char __c_ao; \
19640+ __addr_ao += PAGE_SIZE; \
19641+ if (__size > PAGE_SIZE) \
19642+ _cond_resched(); \
19643+ if (__get_user(__c_ao, (char __user *)__addr)) \
19644+ break; \
19645+ if (type != VERIFY_WRITE) { \
19646+ __addr = __addr_ao; \
19647+ continue; \
19648+ } \
19649+ if (__put_user(__c_ao, (char __user *)__addr)) \
19650+ break; \
19651+ __addr = __addr_ao; \
19652+ } \
19653+ } \
19654+ __ret_ao; \
19655+})
19656
19657 /*
19658 * The exception table consists of pairs of addresses relative to the
19659@@ -176,10 +208,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19660 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
19661 __chk_user_ptr(ptr); \
19662 might_fault(); \
19663+ pax_open_userland(); \
19664 asm volatile("call __get_user_%P3" \
19665 : "=a" (__ret_gu), "=r" (__val_gu) \
19666 : "0" (ptr), "i" (sizeof(*(ptr)))); \
19667 (x) = (__typeof__(*(ptr))) __val_gu; \
19668+ pax_close_userland(); \
19669 __ret_gu; \
19670 })
19671
19672@@ -187,13 +221,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19673 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
19674 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
19675
19676-
19677+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19678+#define __copyuser_seg "gs;"
19679+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
19680+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
19681+#else
19682+#define __copyuser_seg
19683+#define __COPYUSER_SET_ES
19684+#define __COPYUSER_RESTORE_ES
19685+#endif
19686
19687 #ifdef CONFIG_X86_32
19688 #define __put_user_asm_u64(x, addr, err, errret) \
19689 asm volatile(ASM_STAC "\n" \
19690- "1: movl %%eax,0(%2)\n" \
19691- "2: movl %%edx,4(%2)\n" \
19692+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
19693+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
19694 "3: " ASM_CLAC "\n" \
19695 ".section .fixup,\"ax\"\n" \
19696 "4: movl %3,%0\n" \
19697@@ -206,8 +248,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19698
19699 #define __put_user_asm_ex_u64(x, addr) \
19700 asm volatile(ASM_STAC "\n" \
19701- "1: movl %%eax,0(%1)\n" \
19702- "2: movl %%edx,4(%1)\n" \
19703+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
19704+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
19705 "3: " ASM_CLAC "\n" \
19706 _ASM_EXTABLE_EX(1b, 2b) \
19707 _ASM_EXTABLE_EX(2b, 3b) \
19708@@ -257,7 +299,8 @@ extern void __put_user_8(void);
19709 __typeof__(*(ptr)) __pu_val; \
19710 __chk_user_ptr(ptr); \
19711 might_fault(); \
19712- __pu_val = x; \
19713+ __pu_val = (x); \
19714+ pax_open_userland(); \
19715 switch (sizeof(*(ptr))) { \
19716 case 1: \
19717 __put_user_x(1, __pu_val, ptr, __ret_pu); \
19718@@ -275,6 +318,7 @@ extern void __put_user_8(void);
19719 __put_user_x(X, __pu_val, ptr, __ret_pu); \
19720 break; \
19721 } \
19722+ pax_close_userland(); \
19723 __ret_pu; \
19724 })
19725
19726@@ -355,8 +399,10 @@ do { \
19727 } while (0)
19728
19729 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19730+do { \
19731+ pax_open_userland(); \
19732 asm volatile(ASM_STAC "\n" \
19733- "1: mov"itype" %2,%"rtype"1\n" \
19734+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
19735 "2: " ASM_CLAC "\n" \
19736 ".section .fixup,\"ax\"\n" \
19737 "3: mov %3,%0\n" \
19738@@ -364,8 +410,10 @@ do { \
19739 " jmp 2b\n" \
19740 ".previous\n" \
19741 _ASM_EXTABLE(1b, 3b) \
19742- : "=r" (err), ltype(x) \
19743- : "m" (__m(addr)), "i" (errret), "0" (err))
19744+ : "=r" (err), ltype (x) \
19745+ : "m" (__m(addr)), "i" (errret), "0" (err)); \
19746+ pax_close_userland(); \
19747+} while (0)
19748
19749 #define __get_user_size_ex(x, ptr, size) \
19750 do { \
19751@@ -389,7 +437,7 @@ do { \
19752 } while (0)
19753
19754 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
19755- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
19756+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
19757 "2:\n" \
19758 _ASM_EXTABLE_EX(1b, 2b) \
19759 : ltype(x) : "m" (__m(addr)))
19760@@ -406,13 +454,24 @@ do { \
19761 int __gu_err; \
19762 unsigned long __gu_val; \
19763 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
19764- (x) = (__force __typeof__(*(ptr)))__gu_val; \
19765+ (x) = (__typeof__(*(ptr)))__gu_val; \
19766 __gu_err; \
19767 })
19768
19769 /* FIXME: this hack is definitely wrong -AK */
19770 struct __large_struct { unsigned long buf[100]; };
19771-#define __m(x) (*(struct __large_struct __user *)(x))
19772+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19773+#define ____m(x) \
19774+({ \
19775+ unsigned long ____x = (unsigned long)(x); \
19776+ if (____x < pax_user_shadow_base) \
19777+ ____x += pax_user_shadow_base; \
19778+ (typeof(x))____x; \
19779+})
19780+#else
19781+#define ____m(x) (x)
19782+#endif
19783+#define __m(x) (*(struct __large_struct __user *)____m(x))
19784
19785 /*
19786 * Tell gcc we read from memory instead of writing: this is because
19787@@ -420,8 +479,10 @@ struct __large_struct { unsigned long buf[100]; };
19788 * aliasing issues.
19789 */
19790 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19791+do { \
19792+ pax_open_userland(); \
19793 asm volatile(ASM_STAC "\n" \
19794- "1: mov"itype" %"rtype"1,%2\n" \
19795+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
19796 "2: " ASM_CLAC "\n" \
19797 ".section .fixup,\"ax\"\n" \
19798 "3: mov %3,%0\n" \
19799@@ -429,10 +490,12 @@ struct __large_struct { unsigned long buf[100]; };
19800 ".previous\n" \
19801 _ASM_EXTABLE(1b, 3b) \
19802 : "=r"(err) \
19803- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
19804+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
19805+ pax_close_userland(); \
19806+} while (0)
19807
19808 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
19809- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
19810+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
19811 "2:\n" \
19812 _ASM_EXTABLE_EX(1b, 2b) \
19813 : : ltype(x), "m" (__m(addr)))
19814@@ -442,11 +505,13 @@ struct __large_struct { unsigned long buf[100]; };
19815 */
19816 #define uaccess_try do { \
19817 current_thread_info()->uaccess_err = 0; \
19818+ pax_open_userland(); \
19819 stac(); \
19820 barrier();
19821
19822 #define uaccess_catch(err) \
19823 clac(); \
19824+ pax_close_userland(); \
19825 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
19826 } while (0)
19827
19828@@ -471,8 +536,12 @@ struct __large_struct { unsigned long buf[100]; };
19829 * On error, the variable @x is set to zero.
19830 */
19831
19832+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19833+#define __get_user(x, ptr) get_user((x), (ptr))
19834+#else
19835 #define __get_user(x, ptr) \
19836 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
19837+#endif
19838
19839 /**
19840 * __put_user: - Write a simple value into user space, with less checking.
19841@@ -494,8 +563,12 @@ struct __large_struct { unsigned long buf[100]; };
19842 * Returns zero on success, or -EFAULT on error.
19843 */
19844
19845+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19846+#define __put_user(x, ptr) put_user((x), (ptr))
19847+#else
19848 #define __put_user(x, ptr) \
19849 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
19850+#endif
19851
19852 #define __get_user_unaligned __get_user
19853 #define __put_user_unaligned __put_user
19854@@ -513,7 +586,7 @@ struct __large_struct { unsigned long buf[100]; };
19855 #define get_user_ex(x, ptr) do { \
19856 unsigned long __gue_val; \
19857 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
19858- (x) = (__force __typeof__(*(ptr)))__gue_val; \
19859+ (x) = (__typeof__(*(ptr)))__gue_val; \
19860 } while (0)
19861
19862 #define put_user_try uaccess_try
19863@@ -542,18 +615,19 @@ extern void __cmpxchg_wrong_size(void)
19864 __typeof__(ptr) __uval = (uval); \
19865 __typeof__(*(ptr)) __old = (old); \
19866 __typeof__(*(ptr)) __new = (new); \
19867+ pax_open_userland(); \
19868 switch (size) { \
19869 case 1: \
19870 { \
19871 asm volatile("\t" ASM_STAC "\n" \
19872- "1:\t" LOCK_PREFIX "cmpxchgb %4, %2\n" \
19873+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgb %4, %2\n"\
19874 "2:\t" ASM_CLAC "\n" \
19875 "\t.section .fixup, \"ax\"\n" \
19876 "3:\tmov %3, %0\n" \
19877 "\tjmp 2b\n" \
19878 "\t.previous\n" \
19879 _ASM_EXTABLE(1b, 3b) \
19880- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19881+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19882 : "i" (-EFAULT), "q" (__new), "1" (__old) \
19883 : "memory" \
19884 ); \
19885@@ -562,14 +636,14 @@ extern void __cmpxchg_wrong_size(void)
19886 case 2: \
19887 { \
19888 asm volatile("\t" ASM_STAC "\n" \
19889- "1:\t" LOCK_PREFIX "cmpxchgw %4, %2\n" \
19890+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgw %4, %2\n"\
19891 "2:\t" ASM_CLAC "\n" \
19892 "\t.section .fixup, \"ax\"\n" \
19893 "3:\tmov %3, %0\n" \
19894 "\tjmp 2b\n" \
19895 "\t.previous\n" \
19896 _ASM_EXTABLE(1b, 3b) \
19897- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19898+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19899 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19900 : "memory" \
19901 ); \
19902@@ -578,14 +652,14 @@ extern void __cmpxchg_wrong_size(void)
19903 case 4: \
19904 { \
19905 asm volatile("\t" ASM_STAC "\n" \
19906- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n" \
19907+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"\
19908 "2:\t" ASM_CLAC "\n" \
19909 "\t.section .fixup, \"ax\"\n" \
19910 "3:\tmov %3, %0\n" \
19911 "\tjmp 2b\n" \
19912 "\t.previous\n" \
19913 _ASM_EXTABLE(1b, 3b) \
19914- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19915+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19916 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19917 : "memory" \
19918 ); \
19919@@ -597,14 +671,14 @@ extern void __cmpxchg_wrong_size(void)
19920 __cmpxchg_wrong_size(); \
19921 \
19922 asm volatile("\t" ASM_STAC "\n" \
19923- "1:\t" LOCK_PREFIX "cmpxchgq %4, %2\n" \
19924+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgq %4, %2\n"\
19925 "2:\t" ASM_CLAC "\n" \
19926 "\t.section .fixup, \"ax\"\n" \
19927 "3:\tmov %3, %0\n" \
19928 "\tjmp 2b\n" \
19929 "\t.previous\n" \
19930 _ASM_EXTABLE(1b, 3b) \
19931- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19932+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19933 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19934 : "memory" \
19935 ); \
19936@@ -613,6 +687,7 @@ extern void __cmpxchg_wrong_size(void)
19937 default: \
19938 __cmpxchg_wrong_size(); \
19939 } \
19940+ pax_close_userland(); \
19941 *__uval = __old; \
19942 __ret; \
19943 })
19944@@ -636,17 +711,6 @@ extern struct movsl_mask {
19945
19946 #define ARCH_HAS_NOCACHE_UACCESS 1
19947
19948-#ifdef CONFIG_X86_32
19949-# include <asm/uaccess_32.h>
19950-#else
19951-# include <asm/uaccess_64.h>
19952-#endif
19953-
19954-unsigned long __must_check _copy_from_user(void *to, const void __user *from,
19955- unsigned n);
19956-unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19957- unsigned n);
19958-
19959 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19960 # define copy_user_diag __compiletime_error
19961 #else
19962@@ -656,7 +720,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19963 extern void copy_user_diag("copy_from_user() buffer size is too small")
19964 copy_from_user_overflow(void);
19965 extern void copy_user_diag("copy_to_user() buffer size is too small")
19966-copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19967+copy_to_user_overflow(void);
19968
19969 #undef copy_user_diag
19970
19971@@ -669,7 +733,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
19972
19973 extern void
19974 __compiletime_warning("copy_to_user() buffer size is not provably correct")
19975-__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19976+__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
19977 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
19978
19979 #else
19980@@ -684,10 +748,16 @@ __copy_from_user_overflow(int size, unsigned long count)
19981
19982 #endif
19983
19984+#ifdef CONFIG_X86_32
19985+# include <asm/uaccess_32.h>
19986+#else
19987+# include <asm/uaccess_64.h>
19988+#endif
19989+
19990 static inline unsigned long __must_check
19991 copy_from_user(void *to, const void __user *from, unsigned long n)
19992 {
19993- int sz = __compiletime_object_size(to);
19994+ size_t sz = __compiletime_object_size(to);
19995
19996 might_fault();
19997
19998@@ -709,12 +779,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19999 * case, and do only runtime checking for non-constant sizes.
20000 */
20001
20002- if (likely(sz < 0 || sz >= n))
20003- n = _copy_from_user(to, from, n);
20004- else if(__builtin_constant_p(n))
20005- copy_from_user_overflow();
20006- else
20007- __copy_from_user_overflow(sz, n);
20008+ if (likely(sz != (size_t)-1 && sz < n)) {
20009+ if(__builtin_constant_p(n))
20010+ copy_from_user_overflow();
20011+ else
20012+ __copy_from_user_overflow(sz, n);
20013+ } if (access_ok(VERIFY_READ, from, n))
20014+ n = __copy_from_user(to, from, n);
20015+ else if ((long)n > 0)
20016+ memset(to, 0, n);
20017
20018 return n;
20019 }
20020@@ -722,17 +795,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
20021 static inline unsigned long __must_check
20022 copy_to_user(void __user *to, const void *from, unsigned long n)
20023 {
20024- int sz = __compiletime_object_size(from);
20025+ size_t sz = __compiletime_object_size(from);
20026
20027 might_fault();
20028
20029 /* See the comment in copy_from_user() above. */
20030- if (likely(sz < 0 || sz >= n))
20031- n = _copy_to_user(to, from, n);
20032- else if(__builtin_constant_p(n))
20033- copy_to_user_overflow();
20034- else
20035- __copy_to_user_overflow(sz, n);
20036+ if (likely(sz != (size_t)-1 && sz < n)) {
20037+ if(__builtin_constant_p(n))
20038+ copy_to_user_overflow();
20039+ else
20040+ __copy_to_user_overflow(sz, n);
20041+ } else if (access_ok(VERIFY_WRITE, to, n))
20042+ n = __copy_to_user(to, from, n);
20043
20044 return n;
20045 }
20046diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
20047index 3c03a5d..1071638 100644
20048--- a/arch/x86/include/asm/uaccess_32.h
20049+++ b/arch/x86/include/asm/uaccess_32.h
20050@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
20051 static __always_inline unsigned long __must_check
20052 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
20053 {
20054+ if ((long)n < 0)
20055+ return n;
20056+
20057+ check_object_size(from, n, true);
20058+
20059 if (__builtin_constant_p(n)) {
20060 unsigned long ret;
20061
20062@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
20063 __copy_to_user(void __user *to, const void *from, unsigned long n)
20064 {
20065 might_fault();
20066+
20067 return __copy_to_user_inatomic(to, from, n);
20068 }
20069
20070 static __always_inline unsigned long
20071 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
20072 {
20073+ if ((long)n < 0)
20074+ return n;
20075+
20076 /* Avoid zeroing the tail if the copy fails..
20077 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
20078 * but as the zeroing behaviour is only significant when n is not
20079@@ -137,6 +146,12 @@ static __always_inline unsigned long
20080 __copy_from_user(void *to, const void __user *from, unsigned long n)
20081 {
20082 might_fault();
20083+
20084+ if ((long)n < 0)
20085+ return n;
20086+
20087+ check_object_size(to, n, false);
20088+
20089 if (__builtin_constant_p(n)) {
20090 unsigned long ret;
20091
20092@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
20093 const void __user *from, unsigned long n)
20094 {
20095 might_fault();
20096+
20097+ if ((long)n < 0)
20098+ return n;
20099+
20100 if (__builtin_constant_p(n)) {
20101 unsigned long ret;
20102
20103@@ -181,7 +200,10 @@ static __always_inline unsigned long
20104 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
20105 unsigned long n)
20106 {
20107- return __copy_from_user_ll_nocache_nozero(to, from, n);
20108+ if ((long)n < 0)
20109+ return n;
20110+
20111+ return __copy_from_user_ll_nocache_nozero(to, from, n);
20112 }
20113
20114 #endif /* _ASM_X86_UACCESS_32_H */
20115diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
20116index 12a26b9..206c200 100644
20117--- a/arch/x86/include/asm/uaccess_64.h
20118+++ b/arch/x86/include/asm/uaccess_64.h
20119@@ -10,6 +10,9 @@
20120 #include <asm/alternative.h>
20121 #include <asm/cpufeature.h>
20122 #include <asm/page.h>
20123+#include <asm/pgtable.h>
20124+
20125+#define set_fs(x) (current_thread_info()->addr_limit = (x))
20126
20127 /*
20128 * Copy To/From Userspace
20129@@ -17,14 +20,14 @@
20130
20131 /* Handles exceptions in both to and from, but doesn't do access_ok */
20132 __must_check unsigned long
20133-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
20134+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
20135 __must_check unsigned long
20136-copy_user_generic_string(void *to, const void *from, unsigned len);
20137+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
20138 __must_check unsigned long
20139-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
20140+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
20141
20142 static __always_inline __must_check unsigned long
20143-copy_user_generic(void *to, const void *from, unsigned len)
20144+copy_user_generic(void *to, const void *from, unsigned long len)
20145 {
20146 unsigned ret;
20147
20148@@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
20149 }
20150
20151 __must_check unsigned long
20152-copy_in_user(void __user *to, const void __user *from, unsigned len);
20153+copy_in_user(void __user *to, const void __user *from, unsigned long len);
20154
20155 static __always_inline __must_check
20156-int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
20157+unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
20158 {
20159- int ret = 0;
20160+ size_t sz = __compiletime_object_size(dst);
20161+ unsigned ret = 0;
20162+
20163+ if (size > INT_MAX)
20164+ return size;
20165+
20166+ check_object_size(dst, size, false);
20167+
20168+#ifdef CONFIG_PAX_MEMORY_UDEREF
20169+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20170+ return size;
20171+#endif
20172+
20173+ if (unlikely(sz != (size_t)-1 && sz < size)) {
20174+ if(__builtin_constant_p(size))
20175+ copy_from_user_overflow();
20176+ else
20177+ __copy_from_user_overflow(sz, size);
20178+ return size;
20179+ }
20180
20181 if (!__builtin_constant_p(size))
20182- return copy_user_generic(dst, (__force void *)src, size);
20183+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20184 switch (size) {
20185- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
20186+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
20187 ret, "b", "b", "=q", 1);
20188 return ret;
20189- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
20190+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
20191 ret, "w", "w", "=r", 2);
20192 return ret;
20193- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
20194+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
20195 ret, "l", "k", "=r", 4);
20196 return ret;
20197- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
20198+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20199 ret, "q", "", "=r", 8);
20200 return ret;
20201 case 10:
20202- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
20203+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20204 ret, "q", "", "=r", 10);
20205 if (unlikely(ret))
20206 return ret;
20207 __get_user_asm(*(u16 *)(8 + (char *)dst),
20208- (u16 __user *)(8 + (char __user *)src),
20209+ (const u16 __user *)(8 + (const char __user *)src),
20210 ret, "w", "w", "=r", 2);
20211 return ret;
20212 case 16:
20213- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
20214+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20215 ret, "q", "", "=r", 16);
20216 if (unlikely(ret))
20217 return ret;
20218 __get_user_asm(*(u64 *)(8 + (char *)dst),
20219- (u64 __user *)(8 + (char __user *)src),
20220+ (const u64 __user *)(8 + (const char __user *)src),
20221 ret, "q", "", "=r", 8);
20222 return ret;
20223 default:
20224- return copy_user_generic(dst, (__force void *)src, size);
20225+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20226 }
20227 }
20228
20229 static __always_inline __must_check
20230-int __copy_from_user(void *dst, const void __user *src, unsigned size)
20231+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
20232 {
20233 might_fault();
20234 return __copy_from_user_nocheck(dst, src, size);
20235 }
20236
20237 static __always_inline __must_check
20238-int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
20239+unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
20240 {
20241- int ret = 0;
20242+ size_t sz = __compiletime_object_size(src);
20243+ unsigned ret = 0;
20244+
20245+ if (size > INT_MAX)
20246+ return size;
20247+
20248+ check_object_size(src, size, true);
20249+
20250+#ifdef CONFIG_PAX_MEMORY_UDEREF
20251+ if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20252+ return size;
20253+#endif
20254+
20255+ if (unlikely(sz != (size_t)-1 && sz < size)) {
20256+ if(__builtin_constant_p(size))
20257+ copy_to_user_overflow();
20258+ else
20259+ __copy_to_user_overflow(sz, size);
20260+ return size;
20261+ }
20262
20263 if (!__builtin_constant_p(size))
20264- return copy_user_generic((__force void *)dst, src, size);
20265+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20266 switch (size) {
20267- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
20268+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
20269 ret, "b", "b", "iq", 1);
20270 return ret;
20271- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
20272+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
20273 ret, "w", "w", "ir", 2);
20274 return ret;
20275- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
20276+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
20277 ret, "l", "k", "ir", 4);
20278 return ret;
20279- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
20280+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20281 ret, "q", "", "er", 8);
20282 return ret;
20283 case 10:
20284- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20285+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20286 ret, "q", "", "er", 10);
20287 if (unlikely(ret))
20288 return ret;
20289 asm("":::"memory");
20290- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
20291+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
20292 ret, "w", "w", "ir", 2);
20293 return ret;
20294 case 16:
20295- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20296+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20297 ret, "q", "", "er", 16);
20298 if (unlikely(ret))
20299 return ret;
20300 asm("":::"memory");
20301- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
20302+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
20303 ret, "q", "", "er", 8);
20304 return ret;
20305 default:
20306- return copy_user_generic((__force void *)dst, src, size);
20307+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20308 }
20309 }
20310
20311 static __always_inline __must_check
20312-int __copy_to_user(void __user *dst, const void *src, unsigned size)
20313+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
20314 {
20315 might_fault();
20316 return __copy_to_user_nocheck(dst, src, size);
20317 }
20318
20319 static __always_inline __must_check
20320-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20321+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20322 {
20323- int ret = 0;
20324+ unsigned ret = 0;
20325
20326 might_fault();
20327+
20328+ if (size > INT_MAX)
20329+ return size;
20330+
20331+#ifdef CONFIG_PAX_MEMORY_UDEREF
20332+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20333+ return size;
20334+ if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20335+ return size;
20336+#endif
20337+
20338 if (!__builtin_constant_p(size))
20339- return copy_user_generic((__force void *)dst,
20340- (__force void *)src, size);
20341+ return copy_user_generic((__force_kernel void *)____m(dst),
20342+ (__force_kernel const void *)____m(src), size);
20343 switch (size) {
20344 case 1: {
20345 u8 tmp;
20346- __get_user_asm(tmp, (u8 __user *)src,
20347+ __get_user_asm(tmp, (const u8 __user *)src,
20348 ret, "b", "b", "=q", 1);
20349 if (likely(!ret))
20350 __put_user_asm(tmp, (u8 __user *)dst,
20351@@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20352 }
20353 case 2: {
20354 u16 tmp;
20355- __get_user_asm(tmp, (u16 __user *)src,
20356+ __get_user_asm(tmp, (const u16 __user *)src,
20357 ret, "w", "w", "=r", 2);
20358 if (likely(!ret))
20359 __put_user_asm(tmp, (u16 __user *)dst,
20360@@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20361
20362 case 4: {
20363 u32 tmp;
20364- __get_user_asm(tmp, (u32 __user *)src,
20365+ __get_user_asm(tmp, (const u32 __user *)src,
20366 ret, "l", "k", "=r", 4);
20367 if (likely(!ret))
20368 __put_user_asm(tmp, (u32 __user *)dst,
20369@@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20370 }
20371 case 8: {
20372 u64 tmp;
20373- __get_user_asm(tmp, (u64 __user *)src,
20374+ __get_user_asm(tmp, (const u64 __user *)src,
20375 ret, "q", "", "=r", 8);
20376 if (likely(!ret))
20377 __put_user_asm(tmp, (u64 __user *)dst,
20378@@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20379 return ret;
20380 }
20381 default:
20382- return copy_user_generic((__force void *)dst,
20383- (__force void *)src, size);
20384+ return copy_user_generic((__force_kernel void *)____m(dst),
20385+ (__force_kernel const void *)____m(src), size);
20386 }
20387 }
20388
20389-static __must_check __always_inline int
20390-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
20391+static __must_check __always_inline unsigned long
20392+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
20393 {
20394 return __copy_from_user_nocheck(dst, src, size);
20395 }
20396
20397-static __must_check __always_inline int
20398-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
20399+static __must_check __always_inline unsigned long
20400+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
20401 {
20402 return __copy_to_user_nocheck(dst, src, size);
20403 }
20404
20405-extern long __copy_user_nocache(void *dst, const void __user *src,
20406- unsigned size, int zerorest);
20407+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
20408+ unsigned long size, int zerorest);
20409
20410-static inline int
20411-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
20412+static inline unsigned long
20413+__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
20414 {
20415 might_fault();
20416+
20417+ if (size > INT_MAX)
20418+ return size;
20419+
20420+#ifdef CONFIG_PAX_MEMORY_UDEREF
20421+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20422+ return size;
20423+#endif
20424+
20425 return __copy_user_nocache(dst, src, size, 1);
20426 }
20427
20428-static inline int
20429+static inline unsigned long
20430 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
20431- unsigned size)
20432+ unsigned long size)
20433 {
20434+ if (size > INT_MAX)
20435+ return size;
20436+
20437+#ifdef CONFIG_PAX_MEMORY_UDEREF
20438+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20439+ return size;
20440+#endif
20441+
20442 return __copy_user_nocache(dst, src, size, 0);
20443 }
20444
20445 unsigned long
20446-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
20447+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
20448
20449 #endif /* _ASM_X86_UACCESS_64_H */
20450diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
20451index 5b238981..77fdd78 100644
20452--- a/arch/x86/include/asm/word-at-a-time.h
20453+++ b/arch/x86/include/asm/word-at-a-time.h
20454@@ -11,7 +11,7 @@
20455 * and shift, for example.
20456 */
20457 struct word_at_a_time {
20458- const unsigned long one_bits, high_bits;
20459+ unsigned long one_bits, high_bits;
20460 };
20461
20462 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
20463diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
20464index e45e4da..44e8572 100644
20465--- a/arch/x86/include/asm/x86_init.h
20466+++ b/arch/x86/include/asm/x86_init.h
20467@@ -129,7 +129,7 @@ struct x86_init_ops {
20468 struct x86_init_timers timers;
20469 struct x86_init_iommu iommu;
20470 struct x86_init_pci pci;
20471-};
20472+} __no_const;
20473
20474 /**
20475 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
20476@@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
20477 void (*setup_percpu_clockev)(void);
20478 void (*early_percpu_clock_init)(void);
20479 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
20480-};
20481+} __no_const;
20482
20483 struct timespec;
20484
20485@@ -168,7 +168,7 @@ struct x86_platform_ops {
20486 void (*save_sched_clock_state)(void);
20487 void (*restore_sched_clock_state)(void);
20488 void (*apic_post_init)(void);
20489-};
20490+} __no_const;
20491
20492 struct pci_dev;
20493 struct msi_msg;
20494@@ -185,7 +185,7 @@ struct x86_msi_ops {
20495 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
20496 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
20497 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
20498-};
20499+} __no_const;
20500
20501 struct IO_APIC_route_entry;
20502 struct io_apic_irq_attr;
20503@@ -206,7 +206,7 @@ struct x86_io_apic_ops {
20504 unsigned int destination, int vector,
20505 struct io_apic_irq_attr *attr);
20506 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
20507-};
20508+} __no_const;
20509
20510 extern struct x86_init_ops x86_init;
20511 extern struct x86_cpuinit_ops x86_cpuinit;
20512diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
20513index 3e276eb..2eb3c30 100644
20514--- a/arch/x86/include/asm/xen/page.h
20515+++ b/arch/x86/include/asm/xen/page.h
20516@@ -56,7 +56,7 @@ extern int m2p_remove_override(struct page *page,
20517 extern struct page *m2p_find_override(unsigned long mfn);
20518 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
20519
20520-static inline unsigned long pfn_to_mfn(unsigned long pfn)
20521+static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
20522 {
20523 unsigned long mfn;
20524
20525diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
20526index 6c1d741..39e6ecf 100644
20527--- a/arch/x86/include/asm/xsave.h
20528+++ b/arch/x86/include/asm/xsave.h
20529@@ -80,8 +80,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20530 if (unlikely(err))
20531 return -EFAULT;
20532
20533+ pax_open_userland();
20534 __asm__ __volatile__(ASM_STAC "\n"
20535- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
20536+ "1:"
20537+ __copyuser_seg
20538+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
20539 "2: " ASM_CLAC "\n"
20540 ".section .fixup,\"ax\"\n"
20541 "3: movl $-1,%[err]\n"
20542@@ -91,18 +94,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20543 : [err] "=r" (err)
20544 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
20545 : "memory");
20546+ pax_close_userland();
20547 return err;
20548 }
20549
20550 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20551 {
20552 int err;
20553- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
20554+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
20555 u32 lmask = mask;
20556 u32 hmask = mask >> 32;
20557
20558+ pax_open_userland();
20559 __asm__ __volatile__(ASM_STAC "\n"
20560- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20561+ "1:"
20562+ __copyuser_seg
20563+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20564 "2: " ASM_CLAC "\n"
20565 ".section .fixup,\"ax\"\n"
20566 "3: movl $-1,%[err]\n"
20567@@ -112,6 +119,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20568 : [err] "=r" (err)
20569 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
20570 : "memory"); /* memory required? */
20571+ pax_close_userland();
20572 return err;
20573 }
20574
20575diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
20576index bbae024..e1528f9 100644
20577--- a/arch/x86/include/uapi/asm/e820.h
20578+++ b/arch/x86/include/uapi/asm/e820.h
20579@@ -63,7 +63,7 @@ struct e820map {
20580 #define ISA_START_ADDRESS 0xa0000
20581 #define ISA_END_ADDRESS 0x100000
20582
20583-#define BIOS_BEGIN 0x000a0000
20584+#define BIOS_BEGIN 0x000c0000
20585 #define BIOS_END 0x00100000
20586
20587 #define BIOS_ROM_BASE 0xffe00000
20588diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
20589index 7b0a55a..ad115bf 100644
20590--- a/arch/x86/include/uapi/asm/ptrace-abi.h
20591+++ b/arch/x86/include/uapi/asm/ptrace-abi.h
20592@@ -49,7 +49,6 @@
20593 #define EFLAGS 144
20594 #define RSP 152
20595 #define SS 160
20596-#define ARGOFFSET R11
20597 #endif /* __ASSEMBLY__ */
20598
20599 /* top of stack page */
20600diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
20601index cb648c8..91cb07e 100644
20602--- a/arch/x86/kernel/Makefile
20603+++ b/arch/x86/kernel/Makefile
20604@@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
20605 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
20606 obj-$(CONFIG_IRQ_WORK) += irq_work.o
20607 obj-y += probe_roms.o
20608-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
20609+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
20610 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
20611 obj-y += syscall_$(BITS).o
20612 obj-$(CONFIG_X86_64) += vsyscall_64.o
20613diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
20614index 1dac942..19c8b0c 100644
20615--- a/arch/x86/kernel/acpi/boot.c
20616+++ b/arch/x86/kernel/acpi/boot.c
20617@@ -1312,7 +1312,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
20618 * If your system is blacklisted here, but you find that acpi=force
20619 * works for you, please contact linux-acpi@vger.kernel.org
20620 */
20621-static struct dmi_system_id __initdata acpi_dmi_table[] = {
20622+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
20623 /*
20624 * Boxes that need ACPI disabled
20625 */
20626@@ -1387,7 +1387,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
20627 };
20628
20629 /* second table for DMI checks that should run after early-quirks */
20630-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
20631+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
20632 /*
20633 * HP laptops which use a DSDT reporting as HP/SB400/10000,
20634 * which includes some code which overrides all temperature
20635diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
20636index 3a2ae4c..9db31d6 100644
20637--- a/arch/x86/kernel/acpi/sleep.c
20638+++ b/arch/x86/kernel/acpi/sleep.c
20639@@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
20640 #else /* CONFIG_64BIT */
20641 #ifdef CONFIG_SMP
20642 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
20643+
20644+ pax_open_kernel();
20645 early_gdt_descr.address =
20646 (unsigned long)get_cpu_gdt_table(smp_processor_id());
20647+ pax_close_kernel();
20648+
20649 initial_gs = per_cpu_offset(smp_processor_id());
20650 #endif
20651 initial_code = (unsigned long)wakeup_long64;
20652diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
20653index 665c6b7..eae4d56 100644
20654--- a/arch/x86/kernel/acpi/wakeup_32.S
20655+++ b/arch/x86/kernel/acpi/wakeup_32.S
20656@@ -29,13 +29,11 @@ wakeup_pmode_return:
20657 # and restore the stack ... but you need gdt for this to work
20658 movl saved_context_esp, %esp
20659
20660- movl %cs:saved_magic, %eax
20661- cmpl $0x12345678, %eax
20662+ cmpl $0x12345678, saved_magic
20663 jne bogus_magic
20664
20665 # jump to place where we left off
20666- movl saved_eip, %eax
20667- jmp *%eax
20668+ jmp *(saved_eip)
20669
20670 bogus_magic:
20671 jmp bogus_magic
20672diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
20673index df94598..f3b29bf 100644
20674--- a/arch/x86/kernel/alternative.c
20675+++ b/arch/x86/kernel/alternative.c
20676@@ -269,6 +269,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20677 */
20678 for (a = start; a < end; a++) {
20679 instr = (u8 *)&a->instr_offset + a->instr_offset;
20680+
20681+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20682+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20683+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20684+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20685+#endif
20686+
20687 replacement = (u8 *)&a->repl_offset + a->repl_offset;
20688 BUG_ON(a->replacementlen > a->instrlen);
20689 BUG_ON(a->instrlen > sizeof(insnbuf));
20690@@ -300,10 +307,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
20691 for (poff = start; poff < end; poff++) {
20692 u8 *ptr = (u8 *)poff + *poff;
20693
20694+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20695+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20696+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20697+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20698+#endif
20699+
20700 if (!*poff || ptr < text || ptr >= text_end)
20701 continue;
20702 /* turn DS segment override prefix into lock prefix */
20703- if (*ptr == 0x3e)
20704+ if (*ktla_ktva(ptr) == 0x3e)
20705 text_poke(ptr, ((unsigned char []){0xf0}), 1);
20706 }
20707 mutex_unlock(&text_mutex);
20708@@ -318,10 +331,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
20709 for (poff = start; poff < end; poff++) {
20710 u8 *ptr = (u8 *)poff + *poff;
20711
20712+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20713+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20714+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20715+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20716+#endif
20717+
20718 if (!*poff || ptr < text || ptr >= text_end)
20719 continue;
20720 /* turn lock prefix into DS segment override prefix */
20721- if (*ptr == 0xf0)
20722+ if (*ktla_ktva(ptr) == 0xf0)
20723 text_poke(ptr, ((unsigned char []){0x3E}), 1);
20724 }
20725 mutex_unlock(&text_mutex);
20726@@ -458,7 +477,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
20727
20728 BUG_ON(p->len > MAX_PATCH_LEN);
20729 /* prep the buffer with the original instructions */
20730- memcpy(insnbuf, p->instr, p->len);
20731+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
20732 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
20733 (unsigned long)p->instr, p->len);
20734
20735@@ -505,7 +524,7 @@ void __init alternative_instructions(void)
20736 if (!uniproc_patched || num_possible_cpus() == 1)
20737 free_init_pages("SMP alternatives",
20738 (unsigned long)__smp_locks,
20739- (unsigned long)__smp_locks_end);
20740+ PAGE_ALIGN((unsigned long)__smp_locks_end));
20741 #endif
20742
20743 apply_paravirt(__parainstructions, __parainstructions_end);
20744@@ -525,13 +544,17 @@ void __init alternative_instructions(void)
20745 * instructions. And on the local CPU you need to be protected again NMI or MCE
20746 * handlers seeing an inconsistent instruction while you patch.
20747 */
20748-void *__init_or_module text_poke_early(void *addr, const void *opcode,
20749+void *__kprobes text_poke_early(void *addr, const void *opcode,
20750 size_t len)
20751 {
20752 unsigned long flags;
20753 local_irq_save(flags);
20754- memcpy(addr, opcode, len);
20755+
20756+ pax_open_kernel();
20757+ memcpy(ktla_ktva(addr), opcode, len);
20758 sync_core();
20759+ pax_close_kernel();
20760+
20761 local_irq_restore(flags);
20762 /* Could also do a CLFLUSH here to speed up CPU recovery; but
20763 that causes hangs on some VIA CPUs. */
20764@@ -553,36 +576,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
20765 */
20766 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
20767 {
20768- unsigned long flags;
20769- char *vaddr;
20770+ unsigned char *vaddr = ktla_ktva(addr);
20771 struct page *pages[2];
20772- int i;
20773+ size_t i;
20774
20775 if (!core_kernel_text((unsigned long)addr)) {
20776- pages[0] = vmalloc_to_page(addr);
20777- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
20778+ pages[0] = vmalloc_to_page(vaddr);
20779+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
20780 } else {
20781- pages[0] = virt_to_page(addr);
20782+ pages[0] = virt_to_page(vaddr);
20783 WARN_ON(!PageReserved(pages[0]));
20784- pages[1] = virt_to_page(addr + PAGE_SIZE);
20785+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
20786 }
20787 BUG_ON(!pages[0]);
20788- local_irq_save(flags);
20789- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
20790- if (pages[1])
20791- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
20792- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
20793- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
20794- clear_fixmap(FIX_TEXT_POKE0);
20795- if (pages[1])
20796- clear_fixmap(FIX_TEXT_POKE1);
20797- local_flush_tlb();
20798- sync_core();
20799- /* Could also do a CLFLUSH here to speed up CPU recovery; but
20800- that causes hangs on some VIA CPUs. */
20801+ text_poke_early(addr, opcode, len);
20802 for (i = 0; i < len; i++)
20803- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
20804- local_irq_restore(flags);
20805+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
20806 return addr;
20807 }
20808
20809@@ -602,7 +611,7 @@ int poke_int3_handler(struct pt_regs *regs)
20810 if (likely(!bp_patching_in_progress))
20811 return 0;
20812
20813- if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
20814+ if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
20815 return 0;
20816
20817 /* set up the specified breakpoint handler */
20818@@ -636,7 +645,7 @@ int poke_int3_handler(struct pt_regs *regs)
20819 */
20820 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
20821 {
20822- unsigned char int3 = 0xcc;
20823+ const unsigned char int3 = 0xcc;
20824
20825 bp_int3_handler = handler;
20826 bp_int3_addr = (u8 *)addr + sizeof(int3);
20827diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
20828index 7f26c9a..694544e 100644
20829--- a/arch/x86/kernel/apic/apic.c
20830+++ b/arch/x86/kernel/apic/apic.c
20831@@ -198,7 +198,7 @@ int first_system_vector = 0xfe;
20832 /*
20833 * Debug level, exported for io_apic.c
20834 */
20835-unsigned int apic_verbosity;
20836+int apic_verbosity;
20837
20838 int pic_mode;
20839
20840@@ -1992,7 +1992,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
20841 apic_write(APIC_ESR, 0);
20842 v = apic_read(APIC_ESR);
20843 ack_APIC_irq();
20844- atomic_inc(&irq_err_count);
20845+ atomic_inc_unchecked(&irq_err_count);
20846
20847 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x",
20848 smp_processor_id(), v);
20849diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
20850index 2c621a6..fa2b1ae 100644
20851--- a/arch/x86/kernel/apic/apic_flat_64.c
20852+++ b/arch/x86/kernel/apic/apic_flat_64.c
20853@@ -154,7 +154,7 @@ static int flat_probe(void)
20854 return 1;
20855 }
20856
20857-static struct apic apic_flat = {
20858+static struct apic apic_flat __read_only = {
20859 .name = "flat",
20860 .probe = flat_probe,
20861 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
20862@@ -268,7 +268,7 @@ static int physflat_probe(void)
20863 return 0;
20864 }
20865
20866-static struct apic apic_physflat = {
20867+static struct apic apic_physflat __read_only = {
20868
20869 .name = "physical flat",
20870 .probe = physflat_probe,
20871diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
20872index 191ce75..2db6d63 100644
20873--- a/arch/x86/kernel/apic/apic_noop.c
20874+++ b/arch/x86/kernel/apic/apic_noop.c
20875@@ -118,7 +118,7 @@ static void noop_apic_write(u32 reg, u32 v)
20876 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
20877 }
20878
20879-struct apic apic_noop = {
20880+struct apic apic_noop __read_only = {
20881 .name = "noop",
20882 .probe = noop_probe,
20883 .acpi_madt_oem_check = NULL,
20884diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
20885index d50e364..543bee3 100644
20886--- a/arch/x86/kernel/apic/bigsmp_32.c
20887+++ b/arch/x86/kernel/apic/bigsmp_32.c
20888@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
20889 return dmi_bigsmp;
20890 }
20891
20892-static struct apic apic_bigsmp = {
20893+static struct apic apic_bigsmp __read_only = {
20894
20895 .name = "bigsmp",
20896 .probe = probe_bigsmp,
20897diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
20898index c552247..587a316 100644
20899--- a/arch/x86/kernel/apic/es7000_32.c
20900+++ b/arch/x86/kernel/apic/es7000_32.c
20901@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
20902 return ret && es7000_apic_is_cluster();
20903 }
20904
20905-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
20906-static struct apic __refdata apic_es7000_cluster = {
20907+static struct apic apic_es7000_cluster __read_only = {
20908
20909 .name = "es7000",
20910 .probe = probe_es7000,
20911@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
20912 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
20913 };
20914
20915-static struct apic __refdata apic_es7000 = {
20916+static struct apic apic_es7000 __read_only = {
20917
20918 .name = "es7000",
20919 .probe = probe_es7000,
20920diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
20921index 6ad4658..38a7b5c 100644
20922--- a/arch/x86/kernel/apic/io_apic.c
20923+++ b/arch/x86/kernel/apic/io_apic.c
20924@@ -1057,7 +1057,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
20925 }
20926 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
20927
20928-void lock_vector_lock(void)
20929+void lock_vector_lock(void) __acquires(vector_lock)
20930 {
20931 /* Used to the online set of cpus does not change
20932 * during assign_irq_vector.
20933@@ -1065,7 +1065,7 @@ void lock_vector_lock(void)
20934 raw_spin_lock(&vector_lock);
20935 }
20936
20937-void unlock_vector_lock(void)
20938+void unlock_vector_lock(void) __releases(vector_lock)
20939 {
20940 raw_spin_unlock(&vector_lock);
20941 }
20942@@ -2364,7 +2364,7 @@ static void ack_apic_edge(struct irq_data *data)
20943 ack_APIC_irq();
20944 }
20945
20946-atomic_t irq_mis_count;
20947+atomic_unchecked_t irq_mis_count;
20948
20949 #ifdef CONFIG_GENERIC_PENDING_IRQ
20950 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
20951@@ -2505,7 +2505,7 @@ static void ack_apic_level(struct irq_data *data)
20952 * at the cpu.
20953 */
20954 if (!(v & (1 << (i & 0x1f)))) {
20955- atomic_inc(&irq_mis_count);
20956+ atomic_inc_unchecked(&irq_mis_count);
20957
20958 eoi_ioapic_irq(irq, cfg);
20959 }
20960diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
20961index 1e42e8f..daacf44 100644
20962--- a/arch/x86/kernel/apic/numaq_32.c
20963+++ b/arch/x86/kernel/apic/numaq_32.c
20964@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
20965 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
20966 }
20967
20968-/* Use __refdata to keep false positive warning calm. */
20969-static struct apic __refdata apic_numaq = {
20970+static struct apic apic_numaq __read_only = {
20971
20972 .name = "NUMAQ",
20973 .probe = probe_numaq,
20974diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
20975index eb35ef9..f184a21 100644
20976--- a/arch/x86/kernel/apic/probe_32.c
20977+++ b/arch/x86/kernel/apic/probe_32.c
20978@@ -72,7 +72,7 @@ static int probe_default(void)
20979 return 1;
20980 }
20981
20982-static struct apic apic_default = {
20983+static struct apic apic_default __read_only = {
20984
20985 .name = "default",
20986 .probe = probe_default,
20987diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
20988index 00146f9..5e299b8 100644
20989--- a/arch/x86/kernel/apic/summit_32.c
20990+++ b/arch/x86/kernel/apic/summit_32.c
20991@@ -485,7 +485,7 @@ void setup_summit(void)
20992 }
20993 #endif
20994
20995-static struct apic apic_summit = {
20996+static struct apic apic_summit __read_only = {
20997
20998 .name = "summit",
20999 .probe = probe_summit,
21000diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
21001index cac85ee..01fa741 100644
21002--- a/arch/x86/kernel/apic/x2apic_cluster.c
21003+++ b/arch/x86/kernel/apic/x2apic_cluster.c
21004@@ -182,7 +182,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
21005 return notifier_from_errno(err);
21006 }
21007
21008-static struct notifier_block __refdata x2apic_cpu_notifier = {
21009+static struct notifier_block x2apic_cpu_notifier = {
21010 .notifier_call = update_clusterinfo,
21011 };
21012
21013@@ -234,7 +234,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
21014 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
21015 }
21016
21017-static struct apic apic_x2apic_cluster = {
21018+static struct apic apic_x2apic_cluster __read_only = {
21019
21020 .name = "cluster x2apic",
21021 .probe = x2apic_cluster_probe,
21022diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
21023index de231e3..1d1b2ee 100644
21024--- a/arch/x86/kernel/apic/x2apic_phys.c
21025+++ b/arch/x86/kernel/apic/x2apic_phys.c
21026@@ -88,7 +88,7 @@ static int x2apic_phys_probe(void)
21027 return apic == &apic_x2apic_phys;
21028 }
21029
21030-static struct apic apic_x2apic_phys = {
21031+static struct apic apic_x2apic_phys __read_only = {
21032
21033 .name = "physical x2apic",
21034 .probe = x2apic_phys_probe,
21035diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
21036index d263b13..963258b 100644
21037--- a/arch/x86/kernel/apic/x2apic_uv_x.c
21038+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
21039@@ -350,7 +350,7 @@ static int uv_probe(void)
21040 return apic == &apic_x2apic_uv_x;
21041 }
21042
21043-static struct apic __refdata apic_x2apic_uv_x = {
21044+static struct apic apic_x2apic_uv_x __read_only = {
21045
21046 .name = "UV large system",
21047 .probe = uv_probe,
21048diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
21049index 3ab0343..814c4787 100644
21050--- a/arch/x86/kernel/apm_32.c
21051+++ b/arch/x86/kernel/apm_32.c
21052@@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
21053 * This is for buggy BIOS's that refer to (real mode) segment 0x40
21054 * even though they are called in protected mode.
21055 */
21056-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
21057+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
21058 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
21059
21060 static const char driver_version[] = "1.16ac"; /* no spaces */
21061@@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
21062 BUG_ON(cpu != 0);
21063 gdt = get_cpu_gdt_table(cpu);
21064 save_desc_40 = gdt[0x40 / 8];
21065+
21066+ pax_open_kernel();
21067 gdt[0x40 / 8] = bad_bios_desc;
21068+ pax_close_kernel();
21069
21070 apm_irq_save(flags);
21071 APM_DO_SAVE_SEGS;
21072@@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
21073 &call->esi);
21074 APM_DO_RESTORE_SEGS;
21075 apm_irq_restore(flags);
21076+
21077+ pax_open_kernel();
21078 gdt[0x40 / 8] = save_desc_40;
21079+ pax_close_kernel();
21080+
21081 put_cpu();
21082
21083 return call->eax & 0xff;
21084@@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
21085 BUG_ON(cpu != 0);
21086 gdt = get_cpu_gdt_table(cpu);
21087 save_desc_40 = gdt[0x40 / 8];
21088+
21089+ pax_open_kernel();
21090 gdt[0x40 / 8] = bad_bios_desc;
21091+ pax_close_kernel();
21092
21093 apm_irq_save(flags);
21094 APM_DO_SAVE_SEGS;
21095@@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
21096 &call->eax);
21097 APM_DO_RESTORE_SEGS;
21098 apm_irq_restore(flags);
21099+
21100+ pax_open_kernel();
21101 gdt[0x40 / 8] = save_desc_40;
21102+ pax_close_kernel();
21103+
21104 put_cpu();
21105 return error;
21106 }
21107@@ -2362,12 +2376,15 @@ static int __init apm_init(void)
21108 * code to that CPU.
21109 */
21110 gdt = get_cpu_gdt_table(0);
21111+
21112+ pax_open_kernel();
21113 set_desc_base(&gdt[APM_CS >> 3],
21114 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
21115 set_desc_base(&gdt[APM_CS_16 >> 3],
21116 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
21117 set_desc_base(&gdt[APM_DS >> 3],
21118 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
21119+ pax_close_kernel();
21120
21121 proc_create("apm", 0, NULL, &apm_file_ops);
21122
21123diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
21124index 9f6b934..cf5ffb3 100644
21125--- a/arch/x86/kernel/asm-offsets.c
21126+++ b/arch/x86/kernel/asm-offsets.c
21127@@ -32,6 +32,8 @@ void common(void) {
21128 OFFSET(TI_flags, thread_info, flags);
21129 OFFSET(TI_status, thread_info, status);
21130 OFFSET(TI_addr_limit, thread_info, addr_limit);
21131+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
21132+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
21133
21134 BLANK();
21135 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
21136@@ -52,8 +54,26 @@ void common(void) {
21137 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
21138 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
21139 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
21140+
21141+#ifdef CONFIG_PAX_KERNEXEC
21142+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
21143 #endif
21144
21145+#ifdef CONFIG_PAX_MEMORY_UDEREF
21146+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
21147+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
21148+#ifdef CONFIG_X86_64
21149+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
21150+#endif
21151+#endif
21152+
21153+#endif
21154+
21155+ BLANK();
21156+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
21157+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
21158+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
21159+
21160 #ifdef CONFIG_XEN
21161 BLANK();
21162 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
21163diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
21164index e7c798b..2b2019b 100644
21165--- a/arch/x86/kernel/asm-offsets_64.c
21166+++ b/arch/x86/kernel/asm-offsets_64.c
21167@@ -77,6 +77,7 @@ int main(void)
21168 BLANK();
21169 #undef ENTRY
21170
21171+ DEFINE(TSS_size, sizeof(struct tss_struct));
21172 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
21173 BLANK();
21174
21175diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
21176index 7fd54f0..0691410 100644
21177--- a/arch/x86/kernel/cpu/Makefile
21178+++ b/arch/x86/kernel/cpu/Makefile
21179@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
21180 CFLAGS_REMOVE_perf_event.o = -pg
21181 endif
21182
21183-# Make sure load_percpu_segment has no stackprotector
21184-nostackp := $(call cc-option, -fno-stack-protector)
21185-CFLAGS_common.o := $(nostackp)
21186-
21187 obj-y := intel_cacheinfo.o scattered.o topology.o
21188 obj-y += proc.o capflags.o powerflags.o common.o
21189 obj-y += rdrand.o
21190diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
21191index c67ffa6..f41fbbf 100644
21192--- a/arch/x86/kernel/cpu/amd.c
21193+++ b/arch/x86/kernel/cpu/amd.c
21194@@ -752,7 +752,7 @@ static void init_amd(struct cpuinfo_x86 *c)
21195 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
21196 {
21197 /* AMD errata T13 (order #21922) */
21198- if ((c->x86 == 6)) {
21199+ if (c->x86 == 6) {
21200 /* Duron Rev A0 */
21201 if (c->x86_model == 3 && c->x86_mask == 0)
21202 size = 64;
21203diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
21204index 8e28bf2..bf5c0d2 100644
21205--- a/arch/x86/kernel/cpu/common.c
21206+++ b/arch/x86/kernel/cpu/common.c
21207@@ -88,60 +88,6 @@ static const struct cpu_dev default_cpu = {
21208
21209 static const struct cpu_dev *this_cpu = &default_cpu;
21210
21211-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
21212-#ifdef CONFIG_X86_64
21213- /*
21214- * We need valid kernel segments for data and code in long mode too
21215- * IRET will check the segment types kkeil 2000/10/28
21216- * Also sysret mandates a special GDT layout
21217- *
21218- * TLS descriptors are currently at a different place compared to i386.
21219- * Hopefully nobody expects them at a fixed place (Wine?)
21220- */
21221- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
21222- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
21223- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
21224- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
21225- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
21226- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
21227-#else
21228- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
21229- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21230- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
21231- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
21232- /*
21233- * Segments used for calling PnP BIOS have byte granularity.
21234- * They code segments and data segments have fixed 64k limits,
21235- * the transfer segment sizes are set at run time.
21236- */
21237- /* 32-bit code */
21238- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21239- /* 16-bit code */
21240- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
21241- /* 16-bit data */
21242- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
21243- /* 16-bit data */
21244- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
21245- /* 16-bit data */
21246- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
21247- /*
21248- * The APM segments have byte granularity and their bases
21249- * are set at run time. All have 64k limits.
21250- */
21251- /* 32-bit code */
21252- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21253- /* 16-bit code */
21254- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
21255- /* data */
21256- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
21257-
21258- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21259- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21260- GDT_STACK_CANARY_INIT
21261-#endif
21262-} };
21263-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
21264-
21265 static int __init x86_xsave_setup(char *s)
21266 {
21267 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
21268@@ -293,6 +239,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
21269 }
21270 }
21271
21272+#ifdef CONFIG_X86_64
21273+static __init int setup_disable_pcid(char *arg)
21274+{
21275+ setup_clear_cpu_cap(X86_FEATURE_PCID);
21276+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
21277+
21278+#ifdef CONFIG_PAX_MEMORY_UDEREF
21279+ if (clone_pgd_mask != ~(pgdval_t)0UL)
21280+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21281+#endif
21282+
21283+ return 1;
21284+}
21285+__setup("nopcid", setup_disable_pcid);
21286+
21287+static void setup_pcid(struct cpuinfo_x86 *c)
21288+{
21289+ if (!cpu_has(c, X86_FEATURE_PCID)) {
21290+ clear_cpu_cap(c, X86_FEATURE_INVPCID);
21291+
21292+#ifdef CONFIG_PAX_MEMORY_UDEREF
21293+ if (clone_pgd_mask != ~(pgdval_t)0UL) {
21294+ pax_open_kernel();
21295+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21296+ pax_close_kernel();
21297+ printk("PAX: slow and weak UDEREF enabled\n");
21298+ } else
21299+ printk("PAX: UDEREF disabled\n");
21300+#endif
21301+
21302+ return;
21303+ }
21304+
21305+ printk("PAX: PCID detected\n");
21306+ set_in_cr4(X86_CR4_PCIDE);
21307+
21308+#ifdef CONFIG_PAX_MEMORY_UDEREF
21309+ pax_open_kernel();
21310+ clone_pgd_mask = ~(pgdval_t)0UL;
21311+ pax_close_kernel();
21312+ if (pax_user_shadow_base)
21313+ printk("PAX: weak UDEREF enabled\n");
21314+ else {
21315+ set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
21316+ printk("PAX: strong UDEREF enabled\n");
21317+ }
21318+#endif
21319+
21320+ if (cpu_has(c, X86_FEATURE_INVPCID))
21321+ printk("PAX: INVPCID detected\n");
21322+}
21323+#endif
21324+
21325 /*
21326 * Some CPU features depend on higher CPUID levels, which may not always
21327 * be available due to CPUID level capping or broken virtualization
21328@@ -393,7 +392,7 @@ void switch_to_new_gdt(int cpu)
21329 {
21330 struct desc_ptr gdt_descr;
21331
21332- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
21333+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
21334 gdt_descr.size = GDT_SIZE - 1;
21335 load_gdt(&gdt_descr);
21336 /* Reload the per-cpu base */
21337@@ -883,6 +882,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21338 setup_smep(c);
21339 setup_smap(c);
21340
21341+#ifdef CONFIG_X86_64
21342+ setup_pcid(c);
21343+#endif
21344+
21345 /*
21346 * The vendor-specific functions might have changed features.
21347 * Now we do "generic changes."
21348@@ -891,6 +894,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21349 /* Filter out anything that depends on CPUID levels we don't have */
21350 filter_cpuid_features(c, true);
21351
21352+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
21353+ setup_clear_cpu_cap(X86_FEATURE_SEP);
21354+#endif
21355+
21356 /* If the model name is still unset, do table lookup. */
21357 if (!c->x86_model_id[0]) {
21358 const char *p;
21359@@ -1078,10 +1085,12 @@ static __init int setup_disablecpuid(char *arg)
21360 }
21361 __setup("clearcpuid=", setup_disablecpuid);
21362
21363+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
21364+EXPORT_PER_CPU_SYMBOL(current_tinfo);
21365+
21366 #ifdef CONFIG_X86_64
21367-struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21368-struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
21369- (unsigned long) debug_idt_table };
21370+struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21371+const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
21372
21373 DEFINE_PER_CPU_FIRST(union irq_stack_union,
21374 irq_stack_union) __aligned(PAGE_SIZE) __visible;
21375@@ -1095,7 +1104,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
21376 EXPORT_PER_CPU_SYMBOL(current_task);
21377
21378 DEFINE_PER_CPU(unsigned long, kernel_stack) =
21379- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
21380+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
21381 EXPORT_PER_CPU_SYMBOL(kernel_stack);
21382
21383 DEFINE_PER_CPU(char *, irq_stack_ptr) =
21384@@ -1245,7 +1254,7 @@ void cpu_init(void)
21385 load_ucode_ap();
21386
21387 cpu = stack_smp_processor_id();
21388- t = &per_cpu(init_tss, cpu);
21389+ t = init_tss + cpu;
21390 oist = &per_cpu(orig_ist, cpu);
21391
21392 #ifdef CONFIG_NUMA
21393@@ -1280,7 +1289,6 @@ void cpu_init(void)
21394 wrmsrl(MSR_KERNEL_GS_BASE, 0);
21395 barrier();
21396
21397- x86_configure_nx();
21398 enable_x2apic();
21399
21400 /*
21401@@ -1332,7 +1340,7 @@ void cpu_init(void)
21402 {
21403 int cpu = smp_processor_id();
21404 struct task_struct *curr = current;
21405- struct tss_struct *t = &per_cpu(init_tss, cpu);
21406+ struct tss_struct *t = init_tss + cpu;
21407 struct thread_struct *thread = &curr->thread;
21408
21409 show_ucode_info_early();
21410diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
21411index 0641113..06f5ba4 100644
21412--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
21413+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
21414@@ -1014,6 +1014,22 @@ static struct attribute *default_attrs[] = {
21415 };
21416
21417 #ifdef CONFIG_AMD_NB
21418+static struct attribute *default_attrs_amd_nb[] = {
21419+ &type.attr,
21420+ &level.attr,
21421+ &coherency_line_size.attr,
21422+ &physical_line_partition.attr,
21423+ &ways_of_associativity.attr,
21424+ &number_of_sets.attr,
21425+ &size.attr,
21426+ &shared_cpu_map.attr,
21427+ &shared_cpu_list.attr,
21428+ NULL,
21429+ NULL,
21430+ NULL,
21431+ NULL
21432+};
21433+
21434 static struct attribute **amd_l3_attrs(void)
21435 {
21436 static struct attribute **attrs;
21437@@ -1024,18 +1040,7 @@ static struct attribute **amd_l3_attrs(void)
21438
21439 n = ARRAY_SIZE(default_attrs);
21440
21441- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
21442- n += 2;
21443-
21444- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
21445- n += 1;
21446-
21447- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
21448- if (attrs == NULL)
21449- return attrs = default_attrs;
21450-
21451- for (n = 0; default_attrs[n]; n++)
21452- attrs[n] = default_attrs[n];
21453+ attrs = default_attrs_amd_nb;
21454
21455 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
21456 attrs[n++] = &cache_disable_0.attr;
21457@@ -1086,6 +1091,13 @@ static struct kobj_type ktype_cache = {
21458 .default_attrs = default_attrs,
21459 };
21460
21461+#ifdef CONFIG_AMD_NB
21462+static struct kobj_type ktype_cache_amd_nb = {
21463+ .sysfs_ops = &sysfs_ops,
21464+ .default_attrs = default_attrs_amd_nb,
21465+};
21466+#endif
21467+
21468 static struct kobj_type ktype_percpu_entry = {
21469 .sysfs_ops = &sysfs_ops,
21470 };
21471@@ -1151,20 +1163,26 @@ static int cache_add_dev(struct device *dev)
21472 return retval;
21473 }
21474
21475+#ifdef CONFIG_AMD_NB
21476+ amd_l3_attrs();
21477+#endif
21478+
21479 for (i = 0; i < num_cache_leaves; i++) {
21480+ struct kobj_type *ktype;
21481+
21482 this_object = INDEX_KOBJECT_PTR(cpu, i);
21483 this_object->cpu = cpu;
21484 this_object->index = i;
21485
21486 this_leaf = CPUID4_INFO_IDX(cpu, i);
21487
21488- ktype_cache.default_attrs = default_attrs;
21489+ ktype = &ktype_cache;
21490 #ifdef CONFIG_AMD_NB
21491 if (this_leaf->base.nb)
21492- ktype_cache.default_attrs = amd_l3_attrs();
21493+ ktype = &ktype_cache_amd_nb;
21494 #endif
21495 retval = kobject_init_and_add(&(this_object->kobj),
21496- &ktype_cache,
21497+ ktype,
21498 per_cpu(ici_cache_kobject, cpu),
21499 "index%1lu", i);
21500 if (unlikely(retval)) {
21501diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
21502index 4d5419b..95f11bb 100644
21503--- a/arch/x86/kernel/cpu/mcheck/mce.c
21504+++ b/arch/x86/kernel/cpu/mcheck/mce.c
21505@@ -45,6 +45,7 @@
21506 #include <asm/processor.h>
21507 #include <asm/mce.h>
21508 #include <asm/msr.h>
21509+#include <asm/local.h>
21510
21511 #include "mce-internal.h"
21512
21513@@ -258,7 +259,7 @@ static void print_mce(struct mce *m)
21514 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
21515 m->cs, m->ip);
21516
21517- if (m->cs == __KERNEL_CS)
21518+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
21519 print_symbol("{%s}", m->ip);
21520 pr_cont("\n");
21521 }
21522@@ -291,10 +292,10 @@ static void print_mce(struct mce *m)
21523
21524 #define PANIC_TIMEOUT 5 /* 5 seconds */
21525
21526-static atomic_t mce_paniced;
21527+static atomic_unchecked_t mce_paniced;
21528
21529 static int fake_panic;
21530-static atomic_t mce_fake_paniced;
21531+static atomic_unchecked_t mce_fake_paniced;
21532
21533 /* Panic in progress. Enable interrupts and wait for final IPI */
21534 static void wait_for_panic(void)
21535@@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21536 /*
21537 * Make sure only one CPU runs in machine check panic
21538 */
21539- if (atomic_inc_return(&mce_paniced) > 1)
21540+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
21541 wait_for_panic();
21542 barrier();
21543
21544@@ -326,7 +327,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21545 console_verbose();
21546 } else {
21547 /* Don't log too much for fake panic */
21548- if (atomic_inc_return(&mce_fake_paniced) > 1)
21549+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
21550 return;
21551 }
21552 /* First print corrected ones that are still unlogged */
21553@@ -365,7 +366,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21554 if (!fake_panic) {
21555 if (panic_timeout == 0)
21556 panic_timeout = mca_cfg.panic_timeout;
21557- panic(msg);
21558+ panic("%s", msg);
21559 } else
21560 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
21561 }
21562@@ -695,7 +696,7 @@ static int mce_timed_out(u64 *t)
21563 * might have been modified by someone else.
21564 */
21565 rmb();
21566- if (atomic_read(&mce_paniced))
21567+ if (atomic_read_unchecked(&mce_paniced))
21568 wait_for_panic();
21569 if (!mca_cfg.monarch_timeout)
21570 goto out;
21571@@ -1666,7 +1667,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
21572 }
21573
21574 /* Call the installed machine check handler for this CPU setup. */
21575-void (*machine_check_vector)(struct pt_regs *, long error_code) =
21576+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
21577 unexpected_machine_check;
21578
21579 /*
21580@@ -1689,7 +1690,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21581 return;
21582 }
21583
21584+ pax_open_kernel();
21585 machine_check_vector = do_machine_check;
21586+ pax_close_kernel();
21587
21588 __mcheck_cpu_init_generic();
21589 __mcheck_cpu_init_vendor(c);
21590@@ -1703,7 +1706,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21591 */
21592
21593 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
21594-static int mce_chrdev_open_count; /* #times opened */
21595+static local_t mce_chrdev_open_count; /* #times opened */
21596 static int mce_chrdev_open_exclu; /* already open exclusive? */
21597
21598 static int mce_chrdev_open(struct inode *inode, struct file *file)
21599@@ -1711,7 +1714,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21600 spin_lock(&mce_chrdev_state_lock);
21601
21602 if (mce_chrdev_open_exclu ||
21603- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
21604+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
21605 spin_unlock(&mce_chrdev_state_lock);
21606
21607 return -EBUSY;
21608@@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21609
21610 if (file->f_flags & O_EXCL)
21611 mce_chrdev_open_exclu = 1;
21612- mce_chrdev_open_count++;
21613+ local_inc(&mce_chrdev_open_count);
21614
21615 spin_unlock(&mce_chrdev_state_lock);
21616
21617@@ -1730,7 +1733,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
21618 {
21619 spin_lock(&mce_chrdev_state_lock);
21620
21621- mce_chrdev_open_count--;
21622+ local_dec(&mce_chrdev_open_count);
21623 mce_chrdev_open_exclu = 0;
21624
21625 spin_unlock(&mce_chrdev_state_lock);
21626@@ -2406,7 +2409,7 @@ static __init void mce_init_banks(void)
21627
21628 for (i = 0; i < mca_cfg.banks; i++) {
21629 struct mce_bank *b = &mce_banks[i];
21630- struct device_attribute *a = &b->attr;
21631+ device_attribute_no_const *a = &b->attr;
21632
21633 sysfs_attr_init(&a->attr);
21634 a->attr.name = b->attrname;
21635@@ -2474,7 +2477,7 @@ struct dentry *mce_get_debugfs_dir(void)
21636 static void mce_reset(void)
21637 {
21638 cpu_missing = 0;
21639- atomic_set(&mce_fake_paniced, 0);
21640+ atomic_set_unchecked(&mce_fake_paniced, 0);
21641 atomic_set(&mce_executing, 0);
21642 atomic_set(&mce_callin, 0);
21643 atomic_set(&global_nwo, 0);
21644diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
21645index a304298..49b6d06 100644
21646--- a/arch/x86/kernel/cpu/mcheck/p5.c
21647+++ b/arch/x86/kernel/cpu/mcheck/p5.c
21648@@ -10,6 +10,7 @@
21649 #include <asm/processor.h>
21650 #include <asm/mce.h>
21651 #include <asm/msr.h>
21652+#include <asm/pgtable.h>
21653
21654 /* By default disabled */
21655 int mce_p5_enabled __read_mostly;
21656@@ -48,7 +49,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
21657 if (!cpu_has(c, X86_FEATURE_MCE))
21658 return;
21659
21660+ pax_open_kernel();
21661 machine_check_vector = pentium_machine_check;
21662+ pax_close_kernel();
21663 /* Make sure the vector pointer is visible before we enable MCEs: */
21664 wmb();
21665
21666diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
21667index 7dc5564..1273569 100644
21668--- a/arch/x86/kernel/cpu/mcheck/winchip.c
21669+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
21670@@ -9,6 +9,7 @@
21671 #include <asm/processor.h>
21672 #include <asm/mce.h>
21673 #include <asm/msr.h>
21674+#include <asm/pgtable.h>
21675
21676 /* Machine check handler for WinChip C6: */
21677 static void winchip_machine_check(struct pt_regs *regs, long error_code)
21678@@ -22,7 +23,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
21679 {
21680 u32 lo, hi;
21681
21682+ pax_open_kernel();
21683 machine_check_vector = winchip_machine_check;
21684+ pax_close_kernel();
21685 /* Make sure the vector pointer is visible before we enable MCEs: */
21686 wmb();
21687
21688diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
21689index 15c9876..0a43909 100644
21690--- a/arch/x86/kernel/cpu/microcode/core.c
21691+++ b/arch/x86/kernel/cpu/microcode/core.c
21692@@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21693 return NOTIFY_OK;
21694 }
21695
21696-static struct notifier_block __refdata mc_cpu_notifier = {
21697+static struct notifier_block mc_cpu_notifier = {
21698 .notifier_call = mc_cpu_callback,
21699 };
21700
21701diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
21702index a276fa7..e66810f 100644
21703--- a/arch/x86/kernel/cpu/microcode/intel.c
21704+++ b/arch/x86/kernel/cpu/microcode/intel.c
21705@@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21706
21707 static int get_ucode_user(void *to, const void *from, size_t n)
21708 {
21709- return copy_from_user(to, from, n);
21710+ return copy_from_user(to, (const void __force_user *)from, n);
21711 }
21712
21713 static enum ucode_state
21714 request_microcode_user(int cpu, const void __user *buf, size_t size)
21715 {
21716- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21717+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21718 }
21719
21720 static void microcode_fini_cpu(int cpu)
21721diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
21722index f961de9..8a9d332 100644
21723--- a/arch/x86/kernel/cpu/mtrr/main.c
21724+++ b/arch/x86/kernel/cpu/mtrr/main.c
21725@@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
21726 u64 size_or_mask, size_and_mask;
21727 static bool mtrr_aps_delayed_init;
21728
21729-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
21730+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
21731
21732 const struct mtrr_ops *mtrr_if;
21733
21734diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
21735index df5e41f..816c719 100644
21736--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
21737+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
21738@@ -25,7 +25,7 @@ struct mtrr_ops {
21739 int (*validate_add_page)(unsigned long base, unsigned long size,
21740 unsigned int type);
21741 int (*have_wrcomb)(void);
21742-};
21743+} __do_const;
21744
21745 extern int generic_get_free_region(unsigned long base, unsigned long size,
21746 int replace_reg);
21747diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
21748index 79f9f84..38ace52 100644
21749--- a/arch/x86/kernel/cpu/perf_event.c
21750+++ b/arch/x86/kernel/cpu/perf_event.c
21751@@ -1351,7 +1351,7 @@ static void __init pmu_check_apic(void)
21752 pr_info("no hardware sampling interrupt available.\n");
21753 }
21754
21755-static struct attribute_group x86_pmu_format_group = {
21756+static attribute_group_no_const x86_pmu_format_group = {
21757 .name = "format",
21758 .attrs = NULL,
21759 };
21760@@ -1450,7 +1450,7 @@ static struct attribute *events_attr[] = {
21761 NULL,
21762 };
21763
21764-static struct attribute_group x86_pmu_events_group = {
21765+static attribute_group_no_const x86_pmu_events_group = {
21766 .name = "events",
21767 .attrs = events_attr,
21768 };
21769@@ -1971,7 +1971,7 @@ static unsigned long get_segment_base(unsigned int segment)
21770 if (idx > GDT_ENTRIES)
21771 return 0;
21772
21773- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
21774+ desc = get_cpu_gdt_table(smp_processor_id());
21775 }
21776
21777 return get_desc_base(desc + idx);
21778@@ -2061,7 +2061,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
21779 break;
21780
21781 perf_callchain_store(entry, frame.return_address);
21782- fp = frame.next_frame;
21783+ fp = (const void __force_user *)frame.next_frame;
21784 }
21785 }
21786
21787diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21788index 639d128..e92d7e5 100644
21789--- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21790+++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21791@@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
21792 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
21793 {
21794 struct attribute **attrs;
21795- struct attribute_group *attr_group;
21796+ attribute_group_no_const *attr_group;
21797 int i = 0, j;
21798
21799 while (amd_iommu_v2_event_descs[i].attr.attr.name)
21800diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
21801index aa333d9..f9db700 100644
21802--- a/arch/x86/kernel/cpu/perf_event_intel.c
21803+++ b/arch/x86/kernel/cpu/perf_event_intel.c
21804@@ -2309,10 +2309,10 @@ __init int intel_pmu_init(void)
21805 x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
21806
21807 if (boot_cpu_has(X86_FEATURE_PDCM)) {
21808- u64 capabilities;
21809+ u64 capabilities = x86_pmu.intel_cap.capabilities;
21810
21811- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
21812- x86_pmu.intel_cap.capabilities = capabilities;
21813+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
21814+ x86_pmu.intel_cap.capabilities = capabilities;
21815 }
21816
21817 intel_ds_init();
21818diff --git a/arch/x86/kernel/cpu/perf_event_intel_rapl.c b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21819index 5ad35ad..e0a3960 100644
21820--- a/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21821+++ b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21822@@ -425,7 +425,7 @@ static struct attribute *rapl_events_cln_attr[] = {
21823 NULL,
21824 };
21825
21826-static struct attribute_group rapl_pmu_events_group = {
21827+static attribute_group_no_const rapl_pmu_events_group __read_only = {
21828 .name = "events",
21829 .attrs = NULL, /* patched at runtime */
21830 };
21831diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21832index 047f540..afdeba0 100644
21833--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21834+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21835@@ -3326,7 +3326,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
21836 static int __init uncore_type_init(struct intel_uncore_type *type)
21837 {
21838 struct intel_uncore_pmu *pmus;
21839- struct attribute_group *attr_group;
21840+ attribute_group_no_const *attr_group;
21841 struct attribute **attrs;
21842 int i, j;
21843
21844diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21845index a80ab71..4089da5 100644
21846--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21847+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21848@@ -498,7 +498,7 @@ struct intel_uncore_box {
21849 struct uncore_event_desc {
21850 struct kobj_attribute attr;
21851 const char *config;
21852-};
21853+} __do_const;
21854
21855 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
21856 { \
21857diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
21858index 7d9481c..99c7e4b 100644
21859--- a/arch/x86/kernel/cpuid.c
21860+++ b/arch/x86/kernel/cpuid.c
21861@@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
21862 return notifier_from_errno(err);
21863 }
21864
21865-static struct notifier_block __refdata cpuid_class_cpu_notifier =
21866+static struct notifier_block cpuid_class_cpu_notifier =
21867 {
21868 .notifier_call = cpuid_class_cpu_callback,
21869 };
21870diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
21871index a57902e..ebaae2a 100644
21872--- a/arch/x86/kernel/crash.c
21873+++ b/arch/x86/kernel/crash.c
21874@@ -57,10 +57,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
21875 {
21876 #ifdef CONFIG_X86_32
21877 struct pt_regs fixed_regs;
21878-#endif
21879
21880-#ifdef CONFIG_X86_32
21881- if (!user_mode_vm(regs)) {
21882+ if (!user_mode(regs)) {
21883 crash_fixup_ss_esp(&fixed_regs, regs);
21884 regs = &fixed_regs;
21885 }
21886diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
21887index afa64ad..dce67dd 100644
21888--- a/arch/x86/kernel/crash_dump_64.c
21889+++ b/arch/x86/kernel/crash_dump_64.c
21890@@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
21891 return -ENOMEM;
21892
21893 if (userbuf) {
21894- if (copy_to_user(buf, vaddr + offset, csize)) {
21895+ if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
21896 iounmap(vaddr);
21897 return -EFAULT;
21898 }
21899diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
21900index f6dfd93..892ade4 100644
21901--- a/arch/x86/kernel/doublefault.c
21902+++ b/arch/x86/kernel/doublefault.c
21903@@ -12,7 +12,7 @@
21904
21905 #define DOUBLEFAULT_STACKSIZE (1024)
21906 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
21907-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
21908+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
21909
21910 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
21911
21912@@ -22,7 +22,7 @@ static void doublefault_fn(void)
21913 unsigned long gdt, tss;
21914
21915 native_store_gdt(&gdt_desc);
21916- gdt = gdt_desc.address;
21917+ gdt = (unsigned long)gdt_desc.address;
21918
21919 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
21920
21921@@ -59,10 +59,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
21922 /* 0x2 bit is always set */
21923 .flags = X86_EFLAGS_SF | 0x2,
21924 .sp = STACK_START,
21925- .es = __USER_DS,
21926+ .es = __KERNEL_DS,
21927 .cs = __KERNEL_CS,
21928 .ss = __KERNEL_DS,
21929- .ds = __USER_DS,
21930+ .ds = __KERNEL_DS,
21931 .fs = __KERNEL_PERCPU,
21932
21933 .__cr3 = __pa_nodebug(swapper_pg_dir),
21934diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
21935index d9c12d3..7858b62 100644
21936--- a/arch/x86/kernel/dumpstack.c
21937+++ b/arch/x86/kernel/dumpstack.c
21938@@ -2,6 +2,9 @@
21939 * Copyright (C) 1991, 1992 Linus Torvalds
21940 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
21941 */
21942+#ifdef CONFIG_GRKERNSEC_HIDESYM
21943+#define __INCLUDED_BY_HIDESYM 1
21944+#endif
21945 #include <linux/kallsyms.h>
21946 #include <linux/kprobes.h>
21947 #include <linux/uaccess.h>
21948@@ -40,16 +43,14 @@ void printk_address(unsigned long address)
21949 static void
21950 print_ftrace_graph_addr(unsigned long addr, void *data,
21951 const struct stacktrace_ops *ops,
21952- struct thread_info *tinfo, int *graph)
21953+ struct task_struct *task, int *graph)
21954 {
21955- struct task_struct *task;
21956 unsigned long ret_addr;
21957 int index;
21958
21959 if (addr != (unsigned long)return_to_handler)
21960 return;
21961
21962- task = tinfo->task;
21963 index = task->curr_ret_stack;
21964
21965 if (!task->ret_stack || index < *graph)
21966@@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21967 static inline void
21968 print_ftrace_graph_addr(unsigned long addr, void *data,
21969 const struct stacktrace_ops *ops,
21970- struct thread_info *tinfo, int *graph)
21971+ struct task_struct *task, int *graph)
21972 { }
21973 #endif
21974
21975@@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21976 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
21977 */
21978
21979-static inline int valid_stack_ptr(struct thread_info *tinfo,
21980- void *p, unsigned int size, void *end)
21981+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
21982 {
21983- void *t = tinfo;
21984 if (end) {
21985 if (p < end && p >= (end-THREAD_SIZE))
21986 return 1;
21987@@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
21988 }
21989
21990 unsigned long
21991-print_context_stack(struct thread_info *tinfo,
21992+print_context_stack(struct task_struct *task, void *stack_start,
21993 unsigned long *stack, unsigned long bp,
21994 const struct stacktrace_ops *ops, void *data,
21995 unsigned long *end, int *graph)
21996 {
21997 struct stack_frame *frame = (struct stack_frame *)bp;
21998
21999- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
22000+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
22001 unsigned long addr;
22002
22003 addr = *stack;
22004@@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
22005 } else {
22006 ops->address(data, addr, 0);
22007 }
22008- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
22009+ print_ftrace_graph_addr(addr, data, ops, task, graph);
22010 }
22011 stack++;
22012 }
22013@@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
22014 EXPORT_SYMBOL_GPL(print_context_stack);
22015
22016 unsigned long
22017-print_context_stack_bp(struct thread_info *tinfo,
22018+print_context_stack_bp(struct task_struct *task, void *stack_start,
22019 unsigned long *stack, unsigned long bp,
22020 const struct stacktrace_ops *ops, void *data,
22021 unsigned long *end, int *graph)
22022@@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
22023 struct stack_frame *frame = (struct stack_frame *)bp;
22024 unsigned long *ret_addr = &frame->return_address;
22025
22026- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
22027+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
22028 unsigned long addr = *ret_addr;
22029
22030 if (!__kernel_text_address(addr))
22031@@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
22032 ops->address(data, addr, 1);
22033 frame = frame->next_frame;
22034 ret_addr = &frame->return_address;
22035- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
22036+ print_ftrace_graph_addr(addr, data, ops, task, graph);
22037 }
22038
22039 return (unsigned long)frame;
22040@@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
22041 static void print_trace_address(void *data, unsigned long addr, int reliable)
22042 {
22043 touch_nmi_watchdog();
22044- printk(data);
22045+ printk("%s", (char *)data);
22046 printk_stack_address(addr, reliable);
22047 }
22048
22049@@ -224,6 +223,8 @@ unsigned __kprobes long oops_begin(void)
22050 }
22051 EXPORT_SYMBOL_GPL(oops_begin);
22052
22053+extern void gr_handle_kernel_exploit(void);
22054+
22055 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
22056 {
22057 if (regs && kexec_should_crash(current))
22058@@ -245,7 +246,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
22059 panic("Fatal exception in interrupt");
22060 if (panic_on_oops)
22061 panic("Fatal exception");
22062- do_exit(signr);
22063+
22064+ gr_handle_kernel_exploit();
22065+
22066+ do_group_exit(signr);
22067 }
22068
22069 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
22070@@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
22071 print_modules();
22072 show_regs(regs);
22073 #ifdef CONFIG_X86_32
22074- if (user_mode_vm(regs)) {
22075+ if (user_mode(regs)) {
22076 sp = regs->sp;
22077 ss = regs->ss & 0xffff;
22078 } else {
22079@@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
22080 unsigned long flags = oops_begin();
22081 int sig = SIGSEGV;
22082
22083- if (!user_mode_vm(regs))
22084+ if (!user_mode(regs))
22085 report_bug(regs->ip, regs);
22086
22087 if (__die(str, regs, err))
22088diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
22089index f2a1770..10fa52d 100644
22090--- a/arch/x86/kernel/dumpstack_32.c
22091+++ b/arch/x86/kernel/dumpstack_32.c
22092@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22093 bp = stack_frame(task, regs);
22094
22095 for (;;) {
22096- struct thread_info *context;
22097+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
22098
22099- context = (struct thread_info *)
22100- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
22101- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
22102+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
22103
22104- stack = (unsigned long *)context->previous_esp;
22105- if (!stack)
22106+ if (stack_start == task_stack_page(task))
22107 break;
22108+ stack = *(unsigned long **)stack_start;
22109 if (ops->stack(data, "IRQ") < 0)
22110 break;
22111 touch_nmi_watchdog();
22112@@ -87,27 +85,28 @@ void show_regs(struct pt_regs *regs)
22113 int i;
22114
22115 show_regs_print_info(KERN_EMERG);
22116- __show_regs(regs, !user_mode_vm(regs));
22117+ __show_regs(regs, !user_mode(regs));
22118
22119 /*
22120 * When in-kernel, we also print out the stack and code at the
22121 * time of the fault..
22122 */
22123- if (!user_mode_vm(regs)) {
22124+ if (!user_mode(regs)) {
22125 unsigned int code_prologue = code_bytes * 43 / 64;
22126 unsigned int code_len = code_bytes;
22127 unsigned char c;
22128 u8 *ip;
22129+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
22130
22131 pr_emerg("Stack:\n");
22132 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
22133
22134 pr_emerg("Code:");
22135
22136- ip = (u8 *)regs->ip - code_prologue;
22137+ ip = (u8 *)regs->ip - code_prologue + cs_base;
22138 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
22139 /* try starting at IP */
22140- ip = (u8 *)regs->ip;
22141+ ip = (u8 *)regs->ip + cs_base;
22142 code_len = code_len - code_prologue + 1;
22143 }
22144 for (i = 0; i < code_len; i++, ip++) {
22145@@ -116,7 +115,7 @@ void show_regs(struct pt_regs *regs)
22146 pr_cont(" Bad EIP value.");
22147 break;
22148 }
22149- if (ip == (u8 *)regs->ip)
22150+ if (ip == (u8 *)regs->ip + cs_base)
22151 pr_cont(" <%02x>", c);
22152 else
22153 pr_cont(" %02x", c);
22154@@ -129,6 +128,7 @@ int is_valid_bugaddr(unsigned long ip)
22155 {
22156 unsigned short ud2;
22157
22158+ ip = ktla_ktva(ip);
22159 if (ip < PAGE_OFFSET)
22160 return 0;
22161 if (probe_kernel_address((unsigned short *)ip, ud2))
22162@@ -136,3 +136,15 @@ int is_valid_bugaddr(unsigned long ip)
22163
22164 return ud2 == 0x0b0f;
22165 }
22166+
22167+#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22168+void pax_check_alloca(unsigned long size)
22169+{
22170+ unsigned long sp = (unsigned long)&sp, stack_left;
22171+
22172+ /* all kernel stacks are of the same size */
22173+ stack_left = sp & (THREAD_SIZE - 1);
22174+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
22175+}
22176+EXPORT_SYMBOL(pax_check_alloca);
22177+#endif
22178diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
22179index addb207..921706b 100644
22180--- a/arch/x86/kernel/dumpstack_64.c
22181+++ b/arch/x86/kernel/dumpstack_64.c
22182@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22183 unsigned long *irq_stack_end =
22184 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
22185 unsigned used = 0;
22186- struct thread_info *tinfo;
22187 int graph = 0;
22188 unsigned long dummy;
22189+ void *stack_start;
22190
22191 if (!task)
22192 task = current;
22193@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22194 * current stack address. If the stacks consist of nested
22195 * exceptions
22196 */
22197- tinfo = task_thread_info(task);
22198 for (;;) {
22199 char *id;
22200 unsigned long *estack_end;
22201+
22202 estack_end = in_exception_stack(cpu, (unsigned long)stack,
22203 &used, &id);
22204
22205@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22206 if (ops->stack(data, id) < 0)
22207 break;
22208
22209- bp = ops->walk_stack(tinfo, stack, bp, ops,
22210+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
22211 data, estack_end, &graph);
22212 ops->stack(data, "<EOE>");
22213 /*
22214@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22215 * second-to-last pointer (index -2 to end) in the
22216 * exception stack:
22217 */
22218+ if ((u16)estack_end[-1] != __KERNEL_DS)
22219+ goto out;
22220 stack = (unsigned long *) estack_end[-2];
22221 continue;
22222 }
22223@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22224 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
22225 if (ops->stack(data, "IRQ") < 0)
22226 break;
22227- bp = ops->walk_stack(tinfo, stack, bp,
22228+ bp = ops->walk_stack(task, irq_stack, stack, bp,
22229 ops, data, irq_stack_end, &graph);
22230 /*
22231 * We link to the next stack (which would be
22232@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22233 /*
22234 * This handles the process stack:
22235 */
22236- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
22237+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
22238+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
22239+out:
22240 put_cpu();
22241 }
22242 EXPORT_SYMBOL(dump_trace);
22243@@ -300,3 +304,50 @@ int is_valid_bugaddr(unsigned long ip)
22244
22245 return ud2 == 0x0b0f;
22246 }
22247+
22248+#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22249+void pax_check_alloca(unsigned long size)
22250+{
22251+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
22252+ unsigned cpu, used;
22253+ char *id;
22254+
22255+ /* check the process stack first */
22256+ stack_start = (unsigned long)task_stack_page(current);
22257+ stack_end = stack_start + THREAD_SIZE;
22258+ if (likely(stack_start <= sp && sp < stack_end)) {
22259+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
22260+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
22261+ return;
22262+ }
22263+
22264+ cpu = get_cpu();
22265+
22266+ /* check the irq stacks */
22267+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
22268+ stack_start = stack_end - IRQ_STACK_SIZE;
22269+ if (stack_start <= sp && sp < stack_end) {
22270+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
22271+ put_cpu();
22272+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
22273+ return;
22274+ }
22275+
22276+ /* check the exception stacks */
22277+ used = 0;
22278+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
22279+ stack_start = stack_end - EXCEPTION_STKSZ;
22280+ if (stack_end && stack_start <= sp && sp < stack_end) {
22281+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
22282+ put_cpu();
22283+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
22284+ return;
22285+ }
22286+
22287+ put_cpu();
22288+
22289+ /* unknown stack */
22290+ BUG();
22291+}
22292+EXPORT_SYMBOL(pax_check_alloca);
22293+#endif
22294diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
22295index 988c00a..4f673b6 100644
22296--- a/arch/x86/kernel/e820.c
22297+++ b/arch/x86/kernel/e820.c
22298@@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
22299
22300 static void early_panic(char *msg)
22301 {
22302- early_printk(msg);
22303- panic(msg);
22304+ early_printk("%s", msg);
22305+ panic("%s", msg);
22306 }
22307
22308 static int userdef __initdata;
22309diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
22310index 01d1c18..8073693 100644
22311--- a/arch/x86/kernel/early_printk.c
22312+++ b/arch/x86/kernel/early_printk.c
22313@@ -7,6 +7,7 @@
22314 #include <linux/pci_regs.h>
22315 #include <linux/pci_ids.h>
22316 #include <linux/errno.h>
22317+#include <linux/sched.h>
22318 #include <asm/io.h>
22319 #include <asm/processor.h>
22320 #include <asm/fcntl.h>
22321diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
22322index a2a4f46..6cab058 100644
22323--- a/arch/x86/kernel/entry_32.S
22324+++ b/arch/x86/kernel/entry_32.S
22325@@ -177,13 +177,153 @@
22326 /*CFI_REL_OFFSET gs, PT_GS*/
22327 .endm
22328 .macro SET_KERNEL_GS reg
22329+
22330+#ifdef CONFIG_CC_STACKPROTECTOR
22331 movl $(__KERNEL_STACK_CANARY), \reg
22332+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
22333+ movl $(__USER_DS), \reg
22334+#else
22335+ xorl \reg, \reg
22336+#endif
22337+
22338 movl \reg, %gs
22339 .endm
22340
22341 #endif /* CONFIG_X86_32_LAZY_GS */
22342
22343-.macro SAVE_ALL
22344+.macro pax_enter_kernel
22345+#ifdef CONFIG_PAX_KERNEXEC
22346+ call pax_enter_kernel
22347+#endif
22348+.endm
22349+
22350+.macro pax_exit_kernel
22351+#ifdef CONFIG_PAX_KERNEXEC
22352+ call pax_exit_kernel
22353+#endif
22354+.endm
22355+
22356+#ifdef CONFIG_PAX_KERNEXEC
22357+ENTRY(pax_enter_kernel)
22358+#ifdef CONFIG_PARAVIRT
22359+ pushl %eax
22360+ pushl %ecx
22361+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
22362+ mov %eax, %esi
22363+#else
22364+ mov %cr0, %esi
22365+#endif
22366+ bts $16, %esi
22367+ jnc 1f
22368+ mov %cs, %esi
22369+ cmp $__KERNEL_CS, %esi
22370+ jz 3f
22371+ ljmp $__KERNEL_CS, $3f
22372+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
22373+2:
22374+#ifdef CONFIG_PARAVIRT
22375+ mov %esi, %eax
22376+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
22377+#else
22378+ mov %esi, %cr0
22379+#endif
22380+3:
22381+#ifdef CONFIG_PARAVIRT
22382+ popl %ecx
22383+ popl %eax
22384+#endif
22385+ ret
22386+ENDPROC(pax_enter_kernel)
22387+
22388+ENTRY(pax_exit_kernel)
22389+#ifdef CONFIG_PARAVIRT
22390+ pushl %eax
22391+ pushl %ecx
22392+#endif
22393+ mov %cs, %esi
22394+ cmp $__KERNEXEC_KERNEL_CS, %esi
22395+ jnz 2f
22396+#ifdef CONFIG_PARAVIRT
22397+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
22398+ mov %eax, %esi
22399+#else
22400+ mov %cr0, %esi
22401+#endif
22402+ btr $16, %esi
22403+ ljmp $__KERNEL_CS, $1f
22404+1:
22405+#ifdef CONFIG_PARAVIRT
22406+ mov %esi, %eax
22407+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
22408+#else
22409+ mov %esi, %cr0
22410+#endif
22411+2:
22412+#ifdef CONFIG_PARAVIRT
22413+ popl %ecx
22414+ popl %eax
22415+#endif
22416+ ret
22417+ENDPROC(pax_exit_kernel)
22418+#endif
22419+
22420+ .macro pax_erase_kstack
22421+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22422+ call pax_erase_kstack
22423+#endif
22424+ .endm
22425+
22426+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22427+/*
22428+ * ebp: thread_info
22429+ */
22430+ENTRY(pax_erase_kstack)
22431+ pushl %edi
22432+ pushl %ecx
22433+ pushl %eax
22434+
22435+ mov TI_lowest_stack(%ebp), %edi
22436+ mov $-0xBEEF, %eax
22437+ std
22438+
22439+1: mov %edi, %ecx
22440+ and $THREAD_SIZE_asm - 1, %ecx
22441+ shr $2, %ecx
22442+ repne scasl
22443+ jecxz 2f
22444+
22445+ cmp $2*16, %ecx
22446+ jc 2f
22447+
22448+ mov $2*16, %ecx
22449+ repe scasl
22450+ jecxz 2f
22451+ jne 1b
22452+
22453+2: cld
22454+ mov %esp, %ecx
22455+ sub %edi, %ecx
22456+
22457+ cmp $THREAD_SIZE_asm, %ecx
22458+ jb 3f
22459+ ud2
22460+3:
22461+
22462+ shr $2, %ecx
22463+ rep stosl
22464+
22465+ mov TI_task_thread_sp0(%ebp), %edi
22466+ sub $128, %edi
22467+ mov %edi, TI_lowest_stack(%ebp)
22468+
22469+ popl %eax
22470+ popl %ecx
22471+ popl %edi
22472+ ret
22473+ENDPROC(pax_erase_kstack)
22474+#endif
22475+
22476+.macro __SAVE_ALL _DS
22477 cld
22478 PUSH_GS
22479 pushl_cfi %fs
22480@@ -206,7 +346,7 @@
22481 CFI_REL_OFFSET ecx, 0
22482 pushl_cfi %ebx
22483 CFI_REL_OFFSET ebx, 0
22484- movl $(__USER_DS), %edx
22485+ movl $\_DS, %edx
22486 movl %edx, %ds
22487 movl %edx, %es
22488 movl $(__KERNEL_PERCPU), %edx
22489@@ -214,6 +354,15 @@
22490 SET_KERNEL_GS %edx
22491 .endm
22492
22493+.macro SAVE_ALL
22494+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22495+ __SAVE_ALL __KERNEL_DS
22496+ pax_enter_kernel
22497+#else
22498+ __SAVE_ALL __USER_DS
22499+#endif
22500+.endm
22501+
22502 .macro RESTORE_INT_REGS
22503 popl_cfi %ebx
22504 CFI_RESTORE ebx
22505@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
22506 popfl_cfi
22507 jmp syscall_exit
22508 CFI_ENDPROC
22509-END(ret_from_fork)
22510+ENDPROC(ret_from_fork)
22511
22512 ENTRY(ret_from_kernel_thread)
22513 CFI_STARTPROC
22514@@ -344,7 +493,15 @@ ret_from_intr:
22515 andl $SEGMENT_RPL_MASK, %eax
22516 #endif
22517 cmpl $USER_RPL, %eax
22518+
22519+#ifdef CONFIG_PAX_KERNEXEC
22520+ jae resume_userspace
22521+
22522+ pax_exit_kernel
22523+ jmp resume_kernel
22524+#else
22525 jb resume_kernel # not returning to v8086 or userspace
22526+#endif
22527
22528 ENTRY(resume_userspace)
22529 LOCKDEP_SYS_EXIT
22530@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
22531 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
22532 # int/exception return?
22533 jne work_pending
22534- jmp restore_all
22535-END(ret_from_exception)
22536+ jmp restore_all_pax
22537+ENDPROC(ret_from_exception)
22538
22539 #ifdef CONFIG_PREEMPT
22540 ENTRY(resume_kernel)
22541@@ -369,7 +526,7 @@ need_resched:
22542 jz restore_all
22543 call preempt_schedule_irq
22544 jmp need_resched
22545-END(resume_kernel)
22546+ENDPROC(resume_kernel)
22547 #endif
22548 CFI_ENDPROC
22549 /*
22550@@ -403,30 +560,45 @@ sysenter_past_esp:
22551 /*CFI_REL_OFFSET cs, 0*/
22552 /*
22553 * Push current_thread_info()->sysenter_return to the stack.
22554- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
22555- * pushed above; +8 corresponds to copy_thread's esp0 setting.
22556 */
22557- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
22558+ pushl_cfi $0
22559 CFI_REL_OFFSET eip, 0
22560
22561 pushl_cfi %eax
22562 SAVE_ALL
22563+ GET_THREAD_INFO(%ebp)
22564+ movl TI_sysenter_return(%ebp),%ebp
22565+ movl %ebp,PT_EIP(%esp)
22566 ENABLE_INTERRUPTS(CLBR_NONE)
22567
22568 /*
22569 * Load the potential sixth argument from user stack.
22570 * Careful about security.
22571 */
22572+ movl PT_OLDESP(%esp),%ebp
22573+
22574+#ifdef CONFIG_PAX_MEMORY_UDEREF
22575+ mov PT_OLDSS(%esp),%ds
22576+1: movl %ds:(%ebp),%ebp
22577+ push %ss
22578+ pop %ds
22579+#else
22580 cmpl $__PAGE_OFFSET-3,%ebp
22581 jae syscall_fault
22582 ASM_STAC
22583 1: movl (%ebp),%ebp
22584 ASM_CLAC
22585+#endif
22586+
22587 movl %ebp,PT_EBP(%esp)
22588 _ASM_EXTABLE(1b,syscall_fault)
22589
22590 GET_THREAD_INFO(%ebp)
22591
22592+#ifdef CONFIG_PAX_RANDKSTACK
22593+ pax_erase_kstack
22594+#endif
22595+
22596 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22597 jnz sysenter_audit
22598 sysenter_do_call:
22599@@ -441,12 +613,24 @@ sysenter_do_call:
22600 testl $_TIF_ALLWORK_MASK, %ecx
22601 jne sysexit_audit
22602 sysenter_exit:
22603+
22604+#ifdef CONFIG_PAX_RANDKSTACK
22605+ pushl_cfi %eax
22606+ movl %esp, %eax
22607+ call pax_randomize_kstack
22608+ popl_cfi %eax
22609+#endif
22610+
22611+ pax_erase_kstack
22612+
22613 /* if something modifies registers it must also disable sysexit */
22614 movl PT_EIP(%esp), %edx
22615 movl PT_OLDESP(%esp), %ecx
22616 xorl %ebp,%ebp
22617 TRACE_IRQS_ON
22618 1: mov PT_FS(%esp), %fs
22619+2: mov PT_DS(%esp), %ds
22620+3: mov PT_ES(%esp), %es
22621 PTGS_TO_GS
22622 ENABLE_INTERRUPTS_SYSEXIT
22623
22624@@ -463,6 +647,9 @@ sysenter_audit:
22625 movl %eax,%edx /* 2nd arg: syscall number */
22626 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
22627 call __audit_syscall_entry
22628+
22629+ pax_erase_kstack
22630+
22631 pushl_cfi %ebx
22632 movl PT_EAX(%esp),%eax /* reload syscall number */
22633 jmp sysenter_do_call
22634@@ -488,10 +675,16 @@ sysexit_audit:
22635
22636 CFI_ENDPROC
22637 .pushsection .fixup,"ax"
22638-2: movl $0,PT_FS(%esp)
22639+4: movl $0,PT_FS(%esp)
22640+ jmp 1b
22641+5: movl $0,PT_DS(%esp)
22642+ jmp 1b
22643+6: movl $0,PT_ES(%esp)
22644 jmp 1b
22645 .popsection
22646- _ASM_EXTABLE(1b,2b)
22647+ _ASM_EXTABLE(1b,4b)
22648+ _ASM_EXTABLE(2b,5b)
22649+ _ASM_EXTABLE(3b,6b)
22650 PTGS_TO_GS_EX
22651 ENDPROC(ia32_sysenter_target)
22652
22653@@ -506,6 +699,11 @@ ENTRY(system_call)
22654 pushl_cfi %eax # save orig_eax
22655 SAVE_ALL
22656 GET_THREAD_INFO(%ebp)
22657+
22658+#ifdef CONFIG_PAX_RANDKSTACK
22659+ pax_erase_kstack
22660+#endif
22661+
22662 # system call tracing in operation / emulation
22663 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22664 jnz syscall_trace_entry
22665@@ -524,6 +722,15 @@ syscall_exit:
22666 testl $_TIF_ALLWORK_MASK, %ecx # current->work
22667 jne syscall_exit_work
22668
22669+restore_all_pax:
22670+
22671+#ifdef CONFIG_PAX_RANDKSTACK
22672+ movl %esp, %eax
22673+ call pax_randomize_kstack
22674+#endif
22675+
22676+ pax_erase_kstack
22677+
22678 restore_all:
22679 TRACE_IRQS_IRET
22680 restore_all_notrace:
22681@@ -580,14 +787,34 @@ ldt_ss:
22682 * compensating for the offset by changing to the ESPFIX segment with
22683 * a base address that matches for the difference.
22684 */
22685-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
22686+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
22687 mov %esp, %edx /* load kernel esp */
22688 mov PT_OLDESP(%esp), %eax /* load userspace esp */
22689 mov %dx, %ax /* eax: new kernel esp */
22690 sub %eax, %edx /* offset (low word is 0) */
22691+#ifdef CONFIG_SMP
22692+ movl PER_CPU_VAR(cpu_number), %ebx
22693+ shll $PAGE_SHIFT_asm, %ebx
22694+ addl $cpu_gdt_table, %ebx
22695+#else
22696+ movl $cpu_gdt_table, %ebx
22697+#endif
22698 shr $16, %edx
22699- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
22700- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
22701+
22702+#ifdef CONFIG_PAX_KERNEXEC
22703+ mov %cr0, %esi
22704+ btr $16, %esi
22705+ mov %esi, %cr0
22706+#endif
22707+
22708+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
22709+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
22710+
22711+#ifdef CONFIG_PAX_KERNEXEC
22712+ bts $16, %esi
22713+ mov %esi, %cr0
22714+#endif
22715+
22716 pushl_cfi $__ESPFIX_SS
22717 pushl_cfi %eax /* new kernel esp */
22718 /* Disable interrupts, but do not irqtrace this section: we
22719@@ -616,20 +843,18 @@ work_resched:
22720 movl TI_flags(%ebp), %ecx
22721 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
22722 # than syscall tracing?
22723- jz restore_all
22724+ jz restore_all_pax
22725 testb $_TIF_NEED_RESCHED, %cl
22726 jnz work_resched
22727
22728 work_notifysig: # deal with pending signals and
22729 # notify-resume requests
22730+ movl %esp, %eax
22731 #ifdef CONFIG_VM86
22732 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
22733- movl %esp, %eax
22734 jne work_notifysig_v86 # returning to kernel-space or
22735 # vm86-space
22736 1:
22737-#else
22738- movl %esp, %eax
22739 #endif
22740 TRACE_IRQS_ON
22741 ENABLE_INTERRUPTS(CLBR_NONE)
22742@@ -650,7 +875,7 @@ work_notifysig_v86:
22743 movl %eax, %esp
22744 jmp 1b
22745 #endif
22746-END(work_pending)
22747+ENDPROC(work_pending)
22748
22749 # perform syscall exit tracing
22750 ALIGN
22751@@ -658,11 +883,14 @@ syscall_trace_entry:
22752 movl $-ENOSYS,PT_EAX(%esp)
22753 movl %esp, %eax
22754 call syscall_trace_enter
22755+
22756+ pax_erase_kstack
22757+
22758 /* What it returned is what we'll actually use. */
22759 cmpl $(NR_syscalls), %eax
22760 jnae syscall_call
22761 jmp syscall_exit
22762-END(syscall_trace_entry)
22763+ENDPROC(syscall_trace_entry)
22764
22765 # perform syscall exit tracing
22766 ALIGN
22767@@ -675,21 +903,25 @@ syscall_exit_work:
22768 movl %esp, %eax
22769 call syscall_trace_leave
22770 jmp resume_userspace
22771-END(syscall_exit_work)
22772+ENDPROC(syscall_exit_work)
22773 CFI_ENDPROC
22774
22775 RING0_INT_FRAME # can't unwind into user space anyway
22776 syscall_fault:
22777+#ifdef CONFIG_PAX_MEMORY_UDEREF
22778+ push %ss
22779+ pop %ds
22780+#endif
22781 ASM_CLAC
22782 GET_THREAD_INFO(%ebp)
22783 movl $-EFAULT,PT_EAX(%esp)
22784 jmp resume_userspace
22785-END(syscall_fault)
22786+ENDPROC(syscall_fault)
22787
22788 syscall_badsys:
22789 movl $-ENOSYS,PT_EAX(%esp)
22790 jmp resume_userspace
22791-END(syscall_badsys)
22792+ENDPROC(syscall_badsys)
22793 CFI_ENDPROC
22794 /*
22795 * End of kprobes section
22796@@ -705,8 +937,15 @@ END(syscall_badsys)
22797 * normal stack and adjusts ESP with the matching offset.
22798 */
22799 /* fixup the stack */
22800- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
22801- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
22802+#ifdef CONFIG_SMP
22803+ movl PER_CPU_VAR(cpu_number), %ebx
22804+ shll $PAGE_SHIFT_asm, %ebx
22805+ addl $cpu_gdt_table, %ebx
22806+#else
22807+ movl $cpu_gdt_table, %ebx
22808+#endif
22809+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
22810+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
22811 shl $16, %eax
22812 addl %esp, %eax /* the adjusted stack pointer */
22813 pushl_cfi $__KERNEL_DS
22814@@ -759,7 +998,7 @@ vector=vector+1
22815 .endr
22816 2: jmp common_interrupt
22817 .endr
22818-END(irq_entries_start)
22819+ENDPROC(irq_entries_start)
22820
22821 .previous
22822 END(interrupt)
22823@@ -820,7 +1059,7 @@ ENTRY(coprocessor_error)
22824 pushl_cfi $do_coprocessor_error
22825 jmp error_code
22826 CFI_ENDPROC
22827-END(coprocessor_error)
22828+ENDPROC(coprocessor_error)
22829
22830 ENTRY(simd_coprocessor_error)
22831 RING0_INT_FRAME
22832@@ -833,7 +1072,7 @@ ENTRY(simd_coprocessor_error)
22833 .section .altinstructions,"a"
22834 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
22835 .previous
22836-.section .altinstr_replacement,"ax"
22837+.section .altinstr_replacement,"a"
22838 663: pushl $do_simd_coprocessor_error
22839 664:
22840 .previous
22841@@ -842,7 +1081,7 @@ ENTRY(simd_coprocessor_error)
22842 #endif
22843 jmp error_code
22844 CFI_ENDPROC
22845-END(simd_coprocessor_error)
22846+ENDPROC(simd_coprocessor_error)
22847
22848 ENTRY(device_not_available)
22849 RING0_INT_FRAME
22850@@ -851,18 +1090,18 @@ ENTRY(device_not_available)
22851 pushl_cfi $do_device_not_available
22852 jmp error_code
22853 CFI_ENDPROC
22854-END(device_not_available)
22855+ENDPROC(device_not_available)
22856
22857 #ifdef CONFIG_PARAVIRT
22858 ENTRY(native_iret)
22859 iret
22860 _ASM_EXTABLE(native_iret, iret_exc)
22861-END(native_iret)
22862+ENDPROC(native_iret)
22863
22864 ENTRY(native_irq_enable_sysexit)
22865 sti
22866 sysexit
22867-END(native_irq_enable_sysexit)
22868+ENDPROC(native_irq_enable_sysexit)
22869 #endif
22870
22871 ENTRY(overflow)
22872@@ -872,7 +1111,7 @@ ENTRY(overflow)
22873 pushl_cfi $do_overflow
22874 jmp error_code
22875 CFI_ENDPROC
22876-END(overflow)
22877+ENDPROC(overflow)
22878
22879 ENTRY(bounds)
22880 RING0_INT_FRAME
22881@@ -881,7 +1120,7 @@ ENTRY(bounds)
22882 pushl_cfi $do_bounds
22883 jmp error_code
22884 CFI_ENDPROC
22885-END(bounds)
22886+ENDPROC(bounds)
22887
22888 ENTRY(invalid_op)
22889 RING0_INT_FRAME
22890@@ -890,7 +1129,7 @@ ENTRY(invalid_op)
22891 pushl_cfi $do_invalid_op
22892 jmp error_code
22893 CFI_ENDPROC
22894-END(invalid_op)
22895+ENDPROC(invalid_op)
22896
22897 ENTRY(coprocessor_segment_overrun)
22898 RING0_INT_FRAME
22899@@ -899,7 +1138,7 @@ ENTRY(coprocessor_segment_overrun)
22900 pushl_cfi $do_coprocessor_segment_overrun
22901 jmp error_code
22902 CFI_ENDPROC
22903-END(coprocessor_segment_overrun)
22904+ENDPROC(coprocessor_segment_overrun)
22905
22906 ENTRY(invalid_TSS)
22907 RING0_EC_FRAME
22908@@ -907,7 +1146,7 @@ ENTRY(invalid_TSS)
22909 pushl_cfi $do_invalid_TSS
22910 jmp error_code
22911 CFI_ENDPROC
22912-END(invalid_TSS)
22913+ENDPROC(invalid_TSS)
22914
22915 ENTRY(segment_not_present)
22916 RING0_EC_FRAME
22917@@ -915,7 +1154,7 @@ ENTRY(segment_not_present)
22918 pushl_cfi $do_segment_not_present
22919 jmp error_code
22920 CFI_ENDPROC
22921-END(segment_not_present)
22922+ENDPROC(segment_not_present)
22923
22924 ENTRY(stack_segment)
22925 RING0_EC_FRAME
22926@@ -923,7 +1162,7 @@ ENTRY(stack_segment)
22927 pushl_cfi $do_stack_segment
22928 jmp error_code
22929 CFI_ENDPROC
22930-END(stack_segment)
22931+ENDPROC(stack_segment)
22932
22933 ENTRY(alignment_check)
22934 RING0_EC_FRAME
22935@@ -931,7 +1170,7 @@ ENTRY(alignment_check)
22936 pushl_cfi $do_alignment_check
22937 jmp error_code
22938 CFI_ENDPROC
22939-END(alignment_check)
22940+ENDPROC(alignment_check)
22941
22942 ENTRY(divide_error)
22943 RING0_INT_FRAME
22944@@ -940,7 +1179,7 @@ ENTRY(divide_error)
22945 pushl_cfi $do_divide_error
22946 jmp error_code
22947 CFI_ENDPROC
22948-END(divide_error)
22949+ENDPROC(divide_error)
22950
22951 #ifdef CONFIG_X86_MCE
22952 ENTRY(machine_check)
22953@@ -950,7 +1189,7 @@ ENTRY(machine_check)
22954 pushl_cfi machine_check_vector
22955 jmp error_code
22956 CFI_ENDPROC
22957-END(machine_check)
22958+ENDPROC(machine_check)
22959 #endif
22960
22961 ENTRY(spurious_interrupt_bug)
22962@@ -960,7 +1199,7 @@ ENTRY(spurious_interrupt_bug)
22963 pushl_cfi $do_spurious_interrupt_bug
22964 jmp error_code
22965 CFI_ENDPROC
22966-END(spurious_interrupt_bug)
22967+ENDPROC(spurious_interrupt_bug)
22968 /*
22969 * End of kprobes section
22970 */
22971@@ -1070,7 +1309,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
22972
22973 ENTRY(mcount)
22974 ret
22975-END(mcount)
22976+ENDPROC(mcount)
22977
22978 ENTRY(ftrace_caller)
22979 cmpl $0, function_trace_stop
22980@@ -1103,7 +1342,7 @@ ftrace_graph_call:
22981 .globl ftrace_stub
22982 ftrace_stub:
22983 ret
22984-END(ftrace_caller)
22985+ENDPROC(ftrace_caller)
22986
22987 ENTRY(ftrace_regs_caller)
22988 pushf /* push flags before compare (in cs location) */
22989@@ -1207,7 +1446,7 @@ trace:
22990 popl %ecx
22991 popl %eax
22992 jmp ftrace_stub
22993-END(mcount)
22994+ENDPROC(mcount)
22995 #endif /* CONFIG_DYNAMIC_FTRACE */
22996 #endif /* CONFIG_FUNCTION_TRACER */
22997
22998@@ -1225,7 +1464,7 @@ ENTRY(ftrace_graph_caller)
22999 popl %ecx
23000 popl %eax
23001 ret
23002-END(ftrace_graph_caller)
23003+ENDPROC(ftrace_graph_caller)
23004
23005 .globl return_to_handler
23006 return_to_handler:
23007@@ -1291,15 +1530,18 @@ error_code:
23008 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
23009 REG_TO_PTGS %ecx
23010 SET_KERNEL_GS %ecx
23011- movl $(__USER_DS), %ecx
23012+ movl $(__KERNEL_DS), %ecx
23013 movl %ecx, %ds
23014 movl %ecx, %es
23015+
23016+ pax_enter_kernel
23017+
23018 TRACE_IRQS_OFF
23019 movl %esp,%eax # pt_regs pointer
23020 call *%edi
23021 jmp ret_from_exception
23022 CFI_ENDPROC
23023-END(page_fault)
23024+ENDPROC(page_fault)
23025
23026 /*
23027 * Debug traps and NMI can happen at the one SYSENTER instruction
23028@@ -1342,7 +1584,7 @@ debug_stack_correct:
23029 call do_debug
23030 jmp ret_from_exception
23031 CFI_ENDPROC
23032-END(debug)
23033+ENDPROC(debug)
23034
23035 /*
23036 * NMI is doubly nasty. It can happen _while_ we're handling
23037@@ -1380,6 +1622,9 @@ nmi_stack_correct:
23038 xorl %edx,%edx # zero error code
23039 movl %esp,%eax # pt_regs pointer
23040 call do_nmi
23041+
23042+ pax_exit_kernel
23043+
23044 jmp restore_all_notrace
23045 CFI_ENDPROC
23046
23047@@ -1416,12 +1661,15 @@ nmi_espfix_stack:
23048 FIXUP_ESPFIX_STACK # %eax == %esp
23049 xorl %edx,%edx # zero error code
23050 call do_nmi
23051+
23052+ pax_exit_kernel
23053+
23054 RESTORE_REGS
23055 lss 12+4(%esp), %esp # back to espfix stack
23056 CFI_ADJUST_CFA_OFFSET -24
23057 jmp irq_return
23058 CFI_ENDPROC
23059-END(nmi)
23060+ENDPROC(nmi)
23061
23062 ENTRY(int3)
23063 RING0_INT_FRAME
23064@@ -1434,14 +1682,14 @@ ENTRY(int3)
23065 call do_int3
23066 jmp ret_from_exception
23067 CFI_ENDPROC
23068-END(int3)
23069+ENDPROC(int3)
23070
23071 ENTRY(general_protection)
23072 RING0_EC_FRAME
23073 pushl_cfi $do_general_protection
23074 jmp error_code
23075 CFI_ENDPROC
23076-END(general_protection)
23077+ENDPROC(general_protection)
23078
23079 #ifdef CONFIG_KVM_GUEST
23080 ENTRY(async_page_fault)
23081@@ -1450,7 +1698,7 @@ ENTRY(async_page_fault)
23082 pushl_cfi $do_async_page_fault
23083 jmp error_code
23084 CFI_ENDPROC
23085-END(async_page_fault)
23086+ENDPROC(async_page_fault)
23087 #endif
23088
23089 /*
23090diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
23091index 1e96c36..3ff710a 100644
23092--- a/arch/x86/kernel/entry_64.S
23093+++ b/arch/x86/kernel/entry_64.S
23094@@ -59,6 +59,8 @@
23095 #include <asm/context_tracking.h>
23096 #include <asm/smap.h>
23097 #include <linux/err.h>
23098+#include <asm/pgtable.h>
23099+#include <asm/alternative-asm.h>
23100
23101 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
23102 #include <linux/elf-em.h>
23103@@ -80,8 +82,9 @@
23104 #ifdef CONFIG_DYNAMIC_FTRACE
23105
23106 ENTRY(function_hook)
23107+ pax_force_retaddr
23108 retq
23109-END(function_hook)
23110+ENDPROC(function_hook)
23111
23112 /* skip is set if stack has been adjusted */
23113 .macro ftrace_caller_setup skip=0
23114@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
23115 #endif
23116
23117 GLOBAL(ftrace_stub)
23118+ pax_force_retaddr
23119 retq
23120-END(ftrace_caller)
23121+ENDPROC(ftrace_caller)
23122
23123 ENTRY(ftrace_regs_caller)
23124 /* Save the current flags before compare (in SS location)*/
23125@@ -191,7 +195,7 @@ ftrace_restore_flags:
23126 popfq
23127 jmp ftrace_stub
23128
23129-END(ftrace_regs_caller)
23130+ENDPROC(ftrace_regs_caller)
23131
23132
23133 #else /* ! CONFIG_DYNAMIC_FTRACE */
23134@@ -212,6 +216,7 @@ ENTRY(function_hook)
23135 #endif
23136
23137 GLOBAL(ftrace_stub)
23138+ pax_force_retaddr
23139 retq
23140
23141 trace:
23142@@ -225,12 +230,13 @@ trace:
23143 #endif
23144 subq $MCOUNT_INSN_SIZE, %rdi
23145
23146+ pax_force_fptr ftrace_trace_function
23147 call *ftrace_trace_function
23148
23149 MCOUNT_RESTORE_FRAME
23150
23151 jmp ftrace_stub
23152-END(function_hook)
23153+ENDPROC(function_hook)
23154 #endif /* CONFIG_DYNAMIC_FTRACE */
23155 #endif /* CONFIG_FUNCTION_TRACER */
23156
23157@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
23158
23159 MCOUNT_RESTORE_FRAME
23160
23161+ pax_force_retaddr
23162 retq
23163-END(ftrace_graph_caller)
23164+ENDPROC(ftrace_graph_caller)
23165
23166 GLOBAL(return_to_handler)
23167 subq $24, %rsp
23168@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
23169 movq 8(%rsp), %rdx
23170 movq (%rsp), %rax
23171 addq $24, %rsp
23172+ pax_force_fptr %rdi
23173 jmp *%rdi
23174+ENDPROC(return_to_handler)
23175 #endif
23176
23177
23178@@ -284,6 +293,430 @@ ENTRY(native_usergs_sysret64)
23179 ENDPROC(native_usergs_sysret64)
23180 #endif /* CONFIG_PARAVIRT */
23181
23182+ .macro ljmpq sel, off
23183+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
23184+ .byte 0x48; ljmp *1234f(%rip)
23185+ .pushsection .rodata
23186+ .align 16
23187+ 1234: .quad \off; .word \sel
23188+ .popsection
23189+#else
23190+ pushq $\sel
23191+ pushq $\off
23192+ lretq
23193+#endif
23194+ .endm
23195+
23196+ .macro pax_enter_kernel
23197+ pax_set_fptr_mask
23198+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23199+ call pax_enter_kernel
23200+#endif
23201+ .endm
23202+
23203+ .macro pax_exit_kernel
23204+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23205+ call pax_exit_kernel
23206+#endif
23207+
23208+ .endm
23209+
23210+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23211+ENTRY(pax_enter_kernel)
23212+ pushq %rdi
23213+
23214+#ifdef CONFIG_PARAVIRT
23215+ PV_SAVE_REGS(CLBR_RDI)
23216+#endif
23217+
23218+#ifdef CONFIG_PAX_KERNEXEC
23219+ GET_CR0_INTO_RDI
23220+ bts $16,%rdi
23221+ jnc 3f
23222+ mov %cs,%edi
23223+ cmp $__KERNEL_CS,%edi
23224+ jnz 2f
23225+1:
23226+#endif
23227+
23228+#ifdef CONFIG_PAX_MEMORY_UDEREF
23229+ 661: jmp 111f
23230+ .pushsection .altinstr_replacement, "a"
23231+ 662: ASM_NOP2
23232+ .popsection
23233+ .pushsection .altinstructions, "a"
23234+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23235+ .popsection
23236+ GET_CR3_INTO_RDI
23237+ cmp $0,%dil
23238+ jnz 112f
23239+ mov $__KERNEL_DS,%edi
23240+ mov %edi,%ss
23241+ jmp 111f
23242+112: cmp $1,%dil
23243+ jz 113f
23244+ ud2
23245+113: sub $4097,%rdi
23246+ bts $63,%rdi
23247+ SET_RDI_INTO_CR3
23248+ mov $__UDEREF_KERNEL_DS,%edi
23249+ mov %edi,%ss
23250+111:
23251+#endif
23252+
23253+#ifdef CONFIG_PARAVIRT
23254+ PV_RESTORE_REGS(CLBR_RDI)
23255+#endif
23256+
23257+ popq %rdi
23258+ pax_force_retaddr
23259+ retq
23260+
23261+#ifdef CONFIG_PAX_KERNEXEC
23262+2: ljmpq __KERNEL_CS,1b
23263+3: ljmpq __KERNEXEC_KERNEL_CS,4f
23264+4: SET_RDI_INTO_CR0
23265+ jmp 1b
23266+#endif
23267+ENDPROC(pax_enter_kernel)
23268+
23269+ENTRY(pax_exit_kernel)
23270+ pushq %rdi
23271+
23272+#ifdef CONFIG_PARAVIRT
23273+ PV_SAVE_REGS(CLBR_RDI)
23274+#endif
23275+
23276+#ifdef CONFIG_PAX_KERNEXEC
23277+ mov %cs,%rdi
23278+ cmp $__KERNEXEC_KERNEL_CS,%edi
23279+ jz 2f
23280+ GET_CR0_INTO_RDI
23281+ bts $16,%rdi
23282+ jnc 4f
23283+1:
23284+#endif
23285+
23286+#ifdef CONFIG_PAX_MEMORY_UDEREF
23287+ 661: jmp 111f
23288+ .pushsection .altinstr_replacement, "a"
23289+ 662: ASM_NOP2
23290+ .popsection
23291+ .pushsection .altinstructions, "a"
23292+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23293+ .popsection
23294+ mov %ss,%edi
23295+ cmp $__UDEREF_KERNEL_DS,%edi
23296+ jnz 111f
23297+ GET_CR3_INTO_RDI
23298+ cmp $0,%dil
23299+ jz 112f
23300+ ud2
23301+112: add $4097,%rdi
23302+ bts $63,%rdi
23303+ SET_RDI_INTO_CR3
23304+ mov $__KERNEL_DS,%edi
23305+ mov %edi,%ss
23306+111:
23307+#endif
23308+
23309+#ifdef CONFIG_PARAVIRT
23310+ PV_RESTORE_REGS(CLBR_RDI);
23311+#endif
23312+
23313+ popq %rdi
23314+ pax_force_retaddr
23315+ retq
23316+
23317+#ifdef CONFIG_PAX_KERNEXEC
23318+2: GET_CR0_INTO_RDI
23319+ btr $16,%rdi
23320+ jnc 4f
23321+ ljmpq __KERNEL_CS,3f
23322+3: SET_RDI_INTO_CR0
23323+ jmp 1b
23324+4: ud2
23325+ jmp 4b
23326+#endif
23327+ENDPROC(pax_exit_kernel)
23328+#endif
23329+
23330+ .macro pax_enter_kernel_user
23331+ pax_set_fptr_mask
23332+#ifdef CONFIG_PAX_MEMORY_UDEREF
23333+ call pax_enter_kernel_user
23334+#endif
23335+ .endm
23336+
23337+ .macro pax_exit_kernel_user
23338+#ifdef CONFIG_PAX_MEMORY_UDEREF
23339+ call pax_exit_kernel_user
23340+#endif
23341+#ifdef CONFIG_PAX_RANDKSTACK
23342+ pushq %rax
23343+ pushq %r11
23344+ call pax_randomize_kstack
23345+ popq %r11
23346+ popq %rax
23347+#endif
23348+ .endm
23349+
23350+#ifdef CONFIG_PAX_MEMORY_UDEREF
23351+ENTRY(pax_enter_kernel_user)
23352+ pushq %rdi
23353+ pushq %rbx
23354+
23355+#ifdef CONFIG_PARAVIRT
23356+ PV_SAVE_REGS(CLBR_RDI)
23357+#endif
23358+
23359+ 661: jmp 111f
23360+ .pushsection .altinstr_replacement, "a"
23361+ 662: ASM_NOP2
23362+ .popsection
23363+ .pushsection .altinstructions, "a"
23364+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23365+ .popsection
23366+ GET_CR3_INTO_RDI
23367+ cmp $1,%dil
23368+ jnz 4f
23369+ sub $4097,%rdi
23370+ bts $63,%rdi
23371+ SET_RDI_INTO_CR3
23372+ jmp 3f
23373+111:
23374+
23375+ GET_CR3_INTO_RDI
23376+ mov %rdi,%rbx
23377+ add $__START_KERNEL_map,%rbx
23378+ sub phys_base(%rip),%rbx
23379+
23380+#ifdef CONFIG_PARAVIRT
23381+ cmpl $0, pv_info+PARAVIRT_enabled
23382+ jz 1f
23383+ pushq %rdi
23384+ i = 0
23385+ .rept USER_PGD_PTRS
23386+ mov i*8(%rbx),%rsi
23387+ mov $0,%sil
23388+ lea i*8(%rbx),%rdi
23389+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23390+ i = i + 1
23391+ .endr
23392+ popq %rdi
23393+ jmp 2f
23394+1:
23395+#endif
23396+
23397+ i = 0
23398+ .rept USER_PGD_PTRS
23399+ movb $0,i*8(%rbx)
23400+ i = i + 1
23401+ .endr
23402+
23403+2: SET_RDI_INTO_CR3
23404+
23405+#ifdef CONFIG_PAX_KERNEXEC
23406+ GET_CR0_INTO_RDI
23407+ bts $16,%rdi
23408+ SET_RDI_INTO_CR0
23409+#endif
23410+
23411+3:
23412+
23413+#ifdef CONFIG_PARAVIRT
23414+ PV_RESTORE_REGS(CLBR_RDI)
23415+#endif
23416+
23417+ popq %rbx
23418+ popq %rdi
23419+ pax_force_retaddr
23420+ retq
23421+4: ud2
23422+ENDPROC(pax_enter_kernel_user)
23423+
23424+ENTRY(pax_exit_kernel_user)
23425+ pushq %rdi
23426+ pushq %rbx
23427+
23428+#ifdef CONFIG_PARAVIRT
23429+ PV_SAVE_REGS(CLBR_RDI)
23430+#endif
23431+
23432+ GET_CR3_INTO_RDI
23433+ 661: jmp 1f
23434+ .pushsection .altinstr_replacement, "a"
23435+ 662: ASM_NOP2
23436+ .popsection
23437+ .pushsection .altinstructions, "a"
23438+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23439+ .popsection
23440+ cmp $0,%dil
23441+ jnz 3f
23442+ add $4097,%rdi
23443+ bts $63,%rdi
23444+ SET_RDI_INTO_CR3
23445+ jmp 2f
23446+1:
23447+
23448+ mov %rdi,%rbx
23449+
23450+#ifdef CONFIG_PAX_KERNEXEC
23451+ GET_CR0_INTO_RDI
23452+ btr $16,%rdi
23453+ jnc 3f
23454+ SET_RDI_INTO_CR0
23455+#endif
23456+
23457+ add $__START_KERNEL_map,%rbx
23458+ sub phys_base(%rip),%rbx
23459+
23460+#ifdef CONFIG_PARAVIRT
23461+ cmpl $0, pv_info+PARAVIRT_enabled
23462+ jz 1f
23463+ i = 0
23464+ .rept USER_PGD_PTRS
23465+ mov i*8(%rbx),%rsi
23466+ mov $0x67,%sil
23467+ lea i*8(%rbx),%rdi
23468+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23469+ i = i + 1
23470+ .endr
23471+ jmp 2f
23472+1:
23473+#endif
23474+
23475+ i = 0
23476+ .rept USER_PGD_PTRS
23477+ movb $0x67,i*8(%rbx)
23478+ i = i + 1
23479+ .endr
23480+2:
23481+
23482+#ifdef CONFIG_PARAVIRT
23483+ PV_RESTORE_REGS(CLBR_RDI)
23484+#endif
23485+
23486+ popq %rbx
23487+ popq %rdi
23488+ pax_force_retaddr
23489+ retq
23490+3: ud2
23491+ENDPROC(pax_exit_kernel_user)
23492+#endif
23493+
23494+ .macro pax_enter_kernel_nmi
23495+ pax_set_fptr_mask
23496+
23497+#ifdef CONFIG_PAX_KERNEXEC
23498+ GET_CR0_INTO_RDI
23499+ bts $16,%rdi
23500+ jc 110f
23501+ SET_RDI_INTO_CR0
23502+ or $2,%ebx
23503+110:
23504+#endif
23505+
23506+#ifdef CONFIG_PAX_MEMORY_UDEREF
23507+ 661: jmp 111f
23508+ .pushsection .altinstr_replacement, "a"
23509+ 662: ASM_NOP2
23510+ .popsection
23511+ .pushsection .altinstructions, "a"
23512+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23513+ .popsection
23514+ GET_CR3_INTO_RDI
23515+ cmp $0,%dil
23516+ jz 111f
23517+ sub $4097,%rdi
23518+ or $4,%ebx
23519+ bts $63,%rdi
23520+ SET_RDI_INTO_CR3
23521+ mov $__UDEREF_KERNEL_DS,%edi
23522+ mov %edi,%ss
23523+111:
23524+#endif
23525+ .endm
23526+
23527+ .macro pax_exit_kernel_nmi
23528+#ifdef CONFIG_PAX_KERNEXEC
23529+ btr $1,%ebx
23530+ jnc 110f
23531+ GET_CR0_INTO_RDI
23532+ btr $16,%rdi
23533+ SET_RDI_INTO_CR0
23534+110:
23535+#endif
23536+
23537+#ifdef CONFIG_PAX_MEMORY_UDEREF
23538+ btr $2,%ebx
23539+ jnc 111f
23540+ GET_CR3_INTO_RDI
23541+ add $4097,%rdi
23542+ bts $63,%rdi
23543+ SET_RDI_INTO_CR3
23544+ mov $__KERNEL_DS,%edi
23545+ mov %edi,%ss
23546+111:
23547+#endif
23548+ .endm
23549+
23550+ .macro pax_erase_kstack
23551+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23552+ call pax_erase_kstack
23553+#endif
23554+ .endm
23555+
23556+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23557+ENTRY(pax_erase_kstack)
23558+ pushq %rdi
23559+ pushq %rcx
23560+ pushq %rax
23561+ pushq %r11
23562+
23563+ GET_THREAD_INFO(%r11)
23564+ mov TI_lowest_stack(%r11), %rdi
23565+ mov $-0xBEEF, %rax
23566+ std
23567+
23568+1: mov %edi, %ecx
23569+ and $THREAD_SIZE_asm - 1, %ecx
23570+ shr $3, %ecx
23571+ repne scasq
23572+ jecxz 2f
23573+
23574+ cmp $2*8, %ecx
23575+ jc 2f
23576+
23577+ mov $2*8, %ecx
23578+ repe scasq
23579+ jecxz 2f
23580+ jne 1b
23581+
23582+2: cld
23583+ mov %esp, %ecx
23584+ sub %edi, %ecx
23585+
23586+ cmp $THREAD_SIZE_asm, %rcx
23587+ jb 3f
23588+ ud2
23589+3:
23590+
23591+ shr $3, %ecx
23592+ rep stosq
23593+
23594+ mov TI_task_thread_sp0(%r11), %rdi
23595+ sub $256, %rdi
23596+ mov %rdi, TI_lowest_stack(%r11)
23597+
23598+ popq %r11
23599+ popq %rax
23600+ popq %rcx
23601+ popq %rdi
23602+ pax_force_retaddr
23603+ ret
23604+ENDPROC(pax_erase_kstack)
23605+#endif
23606
23607 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
23608 #ifdef CONFIG_TRACE_IRQFLAGS
23609@@ -320,7 +753,7 @@ ENDPROC(native_usergs_sysret64)
23610 .endm
23611
23612 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
23613- bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
23614+ bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
23615 jnc 1f
23616 TRACE_IRQS_ON_DEBUG
23617 1:
23618@@ -358,27 +791,6 @@ ENDPROC(native_usergs_sysret64)
23619 movq \tmp,R11+\offset(%rsp)
23620 .endm
23621
23622- .macro FAKE_STACK_FRAME child_rip
23623- /* push in order ss, rsp, eflags, cs, rip */
23624- xorl %eax, %eax
23625- pushq_cfi $__KERNEL_DS /* ss */
23626- /*CFI_REL_OFFSET ss,0*/
23627- pushq_cfi %rax /* rsp */
23628- CFI_REL_OFFSET rsp,0
23629- pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
23630- /*CFI_REL_OFFSET rflags,0*/
23631- pushq_cfi $__KERNEL_CS /* cs */
23632- /*CFI_REL_OFFSET cs,0*/
23633- pushq_cfi \child_rip /* rip */
23634- CFI_REL_OFFSET rip,0
23635- pushq_cfi %rax /* orig rax */
23636- .endm
23637-
23638- .macro UNFAKE_STACK_FRAME
23639- addq $8*6, %rsp
23640- CFI_ADJUST_CFA_OFFSET -(6*8)
23641- .endm
23642-
23643 /*
23644 * initial frame state for interrupts (and exceptions without error code)
23645 */
23646@@ -445,25 +857,26 @@ ENDPROC(native_usergs_sysret64)
23647 /* save partial stack frame */
23648 .macro SAVE_ARGS_IRQ
23649 cld
23650- /* start from rbp in pt_regs and jump over */
23651- movq_cfi rdi, (RDI-RBP)
23652- movq_cfi rsi, (RSI-RBP)
23653- movq_cfi rdx, (RDX-RBP)
23654- movq_cfi rcx, (RCX-RBP)
23655- movq_cfi rax, (RAX-RBP)
23656- movq_cfi r8, (R8-RBP)
23657- movq_cfi r9, (R9-RBP)
23658- movq_cfi r10, (R10-RBP)
23659- movq_cfi r11, (R11-RBP)
23660+ /* start from r15 in pt_regs and jump over */
23661+ movq_cfi rdi, RDI
23662+ movq_cfi rsi, RSI
23663+ movq_cfi rdx, RDX
23664+ movq_cfi rcx, RCX
23665+ movq_cfi rax, RAX
23666+ movq_cfi r8, R8
23667+ movq_cfi r9, R9
23668+ movq_cfi r10, R10
23669+ movq_cfi r11, R11
23670+ movq_cfi r12, R12
23671
23672 /* Save rbp so that we can unwind from get_irq_regs() */
23673- movq_cfi rbp, 0
23674+ movq_cfi rbp, RBP
23675
23676 /* Save previous stack value */
23677 movq %rsp, %rsi
23678
23679- leaq -RBP(%rsp),%rdi /* arg1 for handler */
23680- testl $3, CS-RBP(%rsi)
23681+ movq %rsp,%rdi /* arg1 for handler */
23682+ testb $3, CS(%rsi)
23683 je 1f
23684 SWAPGS
23685 /*
23686@@ -483,6 +896,18 @@ ENDPROC(native_usergs_sysret64)
23687 0x06 /* DW_OP_deref */, \
23688 0x08 /* DW_OP_const1u */, SS+8-RBP, \
23689 0x22 /* DW_OP_plus */
23690+
23691+#ifdef CONFIG_PAX_MEMORY_UDEREF
23692+ testb $3, CS(%rdi)
23693+ jnz 1f
23694+ pax_enter_kernel
23695+ jmp 2f
23696+1: pax_enter_kernel_user
23697+2:
23698+#else
23699+ pax_enter_kernel
23700+#endif
23701+
23702 /* We entered an interrupt context - irqs are off: */
23703 TRACE_IRQS_OFF
23704 .endm
23705@@ -514,9 +939,52 @@ ENTRY(save_paranoid)
23706 js 1f /* negative -> in kernel */
23707 SWAPGS
23708 xorl %ebx,%ebx
23709-1: ret
23710+1:
23711+#ifdef CONFIG_PAX_MEMORY_UDEREF
23712+ testb $3, CS+8(%rsp)
23713+ jnz 1f
23714+ pax_enter_kernel
23715+ jmp 2f
23716+1: pax_enter_kernel_user
23717+2:
23718+#else
23719+ pax_enter_kernel
23720+#endif
23721+ pax_force_retaddr
23722+ ret
23723 CFI_ENDPROC
23724-END(save_paranoid)
23725+ENDPROC(save_paranoid)
23726+
23727+ENTRY(save_paranoid_nmi)
23728+ XCPT_FRAME 1 RDI+8
23729+ cld
23730+ movq_cfi rdi, RDI+8
23731+ movq_cfi rsi, RSI+8
23732+ movq_cfi rdx, RDX+8
23733+ movq_cfi rcx, RCX+8
23734+ movq_cfi rax, RAX+8
23735+ movq_cfi r8, R8+8
23736+ movq_cfi r9, R9+8
23737+ movq_cfi r10, R10+8
23738+ movq_cfi r11, R11+8
23739+ movq_cfi rbx, RBX+8
23740+ movq_cfi rbp, RBP+8
23741+ movq_cfi r12, R12+8
23742+ movq_cfi r13, R13+8
23743+ movq_cfi r14, R14+8
23744+ movq_cfi r15, R15+8
23745+ movl $1,%ebx
23746+ movl $MSR_GS_BASE,%ecx
23747+ rdmsr
23748+ testl %edx,%edx
23749+ js 1f /* negative -> in kernel */
23750+ SWAPGS
23751+ xorl %ebx,%ebx
23752+1: pax_enter_kernel_nmi
23753+ pax_force_retaddr
23754+ ret
23755+ CFI_ENDPROC
23756+ENDPROC(save_paranoid_nmi)
23757 .popsection
23758
23759 /*
23760@@ -538,7 +1006,7 @@ ENTRY(ret_from_fork)
23761
23762 RESTORE_REST
23763
23764- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23765+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23766 jz 1f
23767
23768 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
23769@@ -548,15 +1016,13 @@ ENTRY(ret_from_fork)
23770 jmp ret_from_sys_call # go to the SYSRET fastpath
23771
23772 1:
23773- subq $REST_SKIP, %rsp # leave space for volatiles
23774- CFI_ADJUST_CFA_OFFSET REST_SKIP
23775 movq %rbp, %rdi
23776 call *%rbx
23777 movl $0, RAX(%rsp)
23778 RESTORE_REST
23779 jmp int_ret_from_sys_call
23780 CFI_ENDPROC
23781-END(ret_from_fork)
23782+ENDPROC(ret_from_fork)
23783
23784 /*
23785 * System call entry. Up to 6 arguments in registers are supported.
23786@@ -593,7 +1059,7 @@ END(ret_from_fork)
23787 ENTRY(system_call)
23788 CFI_STARTPROC simple
23789 CFI_SIGNAL_FRAME
23790- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
23791+ CFI_DEF_CFA rsp,0
23792 CFI_REGISTER rip,rcx
23793 /*CFI_REGISTER rflags,r11*/
23794 SWAPGS_UNSAFE_STACK
23795@@ -606,16 +1072,23 @@ GLOBAL(system_call_after_swapgs)
23796
23797 movq %rsp,PER_CPU_VAR(old_rsp)
23798 movq PER_CPU_VAR(kernel_stack),%rsp
23799+ SAVE_ARGS 8*6,0
23800+ pax_enter_kernel_user
23801+
23802+#ifdef CONFIG_PAX_RANDKSTACK
23803+ pax_erase_kstack
23804+#endif
23805+
23806 /*
23807 * No need to follow this irqs off/on section - it's straight
23808 * and short:
23809 */
23810 ENABLE_INTERRUPTS(CLBR_NONE)
23811- SAVE_ARGS 8,0
23812 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
23813 movq %rcx,RIP-ARGOFFSET(%rsp)
23814 CFI_REL_OFFSET rip,RIP-ARGOFFSET
23815- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23816+ GET_THREAD_INFO(%rcx)
23817+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
23818 jnz tracesys
23819 system_call_fastpath:
23820 #if __SYSCALL_MASK == ~0
23821@@ -639,10 +1112,13 @@ sysret_check:
23822 LOCKDEP_SYS_EXIT
23823 DISABLE_INTERRUPTS(CLBR_NONE)
23824 TRACE_IRQS_OFF
23825- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
23826+ GET_THREAD_INFO(%rcx)
23827+ movl TI_flags(%rcx),%edx
23828 andl %edi,%edx
23829 jnz sysret_careful
23830 CFI_REMEMBER_STATE
23831+ pax_exit_kernel_user
23832+ pax_erase_kstack
23833 /*
23834 * sysretq will re-enable interrupts:
23835 */
23836@@ -701,6 +1177,9 @@ auditsys:
23837 movq %rax,%rsi /* 2nd arg: syscall number */
23838 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
23839 call __audit_syscall_entry
23840+
23841+ pax_erase_kstack
23842+
23843 LOAD_ARGS 0 /* reload call-clobbered registers */
23844 jmp system_call_fastpath
23845
23846@@ -722,7 +1201,7 @@ sysret_audit:
23847 /* Do syscall tracing */
23848 tracesys:
23849 #ifdef CONFIG_AUDITSYSCALL
23850- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23851+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
23852 jz auditsys
23853 #endif
23854 SAVE_REST
23855@@ -730,12 +1209,15 @@ tracesys:
23856 FIXUP_TOP_OF_STACK %rdi
23857 movq %rsp,%rdi
23858 call syscall_trace_enter
23859+
23860+ pax_erase_kstack
23861+
23862 /*
23863 * Reload arg registers from stack in case ptrace changed them.
23864 * We don't reload %rax because syscall_trace_enter() returned
23865 * the value it wants us to use in the table lookup.
23866 */
23867- LOAD_ARGS ARGOFFSET, 1
23868+ LOAD_ARGS 1
23869 RESTORE_REST
23870 #if __SYSCALL_MASK == ~0
23871 cmpq $__NR_syscall_max,%rax
23872@@ -765,7 +1247,9 @@ GLOBAL(int_with_check)
23873 andl %edi,%edx
23874 jnz int_careful
23875 andl $~TS_COMPAT,TI_status(%rcx)
23876- jmp retint_swapgs
23877+ pax_exit_kernel_user
23878+ pax_erase_kstack
23879+ jmp retint_swapgs_pax
23880
23881 /* Either reschedule or signal or syscall exit tracking needed. */
23882 /* First do a reschedule test. */
23883@@ -811,7 +1295,7 @@ int_restore_rest:
23884 TRACE_IRQS_OFF
23885 jmp int_with_check
23886 CFI_ENDPROC
23887-END(system_call)
23888+ENDPROC(system_call)
23889
23890 .macro FORK_LIKE func
23891 ENTRY(stub_\func)
23892@@ -824,9 +1308,10 @@ ENTRY(stub_\func)
23893 DEFAULT_FRAME 0 8 /* offset 8: return address */
23894 call sys_\func
23895 RESTORE_TOP_OF_STACK %r11, 8
23896- ret $REST_SKIP /* pop extended registers */
23897+ pax_force_retaddr
23898+ ret
23899 CFI_ENDPROC
23900-END(stub_\func)
23901+ENDPROC(stub_\func)
23902 .endm
23903
23904 .macro FIXED_FRAME label,func
23905@@ -836,9 +1321,10 @@ ENTRY(\label)
23906 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
23907 call \func
23908 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
23909+ pax_force_retaddr
23910 ret
23911 CFI_ENDPROC
23912-END(\label)
23913+ENDPROC(\label)
23914 .endm
23915
23916 FORK_LIKE clone
23917@@ -846,19 +1332,6 @@ END(\label)
23918 FORK_LIKE vfork
23919 FIXED_FRAME stub_iopl, sys_iopl
23920
23921-ENTRY(ptregscall_common)
23922- DEFAULT_FRAME 1 8 /* offset 8: return address */
23923- RESTORE_TOP_OF_STACK %r11, 8
23924- movq_cfi_restore R15+8, r15
23925- movq_cfi_restore R14+8, r14
23926- movq_cfi_restore R13+8, r13
23927- movq_cfi_restore R12+8, r12
23928- movq_cfi_restore RBP+8, rbp
23929- movq_cfi_restore RBX+8, rbx
23930- ret $REST_SKIP /* pop extended registers */
23931- CFI_ENDPROC
23932-END(ptregscall_common)
23933-
23934 ENTRY(stub_execve)
23935 CFI_STARTPROC
23936 addq $8, %rsp
23937@@ -870,7 +1343,7 @@ ENTRY(stub_execve)
23938 RESTORE_REST
23939 jmp int_ret_from_sys_call
23940 CFI_ENDPROC
23941-END(stub_execve)
23942+ENDPROC(stub_execve)
23943
23944 /*
23945 * sigreturn is special because it needs to restore all registers on return.
23946@@ -887,7 +1360,7 @@ ENTRY(stub_rt_sigreturn)
23947 RESTORE_REST
23948 jmp int_ret_from_sys_call
23949 CFI_ENDPROC
23950-END(stub_rt_sigreturn)
23951+ENDPROC(stub_rt_sigreturn)
23952
23953 #ifdef CONFIG_X86_X32_ABI
23954 ENTRY(stub_x32_rt_sigreturn)
23955@@ -901,7 +1374,7 @@ ENTRY(stub_x32_rt_sigreturn)
23956 RESTORE_REST
23957 jmp int_ret_from_sys_call
23958 CFI_ENDPROC
23959-END(stub_x32_rt_sigreturn)
23960+ENDPROC(stub_x32_rt_sigreturn)
23961
23962 ENTRY(stub_x32_execve)
23963 CFI_STARTPROC
23964@@ -915,7 +1388,7 @@ ENTRY(stub_x32_execve)
23965 RESTORE_REST
23966 jmp int_ret_from_sys_call
23967 CFI_ENDPROC
23968-END(stub_x32_execve)
23969+ENDPROC(stub_x32_execve)
23970
23971 #endif
23972
23973@@ -952,7 +1425,7 @@ vector=vector+1
23974 2: jmp common_interrupt
23975 .endr
23976 CFI_ENDPROC
23977-END(irq_entries_start)
23978+ENDPROC(irq_entries_start)
23979
23980 .previous
23981 END(interrupt)
23982@@ -969,8 +1442,8 @@ END(interrupt)
23983 /* 0(%rsp): ~(interrupt number) */
23984 .macro interrupt func
23985 /* reserve pt_regs for scratch regs and rbp */
23986- subq $ORIG_RAX-RBP, %rsp
23987- CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
23988+ subq $ORIG_RAX, %rsp
23989+ CFI_ADJUST_CFA_OFFSET ORIG_RAX
23990 SAVE_ARGS_IRQ
23991 call \func
23992 .endm
23993@@ -997,14 +1470,14 @@ ret_from_intr:
23994
23995 /* Restore saved previous stack */
23996 popq %rsi
23997- CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
23998- leaq ARGOFFSET-RBP(%rsi), %rsp
23999+ CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
24000+ movq %rsi, %rsp
24001 CFI_DEF_CFA_REGISTER rsp
24002- CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
24003+ CFI_ADJUST_CFA_OFFSET -ARGOFFSET
24004
24005 exit_intr:
24006 GET_THREAD_INFO(%rcx)
24007- testl $3,CS-ARGOFFSET(%rsp)
24008+ testb $3,CS-ARGOFFSET(%rsp)
24009 je retint_kernel
24010
24011 /* Interrupt came from user space */
24012@@ -1026,12 +1499,16 @@ retint_swapgs: /* return to user-space */
24013 * The iretq could re-enable interrupts:
24014 */
24015 DISABLE_INTERRUPTS(CLBR_ANY)
24016+ pax_exit_kernel_user
24017+retint_swapgs_pax:
24018 TRACE_IRQS_IRETQ
24019 SWAPGS
24020 jmp restore_args
24021
24022 retint_restore_args: /* return to kernel space */
24023 DISABLE_INTERRUPTS(CLBR_ANY)
24024+ pax_exit_kernel
24025+ pax_force_retaddr (RIP-ARGOFFSET)
24026 /*
24027 * The iretq could re-enable interrupts:
24028 */
24029@@ -1112,7 +1589,7 @@ ENTRY(retint_kernel)
24030 #endif
24031
24032 CFI_ENDPROC
24033-END(common_interrupt)
24034+ENDPROC(common_interrupt)
24035 /*
24036 * End of kprobes section
24037 */
24038@@ -1130,7 +1607,7 @@ ENTRY(\sym)
24039 interrupt \do_sym
24040 jmp ret_from_intr
24041 CFI_ENDPROC
24042-END(\sym)
24043+ENDPROC(\sym)
24044 .endm
24045
24046 #ifdef CONFIG_TRACING
24047@@ -1218,7 +1695,7 @@ ENTRY(\sym)
24048 call \do_sym
24049 jmp error_exit /* %ebx: no swapgs flag */
24050 CFI_ENDPROC
24051-END(\sym)
24052+ENDPROC(\sym)
24053 .endm
24054
24055 .macro paranoidzeroentry sym do_sym
24056@@ -1236,10 +1713,10 @@ ENTRY(\sym)
24057 call \do_sym
24058 jmp paranoid_exit /* %ebx: no swapgs flag */
24059 CFI_ENDPROC
24060-END(\sym)
24061+ENDPROC(\sym)
24062 .endm
24063
24064-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
24065+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
24066 .macro paranoidzeroentry_ist sym do_sym ist
24067 ENTRY(\sym)
24068 INTR_FRAME
24069@@ -1252,12 +1729,18 @@ ENTRY(\sym)
24070 TRACE_IRQS_OFF_DEBUG
24071 movq %rsp,%rdi /* pt_regs pointer */
24072 xorl %esi,%esi /* no error code */
24073+#ifdef CONFIG_SMP
24074+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
24075+ lea init_tss(%r13), %r13
24076+#else
24077+ lea init_tss(%rip), %r13
24078+#endif
24079 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
24080 call \do_sym
24081 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
24082 jmp paranoid_exit /* %ebx: no swapgs flag */
24083 CFI_ENDPROC
24084-END(\sym)
24085+ENDPROC(\sym)
24086 .endm
24087
24088 .macro errorentry sym do_sym
24089@@ -1275,7 +1758,7 @@ ENTRY(\sym)
24090 call \do_sym
24091 jmp error_exit /* %ebx: no swapgs flag */
24092 CFI_ENDPROC
24093-END(\sym)
24094+ENDPROC(\sym)
24095 .endm
24096
24097 #ifdef CONFIG_TRACING
24098@@ -1306,7 +1789,7 @@ ENTRY(\sym)
24099 call \do_sym
24100 jmp paranoid_exit /* %ebx: no swapgs flag */
24101 CFI_ENDPROC
24102-END(\sym)
24103+ENDPROC(\sym)
24104 .endm
24105
24106 zeroentry divide_error do_divide_error
24107@@ -1336,9 +1819,10 @@ gs_change:
24108 2: mfence /* workaround */
24109 SWAPGS
24110 popfq_cfi
24111+ pax_force_retaddr
24112 ret
24113 CFI_ENDPROC
24114-END(native_load_gs_index)
24115+ENDPROC(native_load_gs_index)
24116
24117 _ASM_EXTABLE(gs_change,bad_gs)
24118 .section .fixup,"ax"
24119@@ -1366,9 +1850,10 @@ ENTRY(do_softirq_own_stack)
24120 CFI_DEF_CFA_REGISTER rsp
24121 CFI_ADJUST_CFA_OFFSET -8
24122 decl PER_CPU_VAR(irq_count)
24123+ pax_force_retaddr
24124 ret
24125 CFI_ENDPROC
24126-END(do_softirq_own_stack)
24127+ENDPROC(do_softirq_own_stack)
24128
24129 #ifdef CONFIG_XEN
24130 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
24131@@ -1406,7 +1891,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
24132 decl PER_CPU_VAR(irq_count)
24133 jmp error_exit
24134 CFI_ENDPROC
24135-END(xen_do_hypervisor_callback)
24136+ENDPROC(xen_do_hypervisor_callback)
24137
24138 /*
24139 * Hypervisor uses this for application faults while it executes.
24140@@ -1465,7 +1950,7 @@ ENTRY(xen_failsafe_callback)
24141 SAVE_ALL
24142 jmp error_exit
24143 CFI_ENDPROC
24144-END(xen_failsafe_callback)
24145+ENDPROC(xen_failsafe_callback)
24146
24147 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
24148 xen_hvm_callback_vector xen_evtchn_do_upcall
24149@@ -1517,18 +2002,33 @@ ENTRY(paranoid_exit)
24150 DEFAULT_FRAME
24151 DISABLE_INTERRUPTS(CLBR_NONE)
24152 TRACE_IRQS_OFF_DEBUG
24153- testl %ebx,%ebx /* swapgs needed? */
24154+ testl $1,%ebx /* swapgs needed? */
24155 jnz paranoid_restore
24156- testl $3,CS(%rsp)
24157+ testb $3,CS(%rsp)
24158 jnz paranoid_userspace
24159+#ifdef CONFIG_PAX_MEMORY_UDEREF
24160+ pax_exit_kernel
24161+ TRACE_IRQS_IRETQ 0
24162+ SWAPGS_UNSAFE_STACK
24163+ RESTORE_ALL 8
24164+ pax_force_retaddr_bts
24165+ jmp irq_return
24166+#endif
24167 paranoid_swapgs:
24168+#ifdef CONFIG_PAX_MEMORY_UDEREF
24169+ pax_exit_kernel_user
24170+#else
24171+ pax_exit_kernel
24172+#endif
24173 TRACE_IRQS_IRETQ 0
24174 SWAPGS_UNSAFE_STACK
24175 RESTORE_ALL 8
24176 jmp irq_return
24177 paranoid_restore:
24178+ pax_exit_kernel
24179 TRACE_IRQS_IRETQ_DEBUG 0
24180 RESTORE_ALL 8
24181+ pax_force_retaddr_bts
24182 jmp irq_return
24183 paranoid_userspace:
24184 GET_THREAD_INFO(%rcx)
24185@@ -1557,7 +2057,7 @@ paranoid_schedule:
24186 TRACE_IRQS_OFF
24187 jmp paranoid_userspace
24188 CFI_ENDPROC
24189-END(paranoid_exit)
24190+ENDPROC(paranoid_exit)
24191
24192 /*
24193 * Exception entry point. This expects an error code/orig_rax on the stack.
24194@@ -1584,12 +2084,23 @@ ENTRY(error_entry)
24195 movq_cfi r14, R14+8
24196 movq_cfi r15, R15+8
24197 xorl %ebx,%ebx
24198- testl $3,CS+8(%rsp)
24199+ testb $3,CS+8(%rsp)
24200 je error_kernelspace
24201 error_swapgs:
24202 SWAPGS
24203 error_sti:
24204+#ifdef CONFIG_PAX_MEMORY_UDEREF
24205+ testb $3, CS+8(%rsp)
24206+ jnz 1f
24207+ pax_enter_kernel
24208+ jmp 2f
24209+1: pax_enter_kernel_user
24210+2:
24211+#else
24212+ pax_enter_kernel
24213+#endif
24214 TRACE_IRQS_OFF
24215+ pax_force_retaddr
24216 ret
24217
24218 /*
24219@@ -1616,7 +2127,7 @@ bstep_iret:
24220 movq %rcx,RIP+8(%rsp)
24221 jmp error_swapgs
24222 CFI_ENDPROC
24223-END(error_entry)
24224+ENDPROC(error_entry)
24225
24226
24227 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
24228@@ -1627,7 +2138,7 @@ ENTRY(error_exit)
24229 DISABLE_INTERRUPTS(CLBR_NONE)
24230 TRACE_IRQS_OFF
24231 GET_THREAD_INFO(%rcx)
24232- testl %eax,%eax
24233+ testl $1,%eax
24234 jne retint_kernel
24235 LOCKDEP_SYS_EXIT_IRQ
24236 movl TI_flags(%rcx),%edx
24237@@ -1636,7 +2147,7 @@ ENTRY(error_exit)
24238 jnz retint_careful
24239 jmp retint_swapgs
24240 CFI_ENDPROC
24241-END(error_exit)
24242+ENDPROC(error_exit)
24243
24244 /*
24245 * Test if a given stack is an NMI stack or not.
24246@@ -1694,9 +2205,11 @@ ENTRY(nmi)
24247 * If %cs was not the kernel segment, then the NMI triggered in user
24248 * space, which means it is definitely not nested.
24249 */
24250+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
24251+ je 1f
24252 cmpl $__KERNEL_CS, 16(%rsp)
24253 jne first_nmi
24254-
24255+1:
24256 /*
24257 * Check the special variable on the stack to see if NMIs are
24258 * executing.
24259@@ -1730,8 +2243,7 @@ nested_nmi:
24260
24261 1:
24262 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
24263- leaq -1*8(%rsp), %rdx
24264- movq %rdx, %rsp
24265+ subq $8, %rsp
24266 CFI_ADJUST_CFA_OFFSET 1*8
24267 leaq -10*8(%rsp), %rdx
24268 pushq_cfi $__KERNEL_DS
24269@@ -1749,6 +2261,7 @@ nested_nmi_out:
24270 CFI_RESTORE rdx
24271
24272 /* No need to check faults here */
24273+# pax_force_retaddr_bts
24274 INTERRUPT_RETURN
24275
24276 CFI_RESTORE_STATE
24277@@ -1845,13 +2358,13 @@ end_repeat_nmi:
24278 subq $ORIG_RAX-R15, %rsp
24279 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
24280 /*
24281- * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
24282+ * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
24283 * as we should not be calling schedule in NMI context.
24284 * Even with normal interrupts enabled. An NMI should not be
24285 * setting NEED_RESCHED or anything that normal interrupts and
24286 * exceptions might do.
24287 */
24288- call save_paranoid
24289+ call save_paranoid_nmi
24290 DEFAULT_FRAME 0
24291
24292 /*
24293@@ -1861,9 +2374,9 @@ end_repeat_nmi:
24294 * NMI itself takes a page fault, the page fault that was preempted
24295 * will read the information from the NMI page fault and not the
24296 * origin fault. Save it off and restore it if it changes.
24297- * Use the r12 callee-saved register.
24298+ * Use the r13 callee-saved register.
24299 */
24300- movq %cr2, %r12
24301+ movq %cr2, %r13
24302
24303 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
24304 movq %rsp,%rdi
24305@@ -1872,31 +2385,36 @@ end_repeat_nmi:
24306
24307 /* Did the NMI take a page fault? Restore cr2 if it did */
24308 movq %cr2, %rcx
24309- cmpq %rcx, %r12
24310+ cmpq %rcx, %r13
24311 je 1f
24312- movq %r12, %cr2
24313+ movq %r13, %cr2
24314 1:
24315
24316- testl %ebx,%ebx /* swapgs needed? */
24317+ testl $1,%ebx /* swapgs needed? */
24318 jnz nmi_restore
24319 nmi_swapgs:
24320 SWAPGS_UNSAFE_STACK
24321 nmi_restore:
24322+ pax_exit_kernel_nmi
24323 /* Pop the extra iret frame at once */
24324 RESTORE_ALL 6*8
24325+ testb $3, 8(%rsp)
24326+ jnz 1f
24327+ pax_force_retaddr_bts
24328+1:
24329
24330 /* Clear the NMI executing stack variable */
24331 movq $0, 5*8(%rsp)
24332 jmp irq_return
24333 CFI_ENDPROC
24334-END(nmi)
24335+ENDPROC(nmi)
24336
24337 ENTRY(ignore_sysret)
24338 CFI_STARTPROC
24339 mov $-ENOSYS,%eax
24340 sysret
24341 CFI_ENDPROC
24342-END(ignore_sysret)
24343+ENDPROC(ignore_sysret)
24344
24345 /*
24346 * End of kprobes section
24347diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
24348index 1ffc32d..e52c745 100644
24349--- a/arch/x86/kernel/ftrace.c
24350+++ b/arch/x86/kernel/ftrace.c
24351@@ -104,6 +104,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
24352 {
24353 unsigned char replaced[MCOUNT_INSN_SIZE];
24354
24355+ ip = ktla_ktva(ip);
24356+
24357 /*
24358 * Note: Due to modules and __init, code can
24359 * disappear and change, we need to protect against faulting
24360@@ -229,7 +231,7 @@ static int update_ftrace_func(unsigned long ip, void *new)
24361 unsigned char old[MCOUNT_INSN_SIZE];
24362 int ret;
24363
24364- memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
24365+ memcpy(old, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE);
24366
24367 ftrace_update_func = ip;
24368 /* Make sure the breakpoints see the ftrace_update_func update */
24369@@ -306,7 +308,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
24370 * kernel identity mapping to modify code.
24371 */
24372 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
24373- ip = (unsigned long)__va(__pa_symbol(ip));
24374+ ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
24375
24376 return probe_kernel_write((void *)ip, val, size);
24377 }
24378@@ -316,7 +318,7 @@ static int add_break(unsigned long ip, const char *old)
24379 unsigned char replaced[MCOUNT_INSN_SIZE];
24380 unsigned char brk = BREAKPOINT_INSTRUCTION;
24381
24382- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
24383+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
24384 return -EFAULT;
24385
24386 /* Make sure it is what we expect it to be */
24387@@ -664,7 +666,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
24388 return ret;
24389
24390 fail_update:
24391- probe_kernel_write((void *)ip, &old_code[0], 1);
24392+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
24393 goto out;
24394 }
24395
24396diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
24397index 85126cc..1bbce17 100644
24398--- a/arch/x86/kernel/head64.c
24399+++ b/arch/x86/kernel/head64.c
24400@@ -67,12 +67,12 @@ again:
24401 pgd = *pgd_p;
24402
24403 /*
24404- * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
24405- * critical -- __PAGE_OFFSET would point us back into the dynamic
24406+ * The use of __early_va rather than __va here is critical:
24407+ * __va would point us back into the dynamic
24408 * range and we might end up looping forever...
24409 */
24410 if (pgd)
24411- pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24412+ pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
24413 else {
24414 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24415 reset_early_page_tables();
24416@@ -82,13 +82,13 @@ again:
24417 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
24418 for (i = 0; i < PTRS_PER_PUD; i++)
24419 pud_p[i] = 0;
24420- *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24421+ *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
24422 }
24423 pud_p += pud_index(address);
24424 pud = *pud_p;
24425
24426 if (pud)
24427- pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24428+ pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
24429 else {
24430 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24431 reset_early_page_tables();
24432@@ -98,7 +98,7 @@ again:
24433 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
24434 for (i = 0; i < PTRS_PER_PMD; i++)
24435 pmd_p[i] = 0;
24436- *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24437+ *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
24438 }
24439 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
24440 pmd_p[pmd_index(address)] = pmd;
24441@@ -175,7 +175,6 @@ asmlinkage void __init x86_64_start_kernel(char * real_mode_data)
24442 if (console_loglevel == 10)
24443 early_printk("Kernel alive\n");
24444
24445- clear_page(init_level4_pgt);
24446 /* set init_level4_pgt kernel high mapping*/
24447 init_level4_pgt[511] = early_level4_pgt[511];
24448
24449diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
24450index f36bd42..56ee1534 100644
24451--- a/arch/x86/kernel/head_32.S
24452+++ b/arch/x86/kernel/head_32.S
24453@@ -26,6 +26,12 @@
24454 /* Physical address */
24455 #define pa(X) ((X) - __PAGE_OFFSET)
24456
24457+#ifdef CONFIG_PAX_KERNEXEC
24458+#define ta(X) (X)
24459+#else
24460+#define ta(X) ((X) - __PAGE_OFFSET)
24461+#endif
24462+
24463 /*
24464 * References to members of the new_cpu_data structure.
24465 */
24466@@ -55,11 +61,7 @@
24467 * and small than max_low_pfn, otherwise will waste some page table entries
24468 */
24469
24470-#if PTRS_PER_PMD > 1
24471-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
24472-#else
24473-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
24474-#endif
24475+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
24476
24477 /* Number of possible pages in the lowmem region */
24478 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
24479@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
24480 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24481
24482 /*
24483+ * Real beginning of normal "text" segment
24484+ */
24485+ENTRY(stext)
24486+ENTRY(_stext)
24487+
24488+/*
24489 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
24490 * %esi points to the real-mode code as a 32-bit pointer.
24491 * CS and DS must be 4 GB flat segments, but we don't depend on
24492@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24493 * can.
24494 */
24495 __HEAD
24496+
24497+#ifdef CONFIG_PAX_KERNEXEC
24498+ jmp startup_32
24499+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
24500+.fill PAGE_SIZE-5,1,0xcc
24501+#endif
24502+
24503 ENTRY(startup_32)
24504 movl pa(stack_start),%ecx
24505
24506@@ -106,6 +121,59 @@ ENTRY(startup_32)
24507 2:
24508 leal -__PAGE_OFFSET(%ecx),%esp
24509
24510+#ifdef CONFIG_SMP
24511+ movl $pa(cpu_gdt_table),%edi
24512+ movl $__per_cpu_load,%eax
24513+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
24514+ rorl $16,%eax
24515+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
24516+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
24517+ movl $__per_cpu_end - 1,%eax
24518+ subl $__per_cpu_start,%eax
24519+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
24520+#endif
24521+
24522+#ifdef CONFIG_PAX_MEMORY_UDEREF
24523+ movl $NR_CPUS,%ecx
24524+ movl $pa(cpu_gdt_table),%edi
24525+1:
24526+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
24527+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
24528+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
24529+ addl $PAGE_SIZE_asm,%edi
24530+ loop 1b
24531+#endif
24532+
24533+#ifdef CONFIG_PAX_KERNEXEC
24534+ movl $pa(boot_gdt),%edi
24535+ movl $__LOAD_PHYSICAL_ADDR,%eax
24536+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
24537+ rorl $16,%eax
24538+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
24539+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
24540+ rorl $16,%eax
24541+
24542+ ljmp $(__BOOT_CS),$1f
24543+1:
24544+
24545+ movl $NR_CPUS,%ecx
24546+ movl $pa(cpu_gdt_table),%edi
24547+ addl $__PAGE_OFFSET,%eax
24548+1:
24549+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
24550+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
24551+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
24552+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
24553+ rorl $16,%eax
24554+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
24555+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
24556+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
24557+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
24558+ rorl $16,%eax
24559+ addl $PAGE_SIZE_asm,%edi
24560+ loop 1b
24561+#endif
24562+
24563 /*
24564 * Clear BSS first so that there are no surprises...
24565 */
24566@@ -201,8 +269,11 @@ ENTRY(startup_32)
24567 movl %eax, pa(max_pfn_mapped)
24568
24569 /* Do early initialization of the fixmap area */
24570- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24571- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
24572+#ifdef CONFIG_COMPAT_VDSO
24573+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
24574+#else
24575+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
24576+#endif
24577 #else /* Not PAE */
24578
24579 page_pde_offset = (__PAGE_OFFSET >> 20);
24580@@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24581 movl %eax, pa(max_pfn_mapped)
24582
24583 /* Do early initialization of the fixmap area */
24584- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24585- movl %eax,pa(initial_page_table+0xffc)
24586+#ifdef CONFIG_COMPAT_VDSO
24587+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
24588+#else
24589+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
24590+#endif
24591 #endif
24592
24593 #ifdef CONFIG_PARAVIRT
24594@@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24595 cmpl $num_subarch_entries, %eax
24596 jae bad_subarch
24597
24598- movl pa(subarch_entries)(,%eax,4), %eax
24599- subl $__PAGE_OFFSET, %eax
24600- jmp *%eax
24601+ jmp *pa(subarch_entries)(,%eax,4)
24602
24603 bad_subarch:
24604 WEAK(lguest_entry)
24605@@ -261,10 +333,10 @@ WEAK(xen_entry)
24606 __INITDATA
24607
24608 subarch_entries:
24609- .long default_entry /* normal x86/PC */
24610- .long lguest_entry /* lguest hypervisor */
24611- .long xen_entry /* Xen hypervisor */
24612- .long default_entry /* Moorestown MID */
24613+ .long ta(default_entry) /* normal x86/PC */
24614+ .long ta(lguest_entry) /* lguest hypervisor */
24615+ .long ta(xen_entry) /* Xen hypervisor */
24616+ .long ta(default_entry) /* Moorestown MID */
24617 num_subarch_entries = (. - subarch_entries) / 4
24618 .previous
24619 #else
24620@@ -354,6 +426,7 @@ default_entry:
24621 movl pa(mmu_cr4_features),%eax
24622 movl %eax,%cr4
24623
24624+#ifdef CONFIG_X86_PAE
24625 testb $X86_CR4_PAE, %al # check if PAE is enabled
24626 jz enable_paging
24627
24628@@ -382,6 +455,9 @@ default_entry:
24629 /* Make changes effective */
24630 wrmsr
24631
24632+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
24633+#endif
24634+
24635 enable_paging:
24636
24637 /*
24638@@ -449,14 +525,20 @@ is486:
24639 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
24640 movl %eax,%ss # after changing gdt.
24641
24642- movl $(__USER_DS),%eax # DS/ES contains default USER segment
24643+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
24644 movl %eax,%ds
24645 movl %eax,%es
24646
24647 movl $(__KERNEL_PERCPU), %eax
24648 movl %eax,%fs # set this cpu's percpu
24649
24650+#ifdef CONFIG_CC_STACKPROTECTOR
24651 movl $(__KERNEL_STACK_CANARY),%eax
24652+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
24653+ movl $(__USER_DS),%eax
24654+#else
24655+ xorl %eax,%eax
24656+#endif
24657 movl %eax,%gs
24658
24659 xorl %eax,%eax # Clear LDT
24660@@ -512,8 +594,11 @@ setup_once:
24661 * relocation. Manually set base address in stack canary
24662 * segment descriptor.
24663 */
24664- movl $gdt_page,%eax
24665+ movl $cpu_gdt_table,%eax
24666 movl $stack_canary,%ecx
24667+#ifdef CONFIG_SMP
24668+ addl $__per_cpu_load,%ecx
24669+#endif
24670 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
24671 shrl $16, %ecx
24672 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
24673@@ -548,7 +633,7 @@ ENTRY(early_idt_handler)
24674 cmpl $2,(%esp) # X86_TRAP_NMI
24675 je is_nmi # Ignore NMI
24676
24677- cmpl $2,%ss:early_recursion_flag
24678+ cmpl $1,%ss:early_recursion_flag
24679 je hlt_loop
24680 incl %ss:early_recursion_flag
24681
24682@@ -586,8 +671,8 @@ ENTRY(early_idt_handler)
24683 pushl (20+6*4)(%esp) /* trapno */
24684 pushl $fault_msg
24685 call printk
24686-#endif
24687 call dump_stack
24688+#endif
24689 hlt_loop:
24690 hlt
24691 jmp hlt_loop
24692@@ -607,8 +692,11 @@ ENDPROC(early_idt_handler)
24693 /* This is the default interrupt "handler" :-) */
24694 ALIGN
24695 ignore_int:
24696- cld
24697 #ifdef CONFIG_PRINTK
24698+ cmpl $2,%ss:early_recursion_flag
24699+ je hlt_loop
24700+ incl %ss:early_recursion_flag
24701+ cld
24702 pushl %eax
24703 pushl %ecx
24704 pushl %edx
24705@@ -617,9 +705,6 @@ ignore_int:
24706 movl $(__KERNEL_DS),%eax
24707 movl %eax,%ds
24708 movl %eax,%es
24709- cmpl $2,early_recursion_flag
24710- je hlt_loop
24711- incl early_recursion_flag
24712 pushl 16(%esp)
24713 pushl 24(%esp)
24714 pushl 32(%esp)
24715@@ -653,29 +738,34 @@ ENTRY(setup_once_ref)
24716 /*
24717 * BSS section
24718 */
24719-__PAGE_ALIGNED_BSS
24720- .align PAGE_SIZE
24721 #ifdef CONFIG_X86_PAE
24722+.section .initial_pg_pmd,"a",@progbits
24723 initial_pg_pmd:
24724 .fill 1024*KPMDS,4,0
24725 #else
24726+.section .initial_page_table,"a",@progbits
24727 ENTRY(initial_page_table)
24728 .fill 1024,4,0
24729 #endif
24730+.section .initial_pg_fixmap,"a",@progbits
24731 initial_pg_fixmap:
24732 .fill 1024,4,0
24733+.section .empty_zero_page,"a",@progbits
24734 ENTRY(empty_zero_page)
24735 .fill 4096,1,0
24736+.section .swapper_pg_dir,"a",@progbits
24737 ENTRY(swapper_pg_dir)
24738+#ifdef CONFIG_X86_PAE
24739+ .fill 4,8,0
24740+#else
24741 .fill 1024,4,0
24742+#endif
24743
24744 /*
24745 * This starts the data section.
24746 */
24747 #ifdef CONFIG_X86_PAE
24748-__PAGE_ALIGNED_DATA
24749- /* Page-aligned for the benefit of paravirt? */
24750- .align PAGE_SIZE
24751+.section .initial_page_table,"a",@progbits
24752 ENTRY(initial_page_table)
24753 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
24754 # if KPMDS == 3
24755@@ -694,12 +784,20 @@ ENTRY(initial_page_table)
24756 # error "Kernel PMDs should be 1, 2 or 3"
24757 # endif
24758 .align PAGE_SIZE /* needs to be page-sized too */
24759+
24760+#ifdef CONFIG_PAX_PER_CPU_PGD
24761+ENTRY(cpu_pgd)
24762+ .rept 2*NR_CPUS
24763+ .fill 4,8,0
24764+ .endr
24765+#endif
24766+
24767 #endif
24768
24769 .data
24770 .balign 4
24771 ENTRY(stack_start)
24772- .long init_thread_union+THREAD_SIZE
24773+ .long init_thread_union+THREAD_SIZE-8
24774
24775 __INITRODATA
24776 int_msg:
24777@@ -727,7 +825,7 @@ fault_msg:
24778 * segment size, and 32-bit linear address value:
24779 */
24780
24781- .data
24782+.section .rodata,"a",@progbits
24783 .globl boot_gdt_descr
24784 .globl idt_descr
24785
24786@@ -736,7 +834,7 @@ fault_msg:
24787 .word 0 # 32 bit align gdt_desc.address
24788 boot_gdt_descr:
24789 .word __BOOT_DS+7
24790- .long boot_gdt - __PAGE_OFFSET
24791+ .long pa(boot_gdt)
24792
24793 .word 0 # 32-bit align idt_desc.address
24794 idt_descr:
24795@@ -747,7 +845,7 @@ idt_descr:
24796 .word 0 # 32 bit align gdt_desc.address
24797 ENTRY(early_gdt_descr)
24798 .word GDT_ENTRIES*8-1
24799- .long gdt_page /* Overwritten for secondary CPUs */
24800+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
24801
24802 /*
24803 * The boot_gdt must mirror the equivalent in setup.S and is
24804@@ -756,5 +854,65 @@ ENTRY(early_gdt_descr)
24805 .align L1_CACHE_BYTES
24806 ENTRY(boot_gdt)
24807 .fill GDT_ENTRY_BOOT_CS,8,0
24808- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
24809- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
24810+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
24811+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
24812+
24813+ .align PAGE_SIZE_asm
24814+ENTRY(cpu_gdt_table)
24815+ .rept NR_CPUS
24816+ .quad 0x0000000000000000 /* NULL descriptor */
24817+ .quad 0x0000000000000000 /* 0x0b reserved */
24818+ .quad 0x0000000000000000 /* 0x13 reserved */
24819+ .quad 0x0000000000000000 /* 0x1b reserved */
24820+
24821+#ifdef CONFIG_PAX_KERNEXEC
24822+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
24823+#else
24824+ .quad 0x0000000000000000 /* 0x20 unused */
24825+#endif
24826+
24827+ .quad 0x0000000000000000 /* 0x28 unused */
24828+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
24829+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
24830+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
24831+ .quad 0x0000000000000000 /* 0x4b reserved */
24832+ .quad 0x0000000000000000 /* 0x53 reserved */
24833+ .quad 0x0000000000000000 /* 0x5b reserved */
24834+
24835+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
24836+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
24837+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
24838+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
24839+
24840+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
24841+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
24842+
24843+ /*
24844+ * Segments used for calling PnP BIOS have byte granularity.
24845+ * The code segments and data segments have fixed 64k limits,
24846+ * the transfer segment sizes are set at run time.
24847+ */
24848+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
24849+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
24850+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
24851+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
24852+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
24853+
24854+ /*
24855+ * The APM segments have byte granularity and their bases
24856+ * are set at run time. All have 64k limits.
24857+ */
24858+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
24859+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
24860+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
24861+
24862+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
24863+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
24864+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
24865+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
24866+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
24867+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
24868+
24869+ /* Be sure this is zeroed to avoid false validations in Xen */
24870+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
24871+ .endr
24872diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
24873index a468c0a..c7dec74 100644
24874--- a/arch/x86/kernel/head_64.S
24875+++ b/arch/x86/kernel/head_64.S
24876@@ -20,6 +20,8 @@
24877 #include <asm/processor-flags.h>
24878 #include <asm/percpu.h>
24879 #include <asm/nops.h>
24880+#include <asm/cpufeature.h>
24881+#include <asm/alternative-asm.h>
24882
24883 #ifdef CONFIG_PARAVIRT
24884 #include <asm/asm-offsets.h>
24885@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
24886 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
24887 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
24888 L3_START_KERNEL = pud_index(__START_KERNEL_map)
24889+L4_VMALLOC_START = pgd_index(VMALLOC_START)
24890+L3_VMALLOC_START = pud_index(VMALLOC_START)
24891+L4_VMALLOC_END = pgd_index(VMALLOC_END)
24892+L3_VMALLOC_END = pud_index(VMALLOC_END)
24893+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
24894+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
24895
24896 .text
24897 __HEAD
24898@@ -89,11 +97,24 @@ startup_64:
24899 * Fixup the physical addresses in the page table
24900 */
24901 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
24902+ addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
24903+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
24904+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
24905+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
24906+ addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
24907
24908- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
24909- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
24910+ addq %rbp, level3_ident_pgt + (0*8)(%rip)
24911+#ifndef CONFIG_XEN
24912+ addq %rbp, level3_ident_pgt + (1*8)(%rip)
24913+#endif
24914+
24915+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
24916+
24917+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
24918+ addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
24919
24920 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
24921+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
24922
24923 /*
24924 * Set up the identity mapping for the switchover. These
24925@@ -177,8 +198,8 @@ ENTRY(secondary_startup_64)
24926 movq $(init_level4_pgt - __START_KERNEL_map), %rax
24927 1:
24928
24929- /* Enable PAE mode and PGE */
24930- movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
24931+ /* Enable PAE mode and PSE/PGE */
24932+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
24933 movq %rcx, %cr4
24934
24935 /* Setup early boot stage 4 level pagetables. */
24936@@ -199,10 +220,19 @@ ENTRY(secondary_startup_64)
24937 movl $MSR_EFER, %ecx
24938 rdmsr
24939 btsl $_EFER_SCE, %eax /* Enable System Call */
24940- btl $20,%edi /* No Execute supported? */
24941+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
24942 jnc 1f
24943 btsl $_EFER_NX, %eax
24944 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
24945+#ifndef CONFIG_EFI
24946+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
24947+#endif
24948+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
24949+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
24950+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
24951+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
24952+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
24953+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
24954 1: wrmsr /* Make changes effective */
24955
24956 /* Setup cr0 */
24957@@ -282,6 +312,7 @@ ENTRY(secondary_startup_64)
24958 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
24959 * address given in m16:64.
24960 */
24961+ pax_set_fptr_mask
24962 movq initial_code(%rip),%rax
24963 pushq $0 # fake return address to stop unwinder
24964 pushq $__KERNEL_CS # set correct cs
24965@@ -313,7 +344,7 @@ ENDPROC(start_cpu0)
24966 .quad INIT_PER_CPU_VAR(irq_stack_union)
24967
24968 GLOBAL(stack_start)
24969- .quad init_thread_union+THREAD_SIZE-8
24970+ .quad init_thread_union+THREAD_SIZE-16
24971 .word 0
24972 __FINITDATA
24973
24974@@ -391,7 +422,7 @@ ENTRY(early_idt_handler)
24975 call dump_stack
24976 #ifdef CONFIG_KALLSYMS
24977 leaq early_idt_ripmsg(%rip),%rdi
24978- movq 40(%rsp),%rsi # %rip again
24979+ movq 88(%rsp),%rsi # %rip again
24980 call __print_symbol
24981 #endif
24982 #endif /* EARLY_PRINTK */
24983@@ -420,6 +451,7 @@ ENDPROC(early_idt_handler)
24984 early_recursion_flag:
24985 .long 0
24986
24987+ .section .rodata,"a",@progbits
24988 #ifdef CONFIG_EARLY_PRINTK
24989 early_idt_msg:
24990 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
24991@@ -447,29 +479,52 @@ NEXT_PAGE(early_level4_pgt)
24992 NEXT_PAGE(early_dynamic_pgts)
24993 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
24994
24995- .data
24996+ .section .rodata,"a",@progbits
24997
24998-#ifndef CONFIG_XEN
24999 NEXT_PAGE(init_level4_pgt)
25000- .fill 512,8,0
25001-#else
25002-NEXT_PAGE(init_level4_pgt)
25003- .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25004 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
25005 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25006+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
25007+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
25008+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
25009+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
25010+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
25011+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
25012 .org init_level4_pgt + L4_START_KERNEL*8, 0
25013 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
25014 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
25015
25016+#ifdef CONFIG_PAX_PER_CPU_PGD
25017+NEXT_PAGE(cpu_pgd)
25018+ .rept 2*NR_CPUS
25019+ .fill 512,8,0
25020+ .endr
25021+#endif
25022+
25023 NEXT_PAGE(level3_ident_pgt)
25024 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25025+#ifdef CONFIG_XEN
25026 .fill 511, 8, 0
25027+#else
25028+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
25029+ .fill 510,8,0
25030+#endif
25031+
25032+NEXT_PAGE(level3_vmalloc_start_pgt)
25033+ .fill 512,8,0
25034+
25035+NEXT_PAGE(level3_vmalloc_end_pgt)
25036+ .fill 512,8,0
25037+
25038+NEXT_PAGE(level3_vmemmap_pgt)
25039+ .fill L3_VMEMMAP_START,8,0
25040+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
25041+
25042 NEXT_PAGE(level2_ident_pgt)
25043- /* Since I easily can, map the first 1G.
25044+ /* Since I easily can, map the first 2G.
25045 * Don't set NX because code runs from these pages.
25046 */
25047- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
25048-#endif
25049+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
25050
25051 NEXT_PAGE(level3_kernel_pgt)
25052 .fill L3_START_KERNEL,8,0
25053@@ -477,6 +532,9 @@ NEXT_PAGE(level3_kernel_pgt)
25054 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
25055 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
25056
25057+NEXT_PAGE(level2_vmemmap_pgt)
25058+ .fill 512,8,0
25059+
25060 NEXT_PAGE(level2_kernel_pgt)
25061 /*
25062 * 512 MB kernel mapping. We spend a full page on this pagetable
25063@@ -494,28 +552,64 @@ NEXT_PAGE(level2_kernel_pgt)
25064 NEXT_PAGE(level2_fixmap_pgt)
25065 .fill 506,8,0
25066 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
25067- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
25068- .fill 5,8,0
25069+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
25070+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
25071+ .fill 4,8,0
25072
25073 NEXT_PAGE(level1_fixmap_pgt)
25074 .fill 512,8,0
25075
25076+NEXT_PAGE(level1_vsyscall_pgt)
25077+ .fill 512,8,0
25078+
25079 #undef PMDS
25080
25081- .data
25082+ .align PAGE_SIZE
25083+ENTRY(cpu_gdt_table)
25084+ .rept NR_CPUS
25085+ .quad 0x0000000000000000 /* NULL descriptor */
25086+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
25087+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
25088+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
25089+ .quad 0x00cffb000000ffff /* __USER32_CS */
25090+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
25091+ .quad 0x00affb000000ffff /* __USER_CS */
25092+
25093+#ifdef CONFIG_PAX_KERNEXEC
25094+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
25095+#else
25096+ .quad 0x0 /* unused */
25097+#endif
25098+
25099+ .quad 0,0 /* TSS */
25100+ .quad 0,0 /* LDT */
25101+ .quad 0,0,0 /* three TLS descriptors */
25102+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
25103+ /* asm/segment.h:GDT_ENTRIES must match this */
25104+
25105+#ifdef CONFIG_PAX_MEMORY_UDEREF
25106+ .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
25107+#else
25108+ .quad 0x0 /* unused */
25109+#endif
25110+
25111+ /* zero the remaining page */
25112+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
25113+ .endr
25114+
25115 .align 16
25116 .globl early_gdt_descr
25117 early_gdt_descr:
25118 .word GDT_ENTRIES*8-1
25119 early_gdt_descr_base:
25120- .quad INIT_PER_CPU_VAR(gdt_page)
25121+ .quad cpu_gdt_table
25122
25123 ENTRY(phys_base)
25124 /* This must match the first entry in level2_kernel_pgt */
25125 .quad 0x0000000000000000
25126
25127 #include "../../x86/xen/xen-head.S"
25128-
25129- __PAGE_ALIGNED_BSS
25130+
25131+ .section .rodata,"a",@progbits
25132 NEXT_PAGE(empty_zero_page)
25133 .skip PAGE_SIZE
25134diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
25135index 05fd74f..c3548b1 100644
25136--- a/arch/x86/kernel/i386_ksyms_32.c
25137+++ b/arch/x86/kernel/i386_ksyms_32.c
25138@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
25139 EXPORT_SYMBOL(cmpxchg8b_emu);
25140 #endif
25141
25142+EXPORT_SYMBOL_GPL(cpu_gdt_table);
25143+
25144 /* Networking helper routines. */
25145 EXPORT_SYMBOL(csum_partial_copy_generic);
25146+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
25147+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
25148
25149 EXPORT_SYMBOL(__get_user_1);
25150 EXPORT_SYMBOL(__get_user_2);
25151@@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
25152 EXPORT_SYMBOL(___preempt_schedule_context);
25153 #endif
25154 #endif
25155+
25156+#ifdef CONFIG_PAX_KERNEXEC
25157+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
25158+#endif
25159+
25160+#ifdef CONFIG_PAX_PER_CPU_PGD
25161+EXPORT_SYMBOL(cpu_pgd);
25162+#endif
25163diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
25164index d5dd808..b6432cf 100644
25165--- a/arch/x86/kernel/i387.c
25166+++ b/arch/x86/kernel/i387.c
25167@@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
25168 static inline bool interrupted_user_mode(void)
25169 {
25170 struct pt_regs *regs = get_irq_regs();
25171- return regs && user_mode_vm(regs);
25172+ return regs && user_mode(regs);
25173 }
25174
25175 /*
25176diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
25177index 2e977b5..5f2c273 100644
25178--- a/arch/x86/kernel/i8259.c
25179+++ b/arch/x86/kernel/i8259.c
25180@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
25181 static void make_8259A_irq(unsigned int irq)
25182 {
25183 disable_irq_nosync(irq);
25184- io_apic_irqs &= ~(1<<irq);
25185+ io_apic_irqs &= ~(1UL<<irq);
25186 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
25187 i8259A_chip.name);
25188 enable_irq(irq);
25189@@ -209,7 +209,7 @@ spurious_8259A_irq:
25190 "spurious 8259A interrupt: IRQ%d.\n", irq);
25191 spurious_irq_mask |= irqmask;
25192 }
25193- atomic_inc(&irq_err_count);
25194+ atomic_inc_unchecked(&irq_err_count);
25195 /*
25196 * Theoretically we do not have to handle this IRQ,
25197 * but in Linux this does not cause problems and is
25198@@ -332,14 +332,16 @@ static void init_8259A(int auto_eoi)
25199 /* (slave's support for AEOI in flat mode is to be investigated) */
25200 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
25201
25202+ pax_open_kernel();
25203 if (auto_eoi)
25204 /*
25205 * In AEOI mode we just have to mask the interrupt
25206 * when acking.
25207 */
25208- i8259A_chip.irq_mask_ack = disable_8259A_irq;
25209+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
25210 else
25211- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25212+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25213+ pax_close_kernel();
25214
25215 udelay(100); /* wait for 8259A to initialize */
25216
25217diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
25218index a979b5b..1d6db75 100644
25219--- a/arch/x86/kernel/io_delay.c
25220+++ b/arch/x86/kernel/io_delay.c
25221@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
25222 * Quirk table for systems that misbehave (lock up, etc.) if port
25223 * 0x80 is used:
25224 */
25225-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
25226+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
25227 {
25228 .callback = dmi_io_delay_0xed_port,
25229 .ident = "Compaq Presario V6000",
25230diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
25231index 4ddaf66..49d5c18 100644
25232--- a/arch/x86/kernel/ioport.c
25233+++ b/arch/x86/kernel/ioport.c
25234@@ -6,6 +6,7 @@
25235 #include <linux/sched.h>
25236 #include <linux/kernel.h>
25237 #include <linux/capability.h>
25238+#include <linux/security.h>
25239 #include <linux/errno.h>
25240 #include <linux/types.h>
25241 #include <linux/ioport.h>
25242@@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25243 return -EINVAL;
25244 if (turn_on && !capable(CAP_SYS_RAWIO))
25245 return -EPERM;
25246+#ifdef CONFIG_GRKERNSEC_IO
25247+ if (turn_on && grsec_disable_privio) {
25248+ gr_handle_ioperm();
25249+ return -ENODEV;
25250+ }
25251+#endif
25252
25253 /*
25254 * If it's the first ioperm() call in this thread's lifetime, set the
25255@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25256 * because the ->io_bitmap_max value must match the bitmap
25257 * contents:
25258 */
25259- tss = &per_cpu(init_tss, get_cpu());
25260+ tss = init_tss + get_cpu();
25261
25262 if (turn_on)
25263 bitmap_clear(t->io_bitmap_ptr, from, num);
25264@@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
25265 if (level > old) {
25266 if (!capable(CAP_SYS_RAWIO))
25267 return -EPERM;
25268+#ifdef CONFIG_GRKERNSEC_IO
25269+ if (grsec_disable_privio) {
25270+ gr_handle_iopl();
25271+ return -ENODEV;
25272+ }
25273+#endif
25274 }
25275 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
25276 t->iopl = level << 12;
25277diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
25278index d99f31d..1c0f466 100644
25279--- a/arch/x86/kernel/irq.c
25280+++ b/arch/x86/kernel/irq.c
25281@@ -21,7 +21,7 @@
25282 #define CREATE_TRACE_POINTS
25283 #include <asm/trace/irq_vectors.h>
25284
25285-atomic_t irq_err_count;
25286+atomic_unchecked_t irq_err_count;
25287
25288 /* Function pointer for generic interrupt vector handling */
25289 void (*x86_platform_ipi_callback)(void) = NULL;
25290@@ -125,9 +125,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
25291 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
25292 seq_printf(p, " Machine check polls\n");
25293 #endif
25294- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
25295+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
25296 #if defined(CONFIG_X86_IO_APIC)
25297- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
25298+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
25299 #endif
25300 return 0;
25301 }
25302@@ -167,7 +167,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
25303
25304 u64 arch_irq_stat(void)
25305 {
25306- u64 sum = atomic_read(&irq_err_count);
25307+ u64 sum = atomic_read_unchecked(&irq_err_count);
25308 return sum;
25309 }
25310
25311diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
25312index d7fcbed..96e715a 100644
25313--- a/arch/x86/kernel/irq_32.c
25314+++ b/arch/x86/kernel/irq_32.c
25315@@ -29,6 +29,8 @@ EXPORT_PER_CPU_SYMBOL(irq_regs);
25316
25317 #ifdef CONFIG_DEBUG_STACKOVERFLOW
25318
25319+extern void gr_handle_kernel_exploit(void);
25320+
25321 int sysctl_panic_on_stackoverflow __read_mostly;
25322
25323 /* Debugging check for stack overflow: is there less than 1KB free? */
25324@@ -39,13 +41,14 @@ static int check_stack_overflow(void)
25325 __asm__ __volatile__("andl %%esp,%0" :
25326 "=r" (sp) : "0" (THREAD_SIZE - 1));
25327
25328- return sp < (sizeof(struct thread_info) + STACK_WARN);
25329+ return sp < STACK_WARN;
25330 }
25331
25332 static void print_stack_overflow(void)
25333 {
25334 printk(KERN_WARNING "low stack detected by irq handler\n");
25335 dump_stack();
25336+ gr_handle_kernel_exploit();
25337 if (sysctl_panic_on_stackoverflow)
25338 panic("low stack detected by irq handler - check messages\n");
25339 }
25340@@ -59,8 +62,8 @@ static inline void print_stack_overflow(void) { }
25341 * per-CPU IRQ handling contexts (thread information and stack)
25342 */
25343 union irq_ctx {
25344- struct thread_info tinfo;
25345- u32 stack[THREAD_SIZE/sizeof(u32)];
25346+ unsigned long previous_esp;
25347+ u32 stack[THREAD_SIZE/sizeof(u32)];
25348 } __attribute__((aligned(THREAD_SIZE)));
25349
25350 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
25351@@ -80,10 +83,9 @@ static void call_on_stack(void *func, void *stack)
25352 static inline int
25353 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25354 {
25355- union irq_ctx *curctx, *irqctx;
25356+ union irq_ctx *irqctx;
25357 u32 *isp, arg1, arg2;
25358
25359- curctx = (union irq_ctx *) current_thread_info();
25360 irqctx = __this_cpu_read(hardirq_ctx);
25361
25362 /*
25363@@ -92,13 +94,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25364 * handler) we can't do that and just have to keep using the
25365 * current stack (which is the irq stack already after all)
25366 */
25367- if (unlikely(curctx == irqctx))
25368+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
25369 return 0;
25370
25371 /* build the stack frame on the IRQ stack */
25372- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
25373- irqctx->tinfo.task = curctx->tinfo.task;
25374- irqctx->tinfo.previous_esp = current_stack_pointer;
25375+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
25376+ irqctx->previous_esp = current_stack_pointer;
25377+
25378+#ifdef CONFIG_PAX_MEMORY_UDEREF
25379+ __set_fs(MAKE_MM_SEG(0));
25380+#endif
25381
25382 if (unlikely(overflow))
25383 call_on_stack(print_stack_overflow, isp);
25384@@ -110,6 +115,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25385 : "0" (irq), "1" (desc), "2" (isp),
25386 "D" (desc->handle_irq)
25387 : "memory", "cc", "ecx");
25388+
25389+#ifdef CONFIG_PAX_MEMORY_UDEREF
25390+ __set_fs(current_thread_info()->addr_limit);
25391+#endif
25392+
25393 return 1;
25394 }
25395
25396@@ -118,48 +128,34 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25397 */
25398 void irq_ctx_init(int cpu)
25399 {
25400- union irq_ctx *irqctx;
25401-
25402 if (per_cpu(hardirq_ctx, cpu))
25403 return;
25404
25405- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
25406- THREADINFO_GFP,
25407- THREAD_SIZE_ORDER));
25408- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
25409- irqctx->tinfo.cpu = cpu;
25410- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
25411-
25412- per_cpu(hardirq_ctx, cpu) = irqctx;
25413-
25414- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
25415- THREADINFO_GFP,
25416- THREAD_SIZE_ORDER));
25417- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
25418- irqctx->tinfo.cpu = cpu;
25419- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
25420-
25421- per_cpu(softirq_ctx, cpu) = irqctx;
25422-
25423- printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
25424- cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
25425+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25426+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25427 }
25428
25429 void do_softirq_own_stack(void)
25430 {
25431- struct thread_info *curctx;
25432 union irq_ctx *irqctx;
25433 u32 *isp;
25434
25435- curctx = current_thread_info();
25436 irqctx = __this_cpu_read(softirq_ctx);
25437- irqctx->tinfo.task = curctx->task;
25438- irqctx->tinfo.previous_esp = current_stack_pointer;
25439+ irqctx->previous_esp = current_stack_pointer;
25440
25441 /* build the stack frame on the softirq stack */
25442- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
25443+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
25444+
25445+#ifdef CONFIG_PAX_MEMORY_UDEREF
25446+ __set_fs(MAKE_MM_SEG(0));
25447+#endif
25448
25449 call_on_stack(__do_softirq, isp);
25450+
25451+#ifdef CONFIG_PAX_MEMORY_UDEREF
25452+ __set_fs(current_thread_info()->addr_limit);
25453+#endif
25454+
25455 }
25456
25457 bool handle_irq(unsigned irq, struct pt_regs *regs)
25458@@ -173,7 +169,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
25459 if (unlikely(!desc))
25460 return false;
25461
25462- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25463+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25464 if (unlikely(overflow))
25465 print_stack_overflow();
25466 desc->handle_irq(irq, desc);
25467diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
25468index 4d1c746..55a22d6 100644
25469--- a/arch/x86/kernel/irq_64.c
25470+++ b/arch/x86/kernel/irq_64.c
25471@@ -26,6 +26,8 @@ EXPORT_PER_CPU_SYMBOL(irq_stat);
25472 DEFINE_PER_CPU(struct pt_regs *, irq_regs);
25473 EXPORT_PER_CPU_SYMBOL(irq_regs);
25474
25475+extern void gr_handle_kernel_exploit(void);
25476+
25477 int sysctl_panic_on_stackoverflow;
25478
25479 /*
25480@@ -44,7 +46,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25481 u64 estack_top, estack_bottom;
25482 u64 curbase = (u64)task_stack_page(current);
25483
25484- if (user_mode_vm(regs))
25485+ if (user_mode(regs))
25486 return;
25487
25488 if (regs->sp >= curbase + sizeof(struct thread_info) +
25489@@ -69,6 +71,8 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25490 irq_stack_top, irq_stack_bottom,
25491 estack_top, estack_bottom);
25492
25493+ gr_handle_kernel_exploit();
25494+
25495 if (sysctl_panic_on_stackoverflow)
25496 panic("low stack detected by irq handler - check messages\n");
25497 #endif
25498diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
25499index 26d5a55..a01160a 100644
25500--- a/arch/x86/kernel/jump_label.c
25501+++ b/arch/x86/kernel/jump_label.c
25502@@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25503 * Jump label is enabled for the first time.
25504 * So we expect a default_nop...
25505 */
25506- if (unlikely(memcmp((void *)entry->code, default_nop, 5)
25507+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
25508 != 0))
25509 bug_at((void *)entry->code, __LINE__);
25510 } else {
25511@@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25512 * ...otherwise expect an ideal_nop. Otherwise
25513 * something went horribly wrong.
25514 */
25515- if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
25516+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
25517 != 0))
25518 bug_at((void *)entry->code, __LINE__);
25519 }
25520@@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
25521 * are converting the default nop to the ideal nop.
25522 */
25523 if (init) {
25524- if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
25525+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
25526 bug_at((void *)entry->code, __LINE__);
25527 } else {
25528 code.jump = 0xe9;
25529 code.offset = entry->target -
25530 (entry->code + JUMP_LABEL_NOP_SIZE);
25531- if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
25532+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
25533 bug_at((void *)entry->code, __LINE__);
25534 }
25535 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
25536diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
25537index 7ec1d5f..5a7d130 100644
25538--- a/arch/x86/kernel/kgdb.c
25539+++ b/arch/x86/kernel/kgdb.c
25540@@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
25541 #ifdef CONFIG_X86_32
25542 switch (regno) {
25543 case GDB_SS:
25544- if (!user_mode_vm(regs))
25545+ if (!user_mode(regs))
25546 *(unsigned long *)mem = __KERNEL_DS;
25547 break;
25548 case GDB_SP:
25549- if (!user_mode_vm(regs))
25550+ if (!user_mode(regs))
25551 *(unsigned long *)mem = kernel_stack_pointer(regs);
25552 break;
25553 case GDB_GS:
25554@@ -228,7 +228,10 @@ static void kgdb_correct_hw_break(void)
25555 bp->attr.bp_addr = breakinfo[breakno].addr;
25556 bp->attr.bp_len = breakinfo[breakno].len;
25557 bp->attr.bp_type = breakinfo[breakno].type;
25558- info->address = breakinfo[breakno].addr;
25559+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
25560+ info->address = ktla_ktva(breakinfo[breakno].addr);
25561+ else
25562+ info->address = breakinfo[breakno].addr;
25563 info->len = breakinfo[breakno].len;
25564 info->type = breakinfo[breakno].type;
25565 val = arch_install_hw_breakpoint(bp);
25566@@ -475,12 +478,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
25567 case 'k':
25568 /* clear the trace bit */
25569 linux_regs->flags &= ~X86_EFLAGS_TF;
25570- atomic_set(&kgdb_cpu_doing_single_step, -1);
25571+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
25572
25573 /* set the trace bit if we're stepping */
25574 if (remcomInBuffer[0] == 's') {
25575 linux_regs->flags |= X86_EFLAGS_TF;
25576- atomic_set(&kgdb_cpu_doing_single_step,
25577+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
25578 raw_smp_processor_id());
25579 }
25580
25581@@ -545,7 +548,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
25582
25583 switch (cmd) {
25584 case DIE_DEBUG:
25585- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
25586+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
25587 if (user_mode(regs))
25588 return single_step_cont(regs, args);
25589 break;
25590@@ -750,11 +753,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25591 #endif /* CONFIG_DEBUG_RODATA */
25592
25593 bpt->type = BP_BREAKPOINT;
25594- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
25595+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
25596 BREAK_INSTR_SIZE);
25597 if (err)
25598 return err;
25599- err = probe_kernel_write((char *)bpt->bpt_addr,
25600+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25601 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
25602 #ifdef CONFIG_DEBUG_RODATA
25603 if (!err)
25604@@ -767,7 +770,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25605 return -EBUSY;
25606 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
25607 BREAK_INSTR_SIZE);
25608- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25609+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25610 if (err)
25611 return err;
25612 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
25613@@ -792,13 +795,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
25614 if (mutex_is_locked(&text_mutex))
25615 goto knl_write;
25616 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
25617- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25618+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25619 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
25620 goto knl_write;
25621 return err;
25622 knl_write:
25623 #endif /* CONFIG_DEBUG_RODATA */
25624- return probe_kernel_write((char *)bpt->bpt_addr,
25625+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25626 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
25627 }
25628
25629diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
25630index 79a3f96..6ba030a 100644
25631--- a/arch/x86/kernel/kprobes/core.c
25632+++ b/arch/x86/kernel/kprobes/core.c
25633@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
25634 s32 raddr;
25635 } __packed *insn;
25636
25637- insn = (struct __arch_relative_insn *)from;
25638+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
25639+
25640+ pax_open_kernel();
25641 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
25642 insn->op = op;
25643+ pax_close_kernel();
25644 }
25645
25646 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
25647@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
25648 kprobe_opcode_t opcode;
25649 kprobe_opcode_t *orig_opcodes = opcodes;
25650
25651- if (search_exception_tables((unsigned long)opcodes))
25652+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
25653 return 0; /* Page fault may occur on this address. */
25654
25655 retry:
25656@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
25657 * for the first byte, we can recover the original instruction
25658 * from it and kp->opcode.
25659 */
25660- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25661+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25662 buf[0] = kp->opcode;
25663- return (unsigned long)buf;
25664+ return ktva_ktla((unsigned long)buf);
25665 }
25666
25667 /*
25668@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25669 /* Another subsystem puts a breakpoint, failed to recover */
25670 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
25671 return 0;
25672+ pax_open_kernel();
25673 memcpy(dest, insn.kaddr, insn.length);
25674+ pax_close_kernel();
25675
25676 #ifdef CONFIG_X86_64
25677 if (insn_rip_relative(&insn)) {
25678@@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25679 return 0;
25680 }
25681 disp = (u8 *) dest + insn_offset_displacement(&insn);
25682+ pax_open_kernel();
25683 *(s32 *) disp = (s32) newdisp;
25684+ pax_close_kernel();
25685 }
25686 #endif
25687 return insn.length;
25688@@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25689 * nor set current_kprobe, because it doesn't use single
25690 * stepping.
25691 */
25692- regs->ip = (unsigned long)p->ainsn.insn;
25693+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25694 preempt_enable_no_resched();
25695 return;
25696 }
25697@@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25698 regs->flags &= ~X86_EFLAGS_IF;
25699 /* single step inline if the instruction is an int3 */
25700 if (p->opcode == BREAKPOINT_INSTRUCTION)
25701- regs->ip = (unsigned long)p->addr;
25702+ regs->ip = ktla_ktva((unsigned long)p->addr);
25703 else
25704- regs->ip = (unsigned long)p->ainsn.insn;
25705+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25706 }
25707
25708 /*
25709@@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
25710 setup_singlestep(p, regs, kcb, 0);
25711 return 1;
25712 }
25713- } else if (*addr != BREAKPOINT_INSTRUCTION) {
25714+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
25715 /*
25716 * The breakpoint instruction was removed right
25717 * after we hit it. Another cpu has removed
25718@@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
25719 " movq %rax, 152(%rsp)\n"
25720 RESTORE_REGS_STRING
25721 " popfq\n"
25722+#ifdef KERNEXEC_PLUGIN
25723+ " btsq $63,(%rsp)\n"
25724+#endif
25725 #else
25726 " pushf\n"
25727 SAVE_REGS_STRING
25728@@ -779,7 +789,7 @@ static void __kprobes
25729 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
25730 {
25731 unsigned long *tos = stack_addr(regs);
25732- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
25733+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
25734 unsigned long orig_ip = (unsigned long)p->addr;
25735 kprobe_opcode_t *insn = p->ainsn.insn;
25736
25737@@ -961,7 +971,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
25738 struct die_args *args = data;
25739 int ret = NOTIFY_DONE;
25740
25741- if (args->regs && user_mode_vm(args->regs))
25742+ if (args->regs && user_mode(args->regs))
25743 return ret;
25744
25745 switch (val) {
25746diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
25747index 898160b..758cde8 100644
25748--- a/arch/x86/kernel/kprobes/opt.c
25749+++ b/arch/x86/kernel/kprobes/opt.c
25750@@ -79,6 +79,7 @@ found:
25751 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
25752 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25753 {
25754+ pax_open_kernel();
25755 #ifdef CONFIG_X86_64
25756 *addr++ = 0x48;
25757 *addr++ = 0xbf;
25758@@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
25759 *addr++ = 0xb8;
25760 #endif
25761 *(unsigned long *)addr = val;
25762+ pax_close_kernel();
25763 }
25764
25765 asm (
25766@@ -335,7 +337,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25767 * Verify if the address gap is in 2GB range, because this uses
25768 * a relative jump.
25769 */
25770- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
25771+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
25772 if (abs(rel) > 0x7fffffff)
25773 return -ERANGE;
25774
25775@@ -350,16 +352,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25776 op->optinsn.size = ret;
25777
25778 /* Copy arch-dep-instance from template */
25779- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
25780+ pax_open_kernel();
25781+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
25782+ pax_close_kernel();
25783
25784 /* Set probe information */
25785 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
25786
25787 /* Set probe function call */
25788- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
25789+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
25790
25791 /* Set returning jmp instruction at the tail of out-of-line buffer */
25792- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
25793+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
25794 (u8 *)op->kp.addr + op->optinsn.size);
25795
25796 flush_icache_range((unsigned long) buf,
25797@@ -384,7 +388,7 @@ void __kprobes arch_optimize_kprobes(struct list_head *oplist)
25798 WARN_ON(kprobe_disabled(&op->kp));
25799
25800 /* Backup instructions which will be replaced by jump address */
25801- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
25802+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
25803 RELATIVE_ADDR_SIZE);
25804
25805 insn_buf[0] = RELATIVEJUMP_OPCODE;
25806@@ -433,7 +437,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
25807 /* This kprobe is really able to run optimized path. */
25808 op = container_of(p, struct optimized_kprobe, kp);
25809 /* Detour through copied instructions */
25810- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
25811+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
25812 if (!reenter)
25813 reset_current_kprobe();
25814 preempt_enable_no_resched();
25815diff --git a/arch/x86/kernel/ksysfs.c b/arch/x86/kernel/ksysfs.c
25816index c2bedae..25e7ab6 100644
25817--- a/arch/x86/kernel/ksysfs.c
25818+++ b/arch/x86/kernel/ksysfs.c
25819@@ -184,7 +184,7 @@ out:
25820
25821 static struct kobj_attribute type_attr = __ATTR_RO(type);
25822
25823-static struct bin_attribute data_attr = {
25824+static bin_attribute_no_const data_attr __read_only = {
25825 .attr = {
25826 .name = "data",
25827 .mode = S_IRUGO,
25828diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
25829index af1d14a..37b8776 100644
25830--- a/arch/x86/kernel/ldt.c
25831+++ b/arch/x86/kernel/ldt.c
25832@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
25833 if (reload) {
25834 #ifdef CONFIG_SMP
25835 preempt_disable();
25836- load_LDT(pc);
25837+ load_LDT_nolock(pc);
25838 if (!cpumask_equal(mm_cpumask(current->mm),
25839 cpumask_of(smp_processor_id())))
25840 smp_call_function(flush_ldt, current->mm, 1);
25841 preempt_enable();
25842 #else
25843- load_LDT(pc);
25844+ load_LDT_nolock(pc);
25845 #endif
25846 }
25847 if (oldsize) {
25848@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
25849 return err;
25850
25851 for (i = 0; i < old->size; i++)
25852- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
25853+ write_ldt_entry(new->ldt, i, old->ldt + i);
25854 return 0;
25855 }
25856
25857@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
25858 retval = copy_ldt(&mm->context, &old_mm->context);
25859 mutex_unlock(&old_mm->context.lock);
25860 }
25861+
25862+ if (tsk == current) {
25863+ mm->context.vdso = 0;
25864+
25865+#ifdef CONFIG_X86_32
25866+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25867+ mm->context.user_cs_base = 0UL;
25868+ mm->context.user_cs_limit = ~0UL;
25869+
25870+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
25871+ cpus_clear(mm->context.cpu_user_cs_mask);
25872+#endif
25873+
25874+#endif
25875+#endif
25876+
25877+ }
25878+
25879 return retval;
25880 }
25881
25882@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
25883 }
25884 }
25885
25886+#ifdef CONFIG_PAX_SEGMEXEC
25887+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
25888+ error = -EINVAL;
25889+ goto out_unlock;
25890+ }
25891+#endif
25892+
25893 /*
25894 * On x86-64 we do not support 16-bit segments due to
25895 * IRET leaking the high bits of the kernel stack address.
25896diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
25897index 1667b1d..16492c5 100644
25898--- a/arch/x86/kernel/machine_kexec_32.c
25899+++ b/arch/x86/kernel/machine_kexec_32.c
25900@@ -25,7 +25,7 @@
25901 #include <asm/cacheflush.h>
25902 #include <asm/debugreg.h>
25903
25904-static void set_idt(void *newidt, __u16 limit)
25905+static void set_idt(struct desc_struct *newidt, __u16 limit)
25906 {
25907 struct desc_ptr curidt;
25908
25909@@ -37,7 +37,7 @@ static void set_idt(void *newidt, __u16 limit)
25910 }
25911
25912
25913-static void set_gdt(void *newgdt, __u16 limit)
25914+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
25915 {
25916 struct desc_ptr curgdt;
25917
25918@@ -215,7 +215,7 @@ void machine_kexec(struct kimage *image)
25919 }
25920
25921 control_page = page_address(image->control_code_page);
25922- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
25923+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
25924
25925 relocate_kernel_ptr = control_page;
25926 page_list[PA_CONTROL_PAGE] = __pa(control_page);
25927diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
25928index 18be189..4a9fe40 100644
25929--- a/arch/x86/kernel/module.c
25930+++ b/arch/x86/kernel/module.c
25931@@ -43,15 +43,60 @@ do { \
25932 } while (0)
25933 #endif
25934
25935-void *module_alloc(unsigned long size)
25936+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
25937 {
25938- if (PAGE_ALIGN(size) > MODULES_LEN)
25939+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
25940 return NULL;
25941 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
25942- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
25943+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
25944 NUMA_NO_NODE, __builtin_return_address(0));
25945 }
25946
25947+void *module_alloc(unsigned long size)
25948+{
25949+
25950+#ifdef CONFIG_PAX_KERNEXEC
25951+ return __module_alloc(size, PAGE_KERNEL);
25952+#else
25953+ return __module_alloc(size, PAGE_KERNEL_EXEC);
25954+#endif
25955+
25956+}
25957+
25958+#ifdef CONFIG_PAX_KERNEXEC
25959+#ifdef CONFIG_X86_32
25960+void *module_alloc_exec(unsigned long size)
25961+{
25962+ struct vm_struct *area;
25963+
25964+ if (size == 0)
25965+ return NULL;
25966+
25967+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
25968+ return area ? area->addr : NULL;
25969+}
25970+EXPORT_SYMBOL(module_alloc_exec);
25971+
25972+void module_free_exec(struct module *mod, void *module_region)
25973+{
25974+ vunmap(module_region);
25975+}
25976+EXPORT_SYMBOL(module_free_exec);
25977+#else
25978+void module_free_exec(struct module *mod, void *module_region)
25979+{
25980+ module_free(mod, module_region);
25981+}
25982+EXPORT_SYMBOL(module_free_exec);
25983+
25984+void *module_alloc_exec(unsigned long size)
25985+{
25986+ return __module_alloc(size, PAGE_KERNEL_RX);
25987+}
25988+EXPORT_SYMBOL(module_alloc_exec);
25989+#endif
25990+#endif
25991+
25992 #ifdef CONFIG_X86_32
25993 int apply_relocate(Elf32_Shdr *sechdrs,
25994 const char *strtab,
25995@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25996 unsigned int i;
25997 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
25998 Elf32_Sym *sym;
25999- uint32_t *location;
26000+ uint32_t *plocation, location;
26001
26002 DEBUGP("Applying relocate section %u to %u\n",
26003 relsec, sechdrs[relsec].sh_info);
26004 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
26005 /* This is where to make the change */
26006- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
26007- + rel[i].r_offset;
26008+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
26009+ location = (uint32_t)plocation;
26010+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
26011+ plocation = ktla_ktva((void *)plocation);
26012 /* This is the symbol it is referring to. Note that all
26013 undefined symbols have been resolved. */
26014 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
26015@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26016 switch (ELF32_R_TYPE(rel[i].r_info)) {
26017 case R_386_32:
26018 /* We add the value into the location given */
26019- *location += sym->st_value;
26020+ pax_open_kernel();
26021+ *plocation += sym->st_value;
26022+ pax_close_kernel();
26023 break;
26024 case R_386_PC32:
26025 /* Add the value, subtract its position */
26026- *location += sym->st_value - (uint32_t)location;
26027+ pax_open_kernel();
26028+ *plocation += sym->st_value - location;
26029+ pax_close_kernel();
26030 break;
26031 default:
26032 pr_err("%s: Unknown relocation: %u\n",
26033@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
26034 case R_X86_64_NONE:
26035 break;
26036 case R_X86_64_64:
26037+ pax_open_kernel();
26038 *(u64 *)loc = val;
26039+ pax_close_kernel();
26040 break;
26041 case R_X86_64_32:
26042+ pax_open_kernel();
26043 *(u32 *)loc = val;
26044+ pax_close_kernel();
26045 if (val != *(u32 *)loc)
26046 goto overflow;
26047 break;
26048 case R_X86_64_32S:
26049+ pax_open_kernel();
26050 *(s32 *)loc = val;
26051+ pax_close_kernel();
26052 if ((s64)val != *(s32 *)loc)
26053 goto overflow;
26054 break;
26055 case R_X86_64_PC32:
26056 val -= (u64)loc;
26057+ pax_open_kernel();
26058 *(u32 *)loc = val;
26059+ pax_close_kernel();
26060+
26061 #if 0
26062 if ((s64)val != *(s32 *)loc)
26063 goto overflow;
26064diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
26065index 05266b5..3432443 100644
26066--- a/arch/x86/kernel/msr.c
26067+++ b/arch/x86/kernel/msr.c
26068@@ -37,6 +37,7 @@
26069 #include <linux/notifier.h>
26070 #include <linux/uaccess.h>
26071 #include <linux/gfp.h>
26072+#include <linux/grsecurity.h>
26073
26074 #include <asm/processor.h>
26075 #include <asm/msr.h>
26076@@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
26077 int err = 0;
26078 ssize_t bytes = 0;
26079
26080+#ifdef CONFIG_GRKERNSEC_KMEM
26081+ gr_handle_msr_write();
26082+ return -EPERM;
26083+#endif
26084+
26085 if (count % 8)
26086 return -EINVAL; /* Invalid chunk size */
26087
26088@@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
26089 err = -EBADF;
26090 break;
26091 }
26092+#ifdef CONFIG_GRKERNSEC_KMEM
26093+ gr_handle_msr_write();
26094+ return -EPERM;
26095+#endif
26096 if (copy_from_user(&regs, uregs, sizeof regs)) {
26097 err = -EFAULT;
26098 break;
26099@@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
26100 return notifier_from_errno(err);
26101 }
26102
26103-static struct notifier_block __refdata msr_class_cpu_notifier = {
26104+static struct notifier_block msr_class_cpu_notifier = {
26105 .notifier_call = msr_class_cpu_callback,
26106 };
26107
26108diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
26109index 6fcb49c..5b3f4ff 100644
26110--- a/arch/x86/kernel/nmi.c
26111+++ b/arch/x86/kernel/nmi.c
26112@@ -138,7 +138,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
26113 return handled;
26114 }
26115
26116-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26117+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
26118 {
26119 struct nmi_desc *desc = nmi_to_desc(type);
26120 unsigned long flags;
26121@@ -162,9 +162,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26122 * event confuses some handlers (kdump uses this flag)
26123 */
26124 if (action->flags & NMI_FLAG_FIRST)
26125- list_add_rcu(&action->list, &desc->head);
26126+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
26127 else
26128- list_add_tail_rcu(&action->list, &desc->head);
26129+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
26130
26131 spin_unlock_irqrestore(&desc->lock, flags);
26132 return 0;
26133@@ -187,7 +187,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
26134 if (!strcmp(n->name, name)) {
26135 WARN(in_nmi(),
26136 "Trying to free NMI (%s) from NMI context!\n", n->name);
26137- list_del_rcu(&n->list);
26138+ pax_list_del_rcu((struct list_head *)&n->list);
26139 break;
26140 }
26141 }
26142@@ -512,6 +512,17 @@ static inline void nmi_nesting_postprocess(void)
26143 dotraplinkage notrace __kprobes void
26144 do_nmi(struct pt_regs *regs, long error_code)
26145 {
26146+
26147+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26148+ if (!user_mode(regs)) {
26149+ unsigned long cs = regs->cs & 0xFFFF;
26150+ unsigned long ip = ktva_ktla(regs->ip);
26151+
26152+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
26153+ regs->ip = ip;
26154+ }
26155+#endif
26156+
26157 nmi_nesting_preprocess(regs);
26158
26159 nmi_enter();
26160diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
26161index 6d9582e..f746287 100644
26162--- a/arch/x86/kernel/nmi_selftest.c
26163+++ b/arch/x86/kernel/nmi_selftest.c
26164@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
26165 {
26166 /* trap all the unknown NMIs we may generate */
26167 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
26168- __initdata);
26169+ __initconst);
26170 }
26171
26172 static void __init cleanup_nmi_testsuite(void)
26173@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
26174 unsigned long timeout;
26175
26176 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
26177- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
26178+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
26179 nmi_fail = FAILURE;
26180 return;
26181 }
26182diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
26183index bbb6c73..24a58ef 100644
26184--- a/arch/x86/kernel/paravirt-spinlocks.c
26185+++ b/arch/x86/kernel/paravirt-spinlocks.c
26186@@ -8,7 +8,7 @@
26187
26188 #include <asm/paravirt.h>
26189
26190-struct pv_lock_ops pv_lock_ops = {
26191+struct pv_lock_ops pv_lock_ops __read_only = {
26192 #ifdef CONFIG_SMP
26193 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
26194 .unlock_kick = paravirt_nop,
26195diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
26196index 1b10af8..0b58cbc 100644
26197--- a/arch/x86/kernel/paravirt.c
26198+++ b/arch/x86/kernel/paravirt.c
26199@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
26200 {
26201 return x;
26202 }
26203+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26204+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
26205+#endif
26206
26207 void __init default_banner(void)
26208 {
26209@@ -142,15 +145,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
26210 if (opfunc == NULL)
26211 /* If there's no function, patch it with a ud2a (BUG) */
26212 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
26213- else if (opfunc == _paravirt_nop)
26214+ else if (opfunc == (void *)_paravirt_nop)
26215 /* If the operation is a nop, then nop the callsite */
26216 ret = paravirt_patch_nop();
26217
26218 /* identity functions just return their single argument */
26219- else if (opfunc == _paravirt_ident_32)
26220+ else if (opfunc == (void *)_paravirt_ident_32)
26221 ret = paravirt_patch_ident_32(insnbuf, len);
26222- else if (opfunc == _paravirt_ident_64)
26223+ else if (opfunc == (void *)_paravirt_ident_64)
26224 ret = paravirt_patch_ident_64(insnbuf, len);
26225+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26226+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
26227+ ret = paravirt_patch_ident_64(insnbuf, len);
26228+#endif
26229
26230 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
26231 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
26232@@ -175,7 +182,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
26233 if (insn_len > len || start == NULL)
26234 insn_len = len;
26235 else
26236- memcpy(insnbuf, start, insn_len);
26237+ memcpy(insnbuf, ktla_ktva(start), insn_len);
26238
26239 return insn_len;
26240 }
26241@@ -299,7 +306,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
26242 return this_cpu_read(paravirt_lazy_mode);
26243 }
26244
26245-struct pv_info pv_info = {
26246+struct pv_info pv_info __read_only = {
26247 .name = "bare hardware",
26248 .paravirt_enabled = 0,
26249 .kernel_rpl = 0,
26250@@ -310,16 +317,16 @@ struct pv_info pv_info = {
26251 #endif
26252 };
26253
26254-struct pv_init_ops pv_init_ops = {
26255+struct pv_init_ops pv_init_ops __read_only = {
26256 .patch = native_patch,
26257 };
26258
26259-struct pv_time_ops pv_time_ops = {
26260+struct pv_time_ops pv_time_ops __read_only = {
26261 .sched_clock = native_sched_clock,
26262 .steal_clock = native_steal_clock,
26263 };
26264
26265-__visible struct pv_irq_ops pv_irq_ops = {
26266+__visible struct pv_irq_ops pv_irq_ops __read_only = {
26267 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
26268 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
26269 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
26270@@ -331,7 +338,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
26271 #endif
26272 };
26273
26274-__visible struct pv_cpu_ops pv_cpu_ops = {
26275+__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
26276 .cpuid = native_cpuid,
26277 .get_debugreg = native_get_debugreg,
26278 .set_debugreg = native_set_debugreg,
26279@@ -389,21 +396,26 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
26280 .end_context_switch = paravirt_nop,
26281 };
26282
26283-struct pv_apic_ops pv_apic_ops = {
26284+struct pv_apic_ops pv_apic_ops __read_only= {
26285 #ifdef CONFIG_X86_LOCAL_APIC
26286 .startup_ipi_hook = paravirt_nop,
26287 #endif
26288 };
26289
26290-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
26291+#ifdef CONFIG_X86_32
26292+#ifdef CONFIG_X86_PAE
26293+/* 64-bit pagetable entries */
26294+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
26295+#else
26296 /* 32-bit pagetable entries */
26297 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
26298+#endif
26299 #else
26300 /* 64-bit pagetable entries */
26301 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
26302 #endif
26303
26304-struct pv_mmu_ops pv_mmu_ops = {
26305+struct pv_mmu_ops pv_mmu_ops __read_only = {
26306
26307 .read_cr2 = native_read_cr2,
26308 .write_cr2 = native_write_cr2,
26309@@ -453,6 +465,7 @@ struct pv_mmu_ops pv_mmu_ops = {
26310 .make_pud = PTE_IDENT,
26311
26312 .set_pgd = native_set_pgd,
26313+ .set_pgd_batched = native_set_pgd_batched,
26314 #endif
26315 #endif /* PAGETABLE_LEVELS >= 3 */
26316
26317@@ -473,6 +486,12 @@ struct pv_mmu_ops pv_mmu_ops = {
26318 },
26319
26320 .set_fixmap = native_set_fixmap,
26321+
26322+#ifdef CONFIG_PAX_KERNEXEC
26323+ .pax_open_kernel = native_pax_open_kernel,
26324+ .pax_close_kernel = native_pax_close_kernel,
26325+#endif
26326+
26327 };
26328
26329 EXPORT_SYMBOL_GPL(pv_time_ops);
26330diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
26331index 299d493..2ccb0ee 100644
26332--- a/arch/x86/kernel/pci-calgary_64.c
26333+++ b/arch/x86/kernel/pci-calgary_64.c
26334@@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
26335 tce_space = be64_to_cpu(readq(target));
26336 tce_space = tce_space & TAR_SW_BITS;
26337
26338- tce_space = tce_space & (~specified_table_size);
26339+ tce_space = tce_space & (~(unsigned long)specified_table_size);
26340 info->tce_space = (u64 *)__va(tce_space);
26341 }
26342 }
26343diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
26344index 35ccf75..7a15747 100644
26345--- a/arch/x86/kernel/pci-iommu_table.c
26346+++ b/arch/x86/kernel/pci-iommu_table.c
26347@@ -2,7 +2,7 @@
26348 #include <asm/iommu_table.h>
26349 #include <linux/string.h>
26350 #include <linux/kallsyms.h>
26351-
26352+#include <linux/sched.h>
26353
26354 #define DEBUG 1
26355
26356diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
26357index 6c483ba..d10ce2f 100644
26358--- a/arch/x86/kernel/pci-swiotlb.c
26359+++ b/arch/x86/kernel/pci-swiotlb.c
26360@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
26361 void *vaddr, dma_addr_t dma_addr,
26362 struct dma_attrs *attrs)
26363 {
26364- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
26365+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
26366 }
26367
26368 static struct dma_map_ops swiotlb_dma_ops = {
26369diff --git a/arch/x86/kernel/preempt.S b/arch/x86/kernel/preempt.S
26370index ca7f0d5..8996469 100644
26371--- a/arch/x86/kernel/preempt.S
26372+++ b/arch/x86/kernel/preempt.S
26373@@ -3,12 +3,14 @@
26374 #include <asm/dwarf2.h>
26375 #include <asm/asm.h>
26376 #include <asm/calling.h>
26377+#include <asm/alternative-asm.h>
26378
26379 ENTRY(___preempt_schedule)
26380 CFI_STARTPROC
26381 SAVE_ALL
26382 call preempt_schedule
26383 RESTORE_ALL
26384+ pax_force_retaddr
26385 ret
26386 CFI_ENDPROC
26387
26388@@ -19,6 +21,7 @@ ENTRY(___preempt_schedule_context)
26389 SAVE_ALL
26390 call preempt_schedule_context
26391 RESTORE_ALL
26392+ pax_force_retaddr
26393 ret
26394 CFI_ENDPROC
26395
26396diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
26397index 3fb8d95..254dc51 100644
26398--- a/arch/x86/kernel/process.c
26399+++ b/arch/x86/kernel/process.c
26400@@ -36,7 +36,8 @@
26401 * section. Since TSS's are completely CPU-local, we want them
26402 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
26403 */
26404-__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
26405+struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
26406+EXPORT_SYMBOL(init_tss);
26407
26408 #ifdef CONFIG_X86_64
26409 static DEFINE_PER_CPU(unsigned char, is_idle);
26410@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
26411 task_xstate_cachep =
26412 kmem_cache_create("task_xstate", xstate_size,
26413 __alignof__(union thread_xstate),
26414- SLAB_PANIC | SLAB_NOTRACK, NULL);
26415+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
26416 }
26417
26418 /*
26419@@ -105,7 +106,7 @@ void exit_thread(void)
26420 unsigned long *bp = t->io_bitmap_ptr;
26421
26422 if (bp) {
26423- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
26424+ struct tss_struct *tss = init_tss + get_cpu();
26425
26426 t->io_bitmap_ptr = NULL;
26427 clear_thread_flag(TIF_IO_BITMAP);
26428@@ -125,6 +126,9 @@ void flush_thread(void)
26429 {
26430 struct task_struct *tsk = current;
26431
26432+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
26433+ loadsegment(gs, 0);
26434+#endif
26435 flush_ptrace_hw_breakpoint(tsk);
26436 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
26437 drop_init_fpu(tsk);
26438@@ -271,7 +275,7 @@ static void __exit_idle(void)
26439 void exit_idle(void)
26440 {
26441 /* idle loop has pid 0 */
26442- if (current->pid)
26443+ if (task_pid_nr(current))
26444 return;
26445 __exit_idle();
26446 }
26447@@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
26448 return ret;
26449 }
26450 #endif
26451-void stop_this_cpu(void *dummy)
26452+__noreturn void stop_this_cpu(void *dummy)
26453 {
26454 local_irq_disable();
26455 /*
26456@@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
26457 }
26458 early_param("idle", idle_setup);
26459
26460-unsigned long arch_align_stack(unsigned long sp)
26461+#ifdef CONFIG_PAX_RANDKSTACK
26462+void pax_randomize_kstack(struct pt_regs *regs)
26463 {
26464- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
26465- sp -= get_random_int() % 8192;
26466- return sp & ~0xf;
26467-}
26468+ struct thread_struct *thread = &current->thread;
26469+ unsigned long time;
26470
26471-unsigned long arch_randomize_brk(struct mm_struct *mm)
26472-{
26473- unsigned long range_end = mm->brk + 0x02000000;
26474- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
26475-}
26476+ if (!randomize_va_space)
26477+ return;
26478+
26479+ if (v8086_mode(regs))
26480+ return;
26481
26482+ rdtscl(time);
26483+
26484+ /* P4 seems to return a 0 LSB, ignore it */
26485+#ifdef CONFIG_MPENTIUM4
26486+ time &= 0x3EUL;
26487+ time <<= 2;
26488+#elif defined(CONFIG_X86_64)
26489+ time &= 0xFUL;
26490+ time <<= 4;
26491+#else
26492+ time &= 0x1FUL;
26493+ time <<= 3;
26494+#endif
26495+
26496+ thread->sp0 ^= time;
26497+ load_sp0(init_tss + smp_processor_id(), thread);
26498+
26499+#ifdef CONFIG_X86_64
26500+ this_cpu_write(kernel_stack, thread->sp0);
26501+#endif
26502+}
26503+#endif
26504diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
26505index 0de43e9..056b840 100644
26506--- a/arch/x86/kernel/process_32.c
26507+++ b/arch/x86/kernel/process_32.c
26508@@ -64,6 +64,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
26509 unsigned long thread_saved_pc(struct task_struct *tsk)
26510 {
26511 return ((unsigned long *)tsk->thread.sp)[3];
26512+//XXX return tsk->thread.eip;
26513 }
26514
26515 void __show_regs(struct pt_regs *regs, int all)
26516@@ -73,19 +74,18 @@ void __show_regs(struct pt_regs *regs, int all)
26517 unsigned long sp;
26518 unsigned short ss, gs;
26519
26520- if (user_mode_vm(regs)) {
26521+ if (user_mode(regs)) {
26522 sp = regs->sp;
26523 ss = regs->ss & 0xffff;
26524- gs = get_user_gs(regs);
26525 } else {
26526 sp = kernel_stack_pointer(regs);
26527 savesegment(ss, ss);
26528- savesegment(gs, gs);
26529 }
26530+ gs = get_user_gs(regs);
26531
26532 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
26533 (u16)regs->cs, regs->ip, regs->flags,
26534- smp_processor_id());
26535+ raw_smp_processor_id());
26536 print_symbol("EIP is at %s\n", regs->ip);
26537
26538 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
26539@@ -132,20 +132,21 @@ void release_thread(struct task_struct *dead_task)
26540 int copy_thread(unsigned long clone_flags, unsigned long sp,
26541 unsigned long arg, struct task_struct *p)
26542 {
26543- struct pt_regs *childregs = task_pt_regs(p);
26544+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
26545 struct task_struct *tsk;
26546 int err;
26547
26548 p->thread.sp = (unsigned long) childregs;
26549 p->thread.sp0 = (unsigned long) (childregs+1);
26550+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26551
26552 if (unlikely(p->flags & PF_KTHREAD)) {
26553 /* kernel thread */
26554 memset(childregs, 0, sizeof(struct pt_regs));
26555 p->thread.ip = (unsigned long) ret_from_kernel_thread;
26556- task_user_gs(p) = __KERNEL_STACK_CANARY;
26557- childregs->ds = __USER_DS;
26558- childregs->es = __USER_DS;
26559+ savesegment(gs, childregs->gs);
26560+ childregs->ds = __KERNEL_DS;
26561+ childregs->es = __KERNEL_DS;
26562 childregs->fs = __KERNEL_PERCPU;
26563 childregs->bx = sp; /* function */
26564 childregs->bp = arg;
26565@@ -252,7 +253,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26566 struct thread_struct *prev = &prev_p->thread,
26567 *next = &next_p->thread;
26568 int cpu = smp_processor_id();
26569- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26570+ struct tss_struct *tss = init_tss + cpu;
26571 fpu_switch_t fpu;
26572
26573 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
26574@@ -276,6 +277,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26575 */
26576 lazy_save_gs(prev->gs);
26577
26578+#ifdef CONFIG_PAX_MEMORY_UDEREF
26579+ __set_fs(task_thread_info(next_p)->addr_limit);
26580+#endif
26581+
26582 /*
26583 * Load the per-thread Thread-Local Storage descriptor.
26584 */
26585@@ -314,6 +319,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26586 */
26587 arch_end_context_switch(next_p);
26588
26589+ this_cpu_write(current_task, next_p);
26590+ this_cpu_write(current_tinfo, &next_p->tinfo);
26591+
26592 /*
26593 * Restore %gs if needed (which is common)
26594 */
26595@@ -322,8 +330,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26596
26597 switch_fpu_finish(next_p, fpu);
26598
26599- this_cpu_write(current_task, next_p);
26600-
26601 return prev_p;
26602 }
26603
26604@@ -353,4 +359,3 @@ unsigned long get_wchan(struct task_struct *p)
26605 } while (count++ < 16);
26606 return 0;
26607 }
26608-
26609diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
26610index 9c0280f..5bbb1c0 100644
26611--- a/arch/x86/kernel/process_64.c
26612+++ b/arch/x86/kernel/process_64.c
26613@@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26614 struct pt_regs *childregs;
26615 struct task_struct *me = current;
26616
26617- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
26618+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
26619 childregs = task_pt_regs(p);
26620 p->thread.sp = (unsigned long) childregs;
26621 p->thread.usersp = me->thread.usersp;
26622+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26623 set_tsk_thread_flag(p, TIF_FORK);
26624 p->thread.fpu_counter = 0;
26625 p->thread.io_bitmap_ptr = NULL;
26626@@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26627 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
26628 savesegment(es, p->thread.es);
26629 savesegment(ds, p->thread.ds);
26630+ savesegment(ss, p->thread.ss);
26631+ BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
26632 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26633
26634 if (unlikely(p->flags & PF_KTHREAD)) {
26635@@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26636 struct thread_struct *prev = &prev_p->thread;
26637 struct thread_struct *next = &next_p->thread;
26638 int cpu = smp_processor_id();
26639- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26640+ struct tss_struct *tss = init_tss + cpu;
26641 unsigned fsindex, gsindex;
26642 fpu_switch_t fpu;
26643
26644@@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26645 if (unlikely(next->ds | prev->ds))
26646 loadsegment(ds, next->ds);
26647
26648+ savesegment(ss, prev->ss);
26649+ if (unlikely(next->ss != prev->ss))
26650+ loadsegment(ss, next->ss);
26651
26652 /* We must save %fs and %gs before load_TLS() because
26653 * %fs and %gs may be cleared by load_TLS().
26654@@ -362,6 +368,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26655 prev->usersp = this_cpu_read(old_rsp);
26656 this_cpu_write(old_rsp, next->usersp);
26657 this_cpu_write(current_task, next_p);
26658+ this_cpu_write(current_tinfo, &next_p->tinfo);
26659
26660 /*
26661 * If it were not for PREEMPT_ACTIVE we could guarantee that the
26662@@ -371,9 +378,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26663 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
26664 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
26665
26666- this_cpu_write(kernel_stack,
26667- (unsigned long)task_stack_page(next_p) +
26668- THREAD_SIZE - KERNEL_STACK_OFFSET);
26669+ this_cpu_write(kernel_stack, next->sp0);
26670
26671 /*
26672 * Now maybe reload the debug registers and handle I/O bitmaps
26673@@ -442,12 +447,11 @@ unsigned long get_wchan(struct task_struct *p)
26674 if (!p || p == current || p->state == TASK_RUNNING)
26675 return 0;
26676 stack = (unsigned long)task_stack_page(p);
26677- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
26678+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
26679 return 0;
26680 fp = *(u64 *)(p->thread.sp);
26681 do {
26682- if (fp < (unsigned long)stack ||
26683- fp >= (unsigned long)stack+THREAD_SIZE)
26684+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
26685 return 0;
26686 ip = *(u64 *)(fp+8);
26687 if (!in_sched_functions(ip))
26688diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
26689index 7461f50..1334029 100644
26690--- a/arch/x86/kernel/ptrace.c
26691+++ b/arch/x86/kernel/ptrace.c
26692@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
26693 {
26694 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
26695 unsigned long sp = (unsigned long)&regs->sp;
26696- struct thread_info *tinfo;
26697
26698- if (context == (sp & ~(THREAD_SIZE - 1)))
26699+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
26700 return sp;
26701
26702- tinfo = (struct thread_info *)context;
26703- if (tinfo->previous_esp)
26704- return tinfo->previous_esp;
26705+ sp = *(unsigned long *)context;
26706+ if (sp)
26707+ return sp;
26708
26709 return (unsigned long)regs;
26710 }
26711@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
26712 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
26713 {
26714 int i;
26715- int dr7 = 0;
26716+ unsigned long dr7 = 0;
26717 struct arch_hw_breakpoint *info;
26718
26719 for (i = 0; i < HBP_NUM; i++) {
26720@@ -822,7 +821,7 @@ long arch_ptrace(struct task_struct *child, long request,
26721 unsigned long addr, unsigned long data)
26722 {
26723 int ret;
26724- unsigned long __user *datap = (unsigned long __user *)data;
26725+ unsigned long __user *datap = (__force unsigned long __user *)data;
26726
26727 switch (request) {
26728 /* read the word at location addr in the USER area. */
26729@@ -907,14 +906,14 @@ long arch_ptrace(struct task_struct *child, long request,
26730 if ((int) addr < 0)
26731 return -EIO;
26732 ret = do_get_thread_area(child, addr,
26733- (struct user_desc __user *)data);
26734+ (__force struct user_desc __user *) data);
26735 break;
26736
26737 case PTRACE_SET_THREAD_AREA:
26738 if ((int) addr < 0)
26739 return -EIO;
26740 ret = do_set_thread_area(child, addr,
26741- (struct user_desc __user *)data, 0);
26742+ (__force struct user_desc __user *) data, 0);
26743 break;
26744 #endif
26745
26746@@ -1292,7 +1291,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
26747
26748 #ifdef CONFIG_X86_64
26749
26750-static struct user_regset x86_64_regsets[] __read_mostly = {
26751+static user_regset_no_const x86_64_regsets[] __read_only = {
26752 [REGSET_GENERAL] = {
26753 .core_note_type = NT_PRSTATUS,
26754 .n = sizeof(struct user_regs_struct) / sizeof(long),
26755@@ -1333,7 +1332,7 @@ static const struct user_regset_view user_x86_64_view = {
26756 #endif /* CONFIG_X86_64 */
26757
26758 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
26759-static struct user_regset x86_32_regsets[] __read_mostly = {
26760+static user_regset_no_const x86_32_regsets[] __read_only = {
26761 [REGSET_GENERAL] = {
26762 .core_note_type = NT_PRSTATUS,
26763 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
26764@@ -1386,7 +1385,7 @@ static const struct user_regset_view user_x86_32_view = {
26765 */
26766 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
26767
26768-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26769+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26770 {
26771 #ifdef CONFIG_X86_64
26772 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
26773@@ -1421,7 +1420,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
26774 memset(info, 0, sizeof(*info));
26775 info->si_signo = SIGTRAP;
26776 info->si_code = si_code;
26777- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
26778+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
26779 }
26780
26781 void user_single_step_siginfo(struct task_struct *tsk,
26782@@ -1450,6 +1449,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
26783 # define IS_IA32 0
26784 #endif
26785
26786+#ifdef CONFIG_GRKERNSEC_SETXID
26787+extern void gr_delayed_cred_worker(void);
26788+#endif
26789+
26790 /*
26791 * We must return the syscall number to actually look up in the table.
26792 * This can be -1L to skip running any syscall at all.
26793@@ -1460,6 +1463,11 @@ long syscall_trace_enter(struct pt_regs *regs)
26794
26795 user_exit();
26796
26797+#ifdef CONFIG_GRKERNSEC_SETXID
26798+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26799+ gr_delayed_cred_worker();
26800+#endif
26801+
26802 /*
26803 * If we stepped into a sysenter/syscall insn, it trapped in
26804 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
26805@@ -1515,6 +1523,11 @@ void syscall_trace_leave(struct pt_regs *regs)
26806 */
26807 user_exit();
26808
26809+#ifdef CONFIG_GRKERNSEC_SETXID
26810+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26811+ gr_delayed_cred_worker();
26812+#endif
26813+
26814 audit_syscall_exit(regs);
26815
26816 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
26817diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
26818index 2f355d2..e75ed0a 100644
26819--- a/arch/x86/kernel/pvclock.c
26820+++ b/arch/x86/kernel/pvclock.c
26821@@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
26822 reset_hung_task_detector();
26823 }
26824
26825-static atomic64_t last_value = ATOMIC64_INIT(0);
26826+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
26827
26828 void pvclock_resume(void)
26829 {
26830- atomic64_set(&last_value, 0);
26831+ atomic64_set_unchecked(&last_value, 0);
26832 }
26833
26834 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
26835@@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
26836 * updating at the same time, and one of them could be slightly behind,
26837 * making the assumption that last_value always go forward fail to hold.
26838 */
26839- last = atomic64_read(&last_value);
26840+ last = atomic64_read_unchecked(&last_value);
26841 do {
26842 if (ret < last)
26843 return last;
26844- last = atomic64_cmpxchg(&last_value, last, ret);
26845+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
26846 } while (unlikely(last != ret));
26847
26848 return ret;
26849diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
26850index c752cb4..866c432 100644
26851--- a/arch/x86/kernel/reboot.c
26852+++ b/arch/x86/kernel/reboot.c
26853@@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
26854
26855 void __noreturn machine_real_restart(unsigned int type)
26856 {
26857+
26858+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
26859+ struct desc_struct *gdt;
26860+#endif
26861+
26862 local_irq_disable();
26863
26864 /*
26865@@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
26866
26867 /* Jump to the identity-mapped low memory code */
26868 #ifdef CONFIG_X86_32
26869- asm volatile("jmpl *%0" : :
26870+
26871+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
26872+ gdt = get_cpu_gdt_table(smp_processor_id());
26873+ pax_open_kernel();
26874+#ifdef CONFIG_PAX_MEMORY_UDEREF
26875+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
26876+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
26877+ loadsegment(ds, __KERNEL_DS);
26878+ loadsegment(es, __KERNEL_DS);
26879+ loadsegment(ss, __KERNEL_DS);
26880+#endif
26881+#ifdef CONFIG_PAX_KERNEXEC
26882+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
26883+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
26884+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
26885+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
26886+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
26887+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
26888+#endif
26889+ pax_close_kernel();
26890+#endif
26891+
26892+ asm volatile("ljmpl *%0" : :
26893 "rm" (real_mode_header->machine_real_restart_asm),
26894 "a" (type));
26895 #else
26896@@ -470,7 +497,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
26897 * try to force a triple fault and then cycle between hitting the keyboard
26898 * controller and doing that
26899 */
26900-static void native_machine_emergency_restart(void)
26901+static void __noreturn native_machine_emergency_restart(void)
26902 {
26903 int i;
26904 int attempt = 0;
26905@@ -593,13 +620,13 @@ void native_machine_shutdown(void)
26906 #endif
26907 }
26908
26909-static void __machine_emergency_restart(int emergency)
26910+static void __noreturn __machine_emergency_restart(int emergency)
26911 {
26912 reboot_emergency = emergency;
26913 machine_ops.emergency_restart();
26914 }
26915
26916-static void native_machine_restart(char *__unused)
26917+static void __noreturn native_machine_restart(char *__unused)
26918 {
26919 pr_notice("machine restart\n");
26920
26921@@ -608,7 +635,7 @@ static void native_machine_restart(char *__unused)
26922 __machine_emergency_restart(0);
26923 }
26924
26925-static void native_machine_halt(void)
26926+static void __noreturn native_machine_halt(void)
26927 {
26928 /* Stop other cpus and apics */
26929 machine_shutdown();
26930@@ -618,7 +645,7 @@ static void native_machine_halt(void)
26931 stop_this_cpu(NULL);
26932 }
26933
26934-static void native_machine_power_off(void)
26935+static void __noreturn native_machine_power_off(void)
26936 {
26937 if (pm_power_off) {
26938 if (!reboot_force)
26939@@ -627,9 +654,10 @@ static void native_machine_power_off(void)
26940 }
26941 /* A fallback in case there is no PM info available */
26942 tboot_shutdown(TB_SHUTDOWN_HALT);
26943+ unreachable();
26944 }
26945
26946-struct machine_ops machine_ops = {
26947+struct machine_ops machine_ops __read_only = {
26948 .power_off = native_machine_power_off,
26949 .shutdown = native_machine_shutdown,
26950 .emergency_restart = native_machine_emergency_restart,
26951diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
26952index c8e41e9..64049ef 100644
26953--- a/arch/x86/kernel/reboot_fixups_32.c
26954+++ b/arch/x86/kernel/reboot_fixups_32.c
26955@@ -57,7 +57,7 @@ struct device_fixup {
26956 unsigned int vendor;
26957 unsigned int device;
26958 void (*reboot_fixup)(struct pci_dev *);
26959-};
26960+} __do_const;
26961
26962 /*
26963 * PCI ids solely used for fixups_table go here
26964diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
26965index 3fd2c69..a444264 100644
26966--- a/arch/x86/kernel/relocate_kernel_64.S
26967+++ b/arch/x86/kernel/relocate_kernel_64.S
26968@@ -96,8 +96,7 @@ relocate_kernel:
26969
26970 /* jump to identity mapped page */
26971 addq $(identity_mapped - relocate_kernel), %r8
26972- pushq %r8
26973- ret
26974+ jmp *%r8
26975
26976 identity_mapped:
26977 /* set return address to 0 if not preserving context */
26978diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
26979index ce72964..be8aea7 100644
26980--- a/arch/x86/kernel/setup.c
26981+++ b/arch/x86/kernel/setup.c
26982@@ -110,6 +110,7 @@
26983 #include <asm/mce.h>
26984 #include <asm/alternative.h>
26985 #include <asm/prom.h>
26986+#include <asm/boot.h>
26987
26988 /*
26989 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
26990@@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
26991 #endif
26992
26993
26994-#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
26995-__visible unsigned long mmu_cr4_features;
26996+#ifdef CONFIG_X86_64
26997+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
26998+#elif defined(CONFIG_X86_PAE)
26999+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
27000 #else
27001-__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
27002+__visible unsigned long mmu_cr4_features __read_only;
27003 #endif
27004
27005+void set_in_cr4(unsigned long mask)
27006+{
27007+ unsigned long cr4 = read_cr4();
27008+
27009+ if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
27010+ return;
27011+
27012+ pax_open_kernel();
27013+ mmu_cr4_features |= mask;
27014+ pax_close_kernel();
27015+
27016+ if (trampoline_cr4_features)
27017+ *trampoline_cr4_features = mmu_cr4_features;
27018+ cr4 |= mask;
27019+ write_cr4(cr4);
27020+}
27021+EXPORT_SYMBOL(set_in_cr4);
27022+
27023+void clear_in_cr4(unsigned long mask)
27024+{
27025+ unsigned long cr4 = read_cr4();
27026+
27027+ if (!(cr4 & mask) && cr4 == mmu_cr4_features)
27028+ return;
27029+
27030+ pax_open_kernel();
27031+ mmu_cr4_features &= ~mask;
27032+ pax_close_kernel();
27033+
27034+ if (trampoline_cr4_features)
27035+ *trampoline_cr4_features = mmu_cr4_features;
27036+ cr4 &= ~mask;
27037+ write_cr4(cr4);
27038+}
27039+EXPORT_SYMBOL(clear_in_cr4);
27040+
27041 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
27042 int bootloader_type, bootloader_version;
27043
27044@@ -772,7 +811,7 @@ static void __init trim_bios_range(void)
27045 * area (640->1Mb) as ram even though it is not.
27046 * take them out.
27047 */
27048- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
27049+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
27050
27051 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
27052 }
27053@@ -780,7 +819,7 @@ static void __init trim_bios_range(void)
27054 /* called before trim_bios_range() to spare extra sanitize */
27055 static void __init e820_add_kernel_range(void)
27056 {
27057- u64 start = __pa_symbol(_text);
27058+ u64 start = __pa_symbol(ktla_ktva(_text));
27059 u64 size = __pa_symbol(_end) - start;
27060
27061 /*
27062@@ -856,8 +895,12 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
27063
27064 void __init setup_arch(char **cmdline_p)
27065 {
27066+#ifdef CONFIG_X86_32
27067+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
27068+#else
27069 memblock_reserve(__pa_symbol(_text),
27070 (unsigned long)__bss_stop - (unsigned long)_text);
27071+#endif
27072
27073 early_reserve_initrd();
27074
27075@@ -947,14 +990,14 @@ void __init setup_arch(char **cmdline_p)
27076
27077 if (!boot_params.hdr.root_flags)
27078 root_mountflags &= ~MS_RDONLY;
27079- init_mm.start_code = (unsigned long) _text;
27080- init_mm.end_code = (unsigned long) _etext;
27081+ init_mm.start_code = ktla_ktva((unsigned long) _text);
27082+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
27083 init_mm.end_data = (unsigned long) _edata;
27084 init_mm.brk = _brk_end;
27085
27086- code_resource.start = __pa_symbol(_text);
27087- code_resource.end = __pa_symbol(_etext)-1;
27088- data_resource.start = __pa_symbol(_etext);
27089+ code_resource.start = __pa_symbol(ktla_ktva(_text));
27090+ code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
27091+ data_resource.start = __pa_symbol(_sdata);
27092 data_resource.end = __pa_symbol(_edata)-1;
27093 bss_resource.start = __pa_symbol(__bss_start);
27094 bss_resource.end = __pa_symbol(__bss_stop)-1;
27095diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
27096index 5cdff03..80fa283 100644
27097--- a/arch/x86/kernel/setup_percpu.c
27098+++ b/arch/x86/kernel/setup_percpu.c
27099@@ -21,19 +21,17 @@
27100 #include <asm/cpu.h>
27101 #include <asm/stackprotector.h>
27102
27103-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
27104+#ifdef CONFIG_SMP
27105+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
27106 EXPORT_PER_CPU_SYMBOL(cpu_number);
27107+#endif
27108
27109-#ifdef CONFIG_X86_64
27110 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
27111-#else
27112-#define BOOT_PERCPU_OFFSET 0
27113-#endif
27114
27115 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
27116 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
27117
27118-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
27119+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
27120 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
27121 };
27122 EXPORT_SYMBOL(__per_cpu_offset);
27123@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
27124 {
27125 #ifdef CONFIG_NEED_MULTIPLE_NODES
27126 pg_data_t *last = NULL;
27127- unsigned int cpu;
27128+ int cpu;
27129
27130 for_each_possible_cpu(cpu) {
27131 int node = early_cpu_to_node(cpu);
27132@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
27133 {
27134 #ifdef CONFIG_X86_32
27135 struct desc_struct gdt;
27136+ unsigned long base = per_cpu_offset(cpu);
27137
27138- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
27139- 0x2 | DESCTYPE_S, 0x8);
27140- gdt.s = 1;
27141+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
27142+ 0x83 | DESCTYPE_S, 0xC);
27143 write_gdt_entry(get_cpu_gdt_table(cpu),
27144 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
27145 #endif
27146@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
27147 /* alrighty, percpu areas up and running */
27148 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
27149 for_each_possible_cpu(cpu) {
27150+#ifdef CONFIG_CC_STACKPROTECTOR
27151+#ifdef CONFIG_X86_32
27152+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
27153+#endif
27154+#endif
27155 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
27156 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
27157 per_cpu(cpu_number, cpu) = cpu;
27158@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
27159 */
27160 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
27161 #endif
27162+#ifdef CONFIG_CC_STACKPROTECTOR
27163+#ifdef CONFIG_X86_32
27164+ if (!cpu)
27165+ per_cpu(stack_canary.canary, cpu) = canary;
27166+#endif
27167+#endif
27168 /*
27169 * Up to this point, the boot CPU has been using .init.data
27170 * area. Reload any changed state for the boot CPU.
27171diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
27172index 9e5de68..16c53cb 100644
27173--- a/arch/x86/kernel/signal.c
27174+++ b/arch/x86/kernel/signal.c
27175@@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
27176 * Align the stack pointer according to the i386 ABI,
27177 * i.e. so that on function entry ((sp + 4) & 15) == 0.
27178 */
27179- sp = ((sp + 4) & -16ul) - 4;
27180+ sp = ((sp - 12) & -16ul) - 4;
27181 #else /* !CONFIG_X86_32 */
27182 sp = round_down(sp, 16) - 8;
27183 #endif
27184@@ -298,9 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
27185 }
27186
27187 if (current->mm->context.vdso)
27188- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
27189+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
27190 else
27191- restorer = &frame->retcode;
27192+ restorer = (void __user *)&frame->retcode;
27193 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27194 restorer = ksig->ka.sa.sa_restorer;
27195
27196@@ -314,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
27197 * reasons and because gdb uses it as a signature to notice
27198 * signal handler stack frames.
27199 */
27200- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
27201+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
27202
27203 if (err)
27204 return -EFAULT;
27205@@ -361,7 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27206 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
27207
27208 /* Set up to return from userspace. */
27209- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
27210+ if (current->mm->context.vdso)
27211+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
27212+ else
27213+ restorer = (void __user *)&frame->retcode;
27214 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27215 restorer = ksig->ka.sa.sa_restorer;
27216 put_user_ex(restorer, &frame->pretcode);
27217@@ -373,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27218 * reasons and because gdb uses it as a signature to notice
27219 * signal handler stack frames.
27220 */
27221- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
27222+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
27223 } put_user_catch(err);
27224
27225 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
27226@@ -609,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27227 {
27228 int usig = signr_convert(ksig->sig);
27229 sigset_t *set = sigmask_to_save();
27230- compat_sigset_t *cset = (compat_sigset_t *) set;
27231+ sigset_t sigcopy;
27232+ compat_sigset_t *cset;
27233+
27234+ sigcopy = *set;
27235+
27236+ cset = (compat_sigset_t *) &sigcopy;
27237
27238 /* Set up the stack frame */
27239 if (is_ia32_frame()) {
27240@@ -620,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27241 } else if (is_x32_frame()) {
27242 return x32_setup_rt_frame(ksig, cset, regs);
27243 } else {
27244- return __setup_rt_frame(ksig->sig, ksig, set, regs);
27245+ return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
27246 }
27247 }
27248
27249diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
27250index 7c3a5a6..f0a8961 100644
27251--- a/arch/x86/kernel/smp.c
27252+++ b/arch/x86/kernel/smp.c
27253@@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
27254
27255 __setup("nonmi_ipi", nonmi_ipi_setup);
27256
27257-struct smp_ops smp_ops = {
27258+struct smp_ops smp_ops __read_only = {
27259 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
27260 .smp_prepare_cpus = native_smp_prepare_cpus,
27261 .smp_cpus_done = native_smp_cpus_done,
27262diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
27263index a32da80..30c97f1 100644
27264--- a/arch/x86/kernel/smpboot.c
27265+++ b/arch/x86/kernel/smpboot.c
27266@@ -229,14 +229,18 @@ static void notrace start_secondary(void *unused)
27267
27268 enable_start_cpu0 = 0;
27269
27270-#ifdef CONFIG_X86_32
27271- /* switch away from the initial page table */
27272- load_cr3(swapper_pg_dir);
27273- __flush_tlb_all();
27274-#endif
27275-
27276 /* otherwise gcc will move up smp_processor_id before the cpu_init */
27277 barrier();
27278+
27279+ /* switch away from the initial page table */
27280+#ifdef CONFIG_PAX_PER_CPU_PGD
27281+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
27282+ __flush_tlb_all();
27283+#elif defined(CONFIG_X86_32)
27284+ load_cr3(swapper_pg_dir);
27285+ __flush_tlb_all();
27286+#endif
27287+
27288 /*
27289 * Check TSC synchronization with the BP:
27290 */
27291@@ -749,8 +753,9 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27292 alternatives_enable_smp();
27293
27294 idle->thread.sp = (unsigned long) (((struct pt_regs *)
27295- (THREAD_SIZE + task_stack_page(idle))) - 1);
27296+ (THREAD_SIZE - 16 + task_stack_page(idle))) - 1);
27297 per_cpu(current_task, cpu) = idle;
27298+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
27299
27300 #ifdef CONFIG_X86_32
27301 /* Stack for startup_32 can be just as for start_secondary onwards */
27302@@ -758,11 +763,13 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27303 #else
27304 clear_tsk_thread_flag(idle, TIF_FORK);
27305 initial_gs = per_cpu_offset(cpu);
27306- per_cpu(kernel_stack, cpu) =
27307- (unsigned long)task_stack_page(idle) -
27308- KERNEL_STACK_OFFSET + THREAD_SIZE;
27309+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27310 #endif
27311+
27312+ pax_open_kernel();
27313 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
27314+ pax_close_kernel();
27315+
27316 initial_code = (unsigned long)start_secondary;
27317 stack_start = idle->thread.sp;
27318
27319@@ -911,6 +918,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
27320 /* the FPU context is blank, nobody can own it */
27321 __cpu_disable_lazy_restore(cpu);
27322
27323+#ifdef CONFIG_PAX_PER_CPU_PGD
27324+ clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
27325+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27326+ KERNEL_PGD_PTRS);
27327+ clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
27328+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27329+ KERNEL_PGD_PTRS);
27330+#endif
27331+
27332 err = do_boot_cpu(apicid, cpu, tidle);
27333 if (err) {
27334 pr_debug("do_boot_cpu failed %d\n", err);
27335diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
27336index 9b4d51d..5d28b58 100644
27337--- a/arch/x86/kernel/step.c
27338+++ b/arch/x86/kernel/step.c
27339@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27340 struct desc_struct *desc;
27341 unsigned long base;
27342
27343- seg &= ~7UL;
27344+ seg >>= 3;
27345
27346 mutex_lock(&child->mm->context.lock);
27347- if (unlikely((seg >> 3) >= child->mm->context.size))
27348+ if (unlikely(seg >= child->mm->context.size))
27349 addr = -1L; /* bogus selector, access would fault */
27350 else {
27351 desc = child->mm->context.ldt + seg;
27352@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27353 addr += base;
27354 }
27355 mutex_unlock(&child->mm->context.lock);
27356- }
27357+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
27358+ addr = ktla_ktva(addr);
27359
27360 return addr;
27361 }
27362@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
27363 unsigned char opcode[15];
27364 unsigned long addr = convert_ip_to_linear(child, regs);
27365
27366+ if (addr == -EINVAL)
27367+ return 0;
27368+
27369 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
27370 for (i = 0; i < copied; i++) {
27371 switch (opcode[i]) {
27372diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
27373new file mode 100644
27374index 0000000..5877189
27375--- /dev/null
27376+++ b/arch/x86/kernel/sys_i386_32.c
27377@@ -0,0 +1,189 @@
27378+/*
27379+ * This file contains various random system calls that
27380+ * have a non-standard calling sequence on the Linux/i386
27381+ * platform.
27382+ */
27383+
27384+#include <linux/errno.h>
27385+#include <linux/sched.h>
27386+#include <linux/mm.h>
27387+#include <linux/fs.h>
27388+#include <linux/smp.h>
27389+#include <linux/sem.h>
27390+#include <linux/msg.h>
27391+#include <linux/shm.h>
27392+#include <linux/stat.h>
27393+#include <linux/syscalls.h>
27394+#include <linux/mman.h>
27395+#include <linux/file.h>
27396+#include <linux/utsname.h>
27397+#include <linux/ipc.h>
27398+#include <linux/elf.h>
27399+
27400+#include <linux/uaccess.h>
27401+#include <linux/unistd.h>
27402+
27403+#include <asm/syscalls.h>
27404+
27405+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
27406+{
27407+ unsigned long pax_task_size = TASK_SIZE;
27408+
27409+#ifdef CONFIG_PAX_SEGMEXEC
27410+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
27411+ pax_task_size = SEGMEXEC_TASK_SIZE;
27412+#endif
27413+
27414+ if (flags & MAP_FIXED)
27415+ if (len > pax_task_size || addr > pax_task_size - len)
27416+ return -EINVAL;
27417+
27418+ return 0;
27419+}
27420+
27421+/*
27422+ * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
27423+ */
27424+static unsigned long get_align_mask(void)
27425+{
27426+ if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
27427+ return 0;
27428+
27429+ if (!(current->flags & PF_RANDOMIZE))
27430+ return 0;
27431+
27432+ return va_align.mask;
27433+}
27434+
27435+unsigned long
27436+arch_get_unmapped_area(struct file *filp, unsigned long addr,
27437+ unsigned long len, unsigned long pgoff, unsigned long flags)
27438+{
27439+ struct mm_struct *mm = current->mm;
27440+ struct vm_area_struct *vma;
27441+ unsigned long pax_task_size = TASK_SIZE;
27442+ struct vm_unmapped_area_info info;
27443+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27444+
27445+#ifdef CONFIG_PAX_SEGMEXEC
27446+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27447+ pax_task_size = SEGMEXEC_TASK_SIZE;
27448+#endif
27449+
27450+ pax_task_size -= PAGE_SIZE;
27451+
27452+ if (len > pax_task_size)
27453+ return -ENOMEM;
27454+
27455+ if (flags & MAP_FIXED)
27456+ return addr;
27457+
27458+#ifdef CONFIG_PAX_RANDMMAP
27459+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27460+#endif
27461+
27462+ if (addr) {
27463+ addr = PAGE_ALIGN(addr);
27464+ if (pax_task_size - len >= addr) {
27465+ vma = find_vma(mm, addr);
27466+ if (check_heap_stack_gap(vma, addr, len, offset))
27467+ return addr;
27468+ }
27469+ }
27470+
27471+ info.flags = 0;
27472+ info.length = len;
27473+ info.align_mask = filp ? get_align_mask() : 0;
27474+ info.align_offset = pgoff << PAGE_SHIFT;
27475+ info.threadstack_offset = offset;
27476+
27477+#ifdef CONFIG_PAX_PAGEEXEC
27478+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
27479+ info.low_limit = 0x00110000UL;
27480+ info.high_limit = mm->start_code;
27481+
27482+#ifdef CONFIG_PAX_RANDMMAP
27483+ if (mm->pax_flags & MF_PAX_RANDMMAP)
27484+ info.low_limit += mm->delta_mmap & 0x03FFF000UL;
27485+#endif
27486+
27487+ if (info.low_limit < info.high_limit) {
27488+ addr = vm_unmapped_area(&info);
27489+ if (!IS_ERR_VALUE(addr))
27490+ return addr;
27491+ }
27492+ } else
27493+#endif
27494+
27495+ info.low_limit = mm->mmap_base;
27496+ info.high_limit = pax_task_size;
27497+
27498+ return vm_unmapped_area(&info);
27499+}
27500+
27501+unsigned long
27502+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27503+ const unsigned long len, const unsigned long pgoff,
27504+ const unsigned long flags)
27505+{
27506+ struct vm_area_struct *vma;
27507+ struct mm_struct *mm = current->mm;
27508+ unsigned long addr = addr0, pax_task_size = TASK_SIZE;
27509+ struct vm_unmapped_area_info info;
27510+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27511+
27512+#ifdef CONFIG_PAX_SEGMEXEC
27513+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27514+ pax_task_size = SEGMEXEC_TASK_SIZE;
27515+#endif
27516+
27517+ pax_task_size -= PAGE_SIZE;
27518+
27519+ /* requested length too big for entire address space */
27520+ if (len > pax_task_size)
27521+ return -ENOMEM;
27522+
27523+ if (flags & MAP_FIXED)
27524+ return addr;
27525+
27526+#ifdef CONFIG_PAX_PAGEEXEC
27527+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
27528+ goto bottomup;
27529+#endif
27530+
27531+#ifdef CONFIG_PAX_RANDMMAP
27532+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27533+#endif
27534+
27535+ /* requesting a specific address */
27536+ if (addr) {
27537+ addr = PAGE_ALIGN(addr);
27538+ if (pax_task_size - len >= addr) {
27539+ vma = find_vma(mm, addr);
27540+ if (check_heap_stack_gap(vma, addr, len, offset))
27541+ return addr;
27542+ }
27543+ }
27544+
27545+ info.flags = VM_UNMAPPED_AREA_TOPDOWN;
27546+ info.length = len;
27547+ info.low_limit = PAGE_SIZE;
27548+ info.high_limit = mm->mmap_base;
27549+ info.align_mask = filp ? get_align_mask() : 0;
27550+ info.align_offset = pgoff << PAGE_SHIFT;
27551+ info.threadstack_offset = offset;
27552+
27553+ addr = vm_unmapped_area(&info);
27554+ if (!(addr & ~PAGE_MASK))
27555+ return addr;
27556+ VM_BUG_ON(addr != -ENOMEM);
27557+
27558+bottomup:
27559+ /*
27560+ * A failed mmap() very likely causes application failure,
27561+ * so fall back to the bottom-up function here. This scenario
27562+ * can happen with large stack limits and large mmap()
27563+ * allocations.
27564+ */
27565+ return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
27566+}
27567diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
27568index 30277e2..5664a29 100644
27569--- a/arch/x86/kernel/sys_x86_64.c
27570+++ b/arch/x86/kernel/sys_x86_64.c
27571@@ -81,8 +81,8 @@ out:
27572 return error;
27573 }
27574
27575-static void find_start_end(unsigned long flags, unsigned long *begin,
27576- unsigned long *end)
27577+static void find_start_end(struct mm_struct *mm, unsigned long flags,
27578+ unsigned long *begin, unsigned long *end)
27579 {
27580 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
27581 unsigned long new_begin;
27582@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
27583 *begin = new_begin;
27584 }
27585 } else {
27586- *begin = current->mm->mmap_legacy_base;
27587+ *begin = mm->mmap_legacy_base;
27588 *end = TASK_SIZE;
27589 }
27590 }
27591@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27592 struct vm_area_struct *vma;
27593 struct vm_unmapped_area_info info;
27594 unsigned long begin, end;
27595+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27596
27597 if (flags & MAP_FIXED)
27598 return addr;
27599
27600- find_start_end(flags, &begin, &end);
27601+ find_start_end(mm, flags, &begin, &end);
27602
27603 if (len > end)
27604 return -ENOMEM;
27605
27606+#ifdef CONFIG_PAX_RANDMMAP
27607+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27608+#endif
27609+
27610 if (addr) {
27611 addr = PAGE_ALIGN(addr);
27612 vma = find_vma(mm, addr);
27613- if (end - len >= addr &&
27614- (!vma || addr + len <= vma->vm_start))
27615+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27616 return addr;
27617 }
27618
27619@@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27620 info.high_limit = end;
27621 info.align_mask = filp ? get_align_mask() : 0;
27622 info.align_offset = pgoff << PAGE_SHIFT;
27623+ info.threadstack_offset = offset;
27624 return vm_unmapped_area(&info);
27625 }
27626
27627@@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27628 struct mm_struct *mm = current->mm;
27629 unsigned long addr = addr0;
27630 struct vm_unmapped_area_info info;
27631+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27632
27633 /* requested length too big for entire address space */
27634 if (len > TASK_SIZE)
27635@@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27636 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
27637 goto bottomup;
27638
27639+#ifdef CONFIG_PAX_RANDMMAP
27640+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27641+#endif
27642+
27643 /* requesting a specific address */
27644 if (addr) {
27645 addr = PAGE_ALIGN(addr);
27646 vma = find_vma(mm, addr);
27647- if (TASK_SIZE - len >= addr &&
27648- (!vma || addr + len <= vma->vm_start))
27649+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27650 return addr;
27651 }
27652
27653@@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27654 info.high_limit = mm->mmap_base;
27655 info.align_mask = filp ? get_align_mask() : 0;
27656 info.align_offset = pgoff << PAGE_SHIFT;
27657+ info.threadstack_offset = offset;
27658 addr = vm_unmapped_area(&info);
27659 if (!(addr & ~PAGE_MASK))
27660 return addr;
27661diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
27662index 91a4496..bb87552 100644
27663--- a/arch/x86/kernel/tboot.c
27664+++ b/arch/x86/kernel/tboot.c
27665@@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
27666
27667 void tboot_shutdown(u32 shutdown_type)
27668 {
27669- void (*shutdown)(void);
27670+ void (* __noreturn shutdown)(void);
27671
27672 if (!tboot_enabled())
27673 return;
27674@@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
27675
27676 switch_to_tboot_pt();
27677
27678- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
27679+ shutdown = (void *)(unsigned long)tboot->shutdown_entry;
27680 shutdown();
27681
27682 /* should not reach here */
27683@@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
27684 return -ENODEV;
27685 }
27686
27687-static atomic_t ap_wfs_count;
27688+static atomic_unchecked_t ap_wfs_count;
27689
27690 static int tboot_wait_for_aps(int num_aps)
27691 {
27692@@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
27693 {
27694 switch (action) {
27695 case CPU_DYING:
27696- atomic_inc(&ap_wfs_count);
27697+ atomic_inc_unchecked(&ap_wfs_count);
27698 if (num_online_cpus() == 1)
27699- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
27700+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
27701 return NOTIFY_BAD;
27702 break;
27703 }
27704@@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
27705
27706 tboot_create_trampoline();
27707
27708- atomic_set(&ap_wfs_count, 0);
27709+ atomic_set_unchecked(&ap_wfs_count, 0);
27710 register_hotcpu_notifier(&tboot_cpu_notifier);
27711
27712 #ifdef CONFIG_DEBUG_FS
27713diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
27714index 24d3c91..d06b473 100644
27715--- a/arch/x86/kernel/time.c
27716+++ b/arch/x86/kernel/time.c
27717@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
27718 {
27719 unsigned long pc = instruction_pointer(regs);
27720
27721- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
27722+ if (!user_mode(regs) && in_lock_functions(pc)) {
27723 #ifdef CONFIG_FRAME_POINTER
27724- return *(unsigned long *)(regs->bp + sizeof(long));
27725+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
27726 #else
27727 unsigned long *sp =
27728 (unsigned long *)kernel_stack_pointer(regs);
27729@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
27730 * or above a saved flags. Eflags has bits 22-31 zero,
27731 * kernel addresses don't.
27732 */
27733+
27734+#ifdef CONFIG_PAX_KERNEXEC
27735+ return ktla_ktva(sp[0]);
27736+#else
27737 if (sp[0] >> 22)
27738 return sp[0];
27739 if (sp[1] >> 22)
27740 return sp[1];
27741 #endif
27742+
27743+#endif
27744 }
27745 return pc;
27746 }
27747diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
27748index f7fec09..9991981 100644
27749--- a/arch/x86/kernel/tls.c
27750+++ b/arch/x86/kernel/tls.c
27751@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
27752 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
27753 return -EINVAL;
27754
27755+#ifdef CONFIG_PAX_SEGMEXEC
27756+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
27757+ return -EINVAL;
27758+#endif
27759+
27760 set_tls_desc(p, idx, &info, 1);
27761
27762 return 0;
27763@@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
27764
27765 if (kbuf)
27766 info = kbuf;
27767- else if (__copy_from_user(infobuf, ubuf, count))
27768+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
27769 return -EFAULT;
27770 else
27771 info = infobuf;
27772diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
27773index 1c113db..287b42e 100644
27774--- a/arch/x86/kernel/tracepoint.c
27775+++ b/arch/x86/kernel/tracepoint.c
27776@@ -9,11 +9,11 @@
27777 #include <linux/atomic.h>
27778
27779 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
27780-struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27781+const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27782 (unsigned long) trace_idt_table };
27783
27784 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27785-gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
27786+gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
27787
27788 static int trace_irq_vector_refcount;
27789 static DEFINE_MUTEX(irq_vector_mutex);
27790diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
27791index 57409f6..e2c17e1 100644
27792--- a/arch/x86/kernel/traps.c
27793+++ b/arch/x86/kernel/traps.c
27794@@ -66,7 +66,7 @@
27795 #include <asm/proto.h>
27796
27797 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27798-gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
27799+gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
27800 #else
27801 #include <asm/processor-flags.h>
27802 #include <asm/setup.h>
27803@@ -75,7 +75,7 @@ asmlinkage int system_call(void);
27804 #endif
27805
27806 /* Must be page-aligned because the real IDT is used in a fixmap. */
27807-gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
27808+gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
27809
27810 DECLARE_BITMAP(used_vectors, NR_VECTORS);
27811 EXPORT_SYMBOL_GPL(used_vectors);
27812@@ -107,11 +107,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
27813 }
27814
27815 static int __kprobes
27816-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27817+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
27818 struct pt_regs *regs, long error_code)
27819 {
27820 #ifdef CONFIG_X86_32
27821- if (regs->flags & X86_VM_MASK) {
27822+ if (v8086_mode(regs)) {
27823 /*
27824 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
27825 * On nmi (interrupt 2), do_trap should not be called.
27826@@ -124,12 +124,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27827 return -1;
27828 }
27829 #endif
27830- if (!user_mode(regs)) {
27831+ if (!user_mode_novm(regs)) {
27832 if (!fixup_exception(regs)) {
27833 tsk->thread.error_code = error_code;
27834 tsk->thread.trap_nr = trapnr;
27835+
27836+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27837+ if (trapnr == X86_TRAP_SS && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
27838+ str = "PAX: suspicious stack segment fault";
27839+#endif
27840+
27841 die(str, regs, error_code);
27842 }
27843+
27844+#ifdef CONFIG_PAX_REFCOUNT
27845+ if (trapnr == X86_TRAP_OF)
27846+ pax_report_refcount_overflow(regs);
27847+#endif
27848+
27849 return 0;
27850 }
27851
27852@@ -137,7 +149,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27853 }
27854
27855 static void __kprobes
27856-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27857+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
27858 long error_code, siginfo_t *info)
27859 {
27860 struct task_struct *tsk = current;
27861@@ -161,7 +173,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27862 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
27863 printk_ratelimit()) {
27864 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
27865- tsk->comm, tsk->pid, str,
27866+ tsk->comm, task_pid_nr(tsk), str,
27867 regs->ip, regs->sp, error_code);
27868 print_vma_addr(" in ", regs->ip);
27869 pr_cont("\n");
27870@@ -273,7 +285,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
27871 conditional_sti(regs);
27872
27873 #ifdef CONFIG_X86_32
27874- if (regs->flags & X86_VM_MASK) {
27875+ if (v8086_mode(regs)) {
27876 local_irq_enable();
27877 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
27878 goto exit;
27879@@ -281,18 +293,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
27880 #endif
27881
27882 tsk = current;
27883- if (!user_mode(regs)) {
27884+ if (!user_mode_novm(regs)) {
27885 if (fixup_exception(regs))
27886 goto exit;
27887
27888 tsk->thread.error_code = error_code;
27889 tsk->thread.trap_nr = X86_TRAP_GP;
27890 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
27891- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
27892+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
27893+
27894+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27895+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
27896+ die("PAX: suspicious general protection fault", regs, error_code);
27897+ else
27898+#endif
27899+
27900 die("general protection fault", regs, error_code);
27901+ }
27902 goto exit;
27903 }
27904
27905+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27906+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
27907+ struct mm_struct *mm = tsk->mm;
27908+ unsigned long limit;
27909+
27910+ down_write(&mm->mmap_sem);
27911+ limit = mm->context.user_cs_limit;
27912+ if (limit < TASK_SIZE) {
27913+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
27914+ up_write(&mm->mmap_sem);
27915+ return;
27916+ }
27917+ up_write(&mm->mmap_sem);
27918+ }
27919+#endif
27920+
27921 tsk->thread.error_code = error_code;
27922 tsk->thread.trap_nr = X86_TRAP_GP;
27923
27924@@ -453,7 +489,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27925 /* It's safe to allow irq's after DR6 has been saved */
27926 preempt_conditional_sti(regs);
27927
27928- if (regs->flags & X86_VM_MASK) {
27929+ if (v8086_mode(regs)) {
27930 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
27931 X86_TRAP_DB);
27932 preempt_conditional_cli(regs);
27933@@ -468,7 +504,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27934 * We already checked v86 mode above, so we can check for kernel mode
27935 * by just checking the CPL of CS.
27936 */
27937- if ((dr6 & DR_STEP) && !user_mode(regs)) {
27938+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
27939 tsk->thread.debugreg6 &= ~DR_STEP;
27940 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
27941 regs->flags &= ~X86_EFLAGS_TF;
27942@@ -500,7 +536,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
27943 return;
27944 conditional_sti(regs);
27945
27946- if (!user_mode_vm(regs))
27947+ if (!user_mode(regs))
27948 {
27949 if (!fixup_exception(regs)) {
27950 task->thread.error_code = error_code;
27951diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
27952index cfbe99f..a6e8fa7 100644
27953--- a/arch/x86/kernel/tsc.c
27954+++ b/arch/x86/kernel/tsc.c
27955@@ -150,7 +150,7 @@ static void cyc2ns_write_end(int cpu, struct cyc2ns_data *data)
27956 */
27957 smp_wmb();
27958
27959- ACCESS_ONCE(c2n->head) = data;
27960+ ACCESS_ONCE_RW(c2n->head) = data;
27961 }
27962
27963 /*
27964diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
27965index 2ed8459..7cf329f 100644
27966--- a/arch/x86/kernel/uprobes.c
27967+++ b/arch/x86/kernel/uprobes.c
27968@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
27969 int ret = NOTIFY_DONE;
27970
27971 /* We are only interested in userspace traps */
27972- if (regs && !user_mode_vm(regs))
27973+ if (regs && !user_mode(regs))
27974 return NOTIFY_DONE;
27975
27976 switch (val) {
27977@@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
27978
27979 if (ncopied != rasize) {
27980 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
27981- "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
27982+ "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
27983
27984 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
27985 }
27986diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
27987index b9242ba..50c5edd 100644
27988--- a/arch/x86/kernel/verify_cpu.S
27989+++ b/arch/x86/kernel/verify_cpu.S
27990@@ -20,6 +20,7 @@
27991 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
27992 * arch/x86/kernel/trampoline_64.S: secondary processor verification
27993 * arch/x86/kernel/head_32.S: processor startup
27994+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
27995 *
27996 * verify_cpu, returns the status of longmode and SSE in register %eax.
27997 * 0: Success 1: Failure
27998diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
27999index e8edcf5..27f9344 100644
28000--- a/arch/x86/kernel/vm86_32.c
28001+++ b/arch/x86/kernel/vm86_32.c
28002@@ -44,6 +44,7 @@
28003 #include <linux/ptrace.h>
28004 #include <linux/audit.h>
28005 #include <linux/stddef.h>
28006+#include <linux/grsecurity.h>
28007
28008 #include <asm/uaccess.h>
28009 #include <asm/io.h>
28010@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
28011 do_exit(SIGSEGV);
28012 }
28013
28014- tss = &per_cpu(init_tss, get_cpu());
28015+ tss = init_tss + get_cpu();
28016 current->thread.sp0 = current->thread.saved_sp0;
28017 current->thread.sysenter_cs = __KERNEL_CS;
28018 load_sp0(tss, &current->thread);
28019@@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
28020
28021 if (tsk->thread.saved_sp0)
28022 return -EPERM;
28023+
28024+#ifdef CONFIG_GRKERNSEC_VM86
28025+ if (!capable(CAP_SYS_RAWIO)) {
28026+ gr_handle_vm86();
28027+ return -EPERM;
28028+ }
28029+#endif
28030+
28031 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
28032 offsetof(struct kernel_vm86_struct, vm86plus) -
28033 sizeof(info.regs));
28034@@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
28035 int tmp;
28036 struct vm86plus_struct __user *v86;
28037
28038+#ifdef CONFIG_GRKERNSEC_VM86
28039+ if (!capable(CAP_SYS_RAWIO)) {
28040+ gr_handle_vm86();
28041+ return -EPERM;
28042+ }
28043+#endif
28044+
28045 tsk = current;
28046 switch (cmd) {
28047 case VM86_REQUEST_IRQ:
28048@@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
28049 tsk->thread.saved_fs = info->regs32->fs;
28050 tsk->thread.saved_gs = get_user_gs(info->regs32);
28051
28052- tss = &per_cpu(init_tss, get_cpu());
28053+ tss = init_tss + get_cpu();
28054 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
28055 if (cpu_has_sep)
28056 tsk->thread.sysenter_cs = 0;
28057@@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
28058 goto cannot_handle;
28059 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
28060 goto cannot_handle;
28061- intr_ptr = (unsigned long __user *) (i << 2);
28062+ intr_ptr = (__force unsigned long __user *) (i << 2);
28063 if (get_user(segoffs, intr_ptr))
28064 goto cannot_handle;
28065 if ((segoffs >> 16) == BIOSSEG)
28066diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
28067index da6b35a..977e9cf 100644
28068--- a/arch/x86/kernel/vmlinux.lds.S
28069+++ b/arch/x86/kernel/vmlinux.lds.S
28070@@ -26,6 +26,13 @@
28071 #include <asm/page_types.h>
28072 #include <asm/cache.h>
28073 #include <asm/boot.h>
28074+#include <asm/segment.h>
28075+
28076+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28077+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
28078+#else
28079+#define __KERNEL_TEXT_OFFSET 0
28080+#endif
28081
28082 #undef i386 /* in case the preprocessor is a 32bit one */
28083
28084@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
28085
28086 PHDRS {
28087 text PT_LOAD FLAGS(5); /* R_E */
28088+#ifdef CONFIG_X86_32
28089+ module PT_LOAD FLAGS(5); /* R_E */
28090+#endif
28091+#ifdef CONFIG_XEN
28092+ rodata PT_LOAD FLAGS(5); /* R_E */
28093+#else
28094+ rodata PT_LOAD FLAGS(4); /* R__ */
28095+#endif
28096 data PT_LOAD FLAGS(6); /* RW_ */
28097-#ifdef CONFIG_X86_64
28098+ init.begin PT_LOAD FLAGS(6); /* RW_ */
28099 #ifdef CONFIG_SMP
28100 percpu PT_LOAD FLAGS(6); /* RW_ */
28101 #endif
28102+ text.init PT_LOAD FLAGS(5); /* R_E */
28103+ text.exit PT_LOAD FLAGS(5); /* R_E */
28104 init PT_LOAD FLAGS(7); /* RWE */
28105-#endif
28106 note PT_NOTE FLAGS(0); /* ___ */
28107 }
28108
28109 SECTIONS
28110 {
28111 #ifdef CONFIG_X86_32
28112- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
28113- phys_startup_32 = startup_32 - LOAD_OFFSET;
28114+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
28115 #else
28116- . = __START_KERNEL;
28117- phys_startup_64 = startup_64 - LOAD_OFFSET;
28118+ . = __START_KERNEL;
28119 #endif
28120
28121 /* Text and read-only data */
28122- .text : AT(ADDR(.text) - LOAD_OFFSET) {
28123- _text = .;
28124+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28125 /* bootstrapping code */
28126+#ifdef CONFIG_X86_32
28127+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28128+#else
28129+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28130+#endif
28131+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28132+ _text = .;
28133 HEAD_TEXT
28134 . = ALIGN(8);
28135 _stext = .;
28136@@ -104,13 +124,47 @@ SECTIONS
28137 IRQENTRY_TEXT
28138 *(.fixup)
28139 *(.gnu.warning)
28140- /* End of text section */
28141- _etext = .;
28142 } :text = 0x9090
28143
28144- NOTES :text :note
28145+ . += __KERNEL_TEXT_OFFSET;
28146
28147- EXCEPTION_TABLE(16) :text = 0x9090
28148+#ifdef CONFIG_X86_32
28149+ . = ALIGN(PAGE_SIZE);
28150+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
28151+
28152+#ifdef CONFIG_PAX_KERNEXEC
28153+ MODULES_EXEC_VADDR = .;
28154+ BYTE(0)
28155+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
28156+ . = ALIGN(HPAGE_SIZE) - 1;
28157+ MODULES_EXEC_END = .;
28158+#endif
28159+
28160+ } :module
28161+#endif
28162+
28163+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
28164+ /* End of text section */
28165+ BYTE(0)
28166+ _etext = . - __KERNEL_TEXT_OFFSET;
28167+ }
28168+
28169+#ifdef CONFIG_X86_32
28170+ . = ALIGN(PAGE_SIZE);
28171+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
28172+ . = ALIGN(PAGE_SIZE);
28173+ *(.empty_zero_page)
28174+ *(.initial_pg_fixmap)
28175+ *(.initial_pg_pmd)
28176+ *(.initial_page_table)
28177+ *(.swapper_pg_dir)
28178+ } :rodata
28179+#endif
28180+
28181+ . = ALIGN(PAGE_SIZE);
28182+ NOTES :rodata :note
28183+
28184+ EXCEPTION_TABLE(16) :rodata
28185
28186 #if defined(CONFIG_DEBUG_RODATA)
28187 /* .text should occupy whole number of pages */
28188@@ -122,16 +176,20 @@ SECTIONS
28189
28190 /* Data */
28191 .data : AT(ADDR(.data) - LOAD_OFFSET) {
28192+
28193+#ifdef CONFIG_PAX_KERNEXEC
28194+ . = ALIGN(HPAGE_SIZE);
28195+#else
28196+ . = ALIGN(PAGE_SIZE);
28197+#endif
28198+
28199 /* Start of data section */
28200 _sdata = .;
28201
28202 /* init_task */
28203 INIT_TASK_DATA(THREAD_SIZE)
28204
28205-#ifdef CONFIG_X86_32
28206- /* 32 bit has nosave before _edata */
28207 NOSAVE_DATA
28208-#endif
28209
28210 PAGE_ALIGNED_DATA(PAGE_SIZE)
28211
28212@@ -172,12 +230,19 @@ SECTIONS
28213 #endif /* CONFIG_X86_64 */
28214
28215 /* Init code and data - will be freed after init */
28216- . = ALIGN(PAGE_SIZE);
28217 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
28218+ BYTE(0)
28219+
28220+#ifdef CONFIG_PAX_KERNEXEC
28221+ . = ALIGN(HPAGE_SIZE);
28222+#else
28223+ . = ALIGN(PAGE_SIZE);
28224+#endif
28225+
28226 __init_begin = .; /* paired with __init_end */
28227- }
28228+ } :init.begin
28229
28230-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
28231+#ifdef CONFIG_SMP
28232 /*
28233 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
28234 * output PHDR, so the next output section - .init.text - should
28235@@ -186,12 +251,27 @@ SECTIONS
28236 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
28237 #endif
28238
28239- INIT_TEXT_SECTION(PAGE_SIZE)
28240-#ifdef CONFIG_X86_64
28241- :init
28242-#endif
28243+ . = ALIGN(PAGE_SIZE);
28244+ init_begin = .;
28245+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
28246+ VMLINUX_SYMBOL(_sinittext) = .;
28247+ INIT_TEXT
28248+ VMLINUX_SYMBOL(_einittext) = .;
28249+ . = ALIGN(PAGE_SIZE);
28250+ } :text.init
28251
28252- INIT_DATA_SECTION(16)
28253+ /*
28254+ * .exit.text is discard at runtime, not link time, to deal with
28255+ * references from .altinstructions and .eh_frame
28256+ */
28257+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28258+ EXIT_TEXT
28259+ . = ALIGN(16);
28260+ } :text.exit
28261+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
28262+
28263+ . = ALIGN(PAGE_SIZE);
28264+ INIT_DATA_SECTION(16) :init
28265
28266 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
28267 __x86_cpu_dev_start = .;
28268@@ -262,19 +342,12 @@ SECTIONS
28269 }
28270
28271 . = ALIGN(8);
28272- /*
28273- * .exit.text is discard at runtime, not link time, to deal with
28274- * references from .altinstructions and .eh_frame
28275- */
28276- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
28277- EXIT_TEXT
28278- }
28279
28280 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
28281 EXIT_DATA
28282 }
28283
28284-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
28285+#ifndef CONFIG_SMP
28286 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
28287 #endif
28288
28289@@ -293,16 +366,10 @@ SECTIONS
28290 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
28291 __smp_locks = .;
28292 *(.smp_locks)
28293- . = ALIGN(PAGE_SIZE);
28294 __smp_locks_end = .;
28295+ . = ALIGN(PAGE_SIZE);
28296 }
28297
28298-#ifdef CONFIG_X86_64
28299- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
28300- NOSAVE_DATA
28301- }
28302-#endif
28303-
28304 /* BSS */
28305 . = ALIGN(PAGE_SIZE);
28306 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
28307@@ -318,6 +385,7 @@ SECTIONS
28308 __brk_base = .;
28309 . += 64 * 1024; /* 64k alignment slop space */
28310 *(.brk_reservation) /* areas brk users have reserved */
28311+ . = ALIGN(HPAGE_SIZE);
28312 __brk_limit = .;
28313 }
28314
28315@@ -344,13 +412,12 @@ SECTIONS
28316 * for the boot processor.
28317 */
28318 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
28319-INIT_PER_CPU(gdt_page);
28320 INIT_PER_CPU(irq_stack_union);
28321
28322 /*
28323 * Build-time check on the image size:
28324 */
28325-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
28326+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
28327 "kernel image bigger than KERNEL_IMAGE_SIZE");
28328
28329 #ifdef CONFIG_SMP
28330diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
28331index 1f96f93..6f29be7 100644
28332--- a/arch/x86/kernel/vsyscall_64.c
28333+++ b/arch/x86/kernel/vsyscall_64.c
28334@@ -56,15 +56,13 @@
28335 DEFINE_VVAR(int, vgetcpu_mode);
28336 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
28337
28338-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
28339+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
28340
28341 static int __init vsyscall_setup(char *str)
28342 {
28343 if (str) {
28344 if (!strcmp("emulate", str))
28345 vsyscall_mode = EMULATE;
28346- else if (!strcmp("native", str))
28347- vsyscall_mode = NATIVE;
28348 else if (!strcmp("none", str))
28349 vsyscall_mode = NONE;
28350 else
28351@@ -101,7 +99,7 @@ void update_vsyscall(struct timekeeper *tk)
28352 vdata->monotonic_time_sec = tk->xtime_sec
28353 + tk->wall_to_monotonic.tv_sec;
28354 vdata->monotonic_time_snsec = tk->xtime_nsec
28355- + (tk->wall_to_monotonic.tv_nsec
28356+ + ((u64)tk->wall_to_monotonic.tv_nsec
28357 << tk->shift);
28358 while (vdata->monotonic_time_snsec >=
28359 (((u64)NSEC_PER_SEC) << tk->shift)) {
28360@@ -323,8 +321,7 @@ do_ret:
28361 return true;
28362
28363 sigsegv:
28364- force_sig(SIGSEGV, current);
28365- return true;
28366+ do_group_exit(SIGKILL);
28367 }
28368
28369 /*
28370@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
28371 extern char __vvar_page;
28372 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
28373
28374- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
28375- vsyscall_mode == NATIVE
28376- ? PAGE_KERNEL_VSYSCALL
28377- : PAGE_KERNEL_VVAR);
28378+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
28379 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
28380 (unsigned long)VSYSCALL_START);
28381
28382diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
28383index 04068192..4d75aa6 100644
28384--- a/arch/x86/kernel/x8664_ksyms_64.c
28385+++ b/arch/x86/kernel/x8664_ksyms_64.c
28386@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
28387 EXPORT_SYMBOL(copy_user_generic_unrolled);
28388 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
28389 EXPORT_SYMBOL(__copy_user_nocache);
28390-EXPORT_SYMBOL(_copy_from_user);
28391-EXPORT_SYMBOL(_copy_to_user);
28392
28393 EXPORT_SYMBOL(copy_page);
28394 EXPORT_SYMBOL(clear_page);
28395@@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
28396 EXPORT_SYMBOL(___preempt_schedule_context);
28397 #endif
28398 #endif
28399+
28400+#ifdef CONFIG_PAX_PER_CPU_PGD
28401+EXPORT_SYMBOL(cpu_pgd);
28402+#endif
28403diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
28404index e48b674..a451dd9 100644
28405--- a/arch/x86/kernel/x86_init.c
28406+++ b/arch/x86/kernel/x86_init.c
28407@@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
28408 static void default_nmi_init(void) { };
28409 static int default_i8042_detect(void) { return 1; };
28410
28411-struct x86_platform_ops x86_platform = {
28412+struct x86_platform_ops x86_platform __read_only = {
28413 .calibrate_tsc = native_calibrate_tsc,
28414 .get_wallclock = mach_get_cmos_time,
28415 .set_wallclock = mach_set_rtc_mmss,
28416@@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
28417 EXPORT_SYMBOL_GPL(x86_platform);
28418
28419 #if defined(CONFIG_PCI_MSI)
28420-struct x86_msi_ops x86_msi = {
28421+struct x86_msi_ops x86_msi __read_only = {
28422 .setup_msi_irqs = native_setup_msi_irqs,
28423 .compose_msi_msg = native_compose_msi_msg,
28424 .teardown_msi_irq = native_teardown_msi_irq,
28425@@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
28426 }
28427 #endif
28428
28429-struct x86_io_apic_ops x86_io_apic_ops = {
28430+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
28431 .init = native_io_apic_init_mappings,
28432 .read = native_io_apic_read,
28433 .write = native_io_apic_write,
28434diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
28435index a4b451c..8dfe1ad 100644
28436--- a/arch/x86/kernel/xsave.c
28437+++ b/arch/x86/kernel/xsave.c
28438@@ -164,18 +164,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28439
28440 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
28441 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
28442- err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28443+ err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28444
28445 if (!use_xsave())
28446 return err;
28447
28448- err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
28449+ err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
28450
28451 /*
28452 * Read the xstate_bv which we copied (directly from the cpu or
28453 * from the state in task struct) to the user buffers.
28454 */
28455- err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28456+ err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28457
28458 /*
28459 * For legacy compatible, we always set FP/SSE bits in the bit
28460@@ -190,7 +190,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28461 */
28462 xstate_bv |= XSTATE_FPSSE;
28463
28464- err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28465+ err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28466
28467 return err;
28468 }
28469@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
28470 {
28471 int err;
28472
28473+ buf = (struct xsave_struct __user *)____m(buf);
28474 if (use_xsave())
28475 err = xsave_user(buf);
28476 else if (use_fxsr())
28477@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
28478 */
28479 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
28480 {
28481+ buf = (void __user *)____m(buf);
28482 if (use_xsave()) {
28483 if ((unsigned long)buf % 64 || fx_only) {
28484 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
28485diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
28486index c697625..a032162 100644
28487--- a/arch/x86/kvm/cpuid.c
28488+++ b/arch/x86/kvm/cpuid.c
28489@@ -156,15 +156,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
28490 struct kvm_cpuid2 *cpuid,
28491 struct kvm_cpuid_entry2 __user *entries)
28492 {
28493- int r;
28494+ int r, i;
28495
28496 r = -E2BIG;
28497 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
28498 goto out;
28499 r = -EFAULT;
28500- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
28501- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28502+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28503 goto out;
28504+ for (i = 0; i < cpuid->nent; ++i) {
28505+ struct kvm_cpuid_entry2 cpuid_entry;
28506+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
28507+ goto out;
28508+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
28509+ }
28510 vcpu->arch.cpuid_nent = cpuid->nent;
28511 kvm_apic_set_version(vcpu);
28512 kvm_x86_ops->cpuid_update(vcpu);
28513@@ -179,15 +184,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
28514 struct kvm_cpuid2 *cpuid,
28515 struct kvm_cpuid_entry2 __user *entries)
28516 {
28517- int r;
28518+ int r, i;
28519
28520 r = -E2BIG;
28521 if (cpuid->nent < vcpu->arch.cpuid_nent)
28522 goto out;
28523 r = -EFAULT;
28524- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
28525- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28526+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28527 goto out;
28528+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
28529+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
28530+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
28531+ goto out;
28532+ }
28533 return 0;
28534
28535 out:
28536diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
28537index 9736529..ab4f54c 100644
28538--- a/arch/x86/kvm/lapic.c
28539+++ b/arch/x86/kvm/lapic.c
28540@@ -55,7 +55,7 @@
28541 #define APIC_BUS_CYCLE_NS 1
28542
28543 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
28544-#define apic_debug(fmt, arg...)
28545+#define apic_debug(fmt, arg...) do {} while (0)
28546
28547 #define APIC_LVT_NUM 6
28548 /* 14 is the version for Xeon and Pentium 8.4.8*/
28549diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
28550index cba218a..1cc1bed 100644
28551--- a/arch/x86/kvm/paging_tmpl.h
28552+++ b/arch/x86/kvm/paging_tmpl.h
28553@@ -331,7 +331,7 @@ retry_walk:
28554 if (unlikely(kvm_is_error_hva(host_addr)))
28555 goto error;
28556
28557- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
28558+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
28559 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
28560 goto error;
28561 walker->ptep_user[walker->level - 1] = ptep_user;
28562diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
28563index 2de1bc0..22251ee 100644
28564--- a/arch/x86/kvm/svm.c
28565+++ b/arch/x86/kvm/svm.c
28566@@ -3508,7 +3508,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
28567 int cpu = raw_smp_processor_id();
28568
28569 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
28570+
28571+ pax_open_kernel();
28572 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
28573+ pax_close_kernel();
28574+
28575 load_TR_desc();
28576 }
28577
28578@@ -3911,6 +3915,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
28579 #endif
28580 #endif
28581
28582+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28583+ __set_fs(current_thread_info()->addr_limit);
28584+#endif
28585+
28586 reload_tss(vcpu);
28587
28588 local_irq_disable();
28589diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
28590index 3927528..fc19971 100644
28591--- a/arch/x86/kvm/vmx.c
28592+++ b/arch/x86/kvm/vmx.c
28593@@ -1320,12 +1320,12 @@ static void vmcs_write64(unsigned long field, u64 value)
28594 #endif
28595 }
28596
28597-static void vmcs_clear_bits(unsigned long field, u32 mask)
28598+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
28599 {
28600 vmcs_writel(field, vmcs_readl(field) & ~mask);
28601 }
28602
28603-static void vmcs_set_bits(unsigned long field, u32 mask)
28604+static void vmcs_set_bits(unsigned long field, unsigned long mask)
28605 {
28606 vmcs_writel(field, vmcs_readl(field) | mask);
28607 }
28608@@ -1585,7 +1585,11 @@ static void reload_tss(void)
28609 struct desc_struct *descs;
28610
28611 descs = (void *)gdt->address;
28612+
28613+ pax_open_kernel();
28614 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
28615+ pax_close_kernel();
28616+
28617 load_TR_desc();
28618 }
28619
28620@@ -1809,6 +1813,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
28621 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
28622 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
28623
28624+#ifdef CONFIG_PAX_PER_CPU_PGD
28625+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28626+#endif
28627+
28628 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
28629 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
28630 vmx->loaded_vmcs->cpu = cpu;
28631@@ -2098,7 +2106,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
28632 * reads and returns guest's timestamp counter "register"
28633 * guest_tsc = host_tsc + tsc_offset -- 21.3
28634 */
28635-static u64 guest_read_tsc(void)
28636+static u64 __intentional_overflow(-1) guest_read_tsc(void)
28637 {
28638 u64 host_tsc, tsc_offset;
28639
28640@@ -3024,8 +3032,11 @@ static __init int hardware_setup(void)
28641 if (!cpu_has_vmx_flexpriority())
28642 flexpriority_enabled = 0;
28643
28644- if (!cpu_has_vmx_tpr_shadow())
28645- kvm_x86_ops->update_cr8_intercept = NULL;
28646+ if (!cpu_has_vmx_tpr_shadow()) {
28647+ pax_open_kernel();
28648+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28649+ pax_close_kernel();
28650+ }
28651
28652 if (enable_ept && !cpu_has_vmx_ept_2m_page())
28653 kvm_disable_largepages();
28654@@ -3036,13 +3047,15 @@ static __init int hardware_setup(void)
28655 if (!cpu_has_vmx_apicv())
28656 enable_apicv = 0;
28657
28658+ pax_open_kernel();
28659 if (enable_apicv)
28660- kvm_x86_ops->update_cr8_intercept = NULL;
28661+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28662 else {
28663- kvm_x86_ops->hwapic_irr_update = NULL;
28664- kvm_x86_ops->deliver_posted_interrupt = NULL;
28665- kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28666+ *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
28667+ *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
28668+ *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28669 }
28670+ pax_close_kernel();
28671
28672 if (nested)
28673 nested_vmx_setup_ctls_msrs();
28674@@ -4165,7 +4178,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28675
28676 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
28677 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
28678+
28679+#ifndef CONFIG_PAX_PER_CPU_PGD
28680 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28681+#endif
28682
28683 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
28684 #ifdef CONFIG_X86_64
28685@@ -4187,7 +4203,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28686 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
28687 vmx->host_idt_base = dt.address;
28688
28689- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
28690+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
28691
28692 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
28693 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
28694@@ -7265,6 +7281,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28695 "jmp 2f \n\t"
28696 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
28697 "2: "
28698+
28699+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28700+ "ljmp %[cs],$3f\n\t"
28701+ "3: "
28702+#endif
28703+
28704 /* Save guest registers, load host registers, keep flags */
28705 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
28706 "pop %0 \n\t"
28707@@ -7317,6 +7339,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28708 #endif
28709 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
28710 [wordsize]"i"(sizeof(ulong))
28711+
28712+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28713+ ,[cs]"i"(__KERNEL_CS)
28714+#endif
28715+
28716 : "cc", "memory"
28717 #ifdef CONFIG_X86_64
28718 , "rax", "rbx", "rdi", "rsi"
28719@@ -7330,7 +7357,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28720 if (debugctlmsr)
28721 update_debugctlmsr(debugctlmsr);
28722
28723-#ifndef CONFIG_X86_64
28724+#ifdef CONFIG_X86_32
28725 /*
28726 * The sysexit path does not restore ds/es, so we must set them to
28727 * a reasonable value ourselves.
28728@@ -7339,8 +7366,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28729 * may be executed in interrupt context, which saves and restore segments
28730 * around it, nullifying its effect.
28731 */
28732- loadsegment(ds, __USER_DS);
28733- loadsegment(es, __USER_DS);
28734+ loadsegment(ds, __KERNEL_DS);
28735+ loadsegment(es, __KERNEL_DS);
28736+ loadsegment(ss, __KERNEL_DS);
28737+
28738+#ifdef CONFIG_PAX_KERNEXEC
28739+ loadsegment(fs, __KERNEL_PERCPU);
28740+#endif
28741+
28742+#ifdef CONFIG_PAX_MEMORY_UDEREF
28743+ __set_fs(current_thread_info()->addr_limit);
28744+#endif
28745+
28746 #endif
28747
28748 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
28749diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
28750index 2b85784..ad70e19 100644
28751--- a/arch/x86/kvm/x86.c
28752+++ b/arch/x86/kvm/x86.c
28753@@ -1777,8 +1777,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
28754 {
28755 struct kvm *kvm = vcpu->kvm;
28756 int lm = is_long_mode(vcpu);
28757- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28758- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28759+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28760+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28761 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
28762 : kvm->arch.xen_hvm_config.blob_size_32;
28763 u32 page_num = data & ~PAGE_MASK;
28764@@ -2689,6 +2689,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
28765 if (n < msr_list.nmsrs)
28766 goto out;
28767 r = -EFAULT;
28768+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
28769+ goto out;
28770 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
28771 num_msrs_to_save * sizeof(u32)))
28772 goto out;
28773@@ -5503,7 +5505,7 @@ static struct notifier_block pvclock_gtod_notifier = {
28774 };
28775 #endif
28776
28777-int kvm_arch_init(void *opaque)
28778+int kvm_arch_init(const void *opaque)
28779 {
28780 int r;
28781 struct kvm_x86_ops *ops = opaque;
28782diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
28783index ad1fb5f..fe30b66 100644
28784--- a/arch/x86/lguest/boot.c
28785+++ b/arch/x86/lguest/boot.c
28786@@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
28787 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
28788 * Launcher to reboot us.
28789 */
28790-static void lguest_restart(char *reason)
28791+static __noreturn void lguest_restart(char *reason)
28792 {
28793 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
28794+ BUG();
28795 }
28796
28797 /*G:050
28798diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
28799index 00933d5..3a64af9 100644
28800--- a/arch/x86/lib/atomic64_386_32.S
28801+++ b/arch/x86/lib/atomic64_386_32.S
28802@@ -48,6 +48,10 @@ BEGIN(read)
28803 movl (v), %eax
28804 movl 4(v), %edx
28805 RET_ENDP
28806+BEGIN(read_unchecked)
28807+ movl (v), %eax
28808+ movl 4(v), %edx
28809+RET_ENDP
28810 #undef v
28811
28812 #define v %esi
28813@@ -55,6 +59,10 @@ BEGIN(set)
28814 movl %ebx, (v)
28815 movl %ecx, 4(v)
28816 RET_ENDP
28817+BEGIN(set_unchecked)
28818+ movl %ebx, (v)
28819+ movl %ecx, 4(v)
28820+RET_ENDP
28821 #undef v
28822
28823 #define v %esi
28824@@ -70,6 +78,20 @@ RET_ENDP
28825 BEGIN(add)
28826 addl %eax, (v)
28827 adcl %edx, 4(v)
28828+
28829+#ifdef CONFIG_PAX_REFCOUNT
28830+ jno 0f
28831+ subl %eax, (v)
28832+ sbbl %edx, 4(v)
28833+ int $4
28834+0:
28835+ _ASM_EXTABLE(0b, 0b)
28836+#endif
28837+
28838+RET_ENDP
28839+BEGIN(add_unchecked)
28840+ addl %eax, (v)
28841+ adcl %edx, 4(v)
28842 RET_ENDP
28843 #undef v
28844
28845@@ -77,6 +99,24 @@ RET_ENDP
28846 BEGIN(add_return)
28847 addl (v), %eax
28848 adcl 4(v), %edx
28849+
28850+#ifdef CONFIG_PAX_REFCOUNT
28851+ into
28852+1234:
28853+ _ASM_EXTABLE(1234b, 2f)
28854+#endif
28855+
28856+ movl %eax, (v)
28857+ movl %edx, 4(v)
28858+
28859+#ifdef CONFIG_PAX_REFCOUNT
28860+2:
28861+#endif
28862+
28863+RET_ENDP
28864+BEGIN(add_return_unchecked)
28865+ addl (v), %eax
28866+ adcl 4(v), %edx
28867 movl %eax, (v)
28868 movl %edx, 4(v)
28869 RET_ENDP
28870@@ -86,6 +126,20 @@ RET_ENDP
28871 BEGIN(sub)
28872 subl %eax, (v)
28873 sbbl %edx, 4(v)
28874+
28875+#ifdef CONFIG_PAX_REFCOUNT
28876+ jno 0f
28877+ addl %eax, (v)
28878+ adcl %edx, 4(v)
28879+ int $4
28880+0:
28881+ _ASM_EXTABLE(0b, 0b)
28882+#endif
28883+
28884+RET_ENDP
28885+BEGIN(sub_unchecked)
28886+ subl %eax, (v)
28887+ sbbl %edx, 4(v)
28888 RET_ENDP
28889 #undef v
28890
28891@@ -96,6 +150,27 @@ BEGIN(sub_return)
28892 sbbl $0, %edx
28893 addl (v), %eax
28894 adcl 4(v), %edx
28895+
28896+#ifdef CONFIG_PAX_REFCOUNT
28897+ into
28898+1234:
28899+ _ASM_EXTABLE(1234b, 2f)
28900+#endif
28901+
28902+ movl %eax, (v)
28903+ movl %edx, 4(v)
28904+
28905+#ifdef CONFIG_PAX_REFCOUNT
28906+2:
28907+#endif
28908+
28909+RET_ENDP
28910+BEGIN(sub_return_unchecked)
28911+ negl %edx
28912+ negl %eax
28913+ sbbl $0, %edx
28914+ addl (v), %eax
28915+ adcl 4(v), %edx
28916 movl %eax, (v)
28917 movl %edx, 4(v)
28918 RET_ENDP
28919@@ -105,6 +180,20 @@ RET_ENDP
28920 BEGIN(inc)
28921 addl $1, (v)
28922 adcl $0, 4(v)
28923+
28924+#ifdef CONFIG_PAX_REFCOUNT
28925+ jno 0f
28926+ subl $1, (v)
28927+ sbbl $0, 4(v)
28928+ int $4
28929+0:
28930+ _ASM_EXTABLE(0b, 0b)
28931+#endif
28932+
28933+RET_ENDP
28934+BEGIN(inc_unchecked)
28935+ addl $1, (v)
28936+ adcl $0, 4(v)
28937 RET_ENDP
28938 #undef v
28939
28940@@ -114,6 +203,26 @@ BEGIN(inc_return)
28941 movl 4(v), %edx
28942 addl $1, %eax
28943 adcl $0, %edx
28944+
28945+#ifdef CONFIG_PAX_REFCOUNT
28946+ into
28947+1234:
28948+ _ASM_EXTABLE(1234b, 2f)
28949+#endif
28950+
28951+ movl %eax, (v)
28952+ movl %edx, 4(v)
28953+
28954+#ifdef CONFIG_PAX_REFCOUNT
28955+2:
28956+#endif
28957+
28958+RET_ENDP
28959+BEGIN(inc_return_unchecked)
28960+ movl (v), %eax
28961+ movl 4(v), %edx
28962+ addl $1, %eax
28963+ adcl $0, %edx
28964 movl %eax, (v)
28965 movl %edx, 4(v)
28966 RET_ENDP
28967@@ -123,6 +232,20 @@ RET_ENDP
28968 BEGIN(dec)
28969 subl $1, (v)
28970 sbbl $0, 4(v)
28971+
28972+#ifdef CONFIG_PAX_REFCOUNT
28973+ jno 0f
28974+ addl $1, (v)
28975+ adcl $0, 4(v)
28976+ int $4
28977+0:
28978+ _ASM_EXTABLE(0b, 0b)
28979+#endif
28980+
28981+RET_ENDP
28982+BEGIN(dec_unchecked)
28983+ subl $1, (v)
28984+ sbbl $0, 4(v)
28985 RET_ENDP
28986 #undef v
28987
28988@@ -132,6 +255,26 @@ BEGIN(dec_return)
28989 movl 4(v), %edx
28990 subl $1, %eax
28991 sbbl $0, %edx
28992+
28993+#ifdef CONFIG_PAX_REFCOUNT
28994+ into
28995+1234:
28996+ _ASM_EXTABLE(1234b, 2f)
28997+#endif
28998+
28999+ movl %eax, (v)
29000+ movl %edx, 4(v)
29001+
29002+#ifdef CONFIG_PAX_REFCOUNT
29003+2:
29004+#endif
29005+
29006+RET_ENDP
29007+BEGIN(dec_return_unchecked)
29008+ movl (v), %eax
29009+ movl 4(v), %edx
29010+ subl $1, %eax
29011+ sbbl $0, %edx
29012 movl %eax, (v)
29013 movl %edx, 4(v)
29014 RET_ENDP
29015@@ -143,6 +286,13 @@ BEGIN(add_unless)
29016 adcl %edx, %edi
29017 addl (v), %eax
29018 adcl 4(v), %edx
29019+
29020+#ifdef CONFIG_PAX_REFCOUNT
29021+ into
29022+1234:
29023+ _ASM_EXTABLE(1234b, 2f)
29024+#endif
29025+
29026 cmpl %eax, %ecx
29027 je 3f
29028 1:
29029@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
29030 1:
29031 addl $1, %eax
29032 adcl $0, %edx
29033+
29034+#ifdef CONFIG_PAX_REFCOUNT
29035+ into
29036+1234:
29037+ _ASM_EXTABLE(1234b, 2f)
29038+#endif
29039+
29040 movl %eax, (v)
29041 movl %edx, 4(v)
29042 movl $1, %eax
29043@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
29044 movl 4(v), %edx
29045 subl $1, %eax
29046 sbbl $0, %edx
29047+
29048+#ifdef CONFIG_PAX_REFCOUNT
29049+ into
29050+1234:
29051+ _ASM_EXTABLE(1234b, 1f)
29052+#endif
29053+
29054 js 1f
29055 movl %eax, (v)
29056 movl %edx, 4(v)
29057diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
29058index f5cc9eb..51fa319 100644
29059--- a/arch/x86/lib/atomic64_cx8_32.S
29060+++ b/arch/x86/lib/atomic64_cx8_32.S
29061@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
29062 CFI_STARTPROC
29063
29064 read64 %ecx
29065+ pax_force_retaddr
29066 ret
29067 CFI_ENDPROC
29068 ENDPROC(atomic64_read_cx8)
29069
29070+ENTRY(atomic64_read_unchecked_cx8)
29071+ CFI_STARTPROC
29072+
29073+ read64 %ecx
29074+ pax_force_retaddr
29075+ ret
29076+ CFI_ENDPROC
29077+ENDPROC(atomic64_read_unchecked_cx8)
29078+
29079 ENTRY(atomic64_set_cx8)
29080 CFI_STARTPROC
29081
29082@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
29083 cmpxchg8b (%esi)
29084 jne 1b
29085
29086+ pax_force_retaddr
29087 ret
29088 CFI_ENDPROC
29089 ENDPROC(atomic64_set_cx8)
29090
29091+ENTRY(atomic64_set_unchecked_cx8)
29092+ CFI_STARTPROC
29093+
29094+1:
29095+/* we don't need LOCK_PREFIX since aligned 64-bit writes
29096+ * are atomic on 586 and newer */
29097+ cmpxchg8b (%esi)
29098+ jne 1b
29099+
29100+ pax_force_retaddr
29101+ ret
29102+ CFI_ENDPROC
29103+ENDPROC(atomic64_set_unchecked_cx8)
29104+
29105 ENTRY(atomic64_xchg_cx8)
29106 CFI_STARTPROC
29107
29108@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
29109 cmpxchg8b (%esi)
29110 jne 1b
29111
29112+ pax_force_retaddr
29113 ret
29114 CFI_ENDPROC
29115 ENDPROC(atomic64_xchg_cx8)
29116
29117-.macro addsub_return func ins insc
29118-ENTRY(atomic64_\func\()_return_cx8)
29119+.macro addsub_return func ins insc unchecked=""
29120+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
29121 CFI_STARTPROC
29122 SAVE ebp
29123 SAVE ebx
29124@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
29125 movl %edx, %ecx
29126 \ins\()l %esi, %ebx
29127 \insc\()l %edi, %ecx
29128+
29129+.ifb \unchecked
29130+#ifdef CONFIG_PAX_REFCOUNT
29131+ into
29132+2:
29133+ _ASM_EXTABLE(2b, 3f)
29134+#endif
29135+.endif
29136+
29137 LOCK_PREFIX
29138 cmpxchg8b (%ebp)
29139 jne 1b
29140-
29141-10:
29142 movl %ebx, %eax
29143 movl %ecx, %edx
29144+
29145+.ifb \unchecked
29146+#ifdef CONFIG_PAX_REFCOUNT
29147+3:
29148+#endif
29149+.endif
29150+
29151 RESTORE edi
29152 RESTORE esi
29153 RESTORE ebx
29154 RESTORE ebp
29155+ pax_force_retaddr
29156 ret
29157 CFI_ENDPROC
29158-ENDPROC(atomic64_\func\()_return_cx8)
29159+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
29160 .endm
29161
29162 addsub_return add add adc
29163 addsub_return sub sub sbb
29164+addsub_return add add adc _unchecked
29165+addsub_return sub sub sbb _unchecked
29166
29167-.macro incdec_return func ins insc
29168-ENTRY(atomic64_\func\()_return_cx8)
29169+.macro incdec_return func ins insc unchecked=""
29170+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
29171 CFI_STARTPROC
29172 SAVE ebx
29173
29174@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
29175 movl %edx, %ecx
29176 \ins\()l $1, %ebx
29177 \insc\()l $0, %ecx
29178+
29179+.ifb \unchecked
29180+#ifdef CONFIG_PAX_REFCOUNT
29181+ into
29182+2:
29183+ _ASM_EXTABLE(2b, 3f)
29184+#endif
29185+.endif
29186+
29187 LOCK_PREFIX
29188 cmpxchg8b (%esi)
29189 jne 1b
29190
29191-10:
29192 movl %ebx, %eax
29193 movl %ecx, %edx
29194+
29195+.ifb \unchecked
29196+#ifdef CONFIG_PAX_REFCOUNT
29197+3:
29198+#endif
29199+.endif
29200+
29201 RESTORE ebx
29202+ pax_force_retaddr
29203 ret
29204 CFI_ENDPROC
29205-ENDPROC(atomic64_\func\()_return_cx8)
29206+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
29207 .endm
29208
29209 incdec_return inc add adc
29210 incdec_return dec sub sbb
29211+incdec_return inc add adc _unchecked
29212+incdec_return dec sub sbb _unchecked
29213
29214 ENTRY(atomic64_dec_if_positive_cx8)
29215 CFI_STARTPROC
29216@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
29217 movl %edx, %ecx
29218 subl $1, %ebx
29219 sbb $0, %ecx
29220+
29221+#ifdef CONFIG_PAX_REFCOUNT
29222+ into
29223+1234:
29224+ _ASM_EXTABLE(1234b, 2f)
29225+#endif
29226+
29227 js 2f
29228 LOCK_PREFIX
29229 cmpxchg8b (%esi)
29230@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
29231 movl %ebx, %eax
29232 movl %ecx, %edx
29233 RESTORE ebx
29234+ pax_force_retaddr
29235 ret
29236 CFI_ENDPROC
29237 ENDPROC(atomic64_dec_if_positive_cx8)
29238@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
29239 movl %edx, %ecx
29240 addl %ebp, %ebx
29241 adcl %edi, %ecx
29242+
29243+#ifdef CONFIG_PAX_REFCOUNT
29244+ into
29245+1234:
29246+ _ASM_EXTABLE(1234b, 3f)
29247+#endif
29248+
29249 LOCK_PREFIX
29250 cmpxchg8b (%esi)
29251 jne 1b
29252@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
29253 CFI_ADJUST_CFA_OFFSET -8
29254 RESTORE ebx
29255 RESTORE ebp
29256+ pax_force_retaddr
29257 ret
29258 4:
29259 cmpl %edx, 4(%esp)
29260@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
29261 xorl %ecx, %ecx
29262 addl $1, %ebx
29263 adcl %edx, %ecx
29264+
29265+#ifdef CONFIG_PAX_REFCOUNT
29266+ into
29267+1234:
29268+ _ASM_EXTABLE(1234b, 3f)
29269+#endif
29270+
29271 LOCK_PREFIX
29272 cmpxchg8b (%esi)
29273 jne 1b
29274@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
29275 movl $1, %eax
29276 3:
29277 RESTORE ebx
29278+ pax_force_retaddr
29279 ret
29280 CFI_ENDPROC
29281 ENDPROC(atomic64_inc_not_zero_cx8)
29282diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
29283index e78b8ee..7e173a8 100644
29284--- a/arch/x86/lib/checksum_32.S
29285+++ b/arch/x86/lib/checksum_32.S
29286@@ -29,7 +29,8 @@
29287 #include <asm/dwarf2.h>
29288 #include <asm/errno.h>
29289 #include <asm/asm.h>
29290-
29291+#include <asm/segment.h>
29292+
29293 /*
29294 * computes a partial checksum, e.g. for TCP/UDP fragments
29295 */
29296@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
29297
29298 #define ARGBASE 16
29299 #define FP 12
29300-
29301-ENTRY(csum_partial_copy_generic)
29302+
29303+ENTRY(csum_partial_copy_generic_to_user)
29304 CFI_STARTPROC
29305+
29306+#ifdef CONFIG_PAX_MEMORY_UDEREF
29307+ pushl_cfi %gs
29308+ popl_cfi %es
29309+ jmp csum_partial_copy_generic
29310+#endif
29311+
29312+ENTRY(csum_partial_copy_generic_from_user)
29313+
29314+#ifdef CONFIG_PAX_MEMORY_UDEREF
29315+ pushl_cfi %gs
29316+ popl_cfi %ds
29317+#endif
29318+
29319+ENTRY(csum_partial_copy_generic)
29320 subl $4,%esp
29321 CFI_ADJUST_CFA_OFFSET 4
29322 pushl_cfi %edi
29323@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
29324 jmp 4f
29325 SRC(1: movw (%esi), %bx )
29326 addl $2, %esi
29327-DST( movw %bx, (%edi) )
29328+DST( movw %bx, %es:(%edi) )
29329 addl $2, %edi
29330 addw %bx, %ax
29331 adcl $0, %eax
29332@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
29333 SRC(1: movl (%esi), %ebx )
29334 SRC( movl 4(%esi), %edx )
29335 adcl %ebx, %eax
29336-DST( movl %ebx, (%edi) )
29337+DST( movl %ebx, %es:(%edi) )
29338 adcl %edx, %eax
29339-DST( movl %edx, 4(%edi) )
29340+DST( movl %edx, %es:4(%edi) )
29341
29342 SRC( movl 8(%esi), %ebx )
29343 SRC( movl 12(%esi), %edx )
29344 adcl %ebx, %eax
29345-DST( movl %ebx, 8(%edi) )
29346+DST( movl %ebx, %es:8(%edi) )
29347 adcl %edx, %eax
29348-DST( movl %edx, 12(%edi) )
29349+DST( movl %edx, %es:12(%edi) )
29350
29351 SRC( movl 16(%esi), %ebx )
29352 SRC( movl 20(%esi), %edx )
29353 adcl %ebx, %eax
29354-DST( movl %ebx, 16(%edi) )
29355+DST( movl %ebx, %es:16(%edi) )
29356 adcl %edx, %eax
29357-DST( movl %edx, 20(%edi) )
29358+DST( movl %edx, %es:20(%edi) )
29359
29360 SRC( movl 24(%esi), %ebx )
29361 SRC( movl 28(%esi), %edx )
29362 adcl %ebx, %eax
29363-DST( movl %ebx, 24(%edi) )
29364+DST( movl %ebx, %es:24(%edi) )
29365 adcl %edx, %eax
29366-DST( movl %edx, 28(%edi) )
29367+DST( movl %edx, %es:28(%edi) )
29368
29369 lea 32(%esi), %esi
29370 lea 32(%edi), %edi
29371@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
29372 shrl $2, %edx # This clears CF
29373 SRC(3: movl (%esi), %ebx )
29374 adcl %ebx, %eax
29375-DST( movl %ebx, (%edi) )
29376+DST( movl %ebx, %es:(%edi) )
29377 lea 4(%esi), %esi
29378 lea 4(%edi), %edi
29379 dec %edx
29380@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
29381 jb 5f
29382 SRC( movw (%esi), %cx )
29383 leal 2(%esi), %esi
29384-DST( movw %cx, (%edi) )
29385+DST( movw %cx, %es:(%edi) )
29386 leal 2(%edi), %edi
29387 je 6f
29388 shll $16,%ecx
29389 SRC(5: movb (%esi), %cl )
29390-DST( movb %cl, (%edi) )
29391+DST( movb %cl, %es:(%edi) )
29392 6: addl %ecx, %eax
29393 adcl $0, %eax
29394 7:
29395@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
29396
29397 6001:
29398 movl ARGBASE+20(%esp), %ebx # src_err_ptr
29399- movl $-EFAULT, (%ebx)
29400+ movl $-EFAULT, %ss:(%ebx)
29401
29402 # zero the complete destination - computing the rest
29403 # is too much work
29404@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
29405
29406 6002:
29407 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29408- movl $-EFAULT,(%ebx)
29409+ movl $-EFAULT,%ss:(%ebx)
29410 jmp 5000b
29411
29412 .previous
29413
29414+ pushl_cfi %ss
29415+ popl_cfi %ds
29416+ pushl_cfi %ss
29417+ popl_cfi %es
29418 popl_cfi %ebx
29419 CFI_RESTORE ebx
29420 popl_cfi %esi
29421@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
29422 popl_cfi %ecx # equivalent to addl $4,%esp
29423 ret
29424 CFI_ENDPROC
29425-ENDPROC(csum_partial_copy_generic)
29426+ENDPROC(csum_partial_copy_generic_to_user)
29427
29428 #else
29429
29430 /* Version for PentiumII/PPro */
29431
29432 #define ROUND1(x) \
29433+ nop; nop; nop; \
29434 SRC(movl x(%esi), %ebx ) ; \
29435 addl %ebx, %eax ; \
29436- DST(movl %ebx, x(%edi) ) ;
29437+ DST(movl %ebx, %es:x(%edi)) ;
29438
29439 #define ROUND(x) \
29440+ nop; nop; nop; \
29441 SRC(movl x(%esi), %ebx ) ; \
29442 adcl %ebx, %eax ; \
29443- DST(movl %ebx, x(%edi) ) ;
29444+ DST(movl %ebx, %es:x(%edi)) ;
29445
29446 #define ARGBASE 12
29447-
29448-ENTRY(csum_partial_copy_generic)
29449+
29450+ENTRY(csum_partial_copy_generic_to_user)
29451 CFI_STARTPROC
29452+
29453+#ifdef CONFIG_PAX_MEMORY_UDEREF
29454+ pushl_cfi %gs
29455+ popl_cfi %es
29456+ jmp csum_partial_copy_generic
29457+#endif
29458+
29459+ENTRY(csum_partial_copy_generic_from_user)
29460+
29461+#ifdef CONFIG_PAX_MEMORY_UDEREF
29462+ pushl_cfi %gs
29463+ popl_cfi %ds
29464+#endif
29465+
29466+ENTRY(csum_partial_copy_generic)
29467 pushl_cfi %ebx
29468 CFI_REL_OFFSET ebx, 0
29469 pushl_cfi %edi
29470@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
29471 subl %ebx, %edi
29472 lea -1(%esi),%edx
29473 andl $-32,%edx
29474- lea 3f(%ebx,%ebx), %ebx
29475+ lea 3f(%ebx,%ebx,2), %ebx
29476 testl %esi, %esi
29477 jmp *%ebx
29478 1: addl $64,%esi
29479@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
29480 jb 5f
29481 SRC( movw (%esi), %dx )
29482 leal 2(%esi), %esi
29483-DST( movw %dx, (%edi) )
29484+DST( movw %dx, %es:(%edi) )
29485 leal 2(%edi), %edi
29486 je 6f
29487 shll $16,%edx
29488 5:
29489 SRC( movb (%esi), %dl )
29490-DST( movb %dl, (%edi) )
29491+DST( movb %dl, %es:(%edi) )
29492 6: addl %edx, %eax
29493 adcl $0, %eax
29494 7:
29495 .section .fixup, "ax"
29496 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
29497- movl $-EFAULT, (%ebx)
29498+ movl $-EFAULT, %ss:(%ebx)
29499 # zero the complete destination (computing the rest is too much work)
29500 movl ARGBASE+8(%esp),%edi # dst
29501 movl ARGBASE+12(%esp),%ecx # len
29502@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
29503 rep; stosb
29504 jmp 7b
29505 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29506- movl $-EFAULT, (%ebx)
29507+ movl $-EFAULT, %ss:(%ebx)
29508 jmp 7b
29509 .previous
29510
29511+#ifdef CONFIG_PAX_MEMORY_UDEREF
29512+ pushl_cfi %ss
29513+ popl_cfi %ds
29514+ pushl_cfi %ss
29515+ popl_cfi %es
29516+#endif
29517+
29518 popl_cfi %esi
29519 CFI_RESTORE esi
29520 popl_cfi %edi
29521@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
29522 CFI_RESTORE ebx
29523 ret
29524 CFI_ENDPROC
29525-ENDPROC(csum_partial_copy_generic)
29526+ENDPROC(csum_partial_copy_generic_to_user)
29527
29528 #undef ROUND
29529 #undef ROUND1
29530diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
29531index f2145cf..cea889d 100644
29532--- a/arch/x86/lib/clear_page_64.S
29533+++ b/arch/x86/lib/clear_page_64.S
29534@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
29535 movl $4096/8,%ecx
29536 xorl %eax,%eax
29537 rep stosq
29538+ pax_force_retaddr
29539 ret
29540 CFI_ENDPROC
29541 ENDPROC(clear_page_c)
29542@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
29543 movl $4096,%ecx
29544 xorl %eax,%eax
29545 rep stosb
29546+ pax_force_retaddr
29547 ret
29548 CFI_ENDPROC
29549 ENDPROC(clear_page_c_e)
29550@@ -43,6 +45,7 @@ ENTRY(clear_page)
29551 leaq 64(%rdi),%rdi
29552 jnz .Lloop
29553 nop
29554+ pax_force_retaddr
29555 ret
29556 CFI_ENDPROC
29557 .Lclear_page_end:
29558@@ -58,7 +61,7 @@ ENDPROC(clear_page)
29559
29560 #include <asm/cpufeature.h>
29561
29562- .section .altinstr_replacement,"ax"
29563+ .section .altinstr_replacement,"a"
29564 1: .byte 0xeb /* jmp <disp8> */
29565 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
29566 2: .byte 0xeb /* jmp <disp8> */
29567diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
29568index 1e572c5..2a162cd 100644
29569--- a/arch/x86/lib/cmpxchg16b_emu.S
29570+++ b/arch/x86/lib/cmpxchg16b_emu.S
29571@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
29572
29573 popf
29574 mov $1, %al
29575+ pax_force_retaddr
29576 ret
29577
29578 not_same:
29579 popf
29580 xor %al,%al
29581+ pax_force_retaddr
29582 ret
29583
29584 CFI_ENDPROC
29585diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
29586index 176cca6..e0d658e 100644
29587--- a/arch/x86/lib/copy_page_64.S
29588+++ b/arch/x86/lib/copy_page_64.S
29589@@ -9,6 +9,7 @@ copy_page_rep:
29590 CFI_STARTPROC
29591 movl $4096/8, %ecx
29592 rep movsq
29593+ pax_force_retaddr
29594 ret
29595 CFI_ENDPROC
29596 ENDPROC(copy_page_rep)
29597@@ -24,8 +25,8 @@ ENTRY(copy_page)
29598 CFI_ADJUST_CFA_OFFSET 2*8
29599 movq %rbx, (%rsp)
29600 CFI_REL_OFFSET rbx, 0
29601- movq %r12, 1*8(%rsp)
29602- CFI_REL_OFFSET r12, 1*8
29603+ movq %r13, 1*8(%rsp)
29604+ CFI_REL_OFFSET r13, 1*8
29605
29606 movl $(4096/64)-5, %ecx
29607 .p2align 4
29608@@ -38,7 +39,7 @@ ENTRY(copy_page)
29609 movq 0x8*4(%rsi), %r9
29610 movq 0x8*5(%rsi), %r10
29611 movq 0x8*6(%rsi), %r11
29612- movq 0x8*7(%rsi), %r12
29613+ movq 0x8*7(%rsi), %r13
29614
29615 prefetcht0 5*64(%rsi)
29616
29617@@ -49,7 +50,7 @@ ENTRY(copy_page)
29618 movq %r9, 0x8*4(%rdi)
29619 movq %r10, 0x8*5(%rdi)
29620 movq %r11, 0x8*6(%rdi)
29621- movq %r12, 0x8*7(%rdi)
29622+ movq %r13, 0x8*7(%rdi)
29623
29624 leaq 64 (%rsi), %rsi
29625 leaq 64 (%rdi), %rdi
29626@@ -68,7 +69,7 @@ ENTRY(copy_page)
29627 movq 0x8*4(%rsi), %r9
29628 movq 0x8*5(%rsi), %r10
29629 movq 0x8*6(%rsi), %r11
29630- movq 0x8*7(%rsi), %r12
29631+ movq 0x8*7(%rsi), %r13
29632
29633 movq %rax, 0x8*0(%rdi)
29634 movq %rbx, 0x8*1(%rdi)
29635@@ -77,7 +78,7 @@ ENTRY(copy_page)
29636 movq %r9, 0x8*4(%rdi)
29637 movq %r10, 0x8*5(%rdi)
29638 movq %r11, 0x8*6(%rdi)
29639- movq %r12, 0x8*7(%rdi)
29640+ movq %r13, 0x8*7(%rdi)
29641
29642 leaq 64(%rdi), %rdi
29643 leaq 64(%rsi), %rsi
29644@@ -85,10 +86,11 @@ ENTRY(copy_page)
29645
29646 movq (%rsp), %rbx
29647 CFI_RESTORE rbx
29648- movq 1*8(%rsp), %r12
29649- CFI_RESTORE r12
29650+ movq 1*8(%rsp), %r13
29651+ CFI_RESTORE r13
29652 addq $2*8, %rsp
29653 CFI_ADJUST_CFA_OFFSET -2*8
29654+ pax_force_retaddr
29655 ret
29656 .Lcopy_page_end:
29657 CFI_ENDPROC
29658@@ -99,7 +101,7 @@ ENDPROC(copy_page)
29659
29660 #include <asm/cpufeature.h>
29661
29662- .section .altinstr_replacement,"ax"
29663+ .section .altinstr_replacement,"a"
29664 1: .byte 0xeb /* jmp <disp8> */
29665 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
29666 2:
29667diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
29668index dee945d..a84067b 100644
29669--- a/arch/x86/lib/copy_user_64.S
29670+++ b/arch/x86/lib/copy_user_64.S
29671@@ -18,31 +18,7 @@
29672 #include <asm/alternative-asm.h>
29673 #include <asm/asm.h>
29674 #include <asm/smap.h>
29675-
29676-/*
29677- * By placing feature2 after feature1 in altinstructions section, we logically
29678- * implement:
29679- * If CPU has feature2, jmp to alt2 is used
29680- * else if CPU has feature1, jmp to alt1 is used
29681- * else jmp to orig is used.
29682- */
29683- .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
29684-0:
29685- .byte 0xe9 /* 32bit jump */
29686- .long \orig-1f /* by default jump to orig */
29687-1:
29688- .section .altinstr_replacement,"ax"
29689-2: .byte 0xe9 /* near jump with 32bit immediate */
29690- .long \alt1-1b /* offset */ /* or alternatively to alt1 */
29691-3: .byte 0xe9 /* near jump with 32bit immediate */
29692- .long \alt2-1b /* offset */ /* or alternatively to alt2 */
29693- .previous
29694-
29695- .section .altinstructions,"a"
29696- altinstruction_entry 0b,2b,\feature1,5,5
29697- altinstruction_entry 0b,3b,\feature2,5,5
29698- .previous
29699- .endm
29700+#include <asm/pgtable.h>
29701
29702 .macro ALIGN_DESTINATION
29703 #ifdef FIX_ALIGNMENT
29704@@ -70,52 +46,6 @@
29705 #endif
29706 .endm
29707
29708-/* Standard copy_to_user with segment limit checking */
29709-ENTRY(_copy_to_user)
29710- CFI_STARTPROC
29711- GET_THREAD_INFO(%rax)
29712- movq %rdi,%rcx
29713- addq %rdx,%rcx
29714- jc bad_to_user
29715- cmpq TI_addr_limit(%rax),%rcx
29716- ja bad_to_user
29717- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29718- copy_user_generic_unrolled,copy_user_generic_string, \
29719- copy_user_enhanced_fast_string
29720- CFI_ENDPROC
29721-ENDPROC(_copy_to_user)
29722-
29723-/* Standard copy_from_user with segment limit checking */
29724-ENTRY(_copy_from_user)
29725- CFI_STARTPROC
29726- GET_THREAD_INFO(%rax)
29727- movq %rsi,%rcx
29728- addq %rdx,%rcx
29729- jc bad_from_user
29730- cmpq TI_addr_limit(%rax),%rcx
29731- ja bad_from_user
29732- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29733- copy_user_generic_unrolled,copy_user_generic_string, \
29734- copy_user_enhanced_fast_string
29735- CFI_ENDPROC
29736-ENDPROC(_copy_from_user)
29737-
29738- .section .fixup,"ax"
29739- /* must zero dest */
29740-ENTRY(bad_from_user)
29741-bad_from_user:
29742- CFI_STARTPROC
29743- movl %edx,%ecx
29744- xorl %eax,%eax
29745- rep
29746- stosb
29747-bad_to_user:
29748- movl %edx,%eax
29749- ret
29750- CFI_ENDPROC
29751-ENDPROC(bad_from_user)
29752- .previous
29753-
29754 /*
29755 * copy_user_generic_unrolled - memory copy with exception handling.
29756 * This version is for CPUs like P4 that don't have efficient micro
29757@@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
29758 */
29759 ENTRY(copy_user_generic_unrolled)
29760 CFI_STARTPROC
29761+ ASM_PAX_OPEN_USERLAND
29762 ASM_STAC
29763 cmpl $8,%edx
29764 jb 20f /* less then 8 bytes, go to byte copy loop */
29765@@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
29766 jnz 21b
29767 23: xor %eax,%eax
29768 ASM_CLAC
29769+ ASM_PAX_CLOSE_USERLAND
29770+ pax_force_retaddr
29771 ret
29772
29773 .section .fixup,"ax"
29774@@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
29775 */
29776 ENTRY(copy_user_generic_string)
29777 CFI_STARTPROC
29778+ ASM_PAX_OPEN_USERLAND
29779 ASM_STAC
29780 cmpl $8,%edx
29781 jb 2f /* less than 8 bytes, go to byte copy loop */
29782@@ -249,6 +183,8 @@ ENTRY(copy_user_generic_string)
29783 movsb
29784 xorl %eax,%eax
29785 ASM_CLAC
29786+ ASM_PAX_CLOSE_USERLAND
29787+ pax_force_retaddr
29788 ret
29789
29790 .section .fixup,"ax"
29791@@ -276,12 +212,15 @@ ENDPROC(copy_user_generic_string)
29792 */
29793 ENTRY(copy_user_enhanced_fast_string)
29794 CFI_STARTPROC
29795+ ASM_PAX_OPEN_USERLAND
29796 ASM_STAC
29797 movl %edx,%ecx
29798 1: rep
29799 movsb
29800 xorl %eax,%eax
29801 ASM_CLAC
29802+ ASM_PAX_CLOSE_USERLAND
29803+ pax_force_retaddr
29804 ret
29805
29806 .section .fixup,"ax"
29807diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
29808index 6a4f43c..c70fb52 100644
29809--- a/arch/x86/lib/copy_user_nocache_64.S
29810+++ b/arch/x86/lib/copy_user_nocache_64.S
29811@@ -8,6 +8,7 @@
29812
29813 #include <linux/linkage.h>
29814 #include <asm/dwarf2.h>
29815+#include <asm/alternative-asm.h>
29816
29817 #define FIX_ALIGNMENT 1
29818
29819@@ -16,6 +17,7 @@
29820 #include <asm/thread_info.h>
29821 #include <asm/asm.h>
29822 #include <asm/smap.h>
29823+#include <asm/pgtable.h>
29824
29825 .macro ALIGN_DESTINATION
29826 #ifdef FIX_ALIGNMENT
29827@@ -49,6 +51,16 @@
29828 */
29829 ENTRY(__copy_user_nocache)
29830 CFI_STARTPROC
29831+
29832+#ifdef CONFIG_PAX_MEMORY_UDEREF
29833+ mov pax_user_shadow_base,%rcx
29834+ cmp %rcx,%rsi
29835+ jae 1f
29836+ add %rcx,%rsi
29837+1:
29838+#endif
29839+
29840+ ASM_PAX_OPEN_USERLAND
29841 ASM_STAC
29842 cmpl $8,%edx
29843 jb 20f /* less then 8 bytes, go to byte copy loop */
29844@@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
29845 jnz 21b
29846 23: xorl %eax,%eax
29847 ASM_CLAC
29848+ ASM_PAX_CLOSE_USERLAND
29849 sfence
29850+ pax_force_retaddr
29851 ret
29852
29853 .section .fixup,"ax"
29854diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
29855index 2419d5f..fe52d0e 100644
29856--- a/arch/x86/lib/csum-copy_64.S
29857+++ b/arch/x86/lib/csum-copy_64.S
29858@@ -9,6 +9,7 @@
29859 #include <asm/dwarf2.h>
29860 #include <asm/errno.h>
29861 #include <asm/asm.h>
29862+#include <asm/alternative-asm.h>
29863
29864 /*
29865 * Checksum copy with exception handling.
29866@@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
29867 CFI_ADJUST_CFA_OFFSET 7*8
29868 movq %rbx, 2*8(%rsp)
29869 CFI_REL_OFFSET rbx, 2*8
29870- movq %r12, 3*8(%rsp)
29871- CFI_REL_OFFSET r12, 3*8
29872+ movq %r15, 3*8(%rsp)
29873+ CFI_REL_OFFSET r15, 3*8
29874 movq %r14, 4*8(%rsp)
29875 CFI_REL_OFFSET r14, 4*8
29876 movq %r13, 5*8(%rsp)
29877@@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
29878 movl %edx, %ecx
29879
29880 xorl %r9d, %r9d
29881- movq %rcx, %r12
29882+ movq %rcx, %r15
29883
29884- shrq $6, %r12
29885+ shrq $6, %r15
29886 jz .Lhandle_tail /* < 64 */
29887
29888 clc
29889
29890 /* main loop. clear in 64 byte blocks */
29891 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
29892- /* r11: temp3, rdx: temp4, r12 loopcnt */
29893+ /* r11: temp3, rdx: temp4, r15 loopcnt */
29894 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
29895 .p2align 4
29896 .Lloop:
29897@@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
29898 adcq %r14, %rax
29899 adcq %r13, %rax
29900
29901- decl %r12d
29902+ decl %r15d
29903
29904 dest
29905 movq %rbx, (%rsi)
29906@@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
29907 .Lende:
29908 movq 2*8(%rsp), %rbx
29909 CFI_RESTORE rbx
29910- movq 3*8(%rsp), %r12
29911- CFI_RESTORE r12
29912+ movq 3*8(%rsp), %r15
29913+ CFI_RESTORE r15
29914 movq 4*8(%rsp), %r14
29915 CFI_RESTORE r14
29916 movq 5*8(%rsp), %r13
29917@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
29918 CFI_RESTORE rbp
29919 addq $7*8, %rsp
29920 CFI_ADJUST_CFA_OFFSET -7*8
29921+ pax_force_retaddr
29922 ret
29923 CFI_RESTORE_STATE
29924
29925diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
29926index 7609e0e..b449b98 100644
29927--- a/arch/x86/lib/csum-wrappers_64.c
29928+++ b/arch/x86/lib/csum-wrappers_64.c
29929@@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
29930 len -= 2;
29931 }
29932 }
29933+ pax_open_userland();
29934 stac();
29935- isum = csum_partial_copy_generic((__force const void *)src,
29936+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
29937 dst, len, isum, errp, NULL);
29938 clac();
29939+ pax_close_userland();
29940 if (unlikely(*errp))
29941 goto out_err;
29942
29943@@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
29944 }
29945
29946 *errp = 0;
29947+ pax_open_userland();
29948 stac();
29949- ret = csum_partial_copy_generic(src, (void __force *)dst,
29950+ ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
29951 len, isum, NULL, errp);
29952 clac();
29953+ pax_close_userland();
29954 return ret;
29955 }
29956 EXPORT_SYMBOL(csum_partial_copy_to_user);
29957diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
29958index a451235..1daa956 100644
29959--- a/arch/x86/lib/getuser.S
29960+++ b/arch/x86/lib/getuser.S
29961@@ -33,17 +33,40 @@
29962 #include <asm/thread_info.h>
29963 #include <asm/asm.h>
29964 #include <asm/smap.h>
29965+#include <asm/segment.h>
29966+#include <asm/pgtable.h>
29967+#include <asm/alternative-asm.h>
29968+
29969+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
29970+#define __copyuser_seg gs;
29971+#else
29972+#define __copyuser_seg
29973+#endif
29974
29975 .text
29976 ENTRY(__get_user_1)
29977 CFI_STARTPROC
29978+
29979+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29980 GET_THREAD_INFO(%_ASM_DX)
29981 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29982 jae bad_get_user
29983 ASM_STAC
29984-1: movzbl (%_ASM_AX),%edx
29985+
29986+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29987+ mov pax_user_shadow_base,%_ASM_DX
29988+ cmp %_ASM_DX,%_ASM_AX
29989+ jae 1234f
29990+ add %_ASM_DX,%_ASM_AX
29991+1234:
29992+#endif
29993+
29994+#endif
29995+
29996+1: __copyuser_seg movzbl (%_ASM_AX),%edx
29997 xor %eax,%eax
29998 ASM_CLAC
29999+ pax_force_retaddr
30000 ret
30001 CFI_ENDPROC
30002 ENDPROC(__get_user_1)
30003@@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
30004 ENTRY(__get_user_2)
30005 CFI_STARTPROC
30006 add $1,%_ASM_AX
30007+
30008+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30009 jc bad_get_user
30010 GET_THREAD_INFO(%_ASM_DX)
30011 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30012 jae bad_get_user
30013 ASM_STAC
30014-2: movzwl -1(%_ASM_AX),%edx
30015+
30016+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30017+ mov pax_user_shadow_base,%_ASM_DX
30018+ cmp %_ASM_DX,%_ASM_AX
30019+ jae 1234f
30020+ add %_ASM_DX,%_ASM_AX
30021+1234:
30022+#endif
30023+
30024+#endif
30025+
30026+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
30027 xor %eax,%eax
30028 ASM_CLAC
30029+ pax_force_retaddr
30030 ret
30031 CFI_ENDPROC
30032 ENDPROC(__get_user_2)
30033@@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
30034 ENTRY(__get_user_4)
30035 CFI_STARTPROC
30036 add $3,%_ASM_AX
30037+
30038+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30039 jc bad_get_user
30040 GET_THREAD_INFO(%_ASM_DX)
30041 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30042 jae bad_get_user
30043 ASM_STAC
30044-3: movl -3(%_ASM_AX),%edx
30045+
30046+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30047+ mov pax_user_shadow_base,%_ASM_DX
30048+ cmp %_ASM_DX,%_ASM_AX
30049+ jae 1234f
30050+ add %_ASM_DX,%_ASM_AX
30051+1234:
30052+#endif
30053+
30054+#endif
30055+
30056+3: __copyuser_seg movl -3(%_ASM_AX),%edx
30057 xor %eax,%eax
30058 ASM_CLAC
30059+ pax_force_retaddr
30060 ret
30061 CFI_ENDPROC
30062 ENDPROC(__get_user_4)
30063@@ -86,10 +137,20 @@ ENTRY(__get_user_8)
30064 GET_THREAD_INFO(%_ASM_DX)
30065 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30066 jae bad_get_user
30067+
30068+#ifdef CONFIG_PAX_MEMORY_UDEREF
30069+ mov pax_user_shadow_base,%_ASM_DX
30070+ cmp %_ASM_DX,%_ASM_AX
30071+ jae 1234f
30072+ add %_ASM_DX,%_ASM_AX
30073+1234:
30074+#endif
30075+
30076 ASM_STAC
30077 4: movq -7(%_ASM_AX),%rdx
30078 xor %eax,%eax
30079 ASM_CLAC
30080+ pax_force_retaddr
30081 ret
30082 #else
30083 add $7,%_ASM_AX
30084@@ -98,10 +159,11 @@ ENTRY(__get_user_8)
30085 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30086 jae bad_get_user_8
30087 ASM_STAC
30088-4: movl -7(%_ASM_AX),%edx
30089-5: movl -3(%_ASM_AX),%ecx
30090+4: __copyuser_seg movl -7(%_ASM_AX),%edx
30091+5: __copyuser_seg movl -3(%_ASM_AX),%ecx
30092 xor %eax,%eax
30093 ASM_CLAC
30094+ pax_force_retaddr
30095 ret
30096 #endif
30097 CFI_ENDPROC
30098@@ -113,6 +175,7 @@ bad_get_user:
30099 xor %edx,%edx
30100 mov $(-EFAULT),%_ASM_AX
30101 ASM_CLAC
30102+ pax_force_retaddr
30103 ret
30104 CFI_ENDPROC
30105 END(bad_get_user)
30106@@ -124,6 +187,7 @@ bad_get_user_8:
30107 xor %ecx,%ecx
30108 mov $(-EFAULT),%_ASM_AX
30109 ASM_CLAC
30110+ pax_force_retaddr
30111 ret
30112 CFI_ENDPROC
30113 END(bad_get_user_8)
30114diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
30115index 54fcffe..7be149e 100644
30116--- a/arch/x86/lib/insn.c
30117+++ b/arch/x86/lib/insn.c
30118@@ -20,8 +20,10 @@
30119
30120 #ifdef __KERNEL__
30121 #include <linux/string.h>
30122+#include <asm/pgtable_types.h>
30123 #else
30124 #include <string.h>
30125+#define ktla_ktva(addr) addr
30126 #endif
30127 #include <asm/inat.h>
30128 #include <asm/insn.h>
30129@@ -53,8 +55,8 @@
30130 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
30131 {
30132 memset(insn, 0, sizeof(*insn));
30133- insn->kaddr = kaddr;
30134- insn->next_byte = kaddr;
30135+ insn->kaddr = ktla_ktva(kaddr);
30136+ insn->next_byte = ktla_ktva(kaddr);
30137 insn->x86_64 = x86_64 ? 1 : 0;
30138 insn->opnd_bytes = 4;
30139 if (x86_64)
30140diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
30141index 05a95e7..326f2fa 100644
30142--- a/arch/x86/lib/iomap_copy_64.S
30143+++ b/arch/x86/lib/iomap_copy_64.S
30144@@ -17,6 +17,7 @@
30145
30146 #include <linux/linkage.h>
30147 #include <asm/dwarf2.h>
30148+#include <asm/alternative-asm.h>
30149
30150 /*
30151 * override generic version in lib/iomap_copy.c
30152@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
30153 CFI_STARTPROC
30154 movl %edx,%ecx
30155 rep movsd
30156+ pax_force_retaddr
30157 ret
30158 CFI_ENDPROC
30159 ENDPROC(__iowrite32_copy)
30160diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
30161index 56313a3..0db417e 100644
30162--- a/arch/x86/lib/memcpy_64.S
30163+++ b/arch/x86/lib/memcpy_64.S
30164@@ -24,7 +24,7 @@
30165 * This gets patched over the unrolled variant (below) via the
30166 * alternative instructions framework:
30167 */
30168- .section .altinstr_replacement, "ax", @progbits
30169+ .section .altinstr_replacement, "a", @progbits
30170 .Lmemcpy_c:
30171 movq %rdi, %rax
30172 movq %rdx, %rcx
30173@@ -33,6 +33,7 @@
30174 rep movsq
30175 movl %edx, %ecx
30176 rep movsb
30177+ pax_force_retaddr
30178 ret
30179 .Lmemcpy_e:
30180 .previous
30181@@ -44,11 +45,12 @@
30182 * This gets patched over the unrolled variant (below) via the
30183 * alternative instructions framework:
30184 */
30185- .section .altinstr_replacement, "ax", @progbits
30186+ .section .altinstr_replacement, "a", @progbits
30187 .Lmemcpy_c_e:
30188 movq %rdi, %rax
30189 movq %rdx, %rcx
30190 rep movsb
30191+ pax_force_retaddr
30192 ret
30193 .Lmemcpy_e_e:
30194 .previous
30195@@ -136,6 +138,7 @@ ENTRY(memcpy)
30196 movq %r9, 1*8(%rdi)
30197 movq %r10, -2*8(%rdi, %rdx)
30198 movq %r11, -1*8(%rdi, %rdx)
30199+ pax_force_retaddr
30200 retq
30201 .p2align 4
30202 .Lless_16bytes:
30203@@ -148,6 +151,7 @@ ENTRY(memcpy)
30204 movq -1*8(%rsi, %rdx), %r9
30205 movq %r8, 0*8(%rdi)
30206 movq %r9, -1*8(%rdi, %rdx)
30207+ pax_force_retaddr
30208 retq
30209 .p2align 4
30210 .Lless_8bytes:
30211@@ -161,6 +165,7 @@ ENTRY(memcpy)
30212 movl -4(%rsi, %rdx), %r8d
30213 movl %ecx, (%rdi)
30214 movl %r8d, -4(%rdi, %rdx)
30215+ pax_force_retaddr
30216 retq
30217 .p2align 4
30218 .Lless_3bytes:
30219@@ -179,6 +184,7 @@ ENTRY(memcpy)
30220 movb %cl, (%rdi)
30221
30222 .Lend:
30223+ pax_force_retaddr
30224 retq
30225 CFI_ENDPROC
30226 ENDPROC(memcpy)
30227diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
30228index 65268a6..dd1de11 100644
30229--- a/arch/x86/lib/memmove_64.S
30230+++ b/arch/x86/lib/memmove_64.S
30231@@ -202,14 +202,16 @@ ENTRY(memmove)
30232 movb (%rsi), %r11b
30233 movb %r11b, (%rdi)
30234 13:
30235+ pax_force_retaddr
30236 retq
30237 CFI_ENDPROC
30238
30239- .section .altinstr_replacement,"ax"
30240+ .section .altinstr_replacement,"a"
30241 .Lmemmove_begin_forward_efs:
30242 /* Forward moving data. */
30243 movq %rdx, %rcx
30244 rep movsb
30245+ pax_force_retaddr
30246 retq
30247 .Lmemmove_end_forward_efs:
30248 .previous
30249diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
30250index 2dcb380..2eb79fe 100644
30251--- a/arch/x86/lib/memset_64.S
30252+++ b/arch/x86/lib/memset_64.S
30253@@ -16,7 +16,7 @@
30254 *
30255 * rax original destination
30256 */
30257- .section .altinstr_replacement, "ax", @progbits
30258+ .section .altinstr_replacement, "a", @progbits
30259 .Lmemset_c:
30260 movq %rdi,%r9
30261 movq %rdx,%rcx
30262@@ -30,6 +30,7 @@
30263 movl %edx,%ecx
30264 rep stosb
30265 movq %r9,%rax
30266+ pax_force_retaddr
30267 ret
30268 .Lmemset_e:
30269 .previous
30270@@ -45,13 +46,14 @@
30271 *
30272 * rax original destination
30273 */
30274- .section .altinstr_replacement, "ax", @progbits
30275+ .section .altinstr_replacement, "a", @progbits
30276 .Lmemset_c_e:
30277 movq %rdi,%r9
30278 movb %sil,%al
30279 movq %rdx,%rcx
30280 rep stosb
30281 movq %r9,%rax
30282+ pax_force_retaddr
30283 ret
30284 .Lmemset_e_e:
30285 .previous
30286@@ -118,6 +120,7 @@ ENTRY(__memset)
30287
30288 .Lende:
30289 movq %r10,%rax
30290+ pax_force_retaddr
30291 ret
30292
30293 CFI_RESTORE_STATE
30294diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
30295index c9f2d9b..e7fd2c0 100644
30296--- a/arch/x86/lib/mmx_32.c
30297+++ b/arch/x86/lib/mmx_32.c
30298@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30299 {
30300 void *p;
30301 int i;
30302+ unsigned long cr0;
30303
30304 if (unlikely(in_interrupt()))
30305 return __memcpy(to, from, len);
30306@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30307 kernel_fpu_begin();
30308
30309 __asm__ __volatile__ (
30310- "1: prefetch (%0)\n" /* This set is 28 bytes */
30311- " prefetch 64(%0)\n"
30312- " prefetch 128(%0)\n"
30313- " prefetch 192(%0)\n"
30314- " prefetch 256(%0)\n"
30315+ "1: prefetch (%1)\n" /* This set is 28 bytes */
30316+ " prefetch 64(%1)\n"
30317+ " prefetch 128(%1)\n"
30318+ " prefetch 192(%1)\n"
30319+ " prefetch 256(%1)\n"
30320 "2: \n"
30321 ".section .fixup, \"ax\"\n"
30322- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30323+ "3: \n"
30324+
30325+#ifdef CONFIG_PAX_KERNEXEC
30326+ " movl %%cr0, %0\n"
30327+ " movl %0, %%eax\n"
30328+ " andl $0xFFFEFFFF, %%eax\n"
30329+ " movl %%eax, %%cr0\n"
30330+#endif
30331+
30332+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30333+
30334+#ifdef CONFIG_PAX_KERNEXEC
30335+ " movl %0, %%cr0\n"
30336+#endif
30337+
30338 " jmp 2b\n"
30339 ".previous\n"
30340 _ASM_EXTABLE(1b, 3b)
30341- : : "r" (from));
30342+ : "=&r" (cr0) : "r" (from) : "ax");
30343
30344 for ( ; i > 5; i--) {
30345 __asm__ __volatile__ (
30346- "1: prefetch 320(%0)\n"
30347- "2: movq (%0), %%mm0\n"
30348- " movq 8(%0), %%mm1\n"
30349- " movq 16(%0), %%mm2\n"
30350- " movq 24(%0), %%mm3\n"
30351- " movq %%mm0, (%1)\n"
30352- " movq %%mm1, 8(%1)\n"
30353- " movq %%mm2, 16(%1)\n"
30354- " movq %%mm3, 24(%1)\n"
30355- " movq 32(%0), %%mm0\n"
30356- " movq 40(%0), %%mm1\n"
30357- " movq 48(%0), %%mm2\n"
30358- " movq 56(%0), %%mm3\n"
30359- " movq %%mm0, 32(%1)\n"
30360- " movq %%mm1, 40(%1)\n"
30361- " movq %%mm2, 48(%1)\n"
30362- " movq %%mm3, 56(%1)\n"
30363+ "1: prefetch 320(%1)\n"
30364+ "2: movq (%1), %%mm0\n"
30365+ " movq 8(%1), %%mm1\n"
30366+ " movq 16(%1), %%mm2\n"
30367+ " movq 24(%1), %%mm3\n"
30368+ " movq %%mm0, (%2)\n"
30369+ " movq %%mm1, 8(%2)\n"
30370+ " movq %%mm2, 16(%2)\n"
30371+ " movq %%mm3, 24(%2)\n"
30372+ " movq 32(%1), %%mm0\n"
30373+ " movq 40(%1), %%mm1\n"
30374+ " movq 48(%1), %%mm2\n"
30375+ " movq 56(%1), %%mm3\n"
30376+ " movq %%mm0, 32(%2)\n"
30377+ " movq %%mm1, 40(%2)\n"
30378+ " movq %%mm2, 48(%2)\n"
30379+ " movq %%mm3, 56(%2)\n"
30380 ".section .fixup, \"ax\"\n"
30381- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30382+ "3:\n"
30383+
30384+#ifdef CONFIG_PAX_KERNEXEC
30385+ " movl %%cr0, %0\n"
30386+ " movl %0, %%eax\n"
30387+ " andl $0xFFFEFFFF, %%eax\n"
30388+ " movl %%eax, %%cr0\n"
30389+#endif
30390+
30391+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30392+
30393+#ifdef CONFIG_PAX_KERNEXEC
30394+ " movl %0, %%cr0\n"
30395+#endif
30396+
30397 " jmp 2b\n"
30398 ".previous\n"
30399 _ASM_EXTABLE(1b, 3b)
30400- : : "r" (from), "r" (to) : "memory");
30401+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30402
30403 from += 64;
30404 to += 64;
30405@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
30406 static void fast_copy_page(void *to, void *from)
30407 {
30408 int i;
30409+ unsigned long cr0;
30410
30411 kernel_fpu_begin();
30412
30413@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
30414 * but that is for later. -AV
30415 */
30416 __asm__ __volatile__(
30417- "1: prefetch (%0)\n"
30418- " prefetch 64(%0)\n"
30419- " prefetch 128(%0)\n"
30420- " prefetch 192(%0)\n"
30421- " prefetch 256(%0)\n"
30422+ "1: prefetch (%1)\n"
30423+ " prefetch 64(%1)\n"
30424+ " prefetch 128(%1)\n"
30425+ " prefetch 192(%1)\n"
30426+ " prefetch 256(%1)\n"
30427 "2: \n"
30428 ".section .fixup, \"ax\"\n"
30429- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30430+ "3: \n"
30431+
30432+#ifdef CONFIG_PAX_KERNEXEC
30433+ " movl %%cr0, %0\n"
30434+ " movl %0, %%eax\n"
30435+ " andl $0xFFFEFFFF, %%eax\n"
30436+ " movl %%eax, %%cr0\n"
30437+#endif
30438+
30439+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30440+
30441+#ifdef CONFIG_PAX_KERNEXEC
30442+ " movl %0, %%cr0\n"
30443+#endif
30444+
30445 " jmp 2b\n"
30446 ".previous\n"
30447- _ASM_EXTABLE(1b, 3b) : : "r" (from));
30448+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30449
30450 for (i = 0; i < (4096-320)/64; i++) {
30451 __asm__ __volatile__ (
30452- "1: prefetch 320(%0)\n"
30453- "2: movq (%0), %%mm0\n"
30454- " movntq %%mm0, (%1)\n"
30455- " movq 8(%0), %%mm1\n"
30456- " movntq %%mm1, 8(%1)\n"
30457- " movq 16(%0), %%mm2\n"
30458- " movntq %%mm2, 16(%1)\n"
30459- " movq 24(%0), %%mm3\n"
30460- " movntq %%mm3, 24(%1)\n"
30461- " movq 32(%0), %%mm4\n"
30462- " movntq %%mm4, 32(%1)\n"
30463- " movq 40(%0), %%mm5\n"
30464- " movntq %%mm5, 40(%1)\n"
30465- " movq 48(%0), %%mm6\n"
30466- " movntq %%mm6, 48(%1)\n"
30467- " movq 56(%0), %%mm7\n"
30468- " movntq %%mm7, 56(%1)\n"
30469+ "1: prefetch 320(%1)\n"
30470+ "2: movq (%1), %%mm0\n"
30471+ " movntq %%mm0, (%2)\n"
30472+ " movq 8(%1), %%mm1\n"
30473+ " movntq %%mm1, 8(%2)\n"
30474+ " movq 16(%1), %%mm2\n"
30475+ " movntq %%mm2, 16(%2)\n"
30476+ " movq 24(%1), %%mm3\n"
30477+ " movntq %%mm3, 24(%2)\n"
30478+ " movq 32(%1), %%mm4\n"
30479+ " movntq %%mm4, 32(%2)\n"
30480+ " movq 40(%1), %%mm5\n"
30481+ " movntq %%mm5, 40(%2)\n"
30482+ " movq 48(%1), %%mm6\n"
30483+ " movntq %%mm6, 48(%2)\n"
30484+ " movq 56(%1), %%mm7\n"
30485+ " movntq %%mm7, 56(%2)\n"
30486 ".section .fixup, \"ax\"\n"
30487- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30488+ "3:\n"
30489+
30490+#ifdef CONFIG_PAX_KERNEXEC
30491+ " movl %%cr0, %0\n"
30492+ " movl %0, %%eax\n"
30493+ " andl $0xFFFEFFFF, %%eax\n"
30494+ " movl %%eax, %%cr0\n"
30495+#endif
30496+
30497+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30498+
30499+#ifdef CONFIG_PAX_KERNEXEC
30500+ " movl %0, %%cr0\n"
30501+#endif
30502+
30503 " jmp 2b\n"
30504 ".previous\n"
30505- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
30506+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30507
30508 from += 64;
30509 to += 64;
30510@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
30511 static void fast_copy_page(void *to, void *from)
30512 {
30513 int i;
30514+ unsigned long cr0;
30515
30516 kernel_fpu_begin();
30517
30518 __asm__ __volatile__ (
30519- "1: prefetch (%0)\n"
30520- " prefetch 64(%0)\n"
30521- " prefetch 128(%0)\n"
30522- " prefetch 192(%0)\n"
30523- " prefetch 256(%0)\n"
30524+ "1: prefetch (%1)\n"
30525+ " prefetch 64(%1)\n"
30526+ " prefetch 128(%1)\n"
30527+ " prefetch 192(%1)\n"
30528+ " prefetch 256(%1)\n"
30529 "2: \n"
30530 ".section .fixup, \"ax\"\n"
30531- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30532+ "3: \n"
30533+
30534+#ifdef CONFIG_PAX_KERNEXEC
30535+ " movl %%cr0, %0\n"
30536+ " movl %0, %%eax\n"
30537+ " andl $0xFFFEFFFF, %%eax\n"
30538+ " movl %%eax, %%cr0\n"
30539+#endif
30540+
30541+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30542+
30543+#ifdef CONFIG_PAX_KERNEXEC
30544+ " movl %0, %%cr0\n"
30545+#endif
30546+
30547 " jmp 2b\n"
30548 ".previous\n"
30549- _ASM_EXTABLE(1b, 3b) : : "r" (from));
30550+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30551
30552 for (i = 0; i < 4096/64; i++) {
30553 __asm__ __volatile__ (
30554- "1: prefetch 320(%0)\n"
30555- "2: movq (%0), %%mm0\n"
30556- " movq 8(%0), %%mm1\n"
30557- " movq 16(%0), %%mm2\n"
30558- " movq 24(%0), %%mm3\n"
30559- " movq %%mm0, (%1)\n"
30560- " movq %%mm1, 8(%1)\n"
30561- " movq %%mm2, 16(%1)\n"
30562- " movq %%mm3, 24(%1)\n"
30563- " movq 32(%0), %%mm0\n"
30564- " movq 40(%0), %%mm1\n"
30565- " movq 48(%0), %%mm2\n"
30566- " movq 56(%0), %%mm3\n"
30567- " movq %%mm0, 32(%1)\n"
30568- " movq %%mm1, 40(%1)\n"
30569- " movq %%mm2, 48(%1)\n"
30570- " movq %%mm3, 56(%1)\n"
30571+ "1: prefetch 320(%1)\n"
30572+ "2: movq (%1), %%mm0\n"
30573+ " movq 8(%1), %%mm1\n"
30574+ " movq 16(%1), %%mm2\n"
30575+ " movq 24(%1), %%mm3\n"
30576+ " movq %%mm0, (%2)\n"
30577+ " movq %%mm1, 8(%2)\n"
30578+ " movq %%mm2, 16(%2)\n"
30579+ " movq %%mm3, 24(%2)\n"
30580+ " movq 32(%1), %%mm0\n"
30581+ " movq 40(%1), %%mm1\n"
30582+ " movq 48(%1), %%mm2\n"
30583+ " movq 56(%1), %%mm3\n"
30584+ " movq %%mm0, 32(%2)\n"
30585+ " movq %%mm1, 40(%2)\n"
30586+ " movq %%mm2, 48(%2)\n"
30587+ " movq %%mm3, 56(%2)\n"
30588 ".section .fixup, \"ax\"\n"
30589- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30590+ "3:\n"
30591+
30592+#ifdef CONFIG_PAX_KERNEXEC
30593+ " movl %%cr0, %0\n"
30594+ " movl %0, %%eax\n"
30595+ " andl $0xFFFEFFFF, %%eax\n"
30596+ " movl %%eax, %%cr0\n"
30597+#endif
30598+
30599+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30600+
30601+#ifdef CONFIG_PAX_KERNEXEC
30602+ " movl %0, %%cr0\n"
30603+#endif
30604+
30605 " jmp 2b\n"
30606 ".previous\n"
30607 _ASM_EXTABLE(1b, 3b)
30608- : : "r" (from), "r" (to) : "memory");
30609+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30610
30611 from += 64;
30612 to += 64;
30613diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
30614index f6d13ee..d789440 100644
30615--- a/arch/x86/lib/msr-reg.S
30616+++ b/arch/x86/lib/msr-reg.S
30617@@ -3,6 +3,7 @@
30618 #include <asm/dwarf2.h>
30619 #include <asm/asm.h>
30620 #include <asm/msr.h>
30621+#include <asm/alternative-asm.h>
30622
30623 #ifdef CONFIG_X86_64
30624 /*
30625@@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
30626 movl %edi, 28(%r10)
30627 popq_cfi %rbp
30628 popq_cfi %rbx
30629+ pax_force_retaddr
30630 ret
30631 3:
30632 CFI_RESTORE_STATE
30633diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
30634index fc6ba17..d4d989d 100644
30635--- a/arch/x86/lib/putuser.S
30636+++ b/arch/x86/lib/putuser.S
30637@@ -16,7 +16,9 @@
30638 #include <asm/errno.h>
30639 #include <asm/asm.h>
30640 #include <asm/smap.h>
30641-
30642+#include <asm/segment.h>
30643+#include <asm/pgtable.h>
30644+#include <asm/alternative-asm.h>
30645
30646 /*
30647 * __put_user_X
30648@@ -30,57 +32,125 @@
30649 * as they get called from within inline assembly.
30650 */
30651
30652-#define ENTER CFI_STARTPROC ; \
30653- GET_THREAD_INFO(%_ASM_BX)
30654-#define EXIT ASM_CLAC ; \
30655- ret ; \
30656+#define ENTER CFI_STARTPROC
30657+#define EXIT ASM_CLAC ; \
30658+ pax_force_retaddr ; \
30659+ ret ; \
30660 CFI_ENDPROC
30661
30662+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30663+#define _DEST %_ASM_CX,%_ASM_BX
30664+#else
30665+#define _DEST %_ASM_CX
30666+#endif
30667+
30668+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30669+#define __copyuser_seg gs;
30670+#else
30671+#define __copyuser_seg
30672+#endif
30673+
30674 .text
30675 ENTRY(__put_user_1)
30676 ENTER
30677+
30678+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30679+ GET_THREAD_INFO(%_ASM_BX)
30680 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
30681 jae bad_put_user
30682 ASM_STAC
30683-1: movb %al,(%_ASM_CX)
30684+
30685+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30686+ mov pax_user_shadow_base,%_ASM_BX
30687+ cmp %_ASM_BX,%_ASM_CX
30688+ jb 1234f
30689+ xor %ebx,%ebx
30690+1234:
30691+#endif
30692+
30693+#endif
30694+
30695+1: __copyuser_seg movb %al,(_DEST)
30696 xor %eax,%eax
30697 EXIT
30698 ENDPROC(__put_user_1)
30699
30700 ENTRY(__put_user_2)
30701 ENTER
30702+
30703+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30704+ GET_THREAD_INFO(%_ASM_BX)
30705 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30706 sub $1,%_ASM_BX
30707 cmp %_ASM_BX,%_ASM_CX
30708 jae bad_put_user
30709 ASM_STAC
30710-2: movw %ax,(%_ASM_CX)
30711+
30712+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30713+ mov pax_user_shadow_base,%_ASM_BX
30714+ cmp %_ASM_BX,%_ASM_CX
30715+ jb 1234f
30716+ xor %ebx,%ebx
30717+1234:
30718+#endif
30719+
30720+#endif
30721+
30722+2: __copyuser_seg movw %ax,(_DEST)
30723 xor %eax,%eax
30724 EXIT
30725 ENDPROC(__put_user_2)
30726
30727 ENTRY(__put_user_4)
30728 ENTER
30729+
30730+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30731+ GET_THREAD_INFO(%_ASM_BX)
30732 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30733 sub $3,%_ASM_BX
30734 cmp %_ASM_BX,%_ASM_CX
30735 jae bad_put_user
30736 ASM_STAC
30737-3: movl %eax,(%_ASM_CX)
30738+
30739+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30740+ mov pax_user_shadow_base,%_ASM_BX
30741+ cmp %_ASM_BX,%_ASM_CX
30742+ jb 1234f
30743+ xor %ebx,%ebx
30744+1234:
30745+#endif
30746+
30747+#endif
30748+
30749+3: __copyuser_seg movl %eax,(_DEST)
30750 xor %eax,%eax
30751 EXIT
30752 ENDPROC(__put_user_4)
30753
30754 ENTRY(__put_user_8)
30755 ENTER
30756+
30757+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30758+ GET_THREAD_INFO(%_ASM_BX)
30759 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30760 sub $7,%_ASM_BX
30761 cmp %_ASM_BX,%_ASM_CX
30762 jae bad_put_user
30763 ASM_STAC
30764-4: mov %_ASM_AX,(%_ASM_CX)
30765+
30766+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30767+ mov pax_user_shadow_base,%_ASM_BX
30768+ cmp %_ASM_BX,%_ASM_CX
30769+ jb 1234f
30770+ xor %ebx,%ebx
30771+1234:
30772+#endif
30773+
30774+#endif
30775+
30776+4: __copyuser_seg mov %_ASM_AX,(_DEST)
30777 #ifdef CONFIG_X86_32
30778-5: movl %edx,4(%_ASM_CX)
30779+5: __copyuser_seg movl %edx,4(_DEST)
30780 #endif
30781 xor %eax,%eax
30782 EXIT
30783diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
30784index 1cad221..de671ee 100644
30785--- a/arch/x86/lib/rwlock.S
30786+++ b/arch/x86/lib/rwlock.S
30787@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
30788 FRAME
30789 0: LOCK_PREFIX
30790 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30791+
30792+#ifdef CONFIG_PAX_REFCOUNT
30793+ jno 1234f
30794+ LOCK_PREFIX
30795+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30796+ int $4
30797+1234:
30798+ _ASM_EXTABLE(1234b, 1234b)
30799+#endif
30800+
30801 1: rep; nop
30802 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
30803 jne 1b
30804 LOCK_PREFIX
30805 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30806+
30807+#ifdef CONFIG_PAX_REFCOUNT
30808+ jno 1234f
30809+ LOCK_PREFIX
30810+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30811+ int $4
30812+1234:
30813+ _ASM_EXTABLE(1234b, 1234b)
30814+#endif
30815+
30816 jnz 0b
30817 ENDFRAME
30818+ pax_force_retaddr
30819 ret
30820 CFI_ENDPROC
30821 END(__write_lock_failed)
30822@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
30823 FRAME
30824 0: LOCK_PREFIX
30825 READ_LOCK_SIZE(inc) (%__lock_ptr)
30826+
30827+#ifdef CONFIG_PAX_REFCOUNT
30828+ jno 1234f
30829+ LOCK_PREFIX
30830+ READ_LOCK_SIZE(dec) (%__lock_ptr)
30831+ int $4
30832+1234:
30833+ _ASM_EXTABLE(1234b, 1234b)
30834+#endif
30835+
30836 1: rep; nop
30837 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
30838 js 1b
30839 LOCK_PREFIX
30840 READ_LOCK_SIZE(dec) (%__lock_ptr)
30841+
30842+#ifdef CONFIG_PAX_REFCOUNT
30843+ jno 1234f
30844+ LOCK_PREFIX
30845+ READ_LOCK_SIZE(inc) (%__lock_ptr)
30846+ int $4
30847+1234:
30848+ _ASM_EXTABLE(1234b, 1234b)
30849+#endif
30850+
30851 js 0b
30852 ENDFRAME
30853+ pax_force_retaddr
30854 ret
30855 CFI_ENDPROC
30856 END(__read_lock_failed)
30857diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
30858index 5dff5f0..cadebf4 100644
30859--- a/arch/x86/lib/rwsem.S
30860+++ b/arch/x86/lib/rwsem.S
30861@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
30862 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30863 CFI_RESTORE __ASM_REG(dx)
30864 restore_common_regs
30865+ pax_force_retaddr
30866 ret
30867 CFI_ENDPROC
30868 ENDPROC(call_rwsem_down_read_failed)
30869@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
30870 movq %rax,%rdi
30871 call rwsem_down_write_failed
30872 restore_common_regs
30873+ pax_force_retaddr
30874 ret
30875 CFI_ENDPROC
30876 ENDPROC(call_rwsem_down_write_failed)
30877@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
30878 movq %rax,%rdi
30879 call rwsem_wake
30880 restore_common_regs
30881-1: ret
30882+1: pax_force_retaddr
30883+ ret
30884 CFI_ENDPROC
30885 ENDPROC(call_rwsem_wake)
30886
30887@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
30888 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30889 CFI_RESTORE __ASM_REG(dx)
30890 restore_common_regs
30891+ pax_force_retaddr
30892 ret
30893 CFI_ENDPROC
30894 ENDPROC(call_rwsem_downgrade_wake)
30895diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
30896index a63efd6..8149fbe 100644
30897--- a/arch/x86/lib/thunk_64.S
30898+++ b/arch/x86/lib/thunk_64.S
30899@@ -8,6 +8,7 @@
30900 #include <linux/linkage.h>
30901 #include <asm/dwarf2.h>
30902 #include <asm/calling.h>
30903+#include <asm/alternative-asm.h>
30904
30905 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
30906 .macro THUNK name, func, put_ret_addr_in_rdi=0
30907@@ -15,11 +16,11 @@
30908 \name:
30909 CFI_STARTPROC
30910
30911- /* this one pushes 9 elems, the next one would be %rIP */
30912- SAVE_ARGS
30913+ /* this one pushes 15+1 elems, the next one would be %rIP */
30914+ SAVE_ARGS 8
30915
30916 .if \put_ret_addr_in_rdi
30917- movq_cfi_restore 9*8, rdi
30918+ movq_cfi_restore RIP, rdi
30919 .endif
30920
30921 call \func
30922@@ -38,8 +39,9 @@
30923
30924 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
30925 CFI_STARTPROC
30926- SAVE_ARGS
30927+ SAVE_ARGS 8
30928 restore:
30929- RESTORE_ARGS
30930+ RESTORE_ARGS 1,8
30931+ pax_force_retaddr
30932 ret
30933 CFI_ENDPROC
30934diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
30935index e2f5e21..4b22130 100644
30936--- a/arch/x86/lib/usercopy_32.c
30937+++ b/arch/x86/lib/usercopy_32.c
30938@@ -42,11 +42,13 @@ do { \
30939 int __d0; \
30940 might_fault(); \
30941 __asm__ __volatile__( \
30942+ __COPYUSER_SET_ES \
30943 ASM_STAC "\n" \
30944 "0: rep; stosl\n" \
30945 " movl %2,%0\n" \
30946 "1: rep; stosb\n" \
30947 "2: " ASM_CLAC "\n" \
30948+ __COPYUSER_RESTORE_ES \
30949 ".section .fixup,\"ax\"\n" \
30950 "3: lea 0(%2,%0,4),%0\n" \
30951 " jmp 2b\n" \
30952@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
30953
30954 #ifdef CONFIG_X86_INTEL_USERCOPY
30955 static unsigned long
30956-__copy_user_intel(void __user *to, const void *from, unsigned long size)
30957+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
30958 {
30959 int d0, d1;
30960 __asm__ __volatile__(
30961@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30962 " .align 2,0x90\n"
30963 "3: movl 0(%4), %%eax\n"
30964 "4: movl 4(%4), %%edx\n"
30965- "5: movl %%eax, 0(%3)\n"
30966- "6: movl %%edx, 4(%3)\n"
30967+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
30968+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
30969 "7: movl 8(%4), %%eax\n"
30970 "8: movl 12(%4),%%edx\n"
30971- "9: movl %%eax, 8(%3)\n"
30972- "10: movl %%edx, 12(%3)\n"
30973+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
30974+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
30975 "11: movl 16(%4), %%eax\n"
30976 "12: movl 20(%4), %%edx\n"
30977- "13: movl %%eax, 16(%3)\n"
30978- "14: movl %%edx, 20(%3)\n"
30979+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
30980+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
30981 "15: movl 24(%4), %%eax\n"
30982 "16: movl 28(%4), %%edx\n"
30983- "17: movl %%eax, 24(%3)\n"
30984- "18: movl %%edx, 28(%3)\n"
30985+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
30986+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
30987 "19: movl 32(%4), %%eax\n"
30988 "20: movl 36(%4), %%edx\n"
30989- "21: movl %%eax, 32(%3)\n"
30990- "22: movl %%edx, 36(%3)\n"
30991+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
30992+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
30993 "23: movl 40(%4), %%eax\n"
30994 "24: movl 44(%4), %%edx\n"
30995- "25: movl %%eax, 40(%3)\n"
30996- "26: movl %%edx, 44(%3)\n"
30997+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
30998+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
30999 "27: movl 48(%4), %%eax\n"
31000 "28: movl 52(%4), %%edx\n"
31001- "29: movl %%eax, 48(%3)\n"
31002- "30: movl %%edx, 52(%3)\n"
31003+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
31004+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
31005 "31: movl 56(%4), %%eax\n"
31006 "32: movl 60(%4), %%edx\n"
31007- "33: movl %%eax, 56(%3)\n"
31008- "34: movl %%edx, 60(%3)\n"
31009+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
31010+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
31011 " addl $-64, %0\n"
31012 " addl $64, %4\n"
31013 " addl $64, %3\n"
31014@@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
31015 " shrl $2, %0\n"
31016 " andl $3, %%eax\n"
31017 " cld\n"
31018+ __COPYUSER_SET_ES
31019 "99: rep; movsl\n"
31020 "36: movl %%eax, %0\n"
31021 "37: rep; movsb\n"
31022 "100:\n"
31023+ __COPYUSER_RESTORE_ES
31024+ ".section .fixup,\"ax\"\n"
31025+ "101: lea 0(%%eax,%0,4),%0\n"
31026+ " jmp 100b\n"
31027+ ".previous\n"
31028+ _ASM_EXTABLE(1b,100b)
31029+ _ASM_EXTABLE(2b,100b)
31030+ _ASM_EXTABLE(3b,100b)
31031+ _ASM_EXTABLE(4b,100b)
31032+ _ASM_EXTABLE(5b,100b)
31033+ _ASM_EXTABLE(6b,100b)
31034+ _ASM_EXTABLE(7b,100b)
31035+ _ASM_EXTABLE(8b,100b)
31036+ _ASM_EXTABLE(9b,100b)
31037+ _ASM_EXTABLE(10b,100b)
31038+ _ASM_EXTABLE(11b,100b)
31039+ _ASM_EXTABLE(12b,100b)
31040+ _ASM_EXTABLE(13b,100b)
31041+ _ASM_EXTABLE(14b,100b)
31042+ _ASM_EXTABLE(15b,100b)
31043+ _ASM_EXTABLE(16b,100b)
31044+ _ASM_EXTABLE(17b,100b)
31045+ _ASM_EXTABLE(18b,100b)
31046+ _ASM_EXTABLE(19b,100b)
31047+ _ASM_EXTABLE(20b,100b)
31048+ _ASM_EXTABLE(21b,100b)
31049+ _ASM_EXTABLE(22b,100b)
31050+ _ASM_EXTABLE(23b,100b)
31051+ _ASM_EXTABLE(24b,100b)
31052+ _ASM_EXTABLE(25b,100b)
31053+ _ASM_EXTABLE(26b,100b)
31054+ _ASM_EXTABLE(27b,100b)
31055+ _ASM_EXTABLE(28b,100b)
31056+ _ASM_EXTABLE(29b,100b)
31057+ _ASM_EXTABLE(30b,100b)
31058+ _ASM_EXTABLE(31b,100b)
31059+ _ASM_EXTABLE(32b,100b)
31060+ _ASM_EXTABLE(33b,100b)
31061+ _ASM_EXTABLE(34b,100b)
31062+ _ASM_EXTABLE(35b,100b)
31063+ _ASM_EXTABLE(36b,100b)
31064+ _ASM_EXTABLE(37b,100b)
31065+ _ASM_EXTABLE(99b,101b)
31066+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
31067+ : "1"(to), "2"(from), "0"(size)
31068+ : "eax", "edx", "memory");
31069+ return size;
31070+}
31071+
31072+static unsigned long
31073+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
31074+{
31075+ int d0, d1;
31076+ __asm__ __volatile__(
31077+ " .align 2,0x90\n"
31078+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
31079+ " cmpl $67, %0\n"
31080+ " jbe 3f\n"
31081+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
31082+ " .align 2,0x90\n"
31083+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
31084+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
31085+ "5: movl %%eax, 0(%3)\n"
31086+ "6: movl %%edx, 4(%3)\n"
31087+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
31088+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
31089+ "9: movl %%eax, 8(%3)\n"
31090+ "10: movl %%edx, 12(%3)\n"
31091+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
31092+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
31093+ "13: movl %%eax, 16(%3)\n"
31094+ "14: movl %%edx, 20(%3)\n"
31095+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
31096+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
31097+ "17: movl %%eax, 24(%3)\n"
31098+ "18: movl %%edx, 28(%3)\n"
31099+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
31100+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
31101+ "21: movl %%eax, 32(%3)\n"
31102+ "22: movl %%edx, 36(%3)\n"
31103+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
31104+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
31105+ "25: movl %%eax, 40(%3)\n"
31106+ "26: movl %%edx, 44(%3)\n"
31107+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
31108+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
31109+ "29: movl %%eax, 48(%3)\n"
31110+ "30: movl %%edx, 52(%3)\n"
31111+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
31112+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
31113+ "33: movl %%eax, 56(%3)\n"
31114+ "34: movl %%edx, 60(%3)\n"
31115+ " addl $-64, %0\n"
31116+ " addl $64, %4\n"
31117+ " addl $64, %3\n"
31118+ " cmpl $63, %0\n"
31119+ " ja 1b\n"
31120+ "35: movl %0, %%eax\n"
31121+ " shrl $2, %0\n"
31122+ " andl $3, %%eax\n"
31123+ " cld\n"
31124+ "99: rep; "__copyuser_seg" movsl\n"
31125+ "36: movl %%eax, %0\n"
31126+ "37: rep; "__copyuser_seg" movsb\n"
31127+ "100:\n"
31128 ".section .fixup,\"ax\"\n"
31129 "101: lea 0(%%eax,%0,4),%0\n"
31130 " jmp 100b\n"
31131@@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
31132 int d0, d1;
31133 __asm__ __volatile__(
31134 " .align 2,0x90\n"
31135- "0: movl 32(%4), %%eax\n"
31136+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31137 " cmpl $67, %0\n"
31138 " jbe 2f\n"
31139- "1: movl 64(%4), %%eax\n"
31140+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31141 " .align 2,0x90\n"
31142- "2: movl 0(%4), %%eax\n"
31143- "21: movl 4(%4), %%edx\n"
31144+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31145+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31146 " movl %%eax, 0(%3)\n"
31147 " movl %%edx, 4(%3)\n"
31148- "3: movl 8(%4), %%eax\n"
31149- "31: movl 12(%4),%%edx\n"
31150+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31151+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31152 " movl %%eax, 8(%3)\n"
31153 " movl %%edx, 12(%3)\n"
31154- "4: movl 16(%4), %%eax\n"
31155- "41: movl 20(%4), %%edx\n"
31156+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31157+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31158 " movl %%eax, 16(%3)\n"
31159 " movl %%edx, 20(%3)\n"
31160- "10: movl 24(%4), %%eax\n"
31161- "51: movl 28(%4), %%edx\n"
31162+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31163+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31164 " movl %%eax, 24(%3)\n"
31165 " movl %%edx, 28(%3)\n"
31166- "11: movl 32(%4), %%eax\n"
31167- "61: movl 36(%4), %%edx\n"
31168+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31169+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31170 " movl %%eax, 32(%3)\n"
31171 " movl %%edx, 36(%3)\n"
31172- "12: movl 40(%4), %%eax\n"
31173- "71: movl 44(%4), %%edx\n"
31174+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31175+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31176 " movl %%eax, 40(%3)\n"
31177 " movl %%edx, 44(%3)\n"
31178- "13: movl 48(%4), %%eax\n"
31179- "81: movl 52(%4), %%edx\n"
31180+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31181+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31182 " movl %%eax, 48(%3)\n"
31183 " movl %%edx, 52(%3)\n"
31184- "14: movl 56(%4), %%eax\n"
31185- "91: movl 60(%4), %%edx\n"
31186+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31187+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31188 " movl %%eax, 56(%3)\n"
31189 " movl %%edx, 60(%3)\n"
31190 " addl $-64, %0\n"
31191@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
31192 " shrl $2, %0\n"
31193 " andl $3, %%eax\n"
31194 " cld\n"
31195- "6: rep; movsl\n"
31196+ "6: rep; "__copyuser_seg" movsl\n"
31197 " movl %%eax,%0\n"
31198- "7: rep; movsb\n"
31199+ "7: rep; "__copyuser_seg" movsb\n"
31200 "8:\n"
31201 ".section .fixup,\"ax\"\n"
31202 "9: lea 0(%%eax,%0,4),%0\n"
31203@@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
31204
31205 __asm__ __volatile__(
31206 " .align 2,0x90\n"
31207- "0: movl 32(%4), %%eax\n"
31208+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31209 " cmpl $67, %0\n"
31210 " jbe 2f\n"
31211- "1: movl 64(%4), %%eax\n"
31212+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31213 " .align 2,0x90\n"
31214- "2: movl 0(%4), %%eax\n"
31215- "21: movl 4(%4), %%edx\n"
31216+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31217+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31218 " movnti %%eax, 0(%3)\n"
31219 " movnti %%edx, 4(%3)\n"
31220- "3: movl 8(%4), %%eax\n"
31221- "31: movl 12(%4),%%edx\n"
31222+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31223+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31224 " movnti %%eax, 8(%3)\n"
31225 " movnti %%edx, 12(%3)\n"
31226- "4: movl 16(%4), %%eax\n"
31227- "41: movl 20(%4), %%edx\n"
31228+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31229+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31230 " movnti %%eax, 16(%3)\n"
31231 " movnti %%edx, 20(%3)\n"
31232- "10: movl 24(%4), %%eax\n"
31233- "51: movl 28(%4), %%edx\n"
31234+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31235+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31236 " movnti %%eax, 24(%3)\n"
31237 " movnti %%edx, 28(%3)\n"
31238- "11: movl 32(%4), %%eax\n"
31239- "61: movl 36(%4), %%edx\n"
31240+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31241+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31242 " movnti %%eax, 32(%3)\n"
31243 " movnti %%edx, 36(%3)\n"
31244- "12: movl 40(%4), %%eax\n"
31245- "71: movl 44(%4), %%edx\n"
31246+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31247+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31248 " movnti %%eax, 40(%3)\n"
31249 " movnti %%edx, 44(%3)\n"
31250- "13: movl 48(%4), %%eax\n"
31251- "81: movl 52(%4), %%edx\n"
31252+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31253+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31254 " movnti %%eax, 48(%3)\n"
31255 " movnti %%edx, 52(%3)\n"
31256- "14: movl 56(%4), %%eax\n"
31257- "91: movl 60(%4), %%edx\n"
31258+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31259+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31260 " movnti %%eax, 56(%3)\n"
31261 " movnti %%edx, 60(%3)\n"
31262 " addl $-64, %0\n"
31263@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
31264 " shrl $2, %0\n"
31265 " andl $3, %%eax\n"
31266 " cld\n"
31267- "6: rep; movsl\n"
31268+ "6: rep; "__copyuser_seg" movsl\n"
31269 " movl %%eax,%0\n"
31270- "7: rep; movsb\n"
31271+ "7: rep; "__copyuser_seg" movsb\n"
31272 "8:\n"
31273 ".section .fixup,\"ax\"\n"
31274 "9: lea 0(%%eax,%0,4),%0\n"
31275@@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
31276
31277 __asm__ __volatile__(
31278 " .align 2,0x90\n"
31279- "0: movl 32(%4), %%eax\n"
31280+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31281 " cmpl $67, %0\n"
31282 " jbe 2f\n"
31283- "1: movl 64(%4), %%eax\n"
31284+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31285 " .align 2,0x90\n"
31286- "2: movl 0(%4), %%eax\n"
31287- "21: movl 4(%4), %%edx\n"
31288+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31289+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31290 " movnti %%eax, 0(%3)\n"
31291 " movnti %%edx, 4(%3)\n"
31292- "3: movl 8(%4), %%eax\n"
31293- "31: movl 12(%4),%%edx\n"
31294+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31295+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31296 " movnti %%eax, 8(%3)\n"
31297 " movnti %%edx, 12(%3)\n"
31298- "4: movl 16(%4), %%eax\n"
31299- "41: movl 20(%4), %%edx\n"
31300+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31301+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31302 " movnti %%eax, 16(%3)\n"
31303 " movnti %%edx, 20(%3)\n"
31304- "10: movl 24(%4), %%eax\n"
31305- "51: movl 28(%4), %%edx\n"
31306+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31307+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31308 " movnti %%eax, 24(%3)\n"
31309 " movnti %%edx, 28(%3)\n"
31310- "11: movl 32(%4), %%eax\n"
31311- "61: movl 36(%4), %%edx\n"
31312+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31313+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31314 " movnti %%eax, 32(%3)\n"
31315 " movnti %%edx, 36(%3)\n"
31316- "12: movl 40(%4), %%eax\n"
31317- "71: movl 44(%4), %%edx\n"
31318+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31319+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31320 " movnti %%eax, 40(%3)\n"
31321 " movnti %%edx, 44(%3)\n"
31322- "13: movl 48(%4), %%eax\n"
31323- "81: movl 52(%4), %%edx\n"
31324+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31325+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31326 " movnti %%eax, 48(%3)\n"
31327 " movnti %%edx, 52(%3)\n"
31328- "14: movl 56(%4), %%eax\n"
31329- "91: movl 60(%4), %%edx\n"
31330+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31331+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31332 " movnti %%eax, 56(%3)\n"
31333 " movnti %%edx, 60(%3)\n"
31334 " addl $-64, %0\n"
31335@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
31336 " shrl $2, %0\n"
31337 " andl $3, %%eax\n"
31338 " cld\n"
31339- "6: rep; movsl\n"
31340+ "6: rep; "__copyuser_seg" movsl\n"
31341 " movl %%eax,%0\n"
31342- "7: rep; movsb\n"
31343+ "7: rep; "__copyuser_seg" movsb\n"
31344 "8:\n"
31345 ".section .fixup,\"ax\"\n"
31346 "9: lea 0(%%eax,%0,4),%0\n"
31347@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
31348 */
31349 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
31350 unsigned long size);
31351-unsigned long __copy_user_intel(void __user *to, const void *from,
31352+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
31353+ unsigned long size);
31354+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
31355 unsigned long size);
31356 unsigned long __copy_user_zeroing_intel_nocache(void *to,
31357 const void __user *from, unsigned long size);
31358 #endif /* CONFIG_X86_INTEL_USERCOPY */
31359
31360 /* Generic arbitrary sized copy. */
31361-#define __copy_user(to, from, size) \
31362+#define __copy_user(to, from, size, prefix, set, restore) \
31363 do { \
31364 int __d0, __d1, __d2; \
31365 __asm__ __volatile__( \
31366+ set \
31367 " cmp $7,%0\n" \
31368 " jbe 1f\n" \
31369 " movl %1,%0\n" \
31370 " negl %0\n" \
31371 " andl $7,%0\n" \
31372 " subl %0,%3\n" \
31373- "4: rep; movsb\n" \
31374+ "4: rep; "prefix"movsb\n" \
31375 " movl %3,%0\n" \
31376 " shrl $2,%0\n" \
31377 " andl $3,%3\n" \
31378 " .align 2,0x90\n" \
31379- "0: rep; movsl\n" \
31380+ "0: rep; "prefix"movsl\n" \
31381 " movl %3,%0\n" \
31382- "1: rep; movsb\n" \
31383+ "1: rep; "prefix"movsb\n" \
31384 "2:\n" \
31385+ restore \
31386 ".section .fixup,\"ax\"\n" \
31387 "5: addl %3,%0\n" \
31388 " jmp 2b\n" \
31389@@ -538,14 +650,14 @@ do { \
31390 " negl %0\n" \
31391 " andl $7,%0\n" \
31392 " subl %0,%3\n" \
31393- "4: rep; movsb\n" \
31394+ "4: rep; "__copyuser_seg"movsb\n" \
31395 " movl %3,%0\n" \
31396 " shrl $2,%0\n" \
31397 " andl $3,%3\n" \
31398 " .align 2,0x90\n" \
31399- "0: rep; movsl\n" \
31400+ "0: rep; "__copyuser_seg"movsl\n" \
31401 " movl %3,%0\n" \
31402- "1: rep; movsb\n" \
31403+ "1: rep; "__copyuser_seg"movsb\n" \
31404 "2:\n" \
31405 ".section .fixup,\"ax\"\n" \
31406 "5: addl %3,%0\n" \
31407@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
31408 {
31409 stac();
31410 if (movsl_is_ok(to, from, n))
31411- __copy_user(to, from, n);
31412+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
31413 else
31414- n = __copy_user_intel(to, from, n);
31415+ n = __generic_copy_to_user_intel(to, from, n);
31416 clac();
31417 return n;
31418 }
31419@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
31420 {
31421 stac();
31422 if (movsl_is_ok(to, from, n))
31423- __copy_user(to, from, n);
31424+ __copy_user(to, from, n, __copyuser_seg, "", "");
31425 else
31426- n = __copy_user_intel((void __user *)to,
31427- (const void *)from, n);
31428+ n = __generic_copy_from_user_intel(to, from, n);
31429 clac();
31430 return n;
31431 }
31432@@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
31433 if (n > 64 && cpu_has_xmm2)
31434 n = __copy_user_intel_nocache(to, from, n);
31435 else
31436- __copy_user(to, from, n);
31437+ __copy_user(to, from, n, __copyuser_seg, "", "");
31438 #else
31439- __copy_user(to, from, n);
31440+ __copy_user(to, from, n, __copyuser_seg, "", "");
31441 #endif
31442 clac();
31443 return n;
31444 }
31445 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
31446
31447-/**
31448- * copy_to_user: - Copy a block of data into user space.
31449- * @to: Destination address, in user space.
31450- * @from: Source address, in kernel space.
31451- * @n: Number of bytes to copy.
31452- *
31453- * Context: User context only. This function may sleep.
31454- *
31455- * Copy data from kernel space to user space.
31456- *
31457- * Returns number of bytes that could not be copied.
31458- * On success, this will be zero.
31459- */
31460-unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
31461+#ifdef CONFIG_PAX_MEMORY_UDEREF
31462+void __set_fs(mm_segment_t x)
31463 {
31464- if (access_ok(VERIFY_WRITE, to, n))
31465- n = __copy_to_user(to, from, n);
31466- return n;
31467+ switch (x.seg) {
31468+ case 0:
31469+ loadsegment(gs, 0);
31470+ break;
31471+ case TASK_SIZE_MAX:
31472+ loadsegment(gs, __USER_DS);
31473+ break;
31474+ case -1UL:
31475+ loadsegment(gs, __KERNEL_DS);
31476+ break;
31477+ default:
31478+ BUG();
31479+ }
31480 }
31481-EXPORT_SYMBOL(_copy_to_user);
31482+EXPORT_SYMBOL(__set_fs);
31483
31484-/**
31485- * copy_from_user: - Copy a block of data from user space.
31486- * @to: Destination address, in kernel space.
31487- * @from: Source address, in user space.
31488- * @n: Number of bytes to copy.
31489- *
31490- * Context: User context only. This function may sleep.
31491- *
31492- * Copy data from user space to kernel space.
31493- *
31494- * Returns number of bytes that could not be copied.
31495- * On success, this will be zero.
31496- *
31497- * If some data could not be copied, this function will pad the copied
31498- * data to the requested size using zero bytes.
31499- */
31500-unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
31501+void set_fs(mm_segment_t x)
31502 {
31503- if (access_ok(VERIFY_READ, from, n))
31504- n = __copy_from_user(to, from, n);
31505- else
31506- memset(to, 0, n);
31507- return n;
31508+ current_thread_info()->addr_limit = x;
31509+ __set_fs(x);
31510 }
31511-EXPORT_SYMBOL(_copy_from_user);
31512+EXPORT_SYMBOL(set_fs);
31513+#endif
31514diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
31515index c905e89..01ab928 100644
31516--- a/arch/x86/lib/usercopy_64.c
31517+++ b/arch/x86/lib/usercopy_64.c
31518@@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31519 might_fault();
31520 /* no memory constraint because it doesn't change any memory gcc knows
31521 about */
31522+ pax_open_userland();
31523 stac();
31524 asm volatile(
31525 " testq %[size8],%[size8]\n"
31526@@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31527 _ASM_EXTABLE(0b,3b)
31528 _ASM_EXTABLE(1b,2b)
31529 : [size8] "=&c"(size), [dst] "=&D" (__d0)
31530- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
31531+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
31532 [zero] "r" (0UL), [eight] "r" (8UL));
31533 clac();
31534+ pax_close_userland();
31535 return size;
31536 }
31537 EXPORT_SYMBOL(__clear_user);
31538@@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
31539 }
31540 EXPORT_SYMBOL(clear_user);
31541
31542-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
31543+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
31544 {
31545- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
31546- return copy_user_generic((__force void *)to, (__force void *)from, len);
31547- }
31548- return len;
31549+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
31550+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
31551+ return len;
31552 }
31553 EXPORT_SYMBOL(copy_in_user);
31554
31555@@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
31556 * it is not necessary to optimize tail handling.
31557 */
31558 __visible unsigned long
31559-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31560+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
31561 {
31562 char c;
31563 unsigned zero_len;
31564
31565+ clac();
31566+ pax_close_userland();
31567 for (; len; --len, to++) {
31568 if (__get_user_nocheck(c, from++, sizeof(char)))
31569 break;
31570@@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31571 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
31572 if (__put_user_nocheck(c, to++, sizeof(char)))
31573 break;
31574- clac();
31575 return len;
31576 }
31577diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
31578index 6a19ad9..1c48f9a 100644
31579--- a/arch/x86/mm/Makefile
31580+++ b/arch/x86/mm/Makefile
31581@@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
31582 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
31583
31584 obj-$(CONFIG_MEMTEST) += memtest.o
31585+
31586+quote:="
31587+obj-$(CONFIG_X86_64) += uderef_64.o
31588+CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
31589diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
31590index 903ec1e..c4166b2 100644
31591--- a/arch/x86/mm/extable.c
31592+++ b/arch/x86/mm/extable.c
31593@@ -6,12 +6,24 @@
31594 static inline unsigned long
31595 ex_insn_addr(const struct exception_table_entry *x)
31596 {
31597- return (unsigned long)&x->insn + x->insn;
31598+ unsigned long reloc = 0;
31599+
31600+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31601+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31602+#endif
31603+
31604+ return (unsigned long)&x->insn + x->insn + reloc;
31605 }
31606 static inline unsigned long
31607 ex_fixup_addr(const struct exception_table_entry *x)
31608 {
31609- return (unsigned long)&x->fixup + x->fixup;
31610+ unsigned long reloc = 0;
31611+
31612+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31613+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31614+#endif
31615+
31616+ return (unsigned long)&x->fixup + x->fixup + reloc;
31617 }
31618
31619 int fixup_exception(struct pt_regs *regs)
31620@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
31621 unsigned long new_ip;
31622
31623 #ifdef CONFIG_PNPBIOS
31624- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
31625+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
31626 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
31627 extern u32 pnp_bios_is_utter_crap;
31628 pnp_bios_is_utter_crap = 1;
31629@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
31630 i += 4;
31631 p->fixup -= i;
31632 i += 4;
31633+
31634+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31635+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
31636+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31637+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31638+#endif
31639+
31640 }
31641 }
31642
31643diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
31644index a10c8c7..35a5abb 100644
31645--- a/arch/x86/mm/fault.c
31646+++ b/arch/x86/mm/fault.c
31647@@ -14,11 +14,18 @@
31648 #include <linux/hugetlb.h> /* hstate_index_to_shift */
31649 #include <linux/prefetch.h> /* prefetchw */
31650 #include <linux/context_tracking.h> /* exception_enter(), ... */
31651+#include <linux/unistd.h>
31652+#include <linux/compiler.h>
31653
31654 #include <asm/traps.h> /* dotraplinkage, ... */
31655 #include <asm/pgalloc.h> /* pgd_*(), ... */
31656 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
31657 #include <asm/fixmap.h> /* VSYSCALL_START */
31658+#include <asm/tlbflush.h>
31659+
31660+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31661+#include <asm/stacktrace.h>
31662+#endif
31663
31664 #define CREATE_TRACE_POINTS
31665 #include <asm/trace/exceptions.h>
31666@@ -59,7 +66,7 @@ static inline int __kprobes kprobes_fault(struct pt_regs *regs)
31667 int ret = 0;
31668
31669 /* kprobe_running() needs smp_processor_id() */
31670- if (kprobes_built_in() && !user_mode_vm(regs)) {
31671+ if (kprobes_built_in() && !user_mode(regs)) {
31672 preempt_disable();
31673 if (kprobe_running() && kprobe_fault_handler(regs, 14))
31674 ret = 1;
31675@@ -120,7 +127,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
31676 return !instr_lo || (instr_lo>>1) == 1;
31677 case 0x00:
31678 /* Prefetch instruction is 0x0F0D or 0x0F18 */
31679- if (probe_kernel_address(instr, opcode))
31680+ if (user_mode(regs)) {
31681+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31682+ return 0;
31683+ } else if (probe_kernel_address(instr, opcode))
31684 return 0;
31685
31686 *prefetch = (instr_lo == 0xF) &&
31687@@ -154,7 +164,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
31688 while (instr < max_instr) {
31689 unsigned char opcode;
31690
31691- if (probe_kernel_address(instr, opcode))
31692+ if (user_mode(regs)) {
31693+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31694+ break;
31695+ } else if (probe_kernel_address(instr, opcode))
31696 break;
31697
31698 instr++;
31699@@ -185,6 +198,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
31700 force_sig_info(si_signo, &info, tsk);
31701 }
31702
31703+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31704+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
31705+#endif
31706+
31707+#ifdef CONFIG_PAX_EMUTRAMP
31708+static int pax_handle_fetch_fault(struct pt_regs *regs);
31709+#endif
31710+
31711+#ifdef CONFIG_PAX_PAGEEXEC
31712+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
31713+{
31714+ pgd_t *pgd;
31715+ pud_t *pud;
31716+ pmd_t *pmd;
31717+
31718+ pgd = pgd_offset(mm, address);
31719+ if (!pgd_present(*pgd))
31720+ return NULL;
31721+ pud = pud_offset(pgd, address);
31722+ if (!pud_present(*pud))
31723+ return NULL;
31724+ pmd = pmd_offset(pud, address);
31725+ if (!pmd_present(*pmd))
31726+ return NULL;
31727+ return pmd;
31728+}
31729+#endif
31730+
31731 DEFINE_SPINLOCK(pgd_lock);
31732 LIST_HEAD(pgd_list);
31733
31734@@ -235,10 +276,27 @@ void vmalloc_sync_all(void)
31735 for (address = VMALLOC_START & PMD_MASK;
31736 address >= TASK_SIZE && address < FIXADDR_TOP;
31737 address += PMD_SIZE) {
31738+
31739+#ifdef CONFIG_PAX_PER_CPU_PGD
31740+ unsigned long cpu;
31741+#else
31742 struct page *page;
31743+#endif
31744
31745 spin_lock(&pgd_lock);
31746+
31747+#ifdef CONFIG_PAX_PER_CPU_PGD
31748+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31749+ pgd_t *pgd = get_cpu_pgd(cpu, user);
31750+ pmd_t *ret;
31751+
31752+ ret = vmalloc_sync_one(pgd, address);
31753+ if (!ret)
31754+ break;
31755+ pgd = get_cpu_pgd(cpu, kernel);
31756+#else
31757 list_for_each_entry(page, &pgd_list, lru) {
31758+ pgd_t *pgd;
31759 spinlock_t *pgt_lock;
31760 pmd_t *ret;
31761
31762@@ -246,8 +304,14 @@ void vmalloc_sync_all(void)
31763 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31764
31765 spin_lock(pgt_lock);
31766- ret = vmalloc_sync_one(page_address(page), address);
31767+ pgd = page_address(page);
31768+#endif
31769+
31770+ ret = vmalloc_sync_one(pgd, address);
31771+
31772+#ifndef CONFIG_PAX_PER_CPU_PGD
31773 spin_unlock(pgt_lock);
31774+#endif
31775
31776 if (!ret)
31777 break;
31778@@ -281,6 +345,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31779 * an interrupt in the middle of a task switch..
31780 */
31781 pgd_paddr = read_cr3();
31782+
31783+#ifdef CONFIG_PAX_PER_CPU_PGD
31784+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
31785+ vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
31786+#endif
31787+
31788 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
31789 if (!pmd_k)
31790 return -1;
31791@@ -376,11 +446,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31792 * happen within a race in page table update. In the later
31793 * case just flush:
31794 */
31795- pgd = pgd_offset(current->active_mm, address);
31796+
31797 pgd_ref = pgd_offset_k(address);
31798 if (pgd_none(*pgd_ref))
31799 return -1;
31800
31801+#ifdef CONFIG_PAX_PER_CPU_PGD
31802+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
31803+ pgd = pgd_offset_cpu(smp_processor_id(), user, address);
31804+ if (pgd_none(*pgd)) {
31805+ set_pgd(pgd, *pgd_ref);
31806+ arch_flush_lazy_mmu_mode();
31807+ } else {
31808+ BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
31809+ }
31810+ pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
31811+#else
31812+ pgd = pgd_offset(current->active_mm, address);
31813+#endif
31814+
31815 if (pgd_none(*pgd)) {
31816 set_pgd(pgd, *pgd_ref);
31817 arch_flush_lazy_mmu_mode();
31818@@ -546,7 +630,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
31819 static int is_errata100(struct pt_regs *regs, unsigned long address)
31820 {
31821 #ifdef CONFIG_X86_64
31822- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
31823+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
31824 return 1;
31825 #endif
31826 return 0;
31827@@ -573,7 +657,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
31828 }
31829
31830 static const char nx_warning[] = KERN_CRIT
31831-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
31832+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
31833
31834 static void
31835 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31836@@ -582,15 +666,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31837 if (!oops_may_print())
31838 return;
31839
31840- if (error_code & PF_INSTR) {
31841+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
31842 unsigned int level;
31843
31844 pte_t *pte = lookup_address(address, &level);
31845
31846 if (pte && pte_present(*pte) && !pte_exec(*pte))
31847- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
31848+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
31849 }
31850
31851+#ifdef CONFIG_PAX_KERNEXEC
31852+ if (init_mm.start_code <= address && address < init_mm.end_code) {
31853+ if (current->signal->curr_ip)
31854+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
31855+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
31856+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31857+ else
31858+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
31859+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31860+ }
31861+#endif
31862+
31863 printk(KERN_ALERT "BUG: unable to handle kernel ");
31864 if (address < PAGE_SIZE)
31865 printk(KERN_CONT "NULL pointer dereference");
31866@@ -771,6 +867,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
31867 return;
31868 }
31869 #endif
31870+
31871+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31872+ if (pax_is_fetch_fault(regs, error_code, address)) {
31873+
31874+#ifdef CONFIG_PAX_EMUTRAMP
31875+ switch (pax_handle_fetch_fault(regs)) {
31876+ case 2:
31877+ return;
31878+ }
31879+#endif
31880+
31881+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31882+ do_group_exit(SIGKILL);
31883+ }
31884+#endif
31885+
31886 /* Kernel addresses are always protection faults: */
31887 if (address >= TASK_SIZE)
31888 error_code |= PF_PROT;
31889@@ -856,7 +968,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
31890 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
31891 printk(KERN_ERR
31892 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
31893- tsk->comm, tsk->pid, address);
31894+ tsk->comm, task_pid_nr(tsk), address);
31895 code = BUS_MCEERR_AR;
31896 }
31897 #endif
31898@@ -910,6 +1022,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
31899 return 1;
31900 }
31901
31902+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31903+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
31904+{
31905+ pte_t *pte;
31906+ pmd_t *pmd;
31907+ spinlock_t *ptl;
31908+ unsigned char pte_mask;
31909+
31910+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
31911+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
31912+ return 0;
31913+
31914+ /* PaX: it's our fault, let's handle it if we can */
31915+
31916+ /* PaX: take a look at read faults before acquiring any locks */
31917+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
31918+ /* instruction fetch attempt from a protected page in user mode */
31919+ up_read(&mm->mmap_sem);
31920+
31921+#ifdef CONFIG_PAX_EMUTRAMP
31922+ switch (pax_handle_fetch_fault(regs)) {
31923+ case 2:
31924+ return 1;
31925+ }
31926+#endif
31927+
31928+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31929+ do_group_exit(SIGKILL);
31930+ }
31931+
31932+ pmd = pax_get_pmd(mm, address);
31933+ if (unlikely(!pmd))
31934+ return 0;
31935+
31936+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
31937+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
31938+ pte_unmap_unlock(pte, ptl);
31939+ return 0;
31940+ }
31941+
31942+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
31943+ /* write attempt to a protected page in user mode */
31944+ pte_unmap_unlock(pte, ptl);
31945+ return 0;
31946+ }
31947+
31948+#ifdef CONFIG_SMP
31949+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
31950+#else
31951+ if (likely(address > get_limit(regs->cs)))
31952+#endif
31953+ {
31954+ set_pte(pte, pte_mkread(*pte));
31955+ __flush_tlb_one(address);
31956+ pte_unmap_unlock(pte, ptl);
31957+ up_read(&mm->mmap_sem);
31958+ return 1;
31959+ }
31960+
31961+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
31962+
31963+ /*
31964+ * PaX: fill DTLB with user rights and retry
31965+ */
31966+ __asm__ __volatile__ (
31967+ "orb %2,(%1)\n"
31968+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
31969+/*
31970+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
31971+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
31972+ * page fault when examined during a TLB load attempt. this is true not only
31973+ * for PTEs holding a non-present entry but also present entries that will
31974+ * raise a page fault (such as those set up by PaX, or the copy-on-write
31975+ * mechanism). in effect it means that we do *not* need to flush the TLBs
31976+ * for our target pages since their PTEs are simply not in the TLBs at all.
31977+
31978+ * the best thing in omitting it is that we gain around 15-20% speed in the
31979+ * fast path of the page fault handler and can get rid of tracing since we
31980+ * can no longer flush unintended entries.
31981+ */
31982+ "invlpg (%0)\n"
31983+#endif
31984+ __copyuser_seg"testb $0,(%0)\n"
31985+ "xorb %3,(%1)\n"
31986+ :
31987+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
31988+ : "memory", "cc");
31989+ pte_unmap_unlock(pte, ptl);
31990+ up_read(&mm->mmap_sem);
31991+ return 1;
31992+}
31993+#endif
31994+
31995 /*
31996 * Handle a spurious fault caused by a stale TLB entry.
31997 *
31998@@ -976,6 +1181,9 @@ int show_unhandled_signals = 1;
31999 static inline int
32000 access_error(unsigned long error_code, struct vm_area_struct *vma)
32001 {
32002+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
32003+ return 1;
32004+
32005 if (error_code & PF_WRITE) {
32006 /* write, present and write, not present: */
32007 if (unlikely(!(vma->vm_flags & VM_WRITE)))
32008@@ -1010,7 +1218,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
32009 if (error_code & PF_USER)
32010 return false;
32011
32012- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
32013+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
32014 return false;
32015
32016 return true;
32017@@ -1038,6 +1246,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32018 tsk = current;
32019 mm = tsk->mm;
32020
32021+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32022+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
32023+ if (!search_exception_tables(regs->ip)) {
32024+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32025+ bad_area_nosemaphore(regs, error_code, address);
32026+ return;
32027+ }
32028+ if (address < pax_user_shadow_base) {
32029+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32030+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
32031+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
32032+ } else
32033+ address -= pax_user_shadow_base;
32034+ }
32035+#endif
32036+
32037 /*
32038 * Detect and handle instructions that would cause a page fault for
32039 * both a tracked kernel page and a userspace page.
32040@@ -1115,7 +1339,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32041 * User-mode registers count as a user access even for any
32042 * potential system fault or CPU buglet:
32043 */
32044- if (user_mode_vm(regs)) {
32045+ if (user_mode(regs)) {
32046 local_irq_enable();
32047 error_code |= PF_USER;
32048 flags |= FAULT_FLAG_USER;
32049@@ -1162,6 +1386,11 @@ retry:
32050 might_sleep();
32051 }
32052
32053+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
32054+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
32055+ return;
32056+#endif
32057+
32058 vma = find_vma(mm, address);
32059 if (unlikely(!vma)) {
32060 bad_area(regs, error_code, address);
32061@@ -1173,18 +1402,24 @@ retry:
32062 bad_area(regs, error_code, address);
32063 return;
32064 }
32065- if (error_code & PF_USER) {
32066- /*
32067- * Accessing the stack below %sp is always a bug.
32068- * The large cushion allows instructions like enter
32069- * and pusha to work. ("enter $65535, $31" pushes
32070- * 32 pointers and then decrements %sp by 65535.)
32071- */
32072- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
32073- bad_area(regs, error_code, address);
32074- return;
32075- }
32076+ /*
32077+ * Accessing the stack below %sp is always a bug.
32078+ * The large cushion allows instructions like enter
32079+ * and pusha to work. ("enter $65535, $31" pushes
32080+ * 32 pointers and then decrements %sp by 65535.)
32081+ */
32082+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
32083+ bad_area(regs, error_code, address);
32084+ return;
32085 }
32086+
32087+#ifdef CONFIG_PAX_SEGMEXEC
32088+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
32089+ bad_area(regs, error_code, address);
32090+ return;
32091+ }
32092+#endif
32093+
32094 if (unlikely(expand_stack(vma, address))) {
32095 bad_area(regs, error_code, address);
32096 return;
32097@@ -1296,3 +1531,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
32098 exception_exit(prev_state);
32099 }
32100 #endif /* CONFIG_TRACING */
32101+
32102+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32103+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
32104+{
32105+ struct mm_struct *mm = current->mm;
32106+ unsigned long ip = regs->ip;
32107+
32108+ if (v8086_mode(regs))
32109+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
32110+
32111+#ifdef CONFIG_PAX_PAGEEXEC
32112+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
32113+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
32114+ return true;
32115+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
32116+ return true;
32117+ return false;
32118+ }
32119+#endif
32120+
32121+#ifdef CONFIG_PAX_SEGMEXEC
32122+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
32123+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
32124+ return true;
32125+ return false;
32126+ }
32127+#endif
32128+
32129+ return false;
32130+}
32131+#endif
32132+
32133+#ifdef CONFIG_PAX_EMUTRAMP
32134+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
32135+{
32136+ int err;
32137+
32138+ do { /* PaX: libffi trampoline emulation */
32139+ unsigned char mov, jmp;
32140+ unsigned int addr1, addr2;
32141+
32142+#ifdef CONFIG_X86_64
32143+ if ((regs->ip + 9) >> 32)
32144+ break;
32145+#endif
32146+
32147+ err = get_user(mov, (unsigned char __user *)regs->ip);
32148+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32149+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
32150+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32151+
32152+ if (err)
32153+ break;
32154+
32155+ if (mov == 0xB8 && jmp == 0xE9) {
32156+ regs->ax = addr1;
32157+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
32158+ return 2;
32159+ }
32160+ } while (0);
32161+
32162+ do { /* PaX: gcc trampoline emulation #1 */
32163+ unsigned char mov1, mov2;
32164+ unsigned short jmp;
32165+ unsigned int addr1, addr2;
32166+
32167+#ifdef CONFIG_X86_64
32168+ if ((regs->ip + 11) >> 32)
32169+ break;
32170+#endif
32171+
32172+ err = get_user(mov1, (unsigned char __user *)regs->ip);
32173+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32174+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
32175+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32176+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
32177+
32178+ if (err)
32179+ break;
32180+
32181+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
32182+ regs->cx = addr1;
32183+ regs->ax = addr2;
32184+ regs->ip = addr2;
32185+ return 2;
32186+ }
32187+ } while (0);
32188+
32189+ do { /* PaX: gcc trampoline emulation #2 */
32190+ unsigned char mov, jmp;
32191+ unsigned int addr1, addr2;
32192+
32193+#ifdef CONFIG_X86_64
32194+ if ((regs->ip + 9) >> 32)
32195+ break;
32196+#endif
32197+
32198+ err = get_user(mov, (unsigned char __user *)regs->ip);
32199+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32200+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
32201+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32202+
32203+ if (err)
32204+ break;
32205+
32206+ if (mov == 0xB9 && jmp == 0xE9) {
32207+ regs->cx = addr1;
32208+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
32209+ return 2;
32210+ }
32211+ } while (0);
32212+
32213+ return 1; /* PaX in action */
32214+}
32215+
32216+#ifdef CONFIG_X86_64
32217+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
32218+{
32219+ int err;
32220+
32221+ do { /* PaX: libffi trampoline emulation */
32222+ unsigned short mov1, mov2, jmp1;
32223+ unsigned char stcclc, jmp2;
32224+ unsigned long addr1, addr2;
32225+
32226+ err = get_user(mov1, (unsigned short __user *)regs->ip);
32227+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
32228+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
32229+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
32230+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
32231+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
32232+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
32233+
32234+ if (err)
32235+ break;
32236+
32237+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32238+ regs->r11 = addr1;
32239+ regs->r10 = addr2;
32240+ if (stcclc == 0xF8)
32241+ regs->flags &= ~X86_EFLAGS_CF;
32242+ else
32243+ regs->flags |= X86_EFLAGS_CF;
32244+ regs->ip = addr1;
32245+ return 2;
32246+ }
32247+ } while (0);
32248+
32249+ do { /* PaX: gcc trampoline emulation #1 */
32250+ unsigned short mov1, mov2, jmp1;
32251+ unsigned char jmp2;
32252+ unsigned int addr1;
32253+ unsigned long addr2;
32254+
32255+ err = get_user(mov1, (unsigned short __user *)regs->ip);
32256+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
32257+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
32258+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
32259+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
32260+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
32261+
32262+ if (err)
32263+ break;
32264+
32265+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32266+ regs->r11 = addr1;
32267+ regs->r10 = addr2;
32268+ regs->ip = addr1;
32269+ return 2;
32270+ }
32271+ } while (0);
32272+
32273+ do { /* PaX: gcc trampoline emulation #2 */
32274+ unsigned short mov1, mov2, jmp1;
32275+ unsigned char jmp2;
32276+ unsigned long addr1, addr2;
32277+
32278+ err = get_user(mov1, (unsigned short __user *)regs->ip);
32279+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
32280+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
32281+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
32282+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
32283+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
32284+
32285+ if (err)
32286+ break;
32287+
32288+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32289+ regs->r11 = addr1;
32290+ regs->r10 = addr2;
32291+ regs->ip = addr1;
32292+ return 2;
32293+ }
32294+ } while (0);
32295+
32296+ return 1; /* PaX in action */
32297+}
32298+#endif
32299+
32300+/*
32301+ * PaX: decide what to do with offenders (regs->ip = fault address)
32302+ *
32303+ * returns 1 when task should be killed
32304+ * 2 when gcc trampoline was detected
32305+ */
32306+static int pax_handle_fetch_fault(struct pt_regs *regs)
32307+{
32308+ if (v8086_mode(regs))
32309+ return 1;
32310+
32311+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
32312+ return 1;
32313+
32314+#ifdef CONFIG_X86_32
32315+ return pax_handle_fetch_fault_32(regs);
32316+#else
32317+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
32318+ return pax_handle_fetch_fault_32(regs);
32319+ else
32320+ return pax_handle_fetch_fault_64(regs);
32321+#endif
32322+}
32323+#endif
32324+
32325+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32326+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
32327+{
32328+ long i;
32329+
32330+ printk(KERN_ERR "PAX: bytes at PC: ");
32331+ for (i = 0; i < 20; i++) {
32332+ unsigned char c;
32333+ if (get_user(c, (unsigned char __force_user *)pc+i))
32334+ printk(KERN_CONT "?? ");
32335+ else
32336+ printk(KERN_CONT "%02x ", c);
32337+ }
32338+ printk("\n");
32339+
32340+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
32341+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
32342+ unsigned long c;
32343+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
32344+#ifdef CONFIG_X86_32
32345+ printk(KERN_CONT "???????? ");
32346+#else
32347+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
32348+ printk(KERN_CONT "???????? ???????? ");
32349+ else
32350+ printk(KERN_CONT "???????????????? ");
32351+#endif
32352+ } else {
32353+#ifdef CONFIG_X86_64
32354+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
32355+ printk(KERN_CONT "%08x ", (unsigned int)c);
32356+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
32357+ } else
32358+#endif
32359+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
32360+ }
32361+ }
32362+ printk("\n");
32363+}
32364+#endif
32365+
32366+/**
32367+ * probe_kernel_write(): safely attempt to write to a location
32368+ * @dst: address to write to
32369+ * @src: pointer to the data that shall be written
32370+ * @size: size of the data chunk
32371+ *
32372+ * Safely write to address @dst from the buffer at @src. If a kernel fault
32373+ * happens, handle that and return -EFAULT.
32374+ */
32375+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
32376+{
32377+ long ret;
32378+ mm_segment_t old_fs = get_fs();
32379+
32380+ set_fs(KERNEL_DS);
32381+ pagefault_disable();
32382+ pax_open_kernel();
32383+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
32384+ pax_close_kernel();
32385+ pagefault_enable();
32386+ set_fs(old_fs);
32387+
32388+ return ret ? -EFAULT : 0;
32389+}
32390diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
32391index 207d9aef..69030980 100644
32392--- a/arch/x86/mm/gup.c
32393+++ b/arch/x86/mm/gup.c
32394@@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
32395 addr = start;
32396 len = (unsigned long) nr_pages << PAGE_SHIFT;
32397 end = start + len;
32398- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
32399+ if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32400 (void __user *)start, len)))
32401 return 0;
32402
32403@@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
32404 goto slow_irqon;
32405 #endif
32406
32407+ if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32408+ (void __user *)start, len)))
32409+ return 0;
32410+
32411 /*
32412 * XXX: batch / limit 'nr', to avoid large irq off latency
32413 * needs some instrumenting to determine the common sizes used by
32414diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
32415index 4500142..53a363c 100644
32416--- a/arch/x86/mm/highmem_32.c
32417+++ b/arch/x86/mm/highmem_32.c
32418@@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
32419 idx = type + KM_TYPE_NR*smp_processor_id();
32420 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32421 BUG_ON(!pte_none(*(kmap_pte-idx)));
32422+
32423+ pax_open_kernel();
32424 set_pte(kmap_pte-idx, mk_pte(page, prot));
32425+ pax_close_kernel();
32426+
32427 arch_flush_lazy_mmu_mode();
32428
32429 return (void *)vaddr;
32430diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
32431index 8c9f647..57cb402 100644
32432--- a/arch/x86/mm/hugetlbpage.c
32433+++ b/arch/x86/mm/hugetlbpage.c
32434@@ -90,23 +90,24 @@ int pmd_huge_support(void)
32435 #ifdef CONFIG_HUGETLB_PAGE
32436 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
32437 unsigned long addr, unsigned long len,
32438- unsigned long pgoff, unsigned long flags)
32439+ unsigned long pgoff, unsigned long flags, unsigned long offset)
32440 {
32441 struct hstate *h = hstate_file(file);
32442 struct vm_unmapped_area_info info;
32443-
32444+
32445 info.flags = 0;
32446 info.length = len;
32447 info.low_limit = current->mm->mmap_legacy_base;
32448 info.high_limit = TASK_SIZE;
32449 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32450 info.align_offset = 0;
32451+ info.threadstack_offset = offset;
32452 return vm_unmapped_area(&info);
32453 }
32454
32455 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32456 unsigned long addr0, unsigned long len,
32457- unsigned long pgoff, unsigned long flags)
32458+ unsigned long pgoff, unsigned long flags, unsigned long offset)
32459 {
32460 struct hstate *h = hstate_file(file);
32461 struct vm_unmapped_area_info info;
32462@@ -118,6 +119,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32463 info.high_limit = current->mm->mmap_base;
32464 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32465 info.align_offset = 0;
32466+ info.threadstack_offset = offset;
32467 addr = vm_unmapped_area(&info);
32468
32469 /*
32470@@ -130,6 +132,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32471 VM_BUG_ON(addr != -ENOMEM);
32472 info.flags = 0;
32473 info.low_limit = TASK_UNMAPPED_BASE;
32474+
32475+#ifdef CONFIG_PAX_RANDMMAP
32476+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
32477+ info.low_limit += current->mm->delta_mmap;
32478+#endif
32479+
32480 info.high_limit = TASK_SIZE;
32481 addr = vm_unmapped_area(&info);
32482 }
32483@@ -144,10 +152,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32484 struct hstate *h = hstate_file(file);
32485 struct mm_struct *mm = current->mm;
32486 struct vm_area_struct *vma;
32487+ unsigned long pax_task_size = TASK_SIZE;
32488+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
32489
32490 if (len & ~huge_page_mask(h))
32491 return -EINVAL;
32492- if (len > TASK_SIZE)
32493+
32494+#ifdef CONFIG_PAX_SEGMEXEC
32495+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
32496+ pax_task_size = SEGMEXEC_TASK_SIZE;
32497+#endif
32498+
32499+ pax_task_size -= PAGE_SIZE;
32500+
32501+ if (len > pax_task_size)
32502 return -ENOMEM;
32503
32504 if (flags & MAP_FIXED) {
32505@@ -156,19 +174,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32506 return addr;
32507 }
32508
32509+#ifdef CONFIG_PAX_RANDMMAP
32510+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
32511+#endif
32512+
32513 if (addr) {
32514 addr = ALIGN(addr, huge_page_size(h));
32515 vma = find_vma(mm, addr);
32516- if (TASK_SIZE - len >= addr &&
32517- (!vma || addr + len <= vma->vm_start))
32518+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
32519 return addr;
32520 }
32521 if (mm->get_unmapped_area == arch_get_unmapped_area)
32522 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
32523- pgoff, flags);
32524+ pgoff, flags, offset);
32525 else
32526 return hugetlb_get_unmapped_area_topdown(file, addr, len,
32527- pgoff, flags);
32528+ pgoff, flags, offset);
32529 }
32530 #endif /* CONFIG_HUGETLB_PAGE */
32531
32532diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
32533index f971306..e83e0f6 100644
32534--- a/arch/x86/mm/init.c
32535+++ b/arch/x86/mm/init.c
32536@@ -4,6 +4,7 @@
32537 #include <linux/swap.h>
32538 #include <linux/memblock.h>
32539 #include <linux/bootmem.h> /* for max_low_pfn */
32540+#include <linux/tboot.h>
32541
32542 #include <asm/cacheflush.h>
32543 #include <asm/e820.h>
32544@@ -17,6 +18,8 @@
32545 #include <asm/proto.h>
32546 #include <asm/dma.h> /* for MAX_DMA_PFN */
32547 #include <asm/microcode.h>
32548+#include <asm/desc.h>
32549+#include <asm/bios_ebda.h>
32550
32551 #include "mm_internal.h"
32552
32553@@ -563,7 +566,18 @@ void __init init_mem_mapping(void)
32554 early_ioremap_page_table_range_init();
32555 #endif
32556
32557+#ifdef CONFIG_PAX_PER_CPU_PGD
32558+ clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
32559+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32560+ KERNEL_PGD_PTRS);
32561+ clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
32562+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32563+ KERNEL_PGD_PTRS);
32564+ load_cr3(get_cpu_pgd(0, kernel));
32565+#else
32566 load_cr3(swapper_pg_dir);
32567+#endif
32568+
32569 __flush_tlb_all();
32570
32571 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
32572@@ -579,10 +593,40 @@ void __init init_mem_mapping(void)
32573 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
32574 * mmio resources as well as potential bios/acpi data regions.
32575 */
32576+
32577+#ifdef CONFIG_GRKERNSEC_KMEM
32578+static unsigned int ebda_start __read_only;
32579+static unsigned int ebda_end __read_only;
32580+#endif
32581+
32582 int devmem_is_allowed(unsigned long pagenr)
32583 {
32584- if (pagenr < 256)
32585+#ifdef CONFIG_GRKERNSEC_KMEM
32586+ /* allow BDA */
32587+ if (!pagenr)
32588 return 1;
32589+ /* allow EBDA */
32590+ if (pagenr >= ebda_start && pagenr < ebda_end)
32591+ return 1;
32592+ /* if tboot is in use, allow access to its hardcoded serial log range */
32593+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
32594+ return 1;
32595+#else
32596+ if (!pagenr)
32597+ return 1;
32598+#ifdef CONFIG_VM86
32599+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
32600+ return 1;
32601+#endif
32602+#endif
32603+
32604+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
32605+ return 1;
32606+#ifdef CONFIG_GRKERNSEC_KMEM
32607+ /* throw out everything else below 1MB */
32608+ if (pagenr <= 256)
32609+ return 0;
32610+#endif
32611 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
32612 return 0;
32613 if (!page_is_ram(pagenr))
32614@@ -628,8 +672,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
32615 #endif
32616 }
32617
32618+#ifdef CONFIG_GRKERNSEC_KMEM
32619+static inline void gr_init_ebda(void)
32620+{
32621+ unsigned int ebda_addr;
32622+ unsigned int ebda_size = 0;
32623+
32624+ ebda_addr = get_bios_ebda();
32625+ if (ebda_addr) {
32626+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
32627+ ebda_size <<= 10;
32628+ }
32629+ if (ebda_addr && ebda_size) {
32630+ ebda_start = ebda_addr >> PAGE_SHIFT;
32631+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
32632+ } else {
32633+ ebda_start = 0x9f000 >> PAGE_SHIFT;
32634+ ebda_end = 0xa0000 >> PAGE_SHIFT;
32635+ }
32636+}
32637+#else
32638+static inline void gr_init_ebda(void) { }
32639+#endif
32640+
32641 void free_initmem(void)
32642 {
32643+#ifdef CONFIG_PAX_KERNEXEC
32644+#ifdef CONFIG_X86_32
32645+ /* PaX: limit KERNEL_CS to actual size */
32646+ unsigned long addr, limit;
32647+ struct desc_struct d;
32648+ int cpu;
32649+#else
32650+ pgd_t *pgd;
32651+ pud_t *pud;
32652+ pmd_t *pmd;
32653+ unsigned long addr, end;
32654+#endif
32655+#endif
32656+
32657+ gr_init_ebda();
32658+
32659+#ifdef CONFIG_PAX_KERNEXEC
32660+#ifdef CONFIG_X86_32
32661+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
32662+ limit = (limit - 1UL) >> PAGE_SHIFT;
32663+
32664+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
32665+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32666+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
32667+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
32668+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
32669+ }
32670+
32671+ /* PaX: make KERNEL_CS read-only */
32672+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
32673+ if (!paravirt_enabled())
32674+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
32675+/*
32676+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
32677+ pgd = pgd_offset_k(addr);
32678+ pud = pud_offset(pgd, addr);
32679+ pmd = pmd_offset(pud, addr);
32680+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32681+ }
32682+*/
32683+#ifdef CONFIG_X86_PAE
32684+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
32685+/*
32686+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
32687+ pgd = pgd_offset_k(addr);
32688+ pud = pud_offset(pgd, addr);
32689+ pmd = pmd_offset(pud, addr);
32690+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32691+ }
32692+*/
32693+#endif
32694+
32695+#ifdef CONFIG_MODULES
32696+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
32697+#endif
32698+
32699+#else
32700+ /* PaX: make kernel code/rodata read-only, rest non-executable */
32701+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
32702+ pgd = pgd_offset_k(addr);
32703+ pud = pud_offset(pgd, addr);
32704+ pmd = pmd_offset(pud, addr);
32705+ if (!pmd_present(*pmd))
32706+ continue;
32707+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
32708+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32709+ else
32710+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32711+ }
32712+
32713+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
32714+ end = addr + KERNEL_IMAGE_SIZE;
32715+ for (; addr < end; addr += PMD_SIZE) {
32716+ pgd = pgd_offset_k(addr);
32717+ pud = pud_offset(pgd, addr);
32718+ pmd = pmd_offset(pud, addr);
32719+ if (!pmd_present(*pmd))
32720+ continue;
32721+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
32722+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32723+ }
32724+#endif
32725+
32726+ flush_tlb_all();
32727+#endif
32728+
32729 free_init_pages("unused kernel",
32730 (unsigned long)(&__init_begin),
32731 (unsigned long)(&__init_end));
32732diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
32733index e395048..cd38278 100644
32734--- a/arch/x86/mm/init_32.c
32735+++ b/arch/x86/mm/init_32.c
32736@@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
32737 bool __read_mostly __vmalloc_start_set = false;
32738
32739 /*
32740- * Creates a middle page table and puts a pointer to it in the
32741- * given global directory entry. This only returns the gd entry
32742- * in non-PAE compilation mode, since the middle layer is folded.
32743- */
32744-static pmd_t * __init one_md_table_init(pgd_t *pgd)
32745-{
32746- pud_t *pud;
32747- pmd_t *pmd_table;
32748-
32749-#ifdef CONFIG_X86_PAE
32750- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
32751- pmd_table = (pmd_t *)alloc_low_page();
32752- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
32753- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
32754- pud = pud_offset(pgd, 0);
32755- BUG_ON(pmd_table != pmd_offset(pud, 0));
32756-
32757- return pmd_table;
32758- }
32759-#endif
32760- pud = pud_offset(pgd, 0);
32761- pmd_table = pmd_offset(pud, 0);
32762-
32763- return pmd_table;
32764-}
32765-
32766-/*
32767 * Create a page table and place a pointer to it in a middle page
32768 * directory entry:
32769 */
32770@@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
32771 pte_t *page_table = (pte_t *)alloc_low_page();
32772
32773 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
32774+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32775+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
32776+#else
32777 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
32778+#endif
32779 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
32780 }
32781
32782 return pte_offset_kernel(pmd, 0);
32783 }
32784
32785+static pmd_t * __init one_md_table_init(pgd_t *pgd)
32786+{
32787+ pud_t *pud;
32788+ pmd_t *pmd_table;
32789+
32790+ pud = pud_offset(pgd, 0);
32791+ pmd_table = pmd_offset(pud, 0);
32792+
32793+ return pmd_table;
32794+}
32795+
32796 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
32797 {
32798 int pgd_idx = pgd_index(vaddr);
32799@@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32800 int pgd_idx, pmd_idx;
32801 unsigned long vaddr;
32802 pgd_t *pgd;
32803+ pud_t *pud;
32804 pmd_t *pmd;
32805 pte_t *pte = NULL;
32806 unsigned long count = page_table_range_init_count(start, end);
32807@@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32808 pgd = pgd_base + pgd_idx;
32809
32810 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
32811- pmd = one_md_table_init(pgd);
32812- pmd = pmd + pmd_index(vaddr);
32813+ pud = pud_offset(pgd, vaddr);
32814+ pmd = pmd_offset(pud, vaddr);
32815+
32816+#ifdef CONFIG_X86_PAE
32817+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32818+#endif
32819+
32820 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
32821 pmd++, pmd_idx++) {
32822 pte = page_table_kmap_check(one_page_table_init(pmd),
32823@@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32824 }
32825 }
32826
32827-static inline int is_kernel_text(unsigned long addr)
32828+static inline int is_kernel_text(unsigned long start, unsigned long end)
32829 {
32830- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
32831- return 1;
32832- return 0;
32833+ if ((start >= ktla_ktva((unsigned long)_etext) ||
32834+ end <= ktla_ktva((unsigned long)_stext)) &&
32835+ (start >= ktla_ktva((unsigned long)_einittext) ||
32836+ end <= ktla_ktva((unsigned long)_sinittext)) &&
32837+
32838+#ifdef CONFIG_ACPI_SLEEP
32839+ (start >= (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
32840+#endif
32841+
32842+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
32843+ return 0;
32844+ return 1;
32845 }
32846
32847 /*
32848@@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
32849 unsigned long last_map_addr = end;
32850 unsigned long start_pfn, end_pfn;
32851 pgd_t *pgd_base = swapper_pg_dir;
32852- int pgd_idx, pmd_idx, pte_ofs;
32853+ unsigned int pgd_idx, pmd_idx, pte_ofs;
32854 unsigned long pfn;
32855 pgd_t *pgd;
32856+ pud_t *pud;
32857 pmd_t *pmd;
32858 pte_t *pte;
32859 unsigned pages_2m, pages_4k;
32860@@ -291,8 +295,13 @@ repeat:
32861 pfn = start_pfn;
32862 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32863 pgd = pgd_base + pgd_idx;
32864- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
32865- pmd = one_md_table_init(pgd);
32866+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
32867+ pud = pud_offset(pgd, 0);
32868+ pmd = pmd_offset(pud, 0);
32869+
32870+#ifdef CONFIG_X86_PAE
32871+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32872+#endif
32873
32874 if (pfn >= end_pfn)
32875 continue;
32876@@ -304,14 +313,13 @@ repeat:
32877 #endif
32878 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
32879 pmd++, pmd_idx++) {
32880- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
32881+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
32882
32883 /*
32884 * Map with big pages if possible, otherwise
32885 * create normal page tables:
32886 */
32887 if (use_pse) {
32888- unsigned int addr2;
32889 pgprot_t prot = PAGE_KERNEL_LARGE;
32890 /*
32891 * first pass will use the same initial
32892@@ -322,11 +330,7 @@ repeat:
32893 _PAGE_PSE);
32894
32895 pfn &= PMD_MASK >> PAGE_SHIFT;
32896- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
32897- PAGE_OFFSET + PAGE_SIZE-1;
32898-
32899- if (is_kernel_text(addr) ||
32900- is_kernel_text(addr2))
32901+ if (is_kernel_text(address, address + PMD_SIZE))
32902 prot = PAGE_KERNEL_LARGE_EXEC;
32903
32904 pages_2m++;
32905@@ -343,7 +347,7 @@ repeat:
32906 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32907 pte += pte_ofs;
32908 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
32909- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
32910+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
32911 pgprot_t prot = PAGE_KERNEL;
32912 /*
32913 * first pass will use the same initial
32914@@ -351,7 +355,7 @@ repeat:
32915 */
32916 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
32917
32918- if (is_kernel_text(addr))
32919+ if (is_kernel_text(address, address + PAGE_SIZE))
32920 prot = PAGE_KERNEL_EXEC;
32921
32922 pages_4k++;
32923@@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
32924
32925 pud = pud_offset(pgd, va);
32926 pmd = pmd_offset(pud, va);
32927- if (!pmd_present(*pmd))
32928+ if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
32929 break;
32930
32931 /* should not be large page here */
32932@@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
32933
32934 static void __init pagetable_init(void)
32935 {
32936- pgd_t *pgd_base = swapper_pg_dir;
32937-
32938- permanent_kmaps_init(pgd_base);
32939+ permanent_kmaps_init(swapper_pg_dir);
32940 }
32941
32942-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32943+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32944 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32945
32946 /* user-defined highmem size */
32947@@ -787,10 +789,10 @@ void __init mem_init(void)
32948 ((unsigned long)&__init_end -
32949 (unsigned long)&__init_begin) >> 10,
32950
32951- (unsigned long)&_etext, (unsigned long)&_edata,
32952- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
32953+ (unsigned long)&_sdata, (unsigned long)&_edata,
32954+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
32955
32956- (unsigned long)&_text, (unsigned long)&_etext,
32957+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
32958 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
32959
32960 /*
32961@@ -883,6 +885,7 @@ void set_kernel_text_rw(void)
32962 if (!kernel_set_to_readonly)
32963 return;
32964
32965+ start = ktla_ktva(start);
32966 pr_debug("Set kernel text: %lx - %lx for read write\n",
32967 start, start+size);
32968
32969@@ -897,6 +900,7 @@ void set_kernel_text_ro(void)
32970 if (!kernel_set_to_readonly)
32971 return;
32972
32973+ start = ktla_ktva(start);
32974 pr_debug("Set kernel text: %lx - %lx for read only\n",
32975 start, start+size);
32976
32977@@ -925,6 +929,7 @@ void mark_rodata_ro(void)
32978 unsigned long start = PFN_ALIGN(_text);
32979 unsigned long size = PFN_ALIGN(_etext) - start;
32980
32981+ start = ktla_ktva(start);
32982 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
32983 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
32984 size >> 10);
32985diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
32986index f35c66c..84b95ef 100644
32987--- a/arch/x86/mm/init_64.c
32988+++ b/arch/x86/mm/init_64.c
32989@@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
32990 * around without checking the pgd every time.
32991 */
32992
32993-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
32994+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
32995 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32996
32997 int force_personality32;
32998@@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32999
33000 for (address = start; address <= end; address += PGDIR_SIZE) {
33001 const pgd_t *pgd_ref = pgd_offset_k(address);
33002+
33003+#ifdef CONFIG_PAX_PER_CPU_PGD
33004+ unsigned long cpu;
33005+#else
33006 struct page *page;
33007+#endif
33008
33009 if (pgd_none(*pgd_ref))
33010 continue;
33011
33012 spin_lock(&pgd_lock);
33013+
33014+#ifdef CONFIG_PAX_PER_CPU_PGD
33015+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33016+ pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
33017+
33018+ if (pgd_none(*pgd))
33019+ set_pgd(pgd, *pgd_ref);
33020+ else
33021+ BUG_ON(pgd_page_vaddr(*pgd)
33022+ != pgd_page_vaddr(*pgd_ref));
33023+ pgd = pgd_offset_cpu(cpu, kernel, address);
33024+#else
33025 list_for_each_entry(page, &pgd_list, lru) {
33026 pgd_t *pgd;
33027 spinlock_t *pgt_lock;
33028@@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
33029 /* the pgt_lock only for Xen */
33030 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
33031 spin_lock(pgt_lock);
33032+#endif
33033
33034 if (pgd_none(*pgd))
33035 set_pgd(pgd, *pgd_ref);
33036@@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
33037 BUG_ON(pgd_page_vaddr(*pgd)
33038 != pgd_page_vaddr(*pgd_ref));
33039
33040+#ifndef CONFIG_PAX_PER_CPU_PGD
33041 spin_unlock(pgt_lock);
33042+#endif
33043+
33044 }
33045 spin_unlock(&pgd_lock);
33046 }
33047@@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
33048 {
33049 if (pgd_none(*pgd)) {
33050 pud_t *pud = (pud_t *)spp_getpage();
33051- pgd_populate(&init_mm, pgd, pud);
33052+ pgd_populate_kernel(&init_mm, pgd, pud);
33053 if (pud != pud_offset(pgd, 0))
33054 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
33055 pud, pud_offset(pgd, 0));
33056@@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
33057 {
33058 if (pud_none(*pud)) {
33059 pmd_t *pmd = (pmd_t *) spp_getpage();
33060- pud_populate(&init_mm, pud, pmd);
33061+ pud_populate_kernel(&init_mm, pud, pmd);
33062 if (pmd != pmd_offset(pud, 0))
33063 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
33064 pmd, pmd_offset(pud, 0));
33065@@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
33066 pmd = fill_pmd(pud, vaddr);
33067 pte = fill_pte(pmd, vaddr);
33068
33069+ pax_open_kernel();
33070 set_pte(pte, new_pte);
33071+ pax_close_kernel();
33072
33073 /*
33074 * It's enough to flush this one mapping.
33075@@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
33076 pgd = pgd_offset_k((unsigned long)__va(phys));
33077 if (pgd_none(*pgd)) {
33078 pud = (pud_t *) spp_getpage();
33079- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
33080- _PAGE_USER));
33081+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
33082 }
33083 pud = pud_offset(pgd, (unsigned long)__va(phys));
33084 if (pud_none(*pud)) {
33085 pmd = (pmd_t *) spp_getpage();
33086- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
33087- _PAGE_USER));
33088+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
33089 }
33090 pmd = pmd_offset(pud, phys);
33091 BUG_ON(!pmd_none(*pmd));
33092@@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
33093 prot);
33094
33095 spin_lock(&init_mm.page_table_lock);
33096- pud_populate(&init_mm, pud, pmd);
33097+ pud_populate_kernel(&init_mm, pud, pmd);
33098 spin_unlock(&init_mm.page_table_lock);
33099 }
33100 __flush_tlb_all();
33101@@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
33102 page_size_mask);
33103
33104 spin_lock(&init_mm.page_table_lock);
33105- pgd_populate(&init_mm, pgd, pud);
33106+ pgd_populate_kernel(&init_mm, pgd, pud);
33107 spin_unlock(&init_mm.page_table_lock);
33108 pgd_changed = true;
33109 }
33110@@ -1188,8 +1209,8 @@ int kern_addr_valid(unsigned long addr)
33111 static struct vm_area_struct gate_vma = {
33112 .vm_start = VSYSCALL_START,
33113 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
33114- .vm_page_prot = PAGE_READONLY_EXEC,
33115- .vm_flags = VM_READ | VM_EXEC
33116+ .vm_page_prot = PAGE_READONLY,
33117+ .vm_flags = VM_READ
33118 };
33119
33120 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
33121@@ -1223,7 +1244,7 @@ int in_gate_area_no_mm(unsigned long addr)
33122
33123 const char *arch_vma_name(struct vm_area_struct *vma)
33124 {
33125- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
33126+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
33127 return "[vdso]";
33128 if (vma == &gate_vma)
33129 return "[vsyscall]";
33130diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
33131index 7b179b4..6bd17777 100644
33132--- a/arch/x86/mm/iomap_32.c
33133+++ b/arch/x86/mm/iomap_32.c
33134@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
33135 type = kmap_atomic_idx_push();
33136 idx = type + KM_TYPE_NR * smp_processor_id();
33137 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
33138+
33139+ pax_open_kernel();
33140 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
33141+ pax_close_kernel();
33142+
33143 arch_flush_lazy_mmu_mode();
33144
33145 return (void *)vaddr;
33146diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
33147index 799580c..72f9fe0 100644
33148--- a/arch/x86/mm/ioremap.c
33149+++ b/arch/x86/mm/ioremap.c
33150@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
33151 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
33152 int is_ram = page_is_ram(pfn);
33153
33154- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
33155+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
33156 return NULL;
33157 WARN_ON_ONCE(is_ram);
33158 }
33159@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
33160 *
33161 * Caller must ensure there is only one unmapping for the same pointer.
33162 */
33163-void iounmap(volatile void __iomem *addr)
33164+void iounmap(const volatile void __iomem *addr)
33165 {
33166 struct vm_struct *p, *o;
33167
33168@@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
33169
33170 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
33171 if (page_is_ram(start >> PAGE_SHIFT))
33172+#ifdef CONFIG_HIGHMEM
33173+ if ((start >> PAGE_SHIFT) < max_low_pfn)
33174+#endif
33175 return __va(phys);
33176
33177 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
33178@@ -322,6 +325,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
33179 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
33180 {
33181 if (page_is_ram(phys >> PAGE_SHIFT))
33182+#ifdef CONFIG_HIGHMEM
33183+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
33184+#endif
33185 return;
33186
33187 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
33188@@ -339,7 +345,7 @@ static int __init early_ioremap_debug_setup(char *str)
33189 early_param("early_ioremap_debug", early_ioremap_debug_setup);
33190
33191 static __initdata int after_paging_init;
33192-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
33193+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
33194
33195 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
33196 {
33197@@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
33198 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
33199
33200 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
33201- memset(bm_pte, 0, sizeof(bm_pte));
33202- pmd_populate_kernel(&init_mm, pmd, bm_pte);
33203+ pmd_populate_user(&init_mm, pmd, bm_pte);
33204
33205 /*
33206 * The boot-ioremap range spans multiple pmds, for which
33207diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
33208index d87dd6d..bf3fa66 100644
33209--- a/arch/x86/mm/kmemcheck/kmemcheck.c
33210+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
33211@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
33212 * memory (e.g. tracked pages)? For now, we need this to avoid
33213 * invoking kmemcheck for PnP BIOS calls.
33214 */
33215- if (regs->flags & X86_VM_MASK)
33216+ if (v8086_mode(regs))
33217 return false;
33218- if (regs->cs != __KERNEL_CS)
33219+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
33220 return false;
33221
33222 pte = kmemcheck_pte_lookup(address);
33223diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
33224index 25e7e13..1964579 100644
33225--- a/arch/x86/mm/mmap.c
33226+++ b/arch/x86/mm/mmap.c
33227@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
33228 * Leave an at least ~128 MB hole with possible stack randomization.
33229 */
33230 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
33231-#define MAX_GAP (TASK_SIZE/6*5)
33232+#define MAX_GAP (pax_task_size/6*5)
33233
33234 static int mmap_is_legacy(void)
33235 {
33236@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
33237 return rnd << PAGE_SHIFT;
33238 }
33239
33240-static unsigned long mmap_base(void)
33241+static unsigned long mmap_base(struct mm_struct *mm)
33242 {
33243 unsigned long gap = rlimit(RLIMIT_STACK);
33244+ unsigned long pax_task_size = TASK_SIZE;
33245+
33246+#ifdef CONFIG_PAX_SEGMEXEC
33247+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
33248+ pax_task_size = SEGMEXEC_TASK_SIZE;
33249+#endif
33250
33251 if (gap < MIN_GAP)
33252 gap = MIN_GAP;
33253 else if (gap > MAX_GAP)
33254 gap = MAX_GAP;
33255
33256- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
33257+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
33258 }
33259
33260 /*
33261 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
33262 * does, but not when emulating X86_32
33263 */
33264-static unsigned long mmap_legacy_base(void)
33265+static unsigned long mmap_legacy_base(struct mm_struct *mm)
33266 {
33267- if (mmap_is_ia32())
33268+ if (mmap_is_ia32()) {
33269+
33270+#ifdef CONFIG_PAX_SEGMEXEC
33271+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
33272+ return SEGMEXEC_TASK_UNMAPPED_BASE;
33273+ else
33274+#endif
33275+
33276 return TASK_UNMAPPED_BASE;
33277- else
33278+ } else
33279 return TASK_UNMAPPED_BASE + mmap_rnd();
33280 }
33281
33282@@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
33283 */
33284 void arch_pick_mmap_layout(struct mm_struct *mm)
33285 {
33286- mm->mmap_legacy_base = mmap_legacy_base();
33287- mm->mmap_base = mmap_base();
33288+ mm->mmap_legacy_base = mmap_legacy_base(mm);
33289+ mm->mmap_base = mmap_base(mm);
33290+
33291+#ifdef CONFIG_PAX_RANDMMAP
33292+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
33293+ mm->mmap_legacy_base += mm->delta_mmap;
33294+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
33295+ }
33296+#endif
33297
33298 if (mmap_is_legacy()) {
33299 mm->mmap_base = mm->mmap_legacy_base;
33300diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
33301index 0057a7a..95c7edd 100644
33302--- a/arch/x86/mm/mmio-mod.c
33303+++ b/arch/x86/mm/mmio-mod.c
33304@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
33305 break;
33306 default:
33307 {
33308- unsigned char *ip = (unsigned char *)instptr;
33309+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
33310 my_trace->opcode = MMIO_UNKNOWN_OP;
33311 my_trace->width = 0;
33312 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
33313@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
33314 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33315 void __iomem *addr)
33316 {
33317- static atomic_t next_id;
33318+ static atomic_unchecked_t next_id;
33319 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
33320 /* These are page-unaligned. */
33321 struct mmiotrace_map map = {
33322@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33323 .private = trace
33324 },
33325 .phys = offset,
33326- .id = atomic_inc_return(&next_id)
33327+ .id = atomic_inc_return_unchecked(&next_id)
33328 };
33329 map.map_id = trace->id;
33330
33331@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
33332 ioremap_trace_core(offset, size, addr);
33333 }
33334
33335-static void iounmap_trace_core(volatile void __iomem *addr)
33336+static void iounmap_trace_core(const volatile void __iomem *addr)
33337 {
33338 struct mmiotrace_map map = {
33339 .phys = 0,
33340@@ -328,7 +328,7 @@ not_enabled:
33341 }
33342 }
33343
33344-void mmiotrace_iounmap(volatile void __iomem *addr)
33345+void mmiotrace_iounmap(const volatile void __iomem *addr)
33346 {
33347 might_sleep();
33348 if (is_enabled()) /* recheck and proper locking in *_core() */
33349diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
33350index 27aa0455..0eb1406 100644
33351--- a/arch/x86/mm/numa.c
33352+++ b/arch/x86/mm/numa.c
33353@@ -478,7 +478,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
33354 return true;
33355 }
33356
33357-static int __init numa_register_memblks(struct numa_meminfo *mi)
33358+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
33359 {
33360 unsigned long uninitialized_var(pfn_align);
33361 int i, nid;
33362diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
33363index 461bc82..4e091a3 100644
33364--- a/arch/x86/mm/pageattr-test.c
33365+++ b/arch/x86/mm/pageattr-test.c
33366@@ -35,7 +35,7 @@ enum {
33367
33368 static int pte_testbit(pte_t pte)
33369 {
33370- return pte_flags(pte) & _PAGE_UNUSED1;
33371+ return pte_flags(pte) & _PAGE_CPA_TEST;
33372 }
33373
33374 struct split_state {
33375diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
33376index a348868..3c64310 100644
33377--- a/arch/x86/mm/pageattr.c
33378+++ b/arch/x86/mm/pageattr.c
33379@@ -262,7 +262,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33380 */
33381 #ifdef CONFIG_PCI_BIOS
33382 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
33383- pgprot_val(forbidden) |= _PAGE_NX;
33384+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33385 #endif
33386
33387 /*
33388@@ -270,9 +270,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33389 * Does not cover __inittext since that is gone later on. On
33390 * 64bit we do not enforce !NX on the low mapping
33391 */
33392- if (within(address, (unsigned long)_text, (unsigned long)_etext))
33393- pgprot_val(forbidden) |= _PAGE_NX;
33394+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
33395+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33396
33397+#ifdef CONFIG_DEBUG_RODATA
33398 /*
33399 * The .rodata section needs to be read-only. Using the pfn
33400 * catches all aliases.
33401@@ -280,6 +281,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33402 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
33403 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
33404 pgprot_val(forbidden) |= _PAGE_RW;
33405+#endif
33406
33407 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
33408 /*
33409@@ -318,6 +320,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33410 }
33411 #endif
33412
33413+#ifdef CONFIG_PAX_KERNEXEC
33414+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
33415+ pgprot_val(forbidden) |= _PAGE_RW;
33416+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33417+ }
33418+#endif
33419+
33420 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
33421
33422 return prot;
33423@@ -416,23 +425,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
33424 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
33425 {
33426 /* change init_mm */
33427+ pax_open_kernel();
33428 set_pte_atomic(kpte, pte);
33429+
33430 #ifdef CONFIG_X86_32
33431 if (!SHARED_KERNEL_PMD) {
33432+
33433+#ifdef CONFIG_PAX_PER_CPU_PGD
33434+ unsigned long cpu;
33435+#else
33436 struct page *page;
33437+#endif
33438
33439+#ifdef CONFIG_PAX_PER_CPU_PGD
33440+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33441+ pgd_t *pgd = get_cpu_pgd(cpu, kernel);
33442+#else
33443 list_for_each_entry(page, &pgd_list, lru) {
33444- pgd_t *pgd;
33445+ pgd_t *pgd = (pgd_t *)page_address(page);
33446+#endif
33447+
33448 pud_t *pud;
33449 pmd_t *pmd;
33450
33451- pgd = (pgd_t *)page_address(page) + pgd_index(address);
33452+ pgd += pgd_index(address);
33453 pud = pud_offset(pgd, address);
33454 pmd = pmd_offset(pud, address);
33455 set_pte_atomic((pte_t *)pmd, pte);
33456 }
33457 }
33458 #endif
33459+ pax_close_kernel();
33460 }
33461
33462 static int
33463diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
33464index 6574388..87e9bef 100644
33465--- a/arch/x86/mm/pat.c
33466+++ b/arch/x86/mm/pat.c
33467@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
33468
33469 if (!entry) {
33470 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
33471- current->comm, current->pid, start, end - 1);
33472+ current->comm, task_pid_nr(current), start, end - 1);
33473 return -EINVAL;
33474 }
33475
33476@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33477
33478 while (cursor < to) {
33479 if (!devmem_is_allowed(pfn)) {
33480- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
33481- current->comm, from, to - 1);
33482+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
33483+ current->comm, from, to - 1, cursor);
33484 return 0;
33485 }
33486 cursor += PAGE_SIZE;
33487@@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
33488 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
33489 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
33490 "for [mem %#010Lx-%#010Lx]\n",
33491- current->comm, current->pid,
33492+ current->comm, task_pid_nr(current),
33493 cattr_name(flags),
33494 base, (unsigned long long)(base + size-1));
33495 return -EINVAL;
33496@@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33497 flags = lookup_memtype(paddr);
33498 if (want_flags != flags) {
33499 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
33500- current->comm, current->pid,
33501+ current->comm, task_pid_nr(current),
33502 cattr_name(want_flags),
33503 (unsigned long long)paddr,
33504 (unsigned long long)(paddr + size - 1),
33505@@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33506 free_memtype(paddr, paddr + size);
33507 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
33508 " for [mem %#010Lx-%#010Lx], got %s\n",
33509- current->comm, current->pid,
33510+ current->comm, task_pid_nr(current),
33511 cattr_name(want_flags),
33512 (unsigned long long)paddr,
33513 (unsigned long long)(paddr + size - 1),
33514diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
33515index 415f6c4..d319983 100644
33516--- a/arch/x86/mm/pat_rbtree.c
33517+++ b/arch/x86/mm/pat_rbtree.c
33518@@ -160,7 +160,7 @@ success:
33519
33520 failure:
33521 printk(KERN_INFO "%s:%d conflicting memory types "
33522- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
33523+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
33524 end, cattr_name(found_type), cattr_name(match->type));
33525 return -EBUSY;
33526 }
33527diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
33528index 9f0614d..92ae64a 100644
33529--- a/arch/x86/mm/pf_in.c
33530+++ b/arch/x86/mm/pf_in.c
33531@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
33532 int i;
33533 enum reason_type rv = OTHERS;
33534
33535- p = (unsigned char *)ins_addr;
33536+ p = (unsigned char *)ktla_ktva(ins_addr);
33537 p += skip_prefix(p, &prf);
33538 p += get_opcode(p, &opcode);
33539
33540@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
33541 struct prefix_bits prf;
33542 int i;
33543
33544- p = (unsigned char *)ins_addr;
33545+ p = (unsigned char *)ktla_ktva(ins_addr);
33546 p += skip_prefix(p, &prf);
33547 p += get_opcode(p, &opcode);
33548
33549@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
33550 struct prefix_bits prf;
33551 int i;
33552
33553- p = (unsigned char *)ins_addr;
33554+ p = (unsigned char *)ktla_ktva(ins_addr);
33555 p += skip_prefix(p, &prf);
33556 p += get_opcode(p, &opcode);
33557
33558@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
33559 struct prefix_bits prf;
33560 int i;
33561
33562- p = (unsigned char *)ins_addr;
33563+ p = (unsigned char *)ktla_ktva(ins_addr);
33564 p += skip_prefix(p, &prf);
33565 p += get_opcode(p, &opcode);
33566 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
33567@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
33568 struct prefix_bits prf;
33569 int i;
33570
33571- p = (unsigned char *)ins_addr;
33572+ p = (unsigned char *)ktla_ktva(ins_addr);
33573 p += skip_prefix(p, &prf);
33574 p += get_opcode(p, &opcode);
33575 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
33576diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
33577index c96314a..433b127 100644
33578--- a/arch/x86/mm/pgtable.c
33579+++ b/arch/x86/mm/pgtable.c
33580@@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
33581 list_del(&page->lru);
33582 }
33583
33584-#define UNSHARED_PTRS_PER_PGD \
33585- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33586+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33587+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
33588
33589+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
33590+{
33591+ unsigned int count = USER_PGD_PTRS;
33592
33593+ if (!pax_user_shadow_base)
33594+ return;
33595+
33596+ while (count--)
33597+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
33598+}
33599+#endif
33600+
33601+#ifdef CONFIG_PAX_PER_CPU_PGD
33602+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
33603+{
33604+ unsigned int count = USER_PGD_PTRS;
33605+
33606+ while (count--) {
33607+ pgd_t pgd;
33608+
33609+#ifdef CONFIG_X86_64
33610+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
33611+#else
33612+ pgd = *src++;
33613+#endif
33614+
33615+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33616+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
33617+#endif
33618+
33619+ *dst++ = pgd;
33620+ }
33621+
33622+}
33623+#endif
33624+
33625+#ifdef CONFIG_X86_64
33626+#define pxd_t pud_t
33627+#define pyd_t pgd_t
33628+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
33629+#define pgtable_pxd_page_ctor(page) true
33630+#define pgtable_pxd_page_dtor(page)
33631+#define pxd_free(mm, pud) pud_free((mm), (pud))
33632+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
33633+#define pyd_offset(mm, address) pgd_offset((mm), (address))
33634+#define PYD_SIZE PGDIR_SIZE
33635+#else
33636+#define pxd_t pmd_t
33637+#define pyd_t pud_t
33638+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
33639+#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
33640+#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
33641+#define pxd_free(mm, pud) pmd_free((mm), (pud))
33642+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
33643+#define pyd_offset(mm, address) pud_offset((mm), (address))
33644+#define PYD_SIZE PUD_SIZE
33645+#endif
33646+
33647+#ifdef CONFIG_PAX_PER_CPU_PGD
33648+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
33649+static inline void pgd_dtor(pgd_t *pgd) {}
33650+#else
33651 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
33652 {
33653 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
33654@@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
33655 pgd_list_del(pgd);
33656 spin_unlock(&pgd_lock);
33657 }
33658+#endif
33659
33660 /*
33661 * List of all pgd's needed for non-PAE so it can invalidate entries
33662@@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
33663 * -- nyc
33664 */
33665
33666-#ifdef CONFIG_X86_PAE
33667+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
33668 /*
33669 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
33670 * updating the top-level pagetable entries to guarantee the
33671@@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
33672 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
33673 * and initialize the kernel pmds here.
33674 */
33675-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
33676+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33677
33678 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33679 {
33680@@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33681 */
33682 flush_tlb_mm(mm);
33683 }
33684+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
33685+#define PREALLOCATED_PXDS USER_PGD_PTRS
33686 #else /* !CONFIG_X86_PAE */
33687
33688 /* No need to prepopulate any pagetable entries in non-PAE modes. */
33689-#define PREALLOCATED_PMDS 0
33690+#define PREALLOCATED_PXDS 0
33691
33692 #endif /* CONFIG_X86_PAE */
33693
33694-static void free_pmds(pmd_t *pmds[])
33695+static void free_pxds(pxd_t *pxds[])
33696 {
33697 int i;
33698
33699- for(i = 0; i < PREALLOCATED_PMDS; i++)
33700- if (pmds[i]) {
33701- pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
33702- free_page((unsigned long)pmds[i]);
33703+ for(i = 0; i < PREALLOCATED_PXDS; i++)
33704+ if (pxds[i]) {
33705+ pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
33706+ free_page((unsigned long)pxds[i]);
33707 }
33708 }
33709
33710-static int preallocate_pmds(pmd_t *pmds[])
33711+static int preallocate_pxds(pxd_t *pxds[])
33712 {
33713 int i;
33714 bool failed = false;
33715
33716- for(i = 0; i < PREALLOCATED_PMDS; i++) {
33717- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
33718- if (!pmd)
33719+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
33720+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
33721+ if (!pxd)
33722 failed = true;
33723- if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
33724- free_page((unsigned long)pmd);
33725- pmd = NULL;
33726+ if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
33727+ free_page((unsigned long)pxd);
33728+ pxd = NULL;
33729 failed = true;
33730 }
33731- pmds[i] = pmd;
33732+ pxds[i] = pxd;
33733 }
33734
33735 if (failed) {
33736- free_pmds(pmds);
33737+ free_pxds(pxds);
33738 return -ENOMEM;
33739 }
33740
33741@@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
33742 * preallocate which never got a corresponding vma will need to be
33743 * freed manually.
33744 */
33745-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
33746+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
33747 {
33748 int i;
33749
33750- for(i = 0; i < PREALLOCATED_PMDS; i++) {
33751+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
33752 pgd_t pgd = pgdp[i];
33753
33754 if (pgd_val(pgd) != 0) {
33755- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
33756+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
33757
33758- pgdp[i] = native_make_pgd(0);
33759+ set_pgd(pgdp + i, native_make_pgd(0));
33760
33761- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
33762- pmd_free(mm, pmd);
33763+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
33764+ pxd_free(mm, pxd);
33765 }
33766 }
33767 }
33768
33769-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
33770+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
33771 {
33772- pud_t *pud;
33773+ pyd_t *pyd;
33774 int i;
33775
33776- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
33777+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
33778 return;
33779
33780- pud = pud_offset(pgd, 0);
33781-
33782- for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
33783- pmd_t *pmd = pmds[i];
33784+#ifdef CONFIG_X86_64
33785+ pyd = pyd_offset(mm, 0L);
33786+#else
33787+ pyd = pyd_offset(pgd, 0L);
33788+#endif
33789
33790+ for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
33791+ pxd_t *pxd = pxds[i];
33792 if (i >= KERNEL_PGD_BOUNDARY)
33793- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33794- sizeof(pmd_t) * PTRS_PER_PMD);
33795+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33796+ sizeof(pxd_t) * PTRS_PER_PMD);
33797
33798- pud_populate(mm, pud, pmd);
33799+ pyd_populate(mm, pyd, pxd);
33800 }
33801 }
33802
33803 pgd_t *pgd_alloc(struct mm_struct *mm)
33804 {
33805 pgd_t *pgd;
33806- pmd_t *pmds[PREALLOCATED_PMDS];
33807+ pxd_t *pxds[PREALLOCATED_PXDS];
33808
33809 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
33810
33811@@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33812
33813 mm->pgd = pgd;
33814
33815- if (preallocate_pmds(pmds) != 0)
33816+ if (preallocate_pxds(pxds) != 0)
33817 goto out_free_pgd;
33818
33819 if (paravirt_pgd_alloc(mm) != 0)
33820- goto out_free_pmds;
33821+ goto out_free_pxds;
33822
33823 /*
33824 * Make sure that pre-populating the pmds is atomic with
33825@@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33826 spin_lock(&pgd_lock);
33827
33828 pgd_ctor(mm, pgd);
33829- pgd_prepopulate_pmd(mm, pgd, pmds);
33830+ pgd_prepopulate_pxd(mm, pgd, pxds);
33831
33832 spin_unlock(&pgd_lock);
33833
33834 return pgd;
33835
33836-out_free_pmds:
33837- free_pmds(pmds);
33838+out_free_pxds:
33839+ free_pxds(pxds);
33840 out_free_pgd:
33841 free_page((unsigned long)pgd);
33842 out:
33843@@ -313,7 +380,7 @@ out:
33844
33845 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
33846 {
33847- pgd_mop_up_pmds(mm, pgd);
33848+ pgd_mop_up_pxds(mm, pgd);
33849 pgd_dtor(pgd);
33850 paravirt_pgd_free(mm, pgd);
33851 free_page((unsigned long)pgd);
33852diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
33853index a69bcb8..19068ab 100644
33854--- a/arch/x86/mm/pgtable_32.c
33855+++ b/arch/x86/mm/pgtable_32.c
33856@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
33857 return;
33858 }
33859 pte = pte_offset_kernel(pmd, vaddr);
33860+
33861+ pax_open_kernel();
33862 if (pte_val(pteval))
33863 set_pte_at(&init_mm, vaddr, pte, pteval);
33864 else
33865 pte_clear(&init_mm, vaddr, pte);
33866+ pax_close_kernel();
33867
33868 /*
33869 * It's enough to flush this one mapping.
33870diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
33871index e666cbb..61788c45 100644
33872--- a/arch/x86/mm/physaddr.c
33873+++ b/arch/x86/mm/physaddr.c
33874@@ -10,7 +10,7 @@
33875 #ifdef CONFIG_X86_64
33876
33877 #ifdef CONFIG_DEBUG_VIRTUAL
33878-unsigned long __phys_addr(unsigned long x)
33879+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33880 {
33881 unsigned long y = x - __START_KERNEL_map;
33882
33883@@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
33884 #else
33885
33886 #ifdef CONFIG_DEBUG_VIRTUAL
33887-unsigned long __phys_addr(unsigned long x)
33888+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33889 {
33890 unsigned long phys_addr = x - PAGE_OFFSET;
33891 /* VMALLOC_* aren't constants */
33892diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
33893index 90555bf..f5f1828 100644
33894--- a/arch/x86/mm/setup_nx.c
33895+++ b/arch/x86/mm/setup_nx.c
33896@@ -5,8 +5,10 @@
33897 #include <asm/pgtable.h>
33898 #include <asm/proto.h>
33899
33900+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33901 static int disable_nx;
33902
33903+#ifndef CONFIG_PAX_PAGEEXEC
33904 /*
33905 * noexec = on|off
33906 *
33907@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
33908 return 0;
33909 }
33910 early_param("noexec", noexec_setup);
33911+#endif
33912+
33913+#endif
33914
33915 void x86_configure_nx(void)
33916 {
33917+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33918 if (cpu_has_nx && !disable_nx)
33919 __supported_pte_mask |= _PAGE_NX;
33920 else
33921+#endif
33922 __supported_pte_mask &= ~_PAGE_NX;
33923 }
33924
33925diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
33926index dd8dda1..9e9b0f6 100644
33927--- a/arch/x86/mm/tlb.c
33928+++ b/arch/x86/mm/tlb.c
33929@@ -48,7 +48,11 @@ void leave_mm(int cpu)
33930 BUG();
33931 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
33932 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
33933+
33934+#ifndef CONFIG_PAX_PER_CPU_PGD
33935 load_cr3(swapper_pg_dir);
33936+#endif
33937+
33938 }
33939 }
33940 EXPORT_SYMBOL_GPL(leave_mm);
33941diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
33942new file mode 100644
33943index 0000000..dace51c
33944--- /dev/null
33945+++ b/arch/x86/mm/uderef_64.c
33946@@ -0,0 +1,37 @@
33947+#include <linux/mm.h>
33948+#include <asm/pgtable.h>
33949+#include <asm/uaccess.h>
33950+
33951+#ifdef CONFIG_PAX_MEMORY_UDEREF
33952+/* PaX: due to the special call convention these functions must
33953+ * - remain leaf functions under all configurations,
33954+ * - never be called directly, only dereferenced from the wrappers.
33955+ */
33956+void __pax_open_userland(void)
33957+{
33958+ unsigned int cpu;
33959+
33960+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
33961+ return;
33962+
33963+ cpu = raw_get_cpu();
33964+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
33965+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
33966+ raw_put_cpu_no_resched();
33967+}
33968+EXPORT_SYMBOL(__pax_open_userland);
33969+
33970+void __pax_close_userland(void)
33971+{
33972+ unsigned int cpu;
33973+
33974+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
33975+ return;
33976+
33977+ cpu = raw_get_cpu();
33978+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
33979+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
33980+ raw_put_cpu_no_resched();
33981+}
33982+EXPORT_SYMBOL(__pax_close_userland);
33983+#endif
33984diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
33985index 0149575..f746de8 100644
33986--- a/arch/x86/net/bpf_jit.S
33987+++ b/arch/x86/net/bpf_jit.S
33988@@ -9,6 +9,7 @@
33989 */
33990 #include <linux/linkage.h>
33991 #include <asm/dwarf2.h>
33992+#include <asm/alternative-asm.h>
33993
33994 /*
33995 * Calling convention :
33996@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
33997 jle bpf_slow_path_word
33998 mov (SKBDATA,%rsi),%eax
33999 bswap %eax /* ntohl() */
34000+ pax_force_retaddr
34001 ret
34002
34003 sk_load_half:
34004@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
34005 jle bpf_slow_path_half
34006 movzwl (SKBDATA,%rsi),%eax
34007 rol $8,%ax # ntohs()
34008+ pax_force_retaddr
34009 ret
34010
34011 sk_load_byte:
34012@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
34013 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
34014 jle bpf_slow_path_byte
34015 movzbl (SKBDATA,%rsi),%eax
34016+ pax_force_retaddr
34017 ret
34018
34019 /**
34020@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
34021 movzbl (SKBDATA,%rsi),%ebx
34022 and $15,%bl
34023 shl $2,%bl
34024+ pax_force_retaddr
34025 ret
34026
34027 /* rsi contains offset and can be scratched */
34028@@ -109,6 +114,7 @@ bpf_slow_path_word:
34029 js bpf_error
34030 mov -12(%rbp),%eax
34031 bswap %eax
34032+ pax_force_retaddr
34033 ret
34034
34035 bpf_slow_path_half:
34036@@ -117,12 +123,14 @@ bpf_slow_path_half:
34037 mov -12(%rbp),%ax
34038 rol $8,%ax
34039 movzwl %ax,%eax
34040+ pax_force_retaddr
34041 ret
34042
34043 bpf_slow_path_byte:
34044 bpf_slow_path_common(1)
34045 js bpf_error
34046 movzbl -12(%rbp),%eax
34047+ pax_force_retaddr
34048 ret
34049
34050 bpf_slow_path_byte_msh:
34051@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
34052 and $15,%al
34053 shl $2,%al
34054 xchg %eax,%ebx
34055+ pax_force_retaddr
34056 ret
34057
34058 #define sk_negative_common(SIZE) \
34059@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
34060 sk_negative_common(4)
34061 mov (%rax), %eax
34062 bswap %eax
34063+ pax_force_retaddr
34064 ret
34065
34066 bpf_slow_path_half_neg:
34067@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
34068 mov (%rax),%ax
34069 rol $8,%ax
34070 movzwl %ax,%eax
34071+ pax_force_retaddr
34072 ret
34073
34074 bpf_slow_path_byte_neg:
34075@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
34076 .globl sk_load_byte_negative_offset
34077 sk_negative_common(1)
34078 movzbl (%rax), %eax
34079+ pax_force_retaddr
34080 ret
34081
34082 bpf_slow_path_byte_msh_neg:
34083@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
34084 and $15,%al
34085 shl $2,%al
34086 xchg %eax,%ebx
34087+ pax_force_retaddr
34088 ret
34089
34090 bpf_error:
34091@@ -197,4 +210,5 @@ bpf_error:
34092 xor %eax,%eax
34093 mov -8(%rbp),%rbx
34094 leaveq
34095+ pax_force_retaddr
34096 ret
34097diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
34098index 4ed75dd..3cf24f0b 100644
34099--- a/arch/x86/net/bpf_jit_comp.c
34100+++ b/arch/x86/net/bpf_jit_comp.c
34101@@ -50,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
34102 return ptr + len;
34103 }
34104
34105+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34106+#define MAX_INSTR_CODE_SIZE 96
34107+#else
34108+#define MAX_INSTR_CODE_SIZE 64
34109+#endif
34110+
34111 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
34112
34113 #define EMIT1(b1) EMIT(b1, 1)
34114 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
34115 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
34116 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
34117+
34118+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34119+/* original constant will appear in ecx */
34120+#define DILUTE_CONST_SEQUENCE(_off, _key) \
34121+do { \
34122+ /* mov ecx, randkey */ \
34123+ EMIT1(0xb9); \
34124+ EMIT(_key, 4); \
34125+ /* xor ecx, randkey ^ off */ \
34126+ EMIT2(0x81, 0xf1); \
34127+ EMIT((_key) ^ (_off), 4); \
34128+} while (0)
34129+
34130+#define EMIT1_off32(b1, _off) \
34131+do { \
34132+ switch (b1) { \
34133+ case 0x05: /* add eax, imm32 */ \
34134+ case 0x2d: /* sub eax, imm32 */ \
34135+ case 0x25: /* and eax, imm32 */ \
34136+ case 0x0d: /* or eax, imm32 */ \
34137+ case 0xb8: /* mov eax, imm32 */ \
34138+ case 0x35: /* xor eax, imm32 */ \
34139+ case 0x3d: /* cmp eax, imm32 */ \
34140+ case 0xa9: /* test eax, imm32 */ \
34141+ DILUTE_CONST_SEQUENCE(_off, randkey); \
34142+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
34143+ break; \
34144+ case 0xbb: /* mov ebx, imm32 */ \
34145+ DILUTE_CONST_SEQUENCE(_off, randkey); \
34146+ /* mov ebx, ecx */ \
34147+ EMIT2(0x89, 0xcb); \
34148+ break; \
34149+ case 0xbe: /* mov esi, imm32 */ \
34150+ DILUTE_CONST_SEQUENCE(_off, randkey); \
34151+ /* mov esi, ecx */ \
34152+ EMIT2(0x89, 0xce); \
34153+ break; \
34154+ case 0xe8: /* call rel imm32, always to known funcs */ \
34155+ EMIT1(b1); \
34156+ EMIT(_off, 4); \
34157+ break; \
34158+ case 0xe9: /* jmp rel imm32 */ \
34159+ EMIT1(b1); \
34160+ EMIT(_off, 4); \
34161+ /* prevent fall-through, we're not called if off = 0 */ \
34162+ EMIT(0xcccccccc, 4); \
34163+ EMIT(0xcccccccc, 4); \
34164+ break; \
34165+ default: \
34166+ BUILD_BUG(); \
34167+ } \
34168+} while (0)
34169+
34170+#define EMIT2_off32(b1, b2, _off) \
34171+do { \
34172+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
34173+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
34174+ EMIT(randkey, 4); \
34175+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
34176+ EMIT((_off) - randkey, 4); \
34177+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
34178+ DILUTE_CONST_SEQUENCE(_off, randkey); \
34179+ /* imul eax, ecx */ \
34180+ EMIT3(0x0f, 0xaf, 0xc1); \
34181+ } else { \
34182+ BUILD_BUG(); \
34183+ } \
34184+} while (0)
34185+#else
34186 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
34187+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
34188+#endif
34189
34190 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
34191 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
34192@@ -91,6 +168,24 @@ do { \
34193 #define X86_JBE 0x76
34194 #define X86_JA 0x77
34195
34196+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34197+#define APPEND_FLOW_VERIFY() \
34198+do { \
34199+ /* mov ecx, randkey */ \
34200+ EMIT1(0xb9); \
34201+ EMIT(randkey, 4); \
34202+ /* cmp ecx, randkey */ \
34203+ EMIT2(0x81, 0xf9); \
34204+ EMIT(randkey, 4); \
34205+ /* jz after 8 int 3s */ \
34206+ EMIT2(0x74, 0x08); \
34207+ EMIT(0xcccccccc, 4); \
34208+ EMIT(0xcccccccc, 4); \
34209+} while (0)
34210+#else
34211+#define APPEND_FLOW_VERIFY() do { } while (0)
34212+#endif
34213+
34214 #define EMIT_COND_JMP(op, offset) \
34215 do { \
34216 if (is_near(offset)) \
34217@@ -98,6 +193,7 @@ do { \
34218 else { \
34219 EMIT2(0x0f, op + 0x10); \
34220 EMIT(offset, 4); /* jxx .+off32 */ \
34221+ APPEND_FLOW_VERIFY(); \
34222 } \
34223 } while (0)
34224
34225@@ -145,55 +241,54 @@ static int pkt_type_offset(void)
34226 return -1;
34227 }
34228
34229-struct bpf_binary_header {
34230- unsigned int pages;
34231- /* Note : for security reasons, bpf code will follow a randomly
34232- * sized amount of int3 instructions
34233- */
34234- u8 image[];
34235-};
34236-
34237-static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
34238+/* Note : for security reasons, bpf code will follow a randomly
34239+ * sized amount of int3 instructions
34240+ */
34241+static u8 *bpf_alloc_binary(unsigned int proglen,
34242 u8 **image_ptr)
34243 {
34244 unsigned int sz, hole;
34245- struct bpf_binary_header *header;
34246+ u8 *header;
34247
34248 /* Most of BPF filters are really small,
34249 * but if some of them fill a page, allow at least
34250 * 128 extra bytes to insert a random section of int3
34251 */
34252- sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
34253- header = module_alloc(sz);
34254+ sz = round_up(proglen + 128, PAGE_SIZE);
34255+ header = module_alloc_exec(sz);
34256 if (!header)
34257 return NULL;
34258
34259+ pax_open_kernel();
34260 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
34261+ pax_close_kernel();
34262
34263- header->pages = sz / PAGE_SIZE;
34264- hole = sz - (proglen + sizeof(*header));
34265+ hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
34266
34267 /* insert a random number of int3 instructions before BPF code */
34268- *image_ptr = &header->image[prandom_u32() % hole];
34269+ *image_ptr = &header[prandom_u32() % hole];
34270 return header;
34271 }
34272
34273 void bpf_jit_compile(struct sk_filter *fp)
34274 {
34275- u8 temp[64];
34276+ u8 temp[MAX_INSTR_CODE_SIZE];
34277 u8 *prog;
34278 unsigned int proglen, oldproglen = 0;
34279 int ilen, i;
34280 int t_offset, f_offset;
34281 u8 t_op, f_op, seen = 0, pass;
34282 u8 *image = NULL;
34283- struct bpf_binary_header *header = NULL;
34284+ u8 *header = NULL;
34285 u8 *func;
34286 int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
34287 unsigned int cleanup_addr; /* epilogue code offset */
34288 unsigned int *addrs;
34289 const struct sock_filter *filter = fp->insns;
34290 int flen = fp->len;
34291+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34292+ unsigned int randkey;
34293+#endif
34294
34295 if (!bpf_jit_enable)
34296 return;
34297@@ -203,10 +298,10 @@ void bpf_jit_compile(struct sk_filter *fp)
34298 return;
34299
34300 /* Before first pass, make a rough estimation of addrs[]
34301- * each bpf instruction is translated to less than 64 bytes
34302+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
34303 */
34304 for (proglen = 0, i = 0; i < flen; i++) {
34305- proglen += 64;
34306+ proglen += MAX_INSTR_CODE_SIZE;
34307 addrs[i] = proglen;
34308 }
34309 cleanup_addr = proglen; /* epilogue address */
34310@@ -285,6 +380,10 @@ void bpf_jit_compile(struct sk_filter *fp)
34311 for (i = 0; i < flen; i++) {
34312 unsigned int K = filter[i].k;
34313
34314+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34315+ randkey = prandom_u32();
34316+#endif
34317+
34318 switch (filter[i].code) {
34319 case BPF_S_ALU_ADD_X: /* A += X; */
34320 seen |= SEEN_XREG;
34321@@ -317,10 +416,8 @@ void bpf_jit_compile(struct sk_filter *fp)
34322 case BPF_S_ALU_MUL_K: /* A *= K */
34323 if (is_imm8(K))
34324 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
34325- else {
34326- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
34327- EMIT(K, 4);
34328- }
34329+ else
34330+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
34331 break;
34332 case BPF_S_ALU_DIV_X: /* A /= X; */
34333 seen |= SEEN_XREG;
34334@@ -364,7 +461,11 @@ void bpf_jit_compile(struct sk_filter *fp)
34335 break;
34336 }
34337 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
34338+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34339+ DILUTE_CONST_SEQUENCE(K, randkey);
34340+#else
34341 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
34342+#endif
34343 EMIT2(0xf7, 0xf1); /* div %ecx */
34344 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
34345 break;
34346@@ -372,7 +473,11 @@ void bpf_jit_compile(struct sk_filter *fp)
34347 if (K == 1)
34348 break;
34349 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
34350+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34351+ DILUTE_CONST_SEQUENCE(K, randkey);
34352+#else
34353 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
34354+#endif
34355 EMIT2(0xf7, 0xf1); /* div %ecx */
34356 break;
34357 case BPF_S_ALU_AND_X:
34358@@ -643,8 +748,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
34359 if (is_imm8(K)) {
34360 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
34361 } else {
34362- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
34363- EMIT(K, 4);
34364+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
34365 }
34366 } else {
34367 EMIT2(0x89,0xde); /* mov %ebx,%esi */
34368@@ -734,10 +838,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
34369 if (unlikely(proglen + ilen > oldproglen)) {
34370 pr_err("bpb_jit_compile fatal error\n");
34371 kfree(addrs);
34372- module_free(NULL, header);
34373+ module_free_exec(NULL, image);
34374 return;
34375 }
34376+ pax_open_kernel();
34377 memcpy(image + proglen, temp, ilen);
34378+ pax_close_kernel();
34379 }
34380 proglen += ilen;
34381 addrs[i] = proglen;
34382@@ -770,7 +876,6 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
34383
34384 if (image) {
34385 bpf_flush_icache(header, image + proglen);
34386- set_memory_ro((unsigned long)header, header->pages);
34387 fp->bpf_func = (void *)image;
34388 }
34389 out:
34390@@ -782,10 +887,9 @@ static void bpf_jit_free_deferred(struct work_struct *work)
34391 {
34392 struct sk_filter *fp = container_of(work, struct sk_filter, work);
34393 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
34394- struct bpf_binary_header *header = (void *)addr;
34395
34396- set_memory_rw(addr, header->pages);
34397- module_free(NULL, header);
34398+ set_memory_rw(addr, 1);
34399+ module_free_exec(NULL, (void *)addr);
34400 kfree(fp);
34401 }
34402
34403diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
34404index 5d04be5..2beeaa2 100644
34405--- a/arch/x86/oprofile/backtrace.c
34406+++ b/arch/x86/oprofile/backtrace.c
34407@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
34408 struct stack_frame_ia32 *fp;
34409 unsigned long bytes;
34410
34411- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34412+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34413 if (bytes != 0)
34414 return NULL;
34415
34416- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
34417+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
34418
34419 oprofile_add_trace(bufhead[0].return_address);
34420
34421@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
34422 struct stack_frame bufhead[2];
34423 unsigned long bytes;
34424
34425- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34426+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34427 if (bytes != 0)
34428 return NULL;
34429
34430@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
34431 {
34432 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
34433
34434- if (!user_mode_vm(regs)) {
34435+ if (!user_mode(regs)) {
34436 unsigned long stack = kernel_stack_pointer(regs);
34437 if (depth)
34438 dump_trace(NULL, regs, (unsigned long *)stack, 0,
34439diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
34440index 6890d84..1dad1f1 100644
34441--- a/arch/x86/oprofile/nmi_int.c
34442+++ b/arch/x86/oprofile/nmi_int.c
34443@@ -23,6 +23,7 @@
34444 #include <asm/nmi.h>
34445 #include <asm/msr.h>
34446 #include <asm/apic.h>
34447+#include <asm/pgtable.h>
34448
34449 #include "op_counter.h"
34450 #include "op_x86_model.h"
34451@@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
34452 if (ret)
34453 return ret;
34454
34455- if (!model->num_virt_counters)
34456- model->num_virt_counters = model->num_counters;
34457+ if (!model->num_virt_counters) {
34458+ pax_open_kernel();
34459+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
34460+ pax_close_kernel();
34461+ }
34462
34463 mux_init(ops);
34464
34465diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
34466index 50d86c0..7985318 100644
34467--- a/arch/x86/oprofile/op_model_amd.c
34468+++ b/arch/x86/oprofile/op_model_amd.c
34469@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
34470 num_counters = AMD64_NUM_COUNTERS;
34471 }
34472
34473- op_amd_spec.num_counters = num_counters;
34474- op_amd_spec.num_controls = num_counters;
34475- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34476+ pax_open_kernel();
34477+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
34478+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
34479+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34480+ pax_close_kernel();
34481
34482 return 0;
34483 }
34484diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
34485index d90528e..0127e2b 100644
34486--- a/arch/x86/oprofile/op_model_ppro.c
34487+++ b/arch/x86/oprofile/op_model_ppro.c
34488@@ -19,6 +19,7 @@
34489 #include <asm/msr.h>
34490 #include <asm/apic.h>
34491 #include <asm/nmi.h>
34492+#include <asm/pgtable.h>
34493
34494 #include "op_x86_model.h"
34495 #include "op_counter.h"
34496@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
34497
34498 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
34499
34500- op_arch_perfmon_spec.num_counters = num_counters;
34501- op_arch_perfmon_spec.num_controls = num_counters;
34502+ pax_open_kernel();
34503+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
34504+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
34505+ pax_close_kernel();
34506 }
34507
34508 static int arch_perfmon_init(struct oprofile_operations *ignore)
34509diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
34510index 71e8a67..6a313bb 100644
34511--- a/arch/x86/oprofile/op_x86_model.h
34512+++ b/arch/x86/oprofile/op_x86_model.h
34513@@ -52,7 +52,7 @@ struct op_x86_model_spec {
34514 void (*switch_ctrl)(struct op_x86_model_spec const *model,
34515 struct op_msrs const * const msrs);
34516 #endif
34517-};
34518+} __do_const;
34519
34520 struct op_counter_config;
34521
34522diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
34523index 84b9d67..260e5ff 100644
34524--- a/arch/x86/pci/intel_mid_pci.c
34525+++ b/arch/x86/pci/intel_mid_pci.c
34526@@ -245,7 +245,7 @@ int __init intel_mid_pci_init(void)
34527 pr_info("Intel MID platform detected, using MID PCI ops\n");
34528 pci_mmcfg_late_init();
34529 pcibios_enable_irq = intel_mid_pci_irq_enable;
34530- pci_root_ops = intel_mid_pci_ops;
34531+ memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
34532 pci_soc_mode = 1;
34533 /* Continue with standard init */
34534 return 1;
34535diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
34536index 372e9b8..e775a6c 100644
34537--- a/arch/x86/pci/irq.c
34538+++ b/arch/x86/pci/irq.c
34539@@ -50,7 +50,7 @@ struct irq_router {
34540 struct irq_router_handler {
34541 u16 vendor;
34542 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
34543-};
34544+} __do_const;
34545
34546 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
34547 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
34548@@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
34549 return 0;
34550 }
34551
34552-static __initdata struct irq_router_handler pirq_routers[] = {
34553+static __initconst const struct irq_router_handler pirq_routers[] = {
34554 { PCI_VENDOR_ID_INTEL, intel_router_probe },
34555 { PCI_VENDOR_ID_AL, ali_router_probe },
34556 { PCI_VENDOR_ID_ITE, ite_router_probe },
34557@@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
34558 static void __init pirq_find_router(struct irq_router *r)
34559 {
34560 struct irq_routing_table *rt = pirq_table;
34561- struct irq_router_handler *h;
34562+ const struct irq_router_handler *h;
34563
34564 #ifdef CONFIG_PCI_BIOS
34565 if (!rt->signature) {
34566@@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
34567 return 0;
34568 }
34569
34570-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
34571+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
34572 {
34573 .callback = fix_broken_hp_bios_irq9,
34574 .ident = "HP Pavilion N5400 Series Laptop",
34575diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
34576index c77b24a..c979855 100644
34577--- a/arch/x86/pci/pcbios.c
34578+++ b/arch/x86/pci/pcbios.c
34579@@ -79,7 +79,7 @@ union bios32 {
34580 static struct {
34581 unsigned long address;
34582 unsigned short segment;
34583-} bios32_indirect = { 0, __KERNEL_CS };
34584+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
34585
34586 /*
34587 * Returns the entry point for the given service, NULL on error
34588@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
34589 unsigned long length; /* %ecx */
34590 unsigned long entry; /* %edx */
34591 unsigned long flags;
34592+ struct desc_struct d, *gdt;
34593
34594 local_irq_save(flags);
34595- __asm__("lcall *(%%edi); cld"
34596+
34597+ gdt = get_cpu_gdt_table(smp_processor_id());
34598+
34599+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
34600+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34601+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
34602+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34603+
34604+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
34605 : "=a" (return_code),
34606 "=b" (address),
34607 "=c" (length),
34608 "=d" (entry)
34609 : "0" (service),
34610 "1" (0),
34611- "D" (&bios32_indirect));
34612+ "D" (&bios32_indirect),
34613+ "r"(__PCIBIOS_DS)
34614+ : "memory");
34615+
34616+ pax_open_kernel();
34617+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
34618+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
34619+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
34620+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
34621+ pax_close_kernel();
34622+
34623 local_irq_restore(flags);
34624
34625 switch (return_code) {
34626- case 0:
34627- return address + entry;
34628- case 0x80: /* Not present */
34629- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34630- return 0;
34631- default: /* Shouldn't happen */
34632- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34633- service, return_code);
34634+ case 0: {
34635+ int cpu;
34636+ unsigned char flags;
34637+
34638+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
34639+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
34640+ printk(KERN_WARNING "bios32_service: not valid\n");
34641 return 0;
34642+ }
34643+ address = address + PAGE_OFFSET;
34644+ length += 16UL; /* some BIOSs underreport this... */
34645+ flags = 4;
34646+ if (length >= 64*1024*1024) {
34647+ length >>= PAGE_SHIFT;
34648+ flags |= 8;
34649+ }
34650+
34651+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
34652+ gdt = get_cpu_gdt_table(cpu);
34653+ pack_descriptor(&d, address, length, 0x9b, flags);
34654+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34655+ pack_descriptor(&d, address, length, 0x93, flags);
34656+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34657+ }
34658+ return entry;
34659+ }
34660+ case 0x80: /* Not present */
34661+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34662+ return 0;
34663+ default: /* Shouldn't happen */
34664+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34665+ service, return_code);
34666+ return 0;
34667 }
34668 }
34669
34670 static struct {
34671 unsigned long address;
34672 unsigned short segment;
34673-} pci_indirect = { 0, __KERNEL_CS };
34674+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
34675
34676-static int pci_bios_present;
34677+static int pci_bios_present __read_only;
34678
34679 static int check_pcibios(void)
34680 {
34681@@ -131,11 +174,13 @@ static int check_pcibios(void)
34682 unsigned long flags, pcibios_entry;
34683
34684 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
34685- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
34686+ pci_indirect.address = pcibios_entry;
34687
34688 local_irq_save(flags);
34689- __asm__(
34690- "lcall *(%%edi); cld\n\t"
34691+ __asm__("movw %w6, %%ds\n\t"
34692+ "lcall *%%ss:(%%edi); cld\n\t"
34693+ "push %%ss\n\t"
34694+ "pop %%ds\n\t"
34695 "jc 1f\n\t"
34696 "xor %%ah, %%ah\n"
34697 "1:"
34698@@ -144,7 +189,8 @@ static int check_pcibios(void)
34699 "=b" (ebx),
34700 "=c" (ecx)
34701 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
34702- "D" (&pci_indirect)
34703+ "D" (&pci_indirect),
34704+ "r" (__PCIBIOS_DS)
34705 : "memory");
34706 local_irq_restore(flags);
34707
34708@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34709
34710 switch (len) {
34711 case 1:
34712- __asm__("lcall *(%%esi); cld\n\t"
34713+ __asm__("movw %w6, %%ds\n\t"
34714+ "lcall *%%ss:(%%esi); cld\n\t"
34715+ "push %%ss\n\t"
34716+ "pop %%ds\n\t"
34717 "jc 1f\n\t"
34718 "xor %%ah, %%ah\n"
34719 "1:"
34720@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34721 : "1" (PCIBIOS_READ_CONFIG_BYTE),
34722 "b" (bx),
34723 "D" ((long)reg),
34724- "S" (&pci_indirect));
34725+ "S" (&pci_indirect),
34726+ "r" (__PCIBIOS_DS));
34727 /*
34728 * Zero-extend the result beyond 8 bits, do not trust the
34729 * BIOS having done it:
34730@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34731 *value &= 0xff;
34732 break;
34733 case 2:
34734- __asm__("lcall *(%%esi); cld\n\t"
34735+ __asm__("movw %w6, %%ds\n\t"
34736+ "lcall *%%ss:(%%esi); cld\n\t"
34737+ "push %%ss\n\t"
34738+ "pop %%ds\n\t"
34739 "jc 1f\n\t"
34740 "xor %%ah, %%ah\n"
34741 "1:"
34742@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34743 : "1" (PCIBIOS_READ_CONFIG_WORD),
34744 "b" (bx),
34745 "D" ((long)reg),
34746- "S" (&pci_indirect));
34747+ "S" (&pci_indirect),
34748+ "r" (__PCIBIOS_DS));
34749 /*
34750 * Zero-extend the result beyond 16 bits, do not trust the
34751 * BIOS having done it:
34752@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34753 *value &= 0xffff;
34754 break;
34755 case 4:
34756- __asm__("lcall *(%%esi); cld\n\t"
34757+ __asm__("movw %w6, %%ds\n\t"
34758+ "lcall *%%ss:(%%esi); cld\n\t"
34759+ "push %%ss\n\t"
34760+ "pop %%ds\n\t"
34761 "jc 1f\n\t"
34762 "xor %%ah, %%ah\n"
34763 "1:"
34764@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34765 : "1" (PCIBIOS_READ_CONFIG_DWORD),
34766 "b" (bx),
34767 "D" ((long)reg),
34768- "S" (&pci_indirect));
34769+ "S" (&pci_indirect),
34770+ "r" (__PCIBIOS_DS));
34771 break;
34772 }
34773
34774@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34775
34776 switch (len) {
34777 case 1:
34778- __asm__("lcall *(%%esi); cld\n\t"
34779+ __asm__("movw %w6, %%ds\n\t"
34780+ "lcall *%%ss:(%%esi); cld\n\t"
34781+ "push %%ss\n\t"
34782+ "pop %%ds\n\t"
34783 "jc 1f\n\t"
34784 "xor %%ah, %%ah\n"
34785 "1:"
34786@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34787 "c" (value),
34788 "b" (bx),
34789 "D" ((long)reg),
34790- "S" (&pci_indirect));
34791+ "S" (&pci_indirect),
34792+ "r" (__PCIBIOS_DS));
34793 break;
34794 case 2:
34795- __asm__("lcall *(%%esi); cld\n\t"
34796+ __asm__("movw %w6, %%ds\n\t"
34797+ "lcall *%%ss:(%%esi); cld\n\t"
34798+ "push %%ss\n\t"
34799+ "pop %%ds\n\t"
34800 "jc 1f\n\t"
34801 "xor %%ah, %%ah\n"
34802 "1:"
34803@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34804 "c" (value),
34805 "b" (bx),
34806 "D" ((long)reg),
34807- "S" (&pci_indirect));
34808+ "S" (&pci_indirect),
34809+ "r" (__PCIBIOS_DS));
34810 break;
34811 case 4:
34812- __asm__("lcall *(%%esi); cld\n\t"
34813+ __asm__("movw %w6, %%ds\n\t"
34814+ "lcall *%%ss:(%%esi); cld\n\t"
34815+ "push %%ss\n\t"
34816+ "pop %%ds\n\t"
34817 "jc 1f\n\t"
34818 "xor %%ah, %%ah\n"
34819 "1:"
34820@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34821 "c" (value),
34822 "b" (bx),
34823 "D" ((long)reg),
34824- "S" (&pci_indirect));
34825+ "S" (&pci_indirect),
34826+ "r" (__PCIBIOS_DS));
34827 break;
34828 }
34829
34830@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34831
34832 DBG("PCI: Fetching IRQ routing table... ");
34833 __asm__("push %%es\n\t"
34834+ "movw %w8, %%ds\n\t"
34835 "push %%ds\n\t"
34836 "pop %%es\n\t"
34837- "lcall *(%%esi); cld\n\t"
34838+ "lcall *%%ss:(%%esi); cld\n\t"
34839 "pop %%es\n\t"
34840+ "push %%ss\n\t"
34841+ "pop %%ds\n"
34842 "jc 1f\n\t"
34843 "xor %%ah, %%ah\n"
34844 "1:"
34845@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34846 "1" (0),
34847 "D" ((long) &opt),
34848 "S" (&pci_indirect),
34849- "m" (opt)
34850+ "m" (opt),
34851+ "r" (__PCIBIOS_DS)
34852 : "memory");
34853 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
34854 if (ret & 0xff00)
34855@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34856 {
34857 int ret;
34858
34859- __asm__("lcall *(%%esi); cld\n\t"
34860+ __asm__("movw %w5, %%ds\n\t"
34861+ "lcall *%%ss:(%%esi); cld\n\t"
34862+ "push %%ss\n\t"
34863+ "pop %%ds\n"
34864 "jc 1f\n\t"
34865 "xor %%ah, %%ah\n"
34866 "1:"
34867@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34868 : "0" (PCIBIOS_SET_PCI_HW_INT),
34869 "b" ((dev->bus->number << 8) | dev->devfn),
34870 "c" ((irq << 8) | (pin + 10)),
34871- "S" (&pci_indirect));
34872+ "S" (&pci_indirect),
34873+ "r" (__PCIBIOS_DS));
34874 return !(ret & 0xff00);
34875 }
34876 EXPORT_SYMBOL(pcibios_set_irq_routing);
34877diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
34878index 9ee3491..872192f 100644
34879--- a/arch/x86/platform/efi/efi_32.c
34880+++ b/arch/x86/platform/efi/efi_32.c
34881@@ -59,11 +59,22 @@ void efi_call_phys_prelog(void)
34882 {
34883 struct desc_ptr gdt_descr;
34884
34885+#ifdef CONFIG_PAX_KERNEXEC
34886+ struct desc_struct d;
34887+#endif
34888+
34889 local_irq_save(efi_rt_eflags);
34890
34891 load_cr3(initial_page_table);
34892 __flush_tlb_all();
34893
34894+#ifdef CONFIG_PAX_KERNEXEC
34895+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
34896+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34897+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
34898+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34899+#endif
34900+
34901 gdt_descr.address = __pa(get_cpu_gdt_table(0));
34902 gdt_descr.size = GDT_SIZE - 1;
34903 load_gdt(&gdt_descr);
34904@@ -73,11 +84,24 @@ void efi_call_phys_epilog(void)
34905 {
34906 struct desc_ptr gdt_descr;
34907
34908+#ifdef CONFIG_PAX_KERNEXEC
34909+ struct desc_struct d;
34910+
34911+ memset(&d, 0, sizeof d);
34912+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34913+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34914+#endif
34915+
34916 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
34917 gdt_descr.size = GDT_SIZE - 1;
34918 load_gdt(&gdt_descr);
34919
34920+#ifdef CONFIG_PAX_PER_CPU_PGD
34921+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34922+#else
34923 load_cr3(swapper_pg_dir);
34924+#endif
34925+
34926 __flush_tlb_all();
34927
34928 local_irq_restore(efi_rt_eflags);
34929diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
34930index 666b74a..673d88f 100644
34931--- a/arch/x86/platform/efi/efi_64.c
34932+++ b/arch/x86/platform/efi/efi_64.c
34933@@ -97,6 +97,11 @@ void __init efi_call_phys_prelog(void)
34934 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
34935 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
34936 }
34937+
34938+#ifdef CONFIG_PAX_PER_CPU_PGD
34939+ load_cr3(swapper_pg_dir);
34940+#endif
34941+
34942 __flush_tlb_all();
34943 }
34944
34945@@ -114,6 +119,11 @@ void __init efi_call_phys_epilog(void)
34946 for (pgd = 0; pgd < n_pgds; pgd++)
34947 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
34948 kfree(save_pgd);
34949+
34950+#ifdef CONFIG_PAX_PER_CPU_PGD
34951+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34952+#endif
34953+
34954 __flush_tlb_all();
34955 local_irq_restore(efi_flags);
34956 early_code_mapping_set_exec(0);
34957diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
34958index fbe66e6..eae5e38 100644
34959--- a/arch/x86/platform/efi/efi_stub_32.S
34960+++ b/arch/x86/platform/efi/efi_stub_32.S
34961@@ -6,7 +6,9 @@
34962 */
34963
34964 #include <linux/linkage.h>
34965+#include <linux/init.h>
34966 #include <asm/page_types.h>
34967+#include <asm/segment.h>
34968
34969 /*
34970 * efi_call_phys(void *, ...) is a function with variable parameters.
34971@@ -20,7 +22,7 @@
34972 * service functions will comply with gcc calling convention, too.
34973 */
34974
34975-.text
34976+__INIT
34977 ENTRY(efi_call_phys)
34978 /*
34979 * 0. The function can only be called in Linux kernel. So CS has been
34980@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
34981 * The mapping of lower virtual memory has been created in prelog and
34982 * epilog.
34983 */
34984- movl $1f, %edx
34985- subl $__PAGE_OFFSET, %edx
34986- jmp *%edx
34987+#ifdef CONFIG_PAX_KERNEXEC
34988+ movl $(__KERNEXEC_EFI_DS), %edx
34989+ mov %edx, %ds
34990+ mov %edx, %es
34991+ mov %edx, %ss
34992+ addl $2f,(1f)
34993+ ljmp *(1f)
34994+
34995+__INITDATA
34996+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
34997+.previous
34998+
34999+2:
35000+ subl $2b,(1b)
35001+#else
35002+ jmp 1f-__PAGE_OFFSET
35003 1:
35004+#endif
35005
35006 /*
35007 * 2. Now on the top of stack is the return
35008@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
35009 * parameter 2, ..., param n. To make things easy, we save the return
35010 * address of efi_call_phys in a global variable.
35011 */
35012- popl %edx
35013- movl %edx, saved_return_addr
35014- /* get the function pointer into ECX*/
35015- popl %ecx
35016- movl %ecx, efi_rt_function_ptr
35017- movl $2f, %edx
35018- subl $__PAGE_OFFSET, %edx
35019- pushl %edx
35020+ popl (saved_return_addr)
35021+ popl (efi_rt_function_ptr)
35022
35023 /*
35024 * 3. Clear PG bit in %CR0.
35025@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
35026 /*
35027 * 5. Call the physical function.
35028 */
35029- jmp *%ecx
35030+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
35031
35032-2:
35033 /*
35034 * 6. After EFI runtime service returns, control will return to
35035 * following instruction. We'd better readjust stack pointer first.
35036@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
35037 movl %cr0, %edx
35038 orl $0x80000000, %edx
35039 movl %edx, %cr0
35040- jmp 1f
35041-1:
35042+
35043 /*
35044 * 8. Now restore the virtual mode from flat mode by
35045 * adding EIP with PAGE_OFFSET.
35046 */
35047- movl $1f, %edx
35048- jmp *%edx
35049+#ifdef CONFIG_PAX_KERNEXEC
35050+ movl $(__KERNEL_DS), %edx
35051+ mov %edx, %ds
35052+ mov %edx, %es
35053+ mov %edx, %ss
35054+ ljmp $(__KERNEL_CS),$1f
35055+#else
35056+ jmp 1f+__PAGE_OFFSET
35057+#endif
35058 1:
35059
35060 /*
35061 * 9. Balance the stack. And because EAX contain the return value,
35062 * we'd better not clobber it.
35063 */
35064- leal efi_rt_function_ptr, %edx
35065- movl (%edx), %ecx
35066- pushl %ecx
35067+ pushl (efi_rt_function_ptr)
35068
35069 /*
35070- * 10. Push the saved return address onto the stack and return.
35071+ * 10. Return to the saved return address.
35072 */
35073- leal saved_return_addr, %edx
35074- movl (%edx), %ecx
35075- pushl %ecx
35076- ret
35077+ jmpl *(saved_return_addr)
35078 ENDPROC(efi_call_phys)
35079 .previous
35080
35081-.data
35082+__INITDATA
35083 saved_return_addr:
35084 .long 0
35085 efi_rt_function_ptr:
35086diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
35087index 88073b1..1cc2f53 100644
35088--- a/arch/x86/platform/efi/efi_stub_64.S
35089+++ b/arch/x86/platform/efi/efi_stub_64.S
35090@@ -7,6 +7,7 @@
35091 */
35092
35093 #include <linux/linkage.h>
35094+#include <asm/alternative-asm.h>
35095
35096 #define SAVE_XMM \
35097 mov %rsp, %rax; \
35098@@ -77,6 +78,7 @@ ENTRY(efi_call0)
35099 RESTORE_PGT
35100 addq $32, %rsp
35101 RESTORE_XMM
35102+ pax_force_retaddr 0, 1
35103 ret
35104 ENDPROC(efi_call0)
35105
35106@@ -89,6 +91,7 @@ ENTRY(efi_call1)
35107 RESTORE_PGT
35108 addq $32, %rsp
35109 RESTORE_XMM
35110+ pax_force_retaddr 0, 1
35111 ret
35112 ENDPROC(efi_call1)
35113
35114@@ -101,6 +104,7 @@ ENTRY(efi_call2)
35115 RESTORE_PGT
35116 addq $32, %rsp
35117 RESTORE_XMM
35118+ pax_force_retaddr 0, 1
35119 ret
35120 ENDPROC(efi_call2)
35121
35122@@ -114,6 +118,7 @@ ENTRY(efi_call3)
35123 RESTORE_PGT
35124 addq $32, %rsp
35125 RESTORE_XMM
35126+ pax_force_retaddr 0, 1
35127 ret
35128 ENDPROC(efi_call3)
35129
35130@@ -128,6 +133,7 @@ ENTRY(efi_call4)
35131 RESTORE_PGT
35132 addq $32, %rsp
35133 RESTORE_XMM
35134+ pax_force_retaddr 0, 1
35135 ret
35136 ENDPROC(efi_call4)
35137
35138@@ -143,6 +149,7 @@ ENTRY(efi_call5)
35139 RESTORE_PGT
35140 addq $48, %rsp
35141 RESTORE_XMM
35142+ pax_force_retaddr 0, 1
35143 ret
35144 ENDPROC(efi_call5)
35145
35146@@ -161,6 +168,7 @@ ENTRY(efi_call6)
35147 RESTORE_PGT
35148 addq $48, %rsp
35149 RESTORE_XMM
35150+ pax_force_retaddr 0, 1
35151 ret
35152 ENDPROC(efi_call6)
35153
35154diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
35155index 1bbedc4..eb795b5 100644
35156--- a/arch/x86/platform/intel-mid/intel-mid.c
35157+++ b/arch/x86/platform/intel-mid/intel-mid.c
35158@@ -71,9 +71,10 @@ static void intel_mid_power_off(void)
35159 {
35160 };
35161
35162-static void intel_mid_reboot(void)
35163+static void __noreturn intel_mid_reboot(void)
35164 {
35165 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
35166+ BUG();
35167 }
35168
35169 static unsigned long __init intel_mid_calibrate_tsc(void)
35170diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
35171index d6ee929..3637cb5 100644
35172--- a/arch/x86/platform/olpc/olpc_dt.c
35173+++ b/arch/x86/platform/olpc/olpc_dt.c
35174@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
35175 return res;
35176 }
35177
35178-static struct of_pdt_ops prom_olpc_ops __initdata = {
35179+static struct of_pdt_ops prom_olpc_ops __initconst = {
35180 .nextprop = olpc_dt_nextprop,
35181 .getproplen = olpc_dt_getproplen,
35182 .getproperty = olpc_dt_getproperty,
35183diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
35184index 424f4c9..f2a2988 100644
35185--- a/arch/x86/power/cpu.c
35186+++ b/arch/x86/power/cpu.c
35187@@ -137,11 +137,8 @@ static void do_fpu_end(void)
35188 static void fix_processor_context(void)
35189 {
35190 int cpu = smp_processor_id();
35191- struct tss_struct *t = &per_cpu(init_tss, cpu);
35192-#ifdef CONFIG_X86_64
35193- struct desc_struct *desc = get_cpu_gdt_table(cpu);
35194- tss_desc tss;
35195-#endif
35196+ struct tss_struct *t = init_tss + cpu;
35197+
35198 set_tss_desc(cpu, t); /*
35199 * This just modifies memory; should not be
35200 * necessary. But... This is necessary, because
35201@@ -150,10 +147,6 @@ static void fix_processor_context(void)
35202 */
35203
35204 #ifdef CONFIG_X86_64
35205- memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
35206- tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
35207- write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
35208-
35209 syscall_init(); /* This sets MSR_*STAR and related */
35210 #endif
35211 load_TR_desc(); /* This does ltr */
35212diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
35213index bad628a..a102610 100644
35214--- a/arch/x86/realmode/init.c
35215+++ b/arch/x86/realmode/init.c
35216@@ -68,7 +68,13 @@ void __init setup_real_mode(void)
35217 __va(real_mode_header->trampoline_header);
35218
35219 #ifdef CONFIG_X86_32
35220- trampoline_header->start = __pa_symbol(startup_32_smp);
35221+ trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
35222+
35223+#ifdef CONFIG_PAX_KERNEXEC
35224+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
35225+#endif
35226+
35227+ trampoline_header->boot_cs = __BOOT_CS;
35228 trampoline_header->gdt_limit = __BOOT_DS + 7;
35229 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
35230 #else
35231@@ -84,7 +90,7 @@ void __init setup_real_mode(void)
35232 *trampoline_cr4_features = read_cr4();
35233
35234 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
35235- trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
35236+ trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
35237 trampoline_pgd[511] = init_level4_pgt[511].pgd;
35238 #endif
35239 }
35240diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
35241index 3497f14..cc73b92 100644
35242--- a/arch/x86/realmode/rm/Makefile
35243+++ b/arch/x86/realmode/rm/Makefile
35244@@ -66,5 +66,8 @@ $(obj)/realmode.relocs: $(obj)/realmode.elf FORCE
35245
35246 KBUILD_CFLAGS := $(LINUXINCLUDE) $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \
35247 -I$(srctree)/arch/x86/boot
35248+ifdef CONSTIFY_PLUGIN
35249+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
35250+endif
35251 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
35252 GCOV_PROFILE := n
35253diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
35254index a28221d..93c40f1 100644
35255--- a/arch/x86/realmode/rm/header.S
35256+++ b/arch/x86/realmode/rm/header.S
35257@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
35258 #endif
35259 /* APM/BIOS reboot */
35260 .long pa_machine_real_restart_asm
35261-#ifdef CONFIG_X86_64
35262+#ifdef CONFIG_X86_32
35263+ .long __KERNEL_CS
35264+#else
35265 .long __KERNEL32_CS
35266 #endif
35267 END(real_mode_header)
35268diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
35269index 48ddd76..c26749f 100644
35270--- a/arch/x86/realmode/rm/trampoline_32.S
35271+++ b/arch/x86/realmode/rm/trampoline_32.S
35272@@ -24,6 +24,12 @@
35273 #include <asm/page_types.h>
35274 #include "realmode.h"
35275
35276+#ifdef CONFIG_PAX_KERNEXEC
35277+#define ta(X) (X)
35278+#else
35279+#define ta(X) (pa_ ## X)
35280+#endif
35281+
35282 .text
35283 .code16
35284
35285@@ -38,8 +44,6 @@ ENTRY(trampoline_start)
35286
35287 cli # We should be safe anyway
35288
35289- movl tr_start, %eax # where we need to go
35290-
35291 movl $0xA5A5A5A5, trampoline_status
35292 # write marker for master knows we're running
35293
35294@@ -55,7 +59,7 @@ ENTRY(trampoline_start)
35295 movw $1, %dx # protected mode (PE) bit
35296 lmsw %dx # into protected mode
35297
35298- ljmpl $__BOOT_CS, $pa_startup_32
35299+ ljmpl *(trampoline_header)
35300
35301 .section ".text32","ax"
35302 .code32
35303@@ -66,7 +70,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
35304 .balign 8
35305 GLOBAL(trampoline_header)
35306 tr_start: .space 4
35307- tr_gdt_pad: .space 2
35308+ tr_boot_cs: .space 2
35309 tr_gdt: .space 6
35310 END(trampoline_header)
35311
35312diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
35313index dac7b20..72dbaca 100644
35314--- a/arch/x86/realmode/rm/trampoline_64.S
35315+++ b/arch/x86/realmode/rm/trampoline_64.S
35316@@ -93,6 +93,7 @@ ENTRY(startup_32)
35317 movl %edx, %gs
35318
35319 movl pa_tr_cr4, %eax
35320+ andl $~X86_CR4_PCIDE, %eax
35321 movl %eax, %cr4 # Enable PAE mode
35322
35323 # Setup trampoline 4 level pagetables
35324@@ -106,7 +107,7 @@ ENTRY(startup_32)
35325 wrmsr
35326
35327 # Enable paging and in turn activate Long Mode
35328- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
35329+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
35330 movl %eax, %cr0
35331
35332 /*
35333diff --git a/arch/x86/realmode/rm/wakeup_asm.S b/arch/x86/realmode/rm/wakeup_asm.S
35334index 9e7e147..25a4158 100644
35335--- a/arch/x86/realmode/rm/wakeup_asm.S
35336+++ b/arch/x86/realmode/rm/wakeup_asm.S
35337@@ -126,11 +126,10 @@ ENTRY(wakeup_start)
35338 lgdtl pmode_gdt
35339
35340 /* This really couldn't... */
35341- movl pmode_entry, %eax
35342 movl pmode_cr0, %ecx
35343 movl %ecx, %cr0
35344- ljmpl $__KERNEL_CS, $pa_startup_32
35345- /* -> jmp *%eax in trampoline_32.S */
35346+
35347+ ljmpl *pmode_entry
35348 #else
35349 jmp trampoline_start
35350 #endif
35351diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
35352index e812034..c747134 100644
35353--- a/arch/x86/tools/Makefile
35354+++ b/arch/x86/tools/Makefile
35355@@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
35356
35357 $(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
35358
35359-HOST_EXTRACFLAGS += -I$(srctree)/tools/include
35360+HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
35361 hostprogs-y += relocs
35362 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
35363 relocs: $(obj)/relocs
35364diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
35365index cfbdbdb..1aa763c 100644
35366--- a/arch/x86/tools/relocs.c
35367+++ b/arch/x86/tools/relocs.c
35368@@ -1,5 +1,7 @@
35369 /* This is included from relocs_32/64.c */
35370
35371+#include "../../../include/generated/autoconf.h"
35372+
35373 #define ElfW(type) _ElfW(ELF_BITS, type)
35374 #define _ElfW(bits, type) __ElfW(bits, type)
35375 #define __ElfW(bits, type) Elf##bits##_##type
35376@@ -11,6 +13,7 @@
35377 #define Elf_Sym ElfW(Sym)
35378
35379 static Elf_Ehdr ehdr;
35380+static Elf_Phdr *phdr;
35381
35382 struct relocs {
35383 uint32_t *offset;
35384@@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
35385 }
35386 }
35387
35388+static void read_phdrs(FILE *fp)
35389+{
35390+ unsigned int i;
35391+
35392+ phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
35393+ if (!phdr) {
35394+ die("Unable to allocate %d program headers\n",
35395+ ehdr.e_phnum);
35396+ }
35397+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
35398+ die("Seek to %d failed: %s\n",
35399+ ehdr.e_phoff, strerror(errno));
35400+ }
35401+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
35402+ die("Cannot read ELF program headers: %s\n",
35403+ strerror(errno));
35404+ }
35405+ for(i = 0; i < ehdr.e_phnum; i++) {
35406+ phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
35407+ phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
35408+ phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
35409+ phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
35410+ phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
35411+ phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
35412+ phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
35413+ phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
35414+ }
35415+
35416+}
35417+
35418 static void read_shdrs(FILE *fp)
35419 {
35420- int i;
35421+ unsigned int i;
35422 Elf_Shdr shdr;
35423
35424 secs = calloc(ehdr.e_shnum, sizeof(struct section));
35425@@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
35426
35427 static void read_strtabs(FILE *fp)
35428 {
35429- int i;
35430+ unsigned int i;
35431 for (i = 0; i < ehdr.e_shnum; i++) {
35432 struct section *sec = &secs[i];
35433 if (sec->shdr.sh_type != SHT_STRTAB) {
35434@@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
35435
35436 static void read_symtabs(FILE *fp)
35437 {
35438- int i,j;
35439+ unsigned int i,j;
35440 for (i = 0; i < ehdr.e_shnum; i++) {
35441 struct section *sec = &secs[i];
35442 if (sec->shdr.sh_type != SHT_SYMTAB) {
35443@@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
35444 }
35445
35446
35447-static void read_relocs(FILE *fp)
35448+static void read_relocs(FILE *fp, int use_real_mode)
35449 {
35450- int i,j;
35451+ unsigned int i,j;
35452+ uint32_t base;
35453+
35454 for (i = 0; i < ehdr.e_shnum; i++) {
35455 struct section *sec = &secs[i];
35456 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35457@@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
35458 die("Cannot read symbol table: %s\n",
35459 strerror(errno));
35460 }
35461+ base = 0;
35462+
35463+#ifdef CONFIG_X86_32
35464+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
35465+ if (phdr[j].p_type != PT_LOAD )
35466+ continue;
35467+ 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)
35468+ continue;
35469+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
35470+ break;
35471+ }
35472+#endif
35473+
35474 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
35475 Elf_Rel *rel = &sec->reltab[j];
35476- rel->r_offset = elf_addr_to_cpu(rel->r_offset);
35477+ rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
35478 rel->r_info = elf_xword_to_cpu(rel->r_info);
35479 #if (SHT_REL_TYPE == SHT_RELA)
35480 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
35481@@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
35482
35483 static void print_absolute_symbols(void)
35484 {
35485- int i;
35486+ unsigned int i;
35487 const char *format;
35488
35489 if (ELF_BITS == 64)
35490@@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
35491 for (i = 0; i < ehdr.e_shnum; i++) {
35492 struct section *sec = &secs[i];
35493 char *sym_strtab;
35494- int j;
35495+ unsigned int j;
35496
35497 if (sec->shdr.sh_type != SHT_SYMTAB) {
35498 continue;
35499@@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
35500
35501 static void print_absolute_relocs(void)
35502 {
35503- int i, printed = 0;
35504+ unsigned int i, printed = 0;
35505 const char *format;
35506
35507 if (ELF_BITS == 64)
35508@@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
35509 struct section *sec_applies, *sec_symtab;
35510 char *sym_strtab;
35511 Elf_Sym *sh_symtab;
35512- int j;
35513+ unsigned int j;
35514 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35515 continue;
35516 }
35517@@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
35518 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
35519 Elf_Sym *sym, const char *symname))
35520 {
35521- int i;
35522+ unsigned int i;
35523 /* Walk through the relocations */
35524 for (i = 0; i < ehdr.e_shnum; i++) {
35525 char *sym_strtab;
35526 Elf_Sym *sh_symtab;
35527 struct section *sec_applies, *sec_symtab;
35528- int j;
35529+ unsigned int j;
35530 struct section *sec = &secs[i];
35531
35532 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35533@@ -822,6 +870,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35534 {
35535 unsigned r_type = ELF32_R_TYPE(rel->r_info);
35536 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
35537+ char *sym_strtab = sec->link->link->strtab;
35538+
35539+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
35540+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
35541+ return 0;
35542+
35543+#ifdef CONFIG_PAX_KERNEXEC
35544+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
35545+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
35546+ return 0;
35547+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
35548+ return 0;
35549+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
35550+ return 0;
35551+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
35552+ return 0;
35553+#endif
35554
35555 switch (r_type) {
35556 case R_386_NONE:
35557@@ -960,7 +1025,7 @@ static int write32_as_text(uint32_t v, FILE *f)
35558
35559 static void emit_relocs(int as_text, int use_real_mode)
35560 {
35561- int i;
35562+ unsigned int i;
35563 int (*write_reloc)(uint32_t, FILE *) = write32;
35564 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35565 const char *symname);
35566@@ -1060,10 +1125,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
35567 {
35568 regex_init(use_real_mode);
35569 read_ehdr(fp);
35570+ read_phdrs(fp);
35571 read_shdrs(fp);
35572 read_strtabs(fp);
35573 read_symtabs(fp);
35574- read_relocs(fp);
35575+ read_relocs(fp, use_real_mode);
35576 if (ELF_BITS == 64)
35577 percpu_init();
35578 if (show_absolute_syms) {
35579diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
35580index 80ffa5b..a33bd15 100644
35581--- a/arch/x86/um/tls_32.c
35582+++ b/arch/x86/um/tls_32.c
35583@@ -260,7 +260,7 @@ out:
35584 if (unlikely(task == current &&
35585 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
35586 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
35587- "without flushed TLS.", current->pid);
35588+ "without flushed TLS.", task_pid_nr(current));
35589 }
35590
35591 return 0;
35592diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
35593index fd14be1..e3c79c0 100644
35594--- a/arch/x86/vdso/Makefile
35595+++ b/arch/x86/vdso/Makefile
35596@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
35597 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
35598 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
35599
35600-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
35601+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
35602 GCOV_PROFILE := n
35603
35604 #
35605diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
35606index d6bfb87..876ee18 100644
35607--- a/arch/x86/vdso/vdso32-setup.c
35608+++ b/arch/x86/vdso/vdso32-setup.c
35609@@ -25,6 +25,7 @@
35610 #include <asm/tlbflush.h>
35611 #include <asm/vdso.h>
35612 #include <asm/proto.h>
35613+#include <asm/mman.h>
35614
35615 enum {
35616 VDSO_DISABLED = 0,
35617@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
35618 void enable_sep_cpu(void)
35619 {
35620 int cpu = get_cpu();
35621- struct tss_struct *tss = &per_cpu(init_tss, cpu);
35622+ struct tss_struct *tss = init_tss + cpu;
35623
35624 if (!boot_cpu_has(X86_FEATURE_SEP)) {
35625 put_cpu();
35626@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
35627 gate_vma.vm_start = FIXADDR_USER_START;
35628 gate_vma.vm_end = FIXADDR_USER_END;
35629 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
35630- gate_vma.vm_page_prot = __P101;
35631+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
35632
35633 return 0;
35634 }
35635@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35636 if (compat)
35637 addr = VDSO_HIGH_BASE;
35638 else {
35639- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
35640+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
35641 if (IS_ERR_VALUE(addr)) {
35642 ret = addr;
35643 goto up_fail;
35644 }
35645 }
35646
35647- current->mm->context.vdso = (void *)addr;
35648+ current->mm->context.vdso = addr;
35649
35650 if (compat_uses_vma || !compat) {
35651 /*
35652@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35653 }
35654
35655 current_thread_info()->sysenter_return =
35656- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35657+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35658
35659 up_fail:
35660 if (ret)
35661- current->mm->context.vdso = NULL;
35662+ current->mm->context.vdso = 0;
35663
35664 up_write(&mm->mmap_sem);
35665
35666@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
35667
35668 const char *arch_vma_name(struct vm_area_struct *vma)
35669 {
35670- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
35671+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
35672 return "[vdso]";
35673+
35674+#ifdef CONFIG_PAX_SEGMEXEC
35675+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
35676+ return "[vdso]";
35677+#endif
35678+
35679 return NULL;
35680 }
35681
35682@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
35683 * Check to see if the corresponding task was created in compat vdso
35684 * mode.
35685 */
35686- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
35687+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
35688 return &gate_vma;
35689 return NULL;
35690 }
35691diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
35692index 431e875..cbb23f3 100644
35693--- a/arch/x86/vdso/vma.c
35694+++ b/arch/x86/vdso/vma.c
35695@@ -16,8 +16,6 @@
35696 #include <asm/vdso.h>
35697 #include <asm/page.h>
35698
35699-unsigned int __read_mostly vdso_enabled = 1;
35700-
35701 extern char vdso_start[], vdso_end[];
35702 extern unsigned short vdso_sync_cpuid;
35703
35704@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
35705 * unaligned here as a result of stack start randomization.
35706 */
35707 addr = PAGE_ALIGN(addr);
35708- addr = align_vdso_addr(addr);
35709
35710 return addr;
35711 }
35712@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
35713 unsigned size)
35714 {
35715 struct mm_struct *mm = current->mm;
35716- unsigned long addr;
35717+ unsigned long addr = 0;
35718 int ret;
35719
35720- if (!vdso_enabled)
35721- return 0;
35722-
35723 down_write(&mm->mmap_sem);
35724+
35725+#ifdef CONFIG_PAX_RANDMMAP
35726+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
35727+#endif
35728+
35729 addr = vdso_addr(mm->start_stack, size);
35730+ addr = align_vdso_addr(addr);
35731 addr = get_unmapped_area(NULL, addr, size, 0, 0);
35732 if (IS_ERR_VALUE(addr)) {
35733 ret = addr;
35734 goto up_fail;
35735 }
35736
35737- current->mm->context.vdso = (void *)addr;
35738+ mm->context.vdso = addr;
35739
35740 ret = install_special_mapping(mm, addr, size,
35741 VM_READ|VM_EXEC|
35742 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
35743 pages);
35744- if (ret) {
35745- current->mm->context.vdso = NULL;
35746- goto up_fail;
35747- }
35748+ if (ret)
35749+ mm->context.vdso = 0;
35750
35751 up_fail:
35752 up_write(&mm->mmap_sem);
35753@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35754 vdsox32_size);
35755 }
35756 #endif
35757-
35758-static __init int vdso_setup(char *s)
35759-{
35760- vdso_enabled = simple_strtoul(s, NULL, 0);
35761- return 0;
35762-}
35763-__setup("vdso=", vdso_setup);
35764diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
35765index 01b9026..1e476df 100644
35766--- a/arch/x86/xen/Kconfig
35767+++ b/arch/x86/xen/Kconfig
35768@@ -9,6 +9,7 @@ config XEN
35769 select XEN_HAVE_PVMMU
35770 depends on X86_64 || (X86_32 && X86_PAE && !X86_VISWS)
35771 depends on X86_TSC
35772+ depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
35773 help
35774 This is the Linux Xen port. Enabling this will allow the
35775 kernel to boot in a paravirtualized environment under the
35776diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
35777index 201d09a..e4723e5 100644
35778--- a/arch/x86/xen/enlighten.c
35779+++ b/arch/x86/xen/enlighten.c
35780@@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
35781
35782 struct shared_info xen_dummy_shared_info;
35783
35784-void *xen_initial_gdt;
35785-
35786 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
35787 __read_mostly int xen_have_vector_callback;
35788 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
35789@@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
35790 {
35791 unsigned long va = dtr->address;
35792 unsigned int size = dtr->size + 1;
35793- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35794- unsigned long frames[pages];
35795+ unsigned long frames[65536 / PAGE_SIZE];
35796 int f;
35797
35798 /*
35799@@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35800 {
35801 unsigned long va = dtr->address;
35802 unsigned int size = dtr->size + 1;
35803- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35804- unsigned long frames[pages];
35805+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
35806 int f;
35807
35808 /*
35809@@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35810 * 8-byte entries, or 16 4k pages..
35811 */
35812
35813- BUG_ON(size > 65536);
35814+ BUG_ON(size > GDT_SIZE);
35815 BUG_ON(va & ~PAGE_MASK);
35816
35817 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
35818@@ -989,7 +985,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
35819 return 0;
35820 }
35821
35822-static void set_xen_basic_apic_ops(void)
35823+static void __init set_xen_basic_apic_ops(void)
35824 {
35825 apic->read = xen_apic_read;
35826 apic->write = xen_apic_write;
35827@@ -1295,30 +1291,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
35828 #endif
35829 };
35830
35831-static void xen_reboot(int reason)
35832+static __noreturn void xen_reboot(int reason)
35833 {
35834 struct sched_shutdown r = { .reason = reason };
35835
35836- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
35837- BUG();
35838+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
35839+ BUG();
35840 }
35841
35842-static void xen_restart(char *msg)
35843+static __noreturn void xen_restart(char *msg)
35844 {
35845 xen_reboot(SHUTDOWN_reboot);
35846 }
35847
35848-static void xen_emergency_restart(void)
35849+static __noreturn void xen_emergency_restart(void)
35850 {
35851 xen_reboot(SHUTDOWN_reboot);
35852 }
35853
35854-static void xen_machine_halt(void)
35855+static __noreturn void xen_machine_halt(void)
35856 {
35857 xen_reboot(SHUTDOWN_poweroff);
35858 }
35859
35860-static void xen_machine_power_off(void)
35861+static __noreturn void xen_machine_power_off(void)
35862 {
35863 if (pm_power_off)
35864 pm_power_off();
35865@@ -1564,7 +1560,17 @@ asmlinkage void __init xen_start_kernel(void)
35866 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
35867
35868 /* Work out if we support NX */
35869- x86_configure_nx();
35870+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
35871+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
35872+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
35873+ unsigned l, h;
35874+
35875+ __supported_pte_mask |= _PAGE_NX;
35876+ rdmsr(MSR_EFER, l, h);
35877+ l |= EFER_NX;
35878+ wrmsr(MSR_EFER, l, h);
35879+ }
35880+#endif
35881
35882 /* Get mfn list */
35883 xen_build_dynamic_phys_to_machine();
35884@@ -1592,13 +1598,6 @@ asmlinkage void __init xen_start_kernel(void)
35885
35886 machine_ops = xen_machine_ops;
35887
35888- /*
35889- * The only reliable way to retain the initial address of the
35890- * percpu gdt_page is to remember it here, so we can go and
35891- * mark it RW later, when the initial percpu area is freed.
35892- */
35893- xen_initial_gdt = &per_cpu(gdt_page, 0);
35894-
35895 xen_smp_init();
35896
35897 #ifdef CONFIG_ACPI_NUMA
35898diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
35899index 2423ef0..4f6fb5b 100644
35900--- a/arch/x86/xen/mmu.c
35901+++ b/arch/x86/xen/mmu.c
35902@@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
35903 return val;
35904 }
35905
35906-static pteval_t pte_pfn_to_mfn(pteval_t val)
35907+static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
35908 {
35909 if (val & _PAGE_PRESENT) {
35910 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
35911@@ -1904,6 +1904,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35912 /* L3_k[510] -> level2_kernel_pgt
35913 * L3_i[511] -> level2_fixmap_pgt */
35914 convert_pfn_mfn(level3_kernel_pgt);
35915+ convert_pfn_mfn(level3_vmalloc_start_pgt);
35916+ convert_pfn_mfn(level3_vmalloc_end_pgt);
35917+ convert_pfn_mfn(level3_vmemmap_pgt);
35918 }
35919 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
35920 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
35921@@ -1933,8 +1936,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35922 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
35923 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
35924 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
35925+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
35926+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
35927+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
35928 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
35929 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
35930+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
35931 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
35932 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
35933
35934@@ -2123,6 +2130,7 @@ static void __init xen_post_allocator_init(void)
35935 pv_mmu_ops.set_pud = xen_set_pud;
35936 #if PAGETABLE_LEVELS == 4
35937 pv_mmu_ops.set_pgd = xen_set_pgd;
35938+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
35939 #endif
35940
35941 /* This will work as long as patching hasn't happened yet
35942@@ -2201,6 +2209,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
35943 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
35944 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
35945 .set_pgd = xen_set_pgd_hyper,
35946+ .set_pgd_batched = xen_set_pgd_hyper,
35947
35948 .alloc_pud = xen_alloc_pmd_init,
35949 .release_pud = xen_release_pmd_init,
35950diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
35951index a18eadd..2e2f10e 100644
35952--- a/arch/x86/xen/smp.c
35953+++ b/arch/x86/xen/smp.c
35954@@ -283,17 +283,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
35955
35956 if (xen_pv_domain()) {
35957 if (!xen_feature(XENFEAT_writable_page_tables))
35958- /* We've switched to the "real" per-cpu gdt, so make
35959- * sure the old memory can be recycled. */
35960- make_lowmem_page_readwrite(xen_initial_gdt);
35961-
35962 #ifdef CONFIG_X86_32
35963 /*
35964 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
35965 * expects __USER_DS
35966 */
35967- loadsegment(ds, __USER_DS);
35968- loadsegment(es, __USER_DS);
35969+ loadsegment(ds, __KERNEL_DS);
35970+ loadsegment(es, __KERNEL_DS);
35971 #endif
35972
35973 xen_filter_cpu_maps();
35974@@ -372,7 +368,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35975 #ifdef CONFIG_X86_32
35976 /* Note: PVH is not yet supported on x86_32. */
35977 ctxt->user_regs.fs = __KERNEL_PERCPU;
35978- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
35979+ savesegment(gs, ctxt->user_regs.gs);
35980 #endif
35981 ctxt->user_regs.eip = (unsigned long)cpu_bringup_and_idle;
35982
35983@@ -381,8 +377,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35984 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
35985 ctxt->flags = VGCF_IN_KERNEL;
35986 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
35987- ctxt->user_regs.ds = __USER_DS;
35988- ctxt->user_regs.es = __USER_DS;
35989+ ctxt->user_regs.ds = __KERNEL_DS;
35990+ ctxt->user_regs.es = __KERNEL_DS;
35991 ctxt->user_regs.ss = __KERNEL_DS;
35992
35993 xen_copy_trap_info(ctxt->trap_ctxt);
35994@@ -437,13 +433,12 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
35995 int rc;
35996
35997 per_cpu(current_task, cpu) = idle;
35998+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
35999 #ifdef CONFIG_X86_32
36000 irq_ctx_init(cpu);
36001 #else
36002 clear_tsk_thread_flag(idle, TIF_FORK);
36003- per_cpu(kernel_stack, cpu) =
36004- (unsigned long)task_stack_page(idle) -
36005- KERNEL_STACK_OFFSET + THREAD_SIZE;
36006+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
36007 #endif
36008 xen_setup_runstate_info(cpu);
36009 xen_setup_timer(cpu);
36010@@ -719,7 +714,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
36011
36012 void __init xen_smp_init(void)
36013 {
36014- smp_ops = xen_smp_ops;
36015+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
36016 xen_fill_possible_map();
36017 }
36018
36019diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
36020index 33ca6e4..0ded929 100644
36021--- a/arch/x86/xen/xen-asm_32.S
36022+++ b/arch/x86/xen/xen-asm_32.S
36023@@ -84,14 +84,14 @@ ENTRY(xen_iret)
36024 ESP_OFFSET=4 # bytes pushed onto stack
36025
36026 /*
36027- * Store vcpu_info pointer for easy access. Do it this way to
36028- * avoid having to reload %fs
36029+ * Store vcpu_info pointer for easy access.
36030 */
36031 #ifdef CONFIG_SMP
36032- GET_THREAD_INFO(%eax)
36033- movl %ss:TI_cpu(%eax), %eax
36034- movl %ss:__per_cpu_offset(,%eax,4), %eax
36035- mov %ss:xen_vcpu(%eax), %eax
36036+ push %fs
36037+ mov $(__KERNEL_PERCPU), %eax
36038+ mov %eax, %fs
36039+ mov PER_CPU_VAR(xen_vcpu), %eax
36040+ pop %fs
36041 #else
36042 movl %ss:xen_vcpu, %eax
36043 #endif
36044diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
36045index 485b695..fda3e7c 100644
36046--- a/arch/x86/xen/xen-head.S
36047+++ b/arch/x86/xen/xen-head.S
36048@@ -39,6 +39,17 @@ ENTRY(startup_xen)
36049 #ifdef CONFIG_X86_32
36050 mov %esi,xen_start_info
36051 mov $init_thread_union+THREAD_SIZE,%esp
36052+#ifdef CONFIG_SMP
36053+ movl $cpu_gdt_table,%edi
36054+ movl $__per_cpu_load,%eax
36055+ movw %ax,__KERNEL_PERCPU + 2(%edi)
36056+ rorl $16,%eax
36057+ movb %al,__KERNEL_PERCPU + 4(%edi)
36058+ movb %ah,__KERNEL_PERCPU + 7(%edi)
36059+ movl $__per_cpu_end - 1,%eax
36060+ subl $__per_cpu_start,%eax
36061+ movw %ax,__KERNEL_PERCPU + 0(%edi)
36062+#endif
36063 #else
36064 mov %rsi,xen_start_info
36065 mov $init_thread_union+THREAD_SIZE,%rsp
36066diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
36067index 1cb6f4c..9981524 100644
36068--- a/arch/x86/xen/xen-ops.h
36069+++ b/arch/x86/xen/xen-ops.h
36070@@ -10,8 +10,6 @@
36071 extern const char xen_hypervisor_callback[];
36072 extern const char xen_failsafe_callback[];
36073
36074-extern void *xen_initial_gdt;
36075-
36076 struct trap_info;
36077 void xen_copy_trap_info(struct trap_info *traps);
36078
36079diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
36080index 525bd3d..ef888b1 100644
36081--- a/arch/xtensa/variants/dc232b/include/variant/core.h
36082+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
36083@@ -119,9 +119,9 @@
36084 ----------------------------------------------------------------------*/
36085
36086 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
36087-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
36088 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
36089 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
36090+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36091
36092 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
36093 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
36094diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
36095index 2f33760..835e50a 100644
36096--- a/arch/xtensa/variants/fsf/include/variant/core.h
36097+++ b/arch/xtensa/variants/fsf/include/variant/core.h
36098@@ -11,6 +11,7 @@
36099 #ifndef _XTENSA_CORE_H
36100 #define _XTENSA_CORE_H
36101
36102+#include <linux/const.h>
36103
36104 /****************************************************************************
36105 Parameters Useful for Any Code, USER or PRIVILEGED
36106@@ -112,9 +113,9 @@
36107 ----------------------------------------------------------------------*/
36108
36109 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
36110-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
36111 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
36112 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
36113+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36114
36115 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
36116 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
36117diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
36118index af00795..2bb8105 100644
36119--- a/arch/xtensa/variants/s6000/include/variant/core.h
36120+++ b/arch/xtensa/variants/s6000/include/variant/core.h
36121@@ -11,6 +11,7 @@
36122 #ifndef _XTENSA_CORE_CONFIGURATION_H
36123 #define _XTENSA_CORE_CONFIGURATION_H
36124
36125+#include <linux/const.h>
36126
36127 /****************************************************************************
36128 Parameters Useful for Any Code, USER or PRIVILEGED
36129@@ -118,9 +119,9 @@
36130 ----------------------------------------------------------------------*/
36131
36132 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
36133-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
36134 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
36135 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
36136+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36137
36138 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
36139 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
36140diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
36141index 4e491d9..c8e18e4 100644
36142--- a/block/blk-cgroup.c
36143+++ b/block/blk-cgroup.c
36144@@ -812,7 +812,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
36145 static struct cgroup_subsys_state *
36146 blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
36147 {
36148- static atomic64_t id_seq = ATOMIC64_INIT(0);
36149+ static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
36150 struct blkcg *blkcg;
36151
36152 if (!parent_css) {
36153@@ -826,7 +826,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
36154
36155 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
36156 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
36157- blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
36158+ blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
36159 done:
36160 spin_lock_init(&blkcg->lock);
36161 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
36162diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
36163index 1855bf5..af12b06 100644
36164--- a/block/blk-iopoll.c
36165+++ b/block/blk-iopoll.c
36166@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
36167 }
36168 EXPORT_SYMBOL(blk_iopoll_complete);
36169
36170-static void blk_iopoll_softirq(struct softirq_action *h)
36171+static __latent_entropy void blk_iopoll_softirq(void)
36172 {
36173 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
36174 int rearm = 0, budget = blk_iopoll_budget;
36175diff --git a/block/blk-map.c b/block/blk-map.c
36176index ae4ae10..c470b8d 100644
36177--- a/block/blk-map.c
36178+++ b/block/blk-map.c
36179@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
36180 if (!len || !kbuf)
36181 return -EINVAL;
36182
36183- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
36184+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
36185 if (do_copy)
36186 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
36187 else
36188diff --git a/block/blk-softirq.c b/block/blk-softirq.c
36189index 57790c1..5e988dd 100644
36190--- a/block/blk-softirq.c
36191+++ b/block/blk-softirq.c
36192@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
36193 * Softirq action handler - move entries to local list and loop over them
36194 * while passing them to the queue registered handler.
36195 */
36196-static void blk_done_softirq(struct softirq_action *h)
36197+static __latent_entropy void blk_done_softirq(void)
36198 {
36199 struct list_head *cpu_list, local_list;
36200
36201diff --git a/block/bsg.c b/block/bsg.c
36202index 420a5a9..23834aa 100644
36203--- a/block/bsg.c
36204+++ b/block/bsg.c
36205@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
36206 struct sg_io_v4 *hdr, struct bsg_device *bd,
36207 fmode_t has_write_perm)
36208 {
36209+ unsigned char tmpcmd[sizeof(rq->__cmd)];
36210+ unsigned char *cmdptr;
36211+
36212 if (hdr->request_len > BLK_MAX_CDB) {
36213 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
36214 if (!rq->cmd)
36215 return -ENOMEM;
36216- }
36217+ cmdptr = rq->cmd;
36218+ } else
36219+ cmdptr = tmpcmd;
36220
36221- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
36222+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
36223 hdr->request_len))
36224 return -EFAULT;
36225
36226+ if (cmdptr != rq->cmd)
36227+ memcpy(rq->cmd, cmdptr, hdr->request_len);
36228+
36229 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
36230 if (blk_verify_command(rq->cmd, has_write_perm))
36231 return -EPERM;
36232diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
36233index fbd5a67..f24fd95 100644
36234--- a/block/compat_ioctl.c
36235+++ b/block/compat_ioctl.c
36236@@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
36237 cgc = compat_alloc_user_space(sizeof(*cgc));
36238 cgc32 = compat_ptr(arg);
36239
36240- if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
36241+ if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
36242 get_user(data, &cgc32->buffer) ||
36243 put_user(compat_ptr(data), &cgc->buffer) ||
36244 copy_in_user(&cgc->buflen, &cgc32->buflen,
36245@@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
36246 err |= __get_user(f->spec1, &uf->spec1);
36247 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
36248 err |= __get_user(name, &uf->name);
36249- f->name = compat_ptr(name);
36250+ f->name = (void __force_kernel *)compat_ptr(name);
36251 if (err) {
36252 err = -EFAULT;
36253 goto out;
36254diff --git a/block/genhd.c b/block/genhd.c
36255index 791f419..89f21c4 100644
36256--- a/block/genhd.c
36257+++ b/block/genhd.c
36258@@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
36259
36260 /*
36261 * Register device numbers dev..(dev+range-1)
36262- * range must be nonzero
36263+ * Noop if @range is zero.
36264 * The hash chain is sorted on range, so that subranges can override.
36265 */
36266 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
36267 struct kobject *(*probe)(dev_t, int *, void *),
36268 int (*lock)(dev_t, void *), void *data)
36269 {
36270- kobj_map(bdev_map, devt, range, module, probe, lock, data);
36271+ if (range)
36272+ kobj_map(bdev_map, devt, range, module, probe, lock, data);
36273 }
36274
36275 EXPORT_SYMBOL(blk_register_region);
36276
36277+/* undo blk_register_region(), noop if @range is zero */
36278 void blk_unregister_region(dev_t devt, unsigned long range)
36279 {
36280- kobj_unmap(bdev_map, devt, range);
36281+ if (range)
36282+ kobj_unmap(bdev_map, devt, range);
36283 }
36284
36285 EXPORT_SYMBOL(blk_unregister_region);
36286diff --git a/block/partitions/efi.c b/block/partitions/efi.c
36287index dc51f46..d5446a8 100644
36288--- a/block/partitions/efi.c
36289+++ b/block/partitions/efi.c
36290@@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
36291 if (!gpt)
36292 return NULL;
36293
36294+ if (!le32_to_cpu(gpt->num_partition_entries))
36295+ return NULL;
36296+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
36297+ if (!pte)
36298+ return NULL;
36299+
36300 count = le32_to_cpu(gpt->num_partition_entries) *
36301 le32_to_cpu(gpt->sizeof_partition_entry);
36302- if (!count)
36303- return NULL;
36304- pte = kmalloc(count, GFP_KERNEL);
36305- if (!pte)
36306- return NULL;
36307-
36308 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
36309 (u8 *) pte, count) < count) {
36310 kfree(pte);
36311diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
36312index 2648797..92ed21f 100644
36313--- a/block/scsi_ioctl.c
36314+++ b/block/scsi_ioctl.c
36315@@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
36316 return put_user(0, p);
36317 }
36318
36319-static int sg_get_timeout(struct request_queue *q)
36320+static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
36321 {
36322 return jiffies_to_clock_t(q->sg_timeout);
36323 }
36324@@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
36325 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
36326 struct sg_io_hdr *hdr, fmode_t mode)
36327 {
36328- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
36329+ unsigned char tmpcmd[sizeof(rq->__cmd)];
36330+ unsigned char *cmdptr;
36331+
36332+ if (rq->cmd != rq->__cmd)
36333+ cmdptr = rq->cmd;
36334+ else
36335+ cmdptr = tmpcmd;
36336+
36337+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
36338 return -EFAULT;
36339+
36340+ if (cmdptr != rq->cmd)
36341+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
36342+
36343 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
36344 return -EPERM;
36345
36346@@ -417,6 +429,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36347 int err;
36348 unsigned int in_len, out_len, bytes, opcode, cmdlen;
36349 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
36350+ unsigned char tmpcmd[sizeof(rq->__cmd)];
36351+ unsigned char *cmdptr;
36352
36353 if (!sic)
36354 return -EINVAL;
36355@@ -450,9 +464,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36356 */
36357 err = -EFAULT;
36358 rq->cmd_len = cmdlen;
36359- if (copy_from_user(rq->cmd, sic->data, cmdlen))
36360+
36361+ if (rq->cmd != rq->__cmd)
36362+ cmdptr = rq->cmd;
36363+ else
36364+ cmdptr = tmpcmd;
36365+
36366+ if (copy_from_user(cmdptr, sic->data, cmdlen))
36367 goto error;
36368
36369+ if (rq->cmd != cmdptr)
36370+ memcpy(rq->cmd, cmdptr, cmdlen);
36371+
36372 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
36373 goto error;
36374
36375diff --git a/crypto/cryptd.c b/crypto/cryptd.c
36376index 7bdd61b..afec999 100644
36377--- a/crypto/cryptd.c
36378+++ b/crypto/cryptd.c
36379@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
36380
36381 struct cryptd_blkcipher_request_ctx {
36382 crypto_completion_t complete;
36383-};
36384+} __no_const;
36385
36386 struct cryptd_hash_ctx {
36387 struct crypto_shash *child;
36388@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
36389
36390 struct cryptd_aead_request_ctx {
36391 crypto_completion_t complete;
36392-};
36393+} __no_const;
36394
36395 static void cryptd_queue_worker(struct work_struct *work);
36396
36397diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
36398index 309d345..1632720 100644
36399--- a/crypto/pcrypt.c
36400+++ b/crypto/pcrypt.c
36401@@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
36402 int ret;
36403
36404 pinst->kobj.kset = pcrypt_kset;
36405- ret = kobject_add(&pinst->kobj, NULL, name);
36406+ ret = kobject_add(&pinst->kobj, NULL, "%s", name);
36407 if (!ret)
36408 kobject_uevent(&pinst->kobj, KOBJ_ADD);
36409
36410diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
36411index 15dddc1..b61cf0c 100644
36412--- a/drivers/acpi/acpica/hwxfsleep.c
36413+++ b/drivers/acpi/acpica/hwxfsleep.c
36414@@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
36415 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
36416
36417 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
36418- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36419- acpi_hw_extended_sleep},
36420- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36421- acpi_hw_extended_wake_prep},
36422- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
36423+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36424+ .extended_function = acpi_hw_extended_sleep},
36425+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36426+ .extended_function = acpi_hw_extended_wake_prep},
36427+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
36428+ .extended_function = acpi_hw_extended_wake}
36429 };
36430
36431 /*
36432diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
36433index e5bcd91..74f050d 100644
36434--- a/drivers/acpi/apei/apei-internal.h
36435+++ b/drivers/acpi/apei/apei-internal.h
36436@@ -19,7 +19,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
36437 struct apei_exec_ins_type {
36438 u32 flags;
36439 apei_exec_ins_func_t run;
36440-};
36441+} __do_const;
36442
36443 struct apei_exec_context {
36444 u32 ip;
36445diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
36446index dab7cb7..f0d2994 100644
36447--- a/drivers/acpi/apei/ghes.c
36448+++ b/drivers/acpi/apei/ghes.c
36449@@ -500,7 +500,7 @@ static void __ghes_print_estatus(const char *pfx,
36450 const struct acpi_hest_generic *generic,
36451 const struct acpi_generic_status *estatus)
36452 {
36453- static atomic_t seqno;
36454+ static atomic_unchecked_t seqno;
36455 unsigned int curr_seqno;
36456 char pfx_seq[64];
36457
36458@@ -511,7 +511,7 @@ static void __ghes_print_estatus(const char *pfx,
36459 else
36460 pfx = KERN_ERR;
36461 }
36462- curr_seqno = atomic_inc_return(&seqno);
36463+ curr_seqno = atomic_inc_return_unchecked(&seqno);
36464 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
36465 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
36466 pfx_seq, generic->header.source_id);
36467diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
36468index a83e3c6..c3d617f 100644
36469--- a/drivers/acpi/bgrt.c
36470+++ b/drivers/acpi/bgrt.c
36471@@ -86,8 +86,10 @@ static int __init bgrt_init(void)
36472 if (!bgrt_image)
36473 return -ENODEV;
36474
36475- bin_attr_image.private = bgrt_image;
36476- bin_attr_image.size = bgrt_image_size;
36477+ pax_open_kernel();
36478+ *(void **)&bin_attr_image.private = bgrt_image;
36479+ *(size_t *)&bin_attr_image.size = bgrt_image_size;
36480+ pax_close_kernel();
36481
36482 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
36483 if (!bgrt_kobj)
36484diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
36485index afec452..c5d8b96 100644
36486--- a/drivers/acpi/blacklist.c
36487+++ b/drivers/acpi/blacklist.c
36488@@ -51,7 +51,7 @@ struct acpi_blacklist_item {
36489 u32 is_critical_error;
36490 };
36491
36492-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
36493+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
36494
36495 /*
36496 * POLICY: If *anything* doesn't work, put it on the blacklist.
36497@@ -163,7 +163,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
36498 return 0;
36499 }
36500
36501-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
36502+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
36503 {
36504 .callback = dmi_disable_osi_vista,
36505 .ident = "Fujitsu Siemens",
36506diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
36507index c68e724..e863008 100644
36508--- a/drivers/acpi/custom_method.c
36509+++ b/drivers/acpi/custom_method.c
36510@@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
36511 struct acpi_table_header table;
36512 acpi_status status;
36513
36514+#ifdef CONFIG_GRKERNSEC_KMEM
36515+ return -EPERM;
36516+#endif
36517+
36518 if (!(*ppos)) {
36519 /* parse the table header to get the table length */
36520 if (count <= sizeof(struct acpi_table_header))
36521diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
36522index 3dca36d..abaf070 100644
36523--- a/drivers/acpi/processor_idle.c
36524+++ b/drivers/acpi/processor_idle.c
36525@@ -952,7 +952,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
36526 {
36527 int i, count = CPUIDLE_DRIVER_STATE_START;
36528 struct acpi_processor_cx *cx;
36529- struct cpuidle_state *state;
36530+ cpuidle_state_no_const *state;
36531 struct cpuidle_driver *drv = &acpi_idle_driver;
36532
36533 if (!pr->flags.power_setup_done)
36534diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
36535index 91a32ce..d77fcaf 100644
36536--- a/drivers/acpi/sysfs.c
36537+++ b/drivers/acpi/sysfs.c
36538@@ -425,11 +425,11 @@ static u32 num_counters;
36539 static struct attribute **all_attrs;
36540 static u32 acpi_gpe_count;
36541
36542-static struct attribute_group interrupt_stats_attr_group = {
36543+static attribute_group_no_const interrupt_stats_attr_group = {
36544 .name = "interrupts",
36545 };
36546
36547-static struct kobj_attribute *counter_attrs;
36548+static kobj_attribute_no_const *counter_attrs;
36549
36550 static void delete_gpe_attr_array(void)
36551 {
36552diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
36553index 36605ab..6ef6d4b 100644
36554--- a/drivers/ata/libahci.c
36555+++ b/drivers/ata/libahci.c
36556@@ -1239,7 +1239,7 @@ int ahci_kick_engine(struct ata_port *ap)
36557 }
36558 EXPORT_SYMBOL_GPL(ahci_kick_engine);
36559
36560-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36561+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36562 struct ata_taskfile *tf, int is_cmd, u16 flags,
36563 unsigned long timeout_msec)
36564 {
36565diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
36566index 0a79c54..c1b92ed 100644
36567--- a/drivers/ata/libata-core.c
36568+++ b/drivers/ata/libata-core.c
36569@@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
36570 static void ata_dev_xfermask(struct ata_device *dev);
36571 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
36572
36573-atomic_t ata_print_id = ATOMIC_INIT(0);
36574+atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
36575
36576 struct ata_force_param {
36577 const char *name;
36578@@ -4858,7 +4858,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
36579 struct ata_port *ap;
36580 unsigned int tag;
36581
36582- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36583+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36584 ap = qc->ap;
36585
36586 qc->flags = 0;
36587@@ -4874,7 +4874,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
36588 struct ata_port *ap;
36589 struct ata_link *link;
36590
36591- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36592+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36593 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
36594 ap = qc->ap;
36595 link = qc->dev->link;
36596@@ -5993,6 +5993,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36597 return;
36598
36599 spin_lock(&lock);
36600+ pax_open_kernel();
36601
36602 for (cur = ops->inherits; cur; cur = cur->inherits) {
36603 void **inherit = (void **)cur;
36604@@ -6006,8 +6007,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36605 if (IS_ERR(*pp))
36606 *pp = NULL;
36607
36608- ops->inherits = NULL;
36609+ *(struct ata_port_operations **)&ops->inherits = NULL;
36610
36611+ pax_close_kernel();
36612 spin_unlock(&lock);
36613 }
36614
36615@@ -6200,7 +6202,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
36616
36617 /* give ports names and add SCSI hosts */
36618 for (i = 0; i < host->n_ports; i++) {
36619- host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
36620+ host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
36621 host->ports[i]->local_port_no = i + 1;
36622 }
36623
36624diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
36625index ef8567d..8bdbd03 100644
36626--- a/drivers/ata/libata-scsi.c
36627+++ b/drivers/ata/libata-scsi.c
36628@@ -4147,7 +4147,7 @@ int ata_sas_port_init(struct ata_port *ap)
36629
36630 if (rc)
36631 return rc;
36632- ap->print_id = atomic_inc_return(&ata_print_id);
36633+ ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
36634 return 0;
36635 }
36636 EXPORT_SYMBOL_GPL(ata_sas_port_init);
36637diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
36638index 45b5ab3..98446b8 100644
36639--- a/drivers/ata/libata.h
36640+++ b/drivers/ata/libata.h
36641@@ -53,7 +53,7 @@ enum {
36642 ATA_DNXFER_QUIET = (1 << 31),
36643 };
36644
36645-extern atomic_t ata_print_id;
36646+extern atomic_unchecked_t ata_print_id;
36647 extern int atapi_passthru16;
36648 extern int libata_fua;
36649 extern int libata_noacpi;
36650diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
36651index 73492dd..ca2bff5 100644
36652--- a/drivers/ata/pata_arasan_cf.c
36653+++ b/drivers/ata/pata_arasan_cf.c
36654@@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
36655 /* Handle platform specific quirks */
36656 if (quirk) {
36657 if (quirk & CF_BROKEN_PIO) {
36658- ap->ops->set_piomode = NULL;
36659+ pax_open_kernel();
36660+ *(void **)&ap->ops->set_piomode = NULL;
36661+ pax_close_kernel();
36662 ap->pio_mask = 0;
36663 }
36664 if (quirk & CF_BROKEN_MWDMA)
36665diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
36666index f9b983a..887b9d8 100644
36667--- a/drivers/atm/adummy.c
36668+++ b/drivers/atm/adummy.c
36669@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
36670 vcc->pop(vcc, skb);
36671 else
36672 dev_kfree_skb_any(skb);
36673- atomic_inc(&vcc->stats->tx);
36674+ atomic_inc_unchecked(&vcc->stats->tx);
36675
36676 return 0;
36677 }
36678diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
36679index 62a7607..cc4be104 100644
36680--- a/drivers/atm/ambassador.c
36681+++ b/drivers/atm/ambassador.c
36682@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
36683 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
36684
36685 // VC layer stats
36686- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36687+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36688
36689 // free the descriptor
36690 kfree (tx_descr);
36691@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36692 dump_skb ("<<<", vc, skb);
36693
36694 // VC layer stats
36695- atomic_inc(&atm_vcc->stats->rx);
36696+ atomic_inc_unchecked(&atm_vcc->stats->rx);
36697 __net_timestamp(skb);
36698 // end of our responsibility
36699 atm_vcc->push (atm_vcc, skb);
36700@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36701 } else {
36702 PRINTK (KERN_INFO, "dropped over-size frame");
36703 // should we count this?
36704- atomic_inc(&atm_vcc->stats->rx_drop);
36705+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36706 }
36707
36708 } else {
36709@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
36710 }
36711
36712 if (check_area (skb->data, skb->len)) {
36713- atomic_inc(&atm_vcc->stats->tx_err);
36714+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
36715 return -ENOMEM; // ?
36716 }
36717
36718diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
36719index 0e3f8f9..765a7a5 100644
36720--- a/drivers/atm/atmtcp.c
36721+++ b/drivers/atm/atmtcp.c
36722@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36723 if (vcc->pop) vcc->pop(vcc,skb);
36724 else dev_kfree_skb(skb);
36725 if (dev_data) return 0;
36726- atomic_inc(&vcc->stats->tx_err);
36727+ atomic_inc_unchecked(&vcc->stats->tx_err);
36728 return -ENOLINK;
36729 }
36730 size = skb->len+sizeof(struct atmtcp_hdr);
36731@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36732 if (!new_skb) {
36733 if (vcc->pop) vcc->pop(vcc,skb);
36734 else dev_kfree_skb(skb);
36735- atomic_inc(&vcc->stats->tx_err);
36736+ atomic_inc_unchecked(&vcc->stats->tx_err);
36737 return -ENOBUFS;
36738 }
36739 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
36740@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36741 if (vcc->pop) vcc->pop(vcc,skb);
36742 else dev_kfree_skb(skb);
36743 out_vcc->push(out_vcc,new_skb);
36744- atomic_inc(&vcc->stats->tx);
36745- atomic_inc(&out_vcc->stats->rx);
36746+ atomic_inc_unchecked(&vcc->stats->tx);
36747+ atomic_inc_unchecked(&out_vcc->stats->rx);
36748 return 0;
36749 }
36750
36751@@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36752 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
36753 read_unlock(&vcc_sklist_lock);
36754 if (!out_vcc) {
36755- atomic_inc(&vcc->stats->tx_err);
36756+ atomic_inc_unchecked(&vcc->stats->tx_err);
36757 goto done;
36758 }
36759 skb_pull(skb,sizeof(struct atmtcp_hdr));
36760@@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36761 __net_timestamp(new_skb);
36762 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
36763 out_vcc->push(out_vcc,new_skb);
36764- atomic_inc(&vcc->stats->tx);
36765- atomic_inc(&out_vcc->stats->rx);
36766+ atomic_inc_unchecked(&vcc->stats->tx);
36767+ atomic_inc_unchecked(&out_vcc->stats->rx);
36768 done:
36769 if (vcc->pop) vcc->pop(vcc,skb);
36770 else dev_kfree_skb(skb);
36771diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
36772index b1955ba..b179940 100644
36773--- a/drivers/atm/eni.c
36774+++ b/drivers/atm/eni.c
36775@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
36776 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
36777 vcc->dev->number);
36778 length = 0;
36779- atomic_inc(&vcc->stats->rx_err);
36780+ atomic_inc_unchecked(&vcc->stats->rx_err);
36781 }
36782 else {
36783 length = ATM_CELL_SIZE-1; /* no HEC */
36784@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36785 size);
36786 }
36787 eff = length = 0;
36788- atomic_inc(&vcc->stats->rx_err);
36789+ atomic_inc_unchecked(&vcc->stats->rx_err);
36790 }
36791 else {
36792 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
36793@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36794 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
36795 vcc->dev->number,vcc->vci,length,size << 2,descr);
36796 length = eff = 0;
36797- atomic_inc(&vcc->stats->rx_err);
36798+ atomic_inc_unchecked(&vcc->stats->rx_err);
36799 }
36800 }
36801 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
36802@@ -767,7 +767,7 @@ rx_dequeued++;
36803 vcc->push(vcc,skb);
36804 pushed++;
36805 }
36806- atomic_inc(&vcc->stats->rx);
36807+ atomic_inc_unchecked(&vcc->stats->rx);
36808 }
36809 wake_up(&eni_dev->rx_wait);
36810 }
36811@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
36812 PCI_DMA_TODEVICE);
36813 if (vcc->pop) vcc->pop(vcc,skb);
36814 else dev_kfree_skb_irq(skb);
36815- atomic_inc(&vcc->stats->tx);
36816+ atomic_inc_unchecked(&vcc->stats->tx);
36817 wake_up(&eni_dev->tx_wait);
36818 dma_complete++;
36819 }
36820diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
36821index b41c948..a002b17 100644
36822--- a/drivers/atm/firestream.c
36823+++ b/drivers/atm/firestream.c
36824@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
36825 }
36826 }
36827
36828- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36829+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36830
36831 fs_dprintk (FS_DEBUG_TXMEM, "i");
36832 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
36833@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36834 #endif
36835 skb_put (skb, qe->p1 & 0xffff);
36836 ATM_SKB(skb)->vcc = atm_vcc;
36837- atomic_inc(&atm_vcc->stats->rx);
36838+ atomic_inc_unchecked(&atm_vcc->stats->rx);
36839 __net_timestamp(skb);
36840 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
36841 atm_vcc->push (atm_vcc, skb);
36842@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36843 kfree (pe);
36844 }
36845 if (atm_vcc)
36846- atomic_inc(&atm_vcc->stats->rx_drop);
36847+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36848 break;
36849 case 0x1f: /* Reassembly abort: no buffers. */
36850 /* Silently increment error counter. */
36851 if (atm_vcc)
36852- atomic_inc(&atm_vcc->stats->rx_drop);
36853+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36854 break;
36855 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
36856 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
36857diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
36858index 204814e..cede831 100644
36859--- a/drivers/atm/fore200e.c
36860+++ b/drivers/atm/fore200e.c
36861@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
36862 #endif
36863 /* check error condition */
36864 if (*entry->status & STATUS_ERROR)
36865- atomic_inc(&vcc->stats->tx_err);
36866+ atomic_inc_unchecked(&vcc->stats->tx_err);
36867 else
36868- atomic_inc(&vcc->stats->tx);
36869+ atomic_inc_unchecked(&vcc->stats->tx);
36870 }
36871 }
36872
36873@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36874 if (skb == NULL) {
36875 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
36876
36877- atomic_inc(&vcc->stats->rx_drop);
36878+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36879 return -ENOMEM;
36880 }
36881
36882@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36883
36884 dev_kfree_skb_any(skb);
36885
36886- atomic_inc(&vcc->stats->rx_drop);
36887+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36888 return -ENOMEM;
36889 }
36890
36891 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36892
36893 vcc->push(vcc, skb);
36894- atomic_inc(&vcc->stats->rx);
36895+ atomic_inc_unchecked(&vcc->stats->rx);
36896
36897 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36898
36899@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
36900 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
36901 fore200e->atm_dev->number,
36902 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
36903- atomic_inc(&vcc->stats->rx_err);
36904+ atomic_inc_unchecked(&vcc->stats->rx_err);
36905 }
36906 }
36907
36908@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
36909 goto retry_here;
36910 }
36911
36912- atomic_inc(&vcc->stats->tx_err);
36913+ atomic_inc_unchecked(&vcc->stats->tx_err);
36914
36915 fore200e->tx_sat++;
36916 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
36917diff --git a/drivers/atm/he.c b/drivers/atm/he.c
36918index aa6be26..f70a785 100644
36919--- a/drivers/atm/he.c
36920+++ b/drivers/atm/he.c
36921@@ -1690,7 +1690,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36922
36923 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
36924 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
36925- atomic_inc(&vcc->stats->rx_drop);
36926+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36927 goto return_host_buffers;
36928 }
36929
36930@@ -1717,7 +1717,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36931 RBRQ_LEN_ERR(he_dev->rbrq_head)
36932 ? "LEN_ERR" : "",
36933 vcc->vpi, vcc->vci);
36934- atomic_inc(&vcc->stats->rx_err);
36935+ atomic_inc_unchecked(&vcc->stats->rx_err);
36936 goto return_host_buffers;
36937 }
36938
36939@@ -1769,7 +1769,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36940 vcc->push(vcc, skb);
36941 spin_lock(&he_dev->global_lock);
36942
36943- atomic_inc(&vcc->stats->rx);
36944+ atomic_inc_unchecked(&vcc->stats->rx);
36945
36946 return_host_buffers:
36947 ++pdus_assembled;
36948@@ -2095,7 +2095,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
36949 tpd->vcc->pop(tpd->vcc, tpd->skb);
36950 else
36951 dev_kfree_skb_any(tpd->skb);
36952- atomic_inc(&tpd->vcc->stats->tx_err);
36953+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
36954 }
36955 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
36956 return;
36957@@ -2507,7 +2507,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36958 vcc->pop(vcc, skb);
36959 else
36960 dev_kfree_skb_any(skb);
36961- atomic_inc(&vcc->stats->tx_err);
36962+ atomic_inc_unchecked(&vcc->stats->tx_err);
36963 return -EINVAL;
36964 }
36965
36966@@ -2518,7 +2518,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36967 vcc->pop(vcc, skb);
36968 else
36969 dev_kfree_skb_any(skb);
36970- atomic_inc(&vcc->stats->tx_err);
36971+ atomic_inc_unchecked(&vcc->stats->tx_err);
36972 return -EINVAL;
36973 }
36974 #endif
36975@@ -2530,7 +2530,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36976 vcc->pop(vcc, skb);
36977 else
36978 dev_kfree_skb_any(skb);
36979- atomic_inc(&vcc->stats->tx_err);
36980+ atomic_inc_unchecked(&vcc->stats->tx_err);
36981 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36982 return -ENOMEM;
36983 }
36984@@ -2572,7 +2572,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36985 vcc->pop(vcc, skb);
36986 else
36987 dev_kfree_skb_any(skb);
36988- atomic_inc(&vcc->stats->tx_err);
36989+ atomic_inc_unchecked(&vcc->stats->tx_err);
36990 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36991 return -ENOMEM;
36992 }
36993@@ -2603,7 +2603,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36994 __enqueue_tpd(he_dev, tpd, cid);
36995 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36996
36997- atomic_inc(&vcc->stats->tx);
36998+ atomic_inc_unchecked(&vcc->stats->tx);
36999
37000 return 0;
37001 }
37002diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
37003index 1dc0519..1aadaf7 100644
37004--- a/drivers/atm/horizon.c
37005+++ b/drivers/atm/horizon.c
37006@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
37007 {
37008 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
37009 // VC layer stats
37010- atomic_inc(&vcc->stats->rx);
37011+ atomic_inc_unchecked(&vcc->stats->rx);
37012 __net_timestamp(skb);
37013 // end of our responsibility
37014 vcc->push (vcc, skb);
37015@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
37016 dev->tx_iovec = NULL;
37017
37018 // VC layer stats
37019- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
37020+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
37021
37022 // free the skb
37023 hrz_kfree_skb (skb);
37024diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
37025index 1bdf104..9dc44b1 100644
37026--- a/drivers/atm/idt77252.c
37027+++ b/drivers/atm/idt77252.c
37028@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
37029 else
37030 dev_kfree_skb(skb);
37031
37032- atomic_inc(&vcc->stats->tx);
37033+ atomic_inc_unchecked(&vcc->stats->tx);
37034 }
37035
37036 atomic_dec(&scq->used);
37037@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37038 if ((sb = dev_alloc_skb(64)) == NULL) {
37039 printk("%s: Can't allocate buffers for aal0.\n",
37040 card->name);
37041- atomic_add(i, &vcc->stats->rx_drop);
37042+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
37043 break;
37044 }
37045 if (!atm_charge(vcc, sb->truesize)) {
37046 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
37047 card->name);
37048- atomic_add(i - 1, &vcc->stats->rx_drop);
37049+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
37050 dev_kfree_skb(sb);
37051 break;
37052 }
37053@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37054 ATM_SKB(sb)->vcc = vcc;
37055 __net_timestamp(sb);
37056 vcc->push(vcc, sb);
37057- atomic_inc(&vcc->stats->rx);
37058+ atomic_inc_unchecked(&vcc->stats->rx);
37059
37060 cell += ATM_CELL_PAYLOAD;
37061 }
37062@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37063 "(CDC: %08x)\n",
37064 card->name, len, rpp->len, readl(SAR_REG_CDC));
37065 recycle_rx_pool_skb(card, rpp);
37066- atomic_inc(&vcc->stats->rx_err);
37067+ atomic_inc_unchecked(&vcc->stats->rx_err);
37068 return;
37069 }
37070 if (stat & SAR_RSQE_CRC) {
37071 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
37072 recycle_rx_pool_skb(card, rpp);
37073- atomic_inc(&vcc->stats->rx_err);
37074+ atomic_inc_unchecked(&vcc->stats->rx_err);
37075 return;
37076 }
37077 if (skb_queue_len(&rpp->queue) > 1) {
37078@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37079 RXPRINTK("%s: Can't alloc RX skb.\n",
37080 card->name);
37081 recycle_rx_pool_skb(card, rpp);
37082- atomic_inc(&vcc->stats->rx_err);
37083+ atomic_inc_unchecked(&vcc->stats->rx_err);
37084 return;
37085 }
37086 if (!atm_charge(vcc, skb->truesize)) {
37087@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37088 __net_timestamp(skb);
37089
37090 vcc->push(vcc, skb);
37091- atomic_inc(&vcc->stats->rx);
37092+ atomic_inc_unchecked(&vcc->stats->rx);
37093
37094 return;
37095 }
37096@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37097 __net_timestamp(skb);
37098
37099 vcc->push(vcc, skb);
37100- atomic_inc(&vcc->stats->rx);
37101+ atomic_inc_unchecked(&vcc->stats->rx);
37102
37103 if (skb->truesize > SAR_FB_SIZE_3)
37104 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
37105@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
37106 if (vcc->qos.aal != ATM_AAL0) {
37107 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
37108 card->name, vpi, vci);
37109- atomic_inc(&vcc->stats->rx_drop);
37110+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37111 goto drop;
37112 }
37113
37114 if ((sb = dev_alloc_skb(64)) == NULL) {
37115 printk("%s: Can't allocate buffers for AAL0.\n",
37116 card->name);
37117- atomic_inc(&vcc->stats->rx_err);
37118+ atomic_inc_unchecked(&vcc->stats->rx_err);
37119 goto drop;
37120 }
37121
37122@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
37123 ATM_SKB(sb)->vcc = vcc;
37124 __net_timestamp(sb);
37125 vcc->push(vcc, sb);
37126- atomic_inc(&vcc->stats->rx);
37127+ atomic_inc_unchecked(&vcc->stats->rx);
37128
37129 drop:
37130 skb_pull(queue, 64);
37131@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37132
37133 if (vc == NULL) {
37134 printk("%s: NULL connection in send().\n", card->name);
37135- atomic_inc(&vcc->stats->tx_err);
37136+ atomic_inc_unchecked(&vcc->stats->tx_err);
37137 dev_kfree_skb(skb);
37138 return -EINVAL;
37139 }
37140 if (!test_bit(VCF_TX, &vc->flags)) {
37141 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
37142- atomic_inc(&vcc->stats->tx_err);
37143+ atomic_inc_unchecked(&vcc->stats->tx_err);
37144 dev_kfree_skb(skb);
37145 return -EINVAL;
37146 }
37147@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37148 break;
37149 default:
37150 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
37151- atomic_inc(&vcc->stats->tx_err);
37152+ atomic_inc_unchecked(&vcc->stats->tx_err);
37153 dev_kfree_skb(skb);
37154 return -EINVAL;
37155 }
37156
37157 if (skb_shinfo(skb)->nr_frags != 0) {
37158 printk("%s: No scatter-gather yet.\n", card->name);
37159- atomic_inc(&vcc->stats->tx_err);
37160+ atomic_inc_unchecked(&vcc->stats->tx_err);
37161 dev_kfree_skb(skb);
37162 return -EINVAL;
37163 }
37164@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37165
37166 err = queue_skb(card, vc, skb, oam);
37167 if (err) {
37168- atomic_inc(&vcc->stats->tx_err);
37169+ atomic_inc_unchecked(&vcc->stats->tx_err);
37170 dev_kfree_skb(skb);
37171 return err;
37172 }
37173@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
37174 skb = dev_alloc_skb(64);
37175 if (!skb) {
37176 printk("%s: Out of memory in send_oam().\n", card->name);
37177- atomic_inc(&vcc->stats->tx_err);
37178+ atomic_inc_unchecked(&vcc->stats->tx_err);
37179 return -ENOMEM;
37180 }
37181 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
37182diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
37183index 4217f29..88f547a 100644
37184--- a/drivers/atm/iphase.c
37185+++ b/drivers/atm/iphase.c
37186@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
37187 status = (u_short) (buf_desc_ptr->desc_mode);
37188 if (status & (RX_CER | RX_PTE | RX_OFL))
37189 {
37190- atomic_inc(&vcc->stats->rx_err);
37191+ atomic_inc_unchecked(&vcc->stats->rx_err);
37192 IF_ERR(printk("IA: bad packet, dropping it");)
37193 if (status & RX_CER) {
37194 IF_ERR(printk(" cause: packet CRC error\n");)
37195@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
37196 len = dma_addr - buf_addr;
37197 if (len > iadev->rx_buf_sz) {
37198 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
37199- atomic_inc(&vcc->stats->rx_err);
37200+ atomic_inc_unchecked(&vcc->stats->rx_err);
37201 goto out_free_desc;
37202 }
37203
37204@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37205 ia_vcc = INPH_IA_VCC(vcc);
37206 if (ia_vcc == NULL)
37207 {
37208- atomic_inc(&vcc->stats->rx_err);
37209+ atomic_inc_unchecked(&vcc->stats->rx_err);
37210 atm_return(vcc, skb->truesize);
37211 dev_kfree_skb_any(skb);
37212 goto INCR_DLE;
37213@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37214 if ((length > iadev->rx_buf_sz) || (length >
37215 (skb->len - sizeof(struct cpcs_trailer))))
37216 {
37217- atomic_inc(&vcc->stats->rx_err);
37218+ atomic_inc_unchecked(&vcc->stats->rx_err);
37219 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
37220 length, skb->len);)
37221 atm_return(vcc, skb->truesize);
37222@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37223
37224 IF_RX(printk("rx_dle_intr: skb push");)
37225 vcc->push(vcc,skb);
37226- atomic_inc(&vcc->stats->rx);
37227+ atomic_inc_unchecked(&vcc->stats->rx);
37228 iadev->rx_pkt_cnt++;
37229 }
37230 INCR_DLE:
37231@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
37232 {
37233 struct k_sonet_stats *stats;
37234 stats = &PRIV(_ia_dev[board])->sonet_stats;
37235- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
37236- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
37237- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
37238- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
37239- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
37240- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
37241- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
37242- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
37243- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
37244+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
37245+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
37246+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
37247+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
37248+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
37249+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
37250+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
37251+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
37252+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
37253 }
37254 ia_cmds.status = 0;
37255 break;
37256@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
37257 if ((desc == 0) || (desc > iadev->num_tx_desc))
37258 {
37259 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
37260- atomic_inc(&vcc->stats->tx);
37261+ atomic_inc_unchecked(&vcc->stats->tx);
37262 if (vcc->pop)
37263 vcc->pop(vcc, skb);
37264 else
37265@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
37266 ATM_DESC(skb) = vcc->vci;
37267 skb_queue_tail(&iadev->tx_dma_q, skb);
37268
37269- atomic_inc(&vcc->stats->tx);
37270+ atomic_inc_unchecked(&vcc->stats->tx);
37271 iadev->tx_pkt_cnt++;
37272 /* Increment transaction counter */
37273 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
37274
37275 #if 0
37276 /* add flow control logic */
37277- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
37278+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
37279 if (iavcc->vc_desc_cnt > 10) {
37280 vcc->tx_quota = vcc->tx_quota * 3 / 4;
37281 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
37282diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
37283index fa7d701..1e404c7 100644
37284--- a/drivers/atm/lanai.c
37285+++ b/drivers/atm/lanai.c
37286@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
37287 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
37288 lanai_endtx(lanai, lvcc);
37289 lanai_free_skb(lvcc->tx.atmvcc, skb);
37290- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
37291+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
37292 }
37293
37294 /* Try to fill the buffer - don't call unless there is backlog */
37295@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
37296 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
37297 __net_timestamp(skb);
37298 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
37299- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
37300+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
37301 out:
37302 lvcc->rx.buf.ptr = end;
37303 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
37304@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37305 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
37306 "vcc %d\n", lanai->number, (unsigned int) s, vci);
37307 lanai->stats.service_rxnotaal5++;
37308- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37309+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37310 return 0;
37311 }
37312 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
37313@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37314 int bytes;
37315 read_unlock(&vcc_sklist_lock);
37316 DPRINTK("got trashed rx pdu on vci %d\n", vci);
37317- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37318+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37319 lvcc->stats.x.aal5.service_trash++;
37320 bytes = (SERVICE_GET_END(s) * 16) -
37321 (((unsigned long) lvcc->rx.buf.ptr) -
37322@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37323 }
37324 if (s & SERVICE_STREAM) {
37325 read_unlock(&vcc_sklist_lock);
37326- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37327+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37328 lvcc->stats.x.aal5.service_stream++;
37329 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
37330 "PDU on VCI %d!\n", lanai->number, vci);
37331@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37332 return 0;
37333 }
37334 DPRINTK("got rx crc error on vci %d\n", vci);
37335- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37336+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37337 lvcc->stats.x.aal5.service_rxcrc++;
37338 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
37339 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
37340diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
37341index 9587e95..b45c5cb 100644
37342--- a/drivers/atm/nicstar.c
37343+++ b/drivers/atm/nicstar.c
37344@@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37345 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
37346 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
37347 card->index);
37348- atomic_inc(&vcc->stats->tx_err);
37349+ atomic_inc_unchecked(&vcc->stats->tx_err);
37350 dev_kfree_skb_any(skb);
37351 return -EINVAL;
37352 }
37353@@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37354 if (!vc->tx) {
37355 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
37356 card->index);
37357- atomic_inc(&vcc->stats->tx_err);
37358+ atomic_inc_unchecked(&vcc->stats->tx_err);
37359 dev_kfree_skb_any(skb);
37360 return -EINVAL;
37361 }
37362@@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37363 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
37364 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
37365 card->index);
37366- atomic_inc(&vcc->stats->tx_err);
37367+ atomic_inc_unchecked(&vcc->stats->tx_err);
37368 dev_kfree_skb_any(skb);
37369 return -EINVAL;
37370 }
37371
37372 if (skb_shinfo(skb)->nr_frags != 0) {
37373 printk("nicstar%d: No scatter-gather yet.\n", card->index);
37374- atomic_inc(&vcc->stats->tx_err);
37375+ atomic_inc_unchecked(&vcc->stats->tx_err);
37376 dev_kfree_skb_any(skb);
37377 return -EINVAL;
37378 }
37379@@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37380 }
37381
37382 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
37383- atomic_inc(&vcc->stats->tx_err);
37384+ atomic_inc_unchecked(&vcc->stats->tx_err);
37385 dev_kfree_skb_any(skb);
37386 return -EIO;
37387 }
37388- atomic_inc(&vcc->stats->tx);
37389+ atomic_inc_unchecked(&vcc->stats->tx);
37390
37391 return 0;
37392 }
37393@@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37394 printk
37395 ("nicstar%d: Can't allocate buffers for aal0.\n",
37396 card->index);
37397- atomic_add(i, &vcc->stats->rx_drop);
37398+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
37399 break;
37400 }
37401 if (!atm_charge(vcc, sb->truesize)) {
37402 RXPRINTK
37403 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
37404 card->index);
37405- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37406+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37407 dev_kfree_skb_any(sb);
37408 break;
37409 }
37410@@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37411 ATM_SKB(sb)->vcc = vcc;
37412 __net_timestamp(sb);
37413 vcc->push(vcc, sb);
37414- atomic_inc(&vcc->stats->rx);
37415+ atomic_inc_unchecked(&vcc->stats->rx);
37416 cell += ATM_CELL_PAYLOAD;
37417 }
37418
37419@@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37420 if (iovb == NULL) {
37421 printk("nicstar%d: Out of iovec buffers.\n",
37422 card->index);
37423- atomic_inc(&vcc->stats->rx_drop);
37424+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37425 recycle_rx_buf(card, skb);
37426 return;
37427 }
37428@@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37429 small or large buffer itself. */
37430 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
37431 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
37432- atomic_inc(&vcc->stats->rx_err);
37433+ atomic_inc_unchecked(&vcc->stats->rx_err);
37434 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37435 NS_MAX_IOVECS);
37436 NS_PRV_IOVCNT(iovb) = 0;
37437@@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37438 ("nicstar%d: Expected a small buffer, and this is not one.\n",
37439 card->index);
37440 which_list(card, skb);
37441- atomic_inc(&vcc->stats->rx_err);
37442+ atomic_inc_unchecked(&vcc->stats->rx_err);
37443 recycle_rx_buf(card, skb);
37444 vc->rx_iov = NULL;
37445 recycle_iov_buf(card, iovb);
37446@@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37447 ("nicstar%d: Expected a large buffer, and this is not one.\n",
37448 card->index);
37449 which_list(card, skb);
37450- atomic_inc(&vcc->stats->rx_err);
37451+ atomic_inc_unchecked(&vcc->stats->rx_err);
37452 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37453 NS_PRV_IOVCNT(iovb));
37454 vc->rx_iov = NULL;
37455@@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37456 printk(" - PDU size mismatch.\n");
37457 else
37458 printk(".\n");
37459- atomic_inc(&vcc->stats->rx_err);
37460+ atomic_inc_unchecked(&vcc->stats->rx_err);
37461 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37462 NS_PRV_IOVCNT(iovb));
37463 vc->rx_iov = NULL;
37464@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37465 /* skb points to a small buffer */
37466 if (!atm_charge(vcc, skb->truesize)) {
37467 push_rxbufs(card, skb);
37468- atomic_inc(&vcc->stats->rx_drop);
37469+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37470 } else {
37471 skb_put(skb, len);
37472 dequeue_sm_buf(card, skb);
37473@@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37474 ATM_SKB(skb)->vcc = vcc;
37475 __net_timestamp(skb);
37476 vcc->push(vcc, skb);
37477- atomic_inc(&vcc->stats->rx);
37478+ atomic_inc_unchecked(&vcc->stats->rx);
37479 }
37480 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
37481 struct sk_buff *sb;
37482@@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37483 if (len <= NS_SMBUFSIZE) {
37484 if (!atm_charge(vcc, sb->truesize)) {
37485 push_rxbufs(card, sb);
37486- atomic_inc(&vcc->stats->rx_drop);
37487+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37488 } else {
37489 skb_put(sb, len);
37490 dequeue_sm_buf(card, sb);
37491@@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37492 ATM_SKB(sb)->vcc = vcc;
37493 __net_timestamp(sb);
37494 vcc->push(vcc, sb);
37495- atomic_inc(&vcc->stats->rx);
37496+ atomic_inc_unchecked(&vcc->stats->rx);
37497 }
37498
37499 push_rxbufs(card, skb);
37500@@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37501
37502 if (!atm_charge(vcc, skb->truesize)) {
37503 push_rxbufs(card, skb);
37504- atomic_inc(&vcc->stats->rx_drop);
37505+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37506 } else {
37507 dequeue_lg_buf(card, skb);
37508 #ifdef NS_USE_DESTRUCTORS
37509@@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37510 ATM_SKB(skb)->vcc = vcc;
37511 __net_timestamp(skb);
37512 vcc->push(vcc, skb);
37513- atomic_inc(&vcc->stats->rx);
37514+ atomic_inc_unchecked(&vcc->stats->rx);
37515 }
37516
37517 push_rxbufs(card, sb);
37518@@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37519 printk
37520 ("nicstar%d: Out of huge buffers.\n",
37521 card->index);
37522- atomic_inc(&vcc->stats->rx_drop);
37523+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37524 recycle_iovec_rx_bufs(card,
37525 (struct iovec *)
37526 iovb->data,
37527@@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37528 card->hbpool.count++;
37529 } else
37530 dev_kfree_skb_any(hb);
37531- atomic_inc(&vcc->stats->rx_drop);
37532+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37533 } else {
37534 /* Copy the small buffer to the huge buffer */
37535 sb = (struct sk_buff *)iov->iov_base;
37536@@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37537 #endif /* NS_USE_DESTRUCTORS */
37538 __net_timestamp(hb);
37539 vcc->push(vcc, hb);
37540- atomic_inc(&vcc->stats->rx);
37541+ atomic_inc_unchecked(&vcc->stats->rx);
37542 }
37543 }
37544
37545diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
37546index e3fb496..d9646bf 100644
37547--- a/drivers/atm/solos-pci.c
37548+++ b/drivers/atm/solos-pci.c
37549@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
37550 }
37551 atm_charge(vcc, skb->truesize);
37552 vcc->push(vcc, skb);
37553- atomic_inc(&vcc->stats->rx);
37554+ atomic_inc_unchecked(&vcc->stats->rx);
37555 break;
37556
37557 case PKT_STATUS:
37558@@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
37559 vcc = SKB_CB(oldskb)->vcc;
37560
37561 if (vcc) {
37562- atomic_inc(&vcc->stats->tx);
37563+ atomic_inc_unchecked(&vcc->stats->tx);
37564 solos_pop(vcc, oldskb);
37565 } else {
37566 dev_kfree_skb_irq(oldskb);
37567diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
37568index 0215934..ce9f5b1 100644
37569--- a/drivers/atm/suni.c
37570+++ b/drivers/atm/suni.c
37571@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
37572
37573
37574 #define ADD_LIMITED(s,v) \
37575- atomic_add((v),&stats->s); \
37576- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
37577+ atomic_add_unchecked((v),&stats->s); \
37578+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
37579
37580
37581 static void suni_hz(unsigned long from_timer)
37582diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
37583index 5120a96..e2572bd 100644
37584--- a/drivers/atm/uPD98402.c
37585+++ b/drivers/atm/uPD98402.c
37586@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
37587 struct sonet_stats tmp;
37588 int error = 0;
37589
37590- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37591+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37592 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
37593 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
37594 if (zero && !error) {
37595@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
37596
37597
37598 #define ADD_LIMITED(s,v) \
37599- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
37600- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
37601- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37602+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
37603+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
37604+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37605
37606
37607 static void stat_event(struct atm_dev *dev)
37608@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
37609 if (reason & uPD98402_INT_PFM) stat_event(dev);
37610 if (reason & uPD98402_INT_PCO) {
37611 (void) GET(PCOCR); /* clear interrupt cause */
37612- atomic_add(GET(HECCT),
37613+ atomic_add_unchecked(GET(HECCT),
37614 &PRIV(dev)->sonet_stats.uncorr_hcs);
37615 }
37616 if ((reason & uPD98402_INT_RFO) &&
37617@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
37618 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
37619 uPD98402_INT_LOS),PIMR); /* enable them */
37620 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
37621- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37622- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
37623- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
37624+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37625+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
37626+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
37627 return 0;
37628 }
37629
37630diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
37631index 969c3c2..9b72956 100644
37632--- a/drivers/atm/zatm.c
37633+++ b/drivers/atm/zatm.c
37634@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37635 }
37636 if (!size) {
37637 dev_kfree_skb_irq(skb);
37638- if (vcc) atomic_inc(&vcc->stats->rx_err);
37639+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
37640 continue;
37641 }
37642 if (!atm_charge(vcc,skb->truesize)) {
37643@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37644 skb->len = size;
37645 ATM_SKB(skb)->vcc = vcc;
37646 vcc->push(vcc,skb);
37647- atomic_inc(&vcc->stats->rx);
37648+ atomic_inc_unchecked(&vcc->stats->rx);
37649 }
37650 zout(pos & 0xffff,MTA(mbx));
37651 #if 0 /* probably a stupid idea */
37652@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
37653 skb_queue_head(&zatm_vcc->backlog,skb);
37654 break;
37655 }
37656- atomic_inc(&vcc->stats->tx);
37657+ atomic_inc_unchecked(&vcc->stats->tx);
37658 wake_up(&zatm_vcc->tx_wait);
37659 }
37660
37661diff --git a/drivers/base/bus.c b/drivers/base/bus.c
37662index 59dc808..f10c74e 100644
37663--- a/drivers/base/bus.c
37664+++ b/drivers/base/bus.c
37665@@ -1124,7 +1124,7 @@ int subsys_interface_register(struct subsys_interface *sif)
37666 return -EINVAL;
37667
37668 mutex_lock(&subsys->p->mutex);
37669- list_add_tail(&sif->node, &subsys->p->interfaces);
37670+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
37671 if (sif->add_dev) {
37672 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37673 while ((dev = subsys_dev_iter_next(&iter)))
37674@@ -1149,7 +1149,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
37675 subsys = sif->subsys;
37676
37677 mutex_lock(&subsys->p->mutex);
37678- list_del_init(&sif->node);
37679+ pax_list_del_init((struct list_head *)&sif->node);
37680 if (sif->remove_dev) {
37681 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37682 while ((dev = subsys_dev_iter_next(&iter)))
37683diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
37684index 25798db..15f130e 100644
37685--- a/drivers/base/devtmpfs.c
37686+++ b/drivers/base/devtmpfs.c
37687@@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
37688 if (!thread)
37689 return 0;
37690
37691- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
37692+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
37693 if (err)
37694 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
37695 else
37696@@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
37697 *err = sys_unshare(CLONE_NEWNS);
37698 if (*err)
37699 goto out;
37700- *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
37701+ *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
37702 if (*err)
37703 goto out;
37704- sys_chdir("/.."); /* will traverse into overmounted root */
37705- sys_chroot(".");
37706+ sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
37707+ sys_chroot((char __force_user *)".");
37708 complete(&setup_done);
37709 while (1) {
37710 spin_lock(&req_lock);
37711diff --git a/drivers/base/node.c b/drivers/base/node.c
37712index bc9f43b..29703b8 100644
37713--- a/drivers/base/node.c
37714+++ b/drivers/base/node.c
37715@@ -620,7 +620,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
37716 struct node_attr {
37717 struct device_attribute attr;
37718 enum node_states state;
37719-};
37720+} __do_const;
37721
37722 static ssize_t show_node_state(struct device *dev,
37723 struct device_attribute *attr, char *buf)
37724diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
37725index bfb8955..4ebff34 100644
37726--- a/drivers/base/power/domain.c
37727+++ b/drivers/base/power/domain.c
37728@@ -1809,9 +1809,9 @@ int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td)
37729
37730 if (dev->power.subsys_data->domain_data) {
37731 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
37732- gpd_data->ops = (struct gpd_dev_ops){ NULL };
37733+ memset(&gpd_data->ops, 0, sizeof(gpd_data->ops));
37734 if (clear_td)
37735- gpd_data->td = (struct gpd_timing_data){ 0 };
37736+ memset(&gpd_data->td, 0, sizeof(gpd_data->td));
37737
37738 if (--gpd_data->refcount == 0) {
37739 dev->power.subsys_data->domain_data = NULL;
37740@@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
37741 {
37742 struct cpuidle_driver *cpuidle_drv;
37743 struct gpd_cpu_data *cpu_data;
37744- struct cpuidle_state *idle_state;
37745+ cpuidle_state_no_const *idle_state;
37746 int ret = 0;
37747
37748 if (IS_ERR_OR_NULL(genpd) || state < 0)
37749@@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
37750 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
37751 {
37752 struct gpd_cpu_data *cpu_data;
37753- struct cpuidle_state *idle_state;
37754+ cpuidle_state_no_const *idle_state;
37755 int ret = 0;
37756
37757 if (IS_ERR_OR_NULL(genpd))
37758diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
37759index 03e089a..0e9560c 100644
37760--- a/drivers/base/power/sysfs.c
37761+++ b/drivers/base/power/sysfs.c
37762@@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
37763 return -EIO;
37764 }
37765 }
37766- return sprintf(buf, p);
37767+ return sprintf(buf, "%s", p);
37768 }
37769
37770 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
37771diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
37772index 2d56f41..8830f19 100644
37773--- a/drivers/base/power/wakeup.c
37774+++ b/drivers/base/power/wakeup.c
37775@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
37776 * They need to be modified together atomically, so it's better to use one
37777 * atomic variable to hold them both.
37778 */
37779-static atomic_t combined_event_count = ATOMIC_INIT(0);
37780+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
37781
37782 #define IN_PROGRESS_BITS (sizeof(int) * 4)
37783 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
37784
37785 static void split_counters(unsigned int *cnt, unsigned int *inpr)
37786 {
37787- unsigned int comb = atomic_read(&combined_event_count);
37788+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
37789
37790 *cnt = (comb >> IN_PROGRESS_BITS);
37791 *inpr = comb & MAX_IN_PROGRESS;
37792@@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
37793 ws->start_prevent_time = ws->last_time;
37794
37795 /* Increment the counter of events in progress. */
37796- cec = atomic_inc_return(&combined_event_count);
37797+ cec = atomic_inc_return_unchecked(&combined_event_count);
37798
37799 trace_wakeup_source_activate(ws->name, cec);
37800 }
37801@@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
37802 * Increment the counter of registered wakeup events and decrement the
37803 * couter of wakeup events in progress simultaneously.
37804 */
37805- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
37806+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
37807 trace_wakeup_source_deactivate(ws->name, cec);
37808
37809 split_counters(&cnt, &inpr);
37810diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
37811index e8d11b6..7b1b36f 100644
37812--- a/drivers/base/syscore.c
37813+++ b/drivers/base/syscore.c
37814@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
37815 void register_syscore_ops(struct syscore_ops *ops)
37816 {
37817 mutex_lock(&syscore_ops_lock);
37818- list_add_tail(&ops->node, &syscore_ops_list);
37819+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
37820 mutex_unlock(&syscore_ops_lock);
37821 }
37822 EXPORT_SYMBOL_GPL(register_syscore_ops);
37823@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
37824 void unregister_syscore_ops(struct syscore_ops *ops)
37825 {
37826 mutex_lock(&syscore_ops_lock);
37827- list_del(&ops->node);
37828+ pax_list_del((struct list_head *)&ops->node);
37829 mutex_unlock(&syscore_ops_lock);
37830 }
37831 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
37832diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
37833index 036e8ab..6221dec 100644
37834--- a/drivers/block/cciss.c
37835+++ b/drivers/block/cciss.c
37836@@ -3011,7 +3011,7 @@ static void start_io(ctlr_info_t *h)
37837 while (!list_empty(&h->reqQ)) {
37838 c = list_entry(h->reqQ.next, CommandList_struct, list);
37839 /* can't do anything if fifo is full */
37840- if ((h->access.fifo_full(h))) {
37841+ if ((h->access->fifo_full(h))) {
37842 dev_warn(&h->pdev->dev, "fifo full\n");
37843 break;
37844 }
37845@@ -3021,7 +3021,7 @@ static void start_io(ctlr_info_t *h)
37846 h->Qdepth--;
37847
37848 /* Tell the controller execute command */
37849- h->access.submit_command(h, c);
37850+ h->access->submit_command(h, c);
37851
37852 /* Put job onto the completed Q */
37853 addQ(&h->cmpQ, c);
37854@@ -3447,17 +3447,17 @@ startio:
37855
37856 static inline unsigned long get_next_completion(ctlr_info_t *h)
37857 {
37858- return h->access.command_completed(h);
37859+ return h->access->command_completed(h);
37860 }
37861
37862 static inline int interrupt_pending(ctlr_info_t *h)
37863 {
37864- return h->access.intr_pending(h);
37865+ return h->access->intr_pending(h);
37866 }
37867
37868 static inline long interrupt_not_for_us(ctlr_info_t *h)
37869 {
37870- return ((h->access.intr_pending(h) == 0) ||
37871+ return ((h->access->intr_pending(h) == 0) ||
37872 (h->interrupts_enabled == 0));
37873 }
37874
37875@@ -3490,7 +3490,7 @@ static inline u32 next_command(ctlr_info_t *h)
37876 u32 a;
37877
37878 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
37879- return h->access.command_completed(h);
37880+ return h->access->command_completed(h);
37881
37882 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
37883 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
37884@@ -4047,7 +4047,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
37885 trans_support & CFGTBL_Trans_use_short_tags);
37886
37887 /* Change the access methods to the performant access methods */
37888- h->access = SA5_performant_access;
37889+ h->access = &SA5_performant_access;
37890 h->transMethod = CFGTBL_Trans_Performant;
37891
37892 return;
37893@@ -4327,7 +4327,7 @@ static int cciss_pci_init(ctlr_info_t *h)
37894 if (prod_index < 0)
37895 return -ENODEV;
37896 h->product_name = products[prod_index].product_name;
37897- h->access = *(products[prod_index].access);
37898+ h->access = products[prod_index].access;
37899
37900 if (cciss_board_disabled(h)) {
37901 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
37902@@ -5059,7 +5059,7 @@ reinit_after_soft_reset:
37903 }
37904
37905 /* make sure the board interrupts are off */
37906- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37907+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37908 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
37909 if (rc)
37910 goto clean2;
37911@@ -5109,7 +5109,7 @@ reinit_after_soft_reset:
37912 * fake ones to scoop up any residual completions.
37913 */
37914 spin_lock_irqsave(&h->lock, flags);
37915- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37916+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37917 spin_unlock_irqrestore(&h->lock, flags);
37918 free_irq(h->intr[h->intr_mode], h);
37919 rc = cciss_request_irq(h, cciss_msix_discard_completions,
37920@@ -5129,9 +5129,9 @@ reinit_after_soft_reset:
37921 dev_info(&h->pdev->dev, "Board READY.\n");
37922 dev_info(&h->pdev->dev,
37923 "Waiting for stale completions to drain.\n");
37924- h->access.set_intr_mask(h, CCISS_INTR_ON);
37925+ h->access->set_intr_mask(h, CCISS_INTR_ON);
37926 msleep(10000);
37927- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37928+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37929
37930 rc = controller_reset_failed(h->cfgtable);
37931 if (rc)
37932@@ -5154,7 +5154,7 @@ reinit_after_soft_reset:
37933 cciss_scsi_setup(h);
37934
37935 /* Turn the interrupts on so we can service requests */
37936- h->access.set_intr_mask(h, CCISS_INTR_ON);
37937+ h->access->set_intr_mask(h, CCISS_INTR_ON);
37938
37939 /* Get the firmware version */
37940 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
37941@@ -5226,7 +5226,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
37942 kfree(flush_buf);
37943 if (return_code != IO_OK)
37944 dev_warn(&h->pdev->dev, "Error flushing cache\n");
37945- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37946+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37947 free_irq(h->intr[h->intr_mode], h);
37948 }
37949
37950diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
37951index 7fda30e..2f27946 100644
37952--- a/drivers/block/cciss.h
37953+++ b/drivers/block/cciss.h
37954@@ -101,7 +101,7 @@ struct ctlr_info
37955 /* information about each logical volume */
37956 drive_info_struct *drv[CISS_MAX_LUN];
37957
37958- struct access_method access;
37959+ struct access_method *access;
37960
37961 /* queue and queue Info */
37962 struct list_head reqQ;
37963@@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
37964 }
37965
37966 static struct access_method SA5_access = {
37967- SA5_submit_command,
37968- SA5_intr_mask,
37969- SA5_fifo_full,
37970- SA5_intr_pending,
37971- SA5_completed,
37972+ .submit_command = SA5_submit_command,
37973+ .set_intr_mask = SA5_intr_mask,
37974+ .fifo_full = SA5_fifo_full,
37975+ .intr_pending = SA5_intr_pending,
37976+ .command_completed = SA5_completed,
37977 };
37978
37979 static struct access_method SA5B_access = {
37980- SA5_submit_command,
37981- SA5B_intr_mask,
37982- SA5_fifo_full,
37983- SA5B_intr_pending,
37984- SA5_completed,
37985+ .submit_command = SA5_submit_command,
37986+ .set_intr_mask = SA5B_intr_mask,
37987+ .fifo_full = SA5_fifo_full,
37988+ .intr_pending = SA5B_intr_pending,
37989+ .command_completed = SA5_completed,
37990 };
37991
37992 static struct access_method SA5_performant_access = {
37993- SA5_submit_command,
37994- SA5_performant_intr_mask,
37995- SA5_fifo_full,
37996- SA5_performant_intr_pending,
37997- SA5_performant_completed,
37998+ .submit_command = SA5_submit_command,
37999+ .set_intr_mask = SA5_performant_intr_mask,
38000+ .fifo_full = SA5_fifo_full,
38001+ .intr_pending = SA5_performant_intr_pending,
38002+ .command_completed = SA5_performant_completed,
38003 };
38004
38005 struct board_type {
38006diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
38007index 2b94403..fd6ad1f 100644
38008--- a/drivers/block/cpqarray.c
38009+++ b/drivers/block/cpqarray.c
38010@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
38011 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
38012 goto Enomem4;
38013 }
38014- hba[i]->access.set_intr_mask(hba[i], 0);
38015+ hba[i]->access->set_intr_mask(hba[i], 0);
38016 if (request_irq(hba[i]->intr, do_ida_intr,
38017 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
38018 {
38019@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
38020 add_timer(&hba[i]->timer);
38021
38022 /* Enable IRQ now that spinlock and rate limit timer are set up */
38023- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
38024+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
38025
38026 for(j=0; j<NWD; j++) {
38027 struct gendisk *disk = ida_gendisk[i][j];
38028@@ -694,7 +694,7 @@ DBGINFO(
38029 for(i=0; i<NR_PRODUCTS; i++) {
38030 if (board_id == products[i].board_id) {
38031 c->product_name = products[i].product_name;
38032- c->access = *(products[i].access);
38033+ c->access = products[i].access;
38034 break;
38035 }
38036 }
38037@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
38038 hba[ctlr]->intr = intr;
38039 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
38040 hba[ctlr]->product_name = products[j].product_name;
38041- hba[ctlr]->access = *(products[j].access);
38042+ hba[ctlr]->access = products[j].access;
38043 hba[ctlr]->ctlr = ctlr;
38044 hba[ctlr]->board_id = board_id;
38045 hba[ctlr]->pci_dev = NULL; /* not PCI */
38046@@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
38047
38048 while((c = h->reqQ) != NULL) {
38049 /* Can't do anything if we're busy */
38050- if (h->access.fifo_full(h) == 0)
38051+ if (h->access->fifo_full(h) == 0)
38052 return;
38053
38054 /* Get the first entry from the request Q */
38055@@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
38056 h->Qdepth--;
38057
38058 /* Tell the controller to do our bidding */
38059- h->access.submit_command(h, c);
38060+ h->access->submit_command(h, c);
38061
38062 /* Get onto the completion Q */
38063 addQ(&h->cmpQ, c);
38064@@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
38065 unsigned long flags;
38066 __u32 a,a1;
38067
38068- istat = h->access.intr_pending(h);
38069+ istat = h->access->intr_pending(h);
38070 /* Is this interrupt for us? */
38071 if (istat == 0)
38072 return IRQ_NONE;
38073@@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
38074 */
38075 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
38076 if (istat & FIFO_NOT_EMPTY) {
38077- while((a = h->access.command_completed(h))) {
38078+ while((a = h->access->command_completed(h))) {
38079 a1 = a; a &= ~3;
38080 if ((c = h->cmpQ) == NULL)
38081 {
38082@@ -1448,11 +1448,11 @@ static int sendcmd(
38083 /*
38084 * Disable interrupt
38085 */
38086- info_p->access.set_intr_mask(info_p, 0);
38087+ info_p->access->set_intr_mask(info_p, 0);
38088 /* Make sure there is room in the command FIFO */
38089 /* Actually it should be completely empty at this time. */
38090 for (i = 200000; i > 0; i--) {
38091- temp = info_p->access.fifo_full(info_p);
38092+ temp = info_p->access->fifo_full(info_p);
38093 if (temp != 0) {
38094 break;
38095 }
38096@@ -1465,7 +1465,7 @@ DBG(
38097 /*
38098 * Send the cmd
38099 */
38100- info_p->access.submit_command(info_p, c);
38101+ info_p->access->submit_command(info_p, c);
38102 complete = pollcomplete(ctlr);
38103
38104 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
38105@@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
38106 * we check the new geometry. Then turn interrupts back on when
38107 * we're done.
38108 */
38109- host->access.set_intr_mask(host, 0);
38110+ host->access->set_intr_mask(host, 0);
38111 getgeometry(ctlr);
38112- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
38113+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
38114
38115 for(i=0; i<NWD; i++) {
38116 struct gendisk *disk = ida_gendisk[ctlr][i];
38117@@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
38118 /* Wait (up to 2 seconds) for a command to complete */
38119
38120 for (i = 200000; i > 0; i--) {
38121- done = hba[ctlr]->access.command_completed(hba[ctlr]);
38122+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
38123 if (done == 0) {
38124 udelay(10); /* a short fixed delay */
38125 } else
38126diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
38127index be73e9d..7fbf140 100644
38128--- a/drivers/block/cpqarray.h
38129+++ b/drivers/block/cpqarray.h
38130@@ -99,7 +99,7 @@ struct ctlr_info {
38131 drv_info_t drv[NWD];
38132 struct proc_dir_entry *proc;
38133
38134- struct access_method access;
38135+ struct access_method *access;
38136
38137 cmdlist_t *reqQ;
38138 cmdlist_t *cmpQ;
38139diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
38140index 0e06f0c..c47b81d 100644
38141--- a/drivers/block/drbd/drbd_int.h
38142+++ b/drivers/block/drbd/drbd_int.h
38143@@ -582,7 +582,7 @@ struct drbd_epoch {
38144 struct drbd_tconn *tconn;
38145 struct list_head list;
38146 unsigned int barrier_nr;
38147- atomic_t epoch_size; /* increased on every request added. */
38148+ atomic_unchecked_t epoch_size; /* increased on every request added. */
38149 atomic_t active; /* increased on every req. added, and dec on every finished. */
38150 unsigned long flags;
38151 };
38152@@ -1022,7 +1022,7 @@ struct drbd_conf {
38153 unsigned int al_tr_number;
38154 int al_tr_cycle;
38155 wait_queue_head_t seq_wait;
38156- atomic_t packet_seq;
38157+ atomic_unchecked_t packet_seq;
38158 unsigned int peer_seq;
38159 spinlock_t peer_seq_lock;
38160 unsigned int minor;
38161@@ -1573,7 +1573,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
38162 char __user *uoptval;
38163 int err;
38164
38165- uoptval = (char __user __force *)optval;
38166+ uoptval = (char __force_user *)optval;
38167
38168 set_fs(KERNEL_DS);
38169 if (level == SOL_SOCKET)
38170diff --git a/drivers/block/drbd/drbd_interval.c b/drivers/block/drbd/drbd_interval.c
38171index 89c497c..9c736ae 100644
38172--- a/drivers/block/drbd/drbd_interval.c
38173+++ b/drivers/block/drbd/drbd_interval.c
38174@@ -67,9 +67,9 @@ static void augment_rotate(struct rb_node *rb_old, struct rb_node *rb_new)
38175 }
38176
38177 static const struct rb_augment_callbacks augment_callbacks = {
38178- augment_propagate,
38179- augment_copy,
38180- augment_rotate,
38181+ .propagate = augment_propagate,
38182+ .copy = augment_copy,
38183+ .rotate = augment_rotate,
38184 };
38185
38186 /**
38187diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
38188index 929468e..7d934eb 100644
38189--- a/drivers/block/drbd/drbd_main.c
38190+++ b/drivers/block/drbd/drbd_main.c
38191@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
38192 p->sector = sector;
38193 p->block_id = block_id;
38194 p->blksize = blksize;
38195- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
38196+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
38197 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
38198 }
38199
38200@@ -1622,7 +1622,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
38201 return -EIO;
38202 p->sector = cpu_to_be64(req->i.sector);
38203 p->block_id = (unsigned long)req;
38204- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
38205+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
38206 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
38207 if (mdev->state.conn >= C_SYNC_SOURCE &&
38208 mdev->state.conn <= C_PAUSED_SYNC_T)
38209@@ -2577,8 +2577,8 @@ void conn_destroy(struct kref *kref)
38210 {
38211 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
38212
38213- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
38214- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
38215+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
38216+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
38217 kfree(tconn->current_epoch);
38218
38219 idr_destroy(&tconn->volumes);
38220diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
38221index c706d50..5e1b472 100644
38222--- a/drivers/block/drbd/drbd_nl.c
38223+++ b/drivers/block/drbd/drbd_nl.c
38224@@ -3440,7 +3440,7 @@ out:
38225
38226 void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
38227 {
38228- static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
38229+ static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
38230 struct sk_buff *msg;
38231 struct drbd_genlmsghdr *d_out;
38232 unsigned seq;
38233@@ -3453,7 +3453,7 @@ void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
38234 return;
38235 }
38236
38237- seq = atomic_inc_return(&drbd_genl_seq);
38238+ seq = atomic_inc_return_unchecked(&drbd_genl_seq);
38239 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
38240 if (!msg)
38241 goto failed;
38242diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
38243index d073305..4998fea 100644
38244--- a/drivers/block/drbd/drbd_receiver.c
38245+++ b/drivers/block/drbd/drbd_receiver.c
38246@@ -834,7 +834,7 @@ int drbd_connected(struct drbd_conf *mdev)
38247 {
38248 int err;
38249
38250- atomic_set(&mdev->packet_seq, 0);
38251+ atomic_set_unchecked(&mdev->packet_seq, 0);
38252 mdev->peer_seq = 0;
38253
38254 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
38255@@ -1193,7 +1193,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
38256 do {
38257 next_epoch = NULL;
38258
38259- epoch_size = atomic_read(&epoch->epoch_size);
38260+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
38261
38262 switch (ev & ~EV_CLEANUP) {
38263 case EV_PUT:
38264@@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
38265 rv = FE_DESTROYED;
38266 } else {
38267 epoch->flags = 0;
38268- atomic_set(&epoch->epoch_size, 0);
38269+ atomic_set_unchecked(&epoch->epoch_size, 0);
38270 /* atomic_set(&epoch->active, 0); is already zero */
38271 if (rv == FE_STILL_LIVE)
38272 rv = FE_RECYCLED;
38273@@ -1451,7 +1451,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
38274 conn_wait_active_ee_empty(tconn);
38275 drbd_flush(tconn);
38276
38277- if (atomic_read(&tconn->current_epoch->epoch_size)) {
38278+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
38279 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
38280 if (epoch)
38281 break;
38282@@ -1464,11 +1464,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
38283 }
38284
38285 epoch->flags = 0;
38286- atomic_set(&epoch->epoch_size, 0);
38287+ atomic_set_unchecked(&epoch->epoch_size, 0);
38288 atomic_set(&epoch->active, 0);
38289
38290 spin_lock(&tconn->epoch_lock);
38291- if (atomic_read(&tconn->current_epoch->epoch_size)) {
38292+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
38293 list_add(&epoch->list, &tconn->current_epoch->list);
38294 tconn->current_epoch = epoch;
38295 tconn->epochs++;
38296@@ -2164,7 +2164,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
38297
38298 err = wait_for_and_update_peer_seq(mdev, peer_seq);
38299 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
38300- atomic_inc(&tconn->current_epoch->epoch_size);
38301+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
38302 err2 = drbd_drain_block(mdev, pi->size);
38303 if (!err)
38304 err = err2;
38305@@ -2198,7 +2198,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
38306
38307 spin_lock(&tconn->epoch_lock);
38308 peer_req->epoch = tconn->current_epoch;
38309- atomic_inc(&peer_req->epoch->epoch_size);
38310+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
38311 atomic_inc(&peer_req->epoch->active);
38312 spin_unlock(&tconn->epoch_lock);
38313
38314@@ -4345,7 +4345,7 @@ struct data_cmd {
38315 int expect_payload;
38316 size_t pkt_size;
38317 int (*fn)(struct drbd_tconn *, struct packet_info *);
38318-};
38319+} __do_const;
38320
38321 static struct data_cmd drbd_cmd_handler[] = {
38322 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
38323@@ -4465,7 +4465,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
38324 if (!list_empty(&tconn->current_epoch->list))
38325 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
38326 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
38327- atomic_set(&tconn->current_epoch->epoch_size, 0);
38328+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
38329 tconn->send.seen_any_write_yet = false;
38330
38331 conn_info(tconn, "Connection closed\n");
38332@@ -5221,7 +5221,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
38333 struct asender_cmd {
38334 size_t pkt_size;
38335 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
38336-};
38337+} __do_const;
38338
38339 static struct asender_cmd asender_tbl[] = {
38340 [P_PING] = { 0, got_Ping },
38341diff --git a/drivers/block/loop.c b/drivers/block/loop.c
38342index 66e8c3b..9b68dd9 100644
38343--- a/drivers/block/loop.c
38344+++ b/drivers/block/loop.c
38345@@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
38346
38347 file_start_write(file);
38348 set_fs(get_ds());
38349- bw = file->f_op->write(file, buf, len, &pos);
38350+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
38351 set_fs(old_fs);
38352 file_end_write(file);
38353 if (likely(bw == len))
38354diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c
38355index 091b9ea..f5428f8 100644
38356--- a/drivers/block/null_blk.c
38357+++ b/drivers/block/null_blk.c
38358@@ -382,15 +382,25 @@ static int null_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
38359 return 0;
38360 }
38361
38362-static struct blk_mq_ops null_mq_ops = {
38363- .queue_rq = null_queue_rq,
38364- .map_queue = blk_mq_map_queue,
38365+static struct blk_mq_ops null_mq_single_ops = {
38366+ .queue_rq = null_queue_rq,
38367+ .map_queue = blk_mq_map_queue,
38368 .init_hctx = null_init_hctx,
38369 .complete = null_softirq_done_fn,
38370+ .alloc_hctx = blk_mq_alloc_single_hw_queue,
38371+ .free_hctx = blk_mq_free_single_hw_queue,
38372+};
38373+
38374+static struct blk_mq_ops null_mq_per_node_ops = {
38375+ .queue_rq = null_queue_rq,
38376+ .map_queue = blk_mq_map_queue,
38377+ .init_hctx = null_init_hctx,
38378+ .alloc_hctx = null_alloc_hctx,
38379+ .free_hctx = null_free_hctx,
38380 };
38381
38382 static struct blk_mq_reg null_mq_reg = {
38383- .ops = &null_mq_ops,
38384+ .ops = &null_mq_single_ops,
38385 .queue_depth = 64,
38386 .cmd_size = sizeof(struct nullb_cmd),
38387 .flags = BLK_MQ_F_SHOULD_MERGE,
38388@@ -521,13 +531,8 @@ static int null_add_dev(void)
38389 null_mq_reg.queue_depth = hw_queue_depth;
38390 null_mq_reg.nr_hw_queues = submit_queues;
38391
38392- if (use_per_node_hctx) {
38393- null_mq_reg.ops->alloc_hctx = null_alloc_hctx;
38394- null_mq_reg.ops->free_hctx = null_free_hctx;
38395- } else {
38396- null_mq_reg.ops->alloc_hctx = blk_mq_alloc_single_hw_queue;
38397- null_mq_reg.ops->free_hctx = blk_mq_free_single_hw_queue;
38398- }
38399+ if (use_per_node_hctx)
38400+ null_mq_reg.ops = &null_mq_per_node_ops;
38401
38402 nullb->q = blk_mq_init_queue(&null_mq_reg, nullb);
38403 } else if (queue_mode == NULL_Q_BIO) {
38404diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
38405index a2af73d..c0b8f61 100644
38406--- a/drivers/block/pktcdvd.c
38407+++ b/drivers/block/pktcdvd.c
38408@@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
38409
38410 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
38411 {
38412- return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
38413+ return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
38414 }
38415
38416 /*
38417@@ -1888,7 +1888,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
38418 return -EROFS;
38419 }
38420 pd->settings.fp = ti.fp;
38421- pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
38422+ pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
38423
38424 if (ti.nwa_v) {
38425 pd->nwa = be32_to_cpu(ti.next_writable);
38426diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
38427index e5565fb..71be10b4 100644
38428--- a/drivers/block/smart1,2.h
38429+++ b/drivers/block/smart1,2.h
38430@@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
38431 }
38432
38433 static struct access_method smart4_access = {
38434- smart4_submit_command,
38435- smart4_intr_mask,
38436- smart4_fifo_full,
38437- smart4_intr_pending,
38438- smart4_completed,
38439+ .submit_command = smart4_submit_command,
38440+ .set_intr_mask = smart4_intr_mask,
38441+ .fifo_full = smart4_fifo_full,
38442+ .intr_pending = smart4_intr_pending,
38443+ .command_completed = smart4_completed,
38444 };
38445
38446 /*
38447@@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
38448 }
38449
38450 static struct access_method smart2_access = {
38451- smart2_submit_command,
38452- smart2_intr_mask,
38453- smart2_fifo_full,
38454- smart2_intr_pending,
38455- smart2_completed,
38456+ .submit_command = smart2_submit_command,
38457+ .set_intr_mask = smart2_intr_mask,
38458+ .fifo_full = smart2_fifo_full,
38459+ .intr_pending = smart2_intr_pending,
38460+ .command_completed = smart2_completed,
38461 };
38462
38463 /*
38464@@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
38465 }
38466
38467 static struct access_method smart2e_access = {
38468- smart2e_submit_command,
38469- smart2e_intr_mask,
38470- smart2e_fifo_full,
38471- smart2e_intr_pending,
38472- smart2e_completed,
38473+ .submit_command = smart2e_submit_command,
38474+ .set_intr_mask = smart2e_intr_mask,
38475+ .fifo_full = smart2e_fifo_full,
38476+ .intr_pending = smart2e_intr_pending,
38477+ .command_completed = smart2e_completed,
38478 };
38479
38480 /*
38481@@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
38482 }
38483
38484 static struct access_method smart1_access = {
38485- smart1_submit_command,
38486- smart1_intr_mask,
38487- smart1_fifo_full,
38488- smart1_intr_pending,
38489- smart1_completed,
38490+ .submit_command = smart1_submit_command,
38491+ .set_intr_mask = smart1_intr_mask,
38492+ .fifo_full = smart1_fifo_full,
38493+ .intr_pending = smart1_intr_pending,
38494+ .command_completed = smart1_completed,
38495 };
38496diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
38497index f038dba..bb74c08 100644
38498--- a/drivers/bluetooth/btwilink.c
38499+++ b/drivers/bluetooth/btwilink.c
38500@@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
38501
38502 static int bt_ti_probe(struct platform_device *pdev)
38503 {
38504- static struct ti_st *hst;
38505+ struct ti_st *hst;
38506 struct hci_dev *hdev;
38507 int err;
38508
38509diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
38510index 8a3aff7..d7538c2 100644
38511--- a/drivers/cdrom/cdrom.c
38512+++ b/drivers/cdrom/cdrom.c
38513@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
38514 ENSURE(reset, CDC_RESET);
38515 ENSURE(generic_packet, CDC_GENERIC_PACKET);
38516 cdi->mc_flags = 0;
38517- cdo->n_minors = 0;
38518 cdi->options = CDO_USE_FFLAGS;
38519
38520 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
38521@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
38522 else
38523 cdi->cdda_method = CDDA_OLD;
38524
38525- if (!cdo->generic_packet)
38526- cdo->generic_packet = cdrom_dummy_generic_packet;
38527+ if (!cdo->generic_packet) {
38528+ pax_open_kernel();
38529+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
38530+ pax_close_kernel();
38531+ }
38532
38533 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
38534 mutex_lock(&cdrom_mutex);
38535@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
38536 if (cdi->exit)
38537 cdi->exit(cdi);
38538
38539- cdi->ops->n_minors--;
38540 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
38541 }
38542
38543@@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
38544 */
38545 nr = nframes;
38546 do {
38547- cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38548+ cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38549 if (cgc.buffer)
38550 break;
38551
38552@@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
38553 struct cdrom_device_info *cdi;
38554 int ret;
38555
38556- ret = scnprintf(info + *pos, max_size - *pos, header);
38557+ ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
38558 if (!ret)
38559 return 1;
38560
38561diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
38562index 51e75ad..39c4c76 100644
38563--- a/drivers/cdrom/gdrom.c
38564+++ b/drivers/cdrom/gdrom.c
38565@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
38566 .audio_ioctl = gdrom_audio_ioctl,
38567 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
38568 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
38569- .n_minors = 1,
38570 };
38571
38572 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
38573diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
38574index 1386749..5430258 100644
38575--- a/drivers/char/Kconfig
38576+++ b/drivers/char/Kconfig
38577@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
38578
38579 config DEVKMEM
38580 bool "/dev/kmem virtual device support"
38581- default y
38582+ default n
38583+ depends on !GRKERNSEC_KMEM
38584 help
38585 Say Y here if you want to support the /dev/kmem device. The
38586 /dev/kmem device is rarely used, but can be used for certain
38587@@ -577,6 +578,7 @@ config DEVPORT
38588 bool
38589 depends on !M68K
38590 depends on ISA || PCI
38591+ depends on !GRKERNSEC_KMEM
38592 default y
38593
38594 source "drivers/s390/char/Kconfig"
38595diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
38596index a48e05b..6bac831 100644
38597--- a/drivers/char/agp/compat_ioctl.c
38598+++ b/drivers/char/agp/compat_ioctl.c
38599@@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
38600 return -ENOMEM;
38601 }
38602
38603- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
38604+ if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
38605 sizeof(*usegment) * ureserve.seg_count)) {
38606 kfree(usegment);
38607 kfree(ksegment);
38608diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
38609index 1b19239..963967b 100644
38610--- a/drivers/char/agp/frontend.c
38611+++ b/drivers/char/agp/frontend.c
38612@@ -731,6 +731,7 @@ static int agpioc_info_wrap(struct agp_file_private *priv, void __user *arg)
38613
38614 agp_copy_info(agp_bridge, &kerninfo);
38615
38616+ memset(&userinfo, 0, sizeof(userinfo));
38617 userinfo.version.major = kerninfo.version.major;
38618 userinfo.version.minor = kerninfo.version.minor;
38619 userinfo.bridge_id = kerninfo.device->vendor |
38620@@ -819,7 +820,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38621 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
38622 return -EFAULT;
38623
38624- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
38625+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
38626 return -EFAULT;
38627
38628 client = agp_find_client_by_pid(reserve.pid);
38629@@ -849,7 +850,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38630 if (segment == NULL)
38631 return -ENOMEM;
38632
38633- if (copy_from_user(segment, (void __user *) reserve.seg_list,
38634+ if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
38635 sizeof(struct agp_segment) * reserve.seg_count)) {
38636 kfree(segment);
38637 return -EFAULT;
38638diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
38639index 4f94375..413694e 100644
38640--- a/drivers/char/genrtc.c
38641+++ b/drivers/char/genrtc.c
38642@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
38643 switch (cmd) {
38644
38645 case RTC_PLL_GET:
38646+ memset(&pll, 0, sizeof(pll));
38647 if (get_rtc_pll(&pll))
38648 return -EINVAL;
38649 else
38650diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
38651index d5d4cd8..22d561d 100644
38652--- a/drivers/char/hpet.c
38653+++ b/drivers/char/hpet.c
38654@@ -575,7 +575,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
38655 }
38656
38657 static int
38658-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
38659+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
38660 struct hpet_info *info)
38661 {
38662 struct hpet_timer __iomem *timer;
38663diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
38664index 86fe45c..c0ea948 100644
38665--- a/drivers/char/hw_random/intel-rng.c
38666+++ b/drivers/char/hw_random/intel-rng.c
38667@@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
38668
38669 if (no_fwh_detect)
38670 return -ENODEV;
38671- printk(warning);
38672+ printk("%s", warning);
38673 return -EBUSY;
38674 }
38675
38676diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
38677index ec4e10f..f2a763b 100644
38678--- a/drivers/char/ipmi/ipmi_msghandler.c
38679+++ b/drivers/char/ipmi/ipmi_msghandler.c
38680@@ -420,7 +420,7 @@ struct ipmi_smi {
38681 struct proc_dir_entry *proc_dir;
38682 char proc_dir_name[10];
38683
38684- atomic_t stats[IPMI_NUM_STATS];
38685+ atomic_unchecked_t stats[IPMI_NUM_STATS];
38686
38687 /*
38688 * run_to_completion duplicate of smb_info, smi_info
38689@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
38690
38691
38692 #define ipmi_inc_stat(intf, stat) \
38693- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
38694+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
38695 #define ipmi_get_stat(intf, stat) \
38696- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
38697+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
38698
38699 static int is_lan_addr(struct ipmi_addr *addr)
38700 {
38701@@ -2883,7 +2883,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
38702 INIT_LIST_HEAD(&intf->cmd_rcvrs);
38703 init_waitqueue_head(&intf->waitq);
38704 for (i = 0; i < IPMI_NUM_STATS; i++)
38705- atomic_set(&intf->stats[i], 0);
38706+ atomic_set_unchecked(&intf->stats[i], 0);
38707
38708 intf->proc_dir = NULL;
38709
38710diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
38711index 03f4189..e79f5e0 100644
38712--- a/drivers/char/ipmi/ipmi_si_intf.c
38713+++ b/drivers/char/ipmi/ipmi_si_intf.c
38714@@ -280,7 +280,7 @@ struct smi_info {
38715 unsigned char slave_addr;
38716
38717 /* Counters and things for the proc filesystem. */
38718- atomic_t stats[SI_NUM_STATS];
38719+ atomic_unchecked_t stats[SI_NUM_STATS];
38720
38721 struct task_struct *thread;
38722
38723@@ -289,9 +289,9 @@ struct smi_info {
38724 };
38725
38726 #define smi_inc_stat(smi, stat) \
38727- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
38728+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
38729 #define smi_get_stat(smi, stat) \
38730- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
38731+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
38732
38733 #define SI_MAX_PARMS 4
38734
38735@@ -3339,7 +3339,7 @@ static int try_smi_init(struct smi_info *new_smi)
38736 atomic_set(&new_smi->req_events, 0);
38737 new_smi->run_to_completion = 0;
38738 for (i = 0; i < SI_NUM_STATS; i++)
38739- atomic_set(&new_smi->stats[i], 0);
38740+ atomic_set_unchecked(&new_smi->stats[i], 0);
38741
38742 new_smi->interrupt_disabled = 1;
38743 atomic_set(&new_smi->stop_operation, 0);
38744diff --git a/drivers/char/mem.c b/drivers/char/mem.c
38745index 92c5937..1be4e4d 100644
38746--- a/drivers/char/mem.c
38747+++ b/drivers/char/mem.c
38748@@ -18,6 +18,7 @@
38749 #include <linux/raw.h>
38750 #include <linux/tty.h>
38751 #include <linux/capability.h>
38752+#include <linux/security.h>
38753 #include <linux/ptrace.h>
38754 #include <linux/device.h>
38755 #include <linux/highmem.h>
38756@@ -36,6 +37,10 @@
38757
38758 #define DEVPORT_MINOR 4
38759
38760+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38761+extern const struct file_operations grsec_fops;
38762+#endif
38763+
38764 static inline unsigned long size_inside_page(unsigned long start,
38765 unsigned long size)
38766 {
38767@@ -67,9 +72,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38768
38769 while (cursor < to) {
38770 if (!devmem_is_allowed(pfn)) {
38771+#ifdef CONFIG_GRKERNSEC_KMEM
38772+ gr_handle_mem_readwrite(from, to);
38773+#else
38774 printk(KERN_INFO
38775 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
38776 current->comm, from, to);
38777+#endif
38778 return 0;
38779 }
38780 cursor += PAGE_SIZE;
38781@@ -77,6 +86,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38782 }
38783 return 1;
38784 }
38785+#elif defined(CONFIG_GRKERNSEC_KMEM)
38786+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38787+{
38788+ return 0;
38789+}
38790 #else
38791 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38792 {
38793@@ -119,6 +133,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38794
38795 while (count > 0) {
38796 unsigned long remaining;
38797+ char *temp;
38798
38799 sz = size_inside_page(p, count);
38800
38801@@ -134,7 +149,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38802 if (!ptr)
38803 return -EFAULT;
38804
38805- remaining = copy_to_user(buf, ptr, sz);
38806+#ifdef CONFIG_PAX_USERCOPY
38807+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38808+ if (!temp) {
38809+ unxlate_dev_mem_ptr(p, ptr);
38810+ return -ENOMEM;
38811+ }
38812+ memcpy(temp, ptr, sz);
38813+#else
38814+ temp = ptr;
38815+#endif
38816+
38817+ remaining = copy_to_user(buf, temp, sz);
38818+
38819+#ifdef CONFIG_PAX_USERCOPY
38820+ kfree(temp);
38821+#endif
38822+
38823 unxlate_dev_mem_ptr(p, ptr);
38824 if (remaining)
38825 return -EFAULT;
38826@@ -363,9 +394,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38827 size_t count, loff_t *ppos)
38828 {
38829 unsigned long p = *ppos;
38830- ssize_t low_count, read, sz;
38831+ ssize_t low_count, read, sz, err = 0;
38832 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
38833- int err = 0;
38834
38835 read = 0;
38836 if (p < (unsigned long) high_memory) {
38837@@ -387,6 +417,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38838 }
38839 #endif
38840 while (low_count > 0) {
38841+ char *temp;
38842+
38843 sz = size_inside_page(p, low_count);
38844
38845 /*
38846@@ -396,7 +428,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38847 */
38848 kbuf = xlate_dev_kmem_ptr((char *)p);
38849
38850- if (copy_to_user(buf, kbuf, sz))
38851+#ifdef CONFIG_PAX_USERCOPY
38852+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38853+ if (!temp)
38854+ return -ENOMEM;
38855+ memcpy(temp, kbuf, sz);
38856+#else
38857+ temp = kbuf;
38858+#endif
38859+
38860+ err = copy_to_user(buf, temp, sz);
38861+
38862+#ifdef CONFIG_PAX_USERCOPY
38863+ kfree(temp);
38864+#endif
38865+
38866+ if (err)
38867 return -EFAULT;
38868 buf += sz;
38869 p += sz;
38870@@ -821,6 +868,9 @@ static const struct memdev {
38871 #ifdef CONFIG_PRINTK
38872 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
38873 #endif
38874+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38875+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
38876+#endif
38877 };
38878
38879 static int memory_open(struct inode *inode, struct file *filp)
38880@@ -892,7 +942,7 @@ static int __init chr_dev_init(void)
38881 continue;
38882
38883 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
38884- NULL, devlist[minor].name);
38885+ NULL, "%s", devlist[minor].name);
38886 }
38887
38888 return tty_init();
38889diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
38890index 9df78e2..01ba9ae 100644
38891--- a/drivers/char/nvram.c
38892+++ b/drivers/char/nvram.c
38893@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
38894
38895 spin_unlock_irq(&rtc_lock);
38896
38897- if (copy_to_user(buf, contents, tmp - contents))
38898+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
38899 return -EFAULT;
38900
38901 *ppos = i;
38902diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
38903index 8320abd..ec48108 100644
38904--- a/drivers/char/pcmcia/synclink_cs.c
38905+++ b/drivers/char/pcmcia/synclink_cs.c
38906@@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38907
38908 if (debug_level >= DEBUG_LEVEL_INFO)
38909 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
38910- __FILE__, __LINE__, info->device_name, port->count);
38911+ __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
38912
38913- WARN_ON(!port->count);
38914+ WARN_ON(!atomic_read(&port->count));
38915
38916 if (tty_port_close_start(port, tty, filp) == 0)
38917 goto cleanup;
38918@@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38919 cleanup:
38920 if (debug_level >= DEBUG_LEVEL_INFO)
38921 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
38922- tty->driver->name, port->count);
38923+ tty->driver->name, atomic_read(&port->count));
38924 }
38925
38926 /* Wait until the transmitter is empty.
38927@@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38928
38929 if (debug_level >= DEBUG_LEVEL_INFO)
38930 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
38931- __FILE__, __LINE__, tty->driver->name, port->count);
38932+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
38933
38934 /* If port is closing, signal caller to try again */
38935 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
38936@@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38937 goto cleanup;
38938 }
38939 spin_lock(&port->lock);
38940- port->count++;
38941+ atomic_inc(&port->count);
38942 spin_unlock(&port->lock);
38943 spin_unlock_irqrestore(&info->netlock, flags);
38944
38945- if (port->count == 1) {
38946+ if (atomic_read(&port->count) == 1) {
38947 /* 1st open on this device, init hardware */
38948 retval = startup(info, tty);
38949 if (retval < 0)
38950@@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38951 unsigned short new_crctype;
38952
38953 /* return error if TTY interface open */
38954- if (info->port.count)
38955+ if (atomic_read(&info->port.count))
38956 return -EBUSY;
38957
38958 switch (encoding)
38959@@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
38960
38961 /* arbitrate between network and tty opens */
38962 spin_lock_irqsave(&info->netlock, flags);
38963- if (info->port.count != 0 || info->netcount != 0) {
38964+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38965 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38966 spin_unlock_irqrestore(&info->netlock, flags);
38967 return -EBUSY;
38968@@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38969 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
38970
38971 /* return error if TTY interface open */
38972- if (info->port.count)
38973+ if (atomic_read(&info->port.count))
38974 return -EBUSY;
38975
38976 if (cmd != SIOCWANDEV)
38977diff --git a/drivers/char/random.c b/drivers/char/random.c
38978index 429b75b..a7f4145 100644
38979--- a/drivers/char/random.c
38980+++ b/drivers/char/random.c
38981@@ -270,10 +270,17 @@
38982 /*
38983 * Configuration information
38984 */
38985+#ifdef CONFIG_GRKERNSEC_RANDNET
38986+#define INPUT_POOL_SHIFT 14
38987+#define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
38988+#define OUTPUT_POOL_SHIFT 12
38989+#define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
38990+#else
38991 #define INPUT_POOL_SHIFT 12
38992 #define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
38993 #define OUTPUT_POOL_SHIFT 10
38994 #define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
38995+#endif
38996 #define SEC_XFER_SIZE 512
38997 #define EXTRACT_SIZE 10
38998
38999@@ -284,9 +291,6 @@
39000 /*
39001 * To allow fractional bits to be tracked, the entropy_count field is
39002 * denominated in units of 1/8th bits.
39003- *
39004- * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
39005- * credit_entropy_bits() needs to be 64 bits wide.
39006 */
39007 #define ENTROPY_SHIFT 3
39008 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
39009@@ -361,12 +365,19 @@ static struct poolinfo {
39010 #define S(x) ilog2(x)+5, (x), (x)*4, (x)*32, (x) << (ENTROPY_SHIFT+5)
39011 int tap1, tap2, tap3, tap4, tap5;
39012 } poolinfo_table[] = {
39013+#ifdef CONFIG_GRKERNSEC_RANDNET
39014+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
39015+ { S(512), 411, 308, 208, 104, 1 },
39016+ /* x^128 + x^104 + x^76 + x^51 + x^25 + x + 1 -- 105 */
39017+ { S(128), 104, 76, 51, 25, 1 },
39018+#else
39019 /* was: x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 */
39020 /* x^128 + x^104 + x^76 + x^51 +x^25 + x + 1 */
39021 { S(128), 104, 76, 51, 25, 1 },
39022 /* was: x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 */
39023 /* x^32 + x^26 + x^19 + x^14 + x^7 + x + 1 */
39024 { S(32), 26, 19, 14, 7, 1 },
39025+#endif
39026 #if 0
39027 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
39028 { S(2048), 1638, 1231, 819, 411, 1 },
39029@@ -433,9 +444,9 @@ struct entropy_store {
39030 };
39031
39032 static void push_to_pool(struct work_struct *work);
39033-static __u32 input_pool_data[INPUT_POOL_WORDS];
39034-static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
39035-static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
39036+static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
39037+static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
39038+static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
39039
39040 static struct entropy_store input_pool = {
39041 .poolinfo = &poolinfo_table[0],
39042@@ -524,8 +535,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
39043 input_rotate = (input_rotate + (i ? 7 : 14)) & 31;
39044 }
39045
39046- ACCESS_ONCE(r->input_rotate) = input_rotate;
39047- ACCESS_ONCE(r->add_ptr) = i;
39048+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
39049+ ACCESS_ONCE_RW(r->add_ptr) = i;
39050 smp_wmb();
39051
39052 if (out)
39053@@ -632,7 +643,7 @@ retry:
39054 /* The +2 corresponds to the /4 in the denominator */
39055
39056 do {
39057- unsigned int anfrac = min(pnfrac, pool_size/2);
39058+ u64 anfrac = min(pnfrac, pool_size/2);
39059 unsigned int add =
39060 ((pool_size - entropy_count)*anfrac*3) >> s;
39061
39062@@ -1151,7 +1162,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
39063
39064 extract_buf(r, tmp);
39065 i = min_t(int, nbytes, EXTRACT_SIZE);
39066- if (copy_to_user(buf, tmp, i)) {
39067+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
39068 ret = -EFAULT;
39069 break;
39070 }
39071@@ -1507,7 +1518,7 @@ EXPORT_SYMBOL(generate_random_uuid);
39072 #include <linux/sysctl.h>
39073
39074 static int min_read_thresh = 8, min_write_thresh;
39075-static int max_read_thresh = INPUT_POOL_WORDS * 32;
39076+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
39077 static int max_write_thresh = INPUT_POOL_WORDS * 32;
39078 static char sysctl_bootid[16];
39079
39080@@ -1523,7 +1534,7 @@ static char sysctl_bootid[16];
39081 static int proc_do_uuid(struct ctl_table *table, int write,
39082 void __user *buffer, size_t *lenp, loff_t *ppos)
39083 {
39084- struct ctl_table fake_table;
39085+ ctl_table_no_const fake_table;
39086 unsigned char buf[64], tmp_uuid[16], *uuid;
39087
39088 uuid = table->data;
39089@@ -1553,7 +1564,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
39090 static int proc_do_entropy(ctl_table *table, int write,
39091 void __user *buffer, size_t *lenp, loff_t *ppos)
39092 {
39093- ctl_table fake_table;
39094+ ctl_table_no_const fake_table;
39095 int entropy_count;
39096
39097 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
39098diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
39099index 7cc1fe22..b602d6b 100644
39100--- a/drivers/char/sonypi.c
39101+++ b/drivers/char/sonypi.c
39102@@ -54,6 +54,7 @@
39103
39104 #include <asm/uaccess.h>
39105 #include <asm/io.h>
39106+#include <asm/local.h>
39107
39108 #include <linux/sonypi.h>
39109
39110@@ -490,7 +491,7 @@ static struct sonypi_device {
39111 spinlock_t fifo_lock;
39112 wait_queue_head_t fifo_proc_list;
39113 struct fasync_struct *fifo_async;
39114- int open_count;
39115+ local_t open_count;
39116 int model;
39117 struct input_dev *input_jog_dev;
39118 struct input_dev *input_key_dev;
39119@@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
39120 static int sonypi_misc_release(struct inode *inode, struct file *file)
39121 {
39122 mutex_lock(&sonypi_device.lock);
39123- sonypi_device.open_count--;
39124+ local_dec(&sonypi_device.open_count);
39125 mutex_unlock(&sonypi_device.lock);
39126 return 0;
39127 }
39128@@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
39129 {
39130 mutex_lock(&sonypi_device.lock);
39131 /* Flush input queue on first open */
39132- if (!sonypi_device.open_count)
39133+ if (!local_read(&sonypi_device.open_count))
39134 kfifo_reset(&sonypi_device.fifo);
39135- sonypi_device.open_count++;
39136+ local_inc(&sonypi_device.open_count);
39137 mutex_unlock(&sonypi_device.lock);
39138
39139 return 0;
39140diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
39141index b9a57fa..5bb9e38 100644
39142--- a/drivers/char/tpm/tpm_acpi.c
39143+++ b/drivers/char/tpm/tpm_acpi.c
39144@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
39145 virt = acpi_os_map_memory(start, len);
39146 if (!virt) {
39147 kfree(log->bios_event_log);
39148+ log->bios_event_log = NULL;
39149 printk("%s: ERROR - Unable to map memory\n", __func__);
39150 return -EIO;
39151 }
39152
39153- memcpy_fromio(log->bios_event_log, virt, len);
39154+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
39155
39156 acpi_os_unmap_memory(virt, len);
39157 return 0;
39158diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
39159index 59f7cb2..bac8b6d 100644
39160--- a/drivers/char/tpm/tpm_eventlog.c
39161+++ b/drivers/char/tpm/tpm_eventlog.c
39162@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
39163 event = addr;
39164
39165 if ((event->event_type == 0 && event->event_size == 0) ||
39166- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
39167+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
39168 return NULL;
39169
39170 return addr;
39171@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
39172 return NULL;
39173
39174 if ((event->event_type == 0 && event->event_size == 0) ||
39175- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
39176+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
39177 return NULL;
39178
39179 (*pos)++;
39180@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
39181 int i;
39182
39183 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
39184- seq_putc(m, data[i]);
39185+ if (!seq_putc(m, data[i]))
39186+ return -EFAULT;
39187
39188 return 0;
39189 }
39190diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
39191index 6928d09..ff6abe8 100644
39192--- a/drivers/char/virtio_console.c
39193+++ b/drivers/char/virtio_console.c
39194@@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
39195 if (to_user) {
39196 ssize_t ret;
39197
39198- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
39199+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
39200 if (ret)
39201 return -EFAULT;
39202 } else {
39203@@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
39204 if (!port_has_data(port) && !port->host_connected)
39205 return 0;
39206
39207- return fill_readbuf(port, ubuf, count, true);
39208+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
39209 }
39210
39211 static int wait_port_writable(struct port *port, bool nonblock)
39212diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
39213index 57a078e..c17cde8 100644
39214--- a/drivers/clk/clk-composite.c
39215+++ b/drivers/clk/clk-composite.c
39216@@ -146,7 +146,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
39217 struct clk *clk;
39218 struct clk_init_data init;
39219 struct clk_composite *composite;
39220- struct clk_ops *clk_composite_ops;
39221+ clk_ops_no_const *clk_composite_ops;
39222
39223 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
39224 if (!composite) {
39225diff --git a/drivers/clk/socfpga/clk.c b/drivers/clk/socfpga/clk.c
39226index 5983a26..65d5f46 100644
39227--- a/drivers/clk/socfpga/clk.c
39228+++ b/drivers/clk/socfpga/clk.c
39229@@ -22,6 +22,7 @@
39230 #include <linux/clk-provider.h>
39231 #include <linux/io.h>
39232 #include <linux/of.h>
39233+#include <asm/pgtable.h>
39234
39235 /* Clock Manager offsets */
39236 #define CLKMGR_CTRL 0x0
39237@@ -150,8 +151,10 @@ static __init struct clk *socfpga_clk_init(struct device_node *node,
39238 streq(clk_name, "periph_pll") ||
39239 streq(clk_name, "sdram_pll")) {
39240 socfpga_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
39241- clk_pll_ops.enable = clk_gate_ops.enable;
39242- clk_pll_ops.disable = clk_gate_ops.disable;
39243+ pax_open_kernel();
39244+ *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
39245+ *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
39246+ pax_close_kernel();
39247 }
39248
39249 clk = clk_register(NULL, &socfpga_clk->hw.hw);
39250@@ -242,7 +245,7 @@ static unsigned long socfpga_clk_recalc_rate(struct clk_hw *hwclk,
39251 return parent_rate / div;
39252 }
39253
39254-static struct clk_ops gateclk_ops = {
39255+static clk_ops_no_const gateclk_ops __read_only = {
39256 .recalc_rate = socfpga_clk_recalc_rate,
39257 .get_parent = socfpga_clk_get_parent,
39258 .set_parent = socfpga_clk_set_parent,
39259diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
39260index 18448a7..d5fad43 100644
39261--- a/drivers/cpufreq/acpi-cpufreq.c
39262+++ b/drivers/cpufreq/acpi-cpufreq.c
39263@@ -676,8 +676,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
39264 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
39265 per_cpu(acfreq_data, cpu) = data;
39266
39267- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
39268- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
39269+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
39270+ pax_open_kernel();
39271+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
39272+ pax_close_kernel();
39273+ }
39274
39275 result = acpi_processor_register_performance(data->acpi_data, cpu);
39276 if (result)
39277@@ -810,7 +813,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
39278 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
39279 break;
39280 case ACPI_ADR_SPACE_FIXED_HARDWARE:
39281- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
39282+ pax_open_kernel();
39283+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
39284+ pax_close_kernel();
39285 break;
39286 default:
39287 break;
39288@@ -905,8 +910,10 @@ static void __init acpi_cpufreq_boost_init(void)
39289 if (!msrs)
39290 return;
39291
39292- acpi_cpufreq_driver.boost_supported = true;
39293- acpi_cpufreq_driver.boost_enabled = boost_state(0);
39294+ pax_open_kernel();
39295+ *(bool *)&acpi_cpufreq_driver.boost_supported = true;
39296+ *(bool *)&acpi_cpufreq_driver.boost_enabled = boost_state(0);
39297+ pax_close_kernel();
39298 get_online_cpus();
39299
39300 /* Force all MSRs to the same value */
39301diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
39302index 199b52b..e3503bb 100644
39303--- a/drivers/cpufreq/cpufreq.c
39304+++ b/drivers/cpufreq/cpufreq.c
39305@@ -1970,7 +1970,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
39306 #endif
39307
39308 mutex_lock(&cpufreq_governor_mutex);
39309- list_del(&governor->governor_list);
39310+ pax_list_del(&governor->governor_list);
39311 mutex_unlock(&cpufreq_governor_mutex);
39312 return;
39313 }
39314@@ -2200,7 +2200,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
39315 return NOTIFY_OK;
39316 }
39317
39318-static struct notifier_block __refdata cpufreq_cpu_notifier = {
39319+static struct notifier_block cpufreq_cpu_notifier = {
39320 .notifier_call = cpufreq_cpu_callback,
39321 };
39322
39323@@ -2240,13 +2240,17 @@ int cpufreq_boost_trigger_state(int state)
39324 return 0;
39325
39326 write_lock_irqsave(&cpufreq_driver_lock, flags);
39327- cpufreq_driver->boost_enabled = state;
39328+ pax_open_kernel();
39329+ *(bool *)&cpufreq_driver->boost_enabled = state;
39330+ pax_close_kernel();
39331 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39332
39333 ret = cpufreq_driver->set_boost(state);
39334 if (ret) {
39335 write_lock_irqsave(&cpufreq_driver_lock, flags);
39336- cpufreq_driver->boost_enabled = !state;
39337+ pax_open_kernel();
39338+ *(bool *)&cpufreq_driver->boost_enabled = !state;
39339+ pax_close_kernel();
39340 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39341
39342 pr_err("%s: Cannot %s BOOST\n", __func__,
39343@@ -2300,8 +2304,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39344
39345 pr_debug("trying to register driver %s\n", driver_data->name);
39346
39347- if (driver_data->setpolicy)
39348- driver_data->flags |= CPUFREQ_CONST_LOOPS;
39349+ if (driver_data->setpolicy) {
39350+ pax_open_kernel();
39351+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
39352+ pax_close_kernel();
39353+ }
39354
39355 write_lock_irqsave(&cpufreq_driver_lock, flags);
39356 if (cpufreq_driver) {
39357@@ -2316,8 +2323,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39358 * Check if driver provides function to enable boost -
39359 * if not, use cpufreq_boost_set_sw as default
39360 */
39361- if (!cpufreq_driver->set_boost)
39362- cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39363+ if (!cpufreq_driver->set_boost) {
39364+ pax_open_kernel();
39365+ *(void **)&cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39366+ pax_close_kernel();
39367+ }
39368
39369 ret = cpufreq_sysfs_create_file(&boost.attr);
39370 if (ret) {
39371diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
39372index ba43991..23858ffb 100644
39373--- a/drivers/cpufreq/cpufreq_governor.c
39374+++ b/drivers/cpufreq/cpufreq_governor.c
39375@@ -191,7 +191,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39376 struct dbs_data *dbs_data;
39377 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
39378 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
39379- struct od_ops *od_ops = NULL;
39380+ const struct od_ops *od_ops = NULL;
39381 struct od_dbs_tuners *od_tuners = NULL;
39382 struct cs_dbs_tuners *cs_tuners = NULL;
39383 struct cpu_dbs_common_info *cpu_cdbs;
39384@@ -257,7 +257,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39385
39386 if ((cdata->governor == GOV_CONSERVATIVE) &&
39387 (!policy->governor->initialized)) {
39388- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39389+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39390
39391 cpufreq_register_notifier(cs_ops->notifier_block,
39392 CPUFREQ_TRANSITION_NOTIFIER);
39393@@ -277,7 +277,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39394
39395 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
39396 (policy->governor->initialized == 1)) {
39397- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39398+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39399
39400 cpufreq_unregister_notifier(cs_ops->notifier_block,
39401 CPUFREQ_TRANSITION_NOTIFIER);
39402diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
39403index bfb9ae1..e1d3a7e 100644
39404--- a/drivers/cpufreq/cpufreq_governor.h
39405+++ b/drivers/cpufreq/cpufreq_governor.h
39406@@ -205,7 +205,7 @@ struct common_dbs_data {
39407 void (*exit)(struct dbs_data *dbs_data);
39408
39409 /* Governor specific ops, see below */
39410- void *gov_ops;
39411+ const void *gov_ops;
39412 };
39413
39414 /* Governor Per policy data */
39415@@ -225,7 +225,7 @@ struct od_ops {
39416 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
39417 unsigned int freq_next, unsigned int relation);
39418 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
39419-};
39420+} __no_const;
39421
39422 struct cs_ops {
39423 struct notifier_block *notifier_block;
39424diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
39425index 18d4091..434be15 100644
39426--- a/drivers/cpufreq/cpufreq_ondemand.c
39427+++ b/drivers/cpufreq/cpufreq_ondemand.c
39428@@ -521,7 +521,7 @@ static void od_exit(struct dbs_data *dbs_data)
39429
39430 define_get_cpu_dbs_routines(od_cpu_dbs_info);
39431
39432-static struct od_ops od_ops = {
39433+static struct od_ops od_ops __read_only = {
39434 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
39435 .powersave_bias_target = generic_powersave_bias_target,
39436 .freq_increase = dbs_freq_increase,
39437@@ -576,14 +576,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
39438 (struct cpufreq_policy *, unsigned int, unsigned int),
39439 unsigned int powersave_bias)
39440 {
39441- od_ops.powersave_bias_target = f;
39442+ pax_open_kernel();
39443+ *(void **)&od_ops.powersave_bias_target = f;
39444+ pax_close_kernel();
39445 od_set_powersave_bias(powersave_bias);
39446 }
39447 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
39448
39449 void od_unregister_powersave_bias_handler(void)
39450 {
39451- od_ops.powersave_bias_target = generic_powersave_bias_target;
39452+ pax_open_kernel();
39453+ *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
39454+ pax_close_kernel();
39455 od_set_powersave_bias(0);
39456 }
39457 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
39458diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
39459index 2cd36b9..8f07fae 100644
39460--- a/drivers/cpufreq/intel_pstate.c
39461+++ b/drivers/cpufreq/intel_pstate.c
39462@@ -124,10 +124,10 @@ struct pstate_funcs {
39463 struct cpu_defaults {
39464 struct pstate_adjust_policy pid_policy;
39465 struct pstate_funcs funcs;
39466-};
39467+} __do_const;
39468
39469 static struct pstate_adjust_policy pid_params;
39470-static struct pstate_funcs pstate_funcs;
39471+static struct pstate_funcs *pstate_funcs;
39472
39473 struct perf_limits {
39474 int no_turbo;
39475@@ -518,7 +518,7 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
39476
39477 cpu->pstate.current_pstate = pstate;
39478
39479- pstate_funcs.set(cpu, pstate);
39480+ pstate_funcs->set(cpu, pstate);
39481 }
39482
39483 static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps)
39484@@ -540,12 +540,12 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
39485 {
39486 sprintf(cpu->name, "Intel 2nd generation core");
39487
39488- cpu->pstate.min_pstate = pstate_funcs.get_min();
39489- cpu->pstate.max_pstate = pstate_funcs.get_max();
39490- cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
39491+ cpu->pstate.min_pstate = pstate_funcs->get_min();
39492+ cpu->pstate.max_pstate = pstate_funcs->get_max();
39493+ cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
39494
39495- if (pstate_funcs.get_vid)
39496- pstate_funcs.get_vid(cpu);
39497+ if (pstate_funcs->get_vid)
39498+ pstate_funcs->get_vid(cpu);
39499
39500 /*
39501 * goto max pstate so we don't slow up boot if we are built-in if we are
39502@@ -832,9 +832,9 @@ static int intel_pstate_msrs_not_valid(void)
39503 rdmsrl(MSR_IA32_APERF, aperf);
39504 rdmsrl(MSR_IA32_MPERF, mperf);
39505
39506- if (!pstate_funcs.get_max() ||
39507- !pstate_funcs.get_min() ||
39508- !pstate_funcs.get_turbo())
39509+ if (!pstate_funcs->get_max() ||
39510+ !pstate_funcs->get_min() ||
39511+ !pstate_funcs->get_turbo())
39512 return -ENODEV;
39513
39514 rdmsrl(MSR_IA32_APERF, tmp);
39515@@ -848,7 +848,7 @@ static int intel_pstate_msrs_not_valid(void)
39516 return 0;
39517 }
39518
39519-static void copy_pid_params(struct pstate_adjust_policy *policy)
39520+static void copy_pid_params(const struct pstate_adjust_policy *policy)
39521 {
39522 pid_params.sample_rate_ms = policy->sample_rate_ms;
39523 pid_params.p_gain_pct = policy->p_gain_pct;
39524@@ -860,11 +860,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
39525
39526 static void copy_cpu_funcs(struct pstate_funcs *funcs)
39527 {
39528- pstate_funcs.get_max = funcs->get_max;
39529- pstate_funcs.get_min = funcs->get_min;
39530- pstate_funcs.get_turbo = funcs->get_turbo;
39531- pstate_funcs.set = funcs->set;
39532- pstate_funcs.get_vid = funcs->get_vid;
39533+ pstate_funcs = funcs;
39534 }
39535
39536 #if IS_ENABLED(CONFIG_ACPI)
39537diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
39538index 3d1cba9..0ab21d2 100644
39539--- a/drivers/cpufreq/p4-clockmod.c
39540+++ b/drivers/cpufreq/p4-clockmod.c
39541@@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39542 case 0x0F: /* Core Duo */
39543 case 0x16: /* Celeron Core */
39544 case 0x1C: /* Atom */
39545- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39546+ pax_open_kernel();
39547+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39548+ pax_close_kernel();
39549 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
39550 case 0x0D: /* Pentium M (Dothan) */
39551- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39552+ pax_open_kernel();
39553+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39554+ pax_close_kernel();
39555 /* fall through */
39556 case 0x09: /* Pentium M (Banias) */
39557 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
39558@@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39559
39560 /* on P-4s, the TSC runs with constant frequency independent whether
39561 * throttling is active or not. */
39562- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39563+ pax_open_kernel();
39564+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39565+ pax_close_kernel();
39566
39567 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
39568 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
39569diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
39570index 724ffbd..f06aaaa 100644
39571--- a/drivers/cpufreq/sparc-us3-cpufreq.c
39572+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
39573@@ -18,14 +18,12 @@
39574 #include <asm/head.h>
39575 #include <asm/timer.h>
39576
39577-static struct cpufreq_driver *cpufreq_us3_driver;
39578-
39579 struct us3_freq_percpu_info {
39580 struct cpufreq_frequency_table table[4];
39581 };
39582
39583 /* Indexed by cpu number. */
39584-static struct us3_freq_percpu_info *us3_freq_table;
39585+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
39586
39587 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
39588 * in the Safari config register.
39589@@ -156,18 +154,28 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
39590
39591 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
39592 {
39593- if (cpufreq_us3_driver) {
39594- cpufreq_frequency_table_put_attr(policy->cpu);
39595- us3_freq_target(policy, 0);
39596- }
39597+ cpufreq_frequency_table_put_attr(policy->cpu);
39598+ us3_freq_target(policy, 0);
39599
39600 return 0;
39601 }
39602
39603+static int __init us3_freq_init(void);
39604+static void __exit us3_freq_exit(void);
39605+
39606+static struct cpufreq_driver cpufreq_us3_driver = {
39607+ .init = us3_freq_cpu_init,
39608+ .verify = cpufreq_generic_frequency_table_verify,
39609+ .target_index = us3_freq_target,
39610+ .get = us3_freq_get,
39611+ .exit = us3_freq_cpu_exit,
39612+ .name = "UltraSPARC-III",
39613+
39614+};
39615+
39616 static int __init us3_freq_init(void)
39617 {
39618 unsigned long manuf, impl, ver;
39619- int ret;
39620
39621 if (tlb_type != cheetah && tlb_type != cheetah_plus)
39622 return -ENODEV;
39623@@ -180,55 +188,15 @@ static int __init us3_freq_init(void)
39624 (impl == CHEETAH_IMPL ||
39625 impl == CHEETAH_PLUS_IMPL ||
39626 impl == JAGUAR_IMPL ||
39627- impl == PANTHER_IMPL)) {
39628- struct cpufreq_driver *driver;
39629-
39630- ret = -ENOMEM;
39631- driver = kzalloc(sizeof(*driver), GFP_KERNEL);
39632- if (!driver)
39633- goto err_out;
39634-
39635- us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
39636- GFP_KERNEL);
39637- if (!us3_freq_table)
39638- goto err_out;
39639-
39640- driver->init = us3_freq_cpu_init;
39641- driver->verify = cpufreq_generic_frequency_table_verify;
39642- driver->target_index = us3_freq_target;
39643- driver->get = us3_freq_get;
39644- driver->exit = us3_freq_cpu_exit;
39645- strcpy(driver->name, "UltraSPARC-III");
39646-
39647- cpufreq_us3_driver = driver;
39648- ret = cpufreq_register_driver(driver);
39649- if (ret)
39650- goto err_out;
39651-
39652- return 0;
39653-
39654-err_out:
39655- if (driver) {
39656- kfree(driver);
39657- cpufreq_us3_driver = NULL;
39658- }
39659- kfree(us3_freq_table);
39660- us3_freq_table = NULL;
39661- return ret;
39662- }
39663+ impl == PANTHER_IMPL))
39664+ return cpufreq_register_driver(&cpufreq_us3_driver);
39665
39666 return -ENODEV;
39667 }
39668
39669 static void __exit us3_freq_exit(void)
39670 {
39671- if (cpufreq_us3_driver) {
39672- cpufreq_unregister_driver(cpufreq_us3_driver);
39673- kfree(cpufreq_us3_driver);
39674- cpufreq_us3_driver = NULL;
39675- kfree(us3_freq_table);
39676- us3_freq_table = NULL;
39677- }
39678+ cpufreq_unregister_driver(&cpufreq_us3_driver);
39679 }
39680
39681 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
39682diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
39683index 4e1daca..e707b61 100644
39684--- a/drivers/cpufreq/speedstep-centrino.c
39685+++ b/drivers/cpufreq/speedstep-centrino.c
39686@@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
39687 !cpu_has(cpu, X86_FEATURE_EST))
39688 return -ENODEV;
39689
39690- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
39691- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39692+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
39693+ pax_open_kernel();
39694+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39695+ pax_close_kernel();
39696+ }
39697
39698 if (policy->cpu != 0)
39699 return -ENODEV;
39700diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
39701index 06dbe7c..c2c8671 100644
39702--- a/drivers/cpuidle/driver.c
39703+++ b/drivers/cpuidle/driver.c
39704@@ -202,7 +202,7 @@ static int poll_idle(struct cpuidle_device *dev,
39705
39706 static void poll_idle_init(struct cpuidle_driver *drv)
39707 {
39708- struct cpuidle_state *state = &drv->states[0];
39709+ cpuidle_state_no_const *state = &drv->states[0];
39710
39711 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
39712 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
39713diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
39714index ca89412..a7b9c49 100644
39715--- a/drivers/cpuidle/governor.c
39716+++ b/drivers/cpuidle/governor.c
39717@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
39718 mutex_lock(&cpuidle_lock);
39719 if (__cpuidle_find_governor(gov->name) == NULL) {
39720 ret = 0;
39721- list_add_tail(&gov->governor_list, &cpuidle_governors);
39722+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
39723 if (!cpuidle_curr_governor ||
39724 cpuidle_curr_governor->rating < gov->rating)
39725 cpuidle_switch_governor(gov);
39726diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
39727index e918b6d..f87ea80 100644
39728--- a/drivers/cpuidle/sysfs.c
39729+++ b/drivers/cpuidle/sysfs.c
39730@@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
39731 NULL
39732 };
39733
39734-static struct attribute_group cpuidle_attr_group = {
39735+static attribute_group_no_const cpuidle_attr_group = {
39736 .attrs = cpuidle_default_attrs,
39737 .name = "cpuidle",
39738 };
39739diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
39740index 12fea3e..1e28f47 100644
39741--- a/drivers/crypto/hifn_795x.c
39742+++ b/drivers/crypto/hifn_795x.c
39743@@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
39744 MODULE_PARM_DESC(hifn_pll_ref,
39745 "PLL reference clock (pci[freq] or ext[freq], default ext)");
39746
39747-static atomic_t hifn_dev_number;
39748+static atomic_unchecked_t hifn_dev_number;
39749
39750 #define ACRYPTO_OP_DECRYPT 0
39751 #define ACRYPTO_OP_ENCRYPT 1
39752@@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
39753 goto err_out_disable_pci_device;
39754
39755 snprintf(name, sizeof(name), "hifn%d",
39756- atomic_inc_return(&hifn_dev_number)-1);
39757+ atomic_inc_return_unchecked(&hifn_dev_number)-1);
39758
39759 err = pci_request_regions(pdev, name);
39760 if (err)
39761diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
39762index a0b2f7e..1b6f028 100644
39763--- a/drivers/devfreq/devfreq.c
39764+++ b/drivers/devfreq/devfreq.c
39765@@ -607,7 +607,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
39766 goto err_out;
39767 }
39768
39769- list_add(&governor->node, &devfreq_governor_list);
39770+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
39771
39772 list_for_each_entry(devfreq, &devfreq_list, node) {
39773 int ret = 0;
39774@@ -695,7 +695,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
39775 }
39776 }
39777
39778- list_del(&governor->node);
39779+ pax_list_del((struct list_head *)&governor->node);
39780 err_out:
39781 mutex_unlock(&devfreq_list_lock);
39782
39783diff --git a/drivers/dma/sh/shdma-base.c b/drivers/dma/sh/shdma-base.c
39784index 2e7b394..1371a64 100644
39785--- a/drivers/dma/sh/shdma-base.c
39786+++ b/drivers/dma/sh/shdma-base.c
39787@@ -267,8 +267,8 @@ static int shdma_alloc_chan_resources(struct dma_chan *chan)
39788 schan->slave_id = -EINVAL;
39789 }
39790
39791- schan->desc = kcalloc(NR_DESCS_PER_CHANNEL,
39792- sdev->desc_size, GFP_KERNEL);
39793+ schan->desc = kcalloc(sdev->desc_size,
39794+ NR_DESCS_PER_CHANNEL, GFP_KERNEL);
39795 if (!schan->desc) {
39796 ret = -ENOMEM;
39797 goto edescalloc;
39798diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
39799index 0d765c0..60b7480 100644
39800--- a/drivers/dma/sh/shdmac.c
39801+++ b/drivers/dma/sh/shdmac.c
39802@@ -511,7 +511,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
39803 return ret;
39804 }
39805
39806-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
39807+static struct notifier_block sh_dmae_nmi_notifier = {
39808 .notifier_call = sh_dmae_nmi_handler,
39809
39810 /* Run before NMI debug handler and KGDB */
39811diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
39812index 592af5f..bb1d583 100644
39813--- a/drivers/edac/edac_device.c
39814+++ b/drivers/edac/edac_device.c
39815@@ -477,9 +477,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
39816 */
39817 int edac_device_alloc_index(void)
39818 {
39819- static atomic_t device_indexes = ATOMIC_INIT(0);
39820+ static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
39821
39822- return atomic_inc_return(&device_indexes) - 1;
39823+ return atomic_inc_return_unchecked(&device_indexes) - 1;
39824 }
39825 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
39826
39827diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
39828index b335c6a..db65b44 100644
39829--- a/drivers/edac/edac_mc_sysfs.c
39830+++ b/drivers/edac/edac_mc_sysfs.c
39831@@ -152,7 +152,7 @@ static const char * const edac_caps[] = {
39832 struct dev_ch_attribute {
39833 struct device_attribute attr;
39834 int channel;
39835-};
39836+} __do_const;
39837
39838 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
39839 struct dev_ch_attribute dev_attr_legacy_##_name = \
39840@@ -1009,14 +1009,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
39841 }
39842
39843 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
39844+ pax_open_kernel();
39845 if (mci->get_sdram_scrub_rate) {
39846- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39847- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39848+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39849+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39850 }
39851 if (mci->set_sdram_scrub_rate) {
39852- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39853- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39854+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39855+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39856 }
39857+ pax_close_kernel();
39858 err = device_create_file(&mci->dev,
39859 &dev_attr_sdram_scrub_rate);
39860 if (err) {
39861diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
39862index 2cf44b4d..6dd2dc7 100644
39863--- a/drivers/edac/edac_pci.c
39864+++ b/drivers/edac/edac_pci.c
39865@@ -29,7 +29,7 @@
39866
39867 static DEFINE_MUTEX(edac_pci_ctls_mutex);
39868 static LIST_HEAD(edac_pci_list);
39869-static atomic_t pci_indexes = ATOMIC_INIT(0);
39870+static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
39871
39872 /*
39873 * edac_pci_alloc_ctl_info
39874@@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
39875 */
39876 int edac_pci_alloc_index(void)
39877 {
39878- return atomic_inc_return(&pci_indexes) - 1;
39879+ return atomic_inc_return_unchecked(&pci_indexes) - 1;
39880 }
39881 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
39882
39883diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
39884index e8658e4..22746d6 100644
39885--- a/drivers/edac/edac_pci_sysfs.c
39886+++ b/drivers/edac/edac_pci_sysfs.c
39887@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
39888 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
39889 static int edac_pci_poll_msec = 1000; /* one second workq period */
39890
39891-static atomic_t pci_parity_count = ATOMIC_INIT(0);
39892-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
39893+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
39894+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
39895
39896 static struct kobject *edac_pci_top_main_kobj;
39897 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
39898@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
39899 void *value;
39900 ssize_t(*show) (void *, char *);
39901 ssize_t(*store) (void *, const char *, size_t);
39902-};
39903+} __do_const;
39904
39905 /* Set of show/store abstract level functions for PCI Parity object */
39906 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
39907@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39908 edac_printk(KERN_CRIT, EDAC_PCI,
39909 "Signaled System Error on %s\n",
39910 pci_name(dev));
39911- atomic_inc(&pci_nonparity_count);
39912+ atomic_inc_unchecked(&pci_nonparity_count);
39913 }
39914
39915 if (status & (PCI_STATUS_PARITY)) {
39916@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39917 "Master Data Parity Error on %s\n",
39918 pci_name(dev));
39919
39920- atomic_inc(&pci_parity_count);
39921+ atomic_inc_unchecked(&pci_parity_count);
39922 }
39923
39924 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39925@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39926 "Detected Parity Error on %s\n",
39927 pci_name(dev));
39928
39929- atomic_inc(&pci_parity_count);
39930+ atomic_inc_unchecked(&pci_parity_count);
39931 }
39932 }
39933
39934@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39935 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
39936 "Signaled System Error on %s\n",
39937 pci_name(dev));
39938- atomic_inc(&pci_nonparity_count);
39939+ atomic_inc_unchecked(&pci_nonparity_count);
39940 }
39941
39942 if (status & (PCI_STATUS_PARITY)) {
39943@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39944 "Master Data Parity Error on "
39945 "%s\n", pci_name(dev));
39946
39947- atomic_inc(&pci_parity_count);
39948+ atomic_inc_unchecked(&pci_parity_count);
39949 }
39950
39951 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39952@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39953 "Detected Parity Error on %s\n",
39954 pci_name(dev));
39955
39956- atomic_inc(&pci_parity_count);
39957+ atomic_inc_unchecked(&pci_parity_count);
39958 }
39959 }
39960 }
39961@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
39962 if (!check_pci_errors)
39963 return;
39964
39965- before_count = atomic_read(&pci_parity_count);
39966+ before_count = atomic_read_unchecked(&pci_parity_count);
39967
39968 /* scan all PCI devices looking for a Parity Error on devices and
39969 * bridges.
39970@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
39971 /* Only if operator has selected panic on PCI Error */
39972 if (edac_pci_get_panic_on_pe()) {
39973 /* If the count is different 'after' from 'before' */
39974- if (before_count != atomic_read(&pci_parity_count))
39975+ if (before_count != atomic_read_unchecked(&pci_parity_count))
39976 panic("EDAC: PCI Parity Error");
39977 }
39978 }
39979diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
39980index 51b7e3a..aa8a3e8 100644
39981--- a/drivers/edac/mce_amd.h
39982+++ b/drivers/edac/mce_amd.h
39983@@ -77,7 +77,7 @@ struct amd_decoder_ops {
39984 bool (*mc0_mce)(u16, u8);
39985 bool (*mc1_mce)(u16, u8);
39986 bool (*mc2_mce)(u16, u8);
39987-};
39988+} __no_const;
39989
39990 void amd_report_gart_errors(bool);
39991 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
39992diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
39993index 57ea7f4..af06b76 100644
39994--- a/drivers/firewire/core-card.c
39995+++ b/drivers/firewire/core-card.c
39996@@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
39997 const struct fw_card_driver *driver,
39998 struct device *device)
39999 {
40000- static atomic_t index = ATOMIC_INIT(-1);
40001+ static atomic_unchecked_t index = ATOMIC_INIT(-1);
40002
40003- card->index = atomic_inc_return(&index);
40004+ card->index = atomic_inc_return_unchecked(&index);
40005 card->driver = driver;
40006 card->device = device;
40007 card->current_tlabel = 0;
40008@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
40009
40010 void fw_core_remove_card(struct fw_card *card)
40011 {
40012- struct fw_card_driver dummy_driver = dummy_driver_template;
40013+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
40014
40015 card->driver->update_phy_reg(card, 4,
40016 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
40017diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
40018index 2c6d5e1..a2cca6b 100644
40019--- a/drivers/firewire/core-device.c
40020+++ b/drivers/firewire/core-device.c
40021@@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
40022 struct config_rom_attribute {
40023 struct device_attribute attr;
40024 u32 key;
40025-};
40026+} __do_const;
40027
40028 static ssize_t show_immediate(struct device *dev,
40029 struct device_attribute *dattr, char *buf)
40030diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
40031index eb6935c..3cc2bfa 100644
40032--- a/drivers/firewire/core-transaction.c
40033+++ b/drivers/firewire/core-transaction.c
40034@@ -38,6 +38,7 @@
40035 #include <linux/timer.h>
40036 #include <linux/types.h>
40037 #include <linux/workqueue.h>
40038+#include <linux/sched.h>
40039
40040 #include <asm/byteorder.h>
40041
40042diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
40043index c98764a..551b520 100644
40044--- a/drivers/firewire/core.h
40045+++ b/drivers/firewire/core.h
40046@@ -111,6 +111,7 @@ struct fw_card_driver {
40047
40048 int (*stop_iso)(struct fw_iso_context *ctx);
40049 };
40050+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
40051
40052 void fw_card_initialize(struct fw_card *card,
40053 const struct fw_card_driver *driver, struct device *device);
40054diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
40055index 8db6632..9bbc8ca 100644
40056--- a/drivers/firewire/ohci.c
40057+++ b/drivers/firewire/ohci.c
40058@@ -2049,10 +2049,12 @@ static void bus_reset_work(struct work_struct *work)
40059 be32_to_cpu(ohci->next_header));
40060 }
40061
40062+#ifndef CONFIG_GRKERNSEC
40063 if (param_remote_dma) {
40064 reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
40065 reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
40066 }
40067+#endif
40068
40069 spin_unlock_irq(&ohci->lock);
40070
40071@@ -2584,8 +2586,10 @@ static int ohci_enable_phys_dma(struct fw_card *card,
40072 unsigned long flags;
40073 int n, ret = 0;
40074
40075+#ifndef CONFIG_GRKERNSEC
40076 if (param_remote_dma)
40077 return 0;
40078+#endif
40079
40080 /*
40081 * FIXME: Make sure this bitmask is cleared when we clear the busReset
40082diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
40083index 94a58a0..f5eba42 100644
40084--- a/drivers/firmware/dmi-id.c
40085+++ b/drivers/firmware/dmi-id.c
40086@@ -16,7 +16,7 @@
40087 struct dmi_device_attribute{
40088 struct device_attribute dev_attr;
40089 int field;
40090-};
40091+} __do_const;
40092 #define to_dmi_dev_attr(_dev_attr) \
40093 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
40094
40095diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
40096index 17afc51..0ef90cd 100644
40097--- a/drivers/firmware/dmi_scan.c
40098+++ b/drivers/firmware/dmi_scan.c
40099@@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
40100 if (buf == NULL)
40101 return -1;
40102
40103- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
40104+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
40105
40106 dmi_unmap(buf);
40107 return 0;
40108diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
40109index 1491dd4..aa910db 100644
40110--- a/drivers/firmware/efi/cper.c
40111+++ b/drivers/firmware/efi/cper.c
40112@@ -41,12 +41,12 @@
40113 */
40114 u64 cper_next_record_id(void)
40115 {
40116- static atomic64_t seq;
40117+ static atomic64_unchecked_t seq;
40118
40119- if (!atomic64_read(&seq))
40120- atomic64_set(&seq, ((u64)get_seconds()) << 32);
40121+ if (!atomic64_read_unchecked(&seq))
40122+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
40123
40124- return atomic64_inc_return(&seq);
40125+ return atomic64_inc_return_unchecked(&seq);
40126 }
40127 EXPORT_SYMBOL_GPL(cper_next_record_id);
40128
40129diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
40130index 4753bac..02861a2 100644
40131--- a/drivers/firmware/efi/efi.c
40132+++ b/drivers/firmware/efi/efi.c
40133@@ -120,14 +120,16 @@ static struct attribute_group efi_subsys_attr_group = {
40134 };
40135
40136 static struct efivars generic_efivars;
40137-static struct efivar_operations generic_ops;
40138+static efivar_operations_no_const generic_ops __read_only;
40139
40140 static int generic_ops_register(void)
40141 {
40142- generic_ops.get_variable = efi.get_variable;
40143- generic_ops.set_variable = efi.set_variable;
40144- generic_ops.get_next_variable = efi.get_next_variable;
40145- generic_ops.query_variable_store = efi_query_variable_store;
40146+ pax_open_kernel();
40147+ *(void **)&generic_ops.get_variable = efi.get_variable;
40148+ *(void **)&generic_ops.set_variable = efi.set_variable;
40149+ *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
40150+ *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
40151+ pax_close_kernel();
40152
40153 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
40154 }
40155diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
40156index 3dc2482..7bd2f61 100644
40157--- a/drivers/firmware/efi/efivars.c
40158+++ b/drivers/firmware/efi/efivars.c
40159@@ -456,7 +456,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
40160 static int
40161 create_efivars_bin_attributes(void)
40162 {
40163- struct bin_attribute *attr;
40164+ bin_attribute_no_const *attr;
40165 int error;
40166
40167 /* new_var */
40168diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
40169index 2a90ba6..07f3733 100644
40170--- a/drivers/firmware/google/memconsole.c
40171+++ b/drivers/firmware/google/memconsole.c
40172@@ -147,7 +147,9 @@ static int __init memconsole_init(void)
40173 if (!found_memconsole())
40174 return -ENODEV;
40175
40176- memconsole_bin_attr.size = memconsole_length;
40177+ pax_open_kernel();
40178+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
40179+ pax_close_kernel();
40180
40181 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
40182
40183diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
40184index 1e98a98..b444372 100644
40185--- a/drivers/gpio/gpio-em.c
40186+++ b/drivers/gpio/gpio-em.c
40187@@ -278,7 +278,7 @@ static int em_gio_probe(struct platform_device *pdev)
40188 struct em_gio_priv *p;
40189 struct resource *io[2], *irq[2];
40190 struct gpio_chip *gpio_chip;
40191- struct irq_chip *irq_chip;
40192+ irq_chip_no_const *irq_chip;
40193 const char *name = dev_name(&pdev->dev);
40194 int ret;
40195
40196diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
40197index f5bf3c3..7baaa59 100644
40198--- a/drivers/gpio/gpio-ich.c
40199+++ b/drivers/gpio/gpio-ich.c
40200@@ -71,7 +71,7 @@ struct ichx_desc {
40201 /* Some chipsets have quirks, let these use their own request/get */
40202 int (*request)(struct gpio_chip *chip, unsigned offset);
40203 int (*get)(struct gpio_chip *chip, unsigned offset);
40204-};
40205+} __do_const;
40206
40207 static struct {
40208 spinlock_t lock;
40209diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
40210index ca76ce7..68b384b 100644
40211--- a/drivers/gpio/gpio-rcar.c
40212+++ b/drivers/gpio/gpio-rcar.c
40213@@ -355,7 +355,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
40214 struct gpio_rcar_priv *p;
40215 struct resource *io, *irq;
40216 struct gpio_chip *gpio_chip;
40217- struct irq_chip *irq_chip;
40218+ irq_chip_no_const *irq_chip;
40219 const char *name = dev_name(&pdev->dev);
40220 int ret;
40221
40222diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
40223index 9902732..64b62dd 100644
40224--- a/drivers/gpio/gpio-vr41xx.c
40225+++ b/drivers/gpio/gpio-vr41xx.c
40226@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
40227 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
40228 maskl, pendl, maskh, pendh);
40229
40230- atomic_inc(&irq_err_count);
40231+ atomic_inc_unchecked(&irq_err_count);
40232
40233 return -EINVAL;
40234 }
40235diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
40236index 3b7d32d..05c2f74 100644
40237--- a/drivers/gpu/drm/drm_crtc.c
40238+++ b/drivers/gpu/drm/drm_crtc.c
40239@@ -3123,7 +3123,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
40240 goto done;
40241 }
40242
40243- if (copy_to_user(&enum_ptr[copied].name,
40244+ if (copy_to_user(enum_ptr[copied].name,
40245 &prop_enum->name, DRM_PROP_NAME_LEN)) {
40246 ret = -EFAULT;
40247 goto done;
40248diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
40249index 345be03..158368d 100644
40250--- a/drivers/gpu/drm/drm_drv.c
40251+++ b/drivers/gpu/drm/drm_drv.c
40252@@ -233,7 +233,7 @@ module_exit(drm_core_exit);
40253 /**
40254 * Copy and IOCTL return string to user space
40255 */
40256-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
40257+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
40258 {
40259 int len;
40260
40261@@ -303,7 +303,7 @@ long drm_ioctl(struct file *filp,
40262 struct drm_file *file_priv = filp->private_data;
40263 struct drm_device *dev;
40264 const struct drm_ioctl_desc *ioctl = NULL;
40265- drm_ioctl_t *func;
40266+ drm_ioctl_no_const_t func;
40267 unsigned int nr = DRM_IOCTL_NR(cmd);
40268 int retcode = -EINVAL;
40269 char stack_kdata[128];
40270diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
40271index 7f2af9a..1561914 100644
40272--- a/drivers/gpu/drm/drm_fops.c
40273+++ b/drivers/gpu/drm/drm_fops.c
40274@@ -97,7 +97,7 @@ int drm_open(struct inode *inode, struct file *filp)
40275 if (drm_device_is_unplugged(dev))
40276 return -ENODEV;
40277
40278- if (!dev->open_count++)
40279+ if (local_inc_return(&dev->open_count) == 1)
40280 need_setup = 1;
40281 mutex_lock(&dev->struct_mutex);
40282 old_imapping = inode->i_mapping;
40283@@ -127,7 +127,7 @@ err_undo:
40284 iput(container_of(dev->dev_mapping, struct inode, i_data));
40285 dev->dev_mapping = old_mapping;
40286 mutex_unlock(&dev->struct_mutex);
40287- dev->open_count--;
40288+ local_dec(&dev->open_count);
40289 return retcode;
40290 }
40291 EXPORT_SYMBOL(drm_open);
40292@@ -463,7 +463,7 @@ int drm_release(struct inode *inode, struct file *filp)
40293
40294 mutex_lock(&drm_global_mutex);
40295
40296- DRM_DEBUG("open_count = %d\n", dev->open_count);
40297+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
40298
40299 if (dev->driver->preclose)
40300 dev->driver->preclose(dev, file_priv);
40301@@ -472,10 +472,10 @@ int drm_release(struct inode *inode, struct file *filp)
40302 * Begin inline drm_release
40303 */
40304
40305- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
40306+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
40307 task_pid_nr(current),
40308 (long)old_encode_dev(file_priv->minor->device),
40309- dev->open_count);
40310+ local_read(&dev->open_count));
40311
40312 /* Release any auth tokens that might point to this file_priv,
40313 (do that under the drm_global_mutex) */
40314@@ -573,7 +573,7 @@ int drm_release(struct inode *inode, struct file *filp)
40315 * End inline drm_release
40316 */
40317
40318- if (!--dev->open_count) {
40319+ if (local_dec_and_test(&dev->open_count)) {
40320 retcode = drm_lastclose(dev);
40321 if (drm_device_is_unplugged(dev))
40322 drm_put_dev(dev);
40323diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
40324index 3d2e91c..d31c4c9 100644
40325--- a/drivers/gpu/drm/drm_global.c
40326+++ b/drivers/gpu/drm/drm_global.c
40327@@ -36,7 +36,7 @@
40328 struct drm_global_item {
40329 struct mutex mutex;
40330 void *object;
40331- int refcount;
40332+ atomic_t refcount;
40333 };
40334
40335 static struct drm_global_item glob[DRM_GLOBAL_NUM];
40336@@ -49,7 +49,7 @@ void drm_global_init(void)
40337 struct drm_global_item *item = &glob[i];
40338 mutex_init(&item->mutex);
40339 item->object = NULL;
40340- item->refcount = 0;
40341+ atomic_set(&item->refcount, 0);
40342 }
40343 }
40344
40345@@ -59,7 +59,7 @@ void drm_global_release(void)
40346 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
40347 struct drm_global_item *item = &glob[i];
40348 BUG_ON(item->object != NULL);
40349- BUG_ON(item->refcount != 0);
40350+ BUG_ON(atomic_read(&item->refcount) != 0);
40351 }
40352 }
40353
40354@@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40355 struct drm_global_item *item = &glob[ref->global_type];
40356
40357 mutex_lock(&item->mutex);
40358- if (item->refcount == 0) {
40359+ if (atomic_read(&item->refcount) == 0) {
40360 item->object = kzalloc(ref->size, GFP_KERNEL);
40361 if (unlikely(item->object == NULL)) {
40362 ret = -ENOMEM;
40363@@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40364 goto out_err;
40365
40366 }
40367- ++item->refcount;
40368+ atomic_inc(&item->refcount);
40369 ref->object = item->object;
40370 mutex_unlock(&item->mutex);
40371 return 0;
40372@@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
40373 struct drm_global_item *item = &glob[ref->global_type];
40374
40375 mutex_lock(&item->mutex);
40376- BUG_ON(item->refcount == 0);
40377+ BUG_ON(atomic_read(&item->refcount) == 0);
40378 BUG_ON(ref->object != item->object);
40379- if (--item->refcount == 0) {
40380+ if (atomic_dec_and_test(&item->refcount)) {
40381 ref->release(ref);
40382 item->object = NULL;
40383 }
40384diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
40385index 7473035..a48b9c5 100644
40386--- a/drivers/gpu/drm/drm_info.c
40387+++ b/drivers/gpu/drm/drm_info.c
40388@@ -75,10 +75,13 @@ int drm_vm_info(struct seq_file *m, void *data)
40389 struct drm_local_map *map;
40390 struct drm_map_list *r_list;
40391
40392- /* Hardcoded from _DRM_FRAME_BUFFER,
40393- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
40394- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
40395- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
40396+ static const char * const types[] = {
40397+ [_DRM_FRAME_BUFFER] = "FB",
40398+ [_DRM_REGISTERS] = "REG",
40399+ [_DRM_SHM] = "SHM",
40400+ [_DRM_AGP] = "AGP",
40401+ [_DRM_SCATTER_GATHER] = "SG",
40402+ [_DRM_CONSISTENT] = "PCI"};
40403 const char *type;
40404 int i;
40405
40406@@ -89,7 +92,7 @@ int drm_vm_info(struct seq_file *m, void *data)
40407 map = r_list->map;
40408 if (!map)
40409 continue;
40410- if (map->type < 0 || map->type > 5)
40411+ if (map->type >= ARRAY_SIZE(types))
40412 type = "??";
40413 else
40414 type = types[map->type];
40415@@ -261,7 +264,11 @@ int drm_vma_info(struct seq_file *m, void *data)
40416 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
40417 vma->vm_flags & VM_LOCKED ? 'l' : '-',
40418 vma->vm_flags & VM_IO ? 'i' : '-',
40419+#ifdef CONFIG_GRKERNSEC_HIDESYM
40420+ 0);
40421+#else
40422 vma->vm_pgoff);
40423+#endif
40424
40425 #if defined(__i386__)
40426 pgprot = pgprot_val(vma->vm_page_prot);
40427diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
40428index 2f4c4343..dd12cd2 100644
40429--- a/drivers/gpu/drm/drm_ioc32.c
40430+++ b/drivers/gpu/drm/drm_ioc32.c
40431@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
40432 request = compat_alloc_user_space(nbytes);
40433 if (!access_ok(VERIFY_WRITE, request, nbytes))
40434 return -EFAULT;
40435- list = (struct drm_buf_desc *) (request + 1);
40436+ list = (struct drm_buf_desc __user *) (request + 1);
40437
40438 if (__put_user(count, &request->count)
40439 || __put_user(list, &request->list))
40440@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
40441 request = compat_alloc_user_space(nbytes);
40442 if (!access_ok(VERIFY_WRITE, request, nbytes))
40443 return -EFAULT;
40444- list = (struct drm_buf_pub *) (request + 1);
40445+ list = (struct drm_buf_pub __user *) (request + 1);
40446
40447 if (__put_user(count, &request->count)
40448 || __put_user(list, &request->list))
40449@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
40450 return 0;
40451 }
40452
40453-drm_ioctl_compat_t *drm_compat_ioctls[] = {
40454+drm_ioctl_compat_t drm_compat_ioctls[] = {
40455 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
40456 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
40457 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
40458@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
40459 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40460 {
40461 unsigned int nr = DRM_IOCTL_NR(cmd);
40462- drm_ioctl_compat_t *fn;
40463 int ret;
40464
40465 /* Assume that ioctls without an explicit compat routine will just
40466@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40467 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
40468 return drm_ioctl(filp, cmd, arg);
40469
40470- fn = drm_compat_ioctls[nr];
40471-
40472- if (fn != NULL)
40473- ret = (*fn) (filp, cmd, arg);
40474+ if (drm_compat_ioctls[nr] != NULL)
40475+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
40476 else
40477 ret = drm_ioctl(filp, cmd, arg);
40478
40479diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
40480index 98a33c580..8fd1c2b 100644
40481--- a/drivers/gpu/drm/drm_stub.c
40482+++ b/drivers/gpu/drm/drm_stub.c
40483@@ -409,7 +409,7 @@ void drm_unplug_dev(struct drm_device *dev)
40484
40485 drm_device_set_unplugged(dev);
40486
40487- if (dev->open_count == 0) {
40488+ if (local_read(&dev->open_count) == 0) {
40489 drm_put_dev(dev);
40490 }
40491 mutex_unlock(&drm_global_mutex);
40492diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
40493index c22c309..ae758c3 100644
40494--- a/drivers/gpu/drm/drm_sysfs.c
40495+++ b/drivers/gpu/drm/drm_sysfs.c
40496@@ -505,7 +505,7 @@ static void drm_sysfs_release(struct device *dev)
40497 */
40498 int drm_sysfs_device_add(struct drm_minor *minor)
40499 {
40500- char *minor_str;
40501+ const char *minor_str;
40502 int r;
40503
40504 if (minor->type == DRM_MINOR_CONTROL)
40505diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
40506index d4d16ed..8fb0b51 100644
40507--- a/drivers/gpu/drm/i810/i810_drv.h
40508+++ b/drivers/gpu/drm/i810/i810_drv.h
40509@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
40510 int page_flipping;
40511
40512 wait_queue_head_t irq_queue;
40513- atomic_t irq_received;
40514- atomic_t irq_emitted;
40515+ atomic_unchecked_t irq_received;
40516+ atomic_unchecked_t irq_emitted;
40517
40518 int front_offset;
40519 } drm_i810_private_t;
40520diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
40521index b2b46c5..feb9fe7 100644
40522--- a/drivers/gpu/drm/i915/i915_debugfs.c
40523+++ b/drivers/gpu/drm/i915/i915_debugfs.c
40524@@ -713,7 +713,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
40525 I915_READ(GTIMR));
40526 }
40527 seq_printf(m, "Interrupts received: %d\n",
40528- atomic_read(&dev_priv->irq_received));
40529+ atomic_read_unchecked(&dev_priv->irq_received));
40530 for_each_ring(ring, dev_priv, i) {
40531 if (INTEL_INFO(dev)->gen >= 6) {
40532 seq_printf(m,
40533diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
40534index 15a74f9..4278889 100644
40535--- a/drivers/gpu/drm/i915/i915_dma.c
40536+++ b/drivers/gpu/drm/i915/i915_dma.c
40537@@ -1273,7 +1273,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
40538 bool can_switch;
40539
40540 spin_lock(&dev->count_lock);
40541- can_switch = (dev->open_count == 0);
40542+ can_switch = (local_read(&dev->open_count) == 0);
40543 spin_unlock(&dev->count_lock);
40544 return can_switch;
40545 }
40546diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
40547index df77e20..d3fda9f 100644
40548--- a/drivers/gpu/drm/i915/i915_drv.h
40549+++ b/drivers/gpu/drm/i915/i915_drv.h
40550@@ -1361,7 +1361,7 @@ typedef struct drm_i915_private {
40551 drm_dma_handle_t *status_page_dmah;
40552 struct resource mch_res;
40553
40554- atomic_t irq_received;
40555+ atomic_unchecked_t irq_received;
40556
40557 /* protects the irq masks */
40558 spinlock_t irq_lock;
40559diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40560index d269ecf..6d857bc 100644
40561--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40562+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40563@@ -860,9 +860,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
40564
40565 static int
40566 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
40567- int count)
40568+ unsigned int count)
40569 {
40570- int i;
40571+ unsigned int i;
40572 unsigned relocs_total = 0;
40573 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
40574
40575diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
40576index 3c59584..500f2e9 100644
40577--- a/drivers/gpu/drm/i915/i915_ioc32.c
40578+++ b/drivers/gpu/drm/i915/i915_ioc32.c
40579@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
40580 (unsigned long)request);
40581 }
40582
40583-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40584+static drm_ioctl_compat_t i915_compat_ioctls[] = {
40585 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
40586 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
40587 [DRM_I915_GETPARAM] = compat_i915_getparam,
40588@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40589 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40590 {
40591 unsigned int nr = DRM_IOCTL_NR(cmd);
40592- drm_ioctl_compat_t *fn = NULL;
40593 int ret;
40594
40595 if (nr < DRM_COMMAND_BASE)
40596 return drm_compat_ioctl(filp, cmd, arg);
40597
40598- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
40599- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40600-
40601- if (fn != NULL)
40602+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
40603+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40604 ret = (*fn) (filp, cmd, arg);
40605- else
40606+ } else
40607 ret = drm_ioctl(filp, cmd, arg);
40608
40609 return ret;
40610diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
40611index d554169..f4426bb 100644
40612--- a/drivers/gpu/drm/i915/i915_irq.c
40613+++ b/drivers/gpu/drm/i915/i915_irq.c
40614@@ -1438,7 +1438,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
40615 int pipe;
40616 u32 pipe_stats[I915_MAX_PIPES];
40617
40618- atomic_inc(&dev_priv->irq_received);
40619+ atomic_inc_unchecked(&dev_priv->irq_received);
40620
40621 while (true) {
40622 iir = I915_READ(VLV_IIR);
40623@@ -1751,7 +1751,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
40624 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
40625 irqreturn_t ret = IRQ_NONE;
40626
40627- atomic_inc(&dev_priv->irq_received);
40628+ atomic_inc_unchecked(&dev_priv->irq_received);
40629
40630 /* We get interrupts on unclaimed registers, so check for this before we
40631 * do any I915_{READ,WRITE}. */
40632@@ -1821,7 +1821,7 @@ static irqreturn_t gen8_irq_handler(int irq, void *arg)
40633 uint32_t tmp = 0;
40634 enum pipe pipe;
40635
40636- atomic_inc(&dev_priv->irq_received);
40637+ atomic_inc_unchecked(&dev_priv->irq_received);
40638
40639 master_ctl = I915_READ(GEN8_MASTER_IRQ);
40640 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
40641@@ -2645,7 +2645,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
40642 {
40643 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40644
40645- atomic_set(&dev_priv->irq_received, 0);
40646+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40647
40648 I915_WRITE(HWSTAM, 0xeffe);
40649
40650@@ -2663,7 +2663,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
40651 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40652 int pipe;
40653
40654- atomic_set(&dev_priv->irq_received, 0);
40655+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40656
40657 /* VLV magic */
40658 I915_WRITE(VLV_IMR, 0);
40659@@ -2694,7 +2694,7 @@ static void gen8_irq_preinstall(struct drm_device *dev)
40660 struct drm_i915_private *dev_priv = dev->dev_private;
40661 int pipe;
40662
40663- atomic_set(&dev_priv->irq_received, 0);
40664+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40665
40666 I915_WRITE(GEN8_MASTER_IRQ, 0);
40667 POSTING_READ(GEN8_MASTER_IRQ);
40668@@ -3018,7 +3018,7 @@ static void gen8_irq_uninstall(struct drm_device *dev)
40669 if (!dev_priv)
40670 return;
40671
40672- atomic_set(&dev_priv->irq_received, 0);
40673+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40674
40675 I915_WRITE(GEN8_MASTER_IRQ, 0);
40676
40677@@ -3112,7 +3112,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
40678 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40679 int pipe;
40680
40681- atomic_set(&dev_priv->irq_received, 0);
40682+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40683
40684 for_each_pipe(pipe)
40685 I915_WRITE(PIPESTAT(pipe), 0);
40686@@ -3198,7 +3198,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
40687 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
40688 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40689
40690- atomic_inc(&dev_priv->irq_received);
40691+ atomic_inc_unchecked(&dev_priv->irq_received);
40692
40693 iir = I915_READ16(IIR);
40694 if (iir == 0)
40695@@ -3277,7 +3277,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
40696 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40697 int pipe;
40698
40699- atomic_set(&dev_priv->irq_received, 0);
40700+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40701
40702 if (I915_HAS_HOTPLUG(dev)) {
40703 I915_WRITE(PORT_HOTPLUG_EN, 0);
40704@@ -3384,7 +3384,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
40705 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40706 int pipe, ret = IRQ_NONE;
40707
40708- atomic_inc(&dev_priv->irq_received);
40709+ atomic_inc_unchecked(&dev_priv->irq_received);
40710
40711 iir = I915_READ(IIR);
40712 do {
40713@@ -3511,7 +3511,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
40714 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40715 int pipe;
40716
40717- atomic_set(&dev_priv->irq_received, 0);
40718+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40719
40720 I915_WRITE(PORT_HOTPLUG_EN, 0);
40721 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
40722@@ -3627,7 +3627,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
40723 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
40724 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40725
40726- atomic_inc(&dev_priv->irq_received);
40727+ atomic_inc_unchecked(&dev_priv->irq_received);
40728
40729 iir = I915_READ(IIR);
40730
40731diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
40732index 9b8a7c7..60f6003 100644
40733--- a/drivers/gpu/drm/i915/intel_display.c
40734+++ b/drivers/gpu/drm/i915/intel_display.c
40735@@ -10776,13 +10776,13 @@ struct intel_quirk {
40736 int subsystem_vendor;
40737 int subsystem_device;
40738 void (*hook)(struct drm_device *dev);
40739-};
40740+} __do_const;
40741
40742 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
40743 struct intel_dmi_quirk {
40744 void (*hook)(struct drm_device *dev);
40745 const struct dmi_system_id (*dmi_id_list)[];
40746-};
40747+} __do_const;
40748
40749 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40750 {
40751@@ -10790,18 +10790,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40752 return 1;
40753 }
40754
40755-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40756+static const struct dmi_system_id intel_dmi_quirks_table[] = {
40757 {
40758- .dmi_id_list = &(const struct dmi_system_id[]) {
40759- {
40760- .callback = intel_dmi_reverse_brightness,
40761- .ident = "NCR Corporation",
40762- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40763- DMI_MATCH(DMI_PRODUCT_NAME, ""),
40764- },
40765- },
40766- { } /* terminating entry */
40767+ .callback = intel_dmi_reverse_brightness,
40768+ .ident = "NCR Corporation",
40769+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40770+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
40771 },
40772+ },
40773+ { } /* terminating entry */
40774+};
40775+
40776+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40777+ {
40778+ .dmi_id_list = &intel_dmi_quirks_table,
40779 .hook = quirk_invert_brightness,
40780 },
40781 };
40782diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
40783index fe45321..836fdca 100644
40784--- a/drivers/gpu/drm/mga/mga_drv.h
40785+++ b/drivers/gpu/drm/mga/mga_drv.h
40786@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
40787 u32 clear_cmd;
40788 u32 maccess;
40789
40790- atomic_t vbl_received; /**< Number of vblanks received. */
40791+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
40792 wait_queue_head_t fence_queue;
40793- atomic_t last_fence_retired;
40794+ atomic_unchecked_t last_fence_retired;
40795 u32 next_fence_to_post;
40796
40797 unsigned int fb_cpp;
40798diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
40799index 86b4bb8..ae237ad 100644
40800--- a/drivers/gpu/drm/mga/mga_ioc32.c
40801+++ b/drivers/gpu/drm/mga/mga_ioc32.c
40802@@ -190,7 +190,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
40803 return 0;
40804 }
40805
40806-drm_ioctl_compat_t *mga_compat_ioctls[] = {
40807+drm_ioctl_compat_t mga_compat_ioctls[] = {
40808 [DRM_MGA_INIT] = compat_mga_init,
40809 [DRM_MGA_GETPARAM] = compat_mga_getparam,
40810 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
40811@@ -208,18 +208,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
40812 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40813 {
40814 unsigned int nr = DRM_IOCTL_NR(cmd);
40815- drm_ioctl_compat_t *fn = NULL;
40816 int ret;
40817
40818 if (nr < DRM_COMMAND_BASE)
40819 return drm_compat_ioctl(filp, cmd, arg);
40820
40821- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
40822- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40823-
40824- if (fn != NULL)
40825+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
40826+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40827 ret = (*fn) (filp, cmd, arg);
40828- else
40829+ } else
40830 ret = drm_ioctl(filp, cmd, arg);
40831
40832 return ret;
40833diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
40834index 1b071b8..de8601a 100644
40835--- a/drivers/gpu/drm/mga/mga_irq.c
40836+++ b/drivers/gpu/drm/mga/mga_irq.c
40837@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
40838 if (crtc != 0)
40839 return 0;
40840
40841- return atomic_read(&dev_priv->vbl_received);
40842+ return atomic_read_unchecked(&dev_priv->vbl_received);
40843 }
40844
40845
40846@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40847 /* VBLANK interrupt */
40848 if (status & MGA_VLINEPEN) {
40849 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
40850- atomic_inc(&dev_priv->vbl_received);
40851+ atomic_inc_unchecked(&dev_priv->vbl_received);
40852 drm_handle_vblank(dev, 0);
40853 handled = 1;
40854 }
40855@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40856 if ((prim_start & ~0x03) != (prim_end & ~0x03))
40857 MGA_WRITE(MGA_PRIMEND, prim_end);
40858
40859- atomic_inc(&dev_priv->last_fence_retired);
40860+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
40861 wake_up(&dev_priv->fence_queue);
40862 handled = 1;
40863 }
40864@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
40865 * using fences.
40866 */
40867 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * HZ,
40868- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
40869+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
40870 - *sequence) <= (1 << 23)));
40871
40872 *sequence = cur_fence;
40873diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
40874index 4c3feaa..26391ce 100644
40875--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
40876+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
40877@@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
40878 struct bit_table {
40879 const char id;
40880 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
40881-};
40882+} __no_const;
40883
40884 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
40885
40886diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
40887index 23ca7a5..b6c955d 100644
40888--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
40889+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
40890@@ -97,7 +97,6 @@ struct nouveau_drm {
40891 struct drm_global_reference mem_global_ref;
40892 struct ttm_bo_global_ref bo_global_ref;
40893 struct ttm_bo_device bdev;
40894- atomic_t validate_sequence;
40895 int (*move)(struct nouveau_channel *,
40896 struct ttm_buffer_object *,
40897 struct ttm_mem_reg *, struct ttm_mem_reg *);
40898diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40899index c1a7e5a..38b8539 100644
40900--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40901+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40902@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
40903 unsigned long arg)
40904 {
40905 unsigned int nr = DRM_IOCTL_NR(cmd);
40906- drm_ioctl_compat_t *fn = NULL;
40907+ drm_ioctl_compat_t fn = NULL;
40908 int ret;
40909
40910 if (nr < DRM_COMMAND_BASE)
40911diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40912index d45d50d..72a5dd2 100644
40913--- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
40914+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40915@@ -130,11 +130,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40916 }
40917
40918 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
40919- nouveau_vram_manager_init,
40920- nouveau_vram_manager_fini,
40921- nouveau_vram_manager_new,
40922- nouveau_vram_manager_del,
40923- nouveau_vram_manager_debug
40924+ .init = nouveau_vram_manager_init,
40925+ .takedown = nouveau_vram_manager_fini,
40926+ .get_node = nouveau_vram_manager_new,
40927+ .put_node = nouveau_vram_manager_del,
40928+ .debug = nouveau_vram_manager_debug
40929 };
40930
40931 static int
40932@@ -199,11 +199,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40933 }
40934
40935 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
40936- nouveau_gart_manager_init,
40937- nouveau_gart_manager_fini,
40938- nouveau_gart_manager_new,
40939- nouveau_gart_manager_del,
40940- nouveau_gart_manager_debug
40941+ .init = nouveau_gart_manager_init,
40942+ .takedown = nouveau_gart_manager_fini,
40943+ .get_node = nouveau_gart_manager_new,
40944+ .put_node = nouveau_gart_manager_del,
40945+ .debug = nouveau_gart_manager_debug
40946 };
40947
40948 #include <core/subdev/vm/nv04.h>
40949@@ -271,11 +271,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40950 }
40951
40952 const struct ttm_mem_type_manager_func nv04_gart_manager = {
40953- nv04_gart_manager_init,
40954- nv04_gart_manager_fini,
40955- nv04_gart_manager_new,
40956- nv04_gart_manager_del,
40957- nv04_gart_manager_debug
40958+ .init = nv04_gart_manager_init,
40959+ .takedown = nv04_gart_manager_fini,
40960+ .get_node = nv04_gart_manager_new,
40961+ .put_node = nv04_gart_manager_del,
40962+ .debug = nv04_gart_manager_debug
40963 };
40964
40965 int
40966diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
40967index 471347e..5adc6b9 100644
40968--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
40969+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
40970@@ -67,7 +67,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
40971 bool can_switch;
40972
40973 spin_lock(&dev->count_lock);
40974- can_switch = (dev->open_count == 0);
40975+ can_switch = (local_read(&dev->open_count) == 0);
40976 spin_unlock(&dev->count_lock);
40977 return can_switch;
40978 }
40979diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
40980index eb89653..613cf71 100644
40981--- a/drivers/gpu/drm/qxl/qxl_cmd.c
40982+++ b/drivers/gpu/drm/qxl/qxl_cmd.c
40983@@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
40984 int ret;
40985
40986 mutex_lock(&qdev->async_io_mutex);
40987- irq_num = atomic_read(&qdev->irq_received_io_cmd);
40988+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40989 if (qdev->last_sent_io_cmd > irq_num) {
40990 if (intr)
40991 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40992- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40993+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40994 else
40995 ret = wait_event_timeout(qdev->io_cmd_event,
40996- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40997+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40998 /* 0 is timeout, just bail the "hw" has gone away */
40999 if (ret <= 0)
41000 goto out;
41001- irq_num = atomic_read(&qdev->irq_received_io_cmd);
41002+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
41003 }
41004 outb(val, addr);
41005 qdev->last_sent_io_cmd = irq_num + 1;
41006 if (intr)
41007 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
41008- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41009+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41010 else
41011 ret = wait_event_timeout(qdev->io_cmd_event,
41012- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41013+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41014 out:
41015 if (ret > 0)
41016 ret = 0;
41017diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
41018index c3c2bbd..bc3c0fb 100644
41019--- a/drivers/gpu/drm/qxl/qxl_debugfs.c
41020+++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
41021@@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
41022 struct drm_info_node *node = (struct drm_info_node *) m->private;
41023 struct qxl_device *qdev = node->minor->dev->dev_private;
41024
41025- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
41026- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
41027- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
41028- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
41029+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
41030+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
41031+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
41032+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
41033 seq_printf(m, "%d\n", qdev->irq_received_error);
41034 return 0;
41035 }
41036diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
41037index 36ed40b..0397633 100644
41038--- a/drivers/gpu/drm/qxl/qxl_drv.h
41039+++ b/drivers/gpu/drm/qxl/qxl_drv.h
41040@@ -290,10 +290,10 @@ struct qxl_device {
41041 unsigned int last_sent_io_cmd;
41042
41043 /* interrupt handling */
41044- atomic_t irq_received;
41045- atomic_t irq_received_display;
41046- atomic_t irq_received_cursor;
41047- atomic_t irq_received_io_cmd;
41048+ atomic_unchecked_t irq_received;
41049+ atomic_unchecked_t irq_received_display;
41050+ atomic_unchecked_t irq_received_cursor;
41051+ atomic_unchecked_t irq_received_io_cmd;
41052 unsigned irq_received_error;
41053 wait_queue_head_t display_event;
41054 wait_queue_head_t cursor_event;
41055diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
41056index 0bb86e6..d41416d 100644
41057--- a/drivers/gpu/drm/qxl/qxl_ioctl.c
41058+++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
41059@@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
41060
41061 /* TODO copy slow path code from i915 */
41062 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
41063- 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);
41064+ 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);
41065
41066 {
41067 struct qxl_drawable *draw = fb_cmd;
41068@@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
41069 struct drm_qxl_reloc reloc;
41070
41071 if (copy_from_user(&reloc,
41072- &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
41073+ &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
41074 sizeof(reloc))) {
41075 ret = -EFAULT;
41076 goto out_free_bos;
41077@@ -294,10 +294,10 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
41078
41079 for (cmd_num = 0; cmd_num < execbuffer->commands_num; ++cmd_num) {
41080
41081- struct drm_qxl_command *commands =
41082- (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
41083+ struct drm_qxl_command __user *commands =
41084+ (struct drm_qxl_command __user *)(uintptr_t)execbuffer->commands;
41085
41086- if (copy_from_user(&user_cmd, &commands[cmd_num],
41087+ if (copy_from_user(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
41088 sizeof(user_cmd)))
41089 return -EFAULT;
41090
41091diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
41092index 28f84b4..fb3e224 100644
41093--- a/drivers/gpu/drm/qxl/qxl_irq.c
41094+++ b/drivers/gpu/drm/qxl/qxl_irq.c
41095@@ -33,19 +33,19 @@ irqreturn_t qxl_irq_handler(int irq, void *arg)
41096
41097 pending = xchg(&qdev->ram_header->int_pending, 0);
41098
41099- atomic_inc(&qdev->irq_received);
41100+ atomic_inc_unchecked(&qdev->irq_received);
41101
41102 if (pending & QXL_INTERRUPT_DISPLAY) {
41103- atomic_inc(&qdev->irq_received_display);
41104+ atomic_inc_unchecked(&qdev->irq_received_display);
41105 wake_up_all(&qdev->display_event);
41106 qxl_queue_garbage_collect(qdev, false);
41107 }
41108 if (pending & QXL_INTERRUPT_CURSOR) {
41109- atomic_inc(&qdev->irq_received_cursor);
41110+ atomic_inc_unchecked(&qdev->irq_received_cursor);
41111 wake_up_all(&qdev->cursor_event);
41112 }
41113 if (pending & QXL_INTERRUPT_IO_CMD) {
41114- atomic_inc(&qdev->irq_received_io_cmd);
41115+ atomic_inc_unchecked(&qdev->irq_received_io_cmd);
41116 wake_up_all(&qdev->io_cmd_event);
41117 }
41118 if (pending & QXL_INTERRUPT_ERROR) {
41119@@ -82,10 +82,10 @@ int qxl_irq_init(struct qxl_device *qdev)
41120 init_waitqueue_head(&qdev->io_cmd_event);
41121 INIT_WORK(&qdev->client_monitors_config_work,
41122 qxl_client_monitors_config_work_func);
41123- atomic_set(&qdev->irq_received, 0);
41124- atomic_set(&qdev->irq_received_display, 0);
41125- atomic_set(&qdev->irq_received_cursor, 0);
41126- atomic_set(&qdev->irq_received_io_cmd, 0);
41127+ atomic_set_unchecked(&qdev->irq_received, 0);
41128+ atomic_set_unchecked(&qdev->irq_received_display, 0);
41129+ atomic_set_unchecked(&qdev->irq_received_cursor, 0);
41130+ atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
41131 qdev->irq_received_error = 0;
41132 ret = drm_irq_install(qdev->ddev);
41133 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
41134diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
41135index c7e7e65..7dddd4d 100644
41136--- a/drivers/gpu/drm/qxl/qxl_ttm.c
41137+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
41138@@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
41139 }
41140 }
41141
41142-static struct vm_operations_struct qxl_ttm_vm_ops;
41143+static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
41144 static const struct vm_operations_struct *ttm_vm_ops;
41145
41146 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41147@@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
41148 return r;
41149 if (unlikely(ttm_vm_ops == NULL)) {
41150 ttm_vm_ops = vma->vm_ops;
41151+ pax_open_kernel();
41152 qxl_ttm_vm_ops = *ttm_vm_ops;
41153 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
41154+ pax_close_kernel();
41155 }
41156 vma->vm_ops = &qxl_ttm_vm_ops;
41157 return 0;
41158@@ -560,25 +562,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
41159 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
41160 {
41161 #if defined(CONFIG_DEBUG_FS)
41162- static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
41163- static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
41164- unsigned i;
41165+ static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
41166+ {
41167+ .name = "qxl_mem_mm",
41168+ .show = &qxl_mm_dump_table,
41169+ },
41170+ {
41171+ .name = "qxl_surf_mm",
41172+ .show = &qxl_mm_dump_table,
41173+ }
41174+ };
41175
41176- for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
41177- if (i == 0)
41178- sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
41179- else
41180- sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
41181- qxl_mem_types_list[i].name = qxl_mem_types_names[i];
41182- qxl_mem_types_list[i].show = &qxl_mm_dump_table;
41183- qxl_mem_types_list[i].driver_features = 0;
41184- if (i == 0)
41185- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
41186- else
41187- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
41188+ pax_open_kernel();
41189+ *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
41190+ *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
41191+ pax_close_kernel();
41192
41193- }
41194- return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
41195+ return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
41196 #else
41197 return 0;
41198 #endif
41199diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
41200index 59459fe..be26b31 100644
41201--- a/drivers/gpu/drm/r128/r128_cce.c
41202+++ b/drivers/gpu/drm/r128/r128_cce.c
41203@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
41204
41205 /* GH: Simple idle check.
41206 */
41207- atomic_set(&dev_priv->idle_count, 0);
41208+ atomic_set_unchecked(&dev_priv->idle_count, 0);
41209
41210 /* We don't support anything other than bus-mastering ring mode,
41211 * but the ring can be in either AGP or PCI space for the ring
41212diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
41213index 5bf3f5f..7000661 100644
41214--- a/drivers/gpu/drm/r128/r128_drv.h
41215+++ b/drivers/gpu/drm/r128/r128_drv.h
41216@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
41217 int is_pci;
41218 unsigned long cce_buffers_offset;
41219
41220- atomic_t idle_count;
41221+ atomic_unchecked_t idle_count;
41222
41223 int page_flipping;
41224 int current_page;
41225 u32 crtc_offset;
41226 u32 crtc_offset_cntl;
41227
41228- atomic_t vbl_received;
41229+ atomic_unchecked_t vbl_received;
41230
41231 u32 color_fmt;
41232 unsigned int front_offset;
41233diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
41234index b0d0fd3..a6fbbe4 100644
41235--- a/drivers/gpu/drm/r128/r128_ioc32.c
41236+++ b/drivers/gpu/drm/r128/r128_ioc32.c
41237@@ -178,7 +178,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
41238 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
41239 }
41240
41241-drm_ioctl_compat_t *r128_compat_ioctls[] = {
41242+drm_ioctl_compat_t r128_compat_ioctls[] = {
41243 [DRM_R128_INIT] = compat_r128_init,
41244 [DRM_R128_DEPTH] = compat_r128_depth,
41245 [DRM_R128_STIPPLE] = compat_r128_stipple,
41246@@ -197,18 +197,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
41247 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41248 {
41249 unsigned int nr = DRM_IOCTL_NR(cmd);
41250- drm_ioctl_compat_t *fn = NULL;
41251 int ret;
41252
41253 if (nr < DRM_COMMAND_BASE)
41254 return drm_compat_ioctl(filp, cmd, arg);
41255
41256- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
41257- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
41258-
41259- if (fn != NULL)
41260+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
41261+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
41262 ret = (*fn) (filp, cmd, arg);
41263- else
41264+ } else
41265 ret = drm_ioctl(filp, cmd, arg);
41266
41267 return ret;
41268diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
41269index c2ae496..30b5993 100644
41270--- a/drivers/gpu/drm/r128/r128_irq.c
41271+++ b/drivers/gpu/drm/r128/r128_irq.c
41272@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
41273 if (crtc != 0)
41274 return 0;
41275
41276- return atomic_read(&dev_priv->vbl_received);
41277+ return atomic_read_unchecked(&dev_priv->vbl_received);
41278 }
41279
41280 irqreturn_t r128_driver_irq_handler(int irq, void *arg)
41281@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(int irq, void *arg)
41282 /* VBLANK interrupt */
41283 if (status & R128_CRTC_VBLANK_INT) {
41284 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
41285- atomic_inc(&dev_priv->vbl_received);
41286+ atomic_inc_unchecked(&dev_priv->vbl_received);
41287 drm_handle_vblank(dev, 0);
41288 return IRQ_HANDLED;
41289 }
41290diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
41291index e806dac..f81d32f 100644
41292--- a/drivers/gpu/drm/r128/r128_state.c
41293+++ b/drivers/gpu/drm/r128/r128_state.c
41294@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
41295
41296 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
41297 {
41298- if (atomic_read(&dev_priv->idle_count) == 0)
41299+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
41300 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
41301 else
41302- atomic_set(&dev_priv->idle_count, 0);
41303+ atomic_set_unchecked(&dev_priv->idle_count, 0);
41304 }
41305
41306 #endif
41307diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
41308index 4a85bb6..aaea819 100644
41309--- a/drivers/gpu/drm/radeon/mkregtable.c
41310+++ b/drivers/gpu/drm/radeon/mkregtable.c
41311@@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
41312 regex_t mask_rex;
41313 regmatch_t match[4];
41314 char buf[1024];
41315- size_t end;
41316+ long end;
41317 int len;
41318 int done = 0;
41319 int r;
41320 unsigned o;
41321 struct offset *offset;
41322 char last_reg_s[10];
41323- int last_reg;
41324+ unsigned long last_reg;
41325
41326 if (regcomp
41327 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
41328diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
41329index 044bc98..50ced9b 100644
41330--- a/drivers/gpu/drm/radeon/radeon_device.c
41331+++ b/drivers/gpu/drm/radeon/radeon_device.c
41332@@ -1125,7 +1125,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
41333 bool can_switch;
41334
41335 spin_lock(&dev->count_lock);
41336- can_switch = (dev->open_count == 0);
41337+ can_switch = (local_read(&dev->open_count) == 0);
41338 spin_unlock(&dev->count_lock);
41339 return can_switch;
41340 }
41341diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
41342index dafd812..1bf20c7 100644
41343--- a/drivers/gpu/drm/radeon/radeon_drv.h
41344+++ b/drivers/gpu/drm/radeon/radeon_drv.h
41345@@ -262,7 +262,7 @@ typedef struct drm_radeon_private {
41346
41347 /* SW interrupt */
41348 wait_queue_head_t swi_queue;
41349- atomic_t swi_emitted;
41350+ atomic_unchecked_t swi_emitted;
41351 int vblank_crtc;
41352 uint32_t irq_enable_reg;
41353 uint32_t r500_disp_irq_reg;
41354diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
41355index bdb0f93..5ff558f 100644
41356--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
41357+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
41358@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
41359 request = compat_alloc_user_space(sizeof(*request));
41360 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
41361 || __put_user(req32.param, &request->param)
41362- || __put_user((void __user *)(unsigned long)req32.value,
41363+ || __put_user((unsigned long)req32.value,
41364 &request->value))
41365 return -EFAULT;
41366
41367@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
41368 #define compat_radeon_cp_setparam NULL
41369 #endif /* X86_64 || IA64 */
41370
41371-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
41372+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
41373 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
41374 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
41375 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
41376@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
41377 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41378 {
41379 unsigned int nr = DRM_IOCTL_NR(cmd);
41380- drm_ioctl_compat_t *fn = NULL;
41381 int ret;
41382
41383 if (nr < DRM_COMMAND_BASE)
41384 return drm_compat_ioctl(filp, cmd, arg);
41385
41386- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
41387- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
41388-
41389- if (fn != NULL)
41390+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
41391+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
41392 ret = (*fn) (filp, cmd, arg);
41393- else
41394+ } else
41395 ret = drm_ioctl(filp, cmd, arg);
41396
41397 return ret;
41398diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
41399index 244b19b..c19226d 100644
41400--- a/drivers/gpu/drm/radeon/radeon_irq.c
41401+++ b/drivers/gpu/drm/radeon/radeon_irq.c
41402@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
41403 unsigned int ret;
41404 RING_LOCALS;
41405
41406- atomic_inc(&dev_priv->swi_emitted);
41407- ret = atomic_read(&dev_priv->swi_emitted);
41408+ atomic_inc_unchecked(&dev_priv->swi_emitted);
41409+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
41410
41411 BEGIN_RING(4);
41412 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
41413@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
41414 drm_radeon_private_t *dev_priv =
41415 (drm_radeon_private_t *) dev->dev_private;
41416
41417- atomic_set(&dev_priv->swi_emitted, 0);
41418+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
41419 init_waitqueue_head(&dev_priv->swi_queue);
41420
41421 dev->max_vblank_count = 0x001fffff;
41422diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
41423index 956ab7f..fbd36d8 100644
41424--- a/drivers/gpu/drm/radeon/radeon_state.c
41425+++ b/drivers/gpu/drm/radeon/radeon_state.c
41426@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
41427 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
41428 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
41429
41430- if (copy_from_user(&depth_boxes, clear->depth_boxes,
41431+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || copy_from_user(&depth_boxes, clear->depth_boxes,
41432 sarea_priv->nbox * sizeof(depth_boxes[0])))
41433 return -EFAULT;
41434
41435@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
41436 {
41437 drm_radeon_private_t *dev_priv = dev->dev_private;
41438 drm_radeon_getparam_t *param = data;
41439- int value;
41440+ int value = 0;
41441
41442 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
41443
41444diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
41445index 040a2a1..eae4e54 100644
41446--- a/drivers/gpu/drm/radeon/radeon_ttm.c
41447+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
41448@@ -790,7 +790,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
41449 man->size = size >> PAGE_SHIFT;
41450 }
41451
41452-static struct vm_operations_struct radeon_ttm_vm_ops;
41453+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
41454 static const struct vm_operations_struct *ttm_vm_ops = NULL;
41455
41456 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41457@@ -831,8 +831,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
41458 }
41459 if (unlikely(ttm_vm_ops == NULL)) {
41460 ttm_vm_ops = vma->vm_ops;
41461+ pax_open_kernel();
41462 radeon_ttm_vm_ops = *ttm_vm_ops;
41463 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
41464+ pax_close_kernel();
41465 }
41466 vma->vm_ops = &radeon_ttm_vm_ops;
41467 return 0;
41468diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
41469index 9336006..ce78aa7 100644
41470--- a/drivers/gpu/drm/tegra/dc.c
41471+++ b/drivers/gpu/drm/tegra/dc.c
41472@@ -1057,7 +1057,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
41473 }
41474
41475 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
41476- dc->debugfs_files[i].data = dc;
41477+ *(void **)&dc->debugfs_files[i].data = dc;
41478
41479 err = drm_debugfs_create_files(dc->debugfs_files,
41480 ARRAY_SIZE(debugfs_files),
41481diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c
41482index d452faab..f8cbc6a 100644
41483--- a/drivers/gpu/drm/tegra/dsi.c
41484+++ b/drivers/gpu/drm/tegra/dsi.c
41485@@ -53,7 +53,7 @@ struct tegra_dsi {
41486 struct clk *clk_lp;
41487 struct clk *clk;
41488
41489- struct drm_info_list *debugfs_files;
41490+ drm_info_list_no_const *debugfs_files;
41491 struct drm_minor *minor;
41492 struct dentry *debugfs;
41493
41494diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
41495index 6928015..c9853e7 100644
41496--- a/drivers/gpu/drm/tegra/hdmi.c
41497+++ b/drivers/gpu/drm/tegra/hdmi.c
41498@@ -59,7 +59,7 @@ struct tegra_hdmi {
41499 bool stereo;
41500 bool dvi;
41501
41502- struct drm_info_list *debugfs_files;
41503+ drm_info_list_no_const *debugfs_files;
41504 struct drm_minor *minor;
41505 struct dentry *debugfs;
41506 };
41507diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41508index c58eba33..83c2728 100644
41509--- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
41510+++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41511@@ -141,10 +141,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
41512 }
41513
41514 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
41515- ttm_bo_man_init,
41516- ttm_bo_man_takedown,
41517- ttm_bo_man_get_node,
41518- ttm_bo_man_put_node,
41519- ttm_bo_man_debug
41520+ .init = ttm_bo_man_init,
41521+ .takedown = ttm_bo_man_takedown,
41522+ .get_node = ttm_bo_man_get_node,
41523+ .put_node = ttm_bo_man_put_node,
41524+ .debug = ttm_bo_man_debug
41525 };
41526 EXPORT_SYMBOL(ttm_bo_manager_func);
41527diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
41528index dbc2def..0a9f710 100644
41529--- a/drivers/gpu/drm/ttm/ttm_memory.c
41530+++ b/drivers/gpu/drm/ttm/ttm_memory.c
41531@@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
41532 zone->glob = glob;
41533 glob->zone_kernel = zone;
41534 ret = kobject_init_and_add(
41535- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41536+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41537 if (unlikely(ret != 0)) {
41538 kobject_put(&zone->kobj);
41539 return ret;
41540@@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
41541 zone->glob = glob;
41542 glob->zone_dma32 = zone;
41543 ret = kobject_init_and_add(
41544- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41545+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41546 if (unlikely(ret != 0)) {
41547 kobject_put(&zone->kobj);
41548 return ret;
41549diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41550index 863bef9..cba15cf 100644
41551--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
41552+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41553@@ -391,9 +391,9 @@ out:
41554 static unsigned long
41555 ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41556 {
41557- static atomic_t start_pool = ATOMIC_INIT(0);
41558+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
41559 unsigned i;
41560- unsigned pool_offset = atomic_add_return(1, &start_pool);
41561+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
41562 struct ttm_page_pool *pool;
41563 int shrink_pages = sc->nr_to_scan;
41564 unsigned long freed = 0;
41565diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
41566index dbadd49..1b7457b 100644
41567--- a/drivers/gpu/drm/udl/udl_fb.c
41568+++ b/drivers/gpu/drm/udl/udl_fb.c
41569@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
41570 fb_deferred_io_cleanup(info);
41571 kfree(info->fbdefio);
41572 info->fbdefio = NULL;
41573- info->fbops->fb_mmap = udl_fb_mmap;
41574 }
41575
41576 pr_warn("released /dev/fb%d user=%d count=%d\n",
41577diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
41578index ad02732..144f5ed 100644
41579--- a/drivers/gpu/drm/via/via_drv.h
41580+++ b/drivers/gpu/drm/via/via_drv.h
41581@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
41582 typedef uint32_t maskarray_t[5];
41583
41584 typedef struct drm_via_irq {
41585- atomic_t irq_received;
41586+ atomic_unchecked_t irq_received;
41587 uint32_t pending_mask;
41588 uint32_t enable_mask;
41589 wait_queue_head_t irq_queue;
41590@@ -75,7 +75,7 @@ typedef struct drm_via_private {
41591 struct timeval last_vblank;
41592 int last_vblank_valid;
41593 unsigned usec_per_vblank;
41594- atomic_t vbl_received;
41595+ atomic_unchecked_t vbl_received;
41596 drm_via_state_t hc_state;
41597 char pci_buf[VIA_PCI_BUF_SIZE];
41598 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
41599diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
41600index 1319433..a993b0c 100644
41601--- a/drivers/gpu/drm/via/via_irq.c
41602+++ b/drivers/gpu/drm/via/via_irq.c
41603@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
41604 if (crtc != 0)
41605 return 0;
41606
41607- return atomic_read(&dev_priv->vbl_received);
41608+ return atomic_read_unchecked(&dev_priv->vbl_received);
41609 }
41610
41611 irqreturn_t via_driver_irq_handler(int irq, void *arg)
41612@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41613
41614 status = VIA_READ(VIA_REG_INTERRUPT);
41615 if (status & VIA_IRQ_VBLANK_PENDING) {
41616- atomic_inc(&dev_priv->vbl_received);
41617- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
41618+ atomic_inc_unchecked(&dev_priv->vbl_received);
41619+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
41620 do_gettimeofday(&cur_vblank);
41621 if (dev_priv->last_vblank_valid) {
41622 dev_priv->usec_per_vblank =
41623@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41624 dev_priv->last_vblank = cur_vblank;
41625 dev_priv->last_vblank_valid = 1;
41626 }
41627- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
41628+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
41629 DRM_DEBUG("US per vblank is: %u\n",
41630 dev_priv->usec_per_vblank);
41631 }
41632@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41633
41634 for (i = 0; i < dev_priv->num_irqs; ++i) {
41635 if (status & cur_irq->pending_mask) {
41636- atomic_inc(&cur_irq->irq_received);
41637+ atomic_inc_unchecked(&cur_irq->irq_received);
41638 wake_up(&cur_irq->irq_queue);
41639 handled = 1;
41640 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
41641@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
41642 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41643 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
41644 masks[irq][4]));
41645- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
41646+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
41647 } else {
41648 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41649 (((cur_irq_sequence =
41650- atomic_read(&cur_irq->irq_received)) -
41651+ atomic_read_unchecked(&cur_irq->irq_received)) -
41652 *sequence) <= (1 << 23)));
41653 }
41654 *sequence = cur_irq_sequence;
41655@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
41656 }
41657
41658 for (i = 0; i < dev_priv->num_irqs; ++i) {
41659- atomic_set(&cur_irq->irq_received, 0);
41660+ atomic_set_unchecked(&cur_irq->irq_received, 0);
41661 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
41662 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
41663 init_waitqueue_head(&cur_irq->irq_queue);
41664@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
41665 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
41666 case VIA_IRQ_RELATIVE:
41667 irqwait->request.sequence +=
41668- atomic_read(&cur_irq->irq_received);
41669+ atomic_read_unchecked(&cur_irq->irq_received);
41670 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
41671 case VIA_IRQ_ABSOLUTE:
41672 break;
41673diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41674index 0783155..b29e18e 100644
41675--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41676+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41677@@ -437,7 +437,7 @@ struct vmw_private {
41678 * Fencing and IRQs.
41679 */
41680
41681- atomic_t marker_seq;
41682+ atomic_unchecked_t marker_seq;
41683 wait_queue_head_t fence_queue;
41684 wait_queue_head_t fifo_queue;
41685 int fence_queue_waiters; /* Protected by hw_mutex */
41686diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41687index 6ccd993..618d592 100644
41688--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41689+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41690@@ -154,7 +154,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
41691 (unsigned int) min,
41692 (unsigned int) fifo->capabilities);
41693
41694- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41695+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41696 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
41697 vmw_marker_queue_init(&fifo->marker_queue);
41698 return vmw_fifo_send_fence(dev_priv, &dummy);
41699@@ -372,7 +372,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
41700 if (reserveable)
41701 iowrite32(bytes, fifo_mem +
41702 SVGA_FIFO_RESERVED);
41703- return fifo_mem + (next_cmd >> 2);
41704+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
41705 } else {
41706 need_bounce = true;
41707 }
41708@@ -492,7 +492,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41709
41710 fm = vmw_fifo_reserve(dev_priv, bytes);
41711 if (unlikely(fm == NULL)) {
41712- *seqno = atomic_read(&dev_priv->marker_seq);
41713+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41714 ret = -ENOMEM;
41715 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
41716 false, 3*HZ);
41717@@ -500,7 +500,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41718 }
41719
41720 do {
41721- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
41722+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
41723 } while (*seqno == 0);
41724
41725 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
41726diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41727index b1273e8..9c274fd 100644
41728--- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41729+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41730@@ -164,9 +164,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
41731 }
41732
41733 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
41734- vmw_gmrid_man_init,
41735- vmw_gmrid_man_takedown,
41736- vmw_gmrid_man_get_node,
41737- vmw_gmrid_man_put_node,
41738- vmw_gmrid_man_debug
41739+ .init = vmw_gmrid_man_init,
41740+ .takedown = vmw_gmrid_man_takedown,
41741+ .get_node = vmw_gmrid_man_get_node,
41742+ .put_node = vmw_gmrid_man_put_node,
41743+ .debug = vmw_gmrid_man_debug
41744 };
41745diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41746index 47b7094..698ba09 100644
41747--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41748+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41749@@ -236,7 +236,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
41750 int ret;
41751
41752 num_clips = arg->num_clips;
41753- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41754+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41755
41756 if (unlikely(num_clips == 0))
41757 return 0;
41758@@ -320,7 +320,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
41759 int ret;
41760
41761 num_clips = arg->num_clips;
41762- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41763+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41764
41765 if (unlikely(num_clips == 0))
41766 return 0;
41767diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41768index 0c42376..6febe77 100644
41769--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41770+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41771@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
41772 * emitted. Then the fence is stale and signaled.
41773 */
41774
41775- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
41776+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
41777 > VMW_FENCE_WRAP);
41778
41779 return ret;
41780@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
41781
41782 if (fifo_idle)
41783 down_read(&fifo_state->rwsem);
41784- signal_seq = atomic_read(&dev_priv->marker_seq);
41785+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
41786 ret = 0;
41787
41788 for (;;) {
41789diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41790index 8a8725c2..afed796 100644
41791--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41792+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41793@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
41794 while (!vmw_lag_lt(queue, us)) {
41795 spin_lock(&queue->lock);
41796 if (list_empty(&queue->head))
41797- seqno = atomic_read(&dev_priv->marker_seq);
41798+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41799 else {
41800 marker = list_first_entry(&queue->head,
41801 struct vmw_marker, head);
41802diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
41803index ec0ae2d..dc0780b 100644
41804--- a/drivers/gpu/vga/vga_switcheroo.c
41805+++ b/drivers/gpu/vga/vga_switcheroo.c
41806@@ -643,7 +643,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
41807
41808 /* this version is for the case where the power switch is separate
41809 to the device being powered down. */
41810-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
41811+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
41812 {
41813 /* copy over all the bus versions */
41814 if (dev->bus && dev->bus->pm) {
41815@@ -688,7 +688,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
41816 return ret;
41817 }
41818
41819-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
41820+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
41821 {
41822 /* copy over all the bus versions */
41823 if (dev->bus && dev->bus->pm) {
41824diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
41825index cc32a6f..02a4b1c 100644
41826--- a/drivers/hid/hid-core.c
41827+++ b/drivers/hid/hid-core.c
41828@@ -2421,7 +2421,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
41829
41830 int hid_add_device(struct hid_device *hdev)
41831 {
41832- static atomic_t id = ATOMIC_INIT(0);
41833+ static atomic_unchecked_t id = ATOMIC_INIT(0);
41834 int ret;
41835
41836 if (WARN_ON(hdev->status & HID_STAT_ADDED))
41837@@ -2455,7 +2455,7 @@ int hid_add_device(struct hid_device *hdev)
41838 /* XXX hack, any other cleaner solution after the driver core
41839 * is converted to allow more than 20 bytes as the device name? */
41840 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
41841- hdev->vendor, hdev->product, atomic_inc_return(&id));
41842+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
41843
41844 hid_debug_register(hdev, dev_name(&hdev->dev));
41845 ret = device_add(&hdev->dev);
41846diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
41847index c13fb5b..55a3802 100644
41848--- a/drivers/hid/hid-wiimote-debug.c
41849+++ b/drivers/hid/hid-wiimote-debug.c
41850@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
41851 else if (size == 0)
41852 return -EIO;
41853
41854- if (copy_to_user(u, buf, size))
41855+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
41856 return -EFAULT;
41857
41858 *off += size;
41859diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
41860index cedc6da..2c3da2a 100644
41861--- a/drivers/hid/uhid.c
41862+++ b/drivers/hid/uhid.c
41863@@ -47,7 +47,7 @@ struct uhid_device {
41864 struct mutex report_lock;
41865 wait_queue_head_t report_wait;
41866 atomic_t report_done;
41867- atomic_t report_id;
41868+ atomic_unchecked_t report_id;
41869 struct uhid_event report_buf;
41870 };
41871
41872@@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
41873
41874 spin_lock_irqsave(&uhid->qlock, flags);
41875 ev->type = UHID_FEATURE;
41876- ev->u.feature.id = atomic_inc_return(&uhid->report_id);
41877+ ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
41878 ev->u.feature.rnum = rnum;
41879 ev->u.feature.rtype = report_type;
41880
41881@@ -446,7 +446,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
41882 spin_lock_irqsave(&uhid->qlock, flags);
41883
41884 /* id for old report; drop it silently */
41885- if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
41886+ if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
41887 goto unlock;
41888 if (atomic_read(&uhid->report_done))
41889 goto unlock;
41890diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
41891index 69ea36f..8dbf4bb 100644
41892--- a/drivers/hv/channel.c
41893+++ b/drivers/hv/channel.c
41894@@ -364,8 +364,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
41895 int ret = 0;
41896 int t;
41897
41898- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
41899- atomic_inc(&vmbus_connection.next_gpadl_handle);
41900+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
41901+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
41902
41903 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
41904 if (ret)
41905diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
41906index bcb4950..61dba6c 100644
41907--- a/drivers/hv/hv.c
41908+++ b/drivers/hv/hv.c
41909@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
41910 u64 output_address = (output) ? virt_to_phys(output) : 0;
41911 u32 output_address_hi = output_address >> 32;
41912 u32 output_address_lo = output_address & 0xFFFFFFFF;
41913- void *hypercall_page = hv_context.hypercall_page;
41914+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
41915
41916 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
41917 "=a"(hv_status_lo) : "d" (control_hi),
41918@@ -154,7 +154,7 @@ int hv_init(void)
41919 /* See if the hypercall page is already set */
41920 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
41921
41922- virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
41923+ virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
41924
41925 if (!virtaddr)
41926 goto cleanup;
41927diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
41928index 7e17a54..a50a33d 100644
41929--- a/drivers/hv/hv_balloon.c
41930+++ b/drivers/hv/hv_balloon.c
41931@@ -464,7 +464,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
41932
41933 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
41934 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
41935-static atomic_t trans_id = ATOMIC_INIT(0);
41936+static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
41937
41938 static int dm_ring_size = (5 * PAGE_SIZE);
41939
41940@@ -886,7 +886,7 @@ static void hot_add_req(struct work_struct *dummy)
41941 pr_info("Memory hot add failed\n");
41942
41943 dm->state = DM_INITIALIZED;
41944- resp.hdr.trans_id = atomic_inc_return(&trans_id);
41945+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41946 vmbus_sendpacket(dm->dev->channel, &resp,
41947 sizeof(struct dm_hot_add_response),
41948 (unsigned long)NULL,
41949@@ -960,7 +960,7 @@ static void post_status(struct hv_dynmem_device *dm)
41950 memset(&status, 0, sizeof(struct dm_status));
41951 status.hdr.type = DM_STATUS_REPORT;
41952 status.hdr.size = sizeof(struct dm_status);
41953- status.hdr.trans_id = atomic_inc_return(&trans_id);
41954+ status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41955
41956 /*
41957 * The host expects the guest to report free memory.
41958@@ -980,7 +980,7 @@ static void post_status(struct hv_dynmem_device *dm)
41959 * send the status. This can happen if we were interrupted
41960 * after we picked our transaction ID.
41961 */
41962- if (status.hdr.trans_id != atomic_read(&trans_id))
41963+ if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
41964 return;
41965
41966 vmbus_sendpacket(dm->dev->channel, &status,
41967@@ -1108,7 +1108,7 @@ static void balloon_up(struct work_struct *dummy)
41968 */
41969
41970 do {
41971- bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
41972+ bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41973 ret = vmbus_sendpacket(dm_device.dev->channel,
41974 bl_resp,
41975 bl_resp->hdr.size,
41976@@ -1152,7 +1152,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
41977
41978 memset(&resp, 0, sizeof(struct dm_unballoon_response));
41979 resp.hdr.type = DM_UNBALLOON_RESPONSE;
41980- resp.hdr.trans_id = atomic_inc_return(&trans_id);
41981+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41982 resp.hdr.size = sizeof(struct dm_unballoon_response);
41983
41984 vmbus_sendpacket(dm_device.dev->channel, &resp,
41985@@ -1215,7 +1215,7 @@ static void version_resp(struct hv_dynmem_device *dm,
41986 memset(&version_req, 0, sizeof(struct dm_version_request));
41987 version_req.hdr.type = DM_VERSION_REQUEST;
41988 version_req.hdr.size = sizeof(struct dm_version_request);
41989- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41990+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41991 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
41992 version_req.is_last_attempt = 1;
41993
41994@@ -1385,7 +1385,7 @@ static int balloon_probe(struct hv_device *dev,
41995 memset(&version_req, 0, sizeof(struct dm_version_request));
41996 version_req.hdr.type = DM_VERSION_REQUEST;
41997 version_req.hdr.size = sizeof(struct dm_version_request);
41998- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41999+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42000 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
42001 version_req.is_last_attempt = 0;
42002
42003@@ -1416,7 +1416,7 @@ static int balloon_probe(struct hv_device *dev,
42004 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
42005 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
42006 cap_msg.hdr.size = sizeof(struct dm_capabilities);
42007- cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
42008+ cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42009
42010 cap_msg.caps.cap_bits.balloon = 1;
42011 cap_msg.caps.cap_bits.hot_add = 1;
42012diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
42013index e055176..c22ff1f 100644
42014--- a/drivers/hv/hyperv_vmbus.h
42015+++ b/drivers/hv/hyperv_vmbus.h
42016@@ -602,7 +602,7 @@ enum vmbus_connect_state {
42017 struct vmbus_connection {
42018 enum vmbus_connect_state conn_state;
42019
42020- atomic_t next_gpadl_handle;
42021+ atomic_unchecked_t next_gpadl_handle;
42022
42023 /*
42024 * Represents channel interrupts. Each bit position represents a
42025diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
42026index 077bb1b..d433d74 100644
42027--- a/drivers/hv/vmbus_drv.c
42028+++ b/drivers/hv/vmbus_drv.c
42029@@ -844,10 +844,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
42030 {
42031 int ret = 0;
42032
42033- static atomic_t device_num = ATOMIC_INIT(0);
42034+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
42035
42036 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
42037- atomic_inc_return(&device_num));
42038+ atomic_inc_return_unchecked(&device_num));
42039
42040 child_device_obj->device.bus = &hv_bus;
42041 child_device_obj->device.parent = &hv_acpi_dev->dev;
42042diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
42043index 579bdf9..75118b5 100644
42044--- a/drivers/hwmon/acpi_power_meter.c
42045+++ b/drivers/hwmon/acpi_power_meter.c
42046@@ -116,7 +116,7 @@ struct sensor_template {
42047 struct device_attribute *devattr,
42048 const char *buf, size_t count);
42049 int index;
42050-};
42051+} __do_const;
42052
42053 /* Averaging interval */
42054 static int update_avg_interval(struct acpi_power_meter_resource *resource)
42055@@ -631,7 +631,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
42056 struct sensor_template *attrs)
42057 {
42058 struct device *dev = &resource->acpi_dev->dev;
42059- struct sensor_device_attribute *sensors =
42060+ sensor_device_attribute_no_const *sensors =
42061 &resource->sensors[resource->num_sensors];
42062 int res = 0;
42063
42064diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
42065index 3288f13..71cfb4e 100644
42066--- a/drivers/hwmon/applesmc.c
42067+++ b/drivers/hwmon/applesmc.c
42068@@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
42069 {
42070 struct applesmc_node_group *grp;
42071 struct applesmc_dev_attr *node;
42072- struct attribute *attr;
42073+ attribute_no_const *attr;
42074 int ret, i;
42075
42076 for (grp = groups; grp->format; grp++) {
42077diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
42078index ae208f6..48b6c5b 100644
42079--- a/drivers/hwmon/asus_atk0110.c
42080+++ b/drivers/hwmon/asus_atk0110.c
42081@@ -147,10 +147,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
42082 struct atk_sensor_data {
42083 struct list_head list;
42084 struct atk_data *data;
42085- struct device_attribute label_attr;
42086- struct device_attribute input_attr;
42087- struct device_attribute limit1_attr;
42088- struct device_attribute limit2_attr;
42089+ device_attribute_no_const label_attr;
42090+ device_attribute_no_const input_attr;
42091+ device_attribute_no_const limit1_attr;
42092+ device_attribute_no_const limit2_attr;
42093 char label_attr_name[ATTR_NAME_SIZE];
42094 char input_attr_name[ATTR_NAME_SIZE];
42095 char limit1_attr_name[ATTR_NAME_SIZE];
42096@@ -270,7 +270,7 @@ static ssize_t atk_name_show(struct device *dev,
42097 static struct device_attribute atk_name_attr =
42098 __ATTR(name, 0444, atk_name_show, NULL);
42099
42100-static void atk_init_attribute(struct device_attribute *attr, char *name,
42101+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
42102 sysfs_show_func show)
42103 {
42104 sysfs_attr_init(&attr->attr);
42105diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
42106index bbb0b0d..9fe1332 100644
42107--- a/drivers/hwmon/coretemp.c
42108+++ b/drivers/hwmon/coretemp.c
42109@@ -823,7 +823,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
42110 return NOTIFY_OK;
42111 }
42112
42113-static struct notifier_block coretemp_cpu_notifier __refdata = {
42114+static struct notifier_block coretemp_cpu_notifier = {
42115 .notifier_call = coretemp_cpu_callback,
42116 };
42117
42118diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
42119index 632f1dc..57e6a58 100644
42120--- a/drivers/hwmon/ibmaem.c
42121+++ b/drivers/hwmon/ibmaem.c
42122@@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
42123 struct aem_rw_sensor_template *rw)
42124 {
42125 struct device *dev = &data->pdev->dev;
42126- struct sensor_device_attribute *sensors = data->sensors;
42127+ sensor_device_attribute_no_const *sensors = data->sensors;
42128 int err;
42129
42130 /* Set up read-only sensors */
42131diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
42132index 708081b..fe2d4ab 100644
42133--- a/drivers/hwmon/iio_hwmon.c
42134+++ b/drivers/hwmon/iio_hwmon.c
42135@@ -73,7 +73,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
42136 {
42137 struct device *dev = &pdev->dev;
42138 struct iio_hwmon_state *st;
42139- struct sensor_device_attribute *a;
42140+ sensor_device_attribute_no_const *a;
42141 int ret, i;
42142 int in_i = 1, temp_i = 1, curr_i = 1;
42143 enum iio_chan_type type;
42144diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
42145index 38d5a63..cf2c2ea 100644
42146--- a/drivers/hwmon/nct6775.c
42147+++ b/drivers/hwmon/nct6775.c
42148@@ -944,10 +944,10 @@ static struct attribute_group *
42149 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
42150 int repeat)
42151 {
42152- struct attribute_group *group;
42153+ attribute_group_no_const *group;
42154 struct sensor_device_attr_u *su;
42155- struct sensor_device_attribute *a;
42156- struct sensor_device_attribute_2 *a2;
42157+ sensor_device_attribute_no_const *a;
42158+ sensor_device_attribute_2_no_const *a2;
42159 struct attribute **attrs;
42160 struct sensor_device_template **t;
42161 int i, count;
42162diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
42163index 291d11f..3f0dbbd 100644
42164--- a/drivers/hwmon/pmbus/pmbus_core.c
42165+++ b/drivers/hwmon/pmbus/pmbus_core.c
42166@@ -783,7 +783,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
42167 return 0;
42168 }
42169
42170-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
42171+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
42172 const char *name,
42173 umode_t mode,
42174 ssize_t (*show)(struct device *dev,
42175@@ -800,7 +800,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
42176 dev_attr->store = store;
42177 }
42178
42179-static void pmbus_attr_init(struct sensor_device_attribute *a,
42180+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
42181 const char *name,
42182 umode_t mode,
42183 ssize_t (*show)(struct device *dev,
42184@@ -822,7 +822,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
42185 u16 reg, u8 mask)
42186 {
42187 struct pmbus_boolean *boolean;
42188- struct sensor_device_attribute *a;
42189+ sensor_device_attribute_no_const *a;
42190
42191 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
42192 if (!boolean)
42193@@ -847,7 +847,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
42194 bool update, bool readonly)
42195 {
42196 struct pmbus_sensor *sensor;
42197- struct device_attribute *a;
42198+ device_attribute_no_const *a;
42199
42200 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
42201 if (!sensor)
42202@@ -878,7 +878,7 @@ static int pmbus_add_label(struct pmbus_data *data,
42203 const char *lstring, int index)
42204 {
42205 struct pmbus_label *label;
42206- struct device_attribute *a;
42207+ device_attribute_no_const *a;
42208
42209 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
42210 if (!label)
42211diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
42212index 97cd45a..ac54d8b 100644
42213--- a/drivers/hwmon/sht15.c
42214+++ b/drivers/hwmon/sht15.c
42215@@ -169,7 +169,7 @@ struct sht15_data {
42216 int supply_uv;
42217 bool supply_uv_valid;
42218 struct work_struct update_supply_work;
42219- atomic_t interrupt_handled;
42220+ atomic_unchecked_t interrupt_handled;
42221 };
42222
42223 /**
42224@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
42225 ret = gpio_direction_input(data->pdata->gpio_data);
42226 if (ret)
42227 return ret;
42228- atomic_set(&data->interrupt_handled, 0);
42229+ atomic_set_unchecked(&data->interrupt_handled, 0);
42230
42231 enable_irq(gpio_to_irq(data->pdata->gpio_data));
42232 if (gpio_get_value(data->pdata->gpio_data) == 0) {
42233 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
42234 /* Only relevant if the interrupt hasn't occurred. */
42235- if (!atomic_read(&data->interrupt_handled))
42236+ if (!atomic_read_unchecked(&data->interrupt_handled))
42237 schedule_work(&data->read_work);
42238 }
42239 ret = wait_event_timeout(data->wait_queue,
42240@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
42241
42242 /* First disable the interrupt */
42243 disable_irq_nosync(irq);
42244- atomic_inc(&data->interrupt_handled);
42245+ atomic_inc_unchecked(&data->interrupt_handled);
42246 /* Then schedule a reading work struct */
42247 if (data->state != SHT15_READING_NOTHING)
42248 schedule_work(&data->read_work);
42249@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
42250 * If not, then start the interrupt again - care here as could
42251 * have gone low in meantime so verify it hasn't!
42252 */
42253- atomic_set(&data->interrupt_handled, 0);
42254+ atomic_set_unchecked(&data->interrupt_handled, 0);
42255 enable_irq(gpio_to_irq(data->pdata->gpio_data));
42256 /* If still not occurred or another handler was scheduled */
42257 if (gpio_get_value(data->pdata->gpio_data)
42258- || atomic_read(&data->interrupt_handled))
42259+ || atomic_read_unchecked(&data->interrupt_handled))
42260 return;
42261 }
42262
42263diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
42264index 38944e9..ae9e5ed 100644
42265--- a/drivers/hwmon/via-cputemp.c
42266+++ b/drivers/hwmon/via-cputemp.c
42267@@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
42268 return NOTIFY_OK;
42269 }
42270
42271-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
42272+static struct notifier_block via_cputemp_cpu_notifier = {
42273 .notifier_call = via_cputemp_cpu_callback,
42274 };
42275
42276diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
42277index 41fc683..a39cfea 100644
42278--- a/drivers/i2c/busses/i2c-amd756-s4882.c
42279+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
42280@@ -43,7 +43,7 @@
42281 extern struct i2c_adapter amd756_smbus;
42282
42283 static struct i2c_adapter *s4882_adapter;
42284-static struct i2c_algorithm *s4882_algo;
42285+static i2c_algorithm_no_const *s4882_algo;
42286
42287 /* Wrapper access functions for multiplexed SMBus */
42288 static DEFINE_MUTEX(amd756_lock);
42289diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
42290index 721f7eb..0fd2a09 100644
42291--- a/drivers/i2c/busses/i2c-diolan-u2c.c
42292+++ b/drivers/i2c/busses/i2c-diolan-u2c.c
42293@@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
42294 /* usb layer */
42295
42296 /* Send command to device, and get response. */
42297-static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
42298+static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
42299 {
42300 int ret = 0;
42301 int actual;
42302diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
42303index b170bdf..3c76427 100644
42304--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
42305+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
42306@@ -41,7 +41,7 @@
42307 extern struct i2c_adapter *nforce2_smbus;
42308
42309 static struct i2c_adapter *s4985_adapter;
42310-static struct i2c_algorithm *s4985_algo;
42311+static i2c_algorithm_no_const *s4985_algo;
42312
42313 /* Wrapper access functions for multiplexed SMBus */
42314 static DEFINE_MUTEX(nforce2_lock);
42315diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
42316index 80b47e8..1a6040d9 100644
42317--- a/drivers/i2c/i2c-dev.c
42318+++ b/drivers/i2c/i2c-dev.c
42319@@ -277,7 +277,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
42320 break;
42321 }
42322
42323- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
42324+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
42325 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
42326 if (IS_ERR(rdwr_pa[i].buf)) {
42327 res = PTR_ERR(rdwr_pa[i].buf);
42328diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
42329index 0b510ba..4fbb5085 100644
42330--- a/drivers/ide/ide-cd.c
42331+++ b/drivers/ide/ide-cd.c
42332@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
42333 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
42334 if ((unsigned long)buf & alignment
42335 || blk_rq_bytes(rq) & q->dma_pad_mask
42336- || object_is_on_stack(buf))
42337+ || object_starts_on_stack(buf))
42338 drive->dma = 0;
42339 }
42340 }
42341diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
42342index acc911a..8700c3c 100644
42343--- a/drivers/iio/industrialio-core.c
42344+++ b/drivers/iio/industrialio-core.c
42345@@ -527,7 +527,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
42346 }
42347
42348 static
42349-int __iio_device_attr_init(struct device_attribute *dev_attr,
42350+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
42351 const char *postfix,
42352 struct iio_chan_spec const *chan,
42353 ssize_t (*readfunc)(struct device *dev,
42354diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
42355index c323917..6ddea8b 100644
42356--- a/drivers/infiniband/core/cm.c
42357+++ b/drivers/infiniband/core/cm.c
42358@@ -115,7 +115,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
42359
42360 struct cm_counter_group {
42361 struct kobject obj;
42362- atomic_long_t counter[CM_ATTR_COUNT];
42363+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
42364 };
42365
42366 struct cm_counter_attribute {
42367@@ -1398,7 +1398,7 @@ static void cm_dup_req_handler(struct cm_work *work,
42368 struct ib_mad_send_buf *msg = NULL;
42369 int ret;
42370
42371- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42372+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42373 counter[CM_REQ_COUNTER]);
42374
42375 /* Quick state check to discard duplicate REQs. */
42376@@ -1785,7 +1785,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
42377 if (!cm_id_priv)
42378 return;
42379
42380- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42381+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42382 counter[CM_REP_COUNTER]);
42383 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
42384 if (ret)
42385@@ -1952,7 +1952,7 @@ static int cm_rtu_handler(struct cm_work *work)
42386 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
42387 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
42388 spin_unlock_irq(&cm_id_priv->lock);
42389- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42390+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42391 counter[CM_RTU_COUNTER]);
42392 goto out;
42393 }
42394@@ -2135,7 +2135,7 @@ static int cm_dreq_handler(struct cm_work *work)
42395 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
42396 dreq_msg->local_comm_id);
42397 if (!cm_id_priv) {
42398- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42399+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42400 counter[CM_DREQ_COUNTER]);
42401 cm_issue_drep(work->port, work->mad_recv_wc);
42402 return -EINVAL;
42403@@ -2160,7 +2160,7 @@ static int cm_dreq_handler(struct cm_work *work)
42404 case IB_CM_MRA_REP_RCVD:
42405 break;
42406 case IB_CM_TIMEWAIT:
42407- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42408+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42409 counter[CM_DREQ_COUNTER]);
42410 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42411 goto unlock;
42412@@ -2174,7 +2174,7 @@ static int cm_dreq_handler(struct cm_work *work)
42413 cm_free_msg(msg);
42414 goto deref;
42415 case IB_CM_DREQ_RCVD:
42416- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42417+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42418 counter[CM_DREQ_COUNTER]);
42419 goto unlock;
42420 default:
42421@@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
42422 ib_modify_mad(cm_id_priv->av.port->mad_agent,
42423 cm_id_priv->msg, timeout)) {
42424 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
42425- atomic_long_inc(&work->port->
42426+ atomic_long_inc_unchecked(&work->port->
42427 counter_group[CM_RECV_DUPLICATES].
42428 counter[CM_MRA_COUNTER]);
42429 goto out;
42430@@ -2550,7 +2550,7 @@ static int cm_mra_handler(struct cm_work *work)
42431 break;
42432 case IB_CM_MRA_REQ_RCVD:
42433 case IB_CM_MRA_REP_RCVD:
42434- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42435+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42436 counter[CM_MRA_COUNTER]);
42437 /* fall through */
42438 default:
42439@@ -2712,7 +2712,7 @@ static int cm_lap_handler(struct cm_work *work)
42440 case IB_CM_LAP_IDLE:
42441 break;
42442 case IB_CM_MRA_LAP_SENT:
42443- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42444+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42445 counter[CM_LAP_COUNTER]);
42446 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42447 goto unlock;
42448@@ -2728,7 +2728,7 @@ static int cm_lap_handler(struct cm_work *work)
42449 cm_free_msg(msg);
42450 goto deref;
42451 case IB_CM_LAP_RCVD:
42452- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42453+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42454 counter[CM_LAP_COUNTER]);
42455 goto unlock;
42456 default:
42457@@ -3012,7 +3012,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
42458 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
42459 if (cur_cm_id_priv) {
42460 spin_unlock_irq(&cm.lock);
42461- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42462+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42463 counter[CM_SIDR_REQ_COUNTER]);
42464 goto out; /* Duplicate message. */
42465 }
42466@@ -3224,10 +3224,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
42467 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
42468 msg->retries = 1;
42469
42470- atomic_long_add(1 + msg->retries,
42471+ atomic_long_add_unchecked(1 + msg->retries,
42472 &port->counter_group[CM_XMIT].counter[attr_index]);
42473 if (msg->retries)
42474- atomic_long_add(msg->retries,
42475+ atomic_long_add_unchecked(msg->retries,
42476 &port->counter_group[CM_XMIT_RETRIES].
42477 counter[attr_index]);
42478
42479@@ -3437,7 +3437,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
42480 }
42481
42482 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
42483- atomic_long_inc(&port->counter_group[CM_RECV].
42484+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
42485 counter[attr_id - CM_ATTR_ID_OFFSET]);
42486
42487 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
42488@@ -3668,7 +3668,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
42489 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
42490
42491 return sprintf(buf, "%ld\n",
42492- atomic_long_read(&group->counter[cm_attr->index]));
42493+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
42494 }
42495
42496 static const struct sysfs_ops cm_counter_ops = {
42497diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
42498index 9f5ad7c..588cd84 100644
42499--- a/drivers/infiniband/core/fmr_pool.c
42500+++ b/drivers/infiniband/core/fmr_pool.c
42501@@ -98,8 +98,8 @@ struct ib_fmr_pool {
42502
42503 struct task_struct *thread;
42504
42505- atomic_t req_ser;
42506- atomic_t flush_ser;
42507+ atomic_unchecked_t req_ser;
42508+ atomic_unchecked_t flush_ser;
42509
42510 wait_queue_head_t force_wait;
42511 };
42512@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42513 struct ib_fmr_pool *pool = pool_ptr;
42514
42515 do {
42516- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
42517+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
42518 ib_fmr_batch_release(pool);
42519
42520- atomic_inc(&pool->flush_ser);
42521+ atomic_inc_unchecked(&pool->flush_ser);
42522 wake_up_interruptible(&pool->force_wait);
42523
42524 if (pool->flush_function)
42525@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42526 }
42527
42528 set_current_state(TASK_INTERRUPTIBLE);
42529- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
42530+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
42531 !kthread_should_stop())
42532 schedule();
42533 __set_current_state(TASK_RUNNING);
42534@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
42535 pool->dirty_watermark = params->dirty_watermark;
42536 pool->dirty_len = 0;
42537 spin_lock_init(&pool->pool_lock);
42538- atomic_set(&pool->req_ser, 0);
42539- atomic_set(&pool->flush_ser, 0);
42540+ atomic_set_unchecked(&pool->req_ser, 0);
42541+ atomic_set_unchecked(&pool->flush_ser, 0);
42542 init_waitqueue_head(&pool->force_wait);
42543
42544 pool->thread = kthread_run(ib_fmr_cleanup_thread,
42545@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
42546 }
42547 spin_unlock_irq(&pool->pool_lock);
42548
42549- serial = atomic_inc_return(&pool->req_ser);
42550+ serial = atomic_inc_return_unchecked(&pool->req_ser);
42551 wake_up_process(pool->thread);
42552
42553 if (wait_event_interruptible(pool->force_wait,
42554- atomic_read(&pool->flush_ser) - serial >= 0))
42555+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
42556 return -EINTR;
42557
42558 return 0;
42559@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
42560 } else {
42561 list_add_tail(&fmr->list, &pool->dirty_list);
42562 if (++pool->dirty_len >= pool->dirty_watermark) {
42563- atomic_inc(&pool->req_ser);
42564+ atomic_inc_unchecked(&pool->req_ser);
42565 wake_up_process(pool->thread);
42566 }
42567 }
42568diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
42569index 41b1195..27971a0 100644
42570--- a/drivers/infiniband/hw/cxgb4/mem.c
42571+++ b/drivers/infiniband/hw/cxgb4/mem.c
42572@@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42573 int err;
42574 struct fw_ri_tpte tpt;
42575 u32 stag_idx;
42576- static atomic_t key;
42577+ static atomic_unchecked_t key;
42578
42579 if (c4iw_fatal_error(rdev))
42580 return -EIO;
42581@@ -266,7 +266,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42582 if (rdev->stats.stag.cur > rdev->stats.stag.max)
42583 rdev->stats.stag.max = rdev->stats.stag.cur;
42584 mutex_unlock(&rdev->stats.lock);
42585- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
42586+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
42587 }
42588 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
42589 __func__, stag_state, type, pdid, stag_idx);
42590diff --git a/drivers/infiniband/hw/ipath/ipath_dma.c b/drivers/infiniband/hw/ipath/ipath_dma.c
42591index 644c2c7..ecf0879 100644
42592--- a/drivers/infiniband/hw/ipath/ipath_dma.c
42593+++ b/drivers/infiniband/hw/ipath/ipath_dma.c
42594@@ -176,17 +176,17 @@ static void ipath_dma_free_coherent(struct ib_device *dev, size_t size,
42595 }
42596
42597 struct ib_dma_mapping_ops ipath_dma_mapping_ops = {
42598- ipath_mapping_error,
42599- ipath_dma_map_single,
42600- ipath_dma_unmap_single,
42601- ipath_dma_map_page,
42602- ipath_dma_unmap_page,
42603- ipath_map_sg,
42604- ipath_unmap_sg,
42605- ipath_sg_dma_address,
42606- ipath_sg_dma_len,
42607- ipath_sync_single_for_cpu,
42608- ipath_sync_single_for_device,
42609- ipath_dma_alloc_coherent,
42610- ipath_dma_free_coherent
42611+ .mapping_error = ipath_mapping_error,
42612+ .map_single = ipath_dma_map_single,
42613+ .unmap_single = ipath_dma_unmap_single,
42614+ .map_page = ipath_dma_map_page,
42615+ .unmap_page = ipath_dma_unmap_page,
42616+ .map_sg = ipath_map_sg,
42617+ .unmap_sg = ipath_unmap_sg,
42618+ .dma_address = ipath_sg_dma_address,
42619+ .dma_len = ipath_sg_dma_len,
42620+ .sync_single_for_cpu = ipath_sync_single_for_cpu,
42621+ .sync_single_for_device = ipath_sync_single_for_device,
42622+ .alloc_coherent = ipath_dma_alloc_coherent,
42623+ .free_coherent = ipath_dma_free_coherent
42624 };
42625diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
42626index 79b3dbc..96e5fcc 100644
42627--- a/drivers/infiniband/hw/ipath/ipath_rc.c
42628+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
42629@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42630 struct ib_atomic_eth *ateth;
42631 struct ipath_ack_entry *e;
42632 u64 vaddr;
42633- atomic64_t *maddr;
42634+ atomic64_unchecked_t *maddr;
42635 u64 sdata;
42636 u32 rkey;
42637 u8 next;
42638@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42639 IB_ACCESS_REMOTE_ATOMIC)))
42640 goto nack_acc_unlck;
42641 /* Perform atomic OP and save result. */
42642- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42643+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42644 sdata = be64_to_cpu(ateth->swap_data);
42645 e = &qp->s_ack_queue[qp->r_head_ack_queue];
42646 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
42647- (u64) atomic64_add_return(sdata, maddr) - sdata :
42648+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42649 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42650 be64_to_cpu(ateth->compare_data),
42651 sdata);
42652diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
42653index 1f95bba..9530f87 100644
42654--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
42655+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
42656@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
42657 unsigned long flags;
42658 struct ib_wc wc;
42659 u64 sdata;
42660- atomic64_t *maddr;
42661+ atomic64_unchecked_t *maddr;
42662 enum ib_wc_status send_status;
42663
42664 /*
42665@@ -382,11 +382,11 @@ again:
42666 IB_ACCESS_REMOTE_ATOMIC)))
42667 goto acc_err;
42668 /* Perform atomic OP and save result. */
42669- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42670+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42671 sdata = wqe->wr.wr.atomic.compare_add;
42672 *(u64 *) sqp->s_sge.sge.vaddr =
42673 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
42674- (u64) atomic64_add_return(sdata, maddr) - sdata :
42675+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42676 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42677 sdata, wqe->wr.wr.atomic.swap);
42678 goto send_comp;
42679diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
42680index f2a3f48..673ec79 100644
42681--- a/drivers/infiniband/hw/mlx4/mad.c
42682+++ b/drivers/infiniband/hw/mlx4/mad.c
42683@@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
42684
42685 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
42686 {
42687- return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
42688+ return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
42689 cpu_to_be64(0xff00000000000000LL);
42690 }
42691
42692diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
42693index 25b2cdf..099ff97 100644
42694--- a/drivers/infiniband/hw/mlx4/mcg.c
42695+++ b/drivers/infiniband/hw/mlx4/mcg.c
42696@@ -1040,7 +1040,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
42697 {
42698 char name[20];
42699
42700- atomic_set(&ctx->tid, 0);
42701+ atomic_set_unchecked(&ctx->tid, 0);
42702 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
42703 ctx->mcg_wq = create_singlethread_workqueue(name);
42704 if (!ctx->mcg_wq)
42705diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42706index a230683..3723f2d 100644
42707--- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
42708+++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42709@@ -408,7 +408,7 @@ struct mlx4_ib_demux_ctx {
42710 struct list_head mcg_mgid0_list;
42711 struct workqueue_struct *mcg_wq;
42712 struct mlx4_ib_demux_pv_ctx **tun;
42713- atomic_t tid;
42714+ atomic_unchecked_t tid;
42715 int flushing; /* flushing the work queue */
42716 };
42717
42718diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
42719index 9d3e5c1..6f166df 100644
42720--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
42721+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
42722@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
42723 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
42724 }
42725
42726-int mthca_QUERY_FW(struct mthca_dev *dev)
42727+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
42728 {
42729 struct mthca_mailbox *mailbox;
42730 u32 *outbox;
42731@@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42732 CMD_TIME_CLASS_B);
42733 }
42734
42735-int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42736+int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42737 int num_mtt)
42738 {
42739 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
42740@@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
42741 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
42742 }
42743
42744-int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42745+int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42746 int eq_num)
42747 {
42748 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
42749@@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
42750 CMD_TIME_CLASS_B);
42751 }
42752
42753-int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42754+int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42755 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
42756 void *in_mad, void *response_mad)
42757 {
42758diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
42759index 87897b9..7e79542 100644
42760--- a/drivers/infiniband/hw/mthca/mthca_main.c
42761+++ b/drivers/infiniband/hw/mthca/mthca_main.c
42762@@ -692,7 +692,7 @@ err_close:
42763 return err;
42764 }
42765
42766-static int mthca_setup_hca(struct mthca_dev *dev)
42767+static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
42768 {
42769 int err;
42770
42771diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
42772index ed9a989..6aa5dc2 100644
42773--- a/drivers/infiniband/hw/mthca/mthca_mr.c
42774+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
42775@@ -81,7 +81,7 @@ struct mthca_mpt_entry {
42776 * through the bitmaps)
42777 */
42778
42779-static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42780+static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42781 {
42782 int o;
42783 int m;
42784@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
42785 return key;
42786 }
42787
42788-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42789+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42790 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
42791 {
42792 struct mthca_mailbox *mailbox;
42793@@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
42794 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
42795 }
42796
42797-int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42798+int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42799 u64 *buffer_list, int buffer_size_shift,
42800 int list_len, u64 iova, u64 total_size,
42801 u32 access, struct mthca_mr *mr)
42802diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
42803index 42dde06..1257310 100644
42804--- a/drivers/infiniband/hw/mthca/mthca_provider.c
42805+++ b/drivers/infiniband/hw/mthca/mthca_provider.c
42806@@ -764,7 +764,7 @@ unlock:
42807 return 0;
42808 }
42809
42810-static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42811+static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42812 {
42813 struct mthca_dev *dev = to_mdev(ibcq->device);
42814 struct mthca_cq *cq = to_mcq(ibcq);
42815diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
42816index 353c7b0..c6ce921 100644
42817--- a/drivers/infiniband/hw/nes/nes.c
42818+++ b/drivers/infiniband/hw/nes/nes.c
42819@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
42820 LIST_HEAD(nes_adapter_list);
42821 static LIST_HEAD(nes_dev_list);
42822
42823-atomic_t qps_destroyed;
42824+atomic_unchecked_t qps_destroyed;
42825
42826 static unsigned int ee_flsh_adapter;
42827 static unsigned int sysfs_nonidx_addr;
42828@@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
42829 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
42830 struct nes_adapter *nesadapter = nesdev->nesadapter;
42831
42832- atomic_inc(&qps_destroyed);
42833+ atomic_inc_unchecked(&qps_destroyed);
42834
42835 /* Free the control structures */
42836
42837diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
42838index 33cc589..3bd6538 100644
42839--- a/drivers/infiniband/hw/nes/nes.h
42840+++ b/drivers/infiniband/hw/nes/nes.h
42841@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
42842 extern unsigned int wqm_quanta;
42843 extern struct list_head nes_adapter_list;
42844
42845-extern atomic_t cm_connects;
42846-extern atomic_t cm_accepts;
42847-extern atomic_t cm_disconnects;
42848-extern atomic_t cm_closes;
42849-extern atomic_t cm_connecteds;
42850-extern atomic_t cm_connect_reqs;
42851-extern atomic_t cm_rejects;
42852-extern atomic_t mod_qp_timouts;
42853-extern atomic_t qps_created;
42854-extern atomic_t qps_destroyed;
42855-extern atomic_t sw_qps_destroyed;
42856+extern atomic_unchecked_t cm_connects;
42857+extern atomic_unchecked_t cm_accepts;
42858+extern atomic_unchecked_t cm_disconnects;
42859+extern atomic_unchecked_t cm_closes;
42860+extern atomic_unchecked_t cm_connecteds;
42861+extern atomic_unchecked_t cm_connect_reqs;
42862+extern atomic_unchecked_t cm_rejects;
42863+extern atomic_unchecked_t mod_qp_timouts;
42864+extern atomic_unchecked_t qps_created;
42865+extern atomic_unchecked_t qps_destroyed;
42866+extern atomic_unchecked_t sw_qps_destroyed;
42867 extern u32 mh_detected;
42868 extern u32 mh_pauses_sent;
42869 extern u32 cm_packets_sent;
42870@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
42871 extern u32 cm_packets_received;
42872 extern u32 cm_packets_dropped;
42873 extern u32 cm_packets_retrans;
42874-extern atomic_t cm_listens_created;
42875-extern atomic_t cm_listens_destroyed;
42876+extern atomic_unchecked_t cm_listens_created;
42877+extern atomic_unchecked_t cm_listens_destroyed;
42878 extern u32 cm_backlog_drops;
42879-extern atomic_t cm_loopbacks;
42880-extern atomic_t cm_nodes_created;
42881-extern atomic_t cm_nodes_destroyed;
42882-extern atomic_t cm_accel_dropped_pkts;
42883-extern atomic_t cm_resets_recvd;
42884-extern atomic_t pau_qps_created;
42885-extern atomic_t pau_qps_destroyed;
42886+extern atomic_unchecked_t cm_loopbacks;
42887+extern atomic_unchecked_t cm_nodes_created;
42888+extern atomic_unchecked_t cm_nodes_destroyed;
42889+extern atomic_unchecked_t cm_accel_dropped_pkts;
42890+extern atomic_unchecked_t cm_resets_recvd;
42891+extern atomic_unchecked_t pau_qps_created;
42892+extern atomic_unchecked_t pau_qps_destroyed;
42893
42894 extern u32 int_mod_timer_init;
42895 extern u32 int_mod_cq_depth_256;
42896diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
42897index 9c9f2f5..2559190 100644
42898--- a/drivers/infiniband/hw/nes/nes_cm.c
42899+++ b/drivers/infiniband/hw/nes/nes_cm.c
42900@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
42901 u32 cm_packets_retrans;
42902 u32 cm_packets_created;
42903 u32 cm_packets_received;
42904-atomic_t cm_listens_created;
42905-atomic_t cm_listens_destroyed;
42906+atomic_unchecked_t cm_listens_created;
42907+atomic_unchecked_t cm_listens_destroyed;
42908 u32 cm_backlog_drops;
42909-atomic_t cm_loopbacks;
42910-atomic_t cm_nodes_created;
42911-atomic_t cm_nodes_destroyed;
42912-atomic_t cm_accel_dropped_pkts;
42913-atomic_t cm_resets_recvd;
42914+atomic_unchecked_t cm_loopbacks;
42915+atomic_unchecked_t cm_nodes_created;
42916+atomic_unchecked_t cm_nodes_destroyed;
42917+atomic_unchecked_t cm_accel_dropped_pkts;
42918+atomic_unchecked_t cm_resets_recvd;
42919
42920 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
42921 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
42922@@ -133,28 +133,28 @@ static void print_core(struct nes_cm_core *core);
42923 /* instance of function pointers for client API */
42924 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
42925 static struct nes_cm_ops nes_cm_api = {
42926- mini_cm_accelerated,
42927- mini_cm_listen,
42928- mini_cm_del_listen,
42929- mini_cm_connect,
42930- mini_cm_close,
42931- mini_cm_accept,
42932- mini_cm_reject,
42933- mini_cm_recv_pkt,
42934- mini_cm_dealloc_core,
42935- mini_cm_get,
42936- mini_cm_set
42937+ .accelerated = mini_cm_accelerated,
42938+ .listen = mini_cm_listen,
42939+ .stop_listener = mini_cm_del_listen,
42940+ .connect = mini_cm_connect,
42941+ .close = mini_cm_close,
42942+ .accept = mini_cm_accept,
42943+ .reject = mini_cm_reject,
42944+ .recv_pkt = mini_cm_recv_pkt,
42945+ .destroy_cm_core = mini_cm_dealloc_core,
42946+ .get = mini_cm_get,
42947+ .set = mini_cm_set
42948 };
42949
42950 static struct nes_cm_core *g_cm_core;
42951
42952-atomic_t cm_connects;
42953-atomic_t cm_accepts;
42954-atomic_t cm_disconnects;
42955-atomic_t cm_closes;
42956-atomic_t cm_connecteds;
42957-atomic_t cm_connect_reqs;
42958-atomic_t cm_rejects;
42959+atomic_unchecked_t cm_connects;
42960+atomic_unchecked_t cm_accepts;
42961+atomic_unchecked_t cm_disconnects;
42962+atomic_unchecked_t cm_closes;
42963+atomic_unchecked_t cm_connecteds;
42964+atomic_unchecked_t cm_connect_reqs;
42965+atomic_unchecked_t cm_rejects;
42966
42967 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
42968 {
42969@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
42970 kfree(listener);
42971 listener = NULL;
42972 ret = 0;
42973- atomic_inc(&cm_listens_destroyed);
42974+ atomic_inc_unchecked(&cm_listens_destroyed);
42975 } else {
42976 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
42977 }
42978@@ -1465,7 +1465,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
42979 cm_node->rem_mac);
42980
42981 add_hte_node(cm_core, cm_node);
42982- atomic_inc(&cm_nodes_created);
42983+ atomic_inc_unchecked(&cm_nodes_created);
42984
42985 return cm_node;
42986 }
42987@@ -1523,7 +1523,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
42988 }
42989
42990 atomic_dec(&cm_core->node_cnt);
42991- atomic_inc(&cm_nodes_destroyed);
42992+ atomic_inc_unchecked(&cm_nodes_destroyed);
42993 nesqp = cm_node->nesqp;
42994 if (nesqp) {
42995 nesqp->cm_node = NULL;
42996@@ -1587,7 +1587,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
42997
42998 static void drop_packet(struct sk_buff *skb)
42999 {
43000- atomic_inc(&cm_accel_dropped_pkts);
43001+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
43002 dev_kfree_skb_any(skb);
43003 }
43004
43005@@ -1650,7 +1650,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
43006 {
43007
43008 int reset = 0; /* whether to send reset in case of err.. */
43009- atomic_inc(&cm_resets_recvd);
43010+ atomic_inc_unchecked(&cm_resets_recvd);
43011 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
43012 " refcnt=%d\n", cm_node, cm_node->state,
43013 atomic_read(&cm_node->ref_count));
43014@@ -2291,7 +2291,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
43015 rem_ref_cm_node(cm_node->cm_core, cm_node);
43016 return NULL;
43017 }
43018- atomic_inc(&cm_loopbacks);
43019+ atomic_inc_unchecked(&cm_loopbacks);
43020 loopbackremotenode->loopbackpartner = cm_node;
43021 loopbackremotenode->tcp_cntxt.rcv_wscale =
43022 NES_CM_DEFAULT_RCV_WND_SCALE;
43023@@ -2566,7 +2566,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
43024 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
43025 else {
43026 rem_ref_cm_node(cm_core, cm_node);
43027- atomic_inc(&cm_accel_dropped_pkts);
43028+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
43029 dev_kfree_skb_any(skb);
43030 }
43031 break;
43032@@ -2874,7 +2874,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
43033
43034 if ((cm_id) && (cm_id->event_handler)) {
43035 if (issue_disconn) {
43036- atomic_inc(&cm_disconnects);
43037+ atomic_inc_unchecked(&cm_disconnects);
43038 cm_event.event = IW_CM_EVENT_DISCONNECT;
43039 cm_event.status = disconn_status;
43040 cm_event.local_addr = cm_id->local_addr;
43041@@ -2896,7 +2896,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
43042 }
43043
43044 if (issue_close) {
43045- atomic_inc(&cm_closes);
43046+ atomic_inc_unchecked(&cm_closes);
43047 nes_disconnect(nesqp, 1);
43048
43049 cm_id->provider_data = nesqp;
43050@@ -3034,7 +3034,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
43051
43052 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
43053 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
43054- atomic_inc(&cm_accepts);
43055+ atomic_inc_unchecked(&cm_accepts);
43056
43057 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
43058 netdev_refcnt_read(nesvnic->netdev));
43059@@ -3223,7 +3223,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
43060 struct nes_cm_core *cm_core;
43061 u8 *start_buff;
43062
43063- atomic_inc(&cm_rejects);
43064+ atomic_inc_unchecked(&cm_rejects);
43065 cm_node = (struct nes_cm_node *)cm_id->provider_data;
43066 loopback = cm_node->loopbackpartner;
43067 cm_core = cm_node->cm_core;
43068@@ -3285,7 +3285,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
43069 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
43070 ntohs(laddr->sin_port));
43071
43072- atomic_inc(&cm_connects);
43073+ atomic_inc_unchecked(&cm_connects);
43074 nesqp->active_conn = 1;
43075
43076 /* cache the cm_id in the qp */
43077@@ -3397,7 +3397,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
43078 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
43079 return err;
43080 }
43081- atomic_inc(&cm_listens_created);
43082+ atomic_inc_unchecked(&cm_listens_created);
43083 }
43084
43085 cm_id->add_ref(cm_id);
43086@@ -3504,7 +3504,7 @@ static void cm_event_connected(struct nes_cm_event *event)
43087
43088 if (nesqp->destroyed)
43089 return;
43090- atomic_inc(&cm_connecteds);
43091+ atomic_inc_unchecked(&cm_connecteds);
43092 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
43093 " local port 0x%04X. jiffies = %lu.\n",
43094 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
43095@@ -3685,7 +3685,7 @@ static void cm_event_reset(struct nes_cm_event *event)
43096
43097 cm_id->add_ref(cm_id);
43098 ret = cm_id->event_handler(cm_id, &cm_event);
43099- atomic_inc(&cm_closes);
43100+ atomic_inc_unchecked(&cm_closes);
43101 cm_event.event = IW_CM_EVENT_CLOSE;
43102 cm_event.status = 0;
43103 cm_event.provider_data = cm_id->provider_data;
43104@@ -3725,7 +3725,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
43105 return;
43106 cm_id = cm_node->cm_id;
43107
43108- atomic_inc(&cm_connect_reqs);
43109+ atomic_inc_unchecked(&cm_connect_reqs);
43110 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
43111 cm_node, cm_id, jiffies);
43112
43113@@ -3769,7 +3769,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
43114 return;
43115 cm_id = cm_node->cm_id;
43116
43117- atomic_inc(&cm_connect_reqs);
43118+ atomic_inc_unchecked(&cm_connect_reqs);
43119 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
43120 cm_node, cm_id, jiffies);
43121
43122diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
43123index 4166452..fc952c3 100644
43124--- a/drivers/infiniband/hw/nes/nes_mgt.c
43125+++ b/drivers/infiniband/hw/nes/nes_mgt.c
43126@@ -40,8 +40,8 @@
43127 #include "nes.h"
43128 #include "nes_mgt.h"
43129
43130-atomic_t pau_qps_created;
43131-atomic_t pau_qps_destroyed;
43132+atomic_unchecked_t pau_qps_created;
43133+atomic_unchecked_t pau_qps_destroyed;
43134
43135 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
43136 {
43137@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
43138 {
43139 struct sk_buff *skb;
43140 unsigned long flags;
43141- atomic_inc(&pau_qps_destroyed);
43142+ atomic_inc_unchecked(&pau_qps_destroyed);
43143
43144 /* Free packets that have not yet been forwarded */
43145 /* Lock is acquired by skb_dequeue when removing the skb */
43146@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
43147 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
43148 skb_queue_head_init(&nesqp->pau_list);
43149 spin_lock_init(&nesqp->pau_lock);
43150- atomic_inc(&pau_qps_created);
43151+ atomic_inc_unchecked(&pau_qps_created);
43152 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
43153 }
43154
43155diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
43156index 49eb511..a774366 100644
43157--- a/drivers/infiniband/hw/nes/nes_nic.c
43158+++ b/drivers/infiniband/hw/nes/nes_nic.c
43159@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
43160 target_stat_values[++index] = mh_detected;
43161 target_stat_values[++index] = mh_pauses_sent;
43162 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
43163- target_stat_values[++index] = atomic_read(&cm_connects);
43164- target_stat_values[++index] = atomic_read(&cm_accepts);
43165- target_stat_values[++index] = atomic_read(&cm_disconnects);
43166- target_stat_values[++index] = atomic_read(&cm_connecteds);
43167- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
43168- target_stat_values[++index] = atomic_read(&cm_rejects);
43169- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
43170- target_stat_values[++index] = atomic_read(&qps_created);
43171- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
43172- target_stat_values[++index] = atomic_read(&qps_destroyed);
43173- target_stat_values[++index] = atomic_read(&cm_closes);
43174+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
43175+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
43176+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
43177+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
43178+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
43179+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
43180+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
43181+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
43182+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
43183+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
43184+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
43185 target_stat_values[++index] = cm_packets_sent;
43186 target_stat_values[++index] = cm_packets_bounced;
43187 target_stat_values[++index] = cm_packets_created;
43188 target_stat_values[++index] = cm_packets_received;
43189 target_stat_values[++index] = cm_packets_dropped;
43190 target_stat_values[++index] = cm_packets_retrans;
43191- target_stat_values[++index] = atomic_read(&cm_listens_created);
43192- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
43193+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
43194+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
43195 target_stat_values[++index] = cm_backlog_drops;
43196- target_stat_values[++index] = atomic_read(&cm_loopbacks);
43197- target_stat_values[++index] = atomic_read(&cm_nodes_created);
43198- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
43199- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
43200- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
43201+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
43202+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
43203+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
43204+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
43205+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
43206 target_stat_values[++index] = nesadapter->free_4kpbl;
43207 target_stat_values[++index] = nesadapter->free_256pbl;
43208 target_stat_values[++index] = int_mod_timer_init;
43209 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
43210 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
43211 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
43212- target_stat_values[++index] = atomic_read(&pau_qps_created);
43213- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
43214+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
43215+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
43216 }
43217
43218 /**
43219diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
43220index eb62461..2b7fc71 100644
43221--- a/drivers/infiniband/hw/nes/nes_verbs.c
43222+++ b/drivers/infiniband/hw/nes/nes_verbs.c
43223@@ -46,9 +46,9 @@
43224
43225 #include <rdma/ib_umem.h>
43226
43227-atomic_t mod_qp_timouts;
43228-atomic_t qps_created;
43229-atomic_t sw_qps_destroyed;
43230+atomic_unchecked_t mod_qp_timouts;
43231+atomic_unchecked_t qps_created;
43232+atomic_unchecked_t sw_qps_destroyed;
43233
43234 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
43235
43236@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
43237 if (init_attr->create_flags)
43238 return ERR_PTR(-EINVAL);
43239
43240- atomic_inc(&qps_created);
43241+ atomic_inc_unchecked(&qps_created);
43242 switch (init_attr->qp_type) {
43243 case IB_QPT_RC:
43244 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
43245@@ -1466,7 +1466,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
43246 struct iw_cm_event cm_event;
43247 int ret = 0;
43248
43249- atomic_inc(&sw_qps_destroyed);
43250+ atomic_inc_unchecked(&sw_qps_destroyed);
43251 nesqp->destroyed = 1;
43252
43253 /* Blow away the connection if it exists. */
43254diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
43255index 1946101..09766d2 100644
43256--- a/drivers/infiniband/hw/qib/qib.h
43257+++ b/drivers/infiniband/hw/qib/qib.h
43258@@ -52,6 +52,7 @@
43259 #include <linux/kref.h>
43260 #include <linux/sched.h>
43261 #include <linux/kthread.h>
43262+#include <linux/slab.h>
43263
43264 #include "qib_common.h"
43265 #include "qib_verbs.h"
43266diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
43267index 24c41ba..102d71f 100644
43268--- a/drivers/input/gameport/gameport.c
43269+++ b/drivers/input/gameport/gameport.c
43270@@ -490,14 +490,14 @@ EXPORT_SYMBOL(gameport_set_phys);
43271 */
43272 static void gameport_init_port(struct gameport *gameport)
43273 {
43274- static atomic_t gameport_no = ATOMIC_INIT(0);
43275+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
43276
43277 __module_get(THIS_MODULE);
43278
43279 mutex_init(&gameport->drv_mutex);
43280 device_initialize(&gameport->dev);
43281 dev_set_name(&gameport->dev, "gameport%lu",
43282- (unsigned long)atomic_inc_return(&gameport_no) - 1);
43283+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
43284 gameport->dev.bus = &gameport_bus;
43285 gameport->dev.release = gameport_release_port;
43286 if (gameport->parent)
43287diff --git a/drivers/input/input.c b/drivers/input/input.c
43288index 1c4c0db..6f7abe3 100644
43289--- a/drivers/input/input.c
43290+++ b/drivers/input/input.c
43291@@ -1772,7 +1772,7 @@ EXPORT_SYMBOL_GPL(input_class);
43292 */
43293 struct input_dev *input_allocate_device(void)
43294 {
43295- static atomic_t input_no = ATOMIC_INIT(0);
43296+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
43297 struct input_dev *dev;
43298
43299 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
43300@@ -1787,7 +1787,7 @@ struct input_dev *input_allocate_device(void)
43301 INIT_LIST_HEAD(&dev->node);
43302
43303 dev_set_name(&dev->dev, "input%ld",
43304- (unsigned long) atomic_inc_return(&input_no) - 1);
43305+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
43306
43307 __module_get(THIS_MODULE);
43308 }
43309diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
43310index 4a95b22..874c182 100644
43311--- a/drivers/input/joystick/sidewinder.c
43312+++ b/drivers/input/joystick/sidewinder.c
43313@@ -30,6 +30,7 @@
43314 #include <linux/kernel.h>
43315 #include <linux/module.h>
43316 #include <linux/slab.h>
43317+#include <linux/sched.h>
43318 #include <linux/input.h>
43319 #include <linux/gameport.h>
43320 #include <linux/jiffies.h>
43321diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
43322index 603fe0d..f63decc 100644
43323--- a/drivers/input/joystick/xpad.c
43324+++ b/drivers/input/joystick/xpad.c
43325@@ -737,7 +737,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
43326
43327 static int xpad_led_probe(struct usb_xpad *xpad)
43328 {
43329- static atomic_t led_seq = ATOMIC_INIT(0);
43330+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
43331 long led_no;
43332 struct xpad_led *led;
43333 struct led_classdev *led_cdev;
43334@@ -750,7 +750,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
43335 if (!led)
43336 return -ENOMEM;
43337
43338- led_no = (long)atomic_inc_return(&led_seq) - 1;
43339+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
43340
43341 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
43342 led->xpad = xpad;
43343diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
43344index e204f26..8459f15 100644
43345--- a/drivers/input/misc/ims-pcu.c
43346+++ b/drivers/input/misc/ims-pcu.c
43347@@ -1621,7 +1621,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
43348
43349 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
43350 {
43351- static atomic_t device_no = ATOMIC_INIT(0);
43352+ static atomic_unchecked_t device_no = ATOMIC_INIT(0);
43353
43354 const struct ims_pcu_device_info *info;
43355 u8 device_id;
43356@@ -1653,7 +1653,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
43357 }
43358
43359 /* Device appears to be operable, complete initialization */
43360- pcu->device_no = atomic_inc_return(&device_no) - 1;
43361+ pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
43362
43363 error = ims_pcu_setup_backlight(pcu);
43364 if (error)
43365diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
43366index 2f0b39d..7370f13 100644
43367--- a/drivers/input/mouse/psmouse.h
43368+++ b/drivers/input/mouse/psmouse.h
43369@@ -116,7 +116,7 @@ struct psmouse_attribute {
43370 ssize_t (*set)(struct psmouse *psmouse, void *data,
43371 const char *buf, size_t count);
43372 bool protect;
43373-};
43374+} __do_const;
43375 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
43376
43377 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
43378diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
43379index b604564..3f14ae4 100644
43380--- a/drivers/input/mousedev.c
43381+++ b/drivers/input/mousedev.c
43382@@ -744,7 +744,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
43383
43384 spin_unlock_irq(&client->packet_lock);
43385
43386- if (copy_to_user(buffer, data, count))
43387+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
43388 return -EFAULT;
43389
43390 return count;
43391diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
43392index 8f4c4ab..5fc8a45 100644
43393--- a/drivers/input/serio/serio.c
43394+++ b/drivers/input/serio/serio.c
43395@@ -505,7 +505,7 @@ static void serio_release_port(struct device *dev)
43396 */
43397 static void serio_init_port(struct serio *serio)
43398 {
43399- static atomic_t serio_no = ATOMIC_INIT(0);
43400+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
43401
43402 __module_get(THIS_MODULE);
43403
43404@@ -516,7 +516,7 @@ static void serio_init_port(struct serio *serio)
43405 mutex_init(&serio->drv_mutex);
43406 device_initialize(&serio->dev);
43407 dev_set_name(&serio->dev, "serio%ld",
43408- (long)atomic_inc_return(&serio_no) - 1);
43409+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
43410 serio->dev.bus = &serio_bus;
43411 serio->dev.release = serio_release_port;
43412 serio->dev.groups = serio_device_attr_groups;
43413diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
43414index c9a02fe..0debc75 100644
43415--- a/drivers/input/serio/serio_raw.c
43416+++ b/drivers/input/serio/serio_raw.c
43417@@ -292,7 +292,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
43418
43419 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
43420 {
43421- static atomic_t serio_raw_no = ATOMIC_INIT(0);
43422+ static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
43423 struct serio_raw *serio_raw;
43424 int err;
43425
43426@@ -303,7 +303,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
43427 }
43428
43429 snprintf(serio_raw->name, sizeof(serio_raw->name),
43430- "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
43431+ "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
43432 kref_init(&serio_raw->kref);
43433 INIT_LIST_HEAD(&serio_raw->client_list);
43434 init_waitqueue_head(&serio_raw->wait);
43435diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
43436index e5555fc..937986d 100644
43437--- a/drivers/iommu/iommu.c
43438+++ b/drivers/iommu/iommu.c
43439@@ -588,7 +588,7 @@ static struct notifier_block iommu_bus_nb = {
43440 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
43441 {
43442 bus_register_notifier(bus, &iommu_bus_nb);
43443- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
43444+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
43445 }
43446
43447 /**
43448diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
43449index 228632c9..edfe331 100644
43450--- a/drivers/iommu/irq_remapping.c
43451+++ b/drivers/iommu/irq_remapping.c
43452@@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
43453 void panic_if_irq_remap(const char *msg)
43454 {
43455 if (irq_remapping_enabled)
43456- panic(msg);
43457+ panic("%s", msg);
43458 }
43459
43460 static void ir_ack_apic_edge(struct irq_data *data)
43461@@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
43462
43463 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
43464 {
43465- chip->irq_print_chip = ir_print_prefix;
43466- chip->irq_ack = ir_ack_apic_edge;
43467- chip->irq_eoi = ir_ack_apic_level;
43468- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43469+ pax_open_kernel();
43470+ *(void **)&chip->irq_print_chip = ir_print_prefix;
43471+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
43472+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
43473+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43474+ pax_close_kernel();
43475 }
43476
43477 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
43478diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
43479index 341c601..e5f407e 100644
43480--- a/drivers/irqchip/irq-gic.c
43481+++ b/drivers/irqchip/irq-gic.c
43482@@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
43483 * Supported arch specific GIC irq extension.
43484 * Default make them NULL.
43485 */
43486-struct irq_chip gic_arch_extn = {
43487+irq_chip_no_const gic_arch_extn = {
43488 .irq_eoi = NULL,
43489 .irq_mask = NULL,
43490 .irq_unmask = NULL,
43491@@ -332,7 +332,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
43492 chained_irq_exit(chip, desc);
43493 }
43494
43495-static struct irq_chip gic_chip = {
43496+static irq_chip_no_const gic_chip __read_only = {
43497 .name = "GIC",
43498 .irq_mask = gic_mask_irq,
43499 .irq_unmask = gic_unmask_irq,
43500diff --git a/drivers/irqchip/irq-renesas-irqc.c b/drivers/irqchip/irq-renesas-irqc.c
43501index 8777065..a4a9967 100644
43502--- a/drivers/irqchip/irq-renesas-irqc.c
43503+++ b/drivers/irqchip/irq-renesas-irqc.c
43504@@ -151,7 +151,7 @@ static int irqc_probe(struct platform_device *pdev)
43505 struct irqc_priv *p;
43506 struct resource *io;
43507 struct resource *irq;
43508- struct irq_chip *irq_chip;
43509+ irq_chip_no_const *irq_chip;
43510 const char *name = dev_name(&pdev->dev);
43511 int ret;
43512 int k;
43513diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
43514index ac6f72b..81150f2 100644
43515--- a/drivers/isdn/capi/capi.c
43516+++ b/drivers/isdn/capi/capi.c
43517@@ -81,8 +81,8 @@ struct capiminor {
43518
43519 struct capi20_appl *ap;
43520 u32 ncci;
43521- atomic_t datahandle;
43522- atomic_t msgid;
43523+ atomic_unchecked_t datahandle;
43524+ atomic_unchecked_t msgid;
43525
43526 struct tty_port port;
43527 int ttyinstop;
43528@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
43529 capimsg_setu16(s, 2, mp->ap->applid);
43530 capimsg_setu8 (s, 4, CAPI_DATA_B3);
43531 capimsg_setu8 (s, 5, CAPI_RESP);
43532- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
43533+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
43534 capimsg_setu32(s, 8, mp->ncci);
43535 capimsg_setu16(s, 12, datahandle);
43536 }
43537@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
43538 mp->outbytes -= len;
43539 spin_unlock_bh(&mp->outlock);
43540
43541- datahandle = atomic_inc_return(&mp->datahandle);
43542+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
43543 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
43544 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43545 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43546 capimsg_setu16(skb->data, 2, mp->ap->applid);
43547 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
43548 capimsg_setu8 (skb->data, 5, CAPI_REQ);
43549- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
43550+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
43551 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
43552 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
43553 capimsg_setu16(skb->data, 16, len); /* Data length */
43554diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
43555index c44950d..10ac276 100644
43556--- a/drivers/isdn/gigaset/bas-gigaset.c
43557+++ b/drivers/isdn/gigaset/bas-gigaset.c
43558@@ -2564,22 +2564,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
43559
43560
43561 static const struct gigaset_ops gigops = {
43562- gigaset_write_cmd,
43563- gigaset_write_room,
43564- gigaset_chars_in_buffer,
43565- gigaset_brkchars,
43566- gigaset_init_bchannel,
43567- gigaset_close_bchannel,
43568- gigaset_initbcshw,
43569- gigaset_freebcshw,
43570- gigaset_reinitbcshw,
43571- gigaset_initcshw,
43572- gigaset_freecshw,
43573- gigaset_set_modem_ctrl,
43574- gigaset_baud_rate,
43575- gigaset_set_line_ctrl,
43576- gigaset_isoc_send_skb,
43577- gigaset_isoc_input,
43578+ .write_cmd = gigaset_write_cmd,
43579+ .write_room = gigaset_write_room,
43580+ .chars_in_buffer = gigaset_chars_in_buffer,
43581+ .brkchars = gigaset_brkchars,
43582+ .init_bchannel = gigaset_init_bchannel,
43583+ .close_bchannel = gigaset_close_bchannel,
43584+ .initbcshw = gigaset_initbcshw,
43585+ .freebcshw = gigaset_freebcshw,
43586+ .reinitbcshw = gigaset_reinitbcshw,
43587+ .initcshw = gigaset_initcshw,
43588+ .freecshw = gigaset_freecshw,
43589+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43590+ .baud_rate = gigaset_baud_rate,
43591+ .set_line_ctrl = gigaset_set_line_ctrl,
43592+ .send_skb = gigaset_isoc_send_skb,
43593+ .handle_input = gigaset_isoc_input,
43594 };
43595
43596 /* bas_gigaset_init
43597diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
43598index 600c79b..3752bab 100644
43599--- a/drivers/isdn/gigaset/interface.c
43600+++ b/drivers/isdn/gigaset/interface.c
43601@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
43602 }
43603 tty->driver_data = cs;
43604
43605- ++cs->port.count;
43606+ atomic_inc(&cs->port.count);
43607
43608- if (cs->port.count == 1) {
43609+ if (atomic_read(&cs->port.count) == 1) {
43610 tty_port_tty_set(&cs->port, tty);
43611 cs->port.low_latency = 1;
43612 }
43613@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
43614
43615 if (!cs->connected)
43616 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
43617- else if (!cs->port.count)
43618+ else if (!atomic_read(&cs->port.count))
43619 dev_warn(cs->dev, "%s: device not opened\n", __func__);
43620- else if (!--cs->port.count)
43621+ else if (!atomic_dec_return(&cs->port.count))
43622 tty_port_tty_set(&cs->port, NULL);
43623
43624 mutex_unlock(&cs->mutex);
43625diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
43626index 8c91fd5..14f13ce 100644
43627--- a/drivers/isdn/gigaset/ser-gigaset.c
43628+++ b/drivers/isdn/gigaset/ser-gigaset.c
43629@@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
43630 }
43631
43632 static const struct gigaset_ops ops = {
43633- gigaset_write_cmd,
43634- gigaset_write_room,
43635- gigaset_chars_in_buffer,
43636- gigaset_brkchars,
43637- gigaset_init_bchannel,
43638- gigaset_close_bchannel,
43639- gigaset_initbcshw,
43640- gigaset_freebcshw,
43641- gigaset_reinitbcshw,
43642- gigaset_initcshw,
43643- gigaset_freecshw,
43644- gigaset_set_modem_ctrl,
43645- gigaset_baud_rate,
43646- gigaset_set_line_ctrl,
43647- gigaset_m10x_send_skb, /* asyncdata.c */
43648- gigaset_m10x_input, /* asyncdata.c */
43649+ .write_cmd = gigaset_write_cmd,
43650+ .write_room = gigaset_write_room,
43651+ .chars_in_buffer = gigaset_chars_in_buffer,
43652+ .brkchars = gigaset_brkchars,
43653+ .init_bchannel = gigaset_init_bchannel,
43654+ .close_bchannel = gigaset_close_bchannel,
43655+ .initbcshw = gigaset_initbcshw,
43656+ .freebcshw = gigaset_freebcshw,
43657+ .reinitbcshw = gigaset_reinitbcshw,
43658+ .initcshw = gigaset_initcshw,
43659+ .freecshw = gigaset_freecshw,
43660+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43661+ .baud_rate = gigaset_baud_rate,
43662+ .set_line_ctrl = gigaset_set_line_ctrl,
43663+ .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
43664+ .handle_input = gigaset_m10x_input, /* asyncdata.c */
43665 };
43666
43667
43668diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
43669index d0a41cb..b953e50 100644
43670--- a/drivers/isdn/gigaset/usb-gigaset.c
43671+++ b/drivers/isdn/gigaset/usb-gigaset.c
43672@@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
43673 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
43674 memcpy(cs->hw.usb->bchars, buf, 6);
43675 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
43676- 0, 0, &buf, 6, 2000);
43677+ 0, 0, buf, 6, 2000);
43678 }
43679
43680 static void gigaset_freebcshw(struct bc_state *bcs)
43681@@ -869,22 +869,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
43682 }
43683
43684 static const struct gigaset_ops ops = {
43685- gigaset_write_cmd,
43686- gigaset_write_room,
43687- gigaset_chars_in_buffer,
43688- gigaset_brkchars,
43689- gigaset_init_bchannel,
43690- gigaset_close_bchannel,
43691- gigaset_initbcshw,
43692- gigaset_freebcshw,
43693- gigaset_reinitbcshw,
43694- gigaset_initcshw,
43695- gigaset_freecshw,
43696- gigaset_set_modem_ctrl,
43697- gigaset_baud_rate,
43698- gigaset_set_line_ctrl,
43699- gigaset_m10x_send_skb,
43700- gigaset_m10x_input,
43701+ .write_cmd = gigaset_write_cmd,
43702+ .write_room = gigaset_write_room,
43703+ .chars_in_buffer = gigaset_chars_in_buffer,
43704+ .brkchars = gigaset_brkchars,
43705+ .init_bchannel = gigaset_init_bchannel,
43706+ .close_bchannel = gigaset_close_bchannel,
43707+ .initbcshw = gigaset_initbcshw,
43708+ .freebcshw = gigaset_freebcshw,
43709+ .reinitbcshw = gigaset_reinitbcshw,
43710+ .initcshw = gigaset_initcshw,
43711+ .freecshw = gigaset_freecshw,
43712+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43713+ .baud_rate = gigaset_baud_rate,
43714+ .set_line_ctrl = gigaset_set_line_ctrl,
43715+ .send_skb = gigaset_m10x_send_skb,
43716+ .handle_input = gigaset_m10x_input,
43717 };
43718
43719 /*
43720diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
43721index 4d9b195..455075c 100644
43722--- a/drivers/isdn/hardware/avm/b1.c
43723+++ b/drivers/isdn/hardware/avm/b1.c
43724@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
43725 }
43726 if (left) {
43727 if (t4file->user) {
43728- if (copy_from_user(buf, dp, left))
43729+ if (left > sizeof buf || copy_from_user(buf, dp, left))
43730 return -EFAULT;
43731 } else {
43732 memcpy(buf, dp, left);
43733@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
43734 }
43735 if (left) {
43736 if (config->user) {
43737- if (copy_from_user(buf, dp, left))
43738+ if (left > sizeof buf || copy_from_user(buf, dp, left))
43739 return -EFAULT;
43740 } else {
43741 memcpy(buf, dp, left);
43742diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
43743index 9bb12ba..d4262f7 100644
43744--- a/drivers/isdn/i4l/isdn_common.c
43745+++ b/drivers/isdn/i4l/isdn_common.c
43746@@ -1651,6 +1651,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
43747 } else
43748 return -EINVAL;
43749 case IIOCDBGVAR:
43750+ if (!capable(CAP_SYS_RAWIO))
43751+ return -EPERM;
43752 if (arg) {
43753 if (copy_to_user(argp, &dev, sizeof(ulong)))
43754 return -EFAULT;
43755diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
43756index 91d5730..336523e 100644
43757--- a/drivers/isdn/i4l/isdn_concap.c
43758+++ b/drivers/isdn/i4l/isdn_concap.c
43759@@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
43760 }
43761
43762 struct concap_device_ops isdn_concap_reliable_dl_dops = {
43763- &isdn_concap_dl_data_req,
43764- &isdn_concap_dl_connect_req,
43765- &isdn_concap_dl_disconn_req
43766+ .data_req = &isdn_concap_dl_data_req,
43767+ .connect_req = &isdn_concap_dl_connect_req,
43768+ .disconn_req = &isdn_concap_dl_disconn_req
43769 };
43770
43771 /* The following should better go into a dedicated source file such that
43772diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
43773index 3c5f249..5fac4d0 100644
43774--- a/drivers/isdn/i4l/isdn_tty.c
43775+++ b/drivers/isdn/i4l/isdn_tty.c
43776@@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
43777
43778 #ifdef ISDN_DEBUG_MODEM_OPEN
43779 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
43780- port->count);
43781+ atomic_read(&port->count));
43782 #endif
43783- port->count++;
43784+ atomic_inc(&port->count);
43785 port->tty = tty;
43786 /*
43787 * Start up serial port
43788@@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43789 #endif
43790 return;
43791 }
43792- if ((tty->count == 1) && (port->count != 1)) {
43793+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
43794 /*
43795 * Uh, oh. tty->count is 1, which means that the tty
43796 * structure will be freed. Info->count should always
43797@@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43798 * serial port won't be shutdown.
43799 */
43800 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
43801- "info->count is %d\n", port->count);
43802- port->count = 1;
43803+ "info->count is %d\n", atomic_read(&port->count));
43804+ atomic_set(&port->count, 1);
43805 }
43806- if (--port->count < 0) {
43807+ if (atomic_dec_return(&port->count) < 0) {
43808 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
43809- info->line, port->count);
43810- port->count = 0;
43811+ info->line, atomic_read(&port->count));
43812+ atomic_set(&port->count, 0);
43813 }
43814- if (port->count) {
43815+ if (atomic_read(&port->count)) {
43816 #ifdef ISDN_DEBUG_MODEM_OPEN
43817 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
43818 #endif
43819@@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
43820 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
43821 return;
43822 isdn_tty_shutdown(info);
43823- port->count = 0;
43824+ atomic_set(&port->count, 0);
43825 port->flags &= ~ASYNC_NORMAL_ACTIVE;
43826 port->tty = NULL;
43827 wake_up_interruptible(&port->open_wait);
43828@@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
43829 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
43830 modem_info *info = &dev->mdm.info[i];
43831
43832- if (info->port.count == 0)
43833+ if (atomic_read(&info->port.count) == 0)
43834 continue;
43835 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
43836 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
43837diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
43838index e2d4e58..40cd045 100644
43839--- a/drivers/isdn/i4l/isdn_x25iface.c
43840+++ b/drivers/isdn/i4l/isdn_x25iface.c
43841@@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
43842
43843
43844 static struct concap_proto_ops ix25_pops = {
43845- &isdn_x25iface_proto_new,
43846- &isdn_x25iface_proto_del,
43847- &isdn_x25iface_proto_restart,
43848- &isdn_x25iface_proto_close,
43849- &isdn_x25iface_xmit,
43850- &isdn_x25iface_receive,
43851- &isdn_x25iface_connect_ind,
43852- &isdn_x25iface_disconn_ind
43853+ .proto_new = &isdn_x25iface_proto_new,
43854+ .proto_del = &isdn_x25iface_proto_del,
43855+ .restart = &isdn_x25iface_proto_restart,
43856+ .close = &isdn_x25iface_proto_close,
43857+ .encap_and_xmit = &isdn_x25iface_xmit,
43858+ .data_ind = &isdn_x25iface_receive,
43859+ .connect_ind = &isdn_x25iface_connect_ind,
43860+ .disconn_ind = &isdn_x25iface_disconn_ind
43861 };
43862
43863 /* error message helper function */
43864diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
43865index 53d487f..cae33fe 100644
43866--- a/drivers/isdn/icn/icn.c
43867+++ b/drivers/isdn/icn/icn.c
43868@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
43869 if (count > len)
43870 count = len;
43871 if (user) {
43872- if (copy_from_user(msg, buf, count))
43873+ if (count > sizeof msg || copy_from_user(msg, buf, count))
43874 return -EFAULT;
43875 } else
43876 memcpy(msg, buf, count);
43877@@ -1155,7 +1155,7 @@ icn_command(isdn_ctrl *c, icn_card *card)
43878 ulong a;
43879 ulong flags;
43880 int i;
43881- char cbuf[60];
43882+ char cbuf[80];
43883 isdn_ctrl cmd;
43884 icn_cdef cdef;
43885 char __user *arg;
43886@@ -1309,7 +1309,6 @@ icn_command(isdn_ctrl *c, icn_card *card)
43887 break;
43888 if ((c->arg & 255) < ICN_BCH) {
43889 char *p;
43890- char dial[50];
43891 char dcode[4];
43892
43893 a = c->arg;
43894@@ -1321,10 +1320,10 @@ icn_command(isdn_ctrl *c, icn_card *card)
43895 } else
43896 /* Normal Dial */
43897 strcpy(dcode, "CAL");
43898- strcpy(dial, p);
43899- sprintf(cbuf, "%02d;D%s_R%s,%02d,%02d,%s\n", (int) (a + 1),
43900- dcode, dial, c->parm.setup.si1,
43901- c->parm.setup.si2, c->parm.setup.eazmsn);
43902+ snprintf(cbuf, sizeof(cbuf),
43903+ "%02d;D%s_R%s,%02d,%02d,%s\n", (int) (a + 1),
43904+ dcode, p, c->parm.setup.si1,
43905+ c->parm.setup.si2, c->parm.setup.eazmsn);
43906 i = icn_writecmd(cbuf, strlen(cbuf), 0, card);
43907 }
43908 break;
43909diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
43910index a4f05c5..1433bc5 100644
43911--- a/drivers/isdn/mISDN/dsp_cmx.c
43912+++ b/drivers/isdn/mISDN/dsp_cmx.c
43913@@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
43914 static u16 dsp_count; /* last sample count */
43915 static int dsp_count_valid; /* if we have last sample count */
43916
43917-void
43918+void __intentional_overflow(-1)
43919 dsp_cmx_send(void *arg)
43920 {
43921 struct dsp_conf *conf;
43922diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
43923index d93e245..e7ece6b 100644
43924--- a/drivers/leds/leds-clevo-mail.c
43925+++ b/drivers/leds/leds-clevo-mail.c
43926@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
43927 * detected as working, but in reality it is not) as low as
43928 * possible.
43929 */
43930-static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
43931+static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
43932 {
43933 .callback = clevo_mail_led_dmi_callback,
43934 .ident = "Clevo D410J",
43935diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
43936index 5b8f938..b73d657 100644
43937--- a/drivers/leds/leds-ss4200.c
43938+++ b/drivers/leds/leds-ss4200.c
43939@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
43940 * detected as working, but in reality it is not) as low as
43941 * possible.
43942 */
43943-static struct dmi_system_id nas_led_whitelist[] __initdata = {
43944+static struct dmi_system_id nas_led_whitelist[] __initconst = {
43945 {
43946 .callback = ss4200_led_dmi_callback,
43947 .ident = "Intel SS4200-E",
43948diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
43949index 0bf1e4e..b4bf44e 100644
43950--- a/drivers/lguest/core.c
43951+++ b/drivers/lguest/core.c
43952@@ -97,9 +97,17 @@ static __init int map_switcher(void)
43953 * The end address needs +1 because __get_vm_area allocates an
43954 * extra guard page, so we need space for that.
43955 */
43956+
43957+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
43958+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43959+ VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
43960+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43961+#else
43962 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43963 VM_ALLOC, switcher_addr, switcher_addr
43964 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43965+#endif
43966+
43967 if (!switcher_vma) {
43968 err = -ENOMEM;
43969 printk("lguest: could not map switcher pages high\n");
43970@@ -124,7 +132,7 @@ static __init int map_switcher(void)
43971 * Now the Switcher is mapped at the right address, we can't fail!
43972 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
43973 */
43974- memcpy(switcher_vma->addr, start_switcher_text,
43975+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
43976 end_switcher_text - start_switcher_text);
43977
43978 printk(KERN_INFO "lguest: mapped switcher at %p\n",
43979diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
43980index bfb39bb..08a603b 100644
43981--- a/drivers/lguest/page_tables.c
43982+++ b/drivers/lguest/page_tables.c
43983@@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
43984 /*:*/
43985
43986 #ifdef CONFIG_X86_PAE
43987-static void release_pmd(pmd_t *spmd)
43988+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
43989 {
43990 /* If the entry's not present, there's nothing to release. */
43991 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
43992diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
43993index 922a1ac..9dd0c2a 100644
43994--- a/drivers/lguest/x86/core.c
43995+++ b/drivers/lguest/x86/core.c
43996@@ -59,7 +59,7 @@ static struct {
43997 /* Offset from where switcher.S was compiled to where we've copied it */
43998 static unsigned long switcher_offset(void)
43999 {
44000- return switcher_addr - (unsigned long)start_switcher_text;
44001+ return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
44002 }
44003
44004 /* This cpu's struct lguest_pages (after the Switcher text page) */
44005@@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
44006 * These copies are pretty cheap, so we do them unconditionally: */
44007 /* Save the current Host top-level page directory.
44008 */
44009+
44010+#ifdef CONFIG_PAX_PER_CPU_PGD
44011+ pages->state.host_cr3 = read_cr3();
44012+#else
44013 pages->state.host_cr3 = __pa(current->mm->pgd);
44014+#endif
44015+
44016 /*
44017 * Set up the Guest's page tables to see this CPU's pages (and no
44018 * other CPU's pages).
44019@@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
44020 * compiled-in switcher code and the high-mapped copy we just made.
44021 */
44022 for (i = 0; i < IDT_ENTRIES; i++)
44023- default_idt_entries[i] += switcher_offset();
44024+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
44025
44026 /*
44027 * Set up the Switcher's per-cpu areas.
44028@@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
44029 * it will be undisturbed when we switch. To change %cs and jump we
44030 * need this structure to feed to Intel's "lcall" instruction.
44031 */
44032- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
44033+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
44034 lguest_entry.segment = LGUEST_CS;
44035
44036 /*
44037diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
44038index 40634b0..4f5855e 100644
44039--- a/drivers/lguest/x86/switcher_32.S
44040+++ b/drivers/lguest/x86/switcher_32.S
44041@@ -87,6 +87,7 @@
44042 #include <asm/page.h>
44043 #include <asm/segment.h>
44044 #include <asm/lguest.h>
44045+#include <asm/processor-flags.h>
44046
44047 // We mark the start of the code to copy
44048 // It's placed in .text tho it's never run here
44049@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
44050 // Changes type when we load it: damn Intel!
44051 // For after we switch over our page tables
44052 // That entry will be read-only: we'd crash.
44053+
44054+#ifdef CONFIG_PAX_KERNEXEC
44055+ mov %cr0, %edx
44056+ xor $X86_CR0_WP, %edx
44057+ mov %edx, %cr0
44058+#endif
44059+
44060 movl $(GDT_ENTRY_TSS*8), %edx
44061 ltr %dx
44062
44063@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
44064 // Let's clear it again for our return.
44065 // The GDT descriptor of the Host
44066 // Points to the table after two "size" bytes
44067- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
44068+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
44069 // Clear "used" from type field (byte 5, bit 2)
44070- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
44071+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
44072+
44073+#ifdef CONFIG_PAX_KERNEXEC
44074+ mov %cr0, %eax
44075+ xor $X86_CR0_WP, %eax
44076+ mov %eax, %cr0
44077+#endif
44078
44079 // Once our page table's switched, the Guest is live!
44080 // The Host fades as we run this final step.
44081@@ -295,13 +309,12 @@ deliver_to_host:
44082 // I consulted gcc, and it gave
44083 // These instructions, which I gladly credit:
44084 leal (%edx,%ebx,8), %eax
44085- movzwl (%eax),%edx
44086- movl 4(%eax), %eax
44087- xorw %ax, %ax
44088- orl %eax, %edx
44089+ movl 4(%eax), %edx
44090+ movw (%eax), %dx
44091 // Now the address of the handler's in %edx
44092 // We call it now: its "iret" drops us home.
44093- jmp *%edx
44094+ ljmp $__KERNEL_CS, $1f
44095+1: jmp *%edx
44096
44097 // Every interrupt can come to us here
44098 // But we must truly tell each apart.
44099diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
44100index 7ef7461..5a09dac 100644
44101--- a/drivers/md/bcache/closure.h
44102+++ b/drivers/md/bcache/closure.h
44103@@ -238,7 +238,7 @@ static inline void closure_set_stopped(struct closure *cl)
44104 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
44105 struct workqueue_struct *wq)
44106 {
44107- BUG_ON(object_is_on_stack(cl));
44108+ BUG_ON(object_starts_on_stack(cl));
44109 closure_set_ip(cl);
44110 cl->fn = fn;
44111 cl->wq = wq;
44112diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
44113index 4195a01..42527ac 100644
44114--- a/drivers/md/bitmap.c
44115+++ b/drivers/md/bitmap.c
44116@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
44117 chunk_kb ? "KB" : "B");
44118 if (bitmap->storage.file) {
44119 seq_printf(seq, ", file: ");
44120- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
44121+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
44122 }
44123
44124 seq_printf(seq, "\n");
44125diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
44126index 5152142..623d141 100644
44127--- a/drivers/md/dm-ioctl.c
44128+++ b/drivers/md/dm-ioctl.c
44129@@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
44130 cmd == DM_LIST_VERSIONS_CMD)
44131 return 0;
44132
44133- if ((cmd == DM_DEV_CREATE_CMD)) {
44134+ if (cmd == DM_DEV_CREATE_CMD) {
44135 if (!*param->name) {
44136 DMWARN("name not supplied when creating device");
44137 return -EINVAL;
44138diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
44139index 7dfdb5c..4caada6 100644
44140--- a/drivers/md/dm-raid1.c
44141+++ b/drivers/md/dm-raid1.c
44142@@ -40,7 +40,7 @@ enum dm_raid1_error {
44143
44144 struct mirror {
44145 struct mirror_set *ms;
44146- atomic_t error_count;
44147+ atomic_unchecked_t error_count;
44148 unsigned long error_type;
44149 struct dm_dev *dev;
44150 sector_t offset;
44151@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
44152 struct mirror *m;
44153
44154 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
44155- if (!atomic_read(&m->error_count))
44156+ if (!atomic_read_unchecked(&m->error_count))
44157 return m;
44158
44159 return NULL;
44160@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
44161 * simple way to tell if a device has encountered
44162 * errors.
44163 */
44164- atomic_inc(&m->error_count);
44165+ atomic_inc_unchecked(&m->error_count);
44166
44167 if (test_and_set_bit(error_type, &m->error_type))
44168 return;
44169@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
44170 struct mirror *m = get_default_mirror(ms);
44171
44172 do {
44173- if (likely(!atomic_read(&m->error_count)))
44174+ if (likely(!atomic_read_unchecked(&m->error_count)))
44175 return m;
44176
44177 if (m-- == ms->mirror)
44178@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
44179 {
44180 struct mirror *default_mirror = get_default_mirror(m->ms);
44181
44182- return !atomic_read(&default_mirror->error_count);
44183+ return !atomic_read_unchecked(&default_mirror->error_count);
44184 }
44185
44186 static int mirror_available(struct mirror_set *ms, struct bio *bio)
44187@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
44188 */
44189 if (likely(region_in_sync(ms, region, 1)))
44190 m = choose_mirror(ms, bio->bi_iter.bi_sector);
44191- else if (m && atomic_read(&m->error_count))
44192+ else if (m && atomic_read_unchecked(&m->error_count))
44193 m = NULL;
44194
44195 if (likely(m))
44196@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
44197 }
44198
44199 ms->mirror[mirror].ms = ms;
44200- atomic_set(&(ms->mirror[mirror].error_count), 0);
44201+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
44202 ms->mirror[mirror].error_type = 0;
44203 ms->mirror[mirror].offset = offset;
44204
44205@@ -1342,7 +1342,7 @@ static void mirror_resume(struct dm_target *ti)
44206 */
44207 static char device_status_char(struct mirror *m)
44208 {
44209- if (!atomic_read(&(m->error_count)))
44210+ if (!atomic_read_unchecked(&(m->error_count)))
44211 return 'A';
44212
44213 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
44214diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
44215index 28a9012..9c0f6a5 100644
44216--- a/drivers/md/dm-stats.c
44217+++ b/drivers/md/dm-stats.c
44218@@ -382,7 +382,7 @@ do_sync_free:
44219 synchronize_rcu_expedited();
44220 dm_stat_free(&s->rcu_head);
44221 } else {
44222- ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
44223+ ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
44224 call_rcu(&s->rcu_head, dm_stat_free);
44225 }
44226 return 0;
44227@@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
44228 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
44229 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
44230 ));
44231- ACCESS_ONCE(last->last_sector) = end_sector;
44232- ACCESS_ONCE(last->last_rw) = bi_rw;
44233+ ACCESS_ONCE_RW(last->last_sector) = end_sector;
44234+ ACCESS_ONCE_RW(last->last_rw) = bi_rw;
44235 }
44236
44237 rcu_read_lock();
44238diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
44239index d1600d2..4c3af3a 100644
44240--- a/drivers/md/dm-stripe.c
44241+++ b/drivers/md/dm-stripe.c
44242@@ -21,7 +21,7 @@ struct stripe {
44243 struct dm_dev *dev;
44244 sector_t physical_start;
44245
44246- atomic_t error_count;
44247+ atomic_unchecked_t error_count;
44248 };
44249
44250 struct stripe_c {
44251@@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
44252 kfree(sc);
44253 return r;
44254 }
44255- atomic_set(&(sc->stripe[i].error_count), 0);
44256+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
44257 }
44258
44259 ti->private = sc;
44260@@ -330,7 +330,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
44261 DMEMIT("%d ", sc->stripes);
44262 for (i = 0; i < sc->stripes; i++) {
44263 DMEMIT("%s ", sc->stripe[i].dev->name);
44264- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
44265+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
44266 'D' : 'A';
44267 }
44268 buffer[i] = '\0';
44269@@ -375,8 +375,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
44270 */
44271 for (i = 0; i < sc->stripes; i++)
44272 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
44273- atomic_inc(&(sc->stripe[i].error_count));
44274- if (atomic_read(&(sc->stripe[i].error_count)) <
44275+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
44276+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
44277 DM_IO_ERROR_THRESHOLD)
44278 schedule_work(&sc->trigger_event);
44279 }
44280diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
44281index 6a7f2b8..fea0bde 100644
44282--- a/drivers/md/dm-table.c
44283+++ b/drivers/md/dm-table.c
44284@@ -274,7 +274,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
44285 static int open_dev(struct dm_dev_internal *d, dev_t dev,
44286 struct mapped_device *md)
44287 {
44288- static char *_claim_ptr = "I belong to device-mapper";
44289+ static char _claim_ptr[] = "I belong to device-mapper";
44290 struct block_device *bdev;
44291
44292 int r;
44293@@ -342,7 +342,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
44294 if (!dev_size)
44295 return 0;
44296
44297- if ((start >= dev_size) || (start + len > dev_size)) {
44298+ if ((start >= dev_size) || (len > dev_size - start)) {
44299 DMWARN("%s: %s too small for target: "
44300 "start=%llu, len=%llu, dev_size=%llu",
44301 dm_device_name(ti->table->md), bdevname(bdev, b),
44302diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
44303index b086a94..74cb67e 100644
44304--- a/drivers/md/dm-thin-metadata.c
44305+++ b/drivers/md/dm-thin-metadata.c
44306@@ -404,7 +404,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
44307 {
44308 pmd->info.tm = pmd->tm;
44309 pmd->info.levels = 2;
44310- pmd->info.value_type.context = pmd->data_sm;
44311+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
44312 pmd->info.value_type.size = sizeof(__le64);
44313 pmd->info.value_type.inc = data_block_inc;
44314 pmd->info.value_type.dec = data_block_dec;
44315@@ -423,7 +423,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
44316
44317 pmd->bl_info.tm = pmd->tm;
44318 pmd->bl_info.levels = 1;
44319- pmd->bl_info.value_type.context = pmd->data_sm;
44320+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
44321 pmd->bl_info.value_type.size = sizeof(__le64);
44322 pmd->bl_info.value_type.inc = data_block_inc;
44323 pmd->bl_info.value_type.dec = data_block_dec;
44324diff --git a/drivers/md/dm.c b/drivers/md/dm.c
44325index 8c53b09..f1fb2b0 100644
44326--- a/drivers/md/dm.c
44327+++ b/drivers/md/dm.c
44328@@ -185,9 +185,9 @@ struct mapped_device {
44329 /*
44330 * Event handling.
44331 */
44332- atomic_t event_nr;
44333+ atomic_unchecked_t event_nr;
44334 wait_queue_head_t eventq;
44335- atomic_t uevent_seq;
44336+ atomic_unchecked_t uevent_seq;
44337 struct list_head uevent_list;
44338 spinlock_t uevent_lock; /* Protect access to uevent_list */
44339
44340@@ -1888,8 +1888,8 @@ static struct mapped_device *alloc_dev(int minor)
44341 spin_lock_init(&md->deferred_lock);
44342 atomic_set(&md->holders, 1);
44343 atomic_set(&md->open_count, 0);
44344- atomic_set(&md->event_nr, 0);
44345- atomic_set(&md->uevent_seq, 0);
44346+ atomic_set_unchecked(&md->event_nr, 0);
44347+ atomic_set_unchecked(&md->uevent_seq, 0);
44348 INIT_LIST_HEAD(&md->uevent_list);
44349 spin_lock_init(&md->uevent_lock);
44350
44351@@ -2043,7 +2043,7 @@ static void event_callback(void *context)
44352
44353 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
44354
44355- atomic_inc(&md->event_nr);
44356+ atomic_inc_unchecked(&md->event_nr);
44357 wake_up(&md->eventq);
44358 }
44359
44360@@ -2736,18 +2736,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
44361
44362 uint32_t dm_next_uevent_seq(struct mapped_device *md)
44363 {
44364- return atomic_add_return(1, &md->uevent_seq);
44365+ return atomic_add_return_unchecked(1, &md->uevent_seq);
44366 }
44367
44368 uint32_t dm_get_event_nr(struct mapped_device *md)
44369 {
44370- return atomic_read(&md->event_nr);
44371+ return atomic_read_unchecked(&md->event_nr);
44372 }
44373
44374 int dm_wait_event(struct mapped_device *md, int event_nr)
44375 {
44376 return wait_event_interruptible(md->eventq,
44377- (event_nr != atomic_read(&md->event_nr)));
44378+ (event_nr != atomic_read_unchecked(&md->event_nr)));
44379 }
44380
44381 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
44382diff --git a/drivers/md/md.c b/drivers/md/md.c
44383index 4ad5cc4..0f19664 100644
44384--- a/drivers/md/md.c
44385+++ b/drivers/md/md.c
44386@@ -194,10 +194,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
44387 * start build, activate spare
44388 */
44389 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
44390-static atomic_t md_event_count;
44391+static atomic_unchecked_t md_event_count;
44392 void md_new_event(struct mddev *mddev)
44393 {
44394- atomic_inc(&md_event_count);
44395+ atomic_inc_unchecked(&md_event_count);
44396 wake_up(&md_event_waiters);
44397 }
44398 EXPORT_SYMBOL_GPL(md_new_event);
44399@@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
44400 */
44401 static void md_new_event_inintr(struct mddev *mddev)
44402 {
44403- atomic_inc(&md_event_count);
44404+ atomic_inc_unchecked(&md_event_count);
44405 wake_up(&md_event_waiters);
44406 }
44407
44408@@ -1462,7 +1462,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
44409 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
44410 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
44411 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
44412- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
44413+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
44414
44415 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
44416 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
44417@@ -1713,7 +1713,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
44418 else
44419 sb->resync_offset = cpu_to_le64(0);
44420
44421- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
44422+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
44423
44424 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
44425 sb->size = cpu_to_le64(mddev->dev_sectors);
44426@@ -2725,7 +2725,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
44427 static ssize_t
44428 errors_show(struct md_rdev *rdev, char *page)
44429 {
44430- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
44431+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
44432 }
44433
44434 static ssize_t
44435@@ -2734,7 +2734,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
44436 char *e;
44437 unsigned long n = simple_strtoul(buf, &e, 10);
44438 if (*buf && (*e == 0 || *e == '\n')) {
44439- atomic_set(&rdev->corrected_errors, n);
44440+ atomic_set_unchecked(&rdev->corrected_errors, n);
44441 return len;
44442 }
44443 return -EINVAL;
44444@@ -3183,8 +3183,8 @@ int md_rdev_init(struct md_rdev *rdev)
44445 rdev->sb_loaded = 0;
44446 rdev->bb_page = NULL;
44447 atomic_set(&rdev->nr_pending, 0);
44448- atomic_set(&rdev->read_errors, 0);
44449- atomic_set(&rdev->corrected_errors, 0);
44450+ atomic_set_unchecked(&rdev->read_errors, 0);
44451+ atomic_set_unchecked(&rdev->corrected_errors, 0);
44452
44453 INIT_LIST_HEAD(&rdev->same_set);
44454 init_waitqueue_head(&rdev->blocked_wait);
44455@@ -7075,7 +7075,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
44456
44457 spin_unlock(&pers_lock);
44458 seq_printf(seq, "\n");
44459- seq->poll_event = atomic_read(&md_event_count);
44460+ seq->poll_event = atomic_read_unchecked(&md_event_count);
44461 return 0;
44462 }
44463 if (v == (void*)2) {
44464@@ -7178,7 +7178,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
44465 return error;
44466
44467 seq = file->private_data;
44468- seq->poll_event = atomic_read(&md_event_count);
44469+ seq->poll_event = atomic_read_unchecked(&md_event_count);
44470 return error;
44471 }
44472
44473@@ -7192,7 +7192,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
44474 /* always allow read */
44475 mask = POLLIN | POLLRDNORM;
44476
44477- if (seq->poll_event != atomic_read(&md_event_count))
44478+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
44479 mask |= POLLERR | POLLPRI;
44480 return mask;
44481 }
44482@@ -7236,7 +7236,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
44483 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
44484 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
44485 (int)part_stat_read(&disk->part0, sectors[1]) -
44486- atomic_read(&disk->sync_io);
44487+ atomic_read_unchecked(&disk->sync_io);
44488 /* sync IO will cause sync_io to increase before the disk_stats
44489 * as sync_io is counted when a request starts, and
44490 * disk_stats is counted when it completes.
44491diff --git a/drivers/md/md.h b/drivers/md/md.h
44492index 07bba96..2d6788c 100644
44493--- a/drivers/md/md.h
44494+++ b/drivers/md/md.h
44495@@ -94,13 +94,13 @@ struct md_rdev {
44496 * only maintained for arrays that
44497 * support hot removal
44498 */
44499- atomic_t read_errors; /* number of consecutive read errors that
44500+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
44501 * we have tried to ignore.
44502 */
44503 struct timespec last_read_error; /* monotonic time since our
44504 * last read error
44505 */
44506- atomic_t corrected_errors; /* number of corrected read errors,
44507+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
44508 * for reporting to userspace and storing
44509 * in superblock.
44510 */
44511@@ -449,7 +449,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
44512
44513 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
44514 {
44515- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44516+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44517 }
44518
44519 struct md_personality
44520diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
44521index 786b689..ea8c956 100644
44522--- a/drivers/md/persistent-data/dm-space-map-metadata.c
44523+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
44524@@ -679,7 +679,7 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
44525 * Flick into a mode where all blocks get allocated in the new area.
44526 */
44527 smm->begin = old_len;
44528- memcpy(sm, &bootstrap_ops, sizeof(*sm));
44529+ memcpy((void *)sm, &bootstrap_ops, sizeof(*sm));
44530
44531 /*
44532 * Extend.
44533@@ -710,7 +710,7 @@ out:
44534 /*
44535 * Switch back to normal behaviour.
44536 */
44537- memcpy(sm, &ops, sizeof(*sm));
44538+ memcpy((void *)sm, &ops, sizeof(*sm));
44539 return r;
44540 }
44541
44542diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
44543index 3e6d115..ffecdeb 100644
44544--- a/drivers/md/persistent-data/dm-space-map.h
44545+++ b/drivers/md/persistent-data/dm-space-map.h
44546@@ -71,6 +71,7 @@ struct dm_space_map {
44547 dm_sm_threshold_fn fn,
44548 void *context);
44549 };
44550+typedef struct dm_space_map __no_const dm_space_map_no_const;
44551
44552 /*----------------------------------------------------------------*/
44553
44554diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
44555index 4a6ca1c..e952750 100644
44556--- a/drivers/md/raid1.c
44557+++ b/drivers/md/raid1.c
44558@@ -1922,7 +1922,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
44559 if (r1_sync_page_io(rdev, sect, s,
44560 bio->bi_io_vec[idx].bv_page,
44561 READ) != 0)
44562- atomic_add(s, &rdev->corrected_errors);
44563+ atomic_add_unchecked(s, &rdev->corrected_errors);
44564 }
44565 sectors -= s;
44566 sect += s;
44567@@ -2156,7 +2156,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
44568 test_bit(In_sync, &rdev->flags)) {
44569 if (r1_sync_page_io(rdev, sect, s,
44570 conf->tmppage, READ)) {
44571- atomic_add(s, &rdev->corrected_errors);
44572+ atomic_add_unchecked(s, &rdev->corrected_errors);
44573 printk(KERN_INFO
44574 "md/raid1:%s: read error corrected "
44575 "(%d sectors at %llu on %s)\n",
44576diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
44577index 33fc408..fc61709 100644
44578--- a/drivers/md/raid10.c
44579+++ b/drivers/md/raid10.c
44580@@ -1948,7 +1948,7 @@ static void end_sync_read(struct bio *bio, int error)
44581 /* The write handler will notice the lack of
44582 * R10BIO_Uptodate and record any errors etc
44583 */
44584- atomic_add(r10_bio->sectors,
44585+ atomic_add_unchecked(r10_bio->sectors,
44586 &conf->mirrors[d].rdev->corrected_errors);
44587
44588 /* for reconstruct, we always reschedule after a read.
44589@@ -2306,7 +2306,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44590 {
44591 struct timespec cur_time_mon;
44592 unsigned long hours_since_last;
44593- unsigned int read_errors = atomic_read(&rdev->read_errors);
44594+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
44595
44596 ktime_get_ts(&cur_time_mon);
44597
44598@@ -2328,9 +2328,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44599 * overflowing the shift of read_errors by hours_since_last.
44600 */
44601 if (hours_since_last >= 8 * sizeof(read_errors))
44602- atomic_set(&rdev->read_errors, 0);
44603+ atomic_set_unchecked(&rdev->read_errors, 0);
44604 else
44605- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
44606+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
44607 }
44608
44609 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
44610@@ -2384,8 +2384,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44611 return;
44612
44613 check_decay_read_errors(mddev, rdev);
44614- atomic_inc(&rdev->read_errors);
44615- if (atomic_read(&rdev->read_errors) > max_read_errors) {
44616+ atomic_inc_unchecked(&rdev->read_errors);
44617+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
44618 char b[BDEVNAME_SIZE];
44619 bdevname(rdev->bdev, b);
44620
44621@@ -2393,7 +2393,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44622 "md/raid10:%s: %s: Raid device exceeded "
44623 "read_error threshold [cur %d:max %d]\n",
44624 mdname(mddev), b,
44625- atomic_read(&rdev->read_errors), max_read_errors);
44626+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
44627 printk(KERN_NOTICE
44628 "md/raid10:%s: %s: Failing raid device\n",
44629 mdname(mddev), b);
44630@@ -2548,7 +2548,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44631 sect +
44632 choose_data_offset(r10_bio, rdev)),
44633 bdevname(rdev->bdev, b));
44634- atomic_add(s, &rdev->corrected_errors);
44635+ atomic_add_unchecked(s, &rdev->corrected_errors);
44636 }
44637
44638 rdev_dec_pending(rdev, mddev);
44639diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
44640index 16f5c21..4df20dc 100644
44641--- a/drivers/md/raid5.c
44642+++ b/drivers/md/raid5.c
44643@@ -1991,21 +1991,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
44644 mdname(conf->mddev), STRIPE_SECTORS,
44645 (unsigned long long)s,
44646 bdevname(rdev->bdev, b));
44647- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
44648+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
44649 clear_bit(R5_ReadError, &sh->dev[i].flags);
44650 clear_bit(R5_ReWrite, &sh->dev[i].flags);
44651 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
44652 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
44653
44654- if (atomic_read(&rdev->read_errors))
44655- atomic_set(&rdev->read_errors, 0);
44656+ if (atomic_read_unchecked(&rdev->read_errors))
44657+ atomic_set_unchecked(&rdev->read_errors, 0);
44658 } else {
44659 const char *bdn = bdevname(rdev->bdev, b);
44660 int retry = 0;
44661 int set_bad = 0;
44662
44663 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
44664- atomic_inc(&rdev->read_errors);
44665+ atomic_inc_unchecked(&rdev->read_errors);
44666 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
44667 printk_ratelimited(
44668 KERN_WARNING
44669@@ -2033,7 +2033,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
44670 mdname(conf->mddev),
44671 (unsigned long long)s,
44672 bdn);
44673- } else if (atomic_read(&rdev->read_errors)
44674+ } else if (atomic_read_unchecked(&rdev->read_errors)
44675 > conf->max_nr_stripes)
44676 printk(KERN_WARNING
44677 "md/raid:%s: Too many read errors, failing device %s.\n",
44678diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
44679index 983db75..ef9248c 100644
44680--- a/drivers/media/dvb-core/dvbdev.c
44681+++ b/drivers/media/dvb-core/dvbdev.c
44682@@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
44683 const struct dvb_device *template, void *priv, int type)
44684 {
44685 struct dvb_device *dvbdev;
44686- struct file_operations *dvbdevfops;
44687+ file_operations_no_const *dvbdevfops;
44688 struct device *clsdev;
44689 int minor;
44690 int id;
44691diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
44692index 9b6c3bb..baeb5c7 100644
44693--- a/drivers/media/dvb-frontends/dib3000.h
44694+++ b/drivers/media/dvb-frontends/dib3000.h
44695@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
44696 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
44697 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
44698 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
44699-};
44700+} __no_const;
44701
44702 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
44703 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
44704diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
44705index d5a7a13..703560f 100644
44706--- a/drivers/media/media-device.c
44707+++ b/drivers/media/media-device.c
44708@@ -93,6 +93,7 @@ static long media_device_enum_entities(struct media_device *mdev,
44709 struct media_entity *ent;
44710 struct media_entity_desc u_ent;
44711
44712+ memset(&u_ent, 0, sizeof(u_ent));
44713 if (copy_from_user(&u_ent.id, &uent->id, sizeof(u_ent.id)))
44714 return -EFAULT;
44715
44716diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
44717index ed8cb90..5ef7f79 100644
44718--- a/drivers/media/pci/cx88/cx88-video.c
44719+++ b/drivers/media/pci/cx88/cx88-video.c
44720@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
44721
44722 /* ------------------------------------------------------------------ */
44723
44724-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44725-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44726-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44727+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44728+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44729+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44730
44731 module_param_array(video_nr, int, NULL, 0444);
44732 module_param_array(vbi_nr, int, NULL, 0444);
44733diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
44734index 802642d..5534900 100644
44735--- a/drivers/media/pci/ivtv/ivtv-driver.c
44736+++ b/drivers/media/pci/ivtv/ivtv-driver.c
44737@@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
44738 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
44739
44740 /* ivtv instance counter */
44741-static atomic_t ivtv_instance = ATOMIC_INIT(0);
44742+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
44743
44744 /* Parameter declarations */
44745 static int cardtype[IVTV_MAX_CARDS];
44746diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
44747index dfd0a21..6bbb465 100644
44748--- a/drivers/media/platform/omap/omap_vout.c
44749+++ b/drivers/media/platform/omap/omap_vout.c
44750@@ -63,7 +63,6 @@ enum omap_vout_channels {
44751 OMAP_VIDEO2,
44752 };
44753
44754-static struct videobuf_queue_ops video_vbq_ops;
44755 /* Variables configurable through module params*/
44756 static u32 video1_numbuffers = 3;
44757 static u32 video2_numbuffers = 3;
44758@@ -1014,6 +1013,12 @@ static int omap_vout_open(struct file *file)
44759 {
44760 struct videobuf_queue *q;
44761 struct omap_vout_device *vout = NULL;
44762+ static struct videobuf_queue_ops video_vbq_ops = {
44763+ .buf_setup = omap_vout_buffer_setup,
44764+ .buf_prepare = omap_vout_buffer_prepare,
44765+ .buf_release = omap_vout_buffer_release,
44766+ .buf_queue = omap_vout_buffer_queue,
44767+ };
44768
44769 vout = video_drvdata(file);
44770 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
44771@@ -1031,10 +1036,6 @@ static int omap_vout_open(struct file *file)
44772 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
44773
44774 q = &vout->vbq;
44775- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
44776- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
44777- video_vbq_ops.buf_release = omap_vout_buffer_release;
44778- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
44779 spin_lock_init(&vout->vbq_lock);
44780
44781 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
44782diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
44783index fb2acc5..a2fcbdc4 100644
44784--- a/drivers/media/platform/s5p-tv/mixer.h
44785+++ b/drivers/media/platform/s5p-tv/mixer.h
44786@@ -156,7 +156,7 @@ struct mxr_layer {
44787 /** layer index (unique identifier) */
44788 int idx;
44789 /** callbacks for layer methods */
44790- struct mxr_layer_ops ops;
44791+ struct mxr_layer_ops *ops;
44792 /** format array */
44793 const struct mxr_format **fmt_array;
44794 /** size of format array */
44795diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44796index 74344c7..a39e70e 100644
44797--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44798+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44799@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
44800 {
44801 struct mxr_layer *layer;
44802 int ret;
44803- struct mxr_layer_ops ops = {
44804+ static struct mxr_layer_ops ops = {
44805 .release = mxr_graph_layer_release,
44806 .buffer_set = mxr_graph_buffer_set,
44807 .stream_set = mxr_graph_stream_set,
44808diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
44809index b713403..53cb5ad 100644
44810--- a/drivers/media/platform/s5p-tv/mixer_reg.c
44811+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
44812@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
44813 layer->update_buf = next;
44814 }
44815
44816- layer->ops.buffer_set(layer, layer->update_buf);
44817+ layer->ops->buffer_set(layer, layer->update_buf);
44818
44819 if (done && done != layer->shadow_buf)
44820 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
44821diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
44822index c5059ba..2649f28 100644
44823--- a/drivers/media/platform/s5p-tv/mixer_video.c
44824+++ b/drivers/media/platform/s5p-tv/mixer_video.c
44825@@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
44826 layer->geo.src.height = layer->geo.src.full_height;
44827
44828 mxr_geometry_dump(mdev, &layer->geo);
44829- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44830+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44831 mxr_geometry_dump(mdev, &layer->geo);
44832 }
44833
44834@@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
44835 layer->geo.dst.full_width = mbus_fmt.width;
44836 layer->geo.dst.full_height = mbus_fmt.height;
44837 layer->geo.dst.field = mbus_fmt.field;
44838- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44839+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44840
44841 mxr_geometry_dump(mdev, &layer->geo);
44842 }
44843@@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
44844 /* set source size to highest accepted value */
44845 geo->src.full_width = max(geo->dst.full_width, pix->width);
44846 geo->src.full_height = max(geo->dst.full_height, pix->height);
44847- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44848+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44849 mxr_geometry_dump(mdev, &layer->geo);
44850 /* set cropping to total visible screen */
44851 geo->src.width = pix->width;
44852@@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
44853 geo->src.x_offset = 0;
44854 geo->src.y_offset = 0;
44855 /* assure consistency of geometry */
44856- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44857+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44858 mxr_geometry_dump(mdev, &layer->geo);
44859 /* set full size to lowest possible value */
44860 geo->src.full_width = 0;
44861 geo->src.full_height = 0;
44862- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44863+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44864 mxr_geometry_dump(mdev, &layer->geo);
44865
44866 /* returning results */
44867@@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
44868 target->width = s->r.width;
44869 target->height = s->r.height;
44870
44871- layer->ops.fix_geometry(layer, stage, s->flags);
44872+ layer->ops->fix_geometry(layer, stage, s->flags);
44873
44874 /* retrieve update selection rectangle */
44875 res.left = target->x_offset;
44876@@ -955,13 +955,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
44877 mxr_output_get(mdev);
44878
44879 mxr_layer_update_output(layer);
44880- layer->ops.format_set(layer);
44881+ layer->ops->format_set(layer);
44882 /* enabling layer in hardware */
44883 spin_lock_irqsave(&layer->enq_slock, flags);
44884 layer->state = MXR_LAYER_STREAMING;
44885 spin_unlock_irqrestore(&layer->enq_slock, flags);
44886
44887- layer->ops.stream_set(layer, MXR_ENABLE);
44888+ layer->ops->stream_set(layer, MXR_ENABLE);
44889 mxr_streamer_get(mdev);
44890
44891 return 0;
44892@@ -1031,7 +1031,7 @@ static int stop_streaming(struct vb2_queue *vq)
44893 spin_unlock_irqrestore(&layer->enq_slock, flags);
44894
44895 /* disabling layer in hardware */
44896- layer->ops.stream_set(layer, MXR_DISABLE);
44897+ layer->ops->stream_set(layer, MXR_DISABLE);
44898 /* remove one streamer */
44899 mxr_streamer_put(mdev);
44900 /* allow changes in output configuration */
44901@@ -1070,8 +1070,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
44902
44903 void mxr_layer_release(struct mxr_layer *layer)
44904 {
44905- if (layer->ops.release)
44906- layer->ops.release(layer);
44907+ if (layer->ops->release)
44908+ layer->ops->release(layer);
44909 }
44910
44911 void mxr_base_layer_release(struct mxr_layer *layer)
44912@@ -1097,7 +1097,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
44913
44914 layer->mdev = mdev;
44915 layer->idx = idx;
44916- layer->ops = *ops;
44917+ layer->ops = ops;
44918
44919 spin_lock_init(&layer->enq_slock);
44920 INIT_LIST_HEAD(&layer->enq_list);
44921diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44922index c9388c4..ce71ece 100644
44923--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44924+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44925@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
44926 {
44927 struct mxr_layer *layer;
44928 int ret;
44929- struct mxr_layer_ops ops = {
44930+ static struct mxr_layer_ops ops = {
44931 .release = mxr_vp_layer_release,
44932 .buffer_set = mxr_vp_buffer_set,
44933 .stream_set = mxr_vp_stream_set,
44934diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
44935index 2d4e73b..8b4d5b6 100644
44936--- a/drivers/media/platform/vivi.c
44937+++ b/drivers/media/platform/vivi.c
44938@@ -58,8 +58,8 @@ MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
44939 MODULE_LICENSE("Dual BSD/GPL");
44940 MODULE_VERSION(VIVI_VERSION);
44941
44942-static unsigned video_nr = -1;
44943-module_param(video_nr, uint, 0644);
44944+static int video_nr = -1;
44945+module_param(video_nr, int, 0644);
44946 MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect");
44947
44948 static unsigned n_devs = 1;
44949diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
44950index 545c04c..a14bded 100644
44951--- a/drivers/media/radio/radio-cadet.c
44952+++ b/drivers/media/radio/radio-cadet.c
44953@@ -324,6 +324,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44954 unsigned char readbuf[RDS_BUFFER];
44955 int i = 0;
44956
44957+ if (count > RDS_BUFFER)
44958+ return -EFAULT;
44959 mutex_lock(&dev->lock);
44960 if (dev->rdsstat == 0)
44961 cadet_start_rds(dev);
44962@@ -339,7 +341,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44963 while (i < count && dev->rdsin != dev->rdsout)
44964 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
44965
44966- if (i && copy_to_user(data, readbuf, i))
44967+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
44968 i = -EFAULT;
44969 unlock:
44970 mutex_unlock(&dev->lock);
44971diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
44972index 5236035..c622c74 100644
44973--- a/drivers/media/radio/radio-maxiradio.c
44974+++ b/drivers/media/radio/radio-maxiradio.c
44975@@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
44976 /* TEA5757 pin mappings */
44977 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
44978
44979-static atomic_t maxiradio_instance = ATOMIC_INIT(0);
44980+static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
44981
44982 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
44983 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
44984diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
44985index 050b3bb..79f62b9 100644
44986--- a/drivers/media/radio/radio-shark.c
44987+++ b/drivers/media/radio/radio-shark.c
44988@@ -79,7 +79,7 @@ struct shark_device {
44989 u32 last_val;
44990 };
44991
44992-static atomic_t shark_instance = ATOMIC_INIT(0);
44993+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
44994
44995 static void shark_write_val(struct snd_tea575x *tea, u32 val)
44996 {
44997diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
44998index 8654e0d..0608a64 100644
44999--- a/drivers/media/radio/radio-shark2.c
45000+++ b/drivers/media/radio/radio-shark2.c
45001@@ -74,7 +74,7 @@ struct shark_device {
45002 u8 *transfer_buffer;
45003 };
45004
45005-static atomic_t shark_instance = ATOMIC_INIT(0);
45006+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
45007
45008 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
45009 {
45010diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
45011index 2fd9009..278cc1e 100644
45012--- a/drivers/media/radio/radio-si476x.c
45013+++ b/drivers/media/radio/radio-si476x.c
45014@@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
45015 struct si476x_radio *radio;
45016 struct v4l2_ctrl *ctrl;
45017
45018- static atomic_t instance = ATOMIC_INIT(0);
45019+ static atomic_unchecked_t instance = ATOMIC_INIT(0);
45020
45021 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
45022 if (!radio)
45023diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
45024index a1c641e..3007da9 100644
45025--- a/drivers/media/usb/dvb-usb/cxusb.c
45026+++ b/drivers/media/usb/dvb-usb/cxusb.c
45027@@ -1112,7 +1112,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
45028
45029 struct dib0700_adapter_state {
45030 int (*set_param_save) (struct dvb_frontend *);
45031-};
45032+} __no_const;
45033
45034 static int dib7070_set_param_override(struct dvb_frontend *fe)
45035 {
45036diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
45037index ae0f56a..ec71784 100644
45038--- a/drivers/media/usb/dvb-usb/dw2102.c
45039+++ b/drivers/media/usb/dvb-usb/dw2102.c
45040@@ -118,7 +118,7 @@ struct su3000_state {
45041
45042 struct s6x0_state {
45043 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
45044-};
45045+} __no_const;
45046
45047 /* debug */
45048 static int dvb_usb_dw2102_debug;
45049diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
45050index b63a5e5..b16a062 100644
45051--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
45052+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
45053@@ -326,7 +326,7 @@ struct v4l2_buffer32 {
45054 __u32 reserved;
45055 };
45056
45057-static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
45058+static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
45059 enum v4l2_memory memory)
45060 {
45061 void __user *up_pln;
45062@@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
45063 return 0;
45064 }
45065
45066-static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
45067+static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
45068 enum v4l2_memory memory)
45069 {
45070 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
45071@@ -425,7 +425,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
45072 * by passing a very big num_planes value */
45073 uplane = compat_alloc_user_space(num_planes *
45074 sizeof(struct v4l2_plane));
45075- kp->m.planes = uplane;
45076+ kp->m.planes = (struct v4l2_plane __force_kernel *)uplane;
45077
45078 while (--num_planes >= 0) {
45079 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
45080@@ -496,7 +496,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
45081 if (num_planes == 0)
45082 return 0;
45083
45084- uplane = kp->m.planes;
45085+ uplane = (struct v4l2_plane __force_user *)kp->m.planes;
45086 if (get_user(p, &up->m.planes))
45087 return -EFAULT;
45088 uplane32 = compat_ptr(p);
45089@@ -550,7 +550,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
45090 get_user(kp->capability, &up->capability) ||
45091 get_user(kp->flags, &up->flags))
45092 return -EFAULT;
45093- kp->base = compat_ptr(tmp);
45094+ kp->base = (void __force_kernel *)compat_ptr(tmp);
45095 get_v4l2_pix_format(&kp->fmt, &up->fmt);
45096 return 0;
45097 }
45098@@ -656,7 +656,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
45099 n * sizeof(struct v4l2_ext_control32)))
45100 return -EFAULT;
45101 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
45102- kp->controls = kcontrols;
45103+ kp->controls = (struct v4l2_ext_control __force_kernel *)kcontrols;
45104 while (--n >= 0) {
45105 if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
45106 return -EFAULT;
45107@@ -678,7 +678,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
45108 static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
45109 {
45110 struct v4l2_ext_control32 __user *ucontrols;
45111- struct v4l2_ext_control __user *kcontrols = kp->controls;
45112+ struct v4l2_ext_control __user *kcontrols = (struct v4l2_ext_control __force_user *)kp->controls;
45113 int n = kp->count;
45114 compat_caddr_t p;
45115
45116@@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
45117 put_user(kp->start_block, &up->start_block) ||
45118 put_user(kp->blocks, &up->blocks) ||
45119 put_user(tmp, &up->edid) ||
45120- copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
45121+ copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
45122 return -EFAULT;
45123 return 0;
45124 }
45125diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
45126index 6ff002b..6b9316b 100644
45127--- a/drivers/media/v4l2-core/v4l2-ctrls.c
45128+++ b/drivers/media/v4l2-core/v4l2-ctrls.c
45129@@ -1401,8 +1401,8 @@ static int validate_new(const struct v4l2_ctrl *ctrl,
45130 return 0;
45131
45132 case V4L2_CTRL_TYPE_STRING:
45133- len = strlen(c->string);
45134- if (len < ctrl->minimum)
45135+ len = strlen_user(c->string);
45136+ if (!len || len < ctrl->minimum)
45137 return -ERANGE;
45138 if ((len - ctrl->minimum) % ctrl->step)
45139 return -ERANGE;
45140diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
45141index 02d1b63..5fd6b16 100644
45142--- a/drivers/media/v4l2-core/v4l2-device.c
45143+++ b/drivers/media/v4l2-core/v4l2-device.c
45144@@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
45145 EXPORT_SYMBOL_GPL(v4l2_device_put);
45146
45147 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
45148- atomic_t *instance)
45149+ atomic_unchecked_t *instance)
45150 {
45151- int num = atomic_inc_return(instance) - 1;
45152+ int num = atomic_inc_return_unchecked(instance) - 1;
45153 int len = strlen(basename);
45154
45155 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
45156diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
45157index 707aef7..93b8ac0 100644
45158--- a/drivers/media/v4l2-core/v4l2-ioctl.c
45159+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
45160@@ -1942,7 +1942,8 @@ struct v4l2_ioctl_info {
45161 struct file *file, void *fh, void *p);
45162 } u;
45163 void (*debug)(const void *arg, bool write_only);
45164-};
45165+} __do_const;
45166+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
45167
45168 /* This control needs a priority check */
45169 #define INFO_FL_PRIO (1 << 0)
45170@@ -2123,7 +2124,7 @@ static long __video_do_ioctl(struct file *file,
45171 struct video_device *vfd = video_devdata(file);
45172 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
45173 bool write_only = false;
45174- struct v4l2_ioctl_info default_info;
45175+ v4l2_ioctl_info_no_const default_info;
45176 const struct v4l2_ioctl_info *info;
45177 void *fh = file->private_data;
45178 struct v4l2_fh *vfh = NULL;
45179@@ -2197,7 +2198,7 @@ done:
45180 }
45181
45182 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
45183- void * __user *user_ptr, void ***kernel_ptr)
45184+ void __user **user_ptr, void ***kernel_ptr)
45185 {
45186 int ret = 0;
45187
45188@@ -2213,7 +2214,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
45189 ret = -EINVAL;
45190 break;
45191 }
45192- *user_ptr = (void __user *)buf->m.planes;
45193+ *user_ptr = (void __force_user *)buf->m.planes;
45194 *kernel_ptr = (void *)&buf->m.planes;
45195 *array_size = sizeof(struct v4l2_plane) * buf->length;
45196 ret = 1;
45197@@ -2248,7 +2249,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
45198 ret = -EINVAL;
45199 break;
45200 }
45201- *user_ptr = (void __user *)ctrls->controls;
45202+ *user_ptr = (void __force_user *)ctrls->controls;
45203 *kernel_ptr = (void *)&ctrls->controls;
45204 *array_size = sizeof(struct v4l2_ext_control)
45205 * ctrls->count;
45206@@ -2349,7 +2350,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
45207 }
45208
45209 if (has_array_args) {
45210- *kernel_ptr = user_ptr;
45211+ *kernel_ptr = (void __force_kernel *)user_ptr;
45212 if (copy_to_user(user_ptr, mbuf, array_size))
45213 err = -EFAULT;
45214 goto out_array_args;
45215diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
45216index 570b18a..f880314 100644
45217--- a/drivers/message/fusion/mptbase.c
45218+++ b/drivers/message/fusion/mptbase.c
45219@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
45220 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
45221 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
45222
45223+#ifdef CONFIG_GRKERNSEC_HIDESYM
45224+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
45225+#else
45226 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
45227 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
45228+#endif
45229+
45230 /*
45231 * Rounding UP to nearest 4-kB boundary here...
45232 */
45233@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
45234 ioc->facts.GlobalCredits);
45235
45236 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
45237+#ifdef CONFIG_GRKERNSEC_HIDESYM
45238+ NULL, NULL);
45239+#else
45240 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
45241+#endif
45242 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
45243 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
45244 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
45245diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
45246index 00d339c..2ea899d 100644
45247--- a/drivers/message/fusion/mptsas.c
45248+++ b/drivers/message/fusion/mptsas.c
45249@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
45250 return 0;
45251 }
45252
45253+static inline void
45254+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
45255+{
45256+ if (phy_info->port_details) {
45257+ phy_info->port_details->rphy = rphy;
45258+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
45259+ ioc->name, rphy));
45260+ }
45261+
45262+ if (rphy) {
45263+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
45264+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
45265+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
45266+ ioc->name, rphy, rphy->dev.release));
45267+ }
45268+}
45269+
45270 /* no mutex */
45271 static void
45272 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
45273@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
45274 return NULL;
45275 }
45276
45277-static inline void
45278-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
45279-{
45280- if (phy_info->port_details) {
45281- phy_info->port_details->rphy = rphy;
45282- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
45283- ioc->name, rphy));
45284- }
45285-
45286- if (rphy) {
45287- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
45288- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
45289- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
45290- ioc->name, rphy, rphy->dev.release));
45291- }
45292-}
45293-
45294 static inline struct sas_port *
45295 mptsas_get_port(struct mptsas_phyinfo *phy_info)
45296 {
45297diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
45298index 727819c..ad74694 100644
45299--- a/drivers/message/fusion/mptscsih.c
45300+++ b/drivers/message/fusion/mptscsih.c
45301@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
45302
45303 h = shost_priv(SChost);
45304
45305- if (h) {
45306- if (h->info_kbuf == NULL)
45307- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
45308- return h->info_kbuf;
45309- h->info_kbuf[0] = '\0';
45310+ if (!h)
45311+ return NULL;
45312
45313- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
45314- h->info_kbuf[size-1] = '\0';
45315- }
45316+ if (h->info_kbuf == NULL)
45317+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
45318+ return h->info_kbuf;
45319+ h->info_kbuf[0] = '\0';
45320+
45321+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
45322+ h->info_kbuf[size-1] = '\0';
45323
45324 return h->info_kbuf;
45325 }
45326diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
45327index b7d87cd..3fb36da 100644
45328--- a/drivers/message/i2o/i2o_proc.c
45329+++ b/drivers/message/i2o/i2o_proc.c
45330@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
45331 "Array Controller Device"
45332 };
45333
45334-static char *chtostr(char *tmp, u8 *chars, int n)
45335-{
45336- tmp[0] = 0;
45337- return strncat(tmp, (char *)chars, n);
45338-}
45339-
45340 static int i2o_report_query_status(struct seq_file *seq, int block_status,
45341 char *group)
45342 {
45343@@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
45344 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
45345 {
45346 struct i2o_controller *c = (struct i2o_controller *)seq->private;
45347- static u32 work32[5];
45348- static u8 *work8 = (u8 *) work32;
45349- static u16 *work16 = (u16 *) work32;
45350+ u32 work32[5];
45351+ u8 *work8 = (u8 *) work32;
45352+ u16 *work16 = (u16 *) work32;
45353 int token;
45354 u32 hwcap;
45355
45356@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
45357 } *result;
45358
45359 i2o_exec_execute_ddm_table ddm_table;
45360- char tmp[28 + 1];
45361
45362 result = kmalloc(sizeof(*result), GFP_KERNEL);
45363 if (!result)
45364@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
45365
45366 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
45367 seq_printf(seq, "%-#8x", ddm_table.module_id);
45368- seq_printf(seq, "%-29s",
45369- chtostr(tmp, ddm_table.module_name_version, 28));
45370+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
45371 seq_printf(seq, "%9d ", ddm_table.data_size);
45372 seq_printf(seq, "%8d", ddm_table.code_size);
45373
45374@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
45375
45376 i2o_driver_result_table *result;
45377 i2o_driver_store_table *dst;
45378- char tmp[28 + 1];
45379
45380 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
45381 if (result == NULL)
45382@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
45383
45384 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
45385 seq_printf(seq, "%-#8x", dst->module_id);
45386- seq_printf(seq, "%-29s",
45387- chtostr(tmp, dst->module_name_version, 28));
45388- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
45389+ seq_printf(seq, "%-.28s", dst->module_name_version);
45390+ seq_printf(seq, "%-.8s", dst->date);
45391 seq_printf(seq, "%8d ", dst->module_size);
45392 seq_printf(seq, "%8d ", dst->mpb_size);
45393 seq_printf(seq, "0x%04x", dst->module_flags);
45394@@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
45395 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
45396 {
45397 struct i2o_device *d = (struct i2o_device *)seq->private;
45398- static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
45399+ u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
45400 // == (allow) 512d bytes (max)
45401- static u16 *work16 = (u16 *) work32;
45402+ u16 *work16 = (u16 *) work32;
45403 int token;
45404- char tmp[16 + 1];
45405
45406 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
45407
45408@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
45409 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
45410 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
45411 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
45412- seq_printf(seq, "Vendor info : %s\n",
45413- chtostr(tmp, (u8 *) (work32 + 2), 16));
45414- seq_printf(seq, "Product info : %s\n",
45415- chtostr(tmp, (u8 *) (work32 + 6), 16));
45416- seq_printf(seq, "Description : %s\n",
45417- chtostr(tmp, (u8 *) (work32 + 10), 16));
45418- seq_printf(seq, "Product rev. : %s\n",
45419- chtostr(tmp, (u8 *) (work32 + 14), 8));
45420+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
45421+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
45422+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
45423+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
45424
45425 seq_printf(seq, "Serial number : ");
45426 print_serial_number(seq, (u8 *) (work32 + 16),
45427@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
45428 u8 pad[256]; // allow up to 256 byte (max) serial number
45429 } result;
45430
45431- char tmp[24 + 1];
45432-
45433 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
45434
45435 if (token < 0) {
45436@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
45437 }
45438
45439 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
45440- seq_printf(seq, "Module name : %s\n",
45441- chtostr(tmp, result.module_name, 24));
45442- seq_printf(seq, "Module revision : %s\n",
45443- chtostr(tmp, result.module_rev, 8));
45444+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
45445+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
45446
45447 seq_printf(seq, "Serial number : ");
45448 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
45449@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45450 u8 instance_number[4];
45451 } result;
45452
45453- char tmp[64 + 1];
45454-
45455 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
45456
45457 if (token < 0) {
45458@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45459 return 0;
45460 }
45461
45462- seq_printf(seq, "Device name : %s\n",
45463- chtostr(tmp, result.device_name, 64));
45464- seq_printf(seq, "Service name : %s\n",
45465- chtostr(tmp, result.service_name, 64));
45466- seq_printf(seq, "Physical name : %s\n",
45467- chtostr(tmp, result.physical_location, 64));
45468- seq_printf(seq, "Instance number : %s\n",
45469- chtostr(tmp, result.instance_number, 4));
45470+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
45471+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
45472+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
45473+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
45474
45475 return 0;
45476 }
45477@@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45478 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
45479 {
45480 struct i2o_device *d = (struct i2o_device *)seq->private;
45481- static u32 work32[12];
45482- static u16 *work16 = (u16 *) work32;
45483- static u8 *work8 = (u8 *) work32;
45484+ u32 work32[12];
45485+ u16 *work16 = (u16 *) work32;
45486+ u8 *work8 = (u8 *) work32;
45487 int token;
45488
45489 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
45490diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
45491index a8c08f3..155fe3d 100644
45492--- a/drivers/message/i2o/iop.c
45493+++ b/drivers/message/i2o/iop.c
45494@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
45495
45496 spin_lock_irqsave(&c->context_list_lock, flags);
45497
45498- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
45499- atomic_inc(&c->context_list_counter);
45500+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
45501+ atomic_inc_unchecked(&c->context_list_counter);
45502
45503- entry->context = atomic_read(&c->context_list_counter);
45504+ entry->context = atomic_read_unchecked(&c->context_list_counter);
45505
45506 list_add(&entry->list, &c->context_list);
45507
45508@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
45509
45510 #if BITS_PER_LONG == 64
45511 spin_lock_init(&c->context_list_lock);
45512- atomic_set(&c->context_list_counter, 0);
45513+ atomic_set_unchecked(&c->context_list_counter, 0);
45514 INIT_LIST_HEAD(&c->context_list);
45515 #endif
45516
45517diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
45518index d1a22aa..d0f7bf7 100644
45519--- a/drivers/mfd/ab8500-debugfs.c
45520+++ b/drivers/mfd/ab8500-debugfs.c
45521@@ -100,7 +100,7 @@ static int irq_last;
45522 static u32 *irq_count;
45523 static int num_irqs;
45524
45525-static struct device_attribute **dev_attr;
45526+static device_attribute_no_const **dev_attr;
45527 static char **event_name;
45528
45529 static u8 avg_sample = SAMPLE_16;
45530diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
45531index 81b7d88..95ae998 100644
45532--- a/drivers/mfd/janz-cmodio.c
45533+++ b/drivers/mfd/janz-cmodio.c
45534@@ -13,6 +13,7 @@
45535
45536 #include <linux/kernel.h>
45537 #include <linux/module.h>
45538+#include <linux/slab.h>
45539 #include <linux/init.h>
45540 #include <linux/pci.h>
45541 #include <linux/interrupt.h>
45542diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
45543index a83eed5..62a58a9 100644
45544--- a/drivers/mfd/max8925-i2c.c
45545+++ b/drivers/mfd/max8925-i2c.c
45546@@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
45547 const struct i2c_device_id *id)
45548 {
45549 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
45550- static struct max8925_chip *chip;
45551+ struct max8925_chip *chip;
45552 struct device_node *node = client->dev.of_node;
45553
45554 if (node && !pdata) {
45555diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
45556index d657331..0d9a80f 100644
45557--- a/drivers/mfd/tps65910.c
45558+++ b/drivers/mfd/tps65910.c
45559@@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
45560 struct tps65910_platform_data *pdata)
45561 {
45562 int ret = 0;
45563- static struct regmap_irq_chip *tps6591x_irqs_chip;
45564+ struct regmap_irq_chip *tps6591x_irqs_chip;
45565
45566 if (!irq) {
45567 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
45568diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
45569index 9aa6d1e..1631bfc 100644
45570--- a/drivers/mfd/twl4030-irq.c
45571+++ b/drivers/mfd/twl4030-irq.c
45572@@ -35,6 +35,7 @@
45573 #include <linux/of.h>
45574 #include <linux/irqdomain.h>
45575 #include <linux/i2c/twl.h>
45576+#include <asm/pgtable.h>
45577
45578 #include "twl-core.h"
45579
45580@@ -726,10 +727,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
45581 * Install an irq handler for each of the SIH modules;
45582 * clone dummy irq_chip since PIH can't *do* anything
45583 */
45584- twl4030_irq_chip = dummy_irq_chip;
45585- twl4030_irq_chip.name = "twl4030";
45586+ pax_open_kernel();
45587+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
45588+ *(const char **)&twl4030_irq_chip.name = "twl4030";
45589
45590- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45591+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45592+ pax_close_kernel();
45593
45594 for (i = irq_base; i < irq_end; i++) {
45595 irq_set_chip_and_handler(i, &twl4030_irq_chip,
45596diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
45597index 464419b..64bae8d 100644
45598--- a/drivers/misc/c2port/core.c
45599+++ b/drivers/misc/c2port/core.c
45600@@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
45601 goto error_idr_alloc;
45602 c2dev->id = ret;
45603
45604- bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45605+ pax_open_kernel();
45606+ *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45607+ pax_close_kernel();
45608
45609 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
45610 "c2port%d", c2dev->id);
45611diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
45612index 9c34e57..b981cda 100644
45613--- a/drivers/misc/eeprom/sunxi_sid.c
45614+++ b/drivers/misc/eeprom/sunxi_sid.c
45615@@ -127,7 +127,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
45616
45617 platform_set_drvdata(pdev, sid_data);
45618
45619- sid_bin_attr.size = sid_data->keysize;
45620+ pax_open_kernel();
45621+ *(size_t *)&sid_bin_attr.size = sid_data->keysize;
45622+ pax_close_kernel();
45623 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
45624 return -ENODEV;
45625
45626diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
45627index 36f5d52..32311c3 100644
45628--- a/drivers/misc/kgdbts.c
45629+++ b/drivers/misc/kgdbts.c
45630@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
45631 char before[BREAK_INSTR_SIZE];
45632 char after[BREAK_INSTR_SIZE];
45633
45634- probe_kernel_read(before, (char *)kgdbts_break_test,
45635+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
45636 BREAK_INSTR_SIZE);
45637 init_simple_test();
45638 ts.tst = plant_and_detach_test;
45639@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
45640 /* Activate test with initial breakpoint */
45641 if (!is_early)
45642 kgdb_breakpoint();
45643- probe_kernel_read(after, (char *)kgdbts_break_test,
45644+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
45645 BREAK_INSTR_SIZE);
45646 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
45647 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
45648diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
45649index 036effe..b3a6336 100644
45650--- a/drivers/misc/lis3lv02d/lis3lv02d.c
45651+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
45652@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
45653 * the lid is closed. This leads to interrupts as soon as a little move
45654 * is done.
45655 */
45656- atomic_inc(&lis3->count);
45657+ atomic_inc_unchecked(&lis3->count);
45658
45659 wake_up_interruptible(&lis3->misc_wait);
45660 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
45661@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
45662 if (lis3->pm_dev)
45663 pm_runtime_get_sync(lis3->pm_dev);
45664
45665- atomic_set(&lis3->count, 0);
45666+ atomic_set_unchecked(&lis3->count, 0);
45667 return 0;
45668 }
45669
45670@@ -616,7 +616,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
45671 add_wait_queue(&lis3->misc_wait, &wait);
45672 while (true) {
45673 set_current_state(TASK_INTERRUPTIBLE);
45674- data = atomic_xchg(&lis3->count, 0);
45675+ data = atomic_xchg_unchecked(&lis3->count, 0);
45676 if (data)
45677 break;
45678
45679@@ -657,7 +657,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
45680 struct lis3lv02d, miscdev);
45681
45682 poll_wait(file, &lis3->misc_wait, wait);
45683- if (atomic_read(&lis3->count))
45684+ if (atomic_read_unchecked(&lis3->count))
45685 return POLLIN | POLLRDNORM;
45686 return 0;
45687 }
45688diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
45689index c439c82..1f20f57 100644
45690--- a/drivers/misc/lis3lv02d/lis3lv02d.h
45691+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
45692@@ -297,7 +297,7 @@ struct lis3lv02d {
45693 struct input_polled_dev *idev; /* input device */
45694 struct platform_device *pdev; /* platform device */
45695 struct regulator_bulk_data regulators[2];
45696- atomic_t count; /* interrupt count after last read */
45697+ atomic_unchecked_t count; /* interrupt count after last read */
45698 union axis_conversion ac; /* hw -> logical axis */
45699 int mapped_btns[3];
45700
45701diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
45702index 2f30bad..c4c13d0 100644
45703--- a/drivers/misc/sgi-gru/gruhandles.c
45704+++ b/drivers/misc/sgi-gru/gruhandles.c
45705@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
45706 unsigned long nsec;
45707
45708 nsec = CLKS2NSEC(clks);
45709- atomic_long_inc(&mcs_op_statistics[op].count);
45710- atomic_long_add(nsec, &mcs_op_statistics[op].total);
45711+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
45712+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
45713 if (mcs_op_statistics[op].max < nsec)
45714 mcs_op_statistics[op].max = nsec;
45715 }
45716diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
45717index 4f76359..cdfcb2e 100644
45718--- a/drivers/misc/sgi-gru/gruprocfs.c
45719+++ b/drivers/misc/sgi-gru/gruprocfs.c
45720@@ -32,9 +32,9 @@
45721
45722 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
45723
45724-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
45725+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
45726 {
45727- unsigned long val = atomic_long_read(v);
45728+ unsigned long val = atomic_long_read_unchecked(v);
45729
45730 seq_printf(s, "%16lu %s\n", val, id);
45731 }
45732@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
45733
45734 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
45735 for (op = 0; op < mcsop_last; op++) {
45736- count = atomic_long_read(&mcs_op_statistics[op].count);
45737- total = atomic_long_read(&mcs_op_statistics[op].total);
45738+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
45739+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
45740 max = mcs_op_statistics[op].max;
45741 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
45742 count ? total / count : 0, max);
45743diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
45744index 5c3ce24..4915ccb 100644
45745--- a/drivers/misc/sgi-gru/grutables.h
45746+++ b/drivers/misc/sgi-gru/grutables.h
45747@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
45748 * GRU statistics.
45749 */
45750 struct gru_stats_s {
45751- atomic_long_t vdata_alloc;
45752- atomic_long_t vdata_free;
45753- atomic_long_t gts_alloc;
45754- atomic_long_t gts_free;
45755- atomic_long_t gms_alloc;
45756- atomic_long_t gms_free;
45757- atomic_long_t gts_double_allocate;
45758- atomic_long_t assign_context;
45759- atomic_long_t assign_context_failed;
45760- atomic_long_t free_context;
45761- atomic_long_t load_user_context;
45762- atomic_long_t load_kernel_context;
45763- atomic_long_t lock_kernel_context;
45764- atomic_long_t unlock_kernel_context;
45765- atomic_long_t steal_user_context;
45766- atomic_long_t steal_kernel_context;
45767- atomic_long_t steal_context_failed;
45768- atomic_long_t nopfn;
45769- atomic_long_t asid_new;
45770- atomic_long_t asid_next;
45771- atomic_long_t asid_wrap;
45772- atomic_long_t asid_reuse;
45773- atomic_long_t intr;
45774- atomic_long_t intr_cbr;
45775- atomic_long_t intr_tfh;
45776- atomic_long_t intr_spurious;
45777- atomic_long_t intr_mm_lock_failed;
45778- atomic_long_t call_os;
45779- atomic_long_t call_os_wait_queue;
45780- atomic_long_t user_flush_tlb;
45781- atomic_long_t user_unload_context;
45782- atomic_long_t user_exception;
45783- atomic_long_t set_context_option;
45784- atomic_long_t check_context_retarget_intr;
45785- atomic_long_t check_context_unload;
45786- atomic_long_t tlb_dropin;
45787- atomic_long_t tlb_preload_page;
45788- atomic_long_t tlb_dropin_fail_no_asid;
45789- atomic_long_t tlb_dropin_fail_upm;
45790- atomic_long_t tlb_dropin_fail_invalid;
45791- atomic_long_t tlb_dropin_fail_range_active;
45792- atomic_long_t tlb_dropin_fail_idle;
45793- atomic_long_t tlb_dropin_fail_fmm;
45794- atomic_long_t tlb_dropin_fail_no_exception;
45795- atomic_long_t tfh_stale_on_fault;
45796- atomic_long_t mmu_invalidate_range;
45797- atomic_long_t mmu_invalidate_page;
45798- atomic_long_t flush_tlb;
45799- atomic_long_t flush_tlb_gru;
45800- atomic_long_t flush_tlb_gru_tgh;
45801- atomic_long_t flush_tlb_gru_zero_asid;
45802+ atomic_long_unchecked_t vdata_alloc;
45803+ atomic_long_unchecked_t vdata_free;
45804+ atomic_long_unchecked_t gts_alloc;
45805+ atomic_long_unchecked_t gts_free;
45806+ atomic_long_unchecked_t gms_alloc;
45807+ atomic_long_unchecked_t gms_free;
45808+ atomic_long_unchecked_t gts_double_allocate;
45809+ atomic_long_unchecked_t assign_context;
45810+ atomic_long_unchecked_t assign_context_failed;
45811+ atomic_long_unchecked_t free_context;
45812+ atomic_long_unchecked_t load_user_context;
45813+ atomic_long_unchecked_t load_kernel_context;
45814+ atomic_long_unchecked_t lock_kernel_context;
45815+ atomic_long_unchecked_t unlock_kernel_context;
45816+ atomic_long_unchecked_t steal_user_context;
45817+ atomic_long_unchecked_t steal_kernel_context;
45818+ atomic_long_unchecked_t steal_context_failed;
45819+ atomic_long_unchecked_t nopfn;
45820+ atomic_long_unchecked_t asid_new;
45821+ atomic_long_unchecked_t asid_next;
45822+ atomic_long_unchecked_t asid_wrap;
45823+ atomic_long_unchecked_t asid_reuse;
45824+ atomic_long_unchecked_t intr;
45825+ atomic_long_unchecked_t intr_cbr;
45826+ atomic_long_unchecked_t intr_tfh;
45827+ atomic_long_unchecked_t intr_spurious;
45828+ atomic_long_unchecked_t intr_mm_lock_failed;
45829+ atomic_long_unchecked_t call_os;
45830+ atomic_long_unchecked_t call_os_wait_queue;
45831+ atomic_long_unchecked_t user_flush_tlb;
45832+ atomic_long_unchecked_t user_unload_context;
45833+ atomic_long_unchecked_t user_exception;
45834+ atomic_long_unchecked_t set_context_option;
45835+ atomic_long_unchecked_t check_context_retarget_intr;
45836+ atomic_long_unchecked_t check_context_unload;
45837+ atomic_long_unchecked_t tlb_dropin;
45838+ atomic_long_unchecked_t tlb_preload_page;
45839+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
45840+ atomic_long_unchecked_t tlb_dropin_fail_upm;
45841+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
45842+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
45843+ atomic_long_unchecked_t tlb_dropin_fail_idle;
45844+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
45845+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
45846+ atomic_long_unchecked_t tfh_stale_on_fault;
45847+ atomic_long_unchecked_t mmu_invalidate_range;
45848+ atomic_long_unchecked_t mmu_invalidate_page;
45849+ atomic_long_unchecked_t flush_tlb;
45850+ atomic_long_unchecked_t flush_tlb_gru;
45851+ atomic_long_unchecked_t flush_tlb_gru_tgh;
45852+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
45853
45854- atomic_long_t copy_gpa;
45855- atomic_long_t read_gpa;
45856+ atomic_long_unchecked_t copy_gpa;
45857+ atomic_long_unchecked_t read_gpa;
45858
45859- atomic_long_t mesq_receive;
45860- atomic_long_t mesq_receive_none;
45861- atomic_long_t mesq_send;
45862- atomic_long_t mesq_send_failed;
45863- atomic_long_t mesq_noop;
45864- atomic_long_t mesq_send_unexpected_error;
45865- atomic_long_t mesq_send_lb_overflow;
45866- atomic_long_t mesq_send_qlimit_reached;
45867- atomic_long_t mesq_send_amo_nacked;
45868- atomic_long_t mesq_send_put_nacked;
45869- atomic_long_t mesq_page_overflow;
45870- atomic_long_t mesq_qf_locked;
45871- atomic_long_t mesq_qf_noop_not_full;
45872- atomic_long_t mesq_qf_switch_head_failed;
45873- atomic_long_t mesq_qf_unexpected_error;
45874- atomic_long_t mesq_noop_unexpected_error;
45875- atomic_long_t mesq_noop_lb_overflow;
45876- atomic_long_t mesq_noop_qlimit_reached;
45877- atomic_long_t mesq_noop_amo_nacked;
45878- atomic_long_t mesq_noop_put_nacked;
45879- atomic_long_t mesq_noop_page_overflow;
45880+ atomic_long_unchecked_t mesq_receive;
45881+ atomic_long_unchecked_t mesq_receive_none;
45882+ atomic_long_unchecked_t mesq_send;
45883+ atomic_long_unchecked_t mesq_send_failed;
45884+ atomic_long_unchecked_t mesq_noop;
45885+ atomic_long_unchecked_t mesq_send_unexpected_error;
45886+ atomic_long_unchecked_t mesq_send_lb_overflow;
45887+ atomic_long_unchecked_t mesq_send_qlimit_reached;
45888+ atomic_long_unchecked_t mesq_send_amo_nacked;
45889+ atomic_long_unchecked_t mesq_send_put_nacked;
45890+ atomic_long_unchecked_t mesq_page_overflow;
45891+ atomic_long_unchecked_t mesq_qf_locked;
45892+ atomic_long_unchecked_t mesq_qf_noop_not_full;
45893+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
45894+ atomic_long_unchecked_t mesq_qf_unexpected_error;
45895+ atomic_long_unchecked_t mesq_noop_unexpected_error;
45896+ atomic_long_unchecked_t mesq_noop_lb_overflow;
45897+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
45898+ atomic_long_unchecked_t mesq_noop_amo_nacked;
45899+ atomic_long_unchecked_t mesq_noop_put_nacked;
45900+ atomic_long_unchecked_t mesq_noop_page_overflow;
45901
45902 };
45903
45904@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
45905 tghop_invalidate, mcsop_last};
45906
45907 struct mcs_op_statistic {
45908- atomic_long_t count;
45909- atomic_long_t total;
45910+ atomic_long_unchecked_t count;
45911+ atomic_long_unchecked_t total;
45912 unsigned long max;
45913 };
45914
45915@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
45916
45917 #define STAT(id) do { \
45918 if (gru_options & OPT_STATS) \
45919- atomic_long_inc(&gru_stats.id); \
45920+ atomic_long_inc_unchecked(&gru_stats.id); \
45921 } while (0)
45922
45923 #ifdef CONFIG_SGI_GRU_DEBUG
45924diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
45925index c862cd4..0d176fe 100644
45926--- a/drivers/misc/sgi-xp/xp.h
45927+++ b/drivers/misc/sgi-xp/xp.h
45928@@ -288,7 +288,7 @@ struct xpc_interface {
45929 xpc_notify_func, void *);
45930 void (*received) (short, int, void *);
45931 enum xp_retval (*partid_to_nasids) (short, void *);
45932-};
45933+} __no_const;
45934
45935 extern struct xpc_interface xpc_interface;
45936
45937diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
45938index 01be66d..e3a0c7e 100644
45939--- a/drivers/misc/sgi-xp/xp_main.c
45940+++ b/drivers/misc/sgi-xp/xp_main.c
45941@@ -78,13 +78,13 @@ xpc_notloaded(void)
45942 }
45943
45944 struct xpc_interface xpc_interface = {
45945- (void (*)(int))xpc_notloaded,
45946- (void (*)(int))xpc_notloaded,
45947- (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45948- (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45949+ .connect = (void (*)(int))xpc_notloaded,
45950+ .disconnect = (void (*)(int))xpc_notloaded,
45951+ .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45952+ .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45953 void *))xpc_notloaded,
45954- (void (*)(short, int, void *))xpc_notloaded,
45955- (enum xp_retval(*)(short, void *))xpc_notloaded
45956+ .received = (void (*)(short, int, void *))xpc_notloaded,
45957+ .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
45958 };
45959 EXPORT_SYMBOL_GPL(xpc_interface);
45960
45961diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
45962index b94d5f7..7f494c5 100644
45963--- a/drivers/misc/sgi-xp/xpc.h
45964+++ b/drivers/misc/sgi-xp/xpc.h
45965@@ -835,6 +835,7 @@ struct xpc_arch_operations {
45966 void (*received_payload) (struct xpc_channel *, void *);
45967 void (*notify_senders_of_disconnect) (struct xpc_channel *);
45968 };
45969+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
45970
45971 /* struct xpc_partition act_state values (for XPC HB) */
45972
45973@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
45974 /* found in xpc_main.c */
45975 extern struct device *xpc_part;
45976 extern struct device *xpc_chan;
45977-extern struct xpc_arch_operations xpc_arch_ops;
45978+extern xpc_arch_operations_no_const xpc_arch_ops;
45979 extern int xpc_disengage_timelimit;
45980 extern int xpc_disengage_timedout;
45981 extern int xpc_activate_IRQ_rcvd;
45982diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
45983index 82dc574..8539ab2 100644
45984--- a/drivers/misc/sgi-xp/xpc_main.c
45985+++ b/drivers/misc/sgi-xp/xpc_main.c
45986@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
45987 .notifier_call = xpc_system_die,
45988 };
45989
45990-struct xpc_arch_operations xpc_arch_ops;
45991+xpc_arch_operations_no_const xpc_arch_ops;
45992
45993 /*
45994 * Timer function to enforce the timelimit on the partition disengage.
45995@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
45996
45997 if (((die_args->trapnr == X86_TRAP_MF) ||
45998 (die_args->trapnr == X86_TRAP_XF)) &&
45999- !user_mode_vm(die_args->regs))
46000+ !user_mode(die_args->regs))
46001 xpc_die_deactivate();
46002
46003 break;
46004diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
46005index 7b5424f..ed1d6ac 100644
46006--- a/drivers/mmc/card/block.c
46007+++ b/drivers/mmc/card/block.c
46008@@ -575,7 +575,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
46009 if (idata->ic.postsleep_min_us)
46010 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
46011
46012- if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
46013+ if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
46014 err = -EFAULT;
46015 goto cmd_rel_host;
46016 }
46017diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
46018index e5b5eeb..7bf2212 100644
46019--- a/drivers/mmc/core/mmc_ops.c
46020+++ b/drivers/mmc/core/mmc_ops.c
46021@@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
46022 void *data_buf;
46023 int is_on_stack;
46024
46025- is_on_stack = object_is_on_stack(buf);
46026+ is_on_stack = object_starts_on_stack(buf);
46027 if (is_on_stack) {
46028 /*
46029 * dma onto stack is unsafe/nonportable, but callers to this
46030diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
46031index 6bf24ab..13d0293b 100644
46032--- a/drivers/mmc/host/dw_mmc.h
46033+++ b/drivers/mmc/host/dw_mmc.h
46034@@ -258,5 +258,5 @@ struct dw_mci_drv_data {
46035 int (*parse_dt)(struct dw_mci *host);
46036 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
46037 struct dw_mci_tuning_data *tuning_data);
46038-};
46039+} __do_const;
46040 #endif /* _DW_MMC_H_ */
46041diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
46042index b931226..df6a085 100644
46043--- a/drivers/mmc/host/mmci.c
46044+++ b/drivers/mmc/host/mmci.c
46045@@ -1504,7 +1504,9 @@ static int mmci_probe(struct amba_device *dev,
46046 }
46047
46048 if (variant->busy_detect) {
46049- mmci_ops.card_busy = mmci_card_busy;
46050+ pax_open_kernel();
46051+ *(void **)&mmci_ops.card_busy = mmci_card_busy;
46052+ pax_close_kernel();
46053 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
46054 }
46055
46056diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
46057index b841bb7..d82712f5 100644
46058--- a/drivers/mmc/host/sdhci-esdhc-imx.c
46059+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
46060@@ -1031,9 +1031,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
46061 host->mmc->caps |= MMC_CAP_1_8V_DDR;
46062 }
46063
46064- if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
46065- sdhci_esdhc_ops.platform_execute_tuning =
46066+ if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
46067+ pax_open_kernel();
46068+ *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
46069 esdhc_executing_tuning;
46070+ pax_close_kernel();
46071+ }
46072
46073 if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING)
46074 writel(readl(host->ioaddr + ESDHC_TUNING_CTRL) |
46075diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
46076index 6debda9..2ba7427 100644
46077--- a/drivers/mmc/host/sdhci-s3c.c
46078+++ b/drivers/mmc/host/sdhci-s3c.c
46079@@ -668,9 +668,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
46080 * we can use overriding functions instead of default.
46081 */
46082 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
46083- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
46084- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
46085- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
46086+ pax_open_kernel();
46087+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
46088+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
46089+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
46090+ pax_close_kernel();
46091 }
46092
46093 /* It supports additional host capabilities if needed */
46094diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
46095index 096993f..f02c23b 100644
46096--- a/drivers/mtd/chips/cfi_cmdset_0020.c
46097+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
46098@@ -669,7 +669,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
46099 size_t totlen = 0, thislen;
46100 int ret = 0;
46101 size_t buflen = 0;
46102- static char *buffer;
46103+ char *buffer;
46104
46105 if (!ECCBUF_SIZE) {
46106 /* We should fall back to a general writev implementation.
46107diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
46108index c07cd57..61c4fbd 100644
46109--- a/drivers/mtd/nand/denali.c
46110+++ b/drivers/mtd/nand/denali.c
46111@@ -24,6 +24,7 @@
46112 #include <linux/slab.h>
46113 #include <linux/mtd/mtd.h>
46114 #include <linux/module.h>
46115+#include <linux/slab.h>
46116
46117 #include "denali.h"
46118
46119diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
46120index ca6369f..0ce9fed 100644
46121--- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
46122+++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
46123@@ -369,7 +369,7 @@ void prepare_data_dma(struct gpmi_nand_data *this, enum dma_data_direction dr)
46124
46125 /* first try to map the upper buffer directly */
46126 if (virt_addr_valid(this->upper_buf) &&
46127- !object_is_on_stack(this->upper_buf)) {
46128+ !object_starts_on_stack(this->upper_buf)) {
46129 sg_init_one(sgl, this->upper_buf, this->upper_len);
46130 ret = dma_map_sg(this->dev, sgl, 1, dr);
46131 if (ret == 0)
46132diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
46133index 51b9d6a..52af9a7 100644
46134--- a/drivers/mtd/nftlmount.c
46135+++ b/drivers/mtd/nftlmount.c
46136@@ -24,6 +24,7 @@
46137 #include <asm/errno.h>
46138 #include <linux/delay.h>
46139 #include <linux/slab.h>
46140+#include <linux/sched.h>
46141 #include <linux/mtd/mtd.h>
46142 #include <linux/mtd/nand.h>
46143 #include <linux/mtd/nftl.h>
46144diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
46145index cf49c22..971b133 100644
46146--- a/drivers/mtd/sm_ftl.c
46147+++ b/drivers/mtd/sm_ftl.c
46148@@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
46149 #define SM_CIS_VENDOR_OFFSET 0x59
46150 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
46151 {
46152- struct attribute_group *attr_group;
46153+ attribute_group_no_const *attr_group;
46154 struct attribute **attributes;
46155 struct sm_sysfs_attribute *vendor_attribute;
46156 char *vendor;
46157diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
46158index e5628fc..ffe54d1 100644
46159--- a/drivers/net/bonding/bond_main.c
46160+++ b/drivers/net/bonding/bond_main.c
46161@@ -4551,6 +4551,7 @@ static void __exit bonding_exit(void)
46162
46163 bond_netlink_fini();
46164 unregister_pernet_subsys(&bond_net_ops);
46165+ rtnl_link_unregister(&bond_link_ops);
46166
46167 #ifdef CONFIG_NET_POLL_CONTROLLER
46168 /*
46169diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
46170index 70651f8..7eb1bdf 100644
46171--- a/drivers/net/bonding/bond_netlink.c
46172+++ b/drivers/net/bonding/bond_netlink.c
46173@@ -542,7 +542,7 @@ nla_put_failure:
46174 return -EMSGSIZE;
46175 }
46176
46177-struct rtnl_link_ops bond_link_ops __read_mostly = {
46178+struct rtnl_link_ops bond_link_ops = {
46179 .kind = "bond",
46180 .priv_size = sizeof(struct bonding),
46181 .setup = bond_setup,
46182diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
46183index 9e7d95d..d447b88 100644
46184--- a/drivers/net/can/Kconfig
46185+++ b/drivers/net/can/Kconfig
46186@@ -104,7 +104,7 @@ config CAN_JANZ_ICAN3
46187
46188 config CAN_FLEXCAN
46189 tristate "Support for Freescale FLEXCAN based chips"
46190- depends on ARM || PPC
46191+ depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
46192 ---help---
46193 Say Y here if you want to support for Freescale FlexCAN.
46194
46195diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
46196index 455d4c3..3353ee7 100644
46197--- a/drivers/net/ethernet/8390/ax88796.c
46198+++ b/drivers/net/ethernet/8390/ax88796.c
46199@@ -889,9 +889,11 @@ static int ax_probe(struct platform_device *pdev)
46200 if (ax->plat->reg_offsets)
46201 ei_local->reg_offset = ax->plat->reg_offsets;
46202 else {
46203+ resource_size_t _mem_size = mem_size;
46204+ do_div(_mem_size, 0x18);
46205 ei_local->reg_offset = ax->reg_offsets;
46206 for (ret = 0; ret < 0x18; ret++)
46207- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
46208+ ax->reg_offsets[ret] = _mem_size * ret;
46209 }
46210
46211 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
46212diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
46213index a89a40f..5a8a2ac 100644
46214--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
46215+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
46216@@ -1062,7 +1062,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
46217 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
46218 {
46219 /* RX_MODE controlling object */
46220- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
46221+ bnx2x_init_rx_mode_obj(bp);
46222
46223 /* multicast configuration controlling object */
46224 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
46225diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
46226index 0fb6ff2..78fd55c 100644
46227--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
46228+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
46229@@ -2329,15 +2329,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
46230 return rc;
46231 }
46232
46233-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
46234- struct bnx2x_rx_mode_obj *o)
46235+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
46236 {
46237 if (CHIP_IS_E1x(bp)) {
46238- o->wait_comp = bnx2x_empty_rx_mode_wait;
46239- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
46240+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
46241+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
46242 } else {
46243- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
46244- o->config_rx_mode = bnx2x_set_rx_mode_e2;
46245+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
46246+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
46247 }
46248 }
46249
46250diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
46251index 00d7f21..2cddec4 100644
46252--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
46253+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
46254@@ -1321,8 +1321,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
46255
46256 /********************* RX MODE ****************/
46257
46258-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
46259- struct bnx2x_rx_mode_obj *o);
46260+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
46261
46262 /**
46263 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
46264diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
46265index 04321e5..b51cdc4 100644
46266--- a/drivers/net/ethernet/broadcom/tg3.h
46267+++ b/drivers/net/ethernet/broadcom/tg3.h
46268@@ -150,6 +150,7 @@
46269 #define CHIPREV_ID_5750_A0 0x4000
46270 #define CHIPREV_ID_5750_A1 0x4001
46271 #define CHIPREV_ID_5750_A3 0x4003
46272+#define CHIPREV_ID_5750_C1 0x4201
46273 #define CHIPREV_ID_5750_C2 0x4202
46274 #define CHIPREV_ID_5752_A0_HW 0x5000
46275 #define CHIPREV_ID_5752_A0 0x6000
46276diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
46277index 13f9636..228040f 100644
46278--- a/drivers/net/ethernet/brocade/bna/bna_enet.c
46279+++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
46280@@ -1690,10 +1690,10 @@ bna_cb_ioceth_reset(void *arg)
46281 }
46282
46283 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
46284- bna_cb_ioceth_enable,
46285- bna_cb_ioceth_disable,
46286- bna_cb_ioceth_hbfail,
46287- bna_cb_ioceth_reset
46288+ .enable_cbfn = bna_cb_ioceth_enable,
46289+ .disable_cbfn = bna_cb_ioceth_disable,
46290+ .hbfail_cbfn = bna_cb_ioceth_hbfail,
46291+ .reset_cbfn = bna_cb_ioceth_reset
46292 };
46293
46294 static void bna_attr_init(struct bna_ioceth *ioceth)
46295diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
46296index 8cffcdf..aadf043 100644
46297--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
46298+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
46299@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
46300 */
46301 struct l2t_skb_cb {
46302 arp_failure_handler_func arp_failure_handler;
46303-};
46304+} __no_const;
46305
46306 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
46307
46308diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
46309index 34e2488..07e2079 100644
46310--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
46311+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
46312@@ -2120,7 +2120,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
46313
46314 int i;
46315 struct adapter *ap = netdev2adap(dev);
46316- static const unsigned int *reg_ranges;
46317+ const unsigned int *reg_ranges;
46318 int arr_size = 0, buf_size = 0;
46319
46320 if (is_t4(ap->params.chip)) {
46321diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
46322index c05b66d..ed69872 100644
46323--- a/drivers/net/ethernet/dec/tulip/de4x5.c
46324+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
46325@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
46326 for (i=0; i<ETH_ALEN; i++) {
46327 tmp.addr[i] = dev->dev_addr[i];
46328 }
46329- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
46330+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
46331 break;
46332
46333 case DE4X5_SET_HWADDR: /* Set the hardware address */
46334@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
46335 spin_lock_irqsave(&lp->lock, flags);
46336 memcpy(&statbuf, &lp->pktStats, ioc->len);
46337 spin_unlock_irqrestore(&lp->lock, flags);
46338- if (copy_to_user(ioc->data, &statbuf, ioc->len))
46339+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
46340 return -EFAULT;
46341 break;
46342 }
46343diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
46344index 36c8061..ca5e1e0 100644
46345--- a/drivers/net/ethernet/emulex/benet/be_main.c
46346+++ b/drivers/net/ethernet/emulex/benet/be_main.c
46347@@ -534,7 +534,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
46348
46349 if (wrapped)
46350 newacc += 65536;
46351- ACCESS_ONCE(*acc) = newacc;
46352+ ACCESS_ONCE_RW(*acc) = newacc;
46353 }
46354
46355 static void populate_erx_stats(struct be_adapter *adapter,
46356diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
46357index c11ecbc..13bb299 100644
46358--- a/drivers/net/ethernet/faraday/ftgmac100.c
46359+++ b/drivers/net/ethernet/faraday/ftgmac100.c
46360@@ -30,6 +30,8 @@
46361 #include <linux/netdevice.h>
46362 #include <linux/phy.h>
46363 #include <linux/platform_device.h>
46364+#include <linux/interrupt.h>
46365+#include <linux/irqreturn.h>
46366 #include <net/ip.h>
46367
46368 #include "ftgmac100.h"
46369diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
46370index 8be5b40..081bc1b 100644
46371--- a/drivers/net/ethernet/faraday/ftmac100.c
46372+++ b/drivers/net/ethernet/faraday/ftmac100.c
46373@@ -31,6 +31,8 @@
46374 #include <linux/module.h>
46375 #include <linux/netdevice.h>
46376 #include <linux/platform_device.h>
46377+#include <linux/interrupt.h>
46378+#include <linux/irqreturn.h>
46379
46380 #include "ftmac100.h"
46381
46382diff --git a/drivers/net/ethernet/intel/i40e/i40e_ptp.c b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
46383index e33ec6c..f54cfe7 100644
46384--- a/drivers/net/ethernet/intel/i40e/i40e_ptp.c
46385+++ b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
46386@@ -436,7 +436,7 @@ void i40e_ptp_set_increment(struct i40e_pf *pf)
46387 wr32(hw, I40E_PRTTSYN_INC_H, incval >> 32);
46388
46389 /* Update the base adjustement value. */
46390- ACCESS_ONCE(pf->ptp_base_adj) = incval;
46391+ ACCESS_ONCE_RW(pf->ptp_base_adj) = incval;
46392 smp_mb(); /* Force the above update. */
46393 }
46394
46395diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
46396index 5184e2a..acb28c3 100644
46397--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
46398+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
46399@@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
46400 }
46401
46402 /* update the base incval used to calculate frequency adjustment */
46403- ACCESS_ONCE(adapter->base_incval) = incval;
46404+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
46405 smp_mb();
46406
46407 /* need lock to prevent incorrect read while modifying cyclecounter */
46408diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
46409index 089b713..28d87ae 100644
46410--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
46411+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
46412@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
46413 struct __vxge_hw_fifo *fifo;
46414 struct vxge_hw_fifo_config *config;
46415 u32 txdl_size, txdl_per_memblock;
46416- struct vxge_hw_mempool_cbs fifo_mp_callback;
46417+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
46418+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
46419+ };
46420+
46421 struct __vxge_hw_virtualpath *vpath;
46422
46423 if ((vp == NULL) || (attr == NULL)) {
46424@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
46425 goto exit;
46426 }
46427
46428- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
46429-
46430 fifo->mempool =
46431 __vxge_hw_mempool_create(vpath->hldev,
46432 fifo->config->memblock_size,
46433diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
46434index 90a2dda..47e620e 100644
46435--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
46436+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
46437@@ -2088,7 +2088,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
46438 adapter->max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
46439 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
46440 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
46441- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
46442+ pax_open_kernel();
46443+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
46444+ pax_close_kernel();
46445 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46446 adapter->max_sds_rings = QLCNIC_MAX_SDS_RINGS;
46447 adapter->max_tx_rings = QLCNIC_MAX_TX_RINGS;
46448diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46449index be7d7a6..a8983f8 100644
46450--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46451+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46452@@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
46453 case QLCNIC_NON_PRIV_FUNC:
46454 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
46455 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46456- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
46457+ pax_open_kernel();
46458+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
46459+ pax_close_kernel();
46460 break;
46461 case QLCNIC_PRIV_FUNC:
46462 ahw->op_mode = QLCNIC_PRIV_FUNC;
46463 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
46464- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
46465+ pax_open_kernel();
46466+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
46467+ pax_close_kernel();
46468 break;
46469 case QLCNIC_MGMT_FUNC:
46470 ahw->op_mode = QLCNIC_MGMT_FUNC;
46471 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46472- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
46473+ pax_open_kernel();
46474+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
46475+ pax_close_kernel();
46476 break;
46477 default:
46478 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
46479diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46480index 7763962..c3499a7 100644
46481--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46482+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46483@@ -1108,7 +1108,7 @@ int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
46484 struct qlcnic_dump_entry *entry;
46485 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
46486 struct qlcnic_dump_template_hdr *tmpl_hdr = fw_dump->tmpl_hdr;
46487- static const struct qlcnic_dump_operations *fw_dump_ops;
46488+ const struct qlcnic_dump_operations *fw_dump_ops;
46489 struct device *dev = &adapter->pdev->dev;
46490 struct qlcnic_hardware_context *ahw;
46491 void *temp_buffer;
46492diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
46493index 3ff7bc3..366091b 100644
46494--- a/drivers/net/ethernet/realtek/r8169.c
46495+++ b/drivers/net/ethernet/realtek/r8169.c
46496@@ -758,22 +758,22 @@ struct rtl8169_private {
46497 struct mdio_ops {
46498 void (*write)(struct rtl8169_private *, int, int);
46499 int (*read)(struct rtl8169_private *, int);
46500- } mdio_ops;
46501+ } __no_const mdio_ops;
46502
46503 struct pll_power_ops {
46504 void (*down)(struct rtl8169_private *);
46505 void (*up)(struct rtl8169_private *);
46506- } pll_power_ops;
46507+ } __no_const pll_power_ops;
46508
46509 struct jumbo_ops {
46510 void (*enable)(struct rtl8169_private *);
46511 void (*disable)(struct rtl8169_private *);
46512- } jumbo_ops;
46513+ } __no_const jumbo_ops;
46514
46515 struct csi_ops {
46516 void (*write)(struct rtl8169_private *, int, int);
46517 u32 (*read)(struct rtl8169_private *, int);
46518- } csi_ops;
46519+ } __no_const csi_ops;
46520
46521 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
46522 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
46523diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
46524index d7a3682..9ce272a 100644
46525--- a/drivers/net/ethernet/sfc/ptp.c
46526+++ b/drivers/net/ethernet/sfc/ptp.c
46527@@ -825,7 +825,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
46528 ptp->start.dma_addr);
46529
46530 /* Clear flag that signals MC ready */
46531- ACCESS_ONCE(*start) = 0;
46532+ ACCESS_ONCE_RW(*start) = 0;
46533 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
46534 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
46535 EFX_BUG_ON_PARANOID(rc);
46536diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46537index 50617c5..b13724c 100644
46538--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46539+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46540@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
46541
46542 writel(value, ioaddr + MMC_CNTRL);
46543
46544- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46545- MMC_CNTRL, value);
46546+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46547+// MMC_CNTRL, value);
46548 }
46549
46550 /* To mask all all interrupts.*/
46551diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
46552index 7b594ce..1f6c5708 100644
46553--- a/drivers/net/hyperv/hyperv_net.h
46554+++ b/drivers/net/hyperv/hyperv_net.h
46555@@ -100,7 +100,7 @@ struct rndis_device {
46556
46557 enum rndis_device_state state;
46558 bool link_state;
46559- atomic_t new_req_id;
46560+ atomic_unchecked_t new_req_id;
46561
46562 spinlock_t request_lock;
46563 struct list_head req_list;
46564diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
46565index b54fd25..9bd2bae 100644
46566--- a/drivers/net/hyperv/rndis_filter.c
46567+++ b/drivers/net/hyperv/rndis_filter.c
46568@@ -103,7 +103,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
46569 * template
46570 */
46571 set = &rndis_msg->msg.set_req;
46572- set->req_id = atomic_inc_return(&dev->new_req_id);
46573+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46574
46575 /* Add to the request list */
46576 spin_lock_irqsave(&dev->request_lock, flags);
46577@@ -770,7 +770,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
46578
46579 /* Setup the rndis set */
46580 halt = &request->request_msg.msg.halt_req;
46581- halt->req_id = atomic_inc_return(&dev->new_req_id);
46582+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46583
46584 /* Ignore return since this msg is optional. */
46585 rndis_filter_send_request(dev, request);
46586diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
46587index bf0d55e..82bcfbd1 100644
46588--- a/drivers/net/ieee802154/fakehard.c
46589+++ b/drivers/net/ieee802154/fakehard.c
46590@@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
46591 phy->transmit_power = 0xbf;
46592
46593 dev->netdev_ops = &fake_ops;
46594- dev->ml_priv = &fake_mlme;
46595+ dev->ml_priv = (void *)&fake_mlme;
46596
46597 priv = netdev_priv(dev);
46598 priv->phy = phy;
46599diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
46600index 1831fb7..9c24bca 100644
46601--- a/drivers/net/macvlan.c
46602+++ b/drivers/net/macvlan.c
46603@@ -984,13 +984,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
46604 int macvlan_link_register(struct rtnl_link_ops *ops)
46605 {
46606 /* common fields */
46607- ops->priv_size = sizeof(struct macvlan_dev);
46608- ops->validate = macvlan_validate;
46609- ops->maxtype = IFLA_MACVLAN_MAX;
46610- ops->policy = macvlan_policy;
46611- ops->changelink = macvlan_changelink;
46612- ops->get_size = macvlan_get_size;
46613- ops->fill_info = macvlan_fill_info;
46614+ pax_open_kernel();
46615+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
46616+ *(void **)&ops->validate = macvlan_validate;
46617+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
46618+ *(const void **)&ops->policy = macvlan_policy;
46619+ *(void **)&ops->changelink = macvlan_changelink;
46620+ *(void **)&ops->get_size = macvlan_get_size;
46621+ *(void **)&ops->fill_info = macvlan_fill_info;
46622+ pax_close_kernel();
46623
46624 return rtnl_link_register(ops);
46625 };
46626@@ -1045,7 +1047,7 @@ static int macvlan_device_event(struct notifier_block *unused,
46627 return NOTIFY_DONE;
46628 }
46629
46630-static struct notifier_block macvlan_notifier_block __read_mostly = {
46631+static struct notifier_block macvlan_notifier_block = {
46632 .notifier_call = macvlan_device_event,
46633 };
46634
46635diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
46636index ff111a8..c4c3ac4 100644
46637--- a/drivers/net/macvtap.c
46638+++ b/drivers/net/macvtap.c
46639@@ -1011,7 +1011,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
46640 }
46641
46642 ret = 0;
46643- if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46644+ if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46645 put_user(q->flags, &ifr->ifr_flags))
46646 ret = -EFAULT;
46647 macvtap_put_vlan(vlan);
46648@@ -1181,7 +1181,7 @@ static int macvtap_device_event(struct notifier_block *unused,
46649 return NOTIFY_DONE;
46650 }
46651
46652-static struct notifier_block macvtap_notifier_block __read_mostly = {
46653+static struct notifier_block macvtap_notifier_block = {
46654 .notifier_call = macvtap_device_event,
46655 };
46656
46657diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
46658index daec9b0..6428fcb 100644
46659--- a/drivers/net/phy/mdio-bitbang.c
46660+++ b/drivers/net/phy/mdio-bitbang.c
46661@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
46662 struct mdiobb_ctrl *ctrl = bus->priv;
46663
46664 module_put(ctrl->ops->owner);
46665+ mdiobus_unregister(bus);
46666 mdiobus_free(bus);
46667 }
46668 EXPORT_SYMBOL(free_mdio_bitbang);
46669diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
46670index 72ff14b..11d442d 100644
46671--- a/drivers/net/ppp/ppp_generic.c
46672+++ b/drivers/net/ppp/ppp_generic.c
46673@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46674 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
46675 struct ppp_stats stats;
46676 struct ppp_comp_stats cstats;
46677- char *vers;
46678
46679 switch (cmd) {
46680 case SIOCGPPPSTATS:
46681@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46682 break;
46683
46684 case SIOCGPPPVER:
46685- vers = PPP_VERSION;
46686- if (copy_to_user(addr, vers, strlen(vers) + 1))
46687+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
46688 break;
46689 err = 0;
46690 break;
46691diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
46692index 1252d9c..80e660b 100644
46693--- a/drivers/net/slip/slhc.c
46694+++ b/drivers/net/slip/slhc.c
46695@@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
46696 register struct tcphdr *thp;
46697 register struct iphdr *ip;
46698 register struct cstate *cs;
46699- int len, hdrlen;
46700+ long len, hdrlen;
46701 unsigned char *cp = icp;
46702
46703 /* We've got a compressed packet; read the change byte */
46704diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
46705index c8624a8..f0a4f6a 100644
46706--- a/drivers/net/team/team.c
46707+++ b/drivers/net/team/team.c
46708@@ -2869,7 +2869,7 @@ static int team_device_event(struct notifier_block *unused,
46709 return NOTIFY_DONE;
46710 }
46711
46712-static struct notifier_block team_notifier_block __read_mostly = {
46713+static struct notifier_block team_notifier_block = {
46714 .notifier_call = team_device_event,
46715 };
46716
46717diff --git a/drivers/net/tun.c b/drivers/net/tun.c
46718index 26f8635..c237839 100644
46719--- a/drivers/net/tun.c
46720+++ b/drivers/net/tun.c
46721@@ -1876,7 +1876,7 @@ unlock:
46722 }
46723
46724 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46725- unsigned long arg, int ifreq_len)
46726+ unsigned long arg, size_t ifreq_len)
46727 {
46728 struct tun_file *tfile = file->private_data;
46729 struct tun_struct *tun;
46730@@ -1889,6 +1889,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46731 unsigned int ifindex;
46732 int ret;
46733
46734+ if (ifreq_len > sizeof ifr)
46735+ return -EFAULT;
46736+
46737 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
46738 if (copy_from_user(&ifr, argp, ifreq_len))
46739 return -EFAULT;
46740diff --git a/drivers/net/usb/cdc_ncm.c b/drivers/net/usb/cdc_ncm.c
46741index d350d27..75d7d9d 100644
46742--- a/drivers/net/usb/cdc_ncm.c
46743+++ b/drivers/net/usb/cdc_ncm.c
46744@@ -768,7 +768,7 @@ cdc_ncm_fill_tx_frame(struct usbnet *dev, struct sk_buff *skb, __le32 sign)
46745 skb_out->len > CDC_NCM_MIN_TX_PKT)
46746 memset(skb_put(skb_out, ctx->tx_max - skb_out->len), 0,
46747 ctx->tx_max - skb_out->len);
46748- else if ((skb_out->len % dev->maxpacket) == 0)
46749+ else if (skb_out->len < ctx->tx_max && (skb_out->len % dev->maxpacket) == 0)
46750 *skb_put(skb_out, 1) = 0; /* force short packet */
46751
46752 /* set final frame length */
46753diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
46754index 660bd5e..ac59452 100644
46755--- a/drivers/net/usb/hso.c
46756+++ b/drivers/net/usb/hso.c
46757@@ -71,7 +71,7 @@
46758 #include <asm/byteorder.h>
46759 #include <linux/serial_core.h>
46760 #include <linux/serial.h>
46761-
46762+#include <asm/local.h>
46763
46764 #define MOD_AUTHOR "Option Wireless"
46765 #define MOD_DESCRIPTION "USB High Speed Option driver"
46766@@ -1179,7 +1179,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
46767 struct urb *urb;
46768
46769 urb = serial->rx_urb[0];
46770- if (serial->port.count > 0) {
46771+ if (atomic_read(&serial->port.count) > 0) {
46772 count = put_rxbuf_data(urb, serial);
46773 if (count == -1)
46774 return;
46775@@ -1217,7 +1217,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
46776 DUMP1(urb->transfer_buffer, urb->actual_length);
46777
46778 /* Anyone listening? */
46779- if (serial->port.count == 0)
46780+ if (atomic_read(&serial->port.count) == 0)
46781 return;
46782
46783 if (serial->parent->port_spec & HSO_INFO_CRC_BUG)
46784@@ -1287,8 +1287,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46785 tty_port_tty_set(&serial->port, tty);
46786
46787 /* check for port already opened, if not set the termios */
46788- serial->port.count++;
46789- if (serial->port.count == 1) {
46790+ if (atomic_inc_return(&serial->port.count) == 1) {
46791 serial->rx_state = RX_IDLE;
46792 /* Force default termio settings */
46793 _hso_serial_set_termios(tty, NULL);
46794@@ -1300,7 +1299,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46795 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
46796 if (result) {
46797 hso_stop_serial_device(serial->parent);
46798- serial->port.count--;
46799+ atomic_dec(&serial->port.count);
46800 kref_put(&serial->parent->ref, hso_serial_ref_free);
46801 }
46802 } else {
46803@@ -1337,10 +1336,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
46804
46805 /* reset the rts and dtr */
46806 /* do the actual close */
46807- serial->port.count--;
46808+ atomic_dec(&serial->port.count);
46809
46810- if (serial->port.count <= 0) {
46811- serial->port.count = 0;
46812+ if (atomic_read(&serial->port.count) <= 0) {
46813+ atomic_set(&serial->port.count, 0);
46814 tty_port_tty_set(&serial->port, NULL);
46815 if (!usb_gone)
46816 hso_stop_serial_device(serial->parent);
46817@@ -1416,7 +1415,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
46818
46819 /* the actual setup */
46820 spin_lock_irqsave(&serial->serial_lock, flags);
46821- if (serial->port.count)
46822+ if (atomic_read(&serial->port.count))
46823 _hso_serial_set_termios(tty, old);
46824 else
46825 tty->termios = *old;
46826@@ -1885,7 +1884,7 @@ static void intr_callback(struct urb *urb)
46827 D1("Pending read interrupt on port %d\n", i);
46828 spin_lock(&serial->serial_lock);
46829 if (serial->rx_state == RX_IDLE &&
46830- serial->port.count > 0) {
46831+ atomic_read(&serial->port.count) > 0) {
46832 /* Setup and send a ctrl req read on
46833 * port i */
46834 if (!serial->rx_urb_filled[0]) {
46835@@ -3061,7 +3060,7 @@ static int hso_resume(struct usb_interface *iface)
46836 /* Start all serial ports */
46837 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
46838 if (serial_table[i] && (serial_table[i]->interface == iface)) {
46839- if (dev2ser(serial_table[i])->port.count) {
46840+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
46841 result =
46842 hso_start_serial_device(serial_table[i], GFP_NOIO);
46843 hso_kick_transmit(dev2ser(serial_table[i]));
46844diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
46845index adb12f3..48005ab 100644
46846--- a/drivers/net/usb/r8152.c
46847+++ b/drivers/net/usb/r8152.c
46848@@ -513,7 +513,7 @@ struct r8152 {
46849 void (*disable)(struct r8152 *);
46850 void (*down)(struct r8152 *);
46851 void (*unload)(struct r8152 *);
46852- } rtl_ops;
46853+ } __no_const rtl_ops;
46854
46855 int intr_interval;
46856 u32 msg_enable;
46857diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
46858index a2515887..6d13233 100644
46859--- a/drivers/net/usb/sierra_net.c
46860+++ b/drivers/net/usb/sierra_net.c
46861@@ -51,7 +51,7 @@ static const char driver_name[] = "sierra_net";
46862 /* atomic counter partially included in MAC address to make sure 2 devices
46863 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
46864 */
46865-static atomic_t iface_counter = ATOMIC_INIT(0);
46866+static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
46867
46868 /*
46869 * SYNC Timer Delay definition used to set the expiry time
46870@@ -697,7 +697,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
46871 dev->net->netdev_ops = &sierra_net_device_ops;
46872
46873 /* change MAC addr to include, ifacenum, and to be unique */
46874- dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
46875+ dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
46876 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
46877
46878 /* we will have to manufacture ethernet headers, prepare template */
46879diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
46880index d091e52..568bb179 100644
46881--- a/drivers/net/vxlan.c
46882+++ b/drivers/net/vxlan.c
46883@@ -2847,7 +2847,7 @@ nla_put_failure:
46884 return -EMSGSIZE;
46885 }
46886
46887-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
46888+static struct rtnl_link_ops vxlan_link_ops = {
46889 .kind = "vxlan",
46890 .maxtype = IFLA_VXLAN_MAX,
46891 .policy = vxlan_policy,
46892@@ -2894,7 +2894,7 @@ static int vxlan_lowerdev_event(struct notifier_block *unused,
46893 return NOTIFY_DONE;
46894 }
46895
46896-static struct notifier_block vxlan_notifier_block __read_mostly = {
46897+static struct notifier_block vxlan_notifier_block = {
46898 .notifier_call = vxlan_lowerdev_event,
46899 };
46900
46901diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
46902index 5920c99..ff2e4a5 100644
46903--- a/drivers/net/wan/lmc/lmc_media.c
46904+++ b/drivers/net/wan/lmc/lmc_media.c
46905@@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
46906 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
46907
46908 lmc_media_t lmc_ds3_media = {
46909- lmc_ds3_init, /* special media init stuff */
46910- lmc_ds3_default, /* reset to default state */
46911- lmc_ds3_set_status, /* reset status to state provided */
46912- lmc_dummy_set_1, /* set clock source */
46913- lmc_dummy_set2_1, /* set line speed */
46914- lmc_ds3_set_100ft, /* set cable length */
46915- lmc_ds3_set_scram, /* set scrambler */
46916- lmc_ds3_get_link_status, /* get link status */
46917- lmc_dummy_set_1, /* set link status */
46918- lmc_ds3_set_crc_length, /* set CRC length */
46919- lmc_dummy_set_1, /* set T1 or E1 circuit type */
46920- lmc_ds3_watchdog
46921+ .init = lmc_ds3_init, /* special media init stuff */
46922+ .defaults = lmc_ds3_default, /* reset to default state */
46923+ .set_status = lmc_ds3_set_status, /* reset status to state provided */
46924+ .set_clock_source = lmc_dummy_set_1, /* set clock source */
46925+ .set_speed = lmc_dummy_set2_1, /* set line speed */
46926+ .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
46927+ .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
46928+ .get_link_status = lmc_ds3_get_link_status, /* get link status */
46929+ .set_link_status = lmc_dummy_set_1, /* set link status */
46930+ .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
46931+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46932+ .watchdog = lmc_ds3_watchdog
46933 };
46934
46935 lmc_media_t lmc_hssi_media = {
46936- lmc_hssi_init, /* special media init stuff */
46937- lmc_hssi_default, /* reset to default state */
46938- lmc_hssi_set_status, /* reset status to state provided */
46939- lmc_hssi_set_clock, /* set clock source */
46940- lmc_dummy_set2_1, /* set line speed */
46941- lmc_dummy_set_1, /* set cable length */
46942- lmc_dummy_set_1, /* set scrambler */
46943- lmc_hssi_get_link_status, /* get link status */
46944- lmc_hssi_set_link_status, /* set link status */
46945- lmc_hssi_set_crc_length, /* set CRC length */
46946- lmc_dummy_set_1, /* set T1 or E1 circuit type */
46947- lmc_hssi_watchdog
46948+ .init = lmc_hssi_init, /* special media init stuff */
46949+ .defaults = lmc_hssi_default, /* reset to default state */
46950+ .set_status = lmc_hssi_set_status, /* reset status to state provided */
46951+ .set_clock_source = lmc_hssi_set_clock, /* set clock source */
46952+ .set_speed = lmc_dummy_set2_1, /* set line speed */
46953+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
46954+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46955+ .get_link_status = lmc_hssi_get_link_status, /* get link status */
46956+ .set_link_status = lmc_hssi_set_link_status, /* set link status */
46957+ .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
46958+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46959+ .watchdog = lmc_hssi_watchdog
46960 };
46961
46962-lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
46963- lmc_ssi_default, /* reset to default state */
46964- lmc_ssi_set_status, /* reset status to state provided */
46965- lmc_ssi_set_clock, /* set clock source */
46966- lmc_ssi_set_speed, /* set line speed */
46967- lmc_dummy_set_1, /* set cable length */
46968- lmc_dummy_set_1, /* set scrambler */
46969- lmc_ssi_get_link_status, /* get link status */
46970- lmc_ssi_set_link_status, /* set link status */
46971- lmc_ssi_set_crc_length, /* set CRC length */
46972- lmc_dummy_set_1, /* set T1 or E1 circuit type */
46973- lmc_ssi_watchdog
46974+lmc_media_t lmc_ssi_media = {
46975+ .init = lmc_ssi_init, /* special media init stuff */
46976+ .defaults = lmc_ssi_default, /* reset to default state */
46977+ .set_status = lmc_ssi_set_status, /* reset status to state provided */
46978+ .set_clock_source = lmc_ssi_set_clock, /* set clock source */
46979+ .set_speed = lmc_ssi_set_speed, /* set line speed */
46980+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
46981+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46982+ .get_link_status = lmc_ssi_get_link_status, /* get link status */
46983+ .set_link_status = lmc_ssi_set_link_status, /* set link status */
46984+ .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
46985+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46986+ .watchdog = lmc_ssi_watchdog
46987 };
46988
46989 lmc_media_t lmc_t1_media = {
46990- lmc_t1_init, /* special media init stuff */
46991- lmc_t1_default, /* reset to default state */
46992- lmc_t1_set_status, /* reset status to state provided */
46993- lmc_t1_set_clock, /* set clock source */
46994- lmc_dummy_set2_1, /* set line speed */
46995- lmc_dummy_set_1, /* set cable length */
46996- lmc_dummy_set_1, /* set scrambler */
46997- lmc_t1_get_link_status, /* get link status */
46998- lmc_dummy_set_1, /* set link status */
46999- lmc_t1_set_crc_length, /* set CRC length */
47000- lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
47001- lmc_t1_watchdog
47002+ .init = lmc_t1_init, /* special media init stuff */
47003+ .defaults = lmc_t1_default, /* reset to default state */
47004+ .set_status = lmc_t1_set_status, /* reset status to state provided */
47005+ .set_clock_source = lmc_t1_set_clock, /* set clock source */
47006+ .set_speed = lmc_dummy_set2_1, /* set line speed */
47007+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
47008+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
47009+ .get_link_status = lmc_t1_get_link_status, /* get link status */
47010+ .set_link_status = lmc_dummy_set_1, /* set link status */
47011+ .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
47012+ .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
47013+ .watchdog = lmc_t1_watchdog
47014 };
47015
47016 static void
47017diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
47018index feacc3b..5bac0de 100644
47019--- a/drivers/net/wan/z85230.c
47020+++ b/drivers/net/wan/z85230.c
47021@@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
47022
47023 struct z8530_irqhandler z8530_sync =
47024 {
47025- z8530_rx,
47026- z8530_tx,
47027- z8530_status
47028+ .rx = z8530_rx,
47029+ .tx = z8530_tx,
47030+ .status = z8530_status
47031 };
47032
47033 EXPORT_SYMBOL(z8530_sync);
47034@@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
47035 }
47036
47037 static struct z8530_irqhandler z8530_dma_sync = {
47038- z8530_dma_rx,
47039- z8530_dma_tx,
47040- z8530_dma_status
47041+ .rx = z8530_dma_rx,
47042+ .tx = z8530_dma_tx,
47043+ .status = z8530_dma_status
47044 };
47045
47046 static struct z8530_irqhandler z8530_txdma_sync = {
47047- z8530_rx,
47048- z8530_dma_tx,
47049- z8530_dma_status
47050+ .rx = z8530_rx,
47051+ .tx = z8530_dma_tx,
47052+ .status = z8530_dma_status
47053 };
47054
47055 /**
47056@@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
47057
47058 struct z8530_irqhandler z8530_nop=
47059 {
47060- z8530_rx_clear,
47061- z8530_tx_clear,
47062- z8530_status_clear
47063+ .rx = z8530_rx_clear,
47064+ .tx = z8530_tx_clear,
47065+ .status = z8530_status_clear
47066 };
47067
47068
47069diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
47070index 0b60295..b8bfa5b 100644
47071--- a/drivers/net/wimax/i2400m/rx.c
47072+++ b/drivers/net/wimax/i2400m/rx.c
47073@@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
47074 if (i2400m->rx_roq == NULL)
47075 goto error_roq_alloc;
47076
47077- rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
47078+ rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
47079 GFP_KERNEL);
47080 if (rd == NULL) {
47081 result = -ENOMEM;
47082diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
47083index edf4b57..68b51c0 100644
47084--- a/drivers/net/wireless/airo.c
47085+++ b/drivers/net/wireless/airo.c
47086@@ -7843,7 +7843,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
47087 struct airo_info *ai = dev->ml_priv;
47088 int ridcode;
47089 int enabled;
47090- static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
47091+ int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
47092 unsigned char *iobuf;
47093
47094 /* Only super-user can write RIDs */
47095diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
47096index 99b3bfa..9559372 100644
47097--- a/drivers/net/wireless/at76c50x-usb.c
47098+++ b/drivers/net/wireless/at76c50x-usb.c
47099@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
47100 }
47101
47102 /* Convert timeout from the DFU status to jiffies */
47103-static inline unsigned long at76_get_timeout(struct dfu_status *s)
47104+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
47105 {
47106 return msecs_to_jiffies((s->poll_timeout[2] << 16)
47107 | (s->poll_timeout[1] << 8)
47108diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
47109index edc57ab..ff49e0a 100644
47110--- a/drivers/net/wireless/ath/ath10k/htc.c
47111+++ b/drivers/net/wireless/ath/ath10k/htc.c
47112@@ -831,7 +831,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
47113 /* registered target arrival callback from the HIF layer */
47114 int ath10k_htc_init(struct ath10k *ar)
47115 {
47116- struct ath10k_hif_cb htc_callbacks;
47117+ static struct ath10k_hif_cb htc_callbacks = {
47118+ .rx_completion = ath10k_htc_rx_completion_handler,
47119+ .tx_completion = ath10k_htc_tx_completion_handler,
47120+ };
47121 struct ath10k_htc_ep *ep = NULL;
47122 struct ath10k_htc *htc = &ar->htc;
47123
47124@@ -841,8 +844,6 @@ int ath10k_htc_init(struct ath10k *ar)
47125 ath10k_htc_reset_endpoint_states(htc);
47126
47127 /* setup HIF layer callbacks */
47128- htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
47129- htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
47130 htc->ar = ar;
47131
47132 /* Get HIF default pipe for HTC message exchange */
47133diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
47134index 4716d33..a688310 100644
47135--- a/drivers/net/wireless/ath/ath10k/htc.h
47136+++ b/drivers/net/wireless/ath/ath10k/htc.h
47137@@ -271,13 +271,13 @@ enum ath10k_htc_ep_id {
47138
47139 struct ath10k_htc_ops {
47140 void (*target_send_suspend_complete)(struct ath10k *ar);
47141-};
47142+} __no_const;
47143
47144 struct ath10k_htc_ep_ops {
47145 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
47146 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
47147 void (*ep_tx_credits)(struct ath10k *);
47148-};
47149+} __no_const;
47150
47151 /* service connection information */
47152 struct ath10k_htc_svc_conn_req {
47153diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
47154index 741b38d..b7ae41b 100644
47155--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
47156+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
47157@@ -220,8 +220,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47158 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
47159 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
47160
47161- ACCESS_ONCE(ads->ds_link) = i->link;
47162- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
47163+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
47164+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
47165
47166 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
47167 ctl6 = SM(i->keytype, AR_EncrType);
47168@@ -235,26 +235,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47169
47170 if ((i->is_first || i->is_last) &&
47171 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
47172- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
47173+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
47174 | set11nTries(i->rates, 1)
47175 | set11nTries(i->rates, 2)
47176 | set11nTries(i->rates, 3)
47177 | (i->dur_update ? AR_DurUpdateEna : 0)
47178 | SM(0, AR_BurstDur);
47179
47180- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
47181+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
47182 | set11nRate(i->rates, 1)
47183 | set11nRate(i->rates, 2)
47184 | set11nRate(i->rates, 3);
47185 } else {
47186- ACCESS_ONCE(ads->ds_ctl2) = 0;
47187- ACCESS_ONCE(ads->ds_ctl3) = 0;
47188+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
47189+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
47190 }
47191
47192 if (!i->is_first) {
47193- ACCESS_ONCE(ads->ds_ctl0) = 0;
47194- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
47195- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
47196+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
47197+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
47198+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
47199 return;
47200 }
47201
47202@@ -279,7 +279,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47203 break;
47204 }
47205
47206- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
47207+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
47208 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
47209 | SM(i->txpower, AR_XmitPower)
47210 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
47211@@ -289,19 +289,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47212 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
47213 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
47214
47215- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
47216- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
47217+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
47218+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
47219
47220 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
47221 return;
47222
47223- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
47224+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
47225 | set11nPktDurRTSCTS(i->rates, 1);
47226
47227- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
47228+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
47229 | set11nPktDurRTSCTS(i->rates, 3);
47230
47231- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
47232+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
47233 | set11nRateFlags(i->rates, 1)
47234 | set11nRateFlags(i->rates, 2)
47235 | set11nRateFlags(i->rates, 3)
47236diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
47237index 729ffbf..49f50e3 100644
47238--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
47239+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
47240@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47241 (i->qcu << AR_TxQcuNum_S) | desc_len;
47242
47243 checksum += val;
47244- ACCESS_ONCE(ads->info) = val;
47245+ ACCESS_ONCE_RW(ads->info) = val;
47246
47247 checksum += i->link;
47248- ACCESS_ONCE(ads->link) = i->link;
47249+ ACCESS_ONCE_RW(ads->link) = i->link;
47250
47251 checksum += i->buf_addr[0];
47252- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
47253+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
47254 checksum += i->buf_addr[1];
47255- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
47256+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
47257 checksum += i->buf_addr[2];
47258- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
47259+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
47260 checksum += i->buf_addr[3];
47261- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
47262+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
47263
47264 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
47265- ACCESS_ONCE(ads->ctl3) = val;
47266+ ACCESS_ONCE_RW(ads->ctl3) = val;
47267 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
47268- ACCESS_ONCE(ads->ctl5) = val;
47269+ ACCESS_ONCE_RW(ads->ctl5) = val;
47270 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
47271- ACCESS_ONCE(ads->ctl7) = val;
47272+ ACCESS_ONCE_RW(ads->ctl7) = val;
47273 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
47274- ACCESS_ONCE(ads->ctl9) = val;
47275+ ACCESS_ONCE_RW(ads->ctl9) = val;
47276
47277 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
47278- ACCESS_ONCE(ads->ctl10) = checksum;
47279+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
47280
47281 if (i->is_first || i->is_last) {
47282- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
47283+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
47284 | set11nTries(i->rates, 1)
47285 | set11nTries(i->rates, 2)
47286 | set11nTries(i->rates, 3)
47287 | (i->dur_update ? AR_DurUpdateEna : 0)
47288 | SM(0, AR_BurstDur);
47289
47290- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
47291+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
47292 | set11nRate(i->rates, 1)
47293 | set11nRate(i->rates, 2)
47294 | set11nRate(i->rates, 3);
47295 } else {
47296- ACCESS_ONCE(ads->ctl13) = 0;
47297- ACCESS_ONCE(ads->ctl14) = 0;
47298+ ACCESS_ONCE_RW(ads->ctl13) = 0;
47299+ ACCESS_ONCE_RW(ads->ctl14) = 0;
47300 }
47301
47302 ads->ctl20 = 0;
47303@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47304
47305 ctl17 = SM(i->keytype, AR_EncrType);
47306 if (!i->is_first) {
47307- ACCESS_ONCE(ads->ctl11) = 0;
47308- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
47309- ACCESS_ONCE(ads->ctl15) = 0;
47310- ACCESS_ONCE(ads->ctl16) = 0;
47311- ACCESS_ONCE(ads->ctl17) = ctl17;
47312- ACCESS_ONCE(ads->ctl18) = 0;
47313- ACCESS_ONCE(ads->ctl19) = 0;
47314+ ACCESS_ONCE_RW(ads->ctl11) = 0;
47315+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
47316+ ACCESS_ONCE_RW(ads->ctl15) = 0;
47317+ ACCESS_ONCE_RW(ads->ctl16) = 0;
47318+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
47319+ ACCESS_ONCE_RW(ads->ctl18) = 0;
47320+ ACCESS_ONCE_RW(ads->ctl19) = 0;
47321 return;
47322 }
47323
47324- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
47325+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
47326 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
47327 | SM(i->txpower, AR_XmitPower)
47328 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
47329@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47330 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
47331 ctl12 |= SM(val, AR_PAPRDChainMask);
47332
47333- ACCESS_ONCE(ads->ctl12) = ctl12;
47334- ACCESS_ONCE(ads->ctl17) = ctl17;
47335+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
47336+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
47337
47338- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
47339+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
47340 | set11nPktDurRTSCTS(i->rates, 1);
47341
47342- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
47343+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
47344 | set11nPktDurRTSCTS(i->rates, 3);
47345
47346- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
47347+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
47348 | set11nRateFlags(i->rates, 1)
47349 | set11nRateFlags(i->rates, 2)
47350 | set11nRateFlags(i->rates, 3)
47351 | SM(i->rtscts_rate, AR_RTSCTSRate);
47352
47353- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
47354+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
47355 }
47356
47357 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
47358diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
47359index 0acd4b5..0591c91 100644
47360--- a/drivers/net/wireless/ath/ath9k/hw.h
47361+++ b/drivers/net/wireless/ath/ath9k/hw.h
47362@@ -629,7 +629,7 @@ struct ath_hw_private_ops {
47363
47364 /* ANI */
47365 void (*ani_cache_ini_regs)(struct ath_hw *ah);
47366-};
47367+} __no_const;
47368
47369 /**
47370 * struct ath_spec_scan - parameters for Atheros spectral scan
47371@@ -706,7 +706,7 @@ struct ath_hw_ops {
47372 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
47373 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
47374 #endif
47375-};
47376+} __no_const;
47377
47378 struct ath_nf_limits {
47379 s16 max;
47380diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
47381index 92190da..f3a4c4c 100644
47382--- a/drivers/net/wireless/b43/phy_lp.c
47383+++ b/drivers/net/wireless/b43/phy_lp.c
47384@@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
47385 {
47386 struct ssb_bus *bus = dev->dev->sdev->bus;
47387
47388- static const struct b206x_channel *chandata = NULL;
47389+ const struct b206x_channel *chandata = NULL;
47390 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
47391 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
47392 u16 old_comm15, scale;
47393diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
47394index 0487461..fd9e84a 100644
47395--- a/drivers/net/wireless/iwlegacy/3945-mac.c
47396+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
47397@@ -3638,7 +3638,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
47398 */
47399 if (il3945_mod_params.disable_hw_scan) {
47400 D_INFO("Disabling hw_scan\n");
47401- il3945_mac_ops.hw_scan = NULL;
47402+ pax_open_kernel();
47403+ *(void **)&il3945_mac_ops.hw_scan = NULL;
47404+ pax_close_kernel();
47405 }
47406
47407 D_INFO("*** LOAD DRIVER ***\n");
47408diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
47409index d2fe259..0c4c682 100644
47410--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
47411+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
47412@@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
47413 {
47414 struct iwl_priv *priv = file->private_data;
47415 char buf[64];
47416- int buf_size;
47417+ size_t buf_size;
47418 u32 offset, len;
47419
47420 memset(buf, 0, sizeof(buf));
47421@@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
47422 struct iwl_priv *priv = file->private_data;
47423
47424 char buf[8];
47425- int buf_size;
47426+ size_t buf_size;
47427 u32 reset_flag;
47428
47429 memset(buf, 0, sizeof(buf));
47430@@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
47431 {
47432 struct iwl_priv *priv = file->private_data;
47433 char buf[8];
47434- int buf_size;
47435+ size_t buf_size;
47436 int ht40;
47437
47438 memset(buf, 0, sizeof(buf));
47439@@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
47440 {
47441 struct iwl_priv *priv = file->private_data;
47442 char buf[8];
47443- int buf_size;
47444+ size_t buf_size;
47445 int value;
47446
47447 memset(buf, 0, sizeof(buf));
47448@@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
47449 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
47450 DEBUGFS_READ_FILE_OPS(current_sleep_command);
47451
47452-static const char *fmt_value = " %-30s %10u\n";
47453-static const char *fmt_hex = " %-30s 0x%02X\n";
47454-static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
47455-static const char *fmt_header =
47456+static const char fmt_value[] = " %-30s %10u\n";
47457+static const char fmt_hex[] = " %-30s 0x%02X\n";
47458+static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
47459+static const char fmt_header[] =
47460 "%-32s current cumulative delta max\n";
47461
47462 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
47463@@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
47464 {
47465 struct iwl_priv *priv = file->private_data;
47466 char buf[8];
47467- int buf_size;
47468+ size_t buf_size;
47469 int clear;
47470
47471 memset(buf, 0, sizeof(buf));
47472@@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
47473 {
47474 struct iwl_priv *priv = file->private_data;
47475 char buf[8];
47476- int buf_size;
47477+ size_t buf_size;
47478 int trace;
47479
47480 memset(buf, 0, sizeof(buf));
47481@@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
47482 {
47483 struct iwl_priv *priv = file->private_data;
47484 char buf[8];
47485- int buf_size;
47486+ size_t buf_size;
47487 int missed;
47488
47489 memset(buf, 0, sizeof(buf));
47490@@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
47491
47492 struct iwl_priv *priv = file->private_data;
47493 char buf[8];
47494- int buf_size;
47495+ size_t buf_size;
47496 int plcp;
47497
47498 memset(buf, 0, sizeof(buf));
47499@@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
47500
47501 struct iwl_priv *priv = file->private_data;
47502 char buf[8];
47503- int buf_size;
47504+ size_t buf_size;
47505 int flush;
47506
47507 memset(buf, 0, sizeof(buf));
47508@@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
47509
47510 struct iwl_priv *priv = file->private_data;
47511 char buf[8];
47512- int buf_size;
47513+ size_t buf_size;
47514 int rts;
47515
47516 if (!priv->cfg->ht_params)
47517@@ -2205,7 +2205,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
47518 {
47519 struct iwl_priv *priv = file->private_data;
47520 char buf[8];
47521- int buf_size;
47522+ size_t buf_size;
47523
47524 memset(buf, 0, sizeof(buf));
47525 buf_size = min(count, sizeof(buf) - 1);
47526@@ -2239,7 +2239,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
47527 struct iwl_priv *priv = file->private_data;
47528 u32 event_log_flag;
47529 char buf[8];
47530- int buf_size;
47531+ size_t buf_size;
47532
47533 /* check that the interface is up */
47534 if (!iwl_is_ready(priv))
47535@@ -2293,7 +2293,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
47536 struct iwl_priv *priv = file->private_data;
47537 char buf[8];
47538 u32 calib_disabled;
47539- int buf_size;
47540+ size_t buf_size;
47541
47542 memset(buf, 0, sizeof(buf));
47543 buf_size = min(count, sizeof(buf) - 1);
47544diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
47545index ea7e70c..bc0c45f 100644
47546--- a/drivers/net/wireless/iwlwifi/dvm/main.c
47547+++ b/drivers/net/wireless/iwlwifi/dvm/main.c
47548@@ -1127,7 +1127,7 @@ static void iwl_option_config(struct iwl_priv *priv)
47549 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
47550 {
47551 struct iwl_nvm_data *data = priv->nvm_data;
47552- char *debug_msg;
47553+ static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
47554
47555 if (data->sku_cap_11n_enable &&
47556 !priv->cfg->ht_params) {
47557@@ -1141,7 +1141,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
47558 return -EINVAL;
47559 }
47560
47561- debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
47562 IWL_DEBUG_INFO(priv, debug_msg,
47563 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
47564 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
47565diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
47566index f950780..be9df93 100644
47567--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
47568+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
47569@@ -1365,7 +1365,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
47570 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
47571
47572 char buf[8];
47573- int buf_size;
47574+ size_t buf_size;
47575 u32 reset_flag;
47576
47577 memset(buf, 0, sizeof(buf));
47578@@ -1386,7 +1386,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
47579 {
47580 struct iwl_trans *trans = file->private_data;
47581 char buf[8];
47582- int buf_size;
47583+ size_t buf_size;
47584 int csr;
47585
47586 memset(buf, 0, sizeof(buf));
47587diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
47588index 69d4c31..bd0b316 100644
47589--- a/drivers/net/wireless/mac80211_hwsim.c
47590+++ b/drivers/net/wireless/mac80211_hwsim.c
47591@@ -2541,20 +2541,20 @@ static int __init init_mac80211_hwsim(void)
47592 if (channels < 1)
47593 return -EINVAL;
47594
47595- mac80211_hwsim_mchan_ops = mac80211_hwsim_ops;
47596- mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
47597- mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
47598- mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
47599- mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
47600- mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
47601- mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
47602- mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
47603- mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
47604- mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47605- mac80211_hwsim_mchan_ops.assign_vif_chanctx =
47606- mac80211_hwsim_assign_vif_chanctx;
47607- mac80211_hwsim_mchan_ops.unassign_vif_chanctx =
47608- mac80211_hwsim_unassign_vif_chanctx;
47609+ pax_open_kernel();
47610+ memcpy((void *)&mac80211_hwsim_mchan_ops, &mac80211_hwsim_ops, sizeof mac80211_hwsim_mchan_ops);
47611+ *(void **)&mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
47612+ *(void **)&mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
47613+ *(void **)&mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
47614+ *(void **)&mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
47615+ *(void **)&mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
47616+ *(void **)&mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
47617+ *(void **)&mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
47618+ *(void **)&mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
47619+ *(void **)&mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47620+ *(void **)&mac80211_hwsim_mchan_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
47621+ *(void **)&mac80211_hwsim_mchan_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
47622+ pax_close_kernel();
47623
47624 spin_lock_init(&hwsim_radio_lock);
47625 INIT_LIST_HEAD(&hwsim_radios);
47626diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
47627index 5028557..91cf394 100644
47628--- a/drivers/net/wireless/rndis_wlan.c
47629+++ b/drivers/net/wireless/rndis_wlan.c
47630@@ -1236,7 +1236,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
47631
47632 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
47633
47634- if (rts_threshold < 0 || rts_threshold > 2347)
47635+ if (rts_threshold > 2347)
47636 rts_threshold = 2347;
47637
47638 tmp = cpu_to_le32(rts_threshold);
47639diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
47640index e3b885d..7a7de2f 100644
47641--- a/drivers/net/wireless/rt2x00/rt2x00.h
47642+++ b/drivers/net/wireless/rt2x00/rt2x00.h
47643@@ -375,7 +375,7 @@ struct rt2x00_intf {
47644 * for hardware which doesn't support hardware
47645 * sequence counting.
47646 */
47647- atomic_t seqno;
47648+ atomic_unchecked_t seqno;
47649 };
47650
47651 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
47652diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
47653index 5642ccc..01f03eb 100644
47654--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
47655+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
47656@@ -250,9 +250,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
47657 * sequence counter given by mac80211.
47658 */
47659 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
47660- seqno = atomic_add_return(0x10, &intf->seqno);
47661+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
47662 else
47663- seqno = atomic_read(&intf->seqno);
47664+ seqno = atomic_read_unchecked(&intf->seqno);
47665
47666 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
47667 hdr->seq_ctrl |= cpu_to_le16(seqno);
47668diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
47669index e2b3d9c..67a5184 100644
47670--- a/drivers/net/wireless/ti/wl1251/sdio.c
47671+++ b/drivers/net/wireless/ti/wl1251/sdio.c
47672@@ -271,13 +271,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
47673
47674 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
47675
47676- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47677- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47678+ pax_open_kernel();
47679+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47680+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47681+ pax_close_kernel();
47682
47683 wl1251_info("using dedicated interrupt line");
47684 } else {
47685- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47686- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47687+ pax_open_kernel();
47688+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47689+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47690+ pax_close_kernel();
47691
47692 wl1251_info("using SDIO interrupt");
47693 }
47694diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
47695index be7129b..4161356 100644
47696--- a/drivers/net/wireless/ti/wl12xx/main.c
47697+++ b/drivers/net/wireless/ti/wl12xx/main.c
47698@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47699 sizeof(wl->conf.mem));
47700
47701 /* read data preparation is only needed by wl127x */
47702- wl->ops->prepare_read = wl127x_prepare_read;
47703+ pax_open_kernel();
47704+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47705+ pax_close_kernel();
47706
47707 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47708 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47709@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47710 sizeof(wl->conf.mem));
47711
47712 /* read data preparation is only needed by wl127x */
47713- wl->ops->prepare_read = wl127x_prepare_read;
47714+ pax_open_kernel();
47715+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47716+ pax_close_kernel();
47717
47718 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47719 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47720diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
47721index ec37b16..7e34d66 100644
47722--- a/drivers/net/wireless/ti/wl18xx/main.c
47723+++ b/drivers/net/wireless/ti/wl18xx/main.c
47724@@ -1823,8 +1823,10 @@ static int wl18xx_setup(struct wl1271 *wl)
47725 }
47726
47727 if (!checksum_param) {
47728- wl18xx_ops.set_rx_csum = NULL;
47729- wl18xx_ops.init_vif = NULL;
47730+ pax_open_kernel();
47731+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
47732+ *(void **)&wl18xx_ops.init_vif = NULL;
47733+ pax_close_kernel();
47734 }
47735
47736 /* Enable 11a Band only if we have 5G antennas */
47737diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
47738index a912dc0..a8225ba 100644
47739--- a/drivers/net/wireless/zd1211rw/zd_usb.c
47740+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
47741@@ -385,7 +385,7 @@ static inline void handle_regs_int(struct urb *urb)
47742 {
47743 struct zd_usb *usb = urb->context;
47744 struct zd_usb_interrupt *intr = &usb->intr;
47745- int len;
47746+ unsigned int len;
47747 u16 int_num;
47748
47749 ZD_ASSERT(in_interrupt());
47750diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
47751index 683671a..4519fc2 100644
47752--- a/drivers/nfc/nfcwilink.c
47753+++ b/drivers/nfc/nfcwilink.c
47754@@ -497,7 +497,7 @@ static struct nci_ops nfcwilink_ops = {
47755
47756 static int nfcwilink_probe(struct platform_device *pdev)
47757 {
47758- static struct nfcwilink *drv;
47759+ struct nfcwilink *drv;
47760 int rc;
47761 __u32 protocols;
47762
47763diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
47764index d93b2b6..ae50401 100644
47765--- a/drivers/oprofile/buffer_sync.c
47766+++ b/drivers/oprofile/buffer_sync.c
47767@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
47768 if (cookie == NO_COOKIE)
47769 offset = pc;
47770 if (cookie == INVALID_COOKIE) {
47771- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47772+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47773 offset = pc;
47774 }
47775 if (cookie != last_cookie) {
47776@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
47777 /* add userspace sample */
47778
47779 if (!mm) {
47780- atomic_inc(&oprofile_stats.sample_lost_no_mm);
47781+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
47782 return 0;
47783 }
47784
47785 cookie = lookup_dcookie(mm, s->eip, &offset);
47786
47787 if (cookie == INVALID_COOKIE) {
47788- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47789+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47790 return 0;
47791 }
47792
47793@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
47794 /* ignore backtraces if failed to add a sample */
47795 if (state == sb_bt_start) {
47796 state = sb_bt_ignore;
47797- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
47798+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
47799 }
47800 }
47801 release_mm(mm);
47802diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
47803index c0cc4e7..44d4e54 100644
47804--- a/drivers/oprofile/event_buffer.c
47805+++ b/drivers/oprofile/event_buffer.c
47806@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
47807 }
47808
47809 if (buffer_pos == buffer_size) {
47810- atomic_inc(&oprofile_stats.event_lost_overflow);
47811+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
47812 return;
47813 }
47814
47815diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
47816index ed2c3ec..deda85a 100644
47817--- a/drivers/oprofile/oprof.c
47818+++ b/drivers/oprofile/oprof.c
47819@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
47820 if (oprofile_ops.switch_events())
47821 return;
47822
47823- atomic_inc(&oprofile_stats.multiplex_counter);
47824+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
47825 start_switch_worker();
47826 }
47827
47828diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
47829index ee2cfce..7f8f699 100644
47830--- a/drivers/oprofile/oprofile_files.c
47831+++ b/drivers/oprofile/oprofile_files.c
47832@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
47833
47834 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
47835
47836-static ssize_t timeout_read(struct file *file, char __user *buf,
47837+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
47838 size_t count, loff_t *offset)
47839 {
47840 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
47841diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
47842index 59659ce..6c860a0 100644
47843--- a/drivers/oprofile/oprofile_stats.c
47844+++ b/drivers/oprofile/oprofile_stats.c
47845@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
47846 cpu_buf->sample_invalid_eip = 0;
47847 }
47848
47849- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
47850- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
47851- atomic_set(&oprofile_stats.event_lost_overflow, 0);
47852- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
47853- atomic_set(&oprofile_stats.multiplex_counter, 0);
47854+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
47855+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
47856+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
47857+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
47858+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
47859 }
47860
47861
47862diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
47863index 1fc622b..8c48fc3 100644
47864--- a/drivers/oprofile/oprofile_stats.h
47865+++ b/drivers/oprofile/oprofile_stats.h
47866@@ -13,11 +13,11 @@
47867 #include <linux/atomic.h>
47868
47869 struct oprofile_stat_struct {
47870- atomic_t sample_lost_no_mm;
47871- atomic_t sample_lost_no_mapping;
47872- atomic_t bt_lost_no_mapping;
47873- atomic_t event_lost_overflow;
47874- atomic_t multiplex_counter;
47875+ atomic_unchecked_t sample_lost_no_mm;
47876+ atomic_unchecked_t sample_lost_no_mapping;
47877+ atomic_unchecked_t bt_lost_no_mapping;
47878+ atomic_unchecked_t event_lost_overflow;
47879+ atomic_unchecked_t multiplex_counter;
47880 };
47881
47882 extern struct oprofile_stat_struct oprofile_stats;
47883diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
47884index 3f49345..c750d0b 100644
47885--- a/drivers/oprofile/oprofilefs.c
47886+++ b/drivers/oprofile/oprofilefs.c
47887@@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
47888
47889 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
47890 {
47891- atomic_t *val = file->private_data;
47892- return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
47893+ atomic_unchecked_t *val = file->private_data;
47894+ return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
47895 }
47896
47897
47898@@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
47899
47900
47901 int oprofilefs_create_ro_atomic(struct dentry *root,
47902- char const *name, atomic_t *val)
47903+ char const *name, atomic_unchecked_t *val)
47904 {
47905 return __oprofilefs_create_file(root, name,
47906 &atomic_ro_fops, 0444, val);
47907diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
47908index 61be1d9..dec05d7 100644
47909--- a/drivers/oprofile/timer_int.c
47910+++ b/drivers/oprofile/timer_int.c
47911@@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
47912 return NOTIFY_OK;
47913 }
47914
47915-static struct notifier_block __refdata oprofile_cpu_notifier = {
47916+static struct notifier_block oprofile_cpu_notifier = {
47917 .notifier_call = oprofile_cpu_notify,
47918 };
47919
47920diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
47921index 92ed045..62d39bd7 100644
47922--- a/drivers/parport/procfs.c
47923+++ b/drivers/parport/procfs.c
47924@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
47925
47926 *ppos += len;
47927
47928- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
47929+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
47930 }
47931
47932 #ifdef CONFIG_PARPORT_1284
47933@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
47934
47935 *ppos += len;
47936
47937- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
47938+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
47939 }
47940 #endif /* IEEE1284.3 support. */
47941
47942diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
47943index 8dcccff..35d701d 100644
47944--- a/drivers/pci/hotplug/acpiphp_ibm.c
47945+++ b/drivers/pci/hotplug/acpiphp_ibm.c
47946@@ -452,7 +452,9 @@ static int __init ibm_acpiphp_init(void)
47947 goto init_cleanup;
47948 }
47949
47950- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
47951+ pax_open_kernel();
47952+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
47953+ pax_close_kernel();
47954 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
47955
47956 return retval;
47957diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
47958index 7536eef..52dc8fa 100644
47959--- a/drivers/pci/hotplug/cpcihp_generic.c
47960+++ b/drivers/pci/hotplug/cpcihp_generic.c
47961@@ -73,7 +73,6 @@ static u16 port;
47962 static unsigned int enum_bit;
47963 static u8 enum_mask;
47964
47965-static struct cpci_hp_controller_ops generic_hpc_ops;
47966 static struct cpci_hp_controller generic_hpc;
47967
47968 static int __init validate_parameters(void)
47969@@ -139,6 +138,10 @@ static int query_enum(void)
47970 return ((value & enum_mask) == enum_mask);
47971 }
47972
47973+static struct cpci_hp_controller_ops generic_hpc_ops = {
47974+ .query_enum = query_enum,
47975+};
47976+
47977 static int __init cpcihp_generic_init(void)
47978 {
47979 int status;
47980@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
47981 pci_dev_put(dev);
47982
47983 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
47984- generic_hpc_ops.query_enum = query_enum;
47985 generic_hpc.ops = &generic_hpc_ops;
47986
47987 status = cpci_hp_register_controller(&generic_hpc);
47988diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
47989index e8c4a7c..7046f5c 100644
47990--- a/drivers/pci/hotplug/cpcihp_zt5550.c
47991+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
47992@@ -59,7 +59,6 @@
47993 /* local variables */
47994 static bool debug;
47995 static bool poll;
47996-static struct cpci_hp_controller_ops zt5550_hpc_ops;
47997 static struct cpci_hp_controller zt5550_hpc;
47998
47999 /* Primary cPCI bus bridge device */
48000@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
48001 return 0;
48002 }
48003
48004+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
48005+ .query_enum = zt5550_hc_query_enum,
48006+};
48007+
48008 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
48009 {
48010 int status;
48011@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
48012 dbg("returned from zt5550_hc_config");
48013
48014 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
48015- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
48016 zt5550_hpc.ops = &zt5550_hpc_ops;
48017 if(!poll) {
48018 zt5550_hpc.irq = hc_dev->irq;
48019 zt5550_hpc.irq_flags = IRQF_SHARED;
48020 zt5550_hpc.dev_id = hc_dev;
48021
48022- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
48023- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
48024- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
48025+ pax_open_kernel();
48026+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
48027+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
48028+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
48029+ pax_open_kernel();
48030 } else {
48031 info("using ENUM# polling mode");
48032 }
48033diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
48034index 76ba8a1..20ca857 100644
48035--- a/drivers/pci/hotplug/cpqphp_nvram.c
48036+++ b/drivers/pci/hotplug/cpqphp_nvram.c
48037@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
48038
48039 void compaq_nvram_init (void __iomem *rom_start)
48040 {
48041+
48042+#ifndef CONFIG_PAX_KERNEXEC
48043 if (rom_start) {
48044 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
48045 }
48046+#endif
48047+
48048 dbg("int15 entry = %p\n", compaq_int15_entry_point);
48049
48050 /* initialize our int15 lock */
48051diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
48052index cfa92a9..29539c5 100644
48053--- a/drivers/pci/hotplug/pci_hotplug_core.c
48054+++ b/drivers/pci/hotplug/pci_hotplug_core.c
48055@@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
48056 return -EINVAL;
48057 }
48058
48059- slot->ops->owner = owner;
48060- slot->ops->mod_name = mod_name;
48061+ pax_open_kernel();
48062+ *(struct module **)&slot->ops->owner = owner;
48063+ *(const char **)&slot->ops->mod_name = mod_name;
48064+ pax_close_kernel();
48065
48066 mutex_lock(&pci_hp_mutex);
48067 /*
48068diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
48069index 53b58de..4479896 100644
48070--- a/drivers/pci/hotplug/pciehp_core.c
48071+++ b/drivers/pci/hotplug/pciehp_core.c
48072@@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
48073 struct slot *slot = ctrl->slot;
48074 struct hotplug_slot *hotplug = NULL;
48075 struct hotplug_slot_info *info = NULL;
48076- struct hotplug_slot_ops *ops = NULL;
48077+ hotplug_slot_ops_no_const *ops = NULL;
48078 char name[SLOT_NAME_SIZE];
48079 int retval = -ENOMEM;
48080
48081diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
48082index 955ab79..d1df9c7 100644
48083--- a/drivers/pci/msi.c
48084+++ b/drivers/pci/msi.c
48085@@ -524,8 +524,8 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
48086 {
48087 struct attribute **msi_attrs;
48088 struct attribute *msi_attr;
48089- struct device_attribute *msi_dev_attr;
48090- struct attribute_group *msi_irq_group;
48091+ device_attribute_no_const *msi_dev_attr;
48092+ attribute_group_no_const *msi_irq_group;
48093 const struct attribute_group **msi_irq_groups;
48094 struct msi_desc *entry;
48095 int ret = -ENOMEM;
48096@@ -589,7 +589,7 @@ error_attrs:
48097 count = 0;
48098 msi_attr = msi_attrs[count];
48099 while (msi_attr) {
48100- msi_dev_attr = container_of(msi_attr, struct device_attribute, attr);
48101+ msi_dev_attr = container_of(msi_attr, device_attribute_no_const, attr);
48102 kfree(msi_attr->name);
48103 kfree(msi_dev_attr);
48104 ++count;
48105diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
48106index 276ef9c..1d33a36 100644
48107--- a/drivers/pci/pci-sysfs.c
48108+++ b/drivers/pci/pci-sysfs.c
48109@@ -1112,7 +1112,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
48110 {
48111 /* allocate attribute structure, piggyback attribute name */
48112 int name_len = write_combine ? 13 : 10;
48113- struct bin_attribute *res_attr;
48114+ bin_attribute_no_const *res_attr;
48115 int retval;
48116
48117 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
48118@@ -1297,7 +1297,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
48119 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
48120 {
48121 int retval;
48122- struct bin_attribute *attr;
48123+ bin_attribute_no_const *attr;
48124
48125 /* If the device has VPD, try to expose it in sysfs. */
48126 if (dev->vpd) {
48127@@ -1344,7 +1344,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
48128 {
48129 int retval;
48130 int rom_size = 0;
48131- struct bin_attribute *attr;
48132+ bin_attribute_no_const *attr;
48133
48134 if (!sysfs_initialized)
48135 return -EACCES;
48136diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
48137index 4df38df..b6bb7fe 100644
48138--- a/drivers/pci/pci.h
48139+++ b/drivers/pci/pci.h
48140@@ -93,7 +93,7 @@ struct pci_vpd_ops {
48141 struct pci_vpd {
48142 unsigned int len;
48143 const struct pci_vpd_ops *ops;
48144- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
48145+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
48146 };
48147
48148 int pci_vpd_pci22_init(struct pci_dev *dev);
48149diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
48150index e1e7026..d28dd33 100644
48151--- a/drivers/pci/pcie/aspm.c
48152+++ b/drivers/pci/pcie/aspm.c
48153@@ -27,9 +27,9 @@
48154 #define MODULE_PARAM_PREFIX "pcie_aspm."
48155
48156 /* Note: those are not register definitions */
48157-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
48158-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
48159-#define ASPM_STATE_L1 (4) /* L1 state */
48160+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
48161+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
48162+#define ASPM_STATE_L1 (4U) /* L1 state */
48163 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
48164 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
48165
48166diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
48167index 6e34498..9911975 100644
48168--- a/drivers/pci/probe.c
48169+++ b/drivers/pci/probe.c
48170@@ -175,7 +175,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
48171 struct pci_bus_region region, inverted_region;
48172 bool bar_too_big = false, bar_disabled = false;
48173
48174- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
48175+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
48176
48177 /* No printks while decoding is disabled! */
48178 if (!dev->mmio_always_on) {
48179diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
48180index 46d1378..30e452b 100644
48181--- a/drivers/pci/proc.c
48182+++ b/drivers/pci/proc.c
48183@@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
48184 static int __init pci_proc_init(void)
48185 {
48186 struct pci_dev *dev = NULL;
48187+
48188+#ifdef CONFIG_GRKERNSEC_PROC_ADD
48189+#ifdef CONFIG_GRKERNSEC_PROC_USER
48190+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
48191+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48192+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
48193+#endif
48194+#else
48195 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
48196+#endif
48197 proc_create("devices", 0, proc_bus_pci_dir,
48198 &proc_bus_pci_dev_operations);
48199 proc_initialized = 1;
48200diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
48201index 7f3aad0..7d604bb 100644
48202--- a/drivers/platform/chrome/chromeos_laptop.c
48203+++ b/drivers/platform/chrome/chromeos_laptop.c
48204@@ -406,7 +406,7 @@ static struct chromeos_laptop cr48 = {
48205 .callback = chromeos_laptop_dmi_matched, \
48206 .driver_data = (void *)&board_
48207
48208-static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
48209+static struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
48210 {
48211 .ident = "Samsung Series 5 550",
48212 .matches = {
48213diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
48214index c5e082f..d6307a0 100644
48215--- a/drivers/platform/x86/asus-wmi.c
48216+++ b/drivers/platform/x86/asus-wmi.c
48217@@ -1595,6 +1595,10 @@ static int show_dsts(struct seq_file *m, void *data)
48218 int err;
48219 u32 retval = -1;
48220
48221+#ifdef CONFIG_GRKERNSEC_KMEM
48222+ return -EPERM;
48223+#endif
48224+
48225 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
48226
48227 if (err < 0)
48228@@ -1611,6 +1615,10 @@ static int show_devs(struct seq_file *m, void *data)
48229 int err;
48230 u32 retval = -1;
48231
48232+#ifdef CONFIG_GRKERNSEC_KMEM
48233+ return -EPERM;
48234+#endif
48235+
48236 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
48237 &retval);
48238
48239@@ -1635,6 +1643,10 @@ static int show_call(struct seq_file *m, void *data)
48240 union acpi_object *obj;
48241 acpi_status status;
48242
48243+#ifdef CONFIG_GRKERNSEC_KMEM
48244+ return -EPERM;
48245+#endif
48246+
48247 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
48248 1, asus->debug.method_id,
48249 &input, &output);
48250diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
48251index 62f8030..c7f2a45 100644
48252--- a/drivers/platform/x86/msi-laptop.c
48253+++ b/drivers/platform/x86/msi-laptop.c
48254@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
48255
48256 if (!quirks->ec_read_only) {
48257 /* allow userland write sysfs file */
48258- dev_attr_bluetooth.store = store_bluetooth;
48259- dev_attr_wlan.store = store_wlan;
48260- dev_attr_threeg.store = store_threeg;
48261- dev_attr_bluetooth.attr.mode |= S_IWUSR;
48262- dev_attr_wlan.attr.mode |= S_IWUSR;
48263- dev_attr_threeg.attr.mode |= S_IWUSR;
48264+ pax_open_kernel();
48265+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
48266+ *(void **)&dev_attr_wlan.store = store_wlan;
48267+ *(void **)&dev_attr_threeg.store = store_threeg;
48268+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
48269+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
48270+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
48271+ pax_close_kernel();
48272 }
48273
48274 /* disable hardware control by fn key */
48275diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
48276index 70222f2..8c8ce66 100644
48277--- a/drivers/platform/x86/msi-wmi.c
48278+++ b/drivers/platform/x86/msi-wmi.c
48279@@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
48280 static void msi_wmi_notify(u32 value, void *context)
48281 {
48282 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
48283- static struct key_entry *key;
48284+ struct key_entry *key;
48285 union acpi_object *obj;
48286 acpi_status status;
48287
48288diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
48289index 8f8551a..3ace3ca 100644
48290--- a/drivers/platform/x86/sony-laptop.c
48291+++ b/drivers/platform/x86/sony-laptop.c
48292@@ -2451,7 +2451,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
48293 }
48294
48295 /* High speed charging function */
48296-static struct device_attribute *hsc_handle;
48297+static device_attribute_no_const *hsc_handle;
48298
48299 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
48300 struct device_attribute *attr,
48301diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
48302index e2a91c8..986cc9f 100644
48303--- a/drivers/platform/x86/thinkpad_acpi.c
48304+++ b/drivers/platform/x86/thinkpad_acpi.c
48305@@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
48306 return 0;
48307 }
48308
48309-void static hotkey_mask_warn_incomplete_mask(void)
48310+static void hotkey_mask_warn_incomplete_mask(void)
48311 {
48312 /* log only what the user can fix... */
48313 const u32 wantedmask = hotkey_driver_mask &
48314@@ -2321,11 +2321,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
48315 }
48316 }
48317
48318-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48319- struct tp_nvram_state *newn,
48320- const u32 event_mask)
48321-{
48322-
48323 #define TPACPI_COMPARE_KEY(__scancode, __member) \
48324 do { \
48325 if ((event_mask & (1 << __scancode)) && \
48326@@ -2339,36 +2334,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48327 tpacpi_hotkey_send_key(__scancode); \
48328 } while (0)
48329
48330- void issue_volchange(const unsigned int oldvol,
48331- const unsigned int newvol)
48332- {
48333- unsigned int i = oldvol;
48334+static void issue_volchange(const unsigned int oldvol,
48335+ const unsigned int newvol,
48336+ const u32 event_mask)
48337+{
48338+ unsigned int i = oldvol;
48339
48340- while (i > newvol) {
48341- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
48342- i--;
48343- }
48344- while (i < newvol) {
48345- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
48346- i++;
48347- }
48348+ while (i > newvol) {
48349+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
48350+ i--;
48351 }
48352+ while (i < newvol) {
48353+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
48354+ i++;
48355+ }
48356+}
48357
48358- void issue_brightnesschange(const unsigned int oldbrt,
48359- const unsigned int newbrt)
48360- {
48361- unsigned int i = oldbrt;
48362+static void issue_brightnesschange(const unsigned int oldbrt,
48363+ const unsigned int newbrt,
48364+ const u32 event_mask)
48365+{
48366+ unsigned int i = oldbrt;
48367
48368- while (i > newbrt) {
48369- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
48370- i--;
48371- }
48372- while (i < newbrt) {
48373- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
48374- i++;
48375- }
48376+ while (i > newbrt) {
48377+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
48378+ i--;
48379+ }
48380+ while (i < newbrt) {
48381+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
48382+ i++;
48383 }
48384+}
48385
48386+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48387+ struct tp_nvram_state *newn,
48388+ const u32 event_mask)
48389+{
48390 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
48391 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
48392 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
48393@@ -2402,7 +2403,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48394 oldn->volume_level != newn->volume_level) {
48395 /* recently muted, or repeated mute keypress, or
48396 * multiple presses ending in mute */
48397- issue_volchange(oldn->volume_level, newn->volume_level);
48398+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
48399 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
48400 }
48401 } else {
48402@@ -2412,7 +2413,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48403 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
48404 }
48405 if (oldn->volume_level != newn->volume_level) {
48406- issue_volchange(oldn->volume_level, newn->volume_level);
48407+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
48408 } else if (oldn->volume_toggle != newn->volume_toggle) {
48409 /* repeated vol up/down keypress at end of scale ? */
48410 if (newn->volume_level == 0)
48411@@ -2425,7 +2426,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48412 /* handle brightness */
48413 if (oldn->brightness_level != newn->brightness_level) {
48414 issue_brightnesschange(oldn->brightness_level,
48415- newn->brightness_level);
48416+ newn->brightness_level,
48417+ event_mask);
48418 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
48419 /* repeated key presses that didn't change state */
48420 if (newn->brightness_level == 0)
48421@@ -2434,10 +2436,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48422 && !tp_features.bright_unkfw)
48423 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
48424 }
48425+}
48426
48427 #undef TPACPI_COMPARE_KEY
48428 #undef TPACPI_MAY_SEND_KEY
48429-}
48430
48431 /*
48432 * Polling driver
48433diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
48434index 769d265..a3a05ca 100644
48435--- a/drivers/pnp/pnpbios/bioscalls.c
48436+++ b/drivers/pnp/pnpbios/bioscalls.c
48437@@ -58,7 +58,7 @@ do { \
48438 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
48439 } while(0)
48440
48441-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
48442+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
48443 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
48444
48445 /*
48446@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
48447
48448 cpu = get_cpu();
48449 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
48450+
48451+ pax_open_kernel();
48452 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
48453+ pax_close_kernel();
48454
48455 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
48456 spin_lock_irqsave(&pnp_bios_lock, flags);
48457@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
48458 :"memory");
48459 spin_unlock_irqrestore(&pnp_bios_lock, flags);
48460
48461+ pax_open_kernel();
48462 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
48463+ pax_close_kernel();
48464+
48465 put_cpu();
48466
48467 /* If we get here and this is set then the PnP BIOS faulted on us. */
48468@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
48469 return status;
48470 }
48471
48472-void pnpbios_calls_init(union pnp_bios_install_struct *header)
48473+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
48474 {
48475 int i;
48476
48477@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
48478 pnp_bios_callpoint.offset = header->fields.pm16offset;
48479 pnp_bios_callpoint.segment = PNP_CS16;
48480
48481+ pax_open_kernel();
48482+
48483 for_each_possible_cpu(i) {
48484 struct desc_struct *gdt = get_cpu_gdt_table(i);
48485 if (!gdt)
48486@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
48487 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
48488 (unsigned long)__va(header->fields.pm16dseg));
48489 }
48490+
48491+ pax_close_kernel();
48492 }
48493diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
48494index bacddd1..65ea100 100644
48495--- a/drivers/pnp/resource.c
48496+++ b/drivers/pnp/resource.c
48497@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
48498 return 1;
48499
48500 /* check if the resource is valid */
48501- if (*irq < 0 || *irq > 15)
48502+ if (*irq > 15)
48503 return 0;
48504
48505 /* check if the resource is reserved */
48506@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
48507 return 1;
48508
48509 /* check if the resource is valid */
48510- if (*dma < 0 || *dma == 4 || *dma > 7)
48511+ if (*dma == 4 || *dma > 7)
48512 return 0;
48513
48514 /* check if the resource is reserved */
48515diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
48516index 0c52e2a..3421ab7 100644
48517--- a/drivers/power/pda_power.c
48518+++ b/drivers/power/pda_power.c
48519@@ -37,7 +37,11 @@ static int polling;
48520
48521 #if IS_ENABLED(CONFIG_USB_PHY)
48522 static struct usb_phy *transceiver;
48523-static struct notifier_block otg_nb;
48524+static int otg_handle_notification(struct notifier_block *nb,
48525+ unsigned long event, void *unused);
48526+static struct notifier_block otg_nb = {
48527+ .notifier_call = otg_handle_notification
48528+};
48529 #endif
48530
48531 static struct regulator *ac_draw;
48532@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
48533
48534 #if IS_ENABLED(CONFIG_USB_PHY)
48535 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
48536- otg_nb.notifier_call = otg_handle_notification;
48537 ret = usb_register_notifier(transceiver, &otg_nb);
48538 if (ret) {
48539 dev_err(dev, "failure to register otg notifier\n");
48540diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
48541index cc439fd..8fa30df 100644
48542--- a/drivers/power/power_supply.h
48543+++ b/drivers/power/power_supply.h
48544@@ -16,12 +16,12 @@ struct power_supply;
48545
48546 #ifdef CONFIG_SYSFS
48547
48548-extern void power_supply_init_attrs(struct device_type *dev_type);
48549+extern void power_supply_init_attrs(void);
48550 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
48551
48552 #else
48553
48554-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
48555+static inline void power_supply_init_attrs(void) {}
48556 #define power_supply_uevent NULL
48557
48558 #endif /* CONFIG_SYSFS */
48559diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
48560index 2660664..75fcb04 100644
48561--- a/drivers/power/power_supply_core.c
48562+++ b/drivers/power/power_supply_core.c
48563@@ -28,7 +28,10 @@ EXPORT_SYMBOL_GPL(power_supply_class);
48564 ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
48565 EXPORT_SYMBOL_GPL(power_supply_notifier);
48566
48567-static struct device_type power_supply_dev_type;
48568+extern const struct attribute_group *power_supply_attr_groups[];
48569+static struct device_type power_supply_dev_type = {
48570+ .groups = power_supply_attr_groups,
48571+};
48572
48573 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
48574 struct power_supply *supply)
48575@@ -628,7 +631,7 @@ static int __init power_supply_class_init(void)
48576 return PTR_ERR(power_supply_class);
48577
48578 power_supply_class->dev_uevent = power_supply_uevent;
48579- power_supply_init_attrs(&power_supply_dev_type);
48580+ power_supply_init_attrs();
48581
48582 return 0;
48583 }
48584diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
48585index 44420d1..967126e 100644
48586--- a/drivers/power/power_supply_sysfs.c
48587+++ b/drivers/power/power_supply_sysfs.c
48588@@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
48589 .is_visible = power_supply_attr_is_visible,
48590 };
48591
48592-static const struct attribute_group *power_supply_attr_groups[] = {
48593+const struct attribute_group *power_supply_attr_groups[] = {
48594 &power_supply_attr_group,
48595 NULL,
48596 };
48597
48598-void power_supply_init_attrs(struct device_type *dev_type)
48599+void power_supply_init_attrs(void)
48600 {
48601 int i;
48602
48603- dev_type->groups = power_supply_attr_groups;
48604-
48605 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
48606 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
48607 }
48608diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
48609index 84419af..268ede8 100644
48610--- a/drivers/powercap/powercap_sys.c
48611+++ b/drivers/powercap/powercap_sys.c
48612@@ -154,8 +154,77 @@ struct powercap_constraint_attr {
48613 struct device_attribute name_attr;
48614 };
48615
48616+static ssize_t show_constraint_name(struct device *dev,
48617+ struct device_attribute *dev_attr,
48618+ char *buf);
48619+
48620 static struct powercap_constraint_attr
48621- constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
48622+ constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
48623+ [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
48624+ .power_limit_attr = {
48625+ .attr = {
48626+ .name = NULL,
48627+ .mode = S_IWUSR | S_IRUGO
48628+ },
48629+ .show = show_constraint_power_limit_uw,
48630+ .store = store_constraint_power_limit_uw
48631+ },
48632+
48633+ .time_window_attr = {
48634+ .attr = {
48635+ .name = NULL,
48636+ .mode = S_IWUSR | S_IRUGO
48637+ },
48638+ .show = show_constraint_time_window_us,
48639+ .store = store_constraint_time_window_us
48640+ },
48641+
48642+ .max_power_attr = {
48643+ .attr = {
48644+ .name = NULL,
48645+ .mode = S_IRUGO
48646+ },
48647+ .show = show_constraint_max_power_uw,
48648+ .store = NULL
48649+ },
48650+
48651+ .min_power_attr = {
48652+ .attr = {
48653+ .name = NULL,
48654+ .mode = S_IRUGO
48655+ },
48656+ .show = show_constraint_min_power_uw,
48657+ .store = NULL
48658+ },
48659+
48660+ .max_time_window_attr = {
48661+ .attr = {
48662+ .name = NULL,
48663+ .mode = S_IRUGO
48664+ },
48665+ .show = show_constraint_max_time_window_us,
48666+ .store = NULL
48667+ },
48668+
48669+ .min_time_window_attr = {
48670+ .attr = {
48671+ .name = NULL,
48672+ .mode = S_IRUGO
48673+ },
48674+ .show = show_constraint_min_time_window_us,
48675+ .store = NULL
48676+ },
48677+
48678+ .name_attr = {
48679+ .attr = {
48680+ .name = NULL,
48681+ .mode = S_IRUGO
48682+ },
48683+ .show = show_constraint_name,
48684+ .store = NULL
48685+ }
48686+ }
48687+};
48688
48689 /* A list of powercap control_types */
48690 static LIST_HEAD(powercap_cntrl_list);
48691@@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
48692 }
48693
48694 static int create_constraint_attribute(int id, const char *name,
48695- int mode,
48696- struct device_attribute *dev_attr,
48697- ssize_t (*show)(struct device *,
48698- struct device_attribute *, char *),
48699- ssize_t (*store)(struct device *,
48700- struct device_attribute *,
48701- const char *, size_t)
48702- )
48703+ struct device_attribute *dev_attr)
48704 {
48705+ name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
48706
48707- dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
48708- id, name);
48709- if (!dev_attr->attr.name)
48710+ if (!name)
48711 return -ENOMEM;
48712- dev_attr->attr.mode = mode;
48713- dev_attr->show = show;
48714- dev_attr->store = store;
48715+
48716+ pax_open_kernel();
48717+ *(const char **)&dev_attr->attr.name = name;
48718+ pax_close_kernel();
48719
48720 return 0;
48721 }
48722@@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
48723
48724 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
48725 ret = create_constraint_attribute(i, "power_limit_uw",
48726- S_IWUSR | S_IRUGO,
48727- &constraint_attrs[i].power_limit_attr,
48728- show_constraint_power_limit_uw,
48729- store_constraint_power_limit_uw);
48730+ &constraint_attrs[i].power_limit_attr);
48731 if (ret)
48732 goto err_alloc;
48733 ret = create_constraint_attribute(i, "time_window_us",
48734- S_IWUSR | S_IRUGO,
48735- &constraint_attrs[i].time_window_attr,
48736- show_constraint_time_window_us,
48737- store_constraint_time_window_us);
48738+ &constraint_attrs[i].time_window_attr);
48739 if (ret)
48740 goto err_alloc;
48741- ret = create_constraint_attribute(i, "name", S_IRUGO,
48742- &constraint_attrs[i].name_attr,
48743- show_constraint_name,
48744- NULL);
48745+ ret = create_constraint_attribute(i, "name",
48746+ &constraint_attrs[i].name_attr);
48747 if (ret)
48748 goto err_alloc;
48749- ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
48750- &constraint_attrs[i].max_power_attr,
48751- show_constraint_max_power_uw,
48752- NULL);
48753+ ret = create_constraint_attribute(i, "max_power_uw",
48754+ &constraint_attrs[i].max_power_attr);
48755 if (ret)
48756 goto err_alloc;
48757- ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
48758- &constraint_attrs[i].min_power_attr,
48759- show_constraint_min_power_uw,
48760- NULL);
48761+ ret = create_constraint_attribute(i, "min_power_uw",
48762+ &constraint_attrs[i].min_power_attr);
48763 if (ret)
48764 goto err_alloc;
48765 ret = create_constraint_attribute(i, "max_time_window_us",
48766- S_IRUGO,
48767- &constraint_attrs[i].max_time_window_attr,
48768- show_constraint_max_time_window_us,
48769- NULL);
48770+ &constraint_attrs[i].max_time_window_attr);
48771 if (ret)
48772 goto err_alloc;
48773 ret = create_constraint_attribute(i, "min_time_window_us",
48774- S_IRUGO,
48775- &constraint_attrs[i].min_time_window_attr,
48776- show_constraint_min_time_window_us,
48777- NULL);
48778+ &constraint_attrs[i].min_time_window_attr);
48779 if (ret)
48780 goto err_alloc;
48781
48782@@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
48783 power_zone->zone_dev_attrs[count++] =
48784 &dev_attr_max_energy_range_uj.attr;
48785 if (power_zone->ops->get_energy_uj) {
48786+ pax_open_kernel();
48787 if (power_zone->ops->reset_energy_uj)
48788- dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48789+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48790 else
48791- dev_attr_energy_uj.attr.mode = S_IRUGO;
48792+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
48793+ pax_close_kernel();
48794 power_zone->zone_dev_attrs[count++] =
48795 &dev_attr_energy_uj.attr;
48796 }
48797diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
48798index afca1bc..86840b8 100644
48799--- a/drivers/regulator/core.c
48800+++ b/drivers/regulator/core.c
48801@@ -3366,7 +3366,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48802 {
48803 const struct regulation_constraints *constraints = NULL;
48804 const struct regulator_init_data *init_data;
48805- static atomic_t regulator_no = ATOMIC_INIT(0);
48806+ static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
48807 struct regulator_dev *rdev;
48808 struct device *dev;
48809 int ret, i;
48810@@ -3436,7 +3436,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48811 rdev->dev.of_node = config->of_node;
48812 rdev->dev.parent = dev;
48813 dev_set_name(&rdev->dev, "regulator.%d",
48814- atomic_inc_return(&regulator_no) - 1);
48815+ atomic_inc_return_unchecked(&regulator_no) - 1);
48816 ret = device_register(&rdev->dev);
48817 if (ret != 0) {
48818 put_device(&rdev->dev);
48819diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
48820index 8d94d3d..653b623 100644
48821--- a/drivers/regulator/max8660.c
48822+++ b/drivers/regulator/max8660.c
48823@@ -420,8 +420,10 @@ static int max8660_probe(struct i2c_client *client,
48824 max8660->shadow_regs[MAX8660_OVER1] = 5;
48825 } else {
48826 /* Otherwise devices can be toggled via software */
48827- max8660_dcdc_ops.enable = max8660_dcdc_enable;
48828- max8660_dcdc_ops.disable = max8660_dcdc_disable;
48829+ pax_open_kernel();
48830+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
48831+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
48832+ pax_close_kernel();
48833 }
48834
48835 /*
48836diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
48837index 892aa1e..ebd1b9c 100644
48838--- a/drivers/regulator/max8973-regulator.c
48839+++ b/drivers/regulator/max8973-regulator.c
48840@@ -406,9 +406,11 @@ static int max8973_probe(struct i2c_client *client,
48841 if (!pdata || !pdata->enable_ext_control) {
48842 max->desc.enable_reg = MAX8973_VOUT;
48843 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
48844- max->ops.enable = regulator_enable_regmap;
48845- max->ops.disable = regulator_disable_regmap;
48846- max->ops.is_enabled = regulator_is_enabled_regmap;
48847+ pax_open_kernel();
48848+ *(void **)&max->ops.enable = regulator_enable_regmap;
48849+ *(void **)&max->ops.disable = regulator_disable_regmap;
48850+ *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
48851+ pax_close_kernel();
48852 }
48853
48854 if (pdata) {
48855diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
48856index f374fa5..26f0683 100644
48857--- a/drivers/regulator/mc13892-regulator.c
48858+++ b/drivers/regulator/mc13892-regulator.c
48859@@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
48860 }
48861 mc13xxx_unlock(mc13892);
48862
48863- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48864+ pax_open_kernel();
48865+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48866 = mc13892_vcam_set_mode;
48867- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48868+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48869 = mc13892_vcam_get_mode;
48870+ pax_close_kernel();
48871
48872 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
48873 ARRAY_SIZE(mc13892_regulators));
48874diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
48875index cae212f..58a3980 100644
48876--- a/drivers/rtc/rtc-cmos.c
48877+++ b/drivers/rtc/rtc-cmos.c
48878@@ -777,7 +777,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
48879 hpet_rtc_timer_init();
48880
48881 /* export at least the first block of NVRAM */
48882- nvram.size = address_space - NVRAM_OFFSET;
48883+ pax_open_kernel();
48884+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
48885+ pax_close_kernel();
48886 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
48887 if (retval < 0) {
48888 dev_dbg(dev, "can't create nvram file? %d\n", retval);
48889diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
48890index d049393..bb20be0 100644
48891--- a/drivers/rtc/rtc-dev.c
48892+++ b/drivers/rtc/rtc-dev.c
48893@@ -16,6 +16,7 @@
48894 #include <linux/module.h>
48895 #include <linux/rtc.h>
48896 #include <linux/sched.h>
48897+#include <linux/grsecurity.h>
48898 #include "rtc-core.h"
48899
48900 static dev_t rtc_devt;
48901@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
48902 if (copy_from_user(&tm, uarg, sizeof(tm)))
48903 return -EFAULT;
48904
48905+ gr_log_timechange();
48906+
48907 return rtc_set_time(rtc, &tm);
48908
48909 case RTC_PIE_ON:
48910diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
48911index 4e75345..09f8663 100644
48912--- a/drivers/rtc/rtc-ds1307.c
48913+++ b/drivers/rtc/rtc-ds1307.c
48914@@ -107,7 +107,7 @@ struct ds1307 {
48915 u8 offset; /* register's offset */
48916 u8 regs[11];
48917 u16 nvram_offset;
48918- struct bin_attribute *nvram;
48919+ bin_attribute_no_const *nvram;
48920 enum ds_type type;
48921 unsigned long flags;
48922 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
48923diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
48924index 11880c1..b823aa4 100644
48925--- a/drivers/rtc/rtc-m48t59.c
48926+++ b/drivers/rtc/rtc-m48t59.c
48927@@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
48928 if (IS_ERR(m48t59->rtc))
48929 return PTR_ERR(m48t59->rtc);
48930
48931- m48t59_nvram_attr.size = pdata->offset;
48932+ pax_open_kernel();
48933+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
48934+ pax_close_kernel();
48935
48936 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
48937 if (ret)
48938diff --git a/drivers/scsi/aic7xxx/aic79xx_pci.c b/drivers/scsi/aic7xxx/aic79xx_pci.c
48939index 14b5f8d..cc9bd26 100644
48940--- a/drivers/scsi/aic7xxx/aic79xx_pci.c
48941+++ b/drivers/scsi/aic7xxx/aic79xx_pci.c
48942@@ -827,7 +827,7 @@ ahd_pci_intr(struct ahd_softc *ahd)
48943 for (bit = 0; bit < 8; bit++) {
48944
48945 if ((pci_status[i] & (0x1 << bit)) != 0) {
48946- static const char *s;
48947+ const char *s;
48948
48949 s = pci_status_strings[bit];
48950 if (i == 7/*TARG*/ && bit == 3)
48951@@ -887,23 +887,15 @@ ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat)
48952
48953 for (bit = 0; bit < 8; bit++) {
48954
48955- if ((split_status[i] & (0x1 << bit)) != 0) {
48956- static const char *s;
48957-
48958- s = split_status_strings[bit];
48959- printk(s, ahd_name(ahd),
48960+ if ((split_status[i] & (0x1 << bit)) != 0)
48961+ printk(split_status_strings[bit], ahd_name(ahd),
48962 split_status_source[i]);
48963- }
48964
48965 if (i > 1)
48966 continue;
48967
48968- if ((sg_split_status[i] & (0x1 << bit)) != 0) {
48969- static const char *s;
48970-
48971- s = split_status_strings[bit];
48972- printk(s, ahd_name(ahd), "SG");
48973- }
48974+ if ((sg_split_status[i] & (0x1 << bit)) != 0)
48975+ printk(split_status_strings[bit], ahd_name(ahd), "SG");
48976 }
48977 }
48978 /*
48979diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
48980index e693af6..2e525b6 100644
48981--- a/drivers/scsi/bfa/bfa_fcpim.h
48982+++ b/drivers/scsi/bfa/bfa_fcpim.h
48983@@ -36,7 +36,7 @@ struct bfa_iotag_s {
48984
48985 struct bfa_itn_s {
48986 bfa_isr_func_t isr;
48987-};
48988+} __no_const;
48989
48990 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
48991 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
48992diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
48993index a3ab5cc..8143622 100644
48994--- a/drivers/scsi/bfa/bfa_fcs.c
48995+++ b/drivers/scsi/bfa/bfa_fcs.c
48996@@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
48997 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
48998
48999 static struct bfa_fcs_mod_s fcs_modules[] = {
49000- { bfa_fcs_port_attach, NULL, NULL },
49001- { bfa_fcs_uf_attach, NULL, NULL },
49002- { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
49003- bfa_fcs_fabric_modexit },
49004+ {
49005+ .attach = bfa_fcs_port_attach,
49006+ .modinit = NULL,
49007+ .modexit = NULL
49008+ },
49009+ {
49010+ .attach = bfa_fcs_uf_attach,
49011+ .modinit = NULL,
49012+ .modexit = NULL
49013+ },
49014+ {
49015+ .attach = bfa_fcs_fabric_attach,
49016+ .modinit = bfa_fcs_fabric_modinit,
49017+ .modexit = bfa_fcs_fabric_modexit
49018+ },
49019 };
49020
49021 /*
49022diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
49023index ff75ef8..2dfe00a 100644
49024--- a/drivers/scsi/bfa/bfa_fcs_lport.c
49025+++ b/drivers/scsi/bfa/bfa_fcs_lport.c
49026@@ -89,15 +89,26 @@ static struct {
49027 void (*offline) (struct bfa_fcs_lport_s *port);
49028 } __port_action[] = {
49029 {
49030- bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
49031- bfa_fcs_lport_unknown_offline}, {
49032- bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
49033- bfa_fcs_lport_fab_offline}, {
49034- bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
49035- bfa_fcs_lport_n2n_offline}, {
49036- bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
49037- bfa_fcs_lport_loop_offline},
49038- };
49039+ .init = bfa_fcs_lport_unknown_init,
49040+ .online = bfa_fcs_lport_unknown_online,
49041+ .offline = bfa_fcs_lport_unknown_offline
49042+ },
49043+ {
49044+ .init = bfa_fcs_lport_fab_init,
49045+ .online = bfa_fcs_lport_fab_online,
49046+ .offline = bfa_fcs_lport_fab_offline
49047+ },
49048+ {
49049+ .init = bfa_fcs_lport_n2n_init,
49050+ .online = bfa_fcs_lport_n2n_online,
49051+ .offline = bfa_fcs_lport_n2n_offline
49052+ },
49053+ {
49054+ .init = bfa_fcs_lport_loop_init,
49055+ .online = bfa_fcs_lport_loop_online,
49056+ .offline = bfa_fcs_lport_loop_offline
49057+ },
49058+};
49059
49060 /*
49061 * fcs_port_sm FCS logical port state machine
49062diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
49063index 2e28392..9d865b6 100644
49064--- a/drivers/scsi/bfa/bfa_ioc.h
49065+++ b/drivers/scsi/bfa/bfa_ioc.h
49066@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
49067 bfa_ioc_disable_cbfn_t disable_cbfn;
49068 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
49069 bfa_ioc_reset_cbfn_t reset_cbfn;
49070-};
49071+} __no_const;
49072
49073 /*
49074 * IOC event notification mechanism.
49075@@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
49076 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
49077 enum bfi_ioc_state fwstate);
49078 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
49079-};
49080+} __no_const;
49081
49082 /*
49083 * Queue element to wait for room in request queue. FIFO order is
49084diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
49085index a14c784..6de6790 100644
49086--- a/drivers/scsi/bfa/bfa_modules.h
49087+++ b/drivers/scsi/bfa/bfa_modules.h
49088@@ -78,12 +78,12 @@ enum {
49089 \
49090 extern struct bfa_module_s hal_mod_ ## __mod; \
49091 struct bfa_module_s hal_mod_ ## __mod = { \
49092- bfa_ ## __mod ## _meminfo, \
49093- bfa_ ## __mod ## _attach, \
49094- bfa_ ## __mod ## _detach, \
49095- bfa_ ## __mod ## _start, \
49096- bfa_ ## __mod ## _stop, \
49097- bfa_ ## __mod ## _iocdisable, \
49098+ .meminfo = bfa_ ## __mod ## _meminfo, \
49099+ .attach = bfa_ ## __mod ## _attach, \
49100+ .detach = bfa_ ## __mod ## _detach, \
49101+ .start = bfa_ ## __mod ## _start, \
49102+ .stop = bfa_ ## __mod ## _stop, \
49103+ .iocdisable = bfa_ ## __mod ## _iocdisable, \
49104 }
49105
49106 #define BFA_CACHELINE_SZ (256)
49107diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
49108index 045c4e1..13de803 100644
49109--- a/drivers/scsi/fcoe/fcoe_sysfs.c
49110+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
49111@@ -33,8 +33,8 @@
49112 */
49113 #include "libfcoe.h"
49114
49115-static atomic_t ctlr_num;
49116-static atomic_t fcf_num;
49117+static atomic_unchecked_t ctlr_num;
49118+static atomic_unchecked_t fcf_num;
49119
49120 /*
49121 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
49122@@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
49123 if (!ctlr)
49124 goto out;
49125
49126- ctlr->id = atomic_inc_return(&ctlr_num) - 1;
49127+ ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
49128 ctlr->f = f;
49129 ctlr->mode = FIP_CONN_TYPE_FABRIC;
49130 INIT_LIST_HEAD(&ctlr->fcfs);
49131@@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
49132 fcf->dev.parent = &ctlr->dev;
49133 fcf->dev.bus = &fcoe_bus_type;
49134 fcf->dev.type = &fcoe_fcf_device_type;
49135- fcf->id = atomic_inc_return(&fcf_num) - 1;
49136+ fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
49137 fcf->state = FCOE_FCF_STATE_UNKNOWN;
49138
49139 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
49140@@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
49141 {
49142 int error;
49143
49144- atomic_set(&ctlr_num, 0);
49145- atomic_set(&fcf_num, 0);
49146+ atomic_set_unchecked(&ctlr_num, 0);
49147+ atomic_set_unchecked(&fcf_num, 0);
49148
49149 error = bus_register(&fcoe_bus_type);
49150 if (error)
49151diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
49152index f28ea07..34b16d3 100644
49153--- a/drivers/scsi/hosts.c
49154+++ b/drivers/scsi/hosts.c
49155@@ -42,7 +42,7 @@
49156 #include "scsi_logging.h"
49157
49158
49159-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
49160+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
49161
49162
49163 static void scsi_host_cls_release(struct device *dev)
49164@@ -369,7 +369,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
49165 * subtract one because we increment first then return, but we need to
49166 * know what the next host number was before increment
49167 */
49168- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
49169+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
49170 shost->dma_channel = 0xff;
49171
49172 /* These three are default values which can be overridden */
49173diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
49174index 868318a..e07ef3b 100644
49175--- a/drivers/scsi/hpsa.c
49176+++ b/drivers/scsi/hpsa.c
49177@@ -571,7 +571,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
49178 unsigned long flags;
49179
49180 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
49181- return h->access.command_completed(h, q);
49182+ return h->access->command_completed(h, q);
49183
49184 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
49185 a = rq->head[rq->current_entry];
49186@@ -3474,7 +3474,7 @@ static void start_io(struct ctlr_info *h)
49187 while (!list_empty(&h->reqQ)) {
49188 c = list_entry(h->reqQ.next, struct CommandList, list);
49189 /* can't do anything if fifo is full */
49190- if ((h->access.fifo_full(h))) {
49191+ if ((h->access->fifo_full(h))) {
49192 h->fifo_recently_full = 1;
49193 dev_warn(&h->pdev->dev, "fifo full\n");
49194 break;
49195@@ -3498,7 +3498,7 @@ static void start_io(struct ctlr_info *h)
49196
49197 /* Tell the controller execute command */
49198 spin_unlock_irqrestore(&h->lock, flags);
49199- h->access.submit_command(h, c);
49200+ h->access->submit_command(h, c);
49201 spin_lock_irqsave(&h->lock, flags);
49202 }
49203 spin_unlock_irqrestore(&h->lock, flags);
49204@@ -3506,17 +3506,17 @@ static void start_io(struct ctlr_info *h)
49205
49206 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
49207 {
49208- return h->access.command_completed(h, q);
49209+ return h->access->command_completed(h, q);
49210 }
49211
49212 static inline bool interrupt_pending(struct ctlr_info *h)
49213 {
49214- return h->access.intr_pending(h);
49215+ return h->access->intr_pending(h);
49216 }
49217
49218 static inline long interrupt_not_for_us(struct ctlr_info *h)
49219 {
49220- return (h->access.intr_pending(h) == 0) ||
49221+ return (h->access->intr_pending(h) == 0) ||
49222 (h->interrupts_enabled == 0);
49223 }
49224
49225@@ -4442,7 +4442,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
49226 if (prod_index < 0)
49227 return -ENODEV;
49228 h->product_name = products[prod_index].product_name;
49229- h->access = *(products[prod_index].access);
49230+ h->access = products[prod_index].access;
49231
49232 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
49233 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
49234@@ -4712,7 +4712,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
49235 {
49236 unsigned long flags;
49237
49238- h->access.set_intr_mask(h, HPSA_INTR_OFF);
49239+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
49240 spin_lock_irqsave(&h->lock, flags);
49241 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
49242 spin_unlock_irqrestore(&h->lock, flags);
49243@@ -4843,7 +4843,7 @@ reinit_after_soft_reset:
49244 }
49245
49246 /* make sure the board interrupts are off */
49247- h->access.set_intr_mask(h, HPSA_INTR_OFF);
49248+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
49249
49250 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
49251 goto clean2;
49252@@ -4877,7 +4877,7 @@ reinit_after_soft_reset:
49253 * fake ones to scoop up any residual completions.
49254 */
49255 spin_lock_irqsave(&h->lock, flags);
49256- h->access.set_intr_mask(h, HPSA_INTR_OFF);
49257+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
49258 spin_unlock_irqrestore(&h->lock, flags);
49259 free_irqs(h);
49260 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
49261@@ -4896,9 +4896,9 @@ reinit_after_soft_reset:
49262 dev_info(&h->pdev->dev, "Board READY.\n");
49263 dev_info(&h->pdev->dev,
49264 "Waiting for stale completions to drain.\n");
49265- h->access.set_intr_mask(h, HPSA_INTR_ON);
49266+ h->access->set_intr_mask(h, HPSA_INTR_ON);
49267 msleep(10000);
49268- h->access.set_intr_mask(h, HPSA_INTR_OFF);
49269+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
49270
49271 rc = controller_reset_failed(h->cfgtable);
49272 if (rc)
49273@@ -4919,7 +4919,7 @@ reinit_after_soft_reset:
49274 }
49275
49276 /* Turn the interrupts on so we can service requests */
49277- h->access.set_intr_mask(h, HPSA_INTR_ON);
49278+ h->access->set_intr_mask(h, HPSA_INTR_ON);
49279
49280 hpsa_hba_inquiry(h);
49281 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
49282@@ -4988,7 +4988,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
49283 * To write all data in the battery backed cache to disks
49284 */
49285 hpsa_flush_cache(h);
49286- h->access.set_intr_mask(h, HPSA_INTR_OFF);
49287+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
49288 hpsa_free_irqs_and_disable_msix(h);
49289 }
49290
49291@@ -5162,7 +5162,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
49292 return;
49293 }
49294 /* Change the access methods to the performant access methods */
49295- h->access = SA5_performant_access;
49296+ h->access = &SA5_performant_access;
49297 h->transMethod = CFGTBL_Trans_Performant;
49298 }
49299
49300diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
49301index 01c3283..4655219 100644
49302--- a/drivers/scsi/hpsa.h
49303+++ b/drivers/scsi/hpsa.h
49304@@ -79,7 +79,7 @@ struct ctlr_info {
49305 unsigned int msix_vector;
49306 unsigned int msi_vector;
49307 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
49308- struct access_method access;
49309+ struct access_method *access;
49310
49311 /* queue and queue Info */
49312 struct list_head reqQ;
49313@@ -388,19 +388,19 @@ static bool SA5_performant_intr_pending(struct ctlr_info *h)
49314 }
49315
49316 static struct access_method SA5_access = {
49317- SA5_submit_command,
49318- SA5_intr_mask,
49319- SA5_fifo_full,
49320- SA5_intr_pending,
49321- SA5_completed,
49322+ .submit_command = SA5_submit_command,
49323+ .set_intr_mask = SA5_intr_mask,
49324+ .fifo_full = SA5_fifo_full,
49325+ .intr_pending = SA5_intr_pending,
49326+ .command_completed = SA5_completed,
49327 };
49328
49329 static struct access_method SA5_performant_access = {
49330- SA5_submit_command,
49331- SA5_performant_intr_mask,
49332- SA5_fifo_full,
49333- SA5_performant_intr_pending,
49334- SA5_performant_completed,
49335+ .submit_command = SA5_submit_command,
49336+ .set_intr_mask = SA5_performant_intr_mask,
49337+ .fifo_full = SA5_fifo_full,
49338+ .intr_pending = SA5_performant_intr_pending,
49339+ .command_completed = SA5_performant_completed,
49340 };
49341
49342 struct board_type {
49343diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
49344index 1b3a094..068e683 100644
49345--- a/drivers/scsi/libfc/fc_exch.c
49346+++ b/drivers/scsi/libfc/fc_exch.c
49347@@ -101,12 +101,12 @@ struct fc_exch_mgr {
49348 u16 pool_max_index;
49349
49350 struct {
49351- atomic_t no_free_exch;
49352- atomic_t no_free_exch_xid;
49353- atomic_t xid_not_found;
49354- atomic_t xid_busy;
49355- atomic_t seq_not_found;
49356- atomic_t non_bls_resp;
49357+ atomic_unchecked_t no_free_exch;
49358+ atomic_unchecked_t no_free_exch_xid;
49359+ atomic_unchecked_t xid_not_found;
49360+ atomic_unchecked_t xid_busy;
49361+ atomic_unchecked_t seq_not_found;
49362+ atomic_unchecked_t non_bls_resp;
49363 } stats;
49364 };
49365
49366@@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
49367 /* allocate memory for exchange */
49368 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
49369 if (!ep) {
49370- atomic_inc(&mp->stats.no_free_exch);
49371+ atomic_inc_unchecked(&mp->stats.no_free_exch);
49372 goto out;
49373 }
49374 memset(ep, 0, sizeof(*ep));
49375@@ -874,7 +874,7 @@ out:
49376 return ep;
49377 err:
49378 spin_unlock_bh(&pool->lock);
49379- atomic_inc(&mp->stats.no_free_exch_xid);
49380+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
49381 mempool_free(ep, mp->ep_pool);
49382 return NULL;
49383 }
49384@@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49385 xid = ntohs(fh->fh_ox_id); /* we originated exch */
49386 ep = fc_exch_find(mp, xid);
49387 if (!ep) {
49388- atomic_inc(&mp->stats.xid_not_found);
49389+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49390 reject = FC_RJT_OX_ID;
49391 goto out;
49392 }
49393@@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49394 ep = fc_exch_find(mp, xid);
49395 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
49396 if (ep) {
49397- atomic_inc(&mp->stats.xid_busy);
49398+ atomic_inc_unchecked(&mp->stats.xid_busy);
49399 reject = FC_RJT_RX_ID;
49400 goto rel;
49401 }
49402@@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49403 }
49404 xid = ep->xid; /* get our XID */
49405 } else if (!ep) {
49406- atomic_inc(&mp->stats.xid_not_found);
49407+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49408 reject = FC_RJT_RX_ID; /* XID not found */
49409 goto out;
49410 }
49411@@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49412 } else {
49413 sp = &ep->seq;
49414 if (sp->id != fh->fh_seq_id) {
49415- atomic_inc(&mp->stats.seq_not_found);
49416+ atomic_inc_unchecked(&mp->stats.seq_not_found);
49417 if (f_ctl & FC_FC_END_SEQ) {
49418 /*
49419 * Update sequence_id based on incoming last
49420@@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49421
49422 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
49423 if (!ep) {
49424- atomic_inc(&mp->stats.xid_not_found);
49425+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49426 goto out;
49427 }
49428 if (ep->esb_stat & ESB_ST_COMPLETE) {
49429- atomic_inc(&mp->stats.xid_not_found);
49430+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49431 goto rel;
49432 }
49433 if (ep->rxid == FC_XID_UNKNOWN)
49434 ep->rxid = ntohs(fh->fh_rx_id);
49435 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
49436- atomic_inc(&mp->stats.xid_not_found);
49437+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49438 goto rel;
49439 }
49440 if (ep->did != ntoh24(fh->fh_s_id) &&
49441 ep->did != FC_FID_FLOGI) {
49442- atomic_inc(&mp->stats.xid_not_found);
49443+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49444 goto rel;
49445 }
49446 sof = fr_sof(fp);
49447@@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49448 sp->ssb_stat |= SSB_ST_RESP;
49449 sp->id = fh->fh_seq_id;
49450 } else if (sp->id != fh->fh_seq_id) {
49451- atomic_inc(&mp->stats.seq_not_found);
49452+ atomic_inc_unchecked(&mp->stats.seq_not_found);
49453 goto rel;
49454 }
49455
49456@@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49457 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
49458
49459 if (!sp)
49460- atomic_inc(&mp->stats.xid_not_found);
49461+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49462 else
49463- atomic_inc(&mp->stats.non_bls_resp);
49464+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
49465
49466 fc_frame_free(fp);
49467 }
49468@@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
49469
49470 list_for_each_entry(ema, &lport->ema_list, ema_list) {
49471 mp = ema->mp;
49472- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
49473+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
49474 st->fc_no_free_exch_xid +=
49475- atomic_read(&mp->stats.no_free_exch_xid);
49476- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
49477- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
49478- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
49479- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
49480+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
49481+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
49482+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
49483+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
49484+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
49485 }
49486 }
49487 EXPORT_SYMBOL(fc_exch_update_stats);
49488diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
49489index d289583..b745eec 100644
49490--- a/drivers/scsi/libsas/sas_ata.c
49491+++ b/drivers/scsi/libsas/sas_ata.c
49492@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
49493 .postreset = ata_std_postreset,
49494 .error_handler = ata_std_error_handler,
49495 .post_internal_cmd = sas_ata_post_internal,
49496- .qc_defer = ata_std_qc_defer,
49497+ .qc_defer = ata_std_qc_defer,
49498 .qc_prep = ata_noop_qc_prep,
49499 .qc_issue = sas_ata_qc_issue,
49500 .qc_fill_rtf = sas_ata_qc_fill_rtf,
49501diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
49502index 4e1b75c..0bbdfa9 100644
49503--- a/drivers/scsi/lpfc/lpfc.h
49504+++ b/drivers/scsi/lpfc/lpfc.h
49505@@ -432,7 +432,7 @@ struct lpfc_vport {
49506 struct dentry *debug_nodelist;
49507 struct dentry *vport_debugfs_root;
49508 struct lpfc_debugfs_trc *disc_trc;
49509- atomic_t disc_trc_cnt;
49510+ atomic_unchecked_t disc_trc_cnt;
49511 #endif
49512 uint8_t stat_data_enabled;
49513 uint8_t stat_data_blocked;
49514@@ -865,8 +865,8 @@ struct lpfc_hba {
49515 struct timer_list fabric_block_timer;
49516 unsigned long bit_flags;
49517 #define FABRIC_COMANDS_BLOCKED 0
49518- atomic_t num_rsrc_err;
49519- atomic_t num_cmd_success;
49520+ atomic_unchecked_t num_rsrc_err;
49521+ atomic_unchecked_t num_cmd_success;
49522 unsigned long last_rsrc_error_time;
49523 unsigned long last_ramp_down_time;
49524 unsigned long last_ramp_up_time;
49525@@ -902,7 +902,7 @@ struct lpfc_hba {
49526
49527 struct dentry *debug_slow_ring_trc;
49528 struct lpfc_debugfs_trc *slow_ring_trc;
49529- atomic_t slow_ring_trc_cnt;
49530+ atomic_unchecked_t slow_ring_trc_cnt;
49531 /* iDiag debugfs sub-directory */
49532 struct dentry *idiag_root;
49533 struct dentry *idiag_pci_cfg;
49534diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
49535index b800cc9..16b6a91 100644
49536--- a/drivers/scsi/lpfc/lpfc_debugfs.c
49537+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
49538@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
49539
49540 #include <linux/debugfs.h>
49541
49542-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
49543+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
49544 static unsigned long lpfc_debugfs_start_time = 0L;
49545
49546 /* iDiag */
49547@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
49548 lpfc_debugfs_enable = 0;
49549
49550 len = 0;
49551- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
49552+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
49553 (lpfc_debugfs_max_disc_trc - 1);
49554 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
49555 dtp = vport->disc_trc + i;
49556@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
49557 lpfc_debugfs_enable = 0;
49558
49559 len = 0;
49560- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
49561+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
49562 (lpfc_debugfs_max_slow_ring_trc - 1);
49563 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
49564 dtp = phba->slow_ring_trc + i;
49565@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
49566 !vport || !vport->disc_trc)
49567 return;
49568
49569- index = atomic_inc_return(&vport->disc_trc_cnt) &
49570+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
49571 (lpfc_debugfs_max_disc_trc - 1);
49572 dtp = vport->disc_trc + index;
49573 dtp->fmt = fmt;
49574 dtp->data1 = data1;
49575 dtp->data2 = data2;
49576 dtp->data3 = data3;
49577- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
49578+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
49579 dtp->jif = jiffies;
49580 #endif
49581 return;
49582@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
49583 !phba || !phba->slow_ring_trc)
49584 return;
49585
49586- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
49587+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
49588 (lpfc_debugfs_max_slow_ring_trc - 1);
49589 dtp = phba->slow_ring_trc + index;
49590 dtp->fmt = fmt;
49591 dtp->data1 = data1;
49592 dtp->data2 = data2;
49593 dtp->data3 = data3;
49594- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
49595+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
49596 dtp->jif = jiffies;
49597 #endif
49598 return;
49599@@ -4168,7 +4168,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49600 "slow_ring buffer\n");
49601 goto debug_failed;
49602 }
49603- atomic_set(&phba->slow_ring_trc_cnt, 0);
49604+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
49605 memset(phba->slow_ring_trc, 0,
49606 (sizeof(struct lpfc_debugfs_trc) *
49607 lpfc_debugfs_max_slow_ring_trc));
49608@@ -4214,7 +4214,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49609 "buffer\n");
49610 goto debug_failed;
49611 }
49612- atomic_set(&vport->disc_trc_cnt, 0);
49613+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
49614
49615 snprintf(name, sizeof(name), "discovery_trace");
49616 vport->debug_disc_trc =
49617diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
49618index 68c94cc..8c27be5 100644
49619--- a/drivers/scsi/lpfc/lpfc_init.c
49620+++ b/drivers/scsi/lpfc/lpfc_init.c
49621@@ -10949,8 +10949,10 @@ lpfc_init(void)
49622 "misc_register returned with status %d", error);
49623
49624 if (lpfc_enable_npiv) {
49625- lpfc_transport_functions.vport_create = lpfc_vport_create;
49626- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49627+ pax_open_kernel();
49628+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
49629+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49630+ pax_close_kernel();
49631 }
49632 lpfc_transport_template =
49633 fc_attach_transport(&lpfc_transport_functions);
49634diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
49635index b2ede05..aaf482ca 100644
49636--- a/drivers/scsi/lpfc/lpfc_scsi.c
49637+++ b/drivers/scsi/lpfc/lpfc_scsi.c
49638@@ -353,7 +353,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
49639 uint32_t evt_posted;
49640
49641 spin_lock_irqsave(&phba->hbalock, flags);
49642- atomic_inc(&phba->num_rsrc_err);
49643+ atomic_inc_unchecked(&phba->num_rsrc_err);
49644 phba->last_rsrc_error_time = jiffies;
49645
49646 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
49647@@ -394,7 +394,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
49648 unsigned long flags;
49649 struct lpfc_hba *phba = vport->phba;
49650 uint32_t evt_posted;
49651- atomic_inc(&phba->num_cmd_success);
49652+ atomic_inc_unchecked(&phba->num_cmd_success);
49653
49654 if (vport->cfg_lun_queue_depth <= queue_depth)
49655 return;
49656@@ -438,8 +438,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49657 unsigned long num_rsrc_err, num_cmd_success;
49658 int i;
49659
49660- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
49661- num_cmd_success = atomic_read(&phba->num_cmd_success);
49662+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
49663+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
49664
49665 /*
49666 * The error and success command counters are global per
49667@@ -467,8 +467,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49668 }
49669 }
49670 lpfc_destroy_vport_work_array(phba, vports);
49671- atomic_set(&phba->num_rsrc_err, 0);
49672- atomic_set(&phba->num_cmd_success, 0);
49673+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
49674+ atomic_set_unchecked(&phba->num_cmd_success, 0);
49675 }
49676
49677 /**
49678@@ -502,8 +502,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
49679 }
49680 }
49681 lpfc_destroy_vport_work_array(phba, vports);
49682- atomic_set(&phba->num_rsrc_err, 0);
49683- atomic_set(&phba->num_cmd_success, 0);
49684+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
49685+ atomic_set_unchecked(&phba->num_cmd_success, 0);
49686 }
49687
49688 /**
49689diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49690index 6fd7d40..b444223 100644
49691--- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49692+++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49693@@ -1557,7 +1557,7 @@ _scsih_get_resync(struct device *dev)
49694 {
49695 struct scsi_device *sdev = to_scsi_device(dev);
49696 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49697- static struct _raid_device *raid_device;
49698+ struct _raid_device *raid_device;
49699 unsigned long flags;
49700 Mpi2RaidVolPage0_t vol_pg0;
49701 Mpi2ConfigReply_t mpi_reply;
49702@@ -1609,7 +1609,7 @@ _scsih_get_state(struct device *dev)
49703 {
49704 struct scsi_device *sdev = to_scsi_device(dev);
49705 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49706- static struct _raid_device *raid_device;
49707+ struct _raid_device *raid_device;
49708 unsigned long flags;
49709 Mpi2RaidVolPage0_t vol_pg0;
49710 Mpi2ConfigReply_t mpi_reply;
49711@@ -6637,7 +6637,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
49712 struct fw_event_work *fw_event)
49713 {
49714 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
49715- static struct _raid_device *raid_device;
49716+ struct _raid_device *raid_device;
49717 unsigned long flags;
49718 u16 handle;
49719
49720@@ -7108,7 +7108,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
49721 u64 sas_address;
49722 struct _sas_device *sas_device;
49723 struct _sas_node *expander_device;
49724- static struct _raid_device *raid_device;
49725+ struct _raid_device *raid_device;
49726 u8 retry_count;
49727 unsigned long flags;
49728
49729diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
49730index be8ce54..94ed33a 100644
49731--- a/drivers/scsi/pmcraid.c
49732+++ b/drivers/scsi/pmcraid.c
49733@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
49734 res->scsi_dev = scsi_dev;
49735 scsi_dev->hostdata = res;
49736 res->change_detected = 0;
49737- atomic_set(&res->read_failures, 0);
49738- atomic_set(&res->write_failures, 0);
49739+ atomic_set_unchecked(&res->read_failures, 0);
49740+ atomic_set_unchecked(&res->write_failures, 0);
49741 rc = 0;
49742 }
49743 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
49744@@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
49745
49746 /* If this was a SCSI read/write command keep count of errors */
49747 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
49748- atomic_inc(&res->read_failures);
49749+ atomic_inc_unchecked(&res->read_failures);
49750 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
49751- atomic_inc(&res->write_failures);
49752+ atomic_inc_unchecked(&res->write_failures);
49753
49754 if (!RES_IS_GSCSI(res->cfg_entry) &&
49755 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
49756@@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
49757 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49758 * hrrq_id assigned here in queuecommand
49759 */
49760- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49761+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49762 pinstance->num_hrrq;
49763 cmd->cmd_done = pmcraid_io_done;
49764
49765@@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
49766 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49767 * hrrq_id assigned here in queuecommand
49768 */
49769- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49770+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49771 pinstance->num_hrrq;
49772
49773 if (request_size) {
49774@@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
49775
49776 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
49777 /* add resources only after host is added into system */
49778- if (!atomic_read(&pinstance->expose_resources))
49779+ if (!atomic_read_unchecked(&pinstance->expose_resources))
49780 return;
49781
49782 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
49783@@ -5322,8 +5322,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
49784 init_waitqueue_head(&pinstance->reset_wait_q);
49785
49786 atomic_set(&pinstance->outstanding_cmds, 0);
49787- atomic_set(&pinstance->last_message_id, 0);
49788- atomic_set(&pinstance->expose_resources, 0);
49789+ atomic_set_unchecked(&pinstance->last_message_id, 0);
49790+ atomic_set_unchecked(&pinstance->expose_resources, 0);
49791
49792 INIT_LIST_HEAD(&pinstance->free_res_q);
49793 INIT_LIST_HEAD(&pinstance->used_res_q);
49794@@ -6036,7 +6036,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
49795 /* Schedule worker thread to handle CCN and take care of adding and
49796 * removing devices to OS
49797 */
49798- atomic_set(&pinstance->expose_resources, 1);
49799+ atomic_set_unchecked(&pinstance->expose_resources, 1);
49800 schedule_work(&pinstance->worker_q);
49801 return rc;
49802
49803diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
49804index e1d150f..6c6df44 100644
49805--- a/drivers/scsi/pmcraid.h
49806+++ b/drivers/scsi/pmcraid.h
49807@@ -748,7 +748,7 @@ struct pmcraid_instance {
49808 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
49809
49810 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
49811- atomic_t last_message_id;
49812+ atomic_unchecked_t last_message_id;
49813
49814 /* configuration table */
49815 struct pmcraid_config_table *cfg_table;
49816@@ -777,7 +777,7 @@ struct pmcraid_instance {
49817 atomic_t outstanding_cmds;
49818
49819 /* should add/delete resources to mid-layer now ?*/
49820- atomic_t expose_resources;
49821+ atomic_unchecked_t expose_resources;
49822
49823
49824
49825@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
49826 struct pmcraid_config_table_entry_ext cfg_entry_ext;
49827 };
49828 struct scsi_device *scsi_dev; /* Link scsi_device structure */
49829- atomic_t read_failures; /* count of failed READ commands */
49830- atomic_t write_failures; /* count of failed WRITE commands */
49831+ atomic_unchecked_t read_failures; /* count of failed READ commands */
49832+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
49833
49834 /* To indicate add/delete/modify during CCN */
49835 u8 change_detected;
49836diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
49837index 4a0d7c9..3d658d7 100644
49838--- a/drivers/scsi/qla2xxx/qla_attr.c
49839+++ b/drivers/scsi/qla2xxx/qla_attr.c
49840@@ -2038,7 +2038,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
49841 return 0;
49842 }
49843
49844-struct fc_function_template qla2xxx_transport_functions = {
49845+fc_function_template_no_const qla2xxx_transport_functions = {
49846
49847 .show_host_node_name = 1,
49848 .show_host_port_name = 1,
49849@@ -2086,7 +2086,7 @@ struct fc_function_template qla2xxx_transport_functions = {
49850 .bsg_timeout = qla24xx_bsg_timeout,
49851 };
49852
49853-struct fc_function_template qla2xxx_transport_vport_functions = {
49854+fc_function_template_no_const qla2xxx_transport_vport_functions = {
49855
49856 .show_host_node_name = 1,
49857 .show_host_port_name = 1,
49858diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
49859index 1f42662..bf9836c 100644
49860--- a/drivers/scsi/qla2xxx/qla_gbl.h
49861+++ b/drivers/scsi/qla2xxx/qla_gbl.h
49862@@ -546,8 +546,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
49863 struct device_attribute;
49864 extern struct device_attribute *qla2x00_host_attrs[];
49865 struct fc_function_template;
49866-extern struct fc_function_template qla2xxx_transport_functions;
49867-extern struct fc_function_template qla2xxx_transport_vport_functions;
49868+extern fc_function_template_no_const qla2xxx_transport_functions;
49869+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
49870 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
49871 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *, bool);
49872 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
49873diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
49874index 83cb612..9b7b08c 100644
49875--- a/drivers/scsi/qla2xxx/qla_os.c
49876+++ b/drivers/scsi/qla2xxx/qla_os.c
49877@@ -1491,8 +1491,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
49878 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
49879 /* Ok, a 64bit DMA mask is applicable. */
49880 ha->flags.enable_64bit_addressing = 1;
49881- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49882- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49883+ pax_open_kernel();
49884+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49885+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49886+ pax_close_kernel();
49887 return;
49888 }
49889 }
49890diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
49891index aa67bb9..06d0e2a 100644
49892--- a/drivers/scsi/qla4xxx/ql4_def.h
49893+++ b/drivers/scsi/qla4xxx/ql4_def.h
49894@@ -303,7 +303,7 @@ struct ddb_entry {
49895 * (4000 only) */
49896 atomic_t relogin_timer; /* Max Time to wait for
49897 * relogin to complete */
49898- atomic_t relogin_retry_count; /* Num of times relogin has been
49899+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
49900 * retried */
49901 uint32_t default_time2wait; /* Default Min time between
49902 * relogins (+aens) */
49903diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
49904index c21adc3..1b4155f 100644
49905--- a/drivers/scsi/qla4xxx/ql4_os.c
49906+++ b/drivers/scsi/qla4xxx/ql4_os.c
49907@@ -4463,12 +4463,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
49908 */
49909 if (!iscsi_is_session_online(cls_sess)) {
49910 /* Reset retry relogin timer */
49911- atomic_inc(&ddb_entry->relogin_retry_count);
49912+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
49913 DEBUG2(ql4_printk(KERN_INFO, ha,
49914 "%s: index[%d] relogin timed out-retrying"
49915 " relogin (%d), retry (%d)\n", __func__,
49916 ddb_entry->fw_ddb_index,
49917- atomic_read(&ddb_entry->relogin_retry_count),
49918+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
49919 ddb_entry->default_time2wait + 4));
49920 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
49921 atomic_set(&ddb_entry->retry_relogin_timer,
49922@@ -6552,7 +6552,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
49923
49924 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
49925 atomic_set(&ddb_entry->relogin_timer, 0);
49926- atomic_set(&ddb_entry->relogin_retry_count, 0);
49927+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
49928 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
49929 ddb_entry->default_relogin_timeout =
49930 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
49931diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
49932index d8afec8..3ec7152 100644
49933--- a/drivers/scsi/scsi.c
49934+++ b/drivers/scsi/scsi.c
49935@@ -658,7 +658,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
49936 struct Scsi_Host *host = cmd->device->host;
49937 int rtn = 0;
49938
49939- atomic_inc(&cmd->device->iorequest_cnt);
49940+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
49941
49942 /* check if the device is still usable */
49943 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
49944diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
49945index 62ec84b..93159d8 100644
49946--- a/drivers/scsi/scsi_lib.c
49947+++ b/drivers/scsi/scsi_lib.c
49948@@ -1474,7 +1474,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
49949 shost = sdev->host;
49950 scsi_init_cmd_errh(cmd);
49951 cmd->result = DID_NO_CONNECT << 16;
49952- atomic_inc(&cmd->device->iorequest_cnt);
49953+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
49954
49955 /*
49956 * SCSI request completion path will do scsi_device_unbusy(),
49957@@ -1500,9 +1500,9 @@ static void scsi_softirq_done(struct request *rq)
49958
49959 INIT_LIST_HEAD(&cmd->eh_entry);
49960
49961- atomic_inc(&cmd->device->iodone_cnt);
49962+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
49963 if (cmd->result)
49964- atomic_inc(&cmd->device->ioerr_cnt);
49965+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
49966
49967 disposition = scsi_decide_disposition(cmd);
49968 if (disposition != SUCCESS &&
49969diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
49970index 9117d0b..d289a7a 100644
49971--- a/drivers/scsi/scsi_sysfs.c
49972+++ b/drivers/scsi/scsi_sysfs.c
49973@@ -739,7 +739,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
49974 char *buf) \
49975 { \
49976 struct scsi_device *sdev = to_scsi_device(dev); \
49977- unsigned long long count = atomic_read(&sdev->field); \
49978+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
49979 return snprintf(buf, 20, "0x%llx\n", count); \
49980 } \
49981 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
49982diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
49983index 84a1fdf..693b0d6 100644
49984--- a/drivers/scsi/scsi_tgt_lib.c
49985+++ b/drivers/scsi/scsi_tgt_lib.c
49986@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
49987 int err;
49988
49989 dprintk("%lx %u\n", uaddr, len);
49990- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
49991+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
49992 if (err) {
49993 /*
49994 * TODO: need to fixup sg_tablesize, max_segment_size,
49995diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
49996index 4628fd5..a94a1c2 100644
49997--- a/drivers/scsi/scsi_transport_fc.c
49998+++ b/drivers/scsi/scsi_transport_fc.c
49999@@ -497,7 +497,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
50000 * Netlink Infrastructure
50001 */
50002
50003-static atomic_t fc_event_seq;
50004+static atomic_unchecked_t fc_event_seq;
50005
50006 /**
50007 * fc_get_event_number - Obtain the next sequential FC event number
50008@@ -510,7 +510,7 @@ static atomic_t fc_event_seq;
50009 u32
50010 fc_get_event_number(void)
50011 {
50012- return atomic_add_return(1, &fc_event_seq);
50013+ return atomic_add_return_unchecked(1, &fc_event_seq);
50014 }
50015 EXPORT_SYMBOL(fc_get_event_number);
50016
50017@@ -654,7 +654,7 @@ static __init int fc_transport_init(void)
50018 {
50019 int error;
50020
50021- atomic_set(&fc_event_seq, 0);
50022+ atomic_set_unchecked(&fc_event_seq, 0);
50023
50024 error = transport_class_register(&fc_host_class);
50025 if (error)
50026@@ -844,7 +844,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
50027 char *cp;
50028
50029 *val = simple_strtoul(buf, &cp, 0);
50030- if ((*cp && (*cp != '\n')) || (*val < 0))
50031+ if (*cp && (*cp != '\n'))
50032 return -EINVAL;
50033 /*
50034 * Check for overflow; dev_loss_tmo is u32
50035diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
50036index fd8ffe6..fd0bebf 100644
50037--- a/drivers/scsi/scsi_transport_iscsi.c
50038+++ b/drivers/scsi/scsi_transport_iscsi.c
50039@@ -79,7 +79,7 @@ struct iscsi_internal {
50040 struct transport_container session_cont;
50041 };
50042
50043-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
50044+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
50045 static struct workqueue_struct *iscsi_eh_timer_workq;
50046
50047 static DEFINE_IDA(iscsi_sess_ida);
50048@@ -2071,7 +2071,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
50049 int err;
50050
50051 ihost = shost->shost_data;
50052- session->sid = atomic_add_return(1, &iscsi_session_nr);
50053+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
50054
50055 if (target_id == ISCSI_MAX_TARGET) {
50056 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
50057@@ -4511,7 +4511,7 @@ static __init int iscsi_transport_init(void)
50058 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
50059 ISCSI_TRANSPORT_VERSION);
50060
50061- atomic_set(&iscsi_session_nr, 0);
50062+ atomic_set_unchecked(&iscsi_session_nr, 0);
50063
50064 err = class_register(&iscsi_transport_class);
50065 if (err)
50066diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
50067index d47ffc8..30f46a9 100644
50068--- a/drivers/scsi/scsi_transport_srp.c
50069+++ b/drivers/scsi/scsi_transport_srp.c
50070@@ -36,7 +36,7 @@
50071 #include "scsi_transport_srp_internal.h"
50072
50073 struct srp_host_attrs {
50074- atomic_t next_port_id;
50075+ atomic_unchecked_t next_port_id;
50076 };
50077 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
50078
50079@@ -101,7 +101,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
50080 struct Scsi_Host *shost = dev_to_shost(dev);
50081 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
50082
50083- atomic_set(&srp_host->next_port_id, 0);
50084+ atomic_set_unchecked(&srp_host->next_port_id, 0);
50085 return 0;
50086 }
50087
50088@@ -734,7 +734,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
50089 rport_fast_io_fail_timedout);
50090 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
50091
50092- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
50093+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
50094 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
50095
50096 transport_setup_device(&rport->dev);
50097diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
50098index 36d1a23..3f33303 100644
50099--- a/drivers/scsi/sd.c
50100+++ b/drivers/scsi/sd.c
50101@@ -2962,7 +2962,7 @@ static int sd_probe(struct device *dev)
50102 sdkp->disk = gd;
50103 sdkp->index = index;
50104 atomic_set(&sdkp->openers, 0);
50105- atomic_set(&sdkp->device->ioerr_cnt, 0);
50106+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
50107
50108 if (!sdp->request_queue->rq_timeout) {
50109 if (sdp->type != TYPE_MOD)
50110diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
50111index df5e961..df6b97f 100644
50112--- a/drivers/scsi/sg.c
50113+++ b/drivers/scsi/sg.c
50114@@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
50115 sdp->disk->disk_name,
50116 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
50117 NULL,
50118- (char *)arg);
50119+ (char __user *)arg);
50120 case BLKTRACESTART:
50121 return blk_trace_startstop(sdp->device->request_queue, 1);
50122 case BLKTRACESTOP:
50123diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
50124index d0b28bb..a263613 100644
50125--- a/drivers/spi/spi.c
50126+++ b/drivers/spi/spi.c
50127@@ -1971,7 +1971,7 @@ int spi_bus_unlock(struct spi_master *master)
50128 EXPORT_SYMBOL_GPL(spi_bus_unlock);
50129
50130 /* portable code must never pass more than 32 bytes */
50131-#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
50132+#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
50133
50134 static u8 *buf;
50135
50136diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
50137index 2c61783..4d49e4e 100644
50138--- a/drivers/staging/android/timed_output.c
50139+++ b/drivers/staging/android/timed_output.c
50140@@ -25,7 +25,7 @@
50141 #include "timed_output.h"
50142
50143 static struct class *timed_output_class;
50144-static atomic_t device_count;
50145+static atomic_unchecked_t device_count;
50146
50147 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
50148 char *buf)
50149@@ -63,7 +63,7 @@ static int create_timed_output_class(void)
50150 timed_output_class = class_create(THIS_MODULE, "timed_output");
50151 if (IS_ERR(timed_output_class))
50152 return PTR_ERR(timed_output_class);
50153- atomic_set(&device_count, 0);
50154+ atomic_set_unchecked(&device_count, 0);
50155 timed_output_class->dev_groups = timed_output_groups;
50156 }
50157
50158@@ -81,7 +81,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
50159 if (ret < 0)
50160 return ret;
50161
50162- tdev->index = atomic_inc_return(&device_count);
50163+ tdev->index = atomic_inc_return_unchecked(&device_count);
50164 tdev->dev = device_create(timed_output_class, NULL,
50165 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
50166 if (IS_ERR(tdev->dev))
50167diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
50168index fe47cd3..19a1bd1 100644
50169--- a/drivers/staging/gdm724x/gdm_tty.c
50170+++ b/drivers/staging/gdm724x/gdm_tty.c
50171@@ -44,7 +44,7 @@
50172 #define gdm_tty_send_control(n, r, v, d, l) (\
50173 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
50174
50175-#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
50176+#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
50177
50178 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
50179 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
50180diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
50181index 236ed66..dd9cd74 100644
50182--- a/drivers/staging/imx-drm/imx-drm-core.c
50183+++ b/drivers/staging/imx-drm/imx-drm-core.c
50184@@ -488,7 +488,7 @@ int imx_drm_add_crtc(struct drm_crtc *crtc,
50185 goto err_busy;
50186 }
50187
50188- if (imxdrm->drm->open_count) {
50189+ if (local_read(&imxdrm->drm->open_count)) {
50190 ret = -EBUSY;
50191 goto err_busy;
50192 }
50193@@ -576,7 +576,7 @@ int imx_drm_add_encoder(struct drm_encoder *encoder,
50194
50195 mutex_lock(&imxdrm->mutex);
50196
50197- if (imxdrm->drm->open_count) {
50198+ if (local_read(&imxdrm->drm->open_count)) {
50199 ret = -EBUSY;
50200 goto err_busy;
50201 }
50202@@ -715,7 +715,7 @@ int imx_drm_add_connector(struct drm_connector *connector,
50203
50204 mutex_lock(&imxdrm->mutex);
50205
50206- if (imxdrm->drm->open_count) {
50207+ if (local_read(&imxdrm->drm->open_count)) {
50208 ret = -EBUSY;
50209 goto err_busy;
50210 }
50211diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
50212index 3f8020c..649fded 100644
50213--- a/drivers/staging/lustre/lnet/selftest/brw_test.c
50214+++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
50215@@ -488,13 +488,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
50216 return 0;
50217 }
50218
50219-sfw_test_client_ops_t brw_test_client;
50220-void brw_init_test_client(void)
50221-{
50222- brw_test_client.tso_init = brw_client_init;
50223- brw_test_client.tso_fini = brw_client_fini;
50224- brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
50225- brw_test_client.tso_done_rpc = brw_client_done_rpc;
50226+sfw_test_client_ops_t brw_test_client = {
50227+ .tso_init = brw_client_init,
50228+ .tso_fini = brw_client_fini,
50229+ .tso_prep_rpc = brw_client_prep_rpc,
50230+ .tso_done_rpc = brw_client_done_rpc,
50231 };
50232
50233 srpc_service_t brw_test_service;
50234diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
50235index 050723a..fa6fdf1 100644
50236--- a/drivers/staging/lustre/lnet/selftest/framework.c
50237+++ b/drivers/staging/lustre/lnet/selftest/framework.c
50238@@ -1635,12 +1635,10 @@ static srpc_service_t sfw_services[] =
50239
50240 extern sfw_test_client_ops_t ping_test_client;
50241 extern srpc_service_t ping_test_service;
50242-extern void ping_init_test_client(void);
50243 extern void ping_init_test_service(void);
50244
50245 extern sfw_test_client_ops_t brw_test_client;
50246 extern srpc_service_t brw_test_service;
50247-extern void brw_init_test_client(void);
50248 extern void brw_init_test_service(void);
50249
50250
50251@@ -1684,12 +1682,10 @@ sfw_startup (void)
50252 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
50253 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
50254
50255- brw_init_test_client();
50256 brw_init_test_service();
50257 rc = sfw_register_test(&brw_test_service, &brw_test_client);
50258 LASSERT (rc == 0);
50259
50260- ping_init_test_client();
50261 ping_init_test_service();
50262 rc = sfw_register_test(&ping_test_service, &ping_test_client);
50263 LASSERT (rc == 0);
50264diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
50265index 750cac4..e4d751f 100644
50266--- a/drivers/staging/lustre/lnet/selftest/ping_test.c
50267+++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
50268@@ -211,14 +211,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
50269 return 0;
50270 }
50271
50272-sfw_test_client_ops_t ping_test_client;
50273-void ping_init_test_client(void)
50274-{
50275- ping_test_client.tso_init = ping_client_init;
50276- ping_test_client.tso_fini = ping_client_fini;
50277- ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
50278- ping_test_client.tso_done_rpc = ping_client_done_rpc;
50279-}
50280+sfw_test_client_ops_t ping_test_client = {
50281+ .tso_init = ping_client_init,
50282+ .tso_fini = ping_client_fini,
50283+ .tso_prep_rpc = ping_client_prep_rpc,
50284+ .tso_done_rpc = ping_client_done_rpc,
50285+};
50286
50287 srpc_service_t ping_test_service;
50288 void ping_init_test_service(void)
50289diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
50290index ec4bb5e..740c6dd 100644
50291--- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
50292+++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
50293@@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
50294 ldlm_completion_callback lcs_completion;
50295 ldlm_blocking_callback lcs_blocking;
50296 ldlm_glimpse_callback lcs_glimpse;
50297-};
50298+} __no_const;
50299
50300 /* ldlm_lockd.c */
50301 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
50302diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
50303index c3470ce..2bef527 100644
50304--- a/drivers/staging/lustre/lustre/include/obd.h
50305+++ b/drivers/staging/lustre/lustre/include/obd.h
50306@@ -1426,7 +1426,7 @@ struct md_ops {
50307 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
50308 * wrapper function in include/linux/obd_class.h.
50309 */
50310-};
50311+} __no_const;
50312
50313 struct lsm_operations {
50314 void (*lsm_free)(struct lov_stripe_md *);
50315diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
50316index c9aae13..60ea292 100644
50317--- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
50318+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
50319@@ -239,7 +239,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
50320 int added = (mode == LCK_NL);
50321 int overlaps = 0;
50322 int splitted = 0;
50323- const struct ldlm_callback_suite null_cbs = { NULL };
50324+ const struct ldlm_callback_suite null_cbs = { };
50325
50326 CDEBUG(D_DLMTRACE, "flags %#llx owner "LPU64" pid %u mode %u start "
50327 LPU64" end "LPU64"\n", *flags,
50328diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
50329index e947b91..f408990 100644
50330--- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
50331+++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
50332@@ -217,7 +217,7 @@ DECLARE_PROC_HANDLER(proc_debug_mb)
50333 int LL_PROC_PROTO(proc_console_max_delay_cs)
50334 {
50335 int rc, max_delay_cs;
50336- ctl_table_t dummy = *table;
50337+ ctl_table_no_const dummy = *table;
50338 cfs_duration_t d;
50339
50340 dummy.data = &max_delay_cs;
50341@@ -248,7 +248,7 @@ int LL_PROC_PROTO(proc_console_max_delay_cs)
50342 int LL_PROC_PROTO(proc_console_min_delay_cs)
50343 {
50344 int rc, min_delay_cs;
50345- ctl_table_t dummy = *table;
50346+ ctl_table_no_const dummy = *table;
50347 cfs_duration_t d;
50348
50349 dummy.data = &min_delay_cs;
50350@@ -279,7 +279,7 @@ int LL_PROC_PROTO(proc_console_min_delay_cs)
50351 int LL_PROC_PROTO(proc_console_backoff)
50352 {
50353 int rc, backoff;
50354- ctl_table_t dummy = *table;
50355+ ctl_table_no_const dummy = *table;
50356
50357 dummy.data = &backoff;
50358 dummy.proc_handler = &proc_dointvec;
50359diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
50360index 24ae26d..9d09cab 100644
50361--- a/drivers/staging/lustre/lustre/libcfs/module.c
50362+++ b/drivers/staging/lustre/lustre/libcfs/module.c
50363@@ -313,11 +313,11 @@ out:
50364
50365
50366 struct cfs_psdev_ops libcfs_psdev_ops = {
50367- libcfs_psdev_open,
50368- libcfs_psdev_release,
50369- NULL,
50370- NULL,
50371- libcfs_ioctl
50372+ .p_open = libcfs_psdev_open,
50373+ .p_close = libcfs_psdev_release,
50374+ .p_read = NULL,
50375+ .p_write = NULL,
50376+ .p_ioctl = libcfs_ioctl
50377 };
50378
50379 extern int insert_proc(void);
50380diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
50381index 52b7731..d604da0 100644
50382--- a/drivers/staging/lustre/lustre/llite/dir.c
50383+++ b/drivers/staging/lustre/lustre/llite/dir.c
50384@@ -660,7 +660,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
50385 int mode;
50386 int err;
50387
50388- mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
50389+ mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
50390 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
50391 strlen(filename), mode, LUSTRE_OPC_MKDIR,
50392 lump);
50393diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
50394index 480b7c4..6846324 100644
50395--- a/drivers/staging/media/solo6x10/solo6x10-core.c
50396+++ b/drivers/staging/media/solo6x10/solo6x10-core.c
50397@@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
50398
50399 static int solo_sysfs_init(struct solo_dev *solo_dev)
50400 {
50401- struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
50402+ bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
50403 struct device *dev = &solo_dev->dev;
50404 const char *driver;
50405 int i;
50406diff --git a/drivers/staging/media/solo6x10/solo6x10-g723.c b/drivers/staging/media/solo6x10/solo6x10-g723.c
50407index 1db18c7..35e6afc 100644
50408--- a/drivers/staging/media/solo6x10/solo6x10-g723.c
50409+++ b/drivers/staging/media/solo6x10/solo6x10-g723.c
50410@@ -355,7 +355,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
50411
50412 int solo_g723_init(struct solo_dev *solo_dev)
50413 {
50414- static struct snd_device_ops ops = { NULL };
50415+ static struct snd_device_ops ops = { };
50416 struct snd_card *card;
50417 struct snd_kcontrol_new kctl;
50418 char name[32];
50419diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
50420index 7f2f247..d999137 100644
50421--- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
50422+++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
50423@@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
50424
50425 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
50426 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
50427- p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
50428+ p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
50429 if (p2m_id < 0)
50430 p2m_id = -p2m_id;
50431 }
50432diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
50433index 8964f8b..36eb087 100644
50434--- a/drivers/staging/media/solo6x10/solo6x10.h
50435+++ b/drivers/staging/media/solo6x10/solo6x10.h
50436@@ -237,7 +237,7 @@ struct solo_dev {
50437
50438 /* P2M DMA Engine */
50439 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
50440- atomic_t p2m_count;
50441+ atomic_unchecked_t p2m_count;
50442 int p2m_jiffies;
50443 unsigned int p2m_timeouts;
50444
50445diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
50446index a0f4868..139f1fb 100644
50447--- a/drivers/staging/octeon/ethernet-rx.c
50448+++ b/drivers/staging/octeon/ethernet-rx.c
50449@@ -417,11 +417,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
50450 /* Increment RX stats for virtual ports */
50451 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
50452 #ifdef CONFIG_64BIT
50453- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
50454- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
50455+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
50456+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
50457 #else
50458- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
50459- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
50460+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
50461+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
50462 #endif
50463 }
50464 netif_receive_skb(skb);
50465@@ -432,9 +432,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
50466 dev->name);
50467 */
50468 #ifdef CONFIG_64BIT
50469- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
50470+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
50471 #else
50472- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
50473+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
50474 #endif
50475 dev_kfree_skb_irq(skb);
50476 }
50477diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
50478index 089dc4b..c9a687e 100644
50479--- a/drivers/staging/octeon/ethernet.c
50480+++ b/drivers/staging/octeon/ethernet.c
50481@@ -253,11 +253,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
50482 * since the RX tasklet also increments it.
50483 */
50484 #ifdef CONFIG_64BIT
50485- atomic64_add(rx_status.dropped_packets,
50486- (atomic64_t *)&priv->stats.rx_dropped);
50487+ atomic64_add_unchecked(rx_status.dropped_packets,
50488+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
50489 #else
50490- atomic_add(rx_status.dropped_packets,
50491- (atomic_t *)&priv->stats.rx_dropped);
50492+ atomic_add_unchecked(rx_status.dropped_packets,
50493+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
50494 #endif
50495 }
50496
50497diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
50498index c274b34..f84de76 100644
50499--- a/drivers/staging/rtl8188eu/include/hal_intf.h
50500+++ b/drivers/staging/rtl8188eu/include/hal_intf.h
50501@@ -271,7 +271,7 @@ struct hal_ops {
50502 s32 (*c2h_handler)(struct adapter *padapter,
50503 struct c2h_evt_hdr *c2h_evt);
50504 c2h_id_filter c2h_id_filter_ccx;
50505-};
50506+} __no_const;
50507
50508 enum rt_eeprom_type {
50509 EEPROM_93C46,
50510diff --git a/drivers/staging/rtl8188eu/include/rtw_io.h b/drivers/staging/rtl8188eu/include/rtw_io.h
50511index 3d1dfcc..ff5620a 100644
50512--- a/drivers/staging/rtl8188eu/include/rtw_io.h
50513+++ b/drivers/staging/rtl8188eu/include/rtw_io.h
50514@@ -126,7 +126,7 @@ struct _io_ops {
50515 u32 (*_write_scsi)(struct intf_hdl *pintfhdl, u32 cnt, u8 *pmem);
50516 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
50517 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
50518-};
50519+} __no_const;
50520
50521 struct io_req {
50522 struct list_head list;
50523diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
50524index dc23395..cf7e9b1 100644
50525--- a/drivers/staging/rtl8712/rtl871x_io.h
50526+++ b/drivers/staging/rtl8712/rtl871x_io.h
50527@@ -108,7 +108,7 @@ struct _io_ops {
50528 u8 *pmem);
50529 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
50530 u8 *pmem);
50531-};
50532+} __no_const;
50533
50534 struct io_req {
50535 struct list_head list;
50536diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
50537index 1f5088b..0e59820 100644
50538--- a/drivers/staging/sbe-2t3e3/netdev.c
50539+++ b/drivers/staging/sbe-2t3e3/netdev.c
50540@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
50541 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
50542
50543 if (rlen)
50544- if (copy_to_user(data, &resp, rlen))
50545+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
50546 return -EFAULT;
50547
50548 return 0;
50549diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
50550index a863a98..d272795 100644
50551--- a/drivers/staging/usbip/vhci.h
50552+++ b/drivers/staging/usbip/vhci.h
50553@@ -83,7 +83,7 @@ struct vhci_hcd {
50554 unsigned resuming:1;
50555 unsigned long re_timeout;
50556
50557- atomic_t seqnum;
50558+ atomic_unchecked_t seqnum;
50559
50560 /*
50561 * NOTE:
50562diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
50563index 72391ef..7c6717a 100644
50564--- a/drivers/staging/usbip/vhci_hcd.c
50565+++ b/drivers/staging/usbip/vhci_hcd.c
50566@@ -440,7 +440,7 @@ static void vhci_tx_urb(struct urb *urb)
50567
50568 spin_lock(&vdev->priv_lock);
50569
50570- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
50571+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
50572 if (priv->seqnum == 0xffff)
50573 dev_info(&urb->dev->dev, "seqnum max\n");
50574
50575@@ -686,7 +686,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
50576 return -ENOMEM;
50577 }
50578
50579- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
50580+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
50581 if (unlink->seqnum == 0xffff)
50582 pr_info("seqnum max\n");
50583
50584@@ -890,7 +890,7 @@ static int vhci_start(struct usb_hcd *hcd)
50585 vdev->rhport = rhport;
50586 }
50587
50588- atomic_set(&vhci->seqnum, 0);
50589+ atomic_set_unchecked(&vhci->seqnum, 0);
50590 spin_lock_init(&vhci->lock);
50591
50592 hcd->power_budget = 0; /* no limit */
50593diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
50594index d07fcb5..358e1e1 100644
50595--- a/drivers/staging/usbip/vhci_rx.c
50596+++ b/drivers/staging/usbip/vhci_rx.c
50597@@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
50598 if (!urb) {
50599 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
50600 pr_info("max seqnum %d\n",
50601- atomic_read(&the_controller->seqnum));
50602+ atomic_read_unchecked(&the_controller->seqnum));
50603 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
50604 return;
50605 }
50606diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
50607index 6eecd53..29317c6 100644
50608--- a/drivers/staging/vt6655/hostap.c
50609+++ b/drivers/staging/vt6655/hostap.c
50610@@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
50611 *
50612 */
50613
50614+static net_device_ops_no_const apdev_netdev_ops;
50615+
50616 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50617 {
50618 PSDevice apdev_priv;
50619 struct net_device *dev = pDevice->dev;
50620 int ret;
50621- const struct net_device_ops apdev_netdev_ops = {
50622- .ndo_start_xmit = pDevice->tx_80211,
50623- };
50624
50625 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50626
50627@@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50628 *apdev_priv = *pDevice;
50629 eth_hw_addr_inherit(pDevice->apdev, dev);
50630
50631+ /* only half broken now */
50632+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50633 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50634
50635 pDevice->apdev->type = ARPHRD_IEEE80211;
50636diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
50637index 67ba48b..24e602f 100644
50638--- a/drivers/staging/vt6656/hostap.c
50639+++ b/drivers/staging/vt6656/hostap.c
50640@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
50641 *
50642 */
50643
50644+static net_device_ops_no_const apdev_netdev_ops;
50645+
50646 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50647 {
50648 struct vnt_private *apdev_priv;
50649 struct net_device *dev = pDevice->dev;
50650 int ret;
50651- const struct net_device_ops apdev_netdev_ops = {
50652- .ndo_start_xmit = pDevice->tx_80211,
50653- };
50654
50655 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50656
50657@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50658 *apdev_priv = *pDevice;
50659 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
50660
50661+ /* only half broken now */
50662+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50663 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50664
50665 pDevice->apdev->type = ARPHRD_IEEE80211;
50666diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
50667index 24884ca..26c8220 100644
50668--- a/drivers/target/sbp/sbp_target.c
50669+++ b/drivers/target/sbp/sbp_target.c
50670@@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
50671
50672 #define SESSION_MAINTENANCE_INTERVAL HZ
50673
50674-static atomic_t login_id = ATOMIC_INIT(0);
50675+static atomic_unchecked_t login_id = ATOMIC_INIT(0);
50676
50677 static void session_maintenance_work(struct work_struct *);
50678 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
50679@@ -444,7 +444,7 @@ static void sbp_management_request_login(
50680 login->lun = se_lun;
50681 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
50682 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
50683- login->login_id = atomic_inc_return(&login_id);
50684+ login->login_id = atomic_inc_return_unchecked(&login_id);
50685
50686 login->tgt_agt = sbp_target_agent_register(login);
50687 if (IS_ERR(login->tgt_agt)) {
50688diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
50689index 65001e1..2ebfbb9 100644
50690--- a/drivers/target/target_core_device.c
50691+++ b/drivers/target/target_core_device.c
50692@@ -1520,7 +1520,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
50693 spin_lock_init(&dev->se_tmr_lock);
50694 spin_lock_init(&dev->qf_cmd_lock);
50695 sema_init(&dev->caw_sem, 1);
50696- atomic_set(&dev->dev_ordered_id, 0);
50697+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
50698 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
50699 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
50700 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
50701diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
50702index 2956250..b10f722 100644
50703--- a/drivers/target/target_core_transport.c
50704+++ b/drivers/target/target_core_transport.c
50705@@ -1136,7 +1136,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
50706 * Used to determine when ORDERED commands should go from
50707 * Dormant to Active status.
50708 */
50709- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
50710+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
50711 smp_mb__after_atomic_inc();
50712 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
50713 cmd->se_ordered_id, cmd->sam_task_attr,
50714diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
50715index 04b1be7..5eff86d 100644
50716--- a/drivers/thermal/of-thermal.c
50717+++ b/drivers/thermal/of-thermal.c
50718@@ -30,6 +30,7 @@
50719 #include <linux/err.h>
50720 #include <linux/export.h>
50721 #include <linux/string.h>
50722+#include <linux/mm.h>
50723
50724 #include "thermal_core.h"
50725
50726@@ -341,8 +342,10 @@ thermal_zone_of_add_sensor(struct device_node *zone,
50727 tz->get_trend = get_trend;
50728 tz->sensor_data = data;
50729
50730- tzd->ops->get_temp = of_thermal_get_temp;
50731- tzd->ops->get_trend = of_thermal_get_trend;
50732+ pax_open_kernel();
50733+ *(void **)&tzd->ops->get_temp = of_thermal_get_temp;
50734+ *(void **)&tzd->ops->get_trend = of_thermal_get_trend;
50735+ pax_close_kernel();
50736 mutex_unlock(&tzd->lock);
50737
50738 return tzd;
50739@@ -461,8 +464,10 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
50740 return;
50741
50742 mutex_lock(&tzd->lock);
50743- tzd->ops->get_temp = NULL;
50744- tzd->ops->get_trend = NULL;
50745+ pax_open_kernel();
50746+ *(void **)&tzd->ops->get_temp = NULL;
50747+ *(void **)&tzd->ops->get_trend = NULL;
50748+ pax_close_kernel();
50749
50750 tz->get_temp = NULL;
50751 tz->get_trend = NULL;
50752diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
50753index a57bb5a..1f727d33 100644
50754--- a/drivers/tty/cyclades.c
50755+++ b/drivers/tty/cyclades.c
50756@@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
50757 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
50758 info->port.count);
50759 #endif
50760- info->port.count++;
50761+ atomic_inc(&info->port.count);
50762 #ifdef CY_DEBUG_COUNT
50763 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
50764- current->pid, info->port.count);
50765+ current->pid, atomic_read(&info->port.count));
50766 #endif
50767
50768 /*
50769@@ -3974,7 +3974,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
50770 for (j = 0; j < cy_card[i].nports; j++) {
50771 info = &cy_card[i].ports[j];
50772
50773- if (info->port.count) {
50774+ if (atomic_read(&info->port.count)) {
50775 /* XXX is the ldisc num worth this? */
50776 struct tty_struct *tty;
50777 struct tty_ldisc *ld;
50778diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
50779index 0ff7fda..dbc7d52 100644
50780--- a/drivers/tty/hvc/hvc_console.c
50781+++ b/drivers/tty/hvc/hvc_console.c
50782@@ -342,7 +342,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
50783
50784 spin_lock_irqsave(&hp->port.lock, flags);
50785 /* Check and then increment for fast path open. */
50786- if (hp->port.count++ > 0) {
50787+ if (atomic_inc_return(&hp->port.count) > 1) {
50788 spin_unlock_irqrestore(&hp->port.lock, flags);
50789 hvc_kick();
50790 return 0;
50791@@ -397,7 +397,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50792
50793 spin_lock_irqsave(&hp->port.lock, flags);
50794
50795- if (--hp->port.count == 0) {
50796+ if (atomic_dec_return(&hp->port.count) == 0) {
50797 spin_unlock_irqrestore(&hp->port.lock, flags);
50798 /* We are done with the tty pointer now. */
50799 tty_port_tty_set(&hp->port, NULL);
50800@@ -419,9 +419,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50801 */
50802 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
50803 } else {
50804- if (hp->port.count < 0)
50805+ if (atomic_read(&hp->port.count) < 0)
50806 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
50807- hp->vtermno, hp->port.count);
50808+ hp->vtermno, atomic_read(&hp->port.count));
50809 spin_unlock_irqrestore(&hp->port.lock, flags);
50810 }
50811 }
50812@@ -451,12 +451,12 @@ static void hvc_hangup(struct tty_struct *tty)
50813 * open->hangup case this can be called after the final close so prevent
50814 * that from happening for now.
50815 */
50816- if (hp->port.count <= 0) {
50817+ if (atomic_read(&hp->port.count) <= 0) {
50818 spin_unlock_irqrestore(&hp->port.lock, flags);
50819 return;
50820 }
50821
50822- hp->port.count = 0;
50823+ atomic_set(&hp->port.count, 0);
50824 spin_unlock_irqrestore(&hp->port.lock, flags);
50825 tty_port_tty_set(&hp->port, NULL);
50826
50827@@ -504,7 +504,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
50828 return -EPIPE;
50829
50830 /* FIXME what's this (unprotected) check for? */
50831- if (hp->port.count <= 0)
50832+ if (atomic_read(&hp->port.count) <= 0)
50833 return -EIO;
50834
50835 spin_lock_irqsave(&hp->lock, flags);
50836diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
50837index 81e939e..95ead10 100644
50838--- a/drivers/tty/hvc/hvcs.c
50839+++ b/drivers/tty/hvc/hvcs.c
50840@@ -83,6 +83,7 @@
50841 #include <asm/hvcserver.h>
50842 #include <asm/uaccess.h>
50843 #include <asm/vio.h>
50844+#include <asm/local.h>
50845
50846 /*
50847 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
50848@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
50849
50850 spin_lock_irqsave(&hvcsd->lock, flags);
50851
50852- if (hvcsd->port.count > 0) {
50853+ if (atomic_read(&hvcsd->port.count) > 0) {
50854 spin_unlock_irqrestore(&hvcsd->lock, flags);
50855 printk(KERN_INFO "HVCS: vterm state unchanged. "
50856 "The hvcs device node is still in use.\n");
50857@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
50858 }
50859 }
50860
50861- hvcsd->port.count = 0;
50862+ atomic_set(&hvcsd->port.count, 0);
50863 hvcsd->port.tty = tty;
50864 tty->driver_data = hvcsd;
50865
50866@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
50867 unsigned long flags;
50868
50869 spin_lock_irqsave(&hvcsd->lock, flags);
50870- hvcsd->port.count++;
50871+ atomic_inc(&hvcsd->port.count);
50872 hvcsd->todo_mask |= HVCS_SCHED_READ;
50873 spin_unlock_irqrestore(&hvcsd->lock, flags);
50874
50875@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50876 hvcsd = tty->driver_data;
50877
50878 spin_lock_irqsave(&hvcsd->lock, flags);
50879- if (--hvcsd->port.count == 0) {
50880+ if (atomic_dec_and_test(&hvcsd->port.count)) {
50881
50882 vio_disable_interrupts(hvcsd->vdev);
50883
50884@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50885
50886 free_irq(irq, hvcsd);
50887 return;
50888- } else if (hvcsd->port.count < 0) {
50889+ } else if (atomic_read(&hvcsd->port.count) < 0) {
50890 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
50891 " is missmanaged.\n",
50892- hvcsd->vdev->unit_address, hvcsd->port.count);
50893+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
50894 }
50895
50896 spin_unlock_irqrestore(&hvcsd->lock, flags);
50897@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50898
50899 spin_lock_irqsave(&hvcsd->lock, flags);
50900 /* Preserve this so that we know how many kref refs to put */
50901- temp_open_count = hvcsd->port.count;
50902+ temp_open_count = atomic_read(&hvcsd->port.count);
50903
50904 /*
50905 * Don't kref put inside the spinlock because the destruction
50906@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50907 tty->driver_data = NULL;
50908 hvcsd->port.tty = NULL;
50909
50910- hvcsd->port.count = 0;
50911+ atomic_set(&hvcsd->port.count, 0);
50912
50913 /* This will drop any buffered data on the floor which is OK in a hangup
50914 * scenario. */
50915@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
50916 * the middle of a write operation? This is a crummy place to do this
50917 * but we want to keep it all in the spinlock.
50918 */
50919- if (hvcsd->port.count <= 0) {
50920+ if (atomic_read(&hvcsd->port.count) <= 0) {
50921 spin_unlock_irqrestore(&hvcsd->lock, flags);
50922 return -ENODEV;
50923 }
50924@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
50925 {
50926 struct hvcs_struct *hvcsd = tty->driver_data;
50927
50928- if (!hvcsd || hvcsd->port.count <= 0)
50929+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
50930 return 0;
50931
50932 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
50933diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
50934index 4190199..06d5bfa 100644
50935--- a/drivers/tty/hvc/hvsi.c
50936+++ b/drivers/tty/hvc/hvsi.c
50937@@ -85,7 +85,7 @@ struct hvsi_struct {
50938 int n_outbuf;
50939 uint32_t vtermno;
50940 uint32_t virq;
50941- atomic_t seqno; /* HVSI packet sequence number */
50942+ atomic_unchecked_t seqno; /* HVSI packet sequence number */
50943 uint16_t mctrl;
50944 uint8_t state; /* HVSI protocol state */
50945 uint8_t flags;
50946@@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
50947
50948 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
50949 packet.hdr.len = sizeof(struct hvsi_query_response);
50950- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50951+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50952 packet.verb = VSV_SEND_VERSION_NUMBER;
50953 packet.u.version = HVSI_VERSION;
50954 packet.query_seqno = query_seqno+1;
50955@@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
50956
50957 packet.hdr.type = VS_QUERY_PACKET_HEADER;
50958 packet.hdr.len = sizeof(struct hvsi_query);
50959- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50960+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50961 packet.verb = verb;
50962
50963 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
50964@@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
50965 int wrote;
50966
50967 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
50968- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50969+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50970 packet.hdr.len = sizeof(struct hvsi_control);
50971 packet.verb = VSV_SET_MODEM_CTL;
50972 packet.mask = HVSI_TSDTR;
50973@@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
50974 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
50975
50976 packet.hdr.type = VS_DATA_PACKET_HEADER;
50977- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50978+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50979 packet.hdr.len = count + sizeof(struct hvsi_header);
50980 memcpy(&packet.data, buf, count);
50981
50982@@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
50983 struct hvsi_control packet __ALIGNED__;
50984
50985 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
50986- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50987+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50988 packet.hdr.len = 6;
50989 packet.verb = VSV_CLOSE_PROTOCOL;
50990
50991@@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
50992
50993 tty_port_tty_set(&hp->port, tty);
50994 spin_lock_irqsave(&hp->lock, flags);
50995- hp->port.count++;
50996+ atomic_inc(&hp->port.count);
50997 atomic_set(&hp->seqno, 0);
50998 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
50999 spin_unlock_irqrestore(&hp->lock, flags);
51000@@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
51001
51002 spin_lock_irqsave(&hp->lock, flags);
51003
51004- if (--hp->port.count == 0) {
51005+ if (atomic_dec_return(&hp->port.count) == 0) {
51006 tty_port_tty_set(&hp->port, NULL);
51007 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
51008
51009@@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
51010
51011 spin_lock_irqsave(&hp->lock, flags);
51012 }
51013- } else if (hp->port.count < 0)
51014+ } else if (atomic_read(&hp->port.count) < 0)
51015 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
51016- hp - hvsi_ports, hp->port.count);
51017+ hp - hvsi_ports, atomic_read(&hp->port.count));
51018
51019 spin_unlock_irqrestore(&hp->lock, flags);
51020 }
51021@@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
51022 tty_port_tty_set(&hp->port, NULL);
51023
51024 spin_lock_irqsave(&hp->lock, flags);
51025- hp->port.count = 0;
51026+ atomic_set(&hp->port.count, 0);
51027 hp->n_outbuf = 0;
51028 spin_unlock_irqrestore(&hp->lock, flags);
51029 }
51030diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
51031index 7ae6c29..05c6dba 100644
51032--- a/drivers/tty/hvc/hvsi_lib.c
51033+++ b/drivers/tty/hvc/hvsi_lib.c
51034@@ -8,7 +8,7 @@
51035
51036 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
51037 {
51038- packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
51039+ packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
51040
51041 /* Assumes that always succeeds, works in practice */
51042 return pv->put_chars(pv->termno, (char *)packet, packet->len);
51043@@ -20,7 +20,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
51044
51045 /* Reset state */
51046 pv->established = 0;
51047- atomic_set(&pv->seqno, 0);
51048+ atomic_set_unchecked(&pv->seqno, 0);
51049
51050 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
51051
51052diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
51053index 17ee3bf..8d2520d 100644
51054--- a/drivers/tty/ipwireless/tty.c
51055+++ b/drivers/tty/ipwireless/tty.c
51056@@ -28,6 +28,7 @@
51057 #include <linux/tty_driver.h>
51058 #include <linux/tty_flip.h>
51059 #include <linux/uaccess.h>
51060+#include <asm/local.h>
51061
51062 #include "tty.h"
51063 #include "network.h"
51064@@ -98,10 +99,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
51065 mutex_unlock(&tty->ipw_tty_mutex);
51066 return -ENODEV;
51067 }
51068- if (tty->port.count == 0)
51069+ if (atomic_read(&tty->port.count) == 0)
51070 tty->tx_bytes_queued = 0;
51071
51072- tty->port.count++;
51073+ atomic_inc(&tty->port.count);
51074
51075 tty->port.tty = linux_tty;
51076 linux_tty->driver_data = tty;
51077@@ -117,9 +118,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
51078
51079 static void do_ipw_close(struct ipw_tty *tty)
51080 {
51081- tty->port.count--;
51082-
51083- if (tty->port.count == 0) {
51084+ if (atomic_dec_return(&tty->port.count) == 0) {
51085 struct tty_struct *linux_tty = tty->port.tty;
51086
51087 if (linux_tty != NULL) {
51088@@ -140,7 +139,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
51089 return;
51090
51091 mutex_lock(&tty->ipw_tty_mutex);
51092- if (tty->port.count == 0) {
51093+ if (atomic_read(&tty->port.count) == 0) {
51094 mutex_unlock(&tty->ipw_tty_mutex);
51095 return;
51096 }
51097@@ -163,7 +162,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
51098
51099 mutex_lock(&tty->ipw_tty_mutex);
51100
51101- if (!tty->port.count) {
51102+ if (!atomic_read(&tty->port.count)) {
51103 mutex_unlock(&tty->ipw_tty_mutex);
51104 return;
51105 }
51106@@ -202,7 +201,7 @@ static int ipw_write(struct tty_struct *linux_tty,
51107 return -ENODEV;
51108
51109 mutex_lock(&tty->ipw_tty_mutex);
51110- if (!tty->port.count) {
51111+ if (!atomic_read(&tty->port.count)) {
51112 mutex_unlock(&tty->ipw_tty_mutex);
51113 return -EINVAL;
51114 }
51115@@ -242,7 +241,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
51116 if (!tty)
51117 return -ENODEV;
51118
51119- if (!tty->port.count)
51120+ if (!atomic_read(&tty->port.count))
51121 return -EINVAL;
51122
51123 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
51124@@ -284,7 +283,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
51125 if (!tty)
51126 return 0;
51127
51128- if (!tty->port.count)
51129+ if (!atomic_read(&tty->port.count))
51130 return 0;
51131
51132 return tty->tx_bytes_queued;
51133@@ -365,7 +364,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
51134 if (!tty)
51135 return -ENODEV;
51136
51137- if (!tty->port.count)
51138+ if (!atomic_read(&tty->port.count))
51139 return -EINVAL;
51140
51141 return get_control_lines(tty);
51142@@ -381,7 +380,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
51143 if (!tty)
51144 return -ENODEV;
51145
51146- if (!tty->port.count)
51147+ if (!atomic_read(&tty->port.count))
51148 return -EINVAL;
51149
51150 return set_control_lines(tty, set, clear);
51151@@ -395,7 +394,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
51152 if (!tty)
51153 return -ENODEV;
51154
51155- if (!tty->port.count)
51156+ if (!atomic_read(&tty->port.count))
51157 return -EINVAL;
51158
51159 /* FIXME: Exactly how is the tty object locked here .. */
51160@@ -551,7 +550,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
51161 * are gone */
51162 mutex_lock(&ttyj->ipw_tty_mutex);
51163 }
51164- while (ttyj->port.count)
51165+ while (atomic_read(&ttyj->port.count))
51166 do_ipw_close(ttyj);
51167 ipwireless_disassociate_network_ttys(network,
51168 ttyj->channel_idx);
51169diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
51170index 1deaca4..c8582d4 100644
51171--- a/drivers/tty/moxa.c
51172+++ b/drivers/tty/moxa.c
51173@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
51174 }
51175
51176 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
51177- ch->port.count++;
51178+ atomic_inc(&ch->port.count);
51179 tty->driver_data = ch;
51180 tty_port_tty_set(&ch->port, tty);
51181 mutex_lock(&ch->port.mutex);
51182diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
51183index 2ebe47b..3205833 100644
51184--- a/drivers/tty/n_gsm.c
51185+++ b/drivers/tty/n_gsm.c
51186@@ -1644,7 +1644,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
51187 spin_lock_init(&dlci->lock);
51188 mutex_init(&dlci->mutex);
51189 dlci->fifo = &dlci->_fifo;
51190- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
51191+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
51192 kfree(dlci);
51193 return NULL;
51194 }
51195@@ -2954,7 +2954,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
51196 struct gsm_dlci *dlci = tty->driver_data;
51197 struct tty_port *port = &dlci->port;
51198
51199- port->count++;
51200+ atomic_inc(&port->count);
51201 tty_port_tty_set(port, tty);
51202
51203 dlci->modem_rx = 0;
51204diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
51205index e36d1f5..9938e3e 100644
51206--- a/drivers/tty/n_tty.c
51207+++ b/drivers/tty/n_tty.c
51208@@ -115,7 +115,7 @@ struct n_tty_data {
51209 int minimum_to_wake;
51210
51211 /* consumer-published */
51212- size_t read_tail;
51213+ size_t read_tail __intentional_overflow(-1);
51214 size_t line_start;
51215
51216 /* protected by output lock */
51217@@ -2519,6 +2519,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
51218 {
51219 *ops = tty_ldisc_N_TTY;
51220 ops->owner = NULL;
51221- ops->refcount = ops->flags = 0;
51222+ atomic_set(&ops->refcount, 0);
51223+ ops->flags = 0;
51224 }
51225 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
51226diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
51227index 25c9bc7..24077b7 100644
51228--- a/drivers/tty/pty.c
51229+++ b/drivers/tty/pty.c
51230@@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
51231 panic("Couldn't register Unix98 pts driver");
51232
51233 /* Now create the /dev/ptmx special device */
51234+ pax_open_kernel();
51235 tty_default_fops(&ptmx_fops);
51236- ptmx_fops.open = ptmx_open;
51237+ *(void **)&ptmx_fops.open = ptmx_open;
51238+ pax_close_kernel();
51239
51240 cdev_init(&ptmx_cdev, &ptmx_fops);
51241 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
51242diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
51243index 383c4c7..d408e21 100644
51244--- a/drivers/tty/rocket.c
51245+++ b/drivers/tty/rocket.c
51246@@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
51247 tty->driver_data = info;
51248 tty_port_tty_set(port, tty);
51249
51250- if (port->count++ == 0) {
51251+ if (atomic_inc_return(&port->count) == 1) {
51252 atomic_inc(&rp_num_ports_open);
51253
51254 #ifdef ROCKET_DEBUG_OPEN
51255@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
51256 #endif
51257 }
51258 #ifdef ROCKET_DEBUG_OPEN
51259- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
51260+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
51261 #endif
51262
51263 /*
51264@@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
51265 spin_unlock_irqrestore(&info->port.lock, flags);
51266 return;
51267 }
51268- if (info->port.count)
51269+ if (atomic_read(&info->port.count))
51270 atomic_dec(&rp_num_ports_open);
51271 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
51272 spin_unlock_irqrestore(&info->port.lock, flags);
51273diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
51274index 1274499..f541382 100644
51275--- a/drivers/tty/serial/ioc4_serial.c
51276+++ b/drivers/tty/serial/ioc4_serial.c
51277@@ -437,7 +437,7 @@ struct ioc4_soft {
51278 } is_intr_info[MAX_IOC4_INTR_ENTS];
51279
51280 /* Number of entries active in the above array */
51281- atomic_t is_num_intrs;
51282+ atomic_unchecked_t is_num_intrs;
51283 } is_intr_type[IOC4_NUM_INTR_TYPES];
51284
51285 /* is_ir_lock must be held while
51286@@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
51287 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
51288 || (type == IOC4_OTHER_INTR_TYPE)));
51289
51290- i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
51291+ i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
51292 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
51293
51294 /* Save off the lower level interrupt handler */
51295@@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
51296
51297 soft = arg;
51298 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
51299- num_intrs = (int)atomic_read(
51300+ num_intrs = (int)atomic_read_unchecked(
51301 &soft->is_intr_type[intr_type].is_num_intrs);
51302
51303 this_mir = this_ir = pending_intrs(soft, intr_type);
51304diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
51305index a260cde..6b2b5ce 100644
51306--- a/drivers/tty/serial/kgdboc.c
51307+++ b/drivers/tty/serial/kgdboc.c
51308@@ -24,8 +24,9 @@
51309 #define MAX_CONFIG_LEN 40
51310
51311 static struct kgdb_io kgdboc_io_ops;
51312+static struct kgdb_io kgdboc_io_ops_console;
51313
51314-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
51315+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
51316 static int configured = -1;
51317
51318 static char config[MAX_CONFIG_LEN];
51319@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
51320 kgdboc_unregister_kbd();
51321 if (configured == 1)
51322 kgdb_unregister_io_module(&kgdboc_io_ops);
51323+ else if (configured == 2)
51324+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
51325 }
51326
51327 static int configure_kgdboc(void)
51328@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
51329 int err;
51330 char *cptr = config;
51331 struct console *cons;
51332+ int is_console = 0;
51333
51334 err = kgdboc_option_setup(config);
51335 if (err || !strlen(config) || isspace(config[0]))
51336 goto noconfig;
51337
51338 err = -ENODEV;
51339- kgdboc_io_ops.is_console = 0;
51340 kgdb_tty_driver = NULL;
51341
51342 kgdboc_use_kms = 0;
51343@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
51344 int idx;
51345 if (cons->device && cons->device(cons, &idx) == p &&
51346 idx == tty_line) {
51347- kgdboc_io_ops.is_console = 1;
51348+ is_console = 1;
51349 break;
51350 }
51351 cons = cons->next;
51352@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
51353 kgdb_tty_line = tty_line;
51354
51355 do_register:
51356- err = kgdb_register_io_module(&kgdboc_io_ops);
51357+ if (is_console) {
51358+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
51359+ configured = 2;
51360+ } else {
51361+ err = kgdb_register_io_module(&kgdboc_io_ops);
51362+ configured = 1;
51363+ }
51364 if (err)
51365 goto noconfig;
51366
51367@@ -205,8 +214,6 @@ do_register:
51368 if (err)
51369 goto nmi_con_failed;
51370
51371- configured = 1;
51372-
51373 return 0;
51374
51375 nmi_con_failed:
51376@@ -223,7 +230,7 @@ noconfig:
51377 static int __init init_kgdboc(void)
51378 {
51379 /* Already configured? */
51380- if (configured == 1)
51381+ if (configured >= 1)
51382 return 0;
51383
51384 return configure_kgdboc();
51385@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
51386 if (config[len - 1] == '\n')
51387 config[len - 1] = '\0';
51388
51389- if (configured == 1)
51390+ if (configured >= 1)
51391 cleanup_kgdboc();
51392
51393 /* Go and configure with the new params. */
51394@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
51395 .post_exception = kgdboc_post_exp_handler,
51396 };
51397
51398+static struct kgdb_io kgdboc_io_ops_console = {
51399+ .name = "kgdboc",
51400+ .read_char = kgdboc_get_char,
51401+ .write_char = kgdboc_put_char,
51402+ .pre_exception = kgdboc_pre_exp_handler,
51403+ .post_exception = kgdboc_post_exp_handler,
51404+ .is_console = 1
51405+};
51406+
51407 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
51408 /* This is only available if kgdboc is a built in for early debugging */
51409 static int __init kgdboc_early_init(char *opt)
51410diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
51411index b5d779c..3622cfe 100644
51412--- a/drivers/tty/serial/msm_serial.c
51413+++ b/drivers/tty/serial/msm_serial.c
51414@@ -897,7 +897,7 @@ static struct uart_driver msm_uart_driver = {
51415 .cons = MSM_CONSOLE,
51416 };
51417
51418-static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
51419+static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
51420
51421 static const struct of_device_id msm_uartdm_table[] = {
51422 { .compatible = "qcom,msm-uartdm" },
51423@@ -912,7 +912,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
51424 int irq;
51425
51426 if (pdev->id == -1)
51427- pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
51428+ pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
51429
51430 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
51431 return -ENXIO;
51432diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
51433index 9cd706d..6ff2de7 100644
51434--- a/drivers/tty/serial/samsung.c
51435+++ b/drivers/tty/serial/samsung.c
51436@@ -463,11 +463,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
51437 }
51438 }
51439
51440+static int s3c64xx_serial_startup(struct uart_port *port);
51441 static int s3c24xx_serial_startup(struct uart_port *port)
51442 {
51443 struct s3c24xx_uart_port *ourport = to_ourport(port);
51444 int ret;
51445
51446+ /* Startup sequence is different for s3c64xx and higher SoC's */
51447+ if (s3c24xx_serial_has_interrupt_mask(port))
51448+ return s3c64xx_serial_startup(port);
51449+
51450 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
51451 port->mapbase, port->membase);
51452
51453@@ -1141,10 +1146,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
51454 /* setup info for port */
51455 port->dev = &platdev->dev;
51456
51457- /* Startup sequence is different for s3c64xx and higher SoC's */
51458- if (s3c24xx_serial_has_interrupt_mask(port))
51459- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
51460-
51461 port->uartclk = 1;
51462
51463 if (cfg->uart_flags & UPF_CONS_FLOW) {
51464diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
51465index ece2049..fba2524 100644
51466--- a/drivers/tty/serial/serial_core.c
51467+++ b/drivers/tty/serial/serial_core.c
51468@@ -1448,7 +1448,7 @@ static void uart_hangup(struct tty_struct *tty)
51469 uart_flush_buffer(tty);
51470 uart_shutdown(tty, state);
51471 spin_lock_irqsave(&port->lock, flags);
51472- port->count = 0;
51473+ atomic_set(&port->count, 0);
51474 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
51475 spin_unlock_irqrestore(&port->lock, flags);
51476 tty_port_tty_set(port, NULL);
51477@@ -1544,7 +1544,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51478 goto end;
51479 }
51480
51481- port->count++;
51482+ atomic_inc(&port->count);
51483 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
51484 retval = -ENXIO;
51485 goto err_dec_count;
51486@@ -1572,7 +1572,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51487 /*
51488 * Make sure the device is in D0 state.
51489 */
51490- if (port->count == 1)
51491+ if (atomic_read(&port->count) == 1)
51492 uart_change_pm(state, UART_PM_STATE_ON);
51493
51494 /*
51495@@ -1590,7 +1590,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51496 end:
51497 return retval;
51498 err_dec_count:
51499- port->count--;
51500+ atomic_inc(&port->count);
51501 mutex_unlock(&port->mutex);
51502 goto end;
51503 }
51504diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
51505index 5ae14b4..2c1288f 100644
51506--- a/drivers/tty/synclink.c
51507+++ b/drivers/tty/synclink.c
51508@@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
51509
51510 if (debug_level >= DEBUG_LEVEL_INFO)
51511 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
51512- __FILE__,__LINE__, info->device_name, info->port.count);
51513+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51514
51515 if (tty_port_close_start(&info->port, tty, filp) == 0)
51516 goto cleanup;
51517@@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
51518 cleanup:
51519 if (debug_level >= DEBUG_LEVEL_INFO)
51520 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
51521- tty->driver->name, info->port.count);
51522+ tty->driver->name, atomic_read(&info->port.count));
51523
51524 } /* end of mgsl_close() */
51525
51526@@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
51527
51528 mgsl_flush_buffer(tty);
51529 shutdown(info);
51530-
51531- info->port.count = 0;
51532+
51533+ atomic_set(&info->port.count, 0);
51534 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51535 info->port.tty = NULL;
51536
51537@@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51538
51539 if (debug_level >= DEBUG_LEVEL_INFO)
51540 printk("%s(%d):block_til_ready before block on %s count=%d\n",
51541- __FILE__,__LINE__, tty->driver->name, port->count );
51542+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51543
51544 spin_lock_irqsave(&info->irq_spinlock, flags);
51545 if (!tty_hung_up_p(filp)) {
51546 extra_count = true;
51547- port->count--;
51548+ atomic_dec(&port->count);
51549 }
51550 spin_unlock_irqrestore(&info->irq_spinlock, flags);
51551 port->blocked_open++;
51552@@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51553
51554 if (debug_level >= DEBUG_LEVEL_INFO)
51555 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
51556- __FILE__,__LINE__, tty->driver->name, port->count );
51557+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51558
51559 tty_unlock(tty);
51560 schedule();
51561@@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51562
51563 /* FIXME: Racy on hangup during close wait */
51564 if (extra_count)
51565- port->count++;
51566+ atomic_inc(&port->count);
51567 port->blocked_open--;
51568
51569 if (debug_level >= DEBUG_LEVEL_INFO)
51570 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
51571- __FILE__,__LINE__, tty->driver->name, port->count );
51572+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51573
51574 if (!retval)
51575 port->flags |= ASYNC_NORMAL_ACTIVE;
51576@@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
51577
51578 if (debug_level >= DEBUG_LEVEL_INFO)
51579 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
51580- __FILE__,__LINE__,tty->driver->name, info->port.count);
51581+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51582
51583 /* If port is closing, signal caller to try again */
51584 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51585@@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
51586 spin_unlock_irqrestore(&info->netlock, flags);
51587 goto cleanup;
51588 }
51589- info->port.count++;
51590+ atomic_inc(&info->port.count);
51591 spin_unlock_irqrestore(&info->netlock, flags);
51592
51593- if (info->port.count == 1) {
51594+ if (atomic_read(&info->port.count) == 1) {
51595 /* 1st open on this device, init hardware */
51596 retval = startup(info);
51597 if (retval < 0)
51598@@ -3446,8 +3446,8 @@ cleanup:
51599 if (retval) {
51600 if (tty->count == 1)
51601 info->port.tty = NULL; /* tty layer will release tty struct */
51602- if(info->port.count)
51603- info->port.count--;
51604+ if (atomic_read(&info->port.count))
51605+ atomic_dec(&info->port.count);
51606 }
51607
51608 return retval;
51609@@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51610 unsigned short new_crctype;
51611
51612 /* return error if TTY interface open */
51613- if (info->port.count)
51614+ if (atomic_read(&info->port.count))
51615 return -EBUSY;
51616
51617 switch (encoding)
51618@@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
51619
51620 /* arbitrate between network and tty opens */
51621 spin_lock_irqsave(&info->netlock, flags);
51622- if (info->port.count != 0 || info->netcount != 0) {
51623+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51624 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51625 spin_unlock_irqrestore(&info->netlock, flags);
51626 return -EBUSY;
51627@@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51628 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51629
51630 /* return error if TTY interface open */
51631- if (info->port.count)
51632+ if (atomic_read(&info->port.count))
51633 return -EBUSY;
51634
51635 if (cmd != SIOCWANDEV)
51636diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
51637index c359a91..959fc26 100644
51638--- a/drivers/tty/synclink_gt.c
51639+++ b/drivers/tty/synclink_gt.c
51640@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51641 tty->driver_data = info;
51642 info->port.tty = tty;
51643
51644- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
51645+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
51646
51647 /* If port is closing, signal caller to try again */
51648 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51649@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51650 mutex_unlock(&info->port.mutex);
51651 goto cleanup;
51652 }
51653- info->port.count++;
51654+ atomic_inc(&info->port.count);
51655 spin_unlock_irqrestore(&info->netlock, flags);
51656
51657- if (info->port.count == 1) {
51658+ if (atomic_read(&info->port.count) == 1) {
51659 /* 1st open on this device, init hardware */
51660 retval = startup(info);
51661 if (retval < 0) {
51662@@ -715,8 +715,8 @@ cleanup:
51663 if (retval) {
51664 if (tty->count == 1)
51665 info->port.tty = NULL; /* tty layer will release tty struct */
51666- if(info->port.count)
51667- info->port.count--;
51668+ if(atomic_read(&info->port.count))
51669+ atomic_dec(&info->port.count);
51670 }
51671
51672 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
51673@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51674
51675 if (sanity_check(info, tty->name, "close"))
51676 return;
51677- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
51678+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
51679
51680 if (tty_port_close_start(&info->port, tty, filp) == 0)
51681 goto cleanup;
51682@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51683 tty_port_close_end(&info->port, tty);
51684 info->port.tty = NULL;
51685 cleanup:
51686- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
51687+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
51688 }
51689
51690 static void hangup(struct tty_struct *tty)
51691@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
51692 shutdown(info);
51693
51694 spin_lock_irqsave(&info->port.lock, flags);
51695- info->port.count = 0;
51696+ atomic_set(&info->port.count, 0);
51697 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51698 info->port.tty = NULL;
51699 spin_unlock_irqrestore(&info->port.lock, flags);
51700@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51701 unsigned short new_crctype;
51702
51703 /* return error if TTY interface open */
51704- if (info->port.count)
51705+ if (atomic_read(&info->port.count))
51706 return -EBUSY;
51707
51708 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
51709@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
51710
51711 /* arbitrate between network and tty opens */
51712 spin_lock_irqsave(&info->netlock, flags);
51713- if (info->port.count != 0 || info->netcount != 0) {
51714+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51715 DBGINFO(("%s hdlc_open busy\n", dev->name));
51716 spin_unlock_irqrestore(&info->netlock, flags);
51717 return -EBUSY;
51718@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51719 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
51720
51721 /* return error if TTY interface open */
51722- if (info->port.count)
51723+ if (atomic_read(&info->port.count))
51724 return -EBUSY;
51725
51726 if (cmd != SIOCWANDEV)
51727@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
51728 if (port == NULL)
51729 continue;
51730 spin_lock(&port->lock);
51731- if ((port->port.count || port->netcount) &&
51732+ if ((atomic_read(&port->port.count) || port->netcount) &&
51733 port->pending_bh && !port->bh_running &&
51734 !port->bh_requested) {
51735 DBGISR(("%s bh queued\n", port->device_name));
51736@@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51737 spin_lock_irqsave(&info->lock, flags);
51738 if (!tty_hung_up_p(filp)) {
51739 extra_count = true;
51740- port->count--;
51741+ atomic_dec(&port->count);
51742 }
51743 spin_unlock_irqrestore(&info->lock, flags);
51744 port->blocked_open++;
51745@@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51746 remove_wait_queue(&port->open_wait, &wait);
51747
51748 if (extra_count)
51749- port->count++;
51750+ atomic_inc(&port->count);
51751 port->blocked_open--;
51752
51753 if (!retval)
51754diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
51755index 144202e..4ccb07d 100644
51756--- a/drivers/tty/synclinkmp.c
51757+++ b/drivers/tty/synclinkmp.c
51758@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51759
51760 if (debug_level >= DEBUG_LEVEL_INFO)
51761 printk("%s(%d):%s open(), old ref count = %d\n",
51762- __FILE__,__LINE__,tty->driver->name, info->port.count);
51763+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51764
51765 /* If port is closing, signal caller to try again */
51766 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51767@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51768 spin_unlock_irqrestore(&info->netlock, flags);
51769 goto cleanup;
51770 }
51771- info->port.count++;
51772+ atomic_inc(&info->port.count);
51773 spin_unlock_irqrestore(&info->netlock, flags);
51774
51775- if (info->port.count == 1) {
51776+ if (atomic_read(&info->port.count) == 1) {
51777 /* 1st open on this device, init hardware */
51778 retval = startup(info);
51779 if (retval < 0)
51780@@ -796,8 +796,8 @@ cleanup:
51781 if (retval) {
51782 if (tty->count == 1)
51783 info->port.tty = NULL; /* tty layer will release tty struct */
51784- if(info->port.count)
51785- info->port.count--;
51786+ if(atomic_read(&info->port.count))
51787+ atomic_dec(&info->port.count);
51788 }
51789
51790 return retval;
51791@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51792
51793 if (debug_level >= DEBUG_LEVEL_INFO)
51794 printk("%s(%d):%s close() entry, count=%d\n",
51795- __FILE__,__LINE__, info->device_name, info->port.count);
51796+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51797
51798 if (tty_port_close_start(&info->port, tty, filp) == 0)
51799 goto cleanup;
51800@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51801 cleanup:
51802 if (debug_level >= DEBUG_LEVEL_INFO)
51803 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
51804- tty->driver->name, info->port.count);
51805+ tty->driver->name, atomic_read(&info->port.count));
51806 }
51807
51808 /* Called by tty_hangup() when a hangup is signaled.
51809@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
51810 shutdown(info);
51811
51812 spin_lock_irqsave(&info->port.lock, flags);
51813- info->port.count = 0;
51814+ atomic_set(&info->port.count, 0);
51815 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51816 info->port.tty = NULL;
51817 spin_unlock_irqrestore(&info->port.lock, flags);
51818@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51819 unsigned short new_crctype;
51820
51821 /* return error if TTY interface open */
51822- if (info->port.count)
51823+ if (atomic_read(&info->port.count))
51824 return -EBUSY;
51825
51826 switch (encoding)
51827@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
51828
51829 /* arbitrate between network and tty opens */
51830 spin_lock_irqsave(&info->netlock, flags);
51831- if (info->port.count != 0 || info->netcount != 0) {
51832+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51833 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51834 spin_unlock_irqrestore(&info->netlock, flags);
51835 return -EBUSY;
51836@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51837 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51838
51839 /* return error if TTY interface open */
51840- if (info->port.count)
51841+ if (atomic_read(&info->port.count))
51842 return -EBUSY;
51843
51844 if (cmd != SIOCWANDEV)
51845@@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
51846 * do not request bottom half processing if the
51847 * device is not open in a normal mode.
51848 */
51849- if ( port && (port->port.count || port->netcount) &&
51850+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
51851 port->pending_bh && !port->bh_running &&
51852 !port->bh_requested ) {
51853 if ( debug_level >= DEBUG_LEVEL_ISR )
51854@@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51855
51856 if (debug_level >= DEBUG_LEVEL_INFO)
51857 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
51858- __FILE__,__LINE__, tty->driver->name, port->count );
51859+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51860
51861 spin_lock_irqsave(&info->lock, flags);
51862 if (!tty_hung_up_p(filp)) {
51863 extra_count = true;
51864- port->count--;
51865+ atomic_dec(&port->count);
51866 }
51867 spin_unlock_irqrestore(&info->lock, flags);
51868 port->blocked_open++;
51869@@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51870
51871 if (debug_level >= DEBUG_LEVEL_INFO)
51872 printk("%s(%d):%s block_til_ready() count=%d\n",
51873- __FILE__,__LINE__, tty->driver->name, port->count );
51874+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51875
51876 tty_unlock(tty);
51877 schedule();
51878@@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51879 remove_wait_queue(&port->open_wait, &wait);
51880
51881 if (extra_count)
51882- port->count++;
51883+ atomic_inc(&port->count);
51884 port->blocked_open--;
51885
51886 if (debug_level >= DEBUG_LEVEL_INFO)
51887 printk("%s(%d):%s block_til_ready() after, count=%d\n",
51888- __FILE__,__LINE__, tty->driver->name, port->count );
51889+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51890
51891 if (!retval)
51892 port->flags |= ASYNC_NORMAL_ACTIVE;
51893diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
51894index ce396ec..04a37be 100644
51895--- a/drivers/tty/sysrq.c
51896+++ b/drivers/tty/sysrq.c
51897@@ -1075,7 +1075,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
51898 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
51899 size_t count, loff_t *ppos)
51900 {
51901- if (count) {
51902+ if (count && capable(CAP_SYS_ADMIN)) {
51903 char c;
51904
51905 if (get_user(c, buf))
51906diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
51907index d3448a9..28e8db0 100644
51908--- a/drivers/tty/tty_io.c
51909+++ b/drivers/tty/tty_io.c
51910@@ -3475,7 +3475,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
51911
51912 void tty_default_fops(struct file_operations *fops)
51913 {
51914- *fops = tty_fops;
51915+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
51916 }
51917
51918 /*
51919diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
51920index 2d822aa..a566234 100644
51921--- a/drivers/tty/tty_ldisc.c
51922+++ b/drivers/tty/tty_ldisc.c
51923@@ -71,7 +71,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
51924 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51925 tty_ldiscs[disc] = new_ldisc;
51926 new_ldisc->num = disc;
51927- new_ldisc->refcount = 0;
51928+ atomic_set(&new_ldisc->refcount, 0);
51929 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
51930
51931 return ret;
51932@@ -99,7 +99,7 @@ int tty_unregister_ldisc(int disc)
51933 return -EINVAL;
51934
51935 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51936- if (tty_ldiscs[disc]->refcount)
51937+ if (atomic_read(&tty_ldiscs[disc]->refcount))
51938 ret = -EBUSY;
51939 else
51940 tty_ldiscs[disc] = NULL;
51941@@ -120,7 +120,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
51942 if (ldops) {
51943 ret = ERR_PTR(-EAGAIN);
51944 if (try_module_get(ldops->owner)) {
51945- ldops->refcount++;
51946+ atomic_inc(&ldops->refcount);
51947 ret = ldops;
51948 }
51949 }
51950@@ -133,7 +133,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
51951 unsigned long flags;
51952
51953 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51954- ldops->refcount--;
51955+ atomic_dec(&ldops->refcount);
51956 module_put(ldops->owner);
51957 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
51958 }
51959diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
51960index 3f746c8..2f2fcaa 100644
51961--- a/drivers/tty/tty_port.c
51962+++ b/drivers/tty/tty_port.c
51963@@ -235,7 +235,7 @@ void tty_port_hangup(struct tty_port *port)
51964 unsigned long flags;
51965
51966 spin_lock_irqsave(&port->lock, flags);
51967- port->count = 0;
51968+ atomic_set(&port->count, 0);
51969 port->flags &= ~ASYNC_NORMAL_ACTIVE;
51970 tty = port->tty;
51971 if (tty)
51972@@ -393,7 +393,7 @@ int tty_port_block_til_ready(struct tty_port *port,
51973 /* The port lock protects the port counts */
51974 spin_lock_irqsave(&port->lock, flags);
51975 if (!tty_hung_up_p(filp))
51976- port->count--;
51977+ atomic_dec(&port->count);
51978 port->blocked_open++;
51979 spin_unlock_irqrestore(&port->lock, flags);
51980
51981@@ -435,7 +435,7 @@ int tty_port_block_til_ready(struct tty_port *port,
51982 we must not mess that up further */
51983 spin_lock_irqsave(&port->lock, flags);
51984 if (!tty_hung_up_p(filp))
51985- port->count++;
51986+ atomic_inc(&port->count);
51987 port->blocked_open--;
51988 if (retval == 0)
51989 port->flags |= ASYNC_NORMAL_ACTIVE;
51990@@ -469,19 +469,19 @@ int tty_port_close_start(struct tty_port *port,
51991 return 0;
51992 }
51993
51994- if (tty->count == 1 && port->count != 1) {
51995+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
51996 printk(KERN_WARNING
51997 "tty_port_close_start: tty->count = 1 port count = %d.\n",
51998- port->count);
51999- port->count = 1;
52000+ atomic_read(&port->count));
52001+ atomic_set(&port->count, 1);
52002 }
52003- if (--port->count < 0) {
52004+ if (atomic_dec_return(&port->count) < 0) {
52005 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
52006- port->count);
52007- port->count = 0;
52008+ atomic_read(&port->count));
52009+ atomic_set(&port->count, 0);
52010 }
52011
52012- if (port->count) {
52013+ if (atomic_read(&port->count)) {
52014 spin_unlock_irqrestore(&port->lock, flags);
52015 return 0;
52016 }
52017@@ -563,7 +563,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
52018 {
52019 spin_lock_irq(&port->lock);
52020 if (!tty_hung_up_p(filp))
52021- ++port->count;
52022+ atomic_inc(&port->count);
52023 spin_unlock_irq(&port->lock);
52024 tty_port_tty_set(port, tty);
52025
52026diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
52027index d0e3a44..5f8b754 100644
52028--- a/drivers/tty/vt/keyboard.c
52029+++ b/drivers/tty/vt/keyboard.c
52030@@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
52031 kbd->kbdmode == VC_OFF) &&
52032 value != KVAL(K_SAK))
52033 return; /* SAK is allowed even in raw mode */
52034+
52035+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
52036+ {
52037+ void *func = fn_handler[value];
52038+ if (func == fn_show_state || func == fn_show_ptregs ||
52039+ func == fn_show_mem)
52040+ return;
52041+ }
52042+#endif
52043+
52044 fn_handler[value](vc);
52045 }
52046
52047@@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
52048 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
52049 return -EFAULT;
52050
52051- if (!capable(CAP_SYS_TTY_CONFIG))
52052- perm = 0;
52053-
52054 switch (cmd) {
52055 case KDGKBENT:
52056 /* Ensure another thread doesn't free it under us */
52057@@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
52058 spin_unlock_irqrestore(&kbd_event_lock, flags);
52059 return put_user(val, &user_kbe->kb_value);
52060 case KDSKBENT:
52061+ if (!capable(CAP_SYS_TTY_CONFIG))
52062+ perm = 0;
52063+
52064 if (!perm)
52065 return -EPERM;
52066 if (!i && v == K_NOSUCHMAP) {
52067@@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
52068 int i, j, k;
52069 int ret;
52070
52071- if (!capable(CAP_SYS_TTY_CONFIG))
52072- perm = 0;
52073-
52074 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
52075 if (!kbs) {
52076 ret = -ENOMEM;
52077@@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
52078 kfree(kbs);
52079 return ((p && *p) ? -EOVERFLOW : 0);
52080 case KDSKBSENT:
52081+ if (!capable(CAP_SYS_TTY_CONFIG))
52082+ perm = 0;
52083+
52084 if (!perm) {
52085 ret = -EPERM;
52086 goto reterr;
52087diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
52088index a673e5b..36e5d32 100644
52089--- a/drivers/uio/uio.c
52090+++ b/drivers/uio/uio.c
52091@@ -25,6 +25,7 @@
52092 #include <linux/kobject.h>
52093 #include <linux/cdev.h>
52094 #include <linux/uio_driver.h>
52095+#include <asm/local.h>
52096
52097 #define UIO_MAX_DEVICES (1U << MINORBITS)
52098
52099@@ -32,7 +33,7 @@ struct uio_device {
52100 struct module *owner;
52101 struct device *dev;
52102 int minor;
52103- atomic_t event;
52104+ atomic_unchecked_t event;
52105 struct fasync_struct *async_queue;
52106 wait_queue_head_t wait;
52107 struct uio_info *info;
52108@@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
52109 struct device_attribute *attr, char *buf)
52110 {
52111 struct uio_device *idev = dev_get_drvdata(dev);
52112- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
52113+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
52114 }
52115 static DEVICE_ATTR_RO(event);
52116
52117@@ -405,7 +406,7 @@ void uio_event_notify(struct uio_info *info)
52118 {
52119 struct uio_device *idev = info->uio_dev;
52120
52121- atomic_inc(&idev->event);
52122+ atomic_inc_unchecked(&idev->event);
52123 wake_up_interruptible(&idev->wait);
52124 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
52125 }
52126@@ -458,7 +459,7 @@ static int uio_open(struct inode *inode, struct file *filep)
52127 }
52128
52129 listener->dev = idev;
52130- listener->event_count = atomic_read(&idev->event);
52131+ listener->event_count = atomic_read_unchecked(&idev->event);
52132 filep->private_data = listener;
52133
52134 if (idev->info->open) {
52135@@ -509,7 +510,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
52136 return -EIO;
52137
52138 poll_wait(filep, &idev->wait, wait);
52139- if (listener->event_count != atomic_read(&idev->event))
52140+ if (listener->event_count != atomic_read_unchecked(&idev->event))
52141 return POLLIN | POLLRDNORM;
52142 return 0;
52143 }
52144@@ -534,7 +535,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
52145 do {
52146 set_current_state(TASK_INTERRUPTIBLE);
52147
52148- event_count = atomic_read(&idev->event);
52149+ event_count = atomic_read_unchecked(&idev->event);
52150 if (event_count != listener->event_count) {
52151 if (copy_to_user(buf, &event_count, count))
52152 retval = -EFAULT;
52153@@ -591,9 +592,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
52154 static int uio_find_mem_index(struct vm_area_struct *vma)
52155 {
52156 struct uio_device *idev = vma->vm_private_data;
52157+ unsigned long size;
52158
52159 if (vma->vm_pgoff < MAX_UIO_MAPS) {
52160- if (idev->info->mem[vma->vm_pgoff].size == 0)
52161+ size = idev->info->mem[vma->vm_pgoff].size;
52162+ if (size == 0)
52163+ return -1;
52164+ if (vma->vm_end - vma->vm_start > size)
52165 return -1;
52166 return (int)vma->vm_pgoff;
52167 }
52168@@ -825,7 +830,7 @@ int __uio_register_device(struct module *owner,
52169 idev->owner = owner;
52170 idev->info = info;
52171 init_waitqueue_head(&idev->wait);
52172- atomic_set(&idev->event, 0);
52173+ atomic_set_unchecked(&idev->event, 0);
52174
52175 ret = uio_get_minor(idev);
52176 if (ret)
52177diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
52178index 813d4d3..a71934f 100644
52179--- a/drivers/usb/atm/cxacru.c
52180+++ b/drivers/usb/atm/cxacru.c
52181@@ -472,7 +472,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
52182 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
52183 if (ret < 2)
52184 return -EINVAL;
52185- if (index < 0 || index > 0x7f)
52186+ if (index > 0x7f)
52187 return -EINVAL;
52188 pos += tmp;
52189
52190diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
52191index dada014..1d0d517 100644
52192--- a/drivers/usb/atm/usbatm.c
52193+++ b/drivers/usb/atm/usbatm.c
52194@@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52195 if (printk_ratelimit())
52196 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
52197 __func__, vpi, vci);
52198- atomic_inc(&vcc->stats->rx_err);
52199+ atomic_inc_unchecked(&vcc->stats->rx_err);
52200 return;
52201 }
52202
52203@@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52204 if (length > ATM_MAX_AAL5_PDU) {
52205 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
52206 __func__, length, vcc);
52207- atomic_inc(&vcc->stats->rx_err);
52208+ atomic_inc_unchecked(&vcc->stats->rx_err);
52209 goto out;
52210 }
52211
52212@@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52213 if (sarb->len < pdu_length) {
52214 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
52215 __func__, pdu_length, sarb->len, vcc);
52216- atomic_inc(&vcc->stats->rx_err);
52217+ atomic_inc_unchecked(&vcc->stats->rx_err);
52218 goto out;
52219 }
52220
52221 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
52222 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
52223 __func__, vcc);
52224- atomic_inc(&vcc->stats->rx_err);
52225+ atomic_inc_unchecked(&vcc->stats->rx_err);
52226 goto out;
52227 }
52228
52229@@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52230 if (printk_ratelimit())
52231 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
52232 __func__, length);
52233- atomic_inc(&vcc->stats->rx_drop);
52234+ atomic_inc_unchecked(&vcc->stats->rx_drop);
52235 goto out;
52236 }
52237
52238@@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52239
52240 vcc->push(vcc, skb);
52241
52242- atomic_inc(&vcc->stats->rx);
52243+ atomic_inc_unchecked(&vcc->stats->rx);
52244 out:
52245 skb_trim(sarb, 0);
52246 }
52247@@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
52248 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
52249
52250 usbatm_pop(vcc, skb);
52251- atomic_inc(&vcc->stats->tx);
52252+ atomic_inc_unchecked(&vcc->stats->tx);
52253
52254 skb = skb_dequeue(&instance->sndqueue);
52255 }
52256@@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page
52257 if (!left--)
52258 return sprintf(page,
52259 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
52260- atomic_read(&atm_dev->stats.aal5.tx),
52261- atomic_read(&atm_dev->stats.aal5.tx_err),
52262- atomic_read(&atm_dev->stats.aal5.rx),
52263- atomic_read(&atm_dev->stats.aal5.rx_err),
52264- atomic_read(&atm_dev->stats.aal5.rx_drop));
52265+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
52266+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
52267+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
52268+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
52269+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
52270
52271 if (!left--) {
52272 if (instance->disconnected)
52273diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
52274index 2a3bbdf..91d72cf 100644
52275--- a/drivers/usb/core/devices.c
52276+++ b/drivers/usb/core/devices.c
52277@@ -126,7 +126,7 @@ static const char format_endpt[] =
52278 * time it gets called.
52279 */
52280 static struct device_connect_event {
52281- atomic_t count;
52282+ atomic_unchecked_t count;
52283 wait_queue_head_t wait;
52284 } device_event = {
52285 .count = ATOMIC_INIT(1),
52286@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
52287
52288 void usbfs_conn_disc_event(void)
52289 {
52290- atomic_add(2, &device_event.count);
52291+ atomic_add_unchecked(2, &device_event.count);
52292 wake_up(&device_event.wait);
52293 }
52294
52295@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
52296
52297 poll_wait(file, &device_event.wait, wait);
52298
52299- event_count = atomic_read(&device_event.count);
52300+ event_count = atomic_read_unchecked(&device_event.count);
52301 if (file->f_version != event_count) {
52302 file->f_version = event_count;
52303 return POLLIN | POLLRDNORM;
52304diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
52305index 90e18f6..5eeda46 100644
52306--- a/drivers/usb/core/devio.c
52307+++ b/drivers/usb/core/devio.c
52308@@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
52309 struct dev_state *ps = file->private_data;
52310 struct usb_device *dev = ps->dev;
52311 ssize_t ret = 0;
52312- unsigned len;
52313+ size_t len;
52314 loff_t pos;
52315 int i;
52316
52317@@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
52318 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
52319 struct usb_config_descriptor *config =
52320 (struct usb_config_descriptor *)dev->rawdescriptors[i];
52321- unsigned int length = le16_to_cpu(config->wTotalLength);
52322+ size_t length = le16_to_cpu(config->wTotalLength);
52323
52324 if (*ppos < pos + length) {
52325
52326 /* The descriptor may claim to be longer than it
52327 * really is. Here is the actual allocated length. */
52328- unsigned alloclen =
52329+ size_t alloclen =
52330 le16_to_cpu(dev->config[i].desc.wTotalLength);
52331
52332- len = length - (*ppos - pos);
52333+ len = length + pos - *ppos;
52334 if (len > nbytes)
52335 len = nbytes;
52336
52337 /* Simply don't write (skip over) unallocated parts */
52338 if (alloclen > (*ppos - pos)) {
52339- alloclen -= (*ppos - pos);
52340+ alloclen = alloclen + pos - *ppos;
52341 if (copy_to_user(buf,
52342 dev->rawdescriptors[i] + (*ppos - pos),
52343 min(len, alloclen))) {
52344diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
52345index 2518c32..1c201bb 100644
52346--- a/drivers/usb/core/hcd.c
52347+++ b/drivers/usb/core/hcd.c
52348@@ -1550,7 +1550,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
52349 */
52350 usb_get_urb(urb);
52351 atomic_inc(&urb->use_count);
52352- atomic_inc(&urb->dev->urbnum);
52353+ atomic_inc_unchecked(&urb->dev->urbnum);
52354 usbmon_urb_submit(&hcd->self, urb);
52355
52356 /* NOTE requirements on root-hub callers (usbfs and the hub
52357@@ -1577,7 +1577,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
52358 urb->hcpriv = NULL;
52359 INIT_LIST_HEAD(&urb->urb_list);
52360 atomic_dec(&urb->use_count);
52361- atomic_dec(&urb->dev->urbnum);
52362+ atomic_dec_unchecked(&urb->dev->urbnum);
52363 if (atomic_read(&urb->reject))
52364 wake_up(&usb_kill_urb_queue);
52365 usb_put_urb(urb);
52366diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
52367index d498d03..e26f959 100644
52368--- a/drivers/usb/core/hub.c
52369+++ b/drivers/usb/core/hub.c
52370@@ -27,6 +27,7 @@
52371 #include <linux/freezer.h>
52372 #include <linux/random.h>
52373 #include <linux/pm_qos.h>
52374+#include <linux/grsecurity.h>
52375
52376 #include <asm/uaccess.h>
52377 #include <asm/byteorder.h>
52378@@ -4472,6 +4473,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
52379 goto done;
52380 return;
52381 }
52382+
52383+ if (gr_handle_new_usb())
52384+ goto done;
52385+
52386 if (hub_is_superspeed(hub->hdev))
52387 unit_load = 150;
52388 else
52389diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
52390index f829a1a..e6c334a 100644
52391--- a/drivers/usb/core/message.c
52392+++ b/drivers/usb/core/message.c
52393@@ -128,7 +128,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
52394 * Return: If successful, the number of bytes transferred. Otherwise, a negative
52395 * error number.
52396 */
52397-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
52398+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
52399 __u8 requesttype, __u16 value, __u16 index, void *data,
52400 __u16 size, int timeout)
52401 {
52402@@ -180,7 +180,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
52403 * If successful, 0. Otherwise a negative error number. The number of actual
52404 * bytes transferred will be stored in the @actual_length paramater.
52405 */
52406-int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
52407+int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
52408 void *data, int len, int *actual_length, int timeout)
52409 {
52410 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
52411@@ -220,7 +220,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
52412 * bytes transferred will be stored in the @actual_length parameter.
52413 *
52414 */
52415-int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
52416+int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
52417 void *data, int len, int *actual_length, int timeout)
52418 {
52419 struct urb *urb;
52420diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
52421index 1236c60..d47a51c 100644
52422--- a/drivers/usb/core/sysfs.c
52423+++ b/drivers/usb/core/sysfs.c
52424@@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
52425 struct usb_device *udev;
52426
52427 udev = to_usb_device(dev);
52428- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
52429+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
52430 }
52431 static DEVICE_ATTR_RO(urbnum);
52432
52433diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
52434index 4d11449..f4ccabf 100644
52435--- a/drivers/usb/core/usb.c
52436+++ b/drivers/usb/core/usb.c
52437@@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
52438 set_dev_node(&dev->dev, dev_to_node(bus->controller));
52439 dev->state = USB_STATE_ATTACHED;
52440 dev->lpm_disable_count = 1;
52441- atomic_set(&dev->urbnum, 0);
52442+ atomic_set_unchecked(&dev->urbnum, 0);
52443
52444 INIT_LIST_HEAD(&dev->ep0.urb_list);
52445 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
52446diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
52447index 2da0a5a..4870e09 100644
52448--- a/drivers/usb/dwc3/gadget.c
52449+++ b/drivers/usb/dwc3/gadget.c
52450@@ -532,8 +532,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
52451 if (!usb_endpoint_xfer_isoc(desc))
52452 return 0;
52453
52454- memset(&trb_link, 0, sizeof(trb_link));
52455-
52456 /* Link TRB for ISOC. The HWO bit is never reset */
52457 trb_st_hw = &dep->trb_pool[0];
52458
52459diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
52460index 8cfc319..4868255 100644
52461--- a/drivers/usb/early/ehci-dbgp.c
52462+++ b/drivers/usb/early/ehci-dbgp.c
52463@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
52464
52465 #ifdef CONFIG_KGDB
52466 static struct kgdb_io kgdbdbgp_io_ops;
52467-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
52468+static struct kgdb_io kgdbdbgp_io_ops_console;
52469+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
52470 #else
52471 #define dbgp_kgdb_mode (0)
52472 #endif
52473@@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
52474 .write_char = kgdbdbgp_write_char,
52475 };
52476
52477+static struct kgdb_io kgdbdbgp_io_ops_console = {
52478+ .name = "kgdbdbgp",
52479+ .read_char = kgdbdbgp_read_char,
52480+ .write_char = kgdbdbgp_write_char,
52481+ .is_console = 1
52482+};
52483+
52484 static int kgdbdbgp_wait_time;
52485
52486 static int __init kgdbdbgp_parse_config(char *str)
52487@@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
52488 ptr++;
52489 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
52490 }
52491- kgdb_register_io_module(&kgdbdbgp_io_ops);
52492- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
52493+ if (early_dbgp_console.index != -1)
52494+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
52495+ else
52496+ kgdb_register_io_module(&kgdbdbgp_io_ops);
52497
52498 return 0;
52499 }
52500diff --git a/drivers/usb/gadget/f_uac1.c b/drivers/usb/gadget/f_uac1.c
52501index 2b4c82d..06a8ee6 100644
52502--- a/drivers/usb/gadget/f_uac1.c
52503+++ b/drivers/usb/gadget/f_uac1.c
52504@@ -13,6 +13,7 @@
52505 #include <linux/kernel.h>
52506 #include <linux/device.h>
52507 #include <linux/atomic.h>
52508+#include <linux/module.h>
52509
52510 #include "u_uac1.h"
52511
52512diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
52513index ad0aca8..8ff84865 100644
52514--- a/drivers/usb/gadget/u_serial.c
52515+++ b/drivers/usb/gadget/u_serial.c
52516@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
52517 spin_lock_irq(&port->port_lock);
52518
52519 /* already open? Great. */
52520- if (port->port.count) {
52521+ if (atomic_read(&port->port.count)) {
52522 status = 0;
52523- port->port.count++;
52524+ atomic_inc(&port->port.count);
52525
52526 /* currently opening/closing? wait ... */
52527 } else if (port->openclose) {
52528@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
52529 tty->driver_data = port;
52530 port->port.tty = tty;
52531
52532- port->port.count = 1;
52533+ atomic_set(&port->port.count, 1);
52534 port->openclose = false;
52535
52536 /* if connected, start the I/O stream */
52537@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
52538
52539 spin_lock_irq(&port->port_lock);
52540
52541- if (port->port.count != 1) {
52542- if (port->port.count == 0)
52543+ if (atomic_read(&port->port.count) != 1) {
52544+ if (atomic_read(&port->port.count) == 0)
52545 WARN_ON(1);
52546 else
52547- --port->port.count;
52548+ atomic_dec(&port->port.count);
52549 goto exit;
52550 }
52551
52552@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
52553 * and sleep if necessary
52554 */
52555 port->openclose = true;
52556- port->port.count = 0;
52557+ atomic_set(&port->port.count, 0);
52558
52559 gser = port->port_usb;
52560 if (gser && gser->disconnect)
52561@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
52562 int cond;
52563
52564 spin_lock_irq(&port->port_lock);
52565- cond = (port->port.count == 0) && !port->openclose;
52566+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
52567 spin_unlock_irq(&port->port_lock);
52568 return cond;
52569 }
52570@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
52571 /* if it's already open, start I/O ... and notify the serial
52572 * protocol about open/close status (connect/disconnect).
52573 */
52574- if (port->port.count) {
52575+ if (atomic_read(&port->port.count)) {
52576 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
52577 gs_start_io(port);
52578 if (gser->connect)
52579@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
52580
52581 port->port_usb = NULL;
52582 gser->ioport = NULL;
52583- if (port->port.count > 0 || port->openclose) {
52584+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
52585 wake_up_interruptible(&port->drain_wait);
52586 if (port->port.tty)
52587 tty_hangup(port->port.tty);
52588@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
52589
52590 /* finally, free any unused/unusable I/O buffers */
52591 spin_lock_irqsave(&port->port_lock, flags);
52592- if (port->port.count == 0 && !port->openclose)
52593+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
52594 gs_buf_free(&port->port_write_buf);
52595 gs_free_requests(gser->out, &port->read_pool, NULL);
52596 gs_free_requests(gser->out, &port->read_queue, NULL);
52597diff --git a/drivers/usb/gadget/u_uac1.c b/drivers/usb/gadget/u_uac1.c
52598index 7a55fea..cc0ed4f 100644
52599--- a/drivers/usb/gadget/u_uac1.c
52600+++ b/drivers/usb/gadget/u_uac1.c
52601@@ -16,6 +16,7 @@
52602 #include <linux/ctype.h>
52603 #include <linux/random.h>
52604 #include <linux/syscalls.h>
52605+#include <linux/module.h>
52606
52607 #include "u_uac1.h"
52608
52609diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
52610index 7ae0c4d..35521b7 100644
52611--- a/drivers/usb/host/ehci-hub.c
52612+++ b/drivers/usb/host/ehci-hub.c
52613@@ -780,7 +780,7 @@ static struct urb *request_single_step_set_feature_urb(
52614 urb->transfer_flags = URB_DIR_IN;
52615 usb_get_urb(urb);
52616 atomic_inc(&urb->use_count);
52617- atomic_inc(&urb->dev->urbnum);
52618+ atomic_inc_unchecked(&urb->dev->urbnum);
52619 urb->setup_dma = dma_map_single(
52620 hcd->self.controller,
52621 urb->setup_packet,
52622@@ -847,7 +847,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
52623 urb->status = -EINPROGRESS;
52624 usb_get_urb(urb);
52625 atomic_inc(&urb->use_count);
52626- atomic_inc(&urb->dev->urbnum);
52627+ atomic_inc_unchecked(&urb->dev->urbnum);
52628 retval = submit_single_step_set_feature(hcd, urb, 0);
52629 if (!retval && !wait_for_completion_timeout(&done,
52630 msecs_to_jiffies(2000))) {
52631diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
52632index ba6a5d6..f88f7f3 100644
52633--- a/drivers/usb/misc/appledisplay.c
52634+++ b/drivers/usb/misc/appledisplay.c
52635@@ -83,7 +83,7 @@ struct appledisplay {
52636 spinlock_t lock;
52637 };
52638
52639-static atomic_t count_displays = ATOMIC_INIT(0);
52640+static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
52641 static struct workqueue_struct *wq;
52642
52643 static void appledisplay_complete(struct urb *urb)
52644@@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
52645
52646 /* Register backlight device */
52647 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
52648- atomic_inc_return(&count_displays) - 1);
52649+ atomic_inc_return_unchecked(&count_displays) - 1);
52650 memset(&props, 0, sizeof(struct backlight_properties));
52651 props.type = BACKLIGHT_RAW;
52652 props.max_brightness = 0xff;
52653diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
52654index 8d7fc48..01c4986 100644
52655--- a/drivers/usb/serial/console.c
52656+++ b/drivers/usb/serial/console.c
52657@@ -123,7 +123,7 @@ static int usb_console_setup(struct console *co, char *options)
52658
52659 info->port = port;
52660
52661- ++port->port.count;
52662+ atomic_inc(&port->port.count);
52663 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
52664 if (serial->type->set_termios) {
52665 /*
52666@@ -167,7 +167,7 @@ static int usb_console_setup(struct console *co, char *options)
52667 }
52668 /* Now that any required fake tty operations are completed restore
52669 * the tty port count */
52670- --port->port.count;
52671+ atomic_dec(&port->port.count);
52672 /* The console is special in terms of closing the device so
52673 * indicate this port is now acting as a system console. */
52674 port->port.console = 1;
52675@@ -180,7 +180,7 @@ static int usb_console_setup(struct console *co, char *options)
52676 free_tty:
52677 kfree(tty);
52678 reset_open_count:
52679- port->port.count = 0;
52680+ atomic_set(&port->port.count, 0);
52681 usb_autopm_put_interface(serial->interface);
52682 error_get_interface:
52683 usb_serial_put(serial);
52684@@ -191,7 +191,7 @@ static int usb_console_setup(struct console *co, char *options)
52685 static void usb_console_write(struct console *co,
52686 const char *buf, unsigned count)
52687 {
52688- static struct usbcons_info *info = &usbcons_info;
52689+ struct usbcons_info *info = &usbcons_info;
52690 struct usb_serial_port *port = info->port;
52691 struct usb_serial *serial;
52692 int retval = -ENODEV;
52693diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
52694index 75f70f0..d467e1a 100644
52695--- a/drivers/usb/storage/usb.h
52696+++ b/drivers/usb/storage/usb.h
52697@@ -63,7 +63,7 @@ struct us_unusual_dev {
52698 __u8 useProtocol;
52699 __u8 useTransport;
52700 int (*initFunction)(struct us_data *);
52701-};
52702+} __do_const;
52703
52704
52705 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
52706diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
52707index a2ef84b..aa7c2b8 100644
52708--- a/drivers/usb/wusbcore/wa-hc.h
52709+++ b/drivers/usb/wusbcore/wa-hc.h
52710@@ -225,7 +225,7 @@ struct wahc {
52711 spinlock_t xfer_list_lock;
52712 struct work_struct xfer_enqueue_work;
52713 struct work_struct xfer_error_work;
52714- atomic_t xfer_id_count;
52715+ atomic_unchecked_t xfer_id_count;
52716
52717 kernel_ulong_t quirks;
52718 };
52719@@ -287,7 +287,7 @@ static inline void wa_init(struct wahc *wa)
52720 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
52721 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
52722 wa->dto_in_use = 0;
52723- atomic_set(&wa->xfer_id_count, 1);
52724+ atomic_set_unchecked(&wa->xfer_id_count, 1);
52725 }
52726
52727 /**
52728diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
52729index 3cd96e9..bd7c58d 100644
52730--- a/drivers/usb/wusbcore/wa-xfer.c
52731+++ b/drivers/usb/wusbcore/wa-xfer.c
52732@@ -312,7 +312,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
52733 */
52734 static void wa_xfer_id_init(struct wa_xfer *xfer)
52735 {
52736- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
52737+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
52738 }
52739
52740 /* Return the xfer's ID. */
52741diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
52742index 21271d8..45b55a0 100644
52743--- a/drivers/vfio/vfio.c
52744+++ b/drivers/vfio/vfio.c
52745@@ -487,7 +487,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
52746 return 0;
52747
52748 /* TODO Prevent device auto probing */
52749- WARN("Device %s added to live group %d!\n", dev_name(dev),
52750+ WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
52751 iommu_group_id(group->iommu_group));
52752
52753 return 0;
52754diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
52755index 5174eba..451e6bc 100644
52756--- a/drivers/vhost/vringh.c
52757+++ b/drivers/vhost/vringh.c
52758@@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
52759 /* Userspace access helpers: in this case, addresses are really userspace. */
52760 static inline int getu16_user(u16 *val, const u16 *p)
52761 {
52762- return get_user(*val, (__force u16 __user *)p);
52763+ return get_user(*val, (u16 __force_user *)p);
52764 }
52765
52766 static inline int putu16_user(u16 *p, u16 val)
52767 {
52768- return put_user(val, (__force u16 __user *)p);
52769+ return put_user(val, (u16 __force_user *)p);
52770 }
52771
52772 static inline int copydesc_user(void *dst, const void *src, size_t len)
52773 {
52774- return copy_from_user(dst, (__force void __user *)src, len) ?
52775+ return copy_from_user(dst, (void __force_user *)src, len) ?
52776 -EFAULT : 0;
52777 }
52778
52779@@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
52780 const struct vring_used_elem *src,
52781 unsigned int num)
52782 {
52783- return copy_to_user((__force void __user *)dst, src,
52784+ return copy_to_user((void __force_user *)dst, src,
52785 sizeof(*dst) * num) ? -EFAULT : 0;
52786 }
52787
52788 static inline int xfer_from_user(void *src, void *dst, size_t len)
52789 {
52790- return copy_from_user(dst, (__force void __user *)src, len) ?
52791+ return copy_from_user(dst, (void __force_user *)src, len) ?
52792 -EFAULT : 0;
52793 }
52794
52795 static inline int xfer_to_user(void *dst, void *src, size_t len)
52796 {
52797- return copy_to_user((__force void __user *)dst, src, len) ?
52798+ return copy_to_user((void __force_user *)dst, src, len) ?
52799 -EFAULT : 0;
52800 }
52801
52802@@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
52803 vrh->last_used_idx = 0;
52804 vrh->vring.num = num;
52805 /* vring expects kernel addresses, but only used via accessors. */
52806- vrh->vring.desc = (__force struct vring_desc *)desc;
52807- vrh->vring.avail = (__force struct vring_avail *)avail;
52808- vrh->vring.used = (__force struct vring_used *)used;
52809+ vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
52810+ vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
52811+ vrh->vring.used = (__force_kernel struct vring_used *)used;
52812 return 0;
52813 }
52814 EXPORT_SYMBOL(vringh_init_user);
52815@@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
52816
52817 static inline int putu16_kern(u16 *p, u16 val)
52818 {
52819- ACCESS_ONCE(*p) = val;
52820+ ACCESS_ONCE_RW(*p) = val;
52821 return 0;
52822 }
52823
52824diff --git a/drivers/video/arcfb.c b/drivers/video/arcfb.c
52825index 1b0b233..6f34c2c 100644
52826--- a/drivers/video/arcfb.c
52827+++ b/drivers/video/arcfb.c
52828@@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
52829 return -ENOSPC;
52830
52831 err = 0;
52832- if ((count + p) > fbmemlength) {
52833+ if (count > (fbmemlength - p)) {
52834 count = fbmemlength - p;
52835 err = -ENOSPC;
52836 }
52837diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
52838index 52108be..c7c110d 100644
52839--- a/drivers/video/aty/aty128fb.c
52840+++ b/drivers/video/aty/aty128fb.c
52841@@ -149,7 +149,7 @@ enum {
52842 };
52843
52844 /* Must match above enum */
52845-static char * const r128_family[] = {
52846+static const char * const r128_family[] = {
52847 "AGP",
52848 "PCI",
52849 "PRO AGP",
52850diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
52851index 28fafbf..ae91651 100644
52852--- a/drivers/video/aty/atyfb_base.c
52853+++ b/drivers/video/aty/atyfb_base.c
52854@@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
52855 par->accel_flags = var->accel_flags; /* hack */
52856
52857 if (var->accel_flags) {
52858- info->fbops->fb_sync = atyfb_sync;
52859+ pax_open_kernel();
52860+ *(void **)&info->fbops->fb_sync = atyfb_sync;
52861+ pax_close_kernel();
52862 info->flags &= ~FBINFO_HWACCEL_DISABLED;
52863 } else {
52864- info->fbops->fb_sync = NULL;
52865+ pax_open_kernel();
52866+ *(void **)&info->fbops->fb_sync = NULL;
52867+ pax_close_kernel();
52868 info->flags |= FBINFO_HWACCEL_DISABLED;
52869 }
52870
52871diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
52872index 0fe02e2..ab01b26 100644
52873--- a/drivers/video/aty/mach64_cursor.c
52874+++ b/drivers/video/aty/mach64_cursor.c
52875@@ -8,6 +8,7 @@
52876 #include "../fb_draw.h"
52877
52878 #include <asm/io.h>
52879+#include <asm/pgtable.h>
52880
52881 #ifdef __sparc__
52882 #include <asm/fbio.h>
52883@@ -218,7 +219,9 @@ int aty_init_cursor(struct fb_info *info)
52884 info->sprite.buf_align = 16; /* and 64 lines tall. */
52885 info->sprite.flags = FB_PIXMAP_IO;
52886
52887- info->fbops->fb_cursor = atyfb_cursor;
52888+ pax_open_kernel();
52889+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
52890+ pax_close_kernel();
52891
52892 return 0;
52893 }
52894diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
52895index 84a110a..96312c3 100644
52896--- a/drivers/video/backlight/kb3886_bl.c
52897+++ b/drivers/video/backlight/kb3886_bl.c
52898@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
52899 static unsigned long kb3886bl_flags;
52900 #define KB3886BL_SUSPENDED 0x01
52901
52902-static struct dmi_system_id kb3886bl_device_table[] __initdata = {
52903+static const struct dmi_system_id kb3886bl_device_table[] __initconst = {
52904 {
52905 .ident = "Sahara Touch-iT",
52906 .matches = {
52907diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
52908index 900aa4e..6d49418 100644
52909--- a/drivers/video/fb_defio.c
52910+++ b/drivers/video/fb_defio.c
52911@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
52912
52913 BUG_ON(!fbdefio);
52914 mutex_init(&fbdefio->lock);
52915- info->fbops->fb_mmap = fb_deferred_io_mmap;
52916+ pax_open_kernel();
52917+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
52918+ pax_close_kernel();
52919 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
52920 INIT_LIST_HEAD(&fbdefio->pagelist);
52921 if (fbdefio->delay == 0) /* set a default of 1 s */
52922@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
52923 page->mapping = NULL;
52924 }
52925
52926- info->fbops->fb_mmap = NULL;
52927+ *(void **)&info->fbops->fb_mmap = NULL;
52928 mutex_destroy(&fbdefio->lock);
52929 }
52930 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
52931diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
52932index 7309ac7..be3c49c 100644
52933--- a/drivers/video/fbmem.c
52934+++ b/drivers/video/fbmem.c
52935@@ -433,7 +433,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
52936 image->dx += image->width + 8;
52937 }
52938 } else if (rotate == FB_ROTATE_UD) {
52939- for (x = 0; x < num && image->dx >= 0; x++) {
52940+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
52941 info->fbops->fb_imageblit(info, image);
52942 image->dx -= image->width + 8;
52943 }
52944@@ -445,7 +445,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
52945 image->dy += image->height + 8;
52946 }
52947 } else if (rotate == FB_ROTATE_CCW) {
52948- for (x = 0; x < num && image->dy >= 0; x++) {
52949+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
52950 info->fbops->fb_imageblit(info, image);
52951 image->dy -= image->height + 8;
52952 }
52953@@ -1179,7 +1179,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
52954 return -EFAULT;
52955 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
52956 return -EINVAL;
52957- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
52958+ if (con2fb.framebuffer >= FB_MAX)
52959 return -EINVAL;
52960 if (!registered_fb[con2fb.framebuffer])
52961 request_module("fb%d", con2fb.framebuffer);
52962@@ -1300,7 +1300,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
52963 __u32 data;
52964 int err;
52965
52966- err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
52967+ err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
52968
52969 data = (__u32) (unsigned long) fix->smem_start;
52970 err |= put_user(data, &fix32->smem_start);
52971diff --git a/drivers/video/hyperv_fb.c b/drivers/video/hyperv_fb.c
52972index 130708f..cdac1a9 100644
52973--- a/drivers/video/hyperv_fb.c
52974+++ b/drivers/video/hyperv_fb.c
52975@@ -233,7 +233,7 @@ static uint screen_fb_size;
52976 static inline int synthvid_send(struct hv_device *hdev,
52977 struct synthvid_msg *msg)
52978 {
52979- static atomic64_t request_id = ATOMIC64_INIT(0);
52980+ static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
52981 int ret;
52982
52983 msg->pipe_hdr.type = PIPE_MSG_DATA;
52984@@ -241,7 +241,7 @@ static inline int synthvid_send(struct hv_device *hdev,
52985
52986 ret = vmbus_sendpacket(hdev->channel, msg,
52987 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
52988- atomic64_inc_return(&request_id),
52989+ atomic64_inc_return_unchecked(&request_id),
52990 VM_PKT_DATA_INBAND, 0);
52991
52992 if (ret)
52993diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
52994index 7672d2e..b56437f 100644
52995--- a/drivers/video/i810/i810_accel.c
52996+++ b/drivers/video/i810/i810_accel.c
52997@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
52998 }
52999 }
53000 printk("ringbuffer lockup!!!\n");
53001+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
53002 i810_report_error(mmio);
53003 par->dev_flags |= LOCKUP;
53004 info->pixmap.scan_align = 1;
53005diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
53006index 3c14e43..2630570 100644
53007--- a/drivers/video/logo/logo_linux_clut224.ppm
53008+++ b/drivers/video/logo/logo_linux_clut224.ppm
53009@@ -2,1603 +2,1123 @@ P3
53010 # Standard 224-color Linux logo
53011 80 80
53012 255
53013- 0 0 0 0 0 0 0 0 0 0 0 0
53014- 0 0 0 0 0 0 0 0 0 0 0 0
53015- 0 0 0 0 0 0 0 0 0 0 0 0
53016- 0 0 0 0 0 0 0 0 0 0 0 0
53017- 0 0 0 0 0 0 0 0 0 0 0 0
53018- 0 0 0 0 0 0 0 0 0 0 0 0
53019- 0 0 0 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- 6 6 6 6 6 6 10 10 10 10 10 10
53023- 10 10 10 6 6 6 6 6 6 6 6 6
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 0 0 0 0 0 0 0 0 0
53027- 0 0 0 0 0 0 0 0 0 0 0 0
53028- 0 0 0 0 0 0 0 0 0 0 0 0
53029- 0 0 0 0 0 0 0 0 0 0 0 0
53030- 0 0 0 0 0 0 0 0 0 0 0 0
53031- 0 0 0 0 0 0 0 0 0 0 0 0
53032- 0 0 0 0 0 0 0 0 0 0 0 0
53033- 0 0 0 0 0 0 0 0 0 0 0 0
53034- 0 0 0 0 0 0 0 0 0 0 0 0
53035- 0 0 0 0 0 0 0 0 0 0 0 0
53036- 0 0 0 0 0 0 0 0 0 0 0 0
53037- 0 0 0 0 0 0 0 0 0 0 0 0
53038- 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 10 10 10 14 14 14
53042- 22 22 22 26 26 26 30 30 30 34 34 34
53043- 30 30 30 30 30 30 26 26 26 18 18 18
53044- 14 14 14 10 10 10 6 6 6 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 0 0 0 0 0 0 0 0 0
53048- 0 0 0 0 0 0 0 0 0 0 0 0
53049- 0 0 0 0 0 0 0 0 0 0 0 0
53050- 0 0 0 0 0 0 0 0 0 0 0 0
53051- 0 0 0 0 0 0 0 0 0 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 1 0 0 1 0 0 0
53055- 0 0 0 0 0 0 0 0 0 0 0 0
53056- 0 0 0 0 0 0 0 0 0 0 0 0
53057- 0 0 0 0 0 0 0 0 0 0 0 0
53058- 0 0 0 0 0 0 0 0 0 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- 6 6 6 14 14 14 26 26 26 42 42 42
53062- 54 54 54 66 66 66 78 78 78 78 78 78
53063- 78 78 78 74 74 74 66 66 66 54 54 54
53064- 42 42 42 26 26 26 18 18 18 10 10 10
53065- 6 6 6 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- 0 0 0 0 0 0 0 0 0 0 0 0
53069- 0 0 0 0 0 0 0 0 0 0 0 0
53070- 0 0 0 0 0 0 0 0 0 0 0 0
53071- 0 0 0 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 1 0 0 0 0 0 0 0 0 0
53075- 0 0 0 0 0 0 0 0 0 0 0 0
53076- 0 0 0 0 0 0 0 0 0 0 0 0
53077- 0 0 0 0 0 0 0 0 0 0 0 0
53078- 0 0 0 0 0 0 0 0 0 0 0 0
53079- 0 0 0 0 0 0 0 0 0 0 0 0
53080- 0 0 0 0 0 0 0 0 0 10 10 10
53081- 22 22 22 42 42 42 66 66 66 86 86 86
53082- 66 66 66 38 38 38 38 38 38 22 22 22
53083- 26 26 26 34 34 34 54 54 54 66 66 66
53084- 86 86 86 70 70 70 46 46 46 26 26 26
53085- 14 14 14 6 6 6 0 0 0 0 0 0
53086- 0 0 0 0 0 0 0 0 0 0 0 0
53087- 0 0 0 0 0 0 0 0 0 0 0 0
53088- 0 0 0 0 0 0 0 0 0 0 0 0
53089- 0 0 0 0 0 0 0 0 0 0 0 0
53090- 0 0 0 0 0 0 0 0 0 0 0 0
53091- 0 0 0 0 0 0 0 0 0 0 0 0
53092- 0 0 0 0 0 0 0 0 0 0 0 0
53093- 0 0 0 0 0 0 0 0 0 0 0 0
53094- 0 0 1 0 0 1 0 0 1 0 0 0
53095- 0 0 0 0 0 0 0 0 0 0 0 0
53096- 0 0 0 0 0 0 0 0 0 0 0 0
53097- 0 0 0 0 0 0 0 0 0 0 0 0
53098- 0 0 0 0 0 0 0 0 0 0 0 0
53099- 0 0 0 0 0 0 0 0 0 0 0 0
53100- 0 0 0 0 0 0 10 10 10 26 26 26
53101- 50 50 50 82 82 82 58 58 58 6 6 6
53102- 2 2 6 2 2 6 2 2 6 2 2 6
53103- 2 2 6 2 2 6 2 2 6 2 2 6
53104- 6 6 6 54 54 54 86 86 86 66 66 66
53105- 38 38 38 18 18 18 6 6 6 0 0 0
53106- 0 0 0 0 0 0 0 0 0 0 0 0
53107- 0 0 0 0 0 0 0 0 0 0 0 0
53108- 0 0 0 0 0 0 0 0 0 0 0 0
53109- 0 0 0 0 0 0 0 0 0 0 0 0
53110- 0 0 0 0 0 0 0 0 0 0 0 0
53111- 0 0 0 0 0 0 0 0 0 0 0 0
53112- 0 0 0 0 0 0 0 0 0 0 0 0
53113- 0 0 0 0 0 0 0 0 0 0 0 0
53114- 0 0 0 0 0 0 0 0 0 0 0 0
53115- 0 0 0 0 0 0 0 0 0 0 0 0
53116- 0 0 0 0 0 0 0 0 0 0 0 0
53117- 0 0 0 0 0 0 0 0 0 0 0 0
53118- 0 0 0 0 0 0 0 0 0 0 0 0
53119- 0 0 0 0 0 0 0 0 0 0 0 0
53120- 0 0 0 6 6 6 22 22 22 50 50 50
53121- 78 78 78 34 34 34 2 2 6 2 2 6
53122- 2 2 6 2 2 6 2 2 6 2 2 6
53123- 2 2 6 2 2 6 2 2 6 2 2 6
53124- 2 2 6 2 2 6 6 6 6 70 70 70
53125- 78 78 78 46 46 46 22 22 22 6 6 6
53126- 0 0 0 0 0 0 0 0 0 0 0 0
53127- 0 0 0 0 0 0 0 0 0 0 0 0
53128- 0 0 0 0 0 0 0 0 0 0 0 0
53129- 0 0 0 0 0 0 0 0 0 0 0 0
53130- 0 0 0 0 0 0 0 0 0 0 0 0
53131- 0 0 0 0 0 0 0 0 0 0 0 0
53132- 0 0 0 0 0 0 0 0 0 0 0 0
53133- 0 0 0 0 0 0 0 0 0 0 0 0
53134- 0 0 1 0 0 1 0 0 1 0 0 0
53135- 0 0 0 0 0 0 0 0 0 0 0 0
53136- 0 0 0 0 0 0 0 0 0 0 0 0
53137- 0 0 0 0 0 0 0 0 0 0 0 0
53138- 0 0 0 0 0 0 0 0 0 0 0 0
53139- 0 0 0 0 0 0 0 0 0 0 0 0
53140- 6 6 6 18 18 18 42 42 42 82 82 82
53141- 26 26 26 2 2 6 2 2 6 2 2 6
53142- 2 2 6 2 2 6 2 2 6 2 2 6
53143- 2 2 6 2 2 6 2 2 6 14 14 14
53144- 46 46 46 34 34 34 6 6 6 2 2 6
53145- 42 42 42 78 78 78 42 42 42 18 18 18
53146- 6 6 6 0 0 0 0 0 0 0 0 0
53147- 0 0 0 0 0 0 0 0 0 0 0 0
53148- 0 0 0 0 0 0 0 0 0 0 0 0
53149- 0 0 0 0 0 0 0 0 0 0 0 0
53150- 0 0 0 0 0 0 0 0 0 0 0 0
53151- 0 0 0 0 0 0 0 0 0 0 0 0
53152- 0 0 0 0 0 0 0 0 0 0 0 0
53153- 0 0 0 0 0 0 0 0 0 0 0 0
53154- 0 0 1 0 0 0 0 0 1 0 0 0
53155- 0 0 0 0 0 0 0 0 0 0 0 0
53156- 0 0 0 0 0 0 0 0 0 0 0 0
53157- 0 0 0 0 0 0 0 0 0 0 0 0
53158- 0 0 0 0 0 0 0 0 0 0 0 0
53159- 0 0 0 0 0 0 0 0 0 0 0 0
53160- 10 10 10 30 30 30 66 66 66 58 58 58
53161- 2 2 6 2 2 6 2 2 6 2 2 6
53162- 2 2 6 2 2 6 2 2 6 2 2 6
53163- 2 2 6 2 2 6 2 2 6 26 26 26
53164- 86 86 86 101 101 101 46 46 46 10 10 10
53165- 2 2 6 58 58 58 70 70 70 34 34 34
53166- 10 10 10 0 0 0 0 0 0 0 0 0
53167- 0 0 0 0 0 0 0 0 0 0 0 0
53168- 0 0 0 0 0 0 0 0 0 0 0 0
53169- 0 0 0 0 0 0 0 0 0 0 0 0
53170- 0 0 0 0 0 0 0 0 0 0 0 0
53171- 0 0 0 0 0 0 0 0 0 0 0 0
53172- 0 0 0 0 0 0 0 0 0 0 0 0
53173- 0 0 0 0 0 0 0 0 0 0 0 0
53174- 0 0 1 0 0 1 0 0 1 0 0 0
53175- 0 0 0 0 0 0 0 0 0 0 0 0
53176- 0 0 0 0 0 0 0 0 0 0 0 0
53177- 0 0 0 0 0 0 0 0 0 0 0 0
53178- 0 0 0 0 0 0 0 0 0 0 0 0
53179- 0 0 0 0 0 0 0 0 0 0 0 0
53180- 14 14 14 42 42 42 86 86 86 10 10 10
53181- 2 2 6 2 2 6 2 2 6 2 2 6
53182- 2 2 6 2 2 6 2 2 6 2 2 6
53183- 2 2 6 2 2 6 2 2 6 30 30 30
53184- 94 94 94 94 94 94 58 58 58 26 26 26
53185- 2 2 6 6 6 6 78 78 78 54 54 54
53186- 22 22 22 6 6 6 0 0 0 0 0 0
53187- 0 0 0 0 0 0 0 0 0 0 0 0
53188- 0 0 0 0 0 0 0 0 0 0 0 0
53189- 0 0 0 0 0 0 0 0 0 0 0 0
53190- 0 0 0 0 0 0 0 0 0 0 0 0
53191- 0 0 0 0 0 0 0 0 0 0 0 0
53192- 0 0 0 0 0 0 0 0 0 0 0 0
53193- 0 0 0 0 0 0 0 0 0 0 0 0
53194- 0 0 0 0 0 0 0 0 0 0 0 0
53195- 0 0 0 0 0 0 0 0 0 0 0 0
53196- 0 0 0 0 0 0 0 0 0 0 0 0
53197- 0 0 0 0 0 0 0 0 0 0 0 0
53198- 0 0 0 0 0 0 0 0 0 0 0 0
53199- 0 0 0 0 0 0 0 0 0 6 6 6
53200- 22 22 22 62 62 62 62 62 62 2 2 6
53201- 2 2 6 2 2 6 2 2 6 2 2 6
53202- 2 2 6 2 2 6 2 2 6 2 2 6
53203- 2 2 6 2 2 6 2 2 6 26 26 26
53204- 54 54 54 38 38 38 18 18 18 10 10 10
53205- 2 2 6 2 2 6 34 34 34 82 82 82
53206- 38 38 38 14 14 14 0 0 0 0 0 0
53207- 0 0 0 0 0 0 0 0 0 0 0 0
53208- 0 0 0 0 0 0 0 0 0 0 0 0
53209- 0 0 0 0 0 0 0 0 0 0 0 0
53210- 0 0 0 0 0 0 0 0 0 0 0 0
53211- 0 0 0 0 0 0 0 0 0 0 0 0
53212- 0 0 0 0 0 0 0 0 0 0 0 0
53213- 0 0 0 0 0 0 0 0 0 0 0 0
53214- 0 0 0 0 0 1 0 0 1 0 0 0
53215- 0 0 0 0 0 0 0 0 0 0 0 0
53216- 0 0 0 0 0 0 0 0 0 0 0 0
53217- 0 0 0 0 0 0 0 0 0 0 0 0
53218- 0 0 0 0 0 0 0 0 0 0 0 0
53219- 0 0 0 0 0 0 0 0 0 6 6 6
53220- 30 30 30 78 78 78 30 30 30 2 2 6
53221- 2 2 6 2 2 6 2 2 6 2 2 6
53222- 2 2 6 2 2 6 2 2 6 2 2 6
53223- 2 2 6 2 2 6 2 2 6 10 10 10
53224- 10 10 10 2 2 6 2 2 6 2 2 6
53225- 2 2 6 2 2 6 2 2 6 78 78 78
53226- 50 50 50 18 18 18 6 6 6 0 0 0
53227- 0 0 0 0 0 0 0 0 0 0 0 0
53228- 0 0 0 0 0 0 0 0 0 0 0 0
53229- 0 0 0 0 0 0 0 0 0 0 0 0
53230- 0 0 0 0 0 0 0 0 0 0 0 0
53231- 0 0 0 0 0 0 0 0 0 0 0 0
53232- 0 0 0 0 0 0 0 0 0 0 0 0
53233- 0 0 0 0 0 0 0 0 0 0 0 0
53234- 0 0 1 0 0 0 0 0 0 0 0 0
53235- 0 0 0 0 0 0 0 0 0 0 0 0
53236- 0 0 0 0 0 0 0 0 0 0 0 0
53237- 0 0 0 0 0 0 0 0 0 0 0 0
53238- 0 0 0 0 0 0 0 0 0 0 0 0
53239- 0 0 0 0 0 0 0 0 0 10 10 10
53240- 38 38 38 86 86 86 14 14 14 2 2 6
53241- 2 2 6 2 2 6 2 2 6 2 2 6
53242- 2 2 6 2 2 6 2 2 6 2 2 6
53243- 2 2 6 2 2 6 2 2 6 2 2 6
53244- 2 2 6 2 2 6 2 2 6 2 2 6
53245- 2 2 6 2 2 6 2 2 6 54 54 54
53246- 66 66 66 26 26 26 6 6 6 0 0 0
53247- 0 0 0 0 0 0 0 0 0 0 0 0
53248- 0 0 0 0 0 0 0 0 0 0 0 0
53249- 0 0 0 0 0 0 0 0 0 0 0 0
53250- 0 0 0 0 0 0 0 0 0 0 0 0
53251- 0 0 0 0 0 0 0 0 0 0 0 0
53252- 0 0 0 0 0 0 0 0 0 0 0 0
53253- 0 0 0 0 0 0 0 0 0 0 0 0
53254- 0 0 0 0 0 1 0 0 1 0 0 0
53255- 0 0 0 0 0 0 0 0 0 0 0 0
53256- 0 0 0 0 0 0 0 0 0 0 0 0
53257- 0 0 0 0 0 0 0 0 0 0 0 0
53258- 0 0 0 0 0 0 0 0 0 0 0 0
53259- 0 0 0 0 0 0 0 0 0 14 14 14
53260- 42 42 42 82 82 82 2 2 6 2 2 6
53261- 2 2 6 6 6 6 10 10 10 2 2 6
53262- 2 2 6 2 2 6 2 2 6 2 2 6
53263- 2 2 6 2 2 6 2 2 6 6 6 6
53264- 14 14 14 10 10 10 2 2 6 2 2 6
53265- 2 2 6 2 2 6 2 2 6 18 18 18
53266- 82 82 82 34 34 34 10 10 10 0 0 0
53267- 0 0 0 0 0 0 0 0 0 0 0 0
53268- 0 0 0 0 0 0 0 0 0 0 0 0
53269- 0 0 0 0 0 0 0 0 0 0 0 0
53270- 0 0 0 0 0 0 0 0 0 0 0 0
53271- 0 0 0 0 0 0 0 0 0 0 0 0
53272- 0 0 0 0 0 0 0 0 0 0 0 0
53273- 0 0 0 0 0 0 0 0 0 0 0 0
53274- 0 0 1 0 0 0 0 0 0 0 0 0
53275- 0 0 0 0 0 0 0 0 0 0 0 0
53276- 0 0 0 0 0 0 0 0 0 0 0 0
53277- 0 0 0 0 0 0 0 0 0 0 0 0
53278- 0 0 0 0 0 0 0 0 0 0 0 0
53279- 0 0 0 0 0 0 0 0 0 14 14 14
53280- 46 46 46 86 86 86 2 2 6 2 2 6
53281- 6 6 6 6 6 6 22 22 22 34 34 34
53282- 6 6 6 2 2 6 2 2 6 2 2 6
53283- 2 2 6 2 2 6 18 18 18 34 34 34
53284- 10 10 10 50 50 50 22 22 22 2 2 6
53285- 2 2 6 2 2 6 2 2 6 10 10 10
53286- 86 86 86 42 42 42 14 14 14 0 0 0
53287- 0 0 0 0 0 0 0 0 0 0 0 0
53288- 0 0 0 0 0 0 0 0 0 0 0 0
53289- 0 0 0 0 0 0 0 0 0 0 0 0
53290- 0 0 0 0 0 0 0 0 0 0 0 0
53291- 0 0 0 0 0 0 0 0 0 0 0 0
53292- 0 0 0 0 0 0 0 0 0 0 0 0
53293- 0 0 0 0 0 0 0 0 0 0 0 0
53294- 0 0 1 0 0 1 0 0 1 0 0 0
53295- 0 0 0 0 0 0 0 0 0 0 0 0
53296- 0 0 0 0 0 0 0 0 0 0 0 0
53297- 0 0 0 0 0 0 0 0 0 0 0 0
53298- 0 0 0 0 0 0 0 0 0 0 0 0
53299- 0 0 0 0 0 0 0 0 0 14 14 14
53300- 46 46 46 86 86 86 2 2 6 2 2 6
53301- 38 38 38 116 116 116 94 94 94 22 22 22
53302- 22 22 22 2 2 6 2 2 6 2 2 6
53303- 14 14 14 86 86 86 138 138 138 162 162 162
53304-154 154 154 38 38 38 26 26 26 6 6 6
53305- 2 2 6 2 2 6 2 2 6 2 2 6
53306- 86 86 86 46 46 46 14 14 14 0 0 0
53307- 0 0 0 0 0 0 0 0 0 0 0 0
53308- 0 0 0 0 0 0 0 0 0 0 0 0
53309- 0 0 0 0 0 0 0 0 0 0 0 0
53310- 0 0 0 0 0 0 0 0 0 0 0 0
53311- 0 0 0 0 0 0 0 0 0 0 0 0
53312- 0 0 0 0 0 0 0 0 0 0 0 0
53313- 0 0 0 0 0 0 0 0 0 0 0 0
53314- 0 0 0 0 0 0 0 0 0 0 0 0
53315- 0 0 0 0 0 0 0 0 0 0 0 0
53316- 0 0 0 0 0 0 0 0 0 0 0 0
53317- 0 0 0 0 0 0 0 0 0 0 0 0
53318- 0 0 0 0 0 0 0 0 0 0 0 0
53319- 0 0 0 0 0 0 0 0 0 14 14 14
53320- 46 46 46 86 86 86 2 2 6 14 14 14
53321-134 134 134 198 198 198 195 195 195 116 116 116
53322- 10 10 10 2 2 6 2 2 6 6 6 6
53323-101 98 89 187 187 187 210 210 210 218 218 218
53324-214 214 214 134 134 134 14 14 14 6 6 6
53325- 2 2 6 2 2 6 2 2 6 2 2 6
53326- 86 86 86 50 50 50 18 18 18 6 6 6
53327- 0 0 0 0 0 0 0 0 0 0 0 0
53328- 0 0 0 0 0 0 0 0 0 0 0 0
53329- 0 0 0 0 0 0 0 0 0 0 0 0
53330- 0 0 0 0 0 0 0 0 0 0 0 0
53331- 0 0 0 0 0 0 0 0 0 0 0 0
53332- 0 0 0 0 0 0 0 0 0 0 0 0
53333- 0 0 0 0 0 0 0 0 1 0 0 0
53334- 0 0 1 0 0 1 0 0 1 0 0 0
53335- 0 0 0 0 0 0 0 0 0 0 0 0
53336- 0 0 0 0 0 0 0 0 0 0 0 0
53337- 0 0 0 0 0 0 0 0 0 0 0 0
53338- 0 0 0 0 0 0 0 0 0 0 0 0
53339- 0 0 0 0 0 0 0 0 0 14 14 14
53340- 46 46 46 86 86 86 2 2 6 54 54 54
53341-218 218 218 195 195 195 226 226 226 246 246 246
53342- 58 58 58 2 2 6 2 2 6 30 30 30
53343-210 210 210 253 253 253 174 174 174 123 123 123
53344-221 221 221 234 234 234 74 74 74 2 2 6
53345- 2 2 6 2 2 6 2 2 6 2 2 6
53346- 70 70 70 58 58 58 22 22 22 6 6 6
53347- 0 0 0 0 0 0 0 0 0 0 0 0
53348- 0 0 0 0 0 0 0 0 0 0 0 0
53349- 0 0 0 0 0 0 0 0 0 0 0 0
53350- 0 0 0 0 0 0 0 0 0 0 0 0
53351- 0 0 0 0 0 0 0 0 0 0 0 0
53352- 0 0 0 0 0 0 0 0 0 0 0 0
53353- 0 0 0 0 0 0 0 0 0 0 0 0
53354- 0 0 0 0 0 0 0 0 0 0 0 0
53355- 0 0 0 0 0 0 0 0 0 0 0 0
53356- 0 0 0 0 0 0 0 0 0 0 0 0
53357- 0 0 0 0 0 0 0 0 0 0 0 0
53358- 0 0 0 0 0 0 0 0 0 0 0 0
53359- 0 0 0 0 0 0 0 0 0 14 14 14
53360- 46 46 46 82 82 82 2 2 6 106 106 106
53361-170 170 170 26 26 26 86 86 86 226 226 226
53362-123 123 123 10 10 10 14 14 14 46 46 46
53363-231 231 231 190 190 190 6 6 6 70 70 70
53364- 90 90 90 238 238 238 158 158 158 2 2 6
53365- 2 2 6 2 2 6 2 2 6 2 2 6
53366- 70 70 70 58 58 58 22 22 22 6 6 6
53367- 0 0 0 0 0 0 0 0 0 0 0 0
53368- 0 0 0 0 0 0 0 0 0 0 0 0
53369- 0 0 0 0 0 0 0 0 0 0 0 0
53370- 0 0 0 0 0 0 0 0 0 0 0 0
53371- 0 0 0 0 0 0 0 0 0 0 0 0
53372- 0 0 0 0 0 0 0 0 0 0 0 0
53373- 0 0 0 0 0 0 0 0 1 0 0 0
53374- 0 0 1 0 0 1 0 0 1 0 0 0
53375- 0 0 0 0 0 0 0 0 0 0 0 0
53376- 0 0 0 0 0 0 0 0 0 0 0 0
53377- 0 0 0 0 0 0 0 0 0 0 0 0
53378- 0 0 0 0 0 0 0 0 0 0 0 0
53379- 0 0 0 0 0 0 0 0 0 14 14 14
53380- 42 42 42 86 86 86 6 6 6 116 116 116
53381-106 106 106 6 6 6 70 70 70 149 149 149
53382-128 128 128 18 18 18 38 38 38 54 54 54
53383-221 221 221 106 106 106 2 2 6 14 14 14
53384- 46 46 46 190 190 190 198 198 198 2 2 6
53385- 2 2 6 2 2 6 2 2 6 2 2 6
53386- 74 74 74 62 62 62 22 22 22 6 6 6
53387- 0 0 0 0 0 0 0 0 0 0 0 0
53388- 0 0 0 0 0 0 0 0 0 0 0 0
53389- 0 0 0 0 0 0 0 0 0 0 0 0
53390- 0 0 0 0 0 0 0 0 0 0 0 0
53391- 0 0 0 0 0 0 0 0 0 0 0 0
53392- 0 0 0 0 0 0 0 0 0 0 0 0
53393- 0 0 0 0 0 0 0 0 1 0 0 0
53394- 0 0 1 0 0 0 0 0 1 0 0 0
53395- 0 0 0 0 0 0 0 0 0 0 0 0
53396- 0 0 0 0 0 0 0 0 0 0 0 0
53397- 0 0 0 0 0 0 0 0 0 0 0 0
53398- 0 0 0 0 0 0 0 0 0 0 0 0
53399- 0 0 0 0 0 0 0 0 0 14 14 14
53400- 42 42 42 94 94 94 14 14 14 101 101 101
53401-128 128 128 2 2 6 18 18 18 116 116 116
53402-118 98 46 121 92 8 121 92 8 98 78 10
53403-162 162 162 106 106 106 2 2 6 2 2 6
53404- 2 2 6 195 195 195 195 195 195 6 6 6
53405- 2 2 6 2 2 6 2 2 6 2 2 6
53406- 74 74 74 62 62 62 22 22 22 6 6 6
53407- 0 0 0 0 0 0 0 0 0 0 0 0
53408- 0 0 0 0 0 0 0 0 0 0 0 0
53409- 0 0 0 0 0 0 0 0 0 0 0 0
53410- 0 0 0 0 0 0 0 0 0 0 0 0
53411- 0 0 0 0 0 0 0 0 0 0 0 0
53412- 0 0 0 0 0 0 0 0 0 0 0 0
53413- 0 0 0 0 0 0 0 0 1 0 0 1
53414- 0 0 1 0 0 0 0 0 1 0 0 0
53415- 0 0 0 0 0 0 0 0 0 0 0 0
53416- 0 0 0 0 0 0 0 0 0 0 0 0
53417- 0 0 0 0 0 0 0 0 0 0 0 0
53418- 0 0 0 0 0 0 0 0 0 0 0 0
53419- 0 0 0 0 0 0 0 0 0 10 10 10
53420- 38 38 38 90 90 90 14 14 14 58 58 58
53421-210 210 210 26 26 26 54 38 6 154 114 10
53422-226 170 11 236 186 11 225 175 15 184 144 12
53423-215 174 15 175 146 61 37 26 9 2 2 6
53424- 70 70 70 246 246 246 138 138 138 2 2 6
53425- 2 2 6 2 2 6 2 2 6 2 2 6
53426- 70 70 70 66 66 66 26 26 26 6 6 6
53427- 0 0 0 0 0 0 0 0 0 0 0 0
53428- 0 0 0 0 0 0 0 0 0 0 0 0
53429- 0 0 0 0 0 0 0 0 0 0 0 0
53430- 0 0 0 0 0 0 0 0 0 0 0 0
53431- 0 0 0 0 0 0 0 0 0 0 0 0
53432- 0 0 0 0 0 0 0 0 0 0 0 0
53433- 0 0 0 0 0 0 0 0 0 0 0 0
53434- 0 0 0 0 0 0 0 0 0 0 0 0
53435- 0 0 0 0 0 0 0 0 0 0 0 0
53436- 0 0 0 0 0 0 0 0 0 0 0 0
53437- 0 0 0 0 0 0 0 0 0 0 0 0
53438- 0 0 0 0 0 0 0 0 0 0 0 0
53439- 0 0 0 0 0 0 0 0 0 10 10 10
53440- 38 38 38 86 86 86 14 14 14 10 10 10
53441-195 195 195 188 164 115 192 133 9 225 175 15
53442-239 182 13 234 190 10 232 195 16 232 200 30
53443-245 207 45 241 208 19 232 195 16 184 144 12
53444-218 194 134 211 206 186 42 42 42 2 2 6
53445- 2 2 6 2 2 6 2 2 6 2 2 6
53446- 50 50 50 74 74 74 30 30 30 6 6 6
53447- 0 0 0 0 0 0 0 0 0 0 0 0
53448- 0 0 0 0 0 0 0 0 0 0 0 0
53449- 0 0 0 0 0 0 0 0 0 0 0 0
53450- 0 0 0 0 0 0 0 0 0 0 0 0
53451- 0 0 0 0 0 0 0 0 0 0 0 0
53452- 0 0 0 0 0 0 0 0 0 0 0 0
53453- 0 0 0 0 0 0 0 0 0 0 0 0
53454- 0 0 0 0 0 0 0 0 0 0 0 0
53455- 0 0 0 0 0 0 0 0 0 0 0 0
53456- 0 0 0 0 0 0 0 0 0 0 0 0
53457- 0 0 0 0 0 0 0 0 0 0 0 0
53458- 0 0 0 0 0 0 0 0 0 0 0 0
53459- 0 0 0 0 0 0 0 0 0 10 10 10
53460- 34 34 34 86 86 86 14 14 14 2 2 6
53461-121 87 25 192 133 9 219 162 10 239 182 13
53462-236 186 11 232 195 16 241 208 19 244 214 54
53463-246 218 60 246 218 38 246 215 20 241 208 19
53464-241 208 19 226 184 13 121 87 25 2 2 6
53465- 2 2 6 2 2 6 2 2 6 2 2 6
53466- 50 50 50 82 82 82 34 34 34 10 10 10
53467- 0 0 0 0 0 0 0 0 0 0 0 0
53468- 0 0 0 0 0 0 0 0 0 0 0 0
53469- 0 0 0 0 0 0 0 0 0 0 0 0
53470- 0 0 0 0 0 0 0 0 0 0 0 0
53471- 0 0 0 0 0 0 0 0 0 0 0 0
53472- 0 0 0 0 0 0 0 0 0 0 0 0
53473- 0 0 0 0 0 0 0 0 0 0 0 0
53474- 0 0 0 0 0 0 0 0 0 0 0 0
53475- 0 0 0 0 0 0 0 0 0 0 0 0
53476- 0 0 0 0 0 0 0 0 0 0 0 0
53477- 0 0 0 0 0 0 0 0 0 0 0 0
53478- 0 0 0 0 0 0 0 0 0 0 0 0
53479- 0 0 0 0 0 0 0 0 0 10 10 10
53480- 34 34 34 82 82 82 30 30 30 61 42 6
53481-180 123 7 206 145 10 230 174 11 239 182 13
53482-234 190 10 238 202 15 241 208 19 246 218 74
53483-246 218 38 246 215 20 246 215 20 246 215 20
53484-226 184 13 215 174 15 184 144 12 6 6 6
53485- 2 2 6 2 2 6 2 2 6 2 2 6
53486- 26 26 26 94 94 94 42 42 42 14 14 14
53487- 0 0 0 0 0 0 0 0 0 0 0 0
53488- 0 0 0 0 0 0 0 0 0 0 0 0
53489- 0 0 0 0 0 0 0 0 0 0 0 0
53490- 0 0 0 0 0 0 0 0 0 0 0 0
53491- 0 0 0 0 0 0 0 0 0 0 0 0
53492- 0 0 0 0 0 0 0 0 0 0 0 0
53493- 0 0 0 0 0 0 0 0 0 0 0 0
53494- 0 0 0 0 0 0 0 0 0 0 0 0
53495- 0 0 0 0 0 0 0 0 0 0 0 0
53496- 0 0 0 0 0 0 0 0 0 0 0 0
53497- 0 0 0 0 0 0 0 0 0 0 0 0
53498- 0 0 0 0 0 0 0 0 0 0 0 0
53499- 0 0 0 0 0 0 0 0 0 10 10 10
53500- 30 30 30 78 78 78 50 50 50 104 69 6
53501-192 133 9 216 158 10 236 178 12 236 186 11
53502-232 195 16 241 208 19 244 214 54 245 215 43
53503-246 215 20 246 215 20 241 208 19 198 155 10
53504-200 144 11 216 158 10 156 118 10 2 2 6
53505- 2 2 6 2 2 6 2 2 6 2 2 6
53506- 6 6 6 90 90 90 54 54 54 18 18 18
53507- 6 6 6 0 0 0 0 0 0 0 0 0
53508- 0 0 0 0 0 0 0 0 0 0 0 0
53509- 0 0 0 0 0 0 0 0 0 0 0 0
53510- 0 0 0 0 0 0 0 0 0 0 0 0
53511- 0 0 0 0 0 0 0 0 0 0 0 0
53512- 0 0 0 0 0 0 0 0 0 0 0 0
53513- 0 0 0 0 0 0 0 0 0 0 0 0
53514- 0 0 0 0 0 0 0 0 0 0 0 0
53515- 0 0 0 0 0 0 0 0 0 0 0 0
53516- 0 0 0 0 0 0 0 0 0 0 0 0
53517- 0 0 0 0 0 0 0 0 0 0 0 0
53518- 0 0 0 0 0 0 0 0 0 0 0 0
53519- 0 0 0 0 0 0 0 0 0 10 10 10
53520- 30 30 30 78 78 78 46 46 46 22 22 22
53521-137 92 6 210 162 10 239 182 13 238 190 10
53522-238 202 15 241 208 19 246 215 20 246 215 20
53523-241 208 19 203 166 17 185 133 11 210 150 10
53524-216 158 10 210 150 10 102 78 10 2 2 6
53525- 6 6 6 54 54 54 14 14 14 2 2 6
53526- 2 2 6 62 62 62 74 74 74 30 30 30
53527- 10 10 10 0 0 0 0 0 0 0 0 0
53528- 0 0 0 0 0 0 0 0 0 0 0 0
53529- 0 0 0 0 0 0 0 0 0 0 0 0
53530- 0 0 0 0 0 0 0 0 0 0 0 0
53531- 0 0 0 0 0 0 0 0 0 0 0 0
53532- 0 0 0 0 0 0 0 0 0 0 0 0
53533- 0 0 0 0 0 0 0 0 0 0 0 0
53534- 0 0 0 0 0 0 0 0 0 0 0 0
53535- 0 0 0 0 0 0 0 0 0 0 0 0
53536- 0 0 0 0 0 0 0 0 0 0 0 0
53537- 0 0 0 0 0 0 0 0 0 0 0 0
53538- 0 0 0 0 0 0 0 0 0 0 0 0
53539- 0 0 0 0 0 0 0 0 0 10 10 10
53540- 34 34 34 78 78 78 50 50 50 6 6 6
53541- 94 70 30 139 102 15 190 146 13 226 184 13
53542-232 200 30 232 195 16 215 174 15 190 146 13
53543-168 122 10 192 133 9 210 150 10 213 154 11
53544-202 150 34 182 157 106 101 98 89 2 2 6
53545- 2 2 6 78 78 78 116 116 116 58 58 58
53546- 2 2 6 22 22 22 90 90 90 46 46 46
53547- 18 18 18 6 6 6 0 0 0 0 0 0
53548- 0 0 0 0 0 0 0 0 0 0 0 0
53549- 0 0 0 0 0 0 0 0 0 0 0 0
53550- 0 0 0 0 0 0 0 0 0 0 0 0
53551- 0 0 0 0 0 0 0 0 0 0 0 0
53552- 0 0 0 0 0 0 0 0 0 0 0 0
53553- 0 0 0 0 0 0 0 0 0 0 0 0
53554- 0 0 0 0 0 0 0 0 0 0 0 0
53555- 0 0 0 0 0 0 0 0 0 0 0 0
53556- 0 0 0 0 0 0 0 0 0 0 0 0
53557- 0 0 0 0 0 0 0 0 0 0 0 0
53558- 0 0 0 0 0 0 0 0 0 0 0 0
53559- 0 0 0 0 0 0 0 0 0 10 10 10
53560- 38 38 38 86 86 86 50 50 50 6 6 6
53561-128 128 128 174 154 114 156 107 11 168 122 10
53562-198 155 10 184 144 12 197 138 11 200 144 11
53563-206 145 10 206 145 10 197 138 11 188 164 115
53564-195 195 195 198 198 198 174 174 174 14 14 14
53565- 2 2 6 22 22 22 116 116 116 116 116 116
53566- 22 22 22 2 2 6 74 74 74 70 70 70
53567- 30 30 30 10 10 10 0 0 0 0 0 0
53568- 0 0 0 0 0 0 0 0 0 0 0 0
53569- 0 0 0 0 0 0 0 0 0 0 0 0
53570- 0 0 0 0 0 0 0 0 0 0 0 0
53571- 0 0 0 0 0 0 0 0 0 0 0 0
53572- 0 0 0 0 0 0 0 0 0 0 0 0
53573- 0 0 0 0 0 0 0 0 0 0 0 0
53574- 0 0 0 0 0 0 0 0 0 0 0 0
53575- 0 0 0 0 0 0 0 0 0 0 0 0
53576- 0 0 0 0 0 0 0 0 0 0 0 0
53577- 0 0 0 0 0 0 0 0 0 0 0 0
53578- 0 0 0 0 0 0 0 0 0 0 0 0
53579- 0 0 0 0 0 0 6 6 6 18 18 18
53580- 50 50 50 101 101 101 26 26 26 10 10 10
53581-138 138 138 190 190 190 174 154 114 156 107 11
53582-197 138 11 200 144 11 197 138 11 192 133 9
53583-180 123 7 190 142 34 190 178 144 187 187 187
53584-202 202 202 221 221 221 214 214 214 66 66 66
53585- 2 2 6 2 2 6 50 50 50 62 62 62
53586- 6 6 6 2 2 6 10 10 10 90 90 90
53587- 50 50 50 18 18 18 6 6 6 0 0 0
53588- 0 0 0 0 0 0 0 0 0 0 0 0
53589- 0 0 0 0 0 0 0 0 0 0 0 0
53590- 0 0 0 0 0 0 0 0 0 0 0 0
53591- 0 0 0 0 0 0 0 0 0 0 0 0
53592- 0 0 0 0 0 0 0 0 0 0 0 0
53593- 0 0 0 0 0 0 0 0 0 0 0 0
53594- 0 0 0 0 0 0 0 0 0 0 0 0
53595- 0 0 0 0 0 0 0 0 0 0 0 0
53596- 0 0 0 0 0 0 0 0 0 0 0 0
53597- 0 0 0 0 0 0 0 0 0 0 0 0
53598- 0 0 0 0 0 0 0 0 0 0 0 0
53599- 0 0 0 0 0 0 10 10 10 34 34 34
53600- 74 74 74 74 74 74 2 2 6 6 6 6
53601-144 144 144 198 198 198 190 190 190 178 166 146
53602-154 121 60 156 107 11 156 107 11 168 124 44
53603-174 154 114 187 187 187 190 190 190 210 210 210
53604-246 246 246 253 253 253 253 253 253 182 182 182
53605- 6 6 6 2 2 6 2 2 6 2 2 6
53606- 2 2 6 2 2 6 2 2 6 62 62 62
53607- 74 74 74 34 34 34 14 14 14 0 0 0
53608- 0 0 0 0 0 0 0 0 0 0 0 0
53609- 0 0 0 0 0 0 0 0 0 0 0 0
53610- 0 0 0 0 0 0 0 0 0 0 0 0
53611- 0 0 0 0 0 0 0 0 0 0 0 0
53612- 0 0 0 0 0 0 0 0 0 0 0 0
53613- 0 0 0 0 0 0 0 0 0 0 0 0
53614- 0 0 0 0 0 0 0 0 0 0 0 0
53615- 0 0 0 0 0 0 0 0 0 0 0 0
53616- 0 0 0 0 0 0 0 0 0 0 0 0
53617- 0 0 0 0 0 0 0 0 0 0 0 0
53618- 0 0 0 0 0 0 0 0 0 0 0 0
53619- 0 0 0 10 10 10 22 22 22 54 54 54
53620- 94 94 94 18 18 18 2 2 6 46 46 46
53621-234 234 234 221 221 221 190 190 190 190 190 190
53622-190 190 190 187 187 187 187 187 187 190 190 190
53623-190 190 190 195 195 195 214 214 214 242 242 242
53624-253 253 253 253 253 253 253 253 253 253 253 253
53625- 82 82 82 2 2 6 2 2 6 2 2 6
53626- 2 2 6 2 2 6 2 2 6 14 14 14
53627- 86 86 86 54 54 54 22 22 22 6 6 6
53628- 0 0 0 0 0 0 0 0 0 0 0 0
53629- 0 0 0 0 0 0 0 0 0 0 0 0
53630- 0 0 0 0 0 0 0 0 0 0 0 0
53631- 0 0 0 0 0 0 0 0 0 0 0 0
53632- 0 0 0 0 0 0 0 0 0 0 0 0
53633- 0 0 0 0 0 0 0 0 0 0 0 0
53634- 0 0 0 0 0 0 0 0 0 0 0 0
53635- 0 0 0 0 0 0 0 0 0 0 0 0
53636- 0 0 0 0 0 0 0 0 0 0 0 0
53637- 0 0 0 0 0 0 0 0 0 0 0 0
53638- 0 0 0 0 0 0 0 0 0 0 0 0
53639- 6 6 6 18 18 18 46 46 46 90 90 90
53640- 46 46 46 18 18 18 6 6 6 182 182 182
53641-253 253 253 246 246 246 206 206 206 190 190 190
53642-190 190 190 190 190 190 190 190 190 190 190 190
53643-206 206 206 231 231 231 250 250 250 253 253 253
53644-253 253 253 253 253 253 253 253 253 253 253 253
53645-202 202 202 14 14 14 2 2 6 2 2 6
53646- 2 2 6 2 2 6 2 2 6 2 2 6
53647- 42 42 42 86 86 86 42 42 42 18 18 18
53648- 6 6 6 0 0 0 0 0 0 0 0 0
53649- 0 0 0 0 0 0 0 0 0 0 0 0
53650- 0 0 0 0 0 0 0 0 0 0 0 0
53651- 0 0 0 0 0 0 0 0 0 0 0 0
53652- 0 0 0 0 0 0 0 0 0 0 0 0
53653- 0 0 0 0 0 0 0 0 0 0 0 0
53654- 0 0 0 0 0 0 0 0 0 0 0 0
53655- 0 0 0 0 0 0 0 0 0 0 0 0
53656- 0 0 0 0 0 0 0 0 0 0 0 0
53657- 0 0 0 0 0 0 0 0 0 0 0 0
53658- 0 0 0 0 0 0 0 0 0 6 6 6
53659- 14 14 14 38 38 38 74 74 74 66 66 66
53660- 2 2 6 6 6 6 90 90 90 250 250 250
53661-253 253 253 253 253 253 238 238 238 198 198 198
53662-190 190 190 190 190 190 195 195 195 221 221 221
53663-246 246 246 253 253 253 253 253 253 253 253 253
53664-253 253 253 253 253 253 253 253 253 253 253 253
53665-253 253 253 82 82 82 2 2 6 2 2 6
53666- 2 2 6 2 2 6 2 2 6 2 2 6
53667- 2 2 6 78 78 78 70 70 70 34 34 34
53668- 14 14 14 6 6 6 0 0 0 0 0 0
53669- 0 0 0 0 0 0 0 0 0 0 0 0
53670- 0 0 0 0 0 0 0 0 0 0 0 0
53671- 0 0 0 0 0 0 0 0 0 0 0 0
53672- 0 0 0 0 0 0 0 0 0 0 0 0
53673- 0 0 0 0 0 0 0 0 0 0 0 0
53674- 0 0 0 0 0 0 0 0 0 0 0 0
53675- 0 0 0 0 0 0 0 0 0 0 0 0
53676- 0 0 0 0 0 0 0 0 0 0 0 0
53677- 0 0 0 0 0 0 0 0 0 0 0 0
53678- 0 0 0 0 0 0 0 0 0 14 14 14
53679- 34 34 34 66 66 66 78 78 78 6 6 6
53680- 2 2 6 18 18 18 218 218 218 253 253 253
53681-253 253 253 253 253 253 253 253 253 246 246 246
53682-226 226 226 231 231 231 246 246 246 253 253 253
53683-253 253 253 253 253 253 253 253 253 253 253 253
53684-253 253 253 253 253 253 253 253 253 253 253 253
53685-253 253 253 178 178 178 2 2 6 2 2 6
53686- 2 2 6 2 2 6 2 2 6 2 2 6
53687- 2 2 6 18 18 18 90 90 90 62 62 62
53688- 30 30 30 10 10 10 0 0 0 0 0 0
53689- 0 0 0 0 0 0 0 0 0 0 0 0
53690- 0 0 0 0 0 0 0 0 0 0 0 0
53691- 0 0 0 0 0 0 0 0 0 0 0 0
53692- 0 0 0 0 0 0 0 0 0 0 0 0
53693- 0 0 0 0 0 0 0 0 0 0 0 0
53694- 0 0 0 0 0 0 0 0 0 0 0 0
53695- 0 0 0 0 0 0 0 0 0 0 0 0
53696- 0 0 0 0 0 0 0 0 0 0 0 0
53697- 0 0 0 0 0 0 0 0 0 0 0 0
53698- 0 0 0 0 0 0 10 10 10 26 26 26
53699- 58 58 58 90 90 90 18 18 18 2 2 6
53700- 2 2 6 110 110 110 253 253 253 253 253 253
53701-253 253 253 253 253 253 253 253 253 253 253 253
53702-250 250 250 253 253 253 253 253 253 253 253 253
53703-253 253 253 253 253 253 253 253 253 253 253 253
53704-253 253 253 253 253 253 253 253 253 253 253 253
53705-253 253 253 231 231 231 18 18 18 2 2 6
53706- 2 2 6 2 2 6 2 2 6 2 2 6
53707- 2 2 6 2 2 6 18 18 18 94 94 94
53708- 54 54 54 26 26 26 10 10 10 0 0 0
53709- 0 0 0 0 0 0 0 0 0 0 0 0
53710- 0 0 0 0 0 0 0 0 0 0 0 0
53711- 0 0 0 0 0 0 0 0 0 0 0 0
53712- 0 0 0 0 0 0 0 0 0 0 0 0
53713- 0 0 0 0 0 0 0 0 0 0 0 0
53714- 0 0 0 0 0 0 0 0 0 0 0 0
53715- 0 0 0 0 0 0 0 0 0 0 0 0
53716- 0 0 0 0 0 0 0 0 0 0 0 0
53717- 0 0 0 0 0 0 0 0 0 0 0 0
53718- 0 0 0 6 6 6 22 22 22 50 50 50
53719- 90 90 90 26 26 26 2 2 6 2 2 6
53720- 14 14 14 195 195 195 250 250 250 253 253 253
53721-253 253 253 253 253 253 253 253 253 253 253 253
53722-253 253 253 253 253 253 253 253 253 253 253 253
53723-253 253 253 253 253 253 253 253 253 253 253 253
53724-253 253 253 253 253 253 253 253 253 253 253 253
53725-250 250 250 242 242 242 54 54 54 2 2 6
53726- 2 2 6 2 2 6 2 2 6 2 2 6
53727- 2 2 6 2 2 6 2 2 6 38 38 38
53728- 86 86 86 50 50 50 22 22 22 6 6 6
53729- 0 0 0 0 0 0 0 0 0 0 0 0
53730- 0 0 0 0 0 0 0 0 0 0 0 0
53731- 0 0 0 0 0 0 0 0 0 0 0 0
53732- 0 0 0 0 0 0 0 0 0 0 0 0
53733- 0 0 0 0 0 0 0 0 0 0 0 0
53734- 0 0 0 0 0 0 0 0 0 0 0 0
53735- 0 0 0 0 0 0 0 0 0 0 0 0
53736- 0 0 0 0 0 0 0 0 0 0 0 0
53737- 0 0 0 0 0 0 0 0 0 0 0 0
53738- 6 6 6 14 14 14 38 38 38 82 82 82
53739- 34 34 34 2 2 6 2 2 6 2 2 6
53740- 42 42 42 195 195 195 246 246 246 253 253 253
53741-253 253 253 253 253 253 253 253 253 250 250 250
53742-242 242 242 242 242 242 250 250 250 253 253 253
53743-253 253 253 253 253 253 253 253 253 253 253 253
53744-253 253 253 250 250 250 246 246 246 238 238 238
53745-226 226 226 231 231 231 101 101 101 6 6 6
53746- 2 2 6 2 2 6 2 2 6 2 2 6
53747- 2 2 6 2 2 6 2 2 6 2 2 6
53748- 38 38 38 82 82 82 42 42 42 14 14 14
53749- 6 6 6 0 0 0 0 0 0 0 0 0
53750- 0 0 0 0 0 0 0 0 0 0 0 0
53751- 0 0 0 0 0 0 0 0 0 0 0 0
53752- 0 0 0 0 0 0 0 0 0 0 0 0
53753- 0 0 0 0 0 0 0 0 0 0 0 0
53754- 0 0 0 0 0 0 0 0 0 0 0 0
53755- 0 0 0 0 0 0 0 0 0 0 0 0
53756- 0 0 0 0 0 0 0 0 0 0 0 0
53757- 0 0 0 0 0 0 0 0 0 0 0 0
53758- 10 10 10 26 26 26 62 62 62 66 66 66
53759- 2 2 6 2 2 6 2 2 6 6 6 6
53760- 70 70 70 170 170 170 206 206 206 234 234 234
53761-246 246 246 250 250 250 250 250 250 238 238 238
53762-226 226 226 231 231 231 238 238 238 250 250 250
53763-250 250 250 250 250 250 246 246 246 231 231 231
53764-214 214 214 206 206 206 202 202 202 202 202 202
53765-198 198 198 202 202 202 182 182 182 18 18 18
53766- 2 2 6 2 2 6 2 2 6 2 2 6
53767- 2 2 6 2 2 6 2 2 6 2 2 6
53768- 2 2 6 62 62 62 66 66 66 30 30 30
53769- 10 10 10 0 0 0 0 0 0 0 0 0
53770- 0 0 0 0 0 0 0 0 0 0 0 0
53771- 0 0 0 0 0 0 0 0 0 0 0 0
53772- 0 0 0 0 0 0 0 0 0 0 0 0
53773- 0 0 0 0 0 0 0 0 0 0 0 0
53774- 0 0 0 0 0 0 0 0 0 0 0 0
53775- 0 0 0 0 0 0 0 0 0 0 0 0
53776- 0 0 0 0 0 0 0 0 0 0 0 0
53777- 0 0 0 0 0 0 0 0 0 0 0 0
53778- 14 14 14 42 42 42 82 82 82 18 18 18
53779- 2 2 6 2 2 6 2 2 6 10 10 10
53780- 94 94 94 182 182 182 218 218 218 242 242 242
53781-250 250 250 253 253 253 253 253 253 250 250 250
53782-234 234 234 253 253 253 253 253 253 253 253 253
53783-253 253 253 253 253 253 253 253 253 246 246 246
53784-238 238 238 226 226 226 210 210 210 202 202 202
53785-195 195 195 195 195 195 210 210 210 158 158 158
53786- 6 6 6 14 14 14 50 50 50 14 14 14
53787- 2 2 6 2 2 6 2 2 6 2 2 6
53788- 2 2 6 6 6 6 86 86 86 46 46 46
53789- 18 18 18 6 6 6 0 0 0 0 0 0
53790- 0 0 0 0 0 0 0 0 0 0 0 0
53791- 0 0 0 0 0 0 0 0 0 0 0 0
53792- 0 0 0 0 0 0 0 0 0 0 0 0
53793- 0 0 0 0 0 0 0 0 0 0 0 0
53794- 0 0 0 0 0 0 0 0 0 0 0 0
53795- 0 0 0 0 0 0 0 0 0 0 0 0
53796- 0 0 0 0 0 0 0 0 0 0 0 0
53797- 0 0 0 0 0 0 0 0 0 6 6 6
53798- 22 22 22 54 54 54 70 70 70 2 2 6
53799- 2 2 6 10 10 10 2 2 6 22 22 22
53800-166 166 166 231 231 231 250 250 250 253 253 253
53801-253 253 253 253 253 253 253 253 253 250 250 250
53802-242 242 242 253 253 253 253 253 253 253 253 253
53803-253 253 253 253 253 253 253 253 253 253 253 253
53804-253 253 253 253 253 253 253 253 253 246 246 246
53805-231 231 231 206 206 206 198 198 198 226 226 226
53806- 94 94 94 2 2 6 6 6 6 38 38 38
53807- 30 30 30 2 2 6 2 2 6 2 2 6
53808- 2 2 6 2 2 6 62 62 62 66 66 66
53809- 26 26 26 10 10 10 0 0 0 0 0 0
53810- 0 0 0 0 0 0 0 0 0 0 0 0
53811- 0 0 0 0 0 0 0 0 0 0 0 0
53812- 0 0 0 0 0 0 0 0 0 0 0 0
53813- 0 0 0 0 0 0 0 0 0 0 0 0
53814- 0 0 0 0 0 0 0 0 0 0 0 0
53815- 0 0 0 0 0 0 0 0 0 0 0 0
53816- 0 0 0 0 0 0 0 0 0 0 0 0
53817- 0 0 0 0 0 0 0 0 0 10 10 10
53818- 30 30 30 74 74 74 50 50 50 2 2 6
53819- 26 26 26 26 26 26 2 2 6 106 106 106
53820-238 238 238 253 253 253 253 253 253 253 253 253
53821-253 253 253 253 253 253 253 253 253 253 253 253
53822-253 253 253 253 253 253 253 253 253 253 253 253
53823-253 253 253 253 253 253 253 253 253 253 253 253
53824-253 253 253 253 253 253 253 253 253 253 253 253
53825-253 253 253 246 246 246 218 218 218 202 202 202
53826-210 210 210 14 14 14 2 2 6 2 2 6
53827- 30 30 30 22 22 22 2 2 6 2 2 6
53828- 2 2 6 2 2 6 18 18 18 86 86 86
53829- 42 42 42 14 14 14 0 0 0 0 0 0
53830- 0 0 0 0 0 0 0 0 0 0 0 0
53831- 0 0 0 0 0 0 0 0 0 0 0 0
53832- 0 0 0 0 0 0 0 0 0 0 0 0
53833- 0 0 0 0 0 0 0 0 0 0 0 0
53834- 0 0 0 0 0 0 0 0 0 0 0 0
53835- 0 0 0 0 0 0 0 0 0 0 0 0
53836- 0 0 0 0 0 0 0 0 0 0 0 0
53837- 0 0 0 0 0 0 0 0 0 14 14 14
53838- 42 42 42 90 90 90 22 22 22 2 2 6
53839- 42 42 42 2 2 6 18 18 18 218 218 218
53840-253 253 253 253 253 253 253 253 253 253 253 253
53841-253 253 253 253 253 253 253 253 253 253 253 253
53842-253 253 253 253 253 253 253 253 253 253 253 253
53843-253 253 253 253 253 253 253 253 253 253 253 253
53844-253 253 253 253 253 253 253 253 253 253 253 253
53845-253 253 253 253 253 253 250 250 250 221 221 221
53846-218 218 218 101 101 101 2 2 6 14 14 14
53847- 18 18 18 38 38 38 10 10 10 2 2 6
53848- 2 2 6 2 2 6 2 2 6 78 78 78
53849- 58 58 58 22 22 22 6 6 6 0 0 0
53850- 0 0 0 0 0 0 0 0 0 0 0 0
53851- 0 0 0 0 0 0 0 0 0 0 0 0
53852- 0 0 0 0 0 0 0 0 0 0 0 0
53853- 0 0 0 0 0 0 0 0 0 0 0 0
53854- 0 0 0 0 0 0 0 0 0 0 0 0
53855- 0 0 0 0 0 0 0 0 0 0 0 0
53856- 0 0 0 0 0 0 0 0 0 0 0 0
53857- 0 0 0 0 0 0 6 6 6 18 18 18
53858- 54 54 54 82 82 82 2 2 6 26 26 26
53859- 22 22 22 2 2 6 123 123 123 253 253 253
53860-253 253 253 253 253 253 253 253 253 253 253 253
53861-253 253 253 253 253 253 253 253 253 253 253 253
53862-253 253 253 253 253 253 253 253 253 253 253 253
53863-253 253 253 253 253 253 253 253 253 253 253 253
53864-253 253 253 253 253 253 253 253 253 253 253 253
53865-253 253 253 253 253 253 253 253 253 250 250 250
53866-238 238 238 198 198 198 6 6 6 38 38 38
53867- 58 58 58 26 26 26 38 38 38 2 2 6
53868- 2 2 6 2 2 6 2 2 6 46 46 46
53869- 78 78 78 30 30 30 10 10 10 0 0 0
53870- 0 0 0 0 0 0 0 0 0 0 0 0
53871- 0 0 0 0 0 0 0 0 0 0 0 0
53872- 0 0 0 0 0 0 0 0 0 0 0 0
53873- 0 0 0 0 0 0 0 0 0 0 0 0
53874- 0 0 0 0 0 0 0 0 0 0 0 0
53875- 0 0 0 0 0 0 0 0 0 0 0 0
53876- 0 0 0 0 0 0 0 0 0 0 0 0
53877- 0 0 0 0 0 0 10 10 10 30 30 30
53878- 74 74 74 58 58 58 2 2 6 42 42 42
53879- 2 2 6 22 22 22 231 231 231 253 253 253
53880-253 253 253 253 253 253 253 253 253 253 253 253
53881-253 253 253 253 253 253 253 253 253 250 250 250
53882-253 253 253 253 253 253 253 253 253 253 253 253
53883-253 253 253 253 253 253 253 253 253 253 253 253
53884-253 253 253 253 253 253 253 253 253 253 253 253
53885-253 253 253 253 253 253 253 253 253 253 253 253
53886-253 253 253 246 246 246 46 46 46 38 38 38
53887- 42 42 42 14 14 14 38 38 38 14 14 14
53888- 2 2 6 2 2 6 2 2 6 6 6 6
53889- 86 86 86 46 46 46 14 14 14 0 0 0
53890- 0 0 0 0 0 0 0 0 0 0 0 0
53891- 0 0 0 0 0 0 0 0 0 0 0 0
53892- 0 0 0 0 0 0 0 0 0 0 0 0
53893- 0 0 0 0 0 0 0 0 0 0 0 0
53894- 0 0 0 0 0 0 0 0 0 0 0 0
53895- 0 0 0 0 0 0 0 0 0 0 0 0
53896- 0 0 0 0 0 0 0 0 0 0 0 0
53897- 0 0 0 6 6 6 14 14 14 42 42 42
53898- 90 90 90 18 18 18 18 18 18 26 26 26
53899- 2 2 6 116 116 116 253 253 253 253 253 253
53900-253 253 253 253 253 253 253 253 253 253 253 253
53901-253 253 253 253 253 253 250 250 250 238 238 238
53902-253 253 253 253 253 253 253 253 253 253 253 253
53903-253 253 253 253 253 253 253 253 253 253 253 253
53904-253 253 253 253 253 253 253 253 253 253 253 253
53905-253 253 253 253 253 253 253 253 253 253 253 253
53906-253 253 253 253 253 253 94 94 94 6 6 6
53907- 2 2 6 2 2 6 10 10 10 34 34 34
53908- 2 2 6 2 2 6 2 2 6 2 2 6
53909- 74 74 74 58 58 58 22 22 22 6 6 6
53910- 0 0 0 0 0 0 0 0 0 0 0 0
53911- 0 0 0 0 0 0 0 0 0 0 0 0
53912- 0 0 0 0 0 0 0 0 0 0 0 0
53913- 0 0 0 0 0 0 0 0 0 0 0 0
53914- 0 0 0 0 0 0 0 0 0 0 0 0
53915- 0 0 0 0 0 0 0 0 0 0 0 0
53916- 0 0 0 0 0 0 0 0 0 0 0 0
53917- 0 0 0 10 10 10 26 26 26 66 66 66
53918- 82 82 82 2 2 6 38 38 38 6 6 6
53919- 14 14 14 210 210 210 253 253 253 253 253 253
53920-253 253 253 253 253 253 253 253 253 253 253 253
53921-253 253 253 253 253 253 246 246 246 242 242 242
53922-253 253 253 253 253 253 253 253 253 253 253 253
53923-253 253 253 253 253 253 253 253 253 253 253 253
53924-253 253 253 253 253 253 253 253 253 253 253 253
53925-253 253 253 253 253 253 253 253 253 253 253 253
53926-253 253 253 253 253 253 144 144 144 2 2 6
53927- 2 2 6 2 2 6 2 2 6 46 46 46
53928- 2 2 6 2 2 6 2 2 6 2 2 6
53929- 42 42 42 74 74 74 30 30 30 10 10 10
53930- 0 0 0 0 0 0 0 0 0 0 0 0
53931- 0 0 0 0 0 0 0 0 0 0 0 0
53932- 0 0 0 0 0 0 0 0 0 0 0 0
53933- 0 0 0 0 0 0 0 0 0 0 0 0
53934- 0 0 0 0 0 0 0 0 0 0 0 0
53935- 0 0 0 0 0 0 0 0 0 0 0 0
53936- 0 0 0 0 0 0 0 0 0 0 0 0
53937- 6 6 6 14 14 14 42 42 42 90 90 90
53938- 26 26 26 6 6 6 42 42 42 2 2 6
53939- 74 74 74 250 250 250 253 253 253 253 253 253
53940-253 253 253 253 253 253 253 253 253 253 253 253
53941-253 253 253 253 253 253 242 242 242 242 242 242
53942-253 253 253 253 253 253 253 253 253 253 253 253
53943-253 253 253 253 253 253 253 253 253 253 253 253
53944-253 253 253 253 253 253 253 253 253 253 253 253
53945-253 253 253 253 253 253 253 253 253 253 253 253
53946-253 253 253 253 253 253 182 182 182 2 2 6
53947- 2 2 6 2 2 6 2 2 6 46 46 46
53948- 2 2 6 2 2 6 2 2 6 2 2 6
53949- 10 10 10 86 86 86 38 38 38 10 10 10
53950- 0 0 0 0 0 0 0 0 0 0 0 0
53951- 0 0 0 0 0 0 0 0 0 0 0 0
53952- 0 0 0 0 0 0 0 0 0 0 0 0
53953- 0 0 0 0 0 0 0 0 0 0 0 0
53954- 0 0 0 0 0 0 0 0 0 0 0 0
53955- 0 0 0 0 0 0 0 0 0 0 0 0
53956- 0 0 0 0 0 0 0 0 0 0 0 0
53957- 10 10 10 26 26 26 66 66 66 82 82 82
53958- 2 2 6 22 22 22 18 18 18 2 2 6
53959-149 149 149 253 253 253 253 253 253 253 253 253
53960-253 253 253 253 253 253 253 253 253 253 253 253
53961-253 253 253 253 253 253 234 234 234 242 242 242
53962-253 253 253 253 253 253 253 253 253 253 253 253
53963-253 253 253 253 253 253 253 253 253 253 253 253
53964-253 253 253 253 253 253 253 253 253 253 253 253
53965-253 253 253 253 253 253 253 253 253 253 253 253
53966-253 253 253 253 253 253 206 206 206 2 2 6
53967- 2 2 6 2 2 6 2 2 6 38 38 38
53968- 2 2 6 2 2 6 2 2 6 2 2 6
53969- 6 6 6 86 86 86 46 46 46 14 14 14
53970- 0 0 0 0 0 0 0 0 0 0 0 0
53971- 0 0 0 0 0 0 0 0 0 0 0 0
53972- 0 0 0 0 0 0 0 0 0 0 0 0
53973- 0 0 0 0 0 0 0 0 0 0 0 0
53974- 0 0 0 0 0 0 0 0 0 0 0 0
53975- 0 0 0 0 0 0 0 0 0 0 0 0
53976- 0 0 0 0 0 0 0 0 0 6 6 6
53977- 18 18 18 46 46 46 86 86 86 18 18 18
53978- 2 2 6 34 34 34 10 10 10 6 6 6
53979-210 210 210 253 253 253 253 253 253 253 253 253
53980-253 253 253 253 253 253 253 253 253 253 253 253
53981-253 253 253 253 253 253 234 234 234 242 242 242
53982-253 253 253 253 253 253 253 253 253 253 253 253
53983-253 253 253 253 253 253 253 253 253 253 253 253
53984-253 253 253 253 253 253 253 253 253 253 253 253
53985-253 253 253 253 253 253 253 253 253 253 253 253
53986-253 253 253 253 253 253 221 221 221 6 6 6
53987- 2 2 6 2 2 6 6 6 6 30 30 30
53988- 2 2 6 2 2 6 2 2 6 2 2 6
53989- 2 2 6 82 82 82 54 54 54 18 18 18
53990- 6 6 6 0 0 0 0 0 0 0 0 0
53991- 0 0 0 0 0 0 0 0 0 0 0 0
53992- 0 0 0 0 0 0 0 0 0 0 0 0
53993- 0 0 0 0 0 0 0 0 0 0 0 0
53994- 0 0 0 0 0 0 0 0 0 0 0 0
53995- 0 0 0 0 0 0 0 0 0 0 0 0
53996- 0 0 0 0 0 0 0 0 0 10 10 10
53997- 26 26 26 66 66 66 62 62 62 2 2 6
53998- 2 2 6 38 38 38 10 10 10 26 26 26
53999-238 238 238 253 253 253 253 253 253 253 253 253
54000-253 253 253 253 253 253 253 253 253 253 253 253
54001-253 253 253 253 253 253 231 231 231 238 238 238
54002-253 253 253 253 253 253 253 253 253 253 253 253
54003-253 253 253 253 253 253 253 253 253 253 253 253
54004-253 253 253 253 253 253 253 253 253 253 253 253
54005-253 253 253 253 253 253 253 253 253 253 253 253
54006-253 253 253 253 253 253 231 231 231 6 6 6
54007- 2 2 6 2 2 6 10 10 10 30 30 30
54008- 2 2 6 2 2 6 2 2 6 2 2 6
54009- 2 2 6 66 66 66 58 58 58 22 22 22
54010- 6 6 6 0 0 0 0 0 0 0 0 0
54011- 0 0 0 0 0 0 0 0 0 0 0 0
54012- 0 0 0 0 0 0 0 0 0 0 0 0
54013- 0 0 0 0 0 0 0 0 0 0 0 0
54014- 0 0 0 0 0 0 0 0 0 0 0 0
54015- 0 0 0 0 0 0 0 0 0 0 0 0
54016- 0 0 0 0 0 0 0 0 0 10 10 10
54017- 38 38 38 78 78 78 6 6 6 2 2 6
54018- 2 2 6 46 46 46 14 14 14 42 42 42
54019-246 246 246 253 253 253 253 253 253 253 253 253
54020-253 253 253 253 253 253 253 253 253 253 253 253
54021-253 253 253 253 253 253 231 231 231 242 242 242
54022-253 253 253 253 253 253 253 253 253 253 253 253
54023-253 253 253 253 253 253 253 253 253 253 253 253
54024-253 253 253 253 253 253 253 253 253 253 253 253
54025-253 253 253 253 253 253 253 253 253 253 253 253
54026-253 253 253 253 253 253 234 234 234 10 10 10
54027- 2 2 6 2 2 6 22 22 22 14 14 14
54028- 2 2 6 2 2 6 2 2 6 2 2 6
54029- 2 2 6 66 66 66 62 62 62 22 22 22
54030- 6 6 6 0 0 0 0 0 0 0 0 0
54031- 0 0 0 0 0 0 0 0 0 0 0 0
54032- 0 0 0 0 0 0 0 0 0 0 0 0
54033- 0 0 0 0 0 0 0 0 0 0 0 0
54034- 0 0 0 0 0 0 0 0 0 0 0 0
54035- 0 0 0 0 0 0 0 0 0 0 0 0
54036- 0 0 0 0 0 0 6 6 6 18 18 18
54037- 50 50 50 74 74 74 2 2 6 2 2 6
54038- 14 14 14 70 70 70 34 34 34 62 62 62
54039-250 250 250 253 253 253 253 253 253 253 253 253
54040-253 253 253 253 253 253 253 253 253 253 253 253
54041-253 253 253 253 253 253 231 231 231 246 246 246
54042-253 253 253 253 253 253 253 253 253 253 253 253
54043-253 253 253 253 253 253 253 253 253 253 253 253
54044-253 253 253 253 253 253 253 253 253 253 253 253
54045-253 253 253 253 253 253 253 253 253 253 253 253
54046-253 253 253 253 253 253 234 234 234 14 14 14
54047- 2 2 6 2 2 6 30 30 30 2 2 6
54048- 2 2 6 2 2 6 2 2 6 2 2 6
54049- 2 2 6 66 66 66 62 62 62 22 22 22
54050- 6 6 6 0 0 0 0 0 0 0 0 0
54051- 0 0 0 0 0 0 0 0 0 0 0 0
54052- 0 0 0 0 0 0 0 0 0 0 0 0
54053- 0 0 0 0 0 0 0 0 0 0 0 0
54054- 0 0 0 0 0 0 0 0 0 0 0 0
54055- 0 0 0 0 0 0 0 0 0 0 0 0
54056- 0 0 0 0 0 0 6 6 6 18 18 18
54057- 54 54 54 62 62 62 2 2 6 2 2 6
54058- 2 2 6 30 30 30 46 46 46 70 70 70
54059-250 250 250 253 253 253 253 253 253 253 253 253
54060-253 253 253 253 253 253 253 253 253 253 253 253
54061-253 253 253 253 253 253 231 231 231 246 246 246
54062-253 253 253 253 253 253 253 253 253 253 253 253
54063-253 253 253 253 253 253 253 253 253 253 253 253
54064-253 253 253 253 253 253 253 253 253 253 253 253
54065-253 253 253 253 253 253 253 253 253 253 253 253
54066-253 253 253 253 253 253 226 226 226 10 10 10
54067- 2 2 6 6 6 6 30 30 30 2 2 6
54068- 2 2 6 2 2 6 2 2 6 2 2 6
54069- 2 2 6 66 66 66 58 58 58 22 22 22
54070- 6 6 6 0 0 0 0 0 0 0 0 0
54071- 0 0 0 0 0 0 0 0 0 0 0 0
54072- 0 0 0 0 0 0 0 0 0 0 0 0
54073- 0 0 0 0 0 0 0 0 0 0 0 0
54074- 0 0 0 0 0 0 0 0 0 0 0 0
54075- 0 0 0 0 0 0 0 0 0 0 0 0
54076- 0 0 0 0 0 0 6 6 6 22 22 22
54077- 58 58 58 62 62 62 2 2 6 2 2 6
54078- 2 2 6 2 2 6 30 30 30 78 78 78
54079-250 250 250 253 253 253 253 253 253 253 253 253
54080-253 253 253 253 253 253 253 253 253 253 253 253
54081-253 253 253 253 253 253 231 231 231 246 246 246
54082-253 253 253 253 253 253 253 253 253 253 253 253
54083-253 253 253 253 253 253 253 253 253 253 253 253
54084-253 253 253 253 253 253 253 253 253 253 253 253
54085-253 253 253 253 253 253 253 253 253 253 253 253
54086-253 253 253 253 253 253 206 206 206 2 2 6
54087- 22 22 22 34 34 34 18 14 6 22 22 22
54088- 26 26 26 18 18 18 6 6 6 2 2 6
54089- 2 2 6 82 82 82 54 54 54 18 18 18
54090- 6 6 6 0 0 0 0 0 0 0 0 0
54091- 0 0 0 0 0 0 0 0 0 0 0 0
54092- 0 0 0 0 0 0 0 0 0 0 0 0
54093- 0 0 0 0 0 0 0 0 0 0 0 0
54094- 0 0 0 0 0 0 0 0 0 0 0 0
54095- 0 0 0 0 0 0 0 0 0 0 0 0
54096- 0 0 0 0 0 0 6 6 6 26 26 26
54097- 62 62 62 106 106 106 74 54 14 185 133 11
54098-210 162 10 121 92 8 6 6 6 62 62 62
54099-238 238 238 253 253 253 253 253 253 253 253 253
54100-253 253 253 253 253 253 253 253 253 253 253 253
54101-253 253 253 253 253 253 231 231 231 246 246 246
54102-253 253 253 253 253 253 253 253 253 253 253 253
54103-253 253 253 253 253 253 253 253 253 253 253 253
54104-253 253 253 253 253 253 253 253 253 253 253 253
54105-253 253 253 253 253 253 253 253 253 253 253 253
54106-253 253 253 253 253 253 158 158 158 18 18 18
54107- 14 14 14 2 2 6 2 2 6 2 2 6
54108- 6 6 6 18 18 18 66 66 66 38 38 38
54109- 6 6 6 94 94 94 50 50 50 18 18 18
54110- 6 6 6 0 0 0 0 0 0 0 0 0
54111- 0 0 0 0 0 0 0 0 0 0 0 0
54112- 0 0 0 0 0 0 0 0 0 0 0 0
54113- 0 0 0 0 0 0 0 0 0 0 0 0
54114- 0 0 0 0 0 0 0 0 0 0 0 0
54115- 0 0 0 0 0 0 0 0 0 6 6 6
54116- 10 10 10 10 10 10 18 18 18 38 38 38
54117- 78 78 78 142 134 106 216 158 10 242 186 14
54118-246 190 14 246 190 14 156 118 10 10 10 10
54119- 90 90 90 238 238 238 253 253 253 253 253 253
54120-253 253 253 253 253 253 253 253 253 253 253 253
54121-253 253 253 253 253 253 231 231 231 250 250 250
54122-253 253 253 253 253 253 253 253 253 253 253 253
54123-253 253 253 253 253 253 253 253 253 253 253 253
54124-253 253 253 253 253 253 253 253 253 253 253 253
54125-253 253 253 253 253 253 253 253 253 246 230 190
54126-238 204 91 238 204 91 181 142 44 37 26 9
54127- 2 2 6 2 2 6 2 2 6 2 2 6
54128- 2 2 6 2 2 6 38 38 38 46 46 46
54129- 26 26 26 106 106 106 54 54 54 18 18 18
54130- 6 6 6 0 0 0 0 0 0 0 0 0
54131- 0 0 0 0 0 0 0 0 0 0 0 0
54132- 0 0 0 0 0 0 0 0 0 0 0 0
54133- 0 0 0 0 0 0 0 0 0 0 0 0
54134- 0 0 0 0 0 0 0 0 0 0 0 0
54135- 0 0 0 6 6 6 14 14 14 22 22 22
54136- 30 30 30 38 38 38 50 50 50 70 70 70
54137-106 106 106 190 142 34 226 170 11 242 186 14
54138-246 190 14 246 190 14 246 190 14 154 114 10
54139- 6 6 6 74 74 74 226 226 226 253 253 253
54140-253 253 253 253 253 253 253 253 253 253 253 253
54141-253 253 253 253 253 253 231 231 231 250 250 250
54142-253 253 253 253 253 253 253 253 253 253 253 253
54143-253 253 253 253 253 253 253 253 253 253 253 253
54144-253 253 253 253 253 253 253 253 253 253 253 253
54145-253 253 253 253 253 253 253 253 253 228 184 62
54146-241 196 14 241 208 19 232 195 16 38 30 10
54147- 2 2 6 2 2 6 2 2 6 2 2 6
54148- 2 2 6 6 6 6 30 30 30 26 26 26
54149-203 166 17 154 142 90 66 66 66 26 26 26
54150- 6 6 6 0 0 0 0 0 0 0 0 0
54151- 0 0 0 0 0 0 0 0 0 0 0 0
54152- 0 0 0 0 0 0 0 0 0 0 0 0
54153- 0 0 0 0 0 0 0 0 0 0 0 0
54154- 0 0 0 0 0 0 0 0 0 0 0 0
54155- 6 6 6 18 18 18 38 38 38 58 58 58
54156- 78 78 78 86 86 86 101 101 101 123 123 123
54157-175 146 61 210 150 10 234 174 13 246 186 14
54158-246 190 14 246 190 14 246 190 14 238 190 10
54159-102 78 10 2 2 6 46 46 46 198 198 198
54160-253 253 253 253 253 253 253 253 253 253 253 253
54161-253 253 253 253 253 253 234 234 234 242 242 242
54162-253 253 253 253 253 253 253 253 253 253 253 253
54163-253 253 253 253 253 253 253 253 253 253 253 253
54164-253 253 253 253 253 253 253 253 253 253 253 253
54165-253 253 253 253 253 253 253 253 253 224 178 62
54166-242 186 14 241 196 14 210 166 10 22 18 6
54167- 2 2 6 2 2 6 2 2 6 2 2 6
54168- 2 2 6 2 2 6 6 6 6 121 92 8
54169-238 202 15 232 195 16 82 82 82 34 34 34
54170- 10 10 10 0 0 0 0 0 0 0 0 0
54171- 0 0 0 0 0 0 0 0 0 0 0 0
54172- 0 0 0 0 0 0 0 0 0 0 0 0
54173- 0 0 0 0 0 0 0 0 0 0 0 0
54174- 0 0 0 0 0 0 0 0 0 0 0 0
54175- 14 14 14 38 38 38 70 70 70 154 122 46
54176-190 142 34 200 144 11 197 138 11 197 138 11
54177-213 154 11 226 170 11 242 186 14 246 190 14
54178-246 190 14 246 190 14 246 190 14 246 190 14
54179-225 175 15 46 32 6 2 2 6 22 22 22
54180-158 158 158 250 250 250 253 253 253 253 253 253
54181-253 253 253 253 253 253 253 253 253 253 253 253
54182-253 253 253 253 253 253 253 253 253 253 253 253
54183-253 253 253 253 253 253 253 253 253 253 253 253
54184-253 253 253 253 253 253 253 253 253 253 253 253
54185-253 253 253 250 250 250 242 242 242 224 178 62
54186-239 182 13 236 186 11 213 154 11 46 32 6
54187- 2 2 6 2 2 6 2 2 6 2 2 6
54188- 2 2 6 2 2 6 61 42 6 225 175 15
54189-238 190 10 236 186 11 112 100 78 42 42 42
54190- 14 14 14 0 0 0 0 0 0 0 0 0
54191- 0 0 0 0 0 0 0 0 0 0 0 0
54192- 0 0 0 0 0 0 0 0 0 0 0 0
54193- 0 0 0 0 0 0 0 0 0 0 0 0
54194- 0 0 0 0 0 0 0 0 0 6 6 6
54195- 22 22 22 54 54 54 154 122 46 213 154 11
54196-226 170 11 230 174 11 226 170 11 226 170 11
54197-236 178 12 242 186 14 246 190 14 246 190 14
54198-246 190 14 246 190 14 246 190 14 246 190 14
54199-241 196 14 184 144 12 10 10 10 2 2 6
54200- 6 6 6 116 116 116 242 242 242 253 253 253
54201-253 253 253 253 253 253 253 253 253 253 253 253
54202-253 253 253 253 253 253 253 253 253 253 253 253
54203-253 253 253 253 253 253 253 253 253 253 253 253
54204-253 253 253 253 253 253 253 253 253 253 253 253
54205-253 253 253 231 231 231 198 198 198 214 170 54
54206-236 178 12 236 178 12 210 150 10 137 92 6
54207- 18 14 6 2 2 6 2 2 6 2 2 6
54208- 6 6 6 70 47 6 200 144 11 236 178 12
54209-239 182 13 239 182 13 124 112 88 58 58 58
54210- 22 22 22 6 6 6 0 0 0 0 0 0
54211- 0 0 0 0 0 0 0 0 0 0 0 0
54212- 0 0 0 0 0 0 0 0 0 0 0 0
54213- 0 0 0 0 0 0 0 0 0 0 0 0
54214- 0 0 0 0 0 0 0 0 0 10 10 10
54215- 30 30 30 70 70 70 180 133 36 226 170 11
54216-239 182 13 242 186 14 242 186 14 246 186 14
54217-246 190 14 246 190 14 246 190 14 246 190 14
54218-246 190 14 246 190 14 246 190 14 246 190 14
54219-246 190 14 232 195 16 98 70 6 2 2 6
54220- 2 2 6 2 2 6 66 66 66 221 221 221
54221-253 253 253 253 253 253 253 253 253 253 253 253
54222-253 253 253 253 253 253 253 253 253 253 253 253
54223-253 253 253 253 253 253 253 253 253 253 253 253
54224-253 253 253 253 253 253 253 253 253 253 253 253
54225-253 253 253 206 206 206 198 198 198 214 166 58
54226-230 174 11 230 174 11 216 158 10 192 133 9
54227-163 110 8 116 81 8 102 78 10 116 81 8
54228-167 114 7 197 138 11 226 170 11 239 182 13
54229-242 186 14 242 186 14 162 146 94 78 78 78
54230- 34 34 34 14 14 14 6 6 6 0 0 0
54231- 0 0 0 0 0 0 0 0 0 0 0 0
54232- 0 0 0 0 0 0 0 0 0 0 0 0
54233- 0 0 0 0 0 0 0 0 0 0 0 0
54234- 0 0 0 0 0 0 0 0 0 6 6 6
54235- 30 30 30 78 78 78 190 142 34 226 170 11
54236-239 182 13 246 190 14 246 190 14 246 190 14
54237-246 190 14 246 190 14 246 190 14 246 190 14
54238-246 190 14 246 190 14 246 190 14 246 190 14
54239-246 190 14 241 196 14 203 166 17 22 18 6
54240- 2 2 6 2 2 6 2 2 6 38 38 38
54241-218 218 218 253 253 253 253 253 253 253 253 253
54242-253 253 253 253 253 253 253 253 253 253 253 253
54243-253 253 253 253 253 253 253 253 253 253 253 253
54244-253 253 253 253 253 253 253 253 253 253 253 253
54245-250 250 250 206 206 206 198 198 198 202 162 69
54246-226 170 11 236 178 12 224 166 10 210 150 10
54247-200 144 11 197 138 11 192 133 9 197 138 11
54248-210 150 10 226 170 11 242 186 14 246 190 14
54249-246 190 14 246 186 14 225 175 15 124 112 88
54250- 62 62 62 30 30 30 14 14 14 6 6 6
54251- 0 0 0 0 0 0 0 0 0 0 0 0
54252- 0 0 0 0 0 0 0 0 0 0 0 0
54253- 0 0 0 0 0 0 0 0 0 0 0 0
54254- 0 0 0 0 0 0 0 0 0 10 10 10
54255- 30 30 30 78 78 78 174 135 50 224 166 10
54256-239 182 13 246 190 14 246 190 14 246 190 14
54257-246 190 14 246 190 14 246 190 14 246 190 14
54258-246 190 14 246 190 14 246 190 14 246 190 14
54259-246 190 14 246 190 14 241 196 14 139 102 15
54260- 2 2 6 2 2 6 2 2 6 2 2 6
54261- 78 78 78 250 250 250 253 253 253 253 253 253
54262-253 253 253 253 253 253 253 253 253 253 253 253
54263-253 253 253 253 253 253 253 253 253 253 253 253
54264-253 253 253 253 253 253 253 253 253 253 253 253
54265-250 250 250 214 214 214 198 198 198 190 150 46
54266-219 162 10 236 178 12 234 174 13 224 166 10
54267-216 158 10 213 154 11 213 154 11 216 158 10
54268-226 170 11 239 182 13 246 190 14 246 190 14
54269-246 190 14 246 190 14 242 186 14 206 162 42
54270-101 101 101 58 58 58 30 30 30 14 14 14
54271- 6 6 6 0 0 0 0 0 0 0 0 0
54272- 0 0 0 0 0 0 0 0 0 0 0 0
54273- 0 0 0 0 0 0 0 0 0 0 0 0
54274- 0 0 0 0 0 0 0 0 0 10 10 10
54275- 30 30 30 74 74 74 174 135 50 216 158 10
54276-236 178 12 246 190 14 246 190 14 246 190 14
54277-246 190 14 246 190 14 246 190 14 246 190 14
54278-246 190 14 246 190 14 246 190 14 246 190 14
54279-246 190 14 246 190 14 241 196 14 226 184 13
54280- 61 42 6 2 2 6 2 2 6 2 2 6
54281- 22 22 22 238 238 238 253 253 253 253 253 253
54282-253 253 253 253 253 253 253 253 253 253 253 253
54283-253 253 253 253 253 253 253 253 253 253 253 253
54284-253 253 253 253 253 253 253 253 253 253 253 253
54285-253 253 253 226 226 226 187 187 187 180 133 36
54286-216 158 10 236 178 12 239 182 13 236 178 12
54287-230 174 11 226 170 11 226 170 11 230 174 11
54288-236 178 12 242 186 14 246 190 14 246 190 14
54289-246 190 14 246 190 14 246 186 14 239 182 13
54290-206 162 42 106 106 106 66 66 66 34 34 34
54291- 14 14 14 6 6 6 0 0 0 0 0 0
54292- 0 0 0 0 0 0 0 0 0 0 0 0
54293- 0 0 0 0 0 0 0 0 0 0 0 0
54294- 0 0 0 0 0 0 0 0 0 6 6 6
54295- 26 26 26 70 70 70 163 133 67 213 154 11
54296-236 178 12 246 190 14 246 190 14 246 190 14
54297-246 190 14 246 190 14 246 190 14 246 190 14
54298-246 190 14 246 190 14 246 190 14 246 190 14
54299-246 190 14 246 190 14 246 190 14 241 196 14
54300-190 146 13 18 14 6 2 2 6 2 2 6
54301- 46 46 46 246 246 246 253 253 253 253 253 253
54302-253 253 253 253 253 253 253 253 253 253 253 253
54303-253 253 253 253 253 253 253 253 253 253 253 253
54304-253 253 253 253 253 253 253 253 253 253 253 253
54305-253 253 253 221 221 221 86 86 86 156 107 11
54306-216 158 10 236 178 12 242 186 14 246 186 14
54307-242 186 14 239 182 13 239 182 13 242 186 14
54308-242 186 14 246 186 14 246 190 14 246 190 14
54309-246 190 14 246 190 14 246 190 14 246 190 14
54310-242 186 14 225 175 15 142 122 72 66 66 66
54311- 30 30 30 10 10 10 0 0 0 0 0 0
54312- 0 0 0 0 0 0 0 0 0 0 0 0
54313- 0 0 0 0 0 0 0 0 0 0 0 0
54314- 0 0 0 0 0 0 0 0 0 6 6 6
54315- 26 26 26 70 70 70 163 133 67 210 150 10
54316-236 178 12 246 190 14 246 190 14 246 190 14
54317-246 190 14 246 190 14 246 190 14 246 190 14
54318-246 190 14 246 190 14 246 190 14 246 190 14
54319-246 190 14 246 190 14 246 190 14 246 190 14
54320-232 195 16 121 92 8 34 34 34 106 106 106
54321-221 221 221 253 253 253 253 253 253 253 253 253
54322-253 253 253 253 253 253 253 253 253 253 253 253
54323-253 253 253 253 253 253 253 253 253 253 253 253
54324-253 253 253 253 253 253 253 253 253 253 253 253
54325-242 242 242 82 82 82 18 14 6 163 110 8
54326-216 158 10 236 178 12 242 186 14 246 190 14
54327-246 190 14 246 190 14 246 190 14 246 190 14
54328-246 190 14 246 190 14 246 190 14 246 190 14
54329-246 190 14 246 190 14 246 190 14 246 190 14
54330-246 190 14 246 190 14 242 186 14 163 133 67
54331- 46 46 46 18 18 18 6 6 6 0 0 0
54332- 0 0 0 0 0 0 0 0 0 0 0 0
54333- 0 0 0 0 0 0 0 0 0 0 0 0
54334- 0 0 0 0 0 0 0 0 0 10 10 10
54335- 30 30 30 78 78 78 163 133 67 210 150 10
54336-236 178 12 246 186 14 246 190 14 246 190 14
54337-246 190 14 246 190 14 246 190 14 246 190 14
54338-246 190 14 246 190 14 246 190 14 246 190 14
54339-246 190 14 246 190 14 246 190 14 246 190 14
54340-241 196 14 215 174 15 190 178 144 253 253 253
54341-253 253 253 253 253 253 253 253 253 253 253 253
54342-253 253 253 253 253 253 253 253 253 253 253 253
54343-253 253 253 253 253 253 253 253 253 253 253 253
54344-253 253 253 253 253 253 253 253 253 218 218 218
54345- 58 58 58 2 2 6 22 18 6 167 114 7
54346-216 158 10 236 178 12 246 186 14 246 190 14
54347-246 190 14 246 190 14 246 190 14 246 190 14
54348-246 190 14 246 190 14 246 190 14 246 190 14
54349-246 190 14 246 190 14 246 190 14 246 190 14
54350-246 190 14 246 186 14 242 186 14 190 150 46
54351- 54 54 54 22 22 22 6 6 6 0 0 0
54352- 0 0 0 0 0 0 0 0 0 0 0 0
54353- 0 0 0 0 0 0 0 0 0 0 0 0
54354- 0 0 0 0 0 0 0 0 0 14 14 14
54355- 38 38 38 86 86 86 180 133 36 213 154 11
54356-236 178 12 246 186 14 246 190 14 246 190 14
54357-246 190 14 246 190 14 246 190 14 246 190 14
54358-246 190 14 246 190 14 246 190 14 246 190 14
54359-246 190 14 246 190 14 246 190 14 246 190 14
54360-246 190 14 232 195 16 190 146 13 214 214 214
54361-253 253 253 253 253 253 253 253 253 253 253 253
54362-253 253 253 253 253 253 253 253 253 253 253 253
54363-253 253 253 253 253 253 253 253 253 253 253 253
54364-253 253 253 250 250 250 170 170 170 26 26 26
54365- 2 2 6 2 2 6 37 26 9 163 110 8
54366-219 162 10 239 182 13 246 186 14 246 190 14
54367-246 190 14 246 190 14 246 190 14 246 190 14
54368-246 190 14 246 190 14 246 190 14 246 190 14
54369-246 190 14 246 190 14 246 190 14 246 190 14
54370-246 186 14 236 178 12 224 166 10 142 122 72
54371- 46 46 46 18 18 18 6 6 6 0 0 0
54372- 0 0 0 0 0 0 0 0 0 0 0 0
54373- 0 0 0 0 0 0 0 0 0 0 0 0
54374- 0 0 0 0 0 0 6 6 6 18 18 18
54375- 50 50 50 109 106 95 192 133 9 224 166 10
54376-242 186 14 246 190 14 246 190 14 246 190 14
54377-246 190 14 246 190 14 246 190 14 246 190 14
54378-246 190 14 246 190 14 246 190 14 246 190 14
54379-246 190 14 246 190 14 246 190 14 246 190 14
54380-242 186 14 226 184 13 210 162 10 142 110 46
54381-226 226 226 253 253 253 253 253 253 253 253 253
54382-253 253 253 253 253 253 253 253 253 253 253 253
54383-253 253 253 253 253 253 253 253 253 253 253 253
54384-198 198 198 66 66 66 2 2 6 2 2 6
54385- 2 2 6 2 2 6 50 34 6 156 107 11
54386-219 162 10 239 182 13 246 186 14 246 190 14
54387-246 190 14 246 190 14 246 190 14 246 190 14
54388-246 190 14 246 190 14 246 190 14 246 190 14
54389-246 190 14 246 190 14 246 190 14 242 186 14
54390-234 174 13 213 154 11 154 122 46 66 66 66
54391- 30 30 30 10 10 10 0 0 0 0 0 0
54392- 0 0 0 0 0 0 0 0 0 0 0 0
54393- 0 0 0 0 0 0 0 0 0 0 0 0
54394- 0 0 0 0 0 0 6 6 6 22 22 22
54395- 58 58 58 154 121 60 206 145 10 234 174 13
54396-242 186 14 246 186 14 246 190 14 246 190 14
54397-246 190 14 246 190 14 246 190 14 246 190 14
54398-246 190 14 246 190 14 246 190 14 246 190 14
54399-246 190 14 246 190 14 246 190 14 246 190 14
54400-246 186 14 236 178 12 210 162 10 163 110 8
54401- 61 42 6 138 138 138 218 218 218 250 250 250
54402-253 253 253 253 253 253 253 253 253 250 250 250
54403-242 242 242 210 210 210 144 144 144 66 66 66
54404- 6 6 6 2 2 6 2 2 6 2 2 6
54405- 2 2 6 2 2 6 61 42 6 163 110 8
54406-216 158 10 236 178 12 246 190 14 246 190 14
54407-246 190 14 246 190 14 246 190 14 246 190 14
54408-246 190 14 246 190 14 246 190 14 246 190 14
54409-246 190 14 239 182 13 230 174 11 216 158 10
54410-190 142 34 124 112 88 70 70 70 38 38 38
54411- 18 18 18 6 6 6 0 0 0 0 0 0
54412- 0 0 0 0 0 0 0 0 0 0 0 0
54413- 0 0 0 0 0 0 0 0 0 0 0 0
54414- 0 0 0 0 0 0 6 6 6 22 22 22
54415- 62 62 62 168 124 44 206 145 10 224 166 10
54416-236 178 12 239 182 13 242 186 14 242 186 14
54417-246 186 14 246 190 14 246 190 14 246 190 14
54418-246 190 14 246 190 14 246 190 14 246 190 14
54419-246 190 14 246 190 14 246 190 14 246 190 14
54420-246 190 14 236 178 12 216 158 10 175 118 6
54421- 80 54 7 2 2 6 6 6 6 30 30 30
54422- 54 54 54 62 62 62 50 50 50 38 38 38
54423- 14 14 14 2 2 6 2 2 6 2 2 6
54424- 2 2 6 2 2 6 2 2 6 2 2 6
54425- 2 2 6 6 6 6 80 54 7 167 114 7
54426-213 154 11 236 178 12 246 190 14 246 190 14
54427-246 190 14 246 190 14 246 190 14 246 190 14
54428-246 190 14 242 186 14 239 182 13 239 182 13
54429-230 174 11 210 150 10 174 135 50 124 112 88
54430- 82 82 82 54 54 54 34 34 34 18 18 18
54431- 6 6 6 0 0 0 0 0 0 0 0 0
54432- 0 0 0 0 0 0 0 0 0 0 0 0
54433- 0 0 0 0 0 0 0 0 0 0 0 0
54434- 0 0 0 0 0 0 6 6 6 18 18 18
54435- 50 50 50 158 118 36 192 133 9 200 144 11
54436-216 158 10 219 162 10 224 166 10 226 170 11
54437-230 174 11 236 178 12 239 182 13 239 182 13
54438-242 186 14 246 186 14 246 190 14 246 190 14
54439-246 190 14 246 190 14 246 190 14 246 190 14
54440-246 186 14 230 174 11 210 150 10 163 110 8
54441-104 69 6 10 10 10 2 2 6 2 2 6
54442- 2 2 6 2 2 6 2 2 6 2 2 6
54443- 2 2 6 2 2 6 2 2 6 2 2 6
54444- 2 2 6 2 2 6 2 2 6 2 2 6
54445- 2 2 6 6 6 6 91 60 6 167 114 7
54446-206 145 10 230 174 11 242 186 14 246 190 14
54447-246 190 14 246 190 14 246 186 14 242 186 14
54448-239 182 13 230 174 11 224 166 10 213 154 11
54449-180 133 36 124 112 88 86 86 86 58 58 58
54450- 38 38 38 22 22 22 10 10 10 6 6 6
54451- 0 0 0 0 0 0 0 0 0 0 0 0
54452- 0 0 0 0 0 0 0 0 0 0 0 0
54453- 0 0 0 0 0 0 0 0 0 0 0 0
54454- 0 0 0 0 0 0 0 0 0 14 14 14
54455- 34 34 34 70 70 70 138 110 50 158 118 36
54456-167 114 7 180 123 7 192 133 9 197 138 11
54457-200 144 11 206 145 10 213 154 11 219 162 10
54458-224 166 10 230 174 11 239 182 13 242 186 14
54459-246 186 14 246 186 14 246 186 14 246 186 14
54460-239 182 13 216 158 10 185 133 11 152 99 6
54461-104 69 6 18 14 6 2 2 6 2 2 6
54462- 2 2 6 2 2 6 2 2 6 2 2 6
54463- 2 2 6 2 2 6 2 2 6 2 2 6
54464- 2 2 6 2 2 6 2 2 6 2 2 6
54465- 2 2 6 6 6 6 80 54 7 152 99 6
54466-192 133 9 219 162 10 236 178 12 239 182 13
54467-246 186 14 242 186 14 239 182 13 236 178 12
54468-224 166 10 206 145 10 192 133 9 154 121 60
54469- 94 94 94 62 62 62 42 42 42 22 22 22
54470- 14 14 14 6 6 6 0 0 0 0 0 0
54471- 0 0 0 0 0 0 0 0 0 0 0 0
54472- 0 0 0 0 0 0 0 0 0 0 0 0
54473- 0 0 0 0 0 0 0 0 0 0 0 0
54474- 0 0 0 0 0 0 0 0 0 6 6 6
54475- 18 18 18 34 34 34 58 58 58 78 78 78
54476-101 98 89 124 112 88 142 110 46 156 107 11
54477-163 110 8 167 114 7 175 118 6 180 123 7
54478-185 133 11 197 138 11 210 150 10 219 162 10
54479-226 170 11 236 178 12 236 178 12 234 174 13
54480-219 162 10 197 138 11 163 110 8 130 83 6
54481- 91 60 6 10 10 10 2 2 6 2 2 6
54482- 18 18 18 38 38 38 38 38 38 38 38 38
54483- 38 38 38 38 38 38 38 38 38 38 38 38
54484- 38 38 38 38 38 38 26 26 26 2 2 6
54485- 2 2 6 6 6 6 70 47 6 137 92 6
54486-175 118 6 200 144 11 219 162 10 230 174 11
54487-234 174 13 230 174 11 219 162 10 210 150 10
54488-192 133 9 163 110 8 124 112 88 82 82 82
54489- 50 50 50 30 30 30 14 14 14 6 6 6
54490- 0 0 0 0 0 0 0 0 0 0 0 0
54491- 0 0 0 0 0 0 0 0 0 0 0 0
54492- 0 0 0 0 0 0 0 0 0 0 0 0
54493- 0 0 0 0 0 0 0 0 0 0 0 0
54494- 0 0 0 0 0 0 0 0 0 0 0 0
54495- 6 6 6 14 14 14 22 22 22 34 34 34
54496- 42 42 42 58 58 58 74 74 74 86 86 86
54497-101 98 89 122 102 70 130 98 46 121 87 25
54498-137 92 6 152 99 6 163 110 8 180 123 7
54499-185 133 11 197 138 11 206 145 10 200 144 11
54500-180 123 7 156 107 11 130 83 6 104 69 6
54501- 50 34 6 54 54 54 110 110 110 101 98 89
54502- 86 86 86 82 82 82 78 78 78 78 78 78
54503- 78 78 78 78 78 78 78 78 78 78 78 78
54504- 78 78 78 82 82 82 86 86 86 94 94 94
54505-106 106 106 101 101 101 86 66 34 124 80 6
54506-156 107 11 180 123 7 192 133 9 200 144 11
54507-206 145 10 200 144 11 192 133 9 175 118 6
54508-139 102 15 109 106 95 70 70 70 42 42 42
54509- 22 22 22 10 10 10 0 0 0 0 0 0
54510- 0 0 0 0 0 0 0 0 0 0 0 0
54511- 0 0 0 0 0 0 0 0 0 0 0 0
54512- 0 0 0 0 0 0 0 0 0 0 0 0
54513- 0 0 0 0 0 0 0 0 0 0 0 0
54514- 0 0 0 0 0 0 0 0 0 0 0 0
54515- 0 0 0 0 0 0 6 6 6 10 10 10
54516- 14 14 14 22 22 22 30 30 30 38 38 38
54517- 50 50 50 62 62 62 74 74 74 90 90 90
54518-101 98 89 112 100 78 121 87 25 124 80 6
54519-137 92 6 152 99 6 152 99 6 152 99 6
54520-138 86 6 124 80 6 98 70 6 86 66 30
54521-101 98 89 82 82 82 58 58 58 46 46 46
54522- 38 38 38 34 34 34 34 34 34 34 34 34
54523- 34 34 34 34 34 34 34 34 34 34 34 34
54524- 34 34 34 34 34 34 38 38 38 42 42 42
54525- 54 54 54 82 82 82 94 86 76 91 60 6
54526-134 86 6 156 107 11 167 114 7 175 118 6
54527-175 118 6 167 114 7 152 99 6 121 87 25
54528-101 98 89 62 62 62 34 34 34 18 18 18
54529- 6 6 6 0 0 0 0 0 0 0 0 0
54530- 0 0 0 0 0 0 0 0 0 0 0 0
54531- 0 0 0 0 0 0 0 0 0 0 0 0
54532- 0 0 0 0 0 0 0 0 0 0 0 0
54533- 0 0 0 0 0 0 0 0 0 0 0 0
54534- 0 0 0 0 0 0 0 0 0 0 0 0
54535- 0 0 0 0 0 0 0 0 0 0 0 0
54536- 0 0 0 6 6 6 6 6 6 10 10 10
54537- 18 18 18 22 22 22 30 30 30 42 42 42
54538- 50 50 50 66 66 66 86 86 86 101 98 89
54539-106 86 58 98 70 6 104 69 6 104 69 6
54540-104 69 6 91 60 6 82 62 34 90 90 90
54541- 62 62 62 38 38 38 22 22 22 14 14 14
54542- 10 10 10 10 10 10 10 10 10 10 10 10
54543- 10 10 10 10 10 10 6 6 6 10 10 10
54544- 10 10 10 10 10 10 10 10 10 14 14 14
54545- 22 22 22 42 42 42 70 70 70 89 81 66
54546- 80 54 7 104 69 6 124 80 6 137 92 6
54547-134 86 6 116 81 8 100 82 52 86 86 86
54548- 58 58 58 30 30 30 14 14 14 6 6 6
54549- 0 0 0 0 0 0 0 0 0 0 0 0
54550- 0 0 0 0 0 0 0 0 0 0 0 0
54551- 0 0 0 0 0 0 0 0 0 0 0 0
54552- 0 0 0 0 0 0 0 0 0 0 0 0
54553- 0 0 0 0 0 0 0 0 0 0 0 0
54554- 0 0 0 0 0 0 0 0 0 0 0 0
54555- 0 0 0 0 0 0 0 0 0 0 0 0
54556- 0 0 0 0 0 0 0 0 0 0 0 0
54557- 0 0 0 6 6 6 10 10 10 14 14 14
54558- 18 18 18 26 26 26 38 38 38 54 54 54
54559- 70 70 70 86 86 86 94 86 76 89 81 66
54560- 89 81 66 86 86 86 74 74 74 50 50 50
54561- 30 30 30 14 14 14 6 6 6 0 0 0
54562- 0 0 0 0 0 0 0 0 0 0 0 0
54563- 0 0 0 0 0 0 0 0 0 0 0 0
54564- 0 0 0 0 0 0 0 0 0 0 0 0
54565- 6 6 6 18 18 18 34 34 34 58 58 58
54566- 82 82 82 89 81 66 89 81 66 89 81 66
54567- 94 86 66 94 86 76 74 74 74 50 50 50
54568- 26 26 26 14 14 14 6 6 6 0 0 0
54569- 0 0 0 0 0 0 0 0 0 0 0 0
54570- 0 0 0 0 0 0 0 0 0 0 0 0
54571- 0 0 0 0 0 0 0 0 0 0 0 0
54572- 0 0 0 0 0 0 0 0 0 0 0 0
54573- 0 0 0 0 0 0 0 0 0 0 0 0
54574- 0 0 0 0 0 0 0 0 0 0 0 0
54575- 0 0 0 0 0 0 0 0 0 0 0 0
54576- 0 0 0 0 0 0 0 0 0 0 0 0
54577- 0 0 0 0 0 0 0 0 0 0 0 0
54578- 6 6 6 6 6 6 14 14 14 18 18 18
54579- 30 30 30 38 38 38 46 46 46 54 54 54
54580- 50 50 50 42 42 42 30 30 30 18 18 18
54581- 10 10 10 0 0 0 0 0 0 0 0 0
54582- 0 0 0 0 0 0 0 0 0 0 0 0
54583- 0 0 0 0 0 0 0 0 0 0 0 0
54584- 0 0 0 0 0 0 0 0 0 0 0 0
54585- 0 0 0 6 6 6 14 14 14 26 26 26
54586- 38 38 38 50 50 50 58 58 58 58 58 58
54587- 54 54 54 42 42 42 30 30 30 18 18 18
54588- 10 10 10 0 0 0 0 0 0 0 0 0
54589- 0 0 0 0 0 0 0 0 0 0 0 0
54590- 0 0 0 0 0 0 0 0 0 0 0 0
54591- 0 0 0 0 0 0 0 0 0 0 0 0
54592- 0 0 0 0 0 0 0 0 0 0 0 0
54593- 0 0 0 0 0 0 0 0 0 0 0 0
54594- 0 0 0 0 0 0 0 0 0 0 0 0
54595- 0 0 0 0 0 0 0 0 0 0 0 0
54596- 0 0 0 0 0 0 0 0 0 0 0 0
54597- 0 0 0 0 0 0 0 0 0 0 0 0
54598- 0 0 0 0 0 0 0 0 0 6 6 6
54599- 6 6 6 10 10 10 14 14 14 18 18 18
54600- 18 18 18 14 14 14 10 10 10 6 6 6
54601- 0 0 0 0 0 0 0 0 0 0 0 0
54602- 0 0 0 0 0 0 0 0 0 0 0 0
54603- 0 0 0 0 0 0 0 0 0 0 0 0
54604- 0 0 0 0 0 0 0 0 0 0 0 0
54605- 0 0 0 0 0 0 0 0 0 6 6 6
54606- 14 14 14 18 18 18 22 22 22 22 22 22
54607- 18 18 18 14 14 14 10 10 10 6 6 6
54608- 0 0 0 0 0 0 0 0 0 0 0 0
54609- 0 0 0 0 0 0 0 0 0 0 0 0
54610- 0 0 0 0 0 0 0 0 0 0 0 0
54611- 0 0 0 0 0 0 0 0 0 0 0 0
54612- 0 0 0 0 0 0 0 0 0 0 0 0
54613+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54614+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54615+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54616+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54617+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54618+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54619+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54620+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54621+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54622+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54623+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54624+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54625+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54626+4 4 4 4 4 4
54627+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54628+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54629+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54630+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54631+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54632+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54633+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54634+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54635+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54636+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54637+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54638+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54639+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54640+4 4 4 4 4 4
54641+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54642+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54643+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54644+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54645+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54646+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54647+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54648+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54649+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54650+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54651+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54652+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54653+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54654+4 4 4 4 4 4
54655+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54656+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54657+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54658+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54659+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54660+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54661+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54662+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54663+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54664+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54665+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54666+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54667+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54668+4 4 4 4 4 4
54669+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54670+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54671+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54672+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54673+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54674+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54675+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54676+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54677+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54678+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54679+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54680+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54681+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54682+4 4 4 4 4 4
54683+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54684+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54685+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54686+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54687+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54688+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54689+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54690+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54691+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54692+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54693+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54694+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54695+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54696+4 4 4 4 4 4
54697+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54698+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54699+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54700+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54701+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
54702+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
54703+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54704+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54705+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54706+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
54707+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54708+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
54709+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54710+4 4 4 4 4 4
54711+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54712+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54713+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54714+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54715+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
54716+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
54717+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54718+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54719+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54720+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
54721+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
54722+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
54723+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54724+4 4 4 4 4 4
54725+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54726+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54727+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54728+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54729+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
54730+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
54731+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54732+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54733+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54734+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
54735+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
54736+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
54737+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
54738+4 4 4 4 4 4
54739+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54740+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54741+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54742+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
54743+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
54744+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
54745+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
54746+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54747+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
54748+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
54749+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
54750+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
54751+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
54752+4 4 4 4 4 4
54753+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54754+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54755+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54756+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
54757+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
54758+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
54759+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
54760+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54761+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
54762+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
54763+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
54764+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
54765+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
54766+4 4 4 4 4 4
54767+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54768+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54769+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
54770+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
54771+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
54772+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
54773+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
54774+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
54775+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
54776+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
54777+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
54778+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
54779+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
54780+4 4 4 4 4 4
54781+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54782+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54783+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
54784+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
54785+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
54786+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
54787+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
54788+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
54789+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
54790+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
54791+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
54792+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
54793+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
54794+4 4 4 4 4 4
54795+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54796+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54797+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
54798+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
54799+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
54800+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
54801+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
54802+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
54803+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
54804+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
54805+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
54806+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
54807+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
54808+4 4 4 4 4 4
54809+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54810+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54811+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
54812+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
54813+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
54814+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
54815+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
54816+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
54817+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
54818+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
54819+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
54820+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
54821+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54822+4 4 4 4 4 4
54823+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54824+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54825+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
54826+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
54827+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
54828+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
54829+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
54830+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
54831+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
54832+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
54833+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
54834+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
54835+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
54836+4 4 4 4 4 4
54837+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54838+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
54839+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
54840+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
54841+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
54842+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
54843+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
54844+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
54845+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
54846+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
54847+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
54848+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
54849+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
54850+4 4 4 4 4 4
54851+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54852+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
54853+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
54854+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
54855+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
54856+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
54857+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
54858+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
54859+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
54860+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
54861+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
54862+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
54863+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
54864+0 0 0 4 4 4
54865+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
54866+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
54867+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
54868+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
54869+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
54870+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
54871+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
54872+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
54873+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
54874+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
54875+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
54876+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
54877+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
54878+2 0 0 0 0 0
54879+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
54880+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
54881+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
54882+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
54883+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
54884+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
54885+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
54886+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
54887+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
54888+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
54889+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
54890+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
54891+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
54892+37 38 37 0 0 0
54893+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
54894+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
54895+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
54896+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
54897+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
54898+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
54899+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
54900+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
54901+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
54902+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
54903+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
54904+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
54905+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
54906+85 115 134 4 0 0
54907+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
54908+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
54909+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
54910+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
54911+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
54912+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
54913+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
54914+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
54915+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
54916+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
54917+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
54918+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
54919+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
54920+60 73 81 4 0 0
54921+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
54922+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
54923+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
54924+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
54925+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
54926+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
54927+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
54928+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
54929+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
54930+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
54931+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
54932+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
54933+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
54934+16 19 21 4 0 0
54935+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
54936+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
54937+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
54938+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
54939+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
54940+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
54941+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
54942+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
54943+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
54944+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
54945+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
54946+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
54947+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
54948+4 0 0 4 3 3
54949+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
54950+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
54951+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
54952+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
54953+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
54954+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
54955+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
54956+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
54957+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
54958+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
54959+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
54960+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
54961+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
54962+3 2 2 4 4 4
54963+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
54964+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
54965+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
54966+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
54967+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
54968+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
54969+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
54970+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
54971+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
54972+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
54973+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
54974+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
54975+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
54976+4 4 4 4 4 4
54977+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
54978+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
54979+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
54980+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
54981+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
54982+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
54983+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
54984+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
54985+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
54986+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
54987+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
54988+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
54989+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
54990+4 4 4 4 4 4
54991+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
54992+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
54993+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
54994+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
54995+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
54996+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
54997+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
54998+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
54999+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
55000+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
55001+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
55002+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
55003+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
55004+5 5 5 5 5 5
55005+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
55006+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
55007+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
55008+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
55009+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
55010+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55011+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
55012+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
55013+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
55014+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
55015+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
55016+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
55017+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
55018+5 5 5 4 4 4
55019+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
55020+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
55021+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
55022+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
55023+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
55024+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
55025+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
55026+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
55027+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
55028+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
55029+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
55030+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
55031+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55032+4 4 4 4 4 4
55033+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
55034+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
55035+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
55036+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
55037+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
55038+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55039+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55040+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
55041+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
55042+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
55043+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
55044+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
55045+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55046+4 4 4 4 4 4
55047+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
55048+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
55049+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
55050+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
55051+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
55052+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
55053+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
55054+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
55055+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
55056+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
55057+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
55058+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55059+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55060+4 4 4 4 4 4
55061+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
55062+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
55063+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
55064+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
55065+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55066+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55067+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55068+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
55069+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
55070+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
55071+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
55072+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55073+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55074+4 4 4 4 4 4
55075+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
55076+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
55077+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
55078+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
55079+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55080+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
55081+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
55082+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
55083+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
55084+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
55085+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55086+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55087+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55088+4 4 4 4 4 4
55089+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
55090+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
55091+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
55092+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
55093+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55094+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
55095+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
55096+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
55097+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
55098+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
55099+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
55100+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55101+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55102+4 4 4 4 4 4
55103+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
55104+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
55105+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
55106+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
55107+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
55108+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
55109+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
55110+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
55111+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
55112+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
55113+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
55114+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55115+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55116+4 4 4 4 4 4
55117+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
55118+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
55119+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
55120+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
55121+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
55122+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
55123+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
55124+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
55125+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
55126+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
55127+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55128+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55129+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55130+4 4 4 4 4 4
55131+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
55132+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
55133+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
55134+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
55135+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55136+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
55137+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
55138+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
55139+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
55140+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
55141+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55142+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55143+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55144+4 4 4 4 4 4
55145+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
55146+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
55147+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
55148+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
55149+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55150+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
55151+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
55152+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
55153+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
55154+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
55155+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55156+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55157+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55158+4 4 4 4 4 4
55159+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
55160+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
55161+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
55162+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
55163+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55164+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
55165+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
55166+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
55167+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
55168+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55169+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55170+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55171+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55172+4 4 4 4 4 4
55173+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
55174+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
55175+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
55176+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
55177+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
55178+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
55179+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
55180+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
55181+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55182+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55183+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55184+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55185+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55186+4 4 4 4 4 4
55187+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
55188+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
55189+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
55190+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
55191+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55192+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
55193+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
55194+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
55195+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
55196+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55197+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55198+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55199+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55200+4 4 4 4 4 4
55201+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
55202+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
55203+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
55204+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
55205+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
55206+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
55207+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
55208+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
55209+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55210+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55211+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55212+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55213+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55214+4 4 4 4 4 4
55215+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
55216+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
55217+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
55218+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
55219+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
55220+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
55221+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
55222+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
55223+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
55224+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55225+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55226+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55227+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55228+4 4 4 4 4 4
55229+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
55230+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
55231+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
55232+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
55233+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
55234+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
55235+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
55236+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
55237+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55238+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55239+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55240+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55241+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55242+4 4 4 4 4 4
55243+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
55244+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
55245+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
55246+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
55247+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
55248+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
55249+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
55250+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
55251+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
55252+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55253+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55254+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55255+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55256+4 4 4 4 4 4
55257+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
55258+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
55259+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
55260+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
55261+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
55262+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
55263+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
55264+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
55265+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55266+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55267+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55268+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55269+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55270+4 4 4 4 4 4
55271+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55272+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
55273+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
55274+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
55275+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
55276+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
55277+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
55278+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
55279+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
55280+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55281+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55282+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55283+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55284+4 4 4 4 4 4
55285+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
55286+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
55287+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
55288+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
55289+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
55290+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
55291+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55292+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
55293+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55294+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55295+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55296+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55297+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55298+4 4 4 4 4 4
55299+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55300+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
55301+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
55302+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
55303+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
55304+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
55305+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55306+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
55307+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
55308+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55309+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55310+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55311+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55312+4 4 4 4 4 4
55313+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
55314+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
55315+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
55316+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
55317+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
55318+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
55319+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
55320+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
55321+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
55322+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55323+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55324+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55325+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55326+4 4 4 4 4 4
55327+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55328+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
55329+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
55330+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
55331+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
55332+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
55333+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
55334+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
55335+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
55336+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55337+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55338+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55339+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55340+4 4 4 4 4 4
55341+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
55342+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
55343+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
55344+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
55345+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
55346+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
55347+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
55348+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
55349+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
55350+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55351+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55352+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55353+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55354+4 4 4 4 4 4
55355+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55356+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
55357+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
55358+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
55359+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
55360+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
55361+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
55362+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
55363+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
55364+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55365+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55366+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55367+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55368+4 4 4 4 4 4
55369+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
55370+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
55371+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
55372+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
55373+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
55374+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
55375+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
55376+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
55377+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
55378+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
55379+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55380+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55381+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55382+4 4 4 4 4 4
55383+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
55384+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
55385+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
55386+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
55387+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
55388+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
55389+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
55390+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
55391+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
55392+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
55393+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55394+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55395+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55396+4 4 4 4 4 4
55397+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
55398+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
55399+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
55400+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
55401+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
55402+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
55403+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55404+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
55405+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
55406+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
55407+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55408+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55409+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55410+4 4 4 4 4 4
55411+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
55412+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
55413+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
55414+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
55415+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
55416+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
55417+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
55418+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
55419+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
55420+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
55421+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55422+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55423+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55424+4 4 4 4 4 4
55425+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
55426+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
55427+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
55428+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
55429+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
55430+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
55431+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
55432+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
55433+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
55434+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
55435+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55436+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55437+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55438+4 4 4 4 4 4
55439+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55440+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
55441+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
55442+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
55443+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
55444+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
55445+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
55446+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
55447+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
55448+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
55449+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55450+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55451+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55452+4 4 4 4 4 4
55453+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
55454+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
55455+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
55456+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
55457+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
55458+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
55459+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
55460+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
55461+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
55462+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
55463+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55464+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55465+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55466+4 4 4 4 4 4
55467+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
55468+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
55469+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
55470+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
55471+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
55472+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
55473+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
55474+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
55475+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
55476+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55477+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55478+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55479+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55480+4 4 4 4 4 4
55481+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
55482+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55483+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
55484+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
55485+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
55486+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
55487+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
55488+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
55489+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
55490+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55491+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55492+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55493+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55494+4 4 4 4 4 4
55495+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
55496+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
55497+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
55498+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
55499+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
55500+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
55501+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
55502+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
55503+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
55504+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55505+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55506+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55507+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55508+4 4 4 4 4 4
55509+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
55510+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
55511+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
55512+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
55513+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
55514+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
55515+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
55516+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
55517+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55518+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55519+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55520+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55521+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55522+4 4 4 4 4 4
55523+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
55524+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
55525+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
55526+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
55527+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
55528+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
55529+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
55530+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
55531+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55532+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55533+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55534+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55535+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55536+4 4 4 4 4 4
55537+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
55538+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
55539+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
55540+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
55541+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
55542+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
55543+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
55544+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
55545+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55546+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55547+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55548+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55549+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55550+4 4 4 4 4 4
55551+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55552+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
55553+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55554+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
55555+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
55556+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
55557+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
55558+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
55559+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55560+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55561+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55562+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55563+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55564+4 4 4 4 4 4
55565+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55566+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
55567+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
55568+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
55569+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
55570+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
55571+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
55572+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
55573+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55574+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55575+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55576+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55577+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55578+4 4 4 4 4 4
55579+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55580+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
55581+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
55582+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
55583+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
55584+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
55585+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
55586+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55587+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55588+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55589+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55590+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55591+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55592+4 4 4 4 4 4
55593+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55594+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55595+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
55596+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
55597+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
55598+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
55599+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
55600+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55601+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55602+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55603+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55604+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55605+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55606+4 4 4 4 4 4
55607+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55608+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55609+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55610+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55611+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
55612+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
55613+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
55614+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55615+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55616+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55617+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55618+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55619+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55620+4 4 4 4 4 4
55621+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55622+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55623+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55624+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
55625+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
55626+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
55627+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
55628+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55629+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55630+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55631+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55632+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55633+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55634+4 4 4 4 4 4
55635+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55636+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55637+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55638+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
55639+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55640+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
55641+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
55642+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55643+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55644+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55645+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55646+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55647+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55648+4 4 4 4 4 4
55649+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55650+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55651+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55652+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
55653+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
55654+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
55655+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
55656+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55657+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55658+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55659+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55660+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55661+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55662+4 4 4 4 4 4
55663+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55664+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55665+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55666+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55667+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
55668+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55669+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55670+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55671+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55672+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55673+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55674+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55675+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55676+4 4 4 4 4 4
55677+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55678+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55679+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55680+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55681+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
55682+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
55683+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
55684+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55685+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55686+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55687+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55688+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55689+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55690+4 4 4 4 4 4
55691+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55692+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55693+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55694+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55695+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
55696+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
55697+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55698+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55699+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55700+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55701+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55702+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55703+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55704+4 4 4 4 4 4
55705+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55706+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55707+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55708+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55709+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
55710+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
55711+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55712+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55713+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55714+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55715+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55716+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55717+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55718+4 4 4 4 4 4
55719+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55720+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55721+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55722+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55723+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
55724+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
55725+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55726+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55727+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55728+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55729+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55730+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55731+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55732+4 4 4 4 4 4
55733diff --git a/drivers/video/matrox/matroxfb_DAC1064.c b/drivers/video/matrox/matroxfb_DAC1064.c
55734index a01147f..5d896f8 100644
55735--- a/drivers/video/matrox/matroxfb_DAC1064.c
55736+++ b/drivers/video/matrox/matroxfb_DAC1064.c
55737@@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
55738
55739 #ifdef CONFIG_FB_MATROX_MYSTIQUE
55740 struct matrox_switch matrox_mystique = {
55741- MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
55742+ .preinit = MGA1064_preinit,
55743+ .reset = MGA1064_reset,
55744+ .init = MGA1064_init,
55745+ .restore = MGA1064_restore,
55746 };
55747 EXPORT_SYMBOL(matrox_mystique);
55748 #endif
55749
55750 #ifdef CONFIG_FB_MATROX_G
55751 struct matrox_switch matrox_G100 = {
55752- MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
55753+ .preinit = MGAG100_preinit,
55754+ .reset = MGAG100_reset,
55755+ .init = MGAG100_init,
55756+ .restore = MGAG100_restore,
55757 };
55758 EXPORT_SYMBOL(matrox_G100);
55759 #endif
55760diff --git a/drivers/video/matrox/matroxfb_Ti3026.c b/drivers/video/matrox/matroxfb_Ti3026.c
55761index 195ad7c..09743fc 100644
55762--- a/drivers/video/matrox/matroxfb_Ti3026.c
55763+++ b/drivers/video/matrox/matroxfb_Ti3026.c
55764@@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
55765 }
55766
55767 struct matrox_switch matrox_millennium = {
55768- Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
55769+ .preinit = Ti3026_preinit,
55770+ .reset = Ti3026_reset,
55771+ .init = Ti3026_init,
55772+ .restore = Ti3026_restore
55773 };
55774 EXPORT_SYMBOL(matrox_millennium);
55775 #endif
55776diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
55777index fe92eed..106e085 100644
55778--- a/drivers/video/mb862xx/mb862xxfb_accel.c
55779+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
55780@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
55781 struct mb862xxfb_par *par = info->par;
55782
55783 if (info->var.bits_per_pixel == 32) {
55784- info->fbops->fb_fillrect = cfb_fillrect;
55785- info->fbops->fb_copyarea = cfb_copyarea;
55786- info->fbops->fb_imageblit = cfb_imageblit;
55787+ pax_open_kernel();
55788+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55789+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55790+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55791+ pax_close_kernel();
55792 } else {
55793 outreg(disp, GC_L0EM, 3);
55794- info->fbops->fb_fillrect = mb86290fb_fillrect;
55795- info->fbops->fb_copyarea = mb86290fb_copyarea;
55796- info->fbops->fb_imageblit = mb86290fb_imageblit;
55797+ pax_open_kernel();
55798+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
55799+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
55800+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
55801+ pax_close_kernel();
55802 }
55803 outreg(draw, GDC_REG_DRAW_BASE, 0);
55804 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
55805diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
55806index def0412..fed6529 100644
55807--- a/drivers/video/nvidia/nvidia.c
55808+++ b/drivers/video/nvidia/nvidia.c
55809@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
55810 info->fix.line_length = (info->var.xres_virtual *
55811 info->var.bits_per_pixel) >> 3;
55812 if (info->var.accel_flags) {
55813- info->fbops->fb_imageblit = nvidiafb_imageblit;
55814- info->fbops->fb_fillrect = nvidiafb_fillrect;
55815- info->fbops->fb_copyarea = nvidiafb_copyarea;
55816- info->fbops->fb_sync = nvidiafb_sync;
55817+ pax_open_kernel();
55818+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
55819+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
55820+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
55821+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
55822+ pax_close_kernel();
55823 info->pixmap.scan_align = 4;
55824 info->flags &= ~FBINFO_HWACCEL_DISABLED;
55825 info->flags |= FBINFO_READS_FAST;
55826 NVResetGraphics(info);
55827 } else {
55828- info->fbops->fb_imageblit = cfb_imageblit;
55829- info->fbops->fb_fillrect = cfb_fillrect;
55830- info->fbops->fb_copyarea = cfb_copyarea;
55831- info->fbops->fb_sync = NULL;
55832+ pax_open_kernel();
55833+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55834+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55835+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55836+ *(void **)&info->fbops->fb_sync = NULL;
55837+ pax_close_kernel();
55838 info->pixmap.scan_align = 1;
55839 info->flags |= FBINFO_HWACCEL_DISABLED;
55840 info->flags &= ~FBINFO_READS_FAST;
55841@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
55842 info->pixmap.size = 8 * 1024;
55843 info->pixmap.flags = FB_PIXMAP_SYSTEM;
55844
55845- if (!hwcur)
55846- info->fbops->fb_cursor = NULL;
55847+ if (!hwcur) {
55848+ pax_open_kernel();
55849+ *(void **)&info->fbops->fb_cursor = NULL;
55850+ pax_close_kernel();
55851+ }
55852
55853 info->var.accel_flags = (!noaccel);
55854
55855diff --git a/drivers/video/omap2/dss/display.c b/drivers/video/omap2/dss/display.c
55856index 669a81f..e216d76 100644
55857--- a/drivers/video/omap2/dss/display.c
55858+++ b/drivers/video/omap2/dss/display.c
55859@@ -137,12 +137,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
55860 snprintf(dssdev->alias, sizeof(dssdev->alias),
55861 "display%d", disp_num_counter++);
55862
55863+ pax_open_kernel();
55864 if (drv && drv->get_resolution == NULL)
55865- drv->get_resolution = omapdss_default_get_resolution;
55866+ *(void **)&drv->get_resolution = omapdss_default_get_resolution;
55867 if (drv && drv->get_recommended_bpp == NULL)
55868- drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55869+ *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55870 if (drv && drv->get_timings == NULL)
55871- drv->get_timings = omapdss_default_get_timings;
55872+ *(void **)&drv->get_timings = omapdss_default_get_timings;
55873+ pax_close_kernel();
55874
55875 mutex_lock(&panel_list_mutex);
55876 list_add_tail(&dssdev->panel_list, &panel_list);
55877diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
55878index 83433cb..71e9b98 100644
55879--- a/drivers/video/s1d13xxxfb.c
55880+++ b/drivers/video/s1d13xxxfb.c
55881@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
55882
55883 switch(prod_id) {
55884 case S1D13506_PROD_ID: /* activate acceleration */
55885- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55886- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55887+ pax_open_kernel();
55888+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55889+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55890+ pax_close_kernel();
55891 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
55892 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
55893 break;
55894diff --git a/drivers/video/sh_mobile_lcdcfb.c b/drivers/video/sh_mobile_lcdcfb.c
55895index 2bcc84a..29dd1ea 100644
55896--- a/drivers/video/sh_mobile_lcdcfb.c
55897+++ b/drivers/video/sh_mobile_lcdcfb.c
55898@@ -439,9 +439,9 @@ static unsigned long lcdc_sys_read_data(void *handle)
55899 }
55900
55901 static struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
55902- lcdc_sys_write_index,
55903- lcdc_sys_write_data,
55904- lcdc_sys_read_data,
55905+ .write_index = lcdc_sys_write_index,
55906+ .write_data = lcdc_sys_write_data,
55907+ .read_data = lcdc_sys_read_data,
55908 };
55909
55910 static int sh_mobile_lcdc_sginit(struct fb_info *info,
55911diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
55912index d513ed6..90b0de9 100644
55913--- a/drivers/video/smscufx.c
55914+++ b/drivers/video/smscufx.c
55915@@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
55916 fb_deferred_io_cleanup(info);
55917 kfree(info->fbdefio);
55918 info->fbdefio = NULL;
55919- info->fbops->fb_mmap = ufx_ops_mmap;
55920+ pax_open_kernel();
55921+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
55922+ pax_close_kernel();
55923 }
55924
55925 pr_debug("released /dev/fb%d user=%d count=%d",
55926diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
55927index 77b890e..458e666 100644
55928--- a/drivers/video/udlfb.c
55929+++ b/drivers/video/udlfb.c
55930@@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
55931 dlfb_urb_completion(urb);
55932
55933 error:
55934- atomic_add(bytes_sent, &dev->bytes_sent);
55935- atomic_add(bytes_identical, &dev->bytes_identical);
55936- atomic_add(width*height*2, &dev->bytes_rendered);
55937+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55938+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55939+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
55940 end_cycles = get_cycles();
55941- atomic_add(((unsigned int) ((end_cycles - start_cycles)
55942+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55943 >> 10)), /* Kcycles */
55944 &dev->cpu_kcycles_used);
55945
55946@@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
55947 dlfb_urb_completion(urb);
55948
55949 error:
55950- atomic_add(bytes_sent, &dev->bytes_sent);
55951- atomic_add(bytes_identical, &dev->bytes_identical);
55952- atomic_add(bytes_rendered, &dev->bytes_rendered);
55953+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55954+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55955+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
55956 end_cycles = get_cycles();
55957- atomic_add(((unsigned int) ((end_cycles - start_cycles)
55958+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55959 >> 10)), /* Kcycles */
55960 &dev->cpu_kcycles_used);
55961 }
55962@@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
55963 fb_deferred_io_cleanup(info);
55964 kfree(info->fbdefio);
55965 info->fbdefio = NULL;
55966- info->fbops->fb_mmap = dlfb_ops_mmap;
55967+ pax_open_kernel();
55968+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
55969+ pax_close_kernel();
55970 }
55971
55972 pr_warn("released /dev/fb%d user=%d count=%d\n",
55973@@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
55974 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55975 struct dlfb_data *dev = fb_info->par;
55976 return snprintf(buf, PAGE_SIZE, "%u\n",
55977- atomic_read(&dev->bytes_rendered));
55978+ atomic_read_unchecked(&dev->bytes_rendered));
55979 }
55980
55981 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55982@@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55983 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55984 struct dlfb_data *dev = fb_info->par;
55985 return snprintf(buf, PAGE_SIZE, "%u\n",
55986- atomic_read(&dev->bytes_identical));
55987+ atomic_read_unchecked(&dev->bytes_identical));
55988 }
55989
55990 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55991@@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55992 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55993 struct dlfb_data *dev = fb_info->par;
55994 return snprintf(buf, PAGE_SIZE, "%u\n",
55995- atomic_read(&dev->bytes_sent));
55996+ atomic_read_unchecked(&dev->bytes_sent));
55997 }
55998
55999 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
56000@@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
56001 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56002 struct dlfb_data *dev = fb_info->par;
56003 return snprintf(buf, PAGE_SIZE, "%u\n",
56004- atomic_read(&dev->cpu_kcycles_used));
56005+ atomic_read_unchecked(&dev->cpu_kcycles_used));
56006 }
56007
56008 static ssize_t edid_show(
56009@@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
56010 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56011 struct dlfb_data *dev = fb_info->par;
56012
56013- atomic_set(&dev->bytes_rendered, 0);
56014- atomic_set(&dev->bytes_identical, 0);
56015- atomic_set(&dev->bytes_sent, 0);
56016- atomic_set(&dev->cpu_kcycles_used, 0);
56017+ atomic_set_unchecked(&dev->bytes_rendered, 0);
56018+ atomic_set_unchecked(&dev->bytes_identical, 0);
56019+ atomic_set_unchecked(&dev->bytes_sent, 0);
56020+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
56021
56022 return count;
56023 }
56024diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
56025index 256fba7..6e75516 100644
56026--- a/drivers/video/uvesafb.c
56027+++ b/drivers/video/uvesafb.c
56028@@ -19,6 +19,7 @@
56029 #include <linux/io.h>
56030 #include <linux/mutex.h>
56031 #include <linux/slab.h>
56032+#include <linux/moduleloader.h>
56033 #include <video/edid.h>
56034 #include <video/uvesafb.h>
56035 #ifdef CONFIG_X86
56036@@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
56037 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
56038 par->pmi_setpal = par->ypan = 0;
56039 } else {
56040+
56041+#ifdef CONFIG_PAX_KERNEXEC
56042+#ifdef CONFIG_MODULES
56043+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
56044+#endif
56045+ if (!par->pmi_code) {
56046+ par->pmi_setpal = par->ypan = 0;
56047+ return 0;
56048+ }
56049+#endif
56050+
56051 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
56052 + task->t.regs.edi);
56053+
56054+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56055+ pax_open_kernel();
56056+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
56057+ pax_close_kernel();
56058+
56059+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
56060+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
56061+#else
56062 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
56063 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
56064+#endif
56065+
56066 printk(KERN_INFO "uvesafb: protected mode interface info at "
56067 "%04x:%04x\n",
56068 (u16)task->t.regs.es, (u16)task->t.regs.edi);
56069@@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
56070 par->ypan = ypan;
56071
56072 if (par->pmi_setpal || par->ypan) {
56073+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
56074 if (__supported_pte_mask & _PAGE_NX) {
56075 par->pmi_setpal = par->ypan = 0;
56076 printk(KERN_WARNING "uvesafb: NX protection is active, "
56077 "better not use the PMI.\n");
56078- } else {
56079+ } else
56080+#endif
56081 uvesafb_vbe_getpmi(task, par);
56082- }
56083 }
56084 #else
56085 /* The protected mode interface is not available on non-x86. */
56086@@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
56087 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
56088
56089 /* Disable blanking if the user requested so. */
56090- if (!blank)
56091- info->fbops->fb_blank = NULL;
56092+ if (!blank) {
56093+ pax_open_kernel();
56094+ *(void **)&info->fbops->fb_blank = NULL;
56095+ pax_close_kernel();
56096+ }
56097
56098 /*
56099 * Find out how much IO memory is required for the mode with
56100@@ -1530,8 +1557,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
56101 info->flags = FBINFO_FLAG_DEFAULT |
56102 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
56103
56104- if (!par->ypan)
56105- info->fbops->fb_pan_display = NULL;
56106+ if (!par->ypan) {
56107+ pax_open_kernel();
56108+ *(void **)&info->fbops->fb_pan_display = NULL;
56109+ pax_close_kernel();
56110+ }
56111 }
56112
56113 static void uvesafb_init_mtrr(struct fb_info *info)
56114@@ -1792,6 +1822,11 @@ out_mode:
56115 out:
56116 kfree(par->vbe_modes);
56117
56118+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56119+ if (par->pmi_code)
56120+ module_free_exec(NULL, par->pmi_code);
56121+#endif
56122+
56123 framebuffer_release(info);
56124 return err;
56125 }
56126@@ -1816,6 +1851,12 @@ static int uvesafb_remove(struct platform_device *dev)
56127 kfree(par->vbe_modes);
56128 kfree(par->vbe_state_orig);
56129 kfree(par->vbe_state_saved);
56130+
56131+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56132+ if (par->pmi_code)
56133+ module_free_exec(NULL, par->pmi_code);
56134+#endif
56135+
56136 }
56137
56138 framebuffer_release(info);
56139diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
56140index 1c7da3b..56ea0bd 100644
56141--- a/drivers/video/vesafb.c
56142+++ b/drivers/video/vesafb.c
56143@@ -9,6 +9,7 @@
56144 */
56145
56146 #include <linux/module.h>
56147+#include <linux/moduleloader.h>
56148 #include <linux/kernel.h>
56149 #include <linux/errno.h>
56150 #include <linux/string.h>
56151@@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
56152 static int vram_total; /* Set total amount of memory */
56153 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
56154 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
56155-static void (*pmi_start)(void) __read_mostly;
56156-static void (*pmi_pal) (void) __read_mostly;
56157+static void (*pmi_start)(void) __read_only;
56158+static void (*pmi_pal) (void) __read_only;
56159 static int depth __read_mostly;
56160 static int vga_compat __read_mostly;
56161 /* --------------------------------------------------------------------- */
56162@@ -234,6 +235,7 @@ static int vesafb_probe(struct platform_device *dev)
56163 unsigned int size_remap;
56164 unsigned int size_total;
56165 char *option = NULL;
56166+ void *pmi_code = NULL;
56167
56168 /* ignore error return of fb_get_options */
56169 fb_get_options("vesafb", &option);
56170@@ -280,10 +282,6 @@ static int vesafb_probe(struct platform_device *dev)
56171 size_remap = size_total;
56172 vesafb_fix.smem_len = size_remap;
56173
56174-#ifndef __i386__
56175- screen_info.vesapm_seg = 0;
56176-#endif
56177-
56178 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
56179 printk(KERN_WARNING
56180 "vesafb: cannot reserve video memory at 0x%lx\n",
56181@@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
56182 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
56183 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
56184
56185+#ifdef __i386__
56186+
56187+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56188+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
56189+ if (!pmi_code)
56190+#elif !defined(CONFIG_PAX_KERNEXEC)
56191+ if (0)
56192+#endif
56193+
56194+#endif
56195+ screen_info.vesapm_seg = 0;
56196+
56197 if (screen_info.vesapm_seg) {
56198- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
56199- screen_info.vesapm_seg,screen_info.vesapm_off);
56200+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
56201+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
56202 }
56203
56204 if (screen_info.vesapm_seg < 0xc000)
56205@@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
56206
56207 if (ypan || pmi_setpal) {
56208 unsigned short *pmi_base;
56209+
56210 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
56211- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
56212- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
56213+
56214+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56215+ pax_open_kernel();
56216+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
56217+#else
56218+ pmi_code = pmi_base;
56219+#endif
56220+
56221+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
56222+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
56223+
56224+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56225+ pmi_start = ktva_ktla(pmi_start);
56226+ pmi_pal = ktva_ktla(pmi_pal);
56227+ pax_close_kernel();
56228+#endif
56229+
56230 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
56231 if (pmi_base[3]) {
56232 printk(KERN_INFO "vesafb: pmi: ports = ");
56233@@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
56234 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
56235 (ypan ? FBINFO_HWACCEL_YPAN : 0);
56236
56237- if (!ypan)
56238- info->fbops->fb_pan_display = NULL;
56239+ if (!ypan) {
56240+ pax_open_kernel();
56241+ *(void **)&info->fbops->fb_pan_display = NULL;
56242+ pax_close_kernel();
56243+ }
56244
56245 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
56246 err = -ENOMEM;
56247@@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
56248 fb_info(info, "%s frame buffer device\n", info->fix.id);
56249 return 0;
56250 err:
56251+
56252+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56253+ module_free_exec(NULL, pmi_code);
56254+#endif
56255+
56256 if (info->screen_base)
56257 iounmap(info->screen_base);
56258 framebuffer_release(info);
56259diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
56260index 88714ae..16c2e11 100644
56261--- a/drivers/video/via/via_clock.h
56262+++ b/drivers/video/via/via_clock.h
56263@@ -56,7 +56,7 @@ struct via_clock {
56264
56265 void (*set_engine_pll_state)(u8 state);
56266 void (*set_engine_pll)(struct via_pll_config config);
56267-};
56268+} __no_const;
56269
56270
56271 static inline u32 get_pll_internal_frequency(u32 ref_freq,
56272diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
56273index fef20db..d28b1ab 100644
56274--- a/drivers/xen/xenfs/xenstored.c
56275+++ b/drivers/xen/xenfs/xenstored.c
56276@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
56277 static int xsd_kva_open(struct inode *inode, struct file *file)
56278 {
56279 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
56280+#ifdef CONFIG_GRKERNSEC_HIDESYM
56281+ NULL);
56282+#else
56283 xen_store_interface);
56284+#endif
56285+
56286 if (!file->private_data)
56287 return -ENOMEM;
56288 return 0;
56289diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
56290index c71e886..61d3d44b 100644
56291--- a/fs/9p/vfs_addr.c
56292+++ b/fs/9p/vfs_addr.c
56293@@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
56294
56295 retval = v9fs_file_write_internal(inode,
56296 v9inode->writeback_fid,
56297- (__force const char __user *)buffer,
56298+ (const char __force_user *)buffer,
56299 len, &offset, 0);
56300 if (retval > 0)
56301 retval = 0;
56302diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
56303index bb7991c..481e21a 100644
56304--- a/fs/9p/vfs_inode.c
56305+++ b/fs/9p/vfs_inode.c
56306@@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
56307 void
56308 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
56309 {
56310- char *s = nd_get_link(nd);
56311+ const char *s = nd_get_link(nd);
56312
56313 p9_debug(P9_DEBUG_VFS, " %s %s\n",
56314 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
56315diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
56316index 370b24c..ff0be7b 100644
56317--- a/fs/Kconfig.binfmt
56318+++ b/fs/Kconfig.binfmt
56319@@ -103,7 +103,7 @@ config HAVE_AOUT
56320
56321 config BINFMT_AOUT
56322 tristate "Kernel support for a.out and ECOFF binaries"
56323- depends on HAVE_AOUT
56324+ depends on HAVE_AOUT && BROKEN
56325 ---help---
56326 A.out (Assembler.OUTput) is a set of formats for libraries and
56327 executables used in the earliest versions of UNIX. Linux used
56328diff --git a/fs/affs/super.c b/fs/affs/super.c
56329index d098731..9a5b19d 100644
56330--- a/fs/affs/super.c
56331+++ b/fs/affs/super.c
56332@@ -336,8 +336,6 @@ static int affs_fill_super(struct super_block *sb, void *data, int silent)
56333 &blocksize,&sbi->s_prefix,
56334 sbi->s_volume, &mount_flags)) {
56335 printk(KERN_ERR "AFFS: Error parsing options\n");
56336- kfree(sbi->s_prefix);
56337- kfree(sbi);
56338 return -EINVAL;
56339 }
56340 /* N.B. after this point s_prefix must be released */
56341diff --git a/fs/afs/inode.c b/fs/afs/inode.c
56342index ce25d75..dc09eeb 100644
56343--- a/fs/afs/inode.c
56344+++ b/fs/afs/inode.c
56345@@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
56346 struct afs_vnode *vnode;
56347 struct super_block *sb;
56348 struct inode *inode;
56349- static atomic_t afs_autocell_ino;
56350+ static atomic_unchecked_t afs_autocell_ino;
56351
56352 _enter("{%x:%u},%*.*s,",
56353 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
56354@@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
56355 data.fid.unique = 0;
56356 data.fid.vnode = 0;
56357
56358- inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
56359+ inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
56360 afs_iget5_autocell_test, afs_iget5_set,
56361 &data);
56362 if (!inode) {
56363diff --git a/fs/aio.c b/fs/aio.c
56364index 12a3de0e..25949c1 100644
56365--- a/fs/aio.c
56366+++ b/fs/aio.c
56367@@ -375,7 +375,7 @@ static int aio_setup_ring(struct kioctx *ctx)
56368 size += sizeof(struct io_event) * nr_events;
56369
56370 nr_pages = PFN_UP(size);
56371- if (nr_pages < 0)
56372+ if (nr_pages <= 0)
56373 return -EINVAL;
56374
56375 file = aio_private_file(ctx, nr_pages);
56376@@ -1299,10 +1299,8 @@ rw_common:
56377 &iovec, compat)
56378 : aio_setup_single_vector(req, rw, buf, &nr_segs,
56379 iovec);
56380- if (ret)
56381- return ret;
56382-
56383- ret = rw_verify_area(rw, file, &req->ki_pos, req->ki_nbytes);
56384+ if (!ret)
56385+ ret = rw_verify_area(rw, file, &req->ki_pos, req->ki_nbytes);
56386 if (ret < 0) {
56387 if (iovec != &inline_vec)
56388 kfree(iovec);
56389diff --git a/fs/attr.c b/fs/attr.c
56390index 5d4e59d..fd02418 100644
56391--- a/fs/attr.c
56392+++ b/fs/attr.c
56393@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
56394 unsigned long limit;
56395
56396 limit = rlimit(RLIMIT_FSIZE);
56397+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
56398 if (limit != RLIM_INFINITY && offset > limit)
56399 goto out_sig;
56400 if (offset > inode->i_sb->s_maxbytes)
56401diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
56402index 116fd38..c04182da 100644
56403--- a/fs/autofs4/waitq.c
56404+++ b/fs/autofs4/waitq.c
56405@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
56406 {
56407 unsigned long sigpipe, flags;
56408 mm_segment_t fs;
56409- const char *data = (const char *)addr;
56410+ const char __user *data = (const char __force_user *)addr;
56411 ssize_t wr = 0;
56412
56413 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
56414@@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
56415 return 1;
56416 }
56417
56418+#ifdef CONFIG_GRKERNSEC_HIDESYM
56419+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
56420+#endif
56421+
56422 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
56423 enum autofs_notify notify)
56424 {
56425@@ -385,7 +389,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
56426
56427 /* If this is a direct mount request create a dummy name */
56428 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
56429+#ifdef CONFIG_GRKERNSEC_HIDESYM
56430+ /* this name does get written to userland via autofs4_write() */
56431+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
56432+#else
56433 qstr.len = sprintf(name, "%p", dentry);
56434+#endif
56435 else {
56436 qstr.len = autofs4_getpath(sbi, dentry, &name);
56437 if (!qstr.len) {
56438diff --git a/fs/befs/endian.h b/fs/befs/endian.h
56439index 2722387..56059b5 100644
56440--- a/fs/befs/endian.h
56441+++ b/fs/befs/endian.h
56442@@ -11,7 +11,7 @@
56443
56444 #include <asm/byteorder.h>
56445
56446-static inline u64
56447+static inline u64 __intentional_overflow(-1)
56448 fs64_to_cpu(const struct super_block *sb, fs64 n)
56449 {
56450 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56451@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
56452 return (__force fs64)cpu_to_be64(n);
56453 }
56454
56455-static inline u32
56456+static inline u32 __intentional_overflow(-1)
56457 fs32_to_cpu(const struct super_block *sb, fs32 n)
56458 {
56459 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56460@@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
56461 return (__force fs32)cpu_to_be32(n);
56462 }
56463
56464-static inline u16
56465+static inline u16 __intentional_overflow(-1)
56466 fs16_to_cpu(const struct super_block *sb, fs16 n)
56467 {
56468 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56469diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
56470index ca0ba15..0fa3257 100644
56471--- a/fs/binfmt_aout.c
56472+++ b/fs/binfmt_aout.c
56473@@ -16,6 +16,7 @@
56474 #include <linux/string.h>
56475 #include <linux/fs.h>
56476 #include <linux/file.h>
56477+#include <linux/security.h>
56478 #include <linux/stat.h>
56479 #include <linux/fcntl.h>
56480 #include <linux/ptrace.h>
56481@@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
56482 #endif
56483 # define START_STACK(u) ((void __user *)u.start_stack)
56484
56485+ memset(&dump, 0, sizeof(dump));
56486+
56487 fs = get_fs();
56488 set_fs(KERNEL_DS);
56489 has_dumped = 1;
56490@@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
56491
56492 /* If the size of the dump file exceeds the rlimit, then see what would happen
56493 if we wrote the stack, but not the data area. */
56494+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
56495 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
56496 dump.u_dsize = 0;
56497
56498 /* Make sure we have enough room to write the stack and data areas. */
56499+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
56500 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
56501 dump.u_ssize = 0;
56502
56503@@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
56504 rlim = rlimit(RLIMIT_DATA);
56505 if (rlim >= RLIM_INFINITY)
56506 rlim = ~0;
56507+
56508+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
56509 if (ex.a_data + ex.a_bss > rlim)
56510 return -ENOMEM;
56511
56512@@ -264,6 +271,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
56513
56514 install_exec_creds(bprm);
56515
56516+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56517+ current->mm->pax_flags = 0UL;
56518+#endif
56519+
56520+#ifdef CONFIG_PAX_PAGEEXEC
56521+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
56522+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
56523+
56524+#ifdef CONFIG_PAX_EMUTRAMP
56525+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
56526+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
56527+#endif
56528+
56529+#ifdef CONFIG_PAX_MPROTECT
56530+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
56531+ current->mm->pax_flags |= MF_PAX_MPROTECT;
56532+#endif
56533+
56534+ }
56535+#endif
56536+
56537 if (N_MAGIC(ex) == OMAGIC) {
56538 unsigned long text_addr, map_size;
56539 loff_t pos;
56540@@ -321,7 +349,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
56541 }
56542
56543 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
56544- PROT_READ | PROT_WRITE | PROT_EXEC,
56545+ PROT_READ | PROT_WRITE,
56546 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
56547 fd_offset + ex.a_text);
56548 if (error != N_DATADDR(ex)) {
56549diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
56550index 67be295..83e2f86 100644
56551--- a/fs/binfmt_elf.c
56552+++ b/fs/binfmt_elf.c
56553@@ -34,6 +34,7 @@
56554 #include <linux/utsname.h>
56555 #include <linux/coredump.h>
56556 #include <linux/sched.h>
56557+#include <linux/xattr.h>
56558 #include <asm/uaccess.h>
56559 #include <asm/param.h>
56560 #include <asm/page.h>
56561@@ -48,7 +49,7 @@
56562 static int load_elf_binary(struct linux_binprm *bprm);
56563 static int load_elf_library(struct file *);
56564 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
56565- int, int, unsigned long);
56566+ int, int, unsigned long) __intentional_overflow(-1);
56567
56568 /*
56569 * If we don't support core dumping, then supply a NULL so we
56570@@ -60,6 +61,14 @@ static int elf_core_dump(struct coredump_params *cprm);
56571 #define elf_core_dump NULL
56572 #endif
56573
56574+#ifdef CONFIG_PAX_MPROTECT
56575+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
56576+#endif
56577+
56578+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56579+static void elf_handle_mmap(struct file *file);
56580+#endif
56581+
56582 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
56583 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
56584 #else
56585@@ -79,6 +88,15 @@ static struct linux_binfmt elf_format = {
56586 .load_binary = load_elf_binary,
56587 .load_shlib = load_elf_library,
56588 .core_dump = elf_core_dump,
56589+
56590+#ifdef CONFIG_PAX_MPROTECT
56591+ .handle_mprotect= elf_handle_mprotect,
56592+#endif
56593+
56594+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56595+ .handle_mmap = elf_handle_mmap,
56596+#endif
56597+
56598 .min_coredump = ELF_EXEC_PAGESIZE,
56599 };
56600
56601@@ -86,6 +104,8 @@ static struct linux_binfmt elf_format = {
56602
56603 static int set_brk(unsigned long start, unsigned long end)
56604 {
56605+ unsigned long e = end;
56606+
56607 start = ELF_PAGEALIGN(start);
56608 end = ELF_PAGEALIGN(end);
56609 if (end > start) {
56610@@ -94,7 +114,7 @@ static int set_brk(unsigned long start, unsigned long end)
56611 if (BAD_ADDR(addr))
56612 return addr;
56613 }
56614- current->mm->start_brk = current->mm->brk = end;
56615+ current->mm->start_brk = current->mm->brk = e;
56616 return 0;
56617 }
56618
56619@@ -155,12 +175,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56620 elf_addr_t __user *u_rand_bytes;
56621 const char *k_platform = ELF_PLATFORM;
56622 const char *k_base_platform = ELF_BASE_PLATFORM;
56623- unsigned char k_rand_bytes[16];
56624+ u32 k_rand_bytes[4];
56625 int items;
56626 elf_addr_t *elf_info;
56627 int ei_index = 0;
56628 const struct cred *cred = current_cred();
56629 struct vm_area_struct *vma;
56630+ unsigned long saved_auxv[AT_VECTOR_SIZE];
56631
56632 /*
56633 * In some cases (e.g. Hyper-Threading), we want to avoid L1
56634@@ -202,8 +223,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56635 * Generate 16 random bytes for userspace PRNG seeding.
56636 */
56637 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
56638- u_rand_bytes = (elf_addr_t __user *)
56639- STACK_ALLOC(p, sizeof(k_rand_bytes));
56640+ prandom_seed(k_rand_bytes[0] ^ prandom_u32());
56641+ prandom_seed(k_rand_bytes[1] ^ prandom_u32());
56642+ prandom_seed(k_rand_bytes[2] ^ prandom_u32());
56643+ prandom_seed(k_rand_bytes[3] ^ prandom_u32());
56644+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
56645+ u_rand_bytes = (elf_addr_t __user *) p;
56646 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
56647 return -EFAULT;
56648
56649@@ -318,9 +343,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56650 return -EFAULT;
56651 current->mm->env_end = p;
56652
56653+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
56654+
56655 /* Put the elf_info on the stack in the right place. */
56656 sp = (elf_addr_t __user *)envp + 1;
56657- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
56658+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
56659 return -EFAULT;
56660 return 0;
56661 }
56662@@ -388,15 +415,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
56663 an ELF header */
56664
56665 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56666- struct file *interpreter, unsigned long *interp_map_addr,
56667- unsigned long no_base)
56668+ struct file *interpreter, unsigned long no_base)
56669 {
56670 struct elf_phdr *elf_phdata;
56671 struct elf_phdr *eppnt;
56672- unsigned long load_addr = 0;
56673+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
56674 int load_addr_set = 0;
56675 unsigned long last_bss = 0, elf_bss = 0;
56676- unsigned long error = ~0UL;
56677+ unsigned long error = -EINVAL;
56678 unsigned long total_size;
56679 int retval, i, size;
56680
56681@@ -442,6 +468,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56682 goto out_close;
56683 }
56684
56685+#ifdef CONFIG_PAX_SEGMEXEC
56686+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
56687+ pax_task_size = SEGMEXEC_TASK_SIZE;
56688+#endif
56689+
56690 eppnt = elf_phdata;
56691 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
56692 if (eppnt->p_type == PT_LOAD) {
56693@@ -465,8 +496,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56694 map_addr = elf_map(interpreter, load_addr + vaddr,
56695 eppnt, elf_prot, elf_type, total_size);
56696 total_size = 0;
56697- if (!*interp_map_addr)
56698- *interp_map_addr = map_addr;
56699 error = map_addr;
56700 if (BAD_ADDR(map_addr))
56701 goto out_close;
56702@@ -485,8 +514,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56703 k = load_addr + eppnt->p_vaddr;
56704 if (BAD_ADDR(k) ||
56705 eppnt->p_filesz > eppnt->p_memsz ||
56706- eppnt->p_memsz > TASK_SIZE ||
56707- TASK_SIZE - eppnt->p_memsz < k) {
56708+ eppnt->p_memsz > pax_task_size ||
56709+ pax_task_size - eppnt->p_memsz < k) {
56710 error = -ENOMEM;
56711 goto out_close;
56712 }
56713@@ -525,9 +554,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56714 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
56715
56716 /* Map the last of the bss segment */
56717- error = vm_brk(elf_bss, last_bss - elf_bss);
56718- if (BAD_ADDR(error))
56719- goto out_close;
56720+ if (last_bss > elf_bss) {
56721+ error = vm_brk(elf_bss, last_bss - elf_bss);
56722+ if (BAD_ADDR(error))
56723+ goto out_close;
56724+ }
56725 }
56726
56727 error = load_addr;
56728@@ -538,6 +569,336 @@ out:
56729 return error;
56730 }
56731
56732+#ifdef CONFIG_PAX_PT_PAX_FLAGS
56733+#ifdef CONFIG_PAX_SOFTMODE
56734+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
56735+{
56736+ unsigned long pax_flags = 0UL;
56737+
56738+#ifdef CONFIG_PAX_PAGEEXEC
56739+ if (elf_phdata->p_flags & PF_PAGEEXEC)
56740+ pax_flags |= MF_PAX_PAGEEXEC;
56741+#endif
56742+
56743+#ifdef CONFIG_PAX_SEGMEXEC
56744+ if (elf_phdata->p_flags & PF_SEGMEXEC)
56745+ pax_flags |= MF_PAX_SEGMEXEC;
56746+#endif
56747+
56748+#ifdef CONFIG_PAX_EMUTRAMP
56749+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56750+ pax_flags |= MF_PAX_EMUTRAMP;
56751+#endif
56752+
56753+#ifdef CONFIG_PAX_MPROTECT
56754+ if (elf_phdata->p_flags & PF_MPROTECT)
56755+ pax_flags |= MF_PAX_MPROTECT;
56756+#endif
56757+
56758+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56759+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
56760+ pax_flags |= MF_PAX_RANDMMAP;
56761+#endif
56762+
56763+ return pax_flags;
56764+}
56765+#endif
56766+
56767+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
56768+{
56769+ unsigned long pax_flags = 0UL;
56770+
56771+#ifdef CONFIG_PAX_PAGEEXEC
56772+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
56773+ pax_flags |= MF_PAX_PAGEEXEC;
56774+#endif
56775+
56776+#ifdef CONFIG_PAX_SEGMEXEC
56777+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
56778+ pax_flags |= MF_PAX_SEGMEXEC;
56779+#endif
56780+
56781+#ifdef CONFIG_PAX_EMUTRAMP
56782+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
56783+ pax_flags |= MF_PAX_EMUTRAMP;
56784+#endif
56785+
56786+#ifdef CONFIG_PAX_MPROTECT
56787+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
56788+ pax_flags |= MF_PAX_MPROTECT;
56789+#endif
56790+
56791+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56792+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
56793+ pax_flags |= MF_PAX_RANDMMAP;
56794+#endif
56795+
56796+ return pax_flags;
56797+}
56798+#endif
56799+
56800+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56801+#ifdef CONFIG_PAX_SOFTMODE
56802+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
56803+{
56804+ unsigned long pax_flags = 0UL;
56805+
56806+#ifdef CONFIG_PAX_PAGEEXEC
56807+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
56808+ pax_flags |= MF_PAX_PAGEEXEC;
56809+#endif
56810+
56811+#ifdef CONFIG_PAX_SEGMEXEC
56812+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
56813+ pax_flags |= MF_PAX_SEGMEXEC;
56814+#endif
56815+
56816+#ifdef CONFIG_PAX_EMUTRAMP
56817+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56818+ pax_flags |= MF_PAX_EMUTRAMP;
56819+#endif
56820+
56821+#ifdef CONFIG_PAX_MPROTECT
56822+ if (pax_flags_softmode & MF_PAX_MPROTECT)
56823+ pax_flags |= MF_PAX_MPROTECT;
56824+#endif
56825+
56826+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56827+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
56828+ pax_flags |= MF_PAX_RANDMMAP;
56829+#endif
56830+
56831+ return pax_flags;
56832+}
56833+#endif
56834+
56835+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
56836+{
56837+ unsigned long pax_flags = 0UL;
56838+
56839+#ifdef CONFIG_PAX_PAGEEXEC
56840+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
56841+ pax_flags |= MF_PAX_PAGEEXEC;
56842+#endif
56843+
56844+#ifdef CONFIG_PAX_SEGMEXEC
56845+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
56846+ pax_flags |= MF_PAX_SEGMEXEC;
56847+#endif
56848+
56849+#ifdef CONFIG_PAX_EMUTRAMP
56850+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
56851+ pax_flags |= MF_PAX_EMUTRAMP;
56852+#endif
56853+
56854+#ifdef CONFIG_PAX_MPROTECT
56855+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
56856+ pax_flags |= MF_PAX_MPROTECT;
56857+#endif
56858+
56859+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56860+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
56861+ pax_flags |= MF_PAX_RANDMMAP;
56862+#endif
56863+
56864+ return pax_flags;
56865+}
56866+#endif
56867+
56868+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56869+static unsigned long pax_parse_defaults(void)
56870+{
56871+ unsigned long pax_flags = 0UL;
56872+
56873+#ifdef CONFIG_PAX_SOFTMODE
56874+ if (pax_softmode)
56875+ return pax_flags;
56876+#endif
56877+
56878+#ifdef CONFIG_PAX_PAGEEXEC
56879+ pax_flags |= MF_PAX_PAGEEXEC;
56880+#endif
56881+
56882+#ifdef CONFIG_PAX_SEGMEXEC
56883+ pax_flags |= MF_PAX_SEGMEXEC;
56884+#endif
56885+
56886+#ifdef CONFIG_PAX_MPROTECT
56887+ pax_flags |= MF_PAX_MPROTECT;
56888+#endif
56889+
56890+#ifdef CONFIG_PAX_RANDMMAP
56891+ if (randomize_va_space)
56892+ pax_flags |= MF_PAX_RANDMMAP;
56893+#endif
56894+
56895+ return pax_flags;
56896+}
56897+
56898+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
56899+{
56900+ unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
56901+
56902+#ifdef CONFIG_PAX_EI_PAX
56903+
56904+#ifdef CONFIG_PAX_SOFTMODE
56905+ if (pax_softmode)
56906+ return pax_flags;
56907+#endif
56908+
56909+ pax_flags = 0UL;
56910+
56911+#ifdef CONFIG_PAX_PAGEEXEC
56912+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
56913+ pax_flags |= MF_PAX_PAGEEXEC;
56914+#endif
56915+
56916+#ifdef CONFIG_PAX_SEGMEXEC
56917+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
56918+ pax_flags |= MF_PAX_SEGMEXEC;
56919+#endif
56920+
56921+#ifdef CONFIG_PAX_EMUTRAMP
56922+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
56923+ pax_flags |= MF_PAX_EMUTRAMP;
56924+#endif
56925+
56926+#ifdef CONFIG_PAX_MPROTECT
56927+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
56928+ pax_flags |= MF_PAX_MPROTECT;
56929+#endif
56930+
56931+#ifdef CONFIG_PAX_ASLR
56932+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
56933+ pax_flags |= MF_PAX_RANDMMAP;
56934+#endif
56935+
56936+#endif
56937+
56938+ return pax_flags;
56939+
56940+}
56941+
56942+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
56943+{
56944+
56945+#ifdef CONFIG_PAX_PT_PAX_FLAGS
56946+ unsigned long i;
56947+
56948+ for (i = 0UL; i < elf_ex->e_phnum; i++)
56949+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
56950+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
56951+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
56952+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
56953+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
56954+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
56955+ return PAX_PARSE_FLAGS_FALLBACK;
56956+
56957+#ifdef CONFIG_PAX_SOFTMODE
56958+ if (pax_softmode)
56959+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
56960+ else
56961+#endif
56962+
56963+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
56964+ break;
56965+ }
56966+#endif
56967+
56968+ return PAX_PARSE_FLAGS_FALLBACK;
56969+}
56970+
56971+static unsigned long pax_parse_xattr_pax(struct file * const file)
56972+{
56973+
56974+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56975+ ssize_t xattr_size, i;
56976+ unsigned char xattr_value[sizeof("pemrs") - 1];
56977+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
56978+
56979+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
56980+ if (xattr_size < 0 || xattr_size > sizeof xattr_value)
56981+ return PAX_PARSE_FLAGS_FALLBACK;
56982+
56983+ for (i = 0; i < xattr_size; i++)
56984+ switch (xattr_value[i]) {
56985+ default:
56986+ return PAX_PARSE_FLAGS_FALLBACK;
56987+
56988+#define parse_flag(option1, option2, flag) \
56989+ case option1: \
56990+ if (pax_flags_hardmode & MF_PAX_##flag) \
56991+ return PAX_PARSE_FLAGS_FALLBACK;\
56992+ pax_flags_hardmode |= MF_PAX_##flag; \
56993+ break; \
56994+ case option2: \
56995+ if (pax_flags_softmode & MF_PAX_##flag) \
56996+ return PAX_PARSE_FLAGS_FALLBACK;\
56997+ pax_flags_softmode |= MF_PAX_##flag; \
56998+ break;
56999+
57000+ parse_flag('p', 'P', PAGEEXEC);
57001+ parse_flag('e', 'E', EMUTRAMP);
57002+ parse_flag('m', 'M', MPROTECT);
57003+ parse_flag('r', 'R', RANDMMAP);
57004+ parse_flag('s', 'S', SEGMEXEC);
57005+
57006+#undef parse_flag
57007+ }
57008+
57009+ if (pax_flags_hardmode & pax_flags_softmode)
57010+ return PAX_PARSE_FLAGS_FALLBACK;
57011+
57012+#ifdef CONFIG_PAX_SOFTMODE
57013+ if (pax_softmode)
57014+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
57015+ else
57016+#endif
57017+
57018+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
57019+#else
57020+ return PAX_PARSE_FLAGS_FALLBACK;
57021+#endif
57022+
57023+}
57024+
57025+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
57026+{
57027+ unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
57028+
57029+ pax_flags = pax_parse_defaults();
57030+ ei_pax_flags = pax_parse_ei_pax(elf_ex);
57031+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
57032+ xattr_pax_flags = pax_parse_xattr_pax(file);
57033+
57034+ if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
57035+ xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
57036+ pt_pax_flags != xattr_pax_flags)
57037+ return -EINVAL;
57038+ if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
57039+ pax_flags = xattr_pax_flags;
57040+ else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
57041+ pax_flags = pt_pax_flags;
57042+ else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
57043+ pax_flags = ei_pax_flags;
57044+
57045+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
57046+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
57047+ if ((__supported_pte_mask & _PAGE_NX))
57048+ pax_flags &= ~MF_PAX_SEGMEXEC;
57049+ else
57050+ pax_flags &= ~MF_PAX_PAGEEXEC;
57051+ }
57052+#endif
57053+
57054+ if (0 > pax_check_flags(&pax_flags))
57055+ return -EINVAL;
57056+
57057+ current->mm->pax_flags = pax_flags;
57058+ return 0;
57059+}
57060+#endif
57061+
57062 /*
57063 * These are the functions used to load ELF style executables and shared
57064 * libraries. There is no binary dependent code anywhere else.
57065@@ -551,6 +912,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
57066 {
57067 unsigned int random_variable = 0;
57068
57069+#ifdef CONFIG_PAX_RANDUSTACK
57070+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
57071+ return stack_top - current->mm->delta_stack;
57072+#endif
57073+
57074 if ((current->flags & PF_RANDOMIZE) &&
57075 !(current->personality & ADDR_NO_RANDOMIZE)) {
57076 random_variable = get_random_int() & STACK_RND_MASK;
57077@@ -569,7 +935,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
57078 unsigned long load_addr = 0, load_bias = 0;
57079 int load_addr_set = 0;
57080 char * elf_interpreter = NULL;
57081- unsigned long error;
57082+ unsigned long error = 0;
57083 struct elf_phdr *elf_ppnt, *elf_phdata;
57084 unsigned long elf_bss, elf_brk;
57085 int retval, i;
57086@@ -579,12 +945,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
57087 unsigned long start_code, end_code, start_data, end_data;
57088 unsigned long reloc_func_desc __maybe_unused = 0;
57089 int executable_stack = EXSTACK_DEFAULT;
57090- unsigned long def_flags = 0;
57091 struct pt_regs *regs = current_pt_regs();
57092 struct {
57093 struct elfhdr elf_ex;
57094 struct elfhdr interp_elf_ex;
57095 } *loc;
57096+ unsigned long pax_task_size;
57097
57098 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
57099 if (!loc) {
57100@@ -720,11 +1086,82 @@ static int load_elf_binary(struct linux_binprm *bprm)
57101 goto out_free_dentry;
57102
57103 /* OK, This is the point of no return */
57104- current->mm->def_flags = def_flags;
57105+ current->mm->def_flags = 0;
57106
57107 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
57108 may depend on the personality. */
57109 SET_PERSONALITY(loc->elf_ex);
57110+
57111+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
57112+ current->mm->pax_flags = 0UL;
57113+#endif
57114+
57115+#ifdef CONFIG_PAX_DLRESOLVE
57116+ current->mm->call_dl_resolve = 0UL;
57117+#endif
57118+
57119+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
57120+ current->mm->call_syscall = 0UL;
57121+#endif
57122+
57123+#ifdef CONFIG_PAX_ASLR
57124+ current->mm->delta_mmap = 0UL;
57125+ current->mm->delta_stack = 0UL;
57126+#endif
57127+
57128+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
57129+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
57130+ send_sig(SIGKILL, current, 0);
57131+ goto out_free_dentry;
57132+ }
57133+#endif
57134+
57135+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57136+ pax_set_initial_flags(bprm);
57137+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
57138+ if (pax_set_initial_flags_func)
57139+ (pax_set_initial_flags_func)(bprm);
57140+#endif
57141+
57142+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
57143+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
57144+ current->mm->context.user_cs_limit = PAGE_SIZE;
57145+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
57146+ }
57147+#endif
57148+
57149+#ifdef CONFIG_PAX_SEGMEXEC
57150+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
57151+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
57152+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
57153+ pax_task_size = SEGMEXEC_TASK_SIZE;
57154+ current->mm->def_flags |= VM_NOHUGEPAGE;
57155+ } else
57156+#endif
57157+
57158+ pax_task_size = TASK_SIZE;
57159+
57160+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
57161+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
57162+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
57163+ put_cpu();
57164+ }
57165+#endif
57166+
57167+#ifdef CONFIG_PAX_ASLR
57168+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
57169+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
57170+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
57171+ }
57172+#endif
57173+
57174+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
57175+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
57176+ executable_stack = EXSTACK_DISABLE_X;
57177+ current->personality &= ~READ_IMPLIES_EXEC;
57178+ } else
57179+#endif
57180+
57181 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
57182 current->personality |= READ_IMPLIES_EXEC;
57183
57184@@ -814,6 +1251,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
57185 #else
57186 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
57187 #endif
57188+
57189+#ifdef CONFIG_PAX_RANDMMAP
57190+ /* PaX: randomize base address at the default exe base if requested */
57191+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
57192+#ifdef CONFIG_SPARC64
57193+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
57194+#else
57195+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
57196+#endif
57197+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
57198+ elf_flags |= MAP_FIXED;
57199+ }
57200+#endif
57201+
57202 }
57203
57204 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
57205@@ -846,9 +1297,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
57206 * allowed task size. Note that p_filesz must always be
57207 * <= p_memsz so it is only necessary to check p_memsz.
57208 */
57209- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
57210- elf_ppnt->p_memsz > TASK_SIZE ||
57211- TASK_SIZE - elf_ppnt->p_memsz < k) {
57212+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
57213+ elf_ppnt->p_memsz > pax_task_size ||
57214+ pax_task_size - elf_ppnt->p_memsz < k) {
57215 /* set_brk can never work. Avoid overflows. */
57216 send_sig(SIGKILL, current, 0);
57217 retval = -EINVAL;
57218@@ -887,17 +1338,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
57219 goto out_free_dentry;
57220 }
57221 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
57222- send_sig(SIGSEGV, current, 0);
57223- retval = -EFAULT; /* Nobody gets to see this, but.. */
57224- goto out_free_dentry;
57225+ /*
57226+ * This bss-zeroing can fail if the ELF
57227+ * file specifies odd protections. So
57228+ * we don't check the return value
57229+ */
57230 }
57231
57232+#ifdef CONFIG_PAX_RANDMMAP
57233+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
57234+ unsigned long start, size, flags;
57235+ vm_flags_t vm_flags;
57236+
57237+ start = ELF_PAGEALIGN(elf_brk);
57238+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
57239+ flags = MAP_FIXED | MAP_PRIVATE;
57240+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
57241+
57242+ down_write(&current->mm->mmap_sem);
57243+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
57244+ retval = -ENOMEM;
57245+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
57246+// if (current->personality & ADDR_NO_RANDOMIZE)
57247+// vm_flags |= VM_READ | VM_MAYREAD;
57248+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
57249+ retval = IS_ERR_VALUE(start) ? start : 0;
57250+ }
57251+ up_write(&current->mm->mmap_sem);
57252+ if (retval == 0)
57253+ retval = set_brk(start + size, start + size + PAGE_SIZE);
57254+ if (retval < 0) {
57255+ send_sig(SIGKILL, current, 0);
57256+ goto out_free_dentry;
57257+ }
57258+ }
57259+#endif
57260+
57261 if (elf_interpreter) {
57262- unsigned long interp_map_addr = 0;
57263-
57264 elf_entry = load_elf_interp(&loc->interp_elf_ex,
57265 interpreter,
57266- &interp_map_addr,
57267 load_bias);
57268 if (!IS_ERR((void *)elf_entry)) {
57269 /*
57270@@ -1119,7 +1598,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
57271 * Decide what to dump of a segment, part, all or none.
57272 */
57273 static unsigned long vma_dump_size(struct vm_area_struct *vma,
57274- unsigned long mm_flags)
57275+ unsigned long mm_flags, long signr)
57276 {
57277 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
57278
57279@@ -1157,7 +1636,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
57280 if (vma->vm_file == NULL)
57281 return 0;
57282
57283- if (FILTER(MAPPED_PRIVATE))
57284+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
57285 goto whole;
57286
57287 /*
57288@@ -1364,9 +1843,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
57289 {
57290 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
57291 int i = 0;
57292- do
57293+ do {
57294 i += 2;
57295- while (auxv[i - 2] != AT_NULL);
57296+ } while (auxv[i - 2] != AT_NULL);
57297 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
57298 }
57299
57300@@ -1375,7 +1854,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
57301 {
57302 mm_segment_t old_fs = get_fs();
57303 set_fs(KERNEL_DS);
57304- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
57305+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
57306 set_fs(old_fs);
57307 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
57308 }
57309@@ -1999,14 +2478,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
57310 }
57311
57312 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
57313- unsigned long mm_flags)
57314+ struct coredump_params *cprm)
57315 {
57316 struct vm_area_struct *vma;
57317 size_t size = 0;
57318
57319 for (vma = first_vma(current, gate_vma); vma != NULL;
57320 vma = next_vma(vma, gate_vma))
57321- size += vma_dump_size(vma, mm_flags);
57322+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
57323 return size;
57324 }
57325
57326@@ -2097,7 +2576,7 @@ static int elf_core_dump(struct coredump_params *cprm)
57327
57328 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
57329
57330- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
57331+ offset += elf_core_vma_data_size(gate_vma, cprm);
57332 offset += elf_core_extra_data_size();
57333 e_shoff = offset;
57334
57335@@ -2125,7 +2604,7 @@ static int elf_core_dump(struct coredump_params *cprm)
57336 phdr.p_offset = offset;
57337 phdr.p_vaddr = vma->vm_start;
57338 phdr.p_paddr = 0;
57339- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
57340+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
57341 phdr.p_memsz = vma->vm_end - vma->vm_start;
57342 offset += phdr.p_filesz;
57343 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
57344@@ -2158,7 +2637,7 @@ static int elf_core_dump(struct coredump_params *cprm)
57345 unsigned long addr;
57346 unsigned long end;
57347
57348- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
57349+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
57350
57351 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
57352 struct page *page;
57353@@ -2199,6 +2678,167 @@ out:
57354
57355 #endif /* CONFIG_ELF_CORE */
57356
57357+#ifdef CONFIG_PAX_MPROTECT
57358+/* PaX: non-PIC ELF libraries need relocations on their executable segments
57359+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
57360+ * we'll remove VM_MAYWRITE for good on RELRO segments.
57361+ *
57362+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
57363+ * basis because we want to allow the common case and not the special ones.
57364+ */
57365+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
57366+{
57367+ struct elfhdr elf_h;
57368+ struct elf_phdr elf_p;
57369+ unsigned long i;
57370+ unsigned long oldflags;
57371+ bool is_textrel_rw, is_textrel_rx, is_relro;
57372+
57373+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
57374+ return;
57375+
57376+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
57377+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
57378+
57379+#ifdef CONFIG_PAX_ELFRELOCS
57380+ /* possible TEXTREL */
57381+ is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
57382+ is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
57383+#else
57384+ is_textrel_rw = false;
57385+ is_textrel_rx = false;
57386+#endif
57387+
57388+ /* possible RELRO */
57389+ is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
57390+
57391+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
57392+ return;
57393+
57394+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
57395+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
57396+
57397+#ifdef CONFIG_PAX_ETEXECRELOCS
57398+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
57399+#else
57400+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
57401+#endif
57402+
57403+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
57404+ !elf_check_arch(&elf_h) ||
57405+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
57406+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
57407+ return;
57408+
57409+ for (i = 0UL; i < elf_h.e_phnum; i++) {
57410+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
57411+ return;
57412+ switch (elf_p.p_type) {
57413+ case PT_DYNAMIC:
57414+ if (!is_textrel_rw && !is_textrel_rx)
57415+ continue;
57416+ i = 0UL;
57417+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
57418+ elf_dyn dyn;
57419+
57420+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
57421+ break;
57422+ if (dyn.d_tag == DT_NULL)
57423+ break;
57424+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
57425+ gr_log_textrel(vma);
57426+ if (is_textrel_rw)
57427+ vma->vm_flags |= VM_MAYWRITE;
57428+ else
57429+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
57430+ vma->vm_flags &= ~VM_MAYWRITE;
57431+ break;
57432+ }
57433+ i++;
57434+ }
57435+ is_textrel_rw = false;
57436+ is_textrel_rx = false;
57437+ continue;
57438+
57439+ case PT_GNU_RELRO:
57440+ if (!is_relro)
57441+ continue;
57442+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
57443+ vma->vm_flags &= ~VM_MAYWRITE;
57444+ is_relro = false;
57445+ continue;
57446+
57447+#ifdef CONFIG_PAX_PT_PAX_FLAGS
57448+ case PT_PAX_FLAGS: {
57449+ const char *msg_mprotect = "", *msg_emutramp = "";
57450+ char *buffer_lib, *buffer_exe;
57451+
57452+ if (elf_p.p_flags & PF_NOMPROTECT)
57453+ msg_mprotect = "MPROTECT disabled";
57454+
57455+#ifdef CONFIG_PAX_EMUTRAMP
57456+ if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
57457+ msg_emutramp = "EMUTRAMP enabled";
57458+#endif
57459+
57460+ if (!msg_mprotect[0] && !msg_emutramp[0])
57461+ continue;
57462+
57463+ if (!printk_ratelimit())
57464+ continue;
57465+
57466+ buffer_lib = (char *)__get_free_page(GFP_KERNEL);
57467+ buffer_exe = (char *)__get_free_page(GFP_KERNEL);
57468+ if (buffer_lib && buffer_exe) {
57469+ char *path_lib, *path_exe;
57470+
57471+ path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
57472+ path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
57473+
57474+ pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
57475+ (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
57476+
57477+ }
57478+ free_page((unsigned long)buffer_exe);
57479+ free_page((unsigned long)buffer_lib);
57480+ continue;
57481+ }
57482+#endif
57483+
57484+ }
57485+ }
57486+}
57487+#endif
57488+
57489+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57490+
57491+extern int grsec_enable_log_rwxmaps;
57492+
57493+static void elf_handle_mmap(struct file *file)
57494+{
57495+ struct elfhdr elf_h;
57496+ struct elf_phdr elf_p;
57497+ unsigned long i;
57498+
57499+ if (!grsec_enable_log_rwxmaps)
57500+ return;
57501+
57502+ if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
57503+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
57504+ (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
57505+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
57506+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
57507+ return;
57508+
57509+ for (i = 0UL; i < elf_h.e_phnum; i++) {
57510+ if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
57511+ return;
57512+ if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
57513+ gr_log_ptgnustack(file);
57514+ }
57515+}
57516+#endif
57517+
57518 static int __init init_elf_binfmt(void)
57519 {
57520 register_binfmt(&elf_format);
57521diff --git a/fs/bio.c b/fs/bio.c
57522index 8754e7b..0669094 100644
57523--- a/fs/bio.c
57524+++ b/fs/bio.c
57525@@ -1145,7 +1145,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
57526 /*
57527 * Overflow, abort
57528 */
57529- if (end < start)
57530+ if (end < start || end - start > INT_MAX - nr_pages)
57531 return ERR_PTR(-EINVAL);
57532
57533 nr_pages += end - start;
57534@@ -1279,7 +1279,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
57535 /*
57536 * Overflow, abort
57537 */
57538- if (end < start)
57539+ if (end < start || end - start > INT_MAX - nr_pages)
57540 return ERR_PTR(-EINVAL);
57541
57542 nr_pages += end - start;
57543@@ -1541,7 +1541,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
57544 const int read = bio_data_dir(bio) == READ;
57545 struct bio_map_data *bmd = bio->bi_private;
57546 int i;
57547- char *p = bmd->sgvecs[0].iov_base;
57548+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
57549
57550 bio_for_each_segment_all(bvec, bio, i) {
57551 char *addr = page_address(bvec->bv_page);
57552diff --git a/fs/block_dev.c b/fs/block_dev.c
57553index 1e86823..8e34695 100644
57554--- a/fs/block_dev.c
57555+++ b/fs/block_dev.c
57556@@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
57557 else if (bdev->bd_contains == bdev)
57558 return true; /* is a whole device which isn't held */
57559
57560- else if (whole->bd_holder == bd_may_claim)
57561+ else if (whole->bd_holder == (void *)bd_may_claim)
57562 return true; /* is a partition of a device that is being partitioned */
57563 else if (whole->bd_holder != NULL)
57564 return false; /* is a partition of a held device */
57565diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
57566index cbd3a7d..c6a2881 100644
57567--- a/fs/btrfs/ctree.c
57568+++ b/fs/btrfs/ctree.c
57569@@ -1216,9 +1216,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
57570 free_extent_buffer(buf);
57571 add_root_to_dirty_list(root);
57572 } else {
57573- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
57574- parent_start = parent->start;
57575- else
57576+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
57577+ if (parent)
57578+ parent_start = parent->start;
57579+ else
57580+ parent_start = 0;
57581+ } else
57582 parent_start = 0;
57583
57584 WARN_ON(trans->transid != btrfs_header_generation(parent));
57585diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
57586index 451b00c..a2cccee 100644
57587--- a/fs/btrfs/delayed-inode.c
57588+++ b/fs/btrfs/delayed-inode.c
57589@@ -459,7 +459,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
57590
57591 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
57592 {
57593- int seq = atomic_inc_return(&delayed_root->items_seq);
57594+ int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
57595 if ((atomic_dec_return(&delayed_root->items) <
57596 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
57597 waitqueue_active(&delayed_root->wait))
57598@@ -1409,7 +1409,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
57599
57600 static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
57601 {
57602- int val = atomic_read(&delayed_root->items_seq);
57603+ int val = atomic_read_unchecked(&delayed_root->items_seq);
57604
57605 if (val < seq || val >= seq + BTRFS_DELAYED_BATCH)
57606 return 1;
57607@@ -1433,7 +1433,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
57608 int seq;
57609 int ret;
57610
57611- seq = atomic_read(&delayed_root->items_seq);
57612+ seq = atomic_read_unchecked(&delayed_root->items_seq);
57613
57614 ret = btrfs_wq_run_delayed_node(delayed_root, root, 0);
57615 if (ret)
57616diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
57617index f70119f..ab5894d 100644
57618--- a/fs/btrfs/delayed-inode.h
57619+++ b/fs/btrfs/delayed-inode.h
57620@@ -43,7 +43,7 @@ struct btrfs_delayed_root {
57621 */
57622 struct list_head prepare_list;
57623 atomic_t items; /* for delayed items */
57624- atomic_t items_seq; /* for delayed items */
57625+ atomic_unchecked_t items_seq; /* for delayed items */
57626 int nodes; /* for delayed nodes */
57627 wait_queue_head_t wait;
57628 };
57629@@ -90,7 +90,7 @@ static inline void btrfs_init_delayed_root(
57630 struct btrfs_delayed_root *delayed_root)
57631 {
57632 atomic_set(&delayed_root->items, 0);
57633- atomic_set(&delayed_root->items_seq, 0);
57634+ atomic_set_unchecked(&delayed_root->items_seq, 0);
57635 delayed_root->nodes = 0;
57636 spin_lock_init(&delayed_root->lock);
57637 init_waitqueue_head(&delayed_root->wait);
57638diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
57639index a6d8efa..2f062cf 100644
57640--- a/fs/btrfs/ioctl.c
57641+++ b/fs/btrfs/ioctl.c
57642@@ -3491,9 +3491,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57643 for (i = 0; i < num_types; i++) {
57644 struct btrfs_space_info *tmp;
57645
57646+ /* Don't copy in more than we allocated */
57647 if (!slot_count)
57648 break;
57649
57650+ slot_count--;
57651+
57652 info = NULL;
57653 rcu_read_lock();
57654 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
57655@@ -3515,10 +3518,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57656 memcpy(dest, &space, sizeof(space));
57657 dest++;
57658 space_args.total_spaces++;
57659- slot_count--;
57660 }
57661- if (!slot_count)
57662- break;
57663 }
57664 up_read(&info->groups_sem);
57665 }
57666diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
57667index d04db81..96e54f1 100644
57668--- a/fs/btrfs/super.c
57669+++ b/fs/btrfs/super.c
57670@@ -268,7 +268,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
57671 function, line, errstr);
57672 return;
57673 }
57674- ACCESS_ONCE(trans->transaction->aborted) = errno;
57675+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
57676 /* Wake up anybody who may be waiting on this transaction */
57677 wake_up(&root->fs_info->transaction_wait);
57678 wake_up(&root->fs_info->transaction_blocked_wait);
57679diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
57680index 865f4cf..f321e86 100644
57681--- a/fs/btrfs/sysfs.c
57682+++ b/fs/btrfs/sysfs.c
57683@@ -436,7 +436,7 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
57684 for (set = 0; set < FEAT_MAX; set++) {
57685 int i;
57686 struct attribute *attrs[2];
57687- struct attribute_group agroup = {
57688+ attribute_group_no_const agroup = {
57689 .name = "features",
57690 .attrs = attrs,
57691 };
57692diff --git a/fs/buffer.c b/fs/buffer.c
57693index 27265a8..289f488 100644
57694--- a/fs/buffer.c
57695+++ b/fs/buffer.c
57696@@ -3428,7 +3428,7 @@ void __init buffer_init(void)
57697 bh_cachep = kmem_cache_create("buffer_head",
57698 sizeof(struct buffer_head), 0,
57699 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
57700- SLAB_MEM_SPREAD),
57701+ SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
57702 NULL);
57703
57704 /*
57705diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
57706index 622f469..e8d2d55 100644
57707--- a/fs/cachefiles/bind.c
57708+++ b/fs/cachefiles/bind.c
57709@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
57710 args);
57711
57712 /* start by checking things over */
57713- ASSERT(cache->fstop_percent >= 0 &&
57714- cache->fstop_percent < cache->fcull_percent &&
57715+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
57716 cache->fcull_percent < cache->frun_percent &&
57717 cache->frun_percent < 100);
57718
57719- ASSERT(cache->bstop_percent >= 0 &&
57720- cache->bstop_percent < cache->bcull_percent &&
57721+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
57722 cache->bcull_percent < cache->brun_percent &&
57723 cache->brun_percent < 100);
57724
57725diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
57726index 0a1467b..6a53245 100644
57727--- a/fs/cachefiles/daemon.c
57728+++ b/fs/cachefiles/daemon.c
57729@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
57730 if (n > buflen)
57731 return -EMSGSIZE;
57732
57733- if (copy_to_user(_buffer, buffer, n) != 0)
57734+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
57735 return -EFAULT;
57736
57737 return n;
57738@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
57739 if (test_bit(CACHEFILES_DEAD, &cache->flags))
57740 return -EIO;
57741
57742- if (datalen < 0 || datalen > PAGE_SIZE - 1)
57743+ if (datalen > PAGE_SIZE - 1)
57744 return -EOPNOTSUPP;
57745
57746 /* drag the command string into the kernel so we can parse it */
57747@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
57748 if (args[0] != '%' || args[1] != '\0')
57749 return -EINVAL;
57750
57751- if (fstop < 0 || fstop >= cache->fcull_percent)
57752+ if (fstop >= cache->fcull_percent)
57753 return cachefiles_daemon_range_error(cache, args);
57754
57755 cache->fstop_percent = fstop;
57756@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
57757 if (args[0] != '%' || args[1] != '\0')
57758 return -EINVAL;
57759
57760- if (bstop < 0 || bstop >= cache->bcull_percent)
57761+ if (bstop >= cache->bcull_percent)
57762 return cachefiles_daemon_range_error(cache, args);
57763
57764 cache->bstop_percent = bstop;
57765diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
57766index 5349473..d6c0b93 100644
57767--- a/fs/cachefiles/internal.h
57768+++ b/fs/cachefiles/internal.h
57769@@ -59,7 +59,7 @@ struct cachefiles_cache {
57770 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
57771 struct rb_root active_nodes; /* active nodes (can't be culled) */
57772 rwlock_t active_lock; /* lock for active_nodes */
57773- atomic_t gravecounter; /* graveyard uniquifier */
57774+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
57775 unsigned frun_percent; /* when to stop culling (% files) */
57776 unsigned fcull_percent; /* when to start culling (% files) */
57777 unsigned fstop_percent; /* when to stop allocating (% files) */
57778@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
57779 * proc.c
57780 */
57781 #ifdef CONFIG_CACHEFILES_HISTOGRAM
57782-extern atomic_t cachefiles_lookup_histogram[HZ];
57783-extern atomic_t cachefiles_mkdir_histogram[HZ];
57784-extern atomic_t cachefiles_create_histogram[HZ];
57785+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57786+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57787+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
57788
57789 extern int __init cachefiles_proc_init(void);
57790 extern void cachefiles_proc_cleanup(void);
57791 static inline
57792-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
57793+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
57794 {
57795 unsigned long jif = jiffies - start_jif;
57796 if (jif >= HZ)
57797 jif = HZ - 1;
57798- atomic_inc(&histogram[jif]);
57799+ atomic_inc_unchecked(&histogram[jif]);
57800 }
57801
57802 #else
57803diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
57804index ca65f39..48921e3 100644
57805--- a/fs/cachefiles/namei.c
57806+++ b/fs/cachefiles/namei.c
57807@@ -317,7 +317,7 @@ try_again:
57808 /* first step is to make up a grave dentry in the graveyard */
57809 sprintf(nbuffer, "%08x%08x",
57810 (uint32_t) get_seconds(),
57811- (uint32_t) atomic_inc_return(&cache->gravecounter));
57812+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
57813
57814 /* do the multiway lock magic */
57815 trap = lock_rename(cache->graveyard, dir);
57816diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
57817index eccd339..4c1d995 100644
57818--- a/fs/cachefiles/proc.c
57819+++ b/fs/cachefiles/proc.c
57820@@ -14,9 +14,9 @@
57821 #include <linux/seq_file.h>
57822 #include "internal.h"
57823
57824-atomic_t cachefiles_lookup_histogram[HZ];
57825-atomic_t cachefiles_mkdir_histogram[HZ];
57826-atomic_t cachefiles_create_histogram[HZ];
57827+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57828+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57829+atomic_unchecked_t cachefiles_create_histogram[HZ];
57830
57831 /*
57832 * display the latency histogram
57833@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
57834 return 0;
57835 default:
57836 index = (unsigned long) v - 3;
57837- x = atomic_read(&cachefiles_lookup_histogram[index]);
57838- y = atomic_read(&cachefiles_mkdir_histogram[index]);
57839- z = atomic_read(&cachefiles_create_histogram[index]);
57840+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
57841+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
57842+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
57843 if (x == 0 && y == 0 && z == 0)
57844 return 0;
57845
57846diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
57847index ebaff36..7e3ea26 100644
57848--- a/fs/cachefiles/rdwr.c
57849+++ b/fs/cachefiles/rdwr.c
57850@@ -950,7 +950,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
57851 old_fs = get_fs();
57852 set_fs(KERNEL_DS);
57853 ret = file->f_op->write(
57854- file, (const void __user *) data, len, &pos);
57855+ file, (const void __force_user *) data, len, &pos);
57856 set_fs(old_fs);
57857 kunmap(page);
57858 file_end_write(file);
57859diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
57860index 45eda6d..9126f7f 100644
57861--- a/fs/ceph/dir.c
57862+++ b/fs/ceph/dir.c
57863@@ -248,7 +248,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
57864 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
57865 struct ceph_mds_client *mdsc = fsc->mdsc;
57866 unsigned frag = fpos_frag(ctx->pos);
57867- int off = fpos_off(ctx->pos);
57868+ unsigned int off = fpos_off(ctx->pos);
57869 int err;
57870 u32 ftype;
57871 struct ceph_mds_reply_info_parsed *rinfo;
57872diff --git a/fs/ceph/super.c b/fs/ceph/super.c
57873index 10a4ccb..92dbc5e 100644
57874--- a/fs/ceph/super.c
57875+++ b/fs/ceph/super.c
57876@@ -895,7 +895,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
57877 /*
57878 * construct our own bdi so we can control readahead, etc.
57879 */
57880-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
57881+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
57882
57883 static int ceph_register_bdi(struct super_block *sb,
57884 struct ceph_fs_client *fsc)
57885@@ -912,7 +912,7 @@ static int ceph_register_bdi(struct super_block *sb,
57886 default_backing_dev_info.ra_pages;
57887
57888 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
57889- atomic_long_inc_return(&bdi_seq));
57890+ atomic_long_inc_return_unchecked(&bdi_seq));
57891 if (!err)
57892 sb->s_bdi = &fsc->backing_dev_info;
57893 return err;
57894diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
57895index f3ac415..3d2420c 100644
57896--- a/fs/cifs/cifs_debug.c
57897+++ b/fs/cifs/cifs_debug.c
57898@@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57899
57900 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
57901 #ifdef CONFIG_CIFS_STATS2
57902- atomic_set(&totBufAllocCount, 0);
57903- atomic_set(&totSmBufAllocCount, 0);
57904+ atomic_set_unchecked(&totBufAllocCount, 0);
57905+ atomic_set_unchecked(&totSmBufAllocCount, 0);
57906 #endif /* CONFIG_CIFS_STATS2 */
57907 spin_lock(&cifs_tcp_ses_lock);
57908 list_for_each(tmp1, &cifs_tcp_ses_list) {
57909@@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57910 tcon = list_entry(tmp3,
57911 struct cifs_tcon,
57912 tcon_list);
57913- atomic_set(&tcon->num_smbs_sent, 0);
57914+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
57915 if (server->ops->clear_stats)
57916 server->ops->clear_stats(tcon);
57917 }
57918@@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57919 smBufAllocCount.counter, cifs_min_small);
57920 #ifdef CONFIG_CIFS_STATS2
57921 seq_printf(m, "Total Large %d Small %d Allocations\n",
57922- atomic_read(&totBufAllocCount),
57923- atomic_read(&totSmBufAllocCount));
57924+ atomic_read_unchecked(&totBufAllocCount),
57925+ atomic_read_unchecked(&totSmBufAllocCount));
57926 #endif /* CONFIG_CIFS_STATS2 */
57927
57928 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
57929@@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57930 if (tcon->need_reconnect)
57931 seq_puts(m, "\tDISCONNECTED ");
57932 seq_printf(m, "\nSMBs: %d",
57933- atomic_read(&tcon->num_smbs_sent));
57934+ atomic_read_unchecked(&tcon->num_smbs_sent));
57935 if (server->ops->print_stats)
57936 server->ops->print_stats(m, tcon);
57937 }
57938diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
57939index 849f613..eae6dec 100644
57940--- a/fs/cifs/cifsfs.c
57941+++ b/fs/cifs/cifsfs.c
57942@@ -1056,7 +1056,7 @@ cifs_init_request_bufs(void)
57943 */
57944 cifs_req_cachep = kmem_cache_create("cifs_request",
57945 CIFSMaxBufSize + max_hdr_size, 0,
57946- SLAB_HWCACHE_ALIGN, NULL);
57947+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
57948 if (cifs_req_cachep == NULL)
57949 return -ENOMEM;
57950
57951@@ -1083,7 +1083,7 @@ cifs_init_request_bufs(void)
57952 efficient to alloc 1 per page off the slab compared to 17K (5page)
57953 alloc of large cifs buffers even when page debugging is on */
57954 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
57955- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
57956+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
57957 NULL);
57958 if (cifs_sm_req_cachep == NULL) {
57959 mempool_destroy(cifs_req_poolp);
57960@@ -1168,8 +1168,8 @@ init_cifs(void)
57961 atomic_set(&bufAllocCount, 0);
57962 atomic_set(&smBufAllocCount, 0);
57963 #ifdef CONFIG_CIFS_STATS2
57964- atomic_set(&totBufAllocCount, 0);
57965- atomic_set(&totSmBufAllocCount, 0);
57966+ atomic_set_unchecked(&totBufAllocCount, 0);
57967+ atomic_set_unchecked(&totSmBufAllocCount, 0);
57968 #endif /* CONFIG_CIFS_STATS2 */
57969
57970 atomic_set(&midCount, 0);
57971diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
57972index c0f3718..6afed7d 100644
57973--- a/fs/cifs/cifsglob.h
57974+++ b/fs/cifs/cifsglob.h
57975@@ -804,35 +804,35 @@ struct cifs_tcon {
57976 __u16 Flags; /* optional support bits */
57977 enum statusEnum tidStatus;
57978 #ifdef CONFIG_CIFS_STATS
57979- atomic_t num_smbs_sent;
57980+ atomic_unchecked_t num_smbs_sent;
57981 union {
57982 struct {
57983- atomic_t num_writes;
57984- atomic_t num_reads;
57985- atomic_t num_flushes;
57986- atomic_t num_oplock_brks;
57987- atomic_t num_opens;
57988- atomic_t num_closes;
57989- atomic_t num_deletes;
57990- atomic_t num_mkdirs;
57991- atomic_t num_posixopens;
57992- atomic_t num_posixmkdirs;
57993- atomic_t num_rmdirs;
57994- atomic_t num_renames;
57995- atomic_t num_t2renames;
57996- atomic_t num_ffirst;
57997- atomic_t num_fnext;
57998- atomic_t num_fclose;
57999- atomic_t num_hardlinks;
58000- atomic_t num_symlinks;
58001- atomic_t num_locks;
58002- atomic_t num_acl_get;
58003- atomic_t num_acl_set;
58004+ atomic_unchecked_t num_writes;
58005+ atomic_unchecked_t num_reads;
58006+ atomic_unchecked_t num_flushes;
58007+ atomic_unchecked_t num_oplock_brks;
58008+ atomic_unchecked_t num_opens;
58009+ atomic_unchecked_t num_closes;
58010+ atomic_unchecked_t num_deletes;
58011+ atomic_unchecked_t num_mkdirs;
58012+ atomic_unchecked_t num_posixopens;
58013+ atomic_unchecked_t num_posixmkdirs;
58014+ atomic_unchecked_t num_rmdirs;
58015+ atomic_unchecked_t num_renames;
58016+ atomic_unchecked_t num_t2renames;
58017+ atomic_unchecked_t num_ffirst;
58018+ atomic_unchecked_t num_fnext;
58019+ atomic_unchecked_t num_fclose;
58020+ atomic_unchecked_t num_hardlinks;
58021+ atomic_unchecked_t num_symlinks;
58022+ atomic_unchecked_t num_locks;
58023+ atomic_unchecked_t num_acl_get;
58024+ atomic_unchecked_t num_acl_set;
58025 } cifs_stats;
58026 #ifdef CONFIG_CIFS_SMB2
58027 struct {
58028- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
58029- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
58030+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
58031+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
58032 } smb2_stats;
58033 #endif /* CONFIG_CIFS_SMB2 */
58034 } stats;
58035@@ -1162,7 +1162,7 @@ convert_delimiter(char *path, char delim)
58036 }
58037
58038 #ifdef CONFIG_CIFS_STATS
58039-#define cifs_stats_inc atomic_inc
58040+#define cifs_stats_inc atomic_inc_unchecked
58041
58042 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
58043 unsigned int bytes)
58044@@ -1528,8 +1528,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
58045 /* Various Debug counters */
58046 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
58047 #ifdef CONFIG_CIFS_STATS2
58048-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
58049-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
58050+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
58051+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
58052 #endif
58053 GLOBAL_EXTERN atomic_t smBufAllocCount;
58054 GLOBAL_EXTERN atomic_t midCount;
58055diff --git a/fs/cifs/file.c b/fs/cifs/file.c
58056index 834fce7..8a314b5 100644
58057--- a/fs/cifs/file.c
58058+++ b/fs/cifs/file.c
58059@@ -1900,10 +1900,14 @@ static int cifs_writepages(struct address_space *mapping,
58060 index = mapping->writeback_index; /* Start from prev offset */
58061 end = -1;
58062 } else {
58063- index = wbc->range_start >> PAGE_CACHE_SHIFT;
58064- end = wbc->range_end >> PAGE_CACHE_SHIFT;
58065- if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
58066+ if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
58067 range_whole = true;
58068+ index = 0;
58069+ end = ULONG_MAX;
58070+ } else {
58071+ index = wbc->range_start >> PAGE_CACHE_SHIFT;
58072+ end = wbc->range_end >> PAGE_CACHE_SHIFT;
58073+ }
58074 scanned = true;
58075 }
58076 retry:
58077diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
58078index 2f9f379..43f8025 100644
58079--- a/fs/cifs/misc.c
58080+++ b/fs/cifs/misc.c
58081@@ -170,7 +170,7 @@ cifs_buf_get(void)
58082 memset(ret_buf, 0, buf_size + 3);
58083 atomic_inc(&bufAllocCount);
58084 #ifdef CONFIG_CIFS_STATS2
58085- atomic_inc(&totBufAllocCount);
58086+ atomic_inc_unchecked(&totBufAllocCount);
58087 #endif /* CONFIG_CIFS_STATS2 */
58088 }
58089
58090@@ -205,7 +205,7 @@ cifs_small_buf_get(void)
58091 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
58092 atomic_inc(&smBufAllocCount);
58093 #ifdef CONFIG_CIFS_STATS2
58094- atomic_inc(&totSmBufAllocCount);
58095+ atomic_inc_unchecked(&totSmBufAllocCount);
58096 #endif /* CONFIG_CIFS_STATS2 */
58097
58098 }
58099diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
58100index 526fb89..ecdbf5a 100644
58101--- a/fs/cifs/smb1ops.c
58102+++ b/fs/cifs/smb1ops.c
58103@@ -616,27 +616,27 @@ static void
58104 cifs_clear_stats(struct cifs_tcon *tcon)
58105 {
58106 #ifdef CONFIG_CIFS_STATS
58107- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
58108- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
58109- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
58110- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
58111- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
58112- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
58113- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
58114- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
58115- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
58116- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
58117- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
58118- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
58119- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
58120- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
58121- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
58122- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
58123- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
58124- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
58125- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
58126- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
58127- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
58128+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
58129+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
58130+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
58131+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
58132+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
58133+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
58134+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
58135+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
58136+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
58137+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
58138+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
58139+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
58140+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
58141+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
58142+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
58143+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
58144+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
58145+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
58146+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
58147+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
58148+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
58149 #endif
58150 }
58151
58152@@ -645,36 +645,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
58153 {
58154 #ifdef CONFIG_CIFS_STATS
58155 seq_printf(m, " Oplocks breaks: %d",
58156- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
58157+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
58158 seq_printf(m, "\nReads: %d Bytes: %llu",
58159- atomic_read(&tcon->stats.cifs_stats.num_reads),
58160+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
58161 (long long)(tcon->bytes_read));
58162 seq_printf(m, "\nWrites: %d Bytes: %llu",
58163- atomic_read(&tcon->stats.cifs_stats.num_writes),
58164+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
58165 (long long)(tcon->bytes_written));
58166 seq_printf(m, "\nFlushes: %d",
58167- atomic_read(&tcon->stats.cifs_stats.num_flushes));
58168+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
58169 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
58170- atomic_read(&tcon->stats.cifs_stats.num_locks),
58171- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
58172- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
58173+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
58174+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
58175+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
58176 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
58177- atomic_read(&tcon->stats.cifs_stats.num_opens),
58178- atomic_read(&tcon->stats.cifs_stats.num_closes),
58179- atomic_read(&tcon->stats.cifs_stats.num_deletes));
58180+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
58181+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
58182+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
58183 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
58184- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
58185- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
58186+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
58187+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
58188 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
58189- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
58190- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
58191+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
58192+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
58193 seq_printf(m, "\nRenames: %d T2 Renames %d",
58194- atomic_read(&tcon->stats.cifs_stats.num_renames),
58195- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
58196+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
58197+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
58198 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
58199- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
58200- atomic_read(&tcon->stats.cifs_stats.num_fnext),
58201- atomic_read(&tcon->stats.cifs_stats.num_fclose));
58202+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
58203+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
58204+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
58205 #endif
58206 }
58207
58208diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
58209index 192f51a..539307e 100644
58210--- a/fs/cifs/smb2ops.c
58211+++ b/fs/cifs/smb2ops.c
58212@@ -364,8 +364,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
58213 #ifdef CONFIG_CIFS_STATS
58214 int i;
58215 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
58216- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
58217- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
58218+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
58219+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
58220 }
58221 #endif
58222 }
58223@@ -405,65 +405,65 @@ static void
58224 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
58225 {
58226 #ifdef CONFIG_CIFS_STATS
58227- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
58228- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
58229+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
58230+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
58231 seq_printf(m, "\nNegotiates: %d sent %d failed",
58232- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
58233- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
58234+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
58235+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
58236 seq_printf(m, "\nSessionSetups: %d sent %d failed",
58237- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
58238- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
58239+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
58240+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
58241 seq_printf(m, "\nLogoffs: %d sent %d failed",
58242- atomic_read(&sent[SMB2_LOGOFF_HE]),
58243- atomic_read(&failed[SMB2_LOGOFF_HE]));
58244+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
58245+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
58246 seq_printf(m, "\nTreeConnects: %d sent %d failed",
58247- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
58248- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
58249+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
58250+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
58251 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
58252- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
58253- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
58254+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
58255+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
58256 seq_printf(m, "\nCreates: %d sent %d failed",
58257- atomic_read(&sent[SMB2_CREATE_HE]),
58258- atomic_read(&failed[SMB2_CREATE_HE]));
58259+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
58260+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
58261 seq_printf(m, "\nCloses: %d sent %d failed",
58262- atomic_read(&sent[SMB2_CLOSE_HE]),
58263- atomic_read(&failed[SMB2_CLOSE_HE]));
58264+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
58265+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
58266 seq_printf(m, "\nFlushes: %d sent %d failed",
58267- atomic_read(&sent[SMB2_FLUSH_HE]),
58268- atomic_read(&failed[SMB2_FLUSH_HE]));
58269+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
58270+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
58271 seq_printf(m, "\nReads: %d sent %d failed",
58272- atomic_read(&sent[SMB2_READ_HE]),
58273- atomic_read(&failed[SMB2_READ_HE]));
58274+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
58275+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
58276 seq_printf(m, "\nWrites: %d sent %d failed",
58277- atomic_read(&sent[SMB2_WRITE_HE]),
58278- atomic_read(&failed[SMB2_WRITE_HE]));
58279+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
58280+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
58281 seq_printf(m, "\nLocks: %d sent %d failed",
58282- atomic_read(&sent[SMB2_LOCK_HE]),
58283- atomic_read(&failed[SMB2_LOCK_HE]));
58284+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
58285+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
58286 seq_printf(m, "\nIOCTLs: %d sent %d failed",
58287- atomic_read(&sent[SMB2_IOCTL_HE]),
58288- atomic_read(&failed[SMB2_IOCTL_HE]));
58289+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
58290+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
58291 seq_printf(m, "\nCancels: %d sent %d failed",
58292- atomic_read(&sent[SMB2_CANCEL_HE]),
58293- atomic_read(&failed[SMB2_CANCEL_HE]));
58294+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
58295+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
58296 seq_printf(m, "\nEchos: %d sent %d failed",
58297- atomic_read(&sent[SMB2_ECHO_HE]),
58298- atomic_read(&failed[SMB2_ECHO_HE]));
58299+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
58300+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
58301 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
58302- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
58303- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
58304+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
58305+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
58306 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
58307- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
58308- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
58309+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
58310+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
58311 seq_printf(m, "\nQueryInfos: %d sent %d failed",
58312- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
58313- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
58314+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
58315+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
58316 seq_printf(m, "\nSetInfos: %d sent %d failed",
58317- atomic_read(&sent[SMB2_SET_INFO_HE]),
58318- atomic_read(&failed[SMB2_SET_INFO_HE]));
58319+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
58320+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
58321 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
58322- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
58323- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
58324+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
58325+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
58326 #endif
58327 }
58328
58329diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
58330index 8603447..f9caeee 100644
58331--- a/fs/cifs/smb2pdu.c
58332+++ b/fs/cifs/smb2pdu.c
58333@@ -2094,8 +2094,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
58334 default:
58335 cifs_dbg(VFS, "info level %u isn't supported\n",
58336 srch_inf->info_level);
58337- rc = -EINVAL;
58338- goto qdir_exit;
58339+ return -EINVAL;
58340 }
58341
58342 req->FileIndex = cpu_to_le32(index);
58343diff --git a/fs/coda/cache.c b/fs/coda/cache.c
58344index 1da168c..8bc7ff6 100644
58345--- a/fs/coda/cache.c
58346+++ b/fs/coda/cache.c
58347@@ -24,7 +24,7 @@
58348 #include "coda_linux.h"
58349 #include "coda_cache.h"
58350
58351-static atomic_t permission_epoch = ATOMIC_INIT(0);
58352+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
58353
58354 /* replace or extend an acl cache hit */
58355 void coda_cache_enter(struct inode *inode, int mask)
58356@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
58357 struct coda_inode_info *cii = ITOC(inode);
58358
58359 spin_lock(&cii->c_lock);
58360- cii->c_cached_epoch = atomic_read(&permission_epoch);
58361+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
58362 if (!uid_eq(cii->c_uid, current_fsuid())) {
58363 cii->c_uid = current_fsuid();
58364 cii->c_cached_perm = mask;
58365@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
58366 {
58367 struct coda_inode_info *cii = ITOC(inode);
58368 spin_lock(&cii->c_lock);
58369- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
58370+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
58371 spin_unlock(&cii->c_lock);
58372 }
58373
58374 /* remove all acl caches */
58375 void coda_cache_clear_all(struct super_block *sb)
58376 {
58377- atomic_inc(&permission_epoch);
58378+ atomic_inc_unchecked(&permission_epoch);
58379 }
58380
58381
58382@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
58383 spin_lock(&cii->c_lock);
58384 hit = (mask & cii->c_cached_perm) == mask &&
58385 uid_eq(cii->c_uid, current_fsuid()) &&
58386- cii->c_cached_epoch == atomic_read(&permission_epoch);
58387+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
58388 spin_unlock(&cii->c_lock);
58389
58390 return hit;
58391diff --git a/fs/compat.c b/fs/compat.c
58392index 6af20de..fec3fbb 100644
58393--- a/fs/compat.c
58394+++ b/fs/compat.c
58395@@ -54,7 +54,7 @@
58396 #include <asm/ioctls.h>
58397 #include "internal.h"
58398
58399-int compat_log = 1;
58400+int compat_log = 0;
58401
58402 int compat_printk(const char *fmt, ...)
58403 {
58404@@ -488,7 +488,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
58405
58406 set_fs(KERNEL_DS);
58407 /* The __user pointer cast is valid because of the set_fs() */
58408- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
58409+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
58410 set_fs(oldfs);
58411 /* truncating is ok because it's a user address */
58412 if (!ret)
58413@@ -546,7 +546,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
58414 goto out;
58415
58416 ret = -EINVAL;
58417- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
58418+ if (nr_segs > UIO_MAXIOV)
58419 goto out;
58420 if (nr_segs > fast_segs) {
58421 ret = -ENOMEM;
58422@@ -834,6 +834,7 @@ struct compat_old_linux_dirent {
58423 struct compat_readdir_callback {
58424 struct dir_context ctx;
58425 struct compat_old_linux_dirent __user *dirent;
58426+ struct file * file;
58427 int result;
58428 };
58429
58430@@ -851,6 +852,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
58431 buf->result = -EOVERFLOW;
58432 return -EOVERFLOW;
58433 }
58434+
58435+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58436+ return 0;
58437+
58438 buf->result++;
58439 dirent = buf->dirent;
58440 if (!access_ok(VERIFY_WRITE, dirent,
58441@@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
58442 if (!f.file)
58443 return -EBADF;
58444
58445+ buf.file = f.file;
58446 error = iterate_dir(f.file, &buf.ctx);
58447 if (buf.result)
58448 error = buf.result;
58449@@ -901,6 +907,7 @@ struct compat_getdents_callback {
58450 struct dir_context ctx;
58451 struct compat_linux_dirent __user *current_dir;
58452 struct compat_linux_dirent __user *previous;
58453+ struct file * file;
58454 int count;
58455 int error;
58456 };
58457@@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
58458 buf->error = -EOVERFLOW;
58459 return -EOVERFLOW;
58460 }
58461+
58462+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58463+ return 0;
58464+
58465 dirent = buf->previous;
58466 if (dirent) {
58467 if (__put_user(offset, &dirent->d_off))
58468@@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
58469 if (!f.file)
58470 return -EBADF;
58471
58472+ buf.file = f.file;
58473 error = iterate_dir(f.file, &buf.ctx);
58474 if (error >= 0)
58475 error = buf.error;
58476@@ -987,6 +999,7 @@ struct compat_getdents_callback64 {
58477 struct dir_context ctx;
58478 struct linux_dirent64 __user *current_dir;
58479 struct linux_dirent64 __user *previous;
58480+ struct file * file;
58481 int count;
58482 int error;
58483 };
58484@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
58485 buf->error = -EINVAL; /* only used if we fail.. */
58486 if (reclen > buf->count)
58487 return -EINVAL;
58488+
58489+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58490+ return 0;
58491+
58492 dirent = buf->previous;
58493
58494 if (dirent) {
58495@@ -1052,6 +1069,7 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
58496 if (!f.file)
58497 return -EBADF;
58498
58499+ buf.file = f.file;
58500 error = iterate_dir(f.file, &buf.ctx);
58501 if (error >= 0)
58502 error = buf.error;
58503diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
58504index a81147e..20bf2b5 100644
58505--- a/fs/compat_binfmt_elf.c
58506+++ b/fs/compat_binfmt_elf.c
58507@@ -30,11 +30,13 @@
58508 #undef elf_phdr
58509 #undef elf_shdr
58510 #undef elf_note
58511+#undef elf_dyn
58512 #undef elf_addr_t
58513 #define elfhdr elf32_hdr
58514 #define elf_phdr elf32_phdr
58515 #define elf_shdr elf32_shdr
58516 #define elf_note elf32_note
58517+#define elf_dyn Elf32_Dyn
58518 #define elf_addr_t Elf32_Addr
58519
58520 /*
58521diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
58522index 3881610..ab3df0b 100644
58523--- a/fs/compat_ioctl.c
58524+++ b/fs/compat_ioctl.c
58525@@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
58526 return -EFAULT;
58527 if (__get_user(udata, &ss32->iomem_base))
58528 return -EFAULT;
58529- ss.iomem_base = compat_ptr(udata);
58530+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
58531 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
58532 __get_user(ss.port_high, &ss32->port_high))
58533 return -EFAULT;
58534@@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
58535 for (i = 0; i < nmsgs; i++) {
58536 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
58537 return -EFAULT;
58538- if (get_user(datap, &umsgs[i].buf) ||
58539- put_user(compat_ptr(datap), &tmsgs[i].buf))
58540+ if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
58541+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
58542 return -EFAULT;
58543 }
58544 return sys_ioctl(fd, cmd, (unsigned long)tdata);
58545@@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
58546 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
58547 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
58548 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
58549- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
58550+ copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
58551 return -EFAULT;
58552
58553 return ioctl_preallocate(file, p);
58554@@ -1617,8 +1617,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
58555 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
58556 {
58557 unsigned int a, b;
58558- a = *(unsigned int *)p;
58559- b = *(unsigned int *)q;
58560+ a = *(const unsigned int *)p;
58561+ b = *(const unsigned int *)q;
58562 if (a > b)
58563 return 1;
58564 if (a < b)
58565diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
58566index e081acb..911df21 100644
58567--- a/fs/configfs/dir.c
58568+++ b/fs/configfs/dir.c
58569@@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
58570 }
58571 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
58572 struct configfs_dirent *next;
58573- const char *name;
58574+ const unsigned char * name;
58575+ char d_name[sizeof(next->s_dentry->d_iname)];
58576 int len;
58577 struct inode *inode = NULL;
58578
58579@@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
58580 continue;
58581
58582 name = configfs_get_name(next);
58583- len = strlen(name);
58584+ if (next->s_dentry && name == next->s_dentry->d_iname) {
58585+ len = next->s_dentry->d_name.len;
58586+ memcpy(d_name, name, len);
58587+ name = d_name;
58588+ } else
58589+ len = strlen(name);
58590
58591 /*
58592 * We'll have a dentry and an inode for
58593diff --git a/fs/coredump.c b/fs/coredump.c
58594index e3ad709..836c55f 100644
58595--- a/fs/coredump.c
58596+++ b/fs/coredump.c
58597@@ -73,10 +73,15 @@ static int expand_corename(struct core_name *cn, int size)
58598 static int cn_vprintf(struct core_name *cn, const char *fmt, va_list arg)
58599 {
58600 int free, need;
58601+ va_list arg_copy;
58602
58603 again:
58604 free = cn->size - cn->used;
58605- need = vsnprintf(cn->corename + cn->used, free, fmt, arg);
58606+
58607+ va_copy(arg_copy, arg);
58608+ need = vsnprintf(cn->corename + cn->used, free, fmt, arg_copy);
58609+ va_end(arg_copy);
58610+
58611 if (need < free) {
58612 cn->used += need;
58613 return 0;
58614@@ -437,8 +442,8 @@ static void wait_for_dump_helpers(struct file *file)
58615 struct pipe_inode_info *pipe = file->private_data;
58616
58617 pipe_lock(pipe);
58618- pipe->readers++;
58619- pipe->writers--;
58620+ atomic_inc(&pipe->readers);
58621+ atomic_dec(&pipe->writers);
58622 wake_up_interruptible_sync(&pipe->wait);
58623 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
58624 pipe_unlock(pipe);
58625@@ -447,11 +452,11 @@ static void wait_for_dump_helpers(struct file *file)
58626 * We actually want wait_event_freezable() but then we need
58627 * to clear TIF_SIGPENDING and improve dump_interrupted().
58628 */
58629- wait_event_interruptible(pipe->wait, pipe->readers == 1);
58630+ wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
58631
58632 pipe_lock(pipe);
58633- pipe->readers--;
58634- pipe->writers++;
58635+ atomic_dec(&pipe->readers);
58636+ atomic_inc(&pipe->writers);
58637 pipe_unlock(pipe);
58638 }
58639
58640@@ -498,7 +503,9 @@ void do_coredump(const siginfo_t *siginfo)
58641 struct files_struct *displaced;
58642 bool need_nonrelative = false;
58643 bool core_dumped = false;
58644- static atomic_t core_dump_count = ATOMIC_INIT(0);
58645+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
58646+ long signr = siginfo->si_signo;
58647+ int dumpable;
58648 struct coredump_params cprm = {
58649 .siginfo = siginfo,
58650 .regs = signal_pt_regs(),
58651@@ -511,12 +518,17 @@ void do_coredump(const siginfo_t *siginfo)
58652 .mm_flags = mm->flags,
58653 };
58654
58655- audit_core_dumps(siginfo->si_signo);
58656+ audit_core_dumps(signr);
58657+
58658+ dumpable = __get_dumpable(cprm.mm_flags);
58659+
58660+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
58661+ gr_handle_brute_attach(dumpable);
58662
58663 binfmt = mm->binfmt;
58664 if (!binfmt || !binfmt->core_dump)
58665 goto fail;
58666- if (!__get_dumpable(cprm.mm_flags))
58667+ if (!dumpable)
58668 goto fail;
58669
58670 cred = prepare_creds();
58671@@ -535,7 +547,7 @@ void do_coredump(const siginfo_t *siginfo)
58672 need_nonrelative = true;
58673 }
58674
58675- retval = coredump_wait(siginfo->si_signo, &core_state);
58676+ retval = coredump_wait(signr, &core_state);
58677 if (retval < 0)
58678 goto fail_creds;
58679
58680@@ -578,7 +590,7 @@ void do_coredump(const siginfo_t *siginfo)
58681 }
58682 cprm.limit = RLIM_INFINITY;
58683
58684- dump_count = atomic_inc_return(&core_dump_count);
58685+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
58686 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
58687 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
58688 task_tgid_vnr(current), current->comm);
58689@@ -610,6 +622,8 @@ void do_coredump(const siginfo_t *siginfo)
58690 } else {
58691 struct inode *inode;
58692
58693+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
58694+
58695 if (cprm.limit < binfmt->min_coredump)
58696 goto fail_unlock;
58697
58698@@ -668,7 +682,7 @@ close_fail:
58699 filp_close(cprm.file, NULL);
58700 fail_dropcount:
58701 if (ispipe)
58702- atomic_dec(&core_dump_count);
58703+ atomic_dec_unchecked(&core_dump_count);
58704 fail_unlock:
58705 kfree(cn.corename);
58706 coredump_finish(mm, core_dumped);
58707@@ -689,6 +703,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
58708 struct file *file = cprm->file;
58709 loff_t pos = file->f_pos;
58710 ssize_t n;
58711+
58712+ gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
58713 if (cprm->written + nr > cprm->limit)
58714 return 0;
58715 while (nr) {
58716diff --git a/fs/dcache.c b/fs/dcache.c
58717index ca02c13..7e2b581 100644
58718--- a/fs/dcache.c
58719+++ b/fs/dcache.c
58720@@ -1495,7 +1495,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
58721 */
58722 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
58723 if (name->len > DNAME_INLINE_LEN-1) {
58724- dname = kmalloc(name->len + 1, GFP_KERNEL);
58725+ dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
58726 if (!dname) {
58727 kmem_cache_free(dentry_cache, dentry);
58728 return NULL;
58729@@ -3431,7 +3431,8 @@ void __init vfs_caches_init(unsigned long mempages)
58730 mempages -= reserve;
58731
58732 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
58733- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
58734+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
58735+ SLAB_NO_SANITIZE, NULL);
58736
58737 dcache_init();
58738 inode_init();
58739diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
58740index 9c0444c..628490c 100644
58741--- a/fs/debugfs/inode.c
58742+++ b/fs/debugfs/inode.c
58743@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
58744 */
58745 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
58746 {
58747+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
58748+ return __create_file(name, S_IFDIR | S_IRWXU,
58749+#else
58750 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
58751+#endif
58752 parent, NULL, NULL);
58753 }
58754 EXPORT_SYMBOL_GPL(debugfs_create_dir);
58755diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
58756index b167ca4..a224e19 100644
58757--- a/fs/ecryptfs/inode.c
58758+++ b/fs/ecryptfs/inode.c
58759@@ -673,7 +673,7 @@ static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
58760 old_fs = get_fs();
58761 set_fs(get_ds());
58762 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
58763- (char __user *)lower_buf,
58764+ (char __force_user *)lower_buf,
58765 PATH_MAX);
58766 set_fs(old_fs);
58767 if (rc < 0)
58768diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
58769index e4141f2..d8263e8 100644
58770--- a/fs/ecryptfs/miscdev.c
58771+++ b/fs/ecryptfs/miscdev.c
58772@@ -304,7 +304,7 @@ check_list:
58773 goto out_unlock_msg_ctx;
58774 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
58775 if (msg_ctx->msg) {
58776- if (copy_to_user(&buf[i], packet_length, packet_length_size))
58777+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
58778 goto out_unlock_msg_ctx;
58779 i += packet_length_size;
58780 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
58781diff --git a/fs/exec.c b/fs/exec.c
58782index 3d78fcc..460e2a0 100644
58783--- a/fs/exec.c
58784+++ b/fs/exec.c
58785@@ -55,8 +55,20 @@
58786 #include <linux/pipe_fs_i.h>
58787 #include <linux/oom.h>
58788 #include <linux/compat.h>
58789+#include <linux/random.h>
58790+#include <linux/seq_file.h>
58791+#include <linux/coredump.h>
58792+#include <linux/mman.h>
58793+
58794+#ifdef CONFIG_PAX_REFCOUNT
58795+#include <linux/kallsyms.h>
58796+#include <linux/kdebug.h>
58797+#endif
58798+
58799+#include <trace/events/fs.h>
58800
58801 #include <asm/uaccess.h>
58802+#include <asm/sections.h>
58803 #include <asm/mmu_context.h>
58804 #include <asm/tlb.h>
58805
58806@@ -65,19 +77,34 @@
58807
58808 #include <trace/events/sched.h>
58809
58810+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
58811+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
58812+{
58813+ 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");
58814+}
58815+#endif
58816+
58817+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
58818+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
58819+EXPORT_SYMBOL(pax_set_initial_flags_func);
58820+#endif
58821+
58822 int suid_dumpable = 0;
58823
58824 static LIST_HEAD(formats);
58825 static DEFINE_RWLOCK(binfmt_lock);
58826
58827+extern int gr_process_kernel_exec_ban(void);
58828+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
58829+
58830 void __register_binfmt(struct linux_binfmt * fmt, int insert)
58831 {
58832 BUG_ON(!fmt);
58833 if (WARN_ON(!fmt->load_binary))
58834 return;
58835 write_lock(&binfmt_lock);
58836- insert ? list_add(&fmt->lh, &formats) :
58837- list_add_tail(&fmt->lh, &formats);
58838+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
58839+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
58840 write_unlock(&binfmt_lock);
58841 }
58842
58843@@ -86,7 +113,7 @@ EXPORT_SYMBOL(__register_binfmt);
58844 void unregister_binfmt(struct linux_binfmt * fmt)
58845 {
58846 write_lock(&binfmt_lock);
58847- list_del(&fmt->lh);
58848+ pax_list_del((struct list_head *)&fmt->lh);
58849 write_unlock(&binfmt_lock);
58850 }
58851
58852@@ -180,18 +207,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58853 int write)
58854 {
58855 struct page *page;
58856- int ret;
58857
58858-#ifdef CONFIG_STACK_GROWSUP
58859- if (write) {
58860- ret = expand_downwards(bprm->vma, pos);
58861- if (ret < 0)
58862- return NULL;
58863- }
58864-#endif
58865- ret = get_user_pages(current, bprm->mm, pos,
58866- 1, write, 1, &page, NULL);
58867- if (ret <= 0)
58868+ if (0 > expand_downwards(bprm->vma, pos))
58869+ return NULL;
58870+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
58871 return NULL;
58872
58873 if (write) {
58874@@ -207,6 +226,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58875 if (size <= ARG_MAX)
58876 return page;
58877
58878+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58879+ // only allow 512KB for argv+env on suid/sgid binaries
58880+ // to prevent easy ASLR exhaustion
58881+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
58882+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
58883+ (size > (512 * 1024))) {
58884+ put_page(page);
58885+ return NULL;
58886+ }
58887+#endif
58888+
58889 /*
58890 * Limit to 1/4-th the stack size for the argv+env strings.
58891 * This ensures that:
58892@@ -266,6 +296,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58893 vma->vm_end = STACK_TOP_MAX;
58894 vma->vm_start = vma->vm_end - PAGE_SIZE;
58895 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
58896+
58897+#ifdef CONFIG_PAX_SEGMEXEC
58898+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
58899+#endif
58900+
58901 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
58902 INIT_LIST_HEAD(&vma->anon_vma_chain);
58903
58904@@ -276,6 +311,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58905 mm->stack_vm = mm->total_vm = 1;
58906 up_write(&mm->mmap_sem);
58907 bprm->p = vma->vm_end - sizeof(void *);
58908+
58909+#ifdef CONFIG_PAX_RANDUSTACK
58910+ if (randomize_va_space)
58911+ bprm->p ^= prandom_u32() & ~PAGE_MASK;
58912+#endif
58913+
58914 return 0;
58915 err:
58916 up_write(&mm->mmap_sem);
58917@@ -396,7 +437,7 @@ struct user_arg_ptr {
58918 } ptr;
58919 };
58920
58921-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58922+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58923 {
58924 const char __user *native;
58925
58926@@ -405,14 +446,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58927 compat_uptr_t compat;
58928
58929 if (get_user(compat, argv.ptr.compat + nr))
58930- return ERR_PTR(-EFAULT);
58931+ return (const char __force_user *)ERR_PTR(-EFAULT);
58932
58933 return compat_ptr(compat);
58934 }
58935 #endif
58936
58937 if (get_user(native, argv.ptr.native + nr))
58938- return ERR_PTR(-EFAULT);
58939+ return (const char __force_user *)ERR_PTR(-EFAULT);
58940
58941 return native;
58942 }
58943@@ -431,7 +472,7 @@ static int count(struct user_arg_ptr argv, int max)
58944 if (!p)
58945 break;
58946
58947- if (IS_ERR(p))
58948+ if (IS_ERR((const char __force_kernel *)p))
58949 return -EFAULT;
58950
58951 if (i >= max)
58952@@ -466,7 +507,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
58953
58954 ret = -EFAULT;
58955 str = get_user_arg_ptr(argv, argc);
58956- if (IS_ERR(str))
58957+ if (IS_ERR((const char __force_kernel *)str))
58958 goto out;
58959
58960 len = strnlen_user(str, MAX_ARG_STRLEN);
58961@@ -548,7 +589,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
58962 int r;
58963 mm_segment_t oldfs = get_fs();
58964 struct user_arg_ptr argv = {
58965- .ptr.native = (const char __user *const __user *)__argv,
58966+ .ptr.native = (const char __user * const __force_user *)__argv,
58967 };
58968
58969 set_fs(KERNEL_DS);
58970@@ -583,7 +624,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
58971 unsigned long new_end = old_end - shift;
58972 struct mmu_gather tlb;
58973
58974- BUG_ON(new_start > new_end);
58975+ if (new_start >= new_end || new_start < mmap_min_addr)
58976+ return -ENOMEM;
58977
58978 /*
58979 * ensure there are no vmas between where we want to go
58980@@ -592,6 +634,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
58981 if (vma != find_vma(mm, new_start))
58982 return -EFAULT;
58983
58984+#ifdef CONFIG_PAX_SEGMEXEC
58985+ BUG_ON(pax_find_mirror_vma(vma));
58986+#endif
58987+
58988 /*
58989 * cover the whole range: [new_start, old_end)
58990 */
58991@@ -672,10 +718,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
58992 stack_top = arch_align_stack(stack_top);
58993 stack_top = PAGE_ALIGN(stack_top);
58994
58995- if (unlikely(stack_top < mmap_min_addr) ||
58996- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
58997- return -ENOMEM;
58998-
58999 stack_shift = vma->vm_end - stack_top;
59000
59001 bprm->p -= stack_shift;
59002@@ -687,8 +729,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
59003 bprm->exec -= stack_shift;
59004
59005 down_write(&mm->mmap_sem);
59006+
59007+ /* Move stack pages down in memory. */
59008+ if (stack_shift) {
59009+ ret = shift_arg_pages(vma, stack_shift);
59010+ if (ret)
59011+ goto out_unlock;
59012+ }
59013+
59014 vm_flags = VM_STACK_FLAGS;
59015
59016+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
59017+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
59018+ vm_flags &= ~VM_EXEC;
59019+
59020+#ifdef CONFIG_PAX_MPROTECT
59021+ if (mm->pax_flags & MF_PAX_MPROTECT)
59022+ vm_flags &= ~VM_MAYEXEC;
59023+#endif
59024+
59025+ }
59026+#endif
59027+
59028 /*
59029 * Adjust stack execute permissions; explicitly enable for
59030 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
59031@@ -707,13 +769,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
59032 goto out_unlock;
59033 BUG_ON(prev != vma);
59034
59035- /* Move stack pages down in memory. */
59036- if (stack_shift) {
59037- ret = shift_arg_pages(vma, stack_shift);
59038- if (ret)
59039- goto out_unlock;
59040- }
59041-
59042 /* mprotect_fixup is overkill to remove the temporary stack flags */
59043 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
59044
59045@@ -737,6 +792,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
59046 #endif
59047 current->mm->start_stack = bprm->p;
59048 ret = expand_stack(vma, stack_base);
59049+
59050+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
59051+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
59052+ unsigned long size;
59053+ vm_flags_t vm_flags;
59054+
59055+ size = STACK_TOP - vma->vm_end;
59056+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
59057+
59058+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
59059+
59060+#ifdef CONFIG_X86
59061+ if (!ret) {
59062+ size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
59063+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
59064+ }
59065+#endif
59066+
59067+ }
59068+#endif
59069+
59070 if (ret)
59071 ret = -EFAULT;
59072
59073@@ -772,6 +848,8 @@ static struct file *do_open_exec(struct filename *name)
59074
59075 fsnotify_open(file);
59076
59077+ trace_open_exec(name->name);
59078+
59079 err = deny_write_access(file);
59080 if (err)
59081 goto exit;
59082@@ -801,7 +879,7 @@ int kernel_read(struct file *file, loff_t offset,
59083 old_fs = get_fs();
59084 set_fs(get_ds());
59085 /* The cast to a user pointer is valid due to the set_fs() */
59086- result = vfs_read(file, (void __user *)addr, count, &pos);
59087+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
59088 set_fs(old_fs);
59089 return result;
59090 }
59091@@ -1258,7 +1336,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
59092 }
59093 rcu_read_unlock();
59094
59095- if (p->fs->users > n_fs)
59096+ if (atomic_read(&p->fs->users) > n_fs)
59097 bprm->unsafe |= LSM_UNSAFE_SHARE;
59098 else
59099 p->fs->in_exec = 1;
59100@@ -1434,6 +1512,31 @@ static int exec_binprm(struct linux_binprm *bprm)
59101 return ret;
59102 }
59103
59104+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59105+static DEFINE_PER_CPU(u64, exec_counter);
59106+static int __init init_exec_counters(void)
59107+{
59108+ unsigned int cpu;
59109+
59110+ for_each_possible_cpu(cpu) {
59111+ per_cpu(exec_counter, cpu) = (u64)cpu;
59112+ }
59113+
59114+ return 0;
59115+}
59116+early_initcall(init_exec_counters);
59117+static inline void increment_exec_counter(void)
59118+{
59119+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
59120+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
59121+}
59122+#else
59123+static inline void increment_exec_counter(void) {}
59124+#endif
59125+
59126+extern void gr_handle_exec_args(struct linux_binprm *bprm,
59127+ struct user_arg_ptr argv);
59128+
59129 /*
59130 * sys_execve() executes a new program.
59131 */
59132@@ -1441,6 +1544,11 @@ static int do_execve_common(struct filename *filename,
59133 struct user_arg_ptr argv,
59134 struct user_arg_ptr envp)
59135 {
59136+#ifdef CONFIG_GRKERNSEC
59137+ struct file *old_exec_file;
59138+ struct acl_subject_label *old_acl;
59139+ struct rlimit old_rlim[RLIM_NLIMITS];
59140+#endif
59141 struct linux_binprm *bprm;
59142 struct file *file;
59143 struct files_struct *displaced;
59144@@ -1449,6 +1557,8 @@ static int do_execve_common(struct filename *filename,
59145 if (IS_ERR(filename))
59146 return PTR_ERR(filename);
59147
59148+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
59149+
59150 /*
59151 * We move the actual failure in case of RLIMIT_NPROC excess from
59152 * set*uid() to execve() because too many poorly written programs
59153@@ -1486,11 +1596,21 @@ static int do_execve_common(struct filename *filename,
59154 if (IS_ERR(file))
59155 goto out_unmark;
59156
59157+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
59158+ retval = -EPERM;
59159+ goto out_unmark;
59160+ }
59161+
59162 sched_exec();
59163
59164 bprm->file = file;
59165 bprm->filename = bprm->interp = filename->name;
59166
59167+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
59168+ retval = -EACCES;
59169+ goto out_unmark;
59170+ }
59171+
59172 retval = bprm_mm_init(bprm);
59173 if (retval)
59174 goto out_unmark;
59175@@ -1507,24 +1627,70 @@ static int do_execve_common(struct filename *filename,
59176 if (retval < 0)
59177 goto out;
59178
59179+#ifdef CONFIG_GRKERNSEC
59180+ old_acl = current->acl;
59181+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
59182+ old_exec_file = current->exec_file;
59183+ get_file(file);
59184+ current->exec_file = file;
59185+#endif
59186+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59187+ /* limit suid stack to 8MB
59188+ * we saved the old limits above and will restore them if this exec fails
59189+ */
59190+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
59191+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
59192+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
59193+#endif
59194+
59195+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
59196+ retval = -EPERM;
59197+ goto out_fail;
59198+ }
59199+
59200+ if (!gr_tpe_allow(file)) {
59201+ retval = -EACCES;
59202+ goto out_fail;
59203+ }
59204+
59205+ if (gr_check_crash_exec(file)) {
59206+ retval = -EACCES;
59207+ goto out_fail;
59208+ }
59209+
59210+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
59211+ bprm->unsafe);
59212+ if (retval < 0)
59213+ goto out_fail;
59214+
59215 retval = copy_strings_kernel(1, &bprm->filename, bprm);
59216 if (retval < 0)
59217- goto out;
59218+ goto out_fail;
59219
59220 bprm->exec = bprm->p;
59221 retval = copy_strings(bprm->envc, envp, bprm);
59222 if (retval < 0)
59223- goto out;
59224+ goto out_fail;
59225
59226 retval = copy_strings(bprm->argc, argv, bprm);
59227 if (retval < 0)
59228- goto out;
59229+ goto out_fail;
59230+
59231+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
59232+
59233+ gr_handle_exec_args(bprm, argv);
59234
59235 retval = exec_binprm(bprm);
59236 if (retval < 0)
59237- goto out;
59238+ goto out_fail;
59239+#ifdef CONFIG_GRKERNSEC
59240+ if (old_exec_file)
59241+ fput(old_exec_file);
59242+#endif
59243
59244 /* execve succeeded */
59245+
59246+ increment_exec_counter();
59247 current->fs->in_exec = 0;
59248 current->in_execve = 0;
59249 acct_update_integrals(current);
59250@@ -1535,6 +1701,14 @@ static int do_execve_common(struct filename *filename,
59251 put_files_struct(displaced);
59252 return retval;
59253
59254+out_fail:
59255+#ifdef CONFIG_GRKERNSEC
59256+ current->acl = old_acl;
59257+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
59258+ fput(current->exec_file);
59259+ current->exec_file = old_exec_file;
59260+#endif
59261+
59262 out:
59263 if (bprm->mm) {
59264 acct_arg_size(bprm, 0);
59265@@ -1626,3 +1800,296 @@ asmlinkage long compat_sys_execve(const char __user * filename,
59266 return compat_do_execve(getname(filename), argv, envp);
59267 }
59268 #endif
59269+
59270+int pax_check_flags(unsigned long *flags)
59271+{
59272+ int retval = 0;
59273+
59274+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
59275+ if (*flags & MF_PAX_SEGMEXEC)
59276+ {
59277+ *flags &= ~MF_PAX_SEGMEXEC;
59278+ retval = -EINVAL;
59279+ }
59280+#endif
59281+
59282+ if ((*flags & MF_PAX_PAGEEXEC)
59283+
59284+#ifdef CONFIG_PAX_PAGEEXEC
59285+ && (*flags & MF_PAX_SEGMEXEC)
59286+#endif
59287+
59288+ )
59289+ {
59290+ *flags &= ~MF_PAX_PAGEEXEC;
59291+ retval = -EINVAL;
59292+ }
59293+
59294+ if ((*flags & MF_PAX_MPROTECT)
59295+
59296+#ifdef CONFIG_PAX_MPROTECT
59297+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
59298+#endif
59299+
59300+ )
59301+ {
59302+ *flags &= ~MF_PAX_MPROTECT;
59303+ retval = -EINVAL;
59304+ }
59305+
59306+ if ((*flags & MF_PAX_EMUTRAMP)
59307+
59308+#ifdef CONFIG_PAX_EMUTRAMP
59309+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
59310+#endif
59311+
59312+ )
59313+ {
59314+ *flags &= ~MF_PAX_EMUTRAMP;
59315+ retval = -EINVAL;
59316+ }
59317+
59318+ return retval;
59319+}
59320+
59321+EXPORT_SYMBOL(pax_check_flags);
59322+
59323+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
59324+char *pax_get_path(const struct path *path, char *buf, int buflen)
59325+{
59326+ char *pathname = d_path(path, buf, buflen);
59327+
59328+ if (IS_ERR(pathname))
59329+ goto toolong;
59330+
59331+ pathname = mangle_path(buf, pathname, "\t\n\\");
59332+ if (!pathname)
59333+ goto toolong;
59334+
59335+ *pathname = 0;
59336+ return buf;
59337+
59338+toolong:
59339+ return "<path too long>";
59340+}
59341+EXPORT_SYMBOL(pax_get_path);
59342+
59343+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
59344+{
59345+ struct task_struct *tsk = current;
59346+ struct mm_struct *mm = current->mm;
59347+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
59348+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
59349+ char *path_exec = NULL;
59350+ char *path_fault = NULL;
59351+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
59352+ siginfo_t info = { };
59353+
59354+ if (buffer_exec && buffer_fault) {
59355+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
59356+
59357+ down_read(&mm->mmap_sem);
59358+ vma = mm->mmap;
59359+ while (vma && (!vma_exec || !vma_fault)) {
59360+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
59361+ vma_exec = vma;
59362+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
59363+ vma_fault = vma;
59364+ vma = vma->vm_next;
59365+ }
59366+ if (vma_exec)
59367+ path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
59368+ if (vma_fault) {
59369+ start = vma_fault->vm_start;
59370+ end = vma_fault->vm_end;
59371+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
59372+ if (vma_fault->vm_file)
59373+ path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
59374+ else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
59375+ path_fault = "<heap>";
59376+ else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
59377+ path_fault = "<stack>";
59378+ else
59379+ path_fault = "<anonymous mapping>";
59380+ }
59381+ up_read(&mm->mmap_sem);
59382+ }
59383+ if (tsk->signal->curr_ip)
59384+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
59385+ else
59386+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
59387+ 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),
59388+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
59389+ free_page((unsigned long)buffer_exec);
59390+ free_page((unsigned long)buffer_fault);
59391+ pax_report_insns(regs, pc, sp);
59392+ info.si_signo = SIGKILL;
59393+ info.si_errno = 0;
59394+ info.si_code = SI_KERNEL;
59395+ info.si_pid = 0;
59396+ info.si_uid = 0;
59397+ do_coredump(&info);
59398+}
59399+#endif
59400+
59401+#ifdef CONFIG_PAX_REFCOUNT
59402+void pax_report_refcount_overflow(struct pt_regs *regs)
59403+{
59404+ if (current->signal->curr_ip)
59405+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
59406+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
59407+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
59408+ else
59409+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
59410+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
59411+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
59412+ preempt_disable();
59413+ show_regs(regs);
59414+ preempt_enable();
59415+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
59416+}
59417+#endif
59418+
59419+#ifdef CONFIG_PAX_USERCOPY
59420+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
59421+static noinline int check_stack_object(const void *obj, unsigned long len)
59422+{
59423+ const void * const stack = task_stack_page(current);
59424+ const void * const stackend = stack + THREAD_SIZE;
59425+
59426+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
59427+ const void *frame = NULL;
59428+ const void *oldframe;
59429+#endif
59430+
59431+ if (obj + len < obj)
59432+ return -1;
59433+
59434+ if (obj + len <= stack || stackend <= obj)
59435+ return 0;
59436+
59437+ if (obj < stack || stackend < obj + len)
59438+ return -1;
59439+
59440+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
59441+ oldframe = __builtin_frame_address(1);
59442+ if (oldframe)
59443+ frame = __builtin_frame_address(2);
59444+ /*
59445+ low ----------------------------------------------> high
59446+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
59447+ ^----------------^
59448+ allow copies only within here
59449+ */
59450+ while (stack <= frame && frame < stackend) {
59451+ /* if obj + len extends past the last frame, this
59452+ check won't pass and the next frame will be 0,
59453+ causing us to bail out and correctly report
59454+ the copy as invalid
59455+ */
59456+ if (obj + len <= frame)
59457+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
59458+ oldframe = frame;
59459+ frame = *(const void * const *)frame;
59460+ }
59461+ return -1;
59462+#else
59463+ return 1;
59464+#endif
59465+}
59466+
59467+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
59468+{
59469+ if (current->signal->curr_ip)
59470+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
59471+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
59472+ else
59473+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
59474+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
59475+ dump_stack();
59476+ gr_handle_kernel_exploit();
59477+ do_group_exit(SIGKILL);
59478+}
59479+#endif
59480+
59481+#ifdef CONFIG_PAX_USERCOPY
59482+
59483+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
59484+{
59485+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
59486+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
59487+#ifdef CONFIG_MODULES
59488+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
59489+#else
59490+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
59491+#endif
59492+
59493+#else
59494+ unsigned long textlow = (unsigned long)_stext;
59495+ unsigned long texthigh = (unsigned long)_etext;
59496+
59497+#ifdef CONFIG_X86_64
59498+ /* check against linear mapping as well */
59499+ if (high > (unsigned long)__va(__pa(textlow)) &&
59500+ low < (unsigned long)__va(__pa(texthigh)))
59501+ return true;
59502+#endif
59503+
59504+#endif
59505+
59506+ if (high <= textlow || low >= texthigh)
59507+ return false;
59508+ else
59509+ return true;
59510+}
59511+#endif
59512+
59513+void __check_object_size(const void *ptr, unsigned long n, bool to_user)
59514+{
59515+
59516+#ifdef CONFIG_PAX_USERCOPY
59517+ const char *type;
59518+
59519+ if (!n)
59520+ return;
59521+
59522+ type = check_heap_object(ptr, n);
59523+ if (!type) {
59524+ int ret = check_stack_object(ptr, n);
59525+ if (ret == 1 || ret == 2)
59526+ return;
59527+ if (ret == 0) {
59528+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
59529+ type = "<kernel text>";
59530+ else
59531+ return;
59532+ } else
59533+ type = "<process stack>";
59534+ }
59535+
59536+ pax_report_usercopy(ptr, n, to_user, type);
59537+#endif
59538+
59539+}
59540+EXPORT_SYMBOL(__check_object_size);
59541+
59542+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
59543+void pax_track_stack(void)
59544+{
59545+ unsigned long sp = (unsigned long)&sp;
59546+ if (sp < current_thread_info()->lowest_stack &&
59547+ sp > (unsigned long)task_stack_page(current))
59548+ current_thread_info()->lowest_stack = sp;
59549+}
59550+EXPORT_SYMBOL(pax_track_stack);
59551+#endif
59552+
59553+#ifdef CONFIG_PAX_SIZE_OVERFLOW
59554+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
59555+{
59556+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
59557+ dump_stack();
59558+ do_group_exit(SIGKILL);
59559+}
59560+EXPORT_SYMBOL(report_size_overflow);
59561+#endif
59562diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
59563index 9f9992b..8b59411 100644
59564--- a/fs/ext2/balloc.c
59565+++ b/fs/ext2/balloc.c
59566@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
59567
59568 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
59569 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
59570- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
59571+ if (free_blocks < root_blocks + 1 &&
59572 !uid_eq(sbi->s_resuid, current_fsuid()) &&
59573 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
59574- !in_group_p (sbi->s_resgid))) {
59575+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
59576 return 0;
59577 }
59578 return 1;
59579diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
59580index 9142614..97484fa 100644
59581--- a/fs/ext2/xattr.c
59582+++ b/fs/ext2/xattr.c
59583@@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
59584 struct buffer_head *bh = NULL;
59585 struct ext2_xattr_entry *entry;
59586 char *end;
59587- size_t rest = buffer_size;
59588+ size_t rest = buffer_size, total_size = 0;
59589 int error;
59590
59591 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
59592@@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
59593 buffer += size;
59594 }
59595 rest -= size;
59596+ total_size += size;
59597 }
59598 }
59599- error = buffer_size - rest; /* total size */
59600+ error = total_size;
59601
59602 cleanup:
59603 brelse(bh);
59604diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
59605index 22548f5..41521d8 100644
59606--- a/fs/ext3/balloc.c
59607+++ b/fs/ext3/balloc.c
59608@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
59609
59610 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
59611 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
59612- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
59613+ if (free_blocks < root_blocks + 1 &&
59614 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
59615 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
59616- !in_group_p (sbi->s_resgid))) {
59617+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
59618 return 0;
59619 }
59620 return 1;
59621diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
59622index c6874be..f8a6ae8 100644
59623--- a/fs/ext3/xattr.c
59624+++ b/fs/ext3/xattr.c
59625@@ -330,7 +330,7 @@ static int
59626 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59627 char *buffer, size_t buffer_size)
59628 {
59629- size_t rest = buffer_size;
59630+ size_t rest = buffer_size, total_size = 0;
59631
59632 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
59633 const struct xattr_handler *handler =
59634@@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59635 buffer += size;
59636 }
59637 rest -= size;
59638+ total_size += size;
59639 }
59640 }
59641- return buffer_size - rest;
59642+ return total_size;
59643 }
59644
59645 static int
59646diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
59647index 6ea7b14..8fa16d9 100644
59648--- a/fs/ext4/balloc.c
59649+++ b/fs/ext4/balloc.c
59650@@ -534,8 +534,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
59651 /* Hm, nope. Are (enough) root reserved clusters available? */
59652 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
59653 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
59654- capable(CAP_SYS_RESOURCE) ||
59655- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
59656+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
59657+ capable_nolog(CAP_SYS_RESOURCE)) {
59658
59659 if (free_clusters >= (nclusters + dirty_clusters +
59660 resv_clusters))
59661diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
59662index 3a603a8..9b868ba 100644
59663--- a/fs/ext4/ext4.h
59664+++ b/fs/ext4/ext4.h
59665@@ -1269,19 +1269,19 @@ struct ext4_sb_info {
59666 unsigned long s_mb_last_start;
59667
59668 /* stats for buddy allocator */
59669- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
59670- atomic_t s_bal_success; /* we found long enough chunks */
59671- atomic_t s_bal_allocated; /* in blocks */
59672- atomic_t s_bal_ex_scanned; /* total extents scanned */
59673- atomic_t s_bal_goals; /* goal hits */
59674- atomic_t s_bal_breaks; /* too long searches */
59675- atomic_t s_bal_2orders; /* 2^order hits */
59676+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
59677+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
59678+ atomic_unchecked_t s_bal_allocated; /* in blocks */
59679+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
59680+ atomic_unchecked_t s_bal_goals; /* goal hits */
59681+ atomic_unchecked_t s_bal_breaks; /* too long searches */
59682+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
59683 spinlock_t s_bal_lock;
59684 unsigned long s_mb_buddies_generated;
59685 unsigned long long s_mb_generation_time;
59686- atomic_t s_mb_lost_chunks;
59687- atomic_t s_mb_preallocated;
59688- atomic_t s_mb_discarded;
59689+ atomic_unchecked_t s_mb_lost_chunks;
59690+ atomic_unchecked_t s_mb_preallocated;
59691+ atomic_unchecked_t s_mb_discarded;
59692 atomic_t s_lock_busy;
59693
59694 /* locality groups */
59695diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
59696index 04a5c75..09894fa 100644
59697--- a/fs/ext4/mballoc.c
59698+++ b/fs/ext4/mballoc.c
59699@@ -1880,7 +1880,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
59700 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
59701
59702 if (EXT4_SB(sb)->s_mb_stats)
59703- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
59704+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
59705
59706 break;
59707 }
59708@@ -2189,7 +2189,7 @@ repeat:
59709 ac->ac_status = AC_STATUS_CONTINUE;
59710 ac->ac_flags |= EXT4_MB_HINT_FIRST;
59711 cr = 3;
59712- atomic_inc(&sbi->s_mb_lost_chunks);
59713+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
59714 goto repeat;
59715 }
59716 }
59717@@ -2697,25 +2697,25 @@ int ext4_mb_release(struct super_block *sb)
59718 if (sbi->s_mb_stats) {
59719 ext4_msg(sb, KERN_INFO,
59720 "mballoc: %u blocks %u reqs (%u success)",
59721- atomic_read(&sbi->s_bal_allocated),
59722- atomic_read(&sbi->s_bal_reqs),
59723- atomic_read(&sbi->s_bal_success));
59724+ atomic_read_unchecked(&sbi->s_bal_allocated),
59725+ atomic_read_unchecked(&sbi->s_bal_reqs),
59726+ atomic_read_unchecked(&sbi->s_bal_success));
59727 ext4_msg(sb, KERN_INFO,
59728 "mballoc: %u extents scanned, %u goal hits, "
59729 "%u 2^N hits, %u breaks, %u lost",
59730- atomic_read(&sbi->s_bal_ex_scanned),
59731- atomic_read(&sbi->s_bal_goals),
59732- atomic_read(&sbi->s_bal_2orders),
59733- atomic_read(&sbi->s_bal_breaks),
59734- atomic_read(&sbi->s_mb_lost_chunks));
59735+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
59736+ atomic_read_unchecked(&sbi->s_bal_goals),
59737+ atomic_read_unchecked(&sbi->s_bal_2orders),
59738+ atomic_read_unchecked(&sbi->s_bal_breaks),
59739+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
59740 ext4_msg(sb, KERN_INFO,
59741 "mballoc: %lu generated and it took %Lu",
59742 sbi->s_mb_buddies_generated,
59743 sbi->s_mb_generation_time);
59744 ext4_msg(sb, KERN_INFO,
59745 "mballoc: %u preallocated, %u discarded",
59746- atomic_read(&sbi->s_mb_preallocated),
59747- atomic_read(&sbi->s_mb_discarded));
59748+ atomic_read_unchecked(&sbi->s_mb_preallocated),
59749+ atomic_read_unchecked(&sbi->s_mb_discarded));
59750 }
59751
59752 free_percpu(sbi->s_locality_groups);
59753@@ -3169,16 +3169,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
59754 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
59755
59756 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
59757- atomic_inc(&sbi->s_bal_reqs);
59758- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59759+ atomic_inc_unchecked(&sbi->s_bal_reqs);
59760+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59761 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
59762- atomic_inc(&sbi->s_bal_success);
59763- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
59764+ atomic_inc_unchecked(&sbi->s_bal_success);
59765+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
59766 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
59767 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
59768- atomic_inc(&sbi->s_bal_goals);
59769+ atomic_inc_unchecked(&sbi->s_bal_goals);
59770 if (ac->ac_found > sbi->s_mb_max_to_scan)
59771- atomic_inc(&sbi->s_bal_breaks);
59772+ atomic_inc_unchecked(&sbi->s_bal_breaks);
59773 }
59774
59775 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
59776@@ -3583,7 +3583,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
59777 trace_ext4_mb_new_inode_pa(ac, pa);
59778
59779 ext4_mb_use_inode_pa(ac, pa);
59780- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
59781+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
59782
59783 ei = EXT4_I(ac->ac_inode);
59784 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59785@@ -3643,7 +3643,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
59786 trace_ext4_mb_new_group_pa(ac, pa);
59787
59788 ext4_mb_use_group_pa(ac, pa);
59789- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59790+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59791
59792 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59793 lg = ac->ac_lg;
59794@@ -3732,7 +3732,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
59795 * from the bitmap and continue.
59796 */
59797 }
59798- atomic_add(free, &sbi->s_mb_discarded);
59799+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
59800
59801 return err;
59802 }
59803@@ -3750,7 +3750,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
59804 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
59805 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
59806 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
59807- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59808+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59809 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
59810
59811 return 0;
59812diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
59813index 04434ad..6404663 100644
59814--- a/fs/ext4/mmp.c
59815+++ b/fs/ext4/mmp.c
59816@@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
59817 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
59818 const char *function, unsigned int line, const char *msg)
59819 {
59820- __ext4_warning(sb, function, line, msg);
59821+ __ext4_warning(sb, function, line, "%s", msg);
59822 __ext4_warning(sb, function, line,
59823 "MMP failure info: last update time: %llu, last update "
59824 "node: %s, last update device: %s\n",
59825diff --git a/fs/ext4/super.c b/fs/ext4/super.c
59826index 710fed2..a82e4e8 100644
59827--- a/fs/ext4/super.c
59828+++ b/fs/ext4/super.c
59829@@ -1270,7 +1270,7 @@ static ext4_fsblk_t get_sb_block(void **data)
59830 }
59831
59832 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
59833-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59834+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59835 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
59836
59837 #ifdef CONFIG_QUOTA
59838@@ -2450,7 +2450,7 @@ struct ext4_attr {
59839 int offset;
59840 int deprecated_val;
59841 } u;
59842-};
59843+} __do_const;
59844
59845 static int parse_strtoull(const char *buf,
59846 unsigned long long max, unsigned long long *value)
59847diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
59848index 55e611c..cfad16d 100644
59849--- a/fs/ext4/xattr.c
59850+++ b/fs/ext4/xattr.c
59851@@ -381,7 +381,7 @@ static int
59852 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59853 char *buffer, size_t buffer_size)
59854 {
59855- size_t rest = buffer_size;
59856+ size_t rest = buffer_size, total_size = 0;
59857
59858 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
59859 const struct xattr_handler *handler =
59860@@ -398,9 +398,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59861 buffer += size;
59862 }
59863 rest -= size;
59864+ total_size += size;
59865 }
59866 }
59867- return buffer_size - rest;
59868+ return total_size;
59869 }
59870
59871 static int
59872diff --git a/fs/fcntl.c b/fs/fcntl.c
59873index ef68665..5deacdc 100644
59874--- a/fs/fcntl.c
59875+++ b/fs/fcntl.c
59876@@ -106,6 +106,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
59877 if (err)
59878 return err;
59879
59880+ if (gr_handle_chroot_fowner(pid, type))
59881+ return -ENOENT;
59882+ if (gr_check_protected_task_fowner(pid, type))
59883+ return -EACCES;
59884+
59885 f_modown(filp, pid, type, force);
59886 return 0;
59887 }
59888diff --git a/fs/fhandle.c b/fs/fhandle.c
59889index 999ff5c..41f4109 100644
59890--- a/fs/fhandle.c
59891+++ b/fs/fhandle.c
59892@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
59893 } else
59894 retval = 0;
59895 /* copy the mount id */
59896- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
59897- sizeof(*mnt_id)) ||
59898+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
59899 copy_to_user(ufh, handle,
59900 sizeof(struct file_handle) + handle_bytes))
59901 retval = -EFAULT;
59902diff --git a/fs/file.c b/fs/file.c
59903index eb56a13..ccee850 100644
59904--- a/fs/file.c
59905+++ b/fs/file.c
59906@@ -16,6 +16,7 @@
59907 #include <linux/slab.h>
59908 #include <linux/vmalloc.h>
59909 #include <linux/file.h>
59910+#include <linux/security.h>
59911 #include <linux/fdtable.h>
59912 #include <linux/bitops.h>
59913 #include <linux/interrupt.h>
59914@@ -141,7 +142,7 @@ out:
59915 * Return <0 error code on error; 1 on successful completion.
59916 * The files->file_lock should be held on entry, and will be held on exit.
59917 */
59918-static int expand_fdtable(struct files_struct *files, int nr)
59919+static int expand_fdtable(struct files_struct *files, unsigned int nr)
59920 __releases(files->file_lock)
59921 __acquires(files->file_lock)
59922 {
59923@@ -186,7 +187,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
59924 * expanded and execution may have blocked.
59925 * The files->file_lock should be held on entry, and will be held on exit.
59926 */
59927-static int expand_files(struct files_struct *files, int nr)
59928+static int expand_files(struct files_struct *files, unsigned int nr)
59929 {
59930 struct fdtable *fdt;
59931
59932@@ -807,6 +808,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
59933 if (!file)
59934 return __close_fd(files, fd);
59935
59936+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
59937 if (fd >= rlimit(RLIMIT_NOFILE))
59938 return -EBADF;
59939
59940@@ -833,6 +835,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
59941 if (unlikely(oldfd == newfd))
59942 return -EINVAL;
59943
59944+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
59945 if (newfd >= rlimit(RLIMIT_NOFILE))
59946 return -EBADF;
59947
59948@@ -888,6 +891,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
59949 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
59950 {
59951 int err;
59952+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
59953 if (from >= rlimit(RLIMIT_NOFILE))
59954 return -EINVAL;
59955 err = alloc_fd(from, flags);
59956diff --git a/fs/filesystems.c b/fs/filesystems.c
59957index 92567d9..fcd8cbf 100644
59958--- a/fs/filesystems.c
59959+++ b/fs/filesystems.c
59960@@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
59961 int len = dot ? dot - name : strlen(name);
59962
59963 fs = __get_fs_type(name, len);
59964+#ifdef CONFIG_GRKERNSEC_MODHARDEN
59965+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
59966+#else
59967 if (!fs && (request_module("fs-%.*s", len, name) == 0))
59968+#endif
59969 fs = __get_fs_type(name, len);
59970
59971 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
59972diff --git a/fs/fs_struct.c b/fs/fs_struct.c
59973index 7dca743..543d620 100644
59974--- a/fs/fs_struct.c
59975+++ b/fs/fs_struct.c
59976@@ -4,6 +4,7 @@
59977 #include <linux/path.h>
59978 #include <linux/slab.h>
59979 #include <linux/fs_struct.h>
59980+#include <linux/grsecurity.h>
59981 #include "internal.h"
59982
59983 /*
59984@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
59985 write_seqcount_begin(&fs->seq);
59986 old_root = fs->root;
59987 fs->root = *path;
59988+ gr_set_chroot_entries(current, path);
59989 write_seqcount_end(&fs->seq);
59990 spin_unlock(&fs->lock);
59991 if (old_root.dentry)
59992@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
59993 int hits = 0;
59994 spin_lock(&fs->lock);
59995 write_seqcount_begin(&fs->seq);
59996+ /* this root replacement is only done by pivot_root,
59997+ leave grsec's chroot tagging alone for this task
59998+ so that a pivoted root isn't treated as a chroot
59999+ */
60000 hits += replace_path(&fs->root, old_root, new_root);
60001 hits += replace_path(&fs->pwd, old_root, new_root);
60002 write_seqcount_end(&fs->seq);
60003@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
60004 task_lock(tsk);
60005 spin_lock(&fs->lock);
60006 tsk->fs = NULL;
60007- kill = !--fs->users;
60008+ gr_clear_chroot_entries(tsk);
60009+ kill = !atomic_dec_return(&fs->users);
60010 spin_unlock(&fs->lock);
60011 task_unlock(tsk);
60012 if (kill)
60013@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
60014 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
60015 /* We don't need to lock fs - think why ;-) */
60016 if (fs) {
60017- fs->users = 1;
60018+ atomic_set(&fs->users, 1);
60019 fs->in_exec = 0;
60020 spin_lock_init(&fs->lock);
60021 seqcount_init(&fs->seq);
60022@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
60023 spin_lock(&old->lock);
60024 fs->root = old->root;
60025 path_get(&fs->root);
60026+ /* instead of calling gr_set_chroot_entries here,
60027+ we call it from every caller of this function
60028+ */
60029 fs->pwd = old->pwd;
60030 path_get(&fs->pwd);
60031 spin_unlock(&old->lock);
60032@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
60033
60034 task_lock(current);
60035 spin_lock(&fs->lock);
60036- kill = !--fs->users;
60037+ kill = !atomic_dec_return(&fs->users);
60038 current->fs = new_fs;
60039+ gr_set_chroot_entries(current, &new_fs->root);
60040 spin_unlock(&fs->lock);
60041 task_unlock(current);
60042
60043@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
60044
60045 int current_umask(void)
60046 {
60047- return current->fs->umask;
60048+ return current->fs->umask | gr_acl_umask();
60049 }
60050 EXPORT_SYMBOL(current_umask);
60051
60052 /* to be mentioned only in INIT_TASK */
60053 struct fs_struct init_fs = {
60054- .users = 1,
60055+ .users = ATOMIC_INIT(1),
60056 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
60057 .seq = SEQCNT_ZERO(init_fs.seq),
60058 .umask = 0022,
60059diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
60060index 29d7feb..303644d 100644
60061--- a/fs/fscache/cookie.c
60062+++ b/fs/fscache/cookie.c
60063@@ -19,7 +19,7 @@
60064
60065 struct kmem_cache *fscache_cookie_jar;
60066
60067-static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
60068+static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
60069
60070 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
60071 static int fscache_alloc_object(struct fscache_cache *cache,
60072@@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
60073 parent ? (char *) parent->def->name : "<no-parent>",
60074 def->name, netfs_data, enable);
60075
60076- fscache_stat(&fscache_n_acquires);
60077+ fscache_stat_unchecked(&fscache_n_acquires);
60078
60079 /* if there's no parent cookie, then we don't create one here either */
60080 if (!parent) {
60081- fscache_stat(&fscache_n_acquires_null);
60082+ fscache_stat_unchecked(&fscache_n_acquires_null);
60083 _leave(" [no parent]");
60084 return NULL;
60085 }
60086@@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
60087 /* allocate and initialise a cookie */
60088 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
60089 if (!cookie) {
60090- fscache_stat(&fscache_n_acquires_oom);
60091+ fscache_stat_unchecked(&fscache_n_acquires_oom);
60092 _leave(" [ENOMEM]");
60093 return NULL;
60094 }
60095@@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
60096
60097 switch (cookie->def->type) {
60098 case FSCACHE_COOKIE_TYPE_INDEX:
60099- fscache_stat(&fscache_n_cookie_index);
60100+ fscache_stat_unchecked(&fscache_n_cookie_index);
60101 break;
60102 case FSCACHE_COOKIE_TYPE_DATAFILE:
60103- fscache_stat(&fscache_n_cookie_data);
60104+ fscache_stat_unchecked(&fscache_n_cookie_data);
60105 break;
60106 default:
60107- fscache_stat(&fscache_n_cookie_special);
60108+ fscache_stat_unchecked(&fscache_n_cookie_special);
60109 break;
60110 }
60111
60112@@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
60113 } else {
60114 atomic_dec(&parent->n_children);
60115 __fscache_cookie_put(cookie);
60116- fscache_stat(&fscache_n_acquires_nobufs);
60117+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
60118 _leave(" = NULL");
60119 return NULL;
60120 }
60121@@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
60122 }
60123 }
60124
60125- fscache_stat(&fscache_n_acquires_ok);
60126+ fscache_stat_unchecked(&fscache_n_acquires_ok);
60127 _leave(" = %p", cookie);
60128 return cookie;
60129 }
60130@@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
60131 cache = fscache_select_cache_for_object(cookie->parent);
60132 if (!cache) {
60133 up_read(&fscache_addremove_sem);
60134- fscache_stat(&fscache_n_acquires_no_cache);
60135+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
60136 _leave(" = -ENOMEDIUM [no cache]");
60137 return -ENOMEDIUM;
60138 }
60139@@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
60140 object = cache->ops->alloc_object(cache, cookie);
60141 fscache_stat_d(&fscache_n_cop_alloc_object);
60142 if (IS_ERR(object)) {
60143- fscache_stat(&fscache_n_object_no_alloc);
60144+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
60145 ret = PTR_ERR(object);
60146 goto error;
60147 }
60148
60149- fscache_stat(&fscache_n_object_alloc);
60150+ fscache_stat_unchecked(&fscache_n_object_alloc);
60151
60152- object->debug_id = atomic_inc_return(&fscache_object_debug_id);
60153+ object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
60154
60155 _debug("ALLOC OBJ%x: %s {%lx}",
60156 object->debug_id, cookie->def->name, object->events);
60157@@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
60158
60159 _enter("{%s}", cookie->def->name);
60160
60161- fscache_stat(&fscache_n_invalidates);
60162+ fscache_stat_unchecked(&fscache_n_invalidates);
60163
60164 /* Only permit invalidation of data files. Invalidating an index will
60165 * require the caller to release all its attachments to the tree rooted
60166@@ -477,10 +477,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
60167 {
60168 struct fscache_object *object;
60169
60170- fscache_stat(&fscache_n_updates);
60171+ fscache_stat_unchecked(&fscache_n_updates);
60172
60173 if (!cookie) {
60174- fscache_stat(&fscache_n_updates_null);
60175+ fscache_stat_unchecked(&fscache_n_updates_null);
60176 _leave(" [no cookie]");
60177 return;
60178 }
60179@@ -581,12 +581,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
60180 */
60181 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
60182 {
60183- fscache_stat(&fscache_n_relinquishes);
60184+ fscache_stat_unchecked(&fscache_n_relinquishes);
60185 if (retire)
60186- fscache_stat(&fscache_n_relinquishes_retire);
60187+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
60188
60189 if (!cookie) {
60190- fscache_stat(&fscache_n_relinquishes_null);
60191+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
60192 _leave(" [no cookie]");
60193 return;
60194 }
60195@@ -687,7 +687,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
60196 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
60197 goto inconsistent;
60198
60199- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
60200+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60201
60202 __fscache_use_cookie(cookie);
60203 if (fscache_submit_op(object, op) < 0)
60204diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
60205index 4226f66..0fb3f45 100644
60206--- a/fs/fscache/internal.h
60207+++ b/fs/fscache/internal.h
60208@@ -133,8 +133,8 @@ extern void fscache_operation_gc(struct work_struct *);
60209 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
60210 extern int fscache_wait_for_operation_activation(struct fscache_object *,
60211 struct fscache_operation *,
60212- atomic_t *,
60213- atomic_t *,
60214+ atomic_unchecked_t *,
60215+ atomic_unchecked_t *,
60216 void (*)(struct fscache_operation *));
60217 extern void fscache_invalidate_writes(struct fscache_cookie *);
60218
60219@@ -153,101 +153,101 @@ extern void fscache_proc_cleanup(void);
60220 * stats.c
60221 */
60222 #ifdef CONFIG_FSCACHE_STATS
60223-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
60224-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
60225+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
60226+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
60227
60228-extern atomic_t fscache_n_op_pend;
60229-extern atomic_t fscache_n_op_run;
60230-extern atomic_t fscache_n_op_enqueue;
60231-extern atomic_t fscache_n_op_deferred_release;
60232-extern atomic_t fscache_n_op_release;
60233-extern atomic_t fscache_n_op_gc;
60234-extern atomic_t fscache_n_op_cancelled;
60235-extern atomic_t fscache_n_op_rejected;
60236+extern atomic_unchecked_t fscache_n_op_pend;
60237+extern atomic_unchecked_t fscache_n_op_run;
60238+extern atomic_unchecked_t fscache_n_op_enqueue;
60239+extern atomic_unchecked_t fscache_n_op_deferred_release;
60240+extern atomic_unchecked_t fscache_n_op_release;
60241+extern atomic_unchecked_t fscache_n_op_gc;
60242+extern atomic_unchecked_t fscache_n_op_cancelled;
60243+extern atomic_unchecked_t fscache_n_op_rejected;
60244
60245-extern atomic_t fscache_n_attr_changed;
60246-extern atomic_t fscache_n_attr_changed_ok;
60247-extern atomic_t fscache_n_attr_changed_nobufs;
60248-extern atomic_t fscache_n_attr_changed_nomem;
60249-extern atomic_t fscache_n_attr_changed_calls;
60250+extern atomic_unchecked_t fscache_n_attr_changed;
60251+extern atomic_unchecked_t fscache_n_attr_changed_ok;
60252+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
60253+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
60254+extern atomic_unchecked_t fscache_n_attr_changed_calls;
60255
60256-extern atomic_t fscache_n_allocs;
60257-extern atomic_t fscache_n_allocs_ok;
60258-extern atomic_t fscache_n_allocs_wait;
60259-extern atomic_t fscache_n_allocs_nobufs;
60260-extern atomic_t fscache_n_allocs_intr;
60261-extern atomic_t fscache_n_allocs_object_dead;
60262-extern atomic_t fscache_n_alloc_ops;
60263-extern atomic_t fscache_n_alloc_op_waits;
60264+extern atomic_unchecked_t fscache_n_allocs;
60265+extern atomic_unchecked_t fscache_n_allocs_ok;
60266+extern atomic_unchecked_t fscache_n_allocs_wait;
60267+extern atomic_unchecked_t fscache_n_allocs_nobufs;
60268+extern atomic_unchecked_t fscache_n_allocs_intr;
60269+extern atomic_unchecked_t fscache_n_allocs_object_dead;
60270+extern atomic_unchecked_t fscache_n_alloc_ops;
60271+extern atomic_unchecked_t fscache_n_alloc_op_waits;
60272
60273-extern atomic_t fscache_n_retrievals;
60274-extern atomic_t fscache_n_retrievals_ok;
60275-extern atomic_t fscache_n_retrievals_wait;
60276-extern atomic_t fscache_n_retrievals_nodata;
60277-extern atomic_t fscache_n_retrievals_nobufs;
60278-extern atomic_t fscache_n_retrievals_intr;
60279-extern atomic_t fscache_n_retrievals_nomem;
60280-extern atomic_t fscache_n_retrievals_object_dead;
60281-extern atomic_t fscache_n_retrieval_ops;
60282-extern atomic_t fscache_n_retrieval_op_waits;
60283+extern atomic_unchecked_t fscache_n_retrievals;
60284+extern atomic_unchecked_t fscache_n_retrievals_ok;
60285+extern atomic_unchecked_t fscache_n_retrievals_wait;
60286+extern atomic_unchecked_t fscache_n_retrievals_nodata;
60287+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
60288+extern atomic_unchecked_t fscache_n_retrievals_intr;
60289+extern atomic_unchecked_t fscache_n_retrievals_nomem;
60290+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
60291+extern atomic_unchecked_t fscache_n_retrieval_ops;
60292+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
60293
60294-extern atomic_t fscache_n_stores;
60295-extern atomic_t fscache_n_stores_ok;
60296-extern atomic_t fscache_n_stores_again;
60297-extern atomic_t fscache_n_stores_nobufs;
60298-extern atomic_t fscache_n_stores_oom;
60299-extern atomic_t fscache_n_store_ops;
60300-extern atomic_t fscache_n_store_calls;
60301-extern atomic_t fscache_n_store_pages;
60302-extern atomic_t fscache_n_store_radix_deletes;
60303-extern atomic_t fscache_n_store_pages_over_limit;
60304+extern atomic_unchecked_t fscache_n_stores;
60305+extern atomic_unchecked_t fscache_n_stores_ok;
60306+extern atomic_unchecked_t fscache_n_stores_again;
60307+extern atomic_unchecked_t fscache_n_stores_nobufs;
60308+extern atomic_unchecked_t fscache_n_stores_oom;
60309+extern atomic_unchecked_t fscache_n_store_ops;
60310+extern atomic_unchecked_t fscache_n_store_calls;
60311+extern atomic_unchecked_t fscache_n_store_pages;
60312+extern atomic_unchecked_t fscache_n_store_radix_deletes;
60313+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
60314
60315-extern atomic_t fscache_n_store_vmscan_not_storing;
60316-extern atomic_t fscache_n_store_vmscan_gone;
60317-extern atomic_t fscache_n_store_vmscan_busy;
60318-extern atomic_t fscache_n_store_vmscan_cancelled;
60319-extern atomic_t fscache_n_store_vmscan_wait;
60320+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
60321+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
60322+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
60323+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
60324+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
60325
60326-extern atomic_t fscache_n_marks;
60327-extern atomic_t fscache_n_uncaches;
60328+extern atomic_unchecked_t fscache_n_marks;
60329+extern atomic_unchecked_t fscache_n_uncaches;
60330
60331-extern atomic_t fscache_n_acquires;
60332-extern atomic_t fscache_n_acquires_null;
60333-extern atomic_t fscache_n_acquires_no_cache;
60334-extern atomic_t fscache_n_acquires_ok;
60335-extern atomic_t fscache_n_acquires_nobufs;
60336-extern atomic_t fscache_n_acquires_oom;
60337+extern atomic_unchecked_t fscache_n_acquires;
60338+extern atomic_unchecked_t fscache_n_acquires_null;
60339+extern atomic_unchecked_t fscache_n_acquires_no_cache;
60340+extern atomic_unchecked_t fscache_n_acquires_ok;
60341+extern atomic_unchecked_t fscache_n_acquires_nobufs;
60342+extern atomic_unchecked_t fscache_n_acquires_oom;
60343
60344-extern atomic_t fscache_n_invalidates;
60345-extern atomic_t fscache_n_invalidates_run;
60346+extern atomic_unchecked_t fscache_n_invalidates;
60347+extern atomic_unchecked_t fscache_n_invalidates_run;
60348
60349-extern atomic_t fscache_n_updates;
60350-extern atomic_t fscache_n_updates_null;
60351-extern atomic_t fscache_n_updates_run;
60352+extern atomic_unchecked_t fscache_n_updates;
60353+extern atomic_unchecked_t fscache_n_updates_null;
60354+extern atomic_unchecked_t fscache_n_updates_run;
60355
60356-extern atomic_t fscache_n_relinquishes;
60357-extern atomic_t fscache_n_relinquishes_null;
60358-extern atomic_t fscache_n_relinquishes_waitcrt;
60359-extern atomic_t fscache_n_relinquishes_retire;
60360+extern atomic_unchecked_t fscache_n_relinquishes;
60361+extern atomic_unchecked_t fscache_n_relinquishes_null;
60362+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
60363+extern atomic_unchecked_t fscache_n_relinquishes_retire;
60364
60365-extern atomic_t fscache_n_cookie_index;
60366-extern atomic_t fscache_n_cookie_data;
60367-extern atomic_t fscache_n_cookie_special;
60368+extern atomic_unchecked_t fscache_n_cookie_index;
60369+extern atomic_unchecked_t fscache_n_cookie_data;
60370+extern atomic_unchecked_t fscache_n_cookie_special;
60371
60372-extern atomic_t fscache_n_object_alloc;
60373-extern atomic_t fscache_n_object_no_alloc;
60374-extern atomic_t fscache_n_object_lookups;
60375-extern atomic_t fscache_n_object_lookups_negative;
60376-extern atomic_t fscache_n_object_lookups_positive;
60377-extern atomic_t fscache_n_object_lookups_timed_out;
60378-extern atomic_t fscache_n_object_created;
60379-extern atomic_t fscache_n_object_avail;
60380-extern atomic_t fscache_n_object_dead;
60381+extern atomic_unchecked_t fscache_n_object_alloc;
60382+extern atomic_unchecked_t fscache_n_object_no_alloc;
60383+extern atomic_unchecked_t fscache_n_object_lookups;
60384+extern atomic_unchecked_t fscache_n_object_lookups_negative;
60385+extern atomic_unchecked_t fscache_n_object_lookups_positive;
60386+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
60387+extern atomic_unchecked_t fscache_n_object_created;
60388+extern atomic_unchecked_t fscache_n_object_avail;
60389+extern atomic_unchecked_t fscache_n_object_dead;
60390
60391-extern atomic_t fscache_n_checkaux_none;
60392-extern atomic_t fscache_n_checkaux_okay;
60393-extern atomic_t fscache_n_checkaux_update;
60394-extern atomic_t fscache_n_checkaux_obsolete;
60395+extern atomic_unchecked_t fscache_n_checkaux_none;
60396+extern atomic_unchecked_t fscache_n_checkaux_okay;
60397+extern atomic_unchecked_t fscache_n_checkaux_update;
60398+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
60399
60400 extern atomic_t fscache_n_cop_alloc_object;
60401 extern atomic_t fscache_n_cop_lookup_object;
60402@@ -272,6 +272,11 @@ static inline void fscache_stat(atomic_t *stat)
60403 atomic_inc(stat);
60404 }
60405
60406+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
60407+{
60408+ atomic_inc_unchecked(stat);
60409+}
60410+
60411 static inline void fscache_stat_d(atomic_t *stat)
60412 {
60413 atomic_dec(stat);
60414@@ -284,6 +289,7 @@ extern const struct file_operations fscache_stats_fops;
60415
60416 #define __fscache_stat(stat) (NULL)
60417 #define fscache_stat(stat) do {} while (0)
60418+#define fscache_stat_unchecked(stat) do {} while (0)
60419 #define fscache_stat_d(stat) do {} while (0)
60420 #endif
60421
60422diff --git a/fs/fscache/object.c b/fs/fscache/object.c
60423index d3b4539..ed0c659 100644
60424--- a/fs/fscache/object.c
60425+++ b/fs/fscache/object.c
60426@@ -454,7 +454,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
60427 _debug("LOOKUP \"%s\" in \"%s\"",
60428 cookie->def->name, object->cache->tag->name);
60429
60430- fscache_stat(&fscache_n_object_lookups);
60431+ fscache_stat_unchecked(&fscache_n_object_lookups);
60432 fscache_stat(&fscache_n_cop_lookup_object);
60433 ret = object->cache->ops->lookup_object(object);
60434 fscache_stat_d(&fscache_n_cop_lookup_object);
60435@@ -464,7 +464,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
60436 if (ret == -ETIMEDOUT) {
60437 /* probably stuck behind another object, so move this one to
60438 * the back of the queue */
60439- fscache_stat(&fscache_n_object_lookups_timed_out);
60440+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
60441 _leave(" [timeout]");
60442 return NO_TRANSIT;
60443 }
60444@@ -492,7 +492,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
60445 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
60446
60447 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
60448- fscache_stat(&fscache_n_object_lookups_negative);
60449+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
60450
60451 /* Allow write requests to begin stacking up and read requests to begin
60452 * returning ENODATA.
60453@@ -527,7 +527,7 @@ void fscache_obtained_object(struct fscache_object *object)
60454 /* if we were still looking up, then we must have a positive lookup
60455 * result, in which case there may be data available */
60456 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
60457- fscache_stat(&fscache_n_object_lookups_positive);
60458+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
60459
60460 /* We do (presumably) have data */
60461 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
60462@@ -539,7 +539,7 @@ void fscache_obtained_object(struct fscache_object *object)
60463 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
60464 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
60465 } else {
60466- fscache_stat(&fscache_n_object_created);
60467+ fscache_stat_unchecked(&fscache_n_object_created);
60468 }
60469
60470 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
60471@@ -575,7 +575,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
60472 fscache_stat_d(&fscache_n_cop_lookup_complete);
60473
60474 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
60475- fscache_stat(&fscache_n_object_avail);
60476+ fscache_stat_unchecked(&fscache_n_object_avail);
60477
60478 _leave("");
60479 return transit_to(JUMPSTART_DEPS);
60480@@ -722,7 +722,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
60481
60482 /* this just shifts the object release to the work processor */
60483 fscache_put_object(object);
60484- fscache_stat(&fscache_n_object_dead);
60485+ fscache_stat_unchecked(&fscache_n_object_dead);
60486
60487 _leave("");
60488 return transit_to(OBJECT_DEAD);
60489@@ -887,7 +887,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
60490 enum fscache_checkaux result;
60491
60492 if (!object->cookie->def->check_aux) {
60493- fscache_stat(&fscache_n_checkaux_none);
60494+ fscache_stat_unchecked(&fscache_n_checkaux_none);
60495 return FSCACHE_CHECKAUX_OKAY;
60496 }
60497
60498@@ -896,17 +896,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
60499 switch (result) {
60500 /* entry okay as is */
60501 case FSCACHE_CHECKAUX_OKAY:
60502- fscache_stat(&fscache_n_checkaux_okay);
60503+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
60504 break;
60505
60506 /* entry requires update */
60507 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
60508- fscache_stat(&fscache_n_checkaux_update);
60509+ fscache_stat_unchecked(&fscache_n_checkaux_update);
60510 break;
60511
60512 /* entry requires deletion */
60513 case FSCACHE_CHECKAUX_OBSOLETE:
60514- fscache_stat(&fscache_n_checkaux_obsolete);
60515+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
60516 break;
60517
60518 default:
60519@@ -992,7 +992,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
60520 {
60521 const struct fscache_state *s;
60522
60523- fscache_stat(&fscache_n_invalidates_run);
60524+ fscache_stat_unchecked(&fscache_n_invalidates_run);
60525 fscache_stat(&fscache_n_cop_invalidate_object);
60526 s = _fscache_invalidate_object(object, event);
60527 fscache_stat_d(&fscache_n_cop_invalidate_object);
60528@@ -1007,7 +1007,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
60529 {
60530 _enter("{OBJ%x},%d", object->debug_id, event);
60531
60532- fscache_stat(&fscache_n_updates_run);
60533+ fscache_stat_unchecked(&fscache_n_updates_run);
60534 fscache_stat(&fscache_n_cop_update_object);
60535 object->cache->ops->update_object(object);
60536 fscache_stat_d(&fscache_n_cop_update_object);
60537diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
60538index 318071a..379938b 100644
60539--- a/fs/fscache/operation.c
60540+++ b/fs/fscache/operation.c
60541@@ -17,7 +17,7 @@
60542 #include <linux/slab.h>
60543 #include "internal.h"
60544
60545-atomic_t fscache_op_debug_id;
60546+atomic_unchecked_t fscache_op_debug_id;
60547 EXPORT_SYMBOL(fscache_op_debug_id);
60548
60549 /**
60550@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
60551 ASSERTCMP(atomic_read(&op->usage), >, 0);
60552 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
60553
60554- fscache_stat(&fscache_n_op_enqueue);
60555+ fscache_stat_unchecked(&fscache_n_op_enqueue);
60556 switch (op->flags & FSCACHE_OP_TYPE) {
60557 case FSCACHE_OP_ASYNC:
60558 _debug("queue async");
60559@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
60560 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
60561 if (op->processor)
60562 fscache_enqueue_operation(op);
60563- fscache_stat(&fscache_n_op_run);
60564+ fscache_stat_unchecked(&fscache_n_op_run);
60565 }
60566
60567 /*
60568@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
60569 if (object->n_in_progress > 0) {
60570 atomic_inc(&op->usage);
60571 list_add_tail(&op->pend_link, &object->pending_ops);
60572- fscache_stat(&fscache_n_op_pend);
60573+ fscache_stat_unchecked(&fscache_n_op_pend);
60574 } else if (!list_empty(&object->pending_ops)) {
60575 atomic_inc(&op->usage);
60576 list_add_tail(&op->pend_link, &object->pending_ops);
60577- fscache_stat(&fscache_n_op_pend);
60578+ fscache_stat_unchecked(&fscache_n_op_pend);
60579 fscache_start_operations(object);
60580 } else {
60581 ASSERTCMP(object->n_in_progress, ==, 0);
60582@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
60583 object->n_exclusive++; /* reads and writes must wait */
60584 atomic_inc(&op->usage);
60585 list_add_tail(&op->pend_link, &object->pending_ops);
60586- fscache_stat(&fscache_n_op_pend);
60587+ fscache_stat_unchecked(&fscache_n_op_pend);
60588 ret = 0;
60589 } else {
60590 /* If we're in any other state, there must have been an I/O
60591@@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
60592 if (object->n_exclusive > 0) {
60593 atomic_inc(&op->usage);
60594 list_add_tail(&op->pend_link, &object->pending_ops);
60595- fscache_stat(&fscache_n_op_pend);
60596+ fscache_stat_unchecked(&fscache_n_op_pend);
60597 } else if (!list_empty(&object->pending_ops)) {
60598 atomic_inc(&op->usage);
60599 list_add_tail(&op->pend_link, &object->pending_ops);
60600- fscache_stat(&fscache_n_op_pend);
60601+ fscache_stat_unchecked(&fscache_n_op_pend);
60602 fscache_start_operations(object);
60603 } else {
60604 ASSERTCMP(object->n_exclusive, ==, 0);
60605@@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
60606 object->n_ops++;
60607 atomic_inc(&op->usage);
60608 list_add_tail(&op->pend_link, &object->pending_ops);
60609- fscache_stat(&fscache_n_op_pend);
60610+ fscache_stat_unchecked(&fscache_n_op_pend);
60611 ret = 0;
60612 } else if (fscache_object_is_dying(object)) {
60613- fscache_stat(&fscache_n_op_rejected);
60614+ fscache_stat_unchecked(&fscache_n_op_rejected);
60615 op->state = FSCACHE_OP_ST_CANCELLED;
60616 ret = -ENOBUFS;
60617 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
60618@@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
60619 ret = -EBUSY;
60620 if (op->state == FSCACHE_OP_ST_PENDING) {
60621 ASSERT(!list_empty(&op->pend_link));
60622- fscache_stat(&fscache_n_op_cancelled);
60623+ fscache_stat_unchecked(&fscache_n_op_cancelled);
60624 list_del_init(&op->pend_link);
60625 if (do_cancel)
60626 do_cancel(op);
60627@@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
60628 while (!list_empty(&object->pending_ops)) {
60629 op = list_entry(object->pending_ops.next,
60630 struct fscache_operation, pend_link);
60631- fscache_stat(&fscache_n_op_cancelled);
60632+ fscache_stat_unchecked(&fscache_n_op_cancelled);
60633 list_del_init(&op->pend_link);
60634
60635 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
60636@@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
60637 op->state, ==, FSCACHE_OP_ST_CANCELLED);
60638 op->state = FSCACHE_OP_ST_DEAD;
60639
60640- fscache_stat(&fscache_n_op_release);
60641+ fscache_stat_unchecked(&fscache_n_op_release);
60642
60643 if (op->release) {
60644 op->release(op);
60645@@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
60646 * lock, and defer it otherwise */
60647 if (!spin_trylock(&object->lock)) {
60648 _debug("defer put");
60649- fscache_stat(&fscache_n_op_deferred_release);
60650+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
60651
60652 cache = object->cache;
60653 spin_lock(&cache->op_gc_list_lock);
60654@@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
60655
60656 _debug("GC DEFERRED REL OBJ%x OP%x",
60657 object->debug_id, op->debug_id);
60658- fscache_stat(&fscache_n_op_gc);
60659+ fscache_stat_unchecked(&fscache_n_op_gc);
60660
60661 ASSERTCMP(atomic_read(&op->usage), ==, 0);
60662 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
60663diff --git a/fs/fscache/page.c b/fs/fscache/page.c
60664index 7f5c658..6c1e164 100644
60665--- a/fs/fscache/page.c
60666+++ b/fs/fscache/page.c
60667@@ -61,7 +61,7 @@ try_again:
60668 val = radix_tree_lookup(&cookie->stores, page->index);
60669 if (!val) {
60670 rcu_read_unlock();
60671- fscache_stat(&fscache_n_store_vmscan_not_storing);
60672+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
60673 __fscache_uncache_page(cookie, page);
60674 return true;
60675 }
60676@@ -91,11 +91,11 @@ try_again:
60677 spin_unlock(&cookie->stores_lock);
60678
60679 if (xpage) {
60680- fscache_stat(&fscache_n_store_vmscan_cancelled);
60681- fscache_stat(&fscache_n_store_radix_deletes);
60682+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
60683+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60684 ASSERTCMP(xpage, ==, page);
60685 } else {
60686- fscache_stat(&fscache_n_store_vmscan_gone);
60687+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
60688 }
60689
60690 wake_up_bit(&cookie->flags, 0);
60691@@ -110,11 +110,11 @@ page_busy:
60692 * sleeping on memory allocation, so we may need to impose a timeout
60693 * too. */
60694 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
60695- fscache_stat(&fscache_n_store_vmscan_busy);
60696+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
60697 return false;
60698 }
60699
60700- fscache_stat(&fscache_n_store_vmscan_wait);
60701+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
60702 __fscache_wait_on_page_write(cookie, page);
60703 gfp &= ~__GFP_WAIT;
60704 goto try_again;
60705@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
60706 FSCACHE_COOKIE_STORING_TAG);
60707 if (!radix_tree_tag_get(&cookie->stores, page->index,
60708 FSCACHE_COOKIE_PENDING_TAG)) {
60709- fscache_stat(&fscache_n_store_radix_deletes);
60710+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60711 xpage = radix_tree_delete(&cookie->stores, page->index);
60712 }
60713 spin_unlock(&cookie->stores_lock);
60714@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
60715
60716 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
60717
60718- fscache_stat(&fscache_n_attr_changed_calls);
60719+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
60720
60721 if (fscache_object_is_active(object)) {
60722 fscache_stat(&fscache_n_cop_attr_changed);
60723@@ -188,11 +188,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60724
60725 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60726
60727- fscache_stat(&fscache_n_attr_changed);
60728+ fscache_stat_unchecked(&fscache_n_attr_changed);
60729
60730 op = kzalloc(sizeof(*op), GFP_KERNEL);
60731 if (!op) {
60732- fscache_stat(&fscache_n_attr_changed_nomem);
60733+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
60734 _leave(" = -ENOMEM");
60735 return -ENOMEM;
60736 }
60737@@ -214,7 +214,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60738 if (fscache_submit_exclusive_op(object, op) < 0)
60739 goto nobufs;
60740 spin_unlock(&cookie->lock);
60741- fscache_stat(&fscache_n_attr_changed_ok);
60742+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
60743 fscache_put_operation(op);
60744 _leave(" = 0");
60745 return 0;
60746@@ -225,7 +225,7 @@ nobufs:
60747 kfree(op);
60748 if (wake_cookie)
60749 __fscache_wake_unused_cookie(cookie);
60750- fscache_stat(&fscache_n_attr_changed_nobufs);
60751+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
60752 _leave(" = %d", -ENOBUFS);
60753 return -ENOBUFS;
60754 }
60755@@ -264,7 +264,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
60756 /* allocate a retrieval operation and attempt to submit it */
60757 op = kzalloc(sizeof(*op), GFP_NOIO);
60758 if (!op) {
60759- fscache_stat(&fscache_n_retrievals_nomem);
60760+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60761 return NULL;
60762 }
60763
60764@@ -294,13 +294,13 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
60765 return 0;
60766 }
60767
60768- fscache_stat(&fscache_n_retrievals_wait);
60769+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
60770
60771 jif = jiffies;
60772 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
60773 fscache_wait_bit_interruptible,
60774 TASK_INTERRUPTIBLE) != 0) {
60775- fscache_stat(&fscache_n_retrievals_intr);
60776+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
60777 _leave(" = -ERESTARTSYS");
60778 return -ERESTARTSYS;
60779 }
60780@@ -329,8 +329,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
60781 */
60782 int fscache_wait_for_operation_activation(struct fscache_object *object,
60783 struct fscache_operation *op,
60784- atomic_t *stat_op_waits,
60785- atomic_t *stat_object_dead,
60786+ atomic_unchecked_t *stat_op_waits,
60787+ atomic_unchecked_t *stat_object_dead,
60788 void (*do_cancel)(struct fscache_operation *))
60789 {
60790 int ret;
60791@@ -340,7 +340,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60792
60793 _debug(">>> WT");
60794 if (stat_op_waits)
60795- fscache_stat(stat_op_waits);
60796+ fscache_stat_unchecked(stat_op_waits);
60797 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
60798 fscache_wait_bit_interruptible,
60799 TASK_INTERRUPTIBLE) != 0) {
60800@@ -358,7 +358,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60801 check_if_dead:
60802 if (op->state == FSCACHE_OP_ST_CANCELLED) {
60803 if (stat_object_dead)
60804- fscache_stat(stat_object_dead);
60805+ fscache_stat_unchecked(stat_object_dead);
60806 _leave(" = -ENOBUFS [cancelled]");
60807 return -ENOBUFS;
60808 }
60809@@ -366,7 +366,7 @@ check_if_dead:
60810 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
60811 fscache_cancel_op(op, do_cancel);
60812 if (stat_object_dead)
60813- fscache_stat(stat_object_dead);
60814+ fscache_stat_unchecked(stat_object_dead);
60815 return -ENOBUFS;
60816 }
60817 return 0;
60818@@ -394,7 +394,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60819
60820 _enter("%p,%p,,,", cookie, page);
60821
60822- fscache_stat(&fscache_n_retrievals);
60823+ fscache_stat_unchecked(&fscache_n_retrievals);
60824
60825 if (hlist_empty(&cookie->backing_objects))
60826 goto nobufs;
60827@@ -436,7 +436,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60828 goto nobufs_unlock_dec;
60829 spin_unlock(&cookie->lock);
60830
60831- fscache_stat(&fscache_n_retrieval_ops);
60832+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
60833
60834 /* pin the netfs read context in case we need to do the actual netfs
60835 * read because we've encountered a cache read failure */
60836@@ -467,15 +467,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60837
60838 error:
60839 if (ret == -ENOMEM)
60840- fscache_stat(&fscache_n_retrievals_nomem);
60841+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60842 else if (ret == -ERESTARTSYS)
60843- fscache_stat(&fscache_n_retrievals_intr);
60844+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
60845 else if (ret == -ENODATA)
60846- fscache_stat(&fscache_n_retrievals_nodata);
60847+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60848 else if (ret < 0)
60849- fscache_stat(&fscache_n_retrievals_nobufs);
60850+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60851 else
60852- fscache_stat(&fscache_n_retrievals_ok);
60853+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
60854
60855 fscache_put_retrieval(op);
60856 _leave(" = %d", ret);
60857@@ -490,7 +490,7 @@ nobufs_unlock:
60858 __fscache_wake_unused_cookie(cookie);
60859 kfree(op);
60860 nobufs:
60861- fscache_stat(&fscache_n_retrievals_nobufs);
60862+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60863 _leave(" = -ENOBUFS");
60864 return -ENOBUFS;
60865 }
60866@@ -529,7 +529,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60867
60868 _enter("%p,,%d,,,", cookie, *nr_pages);
60869
60870- fscache_stat(&fscache_n_retrievals);
60871+ fscache_stat_unchecked(&fscache_n_retrievals);
60872
60873 if (hlist_empty(&cookie->backing_objects))
60874 goto nobufs;
60875@@ -567,7 +567,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60876 goto nobufs_unlock_dec;
60877 spin_unlock(&cookie->lock);
60878
60879- fscache_stat(&fscache_n_retrieval_ops);
60880+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
60881
60882 /* pin the netfs read context in case we need to do the actual netfs
60883 * read because we've encountered a cache read failure */
60884@@ -598,15 +598,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60885
60886 error:
60887 if (ret == -ENOMEM)
60888- fscache_stat(&fscache_n_retrievals_nomem);
60889+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60890 else if (ret == -ERESTARTSYS)
60891- fscache_stat(&fscache_n_retrievals_intr);
60892+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
60893 else if (ret == -ENODATA)
60894- fscache_stat(&fscache_n_retrievals_nodata);
60895+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60896 else if (ret < 0)
60897- fscache_stat(&fscache_n_retrievals_nobufs);
60898+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60899 else
60900- fscache_stat(&fscache_n_retrievals_ok);
60901+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
60902
60903 fscache_put_retrieval(op);
60904 _leave(" = %d", ret);
60905@@ -621,7 +621,7 @@ nobufs_unlock:
60906 if (wake_cookie)
60907 __fscache_wake_unused_cookie(cookie);
60908 nobufs:
60909- fscache_stat(&fscache_n_retrievals_nobufs);
60910+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60911 _leave(" = -ENOBUFS");
60912 return -ENOBUFS;
60913 }
60914@@ -646,7 +646,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60915
60916 _enter("%p,%p,,,", cookie, page);
60917
60918- fscache_stat(&fscache_n_allocs);
60919+ fscache_stat_unchecked(&fscache_n_allocs);
60920
60921 if (hlist_empty(&cookie->backing_objects))
60922 goto nobufs;
60923@@ -680,7 +680,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60924 goto nobufs_unlock_dec;
60925 spin_unlock(&cookie->lock);
60926
60927- fscache_stat(&fscache_n_alloc_ops);
60928+ fscache_stat_unchecked(&fscache_n_alloc_ops);
60929
60930 ret = fscache_wait_for_operation_activation(
60931 object, &op->op,
60932@@ -697,11 +697,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60933
60934 error:
60935 if (ret == -ERESTARTSYS)
60936- fscache_stat(&fscache_n_allocs_intr);
60937+ fscache_stat_unchecked(&fscache_n_allocs_intr);
60938 else if (ret < 0)
60939- fscache_stat(&fscache_n_allocs_nobufs);
60940+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
60941 else
60942- fscache_stat(&fscache_n_allocs_ok);
60943+ fscache_stat_unchecked(&fscache_n_allocs_ok);
60944
60945 fscache_put_retrieval(op);
60946 _leave(" = %d", ret);
60947@@ -715,7 +715,7 @@ nobufs_unlock:
60948 if (wake_cookie)
60949 __fscache_wake_unused_cookie(cookie);
60950 nobufs:
60951- fscache_stat(&fscache_n_allocs_nobufs);
60952+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
60953 _leave(" = -ENOBUFS");
60954 return -ENOBUFS;
60955 }
60956@@ -791,7 +791,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60957
60958 spin_lock(&cookie->stores_lock);
60959
60960- fscache_stat(&fscache_n_store_calls);
60961+ fscache_stat_unchecked(&fscache_n_store_calls);
60962
60963 /* find a page to store */
60964 page = NULL;
60965@@ -802,7 +802,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60966 page = results[0];
60967 _debug("gang %d [%lx]", n, page->index);
60968 if (page->index > op->store_limit) {
60969- fscache_stat(&fscache_n_store_pages_over_limit);
60970+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
60971 goto superseded;
60972 }
60973
60974@@ -814,7 +814,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60975 spin_unlock(&cookie->stores_lock);
60976 spin_unlock(&object->lock);
60977
60978- fscache_stat(&fscache_n_store_pages);
60979+ fscache_stat_unchecked(&fscache_n_store_pages);
60980 fscache_stat(&fscache_n_cop_write_page);
60981 ret = object->cache->ops->write_page(op, page);
60982 fscache_stat_d(&fscache_n_cop_write_page);
60983@@ -918,7 +918,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60984 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60985 ASSERT(PageFsCache(page));
60986
60987- fscache_stat(&fscache_n_stores);
60988+ fscache_stat_unchecked(&fscache_n_stores);
60989
60990 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
60991 _leave(" = -ENOBUFS [invalidating]");
60992@@ -977,7 +977,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60993 spin_unlock(&cookie->stores_lock);
60994 spin_unlock(&object->lock);
60995
60996- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
60997+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60998 op->store_limit = object->store_limit;
60999
61000 __fscache_use_cookie(cookie);
61001@@ -986,8 +986,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
61002
61003 spin_unlock(&cookie->lock);
61004 radix_tree_preload_end();
61005- fscache_stat(&fscache_n_store_ops);
61006- fscache_stat(&fscache_n_stores_ok);
61007+ fscache_stat_unchecked(&fscache_n_store_ops);
61008+ fscache_stat_unchecked(&fscache_n_stores_ok);
61009
61010 /* the work queue now carries its own ref on the object */
61011 fscache_put_operation(&op->op);
61012@@ -995,14 +995,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
61013 return 0;
61014
61015 already_queued:
61016- fscache_stat(&fscache_n_stores_again);
61017+ fscache_stat_unchecked(&fscache_n_stores_again);
61018 already_pending:
61019 spin_unlock(&cookie->stores_lock);
61020 spin_unlock(&object->lock);
61021 spin_unlock(&cookie->lock);
61022 radix_tree_preload_end();
61023 kfree(op);
61024- fscache_stat(&fscache_n_stores_ok);
61025+ fscache_stat_unchecked(&fscache_n_stores_ok);
61026 _leave(" = 0");
61027 return 0;
61028
61029@@ -1024,14 +1024,14 @@ nobufs:
61030 kfree(op);
61031 if (wake_cookie)
61032 __fscache_wake_unused_cookie(cookie);
61033- fscache_stat(&fscache_n_stores_nobufs);
61034+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
61035 _leave(" = -ENOBUFS");
61036 return -ENOBUFS;
61037
61038 nomem_free:
61039 kfree(op);
61040 nomem:
61041- fscache_stat(&fscache_n_stores_oom);
61042+ fscache_stat_unchecked(&fscache_n_stores_oom);
61043 _leave(" = -ENOMEM");
61044 return -ENOMEM;
61045 }
61046@@ -1049,7 +1049,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
61047 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
61048 ASSERTCMP(page, !=, NULL);
61049
61050- fscache_stat(&fscache_n_uncaches);
61051+ fscache_stat_unchecked(&fscache_n_uncaches);
61052
61053 /* cache withdrawal may beat us to it */
61054 if (!PageFsCache(page))
61055@@ -1100,7 +1100,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
61056 struct fscache_cookie *cookie = op->op.object->cookie;
61057
61058 #ifdef CONFIG_FSCACHE_STATS
61059- atomic_inc(&fscache_n_marks);
61060+ atomic_inc_unchecked(&fscache_n_marks);
61061 #endif
61062
61063 _debug("- mark %p{%lx}", page, page->index);
61064diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
61065index 40d13c7..ddf52b9 100644
61066--- a/fs/fscache/stats.c
61067+++ b/fs/fscache/stats.c
61068@@ -18,99 +18,99 @@
61069 /*
61070 * operation counters
61071 */
61072-atomic_t fscache_n_op_pend;
61073-atomic_t fscache_n_op_run;
61074-atomic_t fscache_n_op_enqueue;
61075-atomic_t fscache_n_op_requeue;
61076-atomic_t fscache_n_op_deferred_release;
61077-atomic_t fscache_n_op_release;
61078-atomic_t fscache_n_op_gc;
61079-atomic_t fscache_n_op_cancelled;
61080-atomic_t fscache_n_op_rejected;
61081+atomic_unchecked_t fscache_n_op_pend;
61082+atomic_unchecked_t fscache_n_op_run;
61083+atomic_unchecked_t fscache_n_op_enqueue;
61084+atomic_unchecked_t fscache_n_op_requeue;
61085+atomic_unchecked_t fscache_n_op_deferred_release;
61086+atomic_unchecked_t fscache_n_op_release;
61087+atomic_unchecked_t fscache_n_op_gc;
61088+atomic_unchecked_t fscache_n_op_cancelled;
61089+atomic_unchecked_t fscache_n_op_rejected;
61090
61091-atomic_t fscache_n_attr_changed;
61092-atomic_t fscache_n_attr_changed_ok;
61093-atomic_t fscache_n_attr_changed_nobufs;
61094-atomic_t fscache_n_attr_changed_nomem;
61095-atomic_t fscache_n_attr_changed_calls;
61096+atomic_unchecked_t fscache_n_attr_changed;
61097+atomic_unchecked_t fscache_n_attr_changed_ok;
61098+atomic_unchecked_t fscache_n_attr_changed_nobufs;
61099+atomic_unchecked_t fscache_n_attr_changed_nomem;
61100+atomic_unchecked_t fscache_n_attr_changed_calls;
61101
61102-atomic_t fscache_n_allocs;
61103-atomic_t fscache_n_allocs_ok;
61104-atomic_t fscache_n_allocs_wait;
61105-atomic_t fscache_n_allocs_nobufs;
61106-atomic_t fscache_n_allocs_intr;
61107-atomic_t fscache_n_allocs_object_dead;
61108-atomic_t fscache_n_alloc_ops;
61109-atomic_t fscache_n_alloc_op_waits;
61110+atomic_unchecked_t fscache_n_allocs;
61111+atomic_unchecked_t fscache_n_allocs_ok;
61112+atomic_unchecked_t fscache_n_allocs_wait;
61113+atomic_unchecked_t fscache_n_allocs_nobufs;
61114+atomic_unchecked_t fscache_n_allocs_intr;
61115+atomic_unchecked_t fscache_n_allocs_object_dead;
61116+atomic_unchecked_t fscache_n_alloc_ops;
61117+atomic_unchecked_t fscache_n_alloc_op_waits;
61118
61119-atomic_t fscache_n_retrievals;
61120-atomic_t fscache_n_retrievals_ok;
61121-atomic_t fscache_n_retrievals_wait;
61122-atomic_t fscache_n_retrievals_nodata;
61123-atomic_t fscache_n_retrievals_nobufs;
61124-atomic_t fscache_n_retrievals_intr;
61125-atomic_t fscache_n_retrievals_nomem;
61126-atomic_t fscache_n_retrievals_object_dead;
61127-atomic_t fscache_n_retrieval_ops;
61128-atomic_t fscache_n_retrieval_op_waits;
61129+atomic_unchecked_t fscache_n_retrievals;
61130+atomic_unchecked_t fscache_n_retrievals_ok;
61131+atomic_unchecked_t fscache_n_retrievals_wait;
61132+atomic_unchecked_t fscache_n_retrievals_nodata;
61133+atomic_unchecked_t fscache_n_retrievals_nobufs;
61134+atomic_unchecked_t fscache_n_retrievals_intr;
61135+atomic_unchecked_t fscache_n_retrievals_nomem;
61136+atomic_unchecked_t fscache_n_retrievals_object_dead;
61137+atomic_unchecked_t fscache_n_retrieval_ops;
61138+atomic_unchecked_t fscache_n_retrieval_op_waits;
61139
61140-atomic_t fscache_n_stores;
61141-atomic_t fscache_n_stores_ok;
61142-atomic_t fscache_n_stores_again;
61143-atomic_t fscache_n_stores_nobufs;
61144-atomic_t fscache_n_stores_oom;
61145-atomic_t fscache_n_store_ops;
61146-atomic_t fscache_n_store_calls;
61147-atomic_t fscache_n_store_pages;
61148-atomic_t fscache_n_store_radix_deletes;
61149-atomic_t fscache_n_store_pages_over_limit;
61150+atomic_unchecked_t fscache_n_stores;
61151+atomic_unchecked_t fscache_n_stores_ok;
61152+atomic_unchecked_t fscache_n_stores_again;
61153+atomic_unchecked_t fscache_n_stores_nobufs;
61154+atomic_unchecked_t fscache_n_stores_oom;
61155+atomic_unchecked_t fscache_n_store_ops;
61156+atomic_unchecked_t fscache_n_store_calls;
61157+atomic_unchecked_t fscache_n_store_pages;
61158+atomic_unchecked_t fscache_n_store_radix_deletes;
61159+atomic_unchecked_t fscache_n_store_pages_over_limit;
61160
61161-atomic_t fscache_n_store_vmscan_not_storing;
61162-atomic_t fscache_n_store_vmscan_gone;
61163-atomic_t fscache_n_store_vmscan_busy;
61164-atomic_t fscache_n_store_vmscan_cancelled;
61165-atomic_t fscache_n_store_vmscan_wait;
61166+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
61167+atomic_unchecked_t fscache_n_store_vmscan_gone;
61168+atomic_unchecked_t fscache_n_store_vmscan_busy;
61169+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
61170+atomic_unchecked_t fscache_n_store_vmscan_wait;
61171
61172-atomic_t fscache_n_marks;
61173-atomic_t fscache_n_uncaches;
61174+atomic_unchecked_t fscache_n_marks;
61175+atomic_unchecked_t fscache_n_uncaches;
61176
61177-atomic_t fscache_n_acquires;
61178-atomic_t fscache_n_acquires_null;
61179-atomic_t fscache_n_acquires_no_cache;
61180-atomic_t fscache_n_acquires_ok;
61181-atomic_t fscache_n_acquires_nobufs;
61182-atomic_t fscache_n_acquires_oom;
61183+atomic_unchecked_t fscache_n_acquires;
61184+atomic_unchecked_t fscache_n_acquires_null;
61185+atomic_unchecked_t fscache_n_acquires_no_cache;
61186+atomic_unchecked_t fscache_n_acquires_ok;
61187+atomic_unchecked_t fscache_n_acquires_nobufs;
61188+atomic_unchecked_t fscache_n_acquires_oom;
61189
61190-atomic_t fscache_n_invalidates;
61191-atomic_t fscache_n_invalidates_run;
61192+atomic_unchecked_t fscache_n_invalidates;
61193+atomic_unchecked_t fscache_n_invalidates_run;
61194
61195-atomic_t fscache_n_updates;
61196-atomic_t fscache_n_updates_null;
61197-atomic_t fscache_n_updates_run;
61198+atomic_unchecked_t fscache_n_updates;
61199+atomic_unchecked_t fscache_n_updates_null;
61200+atomic_unchecked_t fscache_n_updates_run;
61201
61202-atomic_t fscache_n_relinquishes;
61203-atomic_t fscache_n_relinquishes_null;
61204-atomic_t fscache_n_relinquishes_waitcrt;
61205-atomic_t fscache_n_relinquishes_retire;
61206+atomic_unchecked_t fscache_n_relinquishes;
61207+atomic_unchecked_t fscache_n_relinquishes_null;
61208+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
61209+atomic_unchecked_t fscache_n_relinquishes_retire;
61210
61211-atomic_t fscache_n_cookie_index;
61212-atomic_t fscache_n_cookie_data;
61213-atomic_t fscache_n_cookie_special;
61214+atomic_unchecked_t fscache_n_cookie_index;
61215+atomic_unchecked_t fscache_n_cookie_data;
61216+atomic_unchecked_t fscache_n_cookie_special;
61217
61218-atomic_t fscache_n_object_alloc;
61219-atomic_t fscache_n_object_no_alloc;
61220-atomic_t fscache_n_object_lookups;
61221-atomic_t fscache_n_object_lookups_negative;
61222-atomic_t fscache_n_object_lookups_positive;
61223-atomic_t fscache_n_object_lookups_timed_out;
61224-atomic_t fscache_n_object_created;
61225-atomic_t fscache_n_object_avail;
61226-atomic_t fscache_n_object_dead;
61227+atomic_unchecked_t fscache_n_object_alloc;
61228+atomic_unchecked_t fscache_n_object_no_alloc;
61229+atomic_unchecked_t fscache_n_object_lookups;
61230+atomic_unchecked_t fscache_n_object_lookups_negative;
61231+atomic_unchecked_t fscache_n_object_lookups_positive;
61232+atomic_unchecked_t fscache_n_object_lookups_timed_out;
61233+atomic_unchecked_t fscache_n_object_created;
61234+atomic_unchecked_t fscache_n_object_avail;
61235+atomic_unchecked_t fscache_n_object_dead;
61236
61237-atomic_t fscache_n_checkaux_none;
61238-atomic_t fscache_n_checkaux_okay;
61239-atomic_t fscache_n_checkaux_update;
61240-atomic_t fscache_n_checkaux_obsolete;
61241+atomic_unchecked_t fscache_n_checkaux_none;
61242+atomic_unchecked_t fscache_n_checkaux_okay;
61243+atomic_unchecked_t fscache_n_checkaux_update;
61244+atomic_unchecked_t fscache_n_checkaux_obsolete;
61245
61246 atomic_t fscache_n_cop_alloc_object;
61247 atomic_t fscache_n_cop_lookup_object;
61248@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
61249 seq_puts(m, "FS-Cache statistics\n");
61250
61251 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
61252- atomic_read(&fscache_n_cookie_index),
61253- atomic_read(&fscache_n_cookie_data),
61254- atomic_read(&fscache_n_cookie_special));
61255+ atomic_read_unchecked(&fscache_n_cookie_index),
61256+ atomic_read_unchecked(&fscache_n_cookie_data),
61257+ atomic_read_unchecked(&fscache_n_cookie_special));
61258
61259 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
61260- atomic_read(&fscache_n_object_alloc),
61261- atomic_read(&fscache_n_object_no_alloc),
61262- atomic_read(&fscache_n_object_avail),
61263- atomic_read(&fscache_n_object_dead));
61264+ atomic_read_unchecked(&fscache_n_object_alloc),
61265+ atomic_read_unchecked(&fscache_n_object_no_alloc),
61266+ atomic_read_unchecked(&fscache_n_object_avail),
61267+ atomic_read_unchecked(&fscache_n_object_dead));
61268 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
61269- atomic_read(&fscache_n_checkaux_none),
61270- atomic_read(&fscache_n_checkaux_okay),
61271- atomic_read(&fscache_n_checkaux_update),
61272- atomic_read(&fscache_n_checkaux_obsolete));
61273+ atomic_read_unchecked(&fscache_n_checkaux_none),
61274+ atomic_read_unchecked(&fscache_n_checkaux_okay),
61275+ atomic_read_unchecked(&fscache_n_checkaux_update),
61276+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
61277
61278 seq_printf(m, "Pages : mrk=%u unc=%u\n",
61279- atomic_read(&fscache_n_marks),
61280- atomic_read(&fscache_n_uncaches));
61281+ atomic_read_unchecked(&fscache_n_marks),
61282+ atomic_read_unchecked(&fscache_n_uncaches));
61283
61284 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
61285 " oom=%u\n",
61286- atomic_read(&fscache_n_acquires),
61287- atomic_read(&fscache_n_acquires_null),
61288- atomic_read(&fscache_n_acquires_no_cache),
61289- atomic_read(&fscache_n_acquires_ok),
61290- atomic_read(&fscache_n_acquires_nobufs),
61291- atomic_read(&fscache_n_acquires_oom));
61292+ atomic_read_unchecked(&fscache_n_acquires),
61293+ atomic_read_unchecked(&fscache_n_acquires_null),
61294+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
61295+ atomic_read_unchecked(&fscache_n_acquires_ok),
61296+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
61297+ atomic_read_unchecked(&fscache_n_acquires_oom));
61298
61299 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
61300- atomic_read(&fscache_n_object_lookups),
61301- atomic_read(&fscache_n_object_lookups_negative),
61302- atomic_read(&fscache_n_object_lookups_positive),
61303- atomic_read(&fscache_n_object_created),
61304- atomic_read(&fscache_n_object_lookups_timed_out));
61305+ atomic_read_unchecked(&fscache_n_object_lookups),
61306+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
61307+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
61308+ atomic_read_unchecked(&fscache_n_object_created),
61309+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
61310
61311 seq_printf(m, "Invals : n=%u run=%u\n",
61312- atomic_read(&fscache_n_invalidates),
61313- atomic_read(&fscache_n_invalidates_run));
61314+ atomic_read_unchecked(&fscache_n_invalidates),
61315+ atomic_read_unchecked(&fscache_n_invalidates_run));
61316
61317 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
61318- atomic_read(&fscache_n_updates),
61319- atomic_read(&fscache_n_updates_null),
61320- atomic_read(&fscache_n_updates_run));
61321+ atomic_read_unchecked(&fscache_n_updates),
61322+ atomic_read_unchecked(&fscache_n_updates_null),
61323+ atomic_read_unchecked(&fscache_n_updates_run));
61324
61325 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
61326- atomic_read(&fscache_n_relinquishes),
61327- atomic_read(&fscache_n_relinquishes_null),
61328- atomic_read(&fscache_n_relinquishes_waitcrt),
61329- atomic_read(&fscache_n_relinquishes_retire));
61330+ atomic_read_unchecked(&fscache_n_relinquishes),
61331+ atomic_read_unchecked(&fscache_n_relinquishes_null),
61332+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
61333+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
61334
61335 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
61336- atomic_read(&fscache_n_attr_changed),
61337- atomic_read(&fscache_n_attr_changed_ok),
61338- atomic_read(&fscache_n_attr_changed_nobufs),
61339- atomic_read(&fscache_n_attr_changed_nomem),
61340- atomic_read(&fscache_n_attr_changed_calls));
61341+ atomic_read_unchecked(&fscache_n_attr_changed),
61342+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
61343+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
61344+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
61345+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
61346
61347 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
61348- atomic_read(&fscache_n_allocs),
61349- atomic_read(&fscache_n_allocs_ok),
61350- atomic_read(&fscache_n_allocs_wait),
61351- atomic_read(&fscache_n_allocs_nobufs),
61352- atomic_read(&fscache_n_allocs_intr));
61353+ atomic_read_unchecked(&fscache_n_allocs),
61354+ atomic_read_unchecked(&fscache_n_allocs_ok),
61355+ atomic_read_unchecked(&fscache_n_allocs_wait),
61356+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
61357+ atomic_read_unchecked(&fscache_n_allocs_intr));
61358 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
61359- atomic_read(&fscache_n_alloc_ops),
61360- atomic_read(&fscache_n_alloc_op_waits),
61361- atomic_read(&fscache_n_allocs_object_dead));
61362+ atomic_read_unchecked(&fscache_n_alloc_ops),
61363+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
61364+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
61365
61366 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
61367 " int=%u oom=%u\n",
61368- atomic_read(&fscache_n_retrievals),
61369- atomic_read(&fscache_n_retrievals_ok),
61370- atomic_read(&fscache_n_retrievals_wait),
61371- atomic_read(&fscache_n_retrievals_nodata),
61372- atomic_read(&fscache_n_retrievals_nobufs),
61373- atomic_read(&fscache_n_retrievals_intr),
61374- atomic_read(&fscache_n_retrievals_nomem));
61375+ atomic_read_unchecked(&fscache_n_retrievals),
61376+ atomic_read_unchecked(&fscache_n_retrievals_ok),
61377+ atomic_read_unchecked(&fscache_n_retrievals_wait),
61378+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
61379+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
61380+ atomic_read_unchecked(&fscache_n_retrievals_intr),
61381+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
61382 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
61383- atomic_read(&fscache_n_retrieval_ops),
61384- atomic_read(&fscache_n_retrieval_op_waits),
61385- atomic_read(&fscache_n_retrievals_object_dead));
61386+ atomic_read_unchecked(&fscache_n_retrieval_ops),
61387+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
61388+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
61389
61390 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
61391- atomic_read(&fscache_n_stores),
61392- atomic_read(&fscache_n_stores_ok),
61393- atomic_read(&fscache_n_stores_again),
61394- atomic_read(&fscache_n_stores_nobufs),
61395- atomic_read(&fscache_n_stores_oom));
61396+ atomic_read_unchecked(&fscache_n_stores),
61397+ atomic_read_unchecked(&fscache_n_stores_ok),
61398+ atomic_read_unchecked(&fscache_n_stores_again),
61399+ atomic_read_unchecked(&fscache_n_stores_nobufs),
61400+ atomic_read_unchecked(&fscache_n_stores_oom));
61401 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
61402- atomic_read(&fscache_n_store_ops),
61403- atomic_read(&fscache_n_store_calls),
61404- atomic_read(&fscache_n_store_pages),
61405- atomic_read(&fscache_n_store_radix_deletes),
61406- atomic_read(&fscache_n_store_pages_over_limit));
61407+ atomic_read_unchecked(&fscache_n_store_ops),
61408+ atomic_read_unchecked(&fscache_n_store_calls),
61409+ atomic_read_unchecked(&fscache_n_store_pages),
61410+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
61411+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
61412
61413 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
61414- atomic_read(&fscache_n_store_vmscan_not_storing),
61415- atomic_read(&fscache_n_store_vmscan_gone),
61416- atomic_read(&fscache_n_store_vmscan_busy),
61417- atomic_read(&fscache_n_store_vmscan_cancelled),
61418- atomic_read(&fscache_n_store_vmscan_wait));
61419+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
61420+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
61421+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
61422+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
61423+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
61424
61425 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
61426- atomic_read(&fscache_n_op_pend),
61427- atomic_read(&fscache_n_op_run),
61428- atomic_read(&fscache_n_op_enqueue),
61429- atomic_read(&fscache_n_op_cancelled),
61430- atomic_read(&fscache_n_op_rejected));
61431+ atomic_read_unchecked(&fscache_n_op_pend),
61432+ atomic_read_unchecked(&fscache_n_op_run),
61433+ atomic_read_unchecked(&fscache_n_op_enqueue),
61434+ atomic_read_unchecked(&fscache_n_op_cancelled),
61435+ atomic_read_unchecked(&fscache_n_op_rejected));
61436 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
61437- atomic_read(&fscache_n_op_deferred_release),
61438- atomic_read(&fscache_n_op_release),
61439- atomic_read(&fscache_n_op_gc));
61440+ atomic_read_unchecked(&fscache_n_op_deferred_release),
61441+ atomic_read_unchecked(&fscache_n_op_release),
61442+ atomic_read_unchecked(&fscache_n_op_gc));
61443
61444 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
61445 atomic_read(&fscache_n_cop_alloc_object),
61446diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
61447index b96a49b..9bfdc47 100644
61448--- a/fs/fuse/cuse.c
61449+++ b/fs/fuse/cuse.c
61450@@ -606,10 +606,12 @@ static int __init cuse_init(void)
61451 INIT_LIST_HEAD(&cuse_conntbl[i]);
61452
61453 /* inherit and extend fuse_dev_operations */
61454- cuse_channel_fops = fuse_dev_operations;
61455- cuse_channel_fops.owner = THIS_MODULE;
61456- cuse_channel_fops.open = cuse_channel_open;
61457- cuse_channel_fops.release = cuse_channel_release;
61458+ pax_open_kernel();
61459+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
61460+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
61461+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
61462+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
61463+ pax_close_kernel();
61464
61465 cuse_class = class_create(THIS_MODULE, "cuse");
61466 if (IS_ERR(cuse_class))
61467diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
61468index 0a648bb..8d463f1 100644
61469--- a/fs/fuse/dev.c
61470+++ b/fs/fuse/dev.c
61471@@ -1323,7 +1323,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
61472 ret = 0;
61473 pipe_lock(pipe);
61474
61475- if (!pipe->readers) {
61476+ if (!atomic_read(&pipe->readers)) {
61477 send_sig(SIGPIPE, current, 0);
61478 if (!ret)
61479 ret = -EPIPE;
61480@@ -1352,7 +1352,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
61481 page_nr++;
61482 ret += buf->len;
61483
61484- if (pipe->files)
61485+ if (atomic_read(&pipe->files))
61486 do_wakeup = 1;
61487 }
61488
61489diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
61490index 1d1292c..bba17ea 100644
61491--- a/fs/fuse/dir.c
61492+++ b/fs/fuse/dir.c
61493@@ -1418,7 +1418,7 @@ static char *read_link(struct dentry *dentry)
61494 return link;
61495 }
61496
61497-static void free_link(char *link)
61498+static void free_link(const char *link)
61499 {
61500 if (!IS_ERR(link))
61501 free_page((unsigned long) link);
61502diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
61503index fe649d3..c679164 100644
61504--- a/fs/hostfs/hostfs_kern.c
61505+++ b/fs/hostfs/hostfs_kern.c
61506@@ -898,7 +898,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
61507
61508 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
61509 {
61510- char *s = nd_get_link(nd);
61511+ const char *s = nd_get_link(nd);
61512 if (!IS_ERR(s))
61513 __putname(s);
61514 }
61515diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
61516index d19b30a..ef89c36 100644
61517--- a/fs/hugetlbfs/inode.c
61518+++ b/fs/hugetlbfs/inode.c
61519@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
61520 struct mm_struct *mm = current->mm;
61521 struct vm_area_struct *vma;
61522 struct hstate *h = hstate_file(file);
61523+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
61524 struct vm_unmapped_area_info info;
61525
61526 if (len & ~huge_page_mask(h))
61527@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
61528 return addr;
61529 }
61530
61531+#ifdef CONFIG_PAX_RANDMMAP
61532+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
61533+#endif
61534+
61535 if (addr) {
61536 addr = ALIGN(addr, huge_page_size(h));
61537 vma = find_vma(mm, addr);
61538- if (TASK_SIZE - len >= addr &&
61539- (!vma || addr + len <= vma->vm_start))
61540+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
61541 return addr;
61542 }
61543
61544 info.flags = 0;
61545 info.length = len;
61546 info.low_limit = TASK_UNMAPPED_BASE;
61547+
61548+#ifdef CONFIG_PAX_RANDMMAP
61549+ if (mm->pax_flags & MF_PAX_RANDMMAP)
61550+ info.low_limit += mm->delta_mmap;
61551+#endif
61552+
61553 info.high_limit = TASK_SIZE;
61554 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
61555 info.align_offset = 0;
61556@@ -908,7 +918,7 @@ static struct file_system_type hugetlbfs_fs_type = {
61557 };
61558 MODULE_ALIAS_FS("hugetlbfs");
61559
61560-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
61561+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
61562
61563 static int can_do_hugetlb_shm(void)
61564 {
61565diff --git a/fs/inode.c b/fs/inode.c
61566index 4bcdad3..1883822 100644
61567--- a/fs/inode.c
61568+++ b/fs/inode.c
61569@@ -841,8 +841,8 @@ unsigned int get_next_ino(void)
61570
61571 #ifdef CONFIG_SMP
61572 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
61573- static atomic_t shared_last_ino;
61574- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
61575+ static atomic_unchecked_t shared_last_ino;
61576+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
61577
61578 res = next - LAST_INO_BATCH;
61579 }
61580diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
61581index 4a6cf28..d3a29d3 100644
61582--- a/fs/jffs2/erase.c
61583+++ b/fs/jffs2/erase.c
61584@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
61585 struct jffs2_unknown_node marker = {
61586 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
61587 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
61588- .totlen = cpu_to_je32(c->cleanmarker_size)
61589+ .totlen = cpu_to_je32(c->cleanmarker_size),
61590+ .hdr_crc = cpu_to_je32(0)
61591 };
61592
61593 jffs2_prealloc_raw_node_refs(c, jeb, 1);
61594diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
61595index a6597d6..41b30ec 100644
61596--- a/fs/jffs2/wbuf.c
61597+++ b/fs/jffs2/wbuf.c
61598@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
61599 {
61600 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
61601 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
61602- .totlen = constant_cpu_to_je32(8)
61603+ .totlen = constant_cpu_to_je32(8),
61604+ .hdr_crc = constant_cpu_to_je32(0)
61605 };
61606
61607 /*
61608diff --git a/fs/jfs/super.c b/fs/jfs/super.c
61609index e2b7483..855bca3 100644
61610--- a/fs/jfs/super.c
61611+++ b/fs/jfs/super.c
61612@@ -884,7 +884,7 @@ static int __init init_jfs_fs(void)
61613
61614 jfs_inode_cachep =
61615 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
61616- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
61617+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
61618 init_once);
61619 if (jfs_inode_cachep == NULL)
61620 return -ENOMEM;
61621diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
61622index 39c0143..d54fad4 100644
61623--- a/fs/kernfs/dir.c
61624+++ b/fs/kernfs/dir.c
61625@@ -28,7 +28,7 @@ DEFINE_MUTEX(kernfs_mutex);
61626 *
61627 * Returns 31 bit hash of ns + name (so it fits in an off_t )
61628 */
61629-static unsigned int kernfs_name_hash(const char *name, const void *ns)
61630+static unsigned int kernfs_name_hash(const unsigned char *name, const void *ns)
61631 {
61632 unsigned long hash = init_name_hash();
61633 unsigned int len = strlen(name);
61634diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
61635index dbf397b..d624b48 100644
61636--- a/fs/kernfs/file.c
61637+++ b/fs/kernfs/file.c
61638@@ -33,7 +33,7 @@ static DEFINE_MUTEX(kernfs_open_file_mutex);
61639
61640 struct kernfs_open_node {
61641 atomic_t refcnt;
61642- atomic_t event;
61643+ atomic_unchecked_t event;
61644 wait_queue_head_t poll;
61645 struct list_head files; /* goes through kernfs_open_file.list */
61646 };
61647@@ -149,7 +149,7 @@ static int kernfs_seq_show(struct seq_file *sf, void *v)
61648 {
61649 struct kernfs_open_file *of = sf->private;
61650
61651- of->event = atomic_read(&of->kn->attr.open->event);
61652+ of->event = atomic_read_unchecked(&of->kn->attr.open->event);
61653
61654 return of->kn->attr.ops->seq_show(sf, v);
61655 }
61656@@ -353,12 +353,12 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
61657 return ret;
61658 }
61659
61660-static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
61661- void *buf, int len, int write)
61662+static ssize_t kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
61663+ void *buf, size_t len, int write)
61664 {
61665 struct file *file = vma->vm_file;
61666 struct kernfs_open_file *of = kernfs_of(file);
61667- int ret;
61668+ ssize_t ret;
61669
61670 if (!of->vm_ops)
61671 return -EINVAL;
61672@@ -557,7 +557,7 @@ static int kernfs_get_open_node(struct kernfs_node *kn,
61673 return -ENOMEM;
61674
61675 atomic_set(&new_on->refcnt, 0);
61676- atomic_set(&new_on->event, 1);
61677+ atomic_set_unchecked(&new_on->event, 1);
61678 init_waitqueue_head(&new_on->poll);
61679 INIT_LIST_HEAD(&new_on->files);
61680 goto retry;
61681@@ -754,7 +754,7 @@ static unsigned int kernfs_fop_poll(struct file *filp, poll_table *wait)
61682
61683 kernfs_put_active(kn);
61684
61685- if (of->event != atomic_read(&on->event))
61686+ if (of->event != atomic_read_unchecked(&on->event))
61687 goto trigger;
61688
61689 return DEFAULT_POLLMASK;
61690@@ -779,7 +779,7 @@ void kernfs_notify(struct kernfs_node *kn)
61691 if (!WARN_ON(kernfs_type(kn) != KERNFS_FILE)) {
61692 on = kn->attr.open;
61693 if (on) {
61694- atomic_inc(&on->event);
61695+ atomic_inc_unchecked(&on->event);
61696 wake_up_interruptible(&on->poll);
61697 }
61698 }
61699diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c
61700index 4d45705..b35e0bd 100644
61701--- a/fs/kernfs/symlink.c
61702+++ b/fs/kernfs/symlink.c
61703@@ -132,7 +132,7 @@ static void *kernfs_iop_follow_link(struct dentry *dentry, struct nameidata *nd)
61704 static void kernfs_iop_put_link(struct dentry *dentry, struct nameidata *nd,
61705 void *cookie)
61706 {
61707- char *page = nd_get_link(nd);
61708+ const char *page = nd_get_link(nd);
61709 if (!IS_ERR(page))
61710 free_page((unsigned long)page);
61711 }
61712diff --git a/fs/libfs.c b/fs/libfs.c
61713index a184424..944ddce 100644
61714--- a/fs/libfs.c
61715+++ b/fs/libfs.c
61716@@ -159,6 +159,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61717
61718 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
61719 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
61720+ char d_name[sizeof(next->d_iname)];
61721+ const unsigned char *name;
61722+
61723 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
61724 if (!simple_positive(next)) {
61725 spin_unlock(&next->d_lock);
61726@@ -167,7 +170,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61727
61728 spin_unlock(&next->d_lock);
61729 spin_unlock(&dentry->d_lock);
61730- if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
61731+ name = next->d_name.name;
61732+ if (name == next->d_iname) {
61733+ memcpy(d_name, name, next->d_name.len);
61734+ name = d_name;
61735+ }
61736+ if (!dir_emit(ctx, name, next->d_name.len,
61737 next->d_inode->i_ino, dt_type(next->d_inode)))
61738 return 0;
61739 spin_lock(&dentry->d_lock);
61740@@ -999,7 +1007,7 @@ EXPORT_SYMBOL(noop_fsync);
61741 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
61742 void *cookie)
61743 {
61744- char *s = nd_get_link(nd);
61745+ const char *s = nd_get_link(nd);
61746 if (!IS_ERR(s))
61747 kfree(s);
61748 }
61749diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
61750index acd3947..1f896e2 100644
61751--- a/fs/lockd/clntproc.c
61752+++ b/fs/lockd/clntproc.c
61753@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
61754 /*
61755 * Cookie counter for NLM requests
61756 */
61757-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
61758+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
61759
61760 void nlmclnt_next_cookie(struct nlm_cookie *c)
61761 {
61762- u32 cookie = atomic_inc_return(&nlm_cookie);
61763+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
61764
61765 memcpy(c->data, &cookie, 4);
61766 c->len=4;
61767diff --git a/fs/locks.c b/fs/locks.c
61768index 4dd39b9..12d6aaf 100644
61769--- a/fs/locks.c
61770+++ b/fs/locks.c
61771@@ -2218,16 +2218,16 @@ void locks_remove_flock(struct file *filp)
61772 return;
61773
61774 if (filp->f_op->flock) {
61775- struct file_lock fl = {
61776+ struct file_lock flock = {
61777 .fl_pid = current->tgid,
61778 .fl_file = filp,
61779 .fl_flags = FL_FLOCK,
61780 .fl_type = F_UNLCK,
61781 .fl_end = OFFSET_MAX,
61782 };
61783- filp->f_op->flock(filp, F_SETLKW, &fl);
61784- if (fl.fl_ops && fl.fl_ops->fl_release_private)
61785- fl.fl_ops->fl_release_private(&fl);
61786+ filp->f_op->flock(filp, F_SETLKW, &flock);
61787+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
61788+ flock.fl_ops->fl_release_private(&flock);
61789 }
61790
61791 spin_lock(&inode->i_lock);
61792diff --git a/fs/mount.h b/fs/mount.h
61793index b29e42f..5ea7fdf 100644
61794--- a/fs/mount.h
61795+++ b/fs/mount.h
61796@@ -11,7 +11,7 @@ struct mnt_namespace {
61797 u64 seq; /* Sequence number to prevent loops */
61798 wait_queue_head_t poll;
61799 int event;
61800-};
61801+} __randomize_layout;
61802
61803 struct mnt_pcp {
61804 int mnt_count;
61805@@ -57,7 +57,7 @@ struct mount {
61806 int mnt_expiry_mark; /* true if marked for expiry */
61807 int mnt_pinned;
61808 struct path mnt_ex_mountpoint;
61809-};
61810+} __randomize_layout;
61811
61812 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
61813
61814diff --git a/fs/namei.c b/fs/namei.c
61815index 4b491b4..a0166f9 100644
61816--- a/fs/namei.c
61817+++ b/fs/namei.c
61818@@ -330,16 +330,32 @@ int generic_permission(struct inode *inode, int mask)
61819 if (ret != -EACCES)
61820 return ret;
61821
61822+#ifdef CONFIG_GRKERNSEC
61823+ /* we'll block if we have to log due to a denied capability use */
61824+ if (mask & MAY_NOT_BLOCK)
61825+ return -ECHILD;
61826+#endif
61827+
61828 if (S_ISDIR(inode->i_mode)) {
61829 /* DACs are overridable for directories */
61830- if (inode_capable(inode, CAP_DAC_OVERRIDE))
61831- return 0;
61832 if (!(mask & MAY_WRITE))
61833- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
61834+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
61835+ inode_capable(inode, CAP_DAC_READ_SEARCH))
61836 return 0;
61837+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
61838+ return 0;
61839 return -EACCES;
61840 }
61841 /*
61842+ * Searching includes executable on directories, else just read.
61843+ */
61844+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61845+ if (mask == MAY_READ)
61846+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
61847+ inode_capable(inode, CAP_DAC_READ_SEARCH))
61848+ return 0;
61849+
61850+ /*
61851 * Read/write DACs are always overridable.
61852 * Executable DACs are overridable when there is
61853 * at least one exec bit set.
61854@@ -348,14 +364,6 @@ int generic_permission(struct inode *inode, int mask)
61855 if (inode_capable(inode, CAP_DAC_OVERRIDE))
61856 return 0;
61857
61858- /*
61859- * Searching includes executable on directories, else just read.
61860- */
61861- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61862- if (mask == MAY_READ)
61863- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
61864- return 0;
61865-
61866 return -EACCES;
61867 }
61868
61869@@ -821,7 +829,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61870 {
61871 struct dentry *dentry = link->dentry;
61872 int error;
61873- char *s;
61874+ const char *s;
61875
61876 BUG_ON(nd->flags & LOOKUP_RCU);
61877
61878@@ -842,6 +850,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61879 if (error)
61880 goto out_put_nd_path;
61881
61882+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
61883+ dentry->d_inode, dentry, nd->path.mnt)) {
61884+ error = -EACCES;
61885+ goto out_put_nd_path;
61886+ }
61887+
61888 nd->last_type = LAST_BIND;
61889 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
61890 error = PTR_ERR(*p);
61891@@ -1590,6 +1604,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
61892 if (res)
61893 break;
61894 res = walk_component(nd, path, LOOKUP_FOLLOW);
61895+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
61896+ res = -EACCES;
61897 put_link(nd, &link, cookie);
61898 } while (res > 0);
61899
61900@@ -1663,7 +1679,7 @@ EXPORT_SYMBOL(full_name_hash);
61901 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
61902 {
61903 unsigned long a, b, adata, bdata, mask, hash, len;
61904- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61905+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61906
61907 hash = a = 0;
61908 len = -sizeof(unsigned long);
61909@@ -1947,6 +1963,8 @@ static int path_lookupat(int dfd, const char *name,
61910 if (err)
61911 break;
61912 err = lookup_last(nd, &path);
61913+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
61914+ err = -EACCES;
61915 put_link(nd, &link, cookie);
61916 }
61917 }
61918@@ -1954,6 +1972,13 @@ static int path_lookupat(int dfd, const char *name,
61919 if (!err)
61920 err = complete_walk(nd);
61921
61922+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
61923+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
61924+ path_put(&nd->path);
61925+ err = -ENOENT;
61926+ }
61927+ }
61928+
61929 if (!err && nd->flags & LOOKUP_DIRECTORY) {
61930 if (!d_is_directory(nd->path.dentry)) {
61931 path_put(&nd->path);
61932@@ -1981,8 +2006,15 @@ static int filename_lookup(int dfd, struct filename *name,
61933 retval = path_lookupat(dfd, name->name,
61934 flags | LOOKUP_REVAL, nd);
61935
61936- if (likely(!retval))
61937+ if (likely(!retval)) {
61938 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
61939+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
61940+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
61941+ path_put(&nd->path);
61942+ return -ENOENT;
61943+ }
61944+ }
61945+ }
61946 return retval;
61947 }
61948
61949@@ -2556,6 +2588,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
61950 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
61951 return -EPERM;
61952
61953+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
61954+ return -EPERM;
61955+ if (gr_handle_rawio(inode))
61956+ return -EPERM;
61957+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
61958+ return -EACCES;
61959+
61960 return 0;
61961 }
61962
61963@@ -2787,7 +2826,7 @@ looked_up:
61964 * cleared otherwise prior to returning.
61965 */
61966 static int lookup_open(struct nameidata *nd, struct path *path,
61967- struct file *file,
61968+ struct path *link, struct file *file,
61969 const struct open_flags *op,
61970 bool got_write, int *opened)
61971 {
61972@@ -2822,6 +2861,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
61973 /* Negative dentry, just create the file */
61974 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
61975 umode_t mode = op->mode;
61976+
61977+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
61978+ error = -EACCES;
61979+ goto out_dput;
61980+ }
61981+
61982+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
61983+ error = -EACCES;
61984+ goto out_dput;
61985+ }
61986+
61987 if (!IS_POSIXACL(dir->d_inode))
61988 mode &= ~current_umask();
61989 /*
61990@@ -2843,6 +2893,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
61991 nd->flags & LOOKUP_EXCL);
61992 if (error)
61993 goto out_dput;
61994+ else
61995+ gr_handle_create(dentry, nd->path.mnt);
61996 }
61997 out_no_open:
61998 path->dentry = dentry;
61999@@ -2857,7 +2909,7 @@ out_dput:
62000 /*
62001 * Handle the last step of open()
62002 */
62003-static int do_last(struct nameidata *nd, struct path *path,
62004+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
62005 struct file *file, const struct open_flags *op,
62006 int *opened, struct filename *name)
62007 {
62008@@ -2907,6 +2959,15 @@ static int do_last(struct nameidata *nd, struct path *path,
62009 if (error)
62010 return error;
62011
62012+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
62013+ error = -ENOENT;
62014+ goto out;
62015+ }
62016+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
62017+ error = -EACCES;
62018+ goto out;
62019+ }
62020+
62021 audit_inode(name, dir, LOOKUP_PARENT);
62022 error = -EISDIR;
62023 /* trailing slashes? */
62024@@ -2926,7 +2987,7 @@ retry_lookup:
62025 */
62026 }
62027 mutex_lock(&dir->d_inode->i_mutex);
62028- error = lookup_open(nd, path, file, op, got_write, opened);
62029+ error = lookup_open(nd, path, link, file, op, got_write, opened);
62030 mutex_unlock(&dir->d_inode->i_mutex);
62031
62032 if (error <= 0) {
62033@@ -2950,11 +3011,28 @@ retry_lookup:
62034 goto finish_open_created;
62035 }
62036
62037+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
62038+ error = -ENOENT;
62039+ goto exit_dput;
62040+ }
62041+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
62042+ error = -EACCES;
62043+ goto exit_dput;
62044+ }
62045+
62046 /*
62047 * create/update audit record if it already exists.
62048 */
62049- if (d_is_positive(path->dentry))
62050+ if (d_is_positive(path->dentry)) {
62051+ /* only check if O_CREAT is specified, all other checks need to go
62052+ into may_open */
62053+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
62054+ error = -EACCES;
62055+ goto exit_dput;
62056+ }
62057+
62058 audit_inode(name, path->dentry, 0);
62059+ }
62060
62061 /*
62062 * If atomic_open() acquired write access it is dropped now due to
62063@@ -2995,6 +3073,11 @@ finish_lookup:
62064 }
62065 }
62066 BUG_ON(inode != path->dentry->d_inode);
62067+ /* if we're resolving a symlink to another symlink */
62068+ if (link && gr_handle_symlink_owner(link, inode)) {
62069+ error = -EACCES;
62070+ goto out;
62071+ }
62072 return 1;
62073 }
62074
62075@@ -3004,7 +3087,6 @@ finish_lookup:
62076 save_parent.dentry = nd->path.dentry;
62077 save_parent.mnt = mntget(path->mnt);
62078 nd->path.dentry = path->dentry;
62079-
62080 }
62081 nd->inode = inode;
62082 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
62083@@ -3014,7 +3096,18 @@ finish_open:
62084 path_put(&save_parent);
62085 return error;
62086 }
62087+
62088+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
62089+ error = -ENOENT;
62090+ goto out;
62091+ }
62092+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
62093+ error = -EACCES;
62094+ goto out;
62095+ }
62096+
62097 audit_inode(name, nd->path.dentry, 0);
62098+
62099 error = -EISDIR;
62100 if ((open_flag & O_CREAT) &&
62101 (d_is_directory(nd->path.dentry) || d_is_autodir(nd->path.dentry)))
62102@@ -3178,7 +3271,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
62103 if (unlikely(error))
62104 goto out;
62105
62106- error = do_last(nd, &path, file, op, &opened, pathname);
62107+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
62108 while (unlikely(error > 0)) { /* trailing symlink */
62109 struct path link = path;
62110 void *cookie;
62111@@ -3196,7 +3289,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
62112 error = follow_link(&link, nd, &cookie);
62113 if (unlikely(error))
62114 break;
62115- error = do_last(nd, &path, file, op, &opened, pathname);
62116+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
62117 put_link(nd, &link, cookie);
62118 }
62119 out:
62120@@ -3296,9 +3389,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
62121 goto unlock;
62122
62123 error = -EEXIST;
62124- if (d_is_positive(dentry))
62125+ if (d_is_positive(dentry)) {
62126+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
62127+ error = -ENOENT;
62128 goto fail;
62129-
62130+ }
62131 /*
62132 * Special case - lookup gave negative, but... we had foo/bar/
62133 * From the vfs_mknod() POV we just have a negative dentry -
62134@@ -3350,6 +3445,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
62135 }
62136 EXPORT_SYMBOL(user_path_create);
62137
62138+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
62139+{
62140+ struct filename *tmp = getname(pathname);
62141+ struct dentry *res;
62142+ if (IS_ERR(tmp))
62143+ return ERR_CAST(tmp);
62144+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
62145+ if (IS_ERR(res))
62146+ putname(tmp);
62147+ else
62148+ *to = tmp;
62149+ return res;
62150+}
62151+
62152 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
62153 {
62154 int error = may_create(dir, dentry);
62155@@ -3412,6 +3521,17 @@ retry:
62156
62157 if (!IS_POSIXACL(path.dentry->d_inode))
62158 mode &= ~current_umask();
62159+
62160+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
62161+ error = -EPERM;
62162+ goto out;
62163+ }
62164+
62165+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
62166+ error = -EACCES;
62167+ goto out;
62168+ }
62169+
62170 error = security_path_mknod(&path, dentry, mode, dev);
62171 if (error)
62172 goto out;
62173@@ -3428,6 +3548,8 @@ retry:
62174 break;
62175 }
62176 out:
62177+ if (!error)
62178+ gr_handle_create(dentry, path.mnt);
62179 done_path_create(&path, dentry);
62180 if (retry_estale(error, lookup_flags)) {
62181 lookup_flags |= LOOKUP_REVAL;
62182@@ -3480,9 +3602,16 @@ retry:
62183
62184 if (!IS_POSIXACL(path.dentry->d_inode))
62185 mode &= ~current_umask();
62186+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
62187+ error = -EACCES;
62188+ goto out;
62189+ }
62190 error = security_path_mkdir(&path, dentry, mode);
62191 if (!error)
62192 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
62193+ if (!error)
62194+ gr_handle_create(dentry, path.mnt);
62195+out:
62196 done_path_create(&path, dentry);
62197 if (retry_estale(error, lookup_flags)) {
62198 lookup_flags |= LOOKUP_REVAL;
62199@@ -3563,6 +3692,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
62200 struct filename *name;
62201 struct dentry *dentry;
62202 struct nameidata nd;
62203+ ino_t saved_ino = 0;
62204+ dev_t saved_dev = 0;
62205 unsigned int lookup_flags = 0;
62206 retry:
62207 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
62208@@ -3595,10 +3726,21 @@ retry:
62209 error = -ENOENT;
62210 goto exit3;
62211 }
62212+
62213+ saved_ino = dentry->d_inode->i_ino;
62214+ saved_dev = gr_get_dev_from_dentry(dentry);
62215+
62216+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
62217+ error = -EACCES;
62218+ goto exit3;
62219+ }
62220+
62221 error = security_path_rmdir(&nd.path, dentry);
62222 if (error)
62223 goto exit3;
62224 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
62225+ if (!error && (saved_dev || saved_ino))
62226+ gr_handle_delete(saved_ino, saved_dev);
62227 exit3:
62228 dput(dentry);
62229 exit2:
62230@@ -3688,6 +3830,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
62231 struct nameidata nd;
62232 struct inode *inode = NULL;
62233 struct inode *delegated_inode = NULL;
62234+ ino_t saved_ino = 0;
62235+ dev_t saved_dev = 0;
62236 unsigned int lookup_flags = 0;
62237 retry:
62238 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
62239@@ -3714,10 +3858,22 @@ retry_deleg:
62240 if (d_is_negative(dentry))
62241 goto slashes;
62242 ihold(inode);
62243+
62244+ if (inode->i_nlink <= 1) {
62245+ saved_ino = inode->i_ino;
62246+ saved_dev = gr_get_dev_from_dentry(dentry);
62247+ }
62248+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
62249+ error = -EACCES;
62250+ goto exit2;
62251+ }
62252+
62253 error = security_path_unlink(&nd.path, dentry);
62254 if (error)
62255 goto exit2;
62256 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
62257+ if (!error && (saved_ino || saved_dev))
62258+ gr_handle_delete(saved_ino, saved_dev);
62259 exit2:
62260 dput(dentry);
62261 }
62262@@ -3805,9 +3961,17 @@ retry:
62263 if (IS_ERR(dentry))
62264 goto out_putname;
62265
62266+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
62267+ error = -EACCES;
62268+ goto out;
62269+ }
62270+
62271 error = security_path_symlink(&path, dentry, from->name);
62272 if (!error)
62273 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
62274+ if (!error)
62275+ gr_handle_create(dentry, path.mnt);
62276+out:
62277 done_path_create(&path, dentry);
62278 if (retry_estale(error, lookup_flags)) {
62279 lookup_flags |= LOOKUP_REVAL;
62280@@ -3910,6 +4074,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
62281 struct dentry *new_dentry;
62282 struct path old_path, new_path;
62283 struct inode *delegated_inode = NULL;
62284+ struct filename *to = NULL;
62285 int how = 0;
62286 int error;
62287
62288@@ -3933,7 +4098,7 @@ retry:
62289 if (error)
62290 return error;
62291
62292- new_dentry = user_path_create(newdfd, newname, &new_path,
62293+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
62294 (how & LOOKUP_REVAL));
62295 error = PTR_ERR(new_dentry);
62296 if (IS_ERR(new_dentry))
62297@@ -3945,11 +4110,28 @@ retry:
62298 error = may_linkat(&old_path);
62299 if (unlikely(error))
62300 goto out_dput;
62301+
62302+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
62303+ old_path.dentry->d_inode,
62304+ old_path.dentry->d_inode->i_mode, to)) {
62305+ error = -EACCES;
62306+ goto out_dput;
62307+ }
62308+
62309+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
62310+ old_path.dentry, old_path.mnt, to)) {
62311+ error = -EACCES;
62312+ goto out_dput;
62313+ }
62314+
62315 error = security_path_link(old_path.dentry, &new_path, new_dentry);
62316 if (error)
62317 goto out_dput;
62318 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
62319+ if (!error)
62320+ gr_handle_create(new_dentry, new_path.mnt);
62321 out_dput:
62322+ putname(to);
62323 done_path_create(&new_path, new_dentry);
62324 if (delegated_inode) {
62325 error = break_deleg_wait(&delegated_inode);
62326@@ -4236,6 +4418,12 @@ retry_deleg:
62327 if (new_dentry == trap)
62328 goto exit5;
62329
62330+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
62331+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
62332+ to);
62333+ if (error)
62334+ goto exit5;
62335+
62336 error = security_path_rename(&oldnd.path, old_dentry,
62337 &newnd.path, new_dentry);
62338 if (error)
62339@@ -4243,6 +4431,9 @@ retry_deleg:
62340 error = vfs_rename(old_dir->d_inode, old_dentry,
62341 new_dir->d_inode, new_dentry,
62342 &delegated_inode);
62343+ if (!error)
62344+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
62345+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
62346 exit5:
62347 dput(new_dentry);
62348 exit4:
62349@@ -4279,6 +4470,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
62350
62351 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
62352 {
62353+ char tmpbuf[64];
62354+ const char *newlink;
62355 int len;
62356
62357 len = PTR_ERR(link);
62358@@ -4288,7 +4481,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
62359 len = strlen(link);
62360 if (len > (unsigned) buflen)
62361 len = buflen;
62362- if (copy_to_user(buffer, link, len))
62363+
62364+ if (len < sizeof(tmpbuf)) {
62365+ memcpy(tmpbuf, link, len);
62366+ newlink = tmpbuf;
62367+ } else
62368+ newlink = link;
62369+
62370+ if (copy_to_user(buffer, newlink, len))
62371 len = -EFAULT;
62372 out:
62373 return len;
62374diff --git a/fs/namespace.c b/fs/namespace.c
62375index 65233a5..82ac953 100644
62376--- a/fs/namespace.c
62377+++ b/fs/namespace.c
62378@@ -1339,6 +1339,9 @@ static int do_umount(struct mount *mnt, int flags)
62379 if (!(sb->s_flags & MS_RDONLY))
62380 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
62381 up_write(&sb->s_umount);
62382+
62383+ gr_log_remount(mnt->mnt_devname, retval);
62384+
62385 return retval;
62386 }
62387
62388@@ -1361,6 +1364,9 @@ static int do_umount(struct mount *mnt, int flags)
62389 }
62390 unlock_mount_hash();
62391 namespace_unlock();
62392+
62393+ gr_log_unmount(mnt->mnt_devname, retval);
62394+
62395 return retval;
62396 }
62397
62398@@ -1380,7 +1386,7 @@ static inline bool may_mount(void)
62399 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
62400 */
62401
62402-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
62403+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
62404 {
62405 struct path path;
62406 struct mount *mnt;
62407@@ -1422,7 +1428,7 @@ out:
62408 /*
62409 * The 2.0 compatible umount. No flags.
62410 */
62411-SYSCALL_DEFINE1(oldumount, char __user *, name)
62412+SYSCALL_DEFINE1(oldumount, const char __user *, name)
62413 {
62414 return sys_umount(name, 0);
62415 }
62416@@ -2431,6 +2437,16 @@ long do_mount(const char *dev_name, const char *dir_name,
62417 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
62418 MS_STRICTATIME);
62419
62420+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
62421+ retval = -EPERM;
62422+ goto dput_out;
62423+ }
62424+
62425+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
62426+ retval = -EPERM;
62427+ goto dput_out;
62428+ }
62429+
62430 if (flags & MS_REMOUNT)
62431 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
62432 data_page);
62433@@ -2445,6 +2461,9 @@ long do_mount(const char *dev_name, const char *dir_name,
62434 dev_name, data_page);
62435 dput_out:
62436 path_put(&path);
62437+
62438+ gr_log_mount(dev_name, dir_name, retval);
62439+
62440 return retval;
62441 }
62442
62443@@ -2462,7 +2481,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
62444 * number incrementing at 10Ghz will take 12,427 years to wrap which
62445 * is effectively never, so we can ignore the possibility.
62446 */
62447-static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
62448+static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
62449
62450 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62451 {
62452@@ -2477,7 +2496,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62453 kfree(new_ns);
62454 return ERR_PTR(ret);
62455 }
62456- new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
62457+ new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
62458 atomic_set(&new_ns->count, 1);
62459 new_ns->root = NULL;
62460 INIT_LIST_HEAD(&new_ns->list);
62461@@ -2487,7 +2506,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62462 return new_ns;
62463 }
62464
62465-struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
62466+__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
62467 struct user_namespace *user_ns, struct fs_struct *new_fs)
62468 {
62469 struct mnt_namespace *new_ns;
62470@@ -2608,8 +2627,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
62471 }
62472 EXPORT_SYMBOL(mount_subtree);
62473
62474-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
62475- char __user *, type, unsigned long, flags, void __user *, data)
62476+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
62477+ const char __user *, type, unsigned long, flags, void __user *, data)
62478 {
62479 int ret;
62480 char *kernel_type;
62481@@ -2722,6 +2741,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
62482 if (error)
62483 goto out2;
62484
62485+ if (gr_handle_chroot_pivot()) {
62486+ error = -EPERM;
62487+ goto out2;
62488+ }
62489+
62490 get_fs_root(current->fs, &root);
62491 old_mp = lock_mount(&old);
62492 error = PTR_ERR(old_mp);
62493@@ -2990,7 +3014,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
62494 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
62495 return -EPERM;
62496
62497- if (fs->users != 1)
62498+ if (atomic_read(&fs->users) != 1)
62499 return -EINVAL;
62500
62501 get_mnt_ns(mnt_ns);
62502diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
62503index f4ccfe6..a5cf064 100644
62504--- a/fs/nfs/callback_xdr.c
62505+++ b/fs/nfs/callback_xdr.c
62506@@ -51,7 +51,7 @@ struct callback_op {
62507 callback_decode_arg_t decode_args;
62508 callback_encode_res_t encode_res;
62509 long res_maxsize;
62510-};
62511+} __do_const;
62512
62513 static struct callback_op callback_ops[];
62514
62515diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
62516index 360114a..ac6e265 100644
62517--- a/fs/nfs/inode.c
62518+++ b/fs/nfs/inode.c
62519@@ -1189,16 +1189,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
62520 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
62521 }
62522
62523-static atomic_long_t nfs_attr_generation_counter;
62524+static atomic_long_unchecked_t nfs_attr_generation_counter;
62525
62526 static unsigned long nfs_read_attr_generation_counter(void)
62527 {
62528- return atomic_long_read(&nfs_attr_generation_counter);
62529+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
62530 }
62531
62532 unsigned long nfs_inc_attr_generation_counter(void)
62533 {
62534- return atomic_long_inc_return(&nfs_attr_generation_counter);
62535+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
62536 }
62537
62538 void nfs_fattr_init(struct nfs_fattr *fattr)
62539diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
62540index 9a914e8..e89c0ea 100644
62541--- a/fs/nfsd/nfs4proc.c
62542+++ b/fs/nfsd/nfs4proc.c
62543@@ -1178,7 +1178,7 @@ struct nfsd4_operation {
62544 nfsd4op_rsize op_rsize_bop;
62545 stateid_getter op_get_currentstateid;
62546 stateid_setter op_set_currentstateid;
62547-};
62548+} __do_const;
62549
62550 static struct nfsd4_operation nfsd4_ops[];
62551
62552diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
62553index 16e8fa7..b0803f6 100644
62554--- a/fs/nfsd/nfs4xdr.c
62555+++ b/fs/nfsd/nfs4xdr.c
62556@@ -1531,7 +1531,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
62557
62558 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
62559
62560-static nfsd4_dec nfsd4_dec_ops[] = {
62561+static const nfsd4_dec nfsd4_dec_ops[] = {
62562 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
62563 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
62564 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
62565diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
62566index f8f060f..c4ba09a 100644
62567--- a/fs/nfsd/nfscache.c
62568+++ b/fs/nfsd/nfscache.c
62569@@ -519,14 +519,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
62570 {
62571 struct svc_cacherep *rp = rqstp->rq_cacherep;
62572 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
62573- int len;
62574+ long len;
62575 size_t bufsize = 0;
62576
62577 if (!rp)
62578 return;
62579
62580- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
62581- len >>= 2;
62582+ if (statp) {
62583+ len = (char*)statp - (char*)resv->iov_base;
62584+ len = resv->iov_len - len;
62585+ len >>= 2;
62586+ }
62587
62588 /* Don't cache excessive amounts of data and XDR failures */
62589 if (!statp || len > (256 >> 2)) {
62590diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
62591index eea5ad1..5a84ac7 100644
62592--- a/fs/nfsd/vfs.c
62593+++ b/fs/nfsd/vfs.c
62594@@ -843,7 +843,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
62595 } else {
62596 oldfs = get_fs();
62597 set_fs(KERNEL_DS);
62598- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
62599+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
62600 set_fs(oldfs);
62601 }
62602
62603@@ -934,7 +934,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
62604
62605 /* Write the data. */
62606 oldfs = get_fs(); set_fs(KERNEL_DS);
62607- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
62608+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
62609 set_fs(oldfs);
62610 if (host_err < 0)
62611 goto out_nfserr;
62612@@ -1479,7 +1479,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
62613 */
62614
62615 oldfs = get_fs(); set_fs(KERNEL_DS);
62616- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
62617+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
62618 set_fs(oldfs);
62619
62620 if (host_err < 0)
62621diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
62622index 52ccd34..43a53b1 100644
62623--- a/fs/nls/nls_base.c
62624+++ b/fs/nls/nls_base.c
62625@@ -234,21 +234,25 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
62626
62627 int __register_nls(struct nls_table *nls, struct module *owner)
62628 {
62629- struct nls_table ** tmp = &tables;
62630+ struct nls_table *tmp = tables;
62631
62632 if (nls->next)
62633 return -EBUSY;
62634
62635- nls->owner = owner;
62636+ pax_open_kernel();
62637+ *(void **)&nls->owner = owner;
62638+ pax_close_kernel();
62639 spin_lock(&nls_lock);
62640- while (*tmp) {
62641- if (nls == *tmp) {
62642+ while (tmp) {
62643+ if (nls == tmp) {
62644 spin_unlock(&nls_lock);
62645 return -EBUSY;
62646 }
62647- tmp = &(*tmp)->next;
62648+ tmp = tmp->next;
62649 }
62650- nls->next = tables;
62651+ pax_open_kernel();
62652+ *(struct nls_table **)&nls->next = tables;
62653+ pax_close_kernel();
62654 tables = nls;
62655 spin_unlock(&nls_lock);
62656 return 0;
62657@@ -257,12 +261,14 @@ EXPORT_SYMBOL(__register_nls);
62658
62659 int unregister_nls(struct nls_table * nls)
62660 {
62661- struct nls_table ** tmp = &tables;
62662+ struct nls_table * const * tmp = &tables;
62663
62664 spin_lock(&nls_lock);
62665 while (*tmp) {
62666 if (nls == *tmp) {
62667- *tmp = nls->next;
62668+ pax_open_kernel();
62669+ *(struct nls_table **)tmp = nls->next;
62670+ pax_close_kernel();
62671 spin_unlock(&nls_lock);
62672 return 0;
62673 }
62674diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
62675index 162b3f1..6076a7c 100644
62676--- a/fs/nls/nls_euc-jp.c
62677+++ b/fs/nls/nls_euc-jp.c
62678@@ -560,8 +560,10 @@ static int __init init_nls_euc_jp(void)
62679 p_nls = load_nls("cp932");
62680
62681 if (p_nls) {
62682- table.charset2upper = p_nls->charset2upper;
62683- table.charset2lower = p_nls->charset2lower;
62684+ pax_open_kernel();
62685+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62686+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62687+ pax_close_kernel();
62688 return register_nls(&table);
62689 }
62690
62691diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
62692index a80a741..7b96e1b 100644
62693--- a/fs/nls/nls_koi8-ru.c
62694+++ b/fs/nls/nls_koi8-ru.c
62695@@ -62,8 +62,10 @@ static int __init init_nls_koi8_ru(void)
62696 p_nls = load_nls("koi8-u");
62697
62698 if (p_nls) {
62699- table.charset2upper = p_nls->charset2upper;
62700- table.charset2lower = p_nls->charset2lower;
62701+ pax_open_kernel();
62702+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62703+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62704+ pax_close_kernel();
62705 return register_nls(&table);
62706 }
62707
62708diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
62709index 287a22c..4e56e4e 100644
62710--- a/fs/notify/fanotify/fanotify_user.c
62711+++ b/fs/notify/fanotify/fanotify_user.c
62712@@ -251,8 +251,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
62713
62714 fd = fanotify_event_metadata.fd;
62715 ret = -EFAULT;
62716- if (copy_to_user(buf, &fanotify_event_metadata,
62717- fanotify_event_metadata.event_len))
62718+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
62719+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
62720 goto out_close_fd;
62721
62722 ret = prepare_for_access_response(group, event, fd);
62723@@ -742,6 +742,8 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags)
62724 oevent->path.mnt = NULL;
62725 oevent->path.dentry = NULL;
62726
62727+ if (force_o_largefile())
62728+ event_f_flags |= O_LARGEFILE;
62729 group->fanotify_data.f_flags = event_f_flags;
62730 #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
62731 oevent->response = 0;
62732diff --git a/fs/notify/notification.c b/fs/notify/notification.c
62733index 1e58402..bb2d6f4 100644
62734--- a/fs/notify/notification.c
62735+++ b/fs/notify/notification.c
62736@@ -48,7 +48,7 @@
62737 #include <linux/fsnotify_backend.h>
62738 #include "fsnotify.h"
62739
62740-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62741+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62742
62743 /**
62744 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
62745@@ -56,7 +56,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62746 */
62747 u32 fsnotify_get_cookie(void)
62748 {
62749- return atomic_inc_return(&fsnotify_sync_cookie);
62750+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
62751 }
62752 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
62753
62754diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
62755index 9e38daf..5727cae 100644
62756--- a/fs/ntfs/dir.c
62757+++ b/fs/ntfs/dir.c
62758@@ -1310,7 +1310,7 @@ find_next_index_buffer:
62759 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
62760 ~(s64)(ndir->itype.index.block_size - 1)));
62761 /* Bounds checks. */
62762- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62763+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62764 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
62765 "inode 0x%lx or driver bug.", vdir->i_ino);
62766 goto err_out;
62767diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
62768index db9bd8a..8338fb6 100644
62769--- a/fs/ntfs/file.c
62770+++ b/fs/ntfs/file.c
62771@@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
62772 char *addr;
62773 size_t total = 0;
62774 unsigned len;
62775- int left;
62776+ unsigned left;
62777
62778 do {
62779 len = PAGE_CACHE_SIZE - ofs;
62780diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
62781index 82650d5..db37dcf 100644
62782--- a/fs/ntfs/super.c
62783+++ b/fs/ntfs/super.c
62784@@ -685,7 +685,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62785 if (!silent)
62786 ntfs_error(sb, "Primary boot sector is invalid.");
62787 } else if (!silent)
62788- ntfs_error(sb, read_err_str, "primary");
62789+ ntfs_error(sb, read_err_str, "%s", "primary");
62790 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
62791 if (bh_primary)
62792 brelse(bh_primary);
62793@@ -701,7 +701,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62794 goto hotfix_primary_boot_sector;
62795 brelse(bh_backup);
62796 } else if (!silent)
62797- ntfs_error(sb, read_err_str, "backup");
62798+ ntfs_error(sb, read_err_str, "%s", "backup");
62799 /* Try to read NT3.51- backup boot sector. */
62800 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
62801 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
62802@@ -712,7 +712,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62803 "sector.");
62804 brelse(bh_backup);
62805 } else if (!silent)
62806- ntfs_error(sb, read_err_str, "backup");
62807+ ntfs_error(sb, read_err_str, "%s", "backup");
62808 /* We failed. Cleanup and return. */
62809 if (bh_primary)
62810 brelse(bh_primary);
62811diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
62812index 0440134..d52c93a 100644
62813--- a/fs/ocfs2/localalloc.c
62814+++ b/fs/ocfs2/localalloc.c
62815@@ -1320,7 +1320,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
62816 goto bail;
62817 }
62818
62819- atomic_inc(&osb->alloc_stats.moves);
62820+ atomic_inc_unchecked(&osb->alloc_stats.moves);
62821
62822 bail:
62823 if (handle)
62824diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
62825index 553f53c..aaf5133 100644
62826--- a/fs/ocfs2/ocfs2.h
62827+++ b/fs/ocfs2/ocfs2.h
62828@@ -235,11 +235,11 @@ enum ocfs2_vol_state
62829
62830 struct ocfs2_alloc_stats
62831 {
62832- atomic_t moves;
62833- atomic_t local_data;
62834- atomic_t bitmap_data;
62835- atomic_t bg_allocs;
62836- atomic_t bg_extends;
62837+ atomic_unchecked_t moves;
62838+ atomic_unchecked_t local_data;
62839+ atomic_unchecked_t bitmap_data;
62840+ atomic_unchecked_t bg_allocs;
62841+ atomic_unchecked_t bg_extends;
62842 };
62843
62844 enum ocfs2_local_alloc_state
62845diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
62846index 47ae266..6e8b793 100644
62847--- a/fs/ocfs2/suballoc.c
62848+++ b/fs/ocfs2/suballoc.c
62849@@ -866,7 +866,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
62850 mlog_errno(status);
62851 goto bail;
62852 }
62853- atomic_inc(&osb->alloc_stats.bg_extends);
62854+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
62855
62856 /* You should never ask for this much metadata */
62857 BUG_ON(bits_wanted >
62858@@ -1992,7 +1992,7 @@ int ocfs2_claim_metadata(handle_t *handle,
62859 mlog_errno(status);
62860 goto bail;
62861 }
62862- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62863+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62864
62865 *suballoc_loc = res.sr_bg_blkno;
62866 *suballoc_bit_start = res.sr_bit_offset;
62867@@ -2156,7 +2156,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
62868 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
62869 res->sr_bits);
62870
62871- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62872+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62873
62874 BUG_ON(res->sr_bits != 1);
62875
62876@@ -2198,7 +2198,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
62877 mlog_errno(status);
62878 goto bail;
62879 }
62880- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62881+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62882
62883 BUG_ON(res.sr_bits != 1);
62884
62885@@ -2302,7 +2302,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62886 cluster_start,
62887 num_clusters);
62888 if (!status)
62889- atomic_inc(&osb->alloc_stats.local_data);
62890+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
62891 } else {
62892 if (min_clusters > (osb->bitmap_cpg - 1)) {
62893 /* The only paths asking for contiguousness
62894@@ -2328,7 +2328,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62895 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
62896 res.sr_bg_blkno,
62897 res.sr_bit_offset);
62898- atomic_inc(&osb->alloc_stats.bitmap_data);
62899+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
62900 *num_clusters = res.sr_bits;
62901 }
62902 }
62903diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
62904index 49d84f8..4807e0b 100644
62905--- a/fs/ocfs2/super.c
62906+++ b/fs/ocfs2/super.c
62907@@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
62908 "%10s => GlobalAllocs: %d LocalAllocs: %d "
62909 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
62910 "Stats",
62911- atomic_read(&osb->alloc_stats.bitmap_data),
62912- atomic_read(&osb->alloc_stats.local_data),
62913- atomic_read(&osb->alloc_stats.bg_allocs),
62914- atomic_read(&osb->alloc_stats.moves),
62915- atomic_read(&osb->alloc_stats.bg_extends));
62916+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
62917+ atomic_read_unchecked(&osb->alloc_stats.local_data),
62918+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
62919+ atomic_read_unchecked(&osb->alloc_stats.moves),
62920+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
62921
62922 out += snprintf(buf + out, len - out,
62923 "%10s => State: %u Descriptor: %llu Size: %u bits "
62924@@ -2123,11 +2123,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
62925 spin_lock_init(&osb->osb_xattr_lock);
62926 ocfs2_init_steal_slots(osb);
62927
62928- atomic_set(&osb->alloc_stats.moves, 0);
62929- atomic_set(&osb->alloc_stats.local_data, 0);
62930- atomic_set(&osb->alloc_stats.bitmap_data, 0);
62931- atomic_set(&osb->alloc_stats.bg_allocs, 0);
62932- atomic_set(&osb->alloc_stats.bg_extends, 0);
62933+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
62934+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
62935+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
62936+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
62937+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
62938
62939 /* Copy the blockcheck stats from the superblock probe */
62940 osb->osb_ecc_stats = *stats;
62941diff --git a/fs/open.c b/fs/open.c
62942index b9ed8b2..0d5c7a0 100644
62943--- a/fs/open.c
62944+++ b/fs/open.c
62945@@ -32,6 +32,8 @@
62946 #include <linux/dnotify.h>
62947 #include <linux/compat.h>
62948
62949+#define CREATE_TRACE_POINTS
62950+#include <trace/events/fs.h>
62951 #include "internal.h"
62952
62953 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
62954@@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
62955 error = locks_verify_truncate(inode, NULL, length);
62956 if (!error)
62957 error = security_path_truncate(path);
62958+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
62959+ error = -EACCES;
62960 if (!error)
62961 error = do_truncate(path->dentry, length, 0, NULL);
62962
62963@@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
62964 error = locks_verify_truncate(inode, f.file, length);
62965 if (!error)
62966 error = security_path_truncate(&f.file->f_path);
62967+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
62968+ error = -EACCES;
62969 if (!error)
62970 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
62971 sb_end_write(inode->i_sb);
62972@@ -361,6 +367,9 @@ retry:
62973 if (__mnt_is_readonly(path.mnt))
62974 res = -EROFS;
62975
62976+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
62977+ res = -EACCES;
62978+
62979 out_path_release:
62980 path_put(&path);
62981 if (retry_estale(res, lookup_flags)) {
62982@@ -392,6 +401,8 @@ retry:
62983 if (error)
62984 goto dput_and_out;
62985
62986+ gr_log_chdir(path.dentry, path.mnt);
62987+
62988 set_fs_pwd(current->fs, &path);
62989
62990 dput_and_out:
62991@@ -421,6 +432,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
62992 goto out_putf;
62993
62994 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
62995+
62996+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
62997+ error = -EPERM;
62998+
62999+ if (!error)
63000+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
63001+
63002 if (!error)
63003 set_fs_pwd(current->fs, &f.file->f_path);
63004 out_putf:
63005@@ -450,7 +468,13 @@ retry:
63006 if (error)
63007 goto dput_and_out;
63008
63009+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
63010+ goto dput_and_out;
63011+
63012 set_fs_root(current->fs, &path);
63013+
63014+ gr_handle_chroot_chdir(&path);
63015+
63016 error = 0;
63017 dput_and_out:
63018 path_put(&path);
63019@@ -474,6 +498,16 @@ static int chmod_common(struct path *path, umode_t mode)
63020 return error;
63021 retry_deleg:
63022 mutex_lock(&inode->i_mutex);
63023+
63024+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
63025+ error = -EACCES;
63026+ goto out_unlock;
63027+ }
63028+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
63029+ error = -EACCES;
63030+ goto out_unlock;
63031+ }
63032+
63033 error = security_path_chmod(path, mode);
63034 if (error)
63035 goto out_unlock;
63036@@ -539,6 +573,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
63037 uid = make_kuid(current_user_ns(), user);
63038 gid = make_kgid(current_user_ns(), group);
63039
63040+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
63041+ return -EACCES;
63042+
63043 newattrs.ia_valid = ATTR_CTIME;
63044 if (user != (uid_t) -1) {
63045 if (!uid_valid(uid))
63046@@ -994,6 +1031,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
63047 } else {
63048 fsnotify_open(f);
63049 fd_install(fd, f);
63050+ trace_do_sys_open(tmp->name, flags, mode);
63051 }
63052 }
63053 putname(tmp);
63054diff --git a/fs/pipe.c b/fs/pipe.c
63055index 78fd0d0..f71fc09 100644
63056--- a/fs/pipe.c
63057+++ b/fs/pipe.c
63058@@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
63059
63060 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
63061 {
63062- if (pipe->files)
63063+ if (atomic_read(&pipe->files))
63064 mutex_lock_nested(&pipe->mutex, subclass);
63065 }
63066
63067@@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
63068
63069 void pipe_unlock(struct pipe_inode_info *pipe)
63070 {
63071- if (pipe->files)
63072+ if (atomic_read(&pipe->files))
63073 mutex_unlock(&pipe->mutex);
63074 }
63075 EXPORT_SYMBOL(pipe_unlock);
63076@@ -449,9 +449,9 @@ redo:
63077 }
63078 if (bufs) /* More to do? */
63079 continue;
63080- if (!pipe->writers)
63081+ if (!atomic_read(&pipe->writers))
63082 break;
63083- if (!pipe->waiting_writers) {
63084+ if (!atomic_read(&pipe->waiting_writers)) {
63085 /* syscall merging: Usually we must not sleep
63086 * if O_NONBLOCK is set, or if we got some data.
63087 * But if a writer sleeps in kernel space, then
63088@@ -513,7 +513,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
63089 ret = 0;
63090 __pipe_lock(pipe);
63091
63092- if (!pipe->readers) {
63093+ if (!atomic_read(&pipe->readers)) {
63094 send_sig(SIGPIPE, current, 0);
63095 ret = -EPIPE;
63096 goto out;
63097@@ -562,7 +562,7 @@ redo1:
63098 for (;;) {
63099 int bufs;
63100
63101- if (!pipe->readers) {
63102+ if (!atomic_read(&pipe->readers)) {
63103 send_sig(SIGPIPE, current, 0);
63104 if (!ret)
63105 ret = -EPIPE;
63106@@ -653,9 +653,9 @@ redo2:
63107 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
63108 do_wakeup = 0;
63109 }
63110- pipe->waiting_writers++;
63111+ atomic_inc(&pipe->waiting_writers);
63112 pipe_wait(pipe);
63113- pipe->waiting_writers--;
63114+ atomic_dec(&pipe->waiting_writers);
63115 }
63116 out:
63117 __pipe_unlock(pipe);
63118@@ -710,7 +710,7 @@ pipe_poll(struct file *filp, poll_table *wait)
63119 mask = 0;
63120 if (filp->f_mode & FMODE_READ) {
63121 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
63122- if (!pipe->writers && filp->f_version != pipe->w_counter)
63123+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
63124 mask |= POLLHUP;
63125 }
63126
63127@@ -720,7 +720,7 @@ pipe_poll(struct file *filp, poll_table *wait)
63128 * Most Unices do not set POLLERR for FIFOs but on Linux they
63129 * behave exactly like pipes for poll().
63130 */
63131- if (!pipe->readers)
63132+ if (!atomic_read(&pipe->readers))
63133 mask |= POLLERR;
63134 }
63135
63136@@ -732,7 +732,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
63137 int kill = 0;
63138
63139 spin_lock(&inode->i_lock);
63140- if (!--pipe->files) {
63141+ if (atomic_dec_and_test(&pipe->files)) {
63142 inode->i_pipe = NULL;
63143 kill = 1;
63144 }
63145@@ -749,11 +749,11 @@ pipe_release(struct inode *inode, struct file *file)
63146
63147 __pipe_lock(pipe);
63148 if (file->f_mode & FMODE_READ)
63149- pipe->readers--;
63150+ atomic_dec(&pipe->readers);
63151 if (file->f_mode & FMODE_WRITE)
63152- pipe->writers--;
63153+ atomic_dec(&pipe->writers);
63154
63155- if (pipe->readers || pipe->writers) {
63156+ if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
63157 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
63158 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
63159 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
63160@@ -818,7 +818,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
63161 kfree(pipe);
63162 }
63163
63164-static struct vfsmount *pipe_mnt __read_mostly;
63165+struct vfsmount *pipe_mnt __read_mostly;
63166
63167 /*
63168 * pipefs_dname() is called from d_path().
63169@@ -848,8 +848,9 @@ static struct inode * get_pipe_inode(void)
63170 goto fail_iput;
63171
63172 inode->i_pipe = pipe;
63173- pipe->files = 2;
63174- pipe->readers = pipe->writers = 1;
63175+ atomic_set(&pipe->files, 2);
63176+ atomic_set(&pipe->readers, 1);
63177+ atomic_set(&pipe->writers, 1);
63178 inode->i_fop = &pipefifo_fops;
63179
63180 /*
63181@@ -1028,17 +1029,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
63182 spin_lock(&inode->i_lock);
63183 if (inode->i_pipe) {
63184 pipe = inode->i_pipe;
63185- pipe->files++;
63186+ atomic_inc(&pipe->files);
63187 spin_unlock(&inode->i_lock);
63188 } else {
63189 spin_unlock(&inode->i_lock);
63190 pipe = alloc_pipe_info();
63191 if (!pipe)
63192 return -ENOMEM;
63193- pipe->files = 1;
63194+ atomic_set(&pipe->files, 1);
63195 spin_lock(&inode->i_lock);
63196 if (unlikely(inode->i_pipe)) {
63197- inode->i_pipe->files++;
63198+ atomic_inc(&inode->i_pipe->files);
63199 spin_unlock(&inode->i_lock);
63200 free_pipe_info(pipe);
63201 pipe = inode->i_pipe;
63202@@ -1063,10 +1064,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
63203 * opened, even when there is no process writing the FIFO.
63204 */
63205 pipe->r_counter++;
63206- if (pipe->readers++ == 0)
63207+ if (atomic_inc_return(&pipe->readers) == 1)
63208 wake_up_partner(pipe);
63209
63210- if (!is_pipe && !pipe->writers) {
63211+ if (!is_pipe && !atomic_read(&pipe->writers)) {
63212 if ((filp->f_flags & O_NONBLOCK)) {
63213 /* suppress POLLHUP until we have
63214 * seen a writer */
63215@@ -1085,14 +1086,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
63216 * errno=ENXIO when there is no process reading the FIFO.
63217 */
63218 ret = -ENXIO;
63219- if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
63220+ if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
63221 goto err;
63222
63223 pipe->w_counter++;
63224- if (!pipe->writers++)
63225+ if (atomic_inc_return(&pipe->writers) == 1)
63226 wake_up_partner(pipe);
63227
63228- if (!is_pipe && !pipe->readers) {
63229+ if (!is_pipe && !atomic_read(&pipe->readers)) {
63230 if (wait_for_partner(pipe, &pipe->r_counter))
63231 goto err_wr;
63232 }
63233@@ -1106,11 +1107,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
63234 * the process can at least talk to itself.
63235 */
63236
63237- pipe->readers++;
63238- pipe->writers++;
63239+ atomic_inc(&pipe->readers);
63240+ atomic_inc(&pipe->writers);
63241 pipe->r_counter++;
63242 pipe->w_counter++;
63243- if (pipe->readers == 1 || pipe->writers == 1)
63244+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
63245 wake_up_partner(pipe);
63246 break;
63247
63248@@ -1124,13 +1125,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
63249 return 0;
63250
63251 err_rd:
63252- if (!--pipe->readers)
63253+ if (atomic_dec_and_test(&pipe->readers))
63254 wake_up_interruptible(&pipe->wait);
63255 ret = -ERESTARTSYS;
63256 goto err;
63257
63258 err_wr:
63259- if (!--pipe->writers)
63260+ if (atomic_dec_and_test(&pipe->writers))
63261 wake_up_interruptible(&pipe->wait);
63262 ret = -ERESTARTSYS;
63263 goto err;
63264diff --git a/fs/posix_acl.c b/fs/posix_acl.c
63265index 9e363e4..d936d15 100644
63266--- a/fs/posix_acl.c
63267+++ b/fs/posix_acl.c
63268@@ -20,6 +20,7 @@
63269 #include <linux/xattr.h>
63270 #include <linux/export.h>
63271 #include <linux/user_namespace.h>
63272+#include <linux/grsecurity.h>
63273
63274 struct posix_acl **acl_by_type(struct inode *inode, int type)
63275 {
63276@@ -271,7 +272,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
63277 }
63278 }
63279 if (mode_p)
63280- *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
63281+ *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
63282 return not_equiv;
63283 }
63284 EXPORT_SYMBOL(posix_acl_equiv_mode);
63285@@ -421,7 +422,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
63286 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
63287 }
63288
63289- *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
63290+ *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
63291 return not_equiv;
63292 }
63293
63294@@ -479,6 +480,8 @@ __posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
63295 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
63296 int err = -ENOMEM;
63297 if (clone) {
63298+ *mode_p &= ~gr_acl_umask();
63299+
63300 err = posix_acl_create_masq(clone, mode_p);
63301 if (err < 0) {
63302 posix_acl_release(clone);
63303@@ -653,11 +656,12 @@ struct posix_acl *
63304 posix_acl_from_xattr(struct user_namespace *user_ns,
63305 const void *value, size_t size)
63306 {
63307- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
63308- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
63309+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
63310+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
63311 int count;
63312 struct posix_acl *acl;
63313 struct posix_acl_entry *acl_e;
63314+ umode_t umask = gr_acl_umask();
63315
63316 if (!value)
63317 return NULL;
63318@@ -683,12 +687,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
63319
63320 switch(acl_e->e_tag) {
63321 case ACL_USER_OBJ:
63322+ acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
63323+ break;
63324 case ACL_GROUP_OBJ:
63325 case ACL_MASK:
63326+ acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
63327+ break;
63328 case ACL_OTHER:
63329+ acl_e->e_perm &= ~(umask & S_IRWXO);
63330 break;
63331
63332 case ACL_USER:
63333+ acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
63334 acl_e->e_uid =
63335 make_kuid(user_ns,
63336 le32_to_cpu(entry->e_id));
63337@@ -696,6 +706,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
63338 goto fail;
63339 break;
63340 case ACL_GROUP:
63341+ acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
63342 acl_e->e_gid =
63343 make_kgid(user_ns,
63344 le32_to_cpu(entry->e_id));
63345diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
63346index 2183fcf..3c32a98 100644
63347--- a/fs/proc/Kconfig
63348+++ b/fs/proc/Kconfig
63349@@ -30,7 +30,7 @@ config PROC_FS
63350
63351 config PROC_KCORE
63352 bool "/proc/kcore support" if !ARM
63353- depends on PROC_FS && MMU
63354+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
63355 help
63356 Provides a virtual ELF core file of the live kernel. This can
63357 be read with gdb and other ELF tools. No modifications can be
63358@@ -38,8 +38,8 @@ config PROC_KCORE
63359
63360 config PROC_VMCORE
63361 bool "/proc/vmcore support"
63362- depends on PROC_FS && CRASH_DUMP
63363- default y
63364+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
63365+ default n
63366 help
63367 Exports the dump image of crashed kernel in ELF format.
63368
63369@@ -63,8 +63,8 @@ config PROC_SYSCTL
63370 limited in memory.
63371
63372 config PROC_PAGE_MONITOR
63373- default y
63374- depends on PROC_FS && MMU
63375+ default n
63376+ depends on PROC_FS && MMU && !GRKERNSEC
63377 bool "Enable /proc page monitoring" if EXPERT
63378 help
63379 Various /proc files exist to monitor process memory utilization:
63380diff --git a/fs/proc/array.c b/fs/proc/array.c
63381index 656e401..b5b86b9 100644
63382--- a/fs/proc/array.c
63383+++ b/fs/proc/array.c
63384@@ -60,6 +60,7 @@
63385 #include <linux/tty.h>
63386 #include <linux/string.h>
63387 #include <linux/mman.h>
63388+#include <linux/grsecurity.h>
63389 #include <linux/proc_fs.h>
63390 #include <linux/ioport.h>
63391 #include <linux/uaccess.h>
63392@@ -356,6 +357,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
63393 seq_putc(m, '\n');
63394 }
63395
63396+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63397+static inline void task_pax(struct seq_file *m, struct task_struct *p)
63398+{
63399+ if (p->mm)
63400+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
63401+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
63402+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
63403+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
63404+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
63405+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
63406+ else
63407+ seq_printf(m, "PaX:\t-----\n");
63408+}
63409+#endif
63410+
63411 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
63412 struct pid *pid, struct task_struct *task)
63413 {
63414@@ -374,9 +390,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
63415 task_cpus_allowed(m, task);
63416 cpuset_task_status_allowed(m, task);
63417 task_context_switch_counts(m, task);
63418+
63419+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63420+ task_pax(m, task);
63421+#endif
63422+
63423+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
63424+ task_grsec_rbac(m, task);
63425+#endif
63426+
63427 return 0;
63428 }
63429
63430+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63431+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63432+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
63433+ _mm->pax_flags & MF_PAX_SEGMEXEC))
63434+#endif
63435+
63436 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63437 struct pid *pid, struct task_struct *task, int whole)
63438 {
63439@@ -398,6 +429,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63440 char tcomm[sizeof(task->comm)];
63441 unsigned long flags;
63442
63443+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63444+ if (current->exec_id != m->exec_id) {
63445+ gr_log_badprocpid("stat");
63446+ return 0;
63447+ }
63448+#endif
63449+
63450 state = *get_task_state(task);
63451 vsize = eip = esp = 0;
63452 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
63453@@ -468,6 +506,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63454 gtime = task_gtime(task);
63455 }
63456
63457+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63458+ if (PAX_RAND_FLAGS(mm)) {
63459+ eip = 0;
63460+ esp = 0;
63461+ wchan = 0;
63462+ }
63463+#endif
63464+#ifdef CONFIG_GRKERNSEC_HIDESYM
63465+ wchan = 0;
63466+ eip =0;
63467+ esp =0;
63468+#endif
63469+
63470 /* scale priority and nice values from timeslices to -20..20 */
63471 /* to make it look like a "normal" Unix priority/nice value */
63472 priority = task_prio(task);
63473@@ -504,9 +555,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63474 seq_put_decimal_ull(m, ' ', vsize);
63475 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
63476 seq_put_decimal_ull(m, ' ', rsslim);
63477+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63478+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
63479+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
63480+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
63481+#else
63482 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
63483 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
63484 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
63485+#endif
63486 seq_put_decimal_ull(m, ' ', esp);
63487 seq_put_decimal_ull(m, ' ', eip);
63488 /* The signal information here is obsolete.
63489@@ -528,7 +585,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63490 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
63491 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
63492
63493- if (mm && permitted) {
63494+ if (mm && permitted
63495+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63496+ && !PAX_RAND_FLAGS(mm)
63497+#endif
63498+ ) {
63499 seq_put_decimal_ull(m, ' ', mm->start_data);
63500 seq_put_decimal_ull(m, ' ', mm->end_data);
63501 seq_put_decimal_ull(m, ' ', mm->start_brk);
63502@@ -566,8 +627,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
63503 struct pid *pid, struct task_struct *task)
63504 {
63505 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
63506- struct mm_struct *mm = get_task_mm(task);
63507+ struct mm_struct *mm;
63508
63509+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63510+ if (current->exec_id != m->exec_id) {
63511+ gr_log_badprocpid("statm");
63512+ return 0;
63513+ }
63514+#endif
63515+ mm = get_task_mm(task);
63516 if (mm) {
63517 size = task_statm(mm, &shared, &text, &data, &resident);
63518 mmput(mm);
63519@@ -590,6 +658,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
63520 return 0;
63521 }
63522
63523+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63524+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
63525+{
63526+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
63527+}
63528+#endif
63529+
63530 #ifdef CONFIG_CHECKPOINT_RESTORE
63531 static struct pid *
63532 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
63533diff --git a/fs/proc/base.c b/fs/proc/base.c
63534index b976062..584d0bc 100644
63535--- a/fs/proc/base.c
63536+++ b/fs/proc/base.c
63537@@ -113,6 +113,14 @@ struct pid_entry {
63538 union proc_op op;
63539 };
63540
63541+struct getdents_callback {
63542+ struct linux_dirent __user * current_dir;
63543+ struct linux_dirent __user * previous;
63544+ struct file * file;
63545+ int count;
63546+ int error;
63547+};
63548+
63549 #define NOD(NAME, MODE, IOP, FOP, OP) { \
63550 .name = (NAME), \
63551 .len = sizeof(NAME) - 1, \
63552@@ -210,6 +218,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
63553 if (!mm->arg_end)
63554 goto out_mm; /* Shh! No looking before we're done */
63555
63556+ if (gr_acl_handle_procpidmem(task))
63557+ goto out_mm;
63558+
63559 len = mm->arg_end - mm->arg_start;
63560
63561 if (len > PAGE_SIZE)
63562@@ -237,12 +248,28 @@ out:
63563 return res;
63564 }
63565
63566+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63567+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63568+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
63569+ _mm->pax_flags & MF_PAX_SEGMEXEC))
63570+#endif
63571+
63572 static int proc_pid_auxv(struct task_struct *task, char *buffer)
63573 {
63574 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
63575 int res = PTR_ERR(mm);
63576 if (mm && !IS_ERR(mm)) {
63577 unsigned int nwords = 0;
63578+
63579+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63580+ /* allow if we're currently ptracing this task */
63581+ if (PAX_RAND_FLAGS(mm) &&
63582+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
63583+ mmput(mm);
63584+ return 0;
63585+ }
63586+#endif
63587+
63588 do {
63589 nwords += 2;
63590 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
63591@@ -256,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
63592 }
63593
63594
63595-#ifdef CONFIG_KALLSYMS
63596+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63597 /*
63598 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
63599 * Returns the resolved symbol. If that fails, simply return the address.
63600@@ -295,7 +322,7 @@ static void unlock_trace(struct task_struct *task)
63601 mutex_unlock(&task->signal->cred_guard_mutex);
63602 }
63603
63604-#ifdef CONFIG_STACKTRACE
63605+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63606
63607 #define MAX_STACK_TRACE_DEPTH 64
63608
63609@@ -518,7 +545,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
63610 return count;
63611 }
63612
63613-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63614+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63615 static int proc_pid_syscall(struct task_struct *task, char *buffer)
63616 {
63617 long nr;
63618@@ -547,7 +574,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
63619 /************************************************************************/
63620
63621 /* permission checks */
63622-static int proc_fd_access_allowed(struct inode *inode)
63623+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
63624 {
63625 struct task_struct *task;
63626 int allowed = 0;
63627@@ -557,7 +584,10 @@ static int proc_fd_access_allowed(struct inode *inode)
63628 */
63629 task = get_proc_task(inode);
63630 if (task) {
63631- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
63632+ if (log)
63633+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
63634+ else
63635+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
63636 put_task_struct(task);
63637 }
63638 return allowed;
63639@@ -588,10 +618,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
63640 struct task_struct *task,
63641 int hide_pid_min)
63642 {
63643+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63644+ return false;
63645+
63646+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63647+ rcu_read_lock();
63648+ {
63649+ const struct cred *tmpcred = current_cred();
63650+ const struct cred *cred = __task_cred(task);
63651+
63652+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
63653+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63654+ || in_group_p(grsec_proc_gid)
63655+#endif
63656+ ) {
63657+ rcu_read_unlock();
63658+ return true;
63659+ }
63660+ }
63661+ rcu_read_unlock();
63662+
63663+ if (!pid->hide_pid)
63664+ return false;
63665+#endif
63666+
63667 if (pid->hide_pid < hide_pid_min)
63668 return true;
63669 if (in_group_p(pid->pid_gid))
63670 return true;
63671+
63672 return ptrace_may_access(task, PTRACE_MODE_READ);
63673 }
63674
63675@@ -609,7 +664,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
63676 put_task_struct(task);
63677
63678 if (!has_perms) {
63679+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63680+ {
63681+#else
63682 if (pid->hide_pid == 2) {
63683+#endif
63684 /*
63685 * Let's make getdents(), stat(), and open()
63686 * consistent with each other. If a process
63687@@ -707,6 +766,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
63688 if (!task)
63689 return -ESRCH;
63690
63691+ if (gr_acl_handle_procpidmem(task)) {
63692+ put_task_struct(task);
63693+ return -EPERM;
63694+ }
63695+
63696 mm = mm_access(task, mode);
63697 put_task_struct(task);
63698
63699@@ -722,6 +786,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
63700
63701 file->private_data = mm;
63702
63703+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63704+ file->f_version = current->exec_id;
63705+#endif
63706+
63707 return 0;
63708 }
63709
63710@@ -743,6 +811,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63711 ssize_t copied;
63712 char *page;
63713
63714+#ifdef CONFIG_GRKERNSEC
63715+ if (write)
63716+ return -EPERM;
63717+#endif
63718+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63719+ if (file->f_version != current->exec_id) {
63720+ gr_log_badprocpid("mem");
63721+ return 0;
63722+ }
63723+#endif
63724+
63725 if (!mm)
63726 return 0;
63727
63728@@ -755,7 +834,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63729 goto free;
63730
63731 while (count > 0) {
63732- int this_len = min_t(int, count, PAGE_SIZE);
63733+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
63734
63735 if (write && copy_from_user(page, buf, this_len)) {
63736 copied = -EFAULT;
63737@@ -847,6 +926,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63738 if (!mm)
63739 return 0;
63740
63741+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63742+ if (file->f_version != current->exec_id) {
63743+ gr_log_badprocpid("environ");
63744+ return 0;
63745+ }
63746+#endif
63747+
63748 page = (char *)__get_free_page(GFP_TEMPORARY);
63749 if (!page)
63750 return -ENOMEM;
63751@@ -856,7 +942,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63752 goto free;
63753 while (count > 0) {
63754 size_t this_len, max_len;
63755- int retval;
63756+ ssize_t retval;
63757
63758 if (src >= (mm->env_end - mm->env_start))
63759 break;
63760@@ -1467,7 +1553,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
63761 int error = -EACCES;
63762
63763 /* Are we allowed to snoop on the tasks file descriptors? */
63764- if (!proc_fd_access_allowed(inode))
63765+ if (!proc_fd_access_allowed(inode, 0))
63766 goto out;
63767
63768 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63769@@ -1511,8 +1597,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
63770 struct path path;
63771
63772 /* Are we allowed to snoop on the tasks file descriptors? */
63773- if (!proc_fd_access_allowed(inode))
63774- goto out;
63775+ /* logging this is needed for learning on chromium to work properly,
63776+ but we don't want to flood the logs from 'ps' which does a readlink
63777+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
63778+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
63779+ */
63780+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
63781+ if (!proc_fd_access_allowed(inode,0))
63782+ goto out;
63783+ } else {
63784+ if (!proc_fd_access_allowed(inode,1))
63785+ goto out;
63786+ }
63787
63788 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63789 if (error)
63790@@ -1562,7 +1658,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
63791 rcu_read_lock();
63792 cred = __task_cred(task);
63793 inode->i_uid = cred->euid;
63794+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63795+ inode->i_gid = grsec_proc_gid;
63796+#else
63797 inode->i_gid = cred->egid;
63798+#endif
63799 rcu_read_unlock();
63800 }
63801 security_task_to_inode(task, inode);
63802@@ -1598,10 +1698,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
63803 return -ENOENT;
63804 }
63805 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63806+#ifdef CONFIG_GRKERNSEC_PROC_USER
63807+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63808+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63809+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63810+#endif
63811 task_dumpable(task)) {
63812 cred = __task_cred(task);
63813 stat->uid = cred->euid;
63814+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63815+ stat->gid = grsec_proc_gid;
63816+#else
63817 stat->gid = cred->egid;
63818+#endif
63819 }
63820 }
63821 rcu_read_unlock();
63822@@ -1639,11 +1748,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
63823
63824 if (task) {
63825 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63826+#ifdef CONFIG_GRKERNSEC_PROC_USER
63827+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63828+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63829+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63830+#endif
63831 task_dumpable(task)) {
63832 rcu_read_lock();
63833 cred = __task_cred(task);
63834 inode->i_uid = cred->euid;
63835+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63836+ inode->i_gid = grsec_proc_gid;
63837+#else
63838 inode->i_gid = cred->egid;
63839+#endif
63840 rcu_read_unlock();
63841 } else {
63842 inode->i_uid = GLOBAL_ROOT_UID;
63843@@ -2178,6 +2296,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
63844 if (!task)
63845 goto out_no_task;
63846
63847+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63848+ goto out;
63849+
63850 /*
63851 * Yes, it does not scale. And it should not. Don't add
63852 * new entries into /proc/<tgid>/ without very good reasons.
63853@@ -2208,6 +2329,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
63854 if (!task)
63855 return -ENOENT;
63856
63857+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63858+ goto out;
63859+
63860 if (!dir_emit_dots(file, ctx))
63861 goto out;
63862
63863@@ -2597,7 +2721,7 @@ static const struct pid_entry tgid_base_stuff[] = {
63864 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
63865 #endif
63866 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63867-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63868+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63869 INF("syscall", S_IRUGO, proc_pid_syscall),
63870 #endif
63871 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63872@@ -2622,10 +2746,10 @@ static const struct pid_entry tgid_base_stuff[] = {
63873 #ifdef CONFIG_SECURITY
63874 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63875 #endif
63876-#ifdef CONFIG_KALLSYMS
63877+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63878 INF("wchan", S_IRUGO, proc_pid_wchan),
63879 #endif
63880-#ifdef CONFIG_STACKTRACE
63881+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63882 ONE("stack", S_IRUGO, proc_pid_stack),
63883 #endif
63884 #ifdef CONFIG_SCHEDSTATS
63885@@ -2659,6 +2783,9 @@ static const struct pid_entry tgid_base_stuff[] = {
63886 #ifdef CONFIG_HARDWALL
63887 INF("hardwall", S_IRUGO, proc_pid_hardwall),
63888 #endif
63889+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63890+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
63891+#endif
63892 #ifdef CONFIG_USER_NS
63893 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
63894 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
63895@@ -2789,7 +2916,14 @@ static int proc_pid_instantiate(struct inode *dir,
63896 if (!inode)
63897 goto out;
63898
63899+#ifdef CONFIG_GRKERNSEC_PROC_USER
63900+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
63901+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63902+ inode->i_gid = grsec_proc_gid;
63903+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
63904+#else
63905 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
63906+#endif
63907 inode->i_op = &proc_tgid_base_inode_operations;
63908 inode->i_fop = &proc_tgid_base_operations;
63909 inode->i_flags|=S_IMMUTABLE;
63910@@ -2827,7 +2961,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
63911 if (!task)
63912 goto out;
63913
63914+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63915+ goto out_put_task;
63916+
63917 result = proc_pid_instantiate(dir, dentry, task, NULL);
63918+out_put_task:
63919 put_task_struct(task);
63920 out:
63921 return ERR_PTR(result);
63922@@ -2933,7 +3071,7 @@ static const struct pid_entry tid_base_stuff[] = {
63923 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
63924 #endif
63925 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63926-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63927+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63928 INF("syscall", S_IRUGO, proc_pid_syscall),
63929 #endif
63930 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63931@@ -2960,10 +3098,10 @@ static const struct pid_entry tid_base_stuff[] = {
63932 #ifdef CONFIG_SECURITY
63933 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63934 #endif
63935-#ifdef CONFIG_KALLSYMS
63936+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63937 INF("wchan", S_IRUGO, proc_pid_wchan),
63938 #endif
63939-#ifdef CONFIG_STACKTRACE
63940+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63941 ONE("stack", S_IRUGO, proc_pid_stack),
63942 #endif
63943 #ifdef CONFIG_SCHEDSTATS
63944diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
63945index cbd82df..c0407d2 100644
63946--- a/fs/proc/cmdline.c
63947+++ b/fs/proc/cmdline.c
63948@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
63949
63950 static int __init proc_cmdline_init(void)
63951 {
63952+#ifdef CONFIG_GRKERNSEC_PROC_ADD
63953+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
63954+#else
63955 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
63956+#endif
63957 return 0;
63958 }
63959 fs_initcall(proc_cmdline_init);
63960diff --git a/fs/proc/devices.c b/fs/proc/devices.c
63961index 50493ed..248166b 100644
63962--- a/fs/proc/devices.c
63963+++ b/fs/proc/devices.c
63964@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
63965
63966 static int __init proc_devices_init(void)
63967 {
63968+#ifdef CONFIG_GRKERNSEC_PROC_ADD
63969+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
63970+#else
63971 proc_create("devices", 0, NULL, &proc_devinfo_operations);
63972+#endif
63973 return 0;
63974 }
63975 fs_initcall(proc_devices_init);
63976diff --git a/fs/proc/fd.c b/fs/proc/fd.c
63977index 985ea88..d118a0a 100644
63978--- a/fs/proc/fd.c
63979+++ b/fs/proc/fd.c
63980@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
63981 if (!task)
63982 return -ENOENT;
63983
63984- files = get_files_struct(task);
63985+ if (!gr_acl_handle_procpidmem(task))
63986+ files = get_files_struct(task);
63987 put_task_struct(task);
63988
63989 if (files) {
63990@@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
63991 */
63992 int proc_fd_permission(struct inode *inode, int mask)
63993 {
63994+ struct task_struct *task;
63995 int rv = generic_permission(inode, mask);
63996- if (rv == 0)
63997- return 0;
63998+
63999 if (task_tgid(current) == proc_pid(inode))
64000 rv = 0;
64001+
64002+ task = get_proc_task(inode);
64003+ if (task == NULL)
64004+ return rv;
64005+
64006+ if (gr_acl_handle_procpidmem(task))
64007+ rv = -EACCES;
64008+
64009+ put_task_struct(task);
64010+
64011 return rv;
64012 }
64013
64014diff --git a/fs/proc/generic.c b/fs/proc/generic.c
64015index b7f268e..3bea6b7 100644
64016--- a/fs/proc/generic.c
64017+++ b/fs/proc/generic.c
64018@@ -23,6 +23,7 @@
64019 #include <linux/bitops.h>
64020 #include <linux/spinlock.h>
64021 #include <linux/completion.h>
64022+#include <linux/grsecurity.h>
64023 #include <asm/uaccess.h>
64024
64025 #include "internal.h"
64026@@ -207,6 +208,15 @@ struct dentry *proc_lookup(struct inode *dir, struct dentry *dentry,
64027 return proc_lookup_de(PDE(dir), dir, dentry);
64028 }
64029
64030+struct dentry *proc_lookup_restrict(struct inode *dir, struct dentry *dentry,
64031+ unsigned int flags)
64032+{
64033+ if (gr_proc_is_restricted())
64034+ return ERR_PTR(-EACCES);
64035+
64036+ return proc_lookup_de(PDE(dir), dir, dentry);
64037+}
64038+
64039 /*
64040 * This returns non-zero if at EOF, so that the /proc
64041 * root directory can use this and check if it should
64042@@ -264,6 +274,16 @@ int proc_readdir(struct file *file, struct dir_context *ctx)
64043 return proc_readdir_de(PDE(inode), file, ctx);
64044 }
64045
64046+int proc_readdir_restrict(struct file *file, struct dir_context *ctx)
64047+{
64048+ struct inode *inode = file_inode(file);
64049+
64050+ if (gr_proc_is_restricted())
64051+ return -EACCES;
64052+
64053+ return proc_readdir_de(PDE(inode), file, ctx);
64054+}
64055+
64056 /*
64057 * These are the generic /proc directory operations. They
64058 * use the in-memory "struct proc_dir_entry" tree to parse
64059@@ -275,6 +295,12 @@ static const struct file_operations proc_dir_operations = {
64060 .iterate = proc_readdir,
64061 };
64062
64063+static const struct file_operations proc_dir_restricted_operations = {
64064+ .llseek = generic_file_llseek,
64065+ .read = generic_read_dir,
64066+ .iterate = proc_readdir_restrict,
64067+};
64068+
64069 /*
64070 * proc directories can do almost nothing..
64071 */
64072@@ -284,6 +310,12 @@ static const struct inode_operations proc_dir_inode_operations = {
64073 .setattr = proc_notify_change,
64074 };
64075
64076+static const struct inode_operations proc_dir_restricted_inode_operations = {
64077+ .lookup = proc_lookup_restrict,
64078+ .getattr = proc_getattr,
64079+ .setattr = proc_notify_change,
64080+};
64081+
64082 static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
64083 {
64084 struct proc_dir_entry *tmp;
64085@@ -294,8 +326,13 @@ static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
64086 return ret;
64087
64088 if (S_ISDIR(dp->mode)) {
64089- dp->proc_fops = &proc_dir_operations;
64090- dp->proc_iops = &proc_dir_inode_operations;
64091+ if (dp->restricted) {
64092+ dp->proc_fops = &proc_dir_restricted_operations;
64093+ dp->proc_iops = &proc_dir_restricted_inode_operations;
64094+ } else {
64095+ dp->proc_fops = &proc_dir_operations;
64096+ dp->proc_iops = &proc_dir_inode_operations;
64097+ }
64098 dir->nlink++;
64099 } else if (S_ISLNK(dp->mode)) {
64100 dp->proc_iops = &proc_link_inode_operations;
64101@@ -407,6 +444,27 @@ struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
64102 }
64103 EXPORT_SYMBOL_GPL(proc_mkdir_data);
64104
64105+struct proc_dir_entry *proc_mkdir_data_restrict(const char *name, umode_t mode,
64106+ struct proc_dir_entry *parent, void *data)
64107+{
64108+ struct proc_dir_entry *ent;
64109+
64110+ if (mode == 0)
64111+ mode = S_IRUGO | S_IXUGO;
64112+
64113+ ent = __proc_create(&parent, name, S_IFDIR | mode, 2);
64114+ if (ent) {
64115+ ent->data = data;
64116+ ent->restricted = 1;
64117+ if (proc_register(parent, ent) < 0) {
64118+ kfree(ent);
64119+ ent = NULL;
64120+ }
64121+ }
64122+ return ent;
64123+}
64124+EXPORT_SYMBOL_GPL(proc_mkdir_data_restrict);
64125+
64126 struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
64127 struct proc_dir_entry *parent)
64128 {
64129@@ -421,6 +479,13 @@ struct proc_dir_entry *proc_mkdir(const char *name,
64130 }
64131 EXPORT_SYMBOL(proc_mkdir);
64132
64133+struct proc_dir_entry *proc_mkdir_restrict(const char *name,
64134+ struct proc_dir_entry *parent)
64135+{
64136+ return proc_mkdir_data_restrict(name, 0, parent, NULL);
64137+}
64138+EXPORT_SYMBOL(proc_mkdir_restrict);
64139+
64140 struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
64141 struct proc_dir_entry *parent,
64142 const struct file_operations *proc_fops,
64143diff --git a/fs/proc/inode.c b/fs/proc/inode.c
64144index 124fc43..8afbb02 100644
64145--- a/fs/proc/inode.c
64146+++ b/fs/proc/inode.c
64147@@ -23,11 +23,17 @@
64148 #include <linux/slab.h>
64149 #include <linux/mount.h>
64150 #include <linux/magic.h>
64151+#include <linux/grsecurity.h>
64152
64153 #include <asm/uaccess.h>
64154
64155 #include "internal.h"
64156
64157+#ifdef CONFIG_PROC_SYSCTL
64158+extern const struct inode_operations proc_sys_inode_operations;
64159+extern const struct inode_operations proc_sys_dir_operations;
64160+#endif
64161+
64162 static void proc_evict_inode(struct inode *inode)
64163 {
64164 struct proc_dir_entry *de;
64165@@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
64166 ns = PROC_I(inode)->ns.ns;
64167 if (ns_ops && ns)
64168 ns_ops->put(ns);
64169+
64170+#ifdef CONFIG_PROC_SYSCTL
64171+ if (inode->i_op == &proc_sys_inode_operations ||
64172+ inode->i_op == &proc_sys_dir_operations)
64173+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
64174+#endif
64175+
64176 }
64177
64178 static struct kmem_cache * proc_inode_cachep;
64179@@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
64180 if (de->mode) {
64181 inode->i_mode = de->mode;
64182 inode->i_uid = de->uid;
64183+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64184+ inode->i_gid = grsec_proc_gid;
64185+#else
64186 inode->i_gid = de->gid;
64187+#endif
64188 }
64189 if (de->size)
64190 inode->i_size = de->size;
64191diff --git a/fs/proc/internal.h b/fs/proc/internal.h
64192index 651d09a..6a4b495 100644
64193--- a/fs/proc/internal.h
64194+++ b/fs/proc/internal.h
64195@@ -46,9 +46,10 @@ struct proc_dir_entry {
64196 struct completion *pde_unload_completion;
64197 struct list_head pde_openers; /* who did ->open, but not ->release */
64198 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
64199+ u8 restricted; /* a directory in /proc/net that should be restricted via GRKERNSEC_PROC */
64200 u8 namelen;
64201 char name[];
64202-};
64203+} __randomize_layout;
64204
64205 union proc_op {
64206 int (*proc_get_link)(struct dentry *, struct path *);
64207@@ -67,7 +68,7 @@ struct proc_inode {
64208 struct ctl_table *sysctl_entry;
64209 struct proc_ns ns;
64210 struct inode vfs_inode;
64211-};
64212+} __randomize_layout;
64213
64214 /*
64215 * General functions
64216@@ -155,6 +156,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
64217 struct pid *, struct task_struct *);
64218 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
64219 struct pid *, struct task_struct *);
64220+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
64221+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
64222+#endif
64223
64224 /*
64225 * base.c
64226@@ -181,9 +185,11 @@ extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, i
64227 extern spinlock_t proc_subdir_lock;
64228
64229 extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
64230+extern struct dentry *proc_lookup_restrict(struct inode *, struct dentry *, unsigned int);
64231 extern struct dentry *proc_lookup_de(struct proc_dir_entry *, struct inode *,
64232 struct dentry *);
64233 extern int proc_readdir(struct file *, struct dir_context *);
64234+extern int proc_readdir_restrict(struct file *, struct dir_context *);
64235 extern int proc_readdir_de(struct proc_dir_entry *, struct file *, struct dir_context *);
64236
64237 static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
64238diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
64239index a352d57..cb94a5c 100644
64240--- a/fs/proc/interrupts.c
64241+++ b/fs/proc/interrupts.c
64242@@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
64243
64244 static int __init proc_interrupts_init(void)
64245 {
64246+#ifdef CONFIG_GRKERNSEC_PROC_ADD
64247+ proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
64248+#else
64249 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
64250+#endif
64251 return 0;
64252 }
64253 fs_initcall(proc_interrupts_init);
64254diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
64255index 39e6ef3..2f9cb5e 100644
64256--- a/fs/proc/kcore.c
64257+++ b/fs/proc/kcore.c
64258@@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
64259 * the addresses in the elf_phdr on our list.
64260 */
64261 start = kc_offset_to_vaddr(*fpos - elf_buflen);
64262- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
64263+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
64264+ if (tsz > buflen)
64265 tsz = buflen;
64266-
64267+
64268 while (buflen) {
64269 struct kcore_list *m;
64270
64271@@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
64272 kfree(elf_buf);
64273 } else {
64274 if (kern_addr_valid(start)) {
64275- unsigned long n;
64276+ char *elf_buf;
64277+ mm_segment_t oldfs;
64278
64279- n = copy_to_user(buffer, (char *)start, tsz);
64280- /*
64281- * We cannot distinguish between fault on source
64282- * and fault on destination. When this happens
64283- * we clear too and hope it will trigger the
64284- * EFAULT again.
64285- */
64286- if (n) {
64287- if (clear_user(buffer + tsz - n,
64288- n))
64289+ elf_buf = kmalloc(tsz, GFP_KERNEL);
64290+ if (!elf_buf)
64291+ return -ENOMEM;
64292+ oldfs = get_fs();
64293+ set_fs(KERNEL_DS);
64294+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
64295+ set_fs(oldfs);
64296+ if (copy_to_user(buffer, elf_buf, tsz)) {
64297+ kfree(elf_buf);
64298 return -EFAULT;
64299+ }
64300 }
64301+ set_fs(oldfs);
64302+ kfree(elf_buf);
64303 } else {
64304 if (clear_user(buffer, tsz))
64305 return -EFAULT;
64306@@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
64307
64308 static int open_kcore(struct inode *inode, struct file *filp)
64309 {
64310+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
64311+ return -EPERM;
64312+#endif
64313 if (!capable(CAP_SYS_RAWIO))
64314 return -EPERM;
64315 if (kcore_need_update)
64316diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
64317index 136e548..1f88922 100644
64318--- a/fs/proc/meminfo.c
64319+++ b/fs/proc/meminfo.c
64320@@ -187,7 +187,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
64321 vmi.used >> 10,
64322 vmi.largest_chunk >> 10
64323 #ifdef CONFIG_MEMORY_FAILURE
64324- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
64325+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
64326 #endif
64327 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
64328 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
64329diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
64330index d4a3574..b421ce9 100644
64331--- a/fs/proc/nommu.c
64332+++ b/fs/proc/nommu.c
64333@@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
64334
64335 if (file) {
64336 seq_pad(m, ' ');
64337- seq_path(m, &file->f_path, "");
64338+ seq_path(m, &file->f_path, "\n\\");
64339 }
64340
64341 seq_putc(m, '\n');
64342diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
64343index 4677bb7..94067cd 100644
64344--- a/fs/proc/proc_net.c
64345+++ b/fs/proc/proc_net.c
64346@@ -23,6 +23,7 @@
64347 #include <linux/nsproxy.h>
64348 #include <net/net_namespace.h>
64349 #include <linux/seq_file.h>
64350+#include <linux/grsecurity.h>
64351
64352 #include "internal.h"
64353
64354@@ -36,6 +37,8 @@ static struct net *get_proc_net(const struct inode *inode)
64355 return maybe_get_net(PDE_NET(PDE(inode)));
64356 }
64357
64358+extern const struct seq_operations dev_seq_ops;
64359+
64360 int seq_open_net(struct inode *ino, struct file *f,
64361 const struct seq_operations *ops, int size)
64362 {
64363@@ -44,6 +47,10 @@ int seq_open_net(struct inode *ino, struct file *f,
64364
64365 BUG_ON(size < sizeof(*p));
64366
64367+ /* only permit access to /proc/net/dev */
64368+ if (ops != &dev_seq_ops && gr_proc_is_restricted())
64369+ return -EACCES;
64370+
64371 net = get_proc_net(ino);
64372 if (net == NULL)
64373 return -ENXIO;
64374@@ -66,6 +73,9 @@ int single_open_net(struct inode *inode, struct file *file,
64375 int err;
64376 struct net *net;
64377
64378+ if (gr_proc_is_restricted())
64379+ return -EACCES;
64380+
64381 err = -ENXIO;
64382 net = get_proc_net(inode);
64383 if (net == NULL)
64384diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
64385index 7129046..6914844 100644
64386--- a/fs/proc/proc_sysctl.c
64387+++ b/fs/proc/proc_sysctl.c
64388@@ -11,13 +11,21 @@
64389 #include <linux/namei.h>
64390 #include <linux/mm.h>
64391 #include <linux/module.h>
64392+#include <linux/nsproxy.h>
64393+#ifdef CONFIG_GRKERNSEC
64394+#include <net/net_namespace.h>
64395+#endif
64396 #include "internal.h"
64397
64398+extern int gr_handle_chroot_sysctl(const int op);
64399+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
64400+ const int op);
64401+
64402 static const struct dentry_operations proc_sys_dentry_operations;
64403 static const struct file_operations proc_sys_file_operations;
64404-static const struct inode_operations proc_sys_inode_operations;
64405+const struct inode_operations proc_sys_inode_operations;
64406 static const struct file_operations proc_sys_dir_file_operations;
64407-static const struct inode_operations proc_sys_dir_operations;
64408+const struct inode_operations proc_sys_dir_operations;
64409
64410 void proc_sys_poll_notify(struct ctl_table_poll *poll)
64411 {
64412@@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
64413
64414 err = NULL;
64415 d_set_d_op(dentry, &proc_sys_dentry_operations);
64416+
64417+ gr_handle_proc_create(dentry, inode);
64418+
64419 d_add(dentry, inode);
64420
64421 out:
64422@@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64423 struct inode *inode = file_inode(filp);
64424 struct ctl_table_header *head = grab_header(inode);
64425 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
64426+ int op = write ? MAY_WRITE : MAY_READ;
64427 ssize_t error;
64428 size_t res;
64429
64430@@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64431 * and won't be until we finish.
64432 */
64433 error = -EPERM;
64434- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
64435+ if (sysctl_perm(head, table, op))
64436 goto out;
64437
64438 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
64439@@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64440 if (!table->proc_handler)
64441 goto out;
64442
64443+#ifdef CONFIG_GRKERNSEC
64444+ error = -EPERM;
64445+ if (gr_handle_chroot_sysctl(op))
64446+ goto out;
64447+ dget(filp->f_path.dentry);
64448+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
64449+ dput(filp->f_path.dentry);
64450+ goto out;
64451+ }
64452+ dput(filp->f_path.dentry);
64453+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
64454+ goto out;
64455+ if (write) {
64456+ if (current->nsproxy->net_ns != table->extra2) {
64457+ if (!capable(CAP_SYS_ADMIN))
64458+ goto out;
64459+ } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
64460+ goto out;
64461+ }
64462+#endif
64463+
64464 /* careful: calling conventions are nasty here */
64465 res = count;
64466 error = table->proc_handler(table, write, buf, &res, ppos);
64467@@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
64468 return false;
64469 } else {
64470 d_set_d_op(child, &proc_sys_dentry_operations);
64471+
64472+ gr_handle_proc_create(child, inode);
64473+
64474 d_add(child, inode);
64475 }
64476 } else {
64477@@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
64478 if ((*pos)++ < ctx->pos)
64479 return true;
64480
64481+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
64482+ return 0;
64483+
64484 if (unlikely(S_ISLNK(table->mode)))
64485 res = proc_sys_link_fill_cache(file, ctx, head, table);
64486 else
64487@@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
64488 if (IS_ERR(head))
64489 return PTR_ERR(head);
64490
64491+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
64492+ return -ENOENT;
64493+
64494 generic_fillattr(inode, stat);
64495 if (table)
64496 stat->mode = (stat->mode & S_IFMT) | table->mode;
64497@@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
64498 .llseek = generic_file_llseek,
64499 };
64500
64501-static const struct inode_operations proc_sys_inode_operations = {
64502+const struct inode_operations proc_sys_inode_operations = {
64503 .permission = proc_sys_permission,
64504 .setattr = proc_sys_setattr,
64505 .getattr = proc_sys_getattr,
64506 };
64507
64508-static const struct inode_operations proc_sys_dir_operations = {
64509+const struct inode_operations proc_sys_dir_operations = {
64510 .lookup = proc_sys_lookup,
64511 .permission = proc_sys_permission,
64512 .setattr = proc_sys_setattr,
64513@@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
64514 static struct ctl_dir *new_dir(struct ctl_table_set *set,
64515 const char *name, int namelen)
64516 {
64517- struct ctl_table *table;
64518+ ctl_table_no_const *table;
64519 struct ctl_dir *new;
64520 struct ctl_node *node;
64521 char *new_name;
64522@@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
64523 return NULL;
64524
64525 node = (struct ctl_node *)(new + 1);
64526- table = (struct ctl_table *)(node + 1);
64527+ table = (ctl_table_no_const *)(node + 1);
64528 new_name = (char *)(table + 2);
64529 memcpy(new_name, name, namelen);
64530 new_name[namelen] = '\0';
64531@@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
64532 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
64533 struct ctl_table_root *link_root)
64534 {
64535- struct ctl_table *link_table, *entry, *link;
64536+ ctl_table_no_const *link_table, *link;
64537+ struct ctl_table *entry;
64538 struct ctl_table_header *links;
64539 struct ctl_node *node;
64540 char *link_name;
64541@@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
64542 return NULL;
64543
64544 node = (struct ctl_node *)(links + 1);
64545- link_table = (struct ctl_table *)(node + nr_entries);
64546+ link_table = (ctl_table_no_const *)(node + nr_entries);
64547 link_name = (char *)&link_table[nr_entries + 1];
64548
64549 for (link = link_table, entry = table; entry->procname; link++, entry++) {
64550@@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64551 struct ctl_table_header ***subheader, struct ctl_table_set *set,
64552 struct ctl_table *table)
64553 {
64554- struct ctl_table *ctl_table_arg = NULL;
64555- struct ctl_table *entry, *files;
64556+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
64557+ struct ctl_table *entry;
64558 int nr_files = 0;
64559 int nr_dirs = 0;
64560 int err = -ENOMEM;
64561@@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64562 nr_files++;
64563 }
64564
64565- files = table;
64566 /* If there are mixed files and directories we need a new table */
64567 if (nr_dirs && nr_files) {
64568- struct ctl_table *new;
64569+ ctl_table_no_const *new;
64570 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
64571 GFP_KERNEL);
64572 if (!files)
64573@@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64574 /* Register everything except a directory full of subdirectories */
64575 if (nr_files || !nr_dirs) {
64576 struct ctl_table_header *header;
64577- header = __register_sysctl_table(set, path, files);
64578+ header = __register_sysctl_table(set, path, files ? files : table);
64579 if (!header) {
64580 kfree(ctl_table_arg);
64581 goto out;
64582diff --git a/fs/proc/root.c b/fs/proc/root.c
64583index 87dbcbe..55e1b4d 100644
64584--- a/fs/proc/root.c
64585+++ b/fs/proc/root.c
64586@@ -186,7 +186,15 @@ void __init proc_root_init(void)
64587 #ifdef CONFIG_PROC_DEVICETREE
64588 proc_device_tree_init();
64589 #endif
64590+#ifdef CONFIG_GRKERNSEC_PROC_ADD
64591+#ifdef CONFIG_GRKERNSEC_PROC_USER
64592+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
64593+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64594+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
64595+#endif
64596+#else
64597 proc_mkdir("bus", NULL);
64598+#endif
64599 proc_sys_init();
64600 }
64601
64602diff --git a/fs/proc/stat.c b/fs/proc/stat.c
64603index 6f599c6..bd00271 100644
64604--- a/fs/proc/stat.c
64605+++ b/fs/proc/stat.c
64606@@ -11,6 +11,7 @@
64607 #include <linux/irqnr.h>
64608 #include <asm/cputime.h>
64609 #include <linux/tick.h>
64610+#include <linux/grsecurity.h>
64611
64612 #ifndef arch_irq_stat_cpu
64613 #define arch_irq_stat_cpu(cpu) 0
64614@@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
64615 u64 sum_softirq = 0;
64616 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
64617 struct timespec boottime;
64618+ int unrestricted = 1;
64619+
64620+#ifdef CONFIG_GRKERNSEC_PROC_ADD
64621+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64622+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
64623+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64624+ && !in_group_p(grsec_proc_gid)
64625+#endif
64626+ )
64627+ unrestricted = 0;
64628+#endif
64629+#endif
64630
64631 user = nice = system = idle = iowait =
64632 irq = softirq = steal = 0;
64633@@ -99,23 +112,25 @@ static int show_stat(struct seq_file *p, void *v)
64634 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
64635 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
64636 idle += get_idle_time(i);
64637- iowait += get_iowait_time(i);
64638- irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64639- softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64640- steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64641- guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64642- guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64643- sum += kstat_cpu_irqs_sum(i);
64644- sum += arch_irq_stat_cpu(i);
64645+ if (unrestricted) {
64646+ iowait += get_iowait_time(i);
64647+ irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64648+ softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64649+ steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64650+ guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64651+ guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64652+ sum += kstat_cpu_irqs_sum(i);
64653+ sum += arch_irq_stat_cpu(i);
64654+ for (j = 0; j < NR_SOFTIRQS; j++) {
64655+ unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
64656
64657- for (j = 0; j < NR_SOFTIRQS; j++) {
64658- unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
64659-
64660- per_softirq_sums[j] += softirq_stat;
64661- sum_softirq += softirq_stat;
64662+ per_softirq_sums[j] += softirq_stat;
64663+ sum_softirq += softirq_stat;
64664+ }
64665 }
64666 }
64667- sum += arch_irq_stat();
64668+ if (unrestricted)
64669+ sum += arch_irq_stat();
64670
64671 seq_puts(p, "cpu ");
64672 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
64673@@ -136,12 +151,14 @@ static int show_stat(struct seq_file *p, void *v)
64674 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
64675 system = kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
64676 idle = get_idle_time(i);
64677- iowait = get_iowait_time(i);
64678- irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64679- softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64680- steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64681- guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64682- guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64683+ if (unrestricted) {
64684+ iowait = get_iowait_time(i);
64685+ irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64686+ softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64687+ steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64688+ guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64689+ guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64690+ }
64691 seq_printf(p, "cpu%d", i);
64692 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
64693 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
64694@@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
64695
64696 /* sum again ? it could be updated? */
64697 for_each_irq_nr(j)
64698- seq_put_decimal_ull(p, ' ', kstat_irqs(j));
64699+ seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
64700
64701 seq_printf(p,
64702 "\nctxt %llu\n"
64703@@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
64704 "processes %lu\n"
64705 "procs_running %lu\n"
64706 "procs_blocked %lu\n",
64707- nr_context_switches(),
64708+ unrestricted ? nr_context_switches() : 0ULL,
64709 (unsigned long)jif,
64710- total_forks,
64711- nr_running(),
64712- nr_iowait());
64713+ unrestricted ? total_forks : 0UL,
64714+ unrestricted ? nr_running() : 0UL,
64715+ unrestricted ? nr_iowait() : 0UL);
64716
64717 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
64718
64719diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
64720index fb52b54..5fc7c14 100644
64721--- a/fs/proc/task_mmu.c
64722+++ b/fs/proc/task_mmu.c
64723@@ -12,12 +12,19 @@
64724 #include <linux/swap.h>
64725 #include <linux/swapops.h>
64726 #include <linux/mmu_notifier.h>
64727+#include <linux/grsecurity.h>
64728
64729 #include <asm/elf.h>
64730 #include <asm/uaccess.h>
64731 #include <asm/tlbflush.h>
64732 #include "internal.h"
64733
64734+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64735+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
64736+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
64737+ _mm->pax_flags & MF_PAX_SEGMEXEC))
64738+#endif
64739+
64740 void task_mem(struct seq_file *m, struct mm_struct *mm)
64741 {
64742 unsigned long data, text, lib, swap;
64743@@ -53,8 +60,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64744 "VmExe:\t%8lu kB\n"
64745 "VmLib:\t%8lu kB\n"
64746 "VmPTE:\t%8lu kB\n"
64747- "VmSwap:\t%8lu kB\n",
64748- hiwater_vm << (PAGE_SHIFT-10),
64749+ "VmSwap:\t%8lu kB\n"
64750+
64751+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
64752+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
64753+#endif
64754+
64755+ ,hiwater_vm << (PAGE_SHIFT-10),
64756 total_vm << (PAGE_SHIFT-10),
64757 mm->locked_vm << (PAGE_SHIFT-10),
64758 mm->pinned_vm << (PAGE_SHIFT-10),
64759@@ -64,7 +76,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64760 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
64761 (PTRS_PER_PTE * sizeof(pte_t) *
64762 atomic_long_read(&mm->nr_ptes)) >> 10,
64763- swap << (PAGE_SHIFT-10));
64764+ swap << (PAGE_SHIFT-10)
64765+
64766+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
64767+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64768+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
64769+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
64770+#else
64771+ , mm->context.user_cs_base
64772+ , mm->context.user_cs_limit
64773+#endif
64774+#endif
64775+
64776+ );
64777 }
64778
64779 unsigned long task_vsize(struct mm_struct *mm)
64780@@ -270,13 +294,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64781 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
64782 }
64783
64784- /* We don't show the stack guard page in /proc/maps */
64785+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64786+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
64787+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
64788+#else
64789 start = vma->vm_start;
64790- if (stack_guard_page_start(vma, start))
64791- start += PAGE_SIZE;
64792 end = vma->vm_end;
64793- if (stack_guard_page_end(vma, end))
64794- end -= PAGE_SIZE;
64795+#endif
64796
64797 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
64798 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
64799@@ -286,7 +310,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64800 flags & VM_WRITE ? 'w' : '-',
64801 flags & VM_EXEC ? 'x' : '-',
64802 flags & VM_MAYSHARE ? 's' : 'p',
64803+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64804+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
64805+#else
64806 pgoff,
64807+#endif
64808 MAJOR(dev), MINOR(dev), ino);
64809
64810 /*
64811@@ -295,7 +323,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64812 */
64813 if (file) {
64814 seq_pad(m, ' ');
64815- seq_path(m, &file->f_path, "\n");
64816+ seq_path(m, &file->f_path, "\n\\");
64817 goto done;
64818 }
64819
64820@@ -321,8 +349,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64821 * Thread stack in /proc/PID/task/TID/maps or
64822 * the main process stack.
64823 */
64824- if (!is_pid || (vma->vm_start <= mm->start_stack &&
64825- vma->vm_end >= mm->start_stack)) {
64826+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
64827+ (vma->vm_start <= mm->start_stack &&
64828+ vma->vm_end >= mm->start_stack)) {
64829 name = "[stack]";
64830 } else {
64831 /* Thread stack in /proc/PID/maps */
64832@@ -346,6 +375,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
64833 struct proc_maps_private *priv = m->private;
64834 struct task_struct *task = priv->task;
64835
64836+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64837+ if (current->exec_id != m->exec_id) {
64838+ gr_log_badprocpid("maps");
64839+ return 0;
64840+ }
64841+#endif
64842+
64843 show_map_vma(m, vma, is_pid);
64844
64845 if (m->count < m->size) /* vma is copied successfully */
64846@@ -586,12 +622,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
64847 .private = &mss,
64848 };
64849
64850+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64851+ if (current->exec_id != m->exec_id) {
64852+ gr_log_badprocpid("smaps");
64853+ return 0;
64854+ }
64855+#endif
64856 memset(&mss, 0, sizeof mss);
64857- mss.vma = vma;
64858- /* mmap_sem is held in m_start */
64859- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
64860- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
64861-
64862+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64863+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
64864+#endif
64865+ mss.vma = vma;
64866+ /* mmap_sem is held in m_start */
64867+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
64868+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
64869+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64870+ }
64871+#endif
64872 show_map_vma(m, vma, is_pid);
64873
64874 seq_printf(m,
64875@@ -609,7 +656,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
64876 "KernelPageSize: %8lu kB\n"
64877 "MMUPageSize: %8lu kB\n"
64878 "Locked: %8lu kB\n",
64879+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64880+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
64881+#else
64882 (vma->vm_end - vma->vm_start) >> 10,
64883+#endif
64884 mss.resident >> 10,
64885 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
64886 mss.shared_clean >> 10,
64887@@ -1387,6 +1438,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
64888 char buffer[64];
64889 int nid;
64890
64891+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64892+ if (current->exec_id != m->exec_id) {
64893+ gr_log_badprocpid("numa_maps");
64894+ return 0;
64895+ }
64896+#endif
64897+
64898 if (!mm)
64899 return 0;
64900
64901@@ -1404,11 +1462,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
64902 mpol_to_str(buffer, sizeof(buffer), pol);
64903 mpol_cond_put(pol);
64904
64905+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64906+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
64907+#else
64908 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
64909+#endif
64910
64911 if (file) {
64912 seq_printf(m, " file=");
64913- seq_path(m, &file->f_path, "\n\t= ");
64914+ seq_path(m, &file->f_path, "\n\t\\= ");
64915 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
64916 seq_printf(m, " heap");
64917 } else {
64918diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
64919index 678455d..ebd3245 100644
64920--- a/fs/proc/task_nommu.c
64921+++ b/fs/proc/task_nommu.c
64922@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64923 else
64924 bytes += kobjsize(mm);
64925
64926- if (current->fs && current->fs->users > 1)
64927+ if (current->fs && atomic_read(&current->fs->users) > 1)
64928 sbytes += kobjsize(current->fs);
64929 else
64930 bytes += kobjsize(current->fs);
64931@@ -161,7 +161,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
64932
64933 if (file) {
64934 seq_pad(m, ' ');
64935- seq_path(m, &file->f_path, "");
64936+ seq_path(m, &file->f_path, "\n\\");
64937 } else if (mm) {
64938 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
64939
64940diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
64941index 88d4585..c10bfeb 100644
64942--- a/fs/proc/vmcore.c
64943+++ b/fs/proc/vmcore.c
64944@@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
64945 nr_bytes = count;
64946
64947 /* If pfn is not ram, return zeros for sparse dump files */
64948- if (pfn_is_ram(pfn) == 0)
64949- memset(buf, 0, nr_bytes);
64950- else {
64951+ if (pfn_is_ram(pfn) == 0) {
64952+ if (userbuf) {
64953+ if (clear_user((char __force_user *)buf, nr_bytes))
64954+ return -EFAULT;
64955+ } else
64956+ memset(buf, 0, nr_bytes);
64957+ } else {
64958 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
64959 offset, userbuf);
64960 if (tmp < 0)
64961@@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
64962 static int copy_to(void *target, void *src, size_t size, int userbuf)
64963 {
64964 if (userbuf) {
64965- if (copy_to_user((char __user *) target, src, size))
64966+ if (copy_to_user((char __force_user *) target, src, size))
64967 return -EFAULT;
64968 } else {
64969 memcpy(target, src, size);
64970@@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
64971 if (*fpos < m->offset + m->size) {
64972 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
64973 start = m->paddr + *fpos - m->offset;
64974- tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
64975+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
64976 if (tmp < 0)
64977 return tmp;
64978 buflen -= tsz;
64979@@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
64980 static ssize_t read_vmcore(struct file *file, char __user *buffer,
64981 size_t buflen, loff_t *fpos)
64982 {
64983- return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
64984+ return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
64985 }
64986
64987 /*
64988diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
64989index b00fcc9..e0c6381 100644
64990--- a/fs/qnx6/qnx6.h
64991+++ b/fs/qnx6/qnx6.h
64992@@ -74,7 +74,7 @@ enum {
64993 BYTESEX_BE,
64994 };
64995
64996-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
64997+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
64998 {
64999 if (sbi->s_bytesex == BYTESEX_LE)
65000 return le64_to_cpu((__force __le64)n);
65001@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
65002 return (__force __fs64)cpu_to_be64(n);
65003 }
65004
65005-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
65006+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
65007 {
65008 if (sbi->s_bytesex == BYTESEX_LE)
65009 return le32_to_cpu((__force __le32)n);
65010diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
65011index 72d2917..c917c12 100644
65012--- a/fs/quota/netlink.c
65013+++ b/fs/quota/netlink.c
65014@@ -45,7 +45,7 @@ static struct genl_family quota_genl_family = {
65015 void quota_send_warning(struct kqid qid, dev_t dev,
65016 const char warntype)
65017 {
65018- static atomic_t seq;
65019+ static atomic_unchecked_t seq;
65020 struct sk_buff *skb;
65021 void *msg_head;
65022 int ret;
65023@@ -61,7 +61,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
65024 "VFS: Not enough memory to send quota warning.\n");
65025 return;
65026 }
65027- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
65028+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
65029 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
65030 if (!msg_head) {
65031 printk(KERN_ERR
65032diff --git a/fs/read_write.c b/fs/read_write.c
65033index 28cc9c8..208e4fb 100644
65034--- a/fs/read_write.c
65035+++ b/fs/read_write.c
65036@@ -450,7 +450,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
65037
65038 old_fs = get_fs();
65039 set_fs(get_ds());
65040- p = (__force const char __user *)buf;
65041+ p = (const char __force_user *)buf;
65042 if (count > MAX_RW_COUNT)
65043 count = MAX_RW_COUNT;
65044 if (file->f_op->write)
65045diff --git a/fs/readdir.c b/fs/readdir.c
65046index 5b53d99..a6c3049 100644
65047--- a/fs/readdir.c
65048+++ b/fs/readdir.c
65049@@ -17,6 +17,7 @@
65050 #include <linux/security.h>
65051 #include <linux/syscalls.h>
65052 #include <linux/unistd.h>
65053+#include <linux/namei.h>
65054
65055 #include <asm/uaccess.h>
65056
65057@@ -69,6 +70,7 @@ struct old_linux_dirent {
65058 struct readdir_callback {
65059 struct dir_context ctx;
65060 struct old_linux_dirent __user * dirent;
65061+ struct file * file;
65062 int result;
65063 };
65064
65065@@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
65066 buf->result = -EOVERFLOW;
65067 return -EOVERFLOW;
65068 }
65069+
65070+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
65071+ return 0;
65072+
65073 buf->result++;
65074 dirent = buf->dirent;
65075 if (!access_ok(VERIFY_WRITE, dirent,
65076@@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
65077 if (!f.file)
65078 return -EBADF;
65079
65080+ buf.file = f.file;
65081 error = iterate_dir(f.file, &buf.ctx);
65082 if (buf.result)
65083 error = buf.result;
65084@@ -142,6 +149,7 @@ struct getdents_callback {
65085 struct dir_context ctx;
65086 struct linux_dirent __user * current_dir;
65087 struct linux_dirent __user * previous;
65088+ struct file * file;
65089 int count;
65090 int error;
65091 };
65092@@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
65093 buf->error = -EOVERFLOW;
65094 return -EOVERFLOW;
65095 }
65096+
65097+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
65098+ return 0;
65099+
65100 dirent = buf->previous;
65101 if (dirent) {
65102 if (__put_user(offset, &dirent->d_off))
65103@@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
65104 if (!f.file)
65105 return -EBADF;
65106
65107+ buf.file = f.file;
65108 error = iterate_dir(f.file, &buf.ctx);
65109 if (error >= 0)
65110 error = buf.error;
65111@@ -226,6 +239,7 @@ struct getdents_callback64 {
65112 struct dir_context ctx;
65113 struct linux_dirent64 __user * current_dir;
65114 struct linux_dirent64 __user * previous;
65115+ struct file *file;
65116 int count;
65117 int error;
65118 };
65119@@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
65120 buf->error = -EINVAL; /* only used if we fail.. */
65121 if (reclen > buf->count)
65122 return -EINVAL;
65123+
65124+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
65125+ return 0;
65126+
65127 dirent = buf->previous;
65128 if (dirent) {
65129 if (__put_user(offset, &dirent->d_off))
65130@@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
65131 if (!f.file)
65132 return -EBADF;
65133
65134+ buf.file = f.file;
65135 error = iterate_dir(f.file, &buf.ctx);
65136 if (error >= 0)
65137 error = buf.error;
65138diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
65139index 9a3c68c..767933e 100644
65140--- a/fs/reiserfs/do_balan.c
65141+++ b/fs/reiserfs/do_balan.c
65142@@ -1546,7 +1546,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
65143 return;
65144 }
65145
65146- atomic_inc(&(fs_generation(tb->tb_sb)));
65147+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
65148 do_balance_starts(tb);
65149
65150 /* balance leaf returns 0 except if combining L R and S into
65151diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
65152index ee382ef..f4eb6eb5 100644
65153--- a/fs/reiserfs/item_ops.c
65154+++ b/fs/reiserfs/item_ops.c
65155@@ -725,18 +725,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
65156 }
65157
65158 static struct item_operations errcatch_ops = {
65159- errcatch_bytes_number,
65160- errcatch_decrement_key,
65161- errcatch_is_left_mergeable,
65162- errcatch_print_item,
65163- errcatch_check_item,
65164+ .bytes_number = errcatch_bytes_number,
65165+ .decrement_key = errcatch_decrement_key,
65166+ .is_left_mergeable = errcatch_is_left_mergeable,
65167+ .print_item = errcatch_print_item,
65168+ .check_item = errcatch_check_item,
65169
65170- errcatch_create_vi,
65171- errcatch_check_left,
65172- errcatch_check_right,
65173- errcatch_part_size,
65174- errcatch_unit_num,
65175- errcatch_print_vi
65176+ .create_vi = errcatch_create_vi,
65177+ .check_left = errcatch_check_left,
65178+ .check_right = errcatch_check_right,
65179+ .part_size = errcatch_part_size,
65180+ .unit_num = errcatch_unit_num,
65181+ .print_vi = errcatch_print_vi
65182 };
65183
65184 //////////////////////////////////////////////////////////////////////////////
65185diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
65186index 02b0b7d..c85018b 100644
65187--- a/fs/reiserfs/procfs.c
65188+++ b/fs/reiserfs/procfs.c
65189@@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
65190 "SMALL_TAILS " : "NO_TAILS ",
65191 replay_only(sb) ? "REPLAY_ONLY " : "",
65192 convert_reiserfs(sb) ? "CONV " : "",
65193- atomic_read(&r->s_generation_counter),
65194+ atomic_read_unchecked(&r->s_generation_counter),
65195 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
65196 SF(s_do_balance), SF(s_unneeded_left_neighbor),
65197 SF(s_good_search_by_key_reada), SF(s_bmaps),
65198diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
65199index 8d06adf..7e1c9f8 100644
65200--- a/fs/reiserfs/reiserfs.h
65201+++ b/fs/reiserfs/reiserfs.h
65202@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
65203 /* Comment? -Hans */
65204 wait_queue_head_t s_wait;
65205 /* To be obsoleted soon by per buffer seals.. -Hans */
65206- atomic_t s_generation_counter; // increased by one every time the
65207+ atomic_unchecked_t s_generation_counter; // increased by one every time the
65208 // tree gets re-balanced
65209 unsigned long s_properties; /* File system properties. Currently holds
65210 on-disk FS format */
65211@@ -1972,7 +1972,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
65212 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
65213
65214 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
65215-#define get_generation(s) atomic_read (&fs_generation(s))
65216+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
65217 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
65218 #define __fs_changed(gen,s) (gen != get_generation (s))
65219 #define fs_changed(gen,s) \
65220diff --git a/fs/select.c b/fs/select.c
65221index 467bb1c..cf9d65a 100644
65222--- a/fs/select.c
65223+++ b/fs/select.c
65224@@ -20,6 +20,7 @@
65225 #include <linux/export.h>
65226 #include <linux/slab.h>
65227 #include <linux/poll.h>
65228+#include <linux/security.h>
65229 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
65230 #include <linux/file.h>
65231 #include <linux/fdtable.h>
65232@@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
65233 struct poll_list *walk = head;
65234 unsigned long todo = nfds;
65235
65236+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
65237 if (nfds > rlimit(RLIMIT_NOFILE))
65238 return -EINVAL;
65239
65240diff --git a/fs/seq_file.c b/fs/seq_file.c
65241index 1d641bb..c2f4743 100644
65242--- a/fs/seq_file.c
65243+++ b/fs/seq_file.c
65244@@ -10,6 +10,8 @@
65245 #include <linux/seq_file.h>
65246 #include <linux/slab.h>
65247 #include <linux/cred.h>
65248+#include <linux/sched.h>
65249+#include <linux/grsecurity.h>
65250
65251 #include <asm/uaccess.h>
65252 #include <asm/page.h>
65253@@ -60,6 +62,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
65254 #ifdef CONFIG_USER_NS
65255 p->user_ns = file->f_cred->user_ns;
65256 #endif
65257+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65258+ p->exec_id = current->exec_id;
65259+#endif
65260
65261 /*
65262 * Wrappers around seq_open(e.g. swaps_open) need to be
65263@@ -82,6 +87,16 @@ int seq_open(struct file *file, const struct seq_operations *op)
65264 }
65265 EXPORT_SYMBOL(seq_open);
65266
65267+
65268+int seq_open_restrict(struct file *file, const struct seq_operations *op)
65269+{
65270+ if (gr_proc_is_restricted())
65271+ return -EACCES;
65272+
65273+ return seq_open(file, op);
65274+}
65275+EXPORT_SYMBOL(seq_open_restrict);
65276+
65277 static int traverse(struct seq_file *m, loff_t offset)
65278 {
65279 loff_t pos = 0, index;
65280@@ -96,7 +111,7 @@ static int traverse(struct seq_file *m, loff_t offset)
65281 return 0;
65282 }
65283 if (!m->buf) {
65284- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
65285+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
65286 if (!m->buf)
65287 return -ENOMEM;
65288 }
65289@@ -137,7 +152,7 @@ Eoverflow:
65290 m->op->stop(m, p);
65291 kfree(m->buf);
65292 m->count = 0;
65293- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
65294+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
65295 return !m->buf ? -ENOMEM : -EAGAIN;
65296 }
65297
65298@@ -153,7 +168,7 @@ Eoverflow:
65299 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
65300 {
65301 struct seq_file *m = file->private_data;
65302- size_t copied = 0;
65303+ ssize_t copied = 0;
65304 loff_t pos;
65305 size_t n;
65306 void *p;
65307@@ -192,7 +207,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
65308
65309 /* grab buffer if we didn't have one */
65310 if (!m->buf) {
65311- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
65312+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
65313 if (!m->buf)
65314 goto Enomem;
65315 }
65316@@ -234,7 +249,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
65317 m->op->stop(m, p);
65318 kfree(m->buf);
65319 m->count = 0;
65320- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
65321+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
65322 if (!m->buf)
65323 goto Enomem;
65324 m->version = 0;
65325@@ -584,7 +599,7 @@ static void single_stop(struct seq_file *p, void *v)
65326 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
65327 void *data)
65328 {
65329- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
65330+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
65331 int res = -ENOMEM;
65332
65333 if (op) {
65334@@ -620,6 +635,17 @@ int single_open_size(struct file *file, int (*show)(struct seq_file *, void *),
65335 }
65336 EXPORT_SYMBOL(single_open_size);
65337
65338+int single_open_restrict(struct file *file, int (*show)(struct seq_file *, void *),
65339+ void *data)
65340+{
65341+ if (gr_proc_is_restricted())
65342+ return -EACCES;
65343+
65344+ return single_open(file, show, data);
65345+}
65346+EXPORT_SYMBOL(single_open_restrict);
65347+
65348+
65349 int single_release(struct inode *inode, struct file *file)
65350 {
65351 const struct seq_operations *op = ((struct seq_file *)file->private_data)->op;
65352diff --git a/fs/splice.c b/fs/splice.c
65353index 12028fa..a6f2619 100644
65354--- a/fs/splice.c
65355+++ b/fs/splice.c
65356@@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65357 pipe_lock(pipe);
65358
65359 for (;;) {
65360- if (!pipe->readers) {
65361+ if (!atomic_read(&pipe->readers)) {
65362 send_sig(SIGPIPE, current, 0);
65363 if (!ret)
65364 ret = -EPIPE;
65365@@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65366 page_nr++;
65367 ret += buf->len;
65368
65369- if (pipe->files)
65370+ if (atomic_read(&pipe->files))
65371 do_wakeup = 1;
65372
65373 if (!--spd->nr_pages)
65374@@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65375 do_wakeup = 0;
65376 }
65377
65378- pipe->waiting_writers++;
65379+ atomic_inc(&pipe->waiting_writers);
65380 pipe_wait(pipe);
65381- pipe->waiting_writers--;
65382+ atomic_dec(&pipe->waiting_writers);
65383 }
65384
65385 pipe_unlock(pipe);
65386@@ -583,7 +583,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
65387 old_fs = get_fs();
65388 set_fs(get_ds());
65389 /* The cast to a user pointer is valid due to the set_fs() */
65390- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
65391+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
65392 set_fs(old_fs);
65393
65394 return res;
65395@@ -598,7 +598,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
65396 old_fs = get_fs();
65397 set_fs(get_ds());
65398 /* The cast to a user pointer is valid due to the set_fs() */
65399- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
65400+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
65401 set_fs(old_fs);
65402
65403 return res;
65404@@ -651,7 +651,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
65405 goto err;
65406
65407 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
65408- vec[i].iov_base = (void __user *) page_address(page);
65409+ vec[i].iov_base = (void __force_user *) page_address(page);
65410 vec[i].iov_len = this_len;
65411 spd.pages[i] = page;
65412 spd.nr_pages++;
65413@@ -847,7 +847,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
65414 ops->release(pipe, buf);
65415 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
65416 pipe->nrbufs--;
65417- if (pipe->files)
65418+ if (atomic_read(&pipe->files))
65419 sd->need_wakeup = true;
65420 }
65421
65422@@ -872,10 +872,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
65423 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
65424 {
65425 while (!pipe->nrbufs) {
65426- if (!pipe->writers)
65427+ if (!atomic_read(&pipe->writers))
65428 return 0;
65429
65430- if (!pipe->waiting_writers && sd->num_spliced)
65431+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
65432 return 0;
65433
65434 if (sd->flags & SPLICE_F_NONBLOCK)
65435@@ -1197,7 +1197,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
65436 * out of the pipe right after the splice_to_pipe(). So set
65437 * PIPE_READERS appropriately.
65438 */
65439- pipe->readers = 1;
65440+ atomic_set(&pipe->readers, 1);
65441
65442 current->splice_pipe = pipe;
65443 }
65444@@ -1493,6 +1493,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
65445
65446 partial[buffers].offset = off;
65447 partial[buffers].len = plen;
65448+ partial[buffers].private = 0;
65449
65450 off = 0;
65451 len -= plen;
65452@@ -1795,9 +1796,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65453 ret = -ERESTARTSYS;
65454 break;
65455 }
65456- if (!pipe->writers)
65457+ if (!atomic_read(&pipe->writers))
65458 break;
65459- if (!pipe->waiting_writers) {
65460+ if (!atomic_read(&pipe->waiting_writers)) {
65461 if (flags & SPLICE_F_NONBLOCK) {
65462 ret = -EAGAIN;
65463 break;
65464@@ -1829,7 +1830,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65465 pipe_lock(pipe);
65466
65467 while (pipe->nrbufs >= pipe->buffers) {
65468- if (!pipe->readers) {
65469+ if (!atomic_read(&pipe->readers)) {
65470 send_sig(SIGPIPE, current, 0);
65471 ret = -EPIPE;
65472 break;
65473@@ -1842,9 +1843,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65474 ret = -ERESTARTSYS;
65475 break;
65476 }
65477- pipe->waiting_writers++;
65478+ atomic_inc(&pipe->waiting_writers);
65479 pipe_wait(pipe);
65480- pipe->waiting_writers--;
65481+ atomic_dec(&pipe->waiting_writers);
65482 }
65483
65484 pipe_unlock(pipe);
65485@@ -1880,14 +1881,14 @@ retry:
65486 pipe_double_lock(ipipe, opipe);
65487
65488 do {
65489- if (!opipe->readers) {
65490+ if (!atomic_read(&opipe->readers)) {
65491 send_sig(SIGPIPE, current, 0);
65492 if (!ret)
65493 ret = -EPIPE;
65494 break;
65495 }
65496
65497- if (!ipipe->nrbufs && !ipipe->writers)
65498+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
65499 break;
65500
65501 /*
65502@@ -1984,7 +1985,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
65503 pipe_double_lock(ipipe, opipe);
65504
65505 do {
65506- if (!opipe->readers) {
65507+ if (!atomic_read(&opipe->readers)) {
65508 send_sig(SIGPIPE, current, 0);
65509 if (!ret)
65510 ret = -EPIPE;
65511@@ -2029,7 +2030,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
65512 * return EAGAIN if we have the potential of some data in the
65513 * future, otherwise just return 0
65514 */
65515- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
65516+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
65517 ret = -EAGAIN;
65518
65519 pipe_unlock(ipipe);
65520diff --git a/fs/stat.c b/fs/stat.c
65521index ae0c3ce..9ee641c 100644
65522--- a/fs/stat.c
65523+++ b/fs/stat.c
65524@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
65525 stat->gid = inode->i_gid;
65526 stat->rdev = inode->i_rdev;
65527 stat->size = i_size_read(inode);
65528- stat->atime = inode->i_atime;
65529- stat->mtime = inode->i_mtime;
65530+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
65531+ stat->atime = inode->i_ctime;
65532+ stat->mtime = inode->i_ctime;
65533+ } else {
65534+ stat->atime = inode->i_atime;
65535+ stat->mtime = inode->i_mtime;
65536+ }
65537 stat->ctime = inode->i_ctime;
65538 stat->blksize = (1 << inode->i_blkbits);
65539 stat->blocks = inode->i_blocks;
65540@@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
65541 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
65542 {
65543 struct inode *inode = path->dentry->d_inode;
65544+ int retval;
65545
65546- if (inode->i_op->getattr)
65547- return inode->i_op->getattr(path->mnt, path->dentry, stat);
65548+ if (inode->i_op->getattr) {
65549+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
65550+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
65551+ stat->atime = stat->ctime;
65552+ stat->mtime = stat->ctime;
65553+ }
65554+ return retval;
65555+ }
65556
65557 generic_fillattr(inode, stat);
65558 return 0;
65559diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
65560index ee0d761..b346c58 100644
65561--- a/fs/sysfs/dir.c
65562+++ b/fs/sysfs/dir.c
65563@@ -62,9 +62,16 @@ void sysfs_warn_dup(struct kernfs_node *parent, const char *name)
65564 int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
65565 {
65566 struct kernfs_node *parent, *kn;
65567+ const char *name;
65568+ umode_t mode = S_IRWXU | S_IRUGO | S_IXUGO;
65569+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
65570+ const char *parent_name;
65571+#endif
65572
65573 BUG_ON(!kobj);
65574
65575+ name = kobject_name(kobj);
65576+
65577 if (kobj->parent)
65578 parent = kobj->parent->sd;
65579 else
65580@@ -73,11 +80,22 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
65581 if (!parent)
65582 return -ENOENT;
65583
65584- kn = kernfs_create_dir_ns(parent, kobject_name(kobj),
65585- S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns);
65586+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
65587+ parent_name = parent->name;
65588+ mode = S_IRWXU;
65589+
65590+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
65591+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
65592+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
65593+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
65594+ mode = S_IRWXU | S_IRUGO | S_IXUGO;
65595+#endif
65596+
65597+ kn = kernfs_create_dir_ns(parent, name,
65598+ mode, kobj, ns);
65599 if (IS_ERR(kn)) {
65600 if (PTR_ERR(kn) == -EEXIST)
65601- sysfs_warn_dup(parent, kobject_name(kobj));
65602+ sysfs_warn_dup(parent, name);
65603 return PTR_ERR(kn);
65604 }
65605
65606diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
65607index 69d4889..a810bd4 100644
65608--- a/fs/sysv/sysv.h
65609+++ b/fs/sysv/sysv.h
65610@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
65611 #endif
65612 }
65613
65614-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
65615+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
65616 {
65617 if (sbi->s_bytesex == BYTESEX_PDP)
65618 return PDP_swab((__force __u32)n);
65619diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
65620index e18b988..f1d4ad0f 100644
65621--- a/fs/ubifs/io.c
65622+++ b/fs/ubifs/io.c
65623@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
65624 return err;
65625 }
65626
65627-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
65628+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
65629 {
65630 int err;
65631
65632diff --git a/fs/udf/misc.c b/fs/udf/misc.c
65633index c175b4d..8f36a16 100644
65634--- a/fs/udf/misc.c
65635+++ b/fs/udf/misc.c
65636@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
65637
65638 u8 udf_tag_checksum(const struct tag *t)
65639 {
65640- u8 *data = (u8 *)t;
65641+ const u8 *data = (const u8 *)t;
65642 u8 checksum = 0;
65643 int i;
65644 for (i = 0; i < sizeof(struct tag); ++i)
65645diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
65646index 8d974c4..b82f6ec 100644
65647--- a/fs/ufs/swab.h
65648+++ b/fs/ufs/swab.h
65649@@ -22,7 +22,7 @@ enum {
65650 BYTESEX_BE
65651 };
65652
65653-static inline u64
65654+static inline u64 __intentional_overflow(-1)
65655 fs64_to_cpu(struct super_block *sbp, __fs64 n)
65656 {
65657 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
65658@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
65659 return (__force __fs64)cpu_to_be64(n);
65660 }
65661
65662-static inline u32
65663+static inline u32 __intentional_overflow(-1)
65664 fs32_to_cpu(struct super_block *sbp, __fs32 n)
65665 {
65666 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
65667diff --git a/fs/utimes.c b/fs/utimes.c
65668index aa138d6..5f3a811 100644
65669--- a/fs/utimes.c
65670+++ b/fs/utimes.c
65671@@ -1,6 +1,7 @@
65672 #include <linux/compiler.h>
65673 #include <linux/file.h>
65674 #include <linux/fs.h>
65675+#include <linux/security.h>
65676 #include <linux/linkage.h>
65677 #include <linux/mount.h>
65678 #include <linux/namei.h>
65679@@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
65680 }
65681 }
65682 retry_deleg:
65683+
65684+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
65685+ error = -EACCES;
65686+ goto mnt_drop_write_and_out;
65687+ }
65688+
65689 mutex_lock(&inode->i_mutex);
65690 error = notify_change(path->dentry, &newattrs, &delegated_inode);
65691 mutex_unlock(&inode->i_mutex);
65692diff --git a/fs/xattr.c b/fs/xattr.c
65693index 3377dff..f394815 100644
65694--- a/fs/xattr.c
65695+++ b/fs/xattr.c
65696@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
65697 return rc;
65698 }
65699
65700+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
65701+ssize_t
65702+pax_getxattr(struct dentry *dentry, void *value, size_t size)
65703+{
65704+ struct inode *inode = dentry->d_inode;
65705+ ssize_t error;
65706+
65707+ error = inode_permission(inode, MAY_EXEC);
65708+ if (error)
65709+ return error;
65710+
65711+ if (inode->i_op->getxattr)
65712+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
65713+ else
65714+ error = -EOPNOTSUPP;
65715+
65716+ return error;
65717+}
65718+EXPORT_SYMBOL(pax_getxattr);
65719+#endif
65720+
65721 ssize_t
65722 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
65723 {
65724@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
65725 * Extended attribute SET operations
65726 */
65727 static long
65728-setxattr(struct dentry *d, const char __user *name, const void __user *value,
65729+setxattr(struct path *path, const char __user *name, const void __user *value,
65730 size_t size, int flags)
65731 {
65732 int error;
65733@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
65734 posix_acl_fix_xattr_from_user(kvalue, size);
65735 }
65736
65737- error = vfs_setxattr(d, kname, kvalue, size, flags);
65738+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
65739+ error = -EACCES;
65740+ goto out;
65741+ }
65742+
65743+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
65744 out:
65745 if (vvalue)
65746 vfree(vvalue);
65747@@ -377,7 +403,7 @@ retry:
65748 return error;
65749 error = mnt_want_write(path.mnt);
65750 if (!error) {
65751- error = setxattr(path.dentry, name, value, size, flags);
65752+ error = setxattr(&path, name, value, size, flags);
65753 mnt_drop_write(path.mnt);
65754 }
65755 path_put(&path);
65756@@ -401,7 +427,7 @@ retry:
65757 return error;
65758 error = mnt_want_write(path.mnt);
65759 if (!error) {
65760- error = setxattr(path.dentry, name, value, size, flags);
65761+ error = setxattr(&path, name, value, size, flags);
65762 mnt_drop_write(path.mnt);
65763 }
65764 path_put(&path);
65765@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
65766 const void __user *,value, size_t, size, int, flags)
65767 {
65768 struct fd f = fdget(fd);
65769- struct dentry *dentry;
65770 int error = -EBADF;
65771
65772 if (!f.file)
65773 return error;
65774- dentry = f.file->f_path.dentry;
65775- audit_inode(NULL, dentry, 0);
65776+ audit_inode(NULL, f.file->f_path.dentry, 0);
65777 error = mnt_want_write_file(f.file);
65778 if (!error) {
65779- error = setxattr(dentry, name, value, size, flags);
65780+ error = setxattr(&f.file->f_path, name, value, size, flags);
65781 mnt_drop_write_file(f.file);
65782 }
65783 fdput(f);
65784@@ -626,7 +650,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
65785 * Extended attribute REMOVE operations
65786 */
65787 static long
65788-removexattr(struct dentry *d, const char __user *name)
65789+removexattr(struct path *path, const char __user *name)
65790 {
65791 int error;
65792 char kname[XATTR_NAME_MAX + 1];
65793@@ -637,7 +661,10 @@ removexattr(struct dentry *d, const char __user *name)
65794 if (error < 0)
65795 return error;
65796
65797- return vfs_removexattr(d, kname);
65798+ if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
65799+ return -EACCES;
65800+
65801+ return vfs_removexattr(path->dentry, kname);
65802 }
65803
65804 SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
65805@@ -652,7 +679,7 @@ retry:
65806 return error;
65807 error = mnt_want_write(path.mnt);
65808 if (!error) {
65809- error = removexattr(path.dentry, name);
65810+ error = removexattr(&path, name);
65811 mnt_drop_write(path.mnt);
65812 }
65813 path_put(&path);
65814@@ -675,7 +702,7 @@ retry:
65815 return error;
65816 error = mnt_want_write(path.mnt);
65817 if (!error) {
65818- error = removexattr(path.dentry, name);
65819+ error = removexattr(&path, name);
65820 mnt_drop_write(path.mnt);
65821 }
65822 path_put(&path);
65823@@ -689,16 +716,16 @@ retry:
65824 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
65825 {
65826 struct fd f = fdget(fd);
65827- struct dentry *dentry;
65828+ struct path *path;
65829 int error = -EBADF;
65830
65831 if (!f.file)
65832 return error;
65833- dentry = f.file->f_path.dentry;
65834- audit_inode(NULL, dentry, 0);
65835+ path = &f.file->f_path;
65836+ audit_inode(NULL, path->dentry, 0);
65837 error = mnt_want_write_file(f.file);
65838 if (!error) {
65839- error = removexattr(dentry, name);
65840+ error = removexattr(path, name);
65841 mnt_drop_write_file(f.file);
65842 }
65843 fdput(f);
65844diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
65845index 152543c..d80c361 100644
65846--- a/fs/xfs/xfs_bmap.c
65847+++ b/fs/xfs/xfs_bmap.c
65848@@ -584,7 +584,7 @@ xfs_bmap_validate_ret(
65849
65850 #else
65851 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
65852-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
65853+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
65854 #endif /* DEBUG */
65855
65856 /*
65857diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
65858index aead369..0dfecfd 100644
65859--- a/fs/xfs/xfs_dir2_readdir.c
65860+++ b/fs/xfs/xfs_dir2_readdir.c
65861@@ -160,7 +160,12 @@ xfs_dir2_sf_getdents(
65862 ino = dp->d_ops->sf_get_ino(sfp, sfep);
65863 filetype = dp->d_ops->sf_get_ftype(sfep);
65864 ctx->pos = off & 0x7fffffff;
65865- if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
65866+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
65867+ char name[sfep->namelen];
65868+ memcpy(name, sfep->name, sfep->namelen);
65869+ if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(mp, filetype)))
65870+ return 0;
65871+ } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
65872 xfs_dir3_get_dtype(mp, filetype)))
65873 return 0;
65874 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
65875diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
65876index bcfe612..aa399c0 100644
65877--- a/fs/xfs/xfs_ioctl.c
65878+++ b/fs/xfs/xfs_ioctl.c
65879@@ -122,7 +122,7 @@ xfs_find_handle(
65880 }
65881
65882 error = -EFAULT;
65883- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
65884+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
65885 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
65886 goto out_put;
65887
65888diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
65889new file mode 100644
65890index 0000000..3abaf02
65891--- /dev/null
65892+++ b/grsecurity/Kconfig
65893@@ -0,0 +1,1161 @@
65894+#
65895+# grecurity configuration
65896+#
65897+menu "Memory Protections"
65898+depends on GRKERNSEC
65899+
65900+config GRKERNSEC_KMEM
65901+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
65902+ default y if GRKERNSEC_CONFIG_AUTO
65903+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
65904+ help
65905+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
65906+ be written to or read from to modify or leak the contents of the running
65907+ kernel. /dev/port will also not be allowed to be opened, writing to
65908+ /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
65909+ If you have module support disabled, enabling this will close up several
65910+ ways that are currently used to insert malicious code into the running
65911+ kernel.
65912+
65913+ Even with this feature enabled, we still highly recommend that
65914+ you use the RBAC system, as it is still possible for an attacker to
65915+ modify the running kernel through other more obscure methods.
65916+
65917+ It is highly recommended that you say Y here if you meet all the
65918+ conditions above.
65919+
65920+config GRKERNSEC_VM86
65921+ bool "Restrict VM86 mode"
65922+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65923+ depends on X86_32
65924+
65925+ help
65926+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
65927+ make use of a special execution mode on 32bit x86 processors called
65928+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
65929+ video cards and will still work with this option enabled. The purpose
65930+ of the option is to prevent exploitation of emulation errors in
65931+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
65932+ Nearly all users should be able to enable this option.
65933+
65934+config GRKERNSEC_IO
65935+ bool "Disable privileged I/O"
65936+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65937+ depends on X86
65938+ select RTC_CLASS
65939+ select RTC_INTF_DEV
65940+ select RTC_DRV_CMOS
65941+
65942+ help
65943+ If you say Y here, all ioperm and iopl calls will return an error.
65944+ Ioperm and iopl can be used to modify the running kernel.
65945+ Unfortunately, some programs need this access to operate properly,
65946+ the most notable of which are XFree86 and hwclock. hwclock can be
65947+ remedied by having RTC support in the kernel, so real-time
65948+ clock support is enabled if this option is enabled, to ensure
65949+ that hwclock operates correctly. If hwclock still does not work,
65950+ either update udev or symlink /dev/rtc to /dev/rtc0.
65951+
65952+ If you're using XFree86 or a version of Xorg from 2012 or earlier,
65953+ you may not be able to boot into a graphical environment with this
65954+ option enabled. In this case, you should use the RBAC system instead.
65955+
65956+config GRKERNSEC_JIT_HARDEN
65957+ bool "Harden BPF JIT against spray attacks"
65958+ default y if GRKERNSEC_CONFIG_AUTO
65959+ depends on BPF_JIT && X86
65960+ help
65961+ If you say Y here, the native code generated by the kernel's Berkeley
65962+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
65963+ attacks that attempt to fit attacker-beneficial instructions in
65964+ 32bit immediate fields of JIT-generated native instructions. The
65965+ attacker will generally aim to cause an unintended instruction sequence
65966+ of JIT-generated native code to execute by jumping into the middle of
65967+ a generated instruction. This feature effectively randomizes the 32bit
65968+ immediate constants present in the generated code to thwart such attacks.
65969+
65970+ If you're using KERNEXEC, it's recommended that you enable this option
65971+ to supplement the hardening of the kernel.
65972+
65973+config GRKERNSEC_PERF_HARDEN
65974+ bool "Disable unprivileged PERF_EVENTS usage by default"
65975+ default y if GRKERNSEC_CONFIG_AUTO
65976+ depends on PERF_EVENTS
65977+ help
65978+ If you say Y here, the range of acceptable values for the
65979+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
65980+ default to a new value: 3. When the sysctl is set to this value, no
65981+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
65982+
65983+ Though PERF_EVENTS can be used legitimately for performance monitoring
65984+ and low-level application profiling, it is forced on regardless of
65985+ configuration, has been at fault for several vulnerabilities, and
65986+ creates new opportunities for side channels and other information leaks.
65987+
65988+ This feature puts PERF_EVENTS into a secure default state and permits
65989+ the administrator to change out of it temporarily if unprivileged
65990+ application profiling is needed.
65991+
65992+config GRKERNSEC_RAND_THREADSTACK
65993+ bool "Insert random gaps between thread stacks"
65994+ default y if GRKERNSEC_CONFIG_AUTO
65995+ depends on PAX_RANDMMAP && !PPC
65996+ help
65997+ If you say Y here, a random-sized gap will be enforced between allocated
65998+ thread stacks. Glibc's NPTL and other threading libraries that
65999+ pass MAP_STACK to the kernel for thread stack allocation are supported.
66000+ The implementation currently provides 8 bits of entropy for the gap.
66001+
66002+ Many distributions do not compile threaded remote services with the
66003+ -fstack-check argument to GCC, causing the variable-sized stack-based
66004+ allocator, alloca(), to not probe the stack on allocation. This
66005+ permits an unbounded alloca() to skip over any guard page and potentially
66006+ modify another thread's stack reliably. An enforced random gap
66007+ reduces the reliability of such an attack and increases the chance
66008+ that such a read/write to another thread's stack instead lands in
66009+ an unmapped area, causing a crash and triggering grsecurity's
66010+ anti-bruteforcing logic.
66011+
66012+config GRKERNSEC_PROC_MEMMAP
66013+ bool "Harden ASLR against information leaks and entropy reduction"
66014+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
66015+ depends on PAX_NOEXEC || PAX_ASLR
66016+ help
66017+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
66018+ give no information about the addresses of its mappings if
66019+ PaX features that rely on random addresses are enabled on the task.
66020+ In addition to sanitizing this information and disabling other
66021+ dangerous sources of information, this option causes reads of sensitive
66022+ /proc/<pid> entries where the file descriptor was opened in a different
66023+ task than the one performing the read. Such attempts are logged.
66024+ This option also limits argv/env strings for suid/sgid binaries
66025+ to 512KB to prevent a complete exhaustion of the stack entropy provided
66026+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
66027+ binaries to prevent alternative mmap layouts from being abused.
66028+
66029+ If you use PaX it is essential that you say Y here as it closes up
66030+ several holes that make full ASLR useless locally.
66031+
66032+config GRKERNSEC_BRUTE
66033+ bool "Deter exploit bruteforcing"
66034+ default y if GRKERNSEC_CONFIG_AUTO
66035+ help
66036+ If you say Y here, attempts to bruteforce exploits against forking
66037+ daemons such as apache or sshd, as well as against suid/sgid binaries
66038+ will be deterred. When a child of a forking daemon is killed by PaX
66039+ or crashes due to an illegal instruction or other suspicious signal,
66040+ the parent process will be delayed 30 seconds upon every subsequent
66041+ fork until the administrator is able to assess the situation and
66042+ restart the daemon.
66043+ In the suid/sgid case, the attempt is logged, the user has all their
66044+ existing instances of the suid/sgid binary terminated and will
66045+ be unable to execute any suid/sgid binaries for 15 minutes.
66046+
66047+ It is recommended that you also enable signal logging in the auditing
66048+ section so that logs are generated when a process triggers a suspicious
66049+ signal.
66050+ If the sysctl option is enabled, a sysctl option with name
66051+ "deter_bruteforce" is created.
66052+
66053+config GRKERNSEC_MODHARDEN
66054+ bool "Harden module auto-loading"
66055+ default y if GRKERNSEC_CONFIG_AUTO
66056+ depends on MODULES
66057+ help
66058+ If you say Y here, module auto-loading in response to use of some
66059+ feature implemented by an unloaded module will be restricted to
66060+ root users. Enabling this option helps defend against attacks
66061+ by unprivileged users who abuse the auto-loading behavior to
66062+ cause a vulnerable module to load that is then exploited.
66063+
66064+ If this option prevents a legitimate use of auto-loading for a
66065+ non-root user, the administrator can execute modprobe manually
66066+ with the exact name of the module mentioned in the alert log.
66067+ Alternatively, the administrator can add the module to the list
66068+ of modules loaded at boot by modifying init scripts.
66069+
66070+ Modification of init scripts will most likely be needed on
66071+ Ubuntu servers with encrypted home directory support enabled,
66072+ as the first non-root user logging in will cause the ecb(aes),
66073+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
66074+
66075+config GRKERNSEC_HIDESYM
66076+ bool "Hide kernel symbols"
66077+ default y if GRKERNSEC_CONFIG_AUTO
66078+ select PAX_USERCOPY_SLABS
66079+ help
66080+ If you say Y here, getting information on loaded modules, and
66081+ displaying all kernel symbols through a syscall will be restricted
66082+ to users with CAP_SYS_MODULE. For software compatibility reasons,
66083+ /proc/kallsyms will be restricted to the root user. The RBAC
66084+ system can hide that entry even from root.
66085+
66086+ This option also prevents leaking of kernel addresses through
66087+ several /proc entries.
66088+
66089+ Note that this option is only effective provided the following
66090+ conditions are met:
66091+ 1) The kernel using grsecurity is not precompiled by some distribution
66092+ 2) You have also enabled GRKERNSEC_DMESG
66093+ 3) You are using the RBAC system and hiding other files such as your
66094+ kernel image and System.map. Alternatively, enabling this option
66095+ causes the permissions on /boot, /lib/modules, and the kernel
66096+ source directory to change at compile time to prevent
66097+ reading by non-root users.
66098+ If the above conditions are met, this option will aid in providing a
66099+ useful protection against local kernel exploitation of overflows
66100+ and arbitrary read/write vulnerabilities.
66101+
66102+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
66103+ in addition to this feature.
66104+
66105+config GRKERNSEC_RANDSTRUCT
66106+ bool "Randomize layout of sensitive kernel structures"
66107+ default y if GRKERNSEC_CONFIG_AUTO
66108+ select GRKERNSEC_HIDESYM
66109+ select MODVERSIONS if MODULES
66110+ help
66111+ If you say Y here, the layouts of a number of sensitive kernel
66112+ structures (task, fs, cred, etc) and all structures composed entirely
66113+ of function pointers (aka "ops" structs) will be randomized at compile-time.
66114+ This can introduce the requirement of an additional infoleak
66115+ vulnerability for exploits targeting these structure types.
66116+
66117+ Enabling this feature will introduce some performance impact, slightly
66118+ increase memory usage, and prevent the use of forensic tools like
66119+ Volatility against the system (unless the kernel source tree isn't
66120+ cleaned after kernel installation).
66121+
66122+ The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
66123+ It remains after a make clean to allow for external modules to be compiled
66124+ with the existing seed and will be removed by a make mrproper or
66125+ make distclean.
66126+
66127+ Note that the implementation requires gcc 4.6.4. or newer. You may need
66128+ to install the supporting headers explicitly in addition to the normal
66129+ gcc package.
66130+
66131+config GRKERNSEC_RANDSTRUCT_PERFORMANCE
66132+ bool "Use cacheline-aware structure randomization"
66133+ depends on GRKERNSEC_RANDSTRUCT
66134+ default y if GRKERNSEC_CONFIG_PRIORITY_PERF
66135+ help
66136+ If you say Y here, the RANDSTRUCT randomization will make a best effort
66137+ at restricting randomization to cacheline-sized groups of elements. It
66138+ will further not randomize bitfields in structures. This reduces the
66139+ performance hit of RANDSTRUCT at the cost of weakened randomization.
66140+
66141+config GRKERNSEC_KERN_LOCKOUT
66142+ bool "Active kernel exploit response"
66143+ default y if GRKERNSEC_CONFIG_AUTO
66144+ depends on X86 || ARM || PPC || SPARC
66145+ help
66146+ If you say Y here, when a PaX alert is triggered due to suspicious
66147+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
66148+ or an OOPS occurs due to bad memory accesses, instead of just
66149+ terminating the offending process (and potentially allowing
66150+ a subsequent exploit from the same user), we will take one of two
66151+ actions:
66152+ If the user was root, we will panic the system
66153+ If the user was non-root, we will log the attempt, terminate
66154+ all processes owned by the user, then prevent them from creating
66155+ any new processes until the system is restarted
66156+ This deters repeated kernel exploitation/bruteforcing attempts
66157+ and is useful for later forensics.
66158+
66159+config GRKERNSEC_OLD_ARM_USERLAND
66160+ bool "Old ARM userland compatibility"
66161+ depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
66162+ help
66163+ If you say Y here, stubs of executable code to perform such operations
66164+ as "compare-exchange" will be placed at fixed locations in the ARM vector
66165+ table. This is unfortunately needed for old ARM userland meant to run
66166+ across a wide range of processors. Without this option enabled,
66167+ the get_tls and data memory barrier stubs will be emulated by the kernel,
66168+ which is enough for Linaro userlands or other userlands designed for v6
66169+ and newer ARM CPUs. It's recommended that you try without this option enabled
66170+ first, and only enable it if your userland does not boot (it will likely fail
66171+ at init time).
66172+
66173+endmenu
66174+menu "Role Based Access Control Options"
66175+depends on GRKERNSEC
66176+
66177+config GRKERNSEC_RBAC_DEBUG
66178+ bool
66179+
66180+config GRKERNSEC_NO_RBAC
66181+ bool "Disable RBAC system"
66182+ help
66183+ If you say Y here, the /dev/grsec device will be removed from the kernel,
66184+ preventing the RBAC system from being enabled. You should only say Y
66185+ here if you have no intention of using the RBAC system, so as to prevent
66186+ an attacker with root access from misusing the RBAC system to hide files
66187+ and processes when loadable module support and /dev/[k]mem have been
66188+ locked down.
66189+
66190+config GRKERNSEC_ACL_HIDEKERN
66191+ bool "Hide kernel processes"
66192+ help
66193+ If you say Y here, all kernel threads will be hidden to all
66194+ processes but those whose subject has the "view hidden processes"
66195+ flag.
66196+
66197+config GRKERNSEC_ACL_MAXTRIES
66198+ int "Maximum tries before password lockout"
66199+ default 3
66200+ help
66201+ This option enforces the maximum number of times a user can attempt
66202+ to authorize themselves with the grsecurity RBAC system before being
66203+ denied the ability to attempt authorization again for a specified time.
66204+ The lower the number, the harder it will be to brute-force a password.
66205+
66206+config GRKERNSEC_ACL_TIMEOUT
66207+ int "Time to wait after max password tries, in seconds"
66208+ default 30
66209+ help
66210+ This option specifies the time the user must wait after attempting to
66211+ authorize to the RBAC system with the maximum number of invalid
66212+ passwords. The higher the number, the harder it will be to brute-force
66213+ a password.
66214+
66215+endmenu
66216+menu "Filesystem Protections"
66217+depends on GRKERNSEC
66218+
66219+config GRKERNSEC_PROC
66220+ bool "Proc restrictions"
66221+ default y if GRKERNSEC_CONFIG_AUTO
66222+ help
66223+ If you say Y here, the permissions of the /proc filesystem
66224+ will be altered to enhance system security and privacy. You MUST
66225+ choose either a user only restriction or a user and group restriction.
66226+ Depending upon the option you choose, you can either restrict users to
66227+ see only the processes they themselves run, or choose a group that can
66228+ view all processes and files normally restricted to root if you choose
66229+ the "restrict to user only" option. NOTE: If you're running identd or
66230+ ntpd as a non-root user, you will have to run it as the group you
66231+ specify here.
66232+
66233+config GRKERNSEC_PROC_USER
66234+ bool "Restrict /proc to user only"
66235+ depends on GRKERNSEC_PROC
66236+ help
66237+ If you say Y here, non-root users will only be able to view their own
66238+ processes, and restricts them from viewing network-related information,
66239+ and viewing kernel symbol and module information.
66240+
66241+config GRKERNSEC_PROC_USERGROUP
66242+ bool "Allow special group"
66243+ default y if GRKERNSEC_CONFIG_AUTO
66244+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
66245+ help
66246+ If you say Y here, you will be able to select a group that will be
66247+ able to view all processes and network-related information. If you've
66248+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
66249+ remain hidden. This option is useful if you want to run identd as
66250+ a non-root user. The group you select may also be chosen at boot time
66251+ via "grsec_proc_gid=" on the kernel commandline.
66252+
66253+config GRKERNSEC_PROC_GID
66254+ int "GID for special group"
66255+ depends on GRKERNSEC_PROC_USERGROUP
66256+ default 1001
66257+
66258+config GRKERNSEC_PROC_ADD
66259+ bool "Additional restrictions"
66260+ default y if GRKERNSEC_CONFIG_AUTO
66261+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
66262+ help
66263+ If you say Y here, additional restrictions will be placed on
66264+ /proc that keep normal users from viewing device information and
66265+ slabinfo information that could be useful for exploits.
66266+
66267+config GRKERNSEC_LINK
66268+ bool "Linking restrictions"
66269+ default y if GRKERNSEC_CONFIG_AUTO
66270+ help
66271+ If you say Y here, /tmp race exploits will be prevented, since users
66272+ will no longer be able to follow symlinks owned by other users in
66273+ world-writable +t directories (e.g. /tmp), unless the owner of the
66274+ symlink is the owner of the directory. users will also not be
66275+ able to hardlink to files they do not own. If the sysctl option is
66276+ enabled, a sysctl option with name "linking_restrictions" is created.
66277+
66278+config GRKERNSEC_SYMLINKOWN
66279+ bool "Kernel-enforced SymlinksIfOwnerMatch"
66280+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
66281+ help
66282+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
66283+ that prevents it from being used as a security feature. As Apache
66284+ verifies the symlink by performing a stat() against the target of
66285+ the symlink before it is followed, an attacker can setup a symlink
66286+ to point to a same-owned file, then replace the symlink with one
66287+ that targets another user's file just after Apache "validates" the
66288+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
66289+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
66290+ will be in place for the group you specify. If the sysctl option
66291+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
66292+ created.
66293+
66294+config GRKERNSEC_SYMLINKOWN_GID
66295+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
66296+ depends on GRKERNSEC_SYMLINKOWN
66297+ default 1006
66298+ help
66299+ Setting this GID determines what group kernel-enforced
66300+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
66301+ is enabled, a sysctl option with name "symlinkown_gid" is created.
66302+
66303+config GRKERNSEC_FIFO
66304+ bool "FIFO restrictions"
66305+ default y if GRKERNSEC_CONFIG_AUTO
66306+ help
66307+ If you say Y here, users will not be able to write to FIFOs they don't
66308+ own in world-writable +t directories (e.g. /tmp), unless the owner of
66309+ the FIFO is the same owner of the directory it's held in. If the sysctl
66310+ option is enabled, a sysctl option with name "fifo_restrictions" is
66311+ created.
66312+
66313+config GRKERNSEC_SYSFS_RESTRICT
66314+ bool "Sysfs/debugfs restriction"
66315+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
66316+ depends on SYSFS
66317+ help
66318+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
66319+ any filesystem normally mounted under it (e.g. debugfs) will be
66320+ mostly accessible only by root. These filesystems generally provide access
66321+ to hardware and debug information that isn't appropriate for unprivileged
66322+ users of the system. Sysfs and debugfs have also become a large source
66323+ of new vulnerabilities, ranging from infoleaks to local compromise.
66324+ There has been very little oversight with an eye toward security involved
66325+ in adding new exporters of information to these filesystems, so their
66326+ use is discouraged.
66327+ For reasons of compatibility, a few directories have been whitelisted
66328+ for access by non-root users:
66329+ /sys/fs/selinux
66330+ /sys/fs/fuse
66331+ /sys/devices/system/cpu
66332+
66333+config GRKERNSEC_ROFS
66334+ bool "Runtime read-only mount protection"
66335+ depends on SYSCTL
66336+ help
66337+ If you say Y here, a sysctl option with name "romount_protect" will
66338+ be created. By setting this option to 1 at runtime, filesystems
66339+ will be protected in the following ways:
66340+ * No new writable mounts will be allowed
66341+ * Existing read-only mounts won't be able to be remounted read/write
66342+ * Write operations will be denied on all block devices
66343+ This option acts independently of grsec_lock: once it is set to 1,
66344+ it cannot be turned off. Therefore, please be mindful of the resulting
66345+ behavior if this option is enabled in an init script on a read-only
66346+ filesystem.
66347+ Also be aware that as with other root-focused features, GRKERNSEC_KMEM
66348+ and GRKERNSEC_IO should be enabled and module loading disabled via
66349+ config or at runtime.
66350+ This feature is mainly intended for secure embedded systems.
66351+
66352+
66353+config GRKERNSEC_DEVICE_SIDECHANNEL
66354+ bool "Eliminate stat/notify-based device sidechannels"
66355+ default y if GRKERNSEC_CONFIG_AUTO
66356+ help
66357+ If you say Y here, timing analyses on block or character
66358+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
66359+ will be thwarted for unprivileged users. If a process without
66360+ CAP_MKNOD stats such a device, the last access and last modify times
66361+ will match the device's create time. No access or modify events
66362+ will be triggered through inotify/dnotify/fanotify for such devices.
66363+ This feature will prevent attacks that may at a minimum
66364+ allow an attacker to determine the administrator's password length.
66365+
66366+config GRKERNSEC_CHROOT
66367+ bool "Chroot jail restrictions"
66368+ default y if GRKERNSEC_CONFIG_AUTO
66369+ help
66370+ If you say Y here, you will be able to choose several options that will
66371+ make breaking out of a chrooted jail much more difficult. If you
66372+ encounter no software incompatibilities with the following options, it
66373+ is recommended that you enable each one.
66374+
66375+ Note that the chroot restrictions are not intended to apply to "chroots"
66376+ to directories that are simple bind mounts of the global root filesystem.
66377+ For several other reasons, a user shouldn't expect any significant
66378+ security by performing such a chroot.
66379+
66380+config GRKERNSEC_CHROOT_MOUNT
66381+ bool "Deny mounts"
66382+ default y if GRKERNSEC_CONFIG_AUTO
66383+ depends on GRKERNSEC_CHROOT
66384+ help
66385+ If you say Y here, processes inside a chroot will not be able to
66386+ mount or remount filesystems. If the sysctl option is enabled, a
66387+ sysctl option with name "chroot_deny_mount" is created.
66388+
66389+config GRKERNSEC_CHROOT_DOUBLE
66390+ bool "Deny double-chroots"
66391+ default y if GRKERNSEC_CONFIG_AUTO
66392+ depends on GRKERNSEC_CHROOT
66393+ help
66394+ If you say Y here, processes inside a chroot will not be able to chroot
66395+ again outside the chroot. This is a widely used method of breaking
66396+ out of a chroot jail and should not be allowed. If the sysctl
66397+ option is enabled, a sysctl option with name
66398+ "chroot_deny_chroot" is created.
66399+
66400+config GRKERNSEC_CHROOT_PIVOT
66401+ bool "Deny pivot_root in chroot"
66402+ default y if GRKERNSEC_CONFIG_AUTO
66403+ depends on GRKERNSEC_CHROOT
66404+ help
66405+ If you say Y here, processes inside a chroot will not be able to use
66406+ a function called pivot_root() that was introduced in Linux 2.3.41. It
66407+ works similar to chroot in that it changes the root filesystem. This
66408+ function could be misused in a chrooted process to attempt to break out
66409+ of the chroot, and therefore should not be allowed. If the sysctl
66410+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
66411+ created.
66412+
66413+config GRKERNSEC_CHROOT_CHDIR
66414+ bool "Enforce chdir(\"/\") on all chroots"
66415+ default y if GRKERNSEC_CONFIG_AUTO
66416+ depends on GRKERNSEC_CHROOT
66417+ help
66418+ If you say Y here, the current working directory of all newly-chrooted
66419+ applications will be set to the the root directory of the chroot.
66420+ The man page on chroot(2) states:
66421+ Note that this call does not change the current working
66422+ directory, so that `.' can be outside the tree rooted at
66423+ `/'. In particular, the super-user can escape from a
66424+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
66425+
66426+ It is recommended that you say Y here, since it's not known to break
66427+ any software. If the sysctl option is enabled, a sysctl option with
66428+ name "chroot_enforce_chdir" is created.
66429+
66430+config GRKERNSEC_CHROOT_CHMOD
66431+ bool "Deny (f)chmod +s"
66432+ default y if GRKERNSEC_CONFIG_AUTO
66433+ depends on GRKERNSEC_CHROOT
66434+ help
66435+ If you say Y here, processes inside a chroot will not be able to chmod
66436+ or fchmod files to make them have suid or sgid bits. This protects
66437+ against another published method of breaking a chroot. If the sysctl
66438+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
66439+ created.
66440+
66441+config GRKERNSEC_CHROOT_FCHDIR
66442+ bool "Deny fchdir out of chroot"
66443+ default y if GRKERNSEC_CONFIG_AUTO
66444+ depends on GRKERNSEC_CHROOT
66445+ help
66446+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
66447+ to a file descriptor of the chrooting process that points to a directory
66448+ outside the filesystem will be stopped. If the sysctl option
66449+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
66450+
66451+config GRKERNSEC_CHROOT_MKNOD
66452+ bool "Deny mknod"
66453+ default y if GRKERNSEC_CONFIG_AUTO
66454+ depends on GRKERNSEC_CHROOT
66455+ help
66456+ If you say Y here, processes inside a chroot will not be allowed to
66457+ mknod. The problem with using mknod inside a chroot is that it
66458+ would allow an attacker to create a device entry that is the same
66459+ as one on the physical root of your system, which could range from
66460+ anything from the console device to a device for your harddrive (which
66461+ they could then use to wipe the drive or steal data). It is recommended
66462+ that you say Y here, unless you run into software incompatibilities.
66463+ If the sysctl option is enabled, a sysctl option with name
66464+ "chroot_deny_mknod" is created.
66465+
66466+config GRKERNSEC_CHROOT_SHMAT
66467+ bool "Deny shmat() out of chroot"
66468+ default y if GRKERNSEC_CONFIG_AUTO
66469+ depends on GRKERNSEC_CHROOT
66470+ help
66471+ If you say Y here, processes inside a chroot will not be able to attach
66472+ to shared memory segments that were created outside of the chroot jail.
66473+ It is recommended that you say Y here. If the sysctl option is enabled,
66474+ a sysctl option with name "chroot_deny_shmat" is created.
66475+
66476+config GRKERNSEC_CHROOT_UNIX
66477+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
66478+ default y if GRKERNSEC_CONFIG_AUTO
66479+ depends on GRKERNSEC_CHROOT
66480+ help
66481+ If you say Y here, processes inside a chroot will not be able to
66482+ connect to abstract (meaning not belonging to a filesystem) Unix
66483+ domain sockets that were bound outside of a chroot. It is recommended
66484+ that you say Y here. If the sysctl option is enabled, a sysctl option
66485+ with name "chroot_deny_unix" is created.
66486+
66487+config GRKERNSEC_CHROOT_FINDTASK
66488+ bool "Protect outside processes"
66489+ default y if GRKERNSEC_CONFIG_AUTO
66490+ depends on GRKERNSEC_CHROOT
66491+ help
66492+ If you say Y here, processes inside a chroot will not be able to
66493+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
66494+ getsid, or view any process outside of the chroot. If the sysctl
66495+ option is enabled, a sysctl option with name "chroot_findtask" is
66496+ created.
66497+
66498+config GRKERNSEC_CHROOT_NICE
66499+ bool "Restrict priority changes"
66500+ default y if GRKERNSEC_CONFIG_AUTO
66501+ depends on GRKERNSEC_CHROOT
66502+ help
66503+ If you say Y here, processes inside a chroot will not be able to raise
66504+ the priority of processes in the chroot, or alter the priority of
66505+ processes outside the chroot. This provides more security than simply
66506+ removing CAP_SYS_NICE from the process' capability set. If the
66507+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
66508+ is created.
66509+
66510+config GRKERNSEC_CHROOT_SYSCTL
66511+ bool "Deny sysctl writes"
66512+ default y if GRKERNSEC_CONFIG_AUTO
66513+ depends on GRKERNSEC_CHROOT
66514+ help
66515+ If you say Y here, an attacker in a chroot will not be able to
66516+ write to sysctl entries, either by sysctl(2) or through a /proc
66517+ interface. It is strongly recommended that you say Y here. If the
66518+ sysctl option is enabled, a sysctl option with name
66519+ "chroot_deny_sysctl" is created.
66520+
66521+config GRKERNSEC_CHROOT_CAPS
66522+ bool "Capability restrictions"
66523+ default y if GRKERNSEC_CONFIG_AUTO
66524+ depends on GRKERNSEC_CHROOT
66525+ help
66526+ If you say Y here, the capabilities on all processes within a
66527+ chroot jail will be lowered to stop module insertion, raw i/o,
66528+ system and net admin tasks, rebooting the system, modifying immutable
66529+ files, modifying IPC owned by another, and changing the system time.
66530+ This is left an option because it can break some apps. Disable this
66531+ if your chrooted apps are having problems performing those kinds of
66532+ tasks. If the sysctl option is enabled, a sysctl option with
66533+ name "chroot_caps" is created.
66534+
66535+config GRKERNSEC_CHROOT_INITRD
66536+ bool "Exempt initrd tasks from restrictions"
66537+ default y if GRKERNSEC_CONFIG_AUTO
66538+ depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
66539+ help
66540+ If you say Y here, tasks started prior to init will be exempted from
66541+ grsecurity's chroot restrictions. This option is mainly meant to
66542+ resolve Plymouth's performing privileged operations unnecessarily
66543+ in a chroot.
66544+
66545+endmenu
66546+menu "Kernel Auditing"
66547+depends on GRKERNSEC
66548+
66549+config GRKERNSEC_AUDIT_GROUP
66550+ bool "Single group for auditing"
66551+ help
66552+ If you say Y here, the exec and chdir logging features will only operate
66553+ on a group you specify. This option is recommended if you only want to
66554+ watch certain users instead of having a large amount of logs from the
66555+ entire system. If the sysctl option is enabled, a sysctl option with
66556+ name "audit_group" is created.
66557+
66558+config GRKERNSEC_AUDIT_GID
66559+ int "GID for auditing"
66560+ depends on GRKERNSEC_AUDIT_GROUP
66561+ default 1007
66562+
66563+config GRKERNSEC_EXECLOG
66564+ bool "Exec logging"
66565+ help
66566+ If you say Y here, all execve() calls will be logged (since the
66567+ other exec*() calls are frontends to execve(), all execution
66568+ will be logged). Useful for shell-servers that like to keep track
66569+ of their users. If the sysctl option is enabled, a sysctl option with
66570+ name "exec_logging" is created.
66571+ WARNING: This option when enabled will produce a LOT of logs, especially
66572+ on an active system.
66573+
66574+config GRKERNSEC_RESLOG
66575+ bool "Resource logging"
66576+ default y if GRKERNSEC_CONFIG_AUTO
66577+ help
66578+ If you say Y here, all attempts to overstep resource limits will
66579+ be logged with the resource name, the requested size, and the current
66580+ limit. It is highly recommended that you say Y here. If the sysctl
66581+ option is enabled, a sysctl option with name "resource_logging" is
66582+ created. If the RBAC system is enabled, the sysctl value is ignored.
66583+
66584+config GRKERNSEC_CHROOT_EXECLOG
66585+ bool "Log execs within chroot"
66586+ help
66587+ If you say Y here, all executions inside a chroot jail will be logged
66588+ to syslog. This can cause a large amount of logs if certain
66589+ applications (eg. djb's daemontools) are installed on the system, and
66590+ is therefore left as an option. If the sysctl option is enabled, a
66591+ sysctl option with name "chroot_execlog" is created.
66592+
66593+config GRKERNSEC_AUDIT_PTRACE
66594+ bool "Ptrace logging"
66595+ help
66596+ If you say Y here, all attempts to attach to a process via ptrace
66597+ will be logged. If the sysctl option is enabled, a sysctl option
66598+ with name "audit_ptrace" is created.
66599+
66600+config GRKERNSEC_AUDIT_CHDIR
66601+ bool "Chdir logging"
66602+ help
66603+ If you say Y here, all chdir() calls will be logged. If the sysctl
66604+ option is enabled, a sysctl option with name "audit_chdir" is created.
66605+
66606+config GRKERNSEC_AUDIT_MOUNT
66607+ bool "(Un)Mount logging"
66608+ help
66609+ If you say Y here, all mounts and unmounts will be logged. If the
66610+ sysctl option is enabled, a sysctl option with name "audit_mount" is
66611+ created.
66612+
66613+config GRKERNSEC_SIGNAL
66614+ bool "Signal logging"
66615+ default y if GRKERNSEC_CONFIG_AUTO
66616+ help
66617+ If you say Y here, certain important signals will be logged, such as
66618+ SIGSEGV, which will as a result inform you of when a error in a program
66619+ occurred, which in some cases could mean a possible exploit attempt.
66620+ If the sysctl option is enabled, a sysctl option with name
66621+ "signal_logging" is created.
66622+
66623+config GRKERNSEC_FORKFAIL
66624+ bool "Fork failure logging"
66625+ help
66626+ If you say Y here, all failed fork() attempts will be logged.
66627+ This could suggest a fork bomb, or someone attempting to overstep
66628+ their process limit. If the sysctl option is enabled, a sysctl option
66629+ with name "forkfail_logging" is created.
66630+
66631+config GRKERNSEC_TIME
66632+ bool "Time change logging"
66633+ default y if GRKERNSEC_CONFIG_AUTO
66634+ help
66635+ If you say Y here, any changes of the system clock will be logged.
66636+ If the sysctl option is enabled, a sysctl option with name
66637+ "timechange_logging" is created.
66638+
66639+config GRKERNSEC_PROC_IPADDR
66640+ bool "/proc/<pid>/ipaddr support"
66641+ default y if GRKERNSEC_CONFIG_AUTO
66642+ help
66643+ If you say Y here, a new entry will be added to each /proc/<pid>
66644+ directory that contains the IP address of the person using the task.
66645+ The IP is carried across local TCP and AF_UNIX stream sockets.
66646+ This information can be useful for IDS/IPSes to perform remote response
66647+ to a local attack. The entry is readable by only the owner of the
66648+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
66649+ the RBAC system), and thus does not create privacy concerns.
66650+
66651+config GRKERNSEC_RWXMAP_LOG
66652+ bool 'Denied RWX mmap/mprotect logging'
66653+ default y if GRKERNSEC_CONFIG_AUTO
66654+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
66655+ help
66656+ If you say Y here, calls to mmap() and mprotect() with explicit
66657+ usage of PROT_WRITE and PROT_EXEC together will be logged when
66658+ denied by the PAX_MPROTECT feature. This feature will also
66659+ log other problematic scenarios that can occur when PAX_MPROTECT
66660+ is enabled on a binary, like textrels and PT_GNU_STACK. If the
66661+ sysctl option is enabled, a sysctl option with name "rwxmap_logging"
66662+ is created.
66663+
66664+endmenu
66665+
66666+menu "Executable Protections"
66667+depends on GRKERNSEC
66668+
66669+config GRKERNSEC_DMESG
66670+ bool "Dmesg(8) restriction"
66671+ default y if GRKERNSEC_CONFIG_AUTO
66672+ help
66673+ If you say Y here, non-root users will not be able to use dmesg(8)
66674+ to view the contents of the kernel's circular log buffer.
66675+ The kernel's log buffer often contains kernel addresses and other
66676+ identifying information useful to an attacker in fingerprinting a
66677+ system for a targeted exploit.
66678+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
66679+ created.
66680+
66681+config GRKERNSEC_HARDEN_PTRACE
66682+ bool "Deter ptrace-based process snooping"
66683+ default y if GRKERNSEC_CONFIG_AUTO
66684+ help
66685+ If you say Y here, TTY sniffers and other malicious monitoring
66686+ programs implemented through ptrace will be defeated. If you
66687+ have been using the RBAC system, this option has already been
66688+ enabled for several years for all users, with the ability to make
66689+ fine-grained exceptions.
66690+
66691+ This option only affects the ability of non-root users to ptrace
66692+ processes that are not a descendent of the ptracing process.
66693+ This means that strace ./binary and gdb ./binary will still work,
66694+ but attaching to arbitrary processes will not. If the sysctl
66695+ option is enabled, a sysctl option with name "harden_ptrace" is
66696+ created.
66697+
66698+config GRKERNSEC_PTRACE_READEXEC
66699+ bool "Require read access to ptrace sensitive binaries"
66700+ default y if GRKERNSEC_CONFIG_AUTO
66701+ help
66702+ If you say Y here, unprivileged users will not be able to ptrace unreadable
66703+ binaries. This option is useful in environments that
66704+ remove the read bits (e.g. file mode 4711) from suid binaries to
66705+ prevent infoleaking of their contents. This option adds
66706+ consistency to the use of that file mode, as the binary could normally
66707+ be read out when run without privileges while ptracing.
66708+
66709+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
66710+ is created.
66711+
66712+config GRKERNSEC_SETXID
66713+ bool "Enforce consistent multithreaded privileges"
66714+ default y if GRKERNSEC_CONFIG_AUTO
66715+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
66716+ help
66717+ If you say Y here, a change from a root uid to a non-root uid
66718+ in a multithreaded application will cause the resulting uids,
66719+ gids, supplementary groups, and capabilities in that thread
66720+ to be propagated to the other threads of the process. In most
66721+ cases this is unnecessary, as glibc will emulate this behavior
66722+ on behalf of the application. Other libcs do not act in the
66723+ same way, allowing the other threads of the process to continue
66724+ running with root privileges. If the sysctl option is enabled,
66725+ a sysctl option with name "consistent_setxid" is created.
66726+
66727+config GRKERNSEC_HARDEN_IPC
66728+ bool "Disallow access to overly-permissive IPC objects"
66729+ default y if GRKERNSEC_CONFIG_AUTO
66730+ depends on SYSVIPC
66731+ help
66732+ If you say Y here, access to overly-permissive IPC objects (shared
66733+ memory, message queues, and semaphores) will be denied for processes
66734+ given the following criteria beyond normal permission checks:
66735+ 1) If the IPC object is world-accessible and the euid doesn't match
66736+ that of the creator or current uid for the IPC object
66737+ 2) If the IPC object is group-accessible and the egid doesn't
66738+ match that of the creator or current gid for the IPC object
66739+ It's a common error to grant too much permission to these objects,
66740+ with impact ranging from denial of service and information leaking to
66741+ privilege escalation. This feature was developed in response to
66742+ research by Tim Brown:
66743+ http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
66744+ who found hundreds of such insecure usages. Processes with
66745+ CAP_IPC_OWNER are still permitted to access these IPC objects.
66746+ If the sysctl option is enabled, a sysctl option with name
66747+ "harden_ipc" is created.
66748+
66749+config GRKERNSEC_TPE
66750+ bool "Trusted Path Execution (TPE)"
66751+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
66752+ help
66753+ If you say Y here, you will be able to choose a gid to add to the
66754+ supplementary groups of users you want to mark as "untrusted."
66755+ These users will not be able to execute any files that are not in
66756+ root-owned directories writable only by root. If the sysctl option
66757+ is enabled, a sysctl option with name "tpe" is created.
66758+
66759+config GRKERNSEC_TPE_ALL
66760+ bool "Partially restrict all non-root users"
66761+ depends on GRKERNSEC_TPE
66762+ help
66763+ If you say Y here, all non-root users will be covered under
66764+ a weaker TPE restriction. This is separate from, and in addition to,
66765+ the main TPE options that you have selected elsewhere. Thus, if a
66766+ "trusted" GID is chosen, this restriction applies to even that GID.
66767+ Under this restriction, all non-root users will only be allowed to
66768+ execute files in directories they own that are not group or
66769+ world-writable, or in directories owned by root and writable only by
66770+ root. If the sysctl option is enabled, a sysctl option with name
66771+ "tpe_restrict_all" is created.
66772+
66773+config GRKERNSEC_TPE_INVERT
66774+ bool "Invert GID option"
66775+ depends on GRKERNSEC_TPE
66776+ help
66777+ If you say Y here, the group you specify in the TPE configuration will
66778+ decide what group TPE restrictions will be *disabled* for. This
66779+ option is useful if you want TPE restrictions to be applied to most
66780+ users on the system. If the sysctl option is enabled, a sysctl option
66781+ with name "tpe_invert" is created. Unlike other sysctl options, this
66782+ entry will default to on for backward-compatibility.
66783+
66784+config GRKERNSEC_TPE_GID
66785+ int
66786+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
66787+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
66788+
66789+config GRKERNSEC_TPE_UNTRUSTED_GID
66790+ int "GID for TPE-untrusted users"
66791+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
66792+ default 1005
66793+ help
66794+ Setting this GID determines what group TPE restrictions will be
66795+ *enabled* for. If the sysctl option is enabled, a sysctl option
66796+ with name "tpe_gid" is created.
66797+
66798+config GRKERNSEC_TPE_TRUSTED_GID
66799+ int "GID for TPE-trusted users"
66800+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
66801+ default 1005
66802+ help
66803+ Setting this GID determines what group TPE restrictions will be
66804+ *disabled* for. If the sysctl option is enabled, a sysctl option
66805+ with name "tpe_gid" is created.
66806+
66807+endmenu
66808+menu "Network Protections"
66809+depends on GRKERNSEC
66810+
66811+config GRKERNSEC_RANDNET
66812+ bool "Larger entropy pools"
66813+ default y if GRKERNSEC_CONFIG_AUTO
66814+ help
66815+ If you say Y here, the entropy pools used for many features of Linux
66816+ and grsecurity will be doubled in size. Since several grsecurity
66817+ features use additional randomness, it is recommended that you say Y
66818+ here. Saying Y here has a similar effect as modifying
66819+ /proc/sys/kernel/random/poolsize.
66820+
66821+config GRKERNSEC_BLACKHOLE
66822+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
66823+ default y if GRKERNSEC_CONFIG_AUTO
66824+ depends on NET
66825+ help
66826+ If you say Y here, neither TCP resets nor ICMP
66827+ destination-unreachable packets will be sent in response to packets
66828+ sent to ports for which no associated listening process exists.
66829+ This feature supports both IPV4 and IPV6 and exempts the
66830+ loopback interface from blackholing. Enabling this feature
66831+ makes a host more resilient to DoS attacks and reduces network
66832+ visibility against scanners.
66833+
66834+ The blackhole feature as-implemented is equivalent to the FreeBSD
66835+ blackhole feature, as it prevents RST responses to all packets, not
66836+ just SYNs. Under most application behavior this causes no
66837+ problems, but applications (like haproxy) may not close certain
66838+ connections in a way that cleanly terminates them on the remote
66839+ end, leaving the remote host in LAST_ACK state. Because of this
66840+ side-effect and to prevent intentional LAST_ACK DoSes, this
66841+ feature also adds automatic mitigation against such attacks.
66842+ The mitigation drastically reduces the amount of time a socket
66843+ can spend in LAST_ACK state. If you're using haproxy and not
66844+ all servers it connects to have this option enabled, consider
66845+ disabling this feature on the haproxy host.
66846+
66847+ If the sysctl option is enabled, two sysctl options with names
66848+ "ip_blackhole" and "lastack_retries" will be created.
66849+ While "ip_blackhole" takes the standard zero/non-zero on/off
66850+ toggle, "lastack_retries" uses the same kinds of values as
66851+ "tcp_retries1" and "tcp_retries2". The default value of 4
66852+ prevents a socket from lasting more than 45 seconds in LAST_ACK
66853+ state.
66854+
66855+config GRKERNSEC_NO_SIMULT_CONNECT
66856+ bool "Disable TCP Simultaneous Connect"
66857+ default y if GRKERNSEC_CONFIG_AUTO
66858+ depends on NET
66859+ help
66860+ If you say Y here, a feature by Willy Tarreau will be enabled that
66861+ removes a weakness in Linux's strict implementation of TCP that
66862+ allows two clients to connect to each other without either entering
66863+ a listening state. The weakness allows an attacker to easily prevent
66864+ a client from connecting to a known server provided the source port
66865+ for the connection is guessed correctly.
66866+
66867+ As the weakness could be used to prevent an antivirus or IPS from
66868+ fetching updates, or prevent an SSL gateway from fetching a CRL,
66869+ it should be eliminated by enabling this option. Though Linux is
66870+ one of few operating systems supporting simultaneous connect, it
66871+ has no legitimate use in practice and is rarely supported by firewalls.
66872+
66873+config GRKERNSEC_SOCKET
66874+ bool "Socket restrictions"
66875+ depends on NET
66876+ help
66877+ If you say Y here, you will be able to choose from several options.
66878+ If you assign a GID on your system and add it to the supplementary
66879+ groups of users you want to restrict socket access to, this patch
66880+ will perform up to three things, based on the option(s) you choose.
66881+
66882+config GRKERNSEC_SOCKET_ALL
66883+ bool "Deny any sockets to group"
66884+ depends on GRKERNSEC_SOCKET
66885+ help
66886+ If you say Y here, you will be able to choose a GID of whose users will
66887+ be unable to connect to other hosts from your machine or run server
66888+ applications from your machine. If the sysctl option is enabled, a
66889+ sysctl option with name "socket_all" is created.
66890+
66891+config GRKERNSEC_SOCKET_ALL_GID
66892+ int "GID to deny all sockets for"
66893+ depends on GRKERNSEC_SOCKET_ALL
66894+ default 1004
66895+ help
66896+ Here you can choose the GID to disable socket access for. Remember to
66897+ add the users you want socket access disabled for to the GID
66898+ specified here. If the sysctl option is enabled, a sysctl option
66899+ with name "socket_all_gid" is created.
66900+
66901+config GRKERNSEC_SOCKET_CLIENT
66902+ bool "Deny client sockets to group"
66903+ depends on GRKERNSEC_SOCKET
66904+ help
66905+ If you say Y here, you will be able to choose a GID of whose users will
66906+ be unable to connect to other hosts from your machine, but will be
66907+ able to run servers. If this option is enabled, all users in the group
66908+ you specify will have to use passive mode when initiating ftp transfers
66909+ from the shell on your machine. If the sysctl option is enabled, a
66910+ sysctl option with name "socket_client" is created.
66911+
66912+config GRKERNSEC_SOCKET_CLIENT_GID
66913+ int "GID to deny client sockets for"
66914+ depends on GRKERNSEC_SOCKET_CLIENT
66915+ default 1003
66916+ help
66917+ Here you can choose the GID to disable client socket access for.
66918+ Remember to add the users you want client socket access disabled for to
66919+ the GID specified here. If the sysctl option is enabled, a sysctl
66920+ option with name "socket_client_gid" is created.
66921+
66922+config GRKERNSEC_SOCKET_SERVER
66923+ bool "Deny server sockets to group"
66924+ depends on GRKERNSEC_SOCKET
66925+ help
66926+ If you say Y here, you will be able to choose a GID of whose users will
66927+ be unable to run server applications from your machine. If the sysctl
66928+ option is enabled, a sysctl option with name "socket_server" is created.
66929+
66930+config GRKERNSEC_SOCKET_SERVER_GID
66931+ int "GID to deny server sockets for"
66932+ depends on GRKERNSEC_SOCKET_SERVER
66933+ default 1002
66934+ help
66935+ Here you can choose the GID to disable server socket access for.
66936+ Remember to add the users you want server socket access disabled for to
66937+ the GID specified here. If the sysctl option is enabled, a sysctl
66938+ option with name "socket_server_gid" is created.
66939+
66940+endmenu
66941+
66942+menu "Physical Protections"
66943+depends on GRKERNSEC
66944+
66945+config GRKERNSEC_DENYUSB
66946+ bool "Deny new USB connections after toggle"
66947+ default y if GRKERNSEC_CONFIG_AUTO
66948+ depends on SYSCTL && USB_SUPPORT
66949+ help
66950+ If you say Y here, a new sysctl option with name "deny_new_usb"
66951+ will be created. Setting its value to 1 will prevent any new
66952+ USB devices from being recognized by the OS. Any attempted USB
66953+ device insertion will be logged. This option is intended to be
66954+ used against custom USB devices designed to exploit vulnerabilities
66955+ in various USB device drivers.
66956+
66957+ For greatest effectiveness, this sysctl should be set after any
66958+ relevant init scripts. This option is safe to enable in distros
66959+ as each user can choose whether or not to toggle the sysctl.
66960+
66961+config GRKERNSEC_DENYUSB_FORCE
66962+ bool "Reject all USB devices not connected at boot"
66963+ select USB
66964+ depends on GRKERNSEC_DENYUSB
66965+ help
66966+ If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
66967+ that doesn't involve a sysctl entry. This option should only be
66968+ enabled if you're sure you want to deny all new USB connections
66969+ at runtime and don't want to modify init scripts. This should not
66970+ be enabled by distros. It forces the core USB code to be built
66971+ into the kernel image so that all devices connected at boot time
66972+ can be recognized and new USB device connections can be prevented
66973+ prior to init running.
66974+
66975+endmenu
66976+
66977+menu "Sysctl Support"
66978+depends on GRKERNSEC && SYSCTL
66979+
66980+config GRKERNSEC_SYSCTL
66981+ bool "Sysctl support"
66982+ default y if GRKERNSEC_CONFIG_AUTO
66983+ help
66984+ If you say Y here, you will be able to change the options that
66985+ grsecurity runs with at bootup, without having to recompile your
66986+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
66987+ to enable (1) or disable (0) various features. All the sysctl entries
66988+ are mutable until the "grsec_lock" entry is set to a non-zero value.
66989+ All features enabled in the kernel configuration are disabled at boot
66990+ if you do not say Y to the "Turn on features by default" option.
66991+ All options should be set at startup, and the grsec_lock entry should
66992+ be set to a non-zero value after all the options are set.
66993+ *THIS IS EXTREMELY IMPORTANT*
66994+
66995+config GRKERNSEC_SYSCTL_DISTRO
66996+ bool "Extra sysctl support for distro makers (READ HELP)"
66997+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
66998+ help
66999+ If you say Y here, additional sysctl options will be created
67000+ for features that affect processes running as root. Therefore,
67001+ it is critical when using this option that the grsec_lock entry be
67002+ enabled after boot. Only distros with prebuilt kernel packages
67003+ with this option enabled that can ensure grsec_lock is enabled
67004+ after boot should use this option.
67005+ *Failure to set grsec_lock after boot makes all grsec features
67006+ this option covers useless*
67007+
67008+ Currently this option creates the following sysctl entries:
67009+ "Disable Privileged I/O": "disable_priv_io"
67010+
67011+config GRKERNSEC_SYSCTL_ON
67012+ bool "Turn on features by default"
67013+ default y if GRKERNSEC_CONFIG_AUTO
67014+ depends on GRKERNSEC_SYSCTL
67015+ help
67016+ If you say Y here, instead of having all features enabled in the
67017+ kernel configuration disabled at boot time, the features will be
67018+ enabled at boot time. It is recommended you say Y here unless
67019+ there is some reason you would want all sysctl-tunable features to
67020+ be disabled by default. As mentioned elsewhere, it is important
67021+ to enable the grsec_lock entry once you have finished modifying
67022+ the sysctl entries.
67023+
67024+endmenu
67025+menu "Logging Options"
67026+depends on GRKERNSEC
67027+
67028+config GRKERNSEC_FLOODTIME
67029+ int "Seconds in between log messages (minimum)"
67030+ default 10
67031+ help
67032+ This option allows you to enforce the number of seconds between
67033+ grsecurity log messages. The default should be suitable for most
67034+ people, however, if you choose to change it, choose a value small enough
67035+ to allow informative logs to be produced, but large enough to
67036+ prevent flooding.
67037+
67038+ Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
67039+ any rate limiting on grsecurity log messages.
67040+
67041+config GRKERNSEC_FLOODBURST
67042+ int "Number of messages in a burst (maximum)"
67043+ default 6
67044+ help
67045+ This option allows you to choose the maximum number of messages allowed
67046+ within the flood time interval you chose in a separate option. The
67047+ default should be suitable for most people, however if you find that
67048+ many of your logs are being interpreted as flooding, you may want to
67049+ raise this value.
67050+
67051+ Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
67052+ any rate limiting on grsecurity log messages.
67053+
67054+endmenu
67055diff --git a/grsecurity/Makefile b/grsecurity/Makefile
67056new file mode 100644
67057index 0000000..30ababb
67058--- /dev/null
67059+++ b/grsecurity/Makefile
67060@@ -0,0 +1,54 @@
67061+# grsecurity – access control and security hardening for Linux
67062+# All code in this directory and various hooks located throughout the Linux kernel are
67063+# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
67064+# http://www.grsecurity.net spender@grsecurity.net
67065+#
67066+# This program is free software; you can redistribute it and/or
67067+# modify it under the terms of the GNU General Public License version 2
67068+# as published by the Free Software Foundation.
67069+#
67070+# This program is distributed in the hope that it will be useful,
67071+# but WITHOUT ANY WARRANTY; without even the implied warranty of
67072+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
67073+# GNU General Public License for more details.
67074+#
67075+# You should have received a copy of the GNU General Public License
67076+# along with this program; if not, write to the Free Software
67077+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
67078+
67079+KBUILD_CFLAGS += -Werror
67080+
67081+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
67082+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
67083+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
67084+ grsec_usb.o grsec_ipc.o grsec_proc.o
67085+
67086+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
67087+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
67088+ gracl_learn.o grsec_log.o gracl_policy.o
67089+ifdef CONFIG_COMPAT
67090+obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
67091+endif
67092+
67093+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
67094+
67095+ifdef CONFIG_NET
67096+obj-y += grsec_sock.o
67097+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
67098+endif
67099+
67100+ifndef CONFIG_GRKERNSEC
67101+obj-y += grsec_disabled.o
67102+endif
67103+
67104+ifdef CONFIG_GRKERNSEC_HIDESYM
67105+extra-y := grsec_hidesym.o
67106+$(obj)/grsec_hidesym.o:
67107+ @-chmod -f 500 /boot
67108+ @-chmod -f 500 /lib/modules
67109+ @-chmod -f 500 /lib64/modules
67110+ @-chmod -f 500 /lib32/modules
67111+ @-chmod -f 700 .
67112+ @-chmod -f 700 $(objtree)
67113+ @echo ' grsec: protected kernel image paths'
67114+endif
67115diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
67116new file mode 100644
67117index 0000000..e56396f
67118--- /dev/null
67119+++ b/grsecurity/gracl.c
67120@@ -0,0 +1,2679 @@
67121+#include <linux/kernel.h>
67122+#include <linux/module.h>
67123+#include <linux/sched.h>
67124+#include <linux/mm.h>
67125+#include <linux/file.h>
67126+#include <linux/fs.h>
67127+#include <linux/namei.h>
67128+#include <linux/mount.h>
67129+#include <linux/tty.h>
67130+#include <linux/proc_fs.h>
67131+#include <linux/lglock.h>
67132+#include <linux/slab.h>
67133+#include <linux/vmalloc.h>
67134+#include <linux/types.h>
67135+#include <linux/sysctl.h>
67136+#include <linux/netdevice.h>
67137+#include <linux/ptrace.h>
67138+#include <linux/gracl.h>
67139+#include <linux/gralloc.h>
67140+#include <linux/security.h>
67141+#include <linux/grinternal.h>
67142+#include <linux/pid_namespace.h>
67143+#include <linux/stop_machine.h>
67144+#include <linux/fdtable.h>
67145+#include <linux/percpu.h>
67146+#include <linux/lglock.h>
67147+#include <linux/hugetlb.h>
67148+#include <linux/posix-timers.h>
67149+#include <linux/prefetch.h>
67150+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
67151+#include <linux/magic.h>
67152+#include <linux/pagemap.h>
67153+#include "../fs/btrfs/async-thread.h"
67154+#include "../fs/btrfs/ctree.h"
67155+#include "../fs/btrfs/btrfs_inode.h"
67156+#endif
67157+#include "../fs/mount.h"
67158+
67159+#include <asm/uaccess.h>
67160+#include <asm/errno.h>
67161+#include <asm/mman.h>
67162+
67163+#define FOR_EACH_ROLE_START(role) \
67164+ role = running_polstate.role_list; \
67165+ while (role) {
67166+
67167+#define FOR_EACH_ROLE_END(role) \
67168+ role = role->prev; \
67169+ }
67170+
67171+extern struct path gr_real_root;
67172+
67173+static struct gr_policy_state running_polstate;
67174+struct gr_policy_state *polstate = &running_polstate;
67175+extern struct gr_alloc_state *current_alloc_state;
67176+
67177+extern char *gr_shared_page[4];
67178+DEFINE_RWLOCK(gr_inode_lock);
67179+
67180+static unsigned int gr_status __read_only = GR_STATUS_INIT;
67181+
67182+#ifdef CONFIG_NET
67183+extern struct vfsmount *sock_mnt;
67184+#endif
67185+
67186+extern struct vfsmount *pipe_mnt;
67187+extern struct vfsmount *shm_mnt;
67188+
67189+#ifdef CONFIG_HUGETLBFS
67190+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
67191+#endif
67192+
67193+extern u16 acl_sp_role_value;
67194+extern struct acl_object_label *fakefs_obj_rw;
67195+extern struct acl_object_label *fakefs_obj_rwx;
67196+
67197+int gr_acl_is_enabled(void)
67198+{
67199+ return (gr_status & GR_READY);
67200+}
67201+
67202+void gr_enable_rbac_system(void)
67203+{
67204+ pax_open_kernel();
67205+ gr_status |= GR_READY;
67206+ pax_close_kernel();
67207+}
67208+
67209+int gr_rbac_disable(void *unused)
67210+{
67211+ pax_open_kernel();
67212+ gr_status &= ~GR_READY;
67213+ pax_close_kernel();
67214+
67215+ return 0;
67216+}
67217+
67218+static inline dev_t __get_dev(const struct dentry *dentry)
67219+{
67220+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
67221+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
67222+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
67223+ else
67224+#endif
67225+ return dentry->d_sb->s_dev;
67226+}
67227+
67228+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
67229+{
67230+ return __get_dev(dentry);
67231+}
67232+
67233+static char gr_task_roletype_to_char(struct task_struct *task)
67234+{
67235+ switch (task->role->roletype &
67236+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
67237+ GR_ROLE_SPECIAL)) {
67238+ case GR_ROLE_DEFAULT:
67239+ return 'D';
67240+ case GR_ROLE_USER:
67241+ return 'U';
67242+ case GR_ROLE_GROUP:
67243+ return 'G';
67244+ case GR_ROLE_SPECIAL:
67245+ return 'S';
67246+ }
67247+
67248+ return 'X';
67249+}
67250+
67251+char gr_roletype_to_char(void)
67252+{
67253+ return gr_task_roletype_to_char(current);
67254+}
67255+
67256+__inline__ int
67257+gr_acl_tpe_check(void)
67258+{
67259+ if (unlikely(!(gr_status & GR_READY)))
67260+ return 0;
67261+ if (current->role->roletype & GR_ROLE_TPE)
67262+ return 1;
67263+ else
67264+ return 0;
67265+}
67266+
67267+int
67268+gr_handle_rawio(const struct inode *inode)
67269+{
67270+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
67271+ if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
67272+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
67273+ !capable(CAP_SYS_RAWIO))
67274+ return 1;
67275+#endif
67276+ return 0;
67277+}
67278+
67279+int
67280+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
67281+{
67282+ if (likely(lena != lenb))
67283+ return 0;
67284+
67285+ return !memcmp(a, b, lena);
67286+}
67287+
67288+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
67289+{
67290+ *buflen -= namelen;
67291+ if (*buflen < 0)
67292+ return -ENAMETOOLONG;
67293+ *buffer -= namelen;
67294+ memcpy(*buffer, str, namelen);
67295+ return 0;
67296+}
67297+
67298+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
67299+{
67300+ return prepend(buffer, buflen, name->name, name->len);
67301+}
67302+
67303+static int prepend_path(const struct path *path, struct path *root,
67304+ char **buffer, int *buflen)
67305+{
67306+ struct dentry *dentry = path->dentry;
67307+ struct vfsmount *vfsmnt = path->mnt;
67308+ struct mount *mnt = real_mount(vfsmnt);
67309+ bool slash = false;
67310+ int error = 0;
67311+
67312+ while (dentry != root->dentry || vfsmnt != root->mnt) {
67313+ struct dentry * parent;
67314+
67315+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
67316+ /* Global root? */
67317+ if (!mnt_has_parent(mnt)) {
67318+ goto out;
67319+ }
67320+ dentry = mnt->mnt_mountpoint;
67321+ mnt = mnt->mnt_parent;
67322+ vfsmnt = &mnt->mnt;
67323+ continue;
67324+ }
67325+ parent = dentry->d_parent;
67326+ prefetch(parent);
67327+ spin_lock(&dentry->d_lock);
67328+ error = prepend_name(buffer, buflen, &dentry->d_name);
67329+ spin_unlock(&dentry->d_lock);
67330+ if (!error)
67331+ error = prepend(buffer, buflen, "/", 1);
67332+ if (error)
67333+ break;
67334+
67335+ slash = true;
67336+ dentry = parent;
67337+ }
67338+
67339+out:
67340+ if (!error && !slash)
67341+ error = prepend(buffer, buflen, "/", 1);
67342+
67343+ return error;
67344+}
67345+
67346+/* this must be called with mount_lock and rename_lock held */
67347+
67348+static char *__our_d_path(const struct path *path, struct path *root,
67349+ char *buf, int buflen)
67350+{
67351+ char *res = buf + buflen;
67352+ int error;
67353+
67354+ prepend(&res, &buflen, "\0", 1);
67355+ error = prepend_path(path, root, &res, &buflen);
67356+ if (error)
67357+ return ERR_PTR(error);
67358+
67359+ return res;
67360+}
67361+
67362+static char *
67363+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
67364+{
67365+ char *retval;
67366+
67367+ retval = __our_d_path(path, root, buf, buflen);
67368+ if (unlikely(IS_ERR(retval)))
67369+ retval = strcpy(buf, "<path too long>");
67370+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
67371+ retval[1] = '\0';
67372+
67373+ return retval;
67374+}
67375+
67376+static char *
67377+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
67378+ char *buf, int buflen)
67379+{
67380+ struct path path;
67381+ char *res;
67382+
67383+ path.dentry = (struct dentry *)dentry;
67384+ path.mnt = (struct vfsmount *)vfsmnt;
67385+
67386+ /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
67387+ by the RBAC system */
67388+ res = gen_full_path(&path, &gr_real_root, buf, buflen);
67389+
67390+ return res;
67391+}
67392+
67393+static char *
67394+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
67395+ char *buf, int buflen)
67396+{
67397+ char *res;
67398+ struct path path;
67399+ struct path root;
67400+ struct task_struct *reaper = init_pid_ns.child_reaper;
67401+
67402+ path.dentry = (struct dentry *)dentry;
67403+ path.mnt = (struct vfsmount *)vfsmnt;
67404+
67405+ /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
67406+ get_fs_root(reaper->fs, &root);
67407+
67408+ read_seqlock_excl(&mount_lock);
67409+ write_seqlock(&rename_lock);
67410+ res = gen_full_path(&path, &root, buf, buflen);
67411+ write_sequnlock(&rename_lock);
67412+ read_sequnlock_excl(&mount_lock);
67413+
67414+ path_put(&root);
67415+ return res;
67416+}
67417+
67418+char *
67419+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
67420+{
67421+ char *ret;
67422+ read_seqlock_excl(&mount_lock);
67423+ write_seqlock(&rename_lock);
67424+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
67425+ PAGE_SIZE);
67426+ write_sequnlock(&rename_lock);
67427+ read_sequnlock_excl(&mount_lock);
67428+ return ret;
67429+}
67430+
67431+static char *
67432+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
67433+{
67434+ char *ret;
67435+ char *buf;
67436+ int buflen;
67437+
67438+ read_seqlock_excl(&mount_lock);
67439+ write_seqlock(&rename_lock);
67440+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
67441+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
67442+ buflen = (int)(ret - buf);
67443+ if (buflen >= 5)
67444+ prepend(&ret, &buflen, "/proc", 5);
67445+ else
67446+ ret = strcpy(buf, "<path too long>");
67447+ write_sequnlock(&rename_lock);
67448+ read_sequnlock_excl(&mount_lock);
67449+ return ret;
67450+}
67451+
67452+char *
67453+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
67454+{
67455+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
67456+ PAGE_SIZE);
67457+}
67458+
67459+char *
67460+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
67461+{
67462+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
67463+ PAGE_SIZE);
67464+}
67465+
67466+char *
67467+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
67468+{
67469+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
67470+ PAGE_SIZE);
67471+}
67472+
67473+char *
67474+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
67475+{
67476+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
67477+ PAGE_SIZE);
67478+}
67479+
67480+char *
67481+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
67482+{
67483+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
67484+ PAGE_SIZE);
67485+}
67486+
67487+__inline__ __u32
67488+to_gr_audit(const __u32 reqmode)
67489+{
67490+ /* masks off auditable permission flags, then shifts them to create
67491+ auditing flags, and adds the special case of append auditing if
67492+ we're requesting write */
67493+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
67494+}
67495+
67496+struct acl_role_label *
67497+__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
67498+ const gid_t gid)
67499+{
67500+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
67501+ struct acl_role_label *match;
67502+ struct role_allowed_ip *ipp;
67503+ unsigned int x;
67504+ u32 curr_ip = task->signal->saved_ip;
67505+
67506+ match = state->acl_role_set.r_hash[index];
67507+
67508+ while (match) {
67509+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
67510+ for (x = 0; x < match->domain_child_num; x++) {
67511+ if (match->domain_children[x] == uid)
67512+ goto found;
67513+ }
67514+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
67515+ break;
67516+ match = match->next;
67517+ }
67518+found:
67519+ if (match == NULL) {
67520+ try_group:
67521+ index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
67522+ match = state->acl_role_set.r_hash[index];
67523+
67524+ while (match) {
67525+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
67526+ for (x = 0; x < match->domain_child_num; x++) {
67527+ if (match->domain_children[x] == gid)
67528+ goto found2;
67529+ }
67530+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
67531+ break;
67532+ match = match->next;
67533+ }
67534+found2:
67535+ if (match == NULL)
67536+ match = state->default_role;
67537+ if (match->allowed_ips == NULL)
67538+ return match;
67539+ else {
67540+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
67541+ if (likely
67542+ ((ntohl(curr_ip) & ipp->netmask) ==
67543+ (ntohl(ipp->addr) & ipp->netmask)))
67544+ return match;
67545+ }
67546+ match = state->default_role;
67547+ }
67548+ } else if (match->allowed_ips == NULL) {
67549+ return match;
67550+ } else {
67551+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
67552+ if (likely
67553+ ((ntohl(curr_ip) & ipp->netmask) ==
67554+ (ntohl(ipp->addr) & ipp->netmask)))
67555+ return match;
67556+ }
67557+ goto try_group;
67558+ }
67559+
67560+ return match;
67561+}
67562+
67563+static struct acl_role_label *
67564+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
67565+ const gid_t gid)
67566+{
67567+ return __lookup_acl_role_label(&running_polstate, task, uid, gid);
67568+}
67569+
67570+struct acl_subject_label *
67571+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
67572+ const struct acl_role_label *role)
67573+{
67574+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
67575+ struct acl_subject_label *match;
67576+
67577+ match = role->subj_hash[index];
67578+
67579+ while (match && (match->inode != ino || match->device != dev ||
67580+ (match->mode & GR_DELETED))) {
67581+ match = match->next;
67582+ }
67583+
67584+ if (match && !(match->mode & GR_DELETED))
67585+ return match;
67586+ else
67587+ return NULL;
67588+}
67589+
67590+struct acl_subject_label *
67591+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
67592+ const struct acl_role_label *role)
67593+{
67594+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
67595+ struct acl_subject_label *match;
67596+
67597+ match = role->subj_hash[index];
67598+
67599+ while (match && (match->inode != ino || match->device != dev ||
67600+ !(match->mode & GR_DELETED))) {
67601+ match = match->next;
67602+ }
67603+
67604+ if (match && (match->mode & GR_DELETED))
67605+ return match;
67606+ else
67607+ return NULL;
67608+}
67609+
67610+static struct acl_object_label *
67611+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
67612+ const struct acl_subject_label *subj)
67613+{
67614+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
67615+ struct acl_object_label *match;
67616+
67617+ match = subj->obj_hash[index];
67618+
67619+ while (match && (match->inode != ino || match->device != dev ||
67620+ (match->mode & GR_DELETED))) {
67621+ match = match->next;
67622+ }
67623+
67624+ if (match && !(match->mode & GR_DELETED))
67625+ return match;
67626+ else
67627+ return NULL;
67628+}
67629+
67630+static struct acl_object_label *
67631+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
67632+ const struct acl_subject_label *subj)
67633+{
67634+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
67635+ struct acl_object_label *match;
67636+
67637+ match = subj->obj_hash[index];
67638+
67639+ while (match && (match->inode != ino || match->device != dev ||
67640+ !(match->mode & GR_DELETED))) {
67641+ match = match->next;
67642+ }
67643+
67644+ if (match && (match->mode & GR_DELETED))
67645+ return match;
67646+
67647+ match = subj->obj_hash[index];
67648+
67649+ while (match && (match->inode != ino || match->device != dev ||
67650+ (match->mode & GR_DELETED))) {
67651+ match = match->next;
67652+ }
67653+
67654+ if (match && !(match->mode & GR_DELETED))
67655+ return match;
67656+ else
67657+ return NULL;
67658+}
67659+
67660+struct name_entry *
67661+__lookup_name_entry(const struct gr_policy_state *state, const char *name)
67662+{
67663+ unsigned int len = strlen(name);
67664+ unsigned int key = full_name_hash(name, len);
67665+ unsigned int index = key % state->name_set.n_size;
67666+ struct name_entry *match;
67667+
67668+ match = state->name_set.n_hash[index];
67669+
67670+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
67671+ match = match->next;
67672+
67673+ return match;
67674+}
67675+
67676+static struct name_entry *
67677+lookup_name_entry(const char *name)
67678+{
67679+ return __lookup_name_entry(&running_polstate, name);
67680+}
67681+
67682+static struct name_entry *
67683+lookup_name_entry_create(const char *name)
67684+{
67685+ unsigned int len = strlen(name);
67686+ unsigned int key = full_name_hash(name, len);
67687+ unsigned int index = key % running_polstate.name_set.n_size;
67688+ struct name_entry *match;
67689+
67690+ match = running_polstate.name_set.n_hash[index];
67691+
67692+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
67693+ !match->deleted))
67694+ match = match->next;
67695+
67696+ if (match && match->deleted)
67697+ return match;
67698+
67699+ match = running_polstate.name_set.n_hash[index];
67700+
67701+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
67702+ match->deleted))
67703+ match = match->next;
67704+
67705+ if (match && !match->deleted)
67706+ return match;
67707+ else
67708+ return NULL;
67709+}
67710+
67711+static struct inodev_entry *
67712+lookup_inodev_entry(const ino_t ino, const dev_t dev)
67713+{
67714+ unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
67715+ struct inodev_entry *match;
67716+
67717+ match = running_polstate.inodev_set.i_hash[index];
67718+
67719+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
67720+ match = match->next;
67721+
67722+ return match;
67723+}
67724+
67725+void
67726+__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
67727+{
67728+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
67729+ state->inodev_set.i_size);
67730+ struct inodev_entry **curr;
67731+
67732+ entry->prev = NULL;
67733+
67734+ curr = &state->inodev_set.i_hash[index];
67735+ if (*curr != NULL)
67736+ (*curr)->prev = entry;
67737+
67738+ entry->next = *curr;
67739+ *curr = entry;
67740+
67741+ return;
67742+}
67743+
67744+static void
67745+insert_inodev_entry(struct inodev_entry *entry)
67746+{
67747+ __insert_inodev_entry(&running_polstate, entry);
67748+}
67749+
67750+void
67751+insert_acl_obj_label(struct acl_object_label *obj,
67752+ struct acl_subject_label *subj)
67753+{
67754+ unsigned int index =
67755+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
67756+ struct acl_object_label **curr;
67757+
67758+ obj->prev = NULL;
67759+
67760+ curr = &subj->obj_hash[index];
67761+ if (*curr != NULL)
67762+ (*curr)->prev = obj;
67763+
67764+ obj->next = *curr;
67765+ *curr = obj;
67766+
67767+ return;
67768+}
67769+
67770+void
67771+insert_acl_subj_label(struct acl_subject_label *obj,
67772+ struct acl_role_label *role)
67773+{
67774+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
67775+ struct acl_subject_label **curr;
67776+
67777+ obj->prev = NULL;
67778+
67779+ curr = &role->subj_hash[index];
67780+ if (*curr != NULL)
67781+ (*curr)->prev = obj;
67782+
67783+ obj->next = *curr;
67784+ *curr = obj;
67785+
67786+ return;
67787+}
67788+
67789+/* derived from glibc fnmatch() 0: match, 1: no match*/
67790+
67791+static int
67792+glob_match(const char *p, const char *n)
67793+{
67794+ char c;
67795+
67796+ while ((c = *p++) != '\0') {
67797+ switch (c) {
67798+ case '?':
67799+ if (*n == '\0')
67800+ return 1;
67801+ else if (*n == '/')
67802+ return 1;
67803+ break;
67804+ case '\\':
67805+ if (*n != c)
67806+ return 1;
67807+ break;
67808+ case '*':
67809+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
67810+ if (*n == '/')
67811+ return 1;
67812+ else if (c == '?') {
67813+ if (*n == '\0')
67814+ return 1;
67815+ else
67816+ ++n;
67817+ }
67818+ }
67819+ if (c == '\0') {
67820+ return 0;
67821+ } else {
67822+ const char *endp;
67823+
67824+ if ((endp = strchr(n, '/')) == NULL)
67825+ endp = n + strlen(n);
67826+
67827+ if (c == '[') {
67828+ for (--p; n < endp; ++n)
67829+ if (!glob_match(p, n))
67830+ return 0;
67831+ } else if (c == '/') {
67832+ while (*n != '\0' && *n != '/')
67833+ ++n;
67834+ if (*n == '/' && !glob_match(p, n + 1))
67835+ return 0;
67836+ } else {
67837+ for (--p; n < endp; ++n)
67838+ if (*n == c && !glob_match(p, n))
67839+ return 0;
67840+ }
67841+
67842+ return 1;
67843+ }
67844+ case '[':
67845+ {
67846+ int not;
67847+ char cold;
67848+
67849+ if (*n == '\0' || *n == '/')
67850+ return 1;
67851+
67852+ not = (*p == '!' || *p == '^');
67853+ if (not)
67854+ ++p;
67855+
67856+ c = *p++;
67857+ for (;;) {
67858+ unsigned char fn = (unsigned char)*n;
67859+
67860+ if (c == '\0')
67861+ return 1;
67862+ else {
67863+ if (c == fn)
67864+ goto matched;
67865+ cold = c;
67866+ c = *p++;
67867+
67868+ if (c == '-' && *p != ']') {
67869+ unsigned char cend = *p++;
67870+
67871+ if (cend == '\0')
67872+ return 1;
67873+
67874+ if (cold <= fn && fn <= cend)
67875+ goto matched;
67876+
67877+ c = *p++;
67878+ }
67879+ }
67880+
67881+ if (c == ']')
67882+ break;
67883+ }
67884+ if (!not)
67885+ return 1;
67886+ break;
67887+ matched:
67888+ while (c != ']') {
67889+ if (c == '\0')
67890+ return 1;
67891+
67892+ c = *p++;
67893+ }
67894+ if (not)
67895+ return 1;
67896+ }
67897+ break;
67898+ default:
67899+ if (c != *n)
67900+ return 1;
67901+ }
67902+
67903+ ++n;
67904+ }
67905+
67906+ if (*n == '\0')
67907+ return 0;
67908+
67909+ if (*n == '/')
67910+ return 0;
67911+
67912+ return 1;
67913+}
67914+
67915+static struct acl_object_label *
67916+chk_glob_label(struct acl_object_label *globbed,
67917+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
67918+{
67919+ struct acl_object_label *tmp;
67920+
67921+ if (*path == NULL)
67922+ *path = gr_to_filename_nolock(dentry, mnt);
67923+
67924+ tmp = globbed;
67925+
67926+ while (tmp) {
67927+ if (!glob_match(tmp->filename, *path))
67928+ return tmp;
67929+ tmp = tmp->next;
67930+ }
67931+
67932+ return NULL;
67933+}
67934+
67935+static struct acl_object_label *
67936+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
67937+ const ino_t curr_ino, const dev_t curr_dev,
67938+ const struct acl_subject_label *subj, char **path, const int checkglob)
67939+{
67940+ struct acl_subject_label *tmpsubj;
67941+ struct acl_object_label *retval;
67942+ struct acl_object_label *retval2;
67943+
67944+ tmpsubj = (struct acl_subject_label *) subj;
67945+ read_lock(&gr_inode_lock);
67946+ do {
67947+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
67948+ if (retval) {
67949+ if (checkglob && retval->globbed) {
67950+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
67951+ if (retval2)
67952+ retval = retval2;
67953+ }
67954+ break;
67955+ }
67956+ } while ((tmpsubj = tmpsubj->parent_subject));
67957+ read_unlock(&gr_inode_lock);
67958+
67959+ return retval;
67960+}
67961+
67962+static __inline__ struct acl_object_label *
67963+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
67964+ struct dentry *curr_dentry,
67965+ const struct acl_subject_label *subj, char **path, const int checkglob)
67966+{
67967+ int newglob = checkglob;
67968+ ino_t inode;
67969+ dev_t device;
67970+
67971+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
67972+ as we don't want a / * rule to match instead of the / object
67973+ don't do this for create lookups that call this function though, since they're looking up
67974+ on the parent and thus need globbing checks on all paths
67975+ */
67976+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
67977+ newglob = GR_NO_GLOB;
67978+
67979+ spin_lock(&curr_dentry->d_lock);
67980+ inode = curr_dentry->d_inode->i_ino;
67981+ device = __get_dev(curr_dentry);
67982+ spin_unlock(&curr_dentry->d_lock);
67983+
67984+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
67985+}
67986+
67987+#ifdef CONFIG_HUGETLBFS
67988+static inline bool
67989+is_hugetlbfs_mnt(const struct vfsmount *mnt)
67990+{
67991+ int i;
67992+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
67993+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
67994+ return true;
67995+ }
67996+
67997+ return false;
67998+}
67999+#endif
68000+
68001+static struct acl_object_label *
68002+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68003+ const struct acl_subject_label *subj, char *path, const int checkglob)
68004+{
68005+ struct dentry *dentry = (struct dentry *) l_dentry;
68006+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
68007+ struct mount *real_mnt = real_mount(mnt);
68008+ struct acl_object_label *retval;
68009+ struct dentry *parent;
68010+
68011+ read_seqlock_excl(&mount_lock);
68012+ write_seqlock(&rename_lock);
68013+
68014+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
68015+#ifdef CONFIG_NET
68016+ mnt == sock_mnt ||
68017+#endif
68018+#ifdef CONFIG_HUGETLBFS
68019+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
68020+#endif
68021+ /* ignore Eric Biederman */
68022+ IS_PRIVATE(l_dentry->d_inode))) {
68023+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
68024+ goto out;
68025+ }
68026+
68027+ for (;;) {
68028+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
68029+ break;
68030+
68031+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
68032+ if (!mnt_has_parent(real_mnt))
68033+ break;
68034+
68035+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
68036+ if (retval != NULL)
68037+ goto out;
68038+
68039+ dentry = real_mnt->mnt_mountpoint;
68040+ real_mnt = real_mnt->mnt_parent;
68041+ mnt = &real_mnt->mnt;
68042+ continue;
68043+ }
68044+
68045+ parent = dentry->d_parent;
68046+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
68047+ if (retval != NULL)
68048+ goto out;
68049+
68050+ dentry = parent;
68051+ }
68052+
68053+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
68054+
68055+ /* gr_real_root is pinned so we don't have to hold a reference */
68056+ if (retval == NULL)
68057+ retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
68058+out:
68059+ write_sequnlock(&rename_lock);
68060+ read_sequnlock_excl(&mount_lock);
68061+
68062+ BUG_ON(retval == NULL);
68063+
68064+ return retval;
68065+}
68066+
68067+static __inline__ struct acl_object_label *
68068+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68069+ const struct acl_subject_label *subj)
68070+{
68071+ char *path = NULL;
68072+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
68073+}
68074+
68075+static __inline__ struct acl_object_label *
68076+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68077+ const struct acl_subject_label *subj)
68078+{
68079+ char *path = NULL;
68080+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
68081+}
68082+
68083+static __inline__ struct acl_object_label *
68084+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68085+ const struct acl_subject_label *subj, char *path)
68086+{
68087+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
68088+}
68089+
68090+struct acl_subject_label *
68091+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68092+ const struct acl_role_label *role)
68093+{
68094+ struct dentry *dentry = (struct dentry *) l_dentry;
68095+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
68096+ struct mount *real_mnt = real_mount(mnt);
68097+ struct acl_subject_label *retval;
68098+ struct dentry *parent;
68099+
68100+ read_seqlock_excl(&mount_lock);
68101+ write_seqlock(&rename_lock);
68102+
68103+ for (;;) {
68104+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
68105+ break;
68106+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
68107+ if (!mnt_has_parent(real_mnt))
68108+ break;
68109+
68110+ spin_lock(&dentry->d_lock);
68111+ read_lock(&gr_inode_lock);
68112+ retval =
68113+ lookup_acl_subj_label(dentry->d_inode->i_ino,
68114+ __get_dev(dentry), role);
68115+ read_unlock(&gr_inode_lock);
68116+ spin_unlock(&dentry->d_lock);
68117+ if (retval != NULL)
68118+ goto out;
68119+
68120+ dentry = real_mnt->mnt_mountpoint;
68121+ real_mnt = real_mnt->mnt_parent;
68122+ mnt = &real_mnt->mnt;
68123+ continue;
68124+ }
68125+
68126+ spin_lock(&dentry->d_lock);
68127+ read_lock(&gr_inode_lock);
68128+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
68129+ __get_dev(dentry), role);
68130+ read_unlock(&gr_inode_lock);
68131+ parent = dentry->d_parent;
68132+ spin_unlock(&dentry->d_lock);
68133+
68134+ if (retval != NULL)
68135+ goto out;
68136+
68137+ dentry = parent;
68138+ }
68139+
68140+ spin_lock(&dentry->d_lock);
68141+ read_lock(&gr_inode_lock);
68142+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
68143+ __get_dev(dentry), role);
68144+ read_unlock(&gr_inode_lock);
68145+ spin_unlock(&dentry->d_lock);
68146+
68147+ if (unlikely(retval == NULL)) {
68148+ /* gr_real_root is pinned, we don't need to hold a reference */
68149+ read_lock(&gr_inode_lock);
68150+ retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
68151+ __get_dev(gr_real_root.dentry), role);
68152+ read_unlock(&gr_inode_lock);
68153+ }
68154+out:
68155+ write_sequnlock(&rename_lock);
68156+ read_sequnlock_excl(&mount_lock);
68157+
68158+ BUG_ON(retval == NULL);
68159+
68160+ return retval;
68161+}
68162+
68163+void
68164+assign_special_role(const char *rolename)
68165+{
68166+ struct acl_object_label *obj;
68167+ struct acl_role_label *r;
68168+ struct acl_role_label *assigned = NULL;
68169+ struct task_struct *tsk;
68170+ struct file *filp;
68171+
68172+ FOR_EACH_ROLE_START(r)
68173+ if (!strcmp(rolename, r->rolename) &&
68174+ (r->roletype & GR_ROLE_SPECIAL)) {
68175+ assigned = r;
68176+ break;
68177+ }
68178+ FOR_EACH_ROLE_END(r)
68179+
68180+ if (!assigned)
68181+ return;
68182+
68183+ read_lock(&tasklist_lock);
68184+ read_lock(&grsec_exec_file_lock);
68185+
68186+ tsk = current->real_parent;
68187+ if (tsk == NULL)
68188+ goto out_unlock;
68189+
68190+ filp = tsk->exec_file;
68191+ if (filp == NULL)
68192+ goto out_unlock;
68193+
68194+ tsk->is_writable = 0;
68195+ tsk->inherited = 0;
68196+
68197+ tsk->acl_sp_role = 1;
68198+ tsk->acl_role_id = ++acl_sp_role_value;
68199+ tsk->role = assigned;
68200+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
68201+
68202+ /* ignore additional mmap checks for processes that are writable
68203+ by the default ACL */
68204+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
68205+ if (unlikely(obj->mode & GR_WRITE))
68206+ tsk->is_writable = 1;
68207+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
68208+ if (unlikely(obj->mode & GR_WRITE))
68209+ tsk->is_writable = 1;
68210+
68211+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68212+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
68213+ tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
68214+#endif
68215+
68216+out_unlock:
68217+ read_unlock(&grsec_exec_file_lock);
68218+ read_unlock(&tasklist_lock);
68219+ return;
68220+}
68221+
68222+
68223+static void
68224+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
68225+{
68226+ struct task_struct *task = current;
68227+ const struct cred *cred = current_cred();
68228+
68229+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
68230+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
68231+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
68232+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
68233+
68234+ return;
68235+}
68236+
68237+static void
68238+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
68239+{
68240+ struct task_struct *task = current;
68241+ const struct cred *cred = current_cred();
68242+
68243+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
68244+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
68245+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
68246+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
68247+
68248+ return;
68249+}
68250+
68251+static void
68252+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
68253+{
68254+ struct task_struct *task = current;
68255+ const struct cred *cred = current_cred();
68256+
68257+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
68258+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
68259+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
68260+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
68261+
68262+ return;
68263+}
68264+
68265+static void
68266+gr_set_proc_res(struct task_struct *task)
68267+{
68268+ struct acl_subject_label *proc;
68269+ unsigned short i;
68270+
68271+ proc = task->acl;
68272+
68273+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
68274+ return;
68275+
68276+ for (i = 0; i < RLIM_NLIMITS; i++) {
68277+ if (!(proc->resmask & (1U << i)))
68278+ continue;
68279+
68280+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
68281+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
68282+
68283+ if (i == RLIMIT_CPU)
68284+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
68285+ }
68286+
68287+ return;
68288+}
68289+
68290+/* both of the below must be called with
68291+ rcu_read_lock();
68292+ read_lock(&tasklist_lock);
68293+ read_lock(&grsec_exec_file_lock);
68294+*/
68295+
68296+struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
68297+{
68298+ char *tmpname;
68299+ struct acl_subject_label *tmpsubj;
68300+ struct file *filp;
68301+ struct name_entry *nmatch;
68302+
68303+ filp = task->exec_file;
68304+ if (filp == NULL)
68305+ return NULL;
68306+
68307+ /* the following is to apply the correct subject
68308+ on binaries running when the RBAC system
68309+ is enabled, when the binaries have been
68310+ replaced or deleted since their execution
68311+ -----
68312+ when the RBAC system starts, the inode/dev
68313+ from exec_file will be one the RBAC system
68314+ is unaware of. It only knows the inode/dev
68315+ of the present file on disk, or the absence
68316+ of it.
68317+ */
68318+
68319+ if (filename)
68320+ nmatch = __lookup_name_entry(state, filename);
68321+ else {
68322+ preempt_disable();
68323+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
68324+
68325+ nmatch = __lookup_name_entry(state, tmpname);
68326+ preempt_enable();
68327+ }
68328+ tmpsubj = NULL;
68329+ if (nmatch) {
68330+ if (nmatch->deleted)
68331+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
68332+ else
68333+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
68334+ }
68335+ /* this also works for the reload case -- if we don't match a potentially inherited subject
68336+ then we fall back to a normal lookup based on the binary's ino/dev
68337+ */
68338+ if (tmpsubj == NULL)
68339+ tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
68340+
68341+ return tmpsubj;
68342+}
68343+
68344+static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
68345+{
68346+ return __gr_get_subject_for_task(&running_polstate, task, filename);
68347+}
68348+
68349+void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
68350+{
68351+ struct acl_object_label *obj;
68352+ struct file *filp;
68353+
68354+ filp = task->exec_file;
68355+
68356+ task->acl = subj;
68357+ task->is_writable = 0;
68358+ /* ignore additional mmap checks for processes that are writable
68359+ by the default ACL */
68360+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
68361+ if (unlikely(obj->mode & GR_WRITE))
68362+ task->is_writable = 1;
68363+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
68364+ if (unlikely(obj->mode & GR_WRITE))
68365+ task->is_writable = 1;
68366+
68367+ gr_set_proc_res(task);
68368+
68369+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68370+ 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);
68371+#endif
68372+}
68373+
68374+static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
68375+{
68376+ __gr_apply_subject_to_task(&running_polstate, task, subj);
68377+}
68378+
68379+__u32
68380+gr_search_file(const struct dentry * dentry, const __u32 mode,
68381+ const struct vfsmount * mnt)
68382+{
68383+ __u32 retval = mode;
68384+ struct acl_subject_label *curracl;
68385+ struct acl_object_label *currobj;
68386+
68387+ if (unlikely(!(gr_status & GR_READY)))
68388+ return (mode & ~GR_AUDITS);
68389+
68390+ curracl = current->acl;
68391+
68392+ currobj = chk_obj_label(dentry, mnt, curracl);
68393+ retval = currobj->mode & mode;
68394+
68395+ /* if we're opening a specified transfer file for writing
68396+ (e.g. /dev/initctl), then transfer our role to init
68397+ */
68398+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
68399+ current->role->roletype & GR_ROLE_PERSIST)) {
68400+ struct task_struct *task = init_pid_ns.child_reaper;
68401+
68402+ if (task->role != current->role) {
68403+ struct acl_subject_label *subj;
68404+
68405+ task->acl_sp_role = 0;
68406+ task->acl_role_id = current->acl_role_id;
68407+ task->role = current->role;
68408+ rcu_read_lock();
68409+ read_lock(&grsec_exec_file_lock);
68410+ subj = gr_get_subject_for_task(task, NULL);
68411+ gr_apply_subject_to_task(task, subj);
68412+ read_unlock(&grsec_exec_file_lock);
68413+ rcu_read_unlock();
68414+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
68415+ }
68416+ }
68417+
68418+ if (unlikely
68419+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
68420+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
68421+ __u32 new_mode = mode;
68422+
68423+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
68424+
68425+ retval = new_mode;
68426+
68427+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
68428+ new_mode |= GR_INHERIT;
68429+
68430+ if (!(mode & GR_NOLEARN))
68431+ gr_log_learn(dentry, mnt, new_mode);
68432+ }
68433+
68434+ return retval;
68435+}
68436+
68437+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
68438+ const struct dentry *parent,
68439+ const struct vfsmount *mnt)
68440+{
68441+ struct name_entry *match;
68442+ struct acl_object_label *matchpo;
68443+ struct acl_subject_label *curracl;
68444+ char *path;
68445+
68446+ if (unlikely(!(gr_status & GR_READY)))
68447+ return NULL;
68448+
68449+ preempt_disable();
68450+ path = gr_to_filename_rbac(new_dentry, mnt);
68451+ match = lookup_name_entry_create(path);
68452+
68453+ curracl = current->acl;
68454+
68455+ if (match) {
68456+ read_lock(&gr_inode_lock);
68457+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
68458+ read_unlock(&gr_inode_lock);
68459+
68460+ if (matchpo) {
68461+ preempt_enable();
68462+ return matchpo;
68463+ }
68464+ }
68465+
68466+ // lookup parent
68467+
68468+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
68469+
68470+ preempt_enable();
68471+ return matchpo;
68472+}
68473+
68474+__u32
68475+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
68476+ const struct vfsmount * mnt, const __u32 mode)
68477+{
68478+ struct acl_object_label *matchpo;
68479+ __u32 retval;
68480+
68481+ if (unlikely(!(gr_status & GR_READY)))
68482+ return (mode & ~GR_AUDITS);
68483+
68484+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
68485+
68486+ retval = matchpo->mode & mode;
68487+
68488+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
68489+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
68490+ __u32 new_mode = mode;
68491+
68492+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
68493+
68494+ gr_log_learn(new_dentry, mnt, new_mode);
68495+ return new_mode;
68496+ }
68497+
68498+ return retval;
68499+}
68500+
68501+__u32
68502+gr_check_link(const struct dentry * new_dentry,
68503+ const struct dentry * parent_dentry,
68504+ const struct vfsmount * parent_mnt,
68505+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
68506+{
68507+ struct acl_object_label *obj;
68508+ __u32 oldmode, newmode;
68509+ __u32 needmode;
68510+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
68511+ GR_DELETE | GR_INHERIT;
68512+
68513+ if (unlikely(!(gr_status & GR_READY)))
68514+ return (GR_CREATE | GR_LINK);
68515+
68516+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
68517+ oldmode = obj->mode;
68518+
68519+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
68520+ newmode = obj->mode;
68521+
68522+ needmode = newmode & checkmodes;
68523+
68524+ // old name for hardlink must have at least the permissions of the new name
68525+ if ((oldmode & needmode) != needmode)
68526+ goto bad;
68527+
68528+ // if old name had restrictions/auditing, make sure the new name does as well
68529+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
68530+
68531+ // don't allow hardlinking of suid/sgid/fcapped files without permission
68532+ if (is_privileged_binary(old_dentry))
68533+ needmode |= GR_SETID;
68534+
68535+ if ((newmode & needmode) != needmode)
68536+ goto bad;
68537+
68538+ // enforce minimum permissions
68539+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
68540+ return newmode;
68541+bad:
68542+ needmode = oldmode;
68543+ if (is_privileged_binary(old_dentry))
68544+ needmode |= GR_SETID;
68545+
68546+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
68547+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
68548+ return (GR_CREATE | GR_LINK);
68549+ } else if (newmode & GR_SUPPRESS)
68550+ return GR_SUPPRESS;
68551+ else
68552+ return 0;
68553+}
68554+
68555+int
68556+gr_check_hidden_task(const struct task_struct *task)
68557+{
68558+ if (unlikely(!(gr_status & GR_READY)))
68559+ return 0;
68560+
68561+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
68562+ return 1;
68563+
68564+ return 0;
68565+}
68566+
68567+int
68568+gr_check_protected_task(const struct task_struct *task)
68569+{
68570+ if (unlikely(!(gr_status & GR_READY) || !task))
68571+ return 0;
68572+
68573+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
68574+ task->acl != current->acl)
68575+ return 1;
68576+
68577+ return 0;
68578+}
68579+
68580+int
68581+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
68582+{
68583+ struct task_struct *p;
68584+ int ret = 0;
68585+
68586+ if (unlikely(!(gr_status & GR_READY) || !pid))
68587+ return ret;
68588+
68589+ read_lock(&tasklist_lock);
68590+ do_each_pid_task(pid, type, p) {
68591+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
68592+ p->acl != current->acl) {
68593+ ret = 1;
68594+ goto out;
68595+ }
68596+ } while_each_pid_task(pid, type, p);
68597+out:
68598+ read_unlock(&tasklist_lock);
68599+
68600+ return ret;
68601+}
68602+
68603+void
68604+gr_copy_label(struct task_struct *tsk)
68605+{
68606+ struct task_struct *p = current;
68607+
68608+ tsk->inherited = p->inherited;
68609+ tsk->acl_sp_role = 0;
68610+ tsk->acl_role_id = p->acl_role_id;
68611+ tsk->acl = p->acl;
68612+ tsk->role = p->role;
68613+ tsk->signal->used_accept = 0;
68614+ tsk->signal->curr_ip = p->signal->curr_ip;
68615+ tsk->signal->saved_ip = p->signal->saved_ip;
68616+ if (p->exec_file)
68617+ get_file(p->exec_file);
68618+ tsk->exec_file = p->exec_file;
68619+ tsk->is_writable = p->is_writable;
68620+ if (unlikely(p->signal->used_accept)) {
68621+ p->signal->curr_ip = 0;
68622+ p->signal->saved_ip = 0;
68623+ }
68624+
68625+ return;
68626+}
68627+
68628+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
68629+
68630+int
68631+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
68632+{
68633+ unsigned int i;
68634+ __u16 num;
68635+ uid_t *uidlist;
68636+ uid_t curuid;
68637+ int realok = 0;
68638+ int effectiveok = 0;
68639+ int fsok = 0;
68640+ uid_t globalreal, globaleffective, globalfs;
68641+
68642+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
68643+ struct user_struct *user;
68644+
68645+ if (!uid_valid(real))
68646+ goto skipit;
68647+
68648+ /* find user based on global namespace */
68649+
68650+ globalreal = GR_GLOBAL_UID(real);
68651+
68652+ user = find_user(make_kuid(&init_user_ns, globalreal));
68653+ if (user == NULL)
68654+ goto skipit;
68655+
68656+ if (gr_process_kernel_setuid_ban(user)) {
68657+ /* for find_user */
68658+ free_uid(user);
68659+ return 1;
68660+ }
68661+
68662+ /* for find_user */
68663+ free_uid(user);
68664+
68665+skipit:
68666+#endif
68667+
68668+ if (unlikely(!(gr_status & GR_READY)))
68669+ return 0;
68670+
68671+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68672+ gr_log_learn_uid_change(real, effective, fs);
68673+
68674+ num = current->acl->user_trans_num;
68675+ uidlist = current->acl->user_transitions;
68676+
68677+ if (uidlist == NULL)
68678+ return 0;
68679+
68680+ if (!uid_valid(real)) {
68681+ realok = 1;
68682+ globalreal = (uid_t)-1;
68683+ } else {
68684+ globalreal = GR_GLOBAL_UID(real);
68685+ }
68686+ if (!uid_valid(effective)) {
68687+ effectiveok = 1;
68688+ globaleffective = (uid_t)-1;
68689+ } else {
68690+ globaleffective = GR_GLOBAL_UID(effective);
68691+ }
68692+ if (!uid_valid(fs)) {
68693+ fsok = 1;
68694+ globalfs = (uid_t)-1;
68695+ } else {
68696+ globalfs = GR_GLOBAL_UID(fs);
68697+ }
68698+
68699+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
68700+ for (i = 0; i < num; i++) {
68701+ curuid = uidlist[i];
68702+ if (globalreal == curuid)
68703+ realok = 1;
68704+ if (globaleffective == curuid)
68705+ effectiveok = 1;
68706+ if (globalfs == curuid)
68707+ fsok = 1;
68708+ }
68709+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
68710+ for (i = 0; i < num; i++) {
68711+ curuid = uidlist[i];
68712+ if (globalreal == curuid)
68713+ break;
68714+ if (globaleffective == curuid)
68715+ break;
68716+ if (globalfs == curuid)
68717+ break;
68718+ }
68719+ /* not in deny list */
68720+ if (i == num) {
68721+ realok = 1;
68722+ effectiveok = 1;
68723+ fsok = 1;
68724+ }
68725+ }
68726+
68727+ if (realok && effectiveok && fsok)
68728+ return 0;
68729+ else {
68730+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
68731+ return 1;
68732+ }
68733+}
68734+
68735+int
68736+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
68737+{
68738+ unsigned int i;
68739+ __u16 num;
68740+ gid_t *gidlist;
68741+ gid_t curgid;
68742+ int realok = 0;
68743+ int effectiveok = 0;
68744+ int fsok = 0;
68745+ gid_t globalreal, globaleffective, globalfs;
68746+
68747+ if (unlikely(!(gr_status & GR_READY)))
68748+ return 0;
68749+
68750+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68751+ gr_log_learn_gid_change(real, effective, fs);
68752+
68753+ num = current->acl->group_trans_num;
68754+ gidlist = current->acl->group_transitions;
68755+
68756+ if (gidlist == NULL)
68757+ return 0;
68758+
68759+ if (!gid_valid(real)) {
68760+ realok = 1;
68761+ globalreal = (gid_t)-1;
68762+ } else {
68763+ globalreal = GR_GLOBAL_GID(real);
68764+ }
68765+ if (!gid_valid(effective)) {
68766+ effectiveok = 1;
68767+ globaleffective = (gid_t)-1;
68768+ } else {
68769+ globaleffective = GR_GLOBAL_GID(effective);
68770+ }
68771+ if (!gid_valid(fs)) {
68772+ fsok = 1;
68773+ globalfs = (gid_t)-1;
68774+ } else {
68775+ globalfs = GR_GLOBAL_GID(fs);
68776+ }
68777+
68778+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
68779+ for (i = 0; i < num; i++) {
68780+ curgid = gidlist[i];
68781+ if (globalreal == curgid)
68782+ realok = 1;
68783+ if (globaleffective == curgid)
68784+ effectiveok = 1;
68785+ if (globalfs == curgid)
68786+ fsok = 1;
68787+ }
68788+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
68789+ for (i = 0; i < num; i++) {
68790+ curgid = gidlist[i];
68791+ if (globalreal == curgid)
68792+ break;
68793+ if (globaleffective == curgid)
68794+ break;
68795+ if (globalfs == curgid)
68796+ break;
68797+ }
68798+ /* not in deny list */
68799+ if (i == num) {
68800+ realok = 1;
68801+ effectiveok = 1;
68802+ fsok = 1;
68803+ }
68804+ }
68805+
68806+ if (realok && effectiveok && fsok)
68807+ return 0;
68808+ else {
68809+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
68810+ return 1;
68811+ }
68812+}
68813+
68814+extern int gr_acl_is_capable(const int cap);
68815+
68816+void
68817+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
68818+{
68819+ struct acl_role_label *role = task->role;
68820+ struct acl_subject_label *subj = NULL;
68821+ struct acl_object_label *obj;
68822+ struct file *filp;
68823+ uid_t uid;
68824+ gid_t gid;
68825+
68826+ if (unlikely(!(gr_status & GR_READY)))
68827+ return;
68828+
68829+ uid = GR_GLOBAL_UID(kuid);
68830+ gid = GR_GLOBAL_GID(kgid);
68831+
68832+ filp = task->exec_file;
68833+
68834+ /* kernel process, we'll give them the kernel role */
68835+ if (unlikely(!filp)) {
68836+ task->role = running_polstate.kernel_role;
68837+ task->acl = running_polstate.kernel_role->root_label;
68838+ return;
68839+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
68840+ /* save the current ip at time of role lookup so that the proper
68841+ IP will be learned for role_allowed_ip */
68842+ task->signal->saved_ip = task->signal->curr_ip;
68843+ role = lookup_acl_role_label(task, uid, gid);
68844+ }
68845+
68846+ /* don't change the role if we're not a privileged process */
68847+ if (role && task->role != role &&
68848+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
68849+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
68850+ return;
68851+
68852+ /* perform subject lookup in possibly new role
68853+ we can use this result below in the case where role == task->role
68854+ */
68855+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
68856+
68857+ /* if we changed uid/gid, but result in the same role
68858+ and are using inheritance, don't lose the inherited subject
68859+ if current subject is other than what normal lookup
68860+ would result in, we arrived via inheritance, don't
68861+ lose subject
68862+ */
68863+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
68864+ (subj == task->acl)))
68865+ task->acl = subj;
68866+
68867+ /* leave task->inherited unaffected */
68868+
68869+ task->role = role;
68870+
68871+ task->is_writable = 0;
68872+
68873+ /* ignore additional mmap checks for processes that are writable
68874+ by the default ACL */
68875+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
68876+ if (unlikely(obj->mode & GR_WRITE))
68877+ task->is_writable = 1;
68878+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
68879+ if (unlikely(obj->mode & GR_WRITE))
68880+ task->is_writable = 1;
68881+
68882+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68883+ 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);
68884+#endif
68885+
68886+ gr_set_proc_res(task);
68887+
68888+ return;
68889+}
68890+
68891+int
68892+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
68893+ const int unsafe_flags)
68894+{
68895+ struct task_struct *task = current;
68896+ struct acl_subject_label *newacl;
68897+ struct acl_object_label *obj;
68898+ __u32 retmode;
68899+
68900+ if (unlikely(!(gr_status & GR_READY)))
68901+ return 0;
68902+
68903+ newacl = chk_subj_label(dentry, mnt, task->role);
68904+
68905+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
68906+ did an exec
68907+ */
68908+ rcu_read_lock();
68909+ read_lock(&tasklist_lock);
68910+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
68911+ (task->parent->acl->mode & GR_POVERRIDE))) {
68912+ read_unlock(&tasklist_lock);
68913+ rcu_read_unlock();
68914+ goto skip_check;
68915+ }
68916+ read_unlock(&tasklist_lock);
68917+ rcu_read_unlock();
68918+
68919+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
68920+ !(task->role->roletype & GR_ROLE_GOD) &&
68921+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
68922+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
68923+ if (unsafe_flags & LSM_UNSAFE_SHARE)
68924+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
68925+ else
68926+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
68927+ return -EACCES;
68928+ }
68929+
68930+skip_check:
68931+
68932+ obj = chk_obj_label(dentry, mnt, task->acl);
68933+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
68934+
68935+ if (!(task->acl->mode & GR_INHERITLEARN) &&
68936+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
68937+ if (obj->nested)
68938+ task->acl = obj->nested;
68939+ else
68940+ task->acl = newacl;
68941+ task->inherited = 0;
68942+ } else {
68943+ task->inherited = 1;
68944+ if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
68945+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
68946+ }
68947+
68948+ task->is_writable = 0;
68949+
68950+ /* ignore additional mmap checks for processes that are writable
68951+ by the default ACL */
68952+ obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
68953+ if (unlikely(obj->mode & GR_WRITE))
68954+ task->is_writable = 1;
68955+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
68956+ if (unlikely(obj->mode & GR_WRITE))
68957+ task->is_writable = 1;
68958+
68959+ gr_set_proc_res(task);
68960+
68961+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68962+ 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);
68963+#endif
68964+ return 0;
68965+}
68966+
68967+/* always called with valid inodev ptr */
68968+static void
68969+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
68970+{
68971+ struct acl_object_label *matchpo;
68972+ struct acl_subject_label *matchps;
68973+ struct acl_subject_label *subj;
68974+ struct acl_role_label *role;
68975+ unsigned int x;
68976+
68977+ FOR_EACH_ROLE_START(role)
68978+ FOR_EACH_SUBJECT_START(role, subj, x)
68979+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
68980+ matchpo->mode |= GR_DELETED;
68981+ FOR_EACH_SUBJECT_END(subj,x)
68982+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
68983+ /* nested subjects aren't in the role's subj_hash table */
68984+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
68985+ matchpo->mode |= GR_DELETED;
68986+ FOR_EACH_NESTED_SUBJECT_END(subj)
68987+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
68988+ matchps->mode |= GR_DELETED;
68989+ FOR_EACH_ROLE_END(role)
68990+
68991+ inodev->nentry->deleted = 1;
68992+
68993+ return;
68994+}
68995+
68996+void
68997+gr_handle_delete(const ino_t ino, const dev_t dev)
68998+{
68999+ struct inodev_entry *inodev;
69000+
69001+ if (unlikely(!(gr_status & GR_READY)))
69002+ return;
69003+
69004+ write_lock(&gr_inode_lock);
69005+ inodev = lookup_inodev_entry(ino, dev);
69006+ if (inodev != NULL)
69007+ do_handle_delete(inodev, ino, dev);
69008+ write_unlock(&gr_inode_lock);
69009+
69010+ return;
69011+}
69012+
69013+static void
69014+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
69015+ const ino_t newinode, const dev_t newdevice,
69016+ struct acl_subject_label *subj)
69017+{
69018+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
69019+ struct acl_object_label *match;
69020+
69021+ match = subj->obj_hash[index];
69022+
69023+ while (match && (match->inode != oldinode ||
69024+ match->device != olddevice ||
69025+ !(match->mode & GR_DELETED)))
69026+ match = match->next;
69027+
69028+ if (match && (match->inode == oldinode)
69029+ && (match->device == olddevice)
69030+ && (match->mode & GR_DELETED)) {
69031+ if (match->prev == NULL) {
69032+ subj->obj_hash[index] = match->next;
69033+ if (match->next != NULL)
69034+ match->next->prev = NULL;
69035+ } else {
69036+ match->prev->next = match->next;
69037+ if (match->next != NULL)
69038+ match->next->prev = match->prev;
69039+ }
69040+ match->prev = NULL;
69041+ match->next = NULL;
69042+ match->inode = newinode;
69043+ match->device = newdevice;
69044+ match->mode &= ~GR_DELETED;
69045+
69046+ insert_acl_obj_label(match, subj);
69047+ }
69048+
69049+ return;
69050+}
69051+
69052+static void
69053+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
69054+ const ino_t newinode, const dev_t newdevice,
69055+ struct acl_role_label *role)
69056+{
69057+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
69058+ struct acl_subject_label *match;
69059+
69060+ match = role->subj_hash[index];
69061+
69062+ while (match && (match->inode != oldinode ||
69063+ match->device != olddevice ||
69064+ !(match->mode & GR_DELETED)))
69065+ match = match->next;
69066+
69067+ if (match && (match->inode == oldinode)
69068+ && (match->device == olddevice)
69069+ && (match->mode & GR_DELETED)) {
69070+ if (match->prev == NULL) {
69071+ role->subj_hash[index] = match->next;
69072+ if (match->next != NULL)
69073+ match->next->prev = NULL;
69074+ } else {
69075+ match->prev->next = match->next;
69076+ if (match->next != NULL)
69077+ match->next->prev = match->prev;
69078+ }
69079+ match->prev = NULL;
69080+ match->next = NULL;
69081+ match->inode = newinode;
69082+ match->device = newdevice;
69083+ match->mode &= ~GR_DELETED;
69084+
69085+ insert_acl_subj_label(match, role);
69086+ }
69087+
69088+ return;
69089+}
69090+
69091+static void
69092+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
69093+ const ino_t newinode, const dev_t newdevice)
69094+{
69095+ unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
69096+ struct inodev_entry *match;
69097+
69098+ match = running_polstate.inodev_set.i_hash[index];
69099+
69100+ while (match && (match->nentry->inode != oldinode ||
69101+ match->nentry->device != olddevice || !match->nentry->deleted))
69102+ match = match->next;
69103+
69104+ if (match && (match->nentry->inode == oldinode)
69105+ && (match->nentry->device == olddevice) &&
69106+ match->nentry->deleted) {
69107+ if (match->prev == NULL) {
69108+ running_polstate.inodev_set.i_hash[index] = match->next;
69109+ if (match->next != NULL)
69110+ match->next->prev = NULL;
69111+ } else {
69112+ match->prev->next = match->next;
69113+ if (match->next != NULL)
69114+ match->next->prev = match->prev;
69115+ }
69116+ match->prev = NULL;
69117+ match->next = NULL;
69118+ match->nentry->inode = newinode;
69119+ match->nentry->device = newdevice;
69120+ match->nentry->deleted = 0;
69121+
69122+ insert_inodev_entry(match);
69123+ }
69124+
69125+ return;
69126+}
69127+
69128+static void
69129+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
69130+{
69131+ struct acl_subject_label *subj;
69132+ struct acl_role_label *role;
69133+ unsigned int x;
69134+
69135+ FOR_EACH_ROLE_START(role)
69136+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
69137+
69138+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
69139+ if ((subj->inode == ino) && (subj->device == dev)) {
69140+ subj->inode = ino;
69141+ subj->device = dev;
69142+ }
69143+ /* nested subjects aren't in the role's subj_hash table */
69144+ update_acl_obj_label(matchn->inode, matchn->device,
69145+ ino, dev, subj);
69146+ FOR_EACH_NESTED_SUBJECT_END(subj)
69147+ FOR_EACH_SUBJECT_START(role, subj, x)
69148+ update_acl_obj_label(matchn->inode, matchn->device,
69149+ ino, dev, subj);
69150+ FOR_EACH_SUBJECT_END(subj,x)
69151+ FOR_EACH_ROLE_END(role)
69152+
69153+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
69154+
69155+ return;
69156+}
69157+
69158+static void
69159+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
69160+ const struct vfsmount *mnt)
69161+{
69162+ ino_t ino = dentry->d_inode->i_ino;
69163+ dev_t dev = __get_dev(dentry);
69164+
69165+ __do_handle_create(matchn, ino, dev);
69166+
69167+ return;
69168+}
69169+
69170+void
69171+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
69172+{
69173+ struct name_entry *matchn;
69174+
69175+ if (unlikely(!(gr_status & GR_READY)))
69176+ return;
69177+
69178+ preempt_disable();
69179+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
69180+
69181+ if (unlikely((unsigned long)matchn)) {
69182+ write_lock(&gr_inode_lock);
69183+ do_handle_create(matchn, dentry, mnt);
69184+ write_unlock(&gr_inode_lock);
69185+ }
69186+ preempt_enable();
69187+
69188+ return;
69189+}
69190+
69191+void
69192+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
69193+{
69194+ struct name_entry *matchn;
69195+
69196+ if (unlikely(!(gr_status & GR_READY)))
69197+ return;
69198+
69199+ preempt_disable();
69200+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
69201+
69202+ if (unlikely((unsigned long)matchn)) {
69203+ write_lock(&gr_inode_lock);
69204+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
69205+ write_unlock(&gr_inode_lock);
69206+ }
69207+ preempt_enable();
69208+
69209+ return;
69210+}
69211+
69212+void
69213+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
69214+ struct dentry *old_dentry,
69215+ struct dentry *new_dentry,
69216+ struct vfsmount *mnt, const __u8 replace)
69217+{
69218+ struct name_entry *matchn;
69219+ struct inodev_entry *inodev;
69220+ struct inode *inode = new_dentry->d_inode;
69221+ ino_t old_ino = old_dentry->d_inode->i_ino;
69222+ dev_t old_dev = __get_dev(old_dentry);
69223+
69224+ /* vfs_rename swaps the name and parent link for old_dentry and
69225+ new_dentry
69226+ at this point, old_dentry has the new name, parent link, and inode
69227+ for the renamed file
69228+ if a file is being replaced by a rename, new_dentry has the inode
69229+ and name for the replaced file
69230+ */
69231+
69232+ if (unlikely(!(gr_status & GR_READY)))
69233+ return;
69234+
69235+ preempt_disable();
69236+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
69237+
69238+ /* we wouldn't have to check d_inode if it weren't for
69239+ NFS silly-renaming
69240+ */
69241+
69242+ write_lock(&gr_inode_lock);
69243+ if (unlikely(replace && inode)) {
69244+ ino_t new_ino = inode->i_ino;
69245+ dev_t new_dev = __get_dev(new_dentry);
69246+
69247+ inodev = lookup_inodev_entry(new_ino, new_dev);
69248+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
69249+ do_handle_delete(inodev, new_ino, new_dev);
69250+ }
69251+
69252+ inodev = lookup_inodev_entry(old_ino, old_dev);
69253+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
69254+ do_handle_delete(inodev, old_ino, old_dev);
69255+
69256+ if (unlikely((unsigned long)matchn))
69257+ do_handle_create(matchn, old_dentry, mnt);
69258+
69259+ write_unlock(&gr_inode_lock);
69260+ preempt_enable();
69261+
69262+ return;
69263+}
69264+
69265+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
69266+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
69267+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
69268+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
69269+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
69270+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
69271+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
69272+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
69273+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
69274+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
69275+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
69276+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
69277+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
69278+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
69279+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
69280+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
69281+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
69282+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
69283+};
69284+
69285+void
69286+gr_learn_resource(const struct task_struct *task,
69287+ const int res, const unsigned long wanted, const int gt)
69288+{
69289+ struct acl_subject_label *acl;
69290+ const struct cred *cred;
69291+
69292+ if (unlikely((gr_status & GR_READY) &&
69293+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
69294+ goto skip_reslog;
69295+
69296+ gr_log_resource(task, res, wanted, gt);
69297+skip_reslog:
69298+
69299+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
69300+ return;
69301+
69302+ acl = task->acl;
69303+
69304+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
69305+ !(acl->resmask & (1U << (unsigned short) res))))
69306+ return;
69307+
69308+ if (wanted >= acl->res[res].rlim_cur) {
69309+ unsigned long res_add;
69310+
69311+ res_add = wanted + res_learn_bumps[res];
69312+
69313+ acl->res[res].rlim_cur = res_add;
69314+
69315+ if (wanted > acl->res[res].rlim_max)
69316+ acl->res[res].rlim_max = res_add;
69317+
69318+ /* only log the subject filename, since resource logging is supported for
69319+ single-subject learning only */
69320+ rcu_read_lock();
69321+ cred = __task_cred(task);
69322+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
69323+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
69324+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
69325+ "", (unsigned long) res, &task->signal->saved_ip);
69326+ rcu_read_unlock();
69327+ }
69328+
69329+ return;
69330+}
69331+EXPORT_SYMBOL_GPL(gr_learn_resource);
69332+#endif
69333+
69334+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
69335+void
69336+pax_set_initial_flags(struct linux_binprm *bprm)
69337+{
69338+ struct task_struct *task = current;
69339+ struct acl_subject_label *proc;
69340+ unsigned long flags;
69341+
69342+ if (unlikely(!(gr_status & GR_READY)))
69343+ return;
69344+
69345+ flags = pax_get_flags(task);
69346+
69347+ proc = task->acl;
69348+
69349+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
69350+ flags &= ~MF_PAX_PAGEEXEC;
69351+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
69352+ flags &= ~MF_PAX_SEGMEXEC;
69353+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
69354+ flags &= ~MF_PAX_RANDMMAP;
69355+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
69356+ flags &= ~MF_PAX_EMUTRAMP;
69357+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
69358+ flags &= ~MF_PAX_MPROTECT;
69359+
69360+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
69361+ flags |= MF_PAX_PAGEEXEC;
69362+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
69363+ flags |= MF_PAX_SEGMEXEC;
69364+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
69365+ flags |= MF_PAX_RANDMMAP;
69366+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
69367+ flags |= MF_PAX_EMUTRAMP;
69368+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
69369+ flags |= MF_PAX_MPROTECT;
69370+
69371+ pax_set_flags(task, flags);
69372+
69373+ return;
69374+}
69375+#endif
69376+
69377+int
69378+gr_handle_proc_ptrace(struct task_struct *task)
69379+{
69380+ struct file *filp;
69381+ struct task_struct *tmp = task;
69382+ struct task_struct *curtemp = current;
69383+ __u32 retmode;
69384+
69385+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
69386+ if (unlikely(!(gr_status & GR_READY)))
69387+ return 0;
69388+#endif
69389+
69390+ read_lock(&tasklist_lock);
69391+ read_lock(&grsec_exec_file_lock);
69392+ filp = task->exec_file;
69393+
69394+ while (task_pid_nr(tmp) > 0) {
69395+ if (tmp == curtemp)
69396+ break;
69397+ tmp = tmp->real_parent;
69398+ }
69399+
69400+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
69401+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
69402+ read_unlock(&grsec_exec_file_lock);
69403+ read_unlock(&tasklist_lock);
69404+ return 1;
69405+ }
69406+
69407+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69408+ if (!(gr_status & GR_READY)) {
69409+ read_unlock(&grsec_exec_file_lock);
69410+ read_unlock(&tasklist_lock);
69411+ return 0;
69412+ }
69413+#endif
69414+
69415+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
69416+ read_unlock(&grsec_exec_file_lock);
69417+ read_unlock(&tasklist_lock);
69418+
69419+ if (retmode & GR_NOPTRACE)
69420+ return 1;
69421+
69422+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
69423+ && (current->acl != task->acl || (current->acl != current->role->root_label
69424+ && task_pid_nr(current) != task_pid_nr(task))))
69425+ return 1;
69426+
69427+ return 0;
69428+}
69429+
69430+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
69431+{
69432+ if (unlikely(!(gr_status & GR_READY)))
69433+ return;
69434+
69435+ if (!(current->role->roletype & GR_ROLE_GOD))
69436+ return;
69437+
69438+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
69439+ p->role->rolename, gr_task_roletype_to_char(p),
69440+ p->acl->filename);
69441+}
69442+
69443+int
69444+gr_handle_ptrace(struct task_struct *task, const long request)
69445+{
69446+ struct task_struct *tmp = task;
69447+ struct task_struct *curtemp = current;
69448+ __u32 retmode;
69449+
69450+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
69451+ if (unlikely(!(gr_status & GR_READY)))
69452+ return 0;
69453+#endif
69454+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69455+ read_lock(&tasklist_lock);
69456+ while (task_pid_nr(tmp) > 0) {
69457+ if (tmp == curtemp)
69458+ break;
69459+ tmp = tmp->real_parent;
69460+ }
69461+
69462+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
69463+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
69464+ read_unlock(&tasklist_lock);
69465+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69466+ return 1;
69467+ }
69468+ read_unlock(&tasklist_lock);
69469+ }
69470+
69471+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69472+ if (!(gr_status & GR_READY))
69473+ return 0;
69474+#endif
69475+
69476+ read_lock(&grsec_exec_file_lock);
69477+ if (unlikely(!task->exec_file)) {
69478+ read_unlock(&grsec_exec_file_lock);
69479+ return 0;
69480+ }
69481+
69482+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
69483+ read_unlock(&grsec_exec_file_lock);
69484+
69485+ if (retmode & GR_NOPTRACE) {
69486+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69487+ return 1;
69488+ }
69489+
69490+ if (retmode & GR_PTRACERD) {
69491+ switch (request) {
69492+ case PTRACE_SEIZE:
69493+ case PTRACE_POKETEXT:
69494+ case PTRACE_POKEDATA:
69495+ case PTRACE_POKEUSR:
69496+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
69497+ case PTRACE_SETREGS:
69498+ case PTRACE_SETFPREGS:
69499+#endif
69500+#ifdef CONFIG_X86
69501+ case PTRACE_SETFPXREGS:
69502+#endif
69503+#ifdef CONFIG_ALTIVEC
69504+ case PTRACE_SETVRREGS:
69505+#endif
69506+ return 1;
69507+ default:
69508+ return 0;
69509+ }
69510+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
69511+ !(current->role->roletype & GR_ROLE_GOD) &&
69512+ (current->acl != task->acl)) {
69513+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69514+ return 1;
69515+ }
69516+
69517+ return 0;
69518+}
69519+
69520+static int is_writable_mmap(const struct file *filp)
69521+{
69522+ struct task_struct *task = current;
69523+ struct acl_object_label *obj, *obj2;
69524+
69525+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
69526+ !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))) {
69527+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
69528+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
69529+ task->role->root_label);
69530+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
69531+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
69532+ return 1;
69533+ }
69534+ }
69535+ return 0;
69536+}
69537+
69538+int
69539+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
69540+{
69541+ __u32 mode;
69542+
69543+ if (unlikely(!file || !(prot & PROT_EXEC)))
69544+ return 1;
69545+
69546+ if (is_writable_mmap(file))
69547+ return 0;
69548+
69549+ mode =
69550+ gr_search_file(file->f_path.dentry,
69551+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
69552+ file->f_path.mnt);
69553+
69554+ if (!gr_tpe_allow(file))
69555+ return 0;
69556+
69557+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
69558+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69559+ return 0;
69560+ } else if (unlikely(!(mode & GR_EXEC))) {
69561+ return 0;
69562+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
69563+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69564+ return 1;
69565+ }
69566+
69567+ return 1;
69568+}
69569+
69570+int
69571+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
69572+{
69573+ __u32 mode;
69574+
69575+ if (unlikely(!file || !(prot & PROT_EXEC)))
69576+ return 1;
69577+
69578+ if (is_writable_mmap(file))
69579+ return 0;
69580+
69581+ mode =
69582+ gr_search_file(file->f_path.dentry,
69583+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
69584+ file->f_path.mnt);
69585+
69586+ if (!gr_tpe_allow(file))
69587+ return 0;
69588+
69589+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
69590+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69591+ return 0;
69592+ } else if (unlikely(!(mode & GR_EXEC))) {
69593+ return 0;
69594+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
69595+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69596+ return 1;
69597+ }
69598+
69599+ return 1;
69600+}
69601+
69602+void
69603+gr_acl_handle_psacct(struct task_struct *task, const long code)
69604+{
69605+ unsigned long runtime, cputime;
69606+ cputime_t utime, stime;
69607+ unsigned int wday, cday;
69608+ __u8 whr, chr;
69609+ __u8 wmin, cmin;
69610+ __u8 wsec, csec;
69611+ struct timespec timeval;
69612+
69613+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
69614+ !(task->acl->mode & GR_PROCACCT)))
69615+ return;
69616+
69617+ do_posix_clock_monotonic_gettime(&timeval);
69618+ runtime = timeval.tv_sec - task->start_time.tv_sec;
69619+ wday = runtime / (60 * 60 * 24);
69620+ runtime -= wday * (60 * 60 * 24);
69621+ whr = runtime / (60 * 60);
69622+ runtime -= whr * (60 * 60);
69623+ wmin = runtime / 60;
69624+ runtime -= wmin * 60;
69625+ wsec = runtime;
69626+
69627+ task_cputime(task, &utime, &stime);
69628+ cputime = cputime_to_secs(utime + stime);
69629+ cday = cputime / (60 * 60 * 24);
69630+ cputime -= cday * (60 * 60 * 24);
69631+ chr = cputime / (60 * 60);
69632+ cputime -= chr * (60 * 60);
69633+ cmin = cputime / 60;
69634+ cputime -= cmin * 60;
69635+ csec = cputime;
69636+
69637+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
69638+
69639+ return;
69640+}
69641+
69642+#ifdef CONFIG_TASKSTATS
69643+int gr_is_taskstats_denied(int pid)
69644+{
69645+ struct task_struct *task;
69646+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69647+ const struct cred *cred;
69648+#endif
69649+ int ret = 0;
69650+
69651+ /* restrict taskstats viewing to un-chrooted root users
69652+ who have the 'view' subject flag if the RBAC system is enabled
69653+ */
69654+
69655+ rcu_read_lock();
69656+ read_lock(&tasklist_lock);
69657+ task = find_task_by_vpid(pid);
69658+ if (task) {
69659+#ifdef CONFIG_GRKERNSEC_CHROOT
69660+ if (proc_is_chrooted(task))
69661+ ret = -EACCES;
69662+#endif
69663+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69664+ cred = __task_cred(task);
69665+#ifdef CONFIG_GRKERNSEC_PROC_USER
69666+ if (gr_is_global_nonroot(cred->uid))
69667+ ret = -EACCES;
69668+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69669+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
69670+ ret = -EACCES;
69671+#endif
69672+#endif
69673+ if (gr_status & GR_READY) {
69674+ if (!(task->acl->mode & GR_VIEW))
69675+ ret = -EACCES;
69676+ }
69677+ } else
69678+ ret = -ENOENT;
69679+
69680+ read_unlock(&tasklist_lock);
69681+ rcu_read_unlock();
69682+
69683+ return ret;
69684+}
69685+#endif
69686+
69687+/* AUXV entries are filled via a descendant of search_binary_handler
69688+ after we've already applied the subject for the target
69689+*/
69690+int gr_acl_enable_at_secure(void)
69691+{
69692+ if (unlikely(!(gr_status & GR_READY)))
69693+ return 0;
69694+
69695+ if (current->acl->mode & GR_ATSECURE)
69696+ return 1;
69697+
69698+ return 0;
69699+}
69700+
69701+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
69702+{
69703+ struct task_struct *task = current;
69704+ struct dentry *dentry = file->f_path.dentry;
69705+ struct vfsmount *mnt = file->f_path.mnt;
69706+ struct acl_object_label *obj, *tmp;
69707+ struct acl_subject_label *subj;
69708+ unsigned int bufsize;
69709+ int is_not_root;
69710+ char *path;
69711+ dev_t dev = __get_dev(dentry);
69712+
69713+ if (unlikely(!(gr_status & GR_READY)))
69714+ return 1;
69715+
69716+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
69717+ return 1;
69718+
69719+ /* ignore Eric Biederman */
69720+ if (IS_PRIVATE(dentry->d_inode))
69721+ return 1;
69722+
69723+ subj = task->acl;
69724+ read_lock(&gr_inode_lock);
69725+ do {
69726+ obj = lookup_acl_obj_label(ino, dev, subj);
69727+ if (obj != NULL) {
69728+ read_unlock(&gr_inode_lock);
69729+ return (obj->mode & GR_FIND) ? 1 : 0;
69730+ }
69731+ } while ((subj = subj->parent_subject));
69732+ read_unlock(&gr_inode_lock);
69733+
69734+ /* this is purely an optimization since we're looking for an object
69735+ for the directory we're doing a readdir on
69736+ if it's possible for any globbed object to match the entry we're
69737+ filling into the directory, then the object we find here will be
69738+ an anchor point with attached globbed objects
69739+ */
69740+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
69741+ if (obj->globbed == NULL)
69742+ return (obj->mode & GR_FIND) ? 1 : 0;
69743+
69744+ is_not_root = ((obj->filename[0] == '/') &&
69745+ (obj->filename[1] == '\0')) ? 0 : 1;
69746+ bufsize = PAGE_SIZE - namelen - is_not_root;
69747+
69748+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
69749+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
69750+ return 1;
69751+
69752+ preempt_disable();
69753+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
69754+ bufsize);
69755+
69756+ bufsize = strlen(path);
69757+
69758+ /* if base is "/", don't append an additional slash */
69759+ if (is_not_root)
69760+ *(path + bufsize) = '/';
69761+ memcpy(path + bufsize + is_not_root, name, namelen);
69762+ *(path + bufsize + namelen + is_not_root) = '\0';
69763+
69764+ tmp = obj->globbed;
69765+ while (tmp) {
69766+ if (!glob_match(tmp->filename, path)) {
69767+ preempt_enable();
69768+ return (tmp->mode & GR_FIND) ? 1 : 0;
69769+ }
69770+ tmp = tmp->next;
69771+ }
69772+ preempt_enable();
69773+ return (obj->mode & GR_FIND) ? 1 : 0;
69774+}
69775+
69776+void gr_put_exec_file(struct task_struct *task)
69777+{
69778+ struct file *filp;
69779+
69780+ write_lock(&grsec_exec_file_lock);
69781+ filp = task->exec_file;
69782+ task->exec_file = NULL;
69783+ write_unlock(&grsec_exec_file_lock);
69784+
69785+ if (filp)
69786+ fput(filp);
69787+
69788+ return;
69789+}
69790+
69791+
69792+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
69793+EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
69794+#endif
69795+#ifdef CONFIG_SECURITY
69796+EXPORT_SYMBOL_GPL(gr_check_user_change);
69797+EXPORT_SYMBOL_GPL(gr_check_group_change);
69798+#endif
69799+
69800diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
69801new file mode 100644
69802index 0000000..18ffbbd
69803--- /dev/null
69804+++ b/grsecurity/gracl_alloc.c
69805@@ -0,0 +1,105 @@
69806+#include <linux/kernel.h>
69807+#include <linux/mm.h>
69808+#include <linux/slab.h>
69809+#include <linux/vmalloc.h>
69810+#include <linux/gracl.h>
69811+#include <linux/grsecurity.h>
69812+
69813+static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
69814+struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
69815+
69816+static __inline__ int
69817+alloc_pop(void)
69818+{
69819+ if (current_alloc_state->alloc_stack_next == 1)
69820+ return 0;
69821+
69822+ kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
69823+
69824+ current_alloc_state->alloc_stack_next--;
69825+
69826+ return 1;
69827+}
69828+
69829+static __inline__ int
69830+alloc_push(void *buf)
69831+{
69832+ if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
69833+ return 1;
69834+
69835+ current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
69836+
69837+ current_alloc_state->alloc_stack_next++;
69838+
69839+ return 0;
69840+}
69841+
69842+void *
69843+acl_alloc(unsigned long len)
69844+{
69845+ void *ret = NULL;
69846+
69847+ if (!len || len > PAGE_SIZE)
69848+ goto out;
69849+
69850+ ret = kmalloc(len, GFP_KERNEL);
69851+
69852+ if (ret) {
69853+ if (alloc_push(ret)) {
69854+ kfree(ret);
69855+ ret = NULL;
69856+ }
69857+ }
69858+
69859+out:
69860+ return ret;
69861+}
69862+
69863+void *
69864+acl_alloc_num(unsigned long num, unsigned long len)
69865+{
69866+ if (!len || (num > (PAGE_SIZE / len)))
69867+ return NULL;
69868+
69869+ return acl_alloc(num * len);
69870+}
69871+
69872+void
69873+acl_free_all(void)
69874+{
69875+ if (!current_alloc_state->alloc_stack)
69876+ return;
69877+
69878+ while (alloc_pop()) ;
69879+
69880+ if (current_alloc_state->alloc_stack) {
69881+ if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
69882+ kfree(current_alloc_state->alloc_stack);
69883+ else
69884+ vfree(current_alloc_state->alloc_stack);
69885+ }
69886+
69887+ current_alloc_state->alloc_stack = NULL;
69888+ current_alloc_state->alloc_stack_size = 1;
69889+ current_alloc_state->alloc_stack_next = 1;
69890+
69891+ return;
69892+}
69893+
69894+int
69895+acl_alloc_stack_init(unsigned long size)
69896+{
69897+ if ((size * sizeof (void *)) <= PAGE_SIZE)
69898+ current_alloc_state->alloc_stack =
69899+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
69900+ else
69901+ current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
69902+
69903+ current_alloc_state->alloc_stack_size = size;
69904+ current_alloc_state->alloc_stack_next = 1;
69905+
69906+ if (!current_alloc_state->alloc_stack)
69907+ return 0;
69908+ else
69909+ return 1;
69910+}
69911diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
69912new file mode 100644
69913index 0000000..bdd51ea
69914--- /dev/null
69915+++ b/grsecurity/gracl_cap.c
69916@@ -0,0 +1,110 @@
69917+#include <linux/kernel.h>
69918+#include <linux/module.h>
69919+#include <linux/sched.h>
69920+#include <linux/gracl.h>
69921+#include <linux/grsecurity.h>
69922+#include <linux/grinternal.h>
69923+
69924+extern const char *captab_log[];
69925+extern int captab_log_entries;
69926+
69927+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
69928+{
69929+ struct acl_subject_label *curracl;
69930+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
69931+ kernel_cap_t cap_audit = __cap_empty_set;
69932+
69933+ if (!gr_acl_is_enabled())
69934+ return 1;
69935+
69936+ curracl = task->acl;
69937+
69938+ cap_drop = curracl->cap_lower;
69939+ cap_mask = curracl->cap_mask;
69940+ cap_audit = curracl->cap_invert_audit;
69941+
69942+ while ((curracl = curracl->parent_subject)) {
69943+ /* if the cap isn't specified in the current computed mask but is specified in the
69944+ current level subject, and is lowered in the current level subject, then add
69945+ it to the set of dropped capabilities
69946+ otherwise, add the current level subject's mask to the current computed mask
69947+ */
69948+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
69949+ cap_raise(cap_mask, cap);
69950+ if (cap_raised(curracl->cap_lower, cap))
69951+ cap_raise(cap_drop, cap);
69952+ if (cap_raised(curracl->cap_invert_audit, cap))
69953+ cap_raise(cap_audit, cap);
69954+ }
69955+ }
69956+
69957+ if (!cap_raised(cap_drop, cap)) {
69958+ if (cap_raised(cap_audit, cap))
69959+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
69960+ return 1;
69961+ }
69962+
69963+ curracl = task->acl;
69964+
69965+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
69966+ && cap_raised(cred->cap_effective, cap)) {
69967+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
69968+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
69969+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
69970+ gr_to_filename(task->exec_file->f_path.dentry,
69971+ task->exec_file->f_path.mnt) : curracl->filename,
69972+ curracl->filename, 0UL,
69973+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
69974+ return 1;
69975+ }
69976+
69977+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
69978+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
69979+
69980+ return 0;
69981+}
69982+
69983+int
69984+gr_acl_is_capable(const int cap)
69985+{
69986+ return gr_task_acl_is_capable(current, current_cred(), cap);
69987+}
69988+
69989+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
69990+{
69991+ struct acl_subject_label *curracl;
69992+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
69993+
69994+ if (!gr_acl_is_enabled())
69995+ return 1;
69996+
69997+ curracl = task->acl;
69998+
69999+ cap_drop = curracl->cap_lower;
70000+ cap_mask = curracl->cap_mask;
70001+
70002+ while ((curracl = curracl->parent_subject)) {
70003+ /* if the cap isn't specified in the current computed mask but is specified in the
70004+ current level subject, and is lowered in the current level subject, then add
70005+ it to the set of dropped capabilities
70006+ otherwise, add the current level subject's mask to the current computed mask
70007+ */
70008+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
70009+ cap_raise(cap_mask, cap);
70010+ if (cap_raised(curracl->cap_lower, cap))
70011+ cap_raise(cap_drop, cap);
70012+ }
70013+ }
70014+
70015+ if (!cap_raised(cap_drop, cap))
70016+ return 1;
70017+
70018+ return 0;
70019+}
70020+
70021+int
70022+gr_acl_is_capable_nolog(const int cap)
70023+{
70024+ return gr_task_acl_is_capable_nolog(current, cap);
70025+}
70026+
70027diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
70028new file mode 100644
70029index 0000000..ca25605
70030--- /dev/null
70031+++ b/grsecurity/gracl_compat.c
70032@@ -0,0 +1,270 @@
70033+#include <linux/kernel.h>
70034+#include <linux/gracl.h>
70035+#include <linux/compat.h>
70036+#include <linux/gracl_compat.h>
70037+
70038+#include <asm/uaccess.h>
70039+
70040+int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
70041+{
70042+ struct gr_arg_wrapper_compat uwrapcompat;
70043+
70044+ if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
70045+ return -EFAULT;
70046+
70047+ if (((uwrapcompat.version != GRSECURITY_VERSION) &&
70048+ (uwrapcompat.version != 0x2901)) ||
70049+ (uwrapcompat.size != sizeof(struct gr_arg_compat)))
70050+ return -EINVAL;
70051+
70052+ uwrap->arg = compat_ptr(uwrapcompat.arg);
70053+ uwrap->version = uwrapcompat.version;
70054+ uwrap->size = sizeof(struct gr_arg);
70055+
70056+ return 0;
70057+}
70058+
70059+int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
70060+{
70061+ struct gr_arg_compat argcompat;
70062+
70063+ if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
70064+ return -EFAULT;
70065+
70066+ arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
70067+ arg->role_db.num_pointers = argcompat.role_db.num_pointers;
70068+ arg->role_db.num_roles = argcompat.role_db.num_roles;
70069+ arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
70070+ arg->role_db.num_subjects = argcompat.role_db.num_subjects;
70071+ arg->role_db.num_objects = argcompat.role_db.num_objects;
70072+
70073+ memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
70074+ memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
70075+ memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
70076+ memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
70077+ arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
70078+ arg->segv_device = argcompat.segv_device;
70079+ arg->segv_inode = argcompat.segv_inode;
70080+ arg->segv_uid = argcompat.segv_uid;
70081+ arg->num_sprole_pws = argcompat.num_sprole_pws;
70082+ arg->mode = argcompat.mode;
70083+
70084+ return 0;
70085+}
70086+
70087+int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
70088+{
70089+ struct acl_object_label_compat objcompat;
70090+
70091+ if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
70092+ return -EFAULT;
70093+
70094+ obj->filename = compat_ptr(objcompat.filename);
70095+ obj->inode = objcompat.inode;
70096+ obj->device = objcompat.device;
70097+ obj->mode = objcompat.mode;
70098+
70099+ obj->nested = compat_ptr(objcompat.nested);
70100+ obj->globbed = compat_ptr(objcompat.globbed);
70101+
70102+ obj->prev = compat_ptr(objcompat.prev);
70103+ obj->next = compat_ptr(objcompat.next);
70104+
70105+ return 0;
70106+}
70107+
70108+int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
70109+{
70110+ unsigned int i;
70111+ struct acl_subject_label_compat subjcompat;
70112+
70113+ if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
70114+ return -EFAULT;
70115+
70116+ subj->filename = compat_ptr(subjcompat.filename);
70117+ subj->inode = subjcompat.inode;
70118+ subj->device = subjcompat.device;
70119+ subj->mode = subjcompat.mode;
70120+ subj->cap_mask = subjcompat.cap_mask;
70121+ subj->cap_lower = subjcompat.cap_lower;
70122+ subj->cap_invert_audit = subjcompat.cap_invert_audit;
70123+
70124+ for (i = 0; i < GR_NLIMITS; i++) {
70125+ if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
70126+ subj->res[i].rlim_cur = RLIM_INFINITY;
70127+ else
70128+ subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
70129+ if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
70130+ subj->res[i].rlim_max = RLIM_INFINITY;
70131+ else
70132+ subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
70133+ }
70134+ subj->resmask = subjcompat.resmask;
70135+
70136+ subj->user_trans_type = subjcompat.user_trans_type;
70137+ subj->group_trans_type = subjcompat.group_trans_type;
70138+ subj->user_transitions = compat_ptr(subjcompat.user_transitions);
70139+ subj->group_transitions = compat_ptr(subjcompat.group_transitions);
70140+ subj->user_trans_num = subjcompat.user_trans_num;
70141+ subj->group_trans_num = subjcompat.group_trans_num;
70142+
70143+ memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
70144+ memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
70145+ subj->ip_type = subjcompat.ip_type;
70146+ subj->ips = compat_ptr(subjcompat.ips);
70147+ subj->ip_num = subjcompat.ip_num;
70148+ subj->inaddr_any_override = subjcompat.inaddr_any_override;
70149+
70150+ subj->crashes = subjcompat.crashes;
70151+ subj->expires = subjcompat.expires;
70152+
70153+ subj->parent_subject = compat_ptr(subjcompat.parent_subject);
70154+ subj->hash = compat_ptr(subjcompat.hash);
70155+ subj->prev = compat_ptr(subjcompat.prev);
70156+ subj->next = compat_ptr(subjcompat.next);
70157+
70158+ subj->obj_hash = compat_ptr(subjcompat.obj_hash);
70159+ subj->obj_hash_size = subjcompat.obj_hash_size;
70160+ subj->pax_flags = subjcompat.pax_flags;
70161+
70162+ return 0;
70163+}
70164+
70165+int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
70166+{
70167+ struct acl_role_label_compat rolecompat;
70168+
70169+ if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
70170+ return -EFAULT;
70171+
70172+ role->rolename = compat_ptr(rolecompat.rolename);
70173+ role->uidgid = rolecompat.uidgid;
70174+ role->roletype = rolecompat.roletype;
70175+
70176+ role->auth_attempts = rolecompat.auth_attempts;
70177+ role->expires = rolecompat.expires;
70178+
70179+ role->root_label = compat_ptr(rolecompat.root_label);
70180+ role->hash = compat_ptr(rolecompat.hash);
70181+
70182+ role->prev = compat_ptr(rolecompat.prev);
70183+ role->next = compat_ptr(rolecompat.next);
70184+
70185+ role->transitions = compat_ptr(rolecompat.transitions);
70186+ role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
70187+ role->domain_children = compat_ptr(rolecompat.domain_children);
70188+ role->domain_child_num = rolecompat.domain_child_num;
70189+
70190+ role->umask = rolecompat.umask;
70191+
70192+ role->subj_hash = compat_ptr(rolecompat.subj_hash);
70193+ role->subj_hash_size = rolecompat.subj_hash_size;
70194+
70195+ return 0;
70196+}
70197+
70198+int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
70199+{
70200+ struct role_allowed_ip_compat roleip_compat;
70201+
70202+ if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
70203+ return -EFAULT;
70204+
70205+ roleip->addr = roleip_compat.addr;
70206+ roleip->netmask = roleip_compat.netmask;
70207+
70208+ roleip->prev = compat_ptr(roleip_compat.prev);
70209+ roleip->next = compat_ptr(roleip_compat.next);
70210+
70211+ return 0;
70212+}
70213+
70214+int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
70215+{
70216+ struct role_transition_compat trans_compat;
70217+
70218+ if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
70219+ return -EFAULT;
70220+
70221+ trans->rolename = compat_ptr(trans_compat.rolename);
70222+
70223+ trans->prev = compat_ptr(trans_compat.prev);
70224+ trans->next = compat_ptr(trans_compat.next);
70225+
70226+ return 0;
70227+
70228+}
70229+
70230+int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
70231+{
70232+ struct gr_hash_struct_compat hash_compat;
70233+
70234+ if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
70235+ return -EFAULT;
70236+
70237+ hash->table = compat_ptr(hash_compat.table);
70238+ hash->nametable = compat_ptr(hash_compat.nametable);
70239+ hash->first = compat_ptr(hash_compat.first);
70240+
70241+ hash->table_size = hash_compat.table_size;
70242+ hash->used_size = hash_compat.used_size;
70243+
70244+ hash->type = hash_compat.type;
70245+
70246+ return 0;
70247+}
70248+
70249+int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
70250+{
70251+ compat_uptr_t ptrcompat;
70252+
70253+ if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
70254+ return -EFAULT;
70255+
70256+ *(void **)ptr = compat_ptr(ptrcompat);
70257+
70258+ return 0;
70259+}
70260+
70261+int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
70262+{
70263+ struct acl_ip_label_compat ip_compat;
70264+
70265+ if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
70266+ return -EFAULT;
70267+
70268+ ip->iface = compat_ptr(ip_compat.iface);
70269+ ip->addr = ip_compat.addr;
70270+ ip->netmask = ip_compat.netmask;
70271+ ip->low = ip_compat.low;
70272+ ip->high = ip_compat.high;
70273+ ip->mode = ip_compat.mode;
70274+ ip->type = ip_compat.type;
70275+
70276+ memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
70277+
70278+ ip->prev = compat_ptr(ip_compat.prev);
70279+ ip->next = compat_ptr(ip_compat.next);
70280+
70281+ return 0;
70282+}
70283+
70284+int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
70285+{
70286+ struct sprole_pw_compat pw_compat;
70287+
70288+ if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
70289+ return -EFAULT;
70290+
70291+ pw->rolename = compat_ptr(pw_compat.rolename);
70292+ memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
70293+ memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
70294+
70295+ return 0;
70296+}
70297+
70298+size_t get_gr_arg_wrapper_size_compat(void)
70299+{
70300+ return sizeof(struct gr_arg_wrapper_compat);
70301+}
70302+
70303diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
70304new file mode 100644
70305index 0000000..a89b1f4
70306--- /dev/null
70307+++ b/grsecurity/gracl_fs.c
70308@@ -0,0 +1,437 @@
70309+#include <linux/kernel.h>
70310+#include <linux/sched.h>
70311+#include <linux/types.h>
70312+#include <linux/fs.h>
70313+#include <linux/file.h>
70314+#include <linux/stat.h>
70315+#include <linux/grsecurity.h>
70316+#include <linux/grinternal.h>
70317+#include <linux/gracl.h>
70318+
70319+umode_t
70320+gr_acl_umask(void)
70321+{
70322+ if (unlikely(!gr_acl_is_enabled()))
70323+ return 0;
70324+
70325+ return current->role->umask;
70326+}
70327+
70328+__u32
70329+gr_acl_handle_hidden_file(const struct dentry * dentry,
70330+ const struct vfsmount * mnt)
70331+{
70332+ __u32 mode;
70333+
70334+ if (unlikely(d_is_negative(dentry)))
70335+ return GR_FIND;
70336+
70337+ mode =
70338+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
70339+
70340+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
70341+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
70342+ return mode;
70343+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
70344+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
70345+ return 0;
70346+ } else if (unlikely(!(mode & GR_FIND)))
70347+ return 0;
70348+
70349+ return GR_FIND;
70350+}
70351+
70352+__u32
70353+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
70354+ int acc_mode)
70355+{
70356+ __u32 reqmode = GR_FIND;
70357+ __u32 mode;
70358+
70359+ if (unlikely(d_is_negative(dentry)))
70360+ return reqmode;
70361+
70362+ if (acc_mode & MAY_APPEND)
70363+ reqmode |= GR_APPEND;
70364+ else if (acc_mode & MAY_WRITE)
70365+ reqmode |= GR_WRITE;
70366+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
70367+ reqmode |= GR_READ;
70368+
70369+ mode =
70370+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
70371+ mnt);
70372+
70373+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70374+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
70375+ reqmode & GR_READ ? " reading" : "",
70376+ reqmode & GR_WRITE ? " writing" : reqmode &
70377+ GR_APPEND ? " appending" : "");
70378+ return reqmode;
70379+ } else
70380+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70381+ {
70382+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
70383+ reqmode & GR_READ ? " reading" : "",
70384+ reqmode & GR_WRITE ? " writing" : reqmode &
70385+ GR_APPEND ? " appending" : "");
70386+ return 0;
70387+ } else if (unlikely((mode & reqmode) != reqmode))
70388+ return 0;
70389+
70390+ return reqmode;
70391+}
70392+
70393+__u32
70394+gr_acl_handle_creat(const struct dentry * dentry,
70395+ const struct dentry * p_dentry,
70396+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
70397+ const int imode)
70398+{
70399+ __u32 reqmode = GR_WRITE | GR_CREATE;
70400+ __u32 mode;
70401+
70402+ if (acc_mode & MAY_APPEND)
70403+ reqmode |= GR_APPEND;
70404+ // if a directory was required or the directory already exists, then
70405+ // don't count this open as a read
70406+ if ((acc_mode & MAY_READ) &&
70407+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
70408+ reqmode |= GR_READ;
70409+ if ((open_flags & O_CREAT) &&
70410+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
70411+ reqmode |= GR_SETID;
70412+
70413+ mode =
70414+ gr_check_create(dentry, p_dentry, p_mnt,
70415+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
70416+
70417+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70418+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
70419+ reqmode & GR_READ ? " reading" : "",
70420+ reqmode & GR_WRITE ? " writing" : reqmode &
70421+ GR_APPEND ? " appending" : "");
70422+ return reqmode;
70423+ } else
70424+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70425+ {
70426+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
70427+ reqmode & GR_READ ? " reading" : "",
70428+ reqmode & GR_WRITE ? " writing" : reqmode &
70429+ GR_APPEND ? " appending" : "");
70430+ return 0;
70431+ } else if (unlikely((mode & reqmode) != reqmode))
70432+ return 0;
70433+
70434+ return reqmode;
70435+}
70436+
70437+__u32
70438+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
70439+ const int fmode)
70440+{
70441+ __u32 mode, reqmode = GR_FIND;
70442+
70443+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
70444+ reqmode |= GR_EXEC;
70445+ if (fmode & S_IWOTH)
70446+ reqmode |= GR_WRITE;
70447+ if (fmode & S_IROTH)
70448+ reqmode |= GR_READ;
70449+
70450+ mode =
70451+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
70452+ mnt);
70453+
70454+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70455+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
70456+ reqmode & GR_READ ? " reading" : "",
70457+ reqmode & GR_WRITE ? " writing" : "",
70458+ reqmode & GR_EXEC ? " executing" : "");
70459+ return reqmode;
70460+ } else
70461+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70462+ {
70463+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
70464+ reqmode & GR_READ ? " reading" : "",
70465+ reqmode & GR_WRITE ? " writing" : "",
70466+ reqmode & GR_EXEC ? " executing" : "");
70467+ return 0;
70468+ } else if (unlikely((mode & reqmode) != reqmode))
70469+ return 0;
70470+
70471+ return reqmode;
70472+}
70473+
70474+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
70475+{
70476+ __u32 mode;
70477+
70478+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
70479+
70480+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
70481+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
70482+ return mode;
70483+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
70484+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
70485+ return 0;
70486+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
70487+ return 0;
70488+
70489+ return (reqmode);
70490+}
70491+
70492+__u32
70493+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
70494+{
70495+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
70496+}
70497+
70498+__u32
70499+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
70500+{
70501+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
70502+}
70503+
70504+__u32
70505+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
70506+{
70507+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
70508+}
70509+
70510+__u32
70511+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
70512+{
70513+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
70514+}
70515+
70516+__u32
70517+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
70518+ umode_t *modeptr)
70519+{
70520+ umode_t mode;
70521+
70522+ *modeptr &= ~gr_acl_umask();
70523+ mode = *modeptr;
70524+
70525+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
70526+ return 1;
70527+
70528+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
70529+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
70530+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
70531+ GR_CHMOD_ACL_MSG);
70532+ } else {
70533+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
70534+ }
70535+}
70536+
70537+__u32
70538+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
70539+{
70540+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
70541+}
70542+
70543+__u32
70544+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
70545+{
70546+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
70547+}
70548+
70549+__u32
70550+gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
70551+{
70552+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
70553+}
70554+
70555+__u32
70556+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
70557+{
70558+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
70559+}
70560+
70561+__u32
70562+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
70563+{
70564+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
70565+ GR_UNIXCONNECT_ACL_MSG);
70566+}
70567+
70568+/* hardlinks require at minimum create and link permission,
70569+ any additional privilege required is based on the
70570+ privilege of the file being linked to
70571+*/
70572+__u32
70573+gr_acl_handle_link(const struct dentry * new_dentry,
70574+ const struct dentry * parent_dentry,
70575+ const struct vfsmount * parent_mnt,
70576+ const struct dentry * old_dentry,
70577+ const struct vfsmount * old_mnt, const struct filename *to)
70578+{
70579+ __u32 mode;
70580+ __u32 needmode = GR_CREATE | GR_LINK;
70581+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
70582+
70583+ mode =
70584+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
70585+ old_mnt);
70586+
70587+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
70588+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
70589+ return mode;
70590+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
70591+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
70592+ return 0;
70593+ } else if (unlikely((mode & needmode) != needmode))
70594+ return 0;
70595+
70596+ return 1;
70597+}
70598+
70599+__u32
70600+gr_acl_handle_symlink(const struct dentry * new_dentry,
70601+ const struct dentry * parent_dentry,
70602+ const struct vfsmount * parent_mnt, const struct filename *from)
70603+{
70604+ __u32 needmode = GR_WRITE | GR_CREATE;
70605+ __u32 mode;
70606+
70607+ mode =
70608+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
70609+ GR_CREATE | GR_AUDIT_CREATE |
70610+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
70611+
70612+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
70613+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
70614+ return mode;
70615+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
70616+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
70617+ return 0;
70618+ } else if (unlikely((mode & needmode) != needmode))
70619+ return 0;
70620+
70621+ return (GR_WRITE | GR_CREATE);
70622+}
70623+
70624+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)
70625+{
70626+ __u32 mode;
70627+
70628+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
70629+
70630+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
70631+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
70632+ return mode;
70633+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
70634+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
70635+ return 0;
70636+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
70637+ return 0;
70638+
70639+ return (reqmode);
70640+}
70641+
70642+__u32
70643+gr_acl_handle_mknod(const struct dentry * new_dentry,
70644+ const struct dentry * parent_dentry,
70645+ const struct vfsmount * parent_mnt,
70646+ const int mode)
70647+{
70648+ __u32 reqmode = GR_WRITE | GR_CREATE;
70649+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
70650+ reqmode |= GR_SETID;
70651+
70652+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
70653+ reqmode, GR_MKNOD_ACL_MSG);
70654+}
70655+
70656+__u32
70657+gr_acl_handle_mkdir(const struct dentry *new_dentry,
70658+ const struct dentry *parent_dentry,
70659+ const struct vfsmount *parent_mnt)
70660+{
70661+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
70662+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
70663+}
70664+
70665+#define RENAME_CHECK_SUCCESS(old, new) \
70666+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
70667+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
70668+
70669+int
70670+gr_acl_handle_rename(struct dentry *new_dentry,
70671+ struct dentry *parent_dentry,
70672+ const struct vfsmount *parent_mnt,
70673+ struct dentry *old_dentry,
70674+ struct inode *old_parent_inode,
70675+ struct vfsmount *old_mnt, const struct filename *newname)
70676+{
70677+ __u32 comp1, comp2;
70678+ int error = 0;
70679+
70680+ if (unlikely(!gr_acl_is_enabled()))
70681+ return 0;
70682+
70683+ if (d_is_negative(new_dentry)) {
70684+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
70685+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
70686+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
70687+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
70688+ GR_DELETE | GR_AUDIT_DELETE |
70689+ GR_AUDIT_READ | GR_AUDIT_WRITE |
70690+ GR_SUPPRESS, old_mnt);
70691+ } else {
70692+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
70693+ GR_CREATE | GR_DELETE |
70694+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
70695+ GR_AUDIT_READ | GR_AUDIT_WRITE |
70696+ GR_SUPPRESS, parent_mnt);
70697+ comp2 =
70698+ gr_search_file(old_dentry,
70699+ GR_READ | GR_WRITE | GR_AUDIT_READ |
70700+ GR_DELETE | GR_AUDIT_DELETE |
70701+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
70702+ }
70703+
70704+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
70705+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
70706+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
70707+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
70708+ && !(comp2 & GR_SUPPRESS)) {
70709+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
70710+ error = -EACCES;
70711+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
70712+ error = -EACCES;
70713+
70714+ return error;
70715+}
70716+
70717+void
70718+gr_acl_handle_exit(void)
70719+{
70720+ u16 id;
70721+ char *rolename;
70722+
70723+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
70724+ !(current->role->roletype & GR_ROLE_PERSIST))) {
70725+ id = current->acl_role_id;
70726+ rolename = current->role->rolename;
70727+ gr_set_acls(1);
70728+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
70729+ }
70730+
70731+ gr_put_exec_file(current);
70732+ return;
70733+}
70734+
70735+int
70736+gr_acl_handle_procpidmem(const struct task_struct *task)
70737+{
70738+ if (unlikely(!gr_acl_is_enabled()))
70739+ return 0;
70740+
70741+ if (task != current && task->acl->mode & GR_PROTPROCFD)
70742+ return -EACCES;
70743+
70744+ return 0;
70745+}
70746diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
70747new file mode 100644
70748index 0000000..f056b81
70749--- /dev/null
70750+++ b/grsecurity/gracl_ip.c
70751@@ -0,0 +1,386 @@
70752+#include <linux/kernel.h>
70753+#include <asm/uaccess.h>
70754+#include <asm/errno.h>
70755+#include <net/sock.h>
70756+#include <linux/file.h>
70757+#include <linux/fs.h>
70758+#include <linux/net.h>
70759+#include <linux/in.h>
70760+#include <linux/skbuff.h>
70761+#include <linux/ip.h>
70762+#include <linux/udp.h>
70763+#include <linux/types.h>
70764+#include <linux/sched.h>
70765+#include <linux/netdevice.h>
70766+#include <linux/inetdevice.h>
70767+#include <linux/gracl.h>
70768+#include <linux/grsecurity.h>
70769+#include <linux/grinternal.h>
70770+
70771+#define GR_BIND 0x01
70772+#define GR_CONNECT 0x02
70773+#define GR_INVERT 0x04
70774+#define GR_BINDOVERRIDE 0x08
70775+#define GR_CONNECTOVERRIDE 0x10
70776+#define GR_SOCK_FAMILY 0x20
70777+
70778+static const char * gr_protocols[IPPROTO_MAX] = {
70779+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
70780+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
70781+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
70782+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
70783+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
70784+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
70785+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
70786+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
70787+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
70788+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
70789+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
70790+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
70791+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
70792+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
70793+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
70794+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
70795+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
70796+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
70797+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
70798+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
70799+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
70800+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
70801+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
70802+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
70803+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
70804+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
70805+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
70806+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
70807+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
70808+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
70809+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
70810+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
70811+ };
70812+
70813+static const char * gr_socktypes[SOCK_MAX] = {
70814+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
70815+ "unknown:7", "unknown:8", "unknown:9", "packet"
70816+ };
70817+
70818+static const char * gr_sockfamilies[AF_MAX+1] = {
70819+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
70820+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
70821+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
70822+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
70823+ };
70824+
70825+const char *
70826+gr_proto_to_name(unsigned char proto)
70827+{
70828+ return gr_protocols[proto];
70829+}
70830+
70831+const char *
70832+gr_socktype_to_name(unsigned char type)
70833+{
70834+ return gr_socktypes[type];
70835+}
70836+
70837+const char *
70838+gr_sockfamily_to_name(unsigned char family)
70839+{
70840+ return gr_sockfamilies[family];
70841+}
70842+
70843+extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
70844+
70845+int
70846+gr_search_socket(const int domain, const int type, const int protocol)
70847+{
70848+ struct acl_subject_label *curr;
70849+ const struct cred *cred = current_cred();
70850+
70851+ if (unlikely(!gr_acl_is_enabled()))
70852+ goto exit;
70853+
70854+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
70855+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
70856+ goto exit; // let the kernel handle it
70857+
70858+ curr = current->acl;
70859+
70860+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
70861+ /* the family is allowed, if this is PF_INET allow it only if
70862+ the extra sock type/protocol checks pass */
70863+ if (domain == PF_INET)
70864+ goto inet_check;
70865+ goto exit;
70866+ } else {
70867+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70868+ __u32 fakeip = 0;
70869+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70870+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
70871+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
70872+ gr_to_filename(current->exec_file->f_path.dentry,
70873+ current->exec_file->f_path.mnt) :
70874+ curr->filename, curr->filename,
70875+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
70876+ &current->signal->saved_ip);
70877+ goto exit;
70878+ }
70879+ goto exit_fail;
70880+ }
70881+
70882+inet_check:
70883+ /* the rest of this checking is for IPv4 only */
70884+ if (!curr->ips)
70885+ goto exit;
70886+
70887+ if ((curr->ip_type & (1U << type)) &&
70888+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
70889+ goto exit;
70890+
70891+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70892+ /* we don't place acls on raw sockets , and sometimes
70893+ dgram/ip sockets are opened for ioctl and not
70894+ bind/connect, so we'll fake a bind learn log */
70895+ if (type == SOCK_RAW || type == SOCK_PACKET) {
70896+ __u32 fakeip = 0;
70897+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70898+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
70899+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
70900+ gr_to_filename(current->exec_file->f_path.dentry,
70901+ current->exec_file->f_path.mnt) :
70902+ curr->filename, curr->filename,
70903+ &fakeip, 0, type,
70904+ protocol, GR_CONNECT, &current->signal->saved_ip);
70905+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
70906+ __u32 fakeip = 0;
70907+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70908+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
70909+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
70910+ gr_to_filename(current->exec_file->f_path.dentry,
70911+ current->exec_file->f_path.mnt) :
70912+ curr->filename, curr->filename,
70913+ &fakeip, 0, type,
70914+ protocol, GR_BIND, &current->signal->saved_ip);
70915+ }
70916+ /* we'll log when they use connect or bind */
70917+ goto exit;
70918+ }
70919+
70920+exit_fail:
70921+ if (domain == PF_INET)
70922+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
70923+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
70924+ else if (rcu_access_pointer(net_families[domain]) != NULL)
70925+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
70926+ gr_socktype_to_name(type), protocol);
70927+
70928+ return 0;
70929+exit:
70930+ return 1;
70931+}
70932+
70933+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)
70934+{
70935+ if ((ip->mode & mode) &&
70936+ (ip_port >= ip->low) &&
70937+ (ip_port <= ip->high) &&
70938+ ((ntohl(ip_addr) & our_netmask) ==
70939+ (ntohl(our_addr) & our_netmask))
70940+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
70941+ && (ip->type & (1U << type))) {
70942+ if (ip->mode & GR_INVERT)
70943+ return 2; // specifically denied
70944+ else
70945+ return 1; // allowed
70946+ }
70947+
70948+ return 0; // not specifically allowed, may continue parsing
70949+}
70950+
70951+static int
70952+gr_search_connectbind(const int full_mode, struct sock *sk,
70953+ struct sockaddr_in *addr, const int type)
70954+{
70955+ char iface[IFNAMSIZ] = {0};
70956+ struct acl_subject_label *curr;
70957+ struct acl_ip_label *ip;
70958+ struct inet_sock *isk;
70959+ struct net_device *dev;
70960+ struct in_device *idev;
70961+ unsigned long i;
70962+ int ret;
70963+ int mode = full_mode & (GR_BIND | GR_CONNECT);
70964+ __u32 ip_addr = 0;
70965+ __u32 our_addr;
70966+ __u32 our_netmask;
70967+ char *p;
70968+ __u16 ip_port = 0;
70969+ const struct cred *cred = current_cred();
70970+
70971+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
70972+ return 0;
70973+
70974+ curr = current->acl;
70975+ isk = inet_sk(sk);
70976+
70977+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
70978+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
70979+ addr->sin_addr.s_addr = curr->inaddr_any_override;
70980+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
70981+ struct sockaddr_in saddr;
70982+ int err;
70983+
70984+ saddr.sin_family = AF_INET;
70985+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
70986+ saddr.sin_port = isk->inet_sport;
70987+
70988+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
70989+ if (err)
70990+ return err;
70991+
70992+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
70993+ if (err)
70994+ return err;
70995+ }
70996+
70997+ if (!curr->ips)
70998+ return 0;
70999+
71000+ ip_addr = addr->sin_addr.s_addr;
71001+ ip_port = ntohs(addr->sin_port);
71002+
71003+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
71004+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
71005+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
71006+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
71007+ gr_to_filename(current->exec_file->f_path.dentry,
71008+ current->exec_file->f_path.mnt) :
71009+ curr->filename, curr->filename,
71010+ &ip_addr, ip_port, type,
71011+ sk->sk_protocol, mode, &current->signal->saved_ip);
71012+ return 0;
71013+ }
71014+
71015+ for (i = 0; i < curr->ip_num; i++) {
71016+ ip = *(curr->ips + i);
71017+ if (ip->iface != NULL) {
71018+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
71019+ p = strchr(iface, ':');
71020+ if (p != NULL)
71021+ *p = '\0';
71022+ dev = dev_get_by_name(sock_net(sk), iface);
71023+ if (dev == NULL)
71024+ continue;
71025+ idev = in_dev_get(dev);
71026+ if (idev == NULL) {
71027+ dev_put(dev);
71028+ continue;
71029+ }
71030+ rcu_read_lock();
71031+ for_ifa(idev) {
71032+ if (!strcmp(ip->iface, ifa->ifa_label)) {
71033+ our_addr = ifa->ifa_address;
71034+ our_netmask = 0xffffffff;
71035+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
71036+ if (ret == 1) {
71037+ rcu_read_unlock();
71038+ in_dev_put(idev);
71039+ dev_put(dev);
71040+ return 0;
71041+ } else if (ret == 2) {
71042+ rcu_read_unlock();
71043+ in_dev_put(idev);
71044+ dev_put(dev);
71045+ goto denied;
71046+ }
71047+ }
71048+ } endfor_ifa(idev);
71049+ rcu_read_unlock();
71050+ in_dev_put(idev);
71051+ dev_put(dev);
71052+ } else {
71053+ our_addr = ip->addr;
71054+ our_netmask = ip->netmask;
71055+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
71056+ if (ret == 1)
71057+ return 0;
71058+ else if (ret == 2)
71059+ goto denied;
71060+ }
71061+ }
71062+
71063+denied:
71064+ if (mode == GR_BIND)
71065+ 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));
71066+ else if (mode == GR_CONNECT)
71067+ 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));
71068+
71069+ return -EACCES;
71070+}
71071+
71072+int
71073+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
71074+{
71075+ /* always allow disconnection of dgram sockets with connect */
71076+ if (addr->sin_family == AF_UNSPEC)
71077+ return 0;
71078+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
71079+}
71080+
71081+int
71082+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
71083+{
71084+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
71085+}
71086+
71087+int gr_search_listen(struct socket *sock)
71088+{
71089+ struct sock *sk = sock->sk;
71090+ struct sockaddr_in addr;
71091+
71092+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
71093+ addr.sin_port = inet_sk(sk)->inet_sport;
71094+
71095+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
71096+}
71097+
71098+int gr_search_accept(struct socket *sock)
71099+{
71100+ struct sock *sk = sock->sk;
71101+ struct sockaddr_in addr;
71102+
71103+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
71104+ addr.sin_port = inet_sk(sk)->inet_sport;
71105+
71106+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
71107+}
71108+
71109+int
71110+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
71111+{
71112+ if (addr)
71113+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
71114+ else {
71115+ struct sockaddr_in sin;
71116+ const struct inet_sock *inet = inet_sk(sk);
71117+
71118+ sin.sin_addr.s_addr = inet->inet_daddr;
71119+ sin.sin_port = inet->inet_dport;
71120+
71121+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
71122+ }
71123+}
71124+
71125+int
71126+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
71127+{
71128+ struct sockaddr_in sin;
71129+
71130+ if (unlikely(skb->len < sizeof (struct udphdr)))
71131+ return 0; // skip this packet
71132+
71133+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
71134+ sin.sin_port = udp_hdr(skb)->source;
71135+
71136+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
71137+}
71138diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
71139new file mode 100644
71140index 0000000..25f54ef
71141--- /dev/null
71142+++ b/grsecurity/gracl_learn.c
71143@@ -0,0 +1,207 @@
71144+#include <linux/kernel.h>
71145+#include <linux/mm.h>
71146+#include <linux/sched.h>
71147+#include <linux/poll.h>
71148+#include <linux/string.h>
71149+#include <linux/file.h>
71150+#include <linux/types.h>
71151+#include <linux/vmalloc.h>
71152+#include <linux/grinternal.h>
71153+
71154+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
71155+ size_t count, loff_t *ppos);
71156+extern int gr_acl_is_enabled(void);
71157+
71158+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
71159+static int gr_learn_attached;
71160+
71161+/* use a 512k buffer */
71162+#define LEARN_BUFFER_SIZE (512 * 1024)
71163+
71164+static DEFINE_SPINLOCK(gr_learn_lock);
71165+static DEFINE_MUTEX(gr_learn_user_mutex);
71166+
71167+/* we need to maintain two buffers, so that the kernel context of grlearn
71168+ uses a semaphore around the userspace copying, and the other kernel contexts
71169+ use a spinlock when copying into the buffer, since they cannot sleep
71170+*/
71171+static char *learn_buffer;
71172+static char *learn_buffer_user;
71173+static int learn_buffer_len;
71174+static int learn_buffer_user_len;
71175+
71176+static ssize_t
71177+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
71178+{
71179+ DECLARE_WAITQUEUE(wait, current);
71180+ ssize_t retval = 0;
71181+
71182+ add_wait_queue(&learn_wait, &wait);
71183+ set_current_state(TASK_INTERRUPTIBLE);
71184+ do {
71185+ mutex_lock(&gr_learn_user_mutex);
71186+ spin_lock(&gr_learn_lock);
71187+ if (learn_buffer_len)
71188+ break;
71189+ spin_unlock(&gr_learn_lock);
71190+ mutex_unlock(&gr_learn_user_mutex);
71191+ if (file->f_flags & O_NONBLOCK) {
71192+ retval = -EAGAIN;
71193+ goto out;
71194+ }
71195+ if (signal_pending(current)) {
71196+ retval = -ERESTARTSYS;
71197+ goto out;
71198+ }
71199+
71200+ schedule();
71201+ } while (1);
71202+
71203+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
71204+ learn_buffer_user_len = learn_buffer_len;
71205+ retval = learn_buffer_len;
71206+ learn_buffer_len = 0;
71207+
71208+ spin_unlock(&gr_learn_lock);
71209+
71210+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
71211+ retval = -EFAULT;
71212+
71213+ mutex_unlock(&gr_learn_user_mutex);
71214+out:
71215+ set_current_state(TASK_RUNNING);
71216+ remove_wait_queue(&learn_wait, &wait);
71217+ return retval;
71218+}
71219+
71220+static unsigned int
71221+poll_learn(struct file * file, poll_table * wait)
71222+{
71223+ poll_wait(file, &learn_wait, wait);
71224+
71225+ if (learn_buffer_len)
71226+ return (POLLIN | POLLRDNORM);
71227+
71228+ return 0;
71229+}
71230+
71231+void
71232+gr_clear_learn_entries(void)
71233+{
71234+ char *tmp;
71235+
71236+ mutex_lock(&gr_learn_user_mutex);
71237+ spin_lock(&gr_learn_lock);
71238+ tmp = learn_buffer;
71239+ learn_buffer = NULL;
71240+ spin_unlock(&gr_learn_lock);
71241+ if (tmp)
71242+ vfree(tmp);
71243+ if (learn_buffer_user != NULL) {
71244+ vfree(learn_buffer_user);
71245+ learn_buffer_user = NULL;
71246+ }
71247+ learn_buffer_len = 0;
71248+ mutex_unlock(&gr_learn_user_mutex);
71249+
71250+ return;
71251+}
71252+
71253+void
71254+gr_add_learn_entry(const char *fmt, ...)
71255+{
71256+ va_list args;
71257+ unsigned int len;
71258+
71259+ if (!gr_learn_attached)
71260+ return;
71261+
71262+ spin_lock(&gr_learn_lock);
71263+
71264+ /* leave a gap at the end so we know when it's "full" but don't have to
71265+ compute the exact length of the string we're trying to append
71266+ */
71267+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
71268+ spin_unlock(&gr_learn_lock);
71269+ wake_up_interruptible(&learn_wait);
71270+ return;
71271+ }
71272+ if (learn_buffer == NULL) {
71273+ spin_unlock(&gr_learn_lock);
71274+ return;
71275+ }
71276+
71277+ va_start(args, fmt);
71278+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
71279+ va_end(args);
71280+
71281+ learn_buffer_len += len + 1;
71282+
71283+ spin_unlock(&gr_learn_lock);
71284+ wake_up_interruptible(&learn_wait);
71285+
71286+ return;
71287+}
71288+
71289+static int
71290+open_learn(struct inode *inode, struct file *file)
71291+{
71292+ if (file->f_mode & FMODE_READ && gr_learn_attached)
71293+ return -EBUSY;
71294+ if (file->f_mode & FMODE_READ) {
71295+ int retval = 0;
71296+ mutex_lock(&gr_learn_user_mutex);
71297+ if (learn_buffer == NULL)
71298+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
71299+ if (learn_buffer_user == NULL)
71300+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
71301+ if (learn_buffer == NULL) {
71302+ retval = -ENOMEM;
71303+ goto out_error;
71304+ }
71305+ if (learn_buffer_user == NULL) {
71306+ retval = -ENOMEM;
71307+ goto out_error;
71308+ }
71309+ learn_buffer_len = 0;
71310+ learn_buffer_user_len = 0;
71311+ gr_learn_attached = 1;
71312+out_error:
71313+ mutex_unlock(&gr_learn_user_mutex);
71314+ return retval;
71315+ }
71316+ return 0;
71317+}
71318+
71319+static int
71320+close_learn(struct inode *inode, struct file *file)
71321+{
71322+ if (file->f_mode & FMODE_READ) {
71323+ char *tmp = NULL;
71324+ mutex_lock(&gr_learn_user_mutex);
71325+ spin_lock(&gr_learn_lock);
71326+ tmp = learn_buffer;
71327+ learn_buffer = NULL;
71328+ spin_unlock(&gr_learn_lock);
71329+ if (tmp)
71330+ vfree(tmp);
71331+ if (learn_buffer_user != NULL) {
71332+ vfree(learn_buffer_user);
71333+ learn_buffer_user = NULL;
71334+ }
71335+ learn_buffer_len = 0;
71336+ learn_buffer_user_len = 0;
71337+ gr_learn_attached = 0;
71338+ mutex_unlock(&gr_learn_user_mutex);
71339+ }
71340+
71341+ return 0;
71342+}
71343+
71344+const struct file_operations grsec_fops = {
71345+ .read = read_learn,
71346+ .write = write_grsec_handler,
71347+ .open = open_learn,
71348+ .release = close_learn,
71349+ .poll = poll_learn,
71350+};
71351diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
71352new file mode 100644
71353index 0000000..361a099
71354--- /dev/null
71355+++ b/grsecurity/gracl_policy.c
71356@@ -0,0 +1,1782 @@
71357+#include <linux/kernel.h>
71358+#include <linux/module.h>
71359+#include <linux/sched.h>
71360+#include <linux/mm.h>
71361+#include <linux/file.h>
71362+#include <linux/fs.h>
71363+#include <linux/namei.h>
71364+#include <linux/mount.h>
71365+#include <linux/tty.h>
71366+#include <linux/proc_fs.h>
71367+#include <linux/lglock.h>
71368+#include <linux/slab.h>
71369+#include <linux/vmalloc.h>
71370+#include <linux/types.h>
71371+#include <linux/sysctl.h>
71372+#include <linux/netdevice.h>
71373+#include <linux/ptrace.h>
71374+#include <linux/gracl.h>
71375+#include <linux/gralloc.h>
71376+#include <linux/security.h>
71377+#include <linux/grinternal.h>
71378+#include <linux/pid_namespace.h>
71379+#include <linux/stop_machine.h>
71380+#include <linux/fdtable.h>
71381+#include <linux/percpu.h>
71382+#include <linux/lglock.h>
71383+#include <linux/hugetlb.h>
71384+#include <linux/posix-timers.h>
71385+#include "../fs/mount.h"
71386+
71387+#include <asm/uaccess.h>
71388+#include <asm/errno.h>
71389+#include <asm/mman.h>
71390+
71391+extern struct gr_policy_state *polstate;
71392+
71393+#define FOR_EACH_ROLE_START(role) \
71394+ role = polstate->role_list; \
71395+ while (role) {
71396+
71397+#define FOR_EACH_ROLE_END(role) \
71398+ role = role->prev; \
71399+ }
71400+
71401+struct path gr_real_root;
71402+
71403+extern struct gr_alloc_state *current_alloc_state;
71404+
71405+u16 acl_sp_role_value;
71406+
71407+static DEFINE_MUTEX(gr_dev_mutex);
71408+
71409+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
71410+extern void gr_clear_learn_entries(void);
71411+
71412+static struct gr_arg gr_usermode;
71413+static unsigned char gr_system_salt[GR_SALT_LEN];
71414+static unsigned char gr_system_sum[GR_SHA_LEN];
71415+
71416+static unsigned int gr_auth_attempts = 0;
71417+static unsigned long gr_auth_expires = 0UL;
71418+
71419+struct acl_object_label *fakefs_obj_rw;
71420+struct acl_object_label *fakefs_obj_rwx;
71421+
71422+extern int gr_init_uidset(void);
71423+extern void gr_free_uidset(void);
71424+extern void gr_remove_uid(uid_t uid);
71425+extern int gr_find_uid(uid_t uid);
71426+
71427+extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
71428+extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
71429+extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
71430+extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
71431+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);
71432+extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
71433+extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
71434+extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
71435+extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
71436+extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
71437+extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
71438+extern void assign_special_role(const char *rolename);
71439+extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
71440+extern int gr_rbac_disable(void *unused);
71441+extern void gr_enable_rbac_system(void);
71442+
71443+static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
71444+{
71445+ if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
71446+ return -EFAULT;
71447+
71448+ return 0;
71449+}
71450+
71451+static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
71452+{
71453+ if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
71454+ return -EFAULT;
71455+
71456+ return 0;
71457+}
71458+
71459+static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
71460+{
71461+ if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
71462+ return -EFAULT;
71463+
71464+ return 0;
71465+}
71466+
71467+static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
71468+{
71469+ if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
71470+ return -EFAULT;
71471+
71472+ return 0;
71473+}
71474+
71475+static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
71476+{
71477+ if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
71478+ return -EFAULT;
71479+
71480+ return 0;
71481+}
71482+
71483+static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
71484+{
71485+ if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
71486+ return -EFAULT;
71487+
71488+ return 0;
71489+}
71490+
71491+static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
71492+{
71493+ if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
71494+ return -EFAULT;
71495+
71496+ return 0;
71497+}
71498+
71499+static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
71500+{
71501+ if (copy_from_user(trans, userp, sizeof(struct role_transition)))
71502+ return -EFAULT;
71503+
71504+ return 0;
71505+}
71506+
71507+int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
71508+{
71509+ if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
71510+ return -EFAULT;
71511+
71512+ return 0;
71513+}
71514+
71515+static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
71516+{
71517+ if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
71518+ return -EFAULT;
71519+
71520+ if (((uwrap->version != GRSECURITY_VERSION) &&
71521+ (uwrap->version != 0x2901)) ||
71522+ (uwrap->size != sizeof(struct gr_arg)))
71523+ return -EINVAL;
71524+
71525+ return 0;
71526+}
71527+
71528+static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
71529+{
71530+ if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
71531+ return -EFAULT;
71532+
71533+ return 0;
71534+}
71535+
71536+static size_t get_gr_arg_wrapper_size_normal(void)
71537+{
71538+ return sizeof(struct gr_arg_wrapper);
71539+}
71540+
71541+#ifdef CONFIG_COMPAT
71542+extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
71543+extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
71544+extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
71545+extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
71546+extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
71547+extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
71548+extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
71549+extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
71550+extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
71551+extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
71552+extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
71553+extern size_t get_gr_arg_wrapper_size_compat(void);
71554+
71555+int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
71556+int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
71557+int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
71558+int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
71559+int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
71560+int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
71561+int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
71562+int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
71563+int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
71564+int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
71565+int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
71566+size_t (* get_gr_arg_wrapper_size)(void) __read_only;
71567+
71568+#else
71569+#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
71570+#define copy_gr_arg copy_gr_arg_normal
71571+#define copy_gr_hash_struct copy_gr_hash_struct_normal
71572+#define copy_acl_object_label copy_acl_object_label_normal
71573+#define copy_acl_subject_label copy_acl_subject_label_normal
71574+#define copy_acl_role_label copy_acl_role_label_normal
71575+#define copy_acl_ip_label copy_acl_ip_label_normal
71576+#define copy_pointer_from_array copy_pointer_from_array_normal
71577+#define copy_sprole_pw copy_sprole_pw_normal
71578+#define copy_role_transition copy_role_transition_normal
71579+#define copy_role_allowed_ip copy_role_allowed_ip_normal
71580+#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
71581+#endif
71582+
71583+static struct acl_subject_label *
71584+lookup_subject_map(const struct acl_subject_label *userp)
71585+{
71586+ unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
71587+ struct subject_map *match;
71588+
71589+ match = polstate->subj_map_set.s_hash[index];
71590+
71591+ while (match && match->user != userp)
71592+ match = match->next;
71593+
71594+ if (match != NULL)
71595+ return match->kernel;
71596+ else
71597+ return NULL;
71598+}
71599+
71600+static void
71601+insert_subj_map_entry(struct subject_map *subjmap)
71602+{
71603+ unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
71604+ struct subject_map **curr;
71605+
71606+ subjmap->prev = NULL;
71607+
71608+ curr = &polstate->subj_map_set.s_hash[index];
71609+ if (*curr != NULL)
71610+ (*curr)->prev = subjmap;
71611+
71612+ subjmap->next = *curr;
71613+ *curr = subjmap;
71614+
71615+ return;
71616+}
71617+
71618+static void
71619+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
71620+{
71621+ unsigned int index =
71622+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
71623+ struct acl_role_label **curr;
71624+ struct acl_role_label *tmp, *tmp2;
71625+
71626+ curr = &polstate->acl_role_set.r_hash[index];
71627+
71628+ /* simple case, slot is empty, just set it to our role */
71629+ if (*curr == NULL) {
71630+ *curr = role;
71631+ } else {
71632+ /* example:
71633+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
71634+ 2 -> 3
71635+ */
71636+ /* first check to see if we can already be reached via this slot */
71637+ tmp = *curr;
71638+ while (tmp && tmp != role)
71639+ tmp = tmp->next;
71640+ if (tmp == role) {
71641+ /* we don't need to add ourselves to this slot's chain */
71642+ return;
71643+ }
71644+ /* we need to add ourselves to this chain, two cases */
71645+ if (role->next == NULL) {
71646+ /* simple case, append the current chain to our role */
71647+ role->next = *curr;
71648+ *curr = role;
71649+ } else {
71650+ /* 1 -> 2 -> 3 -> 4
71651+ 2 -> 3 -> 4
71652+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
71653+ */
71654+ /* trickier case: walk our role's chain until we find
71655+ the role for the start of the current slot's chain */
71656+ tmp = role;
71657+ tmp2 = *curr;
71658+ while (tmp->next && tmp->next != tmp2)
71659+ tmp = tmp->next;
71660+ if (tmp->next == tmp2) {
71661+ /* from example above, we found 3, so just
71662+ replace this slot's chain with ours */
71663+ *curr = role;
71664+ } else {
71665+ /* we didn't find a subset of our role's chain
71666+ in the current slot's chain, so append their
71667+ chain to ours, and set us as the first role in
71668+ the slot's chain
71669+
71670+ we could fold this case with the case above,
71671+ but making it explicit for clarity
71672+ */
71673+ tmp->next = tmp2;
71674+ *curr = role;
71675+ }
71676+ }
71677+ }
71678+
71679+ return;
71680+}
71681+
71682+static void
71683+insert_acl_role_label(struct acl_role_label *role)
71684+{
71685+ int i;
71686+
71687+ if (polstate->role_list == NULL) {
71688+ polstate->role_list = role;
71689+ role->prev = NULL;
71690+ } else {
71691+ role->prev = polstate->role_list;
71692+ polstate->role_list = role;
71693+ }
71694+
71695+ /* used for hash chains */
71696+ role->next = NULL;
71697+
71698+ if (role->roletype & GR_ROLE_DOMAIN) {
71699+ for (i = 0; i < role->domain_child_num; i++)
71700+ __insert_acl_role_label(role, role->domain_children[i]);
71701+ } else
71702+ __insert_acl_role_label(role, role->uidgid);
71703+}
71704+
71705+static int
71706+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
71707+{
71708+ struct name_entry **curr, *nentry;
71709+ struct inodev_entry *ientry;
71710+ unsigned int len = strlen(name);
71711+ unsigned int key = full_name_hash(name, len);
71712+ unsigned int index = key % polstate->name_set.n_size;
71713+
71714+ curr = &polstate->name_set.n_hash[index];
71715+
71716+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
71717+ curr = &((*curr)->next);
71718+
71719+ if (*curr != NULL)
71720+ return 1;
71721+
71722+ nentry = acl_alloc(sizeof (struct name_entry));
71723+ if (nentry == NULL)
71724+ return 0;
71725+ ientry = acl_alloc(sizeof (struct inodev_entry));
71726+ if (ientry == NULL)
71727+ return 0;
71728+ ientry->nentry = nentry;
71729+
71730+ nentry->key = key;
71731+ nentry->name = name;
71732+ nentry->inode = inode;
71733+ nentry->device = device;
71734+ nentry->len = len;
71735+ nentry->deleted = deleted;
71736+
71737+ nentry->prev = NULL;
71738+ curr = &polstate->name_set.n_hash[index];
71739+ if (*curr != NULL)
71740+ (*curr)->prev = nentry;
71741+ nentry->next = *curr;
71742+ *curr = nentry;
71743+
71744+ /* insert us into the table searchable by inode/dev */
71745+ __insert_inodev_entry(polstate, ientry);
71746+
71747+ return 1;
71748+}
71749+
71750+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
71751+
71752+static void *
71753+create_table(__u32 * len, int elementsize)
71754+{
71755+ unsigned int table_sizes[] = {
71756+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
71757+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
71758+ 4194301, 8388593, 16777213, 33554393, 67108859
71759+ };
71760+ void *newtable = NULL;
71761+ unsigned int pwr = 0;
71762+
71763+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
71764+ table_sizes[pwr] <= *len)
71765+ pwr++;
71766+
71767+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
71768+ return newtable;
71769+
71770+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
71771+ newtable =
71772+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
71773+ else
71774+ newtable = vmalloc(table_sizes[pwr] * elementsize);
71775+
71776+ *len = table_sizes[pwr];
71777+
71778+ return newtable;
71779+}
71780+
71781+static int
71782+init_variables(const struct gr_arg *arg, bool reload)
71783+{
71784+ struct task_struct *reaper = init_pid_ns.child_reaper;
71785+ unsigned int stacksize;
71786+
71787+ polstate->subj_map_set.s_size = arg->role_db.num_subjects;
71788+ polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
71789+ polstate->name_set.n_size = arg->role_db.num_objects;
71790+ polstate->inodev_set.i_size = arg->role_db.num_objects;
71791+
71792+ if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
71793+ !polstate->name_set.n_size || !polstate->inodev_set.i_size)
71794+ return 1;
71795+
71796+ if (!reload) {
71797+ if (!gr_init_uidset())
71798+ return 1;
71799+ }
71800+
71801+ /* set up the stack that holds allocation info */
71802+
71803+ stacksize = arg->role_db.num_pointers + 5;
71804+
71805+ if (!acl_alloc_stack_init(stacksize))
71806+ return 1;
71807+
71808+ if (!reload) {
71809+ /* grab reference for the real root dentry and vfsmount */
71810+ get_fs_root(reaper->fs, &gr_real_root);
71811+
71812+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71813+ 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);
71814+#endif
71815+
71816+ fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
71817+ if (fakefs_obj_rw == NULL)
71818+ return 1;
71819+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
71820+
71821+ fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
71822+ if (fakefs_obj_rwx == NULL)
71823+ return 1;
71824+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
71825+ }
71826+
71827+ polstate->subj_map_set.s_hash =
71828+ (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
71829+ polstate->acl_role_set.r_hash =
71830+ (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
71831+ polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
71832+ polstate->inodev_set.i_hash =
71833+ (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
71834+
71835+ if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
71836+ !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
71837+ return 1;
71838+
71839+ memset(polstate->subj_map_set.s_hash, 0,
71840+ sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
71841+ memset(polstate->acl_role_set.r_hash, 0,
71842+ sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
71843+ memset(polstate->name_set.n_hash, 0,
71844+ sizeof (struct name_entry *) * polstate->name_set.n_size);
71845+ memset(polstate->inodev_set.i_hash, 0,
71846+ sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
71847+
71848+ return 0;
71849+}
71850+
71851+/* free information not needed after startup
71852+ currently contains user->kernel pointer mappings for subjects
71853+*/
71854+
71855+static void
71856+free_init_variables(void)
71857+{
71858+ __u32 i;
71859+
71860+ if (polstate->subj_map_set.s_hash) {
71861+ for (i = 0; i < polstate->subj_map_set.s_size; i++) {
71862+ if (polstate->subj_map_set.s_hash[i]) {
71863+ kfree(polstate->subj_map_set.s_hash[i]);
71864+ polstate->subj_map_set.s_hash[i] = NULL;
71865+ }
71866+ }
71867+
71868+ if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
71869+ PAGE_SIZE)
71870+ kfree(polstate->subj_map_set.s_hash);
71871+ else
71872+ vfree(polstate->subj_map_set.s_hash);
71873+ }
71874+
71875+ return;
71876+}
71877+
71878+static void
71879+free_variables(bool reload)
71880+{
71881+ struct acl_subject_label *s;
71882+ struct acl_role_label *r;
71883+ struct task_struct *task, *task2;
71884+ unsigned int x;
71885+
71886+ if (!reload) {
71887+ gr_clear_learn_entries();
71888+
71889+ read_lock(&tasklist_lock);
71890+ do_each_thread(task2, task) {
71891+ task->acl_sp_role = 0;
71892+ task->acl_role_id = 0;
71893+ task->inherited = 0;
71894+ task->acl = NULL;
71895+ task->role = NULL;
71896+ } while_each_thread(task2, task);
71897+ read_unlock(&tasklist_lock);
71898+
71899+ kfree(fakefs_obj_rw);
71900+ fakefs_obj_rw = NULL;
71901+ kfree(fakefs_obj_rwx);
71902+ fakefs_obj_rwx = NULL;
71903+
71904+ /* release the reference to the real root dentry and vfsmount */
71905+ path_put(&gr_real_root);
71906+ memset(&gr_real_root, 0, sizeof(gr_real_root));
71907+ }
71908+
71909+ /* free all object hash tables */
71910+
71911+ FOR_EACH_ROLE_START(r)
71912+ if (r->subj_hash == NULL)
71913+ goto next_role;
71914+ FOR_EACH_SUBJECT_START(r, s, x)
71915+ if (s->obj_hash == NULL)
71916+ break;
71917+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
71918+ kfree(s->obj_hash);
71919+ else
71920+ vfree(s->obj_hash);
71921+ FOR_EACH_SUBJECT_END(s, x)
71922+ FOR_EACH_NESTED_SUBJECT_START(r, s)
71923+ if (s->obj_hash == NULL)
71924+ break;
71925+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
71926+ kfree(s->obj_hash);
71927+ else
71928+ vfree(s->obj_hash);
71929+ FOR_EACH_NESTED_SUBJECT_END(s)
71930+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
71931+ kfree(r->subj_hash);
71932+ else
71933+ vfree(r->subj_hash);
71934+ r->subj_hash = NULL;
71935+next_role:
71936+ FOR_EACH_ROLE_END(r)
71937+
71938+ acl_free_all();
71939+
71940+ if (polstate->acl_role_set.r_hash) {
71941+ if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
71942+ PAGE_SIZE)
71943+ kfree(polstate->acl_role_set.r_hash);
71944+ else
71945+ vfree(polstate->acl_role_set.r_hash);
71946+ }
71947+ if (polstate->name_set.n_hash) {
71948+ if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
71949+ PAGE_SIZE)
71950+ kfree(polstate->name_set.n_hash);
71951+ else
71952+ vfree(polstate->name_set.n_hash);
71953+ }
71954+
71955+ if (polstate->inodev_set.i_hash) {
71956+ if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
71957+ PAGE_SIZE)
71958+ kfree(polstate->inodev_set.i_hash);
71959+ else
71960+ vfree(polstate->inodev_set.i_hash);
71961+ }
71962+
71963+ if (!reload)
71964+ gr_free_uidset();
71965+
71966+ memset(&polstate->name_set, 0, sizeof (struct name_db));
71967+ memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
71968+ memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
71969+ memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
71970+
71971+ polstate->default_role = NULL;
71972+ polstate->kernel_role = NULL;
71973+ polstate->role_list = NULL;
71974+
71975+ return;
71976+}
71977+
71978+static struct acl_subject_label *
71979+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
71980+
71981+static int alloc_and_copy_string(char **name, unsigned int maxlen)
71982+{
71983+ unsigned int len = strnlen_user(*name, maxlen);
71984+ char *tmp;
71985+
71986+ if (!len || len >= maxlen)
71987+ return -EINVAL;
71988+
71989+ if ((tmp = (char *) acl_alloc(len)) == NULL)
71990+ return -ENOMEM;
71991+
71992+ if (copy_from_user(tmp, *name, len))
71993+ return -EFAULT;
71994+
71995+ tmp[len-1] = '\0';
71996+ *name = tmp;
71997+
71998+ return 0;
71999+}
72000+
72001+static int
72002+copy_user_glob(struct acl_object_label *obj)
72003+{
72004+ struct acl_object_label *g_tmp, **guser;
72005+ int error;
72006+
72007+ if (obj->globbed == NULL)
72008+ return 0;
72009+
72010+ guser = &obj->globbed;
72011+ while (*guser) {
72012+ g_tmp = (struct acl_object_label *)
72013+ acl_alloc(sizeof (struct acl_object_label));
72014+ if (g_tmp == NULL)
72015+ return -ENOMEM;
72016+
72017+ if (copy_acl_object_label(g_tmp, *guser))
72018+ return -EFAULT;
72019+
72020+ error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
72021+ if (error)
72022+ return error;
72023+
72024+ *guser = g_tmp;
72025+ guser = &(g_tmp->next);
72026+ }
72027+
72028+ return 0;
72029+}
72030+
72031+static int
72032+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
72033+ struct acl_role_label *role)
72034+{
72035+ struct acl_object_label *o_tmp;
72036+ int ret;
72037+
72038+ while (userp) {
72039+ if ((o_tmp = (struct acl_object_label *)
72040+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
72041+ return -ENOMEM;
72042+
72043+ if (copy_acl_object_label(o_tmp, userp))
72044+ return -EFAULT;
72045+
72046+ userp = o_tmp->prev;
72047+
72048+ ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
72049+ if (ret)
72050+ return ret;
72051+
72052+ insert_acl_obj_label(o_tmp, subj);
72053+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
72054+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
72055+ return -ENOMEM;
72056+
72057+ ret = copy_user_glob(o_tmp);
72058+ if (ret)
72059+ return ret;
72060+
72061+ if (o_tmp->nested) {
72062+ int already_copied;
72063+
72064+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
72065+ if (IS_ERR(o_tmp->nested))
72066+ return PTR_ERR(o_tmp->nested);
72067+
72068+ /* insert into nested subject list if we haven't copied this one yet
72069+ to prevent duplicate entries */
72070+ if (!already_copied) {
72071+ o_tmp->nested->next = role->hash->first;
72072+ role->hash->first = o_tmp->nested;
72073+ }
72074+ }
72075+ }
72076+
72077+ return 0;
72078+}
72079+
72080+static __u32
72081+count_user_subjs(struct acl_subject_label *userp)
72082+{
72083+ struct acl_subject_label s_tmp;
72084+ __u32 num = 0;
72085+
72086+ while (userp) {
72087+ if (copy_acl_subject_label(&s_tmp, userp))
72088+ break;
72089+
72090+ userp = s_tmp.prev;
72091+ }
72092+
72093+ return num;
72094+}
72095+
72096+static int
72097+copy_user_allowedips(struct acl_role_label *rolep)
72098+{
72099+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
72100+
72101+ ruserip = rolep->allowed_ips;
72102+
72103+ while (ruserip) {
72104+ rlast = rtmp;
72105+
72106+ if ((rtmp = (struct role_allowed_ip *)
72107+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
72108+ return -ENOMEM;
72109+
72110+ if (copy_role_allowed_ip(rtmp, ruserip))
72111+ return -EFAULT;
72112+
72113+ ruserip = rtmp->prev;
72114+
72115+ if (!rlast) {
72116+ rtmp->prev = NULL;
72117+ rolep->allowed_ips = rtmp;
72118+ } else {
72119+ rlast->next = rtmp;
72120+ rtmp->prev = rlast;
72121+ }
72122+
72123+ if (!ruserip)
72124+ rtmp->next = NULL;
72125+ }
72126+
72127+ return 0;
72128+}
72129+
72130+static int
72131+copy_user_transitions(struct acl_role_label *rolep)
72132+{
72133+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
72134+ int error;
72135+
72136+ rusertp = rolep->transitions;
72137+
72138+ while (rusertp) {
72139+ rlast = rtmp;
72140+
72141+ if ((rtmp = (struct role_transition *)
72142+ acl_alloc(sizeof (struct role_transition))) == NULL)
72143+ return -ENOMEM;
72144+
72145+ if (copy_role_transition(rtmp, rusertp))
72146+ return -EFAULT;
72147+
72148+ rusertp = rtmp->prev;
72149+
72150+ error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
72151+ if (error)
72152+ return error;
72153+
72154+ if (!rlast) {
72155+ rtmp->prev = NULL;
72156+ rolep->transitions = rtmp;
72157+ } else {
72158+ rlast->next = rtmp;
72159+ rtmp->prev = rlast;
72160+ }
72161+
72162+ if (!rusertp)
72163+ rtmp->next = NULL;
72164+ }
72165+
72166+ return 0;
72167+}
72168+
72169+static __u32 count_user_objs(const struct acl_object_label __user *userp)
72170+{
72171+ struct acl_object_label o_tmp;
72172+ __u32 num = 0;
72173+
72174+ while (userp) {
72175+ if (copy_acl_object_label(&o_tmp, userp))
72176+ break;
72177+
72178+ userp = o_tmp.prev;
72179+ num++;
72180+ }
72181+
72182+ return num;
72183+}
72184+
72185+static struct acl_subject_label *
72186+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
72187+{
72188+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
72189+ __u32 num_objs;
72190+ struct acl_ip_label **i_tmp, *i_utmp2;
72191+ struct gr_hash_struct ghash;
72192+ struct subject_map *subjmap;
72193+ unsigned int i_num;
72194+ int err;
72195+
72196+ if (already_copied != NULL)
72197+ *already_copied = 0;
72198+
72199+ s_tmp = lookup_subject_map(userp);
72200+
72201+ /* we've already copied this subject into the kernel, just return
72202+ the reference to it, and don't copy it over again
72203+ */
72204+ if (s_tmp) {
72205+ if (already_copied != NULL)
72206+ *already_copied = 1;
72207+ return(s_tmp);
72208+ }
72209+
72210+ if ((s_tmp = (struct acl_subject_label *)
72211+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
72212+ return ERR_PTR(-ENOMEM);
72213+
72214+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
72215+ if (subjmap == NULL)
72216+ return ERR_PTR(-ENOMEM);
72217+
72218+ subjmap->user = userp;
72219+ subjmap->kernel = s_tmp;
72220+ insert_subj_map_entry(subjmap);
72221+
72222+ if (copy_acl_subject_label(s_tmp, userp))
72223+ return ERR_PTR(-EFAULT);
72224+
72225+ err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
72226+ if (err)
72227+ return ERR_PTR(err);
72228+
72229+ if (!strcmp(s_tmp->filename, "/"))
72230+ role->root_label = s_tmp;
72231+
72232+ if (copy_gr_hash_struct(&ghash, s_tmp->hash))
72233+ return ERR_PTR(-EFAULT);
72234+
72235+ /* copy user and group transition tables */
72236+
72237+ if (s_tmp->user_trans_num) {
72238+ uid_t *uidlist;
72239+
72240+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
72241+ if (uidlist == NULL)
72242+ return ERR_PTR(-ENOMEM);
72243+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
72244+ return ERR_PTR(-EFAULT);
72245+
72246+ s_tmp->user_transitions = uidlist;
72247+ }
72248+
72249+ if (s_tmp->group_trans_num) {
72250+ gid_t *gidlist;
72251+
72252+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
72253+ if (gidlist == NULL)
72254+ return ERR_PTR(-ENOMEM);
72255+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
72256+ return ERR_PTR(-EFAULT);
72257+
72258+ s_tmp->group_transitions = gidlist;
72259+ }
72260+
72261+ /* set up object hash table */
72262+ num_objs = count_user_objs(ghash.first);
72263+
72264+ s_tmp->obj_hash_size = num_objs;
72265+ s_tmp->obj_hash =
72266+ (struct acl_object_label **)
72267+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
72268+
72269+ if (!s_tmp->obj_hash)
72270+ return ERR_PTR(-ENOMEM);
72271+
72272+ memset(s_tmp->obj_hash, 0,
72273+ s_tmp->obj_hash_size *
72274+ sizeof (struct acl_object_label *));
72275+
72276+ /* add in objects */
72277+ err = copy_user_objs(ghash.first, s_tmp, role);
72278+
72279+ if (err)
72280+ return ERR_PTR(err);
72281+
72282+ /* set pointer for parent subject */
72283+ if (s_tmp->parent_subject) {
72284+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
72285+
72286+ if (IS_ERR(s_tmp2))
72287+ return s_tmp2;
72288+
72289+ s_tmp->parent_subject = s_tmp2;
72290+ }
72291+
72292+ /* add in ip acls */
72293+
72294+ if (!s_tmp->ip_num) {
72295+ s_tmp->ips = NULL;
72296+ goto insert;
72297+ }
72298+
72299+ i_tmp =
72300+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
72301+ sizeof (struct acl_ip_label *));
72302+
72303+ if (!i_tmp)
72304+ return ERR_PTR(-ENOMEM);
72305+
72306+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
72307+ *(i_tmp + i_num) =
72308+ (struct acl_ip_label *)
72309+ acl_alloc(sizeof (struct acl_ip_label));
72310+ if (!*(i_tmp + i_num))
72311+ return ERR_PTR(-ENOMEM);
72312+
72313+ if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
72314+ return ERR_PTR(-EFAULT);
72315+
72316+ if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
72317+ return ERR_PTR(-EFAULT);
72318+
72319+ if ((*(i_tmp + i_num))->iface == NULL)
72320+ continue;
72321+
72322+ err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
72323+ if (err)
72324+ return ERR_PTR(err);
72325+ }
72326+
72327+ s_tmp->ips = i_tmp;
72328+
72329+insert:
72330+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
72331+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
72332+ return ERR_PTR(-ENOMEM);
72333+
72334+ return s_tmp;
72335+}
72336+
72337+static int
72338+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
72339+{
72340+ struct acl_subject_label s_pre;
72341+ struct acl_subject_label * ret;
72342+ int err;
72343+
72344+ while (userp) {
72345+ if (copy_acl_subject_label(&s_pre, userp))
72346+ return -EFAULT;
72347+
72348+ ret = do_copy_user_subj(userp, role, NULL);
72349+
72350+ err = PTR_ERR(ret);
72351+ if (IS_ERR(ret))
72352+ return err;
72353+
72354+ insert_acl_subj_label(ret, role);
72355+
72356+ userp = s_pre.prev;
72357+ }
72358+
72359+ return 0;
72360+}
72361+
72362+static int
72363+copy_user_acl(struct gr_arg *arg)
72364+{
72365+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
72366+ struct acl_subject_label *subj_list;
72367+ struct sprole_pw *sptmp;
72368+ struct gr_hash_struct *ghash;
72369+ uid_t *domainlist;
72370+ unsigned int r_num;
72371+ int err = 0;
72372+ __u16 i;
72373+ __u32 num_subjs;
72374+
72375+ /* we need a default and kernel role */
72376+ if (arg->role_db.num_roles < 2)
72377+ return -EINVAL;
72378+
72379+ /* copy special role authentication info from userspace */
72380+
72381+ polstate->num_sprole_pws = arg->num_sprole_pws;
72382+ polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
72383+
72384+ if (!polstate->acl_special_roles && polstate->num_sprole_pws)
72385+ return -ENOMEM;
72386+
72387+ for (i = 0; i < polstate->num_sprole_pws; i++) {
72388+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
72389+ if (!sptmp)
72390+ return -ENOMEM;
72391+ if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
72392+ return -EFAULT;
72393+
72394+ err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
72395+ if (err)
72396+ return err;
72397+
72398+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
72399+ printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
72400+#endif
72401+
72402+ polstate->acl_special_roles[i] = sptmp;
72403+ }
72404+
72405+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
72406+
72407+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
72408+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
72409+
72410+ if (!r_tmp)
72411+ return -ENOMEM;
72412+
72413+ if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
72414+ return -EFAULT;
72415+
72416+ if (copy_acl_role_label(r_tmp, r_utmp2))
72417+ return -EFAULT;
72418+
72419+ err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
72420+ if (err)
72421+ return err;
72422+
72423+ if (!strcmp(r_tmp->rolename, "default")
72424+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
72425+ polstate->default_role = r_tmp;
72426+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
72427+ polstate->kernel_role = r_tmp;
72428+ }
72429+
72430+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
72431+ return -ENOMEM;
72432+
72433+ if (copy_gr_hash_struct(ghash, r_tmp->hash))
72434+ return -EFAULT;
72435+
72436+ r_tmp->hash = ghash;
72437+
72438+ num_subjs = count_user_subjs(r_tmp->hash->first);
72439+
72440+ r_tmp->subj_hash_size = num_subjs;
72441+ r_tmp->subj_hash =
72442+ (struct acl_subject_label **)
72443+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
72444+
72445+ if (!r_tmp->subj_hash)
72446+ return -ENOMEM;
72447+
72448+ err = copy_user_allowedips(r_tmp);
72449+ if (err)
72450+ return err;
72451+
72452+ /* copy domain info */
72453+ if (r_tmp->domain_children != NULL) {
72454+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
72455+ if (domainlist == NULL)
72456+ return -ENOMEM;
72457+
72458+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
72459+ return -EFAULT;
72460+
72461+ r_tmp->domain_children = domainlist;
72462+ }
72463+
72464+ err = copy_user_transitions(r_tmp);
72465+ if (err)
72466+ return err;
72467+
72468+ memset(r_tmp->subj_hash, 0,
72469+ r_tmp->subj_hash_size *
72470+ sizeof (struct acl_subject_label *));
72471+
72472+ /* acquire the list of subjects, then NULL out
72473+ the list prior to parsing the subjects for this role,
72474+ as during this parsing the list is replaced with a list
72475+ of *nested* subjects for the role
72476+ */
72477+ subj_list = r_tmp->hash->first;
72478+
72479+ /* set nested subject list to null */
72480+ r_tmp->hash->first = NULL;
72481+
72482+ err = copy_user_subjs(subj_list, r_tmp);
72483+
72484+ if (err)
72485+ return err;
72486+
72487+ insert_acl_role_label(r_tmp);
72488+ }
72489+
72490+ if (polstate->default_role == NULL || polstate->kernel_role == NULL)
72491+ return -EINVAL;
72492+
72493+ return err;
72494+}
72495+
72496+static int gracl_reload_apply_policies(void *reload)
72497+{
72498+ struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
72499+ struct task_struct *task, *task2;
72500+ struct acl_role_label *role, *rtmp;
72501+ struct acl_subject_label *subj;
72502+ const struct cred *cred;
72503+ int role_applied;
72504+ int ret = 0;
72505+
72506+ memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
72507+ memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
72508+
72509+ /* first make sure we'll be able to apply the new policy cleanly */
72510+ do_each_thread(task2, task) {
72511+ if (task->exec_file == NULL)
72512+ continue;
72513+ role_applied = 0;
72514+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
72515+ /* preserve special roles */
72516+ FOR_EACH_ROLE_START(role)
72517+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
72518+ rtmp = task->role;
72519+ task->role = role;
72520+ role_applied = 1;
72521+ break;
72522+ }
72523+ FOR_EACH_ROLE_END(role)
72524+ }
72525+ if (!role_applied) {
72526+ cred = __task_cred(task);
72527+ rtmp = task->role;
72528+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72529+ }
72530+ /* this handles non-nested inherited subjects, nested subjects will still
72531+ be dropped currently */
72532+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
72533+ task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
72534+ /* change the role back so that we've made no modifications to the policy */
72535+ task->role = rtmp;
72536+
72537+ if (subj == NULL || task->tmpacl == NULL) {
72538+ ret = -EINVAL;
72539+ goto out;
72540+ }
72541+ } while_each_thread(task2, task);
72542+
72543+ /* now actually apply the policy */
72544+
72545+ do_each_thread(task2, task) {
72546+ if (task->exec_file) {
72547+ role_applied = 0;
72548+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
72549+ /* preserve special roles */
72550+ FOR_EACH_ROLE_START(role)
72551+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
72552+ task->role = role;
72553+ role_applied = 1;
72554+ break;
72555+ }
72556+ FOR_EACH_ROLE_END(role)
72557+ }
72558+ if (!role_applied) {
72559+ cred = __task_cred(task);
72560+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72561+ }
72562+ /* this handles non-nested inherited subjects, nested subjects will still
72563+ be dropped currently */
72564+ if (!reload_state->oldmode && task->inherited)
72565+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
72566+ else {
72567+ /* looked up and tagged to the task previously */
72568+ subj = task->tmpacl;
72569+ }
72570+ /* subj will be non-null */
72571+ __gr_apply_subject_to_task(polstate, task, subj);
72572+ if (reload_state->oldmode) {
72573+ task->acl_role_id = 0;
72574+ task->acl_sp_role = 0;
72575+ task->inherited = 0;
72576+ }
72577+ } else {
72578+ // it's a kernel process
72579+ task->role = polstate->kernel_role;
72580+ task->acl = polstate->kernel_role->root_label;
72581+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
72582+ task->acl->mode &= ~GR_PROCFIND;
72583+#endif
72584+ }
72585+ } while_each_thread(task2, task);
72586+
72587+ memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
72588+ memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
72589+
72590+out:
72591+
72592+ return ret;
72593+}
72594+
72595+static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
72596+{
72597+ struct gr_reload_state new_reload_state = { };
72598+ int err;
72599+
72600+ new_reload_state.oldpolicy_ptr = polstate;
72601+ new_reload_state.oldalloc_ptr = current_alloc_state;
72602+ new_reload_state.oldmode = oldmode;
72603+
72604+ current_alloc_state = &new_reload_state.newalloc;
72605+ polstate = &new_reload_state.newpolicy;
72606+
72607+ /* everything relevant is now saved off, copy in the new policy */
72608+ if (init_variables(args, true)) {
72609+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
72610+ err = -ENOMEM;
72611+ goto error;
72612+ }
72613+
72614+ err = copy_user_acl(args);
72615+ free_init_variables();
72616+ if (err)
72617+ goto error;
72618+ /* the new policy is copied in, with the old policy available via saved_state
72619+ first go through applying roles, making sure to preserve special roles
72620+ then apply new subjects, making sure to preserve inherited and nested subjects,
72621+ though currently only inherited subjects will be preserved
72622+ */
72623+ err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
72624+ if (err)
72625+ goto error;
72626+
72627+ /* we've now applied the new policy, so restore the old policy state to free it */
72628+ polstate = &new_reload_state.oldpolicy;
72629+ current_alloc_state = &new_reload_state.oldalloc;
72630+ free_variables(true);
72631+
72632+ /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
72633+ to running_polstate/current_alloc_state inside stop_machine
72634+ */
72635+ err = 0;
72636+ goto out;
72637+error:
72638+ /* on error of loading the new policy, we'll just keep the previous
72639+ policy set around
72640+ */
72641+ free_variables(true);
72642+
72643+ /* doesn't affect runtime, but maintains consistent state */
72644+out:
72645+ polstate = new_reload_state.oldpolicy_ptr;
72646+ current_alloc_state = new_reload_state.oldalloc_ptr;
72647+
72648+ return err;
72649+}
72650+
72651+static int
72652+gracl_init(struct gr_arg *args)
72653+{
72654+ int error = 0;
72655+
72656+ memcpy(&gr_system_salt, args->salt, sizeof(gr_system_salt));
72657+ memcpy(&gr_system_sum, args->sum, sizeof(gr_system_sum));
72658+
72659+ if (init_variables(args, false)) {
72660+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
72661+ error = -ENOMEM;
72662+ goto out;
72663+ }
72664+
72665+ error = copy_user_acl(args);
72666+ free_init_variables();
72667+ if (error)
72668+ goto out;
72669+
72670+ error = gr_set_acls(0);
72671+ if (error)
72672+ goto out;
72673+
72674+ gr_enable_rbac_system();
72675+
72676+ return 0;
72677+
72678+out:
72679+ free_variables(false);
72680+ return error;
72681+}
72682+
72683+static int
72684+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
72685+ unsigned char **sum)
72686+{
72687+ struct acl_role_label *r;
72688+ struct role_allowed_ip *ipp;
72689+ struct role_transition *trans;
72690+ unsigned int i;
72691+ int found = 0;
72692+ u32 curr_ip = current->signal->curr_ip;
72693+
72694+ current->signal->saved_ip = curr_ip;
72695+
72696+ /* check transition table */
72697+
72698+ for (trans = current->role->transitions; trans; trans = trans->next) {
72699+ if (!strcmp(rolename, trans->rolename)) {
72700+ found = 1;
72701+ break;
72702+ }
72703+ }
72704+
72705+ if (!found)
72706+ return 0;
72707+
72708+ /* handle special roles that do not require authentication
72709+ and check ip */
72710+
72711+ FOR_EACH_ROLE_START(r)
72712+ if (!strcmp(rolename, r->rolename) &&
72713+ (r->roletype & GR_ROLE_SPECIAL)) {
72714+ found = 0;
72715+ if (r->allowed_ips != NULL) {
72716+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
72717+ if ((ntohl(curr_ip) & ipp->netmask) ==
72718+ (ntohl(ipp->addr) & ipp->netmask))
72719+ found = 1;
72720+ }
72721+ } else
72722+ found = 2;
72723+ if (!found)
72724+ return 0;
72725+
72726+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
72727+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
72728+ *salt = NULL;
72729+ *sum = NULL;
72730+ return 1;
72731+ }
72732+ }
72733+ FOR_EACH_ROLE_END(r)
72734+
72735+ for (i = 0; i < polstate->num_sprole_pws; i++) {
72736+ if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
72737+ *salt = polstate->acl_special_roles[i]->salt;
72738+ *sum = polstate->acl_special_roles[i]->sum;
72739+ return 1;
72740+ }
72741+ }
72742+
72743+ return 0;
72744+}
72745+
72746+int gr_check_secure_terminal(struct task_struct *task)
72747+{
72748+ struct task_struct *p, *p2, *p3;
72749+ struct files_struct *files;
72750+ struct fdtable *fdt;
72751+ struct file *our_file = NULL, *file;
72752+ int i;
72753+
72754+ if (task->signal->tty == NULL)
72755+ return 1;
72756+
72757+ files = get_files_struct(task);
72758+ if (files != NULL) {
72759+ rcu_read_lock();
72760+ fdt = files_fdtable(files);
72761+ for (i=0; i < fdt->max_fds; i++) {
72762+ file = fcheck_files(files, i);
72763+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
72764+ get_file(file);
72765+ our_file = file;
72766+ }
72767+ }
72768+ rcu_read_unlock();
72769+ put_files_struct(files);
72770+ }
72771+
72772+ if (our_file == NULL)
72773+ return 1;
72774+
72775+ read_lock(&tasklist_lock);
72776+ do_each_thread(p2, p) {
72777+ files = get_files_struct(p);
72778+ if (files == NULL ||
72779+ (p->signal && p->signal->tty == task->signal->tty)) {
72780+ if (files != NULL)
72781+ put_files_struct(files);
72782+ continue;
72783+ }
72784+ rcu_read_lock();
72785+ fdt = files_fdtable(files);
72786+ for (i=0; i < fdt->max_fds; i++) {
72787+ file = fcheck_files(files, i);
72788+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
72789+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
72790+ p3 = task;
72791+ while (task_pid_nr(p3) > 0) {
72792+ if (p3 == p)
72793+ break;
72794+ p3 = p3->real_parent;
72795+ }
72796+ if (p3 == p)
72797+ break;
72798+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
72799+ gr_handle_alertkill(p);
72800+ rcu_read_unlock();
72801+ put_files_struct(files);
72802+ read_unlock(&tasklist_lock);
72803+ fput(our_file);
72804+ return 0;
72805+ }
72806+ }
72807+ rcu_read_unlock();
72808+ put_files_struct(files);
72809+ } while_each_thread(p2, p);
72810+ read_unlock(&tasklist_lock);
72811+
72812+ fput(our_file);
72813+ return 1;
72814+}
72815+
72816+ssize_t
72817+write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
72818+{
72819+ struct gr_arg_wrapper uwrap;
72820+ unsigned char *sprole_salt = NULL;
72821+ unsigned char *sprole_sum = NULL;
72822+ int error = 0;
72823+ int error2 = 0;
72824+ size_t req_count = 0;
72825+ unsigned char oldmode = 0;
72826+
72827+ mutex_lock(&gr_dev_mutex);
72828+
72829+ if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
72830+ error = -EPERM;
72831+ goto out;
72832+ }
72833+
72834+#ifdef CONFIG_COMPAT
72835+ pax_open_kernel();
72836+ if (is_compat_task()) {
72837+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
72838+ copy_gr_arg = &copy_gr_arg_compat;
72839+ copy_acl_object_label = &copy_acl_object_label_compat;
72840+ copy_acl_subject_label = &copy_acl_subject_label_compat;
72841+ copy_acl_role_label = &copy_acl_role_label_compat;
72842+ copy_acl_ip_label = &copy_acl_ip_label_compat;
72843+ copy_role_allowed_ip = &copy_role_allowed_ip_compat;
72844+ copy_role_transition = &copy_role_transition_compat;
72845+ copy_sprole_pw = &copy_sprole_pw_compat;
72846+ copy_gr_hash_struct = &copy_gr_hash_struct_compat;
72847+ copy_pointer_from_array = &copy_pointer_from_array_compat;
72848+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
72849+ } else {
72850+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
72851+ copy_gr_arg = &copy_gr_arg_normal;
72852+ copy_acl_object_label = &copy_acl_object_label_normal;
72853+ copy_acl_subject_label = &copy_acl_subject_label_normal;
72854+ copy_acl_role_label = &copy_acl_role_label_normal;
72855+ copy_acl_ip_label = &copy_acl_ip_label_normal;
72856+ copy_role_allowed_ip = &copy_role_allowed_ip_normal;
72857+ copy_role_transition = &copy_role_transition_normal;
72858+ copy_sprole_pw = &copy_sprole_pw_normal;
72859+ copy_gr_hash_struct = &copy_gr_hash_struct_normal;
72860+ copy_pointer_from_array = &copy_pointer_from_array_normal;
72861+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
72862+ }
72863+ pax_close_kernel();
72864+#endif
72865+
72866+ req_count = get_gr_arg_wrapper_size();
72867+
72868+ if (count != req_count) {
72869+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
72870+ error = -EINVAL;
72871+ goto out;
72872+ }
72873+
72874+
72875+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
72876+ gr_auth_expires = 0;
72877+ gr_auth_attempts = 0;
72878+ }
72879+
72880+ error = copy_gr_arg_wrapper(buf, &uwrap);
72881+ if (error)
72882+ goto out;
72883+
72884+ error = copy_gr_arg(uwrap.arg, &gr_usermode);
72885+ if (error)
72886+ goto out;
72887+
72888+ if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_SPROLEPAM &&
72889+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
72890+ time_after(gr_auth_expires, get_seconds())) {
72891+ error = -EBUSY;
72892+ goto out;
72893+ }
72894+
72895+ /* if non-root trying to do anything other than use a special role,
72896+ do not attempt authentication, do not count towards authentication
72897+ locking
72898+ */
72899+
72900+ if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_STATUS &&
72901+ gr_usermode.mode != GR_UNSPROLE && gr_usermode.mode != GR_SPROLEPAM &&
72902+ gr_is_global_nonroot(current_uid())) {
72903+ error = -EPERM;
72904+ goto out;
72905+ }
72906+
72907+ /* ensure pw and special role name are null terminated */
72908+
72909+ gr_usermode.pw[GR_PW_LEN - 1] = '\0';
72910+ gr_usermode.sp_role[GR_SPROLE_LEN - 1] = '\0';
72911+
72912+ /* Okay.
72913+ * We have our enough of the argument structure..(we have yet
72914+ * to copy_from_user the tables themselves) . Copy the tables
72915+ * only if we need them, i.e. for loading operations. */
72916+
72917+ switch (gr_usermode.mode) {
72918+ case GR_STATUS:
72919+ if (gr_acl_is_enabled()) {
72920+ error = 1;
72921+ if (!gr_check_secure_terminal(current))
72922+ error = 3;
72923+ } else
72924+ error = 2;
72925+ goto out;
72926+ case GR_SHUTDOWN:
72927+ if (gr_acl_is_enabled() && !(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72928+ stop_machine(gr_rbac_disable, NULL, NULL);
72929+ free_variables(false);
72930+ memset(&gr_usermode, 0, sizeof(gr_usermode));
72931+ memset(&gr_system_salt, 0, sizeof(gr_system_salt));
72932+ memset(&gr_system_sum, 0, sizeof(gr_system_sum));
72933+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
72934+ } else if (gr_acl_is_enabled()) {
72935+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
72936+ error = -EPERM;
72937+ } else {
72938+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
72939+ error = -EAGAIN;
72940+ }
72941+ break;
72942+ case GR_ENABLE:
72943+ if (!gr_acl_is_enabled() && !(error2 = gracl_init(&gr_usermode)))
72944+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
72945+ else {
72946+ if (gr_acl_is_enabled())
72947+ error = -EAGAIN;
72948+ else
72949+ error = error2;
72950+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
72951+ }
72952+ break;
72953+ case GR_OLDRELOAD:
72954+ oldmode = 1;
72955+ case GR_RELOAD:
72956+ if (!gr_acl_is_enabled()) {
72957+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
72958+ error = -EAGAIN;
72959+ } else if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72960+ error2 = gracl_reload(&gr_usermode, oldmode);
72961+ if (!error2)
72962+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
72963+ else {
72964+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
72965+ error = error2;
72966+ }
72967+ } else {
72968+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
72969+ error = -EPERM;
72970+ }
72971+ break;
72972+ case GR_SEGVMOD:
72973+ if (unlikely(!gr_acl_is_enabled())) {
72974+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
72975+ error = -EAGAIN;
72976+ break;
72977+ }
72978+
72979+ if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72980+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
72981+ if (gr_usermode.segv_device && gr_usermode.segv_inode) {
72982+ struct acl_subject_label *segvacl;
72983+ segvacl =
72984+ lookup_acl_subj_label(gr_usermode.segv_inode,
72985+ gr_usermode.segv_device,
72986+ current->role);
72987+ if (segvacl) {
72988+ segvacl->crashes = 0;
72989+ segvacl->expires = 0;
72990+ }
72991+ } else if (gr_find_uid(gr_usermode.segv_uid) >= 0) {
72992+ gr_remove_uid(gr_usermode.segv_uid);
72993+ }
72994+ } else {
72995+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
72996+ error = -EPERM;
72997+ }
72998+ break;
72999+ case GR_SPROLE:
73000+ case GR_SPROLEPAM:
73001+ if (unlikely(!gr_acl_is_enabled())) {
73002+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
73003+ error = -EAGAIN;
73004+ break;
73005+ }
73006+
73007+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
73008+ current->role->expires = 0;
73009+ current->role->auth_attempts = 0;
73010+ }
73011+
73012+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
73013+ time_after(current->role->expires, get_seconds())) {
73014+ error = -EBUSY;
73015+ goto out;
73016+ }
73017+
73018+ if (lookup_special_role_auth
73019+ (gr_usermode.mode, gr_usermode.sp_role, &sprole_salt, &sprole_sum)
73020+ && ((!sprole_salt && !sprole_sum)
73021+ || !(chkpw(&gr_usermode, sprole_salt, sprole_sum)))) {
73022+ char *p = "";
73023+ assign_special_role(gr_usermode.sp_role);
73024+ read_lock(&tasklist_lock);
73025+ if (current->real_parent)
73026+ p = current->real_parent->role->rolename;
73027+ read_unlock(&tasklist_lock);
73028+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
73029+ p, acl_sp_role_value);
73030+ } else {
73031+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode.sp_role);
73032+ error = -EPERM;
73033+ if(!(current->role->auth_attempts++))
73034+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
73035+
73036+ goto out;
73037+ }
73038+ break;
73039+ case GR_UNSPROLE:
73040+ if (unlikely(!gr_acl_is_enabled())) {
73041+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
73042+ error = -EAGAIN;
73043+ break;
73044+ }
73045+
73046+ if (current->role->roletype & GR_ROLE_SPECIAL) {
73047+ char *p = "";
73048+ int i = 0;
73049+
73050+ read_lock(&tasklist_lock);
73051+ if (current->real_parent) {
73052+ p = current->real_parent->role->rolename;
73053+ i = current->real_parent->acl_role_id;
73054+ }
73055+ read_unlock(&tasklist_lock);
73056+
73057+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
73058+ gr_set_acls(1);
73059+ } else {
73060+ error = -EPERM;
73061+ goto out;
73062+ }
73063+ break;
73064+ default:
73065+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode.mode);
73066+ error = -EINVAL;
73067+ break;
73068+ }
73069+
73070+ if (error != -EPERM)
73071+ goto out;
73072+
73073+ if(!(gr_auth_attempts++))
73074+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
73075+
73076+ out:
73077+ mutex_unlock(&gr_dev_mutex);
73078+
73079+ if (!error)
73080+ error = req_count;
73081+
73082+ return error;
73083+}
73084+
73085+int
73086+gr_set_acls(const int type)
73087+{
73088+ struct task_struct *task, *task2;
73089+ struct acl_role_label *role = current->role;
73090+ struct acl_subject_label *subj;
73091+ __u16 acl_role_id = current->acl_role_id;
73092+ const struct cred *cred;
73093+ int ret;
73094+
73095+ rcu_read_lock();
73096+ read_lock(&tasklist_lock);
73097+ read_lock(&grsec_exec_file_lock);
73098+ do_each_thread(task2, task) {
73099+ /* check to see if we're called from the exit handler,
73100+ if so, only replace ACLs that have inherited the admin
73101+ ACL */
73102+
73103+ if (type && (task->role != role ||
73104+ task->acl_role_id != acl_role_id))
73105+ continue;
73106+
73107+ task->acl_role_id = 0;
73108+ task->acl_sp_role = 0;
73109+ task->inherited = 0;
73110+
73111+ if (task->exec_file) {
73112+ cred = __task_cred(task);
73113+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
73114+ subj = __gr_get_subject_for_task(polstate, task, NULL);
73115+ if (subj == NULL) {
73116+ ret = -EINVAL;
73117+ read_unlock(&grsec_exec_file_lock);
73118+ read_unlock(&tasklist_lock);
73119+ rcu_read_unlock();
73120+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
73121+ return ret;
73122+ }
73123+ __gr_apply_subject_to_task(polstate, task, subj);
73124+ } else {
73125+ // it's a kernel process
73126+ task->role = polstate->kernel_role;
73127+ task->acl = polstate->kernel_role->root_label;
73128+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
73129+ task->acl->mode &= ~GR_PROCFIND;
73130+#endif
73131+ }
73132+ } while_each_thread(task2, task);
73133+ read_unlock(&grsec_exec_file_lock);
73134+ read_unlock(&tasklist_lock);
73135+ rcu_read_unlock();
73136+
73137+ return 0;
73138+}
73139diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
73140new file mode 100644
73141index 0000000..39645c9
73142--- /dev/null
73143+++ b/grsecurity/gracl_res.c
73144@@ -0,0 +1,68 @@
73145+#include <linux/kernel.h>
73146+#include <linux/sched.h>
73147+#include <linux/gracl.h>
73148+#include <linux/grinternal.h>
73149+
73150+static const char *restab_log[] = {
73151+ [RLIMIT_CPU] = "RLIMIT_CPU",
73152+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
73153+ [RLIMIT_DATA] = "RLIMIT_DATA",
73154+ [RLIMIT_STACK] = "RLIMIT_STACK",
73155+ [RLIMIT_CORE] = "RLIMIT_CORE",
73156+ [RLIMIT_RSS] = "RLIMIT_RSS",
73157+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
73158+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
73159+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
73160+ [RLIMIT_AS] = "RLIMIT_AS",
73161+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
73162+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
73163+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
73164+ [RLIMIT_NICE] = "RLIMIT_NICE",
73165+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
73166+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
73167+ [GR_CRASH_RES] = "RLIMIT_CRASH"
73168+};
73169+
73170+void
73171+gr_log_resource(const struct task_struct *task,
73172+ const int res, const unsigned long wanted, const int gt)
73173+{
73174+ const struct cred *cred;
73175+ unsigned long rlim;
73176+
73177+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
73178+ return;
73179+
73180+ // not yet supported resource
73181+ if (unlikely(!restab_log[res]))
73182+ return;
73183+
73184+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
73185+ rlim = task_rlimit_max(task, res);
73186+ else
73187+ rlim = task_rlimit(task, res);
73188+
73189+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
73190+ return;
73191+
73192+ rcu_read_lock();
73193+ cred = __task_cred(task);
73194+
73195+ if (res == RLIMIT_NPROC &&
73196+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
73197+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
73198+ goto out_rcu_unlock;
73199+ else if (res == RLIMIT_MEMLOCK &&
73200+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
73201+ goto out_rcu_unlock;
73202+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
73203+ goto out_rcu_unlock;
73204+ rcu_read_unlock();
73205+
73206+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
73207+
73208+ return;
73209+out_rcu_unlock:
73210+ rcu_read_unlock();
73211+ return;
73212+}
73213diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
73214new file mode 100644
73215index 0000000..2040e61
73216--- /dev/null
73217+++ b/grsecurity/gracl_segv.c
73218@@ -0,0 +1,313 @@
73219+#include <linux/kernel.h>
73220+#include <linux/mm.h>
73221+#include <asm/uaccess.h>
73222+#include <asm/errno.h>
73223+#include <asm/mman.h>
73224+#include <net/sock.h>
73225+#include <linux/file.h>
73226+#include <linux/fs.h>
73227+#include <linux/net.h>
73228+#include <linux/in.h>
73229+#include <linux/slab.h>
73230+#include <linux/types.h>
73231+#include <linux/sched.h>
73232+#include <linux/timer.h>
73233+#include <linux/gracl.h>
73234+#include <linux/grsecurity.h>
73235+#include <linux/grinternal.h>
73236+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
73237+#include <linux/magic.h>
73238+#include <linux/pagemap.h>
73239+#include "../fs/btrfs/async-thread.h"
73240+#include "../fs/btrfs/ctree.h"
73241+#include "../fs/btrfs/btrfs_inode.h"
73242+#endif
73243+
73244+static struct crash_uid *uid_set;
73245+static unsigned short uid_used;
73246+static DEFINE_SPINLOCK(gr_uid_lock);
73247+extern rwlock_t gr_inode_lock;
73248+extern struct acl_subject_label *
73249+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
73250+ struct acl_role_label *role);
73251+
73252+static inline dev_t __get_dev(const struct dentry *dentry)
73253+{
73254+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
73255+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
73256+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
73257+ else
73258+#endif
73259+ return dentry->d_sb->s_dev;
73260+}
73261+
73262+int
73263+gr_init_uidset(void)
73264+{
73265+ uid_set =
73266+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
73267+ uid_used = 0;
73268+
73269+ return uid_set ? 1 : 0;
73270+}
73271+
73272+void
73273+gr_free_uidset(void)
73274+{
73275+ if (uid_set) {
73276+ struct crash_uid *tmpset;
73277+ spin_lock(&gr_uid_lock);
73278+ tmpset = uid_set;
73279+ uid_set = NULL;
73280+ uid_used = 0;
73281+ spin_unlock(&gr_uid_lock);
73282+ if (tmpset)
73283+ kfree(tmpset);
73284+ }
73285+
73286+ return;
73287+}
73288+
73289+int
73290+gr_find_uid(const uid_t uid)
73291+{
73292+ struct crash_uid *tmp = uid_set;
73293+ uid_t buid;
73294+ int low = 0, high = uid_used - 1, mid;
73295+
73296+ while (high >= low) {
73297+ mid = (low + high) >> 1;
73298+ buid = tmp[mid].uid;
73299+ if (buid == uid)
73300+ return mid;
73301+ if (buid > uid)
73302+ high = mid - 1;
73303+ if (buid < uid)
73304+ low = mid + 1;
73305+ }
73306+
73307+ return -1;
73308+}
73309+
73310+static __inline__ void
73311+gr_insertsort(void)
73312+{
73313+ unsigned short i, j;
73314+ struct crash_uid index;
73315+
73316+ for (i = 1; i < uid_used; i++) {
73317+ index = uid_set[i];
73318+ j = i;
73319+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
73320+ uid_set[j] = uid_set[j - 1];
73321+ j--;
73322+ }
73323+ uid_set[j] = index;
73324+ }
73325+
73326+ return;
73327+}
73328+
73329+static __inline__ void
73330+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
73331+{
73332+ int loc;
73333+ uid_t uid = GR_GLOBAL_UID(kuid);
73334+
73335+ if (uid_used == GR_UIDTABLE_MAX)
73336+ return;
73337+
73338+ loc = gr_find_uid(uid);
73339+
73340+ if (loc >= 0) {
73341+ uid_set[loc].expires = expires;
73342+ return;
73343+ }
73344+
73345+ uid_set[uid_used].uid = uid;
73346+ uid_set[uid_used].expires = expires;
73347+ uid_used++;
73348+
73349+ gr_insertsort();
73350+
73351+ return;
73352+}
73353+
73354+void
73355+gr_remove_uid(const unsigned short loc)
73356+{
73357+ unsigned short i;
73358+
73359+ for (i = loc + 1; i < uid_used; i++)
73360+ uid_set[i - 1] = uid_set[i];
73361+
73362+ uid_used--;
73363+
73364+ return;
73365+}
73366+
73367+int
73368+gr_check_crash_uid(const kuid_t kuid)
73369+{
73370+ int loc;
73371+ int ret = 0;
73372+ uid_t uid;
73373+
73374+ if (unlikely(!gr_acl_is_enabled()))
73375+ return 0;
73376+
73377+ uid = GR_GLOBAL_UID(kuid);
73378+
73379+ spin_lock(&gr_uid_lock);
73380+ loc = gr_find_uid(uid);
73381+
73382+ if (loc < 0)
73383+ goto out_unlock;
73384+
73385+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
73386+ gr_remove_uid(loc);
73387+ else
73388+ ret = 1;
73389+
73390+out_unlock:
73391+ spin_unlock(&gr_uid_lock);
73392+ return ret;
73393+}
73394+
73395+static __inline__ int
73396+proc_is_setxid(const struct cred *cred)
73397+{
73398+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
73399+ !uid_eq(cred->uid, cred->fsuid))
73400+ return 1;
73401+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
73402+ !gid_eq(cred->gid, cred->fsgid))
73403+ return 1;
73404+
73405+ return 0;
73406+}
73407+
73408+extern int gr_fake_force_sig(int sig, struct task_struct *t);
73409+
73410+void
73411+gr_handle_crash(struct task_struct *task, const int sig)
73412+{
73413+ struct acl_subject_label *curr;
73414+ struct task_struct *tsk, *tsk2;
73415+ const struct cred *cred;
73416+ const struct cred *cred2;
73417+
73418+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
73419+ return;
73420+
73421+ if (unlikely(!gr_acl_is_enabled()))
73422+ return;
73423+
73424+ curr = task->acl;
73425+
73426+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
73427+ return;
73428+
73429+ if (time_before_eq(curr->expires, get_seconds())) {
73430+ curr->expires = 0;
73431+ curr->crashes = 0;
73432+ }
73433+
73434+ curr->crashes++;
73435+
73436+ if (!curr->expires)
73437+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
73438+
73439+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
73440+ time_after(curr->expires, get_seconds())) {
73441+ rcu_read_lock();
73442+ cred = __task_cred(task);
73443+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
73444+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
73445+ spin_lock(&gr_uid_lock);
73446+ gr_insert_uid(cred->uid, curr->expires);
73447+ spin_unlock(&gr_uid_lock);
73448+ curr->expires = 0;
73449+ curr->crashes = 0;
73450+ read_lock(&tasklist_lock);
73451+ do_each_thread(tsk2, tsk) {
73452+ cred2 = __task_cred(tsk);
73453+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
73454+ gr_fake_force_sig(SIGKILL, tsk);
73455+ } while_each_thread(tsk2, tsk);
73456+ read_unlock(&tasklist_lock);
73457+ } else {
73458+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
73459+ read_lock(&tasklist_lock);
73460+ read_lock(&grsec_exec_file_lock);
73461+ do_each_thread(tsk2, tsk) {
73462+ if (likely(tsk != task)) {
73463+ // if this thread has the same subject as the one that triggered
73464+ // RES_CRASH and it's the same binary, kill it
73465+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
73466+ gr_fake_force_sig(SIGKILL, tsk);
73467+ }
73468+ } while_each_thread(tsk2, tsk);
73469+ read_unlock(&grsec_exec_file_lock);
73470+ read_unlock(&tasklist_lock);
73471+ }
73472+ rcu_read_unlock();
73473+ }
73474+
73475+ return;
73476+}
73477+
73478+int
73479+gr_check_crash_exec(const struct file *filp)
73480+{
73481+ struct acl_subject_label *curr;
73482+
73483+ if (unlikely(!gr_acl_is_enabled()))
73484+ return 0;
73485+
73486+ read_lock(&gr_inode_lock);
73487+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
73488+ __get_dev(filp->f_path.dentry),
73489+ current->role);
73490+ read_unlock(&gr_inode_lock);
73491+
73492+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
73493+ (!curr->crashes && !curr->expires))
73494+ return 0;
73495+
73496+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
73497+ time_after(curr->expires, get_seconds()))
73498+ return 1;
73499+ else if (time_before_eq(curr->expires, get_seconds())) {
73500+ curr->crashes = 0;
73501+ curr->expires = 0;
73502+ }
73503+
73504+ return 0;
73505+}
73506+
73507+void
73508+gr_handle_alertkill(struct task_struct *task)
73509+{
73510+ struct acl_subject_label *curracl;
73511+ __u32 curr_ip;
73512+ struct task_struct *p, *p2;
73513+
73514+ if (unlikely(!gr_acl_is_enabled()))
73515+ return;
73516+
73517+ curracl = task->acl;
73518+ curr_ip = task->signal->curr_ip;
73519+
73520+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
73521+ read_lock(&tasklist_lock);
73522+ do_each_thread(p2, p) {
73523+ if (p->signal->curr_ip == curr_ip)
73524+ gr_fake_force_sig(SIGKILL, p);
73525+ } while_each_thread(p2, p);
73526+ read_unlock(&tasklist_lock);
73527+ } else if (curracl->mode & GR_KILLPROC)
73528+ gr_fake_force_sig(SIGKILL, task);
73529+
73530+ return;
73531+}
73532diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
73533new file mode 100644
73534index 0000000..98011b0
73535--- /dev/null
73536+++ b/grsecurity/gracl_shm.c
73537@@ -0,0 +1,40 @@
73538+#include <linux/kernel.h>
73539+#include <linux/mm.h>
73540+#include <linux/sched.h>
73541+#include <linux/file.h>
73542+#include <linux/ipc.h>
73543+#include <linux/gracl.h>
73544+#include <linux/grsecurity.h>
73545+#include <linux/grinternal.h>
73546+
73547+int
73548+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73549+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
73550+{
73551+ struct task_struct *task;
73552+
73553+ if (!gr_acl_is_enabled())
73554+ return 1;
73555+
73556+ rcu_read_lock();
73557+ read_lock(&tasklist_lock);
73558+
73559+ task = find_task_by_vpid(shm_cprid);
73560+
73561+ if (unlikely(!task))
73562+ task = find_task_by_vpid(shm_lapid);
73563+
73564+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
73565+ (task_pid_nr(task) == shm_lapid)) &&
73566+ (task->acl->mode & GR_PROTSHM) &&
73567+ (task->acl != current->acl))) {
73568+ read_unlock(&tasklist_lock);
73569+ rcu_read_unlock();
73570+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
73571+ return 0;
73572+ }
73573+ read_unlock(&tasklist_lock);
73574+ rcu_read_unlock();
73575+
73576+ return 1;
73577+}
73578diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
73579new file mode 100644
73580index 0000000..bc0be01
73581--- /dev/null
73582+++ b/grsecurity/grsec_chdir.c
73583@@ -0,0 +1,19 @@
73584+#include <linux/kernel.h>
73585+#include <linux/sched.h>
73586+#include <linux/fs.h>
73587+#include <linux/file.h>
73588+#include <linux/grsecurity.h>
73589+#include <linux/grinternal.h>
73590+
73591+void
73592+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
73593+{
73594+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
73595+ if ((grsec_enable_chdir && grsec_enable_group &&
73596+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
73597+ !grsec_enable_group)) {
73598+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
73599+ }
73600+#endif
73601+ return;
73602+}
73603diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
73604new file mode 100644
73605index 0000000..651d6c2
73606--- /dev/null
73607+++ b/grsecurity/grsec_chroot.c
73608@@ -0,0 +1,370 @@
73609+#include <linux/kernel.h>
73610+#include <linux/module.h>
73611+#include <linux/sched.h>
73612+#include <linux/file.h>
73613+#include <linux/fs.h>
73614+#include <linux/mount.h>
73615+#include <linux/types.h>
73616+#include "../fs/mount.h"
73617+#include <linux/grsecurity.h>
73618+#include <linux/grinternal.h>
73619+
73620+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73621+int gr_init_ran;
73622+#endif
73623+
73624+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
73625+{
73626+#ifdef CONFIG_GRKERNSEC
73627+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
73628+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
73629+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73630+ && gr_init_ran
73631+#endif
73632+ )
73633+ task->gr_is_chrooted = 1;
73634+ else {
73635+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73636+ if (task_pid_nr(task) == 1 && !gr_init_ran)
73637+ gr_init_ran = 1;
73638+#endif
73639+ task->gr_is_chrooted = 0;
73640+ }
73641+
73642+ task->gr_chroot_dentry = path->dentry;
73643+#endif
73644+ return;
73645+}
73646+
73647+void gr_clear_chroot_entries(struct task_struct *task)
73648+{
73649+#ifdef CONFIG_GRKERNSEC
73650+ task->gr_is_chrooted = 0;
73651+ task->gr_chroot_dentry = NULL;
73652+#endif
73653+ return;
73654+}
73655+
73656+int
73657+gr_handle_chroot_unix(const pid_t pid)
73658+{
73659+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
73660+ struct task_struct *p;
73661+
73662+ if (unlikely(!grsec_enable_chroot_unix))
73663+ return 1;
73664+
73665+ if (likely(!proc_is_chrooted(current)))
73666+ return 1;
73667+
73668+ rcu_read_lock();
73669+ read_lock(&tasklist_lock);
73670+ p = find_task_by_vpid_unrestricted(pid);
73671+ if (unlikely(p && !have_same_root(current, p))) {
73672+ read_unlock(&tasklist_lock);
73673+ rcu_read_unlock();
73674+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
73675+ return 0;
73676+ }
73677+ read_unlock(&tasklist_lock);
73678+ rcu_read_unlock();
73679+#endif
73680+ return 1;
73681+}
73682+
73683+int
73684+gr_handle_chroot_nice(void)
73685+{
73686+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
73687+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
73688+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
73689+ return -EPERM;
73690+ }
73691+#endif
73692+ return 0;
73693+}
73694+
73695+int
73696+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
73697+{
73698+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
73699+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
73700+ && proc_is_chrooted(current)) {
73701+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
73702+ return -EACCES;
73703+ }
73704+#endif
73705+ return 0;
73706+}
73707+
73708+int
73709+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
73710+{
73711+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73712+ struct task_struct *p;
73713+ int ret = 0;
73714+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
73715+ return ret;
73716+
73717+ read_lock(&tasklist_lock);
73718+ do_each_pid_task(pid, type, p) {
73719+ if (!have_same_root(current, p)) {
73720+ ret = 1;
73721+ goto out;
73722+ }
73723+ } while_each_pid_task(pid, type, p);
73724+out:
73725+ read_unlock(&tasklist_lock);
73726+ return ret;
73727+#endif
73728+ return 0;
73729+}
73730+
73731+int
73732+gr_pid_is_chrooted(struct task_struct *p)
73733+{
73734+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73735+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
73736+ return 0;
73737+
73738+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
73739+ !have_same_root(current, p)) {
73740+ return 1;
73741+ }
73742+#endif
73743+ return 0;
73744+}
73745+
73746+EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
73747+
73748+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
73749+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
73750+{
73751+ struct path path, currentroot;
73752+ int ret = 0;
73753+
73754+ path.dentry = (struct dentry *)u_dentry;
73755+ path.mnt = (struct vfsmount *)u_mnt;
73756+ get_fs_root(current->fs, &currentroot);
73757+ if (path_is_under(&path, &currentroot))
73758+ ret = 1;
73759+ path_put(&currentroot);
73760+
73761+ return ret;
73762+}
73763+#endif
73764+
73765+int
73766+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
73767+{
73768+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
73769+ if (!grsec_enable_chroot_fchdir)
73770+ return 1;
73771+
73772+ if (!proc_is_chrooted(current))
73773+ return 1;
73774+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
73775+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
73776+ return 0;
73777+ }
73778+#endif
73779+ return 1;
73780+}
73781+
73782+int
73783+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73784+ const time_t shm_createtime)
73785+{
73786+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
73787+ struct task_struct *p;
73788+ time_t starttime;
73789+
73790+ if (unlikely(!grsec_enable_chroot_shmat))
73791+ return 1;
73792+
73793+ if (likely(!proc_is_chrooted(current)))
73794+ return 1;
73795+
73796+ rcu_read_lock();
73797+ read_lock(&tasklist_lock);
73798+
73799+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
73800+ starttime = p->start_time.tv_sec;
73801+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
73802+ if (have_same_root(current, p)) {
73803+ goto allow;
73804+ } else {
73805+ read_unlock(&tasklist_lock);
73806+ rcu_read_unlock();
73807+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
73808+ return 0;
73809+ }
73810+ }
73811+ /* creator exited, pid reuse, fall through to next check */
73812+ }
73813+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
73814+ if (unlikely(!have_same_root(current, p))) {
73815+ read_unlock(&tasklist_lock);
73816+ rcu_read_unlock();
73817+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
73818+ return 0;
73819+ }
73820+ }
73821+
73822+allow:
73823+ read_unlock(&tasklist_lock);
73824+ rcu_read_unlock();
73825+#endif
73826+ return 1;
73827+}
73828+
73829+void
73830+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
73831+{
73832+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
73833+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
73834+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
73835+#endif
73836+ return;
73837+}
73838+
73839+int
73840+gr_handle_chroot_mknod(const struct dentry *dentry,
73841+ const struct vfsmount *mnt, const int mode)
73842+{
73843+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
73844+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
73845+ proc_is_chrooted(current)) {
73846+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
73847+ return -EPERM;
73848+ }
73849+#endif
73850+ return 0;
73851+}
73852+
73853+int
73854+gr_handle_chroot_mount(const struct dentry *dentry,
73855+ const struct vfsmount *mnt, const char *dev_name)
73856+{
73857+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
73858+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
73859+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
73860+ return -EPERM;
73861+ }
73862+#endif
73863+ return 0;
73864+}
73865+
73866+int
73867+gr_handle_chroot_pivot(void)
73868+{
73869+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
73870+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
73871+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
73872+ return -EPERM;
73873+ }
73874+#endif
73875+ return 0;
73876+}
73877+
73878+int
73879+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
73880+{
73881+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
73882+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
73883+ !gr_is_outside_chroot(dentry, mnt)) {
73884+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
73885+ return -EPERM;
73886+ }
73887+#endif
73888+ return 0;
73889+}
73890+
73891+extern const char *captab_log[];
73892+extern int captab_log_entries;
73893+
73894+int
73895+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
73896+{
73897+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73898+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
73899+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
73900+ if (cap_raised(chroot_caps, cap)) {
73901+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
73902+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
73903+ }
73904+ return 0;
73905+ }
73906+ }
73907+#endif
73908+ return 1;
73909+}
73910+
73911+int
73912+gr_chroot_is_capable(const int cap)
73913+{
73914+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73915+ return gr_task_chroot_is_capable(current, current_cred(), cap);
73916+#endif
73917+ return 1;
73918+}
73919+
73920+int
73921+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
73922+{
73923+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73924+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
73925+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
73926+ if (cap_raised(chroot_caps, cap)) {
73927+ return 0;
73928+ }
73929+ }
73930+#endif
73931+ return 1;
73932+}
73933+
73934+int
73935+gr_chroot_is_capable_nolog(const int cap)
73936+{
73937+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73938+ return gr_task_chroot_is_capable_nolog(current, cap);
73939+#endif
73940+ return 1;
73941+}
73942+
73943+int
73944+gr_handle_chroot_sysctl(const int op)
73945+{
73946+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
73947+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
73948+ proc_is_chrooted(current))
73949+ return -EACCES;
73950+#endif
73951+ return 0;
73952+}
73953+
73954+void
73955+gr_handle_chroot_chdir(const struct path *path)
73956+{
73957+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
73958+ if (grsec_enable_chroot_chdir)
73959+ set_fs_pwd(current->fs, path);
73960+#endif
73961+ return;
73962+}
73963+
73964+int
73965+gr_handle_chroot_chmod(const struct dentry *dentry,
73966+ const struct vfsmount *mnt, const int mode)
73967+{
73968+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
73969+ /* allow chmod +s on directories, but not files */
73970+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
73971+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
73972+ proc_is_chrooted(current)) {
73973+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
73974+ return -EPERM;
73975+ }
73976+#endif
73977+ return 0;
73978+}
73979diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
73980new file mode 100644
73981index 0000000..4d6fce8
73982--- /dev/null
73983+++ b/grsecurity/grsec_disabled.c
73984@@ -0,0 +1,433 @@
73985+#include <linux/kernel.h>
73986+#include <linux/module.h>
73987+#include <linux/sched.h>
73988+#include <linux/file.h>
73989+#include <linux/fs.h>
73990+#include <linux/kdev_t.h>
73991+#include <linux/net.h>
73992+#include <linux/in.h>
73993+#include <linux/ip.h>
73994+#include <linux/skbuff.h>
73995+#include <linux/sysctl.h>
73996+
73997+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
73998+void
73999+pax_set_initial_flags(struct linux_binprm *bprm)
74000+{
74001+ return;
74002+}
74003+#endif
74004+
74005+#ifdef CONFIG_SYSCTL
74006+__u32
74007+gr_handle_sysctl(const struct ctl_table * table, const int op)
74008+{
74009+ return 0;
74010+}
74011+#endif
74012+
74013+#ifdef CONFIG_TASKSTATS
74014+int gr_is_taskstats_denied(int pid)
74015+{
74016+ return 0;
74017+}
74018+#endif
74019+
74020+int
74021+gr_acl_is_enabled(void)
74022+{
74023+ return 0;
74024+}
74025+
74026+void
74027+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
74028+{
74029+ return;
74030+}
74031+
74032+int
74033+gr_handle_rawio(const struct inode *inode)
74034+{
74035+ return 0;
74036+}
74037+
74038+void
74039+gr_acl_handle_psacct(struct task_struct *task, const long code)
74040+{
74041+ return;
74042+}
74043+
74044+int
74045+gr_handle_ptrace(struct task_struct *task, const long request)
74046+{
74047+ return 0;
74048+}
74049+
74050+int
74051+gr_handle_proc_ptrace(struct task_struct *task)
74052+{
74053+ return 0;
74054+}
74055+
74056+int
74057+gr_set_acls(const int type)
74058+{
74059+ return 0;
74060+}
74061+
74062+int
74063+gr_check_hidden_task(const struct task_struct *tsk)
74064+{
74065+ return 0;
74066+}
74067+
74068+int
74069+gr_check_protected_task(const struct task_struct *task)
74070+{
74071+ return 0;
74072+}
74073+
74074+int
74075+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
74076+{
74077+ return 0;
74078+}
74079+
74080+void
74081+gr_copy_label(struct task_struct *tsk)
74082+{
74083+ return;
74084+}
74085+
74086+void
74087+gr_set_pax_flags(struct task_struct *task)
74088+{
74089+ return;
74090+}
74091+
74092+int
74093+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
74094+ const int unsafe_share)
74095+{
74096+ return 0;
74097+}
74098+
74099+void
74100+gr_handle_delete(const ino_t ino, const dev_t dev)
74101+{
74102+ return;
74103+}
74104+
74105+void
74106+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
74107+{
74108+ return;
74109+}
74110+
74111+void
74112+gr_handle_crash(struct task_struct *task, const int sig)
74113+{
74114+ return;
74115+}
74116+
74117+int
74118+gr_check_crash_exec(const struct file *filp)
74119+{
74120+ return 0;
74121+}
74122+
74123+int
74124+gr_check_crash_uid(const kuid_t uid)
74125+{
74126+ return 0;
74127+}
74128+
74129+void
74130+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
74131+ struct dentry *old_dentry,
74132+ struct dentry *new_dentry,
74133+ struct vfsmount *mnt, const __u8 replace)
74134+{
74135+ return;
74136+}
74137+
74138+int
74139+gr_search_socket(const int family, const int type, const int protocol)
74140+{
74141+ return 1;
74142+}
74143+
74144+int
74145+gr_search_connectbind(const int mode, const struct socket *sock,
74146+ const struct sockaddr_in *addr)
74147+{
74148+ return 0;
74149+}
74150+
74151+void
74152+gr_handle_alertkill(struct task_struct *task)
74153+{
74154+ return;
74155+}
74156+
74157+__u32
74158+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
74159+{
74160+ return 1;
74161+}
74162+
74163+__u32
74164+gr_acl_handle_hidden_file(const struct dentry * dentry,
74165+ const struct vfsmount * mnt)
74166+{
74167+ return 1;
74168+}
74169+
74170+__u32
74171+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
74172+ int acc_mode)
74173+{
74174+ return 1;
74175+}
74176+
74177+__u32
74178+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
74179+{
74180+ return 1;
74181+}
74182+
74183+__u32
74184+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
74185+{
74186+ return 1;
74187+}
74188+
74189+int
74190+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
74191+ unsigned int *vm_flags)
74192+{
74193+ return 1;
74194+}
74195+
74196+__u32
74197+gr_acl_handle_truncate(const struct dentry * dentry,
74198+ const struct vfsmount * mnt)
74199+{
74200+ return 1;
74201+}
74202+
74203+__u32
74204+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
74205+{
74206+ return 1;
74207+}
74208+
74209+__u32
74210+gr_acl_handle_access(const struct dentry * dentry,
74211+ const struct vfsmount * mnt, const int fmode)
74212+{
74213+ return 1;
74214+}
74215+
74216+__u32
74217+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
74218+ umode_t *mode)
74219+{
74220+ return 1;
74221+}
74222+
74223+__u32
74224+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
74225+{
74226+ return 1;
74227+}
74228+
74229+__u32
74230+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
74231+{
74232+ return 1;
74233+}
74234+
74235+__u32
74236+gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
74237+{
74238+ return 1;
74239+}
74240+
74241+void
74242+grsecurity_init(void)
74243+{
74244+ return;
74245+}
74246+
74247+umode_t gr_acl_umask(void)
74248+{
74249+ return 0;
74250+}
74251+
74252+__u32
74253+gr_acl_handle_mknod(const struct dentry * new_dentry,
74254+ const struct dentry * parent_dentry,
74255+ const struct vfsmount * parent_mnt,
74256+ const int mode)
74257+{
74258+ return 1;
74259+}
74260+
74261+__u32
74262+gr_acl_handle_mkdir(const struct dentry * new_dentry,
74263+ const struct dentry * parent_dentry,
74264+ const struct vfsmount * parent_mnt)
74265+{
74266+ return 1;
74267+}
74268+
74269+__u32
74270+gr_acl_handle_symlink(const struct dentry * new_dentry,
74271+ const struct dentry * parent_dentry,
74272+ const struct vfsmount * parent_mnt, const struct filename *from)
74273+{
74274+ return 1;
74275+}
74276+
74277+__u32
74278+gr_acl_handle_link(const struct dentry * new_dentry,
74279+ const struct dentry * parent_dentry,
74280+ const struct vfsmount * parent_mnt,
74281+ const struct dentry * old_dentry,
74282+ const struct vfsmount * old_mnt, const struct filename *to)
74283+{
74284+ return 1;
74285+}
74286+
74287+int
74288+gr_acl_handle_rename(const struct dentry *new_dentry,
74289+ const struct dentry *parent_dentry,
74290+ const struct vfsmount *parent_mnt,
74291+ const struct dentry *old_dentry,
74292+ const struct inode *old_parent_inode,
74293+ const struct vfsmount *old_mnt, const struct filename *newname)
74294+{
74295+ return 0;
74296+}
74297+
74298+int
74299+gr_acl_handle_filldir(const struct file *file, const char *name,
74300+ const int namelen, const ino_t ino)
74301+{
74302+ return 1;
74303+}
74304+
74305+int
74306+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
74307+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
74308+{
74309+ return 1;
74310+}
74311+
74312+int
74313+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
74314+{
74315+ return 0;
74316+}
74317+
74318+int
74319+gr_search_accept(const struct socket *sock)
74320+{
74321+ return 0;
74322+}
74323+
74324+int
74325+gr_search_listen(const struct socket *sock)
74326+{
74327+ return 0;
74328+}
74329+
74330+int
74331+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
74332+{
74333+ return 0;
74334+}
74335+
74336+__u32
74337+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
74338+{
74339+ return 1;
74340+}
74341+
74342+__u32
74343+gr_acl_handle_creat(const struct dentry * dentry,
74344+ const struct dentry * p_dentry,
74345+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
74346+ const int imode)
74347+{
74348+ return 1;
74349+}
74350+
74351+void
74352+gr_acl_handle_exit(void)
74353+{
74354+ return;
74355+}
74356+
74357+int
74358+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
74359+{
74360+ return 1;
74361+}
74362+
74363+void
74364+gr_set_role_label(const kuid_t uid, const kgid_t gid)
74365+{
74366+ return;
74367+}
74368+
74369+int
74370+gr_acl_handle_procpidmem(const struct task_struct *task)
74371+{
74372+ return 0;
74373+}
74374+
74375+int
74376+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
74377+{
74378+ return 0;
74379+}
74380+
74381+int
74382+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
74383+{
74384+ return 0;
74385+}
74386+
74387+int
74388+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
74389+{
74390+ return 0;
74391+}
74392+
74393+int
74394+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
74395+{
74396+ return 0;
74397+}
74398+
74399+int gr_acl_enable_at_secure(void)
74400+{
74401+ return 0;
74402+}
74403+
74404+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
74405+{
74406+ return dentry->d_sb->s_dev;
74407+}
74408+
74409+void gr_put_exec_file(struct task_struct *task)
74410+{
74411+ return;
74412+}
74413+
74414+#ifdef CONFIG_SECURITY
74415+EXPORT_SYMBOL_GPL(gr_check_user_change);
74416+EXPORT_SYMBOL_GPL(gr_check_group_change);
74417+#endif
74418diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
74419new file mode 100644
74420index 0000000..f35f454
74421--- /dev/null
74422+++ b/grsecurity/grsec_exec.c
74423@@ -0,0 +1,187 @@
74424+#include <linux/kernel.h>
74425+#include <linux/sched.h>
74426+#include <linux/file.h>
74427+#include <linux/binfmts.h>
74428+#include <linux/fs.h>
74429+#include <linux/types.h>
74430+#include <linux/grdefs.h>
74431+#include <linux/grsecurity.h>
74432+#include <linux/grinternal.h>
74433+#include <linux/capability.h>
74434+#include <linux/module.h>
74435+#include <linux/compat.h>
74436+
74437+#include <asm/uaccess.h>
74438+
74439+#ifdef CONFIG_GRKERNSEC_EXECLOG
74440+static char gr_exec_arg_buf[132];
74441+static DEFINE_MUTEX(gr_exec_arg_mutex);
74442+#endif
74443+
74444+struct user_arg_ptr {
74445+#ifdef CONFIG_COMPAT
74446+ bool is_compat;
74447+#endif
74448+ union {
74449+ const char __user *const __user *native;
74450+#ifdef CONFIG_COMPAT
74451+ const compat_uptr_t __user *compat;
74452+#endif
74453+ } ptr;
74454+};
74455+
74456+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
74457+
74458+void
74459+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
74460+{
74461+#ifdef CONFIG_GRKERNSEC_EXECLOG
74462+ char *grarg = gr_exec_arg_buf;
74463+ unsigned int i, x, execlen = 0;
74464+ char c;
74465+
74466+ if (!((grsec_enable_execlog && grsec_enable_group &&
74467+ in_group_p(grsec_audit_gid))
74468+ || (grsec_enable_execlog && !grsec_enable_group)))
74469+ return;
74470+
74471+ mutex_lock(&gr_exec_arg_mutex);
74472+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
74473+
74474+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
74475+ const char __user *p;
74476+ unsigned int len;
74477+
74478+ p = get_user_arg_ptr(argv, i);
74479+ if (IS_ERR(p))
74480+ goto log;
74481+
74482+ len = strnlen_user(p, 128 - execlen);
74483+ if (len > 128 - execlen)
74484+ len = 128 - execlen;
74485+ else if (len > 0)
74486+ len--;
74487+ if (copy_from_user(grarg + execlen, p, len))
74488+ goto log;
74489+
74490+ /* rewrite unprintable characters */
74491+ for (x = 0; x < len; x++) {
74492+ c = *(grarg + execlen + x);
74493+ if (c < 32 || c > 126)
74494+ *(grarg + execlen + x) = ' ';
74495+ }
74496+
74497+ execlen += len;
74498+ *(grarg + execlen) = ' ';
74499+ *(grarg + execlen + 1) = '\0';
74500+ execlen++;
74501+ }
74502+
74503+ log:
74504+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
74505+ bprm->file->f_path.mnt, grarg);
74506+ mutex_unlock(&gr_exec_arg_mutex);
74507+#endif
74508+ return;
74509+}
74510+
74511+#ifdef CONFIG_GRKERNSEC
74512+extern int gr_acl_is_capable(const int cap);
74513+extern int gr_acl_is_capable_nolog(const int cap);
74514+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74515+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
74516+extern int gr_chroot_is_capable(const int cap);
74517+extern int gr_chroot_is_capable_nolog(const int cap);
74518+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74519+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
74520+#endif
74521+
74522+const char *captab_log[] = {
74523+ "CAP_CHOWN",
74524+ "CAP_DAC_OVERRIDE",
74525+ "CAP_DAC_READ_SEARCH",
74526+ "CAP_FOWNER",
74527+ "CAP_FSETID",
74528+ "CAP_KILL",
74529+ "CAP_SETGID",
74530+ "CAP_SETUID",
74531+ "CAP_SETPCAP",
74532+ "CAP_LINUX_IMMUTABLE",
74533+ "CAP_NET_BIND_SERVICE",
74534+ "CAP_NET_BROADCAST",
74535+ "CAP_NET_ADMIN",
74536+ "CAP_NET_RAW",
74537+ "CAP_IPC_LOCK",
74538+ "CAP_IPC_OWNER",
74539+ "CAP_SYS_MODULE",
74540+ "CAP_SYS_RAWIO",
74541+ "CAP_SYS_CHROOT",
74542+ "CAP_SYS_PTRACE",
74543+ "CAP_SYS_PACCT",
74544+ "CAP_SYS_ADMIN",
74545+ "CAP_SYS_BOOT",
74546+ "CAP_SYS_NICE",
74547+ "CAP_SYS_RESOURCE",
74548+ "CAP_SYS_TIME",
74549+ "CAP_SYS_TTY_CONFIG",
74550+ "CAP_MKNOD",
74551+ "CAP_LEASE",
74552+ "CAP_AUDIT_WRITE",
74553+ "CAP_AUDIT_CONTROL",
74554+ "CAP_SETFCAP",
74555+ "CAP_MAC_OVERRIDE",
74556+ "CAP_MAC_ADMIN",
74557+ "CAP_SYSLOG",
74558+ "CAP_WAKE_ALARM"
74559+};
74560+
74561+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
74562+
74563+int gr_is_capable(const int cap)
74564+{
74565+#ifdef CONFIG_GRKERNSEC
74566+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
74567+ return 1;
74568+ return 0;
74569+#else
74570+ return 1;
74571+#endif
74572+}
74573+
74574+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
74575+{
74576+#ifdef CONFIG_GRKERNSEC
74577+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
74578+ return 1;
74579+ return 0;
74580+#else
74581+ return 1;
74582+#endif
74583+}
74584+
74585+int gr_is_capable_nolog(const int cap)
74586+{
74587+#ifdef CONFIG_GRKERNSEC
74588+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
74589+ return 1;
74590+ return 0;
74591+#else
74592+ return 1;
74593+#endif
74594+}
74595+
74596+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
74597+{
74598+#ifdef CONFIG_GRKERNSEC
74599+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
74600+ return 1;
74601+ return 0;
74602+#else
74603+ return 1;
74604+#endif
74605+}
74606+
74607+EXPORT_SYMBOL_GPL(gr_is_capable);
74608+EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
74609+EXPORT_SYMBOL_GPL(gr_task_is_capable);
74610+EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
74611diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
74612new file mode 100644
74613index 0000000..06cc6ea
74614--- /dev/null
74615+++ b/grsecurity/grsec_fifo.c
74616@@ -0,0 +1,24 @@
74617+#include <linux/kernel.h>
74618+#include <linux/sched.h>
74619+#include <linux/fs.h>
74620+#include <linux/file.h>
74621+#include <linux/grinternal.h>
74622+
74623+int
74624+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
74625+ const struct dentry *dir, const int flag, const int acc_mode)
74626+{
74627+#ifdef CONFIG_GRKERNSEC_FIFO
74628+ const struct cred *cred = current_cred();
74629+
74630+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
74631+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
74632+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
74633+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
74634+ if (!inode_permission(dentry->d_inode, acc_mode))
74635+ 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));
74636+ return -EACCES;
74637+ }
74638+#endif
74639+ return 0;
74640+}
74641diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
74642new file mode 100644
74643index 0000000..8ca18bf
74644--- /dev/null
74645+++ b/grsecurity/grsec_fork.c
74646@@ -0,0 +1,23 @@
74647+#include <linux/kernel.h>
74648+#include <linux/sched.h>
74649+#include <linux/grsecurity.h>
74650+#include <linux/grinternal.h>
74651+#include <linux/errno.h>
74652+
74653+void
74654+gr_log_forkfail(const int retval)
74655+{
74656+#ifdef CONFIG_GRKERNSEC_FORKFAIL
74657+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
74658+ switch (retval) {
74659+ case -EAGAIN:
74660+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
74661+ break;
74662+ case -ENOMEM:
74663+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
74664+ break;
74665+ }
74666+ }
74667+#endif
74668+ return;
74669+}
74670diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
74671new file mode 100644
74672index 0000000..ae6c028
74673--- /dev/null
74674+++ b/grsecurity/grsec_init.c
74675@@ -0,0 +1,272 @@
74676+#include <linux/kernel.h>
74677+#include <linux/sched.h>
74678+#include <linux/mm.h>
74679+#include <linux/gracl.h>
74680+#include <linux/slab.h>
74681+#include <linux/vmalloc.h>
74682+#include <linux/percpu.h>
74683+#include <linux/module.h>
74684+
74685+int grsec_enable_ptrace_readexec;
74686+int grsec_enable_setxid;
74687+int grsec_enable_symlinkown;
74688+kgid_t grsec_symlinkown_gid;
74689+int grsec_enable_brute;
74690+int grsec_enable_link;
74691+int grsec_enable_dmesg;
74692+int grsec_enable_harden_ptrace;
74693+int grsec_enable_harden_ipc;
74694+int grsec_enable_fifo;
74695+int grsec_enable_execlog;
74696+int grsec_enable_signal;
74697+int grsec_enable_forkfail;
74698+int grsec_enable_audit_ptrace;
74699+int grsec_enable_time;
74700+int grsec_enable_group;
74701+kgid_t grsec_audit_gid;
74702+int grsec_enable_chdir;
74703+int grsec_enable_mount;
74704+int grsec_enable_rofs;
74705+int grsec_deny_new_usb;
74706+int grsec_enable_chroot_findtask;
74707+int grsec_enable_chroot_mount;
74708+int grsec_enable_chroot_shmat;
74709+int grsec_enable_chroot_fchdir;
74710+int grsec_enable_chroot_double;
74711+int grsec_enable_chroot_pivot;
74712+int grsec_enable_chroot_chdir;
74713+int grsec_enable_chroot_chmod;
74714+int grsec_enable_chroot_mknod;
74715+int grsec_enable_chroot_nice;
74716+int grsec_enable_chroot_execlog;
74717+int grsec_enable_chroot_caps;
74718+int grsec_enable_chroot_sysctl;
74719+int grsec_enable_chroot_unix;
74720+int grsec_enable_tpe;
74721+kgid_t grsec_tpe_gid;
74722+int grsec_enable_blackhole;
74723+#ifdef CONFIG_IPV6_MODULE
74724+EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
74725+#endif
74726+int grsec_lastack_retries;
74727+int grsec_enable_tpe_all;
74728+int grsec_enable_tpe_invert;
74729+int grsec_enable_socket_all;
74730+kgid_t grsec_socket_all_gid;
74731+int grsec_enable_socket_client;
74732+kgid_t grsec_socket_client_gid;
74733+int grsec_enable_socket_server;
74734+kgid_t grsec_socket_server_gid;
74735+int grsec_resource_logging;
74736+int grsec_disable_privio;
74737+int grsec_enable_log_rwxmaps;
74738+int grsec_lock;
74739+
74740+DEFINE_SPINLOCK(grsec_alert_lock);
74741+unsigned long grsec_alert_wtime = 0;
74742+unsigned long grsec_alert_fyet = 0;
74743+
74744+DEFINE_SPINLOCK(grsec_audit_lock);
74745+
74746+DEFINE_RWLOCK(grsec_exec_file_lock);
74747+
74748+char *gr_shared_page[4];
74749+
74750+char *gr_alert_log_fmt;
74751+char *gr_audit_log_fmt;
74752+char *gr_alert_log_buf;
74753+char *gr_audit_log_buf;
74754+
74755+void __init
74756+grsecurity_init(void)
74757+{
74758+ int j;
74759+ /* create the per-cpu shared pages */
74760+
74761+#ifdef CONFIG_X86
74762+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
74763+#endif
74764+
74765+ for (j = 0; j < 4; j++) {
74766+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
74767+ if (gr_shared_page[j] == NULL) {
74768+ panic("Unable to allocate grsecurity shared page");
74769+ return;
74770+ }
74771+ }
74772+
74773+ /* allocate log buffers */
74774+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
74775+ if (!gr_alert_log_fmt) {
74776+ panic("Unable to allocate grsecurity alert log format buffer");
74777+ return;
74778+ }
74779+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
74780+ if (!gr_audit_log_fmt) {
74781+ panic("Unable to allocate grsecurity audit log format buffer");
74782+ return;
74783+ }
74784+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
74785+ if (!gr_alert_log_buf) {
74786+ panic("Unable to allocate grsecurity alert log buffer");
74787+ return;
74788+ }
74789+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
74790+ if (!gr_audit_log_buf) {
74791+ panic("Unable to allocate grsecurity audit log buffer");
74792+ return;
74793+ }
74794+
74795+#ifdef CONFIG_GRKERNSEC_IO
74796+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
74797+ grsec_disable_privio = 1;
74798+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
74799+ grsec_disable_privio = 1;
74800+#else
74801+ grsec_disable_privio = 0;
74802+#endif
74803+#endif
74804+
74805+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
74806+ /* for backward compatibility, tpe_invert always defaults to on if
74807+ enabled in the kernel
74808+ */
74809+ grsec_enable_tpe_invert = 1;
74810+#endif
74811+
74812+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
74813+#ifndef CONFIG_GRKERNSEC_SYSCTL
74814+ grsec_lock = 1;
74815+#endif
74816+
74817+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74818+ grsec_enable_log_rwxmaps = 1;
74819+#endif
74820+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
74821+ grsec_enable_group = 1;
74822+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
74823+#endif
74824+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
74825+ grsec_enable_ptrace_readexec = 1;
74826+#endif
74827+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
74828+ grsec_enable_chdir = 1;
74829+#endif
74830+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
74831+ grsec_enable_harden_ptrace = 1;
74832+#endif
74833+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
74834+ grsec_enable_harden_ipc = 1;
74835+#endif
74836+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74837+ grsec_enable_mount = 1;
74838+#endif
74839+#ifdef CONFIG_GRKERNSEC_LINK
74840+ grsec_enable_link = 1;
74841+#endif
74842+#ifdef CONFIG_GRKERNSEC_BRUTE
74843+ grsec_enable_brute = 1;
74844+#endif
74845+#ifdef CONFIG_GRKERNSEC_DMESG
74846+ grsec_enable_dmesg = 1;
74847+#endif
74848+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74849+ grsec_enable_blackhole = 1;
74850+ grsec_lastack_retries = 4;
74851+#endif
74852+#ifdef CONFIG_GRKERNSEC_FIFO
74853+ grsec_enable_fifo = 1;
74854+#endif
74855+#ifdef CONFIG_GRKERNSEC_EXECLOG
74856+ grsec_enable_execlog = 1;
74857+#endif
74858+#ifdef CONFIG_GRKERNSEC_SETXID
74859+ grsec_enable_setxid = 1;
74860+#endif
74861+#ifdef CONFIG_GRKERNSEC_SIGNAL
74862+ grsec_enable_signal = 1;
74863+#endif
74864+#ifdef CONFIG_GRKERNSEC_FORKFAIL
74865+ grsec_enable_forkfail = 1;
74866+#endif
74867+#ifdef CONFIG_GRKERNSEC_TIME
74868+ grsec_enable_time = 1;
74869+#endif
74870+#ifdef CONFIG_GRKERNSEC_RESLOG
74871+ grsec_resource_logging = 1;
74872+#endif
74873+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
74874+ grsec_enable_chroot_findtask = 1;
74875+#endif
74876+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
74877+ grsec_enable_chroot_unix = 1;
74878+#endif
74879+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
74880+ grsec_enable_chroot_mount = 1;
74881+#endif
74882+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
74883+ grsec_enable_chroot_fchdir = 1;
74884+#endif
74885+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
74886+ grsec_enable_chroot_shmat = 1;
74887+#endif
74888+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
74889+ grsec_enable_audit_ptrace = 1;
74890+#endif
74891+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
74892+ grsec_enable_chroot_double = 1;
74893+#endif
74894+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
74895+ grsec_enable_chroot_pivot = 1;
74896+#endif
74897+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
74898+ grsec_enable_chroot_chdir = 1;
74899+#endif
74900+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
74901+ grsec_enable_chroot_chmod = 1;
74902+#endif
74903+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
74904+ grsec_enable_chroot_mknod = 1;
74905+#endif
74906+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
74907+ grsec_enable_chroot_nice = 1;
74908+#endif
74909+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
74910+ grsec_enable_chroot_execlog = 1;
74911+#endif
74912+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74913+ grsec_enable_chroot_caps = 1;
74914+#endif
74915+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
74916+ grsec_enable_chroot_sysctl = 1;
74917+#endif
74918+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
74919+ grsec_enable_symlinkown = 1;
74920+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
74921+#endif
74922+#ifdef CONFIG_GRKERNSEC_TPE
74923+ grsec_enable_tpe = 1;
74924+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
74925+#ifdef CONFIG_GRKERNSEC_TPE_ALL
74926+ grsec_enable_tpe_all = 1;
74927+#endif
74928+#endif
74929+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
74930+ grsec_enable_socket_all = 1;
74931+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
74932+#endif
74933+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
74934+ grsec_enable_socket_client = 1;
74935+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
74936+#endif
74937+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
74938+ grsec_enable_socket_server = 1;
74939+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
74940+#endif
74941+#endif
74942+#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
74943+ grsec_deny_new_usb = 1;
74944+#endif
74945+
74946+ return;
74947+}
74948diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
74949new file mode 100644
74950index 0000000..1773300
74951--- /dev/null
74952+++ b/grsecurity/grsec_ipc.c
74953@@ -0,0 +1,48 @@
74954+#include <linux/kernel.h>
74955+#include <linux/mm.h>
74956+#include <linux/sched.h>
74957+#include <linux/file.h>
74958+#include <linux/ipc.h>
74959+#include <linux/ipc_namespace.h>
74960+#include <linux/grsecurity.h>
74961+#include <linux/grinternal.h>
74962+
74963+int
74964+gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
74965+{
74966+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
74967+ int write;
74968+ int orig_granted_mode;
74969+ kuid_t euid;
74970+ kgid_t egid;
74971+
74972+ if (!grsec_enable_harden_ipc)
74973+ return 1;
74974+
74975+ euid = current_euid();
74976+ egid = current_egid();
74977+
74978+ write = requested_mode & 00002;
74979+ orig_granted_mode = ipcp->mode;
74980+
74981+ if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
74982+ orig_granted_mode >>= 6;
74983+ else {
74984+ /* if likely wrong permissions, lock to user */
74985+ if (orig_granted_mode & 0007)
74986+ orig_granted_mode = 0;
74987+ /* otherwise do a egid-only check */
74988+ else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
74989+ orig_granted_mode >>= 3;
74990+ /* otherwise, no access */
74991+ else
74992+ orig_granted_mode = 0;
74993+ }
74994+ if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
74995+ !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
74996+ gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
74997+ return 0;
74998+ }
74999+#endif
75000+ return 1;
75001+}
75002diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
75003new file mode 100644
75004index 0000000..5e05e20
75005--- /dev/null
75006+++ b/grsecurity/grsec_link.c
75007@@ -0,0 +1,58 @@
75008+#include <linux/kernel.h>
75009+#include <linux/sched.h>
75010+#include <linux/fs.h>
75011+#include <linux/file.h>
75012+#include <linux/grinternal.h>
75013+
75014+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
75015+{
75016+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
75017+ const struct inode *link_inode = link->dentry->d_inode;
75018+
75019+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
75020+ /* ignore root-owned links, e.g. /proc/self */
75021+ gr_is_global_nonroot(link_inode->i_uid) && target &&
75022+ !uid_eq(link_inode->i_uid, target->i_uid)) {
75023+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
75024+ return 1;
75025+ }
75026+#endif
75027+ return 0;
75028+}
75029+
75030+int
75031+gr_handle_follow_link(const struct inode *parent,
75032+ const struct inode *inode,
75033+ const struct dentry *dentry, const struct vfsmount *mnt)
75034+{
75035+#ifdef CONFIG_GRKERNSEC_LINK
75036+ const struct cred *cred = current_cred();
75037+
75038+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
75039+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
75040+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
75041+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
75042+ return -EACCES;
75043+ }
75044+#endif
75045+ return 0;
75046+}
75047+
75048+int
75049+gr_handle_hardlink(const struct dentry *dentry,
75050+ const struct vfsmount *mnt,
75051+ struct inode *inode, const int mode, const struct filename *to)
75052+{
75053+#ifdef CONFIG_GRKERNSEC_LINK
75054+ const struct cred *cred = current_cred();
75055+
75056+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
75057+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
75058+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
75059+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
75060+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
75061+ return -EPERM;
75062+ }
75063+#endif
75064+ return 0;
75065+}
75066diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
75067new file mode 100644
75068index 0000000..dbe0a6b
75069--- /dev/null
75070+++ b/grsecurity/grsec_log.c
75071@@ -0,0 +1,341 @@
75072+#include <linux/kernel.h>
75073+#include <linux/sched.h>
75074+#include <linux/file.h>
75075+#include <linux/tty.h>
75076+#include <linux/fs.h>
75077+#include <linux/mm.h>
75078+#include <linux/grinternal.h>
75079+
75080+#ifdef CONFIG_TREE_PREEMPT_RCU
75081+#define DISABLE_PREEMPT() preempt_disable()
75082+#define ENABLE_PREEMPT() preempt_enable()
75083+#else
75084+#define DISABLE_PREEMPT()
75085+#define ENABLE_PREEMPT()
75086+#endif
75087+
75088+#define BEGIN_LOCKS(x) \
75089+ DISABLE_PREEMPT(); \
75090+ rcu_read_lock(); \
75091+ read_lock(&tasklist_lock); \
75092+ read_lock(&grsec_exec_file_lock); \
75093+ if (x != GR_DO_AUDIT) \
75094+ spin_lock(&grsec_alert_lock); \
75095+ else \
75096+ spin_lock(&grsec_audit_lock)
75097+
75098+#define END_LOCKS(x) \
75099+ if (x != GR_DO_AUDIT) \
75100+ spin_unlock(&grsec_alert_lock); \
75101+ else \
75102+ spin_unlock(&grsec_audit_lock); \
75103+ read_unlock(&grsec_exec_file_lock); \
75104+ read_unlock(&tasklist_lock); \
75105+ rcu_read_unlock(); \
75106+ ENABLE_PREEMPT(); \
75107+ if (x == GR_DONT_AUDIT) \
75108+ gr_handle_alertkill(current)
75109+
75110+enum {
75111+ FLOODING,
75112+ NO_FLOODING
75113+};
75114+
75115+extern char *gr_alert_log_fmt;
75116+extern char *gr_audit_log_fmt;
75117+extern char *gr_alert_log_buf;
75118+extern char *gr_audit_log_buf;
75119+
75120+static int gr_log_start(int audit)
75121+{
75122+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
75123+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
75124+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75125+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
75126+ unsigned long curr_secs = get_seconds();
75127+
75128+ if (audit == GR_DO_AUDIT)
75129+ goto set_fmt;
75130+
75131+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
75132+ grsec_alert_wtime = curr_secs;
75133+ grsec_alert_fyet = 0;
75134+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
75135+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
75136+ grsec_alert_fyet++;
75137+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
75138+ grsec_alert_wtime = curr_secs;
75139+ grsec_alert_fyet++;
75140+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
75141+ return FLOODING;
75142+ }
75143+ else return FLOODING;
75144+
75145+set_fmt:
75146+#endif
75147+ memset(buf, 0, PAGE_SIZE);
75148+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
75149+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
75150+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
75151+ } else if (current->signal->curr_ip) {
75152+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
75153+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
75154+ } else if (gr_acl_is_enabled()) {
75155+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
75156+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
75157+ } else {
75158+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
75159+ strcpy(buf, fmt);
75160+ }
75161+
75162+ return NO_FLOODING;
75163+}
75164+
75165+static void gr_log_middle(int audit, const char *msg, va_list ap)
75166+ __attribute__ ((format (printf, 2, 0)));
75167+
75168+static void gr_log_middle(int audit, const char *msg, va_list ap)
75169+{
75170+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75171+ unsigned int len = strlen(buf);
75172+
75173+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
75174+
75175+ return;
75176+}
75177+
75178+static void gr_log_middle_varargs(int audit, const char *msg, ...)
75179+ __attribute__ ((format (printf, 2, 3)));
75180+
75181+static void gr_log_middle_varargs(int audit, const char *msg, ...)
75182+{
75183+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75184+ unsigned int len = strlen(buf);
75185+ va_list ap;
75186+
75187+ va_start(ap, msg);
75188+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
75189+ va_end(ap);
75190+
75191+ return;
75192+}
75193+
75194+static void gr_log_end(int audit, int append_default)
75195+{
75196+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75197+ if (append_default) {
75198+ struct task_struct *task = current;
75199+ struct task_struct *parent = task->real_parent;
75200+ const struct cred *cred = __task_cred(task);
75201+ const struct cred *pcred = __task_cred(parent);
75202+ unsigned int len = strlen(buf);
75203+
75204+ 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));
75205+ }
75206+
75207+ printk("%s\n", buf);
75208+
75209+ return;
75210+}
75211+
75212+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
75213+{
75214+ int logtype;
75215+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
75216+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
75217+ void *voidptr = NULL;
75218+ int num1 = 0, num2 = 0;
75219+ unsigned long ulong1 = 0, ulong2 = 0;
75220+ struct dentry *dentry = NULL;
75221+ struct vfsmount *mnt = NULL;
75222+ struct file *file = NULL;
75223+ struct task_struct *task = NULL;
75224+ struct vm_area_struct *vma = NULL;
75225+ const struct cred *cred, *pcred;
75226+ va_list ap;
75227+
75228+ BEGIN_LOCKS(audit);
75229+ logtype = gr_log_start(audit);
75230+ if (logtype == FLOODING) {
75231+ END_LOCKS(audit);
75232+ return;
75233+ }
75234+ va_start(ap, argtypes);
75235+ switch (argtypes) {
75236+ case GR_TTYSNIFF:
75237+ task = va_arg(ap, struct task_struct *);
75238+ 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));
75239+ break;
75240+ case GR_SYSCTL_HIDDEN:
75241+ str1 = va_arg(ap, char *);
75242+ gr_log_middle_varargs(audit, msg, result, str1);
75243+ break;
75244+ case GR_RBAC:
75245+ dentry = va_arg(ap, struct dentry *);
75246+ mnt = va_arg(ap, struct vfsmount *);
75247+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
75248+ break;
75249+ case GR_RBAC_STR:
75250+ dentry = va_arg(ap, struct dentry *);
75251+ mnt = va_arg(ap, struct vfsmount *);
75252+ str1 = va_arg(ap, char *);
75253+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
75254+ break;
75255+ case GR_STR_RBAC:
75256+ str1 = va_arg(ap, char *);
75257+ dentry = va_arg(ap, struct dentry *);
75258+ mnt = va_arg(ap, struct vfsmount *);
75259+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
75260+ break;
75261+ case GR_RBAC_MODE2:
75262+ dentry = va_arg(ap, struct dentry *);
75263+ mnt = va_arg(ap, struct vfsmount *);
75264+ str1 = va_arg(ap, char *);
75265+ str2 = va_arg(ap, char *);
75266+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
75267+ break;
75268+ case GR_RBAC_MODE3:
75269+ dentry = va_arg(ap, struct dentry *);
75270+ mnt = va_arg(ap, struct vfsmount *);
75271+ str1 = va_arg(ap, char *);
75272+ str2 = va_arg(ap, char *);
75273+ str3 = va_arg(ap, char *);
75274+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
75275+ break;
75276+ case GR_FILENAME:
75277+ dentry = va_arg(ap, struct dentry *);
75278+ mnt = va_arg(ap, struct vfsmount *);
75279+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
75280+ break;
75281+ case GR_STR_FILENAME:
75282+ str1 = va_arg(ap, char *);
75283+ dentry = va_arg(ap, struct dentry *);
75284+ mnt = va_arg(ap, struct vfsmount *);
75285+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
75286+ break;
75287+ case GR_FILENAME_STR:
75288+ dentry = va_arg(ap, struct dentry *);
75289+ mnt = va_arg(ap, struct vfsmount *);
75290+ str1 = va_arg(ap, char *);
75291+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
75292+ break;
75293+ case GR_FILENAME_TWO_INT:
75294+ dentry = va_arg(ap, struct dentry *);
75295+ mnt = va_arg(ap, struct vfsmount *);
75296+ num1 = va_arg(ap, int);
75297+ num2 = va_arg(ap, int);
75298+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
75299+ break;
75300+ case GR_FILENAME_TWO_INT_STR:
75301+ dentry = va_arg(ap, struct dentry *);
75302+ mnt = va_arg(ap, struct vfsmount *);
75303+ num1 = va_arg(ap, int);
75304+ num2 = va_arg(ap, int);
75305+ str1 = va_arg(ap, char *);
75306+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
75307+ break;
75308+ case GR_TEXTREL:
75309+ file = va_arg(ap, struct file *);
75310+ ulong1 = va_arg(ap, unsigned long);
75311+ ulong2 = va_arg(ap, unsigned long);
75312+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
75313+ break;
75314+ case GR_PTRACE:
75315+ task = va_arg(ap, struct task_struct *);
75316+ 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));
75317+ break;
75318+ case GR_RESOURCE:
75319+ task = va_arg(ap, struct task_struct *);
75320+ cred = __task_cred(task);
75321+ pcred = __task_cred(task->real_parent);
75322+ ulong1 = va_arg(ap, unsigned long);
75323+ str1 = va_arg(ap, char *);
75324+ ulong2 = va_arg(ap, unsigned long);
75325+ 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));
75326+ break;
75327+ case GR_CAP:
75328+ task = va_arg(ap, struct task_struct *);
75329+ cred = __task_cred(task);
75330+ pcred = __task_cred(task->real_parent);
75331+ str1 = va_arg(ap, char *);
75332+ 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));
75333+ break;
75334+ case GR_SIG:
75335+ str1 = va_arg(ap, char *);
75336+ voidptr = va_arg(ap, void *);
75337+ gr_log_middle_varargs(audit, msg, str1, voidptr);
75338+ break;
75339+ case GR_SIG2:
75340+ task = va_arg(ap, struct task_struct *);
75341+ cred = __task_cred(task);
75342+ pcred = __task_cred(task->real_parent);
75343+ num1 = va_arg(ap, int);
75344+ 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));
75345+ break;
75346+ case GR_CRASH1:
75347+ task = va_arg(ap, struct task_struct *);
75348+ cred = __task_cred(task);
75349+ pcred = __task_cred(task->real_parent);
75350+ ulong1 = va_arg(ap, unsigned long);
75351+ 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);
75352+ break;
75353+ case GR_CRASH2:
75354+ task = va_arg(ap, struct task_struct *);
75355+ cred = __task_cred(task);
75356+ pcred = __task_cred(task->real_parent);
75357+ ulong1 = va_arg(ap, unsigned long);
75358+ 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);
75359+ break;
75360+ case GR_RWXMAP:
75361+ file = va_arg(ap, struct file *);
75362+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
75363+ break;
75364+ case GR_RWXMAPVMA:
75365+ vma = va_arg(ap, struct vm_area_struct *);
75366+ if (vma->vm_file)
75367+ str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
75368+ else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
75369+ str1 = "<stack>";
75370+ else if (vma->vm_start <= current->mm->brk &&
75371+ vma->vm_end >= current->mm->start_brk)
75372+ str1 = "<heap>";
75373+ else
75374+ str1 = "<anonymous mapping>";
75375+ gr_log_middle_varargs(audit, msg, str1);
75376+ break;
75377+ case GR_PSACCT:
75378+ {
75379+ unsigned int wday, cday;
75380+ __u8 whr, chr;
75381+ __u8 wmin, cmin;
75382+ __u8 wsec, csec;
75383+ char cur_tty[64] = { 0 };
75384+ char parent_tty[64] = { 0 };
75385+
75386+ task = va_arg(ap, struct task_struct *);
75387+ wday = va_arg(ap, unsigned int);
75388+ cday = va_arg(ap, unsigned int);
75389+ whr = va_arg(ap, int);
75390+ chr = va_arg(ap, int);
75391+ wmin = va_arg(ap, int);
75392+ cmin = va_arg(ap, int);
75393+ wsec = va_arg(ap, int);
75394+ csec = va_arg(ap, int);
75395+ ulong1 = va_arg(ap, unsigned long);
75396+ cred = __task_cred(task);
75397+ pcred = __task_cred(task->real_parent);
75398+
75399+ 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));
75400+ }
75401+ break;
75402+ default:
75403+ gr_log_middle(audit, msg, ap);
75404+ }
75405+ va_end(ap);
75406+ // these don't need DEFAULTSECARGS printed on the end
75407+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
75408+ gr_log_end(audit, 0);
75409+ else
75410+ gr_log_end(audit, 1);
75411+ END_LOCKS(audit);
75412+}
75413diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
75414new file mode 100644
75415index 0000000..0e39d8c
75416--- /dev/null
75417+++ b/grsecurity/grsec_mem.c
75418@@ -0,0 +1,48 @@
75419+#include <linux/kernel.h>
75420+#include <linux/sched.h>
75421+#include <linux/mm.h>
75422+#include <linux/mman.h>
75423+#include <linux/module.h>
75424+#include <linux/grinternal.h>
75425+
75426+void gr_handle_msr_write(void)
75427+{
75428+ gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
75429+ return;
75430+}
75431+EXPORT_SYMBOL_GPL(gr_handle_msr_write);
75432+
75433+void
75434+gr_handle_ioperm(void)
75435+{
75436+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
75437+ return;
75438+}
75439+
75440+void
75441+gr_handle_iopl(void)
75442+{
75443+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
75444+ return;
75445+}
75446+
75447+void
75448+gr_handle_mem_readwrite(u64 from, u64 to)
75449+{
75450+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
75451+ return;
75452+}
75453+
75454+void
75455+gr_handle_vm86(void)
75456+{
75457+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
75458+ return;
75459+}
75460+
75461+void
75462+gr_log_badprocpid(const char *entry)
75463+{
75464+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
75465+ return;
75466+}
75467diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
75468new file mode 100644
75469index 0000000..cd9e124
75470--- /dev/null
75471+++ b/grsecurity/grsec_mount.c
75472@@ -0,0 +1,65 @@
75473+#include <linux/kernel.h>
75474+#include <linux/sched.h>
75475+#include <linux/mount.h>
75476+#include <linux/major.h>
75477+#include <linux/grsecurity.h>
75478+#include <linux/grinternal.h>
75479+
75480+void
75481+gr_log_remount(const char *devname, const int retval)
75482+{
75483+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75484+ if (grsec_enable_mount && (retval >= 0))
75485+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
75486+#endif
75487+ return;
75488+}
75489+
75490+void
75491+gr_log_unmount(const char *devname, const int retval)
75492+{
75493+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75494+ if (grsec_enable_mount && (retval >= 0))
75495+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
75496+#endif
75497+ return;
75498+}
75499+
75500+void
75501+gr_log_mount(const char *from, const char *to, const int retval)
75502+{
75503+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75504+ if (grsec_enable_mount && (retval >= 0))
75505+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
75506+#endif
75507+ return;
75508+}
75509+
75510+int
75511+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
75512+{
75513+#ifdef CONFIG_GRKERNSEC_ROFS
75514+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
75515+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
75516+ return -EPERM;
75517+ } else
75518+ return 0;
75519+#endif
75520+ return 0;
75521+}
75522+
75523+int
75524+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
75525+{
75526+#ifdef CONFIG_GRKERNSEC_ROFS
75527+ struct inode *inode = dentry->d_inode;
75528+
75529+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
75530+ inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
75531+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
75532+ return -EPERM;
75533+ } else
75534+ return 0;
75535+#endif
75536+ return 0;
75537+}
75538diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
75539new file mode 100644
75540index 0000000..6ee9d50
75541--- /dev/null
75542+++ b/grsecurity/grsec_pax.c
75543@@ -0,0 +1,45 @@
75544+#include <linux/kernel.h>
75545+#include <linux/sched.h>
75546+#include <linux/mm.h>
75547+#include <linux/file.h>
75548+#include <linux/grinternal.h>
75549+#include <linux/grsecurity.h>
75550+
75551+void
75552+gr_log_textrel(struct vm_area_struct * vma)
75553+{
75554+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75555+ if (grsec_enable_log_rwxmaps)
75556+ gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
75557+#endif
75558+ return;
75559+}
75560+
75561+void gr_log_ptgnustack(struct file *file)
75562+{
75563+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75564+ if (grsec_enable_log_rwxmaps)
75565+ gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
75566+#endif
75567+ return;
75568+}
75569+
75570+void
75571+gr_log_rwxmmap(struct file *file)
75572+{
75573+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75574+ if (grsec_enable_log_rwxmaps)
75575+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
75576+#endif
75577+ return;
75578+}
75579+
75580+void
75581+gr_log_rwxmprotect(struct vm_area_struct *vma)
75582+{
75583+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75584+ if (grsec_enable_log_rwxmaps)
75585+ gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
75586+#endif
75587+ return;
75588+}
75589diff --git a/grsecurity/grsec_proc.c b/grsecurity/grsec_proc.c
75590new file mode 100644
75591index 0000000..2005a3a
75592--- /dev/null
75593+++ b/grsecurity/grsec_proc.c
75594@@ -0,0 +1,20 @@
75595+#include <linux/kernel.h>
75596+#include <linux/sched.h>
75597+#include <linux/grsecurity.h>
75598+#include <linux/grinternal.h>
75599+
75600+int gr_proc_is_restricted(void)
75601+{
75602+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75603+ const struct cred *cred = current_cred();
75604+#endif
75605+
75606+#ifdef CONFIG_GRKERNSEC_PROC_USER
75607+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
75608+ return -EACCES;
75609+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75610+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
75611+ return -EACCES;
75612+#endif
75613+ return 0;
75614+}
75615diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
75616new file mode 100644
75617index 0000000..f7f29aa
75618--- /dev/null
75619+++ b/grsecurity/grsec_ptrace.c
75620@@ -0,0 +1,30 @@
75621+#include <linux/kernel.h>
75622+#include <linux/sched.h>
75623+#include <linux/grinternal.h>
75624+#include <linux/security.h>
75625+
75626+void
75627+gr_audit_ptrace(struct task_struct *task)
75628+{
75629+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
75630+ if (grsec_enable_audit_ptrace)
75631+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
75632+#endif
75633+ return;
75634+}
75635+
75636+int
75637+gr_ptrace_readexec(struct file *file, int unsafe_flags)
75638+{
75639+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
75640+ const struct dentry *dentry = file->f_path.dentry;
75641+ const struct vfsmount *mnt = file->f_path.mnt;
75642+
75643+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
75644+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
75645+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
75646+ return -EACCES;
75647+ }
75648+#endif
75649+ return 0;
75650+}
75651diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
75652new file mode 100644
75653index 0000000..3860c7e
75654--- /dev/null
75655+++ b/grsecurity/grsec_sig.c
75656@@ -0,0 +1,236 @@
75657+#include <linux/kernel.h>
75658+#include <linux/sched.h>
75659+#include <linux/fs.h>
75660+#include <linux/delay.h>
75661+#include <linux/grsecurity.h>
75662+#include <linux/grinternal.h>
75663+#include <linux/hardirq.h>
75664+
75665+char *signames[] = {
75666+ [SIGSEGV] = "Segmentation fault",
75667+ [SIGILL] = "Illegal instruction",
75668+ [SIGABRT] = "Abort",
75669+ [SIGBUS] = "Invalid alignment/Bus error"
75670+};
75671+
75672+void
75673+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
75674+{
75675+#ifdef CONFIG_GRKERNSEC_SIGNAL
75676+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
75677+ (sig == SIGABRT) || (sig == SIGBUS))) {
75678+ if (task_pid_nr(t) == task_pid_nr(current)) {
75679+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
75680+ } else {
75681+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
75682+ }
75683+ }
75684+#endif
75685+ return;
75686+}
75687+
75688+int
75689+gr_handle_signal(const struct task_struct *p, const int sig)
75690+{
75691+#ifdef CONFIG_GRKERNSEC
75692+ /* ignore the 0 signal for protected task checks */
75693+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
75694+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
75695+ return -EPERM;
75696+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
75697+ return -EPERM;
75698+ }
75699+#endif
75700+ return 0;
75701+}
75702+
75703+#ifdef CONFIG_GRKERNSEC
75704+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
75705+
75706+int gr_fake_force_sig(int sig, struct task_struct *t)
75707+{
75708+ unsigned long int flags;
75709+ int ret, blocked, ignored;
75710+ struct k_sigaction *action;
75711+
75712+ spin_lock_irqsave(&t->sighand->siglock, flags);
75713+ action = &t->sighand->action[sig-1];
75714+ ignored = action->sa.sa_handler == SIG_IGN;
75715+ blocked = sigismember(&t->blocked, sig);
75716+ if (blocked || ignored) {
75717+ action->sa.sa_handler = SIG_DFL;
75718+ if (blocked) {
75719+ sigdelset(&t->blocked, sig);
75720+ recalc_sigpending_and_wake(t);
75721+ }
75722+ }
75723+ if (action->sa.sa_handler == SIG_DFL)
75724+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
75725+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
75726+
75727+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
75728+
75729+ return ret;
75730+}
75731+#endif
75732+
75733+#define GR_USER_BAN_TIME (15 * 60)
75734+#define GR_DAEMON_BRUTE_TIME (30 * 60)
75735+
75736+void gr_handle_brute_attach(int dumpable)
75737+{
75738+#ifdef CONFIG_GRKERNSEC_BRUTE
75739+ struct task_struct *p = current;
75740+ kuid_t uid = GLOBAL_ROOT_UID;
75741+ int daemon = 0;
75742+
75743+ if (!grsec_enable_brute)
75744+ return;
75745+
75746+ rcu_read_lock();
75747+ read_lock(&tasklist_lock);
75748+ read_lock(&grsec_exec_file_lock);
75749+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
75750+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
75751+ p->real_parent->brute = 1;
75752+ daemon = 1;
75753+ } else {
75754+ const struct cred *cred = __task_cred(p), *cred2;
75755+ struct task_struct *tsk, *tsk2;
75756+
75757+ if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
75758+ struct user_struct *user;
75759+
75760+ uid = cred->uid;
75761+
75762+ /* this is put upon execution past expiration */
75763+ user = find_user(uid);
75764+ if (user == NULL)
75765+ goto unlock;
75766+ user->suid_banned = 1;
75767+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
75768+ if (user->suid_ban_expires == ~0UL)
75769+ user->suid_ban_expires--;
75770+
75771+ /* only kill other threads of the same binary, from the same user */
75772+ do_each_thread(tsk2, tsk) {
75773+ cred2 = __task_cred(tsk);
75774+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
75775+ gr_fake_force_sig(SIGKILL, tsk);
75776+ } while_each_thread(tsk2, tsk);
75777+ }
75778+ }
75779+unlock:
75780+ read_unlock(&grsec_exec_file_lock);
75781+ read_unlock(&tasklist_lock);
75782+ rcu_read_unlock();
75783+
75784+ if (gr_is_global_nonroot(uid))
75785+ 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);
75786+ else if (daemon)
75787+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
75788+
75789+#endif
75790+ return;
75791+}
75792+
75793+void gr_handle_brute_check(void)
75794+{
75795+#ifdef CONFIG_GRKERNSEC_BRUTE
75796+ struct task_struct *p = current;
75797+
75798+ if (unlikely(p->brute)) {
75799+ if (!grsec_enable_brute)
75800+ p->brute = 0;
75801+ else if (time_before(get_seconds(), p->brute_expires))
75802+ msleep(30 * 1000);
75803+ }
75804+#endif
75805+ return;
75806+}
75807+
75808+void gr_handle_kernel_exploit(void)
75809+{
75810+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75811+ const struct cred *cred;
75812+ struct task_struct *tsk, *tsk2;
75813+ struct user_struct *user;
75814+ kuid_t uid;
75815+
75816+ if (in_irq() || in_serving_softirq() || in_nmi())
75817+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
75818+
75819+ uid = current_uid();
75820+
75821+ if (gr_is_global_root(uid))
75822+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
75823+ else {
75824+ /* kill all the processes of this user, hold a reference
75825+ to their creds struct, and prevent them from creating
75826+ another process until system reset
75827+ */
75828+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
75829+ GR_GLOBAL_UID(uid));
75830+ /* we intentionally leak this ref */
75831+ user = get_uid(current->cred->user);
75832+ if (user)
75833+ user->kernel_banned = 1;
75834+
75835+ /* kill all processes of this user */
75836+ read_lock(&tasklist_lock);
75837+ do_each_thread(tsk2, tsk) {
75838+ cred = __task_cred(tsk);
75839+ if (uid_eq(cred->uid, uid))
75840+ gr_fake_force_sig(SIGKILL, tsk);
75841+ } while_each_thread(tsk2, tsk);
75842+ read_unlock(&tasklist_lock);
75843+ }
75844+#endif
75845+}
75846+
75847+#ifdef CONFIG_GRKERNSEC_BRUTE
75848+static bool suid_ban_expired(struct user_struct *user)
75849+{
75850+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
75851+ user->suid_banned = 0;
75852+ user->suid_ban_expires = 0;
75853+ free_uid(user);
75854+ return true;
75855+ }
75856+
75857+ return false;
75858+}
75859+#endif
75860+
75861+int gr_process_kernel_exec_ban(void)
75862+{
75863+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75864+ if (unlikely(current->cred->user->kernel_banned))
75865+ return -EPERM;
75866+#endif
75867+ return 0;
75868+}
75869+
75870+int gr_process_kernel_setuid_ban(struct user_struct *user)
75871+{
75872+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75873+ if (unlikely(user->kernel_banned))
75874+ gr_fake_force_sig(SIGKILL, current);
75875+#endif
75876+ return 0;
75877+}
75878+
75879+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
75880+{
75881+#ifdef CONFIG_GRKERNSEC_BRUTE
75882+ struct user_struct *user = current->cred->user;
75883+ if (unlikely(user->suid_banned)) {
75884+ if (suid_ban_expired(user))
75885+ return 0;
75886+ /* disallow execution of suid binaries only */
75887+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
75888+ return -EPERM;
75889+ }
75890+#endif
75891+ return 0;
75892+}
75893diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
75894new file mode 100644
75895index 0000000..c0aef3a
75896--- /dev/null
75897+++ b/grsecurity/grsec_sock.c
75898@@ -0,0 +1,244 @@
75899+#include <linux/kernel.h>
75900+#include <linux/module.h>
75901+#include <linux/sched.h>
75902+#include <linux/file.h>
75903+#include <linux/net.h>
75904+#include <linux/in.h>
75905+#include <linux/ip.h>
75906+#include <net/sock.h>
75907+#include <net/inet_sock.h>
75908+#include <linux/grsecurity.h>
75909+#include <linux/grinternal.h>
75910+#include <linux/gracl.h>
75911+
75912+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
75913+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
75914+
75915+EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
75916+EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
75917+
75918+#ifdef CONFIG_UNIX_MODULE
75919+EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
75920+EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
75921+EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
75922+EXPORT_SYMBOL_GPL(gr_handle_create);
75923+#endif
75924+
75925+#ifdef CONFIG_GRKERNSEC
75926+#define gr_conn_table_size 32749
75927+struct conn_table_entry {
75928+ struct conn_table_entry *next;
75929+ struct signal_struct *sig;
75930+};
75931+
75932+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
75933+DEFINE_SPINLOCK(gr_conn_table_lock);
75934+
75935+extern const char * gr_socktype_to_name(unsigned char type);
75936+extern const char * gr_proto_to_name(unsigned char proto);
75937+extern const char * gr_sockfamily_to_name(unsigned char family);
75938+
75939+static __inline__ int
75940+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
75941+{
75942+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
75943+}
75944+
75945+static __inline__ int
75946+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
75947+ __u16 sport, __u16 dport)
75948+{
75949+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
75950+ sig->gr_sport == sport && sig->gr_dport == dport))
75951+ return 1;
75952+ else
75953+ return 0;
75954+}
75955+
75956+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
75957+{
75958+ struct conn_table_entry **match;
75959+ unsigned int index;
75960+
75961+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
75962+ sig->gr_sport, sig->gr_dport,
75963+ gr_conn_table_size);
75964+
75965+ newent->sig = sig;
75966+
75967+ match = &gr_conn_table[index];
75968+ newent->next = *match;
75969+ *match = newent;
75970+
75971+ return;
75972+}
75973+
75974+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
75975+{
75976+ struct conn_table_entry *match, *last = NULL;
75977+ unsigned int index;
75978+
75979+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
75980+ sig->gr_sport, sig->gr_dport,
75981+ gr_conn_table_size);
75982+
75983+ match = gr_conn_table[index];
75984+ while (match && !conn_match(match->sig,
75985+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
75986+ sig->gr_dport)) {
75987+ last = match;
75988+ match = match->next;
75989+ }
75990+
75991+ if (match) {
75992+ if (last)
75993+ last->next = match->next;
75994+ else
75995+ gr_conn_table[index] = NULL;
75996+ kfree(match);
75997+ }
75998+
75999+ return;
76000+}
76001+
76002+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
76003+ __u16 sport, __u16 dport)
76004+{
76005+ struct conn_table_entry *match;
76006+ unsigned int index;
76007+
76008+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
76009+
76010+ match = gr_conn_table[index];
76011+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
76012+ match = match->next;
76013+
76014+ if (match)
76015+ return match->sig;
76016+ else
76017+ return NULL;
76018+}
76019+
76020+#endif
76021+
76022+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
76023+{
76024+#ifdef CONFIG_GRKERNSEC
76025+ struct signal_struct *sig = task->signal;
76026+ struct conn_table_entry *newent;
76027+
76028+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
76029+ if (newent == NULL)
76030+ return;
76031+ /* no bh lock needed since we are called with bh disabled */
76032+ spin_lock(&gr_conn_table_lock);
76033+ gr_del_task_from_ip_table_nolock(sig);
76034+ sig->gr_saddr = inet->inet_rcv_saddr;
76035+ sig->gr_daddr = inet->inet_daddr;
76036+ sig->gr_sport = inet->inet_sport;
76037+ sig->gr_dport = inet->inet_dport;
76038+ gr_add_to_task_ip_table_nolock(sig, newent);
76039+ spin_unlock(&gr_conn_table_lock);
76040+#endif
76041+ return;
76042+}
76043+
76044+void gr_del_task_from_ip_table(struct task_struct *task)
76045+{
76046+#ifdef CONFIG_GRKERNSEC
76047+ spin_lock_bh(&gr_conn_table_lock);
76048+ gr_del_task_from_ip_table_nolock(task->signal);
76049+ spin_unlock_bh(&gr_conn_table_lock);
76050+#endif
76051+ return;
76052+}
76053+
76054+void
76055+gr_attach_curr_ip(const struct sock *sk)
76056+{
76057+#ifdef CONFIG_GRKERNSEC
76058+ struct signal_struct *p, *set;
76059+ const struct inet_sock *inet = inet_sk(sk);
76060+
76061+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
76062+ return;
76063+
76064+ set = current->signal;
76065+
76066+ spin_lock_bh(&gr_conn_table_lock);
76067+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
76068+ inet->inet_dport, inet->inet_sport);
76069+ if (unlikely(p != NULL)) {
76070+ set->curr_ip = p->curr_ip;
76071+ set->used_accept = 1;
76072+ gr_del_task_from_ip_table_nolock(p);
76073+ spin_unlock_bh(&gr_conn_table_lock);
76074+ return;
76075+ }
76076+ spin_unlock_bh(&gr_conn_table_lock);
76077+
76078+ set->curr_ip = inet->inet_daddr;
76079+ set->used_accept = 1;
76080+#endif
76081+ return;
76082+}
76083+
76084+int
76085+gr_handle_sock_all(const int family, const int type, const int protocol)
76086+{
76087+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
76088+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
76089+ (family != AF_UNIX)) {
76090+ if (family == AF_INET)
76091+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
76092+ else
76093+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
76094+ return -EACCES;
76095+ }
76096+#endif
76097+ return 0;
76098+}
76099+
76100+int
76101+gr_handle_sock_server(const struct sockaddr *sck)
76102+{
76103+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
76104+ if (grsec_enable_socket_server &&
76105+ in_group_p(grsec_socket_server_gid) &&
76106+ sck && (sck->sa_family != AF_UNIX) &&
76107+ (sck->sa_family != AF_LOCAL)) {
76108+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
76109+ return -EACCES;
76110+ }
76111+#endif
76112+ return 0;
76113+}
76114+
76115+int
76116+gr_handle_sock_server_other(const struct sock *sck)
76117+{
76118+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
76119+ if (grsec_enable_socket_server &&
76120+ in_group_p(grsec_socket_server_gid) &&
76121+ sck && (sck->sk_family != AF_UNIX) &&
76122+ (sck->sk_family != AF_LOCAL)) {
76123+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
76124+ return -EACCES;
76125+ }
76126+#endif
76127+ return 0;
76128+}
76129+
76130+int
76131+gr_handle_sock_client(const struct sockaddr *sck)
76132+{
76133+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
76134+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
76135+ sck && (sck->sa_family != AF_UNIX) &&
76136+ (sck->sa_family != AF_LOCAL)) {
76137+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
76138+ return -EACCES;
76139+ }
76140+#endif
76141+ return 0;
76142+}
76143diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
76144new file mode 100644
76145index 0000000..8159888
76146--- /dev/null
76147+++ b/grsecurity/grsec_sysctl.c
76148@@ -0,0 +1,479 @@
76149+#include <linux/kernel.h>
76150+#include <linux/sched.h>
76151+#include <linux/sysctl.h>
76152+#include <linux/grsecurity.h>
76153+#include <linux/grinternal.h>
76154+
76155+int
76156+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
76157+{
76158+#ifdef CONFIG_GRKERNSEC_SYSCTL
76159+ if (dirname == NULL || name == NULL)
76160+ return 0;
76161+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
76162+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
76163+ return -EACCES;
76164+ }
76165+#endif
76166+ return 0;
76167+}
76168+
76169+#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
76170+static int __maybe_unused __read_only one = 1;
76171+#endif
76172+
76173+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
76174+ defined(CONFIG_GRKERNSEC_DENYUSB)
76175+struct ctl_table grsecurity_table[] = {
76176+#ifdef CONFIG_GRKERNSEC_SYSCTL
76177+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
76178+#ifdef CONFIG_GRKERNSEC_IO
76179+ {
76180+ .procname = "disable_priv_io",
76181+ .data = &grsec_disable_privio,
76182+ .maxlen = sizeof(int),
76183+ .mode = 0600,
76184+ .proc_handler = &proc_dointvec,
76185+ },
76186+#endif
76187+#endif
76188+#ifdef CONFIG_GRKERNSEC_LINK
76189+ {
76190+ .procname = "linking_restrictions",
76191+ .data = &grsec_enable_link,
76192+ .maxlen = sizeof(int),
76193+ .mode = 0600,
76194+ .proc_handler = &proc_dointvec,
76195+ },
76196+#endif
76197+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
76198+ {
76199+ .procname = "enforce_symlinksifowner",
76200+ .data = &grsec_enable_symlinkown,
76201+ .maxlen = sizeof(int),
76202+ .mode = 0600,
76203+ .proc_handler = &proc_dointvec,
76204+ },
76205+ {
76206+ .procname = "symlinkown_gid",
76207+ .data = &grsec_symlinkown_gid,
76208+ .maxlen = sizeof(int),
76209+ .mode = 0600,
76210+ .proc_handler = &proc_dointvec,
76211+ },
76212+#endif
76213+#ifdef CONFIG_GRKERNSEC_BRUTE
76214+ {
76215+ .procname = "deter_bruteforce",
76216+ .data = &grsec_enable_brute,
76217+ .maxlen = sizeof(int),
76218+ .mode = 0600,
76219+ .proc_handler = &proc_dointvec,
76220+ },
76221+#endif
76222+#ifdef CONFIG_GRKERNSEC_FIFO
76223+ {
76224+ .procname = "fifo_restrictions",
76225+ .data = &grsec_enable_fifo,
76226+ .maxlen = sizeof(int),
76227+ .mode = 0600,
76228+ .proc_handler = &proc_dointvec,
76229+ },
76230+#endif
76231+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
76232+ {
76233+ .procname = "ptrace_readexec",
76234+ .data = &grsec_enable_ptrace_readexec,
76235+ .maxlen = sizeof(int),
76236+ .mode = 0600,
76237+ .proc_handler = &proc_dointvec,
76238+ },
76239+#endif
76240+#ifdef CONFIG_GRKERNSEC_SETXID
76241+ {
76242+ .procname = "consistent_setxid",
76243+ .data = &grsec_enable_setxid,
76244+ .maxlen = sizeof(int),
76245+ .mode = 0600,
76246+ .proc_handler = &proc_dointvec,
76247+ },
76248+#endif
76249+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76250+ {
76251+ .procname = "ip_blackhole",
76252+ .data = &grsec_enable_blackhole,
76253+ .maxlen = sizeof(int),
76254+ .mode = 0600,
76255+ .proc_handler = &proc_dointvec,
76256+ },
76257+ {
76258+ .procname = "lastack_retries",
76259+ .data = &grsec_lastack_retries,
76260+ .maxlen = sizeof(int),
76261+ .mode = 0600,
76262+ .proc_handler = &proc_dointvec,
76263+ },
76264+#endif
76265+#ifdef CONFIG_GRKERNSEC_EXECLOG
76266+ {
76267+ .procname = "exec_logging",
76268+ .data = &grsec_enable_execlog,
76269+ .maxlen = sizeof(int),
76270+ .mode = 0600,
76271+ .proc_handler = &proc_dointvec,
76272+ },
76273+#endif
76274+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
76275+ {
76276+ .procname = "rwxmap_logging",
76277+ .data = &grsec_enable_log_rwxmaps,
76278+ .maxlen = sizeof(int),
76279+ .mode = 0600,
76280+ .proc_handler = &proc_dointvec,
76281+ },
76282+#endif
76283+#ifdef CONFIG_GRKERNSEC_SIGNAL
76284+ {
76285+ .procname = "signal_logging",
76286+ .data = &grsec_enable_signal,
76287+ .maxlen = sizeof(int),
76288+ .mode = 0600,
76289+ .proc_handler = &proc_dointvec,
76290+ },
76291+#endif
76292+#ifdef CONFIG_GRKERNSEC_FORKFAIL
76293+ {
76294+ .procname = "forkfail_logging",
76295+ .data = &grsec_enable_forkfail,
76296+ .maxlen = sizeof(int),
76297+ .mode = 0600,
76298+ .proc_handler = &proc_dointvec,
76299+ },
76300+#endif
76301+#ifdef CONFIG_GRKERNSEC_TIME
76302+ {
76303+ .procname = "timechange_logging",
76304+ .data = &grsec_enable_time,
76305+ .maxlen = sizeof(int),
76306+ .mode = 0600,
76307+ .proc_handler = &proc_dointvec,
76308+ },
76309+#endif
76310+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
76311+ {
76312+ .procname = "chroot_deny_shmat",
76313+ .data = &grsec_enable_chroot_shmat,
76314+ .maxlen = sizeof(int),
76315+ .mode = 0600,
76316+ .proc_handler = &proc_dointvec,
76317+ },
76318+#endif
76319+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
76320+ {
76321+ .procname = "chroot_deny_unix",
76322+ .data = &grsec_enable_chroot_unix,
76323+ .maxlen = sizeof(int),
76324+ .mode = 0600,
76325+ .proc_handler = &proc_dointvec,
76326+ },
76327+#endif
76328+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
76329+ {
76330+ .procname = "chroot_deny_mount",
76331+ .data = &grsec_enable_chroot_mount,
76332+ .maxlen = sizeof(int),
76333+ .mode = 0600,
76334+ .proc_handler = &proc_dointvec,
76335+ },
76336+#endif
76337+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
76338+ {
76339+ .procname = "chroot_deny_fchdir",
76340+ .data = &grsec_enable_chroot_fchdir,
76341+ .maxlen = sizeof(int),
76342+ .mode = 0600,
76343+ .proc_handler = &proc_dointvec,
76344+ },
76345+#endif
76346+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
76347+ {
76348+ .procname = "chroot_deny_chroot",
76349+ .data = &grsec_enable_chroot_double,
76350+ .maxlen = sizeof(int),
76351+ .mode = 0600,
76352+ .proc_handler = &proc_dointvec,
76353+ },
76354+#endif
76355+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
76356+ {
76357+ .procname = "chroot_deny_pivot",
76358+ .data = &grsec_enable_chroot_pivot,
76359+ .maxlen = sizeof(int),
76360+ .mode = 0600,
76361+ .proc_handler = &proc_dointvec,
76362+ },
76363+#endif
76364+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
76365+ {
76366+ .procname = "chroot_enforce_chdir",
76367+ .data = &grsec_enable_chroot_chdir,
76368+ .maxlen = sizeof(int),
76369+ .mode = 0600,
76370+ .proc_handler = &proc_dointvec,
76371+ },
76372+#endif
76373+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
76374+ {
76375+ .procname = "chroot_deny_chmod",
76376+ .data = &grsec_enable_chroot_chmod,
76377+ .maxlen = sizeof(int),
76378+ .mode = 0600,
76379+ .proc_handler = &proc_dointvec,
76380+ },
76381+#endif
76382+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
76383+ {
76384+ .procname = "chroot_deny_mknod",
76385+ .data = &grsec_enable_chroot_mknod,
76386+ .maxlen = sizeof(int),
76387+ .mode = 0600,
76388+ .proc_handler = &proc_dointvec,
76389+ },
76390+#endif
76391+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
76392+ {
76393+ .procname = "chroot_restrict_nice",
76394+ .data = &grsec_enable_chroot_nice,
76395+ .maxlen = sizeof(int),
76396+ .mode = 0600,
76397+ .proc_handler = &proc_dointvec,
76398+ },
76399+#endif
76400+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
76401+ {
76402+ .procname = "chroot_execlog",
76403+ .data = &grsec_enable_chroot_execlog,
76404+ .maxlen = sizeof(int),
76405+ .mode = 0600,
76406+ .proc_handler = &proc_dointvec,
76407+ },
76408+#endif
76409+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76410+ {
76411+ .procname = "chroot_caps",
76412+ .data = &grsec_enable_chroot_caps,
76413+ .maxlen = sizeof(int),
76414+ .mode = 0600,
76415+ .proc_handler = &proc_dointvec,
76416+ },
76417+#endif
76418+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
76419+ {
76420+ .procname = "chroot_deny_sysctl",
76421+ .data = &grsec_enable_chroot_sysctl,
76422+ .maxlen = sizeof(int),
76423+ .mode = 0600,
76424+ .proc_handler = &proc_dointvec,
76425+ },
76426+#endif
76427+#ifdef CONFIG_GRKERNSEC_TPE
76428+ {
76429+ .procname = "tpe",
76430+ .data = &grsec_enable_tpe,
76431+ .maxlen = sizeof(int),
76432+ .mode = 0600,
76433+ .proc_handler = &proc_dointvec,
76434+ },
76435+ {
76436+ .procname = "tpe_gid",
76437+ .data = &grsec_tpe_gid,
76438+ .maxlen = sizeof(int),
76439+ .mode = 0600,
76440+ .proc_handler = &proc_dointvec,
76441+ },
76442+#endif
76443+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
76444+ {
76445+ .procname = "tpe_invert",
76446+ .data = &grsec_enable_tpe_invert,
76447+ .maxlen = sizeof(int),
76448+ .mode = 0600,
76449+ .proc_handler = &proc_dointvec,
76450+ },
76451+#endif
76452+#ifdef CONFIG_GRKERNSEC_TPE_ALL
76453+ {
76454+ .procname = "tpe_restrict_all",
76455+ .data = &grsec_enable_tpe_all,
76456+ .maxlen = sizeof(int),
76457+ .mode = 0600,
76458+ .proc_handler = &proc_dointvec,
76459+ },
76460+#endif
76461+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
76462+ {
76463+ .procname = "socket_all",
76464+ .data = &grsec_enable_socket_all,
76465+ .maxlen = sizeof(int),
76466+ .mode = 0600,
76467+ .proc_handler = &proc_dointvec,
76468+ },
76469+ {
76470+ .procname = "socket_all_gid",
76471+ .data = &grsec_socket_all_gid,
76472+ .maxlen = sizeof(int),
76473+ .mode = 0600,
76474+ .proc_handler = &proc_dointvec,
76475+ },
76476+#endif
76477+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
76478+ {
76479+ .procname = "socket_client",
76480+ .data = &grsec_enable_socket_client,
76481+ .maxlen = sizeof(int),
76482+ .mode = 0600,
76483+ .proc_handler = &proc_dointvec,
76484+ },
76485+ {
76486+ .procname = "socket_client_gid",
76487+ .data = &grsec_socket_client_gid,
76488+ .maxlen = sizeof(int),
76489+ .mode = 0600,
76490+ .proc_handler = &proc_dointvec,
76491+ },
76492+#endif
76493+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
76494+ {
76495+ .procname = "socket_server",
76496+ .data = &grsec_enable_socket_server,
76497+ .maxlen = sizeof(int),
76498+ .mode = 0600,
76499+ .proc_handler = &proc_dointvec,
76500+ },
76501+ {
76502+ .procname = "socket_server_gid",
76503+ .data = &grsec_socket_server_gid,
76504+ .maxlen = sizeof(int),
76505+ .mode = 0600,
76506+ .proc_handler = &proc_dointvec,
76507+ },
76508+#endif
76509+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
76510+ {
76511+ .procname = "audit_group",
76512+ .data = &grsec_enable_group,
76513+ .maxlen = sizeof(int),
76514+ .mode = 0600,
76515+ .proc_handler = &proc_dointvec,
76516+ },
76517+ {
76518+ .procname = "audit_gid",
76519+ .data = &grsec_audit_gid,
76520+ .maxlen = sizeof(int),
76521+ .mode = 0600,
76522+ .proc_handler = &proc_dointvec,
76523+ },
76524+#endif
76525+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
76526+ {
76527+ .procname = "audit_chdir",
76528+ .data = &grsec_enable_chdir,
76529+ .maxlen = sizeof(int),
76530+ .mode = 0600,
76531+ .proc_handler = &proc_dointvec,
76532+ },
76533+#endif
76534+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
76535+ {
76536+ .procname = "audit_mount",
76537+ .data = &grsec_enable_mount,
76538+ .maxlen = sizeof(int),
76539+ .mode = 0600,
76540+ .proc_handler = &proc_dointvec,
76541+ },
76542+#endif
76543+#ifdef CONFIG_GRKERNSEC_DMESG
76544+ {
76545+ .procname = "dmesg",
76546+ .data = &grsec_enable_dmesg,
76547+ .maxlen = sizeof(int),
76548+ .mode = 0600,
76549+ .proc_handler = &proc_dointvec,
76550+ },
76551+#endif
76552+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76553+ {
76554+ .procname = "chroot_findtask",
76555+ .data = &grsec_enable_chroot_findtask,
76556+ .maxlen = sizeof(int),
76557+ .mode = 0600,
76558+ .proc_handler = &proc_dointvec,
76559+ },
76560+#endif
76561+#ifdef CONFIG_GRKERNSEC_RESLOG
76562+ {
76563+ .procname = "resource_logging",
76564+ .data = &grsec_resource_logging,
76565+ .maxlen = sizeof(int),
76566+ .mode = 0600,
76567+ .proc_handler = &proc_dointvec,
76568+ },
76569+#endif
76570+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
76571+ {
76572+ .procname = "audit_ptrace",
76573+ .data = &grsec_enable_audit_ptrace,
76574+ .maxlen = sizeof(int),
76575+ .mode = 0600,
76576+ .proc_handler = &proc_dointvec,
76577+ },
76578+#endif
76579+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
76580+ {
76581+ .procname = "harden_ptrace",
76582+ .data = &grsec_enable_harden_ptrace,
76583+ .maxlen = sizeof(int),
76584+ .mode = 0600,
76585+ .proc_handler = &proc_dointvec,
76586+ },
76587+#endif
76588+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
76589+ {
76590+ .procname = "harden_ipc",
76591+ .data = &grsec_enable_harden_ipc,
76592+ .maxlen = sizeof(int),
76593+ .mode = 0600,
76594+ .proc_handler = &proc_dointvec,
76595+ },
76596+#endif
76597+ {
76598+ .procname = "grsec_lock",
76599+ .data = &grsec_lock,
76600+ .maxlen = sizeof(int),
76601+ .mode = 0600,
76602+ .proc_handler = &proc_dointvec,
76603+ },
76604+#endif
76605+#ifdef CONFIG_GRKERNSEC_ROFS
76606+ {
76607+ .procname = "romount_protect",
76608+ .data = &grsec_enable_rofs,
76609+ .maxlen = sizeof(int),
76610+ .mode = 0600,
76611+ .proc_handler = &proc_dointvec_minmax,
76612+ .extra1 = &one,
76613+ .extra2 = &one,
76614+ },
76615+#endif
76616+#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
76617+ {
76618+ .procname = "deny_new_usb",
76619+ .data = &grsec_deny_new_usb,
76620+ .maxlen = sizeof(int),
76621+ .mode = 0600,
76622+ .proc_handler = &proc_dointvec,
76623+ },
76624+#endif
76625+ { }
76626+};
76627+#endif
76628diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
76629new file mode 100644
76630index 0000000..61b514e
76631--- /dev/null
76632+++ b/grsecurity/grsec_time.c
76633@@ -0,0 +1,16 @@
76634+#include <linux/kernel.h>
76635+#include <linux/sched.h>
76636+#include <linux/grinternal.h>
76637+#include <linux/module.h>
76638+
76639+void
76640+gr_log_timechange(void)
76641+{
76642+#ifdef CONFIG_GRKERNSEC_TIME
76643+ if (grsec_enable_time)
76644+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
76645+#endif
76646+ return;
76647+}
76648+
76649+EXPORT_SYMBOL_GPL(gr_log_timechange);
76650diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
76651new file mode 100644
76652index 0000000..ee57dcf
76653--- /dev/null
76654+++ b/grsecurity/grsec_tpe.c
76655@@ -0,0 +1,73 @@
76656+#include <linux/kernel.h>
76657+#include <linux/sched.h>
76658+#include <linux/file.h>
76659+#include <linux/fs.h>
76660+#include <linux/grinternal.h>
76661+
76662+extern int gr_acl_tpe_check(void);
76663+
76664+int
76665+gr_tpe_allow(const struct file *file)
76666+{
76667+#ifdef CONFIG_GRKERNSEC
76668+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
76669+ const struct cred *cred = current_cred();
76670+ char *msg = NULL;
76671+ char *msg2 = NULL;
76672+
76673+ // never restrict root
76674+ if (gr_is_global_root(cred->uid))
76675+ return 1;
76676+
76677+ if (grsec_enable_tpe) {
76678+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
76679+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
76680+ msg = "not being in trusted group";
76681+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
76682+ msg = "being in untrusted group";
76683+#else
76684+ if (in_group_p(grsec_tpe_gid))
76685+ msg = "being in untrusted group";
76686+#endif
76687+ }
76688+ if (!msg && gr_acl_tpe_check())
76689+ msg = "being in untrusted role";
76690+
76691+ // not in any affected group/role
76692+ if (!msg)
76693+ goto next_check;
76694+
76695+ if (gr_is_global_nonroot(inode->i_uid))
76696+ msg2 = "file in non-root-owned directory";
76697+ else if (inode->i_mode & S_IWOTH)
76698+ msg2 = "file in world-writable directory";
76699+ else if (inode->i_mode & S_IWGRP)
76700+ msg2 = "file in group-writable directory";
76701+
76702+ if (msg && msg2) {
76703+ char fullmsg[70] = {0};
76704+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
76705+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
76706+ return 0;
76707+ }
76708+ msg = NULL;
76709+next_check:
76710+#ifdef CONFIG_GRKERNSEC_TPE_ALL
76711+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
76712+ return 1;
76713+
76714+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
76715+ msg = "directory not owned by user";
76716+ else if (inode->i_mode & S_IWOTH)
76717+ msg = "file in world-writable directory";
76718+ else if (inode->i_mode & S_IWGRP)
76719+ msg = "file in group-writable directory";
76720+
76721+ if (msg) {
76722+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
76723+ return 0;
76724+ }
76725+#endif
76726+#endif
76727+ return 1;
76728+}
76729diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
76730new file mode 100644
76731index 0000000..ae02d8e
76732--- /dev/null
76733+++ b/grsecurity/grsec_usb.c
76734@@ -0,0 +1,15 @@
76735+#include <linux/kernel.h>
76736+#include <linux/grinternal.h>
76737+#include <linux/module.h>
76738+
76739+int gr_handle_new_usb(void)
76740+{
76741+#ifdef CONFIG_GRKERNSEC_DENYUSB
76742+ if (grsec_deny_new_usb) {
76743+ printk(KERN_ALERT "grsec: denied insert of new USB device\n");
76744+ return 1;
76745+ }
76746+#endif
76747+ return 0;
76748+}
76749+EXPORT_SYMBOL_GPL(gr_handle_new_usb);
76750diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
76751new file mode 100644
76752index 0000000..9f7b1ac
76753--- /dev/null
76754+++ b/grsecurity/grsum.c
76755@@ -0,0 +1,61 @@
76756+#include <linux/err.h>
76757+#include <linux/kernel.h>
76758+#include <linux/sched.h>
76759+#include <linux/mm.h>
76760+#include <linux/scatterlist.h>
76761+#include <linux/crypto.h>
76762+#include <linux/gracl.h>
76763+
76764+
76765+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
76766+#error "crypto and sha256 must be built into the kernel"
76767+#endif
76768+
76769+int
76770+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
76771+{
76772+ char *p;
76773+ struct crypto_hash *tfm;
76774+ struct hash_desc desc;
76775+ struct scatterlist sg;
76776+ unsigned char temp_sum[GR_SHA_LEN];
76777+ volatile int retval = 0;
76778+ volatile int dummy = 0;
76779+ unsigned int i;
76780+
76781+ sg_init_table(&sg, 1);
76782+
76783+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
76784+ if (IS_ERR(tfm)) {
76785+ /* should never happen, since sha256 should be built in */
76786+ return 1;
76787+ }
76788+
76789+ desc.tfm = tfm;
76790+ desc.flags = 0;
76791+
76792+ crypto_hash_init(&desc);
76793+
76794+ p = salt;
76795+ sg_set_buf(&sg, p, GR_SALT_LEN);
76796+ crypto_hash_update(&desc, &sg, sg.length);
76797+
76798+ p = entry->pw;
76799+ sg_set_buf(&sg, p, strlen(p));
76800+
76801+ crypto_hash_update(&desc, &sg, sg.length);
76802+
76803+ crypto_hash_final(&desc, temp_sum);
76804+
76805+ memset(entry->pw, 0, GR_PW_LEN);
76806+
76807+ for (i = 0; i < GR_SHA_LEN; i++)
76808+ if (sum[i] != temp_sum[i])
76809+ retval = 1;
76810+ else
76811+ dummy = 1; // waste a cycle
76812+
76813+ crypto_free_hash(tfm);
76814+
76815+ return retval;
76816+}
76817diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
76818index 77ff547..181834f 100644
76819--- a/include/asm-generic/4level-fixup.h
76820+++ b/include/asm-generic/4level-fixup.h
76821@@ -13,8 +13,10 @@
76822 #define pmd_alloc(mm, pud, address) \
76823 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
76824 NULL: pmd_offset(pud, address))
76825+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
76826
76827 #define pud_alloc(mm, pgd, address) (pgd)
76828+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
76829 #define pud_offset(pgd, start) (pgd)
76830 #define pud_none(pud) 0
76831 #define pud_bad(pud) 0
76832diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
76833index b7babf0..97f4c4f 100644
76834--- a/include/asm-generic/atomic-long.h
76835+++ b/include/asm-generic/atomic-long.h
76836@@ -22,6 +22,12 @@
76837
76838 typedef atomic64_t atomic_long_t;
76839
76840+#ifdef CONFIG_PAX_REFCOUNT
76841+typedef atomic64_unchecked_t atomic_long_unchecked_t;
76842+#else
76843+typedef atomic64_t atomic_long_unchecked_t;
76844+#endif
76845+
76846 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
76847
76848 static inline long atomic_long_read(atomic_long_t *l)
76849@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
76850 return (long)atomic64_read(v);
76851 }
76852
76853+#ifdef CONFIG_PAX_REFCOUNT
76854+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
76855+{
76856+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76857+
76858+ return (long)atomic64_read_unchecked(v);
76859+}
76860+#endif
76861+
76862 static inline void atomic_long_set(atomic_long_t *l, long i)
76863 {
76864 atomic64_t *v = (atomic64_t *)l;
76865@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
76866 atomic64_set(v, i);
76867 }
76868
76869+#ifdef CONFIG_PAX_REFCOUNT
76870+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
76871+{
76872+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76873+
76874+ atomic64_set_unchecked(v, i);
76875+}
76876+#endif
76877+
76878 static inline void atomic_long_inc(atomic_long_t *l)
76879 {
76880 atomic64_t *v = (atomic64_t *)l;
76881@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
76882 atomic64_inc(v);
76883 }
76884
76885+#ifdef CONFIG_PAX_REFCOUNT
76886+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
76887+{
76888+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76889+
76890+ atomic64_inc_unchecked(v);
76891+}
76892+#endif
76893+
76894 static inline void atomic_long_dec(atomic_long_t *l)
76895 {
76896 atomic64_t *v = (atomic64_t *)l;
76897@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
76898 atomic64_dec(v);
76899 }
76900
76901+#ifdef CONFIG_PAX_REFCOUNT
76902+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
76903+{
76904+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76905+
76906+ atomic64_dec_unchecked(v);
76907+}
76908+#endif
76909+
76910 static inline void atomic_long_add(long i, atomic_long_t *l)
76911 {
76912 atomic64_t *v = (atomic64_t *)l;
76913@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
76914 atomic64_add(i, v);
76915 }
76916
76917+#ifdef CONFIG_PAX_REFCOUNT
76918+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
76919+{
76920+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76921+
76922+ atomic64_add_unchecked(i, v);
76923+}
76924+#endif
76925+
76926 static inline void atomic_long_sub(long i, atomic_long_t *l)
76927 {
76928 atomic64_t *v = (atomic64_t *)l;
76929@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
76930 atomic64_sub(i, v);
76931 }
76932
76933+#ifdef CONFIG_PAX_REFCOUNT
76934+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
76935+{
76936+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76937+
76938+ atomic64_sub_unchecked(i, v);
76939+}
76940+#endif
76941+
76942 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
76943 {
76944 atomic64_t *v = (atomic64_t *)l;
76945@@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
76946 return atomic64_add_negative(i, v);
76947 }
76948
76949-static inline long atomic_long_add_return(long i, atomic_long_t *l)
76950+static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
76951 {
76952 atomic64_t *v = (atomic64_t *)l;
76953
76954 return (long)atomic64_add_return(i, v);
76955 }
76956
76957+#ifdef CONFIG_PAX_REFCOUNT
76958+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
76959+{
76960+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76961+
76962+ return (long)atomic64_add_return_unchecked(i, v);
76963+}
76964+#endif
76965+
76966 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
76967 {
76968 atomic64_t *v = (atomic64_t *)l;
76969@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
76970 return (long)atomic64_inc_return(v);
76971 }
76972
76973+#ifdef CONFIG_PAX_REFCOUNT
76974+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
76975+{
76976+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76977+
76978+ return (long)atomic64_inc_return_unchecked(v);
76979+}
76980+#endif
76981+
76982 static inline long atomic_long_dec_return(atomic_long_t *l)
76983 {
76984 atomic64_t *v = (atomic64_t *)l;
76985@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
76986
76987 typedef atomic_t atomic_long_t;
76988
76989+#ifdef CONFIG_PAX_REFCOUNT
76990+typedef atomic_unchecked_t atomic_long_unchecked_t;
76991+#else
76992+typedef atomic_t atomic_long_unchecked_t;
76993+#endif
76994+
76995 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
76996 static inline long atomic_long_read(atomic_long_t *l)
76997 {
76998@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
76999 return (long)atomic_read(v);
77000 }
77001
77002+#ifdef CONFIG_PAX_REFCOUNT
77003+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
77004+{
77005+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77006+
77007+ return (long)atomic_read_unchecked(v);
77008+}
77009+#endif
77010+
77011 static inline void atomic_long_set(atomic_long_t *l, long i)
77012 {
77013 atomic_t *v = (atomic_t *)l;
77014@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
77015 atomic_set(v, i);
77016 }
77017
77018+#ifdef CONFIG_PAX_REFCOUNT
77019+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
77020+{
77021+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77022+
77023+ atomic_set_unchecked(v, i);
77024+}
77025+#endif
77026+
77027 static inline void atomic_long_inc(atomic_long_t *l)
77028 {
77029 atomic_t *v = (atomic_t *)l;
77030@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
77031 atomic_inc(v);
77032 }
77033
77034+#ifdef CONFIG_PAX_REFCOUNT
77035+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
77036+{
77037+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77038+
77039+ atomic_inc_unchecked(v);
77040+}
77041+#endif
77042+
77043 static inline void atomic_long_dec(atomic_long_t *l)
77044 {
77045 atomic_t *v = (atomic_t *)l;
77046@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
77047 atomic_dec(v);
77048 }
77049
77050+#ifdef CONFIG_PAX_REFCOUNT
77051+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
77052+{
77053+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77054+
77055+ atomic_dec_unchecked(v);
77056+}
77057+#endif
77058+
77059 static inline void atomic_long_add(long i, atomic_long_t *l)
77060 {
77061 atomic_t *v = (atomic_t *)l;
77062@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
77063 atomic_add(i, v);
77064 }
77065
77066+#ifdef CONFIG_PAX_REFCOUNT
77067+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
77068+{
77069+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77070+
77071+ atomic_add_unchecked(i, v);
77072+}
77073+#endif
77074+
77075 static inline void atomic_long_sub(long i, atomic_long_t *l)
77076 {
77077 atomic_t *v = (atomic_t *)l;
77078@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
77079 atomic_sub(i, v);
77080 }
77081
77082+#ifdef CONFIG_PAX_REFCOUNT
77083+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
77084+{
77085+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77086+
77087+ atomic_sub_unchecked(i, v);
77088+}
77089+#endif
77090+
77091 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
77092 {
77093 atomic_t *v = (atomic_t *)l;
77094@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
77095 return (long)atomic_add_return(i, v);
77096 }
77097
77098+#ifdef CONFIG_PAX_REFCOUNT
77099+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
77100+{
77101+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77102+
77103+ return (long)atomic_add_return_unchecked(i, v);
77104+}
77105+
77106+#endif
77107+
77108 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
77109 {
77110 atomic_t *v = (atomic_t *)l;
77111@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
77112 return (long)atomic_inc_return(v);
77113 }
77114
77115+#ifdef CONFIG_PAX_REFCOUNT
77116+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
77117+{
77118+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77119+
77120+ return (long)atomic_inc_return_unchecked(v);
77121+}
77122+#endif
77123+
77124 static inline long atomic_long_dec_return(atomic_long_t *l)
77125 {
77126 atomic_t *v = (atomic_t *)l;
77127@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
77128
77129 #endif /* BITS_PER_LONG == 64 */
77130
77131+#ifdef CONFIG_PAX_REFCOUNT
77132+static inline void pax_refcount_needs_these_functions(void)
77133+{
77134+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
77135+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
77136+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
77137+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
77138+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
77139+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
77140+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
77141+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
77142+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
77143+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
77144+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
77145+#ifdef CONFIG_X86
77146+ atomic_clear_mask_unchecked(0, NULL);
77147+ atomic_set_mask_unchecked(0, NULL);
77148+#endif
77149+
77150+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
77151+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
77152+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
77153+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
77154+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
77155+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
77156+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
77157+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
77158+}
77159+#else
77160+#define atomic_read_unchecked(v) atomic_read(v)
77161+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
77162+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
77163+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
77164+#define atomic_inc_unchecked(v) atomic_inc(v)
77165+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
77166+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
77167+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
77168+#define atomic_dec_unchecked(v) atomic_dec(v)
77169+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
77170+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
77171+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
77172+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
77173+
77174+#define atomic_long_read_unchecked(v) atomic_long_read(v)
77175+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
77176+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
77177+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
77178+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
77179+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
77180+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
77181+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
77182+#endif
77183+
77184 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
77185diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
77186index 33bd2de..f31bff97 100644
77187--- a/include/asm-generic/atomic.h
77188+++ b/include/asm-generic/atomic.h
77189@@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
77190 * Atomically clears the bits set in @mask from @v
77191 */
77192 #ifndef atomic_clear_mask
77193-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
77194+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
77195 {
77196 unsigned long flags;
77197
77198diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
77199index b18ce4f..2ee2843 100644
77200--- a/include/asm-generic/atomic64.h
77201+++ b/include/asm-generic/atomic64.h
77202@@ -16,6 +16,8 @@ typedef struct {
77203 long long counter;
77204 } atomic64_t;
77205
77206+typedef atomic64_t atomic64_unchecked_t;
77207+
77208 #define ATOMIC64_INIT(i) { (i) }
77209
77210 extern long long atomic64_read(const atomic64_t *v);
77211@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
77212 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
77213 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
77214
77215+#define atomic64_read_unchecked(v) atomic64_read(v)
77216+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
77217+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
77218+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
77219+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
77220+#define atomic64_inc_unchecked(v) atomic64_inc(v)
77221+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
77222+#define atomic64_dec_unchecked(v) atomic64_dec(v)
77223+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
77224+
77225 #endif /* _ASM_GENERIC_ATOMIC64_H */
77226diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
77227index a60a7cc..0fe12f2 100644
77228--- a/include/asm-generic/bitops/__fls.h
77229+++ b/include/asm-generic/bitops/__fls.h
77230@@ -9,7 +9,7 @@
77231 *
77232 * Undefined if no set bit exists, so code should check against 0 first.
77233 */
77234-static __always_inline unsigned long __fls(unsigned long word)
77235+static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
77236 {
77237 int num = BITS_PER_LONG - 1;
77238
77239diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
77240index 0576d1f..dad6c71 100644
77241--- a/include/asm-generic/bitops/fls.h
77242+++ b/include/asm-generic/bitops/fls.h
77243@@ -9,7 +9,7 @@
77244 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
77245 */
77246
77247-static __always_inline int fls(int x)
77248+static __always_inline int __intentional_overflow(-1) fls(int x)
77249 {
77250 int r = 32;
77251
77252diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
77253index b097cf8..3d40e14 100644
77254--- a/include/asm-generic/bitops/fls64.h
77255+++ b/include/asm-generic/bitops/fls64.h
77256@@ -15,7 +15,7 @@
77257 * at position 64.
77258 */
77259 #if BITS_PER_LONG == 32
77260-static __always_inline int fls64(__u64 x)
77261+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
77262 {
77263 __u32 h = x >> 32;
77264 if (h)
77265@@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
77266 return fls(x);
77267 }
77268 #elif BITS_PER_LONG == 64
77269-static __always_inline int fls64(__u64 x)
77270+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
77271 {
77272 if (x == 0)
77273 return 0;
77274diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
77275index 1bfcfe5..e04c5c9 100644
77276--- a/include/asm-generic/cache.h
77277+++ b/include/asm-generic/cache.h
77278@@ -6,7 +6,7 @@
77279 * cache lines need to provide their own cache.h.
77280 */
77281
77282-#define L1_CACHE_SHIFT 5
77283-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
77284+#define L1_CACHE_SHIFT 5UL
77285+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
77286
77287 #endif /* __ASM_GENERIC_CACHE_H */
77288diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
77289index 0d68a1e..b74a761 100644
77290--- a/include/asm-generic/emergency-restart.h
77291+++ b/include/asm-generic/emergency-restart.h
77292@@ -1,7 +1,7 @@
77293 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
77294 #define _ASM_GENERIC_EMERGENCY_RESTART_H
77295
77296-static inline void machine_emergency_restart(void)
77297+static inline __noreturn void machine_emergency_restart(void)
77298 {
77299 machine_restart(NULL);
77300 }
77301diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
77302index 90f99c7..00ce236 100644
77303--- a/include/asm-generic/kmap_types.h
77304+++ b/include/asm-generic/kmap_types.h
77305@@ -2,9 +2,9 @@
77306 #define _ASM_GENERIC_KMAP_TYPES_H
77307
77308 #ifdef __WITH_KM_FENCE
77309-# define KM_TYPE_NR 41
77310+# define KM_TYPE_NR 42
77311 #else
77312-# define KM_TYPE_NR 20
77313+# define KM_TYPE_NR 21
77314 #endif
77315
77316 #endif
77317diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
77318index 9ceb03b..62b0b8f 100644
77319--- a/include/asm-generic/local.h
77320+++ b/include/asm-generic/local.h
77321@@ -23,24 +23,37 @@ typedef struct
77322 atomic_long_t a;
77323 } local_t;
77324
77325+typedef struct {
77326+ atomic_long_unchecked_t a;
77327+} local_unchecked_t;
77328+
77329 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
77330
77331 #define local_read(l) atomic_long_read(&(l)->a)
77332+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
77333 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
77334+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
77335 #define local_inc(l) atomic_long_inc(&(l)->a)
77336+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
77337 #define local_dec(l) atomic_long_dec(&(l)->a)
77338+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
77339 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
77340+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
77341 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
77342+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
77343
77344 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
77345 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
77346 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
77347 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
77348 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
77349+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
77350 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
77351 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
77352+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
77353
77354 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
77355+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
77356 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
77357 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
77358 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
77359diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
77360index 725612b..9cc513a 100644
77361--- a/include/asm-generic/pgtable-nopmd.h
77362+++ b/include/asm-generic/pgtable-nopmd.h
77363@@ -1,14 +1,19 @@
77364 #ifndef _PGTABLE_NOPMD_H
77365 #define _PGTABLE_NOPMD_H
77366
77367-#ifndef __ASSEMBLY__
77368-
77369 #include <asm-generic/pgtable-nopud.h>
77370
77371-struct mm_struct;
77372-
77373 #define __PAGETABLE_PMD_FOLDED
77374
77375+#define PMD_SHIFT PUD_SHIFT
77376+#define PTRS_PER_PMD 1
77377+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
77378+#define PMD_MASK (~(PMD_SIZE-1))
77379+
77380+#ifndef __ASSEMBLY__
77381+
77382+struct mm_struct;
77383+
77384 /*
77385 * Having the pmd type consist of a pud gets the size right, and allows
77386 * us to conceptually access the pud entry that this pmd is folded into
77387@@ -16,11 +21,6 @@ struct mm_struct;
77388 */
77389 typedef struct { pud_t pud; } pmd_t;
77390
77391-#define PMD_SHIFT PUD_SHIFT
77392-#define PTRS_PER_PMD 1
77393-#define PMD_SIZE (1UL << PMD_SHIFT)
77394-#define PMD_MASK (~(PMD_SIZE-1))
77395-
77396 /*
77397 * The "pud_xxx()" functions here are trivial for a folded two-level
77398 * setup: the pmd is never bad, and a pmd always exists (as it's folded
77399diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
77400index 810431d..0ec4804f 100644
77401--- a/include/asm-generic/pgtable-nopud.h
77402+++ b/include/asm-generic/pgtable-nopud.h
77403@@ -1,10 +1,15 @@
77404 #ifndef _PGTABLE_NOPUD_H
77405 #define _PGTABLE_NOPUD_H
77406
77407-#ifndef __ASSEMBLY__
77408-
77409 #define __PAGETABLE_PUD_FOLDED
77410
77411+#define PUD_SHIFT PGDIR_SHIFT
77412+#define PTRS_PER_PUD 1
77413+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
77414+#define PUD_MASK (~(PUD_SIZE-1))
77415+
77416+#ifndef __ASSEMBLY__
77417+
77418 /*
77419 * Having the pud type consist of a pgd gets the size right, and allows
77420 * us to conceptually access the pgd entry that this pud is folded into
77421@@ -12,11 +17,6 @@
77422 */
77423 typedef struct { pgd_t pgd; } pud_t;
77424
77425-#define PUD_SHIFT PGDIR_SHIFT
77426-#define PTRS_PER_PUD 1
77427-#define PUD_SIZE (1UL << PUD_SHIFT)
77428-#define PUD_MASK (~(PUD_SIZE-1))
77429-
77430 /*
77431 * The "pgd_xxx()" functions here are trivial for a folded two-level
77432 * setup: the pud is never bad, and a pud always exists (as it's folded
77433@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
77434 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
77435
77436 #define pgd_populate(mm, pgd, pud) do { } while (0)
77437+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
77438 /*
77439 * (puds are folded into pgds so this doesn't get actually called,
77440 * but the define is needed for a generic inline function.)
77441diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
77442index 34c7bdc..38d4f3b 100644
77443--- a/include/asm-generic/pgtable.h
77444+++ b/include/asm-generic/pgtable.h
77445@@ -787,6 +787,22 @@ static inline void pmdp_set_numa(struct mm_struct *mm, unsigned long addr,
77446 }
77447 #endif /* CONFIG_NUMA_BALANCING */
77448
77449+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
77450+#ifdef CONFIG_PAX_KERNEXEC
77451+#error KERNEXEC requires pax_open_kernel
77452+#else
77453+static inline unsigned long pax_open_kernel(void) { return 0; }
77454+#endif
77455+#endif
77456+
77457+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
77458+#ifdef CONFIG_PAX_KERNEXEC
77459+#error KERNEXEC requires pax_close_kernel
77460+#else
77461+static inline unsigned long pax_close_kernel(void) { return 0; }
77462+#endif
77463+#endif
77464+
77465 #endif /* CONFIG_MMU */
77466
77467 #endif /* !__ASSEMBLY__ */
77468diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
77469index 72d8803..cb9749c 100644
77470--- a/include/asm-generic/uaccess.h
77471+++ b/include/asm-generic/uaccess.h
77472@@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
77473 return __clear_user(to, n);
77474 }
77475
77476+#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
77477+#ifdef CONFIG_PAX_MEMORY_UDEREF
77478+#error UDEREF requires pax_open_userland
77479+#else
77480+static inline unsigned long pax_open_userland(void) { return 0; }
77481+#endif
77482+#endif
77483+
77484+#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
77485+#ifdef CONFIG_PAX_MEMORY_UDEREF
77486+#error UDEREF requires pax_close_userland
77487+#else
77488+static inline unsigned long pax_close_userland(void) { return 0; }
77489+#endif
77490+#endif
77491+
77492 #endif /* __ASM_GENERIC_UACCESS_H */
77493diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
77494index bc2121f..2f41f9a 100644
77495--- a/include/asm-generic/vmlinux.lds.h
77496+++ b/include/asm-generic/vmlinux.lds.h
77497@@ -232,6 +232,7 @@
77498 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
77499 VMLINUX_SYMBOL(__start_rodata) = .; \
77500 *(.rodata) *(.rodata.*) \
77501+ *(.data..read_only) \
77502 *(__vermagic) /* Kernel version magic */ \
77503 . = ALIGN(8); \
77504 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
77505@@ -716,17 +717,18 @@
77506 * section in the linker script will go there too. @phdr should have
77507 * a leading colon.
77508 *
77509- * Note that this macros defines __per_cpu_load as an absolute symbol.
77510+ * Note that this macros defines per_cpu_load as an absolute symbol.
77511 * If there is no need to put the percpu section at a predetermined
77512 * address, use PERCPU_SECTION.
77513 */
77514 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
77515- VMLINUX_SYMBOL(__per_cpu_load) = .; \
77516- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
77517+ per_cpu_load = .; \
77518+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
77519 - LOAD_OFFSET) { \
77520+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
77521 PERCPU_INPUT(cacheline) \
77522 } phdr \
77523- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
77524+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
77525
77526 /**
77527 * PERCPU_SECTION - define output section for percpu area, simple version
77528diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
77529index e73c19e..5b89e00 100644
77530--- a/include/crypto/algapi.h
77531+++ b/include/crypto/algapi.h
77532@@ -34,7 +34,7 @@ struct crypto_type {
77533 unsigned int maskclear;
77534 unsigned int maskset;
77535 unsigned int tfmsize;
77536-};
77537+} __do_const;
77538
77539 struct crypto_instance {
77540 struct crypto_alg alg;
77541diff --git a/include/drm/drmP.h b/include/drm/drmP.h
77542index 04a7f31..668d424 100644
77543--- a/include/drm/drmP.h
77544+++ b/include/drm/drmP.h
77545@@ -67,6 +67,7 @@
77546 #include <linux/workqueue.h>
77547 #include <linux/poll.h>
77548 #include <asm/pgalloc.h>
77549+#include <asm/local.h>
77550 #include <drm/drm.h>
77551 #include <drm/drm_sarea.h>
77552 #include <drm/drm_vma_manager.h>
77553@@ -297,10 +298,12 @@ do { \
77554 * \param cmd command.
77555 * \param arg argument.
77556 */
77557-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
77558+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
77559+ struct drm_file *file_priv);
77560+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
77561 struct drm_file *file_priv);
77562
77563-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
77564+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
77565 unsigned long arg);
77566
77567 #define DRM_IOCTL_NR(n) _IOC_NR(n)
77568@@ -316,10 +319,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
77569 struct drm_ioctl_desc {
77570 unsigned int cmd;
77571 int flags;
77572- drm_ioctl_t *func;
77573+ drm_ioctl_t func;
77574 unsigned int cmd_drv;
77575 const char *name;
77576-};
77577+} __do_const;
77578
77579 /**
77580 * Creates a driver or general drm_ioctl_desc array entry for the given
77581@@ -1022,7 +1025,8 @@ struct drm_info_list {
77582 int (*show)(struct seq_file*, void*); /** show callback */
77583 u32 driver_features; /**< Required driver features for this entry */
77584 void *data;
77585-};
77586+} __do_const;
77587+typedef struct drm_info_list __no_const drm_info_list_no_const;
77588
77589 /**
77590 * debugfs node structure. This structure represents a debugfs file.
77591@@ -1106,7 +1110,7 @@ struct drm_device {
77592
77593 /** \name Usage Counters */
77594 /*@{ */
77595- int open_count; /**< Outstanding files open */
77596+ local_t open_count; /**< Outstanding files open */
77597 int buf_use; /**< Buffers in use -- cannot alloc */
77598 atomic_t buf_alloc; /**< Buffer allocation in progress */
77599 /*@} */
77600diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
77601index b1388b5..e1d1163 100644
77602--- a/include/drm/drm_crtc_helper.h
77603+++ b/include/drm/drm_crtc_helper.h
77604@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
77605 struct drm_connector *connector);
77606 /* disable encoder when not in use - more explicit than dpms off */
77607 void (*disable)(struct drm_encoder *encoder);
77608-};
77609+} __no_const;
77610
77611 /**
77612 * drm_connector_helper_funcs - helper operations for connectors
77613diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
77614index 940ece4..8cb727f 100644
77615--- a/include/drm/i915_pciids.h
77616+++ b/include/drm/i915_pciids.h
77617@@ -37,7 +37,7 @@
77618 */
77619 #define INTEL_VGA_DEVICE(id, info) { \
77620 0x8086, id, \
77621- ~0, ~0, \
77622+ PCI_ANY_ID, PCI_ANY_ID, \
77623 0x030000, 0xff0000, \
77624 (unsigned long) info }
77625
77626diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
77627index 72dcbe8..8db58d7 100644
77628--- a/include/drm/ttm/ttm_memory.h
77629+++ b/include/drm/ttm/ttm_memory.h
77630@@ -48,7 +48,7 @@
77631
77632 struct ttm_mem_shrink {
77633 int (*do_shrink) (struct ttm_mem_shrink *);
77634-};
77635+} __no_const;
77636
77637 /**
77638 * struct ttm_mem_global - Global memory accounting structure.
77639diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
77640index 49a8284..9643967 100644
77641--- a/include/drm/ttm/ttm_page_alloc.h
77642+++ b/include/drm/ttm/ttm_page_alloc.h
77643@@ -80,6 +80,7 @@ void ttm_dma_page_alloc_fini(void);
77644 */
77645 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
77646
77647+struct device;
77648 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
77649 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
77650
77651diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
77652index 4b840e8..155d235 100644
77653--- a/include/keys/asymmetric-subtype.h
77654+++ b/include/keys/asymmetric-subtype.h
77655@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
77656 /* Verify the signature on a key of this subtype (optional) */
77657 int (*verify_signature)(const struct key *key,
77658 const struct public_key_signature *sig);
77659-};
77660+} __do_const;
77661
77662 /**
77663 * asymmetric_key_subtype - Get the subtype from an asymmetric key
77664diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
77665index c1da539..1dcec55 100644
77666--- a/include/linux/atmdev.h
77667+++ b/include/linux/atmdev.h
77668@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
77669 #endif
77670
77671 struct k_atm_aal_stats {
77672-#define __HANDLE_ITEM(i) atomic_t i
77673+#define __HANDLE_ITEM(i) atomic_unchecked_t i
77674 __AAL_STAT_ITEMS
77675 #undef __HANDLE_ITEM
77676 };
77677@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
77678 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
77679 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
77680 struct module *owner;
77681-};
77682+} __do_const ;
77683
77684 struct atmphy_ops {
77685 int (*start)(struct atm_dev *dev);
77686diff --git a/include/linux/audit.h b/include/linux/audit.h
77687index ec1464d..833274b 100644
77688--- a/include/linux/audit.h
77689+++ b/include/linux/audit.h
77690@@ -196,7 +196,7 @@ static inline void audit_ptrace(struct task_struct *t)
77691 extern unsigned int audit_serial(void);
77692 extern int auditsc_get_stamp(struct audit_context *ctx,
77693 struct timespec *t, unsigned int *serial);
77694-extern int audit_set_loginuid(kuid_t loginuid);
77695+extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
77696
77697 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
77698 {
77699diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
77700index b4a745d..e3c0942 100644
77701--- a/include/linux/binfmts.h
77702+++ b/include/linux/binfmts.h
77703@@ -45,7 +45,7 @@ struct linux_binprm {
77704 unsigned interp_data;
77705 unsigned long loader, exec;
77706 char tcomm[TASK_COMM_LEN];
77707-};
77708+} __randomize_layout;
77709
77710 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
77711 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
77712@@ -74,8 +74,10 @@ struct linux_binfmt {
77713 int (*load_binary)(struct linux_binprm *);
77714 int (*load_shlib)(struct file *);
77715 int (*core_dump)(struct coredump_params *cprm);
77716+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
77717+ void (*handle_mmap)(struct file *);
77718 unsigned long min_coredump; /* minimal dump size */
77719-};
77720+} __do_const __randomize_layout;
77721
77722 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
77723
77724diff --git a/include/linux/bitops.h b/include/linux/bitops.h
77725index be5fd38..d71192a 100644
77726--- a/include/linux/bitops.h
77727+++ b/include/linux/bitops.h
77728@@ -102,7 +102,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
77729 * @word: value to rotate
77730 * @shift: bits to roll
77731 */
77732-static inline __u32 rol32(__u32 word, unsigned int shift)
77733+static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
77734 {
77735 return (word << shift) | (word >> (32 - shift));
77736 }
77737@@ -112,7 +112,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
77738 * @word: value to rotate
77739 * @shift: bits to roll
77740 */
77741-static inline __u32 ror32(__u32 word, unsigned int shift)
77742+static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
77743 {
77744 return (word >> shift) | (word << (32 - shift));
77745 }
77746@@ -168,7 +168,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
77747 return (__s32)(value << shift) >> shift;
77748 }
77749
77750-static inline unsigned fls_long(unsigned long l)
77751+static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
77752 {
77753 if (sizeof(l) == 4)
77754 return fls(l);
77755diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
77756index 4afa4f8..1ed7824 100644
77757--- a/include/linux/blkdev.h
77758+++ b/include/linux/blkdev.h
77759@@ -1572,7 +1572,7 @@ struct block_device_operations {
77760 /* this callback is with swap_lock and sometimes page table lock held */
77761 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
77762 struct module *owner;
77763-};
77764+} __do_const;
77765
77766 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
77767 unsigned long);
77768diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
77769index afc1343..9735539 100644
77770--- a/include/linux/blktrace_api.h
77771+++ b/include/linux/blktrace_api.h
77772@@ -25,7 +25,7 @@ struct blk_trace {
77773 struct dentry *dropped_file;
77774 struct dentry *msg_file;
77775 struct list_head running_list;
77776- atomic_t dropped;
77777+ atomic_unchecked_t dropped;
77778 };
77779
77780 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
77781diff --git a/include/linux/cache.h b/include/linux/cache.h
77782index 17e7e82..1d7da26 100644
77783--- a/include/linux/cache.h
77784+++ b/include/linux/cache.h
77785@@ -16,6 +16,14 @@
77786 #define __read_mostly
77787 #endif
77788
77789+#ifndef __read_only
77790+#ifdef CONFIG_PAX_KERNEXEC
77791+#error KERNEXEC requires __read_only
77792+#else
77793+#define __read_only __read_mostly
77794+#endif
77795+#endif
77796+
77797 #ifndef ____cacheline_aligned
77798 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
77799 #endif
77800diff --git a/include/linux/capability.h b/include/linux/capability.h
77801index a6ee1f9..e1ca49d 100644
77802--- a/include/linux/capability.h
77803+++ b/include/linux/capability.h
77804@@ -212,8 +212,13 @@ extern bool capable(int cap);
77805 extern bool ns_capable(struct user_namespace *ns, int cap);
77806 extern bool inode_capable(const struct inode *inode, int cap);
77807 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
77808+extern bool capable_nolog(int cap);
77809+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
77810+extern bool inode_capable_nolog(const struct inode *inode, int cap);
77811
77812 /* audit system wants to get cap info from files as well */
77813 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
77814
77815+extern int is_privileged_binary(const struct dentry *dentry);
77816+
77817 #endif /* !_LINUX_CAPABILITY_H */
77818diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
77819index 8609d57..86e4d79 100644
77820--- a/include/linux/cdrom.h
77821+++ b/include/linux/cdrom.h
77822@@ -87,7 +87,6 @@ struct cdrom_device_ops {
77823
77824 /* driver specifications */
77825 const int capability; /* capability flags */
77826- int n_minors; /* number of active minor devices */
77827 /* handle uniform packets for scsi type devices (scsi,atapi) */
77828 int (*generic_packet) (struct cdrom_device_info *,
77829 struct packet_command *);
77830diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
77831index 4ce9056..86caac6 100644
77832--- a/include/linux/cleancache.h
77833+++ b/include/linux/cleancache.h
77834@@ -31,7 +31,7 @@ struct cleancache_ops {
77835 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
77836 void (*invalidate_inode)(int, struct cleancache_filekey);
77837 void (*invalidate_fs)(int);
77838-};
77839+} __no_const;
77840
77841 extern struct cleancache_ops *
77842 cleancache_register_ops(struct cleancache_ops *ops);
77843diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
77844index 939533d..cf0a57c 100644
77845--- a/include/linux/clk-provider.h
77846+++ b/include/linux/clk-provider.h
77847@@ -166,6 +166,7 @@ struct clk_ops {
77848 unsigned long parent_accuracy);
77849 void (*init)(struct clk_hw *hw);
77850 };
77851+typedef struct clk_ops __no_const clk_ops_no_const;
77852
77853 /**
77854 * struct clk_init_data - holds init data that's common to all clocks and is
77855diff --git a/include/linux/compat.h b/include/linux/compat.h
77856index 3f448c6..df3ce1d 100644
77857--- a/include/linux/compat.h
77858+++ b/include/linux/compat.h
77859@@ -313,7 +313,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
77860 compat_size_t __user *len_ptr);
77861
77862 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
77863-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
77864+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
77865 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
77866 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
77867 compat_ssize_t msgsz, int msgflg);
77868@@ -420,7 +420,7 @@ extern int compat_ptrace_request(struct task_struct *child,
77869 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
77870 compat_ulong_t addr, compat_ulong_t data);
77871 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
77872- compat_long_t addr, compat_long_t data);
77873+ compat_ulong_t addr, compat_ulong_t data);
77874
77875 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
77876 /*
77877diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
77878index 2507fd2..55203f8 100644
77879--- a/include/linux/compiler-gcc4.h
77880+++ b/include/linux/compiler-gcc4.h
77881@@ -39,9 +39,34 @@
77882 # define __compiletime_warning(message) __attribute__((warning(message)))
77883 # define __compiletime_error(message) __attribute__((error(message)))
77884 #endif /* __CHECKER__ */
77885+
77886+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
77887+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
77888+#define __bos0(ptr) __bos((ptr), 0)
77889+#define __bos1(ptr) __bos((ptr), 1)
77890 #endif /* GCC_VERSION >= 40300 */
77891
77892 #if GCC_VERSION >= 40500
77893+
77894+#ifdef RANDSTRUCT_PLUGIN
77895+#define __randomize_layout __attribute__((randomize_layout))
77896+#define __no_randomize_layout __attribute__((no_randomize_layout))
77897+#endif
77898+
77899+#ifdef CONSTIFY_PLUGIN
77900+#define __no_const __attribute__((no_const))
77901+#define __do_const __attribute__((do_const))
77902+#endif
77903+
77904+#ifdef SIZE_OVERFLOW_PLUGIN
77905+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
77906+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
77907+#endif
77908+
77909+#ifdef LATENT_ENTROPY_PLUGIN
77910+#define __latent_entropy __attribute__((latent_entropy))
77911+#endif
77912+
77913 /*
77914 * Mark a position in code as unreachable. This can be used to
77915 * suppress control flow warnings after asm blocks that transfer
77916diff --git a/include/linux/compiler.h b/include/linux/compiler.h
77917index 2472740..4857634 100644
77918--- a/include/linux/compiler.h
77919+++ b/include/linux/compiler.h
77920@@ -5,11 +5,14 @@
77921
77922 #ifdef __CHECKER__
77923 # define __user __attribute__((noderef, address_space(1)))
77924+# define __force_user __force __user
77925 # define __kernel __attribute__((address_space(0)))
77926+# define __force_kernel __force __kernel
77927 # define __safe __attribute__((safe))
77928 # define __force __attribute__((force))
77929 # define __nocast __attribute__((nocast))
77930 # define __iomem __attribute__((noderef, address_space(2)))
77931+# define __force_iomem __force __iomem
77932 # define __must_hold(x) __attribute__((context(x,1,1)))
77933 # define __acquires(x) __attribute__((context(x,0,1)))
77934 # define __releases(x) __attribute__((context(x,1,0)))
77935@@ -17,20 +20,37 @@
77936 # define __release(x) __context__(x,-1)
77937 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
77938 # define __percpu __attribute__((noderef, address_space(3)))
77939+# define __force_percpu __force __percpu
77940 #ifdef CONFIG_SPARSE_RCU_POINTER
77941 # define __rcu __attribute__((noderef, address_space(4)))
77942+# define __force_rcu __force __rcu
77943 #else
77944 # define __rcu
77945+# define __force_rcu
77946 #endif
77947 extern void __chk_user_ptr(const volatile void __user *);
77948 extern void __chk_io_ptr(const volatile void __iomem *);
77949 #else
77950-# define __user
77951-# define __kernel
77952+# ifdef CHECKER_PLUGIN
77953+//# define __user
77954+//# define __force_user
77955+//# define __kernel
77956+//# define __force_kernel
77957+# else
77958+# ifdef STRUCTLEAK_PLUGIN
77959+# define __user __attribute__((user))
77960+# else
77961+# define __user
77962+# endif
77963+# define __force_user
77964+# define __kernel
77965+# define __force_kernel
77966+# endif
77967 # define __safe
77968 # define __force
77969 # define __nocast
77970 # define __iomem
77971+# define __force_iomem
77972 # define __chk_user_ptr(x) (void)0
77973 # define __chk_io_ptr(x) (void)0
77974 # define __builtin_warning(x, y...) (1)
77975@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
77976 # define __release(x) (void)0
77977 # define __cond_lock(x,c) (c)
77978 # define __percpu
77979+# define __force_percpu
77980 # define __rcu
77981+# define __force_rcu
77982 #endif
77983
77984 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
77985@@ -279,6 +301,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77986 # define __attribute_const__ /* unimplemented */
77987 #endif
77988
77989+#ifndef __randomize_layout
77990+# define __randomize_layout
77991+#endif
77992+
77993+#ifndef __no_randomize_layout
77994+# define __no_randomize_layout
77995+#endif
77996+
77997+#ifndef __no_const
77998+# define __no_const
77999+#endif
78000+
78001+#ifndef __do_const
78002+# define __do_const
78003+#endif
78004+
78005+#ifndef __size_overflow
78006+# define __size_overflow(...)
78007+#endif
78008+
78009+#ifndef __intentional_overflow
78010+# define __intentional_overflow(...)
78011+#endif
78012+
78013+#ifndef __latent_entropy
78014+# define __latent_entropy
78015+#endif
78016+
78017 /*
78018 * Tell gcc if a function is cold. The compiler will assume any path
78019 * directly leading to the call is unlikely.
78020@@ -288,6 +338,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
78021 #define __cold
78022 #endif
78023
78024+#ifndef __alloc_size
78025+#define __alloc_size(...)
78026+#endif
78027+
78028+#ifndef __bos
78029+#define __bos(ptr, arg)
78030+#endif
78031+
78032+#ifndef __bos0
78033+#define __bos0(ptr)
78034+#endif
78035+
78036+#ifndef __bos1
78037+#define __bos1(ptr)
78038+#endif
78039+
78040 /* Simple shorthand for a section definition */
78041 #ifndef __section
78042 # define __section(S) __attribute__ ((__section__(#S)))
78043@@ -362,7 +428,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
78044 * use is to mediate communication between process-level code and irq/NMI
78045 * handlers, all running on the same CPU.
78046 */
78047-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
78048+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
78049+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
78050
78051 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
78052 #ifdef CONFIG_KPROBES
78053diff --git a/include/linux/completion.h b/include/linux/completion.h
78054index 5d5aaae..0ea9b84 100644
78055--- a/include/linux/completion.h
78056+++ b/include/linux/completion.h
78057@@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
78058
78059 extern void wait_for_completion(struct completion *);
78060 extern void wait_for_completion_io(struct completion *);
78061-extern int wait_for_completion_interruptible(struct completion *x);
78062-extern int wait_for_completion_killable(struct completion *x);
78063+extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
78064+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
78065 extern unsigned long wait_for_completion_timeout(struct completion *x,
78066- unsigned long timeout);
78067+ unsigned long timeout) __intentional_overflow(-1);
78068 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
78069- unsigned long timeout);
78070+ unsigned long timeout) __intentional_overflow(-1);
78071 extern long wait_for_completion_interruptible_timeout(
78072- struct completion *x, unsigned long timeout);
78073+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
78074 extern long wait_for_completion_killable_timeout(
78075- struct completion *x, unsigned long timeout);
78076+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
78077 extern bool try_wait_for_completion(struct completion *x);
78078 extern bool completion_done(struct completion *x);
78079
78080diff --git a/include/linux/configfs.h b/include/linux/configfs.h
78081index 34025df..d94bbbc 100644
78082--- a/include/linux/configfs.h
78083+++ b/include/linux/configfs.h
78084@@ -125,7 +125,7 @@ struct configfs_attribute {
78085 const char *ca_name;
78086 struct module *ca_owner;
78087 umode_t ca_mode;
78088-};
78089+} __do_const;
78090
78091 /*
78092 * Users often need to create attribute structures for their configurable
78093diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
78094index 4d89e0e..5281847 100644
78095--- a/include/linux/cpufreq.h
78096+++ b/include/linux/cpufreq.h
78097@@ -191,6 +191,7 @@ struct global_attr {
78098 ssize_t (*store)(struct kobject *a, struct attribute *b,
78099 const char *c, size_t count);
78100 };
78101+typedef struct global_attr __no_const global_attr_no_const;
78102
78103 #define define_one_global_ro(_name) \
78104 static struct global_attr _name = \
78105@@ -232,7 +233,7 @@ struct cpufreq_driver {
78106 bool boost_supported;
78107 bool boost_enabled;
78108 int (*set_boost) (int state);
78109-};
78110+} __do_const;
78111
78112 /* flags */
78113 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
78114diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
78115index 50fcbb0..9d2dbd9 100644
78116--- a/include/linux/cpuidle.h
78117+++ b/include/linux/cpuidle.h
78118@@ -50,7 +50,8 @@ struct cpuidle_state {
78119 int index);
78120
78121 int (*enter_dead) (struct cpuidle_device *dev, int index);
78122-};
78123+} __do_const;
78124+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
78125
78126 /* Idle State Flags */
78127 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
78128@@ -192,7 +193,7 @@ struct cpuidle_governor {
78129 void (*reflect) (struct cpuidle_device *dev, int index);
78130
78131 struct module *owner;
78132-};
78133+} __do_const;
78134
78135 #ifdef CONFIG_CPU_IDLE
78136 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
78137diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
78138index d08e4d2..95fad61 100644
78139--- a/include/linux/cpumask.h
78140+++ b/include/linux/cpumask.h
78141@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
78142 }
78143
78144 /* Valid inputs for n are -1 and 0. */
78145-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
78146+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
78147 {
78148 return n+1;
78149 }
78150
78151-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
78152+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
78153 {
78154 return n+1;
78155 }
78156
78157-static inline unsigned int cpumask_next_and(int n,
78158+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
78159 const struct cpumask *srcp,
78160 const struct cpumask *andp)
78161 {
78162@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
78163 *
78164 * Returns >= nr_cpu_ids if no further cpus set.
78165 */
78166-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
78167+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
78168 {
78169 /* -1 is a legal arg here. */
78170 if (n != -1)
78171@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
78172 *
78173 * Returns >= nr_cpu_ids if no further cpus unset.
78174 */
78175-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
78176+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
78177 {
78178 /* -1 is a legal arg here. */
78179 if (n != -1)
78180@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
78181 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
78182 }
78183
78184-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
78185+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
78186 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
78187
78188 /**
78189diff --git a/include/linux/cred.h b/include/linux/cred.h
78190index 04421e8..117e17a 100644
78191--- a/include/linux/cred.h
78192+++ b/include/linux/cred.h
78193@@ -35,7 +35,7 @@ struct group_info {
78194 int nblocks;
78195 kgid_t small_block[NGROUPS_SMALL];
78196 kgid_t *blocks[0];
78197-};
78198+} __randomize_layout;
78199
78200 /**
78201 * get_group_info - Get a reference to a group info structure
78202@@ -136,7 +136,7 @@ struct cred {
78203 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
78204 struct group_info *group_info; /* supplementary groups for euid/fsgid */
78205 struct rcu_head rcu; /* RCU deletion hook */
78206-};
78207+} __randomize_layout;
78208
78209 extern void __put_cred(struct cred *);
78210 extern void exit_creds(struct task_struct *);
78211@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
78212 static inline void validate_process_creds(void)
78213 {
78214 }
78215+static inline void validate_task_creds(struct task_struct *task)
78216+{
78217+}
78218 #endif
78219
78220 /**
78221diff --git a/include/linux/crypto.h b/include/linux/crypto.h
78222index b92eadf..b4ecdc1 100644
78223--- a/include/linux/crypto.h
78224+++ b/include/linux/crypto.h
78225@@ -373,7 +373,7 @@ struct cipher_tfm {
78226 const u8 *key, unsigned int keylen);
78227 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
78228 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
78229-};
78230+} __no_const;
78231
78232 struct hash_tfm {
78233 int (*init)(struct hash_desc *desc);
78234@@ -394,13 +394,13 @@ struct compress_tfm {
78235 int (*cot_decompress)(struct crypto_tfm *tfm,
78236 const u8 *src, unsigned int slen,
78237 u8 *dst, unsigned int *dlen);
78238-};
78239+} __no_const;
78240
78241 struct rng_tfm {
78242 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
78243 unsigned int dlen);
78244 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
78245-};
78246+} __no_const;
78247
78248 #define crt_ablkcipher crt_u.ablkcipher
78249 #define crt_aead crt_u.aead
78250diff --git a/include/linux/ctype.h b/include/linux/ctype.h
78251index 653589e..4ef254a 100644
78252--- a/include/linux/ctype.h
78253+++ b/include/linux/ctype.h
78254@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
78255 * Fast implementation of tolower() for internal usage. Do not use in your
78256 * code.
78257 */
78258-static inline char _tolower(const char c)
78259+static inline unsigned char _tolower(const unsigned char c)
78260 {
78261 return c | 0x20;
78262 }
78263diff --git a/include/linux/dcache.h b/include/linux/dcache.h
78264index bf72e9a..4ca7927 100644
78265--- a/include/linux/dcache.h
78266+++ b/include/linux/dcache.h
78267@@ -133,7 +133,7 @@ struct dentry {
78268 } d_u;
78269 struct list_head d_subdirs; /* our children */
78270 struct hlist_node d_alias; /* inode alias list */
78271-};
78272+} __randomize_layout;
78273
78274 /*
78275 * dentry->d_lock spinlock nesting subclasses:
78276diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
78277index 7925bf0..d5143d2 100644
78278--- a/include/linux/decompress/mm.h
78279+++ b/include/linux/decompress/mm.h
78280@@ -77,7 +77,7 @@ static void free(void *where)
78281 * warnings when not needed (indeed large_malloc / large_free are not
78282 * needed by inflate */
78283
78284-#define malloc(a) kmalloc(a, GFP_KERNEL)
78285+#define malloc(a) kmalloc((a), GFP_KERNEL)
78286 #define free(a) kfree(a)
78287
78288 #define large_malloc(a) vmalloc(a)
78289diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
78290index d48dc00..211ee54 100644
78291--- a/include/linux/devfreq.h
78292+++ b/include/linux/devfreq.h
78293@@ -114,7 +114,7 @@ struct devfreq_governor {
78294 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
78295 int (*event_handler)(struct devfreq *devfreq,
78296 unsigned int event, void *data);
78297-};
78298+} __do_const;
78299
78300 /**
78301 * struct devfreq - Device devfreq structure
78302diff --git a/include/linux/device.h b/include/linux/device.h
78303index 952b010..d5b7691 100644
78304--- a/include/linux/device.h
78305+++ b/include/linux/device.h
78306@@ -310,7 +310,7 @@ struct subsys_interface {
78307 struct list_head node;
78308 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
78309 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
78310-};
78311+} __do_const;
78312
78313 int subsys_interface_register(struct subsys_interface *sif);
78314 void subsys_interface_unregister(struct subsys_interface *sif);
78315@@ -506,7 +506,7 @@ struct device_type {
78316 void (*release)(struct device *dev);
78317
78318 const struct dev_pm_ops *pm;
78319-};
78320+} __do_const;
78321
78322 /* interface for exporting device attributes */
78323 struct device_attribute {
78324@@ -516,11 +516,12 @@ struct device_attribute {
78325 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
78326 const char *buf, size_t count);
78327 };
78328+typedef struct device_attribute __no_const device_attribute_no_const;
78329
78330 struct dev_ext_attribute {
78331 struct device_attribute attr;
78332 void *var;
78333-};
78334+} __do_const;
78335
78336 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
78337 char *buf);
78338diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
78339index fd4aee2..1f28db9 100644
78340--- a/include/linux/dma-mapping.h
78341+++ b/include/linux/dma-mapping.h
78342@@ -54,7 +54,7 @@ struct dma_map_ops {
78343 u64 (*get_required_mask)(struct device *dev);
78344 #endif
78345 int is_phys;
78346-};
78347+} __do_const;
78348
78349 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
78350
78351diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
78352index c5c92d5..6a5c2b2 100644
78353--- a/include/linux/dmaengine.h
78354+++ b/include/linux/dmaengine.h
78355@@ -1150,9 +1150,9 @@ struct dma_pinned_list {
78356 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
78357 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
78358
78359-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
78360+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
78361 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
78362-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
78363+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
78364 struct dma_pinned_list *pinned_list, struct page *page,
78365 unsigned int offset, size_t len);
78366
78367diff --git a/include/linux/efi.h b/include/linux/efi.h
78368index 0a819e7..8ed47f1 100644
78369--- a/include/linux/efi.h
78370+++ b/include/linux/efi.h
78371@@ -768,6 +768,7 @@ struct efivar_operations {
78372 efi_set_variable_t *set_variable;
78373 efi_query_variable_store_t *query_variable_store;
78374 };
78375+typedef struct efivar_operations __no_const efivar_operations_no_const;
78376
78377 struct efivars {
78378 /*
78379diff --git a/include/linux/elf.h b/include/linux/elf.h
78380index 67a5fa7..b817372 100644
78381--- a/include/linux/elf.h
78382+++ b/include/linux/elf.h
78383@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
78384 #define elf_note elf32_note
78385 #define elf_addr_t Elf32_Off
78386 #define Elf_Half Elf32_Half
78387+#define elf_dyn Elf32_Dyn
78388
78389 #else
78390
78391@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
78392 #define elf_note elf64_note
78393 #define elf_addr_t Elf64_Off
78394 #define Elf_Half Elf64_Half
78395+#define elf_dyn Elf64_Dyn
78396
78397 #endif
78398
78399diff --git a/include/linux/err.h b/include/linux/err.h
78400index 15f92e0..e825a8e 100644
78401--- a/include/linux/err.h
78402+++ b/include/linux/err.h
78403@@ -19,12 +19,12 @@
78404
78405 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
78406
78407-static inline void * __must_check ERR_PTR(long error)
78408+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
78409 {
78410 return (void *) error;
78411 }
78412
78413-static inline long __must_check PTR_ERR(__force const void *ptr)
78414+static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
78415 {
78416 return (long) ptr;
78417 }
78418diff --git a/include/linux/extcon.h b/include/linux/extcon.h
78419index 21c59af..6057a03 100644
78420--- a/include/linux/extcon.h
78421+++ b/include/linux/extcon.h
78422@@ -135,7 +135,7 @@ struct extcon_dev {
78423 /* /sys/class/extcon/.../mutually_exclusive/... */
78424 struct attribute_group attr_g_muex;
78425 struct attribute **attrs_muex;
78426- struct device_attribute *d_attrs_muex;
78427+ device_attribute_no_const *d_attrs_muex;
78428 };
78429
78430 /**
78431diff --git a/include/linux/fb.h b/include/linux/fb.h
78432index fe6ac95..898d41d 100644
78433--- a/include/linux/fb.h
78434+++ b/include/linux/fb.h
78435@@ -304,7 +304,7 @@ struct fb_ops {
78436 /* called at KDB enter and leave time to prepare the console */
78437 int (*fb_debug_enter)(struct fb_info *info);
78438 int (*fb_debug_leave)(struct fb_info *info);
78439-};
78440+} __do_const;
78441
78442 #ifdef CONFIG_FB_TILEBLITTING
78443 #define FB_TILE_CURSOR_NONE 0
78444diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
78445index 70e8e21..1939916 100644
78446--- a/include/linux/fdtable.h
78447+++ b/include/linux/fdtable.h
78448@@ -102,7 +102,7 @@ struct files_struct *get_files_struct(struct task_struct *);
78449 void put_files_struct(struct files_struct *fs);
78450 void reset_files_struct(struct files_struct *);
78451 int unshare_files(struct files_struct **);
78452-struct files_struct *dup_fd(struct files_struct *, int *);
78453+struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
78454 void do_close_on_exec(struct files_struct *);
78455 int iterate_fd(struct files_struct *, unsigned,
78456 int (*)(const void *, struct file *, unsigned),
78457diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
78458index 8293262..2b3b8bd 100644
78459--- a/include/linux/frontswap.h
78460+++ b/include/linux/frontswap.h
78461@@ -11,7 +11,7 @@ struct frontswap_ops {
78462 int (*load)(unsigned, pgoff_t, struct page *);
78463 void (*invalidate_page)(unsigned, pgoff_t);
78464 void (*invalidate_area)(unsigned);
78465-};
78466+} __no_const;
78467
78468 extern bool frontswap_enabled;
78469 extern struct frontswap_ops *
78470diff --git a/include/linux/fs.h b/include/linux/fs.h
78471index 23b2a35..8764ab7 100644
78472--- a/include/linux/fs.h
78473+++ b/include/linux/fs.h
78474@@ -426,7 +426,7 @@ struct address_space {
78475 spinlock_t private_lock; /* for use by the address_space */
78476 struct list_head private_list; /* ditto */
78477 void *private_data; /* ditto */
78478-} __attribute__((aligned(sizeof(long))));
78479+} __attribute__((aligned(sizeof(long)))) __randomize_layout;
78480 /*
78481 * On most architectures that alignment is already the case; but
78482 * must be enforced here for CRIS, to let the least significant bit
78483@@ -469,7 +469,7 @@ struct block_device {
78484 int bd_fsfreeze_count;
78485 /* Mutex for freeze */
78486 struct mutex bd_fsfreeze_mutex;
78487-};
78488+} __randomize_layout;
78489
78490 /*
78491 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
78492@@ -613,7 +613,7 @@ struct inode {
78493 atomic_t i_readcount; /* struct files open RO */
78494 #endif
78495 void *i_private; /* fs or device private pointer */
78496-};
78497+} __randomize_layout;
78498
78499 static inline int inode_unhashed(struct inode *inode)
78500 {
78501@@ -812,7 +812,7 @@ struct file {
78502 #ifdef CONFIG_DEBUG_WRITECOUNT
78503 unsigned long f_mnt_write_state;
78504 #endif
78505-} __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
78506+} __attribute__((aligned(4))) __randomize_layout; /* lest something weird decides that 2 is OK */
78507
78508 struct file_handle {
78509 __u32 handle_bytes;
78510@@ -982,7 +982,7 @@ struct file_lock {
78511 int state; /* state of grant or error if -ve */
78512 } afs;
78513 } fl_u;
78514-};
78515+} __randomize_layout;
78516
78517 /* The following constant reflects the upper bound of the file/locking space */
78518 #ifndef OFFSET_MAX
78519@@ -1329,7 +1329,7 @@ struct super_block {
78520 struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
78521 struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
78522 struct rcu_head rcu;
78523-};
78524+} __randomize_layout;
78525
78526 extern struct timespec current_fs_time(struct super_block *sb);
78527
78528@@ -1551,7 +1551,8 @@ struct file_operations {
78529 long (*fallocate)(struct file *file, int mode, loff_t offset,
78530 loff_t len);
78531 int (*show_fdinfo)(struct seq_file *m, struct file *f);
78532-};
78533+} __do_const __randomize_layout;
78534+typedef struct file_operations __no_const file_operations_no_const;
78535
78536 struct inode_operations {
78537 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
78538@@ -2820,4 +2821,14 @@ static inline bool dir_relax(struct inode *inode)
78539 return !IS_DEADDIR(inode);
78540 }
78541
78542+static inline bool is_sidechannel_device(const struct inode *inode)
78543+{
78544+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
78545+ umode_t mode = inode->i_mode;
78546+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
78547+#else
78548+ return false;
78549+#endif
78550+}
78551+
78552 #endif /* _LINUX_FS_H */
78553diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
78554index 0efc3e6..fd23610 100644
78555--- a/include/linux/fs_struct.h
78556+++ b/include/linux/fs_struct.h
78557@@ -6,13 +6,13 @@
78558 #include <linux/seqlock.h>
78559
78560 struct fs_struct {
78561- int users;
78562+ atomic_t users;
78563 spinlock_t lock;
78564 seqcount_t seq;
78565 int umask;
78566 int in_exec;
78567 struct path root, pwd;
78568-};
78569+} __randomize_layout;
78570
78571 extern struct kmem_cache *fs_cachep;
78572
78573diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
78574index 7714849..a4a5c7a 100644
78575--- a/include/linux/fscache-cache.h
78576+++ b/include/linux/fscache-cache.h
78577@@ -113,7 +113,7 @@ struct fscache_operation {
78578 fscache_operation_release_t release;
78579 };
78580
78581-extern atomic_t fscache_op_debug_id;
78582+extern atomic_unchecked_t fscache_op_debug_id;
78583 extern void fscache_op_work_func(struct work_struct *work);
78584
78585 extern void fscache_enqueue_operation(struct fscache_operation *);
78586@@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
78587 INIT_WORK(&op->work, fscache_op_work_func);
78588 atomic_set(&op->usage, 1);
78589 op->state = FSCACHE_OP_ST_INITIALISED;
78590- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
78591+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
78592 op->processor = processor;
78593 op->release = release;
78594 INIT_LIST_HEAD(&op->pend_link);
78595diff --git a/include/linux/fscache.h b/include/linux/fscache.h
78596index 115bb81..e7b812b 100644
78597--- a/include/linux/fscache.h
78598+++ b/include/linux/fscache.h
78599@@ -152,7 +152,7 @@ struct fscache_cookie_def {
78600 * - this is mandatory for any object that may have data
78601 */
78602 void (*now_uncached)(void *cookie_netfs_data);
78603-};
78604+} __do_const;
78605
78606 /*
78607 * fscache cached network filesystem type
78608diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
78609index 1c804b0..1432c2b 100644
78610--- a/include/linux/fsnotify.h
78611+++ b/include/linux/fsnotify.h
78612@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
78613 struct inode *inode = file_inode(file);
78614 __u32 mask = FS_ACCESS;
78615
78616+ if (is_sidechannel_device(inode))
78617+ return;
78618+
78619 if (S_ISDIR(inode->i_mode))
78620 mask |= FS_ISDIR;
78621
78622@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
78623 struct inode *inode = file_inode(file);
78624 __u32 mask = FS_MODIFY;
78625
78626+ if (is_sidechannel_device(inode))
78627+ return;
78628+
78629 if (S_ISDIR(inode->i_mode))
78630 mask |= FS_ISDIR;
78631
78632@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
78633 */
78634 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
78635 {
78636- return kstrdup(name, GFP_KERNEL);
78637+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
78638 }
78639
78640 /*
78641diff --git a/include/linux/genhd.h b/include/linux/genhd.h
78642index 9f3c275..8bdff5d 100644
78643--- a/include/linux/genhd.h
78644+++ b/include/linux/genhd.h
78645@@ -194,7 +194,7 @@ struct gendisk {
78646 struct kobject *slave_dir;
78647
78648 struct timer_rand_state *random;
78649- atomic_t sync_io; /* RAID */
78650+ atomic_unchecked_t sync_io; /* RAID */
78651 struct disk_events *ev;
78652 #ifdef CONFIG_BLK_DEV_INTEGRITY
78653 struct blk_integrity *integrity;
78654@@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
78655 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
78656
78657 /* drivers/char/random.c */
78658-extern void add_disk_randomness(struct gendisk *disk);
78659+extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
78660 extern void rand_initialize_disk(struct gendisk *disk);
78661
78662 static inline sector_t get_start_sect(struct block_device *bdev)
78663diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
78664index c0894dd..2fbf10c 100644
78665--- a/include/linux/genl_magic_func.h
78666+++ b/include/linux/genl_magic_func.h
78667@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
78668 },
78669
78670 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
78671-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
78672+static struct genl_ops ZZZ_genl_ops[] = {
78673 #include GENL_MAGIC_INCLUDE_FILE
78674 };
78675
78676diff --git a/include/linux/gfp.h b/include/linux/gfp.h
78677index 39b81dc..819dc51 100644
78678--- a/include/linux/gfp.h
78679+++ b/include/linux/gfp.h
78680@@ -36,6 +36,13 @@ struct vm_area_struct;
78681 #define ___GFP_NO_KSWAPD 0x400000u
78682 #define ___GFP_OTHER_NODE 0x800000u
78683 #define ___GFP_WRITE 0x1000000u
78684+
78685+#ifdef CONFIG_PAX_USERCOPY_SLABS
78686+#define ___GFP_USERCOPY 0x2000000u
78687+#else
78688+#define ___GFP_USERCOPY 0
78689+#endif
78690+
78691 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
78692
78693 /*
78694@@ -93,6 +100,7 @@ struct vm_area_struct;
78695 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
78696 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
78697 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
78698+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
78699
78700 /*
78701 * This may seem redundant, but it's a way of annotating false positives vs.
78702@@ -100,7 +108,7 @@ struct vm_area_struct;
78703 */
78704 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
78705
78706-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
78707+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
78708 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
78709
78710 /* This equals 0, but use constants in case they ever change */
78711@@ -158,6 +166,8 @@ struct vm_area_struct;
78712 /* 4GB DMA on some platforms */
78713 #define GFP_DMA32 __GFP_DMA32
78714
78715+#define GFP_USERCOPY __GFP_USERCOPY
78716+
78717 /* Convert GFP flags to their corresponding migrate type */
78718 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
78719 {
78720diff --git a/include/linux/gracl.h b/include/linux/gracl.h
78721new file mode 100644
78722index 0000000..edb2cb6
78723--- /dev/null
78724+++ b/include/linux/gracl.h
78725@@ -0,0 +1,340 @@
78726+#ifndef GR_ACL_H
78727+#define GR_ACL_H
78728+
78729+#include <linux/grdefs.h>
78730+#include <linux/resource.h>
78731+#include <linux/capability.h>
78732+#include <linux/dcache.h>
78733+#include <asm/resource.h>
78734+
78735+/* Major status information */
78736+
78737+#define GR_VERSION "grsecurity 3.0"
78738+#define GRSECURITY_VERSION 0x3000
78739+
78740+enum {
78741+ GR_SHUTDOWN = 0,
78742+ GR_ENABLE = 1,
78743+ GR_SPROLE = 2,
78744+ GR_OLDRELOAD = 3,
78745+ GR_SEGVMOD = 4,
78746+ GR_STATUS = 5,
78747+ GR_UNSPROLE = 6,
78748+ GR_PASSSET = 7,
78749+ GR_SPROLEPAM = 8,
78750+ GR_RELOAD = 9,
78751+};
78752+
78753+/* Password setup definitions
78754+ * kernel/grhash.c */
78755+enum {
78756+ GR_PW_LEN = 128,
78757+ GR_SALT_LEN = 16,
78758+ GR_SHA_LEN = 32,
78759+};
78760+
78761+enum {
78762+ GR_SPROLE_LEN = 64,
78763+};
78764+
78765+enum {
78766+ GR_NO_GLOB = 0,
78767+ GR_REG_GLOB,
78768+ GR_CREATE_GLOB
78769+};
78770+
78771+#define GR_NLIMITS 32
78772+
78773+/* Begin Data Structures */
78774+
78775+struct sprole_pw {
78776+ unsigned char *rolename;
78777+ unsigned char salt[GR_SALT_LEN];
78778+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
78779+};
78780+
78781+struct name_entry {
78782+ __u32 key;
78783+ ino_t inode;
78784+ dev_t device;
78785+ char *name;
78786+ __u16 len;
78787+ __u8 deleted;
78788+ struct name_entry *prev;
78789+ struct name_entry *next;
78790+};
78791+
78792+struct inodev_entry {
78793+ struct name_entry *nentry;
78794+ struct inodev_entry *prev;
78795+ struct inodev_entry *next;
78796+};
78797+
78798+struct acl_role_db {
78799+ struct acl_role_label **r_hash;
78800+ __u32 r_size;
78801+};
78802+
78803+struct inodev_db {
78804+ struct inodev_entry **i_hash;
78805+ __u32 i_size;
78806+};
78807+
78808+struct name_db {
78809+ struct name_entry **n_hash;
78810+ __u32 n_size;
78811+};
78812+
78813+struct crash_uid {
78814+ uid_t uid;
78815+ unsigned long expires;
78816+};
78817+
78818+struct gr_hash_struct {
78819+ void **table;
78820+ void **nametable;
78821+ void *first;
78822+ __u32 table_size;
78823+ __u32 used_size;
78824+ int type;
78825+};
78826+
78827+/* Userspace Grsecurity ACL data structures */
78828+
78829+struct acl_subject_label {
78830+ char *filename;
78831+ ino_t inode;
78832+ dev_t device;
78833+ __u32 mode;
78834+ kernel_cap_t cap_mask;
78835+ kernel_cap_t cap_lower;
78836+ kernel_cap_t cap_invert_audit;
78837+
78838+ struct rlimit res[GR_NLIMITS];
78839+ __u32 resmask;
78840+
78841+ __u8 user_trans_type;
78842+ __u8 group_trans_type;
78843+ uid_t *user_transitions;
78844+ gid_t *group_transitions;
78845+ __u16 user_trans_num;
78846+ __u16 group_trans_num;
78847+
78848+ __u32 sock_families[2];
78849+ __u32 ip_proto[8];
78850+ __u32 ip_type;
78851+ struct acl_ip_label **ips;
78852+ __u32 ip_num;
78853+ __u32 inaddr_any_override;
78854+
78855+ __u32 crashes;
78856+ unsigned long expires;
78857+
78858+ struct acl_subject_label *parent_subject;
78859+ struct gr_hash_struct *hash;
78860+ struct acl_subject_label *prev;
78861+ struct acl_subject_label *next;
78862+
78863+ struct acl_object_label **obj_hash;
78864+ __u32 obj_hash_size;
78865+ __u16 pax_flags;
78866+};
78867+
78868+struct role_allowed_ip {
78869+ __u32 addr;
78870+ __u32 netmask;
78871+
78872+ struct role_allowed_ip *prev;
78873+ struct role_allowed_ip *next;
78874+};
78875+
78876+struct role_transition {
78877+ char *rolename;
78878+
78879+ struct role_transition *prev;
78880+ struct role_transition *next;
78881+};
78882+
78883+struct acl_role_label {
78884+ char *rolename;
78885+ uid_t uidgid;
78886+ __u16 roletype;
78887+
78888+ __u16 auth_attempts;
78889+ unsigned long expires;
78890+
78891+ struct acl_subject_label *root_label;
78892+ struct gr_hash_struct *hash;
78893+
78894+ struct acl_role_label *prev;
78895+ struct acl_role_label *next;
78896+
78897+ struct role_transition *transitions;
78898+ struct role_allowed_ip *allowed_ips;
78899+ uid_t *domain_children;
78900+ __u16 domain_child_num;
78901+
78902+ umode_t umask;
78903+
78904+ struct acl_subject_label **subj_hash;
78905+ __u32 subj_hash_size;
78906+};
78907+
78908+struct user_acl_role_db {
78909+ struct acl_role_label **r_table;
78910+ __u32 num_pointers; /* Number of allocations to track */
78911+ __u32 num_roles; /* Number of roles */
78912+ __u32 num_domain_children; /* Number of domain children */
78913+ __u32 num_subjects; /* Number of subjects */
78914+ __u32 num_objects; /* Number of objects */
78915+};
78916+
78917+struct acl_object_label {
78918+ char *filename;
78919+ ino_t inode;
78920+ dev_t device;
78921+ __u32 mode;
78922+
78923+ struct acl_subject_label *nested;
78924+ struct acl_object_label *globbed;
78925+
78926+ /* next two structures not used */
78927+
78928+ struct acl_object_label *prev;
78929+ struct acl_object_label *next;
78930+};
78931+
78932+struct acl_ip_label {
78933+ char *iface;
78934+ __u32 addr;
78935+ __u32 netmask;
78936+ __u16 low, high;
78937+ __u8 mode;
78938+ __u32 type;
78939+ __u32 proto[8];
78940+
78941+ /* next two structures not used */
78942+
78943+ struct acl_ip_label *prev;
78944+ struct acl_ip_label *next;
78945+};
78946+
78947+struct gr_arg {
78948+ struct user_acl_role_db role_db;
78949+ unsigned char pw[GR_PW_LEN];
78950+ unsigned char salt[GR_SALT_LEN];
78951+ unsigned char sum[GR_SHA_LEN];
78952+ unsigned char sp_role[GR_SPROLE_LEN];
78953+ struct sprole_pw *sprole_pws;
78954+ dev_t segv_device;
78955+ ino_t segv_inode;
78956+ uid_t segv_uid;
78957+ __u16 num_sprole_pws;
78958+ __u16 mode;
78959+};
78960+
78961+struct gr_arg_wrapper {
78962+ struct gr_arg *arg;
78963+ __u32 version;
78964+ __u32 size;
78965+};
78966+
78967+struct subject_map {
78968+ struct acl_subject_label *user;
78969+ struct acl_subject_label *kernel;
78970+ struct subject_map *prev;
78971+ struct subject_map *next;
78972+};
78973+
78974+struct acl_subj_map_db {
78975+ struct subject_map **s_hash;
78976+ __u32 s_size;
78977+};
78978+
78979+struct gr_policy_state {
78980+ struct sprole_pw **acl_special_roles;
78981+ __u16 num_sprole_pws;
78982+ struct acl_role_label *kernel_role;
78983+ struct acl_role_label *role_list;
78984+ struct acl_role_label *default_role;
78985+ struct acl_role_db acl_role_set;
78986+ struct acl_subj_map_db subj_map_set;
78987+ struct name_db name_set;
78988+ struct inodev_db inodev_set;
78989+};
78990+
78991+struct gr_alloc_state {
78992+ unsigned long alloc_stack_next;
78993+ unsigned long alloc_stack_size;
78994+ void **alloc_stack;
78995+};
78996+
78997+struct gr_reload_state {
78998+ struct gr_policy_state oldpolicy;
78999+ struct gr_alloc_state oldalloc;
79000+ struct gr_policy_state newpolicy;
79001+ struct gr_alloc_state newalloc;
79002+ struct gr_policy_state *oldpolicy_ptr;
79003+ struct gr_alloc_state *oldalloc_ptr;
79004+ unsigned char oldmode;
79005+};
79006+
79007+/* End Data Structures Section */
79008+
79009+/* Hash functions generated by empirical testing by Brad Spengler
79010+ Makes good use of the low bits of the inode. Generally 0-1 times
79011+ in loop for successful match. 0-3 for unsuccessful match.
79012+ Shift/add algorithm with modulus of table size and an XOR*/
79013+
79014+static __inline__ unsigned int
79015+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
79016+{
79017+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
79018+}
79019+
79020+ static __inline__ unsigned int
79021+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
79022+{
79023+ return ((const unsigned long)userp % sz);
79024+}
79025+
79026+static __inline__ unsigned int
79027+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
79028+{
79029+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
79030+}
79031+
79032+static __inline__ unsigned int
79033+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
79034+{
79035+ return full_name_hash((const unsigned char *)name, len) % sz;
79036+}
79037+
79038+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
79039+ subj = NULL; \
79040+ iter = 0; \
79041+ while (iter < role->subj_hash_size) { \
79042+ if (subj == NULL) \
79043+ subj = role->subj_hash[iter]; \
79044+ if (subj == NULL) { \
79045+ iter++; \
79046+ continue; \
79047+ }
79048+
79049+#define FOR_EACH_SUBJECT_END(subj,iter) \
79050+ subj = subj->next; \
79051+ if (subj == NULL) \
79052+ iter++; \
79053+ }
79054+
79055+
79056+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
79057+ subj = role->hash->first; \
79058+ while (subj != NULL) {
79059+
79060+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
79061+ subj = subj->next; \
79062+ }
79063+
79064+#endif
79065+
79066diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
79067new file mode 100644
79068index 0000000..33ebd1f
79069--- /dev/null
79070+++ b/include/linux/gracl_compat.h
79071@@ -0,0 +1,156 @@
79072+#ifndef GR_ACL_COMPAT_H
79073+#define GR_ACL_COMPAT_H
79074+
79075+#include <linux/resource.h>
79076+#include <asm/resource.h>
79077+
79078+struct sprole_pw_compat {
79079+ compat_uptr_t rolename;
79080+ unsigned char salt[GR_SALT_LEN];
79081+ unsigned char sum[GR_SHA_LEN];
79082+};
79083+
79084+struct gr_hash_struct_compat {
79085+ compat_uptr_t table;
79086+ compat_uptr_t nametable;
79087+ compat_uptr_t first;
79088+ __u32 table_size;
79089+ __u32 used_size;
79090+ int type;
79091+};
79092+
79093+struct acl_subject_label_compat {
79094+ compat_uptr_t filename;
79095+ compat_ino_t inode;
79096+ __u32 device;
79097+ __u32 mode;
79098+ kernel_cap_t cap_mask;
79099+ kernel_cap_t cap_lower;
79100+ kernel_cap_t cap_invert_audit;
79101+
79102+ struct compat_rlimit res[GR_NLIMITS];
79103+ __u32 resmask;
79104+
79105+ __u8 user_trans_type;
79106+ __u8 group_trans_type;
79107+ compat_uptr_t user_transitions;
79108+ compat_uptr_t group_transitions;
79109+ __u16 user_trans_num;
79110+ __u16 group_trans_num;
79111+
79112+ __u32 sock_families[2];
79113+ __u32 ip_proto[8];
79114+ __u32 ip_type;
79115+ compat_uptr_t ips;
79116+ __u32 ip_num;
79117+ __u32 inaddr_any_override;
79118+
79119+ __u32 crashes;
79120+ compat_ulong_t expires;
79121+
79122+ compat_uptr_t parent_subject;
79123+ compat_uptr_t hash;
79124+ compat_uptr_t prev;
79125+ compat_uptr_t next;
79126+
79127+ compat_uptr_t obj_hash;
79128+ __u32 obj_hash_size;
79129+ __u16 pax_flags;
79130+};
79131+
79132+struct role_allowed_ip_compat {
79133+ __u32 addr;
79134+ __u32 netmask;
79135+
79136+ compat_uptr_t prev;
79137+ compat_uptr_t next;
79138+};
79139+
79140+struct role_transition_compat {
79141+ compat_uptr_t rolename;
79142+
79143+ compat_uptr_t prev;
79144+ compat_uptr_t next;
79145+};
79146+
79147+struct acl_role_label_compat {
79148+ compat_uptr_t rolename;
79149+ uid_t uidgid;
79150+ __u16 roletype;
79151+
79152+ __u16 auth_attempts;
79153+ compat_ulong_t expires;
79154+
79155+ compat_uptr_t root_label;
79156+ compat_uptr_t hash;
79157+
79158+ compat_uptr_t prev;
79159+ compat_uptr_t next;
79160+
79161+ compat_uptr_t transitions;
79162+ compat_uptr_t allowed_ips;
79163+ compat_uptr_t domain_children;
79164+ __u16 domain_child_num;
79165+
79166+ umode_t umask;
79167+
79168+ compat_uptr_t subj_hash;
79169+ __u32 subj_hash_size;
79170+};
79171+
79172+struct user_acl_role_db_compat {
79173+ compat_uptr_t r_table;
79174+ __u32 num_pointers;
79175+ __u32 num_roles;
79176+ __u32 num_domain_children;
79177+ __u32 num_subjects;
79178+ __u32 num_objects;
79179+};
79180+
79181+struct acl_object_label_compat {
79182+ compat_uptr_t filename;
79183+ compat_ino_t inode;
79184+ __u32 device;
79185+ __u32 mode;
79186+
79187+ compat_uptr_t nested;
79188+ compat_uptr_t globbed;
79189+
79190+ compat_uptr_t prev;
79191+ compat_uptr_t next;
79192+};
79193+
79194+struct acl_ip_label_compat {
79195+ compat_uptr_t iface;
79196+ __u32 addr;
79197+ __u32 netmask;
79198+ __u16 low, high;
79199+ __u8 mode;
79200+ __u32 type;
79201+ __u32 proto[8];
79202+
79203+ compat_uptr_t prev;
79204+ compat_uptr_t next;
79205+};
79206+
79207+struct gr_arg_compat {
79208+ struct user_acl_role_db_compat role_db;
79209+ unsigned char pw[GR_PW_LEN];
79210+ unsigned char salt[GR_SALT_LEN];
79211+ unsigned char sum[GR_SHA_LEN];
79212+ unsigned char sp_role[GR_SPROLE_LEN];
79213+ compat_uptr_t sprole_pws;
79214+ __u32 segv_device;
79215+ compat_ino_t segv_inode;
79216+ uid_t segv_uid;
79217+ __u16 num_sprole_pws;
79218+ __u16 mode;
79219+};
79220+
79221+struct gr_arg_wrapper_compat {
79222+ compat_uptr_t arg;
79223+ __u32 version;
79224+ __u32 size;
79225+};
79226+
79227+#endif
79228diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
79229new file mode 100644
79230index 0000000..323ecf2
79231--- /dev/null
79232+++ b/include/linux/gralloc.h
79233@@ -0,0 +1,9 @@
79234+#ifndef __GRALLOC_H
79235+#define __GRALLOC_H
79236+
79237+void acl_free_all(void);
79238+int acl_alloc_stack_init(unsigned long size);
79239+void *acl_alloc(unsigned long len);
79240+void *acl_alloc_num(unsigned long num, unsigned long len);
79241+
79242+#endif
79243diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
79244new file mode 100644
79245index 0000000..be66033
79246--- /dev/null
79247+++ b/include/linux/grdefs.h
79248@@ -0,0 +1,140 @@
79249+#ifndef GRDEFS_H
79250+#define GRDEFS_H
79251+
79252+/* Begin grsecurity status declarations */
79253+
79254+enum {
79255+ GR_READY = 0x01,
79256+ GR_STATUS_INIT = 0x00 // disabled state
79257+};
79258+
79259+/* Begin ACL declarations */
79260+
79261+/* Role flags */
79262+
79263+enum {
79264+ GR_ROLE_USER = 0x0001,
79265+ GR_ROLE_GROUP = 0x0002,
79266+ GR_ROLE_DEFAULT = 0x0004,
79267+ GR_ROLE_SPECIAL = 0x0008,
79268+ GR_ROLE_AUTH = 0x0010,
79269+ GR_ROLE_NOPW = 0x0020,
79270+ GR_ROLE_GOD = 0x0040,
79271+ GR_ROLE_LEARN = 0x0080,
79272+ GR_ROLE_TPE = 0x0100,
79273+ GR_ROLE_DOMAIN = 0x0200,
79274+ GR_ROLE_PAM = 0x0400,
79275+ GR_ROLE_PERSIST = 0x0800
79276+};
79277+
79278+/* ACL Subject and Object mode flags */
79279+enum {
79280+ GR_DELETED = 0x80000000
79281+};
79282+
79283+/* ACL Object-only mode flags */
79284+enum {
79285+ GR_READ = 0x00000001,
79286+ GR_APPEND = 0x00000002,
79287+ GR_WRITE = 0x00000004,
79288+ GR_EXEC = 0x00000008,
79289+ GR_FIND = 0x00000010,
79290+ GR_INHERIT = 0x00000020,
79291+ GR_SETID = 0x00000040,
79292+ GR_CREATE = 0x00000080,
79293+ GR_DELETE = 0x00000100,
79294+ GR_LINK = 0x00000200,
79295+ GR_AUDIT_READ = 0x00000400,
79296+ GR_AUDIT_APPEND = 0x00000800,
79297+ GR_AUDIT_WRITE = 0x00001000,
79298+ GR_AUDIT_EXEC = 0x00002000,
79299+ GR_AUDIT_FIND = 0x00004000,
79300+ GR_AUDIT_INHERIT= 0x00008000,
79301+ GR_AUDIT_SETID = 0x00010000,
79302+ GR_AUDIT_CREATE = 0x00020000,
79303+ GR_AUDIT_DELETE = 0x00040000,
79304+ GR_AUDIT_LINK = 0x00080000,
79305+ GR_PTRACERD = 0x00100000,
79306+ GR_NOPTRACE = 0x00200000,
79307+ GR_SUPPRESS = 0x00400000,
79308+ GR_NOLEARN = 0x00800000,
79309+ GR_INIT_TRANSFER= 0x01000000
79310+};
79311+
79312+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
79313+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
79314+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
79315+
79316+/* ACL subject-only mode flags */
79317+enum {
79318+ GR_KILL = 0x00000001,
79319+ GR_VIEW = 0x00000002,
79320+ GR_PROTECTED = 0x00000004,
79321+ GR_LEARN = 0x00000008,
79322+ GR_OVERRIDE = 0x00000010,
79323+ /* just a placeholder, this mode is only used in userspace */
79324+ GR_DUMMY = 0x00000020,
79325+ GR_PROTSHM = 0x00000040,
79326+ GR_KILLPROC = 0x00000080,
79327+ GR_KILLIPPROC = 0x00000100,
79328+ /* just a placeholder, this mode is only used in userspace */
79329+ GR_NOTROJAN = 0x00000200,
79330+ GR_PROTPROCFD = 0x00000400,
79331+ GR_PROCACCT = 0x00000800,
79332+ GR_RELAXPTRACE = 0x00001000,
79333+ //GR_NESTED = 0x00002000,
79334+ GR_INHERITLEARN = 0x00004000,
79335+ GR_PROCFIND = 0x00008000,
79336+ GR_POVERRIDE = 0x00010000,
79337+ GR_KERNELAUTH = 0x00020000,
79338+ GR_ATSECURE = 0x00040000,
79339+ GR_SHMEXEC = 0x00080000
79340+};
79341+
79342+enum {
79343+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
79344+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
79345+ GR_PAX_ENABLE_MPROTECT = 0x0004,
79346+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
79347+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
79348+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
79349+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
79350+ GR_PAX_DISABLE_MPROTECT = 0x0400,
79351+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
79352+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
79353+};
79354+
79355+enum {
79356+ GR_ID_USER = 0x01,
79357+ GR_ID_GROUP = 0x02,
79358+};
79359+
79360+enum {
79361+ GR_ID_ALLOW = 0x01,
79362+ GR_ID_DENY = 0x02,
79363+};
79364+
79365+#define GR_CRASH_RES 31
79366+#define GR_UIDTABLE_MAX 500
79367+
79368+/* begin resource learning section */
79369+enum {
79370+ GR_RLIM_CPU_BUMP = 60,
79371+ GR_RLIM_FSIZE_BUMP = 50000,
79372+ GR_RLIM_DATA_BUMP = 10000,
79373+ GR_RLIM_STACK_BUMP = 1000,
79374+ GR_RLIM_CORE_BUMP = 10000,
79375+ GR_RLIM_RSS_BUMP = 500000,
79376+ GR_RLIM_NPROC_BUMP = 1,
79377+ GR_RLIM_NOFILE_BUMP = 5,
79378+ GR_RLIM_MEMLOCK_BUMP = 50000,
79379+ GR_RLIM_AS_BUMP = 500000,
79380+ GR_RLIM_LOCKS_BUMP = 2,
79381+ GR_RLIM_SIGPENDING_BUMP = 5,
79382+ GR_RLIM_MSGQUEUE_BUMP = 10000,
79383+ GR_RLIM_NICE_BUMP = 1,
79384+ GR_RLIM_RTPRIO_BUMP = 1,
79385+ GR_RLIM_RTTIME_BUMP = 1000000
79386+};
79387+
79388+#endif
79389diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
79390new file mode 100644
79391index 0000000..d25522e
79392--- /dev/null
79393+++ b/include/linux/grinternal.h
79394@@ -0,0 +1,229 @@
79395+#ifndef __GRINTERNAL_H
79396+#define __GRINTERNAL_H
79397+
79398+#ifdef CONFIG_GRKERNSEC
79399+
79400+#include <linux/fs.h>
79401+#include <linux/mnt_namespace.h>
79402+#include <linux/nsproxy.h>
79403+#include <linux/gracl.h>
79404+#include <linux/grdefs.h>
79405+#include <linux/grmsg.h>
79406+
79407+void gr_add_learn_entry(const char *fmt, ...)
79408+ __attribute__ ((format (printf, 1, 2)));
79409+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
79410+ const struct vfsmount *mnt);
79411+__u32 gr_check_create(const struct dentry *new_dentry,
79412+ const struct dentry *parent,
79413+ const struct vfsmount *mnt, const __u32 mode);
79414+int gr_check_protected_task(const struct task_struct *task);
79415+__u32 to_gr_audit(const __u32 reqmode);
79416+int gr_set_acls(const int type);
79417+int gr_acl_is_enabled(void);
79418+char gr_roletype_to_char(void);
79419+
79420+void gr_handle_alertkill(struct task_struct *task);
79421+char *gr_to_filename(const struct dentry *dentry,
79422+ const struct vfsmount *mnt);
79423+char *gr_to_filename1(const struct dentry *dentry,
79424+ const struct vfsmount *mnt);
79425+char *gr_to_filename2(const struct dentry *dentry,
79426+ const struct vfsmount *mnt);
79427+char *gr_to_filename3(const struct dentry *dentry,
79428+ const struct vfsmount *mnt);
79429+
79430+extern int grsec_enable_ptrace_readexec;
79431+extern int grsec_enable_harden_ptrace;
79432+extern int grsec_enable_link;
79433+extern int grsec_enable_fifo;
79434+extern int grsec_enable_execve;
79435+extern int grsec_enable_shm;
79436+extern int grsec_enable_execlog;
79437+extern int grsec_enable_signal;
79438+extern int grsec_enable_audit_ptrace;
79439+extern int grsec_enable_forkfail;
79440+extern int grsec_enable_time;
79441+extern int grsec_enable_rofs;
79442+extern int grsec_deny_new_usb;
79443+extern int grsec_enable_chroot_shmat;
79444+extern int grsec_enable_chroot_mount;
79445+extern int grsec_enable_chroot_double;
79446+extern int grsec_enable_chroot_pivot;
79447+extern int grsec_enable_chroot_chdir;
79448+extern int grsec_enable_chroot_chmod;
79449+extern int grsec_enable_chroot_mknod;
79450+extern int grsec_enable_chroot_fchdir;
79451+extern int grsec_enable_chroot_nice;
79452+extern int grsec_enable_chroot_execlog;
79453+extern int grsec_enable_chroot_caps;
79454+extern int grsec_enable_chroot_sysctl;
79455+extern int grsec_enable_chroot_unix;
79456+extern int grsec_enable_symlinkown;
79457+extern kgid_t grsec_symlinkown_gid;
79458+extern int grsec_enable_tpe;
79459+extern kgid_t grsec_tpe_gid;
79460+extern int grsec_enable_tpe_all;
79461+extern int grsec_enable_tpe_invert;
79462+extern int grsec_enable_socket_all;
79463+extern kgid_t grsec_socket_all_gid;
79464+extern int grsec_enable_socket_client;
79465+extern kgid_t grsec_socket_client_gid;
79466+extern int grsec_enable_socket_server;
79467+extern kgid_t grsec_socket_server_gid;
79468+extern kgid_t grsec_audit_gid;
79469+extern int grsec_enable_group;
79470+extern int grsec_enable_log_rwxmaps;
79471+extern int grsec_enable_mount;
79472+extern int grsec_enable_chdir;
79473+extern int grsec_resource_logging;
79474+extern int grsec_enable_blackhole;
79475+extern int grsec_lastack_retries;
79476+extern int grsec_enable_brute;
79477+extern int grsec_enable_harden_ipc;
79478+extern int grsec_lock;
79479+
79480+extern spinlock_t grsec_alert_lock;
79481+extern unsigned long grsec_alert_wtime;
79482+extern unsigned long grsec_alert_fyet;
79483+
79484+extern spinlock_t grsec_audit_lock;
79485+
79486+extern rwlock_t grsec_exec_file_lock;
79487+
79488+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
79489+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
79490+ (tsk)->exec_file->f_path.mnt) : "/")
79491+
79492+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
79493+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
79494+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
79495+
79496+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
79497+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
79498+ (tsk)->exec_file->f_path.mnt) : "/")
79499+
79500+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
79501+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
79502+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
79503+
79504+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
79505+
79506+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
79507+
79508+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
79509+{
79510+ if (file1 && file2) {
79511+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
79512+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
79513+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
79514+ return true;
79515+ }
79516+
79517+ return false;
79518+}
79519+
79520+#define GR_CHROOT_CAPS {{ \
79521+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
79522+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
79523+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
79524+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
79525+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
79526+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
79527+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
79528+
79529+#define security_learn(normal_msg,args...) \
79530+({ \
79531+ read_lock(&grsec_exec_file_lock); \
79532+ gr_add_learn_entry(normal_msg "\n", ## args); \
79533+ read_unlock(&grsec_exec_file_lock); \
79534+})
79535+
79536+enum {
79537+ GR_DO_AUDIT,
79538+ GR_DONT_AUDIT,
79539+ /* used for non-audit messages that we shouldn't kill the task on */
79540+ GR_DONT_AUDIT_GOOD
79541+};
79542+
79543+enum {
79544+ GR_TTYSNIFF,
79545+ GR_RBAC,
79546+ GR_RBAC_STR,
79547+ GR_STR_RBAC,
79548+ GR_RBAC_MODE2,
79549+ GR_RBAC_MODE3,
79550+ GR_FILENAME,
79551+ GR_SYSCTL_HIDDEN,
79552+ GR_NOARGS,
79553+ GR_ONE_INT,
79554+ GR_ONE_INT_TWO_STR,
79555+ GR_ONE_STR,
79556+ GR_STR_INT,
79557+ GR_TWO_STR_INT,
79558+ GR_TWO_INT,
79559+ GR_TWO_U64,
79560+ GR_THREE_INT,
79561+ GR_FIVE_INT_TWO_STR,
79562+ GR_TWO_STR,
79563+ GR_THREE_STR,
79564+ GR_FOUR_STR,
79565+ GR_STR_FILENAME,
79566+ GR_FILENAME_STR,
79567+ GR_FILENAME_TWO_INT,
79568+ GR_FILENAME_TWO_INT_STR,
79569+ GR_TEXTREL,
79570+ GR_PTRACE,
79571+ GR_RESOURCE,
79572+ GR_CAP,
79573+ GR_SIG,
79574+ GR_SIG2,
79575+ GR_CRASH1,
79576+ GR_CRASH2,
79577+ GR_PSACCT,
79578+ GR_RWXMAP,
79579+ GR_RWXMAPVMA
79580+};
79581+
79582+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
79583+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
79584+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
79585+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
79586+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
79587+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
79588+#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)
79589+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
79590+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
79591+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
79592+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
79593+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
79594+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
79595+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
79596+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
79597+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
79598+#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)
79599+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
79600+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
79601+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
79602+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
79603+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
79604+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
79605+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
79606+#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)
79607+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
79608+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
79609+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
79610+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
79611+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
79612+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
79613+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
79614+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
79615+#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)
79616+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
79617+#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
79618+
79619+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
79620+
79621+#endif
79622+
79623+#endif
79624diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
79625new file mode 100644
79626index 0000000..ba93581
79627--- /dev/null
79628+++ b/include/linux/grmsg.h
79629@@ -0,0 +1,116 @@
79630+#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"
79631+#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"
79632+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
79633+#define GR_STOPMOD_MSG "denied modification of module state by "
79634+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
79635+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
79636+#define GR_IOPERM_MSG "denied use of ioperm() by "
79637+#define GR_IOPL_MSG "denied use of iopl() by "
79638+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
79639+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
79640+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
79641+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
79642+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
79643+#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"
79644+#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"
79645+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
79646+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
79647+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
79648+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
79649+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
79650+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
79651+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
79652+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
79653+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
79654+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
79655+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
79656+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
79657+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
79658+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
79659+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
79660+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
79661+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
79662+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
79663+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
79664+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
79665+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
79666+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
79667+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
79668+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
79669+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
79670+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
79671+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
79672+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
79673+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
79674+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
79675+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
79676+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
79677+#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
79678+#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
79679+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
79680+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
79681+#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"
79682+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
79683+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
79684+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
79685+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
79686+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
79687+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
79688+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
79689+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
79690+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
79691+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
79692+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
79693+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
79694+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
79695+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
79696+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
79697+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
79698+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
79699+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
79700+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
79701+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
79702+#define GR_FAILFORK_MSG "failed fork with errno %s by "
79703+#define GR_NICE_CHROOT_MSG "denied priority change by "
79704+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
79705+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
79706+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
79707+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
79708+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
79709+#define GR_TIME_MSG "time set by "
79710+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
79711+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
79712+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
79713+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
79714+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
79715+#define GR_BIND_MSG "denied bind() by "
79716+#define GR_CONNECT_MSG "denied connect() by "
79717+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
79718+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
79719+#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"
79720+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
79721+#define GR_CAP_ACL_MSG "use of %s denied for "
79722+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
79723+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
79724+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
79725+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
79726+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
79727+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
79728+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
79729+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
79730+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
79731+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
79732+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
79733+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
79734+#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
79735+#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
79736+#define GR_VM86_MSG "denied use of vm86 by "
79737+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
79738+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
79739+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
79740+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
79741+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
79742+#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 "
79743+#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 "
79744+#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
79745+#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
79746diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
79747new file mode 100644
79748index 0000000..f2d8c6c
79749--- /dev/null
79750+++ b/include/linux/grsecurity.h
79751@@ -0,0 +1,248 @@
79752+#ifndef GR_SECURITY_H
79753+#define GR_SECURITY_H
79754+#include <linux/fs.h>
79755+#include <linux/fs_struct.h>
79756+#include <linux/binfmts.h>
79757+#include <linux/gracl.h>
79758+
79759+/* notify of brain-dead configs */
79760+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
79761+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
79762+#endif
79763+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
79764+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
79765+#endif
79766+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
79767+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
79768+#endif
79769+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
79770+#error "CONFIG_PAX enabled, but no PaX options are enabled."
79771+#endif
79772+
79773+int gr_handle_new_usb(void);
79774+
79775+void gr_handle_brute_attach(int dumpable);
79776+void gr_handle_brute_check(void);
79777+void gr_handle_kernel_exploit(void);
79778+
79779+char gr_roletype_to_char(void);
79780+
79781+int gr_proc_is_restricted(void);
79782+
79783+int gr_acl_enable_at_secure(void);
79784+
79785+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
79786+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
79787+
79788+void gr_del_task_from_ip_table(struct task_struct *p);
79789+
79790+int gr_pid_is_chrooted(struct task_struct *p);
79791+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
79792+int gr_handle_chroot_nice(void);
79793+int gr_handle_chroot_sysctl(const int op);
79794+int gr_handle_chroot_setpriority(struct task_struct *p,
79795+ const int niceval);
79796+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
79797+int gr_handle_chroot_chroot(const struct dentry *dentry,
79798+ const struct vfsmount *mnt);
79799+void gr_handle_chroot_chdir(const struct path *path);
79800+int gr_handle_chroot_chmod(const struct dentry *dentry,
79801+ const struct vfsmount *mnt, const int mode);
79802+int gr_handle_chroot_mknod(const struct dentry *dentry,
79803+ const struct vfsmount *mnt, const int mode);
79804+int gr_handle_chroot_mount(const struct dentry *dentry,
79805+ const struct vfsmount *mnt,
79806+ const char *dev_name);
79807+int gr_handle_chroot_pivot(void);
79808+int gr_handle_chroot_unix(const pid_t pid);
79809+
79810+int gr_handle_rawio(const struct inode *inode);
79811+
79812+void gr_handle_ioperm(void);
79813+void gr_handle_iopl(void);
79814+void gr_handle_msr_write(void);
79815+
79816+umode_t gr_acl_umask(void);
79817+
79818+int gr_tpe_allow(const struct file *file);
79819+
79820+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
79821+void gr_clear_chroot_entries(struct task_struct *task);
79822+
79823+void gr_log_forkfail(const int retval);
79824+void gr_log_timechange(void);
79825+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
79826+void gr_log_chdir(const struct dentry *dentry,
79827+ const struct vfsmount *mnt);
79828+void gr_log_chroot_exec(const struct dentry *dentry,
79829+ const struct vfsmount *mnt);
79830+void gr_log_remount(const char *devname, const int retval);
79831+void gr_log_unmount(const char *devname, const int retval);
79832+void gr_log_mount(const char *from, const char *to, const int retval);
79833+void gr_log_textrel(struct vm_area_struct *vma);
79834+void gr_log_ptgnustack(struct file *file);
79835+void gr_log_rwxmmap(struct file *file);
79836+void gr_log_rwxmprotect(struct vm_area_struct *vma);
79837+
79838+int gr_handle_follow_link(const struct inode *parent,
79839+ const struct inode *inode,
79840+ const struct dentry *dentry,
79841+ const struct vfsmount *mnt);
79842+int gr_handle_fifo(const struct dentry *dentry,
79843+ const struct vfsmount *mnt,
79844+ const struct dentry *dir, const int flag,
79845+ const int acc_mode);
79846+int gr_handle_hardlink(const struct dentry *dentry,
79847+ const struct vfsmount *mnt,
79848+ struct inode *inode,
79849+ const int mode, const struct filename *to);
79850+
79851+int gr_is_capable(const int cap);
79852+int gr_is_capable_nolog(const int cap);
79853+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
79854+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
79855+
79856+void gr_copy_label(struct task_struct *tsk);
79857+void gr_handle_crash(struct task_struct *task, const int sig);
79858+int gr_handle_signal(const struct task_struct *p, const int sig);
79859+int gr_check_crash_uid(const kuid_t uid);
79860+int gr_check_protected_task(const struct task_struct *task);
79861+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
79862+int gr_acl_handle_mmap(const struct file *file,
79863+ const unsigned long prot);
79864+int gr_acl_handle_mprotect(const struct file *file,
79865+ const unsigned long prot);
79866+int gr_check_hidden_task(const struct task_struct *tsk);
79867+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
79868+ const struct vfsmount *mnt);
79869+__u32 gr_acl_handle_utime(const struct dentry *dentry,
79870+ const struct vfsmount *mnt);
79871+__u32 gr_acl_handle_access(const struct dentry *dentry,
79872+ const struct vfsmount *mnt, const int fmode);
79873+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
79874+ const struct vfsmount *mnt, umode_t *mode);
79875+__u32 gr_acl_handle_chown(const struct dentry *dentry,
79876+ const struct vfsmount *mnt);
79877+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
79878+ const struct vfsmount *mnt);
79879+__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
79880+ const struct vfsmount *mnt);
79881+int gr_handle_ptrace(struct task_struct *task, const long request);
79882+int gr_handle_proc_ptrace(struct task_struct *task);
79883+__u32 gr_acl_handle_execve(const struct dentry *dentry,
79884+ const struct vfsmount *mnt);
79885+int gr_check_crash_exec(const struct file *filp);
79886+int gr_acl_is_enabled(void);
79887+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
79888+ const kgid_t gid);
79889+int gr_set_proc_label(const struct dentry *dentry,
79890+ const struct vfsmount *mnt,
79891+ const int unsafe_flags);
79892+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
79893+ const struct vfsmount *mnt);
79894+__u32 gr_acl_handle_open(const struct dentry *dentry,
79895+ const struct vfsmount *mnt, int acc_mode);
79896+__u32 gr_acl_handle_creat(const struct dentry *dentry,
79897+ const struct dentry *p_dentry,
79898+ const struct vfsmount *p_mnt,
79899+ int open_flags, int acc_mode, const int imode);
79900+void gr_handle_create(const struct dentry *dentry,
79901+ const struct vfsmount *mnt);
79902+void gr_handle_proc_create(const struct dentry *dentry,
79903+ const struct inode *inode);
79904+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
79905+ const struct dentry *parent_dentry,
79906+ const struct vfsmount *parent_mnt,
79907+ const int mode);
79908+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
79909+ const struct dentry *parent_dentry,
79910+ const struct vfsmount *parent_mnt);
79911+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
79912+ const struct vfsmount *mnt);
79913+void gr_handle_delete(const ino_t ino, const dev_t dev);
79914+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
79915+ const struct vfsmount *mnt);
79916+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
79917+ const struct dentry *parent_dentry,
79918+ const struct vfsmount *parent_mnt,
79919+ const struct filename *from);
79920+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
79921+ const struct dentry *parent_dentry,
79922+ const struct vfsmount *parent_mnt,
79923+ const struct dentry *old_dentry,
79924+ const struct vfsmount *old_mnt, const struct filename *to);
79925+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
79926+int gr_acl_handle_rename(struct dentry *new_dentry,
79927+ struct dentry *parent_dentry,
79928+ const struct vfsmount *parent_mnt,
79929+ struct dentry *old_dentry,
79930+ struct inode *old_parent_inode,
79931+ struct vfsmount *old_mnt, const struct filename *newname);
79932+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
79933+ struct dentry *old_dentry,
79934+ struct dentry *new_dentry,
79935+ struct vfsmount *mnt, const __u8 replace);
79936+__u32 gr_check_link(const struct dentry *new_dentry,
79937+ const struct dentry *parent_dentry,
79938+ const struct vfsmount *parent_mnt,
79939+ const struct dentry *old_dentry,
79940+ const struct vfsmount *old_mnt);
79941+int gr_acl_handle_filldir(const struct file *file, const char *name,
79942+ const unsigned int namelen, const ino_t ino);
79943+
79944+__u32 gr_acl_handle_unix(const struct dentry *dentry,
79945+ const struct vfsmount *mnt);
79946+void gr_acl_handle_exit(void);
79947+void gr_acl_handle_psacct(struct task_struct *task, const long code);
79948+int gr_acl_handle_procpidmem(const struct task_struct *task);
79949+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
79950+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
79951+void gr_audit_ptrace(struct task_struct *task);
79952+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
79953+void gr_put_exec_file(struct task_struct *task);
79954+
79955+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
79956+
79957+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
79958+extern void gr_learn_resource(const struct task_struct *task, const int res,
79959+ const unsigned long wanted, const int gt);
79960+#else
79961+static inline void gr_learn_resource(const struct task_struct *task, const int res,
79962+ const unsigned long wanted, const int gt)
79963+{
79964+}
79965+#endif
79966+
79967+#ifdef CONFIG_GRKERNSEC_RESLOG
79968+extern void gr_log_resource(const struct task_struct *task, const int res,
79969+ const unsigned long wanted, const int gt);
79970+#else
79971+static inline void gr_log_resource(const struct task_struct *task, const int res,
79972+ const unsigned long wanted, const int gt)
79973+{
79974+}
79975+#endif
79976+
79977+#ifdef CONFIG_GRKERNSEC
79978+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
79979+void gr_handle_vm86(void);
79980+void gr_handle_mem_readwrite(u64 from, u64 to);
79981+
79982+void gr_log_badprocpid(const char *entry);
79983+
79984+extern int grsec_enable_dmesg;
79985+extern int grsec_disable_privio;
79986+
79987+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
79988+extern kgid_t grsec_proc_gid;
79989+#endif
79990+
79991+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
79992+extern int grsec_enable_chroot_findtask;
79993+#endif
79994+#ifdef CONFIG_GRKERNSEC_SETXID
79995+extern int grsec_enable_setxid;
79996+#endif
79997+#endif
79998+
79999+#endif
80000diff --git a/include/linux/grsock.h b/include/linux/grsock.h
80001new file mode 100644
80002index 0000000..e7ffaaf
80003--- /dev/null
80004+++ b/include/linux/grsock.h
80005@@ -0,0 +1,19 @@
80006+#ifndef __GRSOCK_H
80007+#define __GRSOCK_H
80008+
80009+extern void gr_attach_curr_ip(const struct sock *sk);
80010+extern int gr_handle_sock_all(const int family, const int type,
80011+ const int protocol);
80012+extern int gr_handle_sock_server(const struct sockaddr *sck);
80013+extern int gr_handle_sock_server_other(const struct sock *sck);
80014+extern int gr_handle_sock_client(const struct sockaddr *sck);
80015+extern int gr_search_connect(struct socket * sock,
80016+ struct sockaddr_in * addr);
80017+extern int gr_search_bind(struct socket * sock,
80018+ struct sockaddr_in * addr);
80019+extern int gr_search_listen(struct socket * sock);
80020+extern int gr_search_accept(struct socket * sock);
80021+extern int gr_search_socket(const int domain, const int type,
80022+ const int protocol);
80023+
80024+#endif
80025diff --git a/include/linux/hash.h b/include/linux/hash.h
80026index bd1754c..8240892 100644
80027--- a/include/linux/hash.h
80028+++ b/include/linux/hash.h
80029@@ -83,7 +83,7 @@ static inline u32 hash32_ptr(const void *ptr)
80030 struct fast_hash_ops {
80031 u32 (*hash)(const void *data, u32 len, u32 seed);
80032 u32 (*hash2)(const u32 *data, u32 len, u32 seed);
80033-};
80034+} __no_const;
80035
80036 /**
80037 * arch_fast_hash - Caclulates a hash over a given buffer that can have
80038diff --git a/include/linux/highmem.h b/include/linux/highmem.h
80039index 7fb31da..08b5114 100644
80040--- a/include/linux/highmem.h
80041+++ b/include/linux/highmem.h
80042@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
80043 kunmap_atomic(kaddr);
80044 }
80045
80046+static inline void sanitize_highpage(struct page *page)
80047+{
80048+ void *kaddr;
80049+ unsigned long flags;
80050+
80051+ local_irq_save(flags);
80052+ kaddr = kmap_atomic(page);
80053+ clear_page(kaddr);
80054+ kunmap_atomic(kaddr);
80055+ local_irq_restore(flags);
80056+}
80057+
80058 static inline void zero_user_segments(struct page *page,
80059 unsigned start1, unsigned end1,
80060 unsigned start2, unsigned end2)
80061diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
80062index 1c7b89a..7dda400 100644
80063--- a/include/linux/hwmon-sysfs.h
80064+++ b/include/linux/hwmon-sysfs.h
80065@@ -25,7 +25,8 @@
80066 struct sensor_device_attribute{
80067 struct device_attribute dev_attr;
80068 int index;
80069-};
80070+} __do_const;
80071+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
80072 #define to_sensor_dev_attr(_dev_attr) \
80073 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
80074
80075@@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
80076 struct device_attribute dev_attr;
80077 u8 index;
80078 u8 nr;
80079-};
80080+} __do_const;
80081+typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
80082 #define to_sensor_dev_attr_2(_dev_attr) \
80083 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
80084
80085diff --git a/include/linux/i2c.h b/include/linux/i2c.h
80086index deddeb8..bcaf62d 100644
80087--- a/include/linux/i2c.h
80088+++ b/include/linux/i2c.h
80089@@ -378,6 +378,7 @@ struct i2c_algorithm {
80090 /* To determine what the adapter supports */
80091 u32 (*functionality) (struct i2c_adapter *);
80092 };
80093+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
80094
80095 /**
80096 * struct i2c_bus_recovery_info - I2C bus recovery information
80097diff --git a/include/linux/i2o.h b/include/linux/i2o.h
80098index d23c3c2..eb63c81 100644
80099--- a/include/linux/i2o.h
80100+++ b/include/linux/i2o.h
80101@@ -565,7 +565,7 @@ struct i2o_controller {
80102 struct i2o_device *exec; /* Executive */
80103 #if BITS_PER_LONG == 64
80104 spinlock_t context_list_lock; /* lock for context_list */
80105- atomic_t context_list_counter; /* needed for unique contexts */
80106+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
80107 struct list_head context_list; /* list of context id's
80108 and pointers */
80109 #endif
80110diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
80111index aff7ad8..3942bbd 100644
80112--- a/include/linux/if_pppox.h
80113+++ b/include/linux/if_pppox.h
80114@@ -76,7 +76,7 @@ struct pppox_proto {
80115 int (*ioctl)(struct socket *sock, unsigned int cmd,
80116 unsigned long arg);
80117 struct module *owner;
80118-};
80119+} __do_const;
80120
80121 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
80122 extern void unregister_pppox_proto(int proto_num);
80123diff --git a/include/linux/init.h b/include/linux/init.h
80124index e168880..d9b489d 100644
80125--- a/include/linux/init.h
80126+++ b/include/linux/init.h
80127@@ -37,9 +37,17 @@
80128 * section.
80129 */
80130
80131+#define add_init_latent_entropy __latent_entropy
80132+
80133+#ifdef CONFIG_MEMORY_HOTPLUG
80134+#define add_meminit_latent_entropy
80135+#else
80136+#define add_meminit_latent_entropy __latent_entropy
80137+#endif
80138+
80139 /* These are for everybody (although not all archs will actually
80140 discard it in modules) */
80141-#define __init __section(.init.text) __cold notrace
80142+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
80143 #define __initdata __section(.init.data)
80144 #define __initconst __constsection(.init.rodata)
80145 #define __exitdata __section(.exit.data)
80146@@ -100,7 +108,7 @@
80147 #define __cpuexitconst
80148
80149 /* Used for MEMORY_HOTPLUG */
80150-#define __meminit __section(.meminit.text) __cold notrace
80151+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
80152 #define __meminitdata __section(.meminit.data)
80153 #define __meminitconst __constsection(.meminit.rodata)
80154 #define __memexit __section(.memexit.text) __exitused __cold notrace
80155diff --git a/include/linux/init_task.h b/include/linux/init_task.h
80156index 6df7f9f..d0bf699 100644
80157--- a/include/linux/init_task.h
80158+++ b/include/linux/init_task.h
80159@@ -156,6 +156,12 @@ extern struct task_group root_task_group;
80160
80161 #define INIT_TASK_COMM "swapper"
80162
80163+#ifdef CONFIG_X86
80164+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
80165+#else
80166+#define INIT_TASK_THREAD_INFO
80167+#endif
80168+
80169 #ifdef CONFIG_RT_MUTEXES
80170 # define INIT_RT_MUTEXES(tsk) \
80171 .pi_waiters = RB_ROOT, \
80172@@ -203,6 +209,7 @@ extern struct task_group root_task_group;
80173 RCU_POINTER_INITIALIZER(cred, &init_cred), \
80174 .comm = INIT_TASK_COMM, \
80175 .thread = INIT_THREAD, \
80176+ INIT_TASK_THREAD_INFO \
80177 .fs = &init_fs, \
80178 .files = &init_files, \
80179 .signal = &init_signals, \
80180diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
80181index a2678d3..e411b1b 100644
80182--- a/include/linux/interrupt.h
80183+++ b/include/linux/interrupt.h
80184@@ -373,8 +373,8 @@ extern const char * const softirq_to_name[NR_SOFTIRQS];
80185
80186 struct softirq_action
80187 {
80188- void (*action)(struct softirq_action *);
80189-};
80190+ void (*action)(void);
80191+} __no_const;
80192
80193 asmlinkage void do_softirq(void);
80194 asmlinkage void __do_softirq(void);
80195@@ -388,7 +388,7 @@ static inline void do_softirq_own_stack(void)
80196 }
80197 #endif
80198
80199-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
80200+extern void open_softirq(int nr, void (*action)(void));
80201 extern void softirq_init(void);
80202 extern void __raise_softirq_irqoff(unsigned int nr);
80203
80204diff --git a/include/linux/iommu.h b/include/linux/iommu.h
80205index b96a5b2..2732d1c 100644
80206--- a/include/linux/iommu.h
80207+++ b/include/linux/iommu.h
80208@@ -131,7 +131,7 @@ struct iommu_ops {
80209 u32 (*domain_get_windows)(struct iommu_domain *domain);
80210
80211 unsigned long pgsize_bitmap;
80212-};
80213+} __do_const;
80214
80215 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
80216 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
80217diff --git a/include/linux/ioport.h b/include/linux/ioport.h
80218index 89b7c24..382af74 100644
80219--- a/include/linux/ioport.h
80220+++ b/include/linux/ioport.h
80221@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
80222 int adjust_resource(struct resource *res, resource_size_t start,
80223 resource_size_t size);
80224 resource_size_t resource_alignment(struct resource *res);
80225-static inline resource_size_t resource_size(const struct resource *res)
80226+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
80227 {
80228 return res->end - res->start + 1;
80229 }
80230diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
80231index 35e7eca..6afb7ad 100644
80232--- a/include/linux/ipc_namespace.h
80233+++ b/include/linux/ipc_namespace.h
80234@@ -69,7 +69,7 @@ struct ipc_namespace {
80235 struct user_namespace *user_ns;
80236
80237 unsigned int proc_inum;
80238-};
80239+} __randomize_layout;
80240
80241 extern struct ipc_namespace init_ipc_ns;
80242 extern atomic_t nr_ipc_ns;
80243diff --git a/include/linux/irq.h b/include/linux/irq.h
80244index 7dc1003..407327b 100644
80245--- a/include/linux/irq.h
80246+++ b/include/linux/irq.h
80247@@ -338,7 +338,8 @@ struct irq_chip {
80248 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
80249
80250 unsigned long flags;
80251-};
80252+} __do_const;
80253+typedef struct irq_chip __no_const irq_chip_no_const;
80254
80255 /*
80256 * irq_chip specific flags
80257diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
80258index 0ceb389..eed3fb8 100644
80259--- a/include/linux/irqchip/arm-gic.h
80260+++ b/include/linux/irqchip/arm-gic.h
80261@@ -73,9 +73,11 @@
80262
80263 #ifndef __ASSEMBLY__
80264
80265+#include <linux/irq.h>
80266+
80267 struct device_node;
80268
80269-extern struct irq_chip gic_arch_extn;
80270+extern irq_chip_no_const gic_arch_extn;
80271
80272 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
80273 u32 offset, struct device_node *);
80274diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
80275index 1f44466..b481806 100644
80276--- a/include/linux/jiffies.h
80277+++ b/include/linux/jiffies.h
80278@@ -292,20 +292,20 @@ extern unsigned long preset_lpj;
80279 /*
80280 * Convert various time units to each other:
80281 */
80282-extern unsigned int jiffies_to_msecs(const unsigned long j);
80283-extern unsigned int jiffies_to_usecs(const unsigned long j);
80284+extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
80285+extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
80286
80287-static inline u64 jiffies_to_nsecs(const unsigned long j)
80288+static inline u64 __intentional_overflow(-1) jiffies_to_nsecs(const unsigned long j)
80289 {
80290 return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC;
80291 }
80292
80293-extern unsigned long msecs_to_jiffies(const unsigned int m);
80294-extern unsigned long usecs_to_jiffies(const unsigned int u);
80295+extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
80296+extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
80297 extern unsigned long timespec_to_jiffies(const struct timespec *value);
80298 extern void jiffies_to_timespec(const unsigned long jiffies,
80299- struct timespec *value);
80300-extern unsigned long timeval_to_jiffies(const struct timeval *value);
80301+ struct timespec *value) __intentional_overflow(-1);
80302+extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
80303 extern void jiffies_to_timeval(const unsigned long jiffies,
80304 struct timeval *value);
80305
80306diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
80307index 6883e19..e854fcb 100644
80308--- a/include/linux/kallsyms.h
80309+++ b/include/linux/kallsyms.h
80310@@ -15,7 +15,8 @@
80311
80312 struct module;
80313
80314-#ifdef CONFIG_KALLSYMS
80315+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
80316+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
80317 /* Lookup the address for a symbol. Returns 0 if not found. */
80318 unsigned long kallsyms_lookup_name(const char *name);
80319
80320@@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
80321 /* Stupid that this does nothing, but I didn't create this mess. */
80322 #define __print_symbol(fmt, addr)
80323 #endif /*CONFIG_KALLSYMS*/
80324+#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
80325+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
80326+extern unsigned long kallsyms_lookup_name(const char *name);
80327+extern void __print_symbol(const char *fmt, unsigned long address);
80328+extern int sprint_backtrace(char *buffer, unsigned long address);
80329+extern int sprint_symbol(char *buffer, unsigned long address);
80330+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
80331+const char *kallsyms_lookup(unsigned long addr,
80332+ unsigned long *symbolsize,
80333+ unsigned long *offset,
80334+ char **modname, char *namebuf);
80335+extern int kallsyms_lookup_size_offset(unsigned long addr,
80336+ unsigned long *symbolsize,
80337+ unsigned long *offset);
80338+#endif
80339
80340 /* This macro allows us to keep printk typechecking */
80341 static __printf(1, 2)
80342diff --git a/include/linux/key-type.h b/include/linux/key-type.h
80343index a74c3a8..28d3f21 100644
80344--- a/include/linux/key-type.h
80345+++ b/include/linux/key-type.h
80346@@ -131,7 +131,7 @@ struct key_type {
80347 /* internal fields */
80348 struct list_head link; /* link in types list */
80349 struct lock_class_key lock_class; /* key->sem lock class */
80350-};
80351+} __do_const;
80352
80353 extern struct key_type key_type_keyring;
80354
80355diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
80356index 6b06d37..c134867 100644
80357--- a/include/linux/kgdb.h
80358+++ b/include/linux/kgdb.h
80359@@ -52,7 +52,7 @@ extern int kgdb_connected;
80360 extern int kgdb_io_module_registered;
80361
80362 extern atomic_t kgdb_setting_breakpoint;
80363-extern atomic_t kgdb_cpu_doing_single_step;
80364+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
80365
80366 extern struct task_struct *kgdb_usethread;
80367 extern struct task_struct *kgdb_contthread;
80368@@ -254,7 +254,7 @@ struct kgdb_arch {
80369 void (*correct_hw_break)(void);
80370
80371 void (*enable_nmi)(bool on);
80372-};
80373+} __do_const;
80374
80375 /**
80376 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
80377@@ -279,7 +279,7 @@ struct kgdb_io {
80378 void (*pre_exception) (void);
80379 void (*post_exception) (void);
80380 int is_console;
80381-};
80382+} __do_const;
80383
80384 extern struct kgdb_arch arch_kgdb_ops;
80385
80386diff --git a/include/linux/kmod.h b/include/linux/kmod.h
80387index 0555cc6..40116ce 100644
80388--- a/include/linux/kmod.h
80389+++ b/include/linux/kmod.h
80390@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
80391 * usually useless though. */
80392 extern __printf(2, 3)
80393 int __request_module(bool wait, const char *name, ...);
80394+extern __printf(3, 4)
80395+int ___request_module(bool wait, char *param_name, const char *name, ...);
80396 #define request_module(mod...) __request_module(true, mod)
80397 #define request_module_nowait(mod...) __request_module(false, mod)
80398 #define try_then_request_module(x, mod...) \
80399@@ -57,6 +59,9 @@ struct subprocess_info {
80400 struct work_struct work;
80401 struct completion *complete;
80402 char *path;
80403+#ifdef CONFIG_GRKERNSEC
80404+ char *origpath;
80405+#endif
80406 char **argv;
80407 char **envp;
80408 int wait;
80409diff --git a/include/linux/kobject.h b/include/linux/kobject.h
80410index 926afb6..58dd6e5 100644
80411--- a/include/linux/kobject.h
80412+++ b/include/linux/kobject.h
80413@@ -116,7 +116,7 @@ struct kobj_type {
80414 struct attribute **default_attrs;
80415 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
80416 const void *(*namespace)(struct kobject *kobj);
80417-};
80418+} __do_const;
80419
80420 struct kobj_uevent_env {
80421 char *envp[UEVENT_NUM_ENVP];
80422@@ -139,6 +139,7 @@ struct kobj_attribute {
80423 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
80424 const char *buf, size_t count);
80425 };
80426+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
80427
80428 extern const struct sysfs_ops kobj_sysfs_ops;
80429
80430@@ -166,7 +167,7 @@ struct kset {
80431 spinlock_t list_lock;
80432 struct kobject kobj;
80433 const struct kset_uevent_ops *uevent_ops;
80434-};
80435+} __randomize_layout;
80436
80437 extern void kset_init(struct kset *kset);
80438 extern int __must_check kset_register(struct kset *kset);
80439diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
80440index df32d25..fb52e27 100644
80441--- a/include/linux/kobject_ns.h
80442+++ b/include/linux/kobject_ns.h
80443@@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
80444 const void *(*netlink_ns)(struct sock *sk);
80445 const void *(*initial_ns)(void);
80446 void (*drop_ns)(void *);
80447-};
80448+} __do_const;
80449
80450 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
80451 int kobj_ns_type_registered(enum kobj_ns_type type);
80452diff --git a/include/linux/kref.h b/include/linux/kref.h
80453index 484604d..0f6c5b6 100644
80454--- a/include/linux/kref.h
80455+++ b/include/linux/kref.h
80456@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
80457 static inline int kref_sub(struct kref *kref, unsigned int count,
80458 void (*release)(struct kref *kref))
80459 {
80460- WARN_ON(release == NULL);
80461+ BUG_ON(release == NULL);
80462
80463 if (atomic_sub_and_test((int) count, &kref->refcount)) {
80464 release(kref);
80465diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
80466index b8e9a43..632678d 100644
80467--- a/include/linux/kvm_host.h
80468+++ b/include/linux/kvm_host.h
80469@@ -455,7 +455,7 @@ static inline void kvm_irqfd_exit(void)
80470 {
80471 }
80472 #endif
80473-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
80474+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
80475 struct module *module);
80476 void kvm_exit(void);
80477
80478@@ -621,7 +621,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
80479 struct kvm_guest_debug *dbg);
80480 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
80481
80482-int kvm_arch_init(void *opaque);
80483+int kvm_arch_init(const void *opaque);
80484 void kvm_arch_exit(void);
80485
80486 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
80487diff --git a/include/linux/libata.h b/include/linux/libata.h
80488index 3fee55e..42565b7 100644
80489--- a/include/linux/libata.h
80490+++ b/include/linux/libata.h
80491@@ -976,7 +976,7 @@ struct ata_port_operations {
80492 * fields must be pointers.
80493 */
80494 const struct ata_port_operations *inherits;
80495-};
80496+} __do_const;
80497
80498 struct ata_port_info {
80499 unsigned long flags;
80500diff --git a/include/linux/linkage.h b/include/linux/linkage.h
80501index a6a42dd..6c5ebce 100644
80502--- a/include/linux/linkage.h
80503+++ b/include/linux/linkage.h
80504@@ -36,6 +36,7 @@
80505 #endif
80506
80507 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
80508+#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
80509 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
80510
80511 /*
80512diff --git a/include/linux/list.h b/include/linux/list.h
80513index ef95941..82db65a 100644
80514--- a/include/linux/list.h
80515+++ b/include/linux/list.h
80516@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
80517 extern void list_del(struct list_head *entry);
80518 #endif
80519
80520+extern void __pax_list_add(struct list_head *new,
80521+ struct list_head *prev,
80522+ struct list_head *next);
80523+static inline void pax_list_add(struct list_head *new, struct list_head *head)
80524+{
80525+ __pax_list_add(new, head, head->next);
80526+}
80527+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
80528+{
80529+ __pax_list_add(new, head->prev, head);
80530+}
80531+extern void pax_list_del(struct list_head *entry);
80532+
80533 /**
80534 * list_replace - replace old entry by new one
80535 * @old : the element to be replaced
80536@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
80537 INIT_LIST_HEAD(entry);
80538 }
80539
80540+extern void pax_list_del_init(struct list_head *entry);
80541+
80542 /**
80543 * list_move - delete from one list and add as another's head
80544 * @list: the entry to move
80545diff --git a/include/linux/math64.h b/include/linux/math64.h
80546index c45c089..298841c 100644
80547--- a/include/linux/math64.h
80548+++ b/include/linux/math64.h
80549@@ -15,7 +15,7 @@
80550 * This is commonly provided by 32bit archs to provide an optimized 64bit
80551 * divide.
80552 */
80553-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80554+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80555 {
80556 *remainder = dividend % divisor;
80557 return dividend / divisor;
80558@@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
80559 /**
80560 * div64_u64 - unsigned 64bit divide with 64bit divisor
80561 */
80562-static inline u64 div64_u64(u64 dividend, u64 divisor)
80563+static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
80564 {
80565 return dividend / divisor;
80566 }
80567@@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
80568 #define div64_ul(x, y) div_u64((x), (y))
80569
80570 #ifndef div_u64_rem
80571-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80572+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80573 {
80574 *remainder = do_div(dividend, divisor);
80575 return dividend;
80576@@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
80577 #endif
80578
80579 #ifndef div64_u64
80580-extern u64 div64_u64(u64 dividend, u64 divisor);
80581+extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
80582 #endif
80583
80584 #ifndef div64_s64
80585@@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
80586 * divide.
80587 */
80588 #ifndef div_u64
80589-static inline u64 div_u64(u64 dividend, u32 divisor)
80590+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
80591 {
80592 u32 remainder;
80593 return div_u64_rem(dividend, divisor, &remainder);
80594diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
80595index 5f1ea75..5125ac5 100644
80596--- a/include/linux/mempolicy.h
80597+++ b/include/linux/mempolicy.h
80598@@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
80599 }
80600
80601 #define vma_policy(vma) ((vma)->vm_policy)
80602+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
80603+{
80604+ vma->vm_policy = pol;
80605+}
80606
80607 static inline void mpol_get(struct mempolicy *pol)
80608 {
80609@@ -223,6 +227,9 @@ static inline void mpol_free_shared_policy(struct shared_policy *p)
80610 }
80611
80612 #define vma_policy(vma) NULL
80613+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
80614+{
80615+}
80616
80617 static inline int
80618 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
80619diff --git a/include/linux/mm.h b/include/linux/mm.h
80620index c1b7414..5ea2ad8 100644
80621--- a/include/linux/mm.h
80622+++ b/include/linux/mm.h
80623@@ -127,6 +127,11 @@ extern unsigned int kobjsize(const void *objp);
80624 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
80625 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
80626 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
80627+
80628+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
80629+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
80630+#endif
80631+
80632 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
80633
80634 #ifdef CONFIG_MEM_SOFT_DIRTY
80635@@ -229,8 +234,8 @@ struct vm_operations_struct {
80636 /* called by access_process_vm when get_user_pages() fails, typically
80637 * for use by special VMAs that can switch between memory and hardware
80638 */
80639- int (*access)(struct vm_area_struct *vma, unsigned long addr,
80640- void *buf, int len, int write);
80641+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
80642+ void *buf, size_t len, int write);
80643 #ifdef CONFIG_NUMA
80644 /*
80645 * set_policy() op must add a reference to any non-NULL @new mempolicy
80646@@ -260,6 +265,7 @@ struct vm_operations_struct {
80647 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
80648 unsigned long size, pgoff_t pgoff);
80649 };
80650+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
80651
80652 struct mmu_gather;
80653 struct inode;
80654@@ -1112,8 +1118,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
80655 unsigned long *pfn);
80656 int follow_phys(struct vm_area_struct *vma, unsigned long address,
80657 unsigned int flags, unsigned long *prot, resource_size_t *phys);
80658-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
80659- void *buf, int len, int write);
80660+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
80661+ void *buf, size_t len, int write);
80662
80663 static inline void unmap_shared_mapping_range(struct address_space *mapping,
80664 loff_t const holebegin, loff_t const holelen)
80665@@ -1152,9 +1158,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
80666 }
80667 #endif
80668
80669-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
80670-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
80671- void *buf, int len, int write);
80672+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
80673+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
80674+ void *buf, size_t len, int write);
80675
80676 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
80677 unsigned long start, unsigned long nr_pages,
80678@@ -1186,34 +1192,6 @@ int set_page_dirty(struct page *page);
80679 int set_page_dirty_lock(struct page *page);
80680 int clear_page_dirty_for_io(struct page *page);
80681
80682-/* Is the vma a continuation of the stack vma above it? */
80683-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
80684-{
80685- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
80686-}
80687-
80688-static inline int stack_guard_page_start(struct vm_area_struct *vma,
80689- unsigned long addr)
80690-{
80691- return (vma->vm_flags & VM_GROWSDOWN) &&
80692- (vma->vm_start == addr) &&
80693- !vma_growsdown(vma->vm_prev, addr);
80694-}
80695-
80696-/* Is the vma a continuation of the stack vma below it? */
80697-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
80698-{
80699- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
80700-}
80701-
80702-static inline int stack_guard_page_end(struct vm_area_struct *vma,
80703- unsigned long addr)
80704-{
80705- return (vma->vm_flags & VM_GROWSUP) &&
80706- (vma->vm_end == addr) &&
80707- !vma_growsup(vma->vm_next, addr);
80708-}
80709-
80710 extern pid_t
80711 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
80712
80713@@ -1313,6 +1291,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
80714 }
80715 #endif
80716
80717+#ifdef CONFIG_MMU
80718+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
80719+#else
80720+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
80721+{
80722+ return __pgprot(0);
80723+}
80724+#endif
80725+
80726 int vma_wants_writenotify(struct vm_area_struct *vma);
80727
80728 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
80729@@ -1331,8 +1318,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
80730 {
80731 return 0;
80732 }
80733+
80734+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
80735+ unsigned long address)
80736+{
80737+ return 0;
80738+}
80739 #else
80740 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
80741+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
80742 #endif
80743
80744 #ifdef __PAGETABLE_PMD_FOLDED
80745@@ -1341,8 +1335,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
80746 {
80747 return 0;
80748 }
80749+
80750+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
80751+ unsigned long address)
80752+{
80753+ return 0;
80754+}
80755 #else
80756 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
80757+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
80758 #endif
80759
80760 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
80761@@ -1360,11 +1361,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
80762 NULL: pud_offset(pgd, address);
80763 }
80764
80765+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
80766+{
80767+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
80768+ NULL: pud_offset(pgd, address);
80769+}
80770+
80771 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
80772 {
80773 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
80774 NULL: pmd_offset(pud, address);
80775 }
80776+
80777+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
80778+{
80779+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
80780+ NULL: pmd_offset(pud, address);
80781+}
80782 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
80783
80784 #if USE_SPLIT_PTE_PTLOCKS
80785@@ -1754,7 +1767,7 @@ extern int install_special_mapping(struct mm_struct *mm,
80786 unsigned long addr, unsigned long len,
80787 unsigned long flags, struct page **pages);
80788
80789-extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
80790+extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
80791
80792 extern unsigned long mmap_region(struct file *file, unsigned long addr,
80793 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
80794@@ -1762,6 +1775,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
80795 unsigned long len, unsigned long prot, unsigned long flags,
80796 unsigned long pgoff, unsigned long *populate);
80797 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
80798+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
80799
80800 #ifdef CONFIG_MMU
80801 extern int __mm_populate(unsigned long addr, unsigned long len,
80802@@ -1790,10 +1804,11 @@ struct vm_unmapped_area_info {
80803 unsigned long high_limit;
80804 unsigned long align_mask;
80805 unsigned long align_offset;
80806+ unsigned long threadstack_offset;
80807 };
80808
80809-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
80810-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
80811+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
80812+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
80813
80814 /*
80815 * Search for an unmapped address range.
80816@@ -1805,7 +1820,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
80817 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
80818 */
80819 static inline unsigned long
80820-vm_unmapped_area(struct vm_unmapped_area_info *info)
80821+vm_unmapped_area(const struct vm_unmapped_area_info *info)
80822 {
80823 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
80824 return unmapped_area(info);
80825@@ -1868,6 +1883,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
80826 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
80827 struct vm_area_struct **pprev);
80828
80829+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
80830+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
80831+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
80832+
80833 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
80834 NULL if none. Assume start_addr < end_addr. */
80835 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
80836@@ -1896,15 +1915,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
80837 return vma;
80838 }
80839
80840-#ifdef CONFIG_MMU
80841-pgprot_t vm_get_page_prot(unsigned long vm_flags);
80842-#else
80843-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
80844-{
80845- return __pgprot(0);
80846-}
80847-#endif
80848-
80849 #ifdef CONFIG_NUMA_BALANCING
80850 unsigned long change_prot_numa(struct vm_area_struct *vma,
80851 unsigned long start, unsigned long end);
80852@@ -1956,6 +1966,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
80853 static inline void vm_stat_account(struct mm_struct *mm,
80854 unsigned long flags, struct file *file, long pages)
80855 {
80856+
80857+#ifdef CONFIG_PAX_RANDMMAP
80858+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
80859+#endif
80860+
80861 mm->total_vm += pages;
80862 }
80863 #endif /* CONFIG_PROC_FS */
80864@@ -2037,7 +2052,7 @@ extern int unpoison_memory(unsigned long pfn);
80865 extern int sysctl_memory_failure_early_kill;
80866 extern int sysctl_memory_failure_recovery;
80867 extern void shake_page(struct page *p, int access);
80868-extern atomic_long_t num_poisoned_pages;
80869+extern atomic_long_unchecked_t num_poisoned_pages;
80870 extern int soft_offline_page(struct page *page, int flags);
80871
80872 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
80873@@ -2072,5 +2087,11 @@ void __init setup_nr_node_ids(void);
80874 static inline void setup_nr_node_ids(void) {}
80875 #endif
80876
80877+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
80878+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
80879+#else
80880+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
80881+#endif
80882+
80883 #endif /* __KERNEL__ */
80884 #endif /* _LINUX_MM_H */
80885diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
80886index 290901a..e99b01c 100644
80887--- a/include/linux/mm_types.h
80888+++ b/include/linux/mm_types.h
80889@@ -307,7 +307,9 @@ struct vm_area_struct {
80890 #ifdef CONFIG_NUMA
80891 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
80892 #endif
80893-};
80894+
80895+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
80896+} __randomize_layout;
80897
80898 struct core_thread {
80899 struct task_struct *task;
80900@@ -453,7 +455,25 @@ struct mm_struct {
80901 bool tlb_flush_pending;
80902 #endif
80903 struct uprobes_state uprobes_state;
80904-};
80905+
80906+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
80907+ unsigned long pax_flags;
80908+#endif
80909+
80910+#ifdef CONFIG_PAX_DLRESOLVE
80911+ unsigned long call_dl_resolve;
80912+#endif
80913+
80914+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
80915+ unsigned long call_syscall;
80916+#endif
80917+
80918+#ifdef CONFIG_PAX_ASLR
80919+ unsigned long delta_mmap; /* randomized offset */
80920+ unsigned long delta_stack; /* randomized offset */
80921+#endif
80922+
80923+} __randomize_layout;
80924
80925 static inline void mm_init_cpumask(struct mm_struct *mm)
80926 {
80927diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
80928index c5d5278..f0b68c8 100644
80929--- a/include/linux/mmiotrace.h
80930+++ b/include/linux/mmiotrace.h
80931@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
80932 /* Called from ioremap.c */
80933 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
80934 void __iomem *addr);
80935-extern void mmiotrace_iounmap(volatile void __iomem *addr);
80936+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
80937
80938 /* For anyone to insert markers. Remember trailing newline. */
80939 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
80940@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
80941 {
80942 }
80943
80944-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
80945+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
80946 {
80947 }
80948
80949diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
80950index 9b61b9b..52147d6b 100644
80951--- a/include/linux/mmzone.h
80952+++ b/include/linux/mmzone.h
80953@@ -396,7 +396,7 @@ struct zone {
80954 unsigned long flags; /* zone flags, see below */
80955
80956 /* Zone statistics */
80957- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
80958+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
80959
80960 /*
80961 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
80962diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
80963index 45e9214..a7227d6 100644
80964--- a/include/linux/mod_devicetable.h
80965+++ b/include/linux/mod_devicetable.h
80966@@ -13,7 +13,7 @@
80967 typedef unsigned long kernel_ulong_t;
80968 #endif
80969
80970-#define PCI_ANY_ID (~0)
80971+#define PCI_ANY_ID ((__u16)~0)
80972
80973 struct pci_device_id {
80974 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
80975@@ -139,7 +139,7 @@ struct usb_device_id {
80976 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
80977 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
80978
80979-#define HID_ANY_ID (~0)
80980+#define HID_ANY_ID (~0U)
80981 #define HID_BUS_ANY 0xffff
80982 #define HID_GROUP_ANY 0x0000
80983
80984@@ -467,7 +467,7 @@ struct dmi_system_id {
80985 const char *ident;
80986 struct dmi_strmatch matches[4];
80987 void *driver_data;
80988-};
80989+} __do_const;
80990 /*
80991 * struct dmi_device_id appears during expansion of
80992 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
80993diff --git a/include/linux/module.h b/include/linux/module.h
80994index eaf60ff..641979a 100644
80995--- a/include/linux/module.h
80996+++ b/include/linux/module.h
80997@@ -17,9 +17,11 @@
80998 #include <linux/moduleparam.h>
80999 #include <linux/tracepoint.h>
81000 #include <linux/export.h>
81001+#include <linux/fs.h>
81002
81003 #include <linux/percpu.h>
81004 #include <asm/module.h>
81005+#include <asm/pgtable.h>
81006
81007 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
81008 #define MODULE_SIG_STRING "~Module signature appended~\n"
81009@@ -42,7 +44,7 @@ struct module_kobject {
81010 struct kobject *drivers_dir;
81011 struct module_param_attrs *mp;
81012 struct completion *kobj_completion;
81013-};
81014+} __randomize_layout;
81015
81016 struct module_attribute {
81017 struct attribute attr;
81018@@ -54,12 +56,13 @@ struct module_attribute {
81019 int (*test)(struct module *);
81020 void (*free)(struct module *);
81021 };
81022+typedef struct module_attribute __no_const module_attribute_no_const;
81023
81024 struct module_version_attribute {
81025 struct module_attribute mattr;
81026 const char *module_name;
81027 const char *version;
81028-} __attribute__ ((__aligned__(sizeof(void *))));
81029+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
81030
81031 extern ssize_t __modver_version_show(struct module_attribute *,
81032 struct module_kobject *, char *);
81033@@ -238,7 +241,7 @@ struct module {
81034
81035 /* Sysfs stuff. */
81036 struct module_kobject mkobj;
81037- struct module_attribute *modinfo_attrs;
81038+ module_attribute_no_const *modinfo_attrs;
81039 const char *version;
81040 const char *srcversion;
81041 struct kobject *holders_dir;
81042@@ -287,19 +290,16 @@ struct module {
81043 int (*init)(void);
81044
81045 /* If this is non-NULL, vfree after init() returns */
81046- void *module_init;
81047+ void *module_init_rx, *module_init_rw;
81048
81049 /* Here is the actual code + data, vfree'd on unload. */
81050- void *module_core;
81051+ void *module_core_rx, *module_core_rw;
81052
81053 /* Here are the sizes of the init and core sections */
81054- unsigned int init_size, core_size;
81055+ unsigned int init_size_rw, core_size_rw;
81056
81057 /* The size of the executable code in each section. */
81058- unsigned int init_text_size, core_text_size;
81059-
81060- /* Size of RO sections of the module (text+rodata) */
81061- unsigned int init_ro_size, core_ro_size;
81062+ unsigned int init_size_rx, core_size_rx;
81063
81064 /* Arch-specific module values */
81065 struct mod_arch_specific arch;
81066@@ -355,6 +355,10 @@ struct module {
81067 #ifdef CONFIG_EVENT_TRACING
81068 struct ftrace_event_call **trace_events;
81069 unsigned int num_trace_events;
81070+ struct file_operations trace_id;
81071+ struct file_operations trace_enable;
81072+ struct file_operations trace_format;
81073+ struct file_operations trace_filter;
81074 #endif
81075 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
81076 unsigned int num_ftrace_callsites;
81077@@ -378,7 +382,7 @@ struct module {
81078 ctor_fn_t *ctors;
81079 unsigned int num_ctors;
81080 #endif
81081-};
81082+} __randomize_layout;
81083 #ifndef MODULE_ARCH_INIT
81084 #define MODULE_ARCH_INIT {}
81085 #endif
81086@@ -399,16 +403,46 @@ bool is_module_address(unsigned long addr);
81087 bool is_module_percpu_address(unsigned long addr);
81088 bool is_module_text_address(unsigned long addr);
81089
81090+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
81091+{
81092+
81093+#ifdef CONFIG_PAX_KERNEXEC
81094+ if (ktla_ktva(addr) >= (unsigned long)start &&
81095+ ktla_ktva(addr) < (unsigned long)start + size)
81096+ return 1;
81097+#endif
81098+
81099+ return ((void *)addr >= start && (void *)addr < start + size);
81100+}
81101+
81102+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
81103+{
81104+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
81105+}
81106+
81107+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
81108+{
81109+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
81110+}
81111+
81112+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
81113+{
81114+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
81115+}
81116+
81117+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
81118+{
81119+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
81120+}
81121+
81122 static inline int within_module_core(unsigned long addr, const struct module *mod)
81123 {
81124- return (unsigned long)mod->module_core <= addr &&
81125- addr < (unsigned long)mod->module_core + mod->core_size;
81126+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
81127 }
81128
81129 static inline int within_module_init(unsigned long addr, const struct module *mod)
81130 {
81131- return (unsigned long)mod->module_init <= addr &&
81132- addr < (unsigned long)mod->module_init + mod->init_size;
81133+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
81134 }
81135
81136 /* Search for module by name: must hold module_mutex. */
81137diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
81138index 560ca53..ef621ef 100644
81139--- a/include/linux/moduleloader.h
81140+++ b/include/linux/moduleloader.h
81141@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
81142 sections. Returns NULL on failure. */
81143 void *module_alloc(unsigned long size);
81144
81145+#ifdef CONFIG_PAX_KERNEXEC
81146+void *module_alloc_exec(unsigned long size);
81147+#else
81148+#define module_alloc_exec(x) module_alloc(x)
81149+#endif
81150+
81151 /* Free memory returned from module_alloc. */
81152 void module_free(struct module *mod, void *module_region);
81153
81154+#ifdef CONFIG_PAX_KERNEXEC
81155+void module_free_exec(struct module *mod, void *module_region);
81156+#else
81157+#define module_free_exec(x, y) module_free((x), (y))
81158+#endif
81159+
81160 /*
81161 * Apply the given relocation to the (simplified) ELF. Return -error
81162 * or 0.
81163@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
81164 unsigned int relsec,
81165 struct module *me)
81166 {
81167+#ifdef CONFIG_MODULES
81168 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
81169+#endif
81170 return -ENOEXEC;
81171 }
81172 #endif
81173@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
81174 unsigned int relsec,
81175 struct module *me)
81176 {
81177+#ifdef CONFIG_MODULES
81178 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
81179+#endif
81180 return -ENOEXEC;
81181 }
81182 #endif
81183diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
81184index c3eb102..073c4a6 100644
81185--- a/include/linux/moduleparam.h
81186+++ b/include/linux/moduleparam.h
81187@@ -295,7 +295,7 @@ static inline void __kernel_param_unlock(void)
81188 * @len is usually just sizeof(string).
81189 */
81190 #define module_param_string(name, string, len, perm) \
81191- static const struct kparam_string __param_string_##name \
81192+ static const struct kparam_string __param_string_##name __used \
81193 = { len, string }; \
81194 __module_param_call(MODULE_PARAM_PREFIX, name, \
81195 &param_ops_string, \
81196@@ -434,7 +434,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
81197 */
81198 #define module_param_array_named(name, array, type, nump, perm) \
81199 param_check_##type(name, &(array)[0]); \
81200- static const struct kparam_array __param_arr_##name \
81201+ static const struct kparam_array __param_arr_##name __used \
81202 = { .max = ARRAY_SIZE(array), .num = nump, \
81203 .ops = &param_ops_##type, \
81204 .elemsize = sizeof(array[0]), .elem = array }; \
81205diff --git a/include/linux/mount.h b/include/linux/mount.h
81206index 839bac2..a96b37c 100644
81207--- a/include/linux/mount.h
81208+++ b/include/linux/mount.h
81209@@ -59,7 +59,7 @@ struct vfsmount {
81210 struct dentry *mnt_root; /* root of the mounted tree */
81211 struct super_block *mnt_sb; /* pointer to superblock */
81212 int mnt_flags;
81213-};
81214+} __randomize_layout;
81215
81216 struct file; /* forward dec */
81217
81218diff --git a/include/linux/namei.h b/include/linux/namei.h
81219index 492de72..1bddcd4 100644
81220--- a/include/linux/namei.h
81221+++ b/include/linux/namei.h
81222@@ -19,7 +19,7 @@ struct nameidata {
81223 unsigned seq, m_seq;
81224 int last_type;
81225 unsigned depth;
81226- char *saved_names[MAX_NESTED_LINKS + 1];
81227+ const char *saved_names[MAX_NESTED_LINKS + 1];
81228 };
81229
81230 /*
81231@@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
81232
81233 extern void nd_jump_link(struct nameidata *nd, struct path *path);
81234
81235-static inline void nd_set_link(struct nameidata *nd, char *path)
81236+static inline void nd_set_link(struct nameidata *nd, const char *path)
81237 {
81238 nd->saved_names[nd->depth] = path;
81239 }
81240
81241-static inline char *nd_get_link(struct nameidata *nd)
81242+static inline const char *nd_get_link(const struct nameidata *nd)
81243 {
81244 return nd->saved_names[nd->depth];
81245 }
81246diff --git a/include/linux/net.h b/include/linux/net.h
81247index 94734a6..d8d6931 100644
81248--- a/include/linux/net.h
81249+++ b/include/linux/net.h
81250@@ -192,7 +192,7 @@ struct net_proto_family {
81251 int (*create)(struct net *net, struct socket *sock,
81252 int protocol, int kern);
81253 struct module *owner;
81254-};
81255+} __do_const;
81256
81257 struct iovec;
81258 struct kvec;
81259diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
81260index daafd95..74c5d1e 100644
81261--- a/include/linux/netdevice.h
81262+++ b/include/linux/netdevice.h
81263@@ -1146,6 +1146,7 @@ struct net_device_ops {
81264 struct net_device *dev,
81265 void *priv);
81266 };
81267+typedef struct net_device_ops __no_const net_device_ops_no_const;
81268
81269 /*
81270 * The DEVICE structure.
81271@@ -1228,7 +1229,7 @@ struct net_device {
81272 int iflink;
81273
81274 struct net_device_stats stats;
81275- atomic_long_t rx_dropped; /* dropped packets by core network
81276+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
81277 * Do not use this in drivers.
81278 */
81279
81280diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
81281index 2077489..a15e561 100644
81282--- a/include/linux/netfilter.h
81283+++ b/include/linux/netfilter.h
81284@@ -84,7 +84,7 @@ struct nf_sockopt_ops {
81285 #endif
81286 /* Use the module struct to lock set/get code in place */
81287 struct module *owner;
81288-};
81289+} __do_const;
81290
81291 /* Function to register/unregister hook points. */
81292 int nf_register_hook(struct nf_hook_ops *reg);
81293diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
81294index 28c7436..2d6156a 100644
81295--- a/include/linux/netfilter/nfnetlink.h
81296+++ b/include/linux/netfilter/nfnetlink.h
81297@@ -19,7 +19,7 @@ struct nfnl_callback {
81298 const struct nlattr * const cda[]);
81299 const struct nla_policy *policy; /* netlink attribute policy */
81300 const u_int16_t attr_count; /* number of nlattr's */
81301-};
81302+} __do_const;
81303
81304 struct nfnetlink_subsystem {
81305 const char *name;
81306diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
81307new file mode 100644
81308index 0000000..33f4af8
81309--- /dev/null
81310+++ b/include/linux/netfilter/xt_gradm.h
81311@@ -0,0 +1,9 @@
81312+#ifndef _LINUX_NETFILTER_XT_GRADM_H
81313+#define _LINUX_NETFILTER_XT_GRADM_H 1
81314+
81315+struct xt_gradm_mtinfo {
81316+ __u16 flags;
81317+ __u16 invflags;
81318+};
81319+
81320+#endif
81321diff --git a/include/linux/nls.h b/include/linux/nls.h
81322index 520681b..1d67ed2 100644
81323--- a/include/linux/nls.h
81324+++ b/include/linux/nls.h
81325@@ -31,7 +31,7 @@ struct nls_table {
81326 const unsigned char *charset2upper;
81327 struct module *owner;
81328 struct nls_table *next;
81329-};
81330+} __do_const;
81331
81332 /* this value hold the maximum octet of charset */
81333 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
81334diff --git a/include/linux/notifier.h b/include/linux/notifier.h
81335index d14a4c3..a078786 100644
81336--- a/include/linux/notifier.h
81337+++ b/include/linux/notifier.h
81338@@ -54,7 +54,8 @@ struct notifier_block {
81339 notifier_fn_t notifier_call;
81340 struct notifier_block __rcu *next;
81341 int priority;
81342-};
81343+} __do_const;
81344+typedef struct notifier_block __no_const notifier_block_no_const;
81345
81346 struct atomic_notifier_head {
81347 spinlock_t lock;
81348diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
81349index b2a0f15..4d7da32 100644
81350--- a/include/linux/oprofile.h
81351+++ b/include/linux/oprofile.h
81352@@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
81353 int oprofilefs_create_ro_ulong(struct dentry * root,
81354 char const * name, ulong * val);
81355
81356-/** Create a file for read-only access to an atomic_t. */
81357+/** Create a file for read-only access to an atomic_unchecked_t. */
81358 int oprofilefs_create_ro_atomic(struct dentry * root,
81359- char const * name, atomic_t * val);
81360+ char const * name, atomic_unchecked_t * val);
81361
81362 /** create a directory */
81363 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
81364diff --git a/include/linux/padata.h b/include/linux/padata.h
81365index 4386946..f50c615 100644
81366--- a/include/linux/padata.h
81367+++ b/include/linux/padata.h
81368@@ -129,7 +129,7 @@ struct parallel_data {
81369 struct padata_serial_queue __percpu *squeue;
81370 atomic_t reorder_objects;
81371 atomic_t refcnt;
81372- atomic_t seq_nr;
81373+ atomic_unchecked_t seq_nr;
81374 struct padata_cpumask cpumask;
81375 spinlock_t lock ____cacheline_aligned;
81376 unsigned int processed;
81377diff --git a/include/linux/path.h b/include/linux/path.h
81378index d137218..be0c176 100644
81379--- a/include/linux/path.h
81380+++ b/include/linux/path.h
81381@@ -1,13 +1,15 @@
81382 #ifndef _LINUX_PATH_H
81383 #define _LINUX_PATH_H
81384
81385+#include <linux/compiler.h>
81386+
81387 struct dentry;
81388 struct vfsmount;
81389
81390 struct path {
81391 struct vfsmount *mnt;
81392 struct dentry *dentry;
81393-};
81394+} __randomize_layout;
81395
81396 extern void path_get(const struct path *);
81397 extern void path_put(const struct path *);
81398diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
81399index 5f2e559..7d59314 100644
81400--- a/include/linux/pci_hotplug.h
81401+++ b/include/linux/pci_hotplug.h
81402@@ -71,7 +71,8 @@ struct hotplug_slot_ops {
81403 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
81404 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
81405 int (*reset_slot) (struct hotplug_slot *slot, int probe);
81406-};
81407+} __do_const;
81408+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
81409
81410 /**
81411 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
81412diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
81413index e56b07f..aef789b 100644
81414--- a/include/linux/perf_event.h
81415+++ b/include/linux/perf_event.h
81416@@ -328,8 +328,8 @@ struct perf_event {
81417
81418 enum perf_event_active_state state;
81419 unsigned int attach_state;
81420- local64_t count;
81421- atomic64_t child_count;
81422+ local64_t count; /* PaX: fix it one day */
81423+ atomic64_unchecked_t child_count;
81424
81425 /*
81426 * These are the total time in nanoseconds that the event
81427@@ -380,8 +380,8 @@ struct perf_event {
81428 * These accumulate total time (in nanoseconds) that children
81429 * events have been enabled and running, respectively.
81430 */
81431- atomic64_t child_total_time_enabled;
81432- atomic64_t child_total_time_running;
81433+ atomic64_unchecked_t child_total_time_enabled;
81434+ atomic64_unchecked_t child_total_time_running;
81435
81436 /*
81437 * Protect attach/detach and child_list:
81438@@ -708,7 +708,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
81439 entry->ip[entry->nr++] = ip;
81440 }
81441
81442-extern int sysctl_perf_event_paranoid;
81443+extern int sysctl_perf_event_legitimately_concerned;
81444 extern int sysctl_perf_event_mlock;
81445 extern int sysctl_perf_event_sample_rate;
81446 extern int sysctl_perf_cpu_time_max_percent;
81447@@ -723,19 +723,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
81448 loff_t *ppos);
81449
81450
81451+static inline bool perf_paranoid_any(void)
81452+{
81453+ return sysctl_perf_event_legitimately_concerned > 2;
81454+}
81455+
81456 static inline bool perf_paranoid_tracepoint_raw(void)
81457 {
81458- return sysctl_perf_event_paranoid > -1;
81459+ return sysctl_perf_event_legitimately_concerned > -1;
81460 }
81461
81462 static inline bool perf_paranoid_cpu(void)
81463 {
81464- return sysctl_perf_event_paranoid > 0;
81465+ return sysctl_perf_event_legitimately_concerned > 0;
81466 }
81467
81468 static inline bool perf_paranoid_kernel(void)
81469 {
81470- return sysctl_perf_event_paranoid > 1;
81471+ return sysctl_perf_event_legitimately_concerned > 1;
81472 }
81473
81474 extern void perf_event_init(void);
81475@@ -851,7 +856,7 @@ struct perf_pmu_events_attr {
81476 struct device_attribute attr;
81477 u64 id;
81478 const char *event_str;
81479-};
81480+} __do_const;
81481
81482 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
81483 static struct perf_pmu_events_attr _var = { \
81484diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
81485index 7246ef3..1539ea4 100644
81486--- a/include/linux/pid_namespace.h
81487+++ b/include/linux/pid_namespace.h
81488@@ -43,7 +43,7 @@ struct pid_namespace {
81489 int hide_pid;
81490 int reboot; /* group exit code if this pidns was rebooted */
81491 unsigned int proc_inum;
81492-};
81493+} __randomize_layout;
81494
81495 extern struct pid_namespace init_pid_ns;
81496
81497diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
81498index ab57526..94598804 100644
81499--- a/include/linux/pipe_fs_i.h
81500+++ b/include/linux/pipe_fs_i.h
81501@@ -47,10 +47,10 @@ struct pipe_inode_info {
81502 struct mutex mutex;
81503 wait_queue_head_t wait;
81504 unsigned int nrbufs, curbuf, buffers;
81505- unsigned int readers;
81506- unsigned int writers;
81507- unsigned int files;
81508- unsigned int waiting_writers;
81509+ atomic_t readers;
81510+ atomic_t writers;
81511+ atomic_t files;
81512+ atomic_t waiting_writers;
81513 unsigned int r_counter;
81514 unsigned int w_counter;
81515 struct page *tmp_page;
81516diff --git a/include/linux/pm.h b/include/linux/pm.h
81517index 8c6583a..febb84c 100644
81518--- a/include/linux/pm.h
81519+++ b/include/linux/pm.h
81520@@ -597,6 +597,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
81521 struct dev_pm_domain {
81522 struct dev_pm_ops ops;
81523 };
81524+typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
81525
81526 /*
81527 * The PM_EVENT_ messages are also used by drivers implementing the legacy
81528diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
81529index 7c1d252..0e7061d 100644
81530--- a/include/linux/pm_domain.h
81531+++ b/include/linux/pm_domain.h
81532@@ -44,11 +44,11 @@ struct gpd_dev_ops {
81533 int (*thaw_early)(struct device *dev);
81534 int (*thaw)(struct device *dev);
81535 bool (*active_wakeup)(struct device *dev);
81536-};
81537+} __no_const;
81538
81539 struct gpd_cpu_data {
81540 unsigned int saved_exit_latency;
81541- struct cpuidle_state *idle_state;
81542+ cpuidle_state_no_const *idle_state;
81543 };
81544
81545 struct generic_pm_domain {
81546diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
81547index 16c9a62..f9f0838 100644
81548--- a/include/linux/pm_runtime.h
81549+++ b/include/linux/pm_runtime.h
81550@@ -109,7 +109,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
81551
81552 static inline void pm_runtime_mark_last_busy(struct device *dev)
81553 {
81554- ACCESS_ONCE(dev->power.last_busy) = jiffies;
81555+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
81556 }
81557
81558 #else /* !CONFIG_PM_RUNTIME */
81559diff --git a/include/linux/pnp.h b/include/linux/pnp.h
81560index 195aafc..49a7bc2 100644
81561--- a/include/linux/pnp.h
81562+++ b/include/linux/pnp.h
81563@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
81564 struct pnp_fixup {
81565 char id[7];
81566 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
81567-};
81568+} __do_const;
81569
81570 /* config parameters */
81571 #define PNP_CONFIG_NORMAL 0x0001
81572diff --git a/include/linux/poison.h b/include/linux/poison.h
81573index 2110a81..13a11bb 100644
81574--- a/include/linux/poison.h
81575+++ b/include/linux/poison.h
81576@@ -19,8 +19,8 @@
81577 * under normal circumstances, used to verify that nobody uses
81578 * non-initialized list entries.
81579 */
81580-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
81581-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
81582+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
81583+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
81584
81585 /********** include/linux/timer.h **********/
81586 /*
81587diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
81588index d8b187c3..9a9257a 100644
81589--- a/include/linux/power/smartreflex.h
81590+++ b/include/linux/power/smartreflex.h
81591@@ -238,7 +238,7 @@ struct omap_sr_class_data {
81592 int (*notify)(struct omap_sr *sr, u32 status);
81593 u8 notify_flags;
81594 u8 class_type;
81595-};
81596+} __do_const;
81597
81598 /**
81599 * struct omap_sr_nvalue_table - Smartreflex n-target value info
81600diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
81601index 4ea1d37..80f4b33 100644
81602--- a/include/linux/ppp-comp.h
81603+++ b/include/linux/ppp-comp.h
81604@@ -84,7 +84,7 @@ struct compressor {
81605 struct module *owner;
81606 /* Extra skb space needed by the compressor algorithm */
81607 unsigned int comp_extra;
81608-};
81609+} __do_const;
81610
81611 /*
81612 * The return value from decompress routine is the length of the
81613diff --git a/include/linux/preempt.h b/include/linux/preempt.h
81614index de83b4e..c4b997d 100644
81615--- a/include/linux/preempt.h
81616+++ b/include/linux/preempt.h
81617@@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
81618 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
81619 #endif
81620
81621+#define raw_preempt_count_add(val) __preempt_count_add(val)
81622+#define raw_preempt_count_sub(val) __preempt_count_sub(val)
81623+
81624 #define __preempt_count_inc() __preempt_count_add(1)
81625 #define __preempt_count_dec() __preempt_count_sub(1)
81626
81627 #define preempt_count_inc() preempt_count_add(1)
81628+#define raw_preempt_count_inc() raw_preempt_count_add(1)
81629 #define preempt_count_dec() preempt_count_sub(1)
81630+#define raw_preempt_count_dec() raw_preempt_count_sub(1)
81631
81632 #ifdef CONFIG_PREEMPT_COUNT
81633
81634@@ -41,6 +46,12 @@ do { \
81635 barrier(); \
81636 } while (0)
81637
81638+#define raw_preempt_disable() \
81639+do { \
81640+ raw_preempt_count_inc(); \
81641+ barrier(); \
81642+} while (0)
81643+
81644 #define sched_preempt_enable_no_resched() \
81645 do { \
81646 barrier(); \
81647@@ -49,6 +60,12 @@ do { \
81648
81649 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
81650
81651+#define raw_preempt_enable_no_resched() \
81652+do { \
81653+ barrier(); \
81654+ raw_preempt_count_dec(); \
81655+} while (0)
81656+
81657 #ifdef CONFIG_PREEMPT
81658 #define preempt_enable() \
81659 do { \
81660@@ -113,8 +130,10 @@ do { \
81661 * region.
81662 */
81663 #define preempt_disable() barrier()
81664+#define raw_preempt_disable() barrier()
81665 #define sched_preempt_enable_no_resched() barrier()
81666 #define preempt_enable_no_resched() barrier()
81667+#define raw_preempt_enable_no_resched() barrier()
81668 #define preempt_enable() barrier()
81669 #define preempt_check_resched() do { } while (0)
81670
81671@@ -128,11 +147,13 @@ do { \
81672 /*
81673 * Modules have no business playing preemption tricks.
81674 */
81675+#ifndef CONFIG_PAX_KERNEXEC
81676 #undef sched_preempt_enable_no_resched
81677 #undef preempt_enable_no_resched
81678 #undef preempt_enable_no_resched_notrace
81679 #undef preempt_check_resched
81680 #endif
81681+#endif
81682
81683 #define preempt_set_need_resched() \
81684 do { \
81685diff --git a/include/linux/printk.h b/include/linux/printk.h
81686index fa47e27..c08e034 100644
81687--- a/include/linux/printk.h
81688+++ b/include/linux/printk.h
81689@@ -114,6 +114,8 @@ static inline __printf(1, 2) __cold
81690 void early_printk(const char *s, ...) { }
81691 #endif
81692
81693+extern int kptr_restrict;
81694+
81695 #ifdef CONFIG_PRINTK
81696 asmlinkage __printf(5, 0)
81697 int vprintk_emit(int facility, int level,
81698@@ -148,7 +150,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
81699
81700 extern int printk_delay_msec;
81701 extern int dmesg_restrict;
81702-extern int kptr_restrict;
81703
81704 extern void wake_up_klogd(void);
81705
81706diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
81707index 608e60a..bbcb1a0 100644
81708--- a/include/linux/proc_fs.h
81709+++ b/include/linux/proc_fs.h
81710@@ -17,8 +17,11 @@ extern void proc_flush_task(struct task_struct *);
81711 extern struct proc_dir_entry *proc_symlink(const char *,
81712 struct proc_dir_entry *, const char *);
81713 extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
81714+extern struct proc_dir_entry *proc_mkdir_restrict(const char *, struct proc_dir_entry *);
81715 extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
81716 struct proc_dir_entry *, void *);
81717+extern struct proc_dir_entry *proc_mkdir_data_restrict(const char *, umode_t,
81718+ struct proc_dir_entry *, void *);
81719 extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
81720 struct proc_dir_entry *);
81721
81722@@ -34,6 +37,19 @@ static inline struct proc_dir_entry *proc_create(
81723 return proc_create_data(name, mode, parent, proc_fops, NULL);
81724 }
81725
81726+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
81727+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
81728+{
81729+#ifdef CONFIG_GRKERNSEC_PROC_USER
81730+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
81731+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
81732+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
81733+#else
81734+ return proc_create_data(name, mode, parent, proc_fops, NULL);
81735+#endif
81736+}
81737+
81738+
81739 extern void proc_set_size(struct proc_dir_entry *, loff_t);
81740 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
81741 extern void *PDE_DATA(const struct inode *);
81742@@ -73,7 +89,7 @@ static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *p
81743 static inline struct proc_dir_entry *proc_net_mkdir(
81744 struct net *net, const char *name, struct proc_dir_entry *parent)
81745 {
81746- return proc_mkdir_data(name, 0, parent, net);
81747+ return proc_mkdir_data_restrict(name, 0, parent, net);
81748 }
81749
81750 #endif /* _LINUX_PROC_FS_H */
81751diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
81752index 34a1e10..70f6bde 100644
81753--- a/include/linux/proc_ns.h
81754+++ b/include/linux/proc_ns.h
81755@@ -14,7 +14,7 @@ struct proc_ns_operations {
81756 void (*put)(void *ns);
81757 int (*install)(struct nsproxy *nsproxy, void *ns);
81758 unsigned int (*inum)(void *ns);
81759-};
81760+} __do_const __randomize_layout;
81761
81762 struct proc_ns {
81763 void *ns;
81764diff --git a/include/linux/quota.h b/include/linux/quota.h
81765index cc7494a..1e27036 100644
81766--- a/include/linux/quota.h
81767+++ b/include/linux/quota.h
81768@@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
81769
81770 extern bool qid_eq(struct kqid left, struct kqid right);
81771 extern bool qid_lt(struct kqid left, struct kqid right);
81772-extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
81773+extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
81774 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
81775 extern bool qid_valid(struct kqid qid);
81776
81777diff --git a/include/linux/random.h b/include/linux/random.h
81778index 1cfce0e..b0b9235 100644
81779--- a/include/linux/random.h
81780+++ b/include/linux/random.h
81781@@ -9,9 +9,19 @@
81782 #include <uapi/linux/random.h>
81783
81784 extern void add_device_randomness(const void *, unsigned int);
81785+
81786+static inline void add_latent_entropy(void)
81787+{
81788+
81789+#ifdef LATENT_ENTROPY_PLUGIN
81790+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
81791+#endif
81792+
81793+}
81794+
81795 extern void add_input_randomness(unsigned int type, unsigned int code,
81796- unsigned int value);
81797-extern void add_interrupt_randomness(int irq, int irq_flags);
81798+ unsigned int value) __latent_entropy;
81799+extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
81800
81801 extern void get_random_bytes(void *buf, int nbytes);
81802 extern void get_random_bytes_arch(void *buf, int nbytes);
81803@@ -22,10 +32,10 @@ extern int random_int_secret_init(void);
81804 extern const struct file_operations random_fops, urandom_fops;
81805 #endif
81806
81807-unsigned int get_random_int(void);
81808+unsigned int __intentional_overflow(-1) get_random_int(void);
81809 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
81810
81811-u32 prandom_u32(void);
81812+u32 prandom_u32(void) __intentional_overflow(-1);
81813 void prandom_bytes(void *buf, int nbytes);
81814 void prandom_seed(u32 seed);
81815 void prandom_reseed_late(void);
81816@@ -37,6 +47,11 @@ struct rnd_state {
81817 u32 prandom_u32_state(struct rnd_state *state);
81818 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
81819
81820+static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
81821+{
81822+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
81823+}
81824+
81825 /**
81826 * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro)
81827 * @ep_ro: right open interval endpoint
81828diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
81829index fea49b5..2ac22bb 100644
81830--- a/include/linux/rbtree_augmented.h
81831+++ b/include/linux/rbtree_augmented.h
81832@@ -80,7 +80,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
81833 old->rbaugmented = rbcompute(old); \
81834 } \
81835 rbstatic const struct rb_augment_callbacks rbname = { \
81836- rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
81837+ .propagate = rbname ## _propagate, \
81838+ .copy = rbname ## _copy, \
81839+ .rotate = rbname ## _rotate \
81840 };
81841
81842
81843diff --git a/include/linux/rculist.h b/include/linux/rculist.h
81844index dbaf990..52e07b8 100644
81845--- a/include/linux/rculist.h
81846+++ b/include/linux/rculist.h
81847@@ -29,8 +29,8 @@
81848 */
81849 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
81850 {
81851- ACCESS_ONCE(list->next) = list;
81852- ACCESS_ONCE(list->prev) = list;
81853+ ACCESS_ONCE_RW(list->next) = list;
81854+ ACCESS_ONCE_RW(list->prev) = list;
81855 }
81856
81857 /*
81858@@ -59,6 +59,9 @@ void __list_add_rcu(struct list_head *new,
81859 struct list_head *prev, struct list_head *next);
81860 #endif
81861
81862+void __pax_list_add_rcu(struct list_head *new,
81863+ struct list_head *prev, struct list_head *next);
81864+
81865 /**
81866 * list_add_rcu - add a new entry to rcu-protected list
81867 * @new: new entry to be added
81868@@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
81869 __list_add_rcu(new, head, head->next);
81870 }
81871
81872+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
81873+{
81874+ __pax_list_add_rcu(new, head, head->next);
81875+}
81876+
81877 /**
81878 * list_add_tail_rcu - add a new entry to rcu-protected list
81879 * @new: new entry to be added
81880@@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
81881 __list_add_rcu(new, head->prev, head);
81882 }
81883
81884+static inline void pax_list_add_tail_rcu(struct list_head *new,
81885+ struct list_head *head)
81886+{
81887+ __pax_list_add_rcu(new, head->prev, head);
81888+}
81889+
81890 /**
81891 * list_del_rcu - deletes entry from list without re-initialization
81892 * @entry: the element to delete from the list.
81893@@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
81894 entry->prev = LIST_POISON2;
81895 }
81896
81897+extern void pax_list_del_rcu(struct list_head *entry);
81898+
81899 /**
81900 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
81901 * @n: the element to delete from the hash list.
81902diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
81903index 72bf3a0..853347f 100644
81904--- a/include/linux/rcupdate.h
81905+++ b/include/linux/rcupdate.h
81906@@ -588,7 +588,7 @@ static inline void rcu_preempt_sleep_check(void)
81907 #define rcu_assign_pointer(p, v) \
81908 do { \
81909 smp_wmb(); \
81910- ACCESS_ONCE(p) = RCU_INITIALIZER(v); \
81911+ ACCESS_ONCE_RW(p) = RCU_INITIALIZER(v); \
81912 } while (0)
81913
81914
81915diff --git a/include/linux/reboot.h b/include/linux/reboot.h
81916index 9e7db9e..7d4fd72 100644
81917--- a/include/linux/reboot.h
81918+++ b/include/linux/reboot.h
81919@@ -44,9 +44,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
81920 */
81921
81922 extern void migrate_to_reboot_cpu(void);
81923-extern void machine_restart(char *cmd);
81924-extern void machine_halt(void);
81925-extern void machine_power_off(void);
81926+extern void machine_restart(char *cmd) __noreturn;
81927+extern void machine_halt(void) __noreturn;
81928+extern void machine_power_off(void) __noreturn;
81929
81930 extern void machine_shutdown(void);
81931 struct pt_regs;
81932@@ -57,9 +57,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
81933 */
81934
81935 extern void kernel_restart_prepare(char *cmd);
81936-extern void kernel_restart(char *cmd);
81937-extern void kernel_halt(void);
81938-extern void kernel_power_off(void);
81939+extern void kernel_restart(char *cmd) __noreturn;
81940+extern void kernel_halt(void) __noreturn;
81941+extern void kernel_power_off(void) __noreturn;
81942
81943 extern int C_A_D; /* for sysctl */
81944 void ctrl_alt_del(void);
81945@@ -73,7 +73,7 @@ extern int orderly_poweroff(bool force);
81946 * Emergency restart, callable from an interrupt handler.
81947 */
81948
81949-extern void emergency_restart(void);
81950+extern void emergency_restart(void) __noreturn;
81951 #include <asm/emergency-restart.h>
81952
81953 #endif /* _LINUX_REBOOT_H */
81954diff --git a/include/linux/regset.h b/include/linux/regset.h
81955index 8e0c9fe..ac4d221 100644
81956--- a/include/linux/regset.h
81957+++ b/include/linux/regset.h
81958@@ -161,7 +161,8 @@ struct user_regset {
81959 unsigned int align;
81960 unsigned int bias;
81961 unsigned int core_note_type;
81962-};
81963+} __do_const;
81964+typedef struct user_regset __no_const user_regset_no_const;
81965
81966 /**
81967 * struct user_regset_view - available regsets
81968diff --git a/include/linux/relay.h b/include/linux/relay.h
81969index d7c8359..818daf5 100644
81970--- a/include/linux/relay.h
81971+++ b/include/linux/relay.h
81972@@ -157,7 +157,7 @@ struct rchan_callbacks
81973 * The callback should return 0 if successful, negative if not.
81974 */
81975 int (*remove_buf_file)(struct dentry *dentry);
81976-};
81977+} __no_const;
81978
81979 /*
81980 * CONFIG_RELAY kernel API, kernel/relay.c
81981diff --git a/include/linux/rio.h b/include/linux/rio.h
81982index b71d573..2f940bd 100644
81983--- a/include/linux/rio.h
81984+++ b/include/linux/rio.h
81985@@ -355,7 +355,7 @@ struct rio_ops {
81986 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
81987 u64 rstart, u32 size, u32 flags);
81988 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
81989-};
81990+} __no_const;
81991
81992 #define RIO_RESOURCE_MEM 0x00000100
81993 #define RIO_RESOURCE_DOORBELL 0x00000200
81994diff --git a/include/linux/rmap.h b/include/linux/rmap.h
81995index b66c211..13d2915 100644
81996--- a/include/linux/rmap.h
81997+++ b/include/linux/rmap.h
81998@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
81999 void anon_vma_init(void); /* create anon_vma_cachep */
82000 int anon_vma_prepare(struct vm_area_struct *);
82001 void unlink_anon_vmas(struct vm_area_struct *);
82002-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
82003-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
82004+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
82005+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
82006
82007 static inline void anon_vma_merge(struct vm_area_struct *vma,
82008 struct vm_area_struct *next)
82009diff --git a/include/linux/sched.h b/include/linux/sched.h
82010index a781dec..be1d2a3 100644
82011--- a/include/linux/sched.h
82012+++ b/include/linux/sched.h
82013@@ -129,6 +129,7 @@ struct fs_struct;
82014 struct perf_event_context;
82015 struct blk_plug;
82016 struct filename;
82017+struct linux_binprm;
82018
82019 /*
82020 * List of flags we want to share for kernel threads,
82021@@ -369,7 +370,7 @@ extern char __sched_text_start[], __sched_text_end[];
82022 extern int in_sched_functions(unsigned long addr);
82023
82024 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
82025-extern signed long schedule_timeout(signed long timeout);
82026+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
82027 extern signed long schedule_timeout_interruptible(signed long timeout);
82028 extern signed long schedule_timeout_killable(signed long timeout);
82029 extern signed long schedule_timeout_uninterruptible(signed long timeout);
82030@@ -380,6 +381,19 @@ struct nsproxy;
82031 struct user_namespace;
82032
82033 #ifdef CONFIG_MMU
82034+
82035+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
82036+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
82037+#else
82038+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
82039+{
82040+ return 0;
82041+}
82042+#endif
82043+
82044+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
82045+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
82046+
82047 extern void arch_pick_mmap_layout(struct mm_struct *mm);
82048 extern unsigned long
82049 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
82050@@ -677,6 +691,17 @@ struct signal_struct {
82051 #ifdef CONFIG_TASKSTATS
82052 struct taskstats *stats;
82053 #endif
82054+
82055+#ifdef CONFIG_GRKERNSEC
82056+ u32 curr_ip;
82057+ u32 saved_ip;
82058+ u32 gr_saddr;
82059+ u32 gr_daddr;
82060+ u16 gr_sport;
82061+ u16 gr_dport;
82062+ u8 used_accept:1;
82063+#endif
82064+
82065 #ifdef CONFIG_AUDIT
82066 unsigned audit_tty;
82067 unsigned audit_tty_log_passwd;
82068@@ -703,7 +728,7 @@ struct signal_struct {
82069 struct mutex cred_guard_mutex; /* guard against foreign influences on
82070 * credential calculations
82071 * (notably. ptrace) */
82072-};
82073+} __randomize_layout;
82074
82075 /*
82076 * Bits in flags field of signal_struct.
82077@@ -757,6 +782,14 @@ struct user_struct {
82078 struct key *session_keyring; /* UID's default session keyring */
82079 #endif
82080
82081+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
82082+ unsigned char kernel_banned;
82083+#endif
82084+#ifdef CONFIG_GRKERNSEC_BRUTE
82085+ unsigned char suid_banned;
82086+ unsigned long suid_ban_expires;
82087+#endif
82088+
82089 /* Hash table maintenance information */
82090 struct hlist_node uidhash_node;
82091 kuid_t uid;
82092@@ -764,7 +797,7 @@ struct user_struct {
82093 #ifdef CONFIG_PERF_EVENTS
82094 atomic_long_t locked_vm;
82095 #endif
82096-};
82097+} __randomize_layout;
82098
82099 extern int uids_sysfs_init(void);
82100
82101@@ -1286,8 +1319,8 @@ struct task_struct {
82102 struct list_head thread_node;
82103
82104 struct completion *vfork_done; /* for vfork() */
82105- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
82106- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
82107+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
82108+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
82109
82110 cputime_t utime, stime, utimescaled, stimescaled;
82111 cputime_t gtime;
82112@@ -1312,11 +1345,6 @@ struct task_struct {
82113 struct task_cputime cputime_expires;
82114 struct list_head cpu_timers[3];
82115
82116-/* process credentials */
82117- const struct cred __rcu *real_cred; /* objective and real subjective task
82118- * credentials (COW) */
82119- const struct cred __rcu *cred; /* effective (overridable) subjective task
82120- * credentials (COW) */
82121 char comm[TASK_COMM_LEN]; /* executable name excluding path
82122 - access with [gs]et_task_comm (which lock
82123 it with task_lock())
82124@@ -1333,6 +1361,10 @@ struct task_struct {
82125 #endif
82126 /* CPU-specific state of this task */
82127 struct thread_struct thread;
82128+/* thread_info moved to task_struct */
82129+#ifdef CONFIG_X86
82130+ struct thread_info tinfo;
82131+#endif
82132 /* filesystem information */
82133 struct fs_struct *fs;
82134 /* open file information */
82135@@ -1409,6 +1441,10 @@ struct task_struct {
82136 gfp_t lockdep_reclaim_gfp;
82137 #endif
82138
82139+/* process credentials */
82140+ const struct cred __rcu *real_cred; /* objective and real subjective task
82141+ * credentials (COW) */
82142+
82143 /* journalling filesystem info */
82144 void *journal_info;
82145
82146@@ -1447,6 +1483,10 @@ struct task_struct {
82147 /* cg_list protected by css_set_lock and tsk->alloc_lock */
82148 struct list_head cg_list;
82149 #endif
82150+
82151+ const struct cred __rcu *cred; /* effective (overridable) subjective task
82152+ * credentials (COW) */
82153+
82154 #ifdef CONFIG_FUTEX
82155 struct robust_list_head __user *robust_list;
82156 #ifdef CONFIG_COMPAT
82157@@ -1581,7 +1621,78 @@ struct task_struct {
82158 unsigned int sequential_io;
82159 unsigned int sequential_io_avg;
82160 #endif
82161-};
82162+
82163+#ifdef CONFIG_GRKERNSEC
82164+ /* grsecurity */
82165+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
82166+ u64 exec_id;
82167+#endif
82168+#ifdef CONFIG_GRKERNSEC_SETXID
82169+ const struct cred *delayed_cred;
82170+#endif
82171+ struct dentry *gr_chroot_dentry;
82172+ struct acl_subject_label *acl;
82173+ struct acl_subject_label *tmpacl;
82174+ struct acl_role_label *role;
82175+ struct file *exec_file;
82176+ unsigned long brute_expires;
82177+ u16 acl_role_id;
82178+ u8 inherited;
82179+ /* is this the task that authenticated to the special role */
82180+ u8 acl_sp_role;
82181+ u8 is_writable;
82182+ u8 brute;
82183+ u8 gr_is_chrooted;
82184+#endif
82185+
82186+} __randomize_layout;
82187+
82188+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
82189+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
82190+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
82191+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
82192+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
82193+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
82194+
82195+#ifdef CONFIG_PAX_SOFTMODE
82196+extern int pax_softmode;
82197+#endif
82198+
82199+extern int pax_check_flags(unsigned long *);
82200+#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
82201+
82202+/* if tsk != current then task_lock must be held on it */
82203+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
82204+static inline unsigned long pax_get_flags(struct task_struct *tsk)
82205+{
82206+ if (likely(tsk->mm))
82207+ return tsk->mm->pax_flags;
82208+ else
82209+ return 0UL;
82210+}
82211+
82212+/* if tsk != current then task_lock must be held on it */
82213+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
82214+{
82215+ if (likely(tsk->mm)) {
82216+ tsk->mm->pax_flags = flags;
82217+ return 0;
82218+ }
82219+ return -EINVAL;
82220+}
82221+#endif
82222+
82223+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
82224+extern void pax_set_initial_flags(struct linux_binprm *bprm);
82225+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
82226+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
82227+#endif
82228+
82229+struct path;
82230+extern char *pax_get_path(const struct path *path, char *buf, int buflen);
82231+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
82232+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
82233+extern void pax_report_refcount_overflow(struct pt_regs *regs);
82234
82235 /* Future-safe accessor for struct task_struct's cpus_allowed. */
82236 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
82237@@ -1658,7 +1769,7 @@ struct pid_namespace;
82238 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
82239 struct pid_namespace *ns);
82240
82241-static inline pid_t task_pid_nr(struct task_struct *tsk)
82242+static inline pid_t task_pid_nr(const struct task_struct *tsk)
82243 {
82244 return tsk->pid;
82245 }
82246@@ -2112,7 +2223,9 @@ void yield(void);
82247 extern struct exec_domain default_exec_domain;
82248
82249 union thread_union {
82250+#ifndef CONFIG_X86
82251 struct thread_info thread_info;
82252+#endif
82253 unsigned long stack[THREAD_SIZE/sizeof(long)];
82254 };
82255
82256@@ -2145,6 +2258,7 @@ extern struct pid_namespace init_pid_ns;
82257 */
82258
82259 extern struct task_struct *find_task_by_vpid(pid_t nr);
82260+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
82261 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
82262 struct pid_namespace *ns);
82263
82264@@ -2307,7 +2421,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
82265 extern void exit_itimers(struct signal_struct *);
82266 extern void flush_itimer_signals(void);
82267
82268-extern void do_group_exit(int);
82269+extern __noreturn void do_group_exit(int);
82270
82271 extern int allow_signal(int);
82272 extern int disallow_signal(int);
82273@@ -2508,9 +2622,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
82274
82275 #endif
82276
82277-static inline int object_is_on_stack(void *obj)
82278+static inline int object_starts_on_stack(void *obj)
82279 {
82280- void *stack = task_stack_page(current);
82281+ const void *stack = task_stack_page(current);
82282
82283 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
82284 }
82285diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
82286index 8045a55..c959cd5 100644
82287--- a/include/linux/sched/sysctl.h
82288+++ b/include/linux/sched/sysctl.h
82289@@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
82290 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
82291
82292 extern int sysctl_max_map_count;
82293+extern unsigned long sysctl_heap_stack_gap;
82294
82295 extern unsigned int sysctl_sched_latency;
82296 extern unsigned int sysctl_sched_min_granularity;
82297diff --git a/include/linux/security.h b/include/linux/security.h
82298index 2fc42d1..4d802f2 100644
82299--- a/include/linux/security.h
82300+++ b/include/linux/security.h
82301@@ -27,6 +27,7 @@
82302 #include <linux/slab.h>
82303 #include <linux/err.h>
82304 #include <linux/string.h>
82305+#include <linux/grsecurity.h>
82306
82307 struct linux_binprm;
82308 struct cred;
82309@@ -116,8 +117,6 @@ struct seq_file;
82310
82311 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
82312
82313-void reset_security_ops(void);
82314-
82315 #ifdef CONFIG_MMU
82316 extern unsigned long mmap_min_addr;
82317 extern unsigned long dac_mmap_min_addr;
82318@@ -1719,7 +1718,7 @@ struct security_operations {
82319 struct audit_context *actx);
82320 void (*audit_rule_free) (void *lsmrule);
82321 #endif /* CONFIG_AUDIT */
82322-};
82323+} __randomize_layout;
82324
82325 /* prototypes */
82326 extern int security_init(void);
82327diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
82328index dc368b8..e895209 100644
82329--- a/include/linux/semaphore.h
82330+++ b/include/linux/semaphore.h
82331@@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
82332 }
82333
82334 extern void down(struct semaphore *sem);
82335-extern int __must_check down_interruptible(struct semaphore *sem);
82336+extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
82337 extern int __must_check down_killable(struct semaphore *sem);
82338 extern int __must_check down_trylock(struct semaphore *sem);
82339 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
82340diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
82341index 52e0097..383f21d 100644
82342--- a/include/linux/seq_file.h
82343+++ b/include/linux/seq_file.h
82344@@ -27,6 +27,9 @@ struct seq_file {
82345 struct mutex lock;
82346 const struct seq_operations *op;
82347 int poll_event;
82348+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
82349+ u64 exec_id;
82350+#endif
82351 #ifdef CONFIG_USER_NS
82352 struct user_namespace *user_ns;
82353 #endif
82354@@ -39,6 +42,7 @@ struct seq_operations {
82355 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
82356 int (*show) (struct seq_file *m, void *v);
82357 };
82358+typedef struct seq_operations __no_const seq_operations_no_const;
82359
82360 #define SEQ_SKIP 1
82361
82362@@ -96,6 +100,7 @@ void seq_pad(struct seq_file *m, char c);
82363
82364 char *mangle_path(char *s, const char *p, const char *esc);
82365 int seq_open(struct file *, const struct seq_operations *);
82366+int seq_open_restrict(struct file *, const struct seq_operations *);
82367 ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
82368 loff_t seq_lseek(struct file *, loff_t, int);
82369 int seq_release(struct inode *, struct file *);
82370@@ -138,6 +143,7 @@ static inline int seq_nodemask_list(struct seq_file *m, nodemask_t *mask)
82371 }
82372
82373 int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
82374+int single_open_restrict(struct file *, int (*)(struct seq_file *, void *), void *);
82375 int single_open_size(struct file *, int (*)(struct seq_file *, void *), void *, size_t);
82376 int single_release(struct inode *, struct file *);
82377 void *__seq_open_private(struct file *, const struct seq_operations *, int);
82378diff --git a/include/linux/shm.h b/include/linux/shm.h
82379index 1e2cd2e..0288750 100644
82380--- a/include/linux/shm.h
82381+++ b/include/linux/shm.h
82382@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
82383
82384 /* The task created the shm object. NULL if the task is dead. */
82385 struct task_struct *shm_creator;
82386+#ifdef CONFIG_GRKERNSEC
82387+ time_t shm_createtime;
82388+ pid_t shm_lapid;
82389+#endif
82390 };
82391
82392 /* shm_mode upper byte flags */
82393diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
82394index 15ede6a..80161c3 100644
82395--- a/include/linux/skbuff.h
82396+++ b/include/linux/skbuff.h
82397@@ -662,7 +662,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
82398 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
82399 int node);
82400 struct sk_buff *build_skb(void *data, unsigned int frag_size);
82401-static inline struct sk_buff *alloc_skb(unsigned int size,
82402+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
82403 gfp_t priority)
82404 {
82405 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
82406@@ -1768,7 +1768,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
82407 return skb->inner_transport_header - skb->inner_network_header;
82408 }
82409
82410-static inline int skb_network_offset(const struct sk_buff *skb)
82411+static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
82412 {
82413 return skb_network_header(skb) - skb->data;
82414 }
82415@@ -1828,7 +1828,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
82416 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
82417 */
82418 #ifndef NET_SKB_PAD
82419-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
82420+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
82421 #endif
82422
82423 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
82424@@ -2427,7 +2427,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
82425 int *err);
82426 unsigned int datagram_poll(struct file *file, struct socket *sock,
82427 struct poll_table_struct *wait);
82428-int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
82429+int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
82430 struct iovec *to, int size);
82431 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
82432 struct iovec *iov);
82433@@ -2721,6 +2721,9 @@ static inline void nf_reset(struct sk_buff *skb)
82434 nf_bridge_put(skb->nf_bridge);
82435 skb->nf_bridge = NULL;
82436 #endif
82437+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
82438+ skb->nf_trace = 0;
82439+#endif
82440 }
82441
82442 static inline void nf_reset_trace(struct sk_buff *skb)
82443diff --git a/include/linux/slab.h b/include/linux/slab.h
82444index b5b2df6..69f5734 100644
82445--- a/include/linux/slab.h
82446+++ b/include/linux/slab.h
82447@@ -14,15 +14,29 @@
82448 #include <linux/gfp.h>
82449 #include <linux/types.h>
82450 #include <linux/workqueue.h>
82451-
82452+#include <linux/err.h>
82453
82454 /*
82455 * Flags to pass to kmem_cache_create().
82456 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
82457 */
82458 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
82459+
82460+#ifdef CONFIG_PAX_USERCOPY_SLABS
82461+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
82462+#else
82463+#define SLAB_USERCOPY 0x00000000UL
82464+#endif
82465+
82466 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
82467 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
82468+
82469+#ifdef CONFIG_PAX_MEMORY_SANITIZE
82470+#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
82471+#else
82472+#define SLAB_NO_SANITIZE 0x00000000UL
82473+#endif
82474+
82475 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
82476 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
82477 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
82478@@ -98,10 +112,13 @@
82479 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
82480 * Both make kfree a no-op.
82481 */
82482-#define ZERO_SIZE_PTR ((void *)16)
82483+#define ZERO_SIZE_PTR \
82484+({ \
82485+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
82486+ (void *)(-MAX_ERRNO-1L); \
82487+})
82488
82489-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
82490- (unsigned long)ZERO_SIZE_PTR)
82491+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
82492
82493 #include <linux/kmemleak.h>
82494
82495@@ -142,6 +159,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
82496 void kfree(const void *);
82497 void kzfree(const void *);
82498 size_t ksize(const void *);
82499+const char *check_heap_object(const void *ptr, unsigned long n);
82500+bool is_usercopy_object(const void *ptr);
82501
82502 /*
82503 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
82504@@ -174,7 +193,7 @@ struct kmem_cache {
82505 unsigned int align; /* Alignment as calculated */
82506 unsigned long flags; /* Active flags on the slab */
82507 const char *name; /* Slab name for sysfs */
82508- int refcount; /* Use counter */
82509+ atomic_t refcount; /* Use counter */
82510 void (*ctor)(void *); /* Called on object slot creation */
82511 struct list_head list; /* List of all slab caches on the system */
82512 };
82513@@ -248,6 +267,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
82514 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
82515 #endif
82516
82517+#ifdef CONFIG_PAX_USERCOPY_SLABS
82518+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
82519+#endif
82520+
82521 /*
82522 * Figure out which kmalloc slab an allocation of a certain size
82523 * belongs to.
82524@@ -256,7 +279,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
82525 * 2 = 120 .. 192 bytes
82526 * n = 2^(n-1) .. 2^n -1
82527 */
82528-static __always_inline int kmalloc_index(size_t size)
82529+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
82530 {
82531 if (!size)
82532 return 0;
82533@@ -299,11 +322,11 @@ static __always_inline int kmalloc_index(size_t size)
82534 }
82535 #endif /* !CONFIG_SLOB */
82536
82537-void *__kmalloc(size_t size, gfp_t flags);
82538+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
82539 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
82540
82541 #ifdef CONFIG_NUMA
82542-void *__kmalloc_node(size_t size, gfp_t flags, int node);
82543+void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
82544 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
82545 #else
82546 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
82547diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
82548index 8235dfb..47ce586 100644
82549--- a/include/linux/slab_def.h
82550+++ b/include/linux/slab_def.h
82551@@ -38,7 +38,7 @@ struct kmem_cache {
82552 /* 4) cache creation/removal */
82553 const char *name;
82554 struct list_head list;
82555- int refcount;
82556+ atomic_t refcount;
82557 int object_size;
82558 int align;
82559
82560@@ -54,10 +54,14 @@ struct kmem_cache {
82561 unsigned long node_allocs;
82562 unsigned long node_frees;
82563 unsigned long node_overflow;
82564- atomic_t allochit;
82565- atomic_t allocmiss;
82566- atomic_t freehit;
82567- atomic_t freemiss;
82568+ atomic_unchecked_t allochit;
82569+ atomic_unchecked_t allocmiss;
82570+ atomic_unchecked_t freehit;
82571+ atomic_unchecked_t freemiss;
82572+#ifdef CONFIG_PAX_MEMORY_SANITIZE
82573+ atomic_unchecked_t sanitized;
82574+ atomic_unchecked_t not_sanitized;
82575+#endif
82576
82577 /*
82578 * If debugging is enabled, then the allocator can add additional
82579diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
82580index f56bfa9..8378a26 100644
82581--- a/include/linux/slub_def.h
82582+++ b/include/linux/slub_def.h
82583@@ -74,7 +74,7 @@ struct kmem_cache {
82584 struct kmem_cache_order_objects max;
82585 struct kmem_cache_order_objects min;
82586 gfp_t allocflags; /* gfp flags to use on each alloc */
82587- int refcount; /* Refcount for slab cache destroy */
82588+ atomic_t refcount; /* Refcount for slab cache destroy */
82589 void (*ctor)(void *);
82590 int inuse; /* Offset to metadata */
82591 int align; /* Alignment */
82592diff --git a/include/linux/smp.h b/include/linux/smp.h
82593index 6ae004e..2743532 100644
82594--- a/include/linux/smp.h
82595+++ b/include/linux/smp.h
82596@@ -180,7 +180,9 @@ static inline void kick_all_cpus_sync(void) { }
82597 #endif
82598
82599 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
82600+#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
82601 #define put_cpu() preempt_enable()
82602+#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
82603
82604 /*
82605 * Callback to arch code if there's nosmp or maxcpus=0 on the
82606diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
82607index 54f91d3..be2c379 100644
82608--- a/include/linux/sock_diag.h
82609+++ b/include/linux/sock_diag.h
82610@@ -11,7 +11,7 @@ struct sock;
82611 struct sock_diag_handler {
82612 __u8 family;
82613 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
82614-};
82615+} __do_const;
82616
82617 int sock_diag_register(const struct sock_diag_handler *h);
82618 void sock_diag_unregister(const struct sock_diag_handler *h);
82619diff --git a/include/linux/sonet.h b/include/linux/sonet.h
82620index 680f9a3..f13aeb0 100644
82621--- a/include/linux/sonet.h
82622+++ b/include/linux/sonet.h
82623@@ -7,7 +7,7 @@
82624 #include <uapi/linux/sonet.h>
82625
82626 struct k_sonet_stats {
82627-#define __HANDLE_ITEM(i) atomic_t i
82628+#define __HANDLE_ITEM(i) atomic_unchecked_t i
82629 __SONET_ITEMS
82630 #undef __HANDLE_ITEM
82631 };
82632diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
82633index 07d8e53..dc934c9 100644
82634--- a/include/linux/sunrpc/addr.h
82635+++ b/include/linux/sunrpc/addr.h
82636@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
82637 {
82638 switch (sap->sa_family) {
82639 case AF_INET:
82640- return ntohs(((struct sockaddr_in *)sap)->sin_port);
82641+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
82642 case AF_INET6:
82643- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
82644+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
82645 }
82646 return 0;
82647 }
82648@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
82649 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
82650 const struct sockaddr *src)
82651 {
82652- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
82653+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
82654 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
82655
82656 dsin->sin_family = ssin->sin_family;
82657@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
82658 if (sa->sa_family != AF_INET6)
82659 return 0;
82660
82661- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
82662+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
82663 }
82664
82665 #endif /* _LINUX_SUNRPC_ADDR_H */
82666diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
82667index 8af2804..c7414ef 100644
82668--- a/include/linux/sunrpc/clnt.h
82669+++ b/include/linux/sunrpc/clnt.h
82670@@ -97,7 +97,7 @@ struct rpc_procinfo {
82671 unsigned int p_timer; /* Which RTT timer to use */
82672 u32 p_statidx; /* Which procedure to account */
82673 const char * p_name; /* name of procedure */
82674-};
82675+} __do_const;
82676
82677 #ifdef __KERNEL__
82678
82679diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
82680index 04e7632..2e2a8a3 100644
82681--- a/include/linux/sunrpc/svc.h
82682+++ b/include/linux/sunrpc/svc.h
82683@@ -412,7 +412,7 @@ struct svc_procedure {
82684 unsigned int pc_count; /* call count */
82685 unsigned int pc_cachetype; /* cache info (NFS) */
82686 unsigned int pc_xdrressize; /* maximum size of XDR reply */
82687-};
82688+} __do_const;
82689
82690 /*
82691 * Function prototypes.
82692diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
82693index 0b8e3e6..33e0a01 100644
82694--- a/include/linux/sunrpc/svc_rdma.h
82695+++ b/include/linux/sunrpc/svc_rdma.h
82696@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
82697 extern unsigned int svcrdma_max_requests;
82698 extern unsigned int svcrdma_max_req_size;
82699
82700-extern atomic_t rdma_stat_recv;
82701-extern atomic_t rdma_stat_read;
82702-extern atomic_t rdma_stat_write;
82703-extern atomic_t rdma_stat_sq_starve;
82704-extern atomic_t rdma_stat_rq_starve;
82705-extern atomic_t rdma_stat_rq_poll;
82706-extern atomic_t rdma_stat_rq_prod;
82707-extern atomic_t rdma_stat_sq_poll;
82708-extern atomic_t rdma_stat_sq_prod;
82709+extern atomic_unchecked_t rdma_stat_recv;
82710+extern atomic_unchecked_t rdma_stat_read;
82711+extern atomic_unchecked_t rdma_stat_write;
82712+extern atomic_unchecked_t rdma_stat_sq_starve;
82713+extern atomic_unchecked_t rdma_stat_rq_starve;
82714+extern atomic_unchecked_t rdma_stat_rq_poll;
82715+extern atomic_unchecked_t rdma_stat_rq_prod;
82716+extern atomic_unchecked_t rdma_stat_sq_poll;
82717+extern atomic_unchecked_t rdma_stat_sq_prod;
82718
82719 #define RPCRDMA_VERSION 1
82720
82721diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
82722index 8d71d65..f79586e 100644
82723--- a/include/linux/sunrpc/svcauth.h
82724+++ b/include/linux/sunrpc/svcauth.h
82725@@ -120,7 +120,7 @@ struct auth_ops {
82726 int (*release)(struct svc_rqst *rq);
82727 void (*domain_release)(struct auth_domain *);
82728 int (*set_client)(struct svc_rqst *rq);
82729-};
82730+} __do_const;
82731
82732 #define SVC_GARBAGE 1
82733 #define SVC_SYSERR 2
82734diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
82735index a5ffd32..0935dea 100644
82736--- a/include/linux/swiotlb.h
82737+++ b/include/linux/swiotlb.h
82738@@ -60,7 +60,8 @@ extern void
82739
82740 extern void
82741 swiotlb_free_coherent(struct device *hwdev, size_t size,
82742- void *vaddr, dma_addr_t dma_handle);
82743+ void *vaddr, dma_addr_t dma_handle,
82744+ struct dma_attrs *attrs);
82745
82746 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
82747 unsigned long offset, size_t size,
82748diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
82749index a747a77..9e14df7 100644
82750--- a/include/linux/syscalls.h
82751+++ b/include/linux/syscalls.h
82752@@ -98,8 +98,14 @@ struct sigaltstack;
82753 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
82754
82755 #define __SC_DECL(t, a) t a
82756+#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))
82757 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
82758-#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
82759+#define __SC_LONG(t, a) __typeof( \
82760+ __builtin_choose_expr( \
82761+ sizeof(t) > sizeof(int), \
82762+ (t) 0, \
82763+ __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
82764+ )) a
82765 #define __SC_CAST(t, a) (t) a
82766 #define __SC_ARGS(t, a) a
82767 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
82768@@ -371,11 +377,11 @@ asmlinkage long sys_sync(void);
82769 asmlinkage long sys_fsync(unsigned int fd);
82770 asmlinkage long sys_fdatasync(unsigned int fd);
82771 asmlinkage long sys_bdflush(int func, long data);
82772-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
82773- char __user *type, unsigned long flags,
82774+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
82775+ const char __user *type, unsigned long flags,
82776 void __user *data);
82777-asmlinkage long sys_umount(char __user *name, int flags);
82778-asmlinkage long sys_oldumount(char __user *name);
82779+asmlinkage long sys_umount(const char __user *name, int flags);
82780+asmlinkage long sys_oldumount(const char __user *name);
82781 asmlinkage long sys_truncate(const char __user *path, long length);
82782 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
82783 asmlinkage long sys_stat(const char __user *filename,
82784@@ -587,7 +593,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
82785 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
82786 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
82787 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
82788- struct sockaddr __user *, int);
82789+ struct sockaddr __user *, int) __intentional_overflow(0);
82790 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
82791 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
82792 unsigned int vlen, unsigned flags);
82793diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
82794index 27b3b0b..e093dd9 100644
82795--- a/include/linux/syscore_ops.h
82796+++ b/include/linux/syscore_ops.h
82797@@ -16,7 +16,7 @@ struct syscore_ops {
82798 int (*suspend)(void);
82799 void (*resume)(void);
82800 void (*shutdown)(void);
82801-};
82802+} __do_const;
82803
82804 extern void register_syscore_ops(struct syscore_ops *ops);
82805 extern void unregister_syscore_ops(struct syscore_ops *ops);
82806diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
82807index 14a8ff2..fa95f3a 100644
82808--- a/include/linux/sysctl.h
82809+++ b/include/linux/sysctl.h
82810@@ -34,13 +34,13 @@ struct ctl_table_root;
82811 struct ctl_table_header;
82812 struct ctl_dir;
82813
82814-typedef struct ctl_table ctl_table;
82815-
82816 typedef int proc_handler (struct ctl_table *ctl, int write,
82817 void __user *buffer, size_t *lenp, loff_t *ppos);
82818
82819 extern int proc_dostring(struct ctl_table *, int,
82820 void __user *, size_t *, loff_t *);
82821+extern int proc_dostring_modpriv(struct ctl_table *, int,
82822+ void __user *, size_t *, loff_t *);
82823 extern int proc_dointvec(struct ctl_table *, int,
82824 void __user *, size_t *, loff_t *);
82825 extern int proc_dointvec_minmax(struct ctl_table *, int,
82826@@ -115,7 +115,9 @@ struct ctl_table
82827 struct ctl_table_poll *poll;
82828 void *extra1;
82829 void *extra2;
82830-};
82831+} __do_const __randomize_layout;
82832+typedef struct ctl_table __no_const ctl_table_no_const;
82833+typedef struct ctl_table ctl_table;
82834
82835 struct ctl_node {
82836 struct rb_node node;
82837diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
82838index 30b2ebe..37412ef 100644
82839--- a/include/linux/sysfs.h
82840+++ b/include/linux/sysfs.h
82841@@ -34,7 +34,8 @@ struct attribute {
82842 struct lock_class_key *key;
82843 struct lock_class_key skey;
82844 #endif
82845-};
82846+} __do_const;
82847+typedef struct attribute __no_const attribute_no_const;
82848
82849 /**
82850 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
82851@@ -63,7 +64,8 @@ struct attribute_group {
82852 struct attribute *, int);
82853 struct attribute **attrs;
82854 struct bin_attribute **bin_attrs;
82855-};
82856+} __do_const;
82857+typedef struct attribute_group __no_const attribute_group_no_const;
82858
82859 /**
82860 * Use these macros to make defining attributes easier. See include/linux/device.h
82861@@ -127,7 +129,8 @@ struct bin_attribute {
82862 char *, loff_t, size_t);
82863 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
82864 struct vm_area_struct *vma);
82865-};
82866+} __do_const;
82867+typedef struct bin_attribute __no_const bin_attribute_no_const;
82868
82869 /**
82870 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
82871diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
82872index 387fa7d..3fcde6b 100644
82873--- a/include/linux/sysrq.h
82874+++ b/include/linux/sysrq.h
82875@@ -16,6 +16,7 @@
82876
82877 #include <linux/errno.h>
82878 #include <linux/types.h>
82879+#include <linux/compiler.h>
82880
82881 /* Possible values of bitmask for enabling sysrq functions */
82882 /* 0x0001 is reserved for enable everything */
82883@@ -33,7 +34,7 @@ struct sysrq_key_op {
82884 char *help_msg;
82885 char *action_msg;
82886 int enable_mask;
82887-};
82888+} __do_const;
82889
82890 #ifdef CONFIG_MAGIC_SYSRQ
82891
82892diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
82893index fddbe20..e4cce53 100644
82894--- a/include/linux/thread_info.h
82895+++ b/include/linux/thread_info.h
82896@@ -161,6 +161,25 @@ static inline bool test_and_clear_restore_sigmask(void)
82897 #error "no set_restore_sigmask() provided and default one won't work"
82898 #endif
82899
82900+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
82901+
82902+#if defined(CONFIG_X86) && defined(CONFIG_PAX_USERCOPY)
82903+extern void pax_check_alloca(unsigned long size);
82904+#endif
82905+
82906+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
82907+{
82908+#if defined(CONFIG_X86) && defined(CONFIG_PAX_USERCOPY)
82909+ /* always check if we've overflowed the stack in a copy*user */
82910+ pax_check_alloca(sizeof(unsigned long));
82911+#endif
82912+
82913+#ifndef CONFIG_PAX_USERCOPY_DEBUG
82914+ if (!__builtin_constant_p(n))
82915+#endif
82916+ __check_object_size(ptr, n, to_user);
82917+}
82918+
82919 #endif /* __KERNEL__ */
82920
82921 #endif /* _LINUX_THREAD_INFO_H */
82922diff --git a/include/linux/tty.h b/include/linux/tty.h
82923index b90b5c2..e23a512 100644
82924--- a/include/linux/tty.h
82925+++ b/include/linux/tty.h
82926@@ -202,7 +202,7 @@ struct tty_port {
82927 const struct tty_port_operations *ops; /* Port operations */
82928 spinlock_t lock; /* Lock protecting tty field */
82929 int blocked_open; /* Waiting to open */
82930- int count; /* Usage count */
82931+ atomic_t count; /* Usage count */
82932 wait_queue_head_t open_wait; /* Open waiters */
82933 wait_queue_head_t close_wait; /* Close waiters */
82934 wait_queue_head_t delta_msr_wait; /* Modem status change */
82935@@ -284,7 +284,7 @@ struct tty_struct {
82936 /* If the tty has a pending do_SAK, queue it here - akpm */
82937 struct work_struct SAK_work;
82938 struct tty_port *port;
82939-};
82940+} __randomize_layout;
82941
82942 /* Each of a tty's open files has private_data pointing to tty_file_private */
82943 struct tty_file_private {
82944@@ -550,7 +550,7 @@ extern int tty_port_open(struct tty_port *port,
82945 struct tty_struct *tty, struct file *filp);
82946 static inline int tty_port_users(struct tty_port *port)
82947 {
82948- return port->count + port->blocked_open;
82949+ return atomic_read(&port->count) + port->blocked_open;
82950 }
82951
82952 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
82953diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
82954index 756a609..89db85e 100644
82955--- a/include/linux/tty_driver.h
82956+++ b/include/linux/tty_driver.h
82957@@ -285,7 +285,7 @@ struct tty_operations {
82958 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
82959 #endif
82960 const struct file_operations *proc_fops;
82961-};
82962+} __do_const __randomize_layout;
82963
82964 struct tty_driver {
82965 int magic; /* magic number for this structure */
82966@@ -319,7 +319,7 @@ struct tty_driver {
82967
82968 const struct tty_operations *ops;
82969 struct list_head tty_drivers;
82970-};
82971+} __randomize_layout;
82972
82973 extern struct list_head tty_drivers;
82974
82975diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
82976index b8347c2..85d8b0f 100644
82977--- a/include/linux/tty_ldisc.h
82978+++ b/include/linux/tty_ldisc.h
82979@@ -213,7 +213,7 @@ struct tty_ldisc_ops {
82980
82981 struct module *owner;
82982
82983- int refcount;
82984+ atomic_t refcount;
82985 };
82986
82987 struct tty_ldisc {
82988diff --git a/include/linux/types.h b/include/linux/types.h
82989index 4d118ba..c3ee9bf 100644
82990--- a/include/linux/types.h
82991+++ b/include/linux/types.h
82992@@ -176,10 +176,26 @@ typedef struct {
82993 int counter;
82994 } atomic_t;
82995
82996+#ifdef CONFIG_PAX_REFCOUNT
82997+typedef struct {
82998+ int counter;
82999+} atomic_unchecked_t;
83000+#else
83001+typedef atomic_t atomic_unchecked_t;
83002+#endif
83003+
83004 #ifdef CONFIG_64BIT
83005 typedef struct {
83006 long counter;
83007 } atomic64_t;
83008+
83009+#ifdef CONFIG_PAX_REFCOUNT
83010+typedef struct {
83011+ long counter;
83012+} atomic64_unchecked_t;
83013+#else
83014+typedef atomic64_t atomic64_unchecked_t;
83015+#endif
83016 #endif
83017
83018 struct list_head {
83019diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
83020index ecd3319..8a36ded 100644
83021--- a/include/linux/uaccess.h
83022+++ b/include/linux/uaccess.h
83023@@ -75,11 +75,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
83024 long ret; \
83025 mm_segment_t old_fs = get_fs(); \
83026 \
83027- set_fs(KERNEL_DS); \
83028 pagefault_disable(); \
83029- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
83030- pagefault_enable(); \
83031+ set_fs(KERNEL_DS); \
83032+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
83033 set_fs(old_fs); \
83034+ pagefault_enable(); \
83035 ret; \
83036 })
83037
83038diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
83039index 2d1f9b6..d7a9fce 100644
83040--- a/include/linux/uidgid.h
83041+++ b/include/linux/uidgid.h
83042@@ -175,4 +175,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
83043
83044 #endif /* CONFIG_USER_NS */
83045
83046+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
83047+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
83048+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
83049+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
83050+
83051 #endif /* _LINUX_UIDGID_H */
83052diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
83053index 99c1b4d..562e6f3 100644
83054--- a/include/linux/unaligned/access_ok.h
83055+++ b/include/linux/unaligned/access_ok.h
83056@@ -4,34 +4,34 @@
83057 #include <linux/kernel.h>
83058 #include <asm/byteorder.h>
83059
83060-static inline u16 get_unaligned_le16(const void *p)
83061+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
83062 {
83063- return le16_to_cpup((__le16 *)p);
83064+ return le16_to_cpup((const __le16 *)p);
83065 }
83066
83067-static inline u32 get_unaligned_le32(const void *p)
83068+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
83069 {
83070- return le32_to_cpup((__le32 *)p);
83071+ return le32_to_cpup((const __le32 *)p);
83072 }
83073
83074-static inline u64 get_unaligned_le64(const void *p)
83075+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
83076 {
83077- return le64_to_cpup((__le64 *)p);
83078+ return le64_to_cpup((const __le64 *)p);
83079 }
83080
83081-static inline u16 get_unaligned_be16(const void *p)
83082+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
83083 {
83084- return be16_to_cpup((__be16 *)p);
83085+ return be16_to_cpup((const __be16 *)p);
83086 }
83087
83088-static inline u32 get_unaligned_be32(const void *p)
83089+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
83090 {
83091- return be32_to_cpup((__be32 *)p);
83092+ return be32_to_cpup((const __be32 *)p);
83093 }
83094
83095-static inline u64 get_unaligned_be64(const void *p)
83096+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
83097 {
83098- return be64_to_cpup((__be64 *)p);
83099+ return be64_to_cpup((const __be64 *)p);
83100 }
83101
83102 static inline void put_unaligned_le16(u16 val, void *p)
83103diff --git a/include/linux/usb.h b/include/linux/usb.h
83104index 7f6eb85..656e806 100644
83105--- a/include/linux/usb.h
83106+++ b/include/linux/usb.h
83107@@ -563,7 +563,7 @@ struct usb_device {
83108 int maxchild;
83109
83110 u32 quirks;
83111- atomic_t urbnum;
83112+ atomic_unchecked_t urbnum;
83113
83114 unsigned long active_duration;
83115
83116@@ -1642,7 +1642,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
83117
83118 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
83119 __u8 request, __u8 requesttype, __u16 value, __u16 index,
83120- void *data, __u16 size, int timeout);
83121+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
83122 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
83123 void *data, int len, int *actual_length, int timeout);
83124 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
83125diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
83126index e452ba6..78f8e80 100644
83127--- a/include/linux/usb/renesas_usbhs.h
83128+++ b/include/linux/usb/renesas_usbhs.h
83129@@ -39,7 +39,7 @@ enum {
83130 */
83131 struct renesas_usbhs_driver_callback {
83132 int (*notify_hotplug)(struct platform_device *pdev);
83133-};
83134+} __no_const;
83135
83136 /*
83137 * callback functions for platform
83138diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
83139index 4836ba3..603f6ee 100644
83140--- a/include/linux/user_namespace.h
83141+++ b/include/linux/user_namespace.h
83142@@ -33,7 +33,7 @@ struct user_namespace {
83143 struct key *persistent_keyring_register;
83144 struct rw_semaphore persistent_keyring_register_sem;
83145 #endif
83146-};
83147+} __randomize_layout;
83148
83149 extern struct user_namespace init_user_ns;
83150
83151diff --git a/include/linux/utsname.h b/include/linux/utsname.h
83152index 239e277..22a5cf5 100644
83153--- a/include/linux/utsname.h
83154+++ b/include/linux/utsname.h
83155@@ -24,7 +24,7 @@ struct uts_namespace {
83156 struct new_utsname name;
83157 struct user_namespace *user_ns;
83158 unsigned int proc_inum;
83159-};
83160+} __randomize_layout;
83161 extern struct uts_namespace init_uts_ns;
83162
83163 #ifdef CONFIG_UTS_NS
83164diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
83165index 6f8fbcf..4efc177 100644
83166--- a/include/linux/vermagic.h
83167+++ b/include/linux/vermagic.h
83168@@ -25,9 +25,42 @@
83169 #define MODULE_ARCH_VERMAGIC ""
83170 #endif
83171
83172+#ifdef CONFIG_PAX_REFCOUNT
83173+#define MODULE_PAX_REFCOUNT "REFCOUNT "
83174+#else
83175+#define MODULE_PAX_REFCOUNT ""
83176+#endif
83177+
83178+#ifdef CONSTIFY_PLUGIN
83179+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
83180+#else
83181+#define MODULE_CONSTIFY_PLUGIN ""
83182+#endif
83183+
83184+#ifdef STACKLEAK_PLUGIN
83185+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
83186+#else
83187+#define MODULE_STACKLEAK_PLUGIN ""
83188+#endif
83189+
83190+#ifdef RANDSTRUCT_PLUGIN
83191+#include <generated/randomize_layout_hash.h>
83192+#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
83193+#else
83194+#define MODULE_RANDSTRUCT_PLUGIN
83195+#endif
83196+
83197+#ifdef CONFIG_GRKERNSEC
83198+#define MODULE_GRSEC "GRSEC "
83199+#else
83200+#define MODULE_GRSEC ""
83201+#endif
83202+
83203 #define VERMAGIC_STRING \
83204 UTS_RELEASE " " \
83205 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
83206 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
83207- MODULE_ARCH_VERMAGIC
83208+ MODULE_ARCH_VERMAGIC \
83209+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
83210+ MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
83211
83212diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
83213index 502073a..a7de024 100644
83214--- a/include/linux/vga_switcheroo.h
83215+++ b/include/linux/vga_switcheroo.h
83216@@ -63,8 +63,8 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
83217
83218 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
83219
83220-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
83221-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
83222+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
83223+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
83224 #else
83225
83226 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
83227@@ -81,8 +81,8 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
83228
83229 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
83230
83231-static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
83232-static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
83233+static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
83234+static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
83235
83236 #endif
83237 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
83238diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
83239index 4b8a891..cb8df6e 100644
83240--- a/include/linux/vmalloc.h
83241+++ b/include/linux/vmalloc.h
83242@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
83243 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
83244 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
83245 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
83246+
83247+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
83248+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
83249+#endif
83250+
83251 /* bits [20..32] reserved for arch specific ioremap internals */
83252
83253 /*
83254@@ -142,7 +147,7 @@ extern void free_vm_area(struct vm_struct *area);
83255
83256 /* for /dev/kmem */
83257 extern long vread(char *buf, char *addr, unsigned long count);
83258-extern long vwrite(char *buf, char *addr, unsigned long count);
83259+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
83260
83261 /*
83262 * Internals. Dont't use..
83263diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
83264index 67ce70c..d540954 100644
83265--- a/include/linux/vmstat.h
83266+++ b/include/linux/vmstat.h
83267@@ -98,18 +98,18 @@ static inline void vm_events_fold_cpu(int cpu)
83268 /*
83269 * Zone based page accounting with per cpu differentials.
83270 */
83271-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83272+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83273
83274 static inline void zone_page_state_add(long x, struct zone *zone,
83275 enum zone_stat_item item)
83276 {
83277- atomic_long_add(x, &zone->vm_stat[item]);
83278- atomic_long_add(x, &vm_stat[item]);
83279+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
83280+ atomic_long_add_unchecked(x, &vm_stat[item]);
83281 }
83282
83283-static inline unsigned long global_page_state(enum zone_stat_item item)
83284+static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
83285 {
83286- long x = atomic_long_read(&vm_stat[item]);
83287+ long x = atomic_long_read_unchecked(&vm_stat[item]);
83288 #ifdef CONFIG_SMP
83289 if (x < 0)
83290 x = 0;
83291@@ -117,10 +117,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
83292 return x;
83293 }
83294
83295-static inline unsigned long zone_page_state(struct zone *zone,
83296+static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
83297 enum zone_stat_item item)
83298 {
83299- long x = atomic_long_read(&zone->vm_stat[item]);
83300+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
83301 #ifdef CONFIG_SMP
83302 if (x < 0)
83303 x = 0;
83304@@ -137,7 +137,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
83305 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
83306 enum zone_stat_item item)
83307 {
83308- long x = atomic_long_read(&zone->vm_stat[item]);
83309+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
83310
83311 #ifdef CONFIG_SMP
83312 int cpu;
83313@@ -226,8 +226,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
83314
83315 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
83316 {
83317- atomic_long_inc(&zone->vm_stat[item]);
83318- atomic_long_inc(&vm_stat[item]);
83319+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
83320+ atomic_long_inc_unchecked(&vm_stat[item]);
83321 }
83322
83323 static inline void __inc_zone_page_state(struct page *page,
83324@@ -238,8 +238,8 @@ static inline void __inc_zone_page_state(struct page *page,
83325
83326 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
83327 {
83328- atomic_long_dec(&zone->vm_stat[item]);
83329- atomic_long_dec(&vm_stat[item]);
83330+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
83331+ atomic_long_dec_unchecked(&vm_stat[item]);
83332 }
83333
83334 static inline void __dec_zone_page_state(struct page *page,
83335diff --git a/include/linux/xattr.h b/include/linux/xattr.h
83336index 91b0a68..0e9adf6 100644
83337--- a/include/linux/xattr.h
83338+++ b/include/linux/xattr.h
83339@@ -28,7 +28,7 @@ struct xattr_handler {
83340 size_t size, int handler_flags);
83341 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
83342 size_t size, int flags, int handler_flags);
83343-};
83344+} __do_const;
83345
83346 struct xattr {
83347 const char *name;
83348@@ -37,6 +37,9 @@ struct xattr {
83349 };
83350
83351 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
83352+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
83353+ssize_t pax_getxattr(struct dentry *, void *, size_t);
83354+#endif
83355 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
83356 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
83357 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
83358diff --git a/include/linux/zlib.h b/include/linux/zlib.h
83359index 9c5a6b4..09c9438 100644
83360--- a/include/linux/zlib.h
83361+++ b/include/linux/zlib.h
83362@@ -31,6 +31,7 @@
83363 #define _ZLIB_H
83364
83365 #include <linux/zconf.h>
83366+#include <linux/compiler.h>
83367
83368 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
83369 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
83370@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
83371
83372 /* basic functions */
83373
83374-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
83375+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
83376 /*
83377 Returns the number of bytes that needs to be allocated for a per-
83378 stream workspace with the specified parameters. A pointer to this
83379diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
83380index c768c9f..bdcaa5a 100644
83381--- a/include/media/v4l2-dev.h
83382+++ b/include/media/v4l2-dev.h
83383@@ -76,7 +76,7 @@ struct v4l2_file_operations {
83384 int (*mmap) (struct file *, struct vm_area_struct *);
83385 int (*open) (struct file *);
83386 int (*release) (struct file *);
83387-};
83388+} __do_const;
83389
83390 /*
83391 * Newer version of video_device, handled by videodev2.c
83392diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
83393index c9b1593..a572459 100644
83394--- a/include/media/v4l2-device.h
83395+++ b/include/media/v4l2-device.h
83396@@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
83397 this function returns 0. If the name ends with a digit (e.g. cx18),
83398 then the name will be set to cx18-0 since cx180 looks really odd. */
83399 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
83400- atomic_t *instance);
83401+ atomic_unchecked_t *instance);
83402
83403 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
83404 Since the parent disappears this ensures that v4l2_dev doesn't have an
83405diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
83406index 9a36d92..0aafe2a 100644
83407--- a/include/net/9p/transport.h
83408+++ b/include/net/9p/transport.h
83409@@ -60,7 +60,7 @@ struct p9_trans_module {
83410 int (*cancel) (struct p9_client *, struct p9_req_t *req);
83411 int (*zc_request)(struct p9_client *, struct p9_req_t *,
83412 char *, char *, int , int, int, int);
83413-};
83414+} __do_const;
83415
83416 void v9fs_register_trans(struct p9_trans_module *m);
83417 void v9fs_unregister_trans(struct p9_trans_module *m);
83418diff --git a/include/net/af_unix.h b/include/net/af_unix.h
83419index a175ba4..196eb82 100644
83420--- a/include/net/af_unix.h
83421+++ b/include/net/af_unix.h
83422@@ -36,7 +36,7 @@ struct unix_skb_parms {
83423 u32 secid; /* Security ID */
83424 #endif
83425 u32 consumed;
83426-};
83427+} __randomize_layout;
83428
83429 #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
83430 #define UNIXSID(skb) (&UNIXCB((skb)).secid)
83431diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
83432index dbc4a89..4a59b5d 100644
83433--- a/include/net/bluetooth/l2cap.h
83434+++ b/include/net/bluetooth/l2cap.h
83435@@ -600,7 +600,7 @@ struct l2cap_ops {
83436 long (*get_sndtimeo) (struct l2cap_chan *chan);
83437 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
83438 unsigned long len, int nb);
83439-};
83440+} __do_const;
83441
83442 struct l2cap_conn {
83443 struct hci_conn *hcon;
83444diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
83445index f2ae33d..c457cf0 100644
83446--- a/include/net/caif/cfctrl.h
83447+++ b/include/net/caif/cfctrl.h
83448@@ -52,7 +52,7 @@ struct cfctrl_rsp {
83449 void (*radioset_rsp)(void);
83450 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
83451 struct cflayer *client_layer);
83452-};
83453+} __no_const;
83454
83455 /* Link Setup Parameters for CAIF-Links. */
83456 struct cfctrl_link_param {
83457@@ -101,8 +101,8 @@ struct cfctrl_request_info {
83458 struct cfctrl {
83459 struct cfsrvl serv;
83460 struct cfctrl_rsp res;
83461- atomic_t req_seq_no;
83462- atomic_t rsp_seq_no;
83463+ atomic_unchecked_t req_seq_no;
83464+ atomic_unchecked_t rsp_seq_no;
83465 struct list_head list;
83466 /* Protects from simultaneous access to first_req list */
83467 spinlock_t info_list_lock;
83468diff --git a/include/net/flow.h b/include/net/flow.h
83469index d23e7fa..e188307 100644
83470--- a/include/net/flow.h
83471+++ b/include/net/flow.h
83472@@ -221,6 +221,6 @@ struct flow_cache_object *flow_cache_lookup(struct net *net,
83473
83474 void flow_cache_flush(void);
83475 void flow_cache_flush_deferred(void);
83476-extern atomic_t flow_cache_genid;
83477+extern atomic_unchecked_t flow_cache_genid;
83478
83479 #endif
83480diff --git a/include/net/genetlink.h b/include/net/genetlink.h
83481index 93695f0..766d71c 100644
83482--- a/include/net/genetlink.h
83483+++ b/include/net/genetlink.h
83484@@ -120,7 +120,7 @@ struct genl_ops {
83485 u8 cmd;
83486 u8 internal_flags;
83487 u8 flags;
83488-};
83489+} __do_const;
83490
83491 int __genl_register_family(struct genl_family *family);
83492
83493diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
83494index 734d9b5..48a9a4b 100644
83495--- a/include/net/gro_cells.h
83496+++ b/include/net/gro_cells.h
83497@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
83498 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
83499
83500 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
83501- atomic_long_inc(&dev->rx_dropped);
83502+ atomic_long_inc_unchecked(&dev->rx_dropped);
83503 kfree_skb(skb);
83504 return;
83505 }
83506diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
83507index c55aeed..b3393f4 100644
83508--- a/include/net/inet_connection_sock.h
83509+++ b/include/net/inet_connection_sock.h
83510@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
83511 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
83512 int (*bind_conflict)(const struct sock *sk,
83513 const struct inet_bind_bucket *tb, bool relax);
83514-};
83515+} __do_const;
83516
83517 /** inet_connection_sock - INET connection oriented sock
83518 *
83519diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
83520index 6efe73c..fa94270 100644
83521--- a/include/net/inetpeer.h
83522+++ b/include/net/inetpeer.h
83523@@ -47,8 +47,8 @@ struct inet_peer {
83524 */
83525 union {
83526 struct {
83527- atomic_t rid; /* Frag reception counter */
83528- atomic_t ip_id_count; /* IP ID for the next packet */
83529+ atomic_unchecked_t rid; /* Frag reception counter */
83530+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
83531 };
83532 struct rcu_head rcu;
83533 struct inet_peer *gc_next;
83534@@ -177,16 +177,13 @@ static inline void inet_peer_refcheck(const struct inet_peer *p)
83535 /* can be called with or without local BH being disabled */
83536 static inline int inet_getid(struct inet_peer *p, int more)
83537 {
83538- int old, new;
83539+ int id;
83540 more++;
83541 inet_peer_refcheck(p);
83542- do {
83543- old = atomic_read(&p->ip_id_count);
83544- new = old + more;
83545- if (!new)
83546- new = 1;
83547- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
83548- return new;
83549+ id = atomic_add_return_unchecked(more, &p->ip_id_count);
83550+ if (!id)
83551+ id = atomic_inc_return_unchecked(&p->ip_id_count);
83552+ return id;
83553 }
83554
83555 #endif /* _NET_INETPEER_H */
83556diff --git a/include/net/ip.h b/include/net/ip.h
83557index 23be0fd..0cb3e2c 100644
83558--- a/include/net/ip.h
83559+++ b/include/net/ip.h
83560@@ -214,7 +214,7 @@ static inline void snmp_mib_free(void __percpu *ptr[SNMP_ARRAY_SZ])
83561
83562 void inet_get_local_port_range(struct net *net, int *low, int *high);
83563
83564-extern unsigned long *sysctl_local_reserved_ports;
83565+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
83566 static inline int inet_is_reserved_local_port(int port)
83567 {
83568 return test_bit(port, sysctl_local_reserved_ports);
83569diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
83570index 9922093..a1755d6 100644
83571--- a/include/net/ip_fib.h
83572+++ b/include/net/ip_fib.h
83573@@ -169,7 +169,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
83574
83575 #define FIB_RES_SADDR(net, res) \
83576 ((FIB_RES_NH(res).nh_saddr_genid == \
83577- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
83578+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
83579 FIB_RES_NH(res).nh_saddr : \
83580 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
83581 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
83582diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
83583index 5679d92..2e7a690 100644
83584--- a/include/net/ip_vs.h
83585+++ b/include/net/ip_vs.h
83586@@ -558,7 +558,7 @@ struct ip_vs_conn {
83587 struct ip_vs_conn *control; /* Master control connection */
83588 atomic_t n_control; /* Number of controlled ones */
83589 struct ip_vs_dest *dest; /* real server */
83590- atomic_t in_pkts; /* incoming packet counter */
83591+ atomic_unchecked_t in_pkts; /* incoming packet counter */
83592
83593 /* packet transmitter for different forwarding methods. If it
83594 mangles the packet, it must return NF_DROP or better NF_STOLEN,
83595@@ -705,7 +705,7 @@ struct ip_vs_dest {
83596 __be16 port; /* port number of the server */
83597 union nf_inet_addr addr; /* IP address of the server */
83598 volatile unsigned int flags; /* dest status flags */
83599- atomic_t conn_flags; /* flags to copy to conn */
83600+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
83601 atomic_t weight; /* server weight */
83602
83603 atomic_t refcnt; /* reference counter */
83604@@ -960,11 +960,11 @@ struct netns_ipvs {
83605 /* ip_vs_lblc */
83606 int sysctl_lblc_expiration;
83607 struct ctl_table_header *lblc_ctl_header;
83608- struct ctl_table *lblc_ctl_table;
83609+ ctl_table_no_const *lblc_ctl_table;
83610 /* ip_vs_lblcr */
83611 int sysctl_lblcr_expiration;
83612 struct ctl_table_header *lblcr_ctl_header;
83613- struct ctl_table *lblcr_ctl_table;
83614+ ctl_table_no_const *lblcr_ctl_table;
83615 /* ip_vs_est */
83616 struct list_head est_list; /* estimator list */
83617 spinlock_t est_lock;
83618diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
83619index 8d4f588..2e37ad2 100644
83620--- a/include/net/irda/ircomm_tty.h
83621+++ b/include/net/irda/ircomm_tty.h
83622@@ -33,6 +33,7 @@
83623 #include <linux/termios.h>
83624 #include <linux/timer.h>
83625 #include <linux/tty.h> /* struct tty_struct */
83626+#include <asm/local.h>
83627
83628 #include <net/irda/irias_object.h>
83629 #include <net/irda/ircomm_core.h>
83630diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
83631index 714cc9a..ea05f3e 100644
83632--- a/include/net/iucv/af_iucv.h
83633+++ b/include/net/iucv/af_iucv.h
83634@@ -149,7 +149,7 @@ struct iucv_skb_cb {
83635 struct iucv_sock_list {
83636 struct hlist_head head;
83637 rwlock_t lock;
83638- atomic_t autobind_name;
83639+ atomic_unchecked_t autobind_name;
83640 };
83641
83642 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
83643diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
83644index f3be818..bf46196 100644
83645--- a/include/net/llc_c_ac.h
83646+++ b/include/net/llc_c_ac.h
83647@@ -87,7 +87,7 @@
83648 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
83649 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
83650
83651-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
83652+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
83653
83654 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
83655 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
83656diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
83657index 3948cf1..83b28c4 100644
83658--- a/include/net/llc_c_ev.h
83659+++ b/include/net/llc_c_ev.h
83660@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
83661 return (struct llc_conn_state_ev *)skb->cb;
83662 }
83663
83664-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
83665-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
83666+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
83667+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
83668
83669 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
83670 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
83671diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
83672index 0e79cfb..f46db31 100644
83673--- a/include/net/llc_c_st.h
83674+++ b/include/net/llc_c_st.h
83675@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
83676 u8 next_state;
83677 llc_conn_ev_qfyr_t *ev_qualifiers;
83678 llc_conn_action_t *ev_actions;
83679-};
83680+} __do_const;
83681
83682 struct llc_conn_state {
83683 u8 current_state;
83684diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
83685index a61b98c..aade1eb 100644
83686--- a/include/net/llc_s_ac.h
83687+++ b/include/net/llc_s_ac.h
83688@@ -23,7 +23,7 @@
83689 #define SAP_ACT_TEST_IND 9
83690
83691 /* All action functions must look like this */
83692-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
83693+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
83694
83695 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
83696 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
83697diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
83698index 567c681..cd73ac0 100644
83699--- a/include/net/llc_s_st.h
83700+++ b/include/net/llc_s_st.h
83701@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
83702 llc_sap_ev_t ev;
83703 u8 next_state;
83704 llc_sap_action_t *ev_actions;
83705-};
83706+} __do_const;
83707
83708 struct llc_sap_state {
83709 u8 curr_state;
83710diff --git a/include/net/mac80211.h b/include/net/mac80211.h
83711index f4ab2fb..71a85ba 100644
83712--- a/include/net/mac80211.h
83713+++ b/include/net/mac80211.h
83714@@ -4476,7 +4476,7 @@ struct rate_control_ops {
83715 void (*add_sta_debugfs)(void *priv, void *priv_sta,
83716 struct dentry *dir);
83717 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
83718-};
83719+} __do_const;
83720
83721 static inline int rate_supported(struct ieee80211_sta *sta,
83722 enum ieee80211_band band,
83723diff --git a/include/net/neighbour.h b/include/net/neighbour.h
83724index 7277caf..fd095bc 100644
83725--- a/include/net/neighbour.h
83726+++ b/include/net/neighbour.h
83727@@ -163,7 +163,7 @@ struct neigh_ops {
83728 void (*error_report)(struct neighbour *, struct sk_buff *);
83729 int (*output)(struct neighbour *, struct sk_buff *);
83730 int (*connected_output)(struct neighbour *, struct sk_buff *);
83731-};
83732+} __do_const;
83733
83734 struct pneigh_entry {
83735 struct pneigh_entry *next;
83736@@ -203,7 +203,6 @@ struct neigh_table {
83737 void (*proxy_redo)(struct sk_buff *skb);
83738 char *id;
83739 struct neigh_parms parms;
83740- /* HACK. gc_* should follow parms without a gap! */
83741 int gc_interval;
83742 int gc_thresh1;
83743 int gc_thresh2;
83744@@ -218,7 +217,7 @@ struct neigh_table {
83745 struct neigh_statistics __percpu *stats;
83746 struct neigh_hash_table __rcu *nht;
83747 struct pneigh_entry **phash_buckets;
83748-};
83749+} __randomize_layout;
83750
83751 static inline int neigh_parms_family(struct neigh_parms *p)
83752 {
83753diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
83754index 991dcd9..ab58d00 100644
83755--- a/include/net/net_namespace.h
83756+++ b/include/net/net_namespace.h
83757@@ -124,8 +124,8 @@ struct net {
83758 struct netns_ipvs *ipvs;
83759 #endif
83760 struct sock *diag_nlsk;
83761- atomic_t fnhe_genid;
83762-};
83763+ atomic_unchecked_t fnhe_genid;
83764+} __randomize_layout;
83765
83766 /*
83767 * ifindex generation is per-net namespace, and loopback is
83768@@ -289,7 +289,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
83769 #define __net_init __init
83770 #define __net_exit __exit_refok
83771 #define __net_initdata __initdata
83772+#ifdef CONSTIFY_PLUGIN
83773 #define __net_initconst __initconst
83774+#else
83775+#define __net_initconst __initdata
83776+#endif
83777 #endif
83778
83779 struct pernet_operations {
83780@@ -299,7 +303,7 @@ struct pernet_operations {
83781 void (*exit_batch)(struct list_head *net_exit_list);
83782 int *id;
83783 size_t size;
83784-};
83785+} __do_const;
83786
83787 /*
83788 * Use these carefully. If you implement a network device and it
83789@@ -347,23 +351,23 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
83790
83791 static inline int rt_genid_ipv4(struct net *net)
83792 {
83793- return atomic_read(&net->ipv4.rt_genid);
83794+ return atomic_read_unchecked(&net->ipv4.rt_genid);
83795 }
83796
83797 static inline void rt_genid_bump_ipv4(struct net *net)
83798 {
83799- atomic_inc(&net->ipv4.rt_genid);
83800+ atomic_inc_unchecked(&net->ipv4.rt_genid);
83801 }
83802
83803 #if IS_ENABLED(CONFIG_IPV6)
83804 static inline int rt_genid_ipv6(struct net *net)
83805 {
83806- return atomic_read(&net->ipv6.rt_genid);
83807+ return atomic_read_unchecked(&net->ipv6.rt_genid);
83808 }
83809
83810 static inline void rt_genid_bump_ipv6(struct net *net)
83811 {
83812- atomic_inc(&net->ipv6.rt_genid);
83813+ atomic_inc_unchecked(&net->ipv6.rt_genid);
83814 }
83815 #else
83816 static inline int rt_genid_ipv6(struct net *net)
83817@@ -385,12 +389,12 @@ static inline void rt_genid_bump_all(struct net *net)
83818
83819 static inline int fnhe_genid(struct net *net)
83820 {
83821- return atomic_read(&net->fnhe_genid);
83822+ return atomic_read_unchecked(&net->fnhe_genid);
83823 }
83824
83825 static inline void fnhe_genid_bump(struct net *net)
83826 {
83827- atomic_inc(&net->fnhe_genid);
83828+ atomic_inc_unchecked(&net->fnhe_genid);
83829 }
83830
83831 #endif /* __NET_NET_NAMESPACE_H */
83832diff --git a/include/net/netdma.h b/include/net/netdma.h
83833index 8ba8ce2..99b7fff 100644
83834--- a/include/net/netdma.h
83835+++ b/include/net/netdma.h
83836@@ -24,7 +24,7 @@
83837 #include <linux/dmaengine.h>
83838 #include <linux/skbuff.h>
83839
83840-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
83841+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
83842 struct sk_buff *skb, int offset, struct iovec *to,
83843 size_t len, struct dma_pinned_list *pinned_list);
83844
83845diff --git a/include/net/netfilter/nf_conntrack_extend.h b/include/net/netfilter/nf_conntrack_extend.h
83846index 956b175..55d1504 100644
83847--- a/include/net/netfilter/nf_conntrack_extend.h
83848+++ b/include/net/netfilter/nf_conntrack_extend.h
83849@@ -47,8 +47,8 @@ enum nf_ct_ext_id {
83850 /* Extensions: optional stuff which isn't permanently in struct. */
83851 struct nf_ct_ext {
83852 struct rcu_head rcu;
83853- u8 offset[NF_CT_EXT_NUM];
83854- u8 len;
83855+ u16 offset[NF_CT_EXT_NUM];
83856+ u16 len;
83857 char data[0];
83858 };
83859
83860diff --git a/include/net/netlink.h b/include/net/netlink.h
83861index 2b47eaa..6d5bcc2 100644
83862--- a/include/net/netlink.h
83863+++ b/include/net/netlink.h
83864@@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
83865 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
83866 {
83867 if (mark)
83868- skb_trim(skb, (unsigned char *) mark - skb->data);
83869+ skb_trim(skb, (const unsigned char *) mark - skb->data);
83870 }
83871
83872 /**
83873diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
83874index fbcc7fa..03c7e51 100644
83875--- a/include/net/netns/conntrack.h
83876+++ b/include/net/netns/conntrack.h
83877@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
83878 struct nf_proto_net {
83879 #ifdef CONFIG_SYSCTL
83880 struct ctl_table_header *ctl_table_header;
83881- struct ctl_table *ctl_table;
83882+ ctl_table_no_const *ctl_table;
83883 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
83884 struct ctl_table_header *ctl_compat_header;
83885- struct ctl_table *ctl_compat_table;
83886+ ctl_table_no_const *ctl_compat_table;
83887 #endif
83888 #endif
83889 unsigned int users;
83890@@ -58,7 +58,7 @@ struct nf_ip_net {
83891 struct nf_icmp_net icmpv6;
83892 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
83893 struct ctl_table_header *ctl_table_header;
83894- struct ctl_table *ctl_table;
83895+ ctl_table_no_const *ctl_table;
83896 #endif
83897 };
83898
83899diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
83900index 80f500a..f0c23c2 100644
83901--- a/include/net/netns/ipv4.h
83902+++ b/include/net/netns/ipv4.h
83903@@ -74,7 +74,7 @@ struct netns_ipv4 {
83904
83905 kgid_t sysctl_ping_group_range[2];
83906
83907- atomic_t dev_addr_genid;
83908+ atomic_unchecked_t dev_addr_genid;
83909
83910 #ifdef CONFIG_IP_MROUTE
83911 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
83912@@ -84,6 +84,6 @@ struct netns_ipv4 {
83913 struct fib_rules_ops *mr_rules_ops;
83914 #endif
83915 #endif
83916- atomic_t rt_genid;
83917+ atomic_unchecked_t rt_genid;
83918 };
83919 #endif
83920diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
83921index 21edaf1..4c5faae 100644
83922--- a/include/net/netns/ipv6.h
83923+++ b/include/net/netns/ipv6.h
83924@@ -73,8 +73,8 @@ struct netns_ipv6 {
83925 struct fib_rules_ops *mr6_rules_ops;
83926 #endif
83927 #endif
83928- atomic_t dev_addr_genid;
83929- atomic_t rt_genid;
83930+ atomic_unchecked_t dev_addr_genid;
83931+ atomic_unchecked_t rt_genid;
83932 };
83933
83934 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
83935diff --git a/include/net/ping.h b/include/net/ping.h
83936index 026479b..d9b2829 100644
83937--- a/include/net/ping.h
83938+++ b/include/net/ping.h
83939@@ -54,7 +54,7 @@ struct ping_iter_state {
83940
83941 extern struct proto ping_prot;
83942 #if IS_ENABLED(CONFIG_IPV6)
83943-extern struct pingv6_ops pingv6_ops;
83944+extern struct pingv6_ops *pingv6_ops;
83945 #endif
83946
83947 struct pingfakehdr {
83948diff --git a/include/net/protocol.h b/include/net/protocol.h
83949index a7e986b..dc67bce 100644
83950--- a/include/net/protocol.h
83951+++ b/include/net/protocol.h
83952@@ -49,7 +49,7 @@ struct net_protocol {
83953 * socket lookup?
83954 */
83955 icmp_strict_tag_validation:1;
83956-};
83957+} __do_const;
83958
83959 #if IS_ENABLED(CONFIG_IPV6)
83960 struct inet6_protocol {
83961@@ -62,7 +62,7 @@ struct inet6_protocol {
83962 u8 type, u8 code, int offset,
83963 __be32 info);
83964 unsigned int flags; /* INET6_PROTO_xxx */
83965-};
83966+} __do_const;
83967
83968 #define INET6_PROTO_NOPOLICY 0x1
83969 #define INET6_PROTO_FINAL 0x2
83970diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
83971index 661e45d..54c39df 100644
83972--- a/include/net/rtnetlink.h
83973+++ b/include/net/rtnetlink.h
83974@@ -93,7 +93,7 @@ struct rtnl_link_ops {
83975 int (*fill_slave_info)(struct sk_buff *skb,
83976 const struct net_device *dev,
83977 const struct net_device *slave_dev);
83978-};
83979+} __do_const;
83980
83981 int __rtnl_link_register(struct rtnl_link_ops *ops);
83982 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
83983diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
83984index 4a5b9a3..ca27d73 100644
83985--- a/include/net/sctp/checksum.h
83986+++ b/include/net/sctp/checksum.h
83987@@ -61,8 +61,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
83988 unsigned int offset)
83989 {
83990 struct sctphdr *sh = sctp_hdr(skb);
83991- __le32 ret, old = sh->checksum;
83992- const struct skb_checksum_ops ops = {
83993+ __le32 ret, old = sh->checksum;
83994+ static const struct skb_checksum_ops ops = {
83995 .update = sctp_csum_update,
83996 .combine = sctp_csum_combine,
83997 };
83998diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
83999index 7f4eeb3..37e8fe1 100644
84000--- a/include/net/sctp/sm.h
84001+++ b/include/net/sctp/sm.h
84002@@ -80,7 +80,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
84003 typedef struct {
84004 sctp_state_fn_t *fn;
84005 const char *name;
84006-} sctp_sm_table_entry_t;
84007+} __do_const sctp_sm_table_entry_t;
84008
84009 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
84010 * currently in use.
84011@@ -292,7 +292,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
84012 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
84013
84014 /* Extern declarations for major data structures. */
84015-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
84016+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
84017
84018
84019 /* Get the size of a DATA chunk payload. */
84020diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
84021index 6ee76c8..45f2609 100644
84022--- a/include/net/sctp/structs.h
84023+++ b/include/net/sctp/structs.h
84024@@ -507,7 +507,7 @@ struct sctp_pf {
84025 struct sctp_association *asoc);
84026 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
84027 struct sctp_af *af;
84028-};
84029+} __do_const;
84030
84031
84032 /* Structure to track chunk fragments that have been acked, but peer
84033diff --git a/include/net/sock.h b/include/net/sock.h
84034index b9586a1..b2948c0 100644
84035--- a/include/net/sock.h
84036+++ b/include/net/sock.h
84037@@ -348,7 +348,7 @@ struct sock {
84038 unsigned int sk_napi_id;
84039 unsigned int sk_ll_usec;
84040 #endif
84041- atomic_t sk_drops;
84042+ atomic_unchecked_t sk_drops;
84043 int sk_rcvbuf;
84044
84045 struct sk_filter __rcu *sk_filter;
84046@@ -1036,7 +1036,7 @@ struct proto {
84047 void (*destroy_cgroup)(struct mem_cgroup *memcg);
84048 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
84049 #endif
84050-};
84051+} __randomize_layout;
84052
84053 /*
84054 * Bits in struct cg_proto.flags
84055@@ -1223,7 +1223,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
84056 return ret >> PAGE_SHIFT;
84057 }
84058
84059-static inline long
84060+static inline long __intentional_overflow(-1)
84061 sk_memory_allocated(const struct sock *sk)
84062 {
84063 struct proto *prot = sk->sk_prot;
84064@@ -1368,7 +1368,7 @@ struct sock_iocb {
84065 struct scm_cookie *scm;
84066 struct msghdr *msg, async_msg;
84067 struct kiocb *kiocb;
84068-};
84069+} __randomize_layout;
84070
84071 static inline struct sock_iocb *kiocb_to_siocb(struct kiocb *iocb)
84072 {
84073@@ -1830,7 +1830,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
84074 }
84075
84076 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
84077- char __user *from, char *to,
84078+ char __user *from, unsigned char *to,
84079 int copy, int offset)
84080 {
84081 if (skb->ip_summed == CHECKSUM_NONE) {
84082@@ -2092,7 +2092,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
84083 }
84084 }
84085
84086-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
84087+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
84088
84089 /**
84090 * sk_page_frag - return an appropriate page_frag
84091diff --git a/include/net/tcp.h b/include/net/tcp.h
84092index 743acce..44a58b0 100644
84093--- a/include/net/tcp.h
84094+++ b/include/net/tcp.h
84095@@ -541,7 +541,7 @@ void tcp_retransmit_timer(struct sock *sk);
84096 void tcp_xmit_retransmit_queue(struct sock *);
84097 void tcp_simple_retransmit(struct sock *);
84098 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
84099-int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
84100+int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
84101
84102 void tcp_send_probe0(struct sock *);
84103 void tcp_send_partial(struct sock *);
84104@@ -710,8 +710,8 @@ struct tcp_skb_cb {
84105 struct inet6_skb_parm h6;
84106 #endif
84107 } header; /* For incoming frames */
84108- __u32 seq; /* Starting sequence number */
84109- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
84110+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
84111+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
84112 __u32 when; /* used to compute rtt's */
84113 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
84114
84115@@ -725,7 +725,7 @@ struct tcp_skb_cb {
84116
84117 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
84118 /* 1 byte hole */
84119- __u32 ack_seq; /* Sequence number ACK'd */
84120+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
84121 };
84122
84123 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
84124diff --git a/include/net/xfrm.h b/include/net/xfrm.h
84125index fb5654a..4457522 100644
84126--- a/include/net/xfrm.h
84127+++ b/include/net/xfrm.h
84128@@ -286,7 +286,6 @@ struct xfrm_dst;
84129 struct xfrm_policy_afinfo {
84130 unsigned short family;
84131 struct dst_ops *dst_ops;
84132- void (*garbage_collect)(struct net *net);
84133 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
84134 const xfrm_address_t *saddr,
84135 const xfrm_address_t *daddr);
84136@@ -304,7 +303,7 @@ struct xfrm_policy_afinfo {
84137 struct net_device *dev,
84138 const struct flowi *fl);
84139 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
84140-};
84141+} __do_const;
84142
84143 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
84144 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
84145@@ -343,7 +342,7 @@ struct xfrm_state_afinfo {
84146 int (*transport_finish)(struct sk_buff *skb,
84147 int async);
84148 void (*local_error)(struct sk_buff *skb, u32 mtu);
84149-};
84150+} __do_const;
84151
84152 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
84153 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
84154@@ -428,7 +427,7 @@ struct xfrm_mode {
84155 struct module *owner;
84156 unsigned int encap;
84157 int flags;
84158-};
84159+} __do_const;
84160
84161 /* Flags for xfrm_mode. */
84162 enum {
84163@@ -525,7 +524,7 @@ struct xfrm_policy {
84164 struct timer_list timer;
84165
84166 struct flow_cache_object flo;
84167- atomic_t genid;
84168+ atomic_unchecked_t genid;
84169 u32 priority;
84170 u32 index;
84171 struct xfrm_mark mark;
84172@@ -1165,6 +1164,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
84173 }
84174
84175 void xfrm_garbage_collect(struct net *net);
84176+void xfrm_garbage_collect_deferred(struct net *net);
84177
84178 #else
84179
84180@@ -1203,6 +1203,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
84181 static inline void xfrm_garbage_collect(struct net *net)
84182 {
84183 }
84184+static inline void xfrm_garbage_collect_deferred(struct net *net)
84185+{
84186+}
84187 #endif
84188
84189 static __inline__
84190diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
84191index 1017e0b..227aa4d 100644
84192--- a/include/rdma/iw_cm.h
84193+++ b/include/rdma/iw_cm.h
84194@@ -122,7 +122,7 @@ struct iw_cm_verbs {
84195 int backlog);
84196
84197 int (*destroy_listen)(struct iw_cm_id *cm_id);
84198-};
84199+} __no_const;
84200
84201 /**
84202 * iw_create_cm_id - Create an IW CM identifier.
84203diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
84204index 52beadf..598734c 100644
84205--- a/include/scsi/libfc.h
84206+++ b/include/scsi/libfc.h
84207@@ -771,6 +771,7 @@ struct libfc_function_template {
84208 */
84209 void (*disc_stop_final) (struct fc_lport *);
84210 };
84211+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
84212
84213 /**
84214 * struct fc_disc - Discovery context
84215@@ -875,7 +876,7 @@ struct fc_lport {
84216 struct fc_vport *vport;
84217
84218 /* Operational Information */
84219- struct libfc_function_template tt;
84220+ libfc_function_template_no_const tt;
84221 u8 link_up;
84222 u8 qfull;
84223 enum fc_lport_state state;
84224diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
84225index d65fbec..f80fef2 100644
84226--- a/include/scsi/scsi_device.h
84227+++ b/include/scsi/scsi_device.h
84228@@ -180,9 +180,9 @@ struct scsi_device {
84229 unsigned int max_device_blocked; /* what device_blocked counts down from */
84230 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
84231
84232- atomic_t iorequest_cnt;
84233- atomic_t iodone_cnt;
84234- atomic_t ioerr_cnt;
84235+ atomic_unchecked_t iorequest_cnt;
84236+ atomic_unchecked_t iodone_cnt;
84237+ atomic_unchecked_t ioerr_cnt;
84238
84239 struct device sdev_gendev,
84240 sdev_dev;
84241diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
84242index b797e8f..8e2c3aa 100644
84243--- a/include/scsi/scsi_transport_fc.h
84244+++ b/include/scsi/scsi_transport_fc.h
84245@@ -751,7 +751,8 @@ struct fc_function_template {
84246 unsigned long show_host_system_hostname:1;
84247
84248 unsigned long disable_target_scan:1;
84249-};
84250+} __do_const;
84251+typedef struct fc_function_template __no_const fc_function_template_no_const;
84252
84253
84254 /**
84255diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
84256index ae6c3b8..fd748ac 100644
84257--- a/include/sound/compress_driver.h
84258+++ b/include/sound/compress_driver.h
84259@@ -128,7 +128,7 @@ struct snd_compr_ops {
84260 struct snd_compr_caps *caps);
84261 int (*get_codec_caps) (struct snd_compr_stream *stream,
84262 struct snd_compr_codec_caps *codec);
84263-};
84264+} __no_const;
84265
84266 /**
84267 * struct snd_compr: Compressed device
84268diff --git a/include/sound/soc.h b/include/sound/soc.h
84269index 9a00147..d814573 100644
84270--- a/include/sound/soc.h
84271+++ b/include/sound/soc.h
84272@@ -770,7 +770,7 @@ struct snd_soc_codec_driver {
84273 /* probe ordering - for components with runtime dependencies */
84274 int probe_order;
84275 int remove_order;
84276-};
84277+} __do_const;
84278
84279 /* SoC platform interface */
84280 struct snd_soc_platform_driver {
84281@@ -816,7 +816,7 @@ struct snd_soc_platform_driver {
84282 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
84283 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
84284 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
84285-};
84286+} __do_const;
84287
84288 struct snd_soc_platform {
84289 const char *name;
84290diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
84291index 1772fad..282e3e2 100644
84292--- a/include/target/target_core_base.h
84293+++ b/include/target/target_core_base.h
84294@@ -754,7 +754,7 @@ struct se_device {
84295 atomic_long_t write_bytes;
84296 /* Active commands on this virtual SE device */
84297 atomic_t simple_cmds;
84298- atomic_t dev_ordered_id;
84299+ atomic_unchecked_t dev_ordered_id;
84300 atomic_t dev_ordered_sync;
84301 atomic_t dev_qf_count;
84302 int export_count;
84303diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
84304new file mode 100644
84305index 0000000..fb634b7
84306--- /dev/null
84307+++ b/include/trace/events/fs.h
84308@@ -0,0 +1,53 @@
84309+#undef TRACE_SYSTEM
84310+#define TRACE_SYSTEM fs
84311+
84312+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
84313+#define _TRACE_FS_H
84314+
84315+#include <linux/fs.h>
84316+#include <linux/tracepoint.h>
84317+
84318+TRACE_EVENT(do_sys_open,
84319+
84320+ TP_PROTO(const char *filename, int flags, int mode),
84321+
84322+ TP_ARGS(filename, flags, mode),
84323+
84324+ TP_STRUCT__entry(
84325+ __string( filename, filename )
84326+ __field( int, flags )
84327+ __field( int, mode )
84328+ ),
84329+
84330+ TP_fast_assign(
84331+ __assign_str(filename, filename);
84332+ __entry->flags = flags;
84333+ __entry->mode = mode;
84334+ ),
84335+
84336+ TP_printk("\"%s\" %x %o",
84337+ __get_str(filename), __entry->flags, __entry->mode)
84338+);
84339+
84340+TRACE_EVENT(open_exec,
84341+
84342+ TP_PROTO(const char *filename),
84343+
84344+ TP_ARGS(filename),
84345+
84346+ TP_STRUCT__entry(
84347+ __string( filename, filename )
84348+ ),
84349+
84350+ TP_fast_assign(
84351+ __assign_str(filename, filename);
84352+ ),
84353+
84354+ TP_printk("\"%s\"",
84355+ __get_str(filename))
84356+);
84357+
84358+#endif /* _TRACE_FS_H */
84359+
84360+/* This part must be outside protection */
84361+#include <trace/define_trace.h>
84362diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
84363index 1c09820..7f5ec79 100644
84364--- a/include/trace/events/irq.h
84365+++ b/include/trace/events/irq.h
84366@@ -36,7 +36,7 @@ struct softirq_action;
84367 */
84368 TRACE_EVENT(irq_handler_entry,
84369
84370- TP_PROTO(int irq, struct irqaction *action),
84371+ TP_PROTO(int irq, const struct irqaction *action),
84372
84373 TP_ARGS(irq, action),
84374
84375@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
84376 */
84377 TRACE_EVENT(irq_handler_exit,
84378
84379- TP_PROTO(int irq, struct irqaction *action, int ret),
84380+ TP_PROTO(int irq, const struct irqaction *action, int ret),
84381
84382 TP_ARGS(irq, action, ret),
84383
84384diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
84385index 7caf44c..23c6f27 100644
84386--- a/include/uapi/linux/a.out.h
84387+++ b/include/uapi/linux/a.out.h
84388@@ -39,6 +39,14 @@ enum machine_type {
84389 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
84390 };
84391
84392+/* Constants for the N_FLAGS field */
84393+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
84394+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
84395+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
84396+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
84397+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
84398+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
84399+
84400 #if !defined (N_MAGIC)
84401 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
84402 #endif
84403diff --git a/include/uapi/linux/bcache.h b/include/uapi/linux/bcache.h
84404index 22b6ad3..aeba37e 100644
84405--- a/include/uapi/linux/bcache.h
84406+++ b/include/uapi/linux/bcache.h
84407@@ -5,6 +5,7 @@
84408 * Bcache on disk data structures
84409 */
84410
84411+#include <linux/compiler.h>
84412 #include <asm/types.h>
84413
84414 #define BITMASK(name, type, field, offset, size) \
84415@@ -20,8 +21,8 @@ static inline void SET_##name(type *k, __u64 v) \
84416 /* Btree keys - all units are in sectors */
84417
84418 struct bkey {
84419- __u64 high;
84420- __u64 low;
84421+ __u64 high __intentional_overflow(-1);
84422+ __u64 low __intentional_overflow(-1);
84423 __u64 ptr[];
84424 };
84425
84426diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
84427index d876736..ccce5c0 100644
84428--- a/include/uapi/linux/byteorder/little_endian.h
84429+++ b/include/uapi/linux/byteorder/little_endian.h
84430@@ -42,51 +42,51 @@
84431
84432 static inline __le64 __cpu_to_le64p(const __u64 *p)
84433 {
84434- return (__force __le64)*p;
84435+ return (__force const __le64)*p;
84436 }
84437-static inline __u64 __le64_to_cpup(const __le64 *p)
84438+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
84439 {
84440- return (__force __u64)*p;
84441+ return (__force const __u64)*p;
84442 }
84443 static inline __le32 __cpu_to_le32p(const __u32 *p)
84444 {
84445- return (__force __le32)*p;
84446+ return (__force const __le32)*p;
84447 }
84448 static inline __u32 __le32_to_cpup(const __le32 *p)
84449 {
84450- return (__force __u32)*p;
84451+ return (__force const __u32)*p;
84452 }
84453 static inline __le16 __cpu_to_le16p(const __u16 *p)
84454 {
84455- return (__force __le16)*p;
84456+ return (__force const __le16)*p;
84457 }
84458 static inline __u16 __le16_to_cpup(const __le16 *p)
84459 {
84460- return (__force __u16)*p;
84461+ return (__force const __u16)*p;
84462 }
84463 static inline __be64 __cpu_to_be64p(const __u64 *p)
84464 {
84465- return (__force __be64)__swab64p(p);
84466+ return (__force const __be64)__swab64p(p);
84467 }
84468 static inline __u64 __be64_to_cpup(const __be64 *p)
84469 {
84470- return __swab64p((__u64 *)p);
84471+ return __swab64p((const __u64 *)p);
84472 }
84473 static inline __be32 __cpu_to_be32p(const __u32 *p)
84474 {
84475- return (__force __be32)__swab32p(p);
84476+ return (__force const __be32)__swab32p(p);
84477 }
84478-static inline __u32 __be32_to_cpup(const __be32 *p)
84479+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
84480 {
84481- return __swab32p((__u32 *)p);
84482+ return __swab32p((const __u32 *)p);
84483 }
84484 static inline __be16 __cpu_to_be16p(const __u16 *p)
84485 {
84486- return (__force __be16)__swab16p(p);
84487+ return (__force const __be16)__swab16p(p);
84488 }
84489 static inline __u16 __be16_to_cpup(const __be16 *p)
84490 {
84491- return __swab16p((__u16 *)p);
84492+ return __swab16p((const __u16 *)p);
84493 }
84494 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
84495 #define __le64_to_cpus(x) do { (void)(x); } while (0)
84496diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
84497index ef6103b..d4e65dd 100644
84498--- a/include/uapi/linux/elf.h
84499+++ b/include/uapi/linux/elf.h
84500@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
84501 #define PT_GNU_EH_FRAME 0x6474e550
84502
84503 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
84504+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
84505+
84506+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
84507+
84508+/* Constants for the e_flags field */
84509+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
84510+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
84511+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
84512+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
84513+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
84514+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
84515
84516 /*
84517 * Extended Numbering
84518@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
84519 #define DT_DEBUG 21
84520 #define DT_TEXTREL 22
84521 #define DT_JMPREL 23
84522+#define DT_FLAGS 30
84523+ #define DF_TEXTREL 0x00000004
84524 #define DT_ENCODING 32
84525 #define OLD_DT_LOOS 0x60000000
84526 #define DT_LOOS 0x6000000d
84527@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
84528 #define PF_W 0x2
84529 #define PF_X 0x1
84530
84531+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
84532+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
84533+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
84534+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
84535+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
84536+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
84537+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
84538+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
84539+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
84540+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
84541+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
84542+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
84543+
84544 typedef struct elf32_phdr{
84545 Elf32_Word p_type;
84546 Elf32_Off p_offset;
84547@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
84548 #define EI_OSABI 7
84549 #define EI_PAD 8
84550
84551+#define EI_PAX 14
84552+
84553 #define ELFMAG0 0x7f /* EI_MAG */
84554 #define ELFMAG1 'E'
84555 #define ELFMAG2 'L'
84556diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
84557index aa169c4..6a2771d 100644
84558--- a/include/uapi/linux/personality.h
84559+++ b/include/uapi/linux/personality.h
84560@@ -30,6 +30,7 @@ enum {
84561 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
84562 ADDR_NO_RANDOMIZE | \
84563 ADDR_COMPAT_LAYOUT | \
84564+ ADDR_LIMIT_3GB | \
84565 MMAP_PAGE_ZERO)
84566
84567 /*
84568diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
84569index 7530e74..e714828 100644
84570--- a/include/uapi/linux/screen_info.h
84571+++ b/include/uapi/linux/screen_info.h
84572@@ -43,7 +43,8 @@ struct screen_info {
84573 __u16 pages; /* 0x32 */
84574 __u16 vesa_attributes; /* 0x34 */
84575 __u32 capabilities; /* 0x36 */
84576- __u8 _reserved[6]; /* 0x3a */
84577+ __u16 vesapm_size; /* 0x3a */
84578+ __u8 _reserved[4]; /* 0x3c */
84579 } __attribute__((packed));
84580
84581 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
84582diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
84583index 0e011eb..82681b1 100644
84584--- a/include/uapi/linux/swab.h
84585+++ b/include/uapi/linux/swab.h
84586@@ -43,7 +43,7 @@
84587 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
84588 */
84589
84590-static inline __attribute_const__ __u16 __fswab16(__u16 val)
84591+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
84592 {
84593 #ifdef __HAVE_BUILTIN_BSWAP16__
84594 return __builtin_bswap16(val);
84595@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
84596 #endif
84597 }
84598
84599-static inline __attribute_const__ __u32 __fswab32(__u32 val)
84600+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
84601 {
84602 #ifdef __HAVE_BUILTIN_BSWAP32__
84603 return __builtin_bswap32(val);
84604@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
84605 #endif
84606 }
84607
84608-static inline __attribute_const__ __u64 __fswab64(__u64 val)
84609+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
84610 {
84611 #ifdef __HAVE_BUILTIN_BSWAP64__
84612 return __builtin_bswap64(val);
84613diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
84614index 6d67213..552fdd9 100644
84615--- a/include/uapi/linux/sysctl.h
84616+++ b/include/uapi/linux/sysctl.h
84617@@ -155,8 +155,6 @@ enum
84618 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
84619 };
84620
84621-
84622-
84623 /* CTL_VM names: */
84624 enum
84625 {
84626diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
84627index fe94bb9..c9e51c2 100644
84628--- a/include/uapi/linux/videodev2.h
84629+++ b/include/uapi/linux/videodev2.h
84630@@ -1227,7 +1227,7 @@ struct v4l2_ext_control {
84631 union {
84632 __s32 value;
84633 __s64 value64;
84634- char *string;
84635+ char __user *string;
84636 };
84637 } __attribute__ ((packed));
84638
84639diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
84640index c38355c..17a57bc 100644
84641--- a/include/uapi/linux/xattr.h
84642+++ b/include/uapi/linux/xattr.h
84643@@ -73,5 +73,9 @@
84644 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
84645 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
84646
84647+/* User namespace */
84648+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
84649+#define XATTR_PAX_FLAGS_SUFFIX "flags"
84650+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
84651
84652 #endif /* _UAPI_LINUX_XATTR_H */
84653diff --git a/include/video/udlfb.h b/include/video/udlfb.h
84654index f9466fa..f4e2b81 100644
84655--- a/include/video/udlfb.h
84656+++ b/include/video/udlfb.h
84657@@ -53,10 +53,10 @@ struct dlfb_data {
84658 u32 pseudo_palette[256];
84659 int blank_mode; /*one of FB_BLANK_ */
84660 /* blit-only rendering path metrics, exposed through sysfs */
84661- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
84662- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
84663- atomic_t bytes_sent; /* to usb, after compression including overhead */
84664- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
84665+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
84666+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
84667+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
84668+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
84669 };
84670
84671 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
84672diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
84673index 30f5362..8ed8ac9 100644
84674--- a/include/video/uvesafb.h
84675+++ b/include/video/uvesafb.h
84676@@ -122,6 +122,7 @@ struct uvesafb_par {
84677 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
84678 u8 pmi_setpal; /* PMI for palette changes */
84679 u16 *pmi_base; /* protected mode interface location */
84680+ u8 *pmi_code; /* protected mode code location */
84681 void *pmi_start;
84682 void *pmi_pal;
84683 u8 *vbe_state_orig; /*
84684diff --git a/init/Kconfig b/init/Kconfig
84685index d56cb03..7e6d5dc 100644
84686--- a/init/Kconfig
84687+++ b/init/Kconfig
84688@@ -1079,6 +1079,7 @@ endif # CGROUPS
84689
84690 config CHECKPOINT_RESTORE
84691 bool "Checkpoint/restore support" if EXPERT
84692+ depends on !GRKERNSEC
84693 default n
84694 help
84695 Enables additional kernel features in a sake of checkpoint/restore.
84696@@ -1545,7 +1546,7 @@ config SLUB_DEBUG
84697
84698 config COMPAT_BRK
84699 bool "Disable heap randomization"
84700- default y
84701+ default n
84702 help
84703 Randomizing heap placement makes heap exploits harder, but it
84704 also breaks ancient binaries (including anything libc5 based).
84705@@ -1833,7 +1834,7 @@ config INIT_ALL_POSSIBLE
84706 config STOP_MACHINE
84707 bool
84708 default y
84709- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
84710+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
84711 help
84712 Need stop_machine() primitive.
84713
84714diff --git a/init/Makefile b/init/Makefile
84715index 7bc47ee..6da2dc7 100644
84716--- a/init/Makefile
84717+++ b/init/Makefile
84718@@ -2,6 +2,9 @@
84719 # Makefile for the linux kernel.
84720 #
84721
84722+ccflags-y := $(GCC_PLUGINS_CFLAGS)
84723+asflags-y := $(GCC_PLUGINS_AFLAGS)
84724+
84725 obj-y := main.o version.o mounts.o
84726 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
84727 obj-y += noinitramfs.o
84728diff --git a/init/do_mounts.c b/init/do_mounts.c
84729index 8e5addc..c96ea61 100644
84730--- a/init/do_mounts.c
84731+++ b/init/do_mounts.c
84732@@ -359,11 +359,11 @@ static void __init get_fs_names(char *page)
84733 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
84734 {
84735 struct super_block *s;
84736- int err = sys_mount(name, "/root", fs, flags, data);
84737+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
84738 if (err)
84739 return err;
84740
84741- sys_chdir("/root");
84742+ sys_chdir((const char __force_user *)"/root");
84743 s = current->fs->pwd.dentry->d_sb;
84744 ROOT_DEV = s->s_dev;
84745 printk(KERN_INFO
84746@@ -484,18 +484,18 @@ void __init change_floppy(char *fmt, ...)
84747 va_start(args, fmt);
84748 vsprintf(buf, fmt, args);
84749 va_end(args);
84750- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
84751+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
84752 if (fd >= 0) {
84753 sys_ioctl(fd, FDEJECT, 0);
84754 sys_close(fd);
84755 }
84756 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
84757- fd = sys_open("/dev/console", O_RDWR, 0);
84758+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
84759 if (fd >= 0) {
84760 sys_ioctl(fd, TCGETS, (long)&termios);
84761 termios.c_lflag &= ~ICANON;
84762 sys_ioctl(fd, TCSETSF, (long)&termios);
84763- sys_read(fd, &c, 1);
84764+ sys_read(fd, (char __user *)&c, 1);
84765 termios.c_lflag |= ICANON;
84766 sys_ioctl(fd, TCSETSF, (long)&termios);
84767 sys_close(fd);
84768@@ -589,8 +589,8 @@ void __init prepare_namespace(void)
84769 mount_root();
84770 out:
84771 devtmpfs_mount("dev");
84772- sys_mount(".", "/", NULL, MS_MOVE, NULL);
84773- sys_chroot(".");
84774+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
84775+ sys_chroot((const char __force_user *)".");
84776 }
84777
84778 static bool is_tmpfs;
84779diff --git a/init/do_mounts.h b/init/do_mounts.h
84780index f5b978a..69dbfe8 100644
84781--- a/init/do_mounts.h
84782+++ b/init/do_mounts.h
84783@@ -15,15 +15,15 @@ extern int root_mountflags;
84784
84785 static inline int create_dev(char *name, dev_t dev)
84786 {
84787- sys_unlink(name);
84788- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
84789+ sys_unlink((char __force_user *)name);
84790+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
84791 }
84792
84793 #if BITS_PER_LONG == 32
84794 static inline u32 bstat(char *name)
84795 {
84796 struct stat64 stat;
84797- if (sys_stat64(name, &stat) != 0)
84798+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
84799 return 0;
84800 if (!S_ISBLK(stat.st_mode))
84801 return 0;
84802@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
84803 static inline u32 bstat(char *name)
84804 {
84805 struct stat stat;
84806- if (sys_newstat(name, &stat) != 0)
84807+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
84808 return 0;
84809 if (!S_ISBLK(stat.st_mode))
84810 return 0;
84811diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
84812index 3e0878e..8a9d7a0 100644
84813--- a/init/do_mounts_initrd.c
84814+++ b/init/do_mounts_initrd.c
84815@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
84816 {
84817 sys_unshare(CLONE_FS | CLONE_FILES);
84818 /* stdin/stdout/stderr for /linuxrc */
84819- sys_open("/dev/console", O_RDWR, 0);
84820+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
84821 sys_dup(0);
84822 sys_dup(0);
84823 /* move initrd over / and chdir/chroot in initrd root */
84824- sys_chdir("/root");
84825- sys_mount(".", "/", NULL, MS_MOVE, NULL);
84826- sys_chroot(".");
84827+ sys_chdir((const char __force_user *)"/root");
84828+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
84829+ sys_chroot((const char __force_user *)".");
84830 sys_setsid();
84831 return 0;
84832 }
84833@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
84834 create_dev("/dev/root.old", Root_RAM0);
84835 /* mount initrd on rootfs' /root */
84836 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
84837- sys_mkdir("/old", 0700);
84838- sys_chdir("/old");
84839+ sys_mkdir((const char __force_user *)"/old", 0700);
84840+ sys_chdir((const char __force_user *)"/old");
84841
84842 /* try loading default modules from initrd */
84843 load_default_modules();
84844@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
84845 current->flags &= ~PF_FREEZER_SKIP;
84846
84847 /* move initrd to rootfs' /old */
84848- sys_mount("..", ".", NULL, MS_MOVE, NULL);
84849+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
84850 /* switch root and cwd back to / of rootfs */
84851- sys_chroot("..");
84852+ sys_chroot((const char __force_user *)"..");
84853
84854 if (new_decode_dev(real_root_dev) == Root_RAM0) {
84855- sys_chdir("/old");
84856+ sys_chdir((const char __force_user *)"/old");
84857 return;
84858 }
84859
84860- sys_chdir("/");
84861+ sys_chdir((const char __force_user *)"/");
84862 ROOT_DEV = new_decode_dev(real_root_dev);
84863 mount_root();
84864
84865 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
84866- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
84867+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
84868 if (!error)
84869 printk("okay\n");
84870 else {
84871- int fd = sys_open("/dev/root.old", O_RDWR, 0);
84872+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
84873 if (error == -ENOENT)
84874 printk("/initrd does not exist. Ignored.\n");
84875 else
84876 printk("failed\n");
84877 printk(KERN_NOTICE "Unmounting old root\n");
84878- sys_umount("/old", MNT_DETACH);
84879+ sys_umount((char __force_user *)"/old", MNT_DETACH);
84880 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
84881 if (fd < 0) {
84882 error = fd;
84883@@ -127,11 +127,11 @@ int __init initrd_load(void)
84884 * mounted in the normal path.
84885 */
84886 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
84887- sys_unlink("/initrd.image");
84888+ sys_unlink((const char __force_user *)"/initrd.image");
84889 handle_initrd();
84890 return 1;
84891 }
84892 }
84893- sys_unlink("/initrd.image");
84894+ sys_unlink((const char __force_user *)"/initrd.image");
84895 return 0;
84896 }
84897diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
84898index 8cb6db5..d729f50 100644
84899--- a/init/do_mounts_md.c
84900+++ b/init/do_mounts_md.c
84901@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
84902 partitioned ? "_d" : "", minor,
84903 md_setup_args[ent].device_names);
84904
84905- fd = sys_open(name, 0, 0);
84906+ fd = sys_open((char __force_user *)name, 0, 0);
84907 if (fd < 0) {
84908 printk(KERN_ERR "md: open failed - cannot start "
84909 "array %s\n", name);
84910@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
84911 * array without it
84912 */
84913 sys_close(fd);
84914- fd = sys_open(name, 0, 0);
84915+ fd = sys_open((char __force_user *)name, 0, 0);
84916 sys_ioctl(fd, BLKRRPART, 0);
84917 }
84918 sys_close(fd);
84919@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
84920
84921 wait_for_device_probe();
84922
84923- fd = sys_open("/dev/md0", 0, 0);
84924+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
84925 if (fd >= 0) {
84926 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
84927 sys_close(fd);
84928diff --git a/init/init_task.c b/init/init_task.c
84929index ba0a7f36..2bcf1d5 100644
84930--- a/init/init_task.c
84931+++ b/init/init_task.c
84932@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
84933 * Initial thread structure. Alignment of this is handled by a special
84934 * linker map entry.
84935 */
84936+#ifdef CONFIG_X86
84937+union thread_union init_thread_union __init_task_data;
84938+#else
84939 union thread_union init_thread_union __init_task_data =
84940 { INIT_THREAD_INFO(init_task) };
84941+#endif
84942diff --git a/init/initramfs.c b/init/initramfs.c
84943index 93b6139..8d628b7 100644
84944--- a/init/initramfs.c
84945+++ b/init/initramfs.c
84946@@ -84,7 +84,7 @@ static void __init free_hash(void)
84947 }
84948 }
84949
84950-static long __init do_utime(char *filename, time_t mtime)
84951+static long __init do_utime(char __force_user *filename, time_t mtime)
84952 {
84953 struct timespec t[2];
84954
84955@@ -119,7 +119,7 @@ static void __init dir_utime(void)
84956 struct dir_entry *de, *tmp;
84957 list_for_each_entry_safe(de, tmp, &dir_list, list) {
84958 list_del(&de->list);
84959- do_utime(de->name, de->mtime);
84960+ do_utime((char __force_user *)de->name, de->mtime);
84961 kfree(de->name);
84962 kfree(de);
84963 }
84964@@ -281,7 +281,7 @@ static int __init maybe_link(void)
84965 if (nlink >= 2) {
84966 char *old = find_link(major, minor, ino, mode, collected);
84967 if (old)
84968- return (sys_link(old, collected) < 0) ? -1 : 1;
84969+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
84970 }
84971 return 0;
84972 }
84973@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
84974 {
84975 struct stat st;
84976
84977- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
84978+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
84979 if (S_ISDIR(st.st_mode))
84980- sys_rmdir(path);
84981+ sys_rmdir((char __force_user *)path);
84982 else
84983- sys_unlink(path);
84984+ sys_unlink((char __force_user *)path);
84985 }
84986 }
84987
84988@@ -315,7 +315,7 @@ static int __init do_name(void)
84989 int openflags = O_WRONLY|O_CREAT;
84990 if (ml != 1)
84991 openflags |= O_TRUNC;
84992- wfd = sys_open(collected, openflags, mode);
84993+ wfd = sys_open((char __force_user *)collected, openflags, mode);
84994
84995 if (wfd >= 0) {
84996 sys_fchown(wfd, uid, gid);
84997@@ -327,17 +327,17 @@ static int __init do_name(void)
84998 }
84999 }
85000 } else if (S_ISDIR(mode)) {
85001- sys_mkdir(collected, mode);
85002- sys_chown(collected, uid, gid);
85003- sys_chmod(collected, mode);
85004+ sys_mkdir((char __force_user *)collected, mode);
85005+ sys_chown((char __force_user *)collected, uid, gid);
85006+ sys_chmod((char __force_user *)collected, mode);
85007 dir_add(collected, mtime);
85008 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
85009 S_ISFIFO(mode) || S_ISSOCK(mode)) {
85010 if (maybe_link() == 0) {
85011- sys_mknod(collected, mode, rdev);
85012- sys_chown(collected, uid, gid);
85013- sys_chmod(collected, mode);
85014- do_utime(collected, mtime);
85015+ sys_mknod((char __force_user *)collected, mode, rdev);
85016+ sys_chown((char __force_user *)collected, uid, gid);
85017+ sys_chmod((char __force_user *)collected, mode);
85018+ do_utime((char __force_user *)collected, mtime);
85019 }
85020 }
85021 return 0;
85022@@ -346,15 +346,15 @@ static int __init do_name(void)
85023 static int __init do_copy(void)
85024 {
85025 if (count >= body_len) {
85026- sys_write(wfd, victim, body_len);
85027+ sys_write(wfd, (char __force_user *)victim, body_len);
85028 sys_close(wfd);
85029- do_utime(vcollected, mtime);
85030+ do_utime((char __force_user *)vcollected, mtime);
85031 kfree(vcollected);
85032 eat(body_len);
85033 state = SkipIt;
85034 return 0;
85035 } else {
85036- sys_write(wfd, victim, count);
85037+ sys_write(wfd, (char __force_user *)victim, count);
85038 body_len -= count;
85039 eat(count);
85040 return 1;
85041@@ -365,9 +365,9 @@ static int __init do_symlink(void)
85042 {
85043 collected[N_ALIGN(name_len) + body_len] = '\0';
85044 clean_path(collected, 0);
85045- sys_symlink(collected + N_ALIGN(name_len), collected);
85046- sys_lchown(collected, uid, gid);
85047- do_utime(collected, mtime);
85048+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
85049+ sys_lchown((char __force_user *)collected, uid, gid);
85050+ do_utime((char __force_user *)collected, mtime);
85051 state = SkipIt;
85052 next_state = Reset;
85053 return 0;
85054diff --git a/init/main.c b/init/main.c
85055index 9c7fd4c..650b4f1 100644
85056--- a/init/main.c
85057+++ b/init/main.c
85058@@ -97,6 +97,8 @@ extern void radix_tree_init(void);
85059 static inline void mark_rodata_ro(void) { }
85060 #endif
85061
85062+extern void grsecurity_init(void);
85063+
85064 /*
85065 * Debug helper: via this flag we know that we are in 'early bootup code'
85066 * where only the boot processor is running with IRQ disabled. This means
85067@@ -158,6 +160,75 @@ static int __init set_reset_devices(char *str)
85068
85069 __setup("reset_devices", set_reset_devices);
85070
85071+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
85072+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
85073+static int __init setup_grsec_proc_gid(char *str)
85074+{
85075+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
85076+ return 1;
85077+}
85078+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
85079+#endif
85080+
85081+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
85082+unsigned long pax_user_shadow_base __read_only;
85083+EXPORT_SYMBOL(pax_user_shadow_base);
85084+extern char pax_enter_kernel_user[];
85085+extern char pax_exit_kernel_user[];
85086+#endif
85087+
85088+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
85089+static int __init setup_pax_nouderef(char *str)
85090+{
85091+#ifdef CONFIG_X86_32
85092+ unsigned int cpu;
85093+ struct desc_struct *gdt;
85094+
85095+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
85096+ gdt = get_cpu_gdt_table(cpu);
85097+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
85098+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
85099+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
85100+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
85101+ }
85102+ loadsegment(ds, __KERNEL_DS);
85103+ loadsegment(es, __KERNEL_DS);
85104+ loadsegment(ss, __KERNEL_DS);
85105+#else
85106+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
85107+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
85108+ clone_pgd_mask = ~(pgdval_t)0UL;
85109+ pax_user_shadow_base = 0UL;
85110+ setup_clear_cpu_cap(X86_FEATURE_PCID);
85111+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
85112+#endif
85113+
85114+ return 0;
85115+}
85116+early_param("pax_nouderef", setup_pax_nouderef);
85117+
85118+#ifdef CONFIG_X86_64
85119+static int __init setup_pax_weakuderef(char *str)
85120+{
85121+ if (clone_pgd_mask != ~(pgdval_t)0UL)
85122+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
85123+ return 1;
85124+}
85125+__setup("pax_weakuderef", setup_pax_weakuderef);
85126+#endif
85127+#endif
85128+
85129+#ifdef CONFIG_PAX_SOFTMODE
85130+int pax_softmode;
85131+
85132+static int __init setup_pax_softmode(char *str)
85133+{
85134+ get_option(&str, &pax_softmode);
85135+ return 1;
85136+}
85137+__setup("pax_softmode=", setup_pax_softmode);
85138+#endif
85139+
85140 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
85141 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
85142 static const char *panic_later, *panic_param;
85143@@ -688,25 +759,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
85144 {
85145 int count = preempt_count();
85146 int ret;
85147- char msgbuf[64];
85148+ const char *msg1 = "", *msg2 = "";
85149
85150 if (initcall_debug)
85151 ret = do_one_initcall_debug(fn);
85152 else
85153 ret = fn();
85154
85155- msgbuf[0] = 0;
85156-
85157 if (preempt_count() != count) {
85158- sprintf(msgbuf, "preemption imbalance ");
85159+ msg1 = " preemption imbalance";
85160 preempt_count_set(count);
85161 }
85162 if (irqs_disabled()) {
85163- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
85164+ msg2 = " disabled interrupts";
85165 local_irq_enable();
85166 }
85167- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
85168+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
85169
85170+ add_latent_entropy();
85171 return ret;
85172 }
85173
85174@@ -813,8 +883,8 @@ static int run_init_process(const char *init_filename)
85175 {
85176 argv_init[0] = init_filename;
85177 return do_execve(getname_kernel(init_filename),
85178- (const char __user *const __user *)argv_init,
85179- (const char __user *const __user *)envp_init);
85180+ (const char __user *const __force_user *)argv_init,
85181+ (const char __user *const __force_user *)envp_init);
85182 }
85183
85184 static int try_to_run_init_process(const char *init_filename)
85185@@ -831,6 +901,10 @@ static int try_to_run_init_process(const char *init_filename)
85186 return ret;
85187 }
85188
85189+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
85190+extern int gr_init_ran;
85191+#endif
85192+
85193 static noinline void __init kernel_init_freeable(void);
85194
85195 static int __ref kernel_init(void *unused)
85196@@ -855,6 +929,11 @@ static int __ref kernel_init(void *unused)
85197 ramdisk_execute_command, ret);
85198 }
85199
85200+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
85201+ /* if no initrd was used, be extra sure we enforce chroot restrictions */
85202+ gr_init_ran = 1;
85203+#endif
85204+
85205 /*
85206 * We try each of these until one succeeds.
85207 *
85208@@ -910,7 +989,7 @@ static noinline void __init kernel_init_freeable(void)
85209 do_basic_setup();
85210
85211 /* Open the /dev/console on the rootfs, this should never fail */
85212- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
85213+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
85214 pr_err("Warning: unable to open an initial console.\n");
85215
85216 (void) sys_dup(0);
85217@@ -923,11 +1002,13 @@ static noinline void __init kernel_init_freeable(void)
85218 if (!ramdisk_execute_command)
85219 ramdisk_execute_command = "/init";
85220
85221- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
85222+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
85223 ramdisk_execute_command = NULL;
85224 prepare_namespace();
85225 }
85226
85227+ grsecurity_init();
85228+
85229 /*
85230 * Ok, we have completed the initial bootup, and
85231 * we're essentially up and running. Get rid of the
85232diff --git a/ipc/compat.c b/ipc/compat.c
85233index f486b00..442867f 100644
85234--- a/ipc/compat.c
85235+++ b/ipc/compat.c
85236@@ -399,7 +399,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
85237 COMPAT_SHMLBA);
85238 if (err < 0)
85239 return err;
85240- return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
85241+ return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
85242 }
85243 case SHMDT:
85244 return sys_shmdt(compat_ptr(ptr));
85245diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
85246index 1702864..797fa84 100644
85247--- a/ipc/ipc_sysctl.c
85248+++ b/ipc/ipc_sysctl.c
85249@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
85250 static int proc_ipc_dointvec(ctl_table *table, int write,
85251 void __user *buffer, size_t *lenp, loff_t *ppos)
85252 {
85253- struct ctl_table ipc_table;
85254+ ctl_table_no_const ipc_table;
85255
85256 memcpy(&ipc_table, table, sizeof(ipc_table));
85257 ipc_table.data = get_ipc(table);
85258@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
85259 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
85260 void __user *buffer, size_t *lenp, loff_t *ppos)
85261 {
85262- struct ctl_table ipc_table;
85263+ ctl_table_no_const ipc_table;
85264
85265 memcpy(&ipc_table, table, sizeof(ipc_table));
85266 ipc_table.data = get_ipc(table);
85267@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
85268 static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
85269 void __user *buffer, size_t *lenp, loff_t *ppos)
85270 {
85271- struct ctl_table ipc_table;
85272+ ctl_table_no_const ipc_table;
85273 size_t lenp_bef = *lenp;
85274 int rc;
85275
85276@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
85277 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
85278 void __user *buffer, size_t *lenp, loff_t *ppos)
85279 {
85280- struct ctl_table ipc_table;
85281+ ctl_table_no_const ipc_table;
85282 memcpy(&ipc_table, table, sizeof(ipc_table));
85283 ipc_table.data = get_ipc(table);
85284
85285@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
85286 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
85287 void __user *buffer, size_t *lenp, loff_t *ppos)
85288 {
85289- struct ctl_table ipc_table;
85290+ ctl_table_no_const ipc_table;
85291 size_t lenp_bef = *lenp;
85292 int oldval;
85293 int rc;
85294diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
85295index 5bb8bfe..a38ec05 100644
85296--- a/ipc/mq_sysctl.c
85297+++ b/ipc/mq_sysctl.c
85298@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
85299 static int proc_mq_dointvec(ctl_table *table, int write,
85300 void __user *buffer, size_t *lenp, loff_t *ppos)
85301 {
85302- struct ctl_table mq_table;
85303+ ctl_table_no_const mq_table;
85304 memcpy(&mq_table, table, sizeof(mq_table));
85305 mq_table.data = get_mq(table);
85306
85307@@ -35,7 +35,7 @@ static int proc_mq_dointvec(ctl_table *table, int write,
85308 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
85309 void __user *buffer, size_t *lenp, loff_t *ppos)
85310 {
85311- struct ctl_table mq_table;
85312+ ctl_table_no_const mq_table;
85313 memcpy(&mq_table, table, sizeof(mq_table));
85314 mq_table.data = get_mq(table);
85315
85316diff --git a/ipc/mqueue.c b/ipc/mqueue.c
85317index c3b3117..1efa933 100644
85318--- a/ipc/mqueue.c
85319+++ b/ipc/mqueue.c
85320@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
85321 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
85322 info->attr.mq_msgsize);
85323
85324+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
85325 spin_lock(&mq_lock);
85326 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
85327 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
85328diff --git a/ipc/msg.c b/ipc/msg.c
85329index 6498531..b0ff3c8 100644
85330--- a/ipc/msg.c
85331+++ b/ipc/msg.c
85332@@ -303,18 +303,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
85333 return security_msg_queue_associate(msq, msgflg);
85334 }
85335
85336+static struct ipc_ops msg_ops = {
85337+ .getnew = newque,
85338+ .associate = msg_security,
85339+ .more_checks = NULL
85340+};
85341+
85342 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
85343 {
85344 struct ipc_namespace *ns;
85345- struct ipc_ops msg_ops;
85346 struct ipc_params msg_params;
85347
85348 ns = current->nsproxy->ipc_ns;
85349
85350- msg_ops.getnew = newque;
85351- msg_ops.associate = msg_security;
85352- msg_ops.more_checks = NULL;
85353-
85354 msg_params.key = key;
85355 msg_params.flg = msgflg;
85356
85357diff --git a/ipc/sem.c b/ipc/sem.c
85358index bee5554..e9af81dd 100644
85359--- a/ipc/sem.c
85360+++ b/ipc/sem.c
85361@@ -561,10 +561,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
85362 return 0;
85363 }
85364
85365+static struct ipc_ops sem_ops = {
85366+ .getnew = newary,
85367+ .associate = sem_security,
85368+ .more_checks = sem_more_checks
85369+};
85370+
85371 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
85372 {
85373 struct ipc_namespace *ns;
85374- struct ipc_ops sem_ops;
85375 struct ipc_params sem_params;
85376
85377 ns = current->nsproxy->ipc_ns;
85378@@ -572,10 +577,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
85379 if (nsems < 0 || nsems > ns->sc_semmsl)
85380 return -EINVAL;
85381
85382- sem_ops.getnew = newary;
85383- sem_ops.associate = sem_security;
85384- sem_ops.more_checks = sem_more_checks;
85385-
85386 sem_params.key = key;
85387 sem_params.flg = semflg;
85388 sem_params.u.nsems = nsems;
85389diff --git a/ipc/shm.c b/ipc/shm.c
85390index 7645961..afc7f02 100644
85391--- a/ipc/shm.c
85392+++ b/ipc/shm.c
85393@@ -72,6 +72,14 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
85394 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
85395 #endif
85396
85397+#ifdef CONFIG_GRKERNSEC
85398+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
85399+ const time_t shm_createtime, const kuid_t cuid,
85400+ const int shmid);
85401+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
85402+ const time_t shm_createtime);
85403+#endif
85404+
85405 void shm_init_ns(struct ipc_namespace *ns)
85406 {
85407 ns->shm_ctlmax = SHMMAX;
85408@@ -553,6 +561,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
85409 shp->shm_lprid = 0;
85410 shp->shm_atim = shp->shm_dtim = 0;
85411 shp->shm_ctim = get_seconds();
85412+#ifdef CONFIG_GRKERNSEC
85413+ {
85414+ struct timespec timeval;
85415+ do_posix_clock_monotonic_gettime(&timeval);
85416+
85417+ shp->shm_createtime = timeval.tv_sec;
85418+ }
85419+#endif
85420 shp->shm_segsz = size;
85421 shp->shm_nattch = 0;
85422 shp->shm_file = file;
85423@@ -606,18 +622,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
85424 return 0;
85425 }
85426
85427+static struct ipc_ops shm_ops = {
85428+ .getnew = newseg,
85429+ .associate = shm_security,
85430+ .more_checks = shm_more_checks
85431+};
85432+
85433 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
85434 {
85435 struct ipc_namespace *ns;
85436- struct ipc_ops shm_ops;
85437 struct ipc_params shm_params;
85438
85439 ns = current->nsproxy->ipc_ns;
85440
85441- shm_ops.getnew = newseg;
85442- shm_ops.associate = shm_security;
85443- shm_ops.more_checks = shm_more_checks;
85444-
85445 shm_params.key = key;
85446 shm_params.flg = shmflg;
85447 shm_params.u.size = size;
85448@@ -1088,6 +1105,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85449 f_mode = FMODE_READ | FMODE_WRITE;
85450 }
85451 if (shmflg & SHM_EXEC) {
85452+
85453+#ifdef CONFIG_PAX_MPROTECT
85454+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
85455+ goto out;
85456+#endif
85457+
85458 prot |= PROT_EXEC;
85459 acc_mode |= S_IXUGO;
85460 }
85461@@ -1112,6 +1135,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85462 if (err)
85463 goto out_unlock;
85464
85465+#ifdef CONFIG_GRKERNSEC
85466+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
85467+ shp->shm_perm.cuid, shmid) ||
85468+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
85469+ err = -EACCES;
85470+ goto out_unlock;
85471+ }
85472+#endif
85473+
85474 ipc_lock_object(&shp->shm_perm);
85475
85476 /* check if shm_destroy() is tearing down shp */
85477@@ -1124,6 +1156,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85478 path = shp->shm_file->f_path;
85479 path_get(&path);
85480 shp->shm_nattch++;
85481+#ifdef CONFIG_GRKERNSEC
85482+ shp->shm_lapid = current->pid;
85483+#endif
85484 size = i_size_read(path.dentry->d_inode);
85485 ipc_unlock_object(&shp->shm_perm);
85486 rcu_read_unlock();
85487diff --git a/ipc/util.c b/ipc/util.c
85488index e1b4c6d..8174204 100644
85489--- a/ipc/util.c
85490+++ b/ipc/util.c
85491@@ -71,6 +71,8 @@ struct ipc_proc_iface {
85492 int (*show)(struct seq_file *, void *);
85493 };
85494
85495+extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
85496+
85497 static void ipc_memory_notifier(struct work_struct *work)
85498 {
85499 ipcns_notify(IPCNS_MEMCHANGED);
85500@@ -537,6 +539,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
85501 granted_mode >>= 6;
85502 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
85503 granted_mode >>= 3;
85504+
85505+ if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
85506+ return -1;
85507+
85508 /* is there some bit set in requested_mode but not in granted_mode? */
85509 if ((requested_mode & ~granted_mode & 0007) &&
85510 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
85511diff --git a/kernel/acct.c b/kernel/acct.c
85512index 8d6e145..33e0b1e 100644
85513--- a/kernel/acct.c
85514+++ b/kernel/acct.c
85515@@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
85516 */
85517 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
85518 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
85519- file->f_op->write(file, (char *)&ac,
85520+ file->f_op->write(file, (char __force_user *)&ac,
85521 sizeof(acct_t), &file->f_pos);
85522 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
85523 set_fs(fs);
85524diff --git a/kernel/audit.c b/kernel/audit.c
85525index 95a20f3..e1cb300 100644
85526--- a/kernel/audit.c
85527+++ b/kernel/audit.c
85528@@ -122,7 +122,7 @@ u32 audit_sig_sid = 0;
85529 3) suppressed due to audit_rate_limit
85530 4) suppressed due to audit_backlog_limit
85531 */
85532-static atomic_t audit_lost = ATOMIC_INIT(0);
85533+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
85534
85535 /* The netlink socket. */
85536 static struct sock *audit_sock;
85537@@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
85538 unsigned long now;
85539 int print;
85540
85541- atomic_inc(&audit_lost);
85542+ atomic_inc_unchecked(&audit_lost);
85543
85544 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
85545
85546@@ -273,7 +273,7 @@ void audit_log_lost(const char *message)
85547 if (print) {
85548 if (printk_ratelimit())
85549 pr_warn("audit_lost=%u audit_rate_limit=%u audit_backlog_limit=%u\n",
85550- atomic_read(&audit_lost),
85551+ atomic_read_unchecked(&audit_lost),
85552 audit_rate_limit,
85553 audit_backlog_limit);
85554 audit_panic(message);
85555@@ -803,7 +803,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
85556 s.pid = audit_pid;
85557 s.rate_limit = audit_rate_limit;
85558 s.backlog_limit = audit_backlog_limit;
85559- s.lost = atomic_read(&audit_lost);
85560+ s.lost = atomic_read_unchecked(&audit_lost);
85561 s.backlog = skb_queue_len(&audit_skb_queue);
85562 s.version = AUDIT_VERSION_LATEST;
85563 s.backlog_wait_time = audit_backlog_wait_time;
85564diff --git a/kernel/auditsc.c b/kernel/auditsc.c
85565index 7aef2f4..db6ced2 100644
85566--- a/kernel/auditsc.c
85567+++ b/kernel/auditsc.c
85568@@ -1945,7 +1945,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
85569 }
85570
85571 /* global counter which is incremented every time something logs in */
85572-static atomic_t session_id = ATOMIC_INIT(0);
85573+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
85574
85575 static int audit_set_loginuid_perm(kuid_t loginuid)
85576 {
85577@@ -2014,7 +2014,7 @@ int audit_set_loginuid(kuid_t loginuid)
85578
85579 /* are we setting or clearing? */
85580 if (uid_valid(loginuid))
85581- sessionid = (unsigned int)atomic_inc_return(&session_id);
85582+ sessionid = (unsigned int)atomic_inc_return_unchecked(&session_id);
85583
85584 task->sessionid = sessionid;
85585 task->loginuid = loginuid;
85586diff --git a/kernel/capability.c b/kernel/capability.c
85587index 34019c5..363f279 100644
85588--- a/kernel/capability.c
85589+++ b/kernel/capability.c
85590@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
85591 * before modification is attempted and the application
85592 * fails.
85593 */
85594+ if (tocopy > ARRAY_SIZE(kdata))
85595+ return -EFAULT;
85596+
85597 if (copy_to_user(dataptr, kdata, tocopy
85598 * sizeof(struct __user_cap_data_struct))) {
85599 return -EFAULT;
85600@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
85601 int ret;
85602
85603 rcu_read_lock();
85604- ret = security_capable(__task_cred(t), ns, cap);
85605+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
85606+ gr_task_is_capable(t, __task_cred(t), cap);
85607 rcu_read_unlock();
85608
85609- return (ret == 0);
85610+ return ret;
85611 }
85612
85613 /**
85614@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
85615 int ret;
85616
85617 rcu_read_lock();
85618- ret = security_capable_noaudit(__task_cred(t), ns, cap);
85619+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
85620 rcu_read_unlock();
85621
85622- return (ret == 0);
85623+ return ret;
85624 }
85625
85626 /**
85627@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
85628 BUG();
85629 }
85630
85631- if (security_capable(current_cred(), ns, cap) == 0) {
85632+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
85633 current->flags |= PF_SUPERPRIV;
85634 return true;
85635 }
85636@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
85637 }
85638 EXPORT_SYMBOL(ns_capable);
85639
85640+bool ns_capable_nolog(struct user_namespace *ns, int cap)
85641+{
85642+ if (unlikely(!cap_valid(cap))) {
85643+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
85644+ BUG();
85645+ }
85646+
85647+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
85648+ current->flags |= PF_SUPERPRIV;
85649+ return true;
85650+ }
85651+ return false;
85652+}
85653+EXPORT_SYMBOL(ns_capable_nolog);
85654+
85655 /**
85656 * file_ns_capable - Determine if the file's opener had a capability in effect
85657 * @file: The file we want to check
85658@@ -432,6 +451,12 @@ bool capable(int cap)
85659 }
85660 EXPORT_SYMBOL(capable);
85661
85662+bool capable_nolog(int cap)
85663+{
85664+ return ns_capable_nolog(&init_user_ns, cap);
85665+}
85666+EXPORT_SYMBOL(capable_nolog);
85667+
85668 /**
85669 * inode_capable - Check superior capability over inode
85670 * @inode: The inode in question
85671@@ -453,3 +478,11 @@ bool inode_capable(const struct inode *inode, int cap)
85672 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
85673 }
85674 EXPORT_SYMBOL(inode_capable);
85675+
85676+bool inode_capable_nolog(const struct inode *inode, int cap)
85677+{
85678+ struct user_namespace *ns = current_user_ns();
85679+
85680+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
85681+}
85682+EXPORT_SYMBOL(inode_capable_nolog);
85683diff --git a/kernel/cgroup.c b/kernel/cgroup.c
85684index 0c753dd..dd7d3d6 100644
85685--- a/kernel/cgroup.c
85686+++ b/kernel/cgroup.c
85687@@ -5372,7 +5372,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)
85688 struct css_set *cset = link->cset;
85689 struct task_struct *task;
85690 int count = 0;
85691- seq_printf(seq, "css_set %p\n", cset);
85692+ seq_printf(seq, "css_set %pK\n", cset);
85693 list_for_each_entry(task, &cset->tasks, cg_list) {
85694 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
85695 seq_puts(seq, " ...\n");
85696diff --git a/kernel/compat.c b/kernel/compat.c
85697index 0a09e48..b46b3d78 100644
85698--- a/kernel/compat.c
85699+++ b/kernel/compat.c
85700@@ -13,6 +13,7 @@
85701
85702 #include <linux/linkage.h>
85703 #include <linux/compat.h>
85704+#include <linux/module.h>
85705 #include <linux/errno.h>
85706 #include <linux/time.h>
85707 #include <linux/signal.h>
85708@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
85709 mm_segment_t oldfs;
85710 long ret;
85711
85712- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
85713+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
85714 oldfs = get_fs();
85715 set_fs(KERNEL_DS);
85716 ret = hrtimer_nanosleep_restart(restart);
85717@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
85718 oldfs = get_fs();
85719 set_fs(KERNEL_DS);
85720 ret = hrtimer_nanosleep(&tu,
85721- rmtp ? (struct timespec __user *)&rmt : NULL,
85722+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
85723 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
85724 set_fs(oldfs);
85725
85726@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
85727 mm_segment_t old_fs = get_fs();
85728
85729 set_fs(KERNEL_DS);
85730- ret = sys_sigpending((old_sigset_t __user *) &s);
85731+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
85732 set_fs(old_fs);
85733 if (ret == 0)
85734 ret = put_user(s, set);
85735@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
85736 mm_segment_t old_fs = get_fs();
85737
85738 set_fs(KERNEL_DS);
85739- ret = sys_old_getrlimit(resource, &r);
85740+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
85741 set_fs(old_fs);
85742
85743 if (!ret) {
85744@@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
85745 set_fs (KERNEL_DS);
85746 ret = sys_wait4(pid,
85747 (stat_addr ?
85748- (unsigned int __user *) &status : NULL),
85749- options, (struct rusage __user *) &r);
85750+ (unsigned int __force_user *) &status : NULL),
85751+ options, (struct rusage __force_user *) &r);
85752 set_fs (old_fs);
85753
85754 if (ret > 0) {
85755@@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
85756 memset(&info, 0, sizeof(info));
85757
85758 set_fs(KERNEL_DS);
85759- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
85760- uru ? (struct rusage __user *)&ru : NULL);
85761+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
85762+ uru ? (struct rusage __force_user *)&ru : NULL);
85763 set_fs(old_fs);
85764
85765 if ((ret < 0) || (info.si_signo == 0))
85766@@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
85767 oldfs = get_fs();
85768 set_fs(KERNEL_DS);
85769 err = sys_timer_settime(timer_id, flags,
85770- (struct itimerspec __user *) &newts,
85771- (struct itimerspec __user *) &oldts);
85772+ (struct itimerspec __force_user *) &newts,
85773+ (struct itimerspec __force_user *) &oldts);
85774 set_fs(oldfs);
85775 if (!err && old && put_compat_itimerspec(old, &oldts))
85776 return -EFAULT;
85777@@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
85778 oldfs = get_fs();
85779 set_fs(KERNEL_DS);
85780 err = sys_timer_gettime(timer_id,
85781- (struct itimerspec __user *) &ts);
85782+ (struct itimerspec __force_user *) &ts);
85783 set_fs(oldfs);
85784 if (!err && put_compat_itimerspec(setting, &ts))
85785 return -EFAULT;
85786@@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
85787 oldfs = get_fs();
85788 set_fs(KERNEL_DS);
85789 err = sys_clock_settime(which_clock,
85790- (struct timespec __user *) &ts);
85791+ (struct timespec __force_user *) &ts);
85792 set_fs(oldfs);
85793 return err;
85794 }
85795@@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
85796 oldfs = get_fs();
85797 set_fs(KERNEL_DS);
85798 err = sys_clock_gettime(which_clock,
85799- (struct timespec __user *) &ts);
85800+ (struct timespec __force_user *) &ts);
85801 set_fs(oldfs);
85802 if (!err && put_compat_timespec(&ts, tp))
85803 return -EFAULT;
85804@@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
85805
85806 oldfs = get_fs();
85807 set_fs(KERNEL_DS);
85808- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
85809+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
85810 set_fs(oldfs);
85811
85812 err = compat_put_timex(utp, &txc);
85813@@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
85814 oldfs = get_fs();
85815 set_fs(KERNEL_DS);
85816 err = sys_clock_getres(which_clock,
85817- (struct timespec __user *) &ts);
85818+ (struct timespec __force_user *) &ts);
85819 set_fs(oldfs);
85820 if (!err && tp && put_compat_timespec(&ts, tp))
85821 return -EFAULT;
85822@@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
85823 long err;
85824 mm_segment_t oldfs;
85825 struct timespec tu;
85826- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
85827+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
85828
85829- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
85830+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
85831 oldfs = get_fs();
85832 set_fs(KERNEL_DS);
85833 err = clock_nanosleep_restart(restart);
85834@@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
85835 oldfs = get_fs();
85836 set_fs(KERNEL_DS);
85837 err = sys_clock_nanosleep(which_clock, flags,
85838- (struct timespec __user *) &in,
85839- (struct timespec __user *) &out);
85840+ (struct timespec __force_user *) &in,
85841+ (struct timespec __force_user *) &out);
85842 set_fs(oldfs);
85843
85844 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
85845@@ -1128,7 +1129,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
85846 mm_segment_t old_fs = get_fs();
85847
85848 set_fs(KERNEL_DS);
85849- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
85850+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
85851 set_fs(old_fs);
85852 if (put_compat_timespec(&t, interval))
85853 return -EFAULT;
85854diff --git a/kernel/configs.c b/kernel/configs.c
85855index c18b1f1..b9a0132 100644
85856--- a/kernel/configs.c
85857+++ b/kernel/configs.c
85858@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
85859 struct proc_dir_entry *entry;
85860
85861 /* create the current config file */
85862+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
85863+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
85864+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
85865+ &ikconfig_file_ops);
85866+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
85867+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
85868+ &ikconfig_file_ops);
85869+#endif
85870+#else
85871 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
85872 &ikconfig_file_ops);
85873+#endif
85874+
85875 if (!entry)
85876 return -ENOMEM;
85877
85878diff --git a/kernel/cred.c b/kernel/cred.c
85879index e0573a4..3874e41 100644
85880--- a/kernel/cred.c
85881+++ b/kernel/cred.c
85882@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
85883 validate_creds(cred);
85884 alter_cred_subscribers(cred, -1);
85885 put_cred(cred);
85886+
85887+#ifdef CONFIG_GRKERNSEC_SETXID
85888+ cred = (struct cred *) tsk->delayed_cred;
85889+ if (cred != NULL) {
85890+ tsk->delayed_cred = NULL;
85891+ validate_creds(cred);
85892+ alter_cred_subscribers(cred, -1);
85893+ put_cred(cred);
85894+ }
85895+#endif
85896 }
85897
85898 /**
85899@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
85900 * Always returns 0 thus allowing this function to be tail-called at the end
85901 * of, say, sys_setgid().
85902 */
85903-int commit_creds(struct cred *new)
85904+static int __commit_creds(struct cred *new)
85905 {
85906 struct task_struct *task = current;
85907 const struct cred *old = task->real_cred;
85908@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
85909
85910 get_cred(new); /* we will require a ref for the subj creds too */
85911
85912+ gr_set_role_label(task, new->uid, new->gid);
85913+
85914 /* dumpability changes */
85915 if (!uid_eq(old->euid, new->euid) ||
85916 !gid_eq(old->egid, new->egid) ||
85917@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
85918 put_cred(old);
85919 return 0;
85920 }
85921+#ifdef CONFIG_GRKERNSEC_SETXID
85922+extern int set_user(struct cred *new);
85923+
85924+void gr_delayed_cred_worker(void)
85925+{
85926+ const struct cred *new = current->delayed_cred;
85927+ struct cred *ncred;
85928+
85929+ current->delayed_cred = NULL;
85930+
85931+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
85932+ // from doing get_cred on it when queueing this
85933+ put_cred(new);
85934+ return;
85935+ } else if (new == NULL)
85936+ return;
85937+
85938+ ncred = prepare_creds();
85939+ if (!ncred)
85940+ goto die;
85941+ // uids
85942+ ncred->uid = new->uid;
85943+ ncred->euid = new->euid;
85944+ ncred->suid = new->suid;
85945+ ncred->fsuid = new->fsuid;
85946+ // gids
85947+ ncred->gid = new->gid;
85948+ ncred->egid = new->egid;
85949+ ncred->sgid = new->sgid;
85950+ ncred->fsgid = new->fsgid;
85951+ // groups
85952+ if (set_groups(ncred, new->group_info) < 0) {
85953+ abort_creds(ncred);
85954+ goto die;
85955+ }
85956+ // caps
85957+ ncred->securebits = new->securebits;
85958+ ncred->cap_inheritable = new->cap_inheritable;
85959+ ncred->cap_permitted = new->cap_permitted;
85960+ ncred->cap_effective = new->cap_effective;
85961+ ncred->cap_bset = new->cap_bset;
85962+
85963+ if (set_user(ncred)) {
85964+ abort_creds(ncred);
85965+ goto die;
85966+ }
85967+
85968+ // from doing get_cred on it when queueing this
85969+ put_cred(new);
85970+
85971+ __commit_creds(ncred);
85972+ return;
85973+die:
85974+ // from doing get_cred on it when queueing this
85975+ put_cred(new);
85976+ do_group_exit(SIGKILL);
85977+}
85978+#endif
85979+
85980+int commit_creds(struct cred *new)
85981+{
85982+#ifdef CONFIG_GRKERNSEC_SETXID
85983+ int ret;
85984+ int schedule_it = 0;
85985+ struct task_struct *t;
85986+
85987+ /* we won't get called with tasklist_lock held for writing
85988+ and interrupts disabled as the cred struct in that case is
85989+ init_cred
85990+ */
85991+ if (grsec_enable_setxid && !current_is_single_threaded() &&
85992+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
85993+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
85994+ schedule_it = 1;
85995+ }
85996+ ret = __commit_creds(new);
85997+ if (schedule_it) {
85998+ rcu_read_lock();
85999+ read_lock(&tasklist_lock);
86000+ for (t = next_thread(current); t != current;
86001+ t = next_thread(t)) {
86002+ if (t->delayed_cred == NULL) {
86003+ t->delayed_cred = get_cred(new);
86004+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
86005+ set_tsk_need_resched(t);
86006+ }
86007+ }
86008+ read_unlock(&tasklist_lock);
86009+ rcu_read_unlock();
86010+ }
86011+ return ret;
86012+#else
86013+ return __commit_creds(new);
86014+#endif
86015+}
86016+
86017 EXPORT_SYMBOL(commit_creds);
86018
86019 /**
86020diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
86021index 334b398..9145fb1 100644
86022--- a/kernel/debug/debug_core.c
86023+++ b/kernel/debug/debug_core.c
86024@@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
86025 */
86026 static atomic_t masters_in_kgdb;
86027 static atomic_t slaves_in_kgdb;
86028-static atomic_t kgdb_break_tasklet_var;
86029+static atomic_unchecked_t kgdb_break_tasklet_var;
86030 atomic_t kgdb_setting_breakpoint;
86031
86032 struct task_struct *kgdb_usethread;
86033@@ -133,7 +133,7 @@ int kgdb_single_step;
86034 static pid_t kgdb_sstep_pid;
86035
86036 /* to keep track of the CPU which is doing the single stepping*/
86037-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
86038+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
86039
86040 /*
86041 * If you are debugging a problem where roundup (the collection of
86042@@ -541,7 +541,7 @@ return_normal:
86043 * kernel will only try for the value of sstep_tries before
86044 * giving up and continuing on.
86045 */
86046- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
86047+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
86048 (kgdb_info[cpu].task &&
86049 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
86050 atomic_set(&kgdb_active, -1);
86051@@ -639,8 +639,8 @@ cpu_master_loop:
86052 }
86053
86054 kgdb_restore:
86055- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
86056- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
86057+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
86058+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
86059 if (kgdb_info[sstep_cpu].task)
86060 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
86061 else
86062@@ -917,18 +917,18 @@ static void kgdb_unregister_callbacks(void)
86063 static void kgdb_tasklet_bpt(unsigned long ing)
86064 {
86065 kgdb_breakpoint();
86066- atomic_set(&kgdb_break_tasklet_var, 0);
86067+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
86068 }
86069
86070 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
86071
86072 void kgdb_schedule_breakpoint(void)
86073 {
86074- if (atomic_read(&kgdb_break_tasklet_var) ||
86075+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
86076 atomic_read(&kgdb_active) != -1 ||
86077 atomic_read(&kgdb_setting_breakpoint))
86078 return;
86079- atomic_inc(&kgdb_break_tasklet_var);
86080+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
86081 tasklet_schedule(&kgdb_tasklet_breakpoint);
86082 }
86083 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
86084diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
86085index 0b097c8..11dd5c5 100644
86086--- a/kernel/debug/kdb/kdb_main.c
86087+++ b/kernel/debug/kdb/kdb_main.c
86088@@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
86089 continue;
86090
86091 kdb_printf("%-20s%8u 0x%p ", mod->name,
86092- mod->core_size, (void *)mod);
86093+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
86094 #ifdef CONFIG_MODULE_UNLOAD
86095 kdb_printf("%4ld ", module_refcount(mod));
86096 #endif
86097@@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
86098 kdb_printf(" (Loading)");
86099 else
86100 kdb_printf(" (Live)");
86101- kdb_printf(" 0x%p", mod->module_core);
86102+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
86103
86104 #ifdef CONFIG_MODULE_UNLOAD
86105 {
86106diff --git a/kernel/events/core.c b/kernel/events/core.c
86107index fa0b2d4..67a1c7a 100644
86108--- a/kernel/events/core.c
86109+++ b/kernel/events/core.c
86110@@ -158,8 +158,15 @@ static struct srcu_struct pmus_srcu;
86111 * 0 - disallow raw tracepoint access for unpriv
86112 * 1 - disallow cpu events for unpriv
86113 * 2 - disallow kernel profiling for unpriv
86114+ * 3 - disallow all unpriv perf event use
86115 */
86116-int sysctl_perf_event_paranoid __read_mostly = 1;
86117+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
86118+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
86119+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
86120+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
86121+#else
86122+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
86123+#endif
86124
86125 /* Minimum for 512 kiB + 1 user control page */
86126 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
86127@@ -185,7 +192,7 @@ void update_perf_cpu_limits(void)
86128
86129 tmp *= sysctl_perf_cpu_time_max_percent;
86130 do_div(tmp, 100);
86131- ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
86132+ ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
86133 }
86134
86135 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
86136@@ -272,7 +279,7 @@ void perf_sample_event_took(u64 sample_len_ns)
86137 update_perf_cpu_limits();
86138 }
86139
86140-static atomic64_t perf_event_id;
86141+static atomic64_unchecked_t perf_event_id;
86142
86143 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
86144 enum event_type_t event_type);
86145@@ -2986,7 +2993,7 @@ static void __perf_event_read(void *info)
86146
86147 static inline u64 perf_event_count(struct perf_event *event)
86148 {
86149- return local64_read(&event->count) + atomic64_read(&event->child_count);
86150+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
86151 }
86152
86153 static u64 perf_event_read(struct perf_event *event)
86154@@ -3354,9 +3361,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
86155 mutex_lock(&event->child_mutex);
86156 total += perf_event_read(event);
86157 *enabled += event->total_time_enabled +
86158- atomic64_read(&event->child_total_time_enabled);
86159+ atomic64_read_unchecked(&event->child_total_time_enabled);
86160 *running += event->total_time_running +
86161- atomic64_read(&event->child_total_time_running);
86162+ atomic64_read_unchecked(&event->child_total_time_running);
86163
86164 list_for_each_entry(child, &event->child_list, child_list) {
86165 total += perf_event_read(child);
86166@@ -3785,10 +3792,10 @@ void perf_event_update_userpage(struct perf_event *event)
86167 userpg->offset -= local64_read(&event->hw.prev_count);
86168
86169 userpg->time_enabled = enabled +
86170- atomic64_read(&event->child_total_time_enabled);
86171+ atomic64_read_unchecked(&event->child_total_time_enabled);
86172
86173 userpg->time_running = running +
86174- atomic64_read(&event->child_total_time_running);
86175+ atomic64_read_unchecked(&event->child_total_time_running);
86176
86177 arch_perf_update_userpage(userpg, now);
86178
86179@@ -4339,7 +4346,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
86180
86181 /* Data. */
86182 sp = perf_user_stack_pointer(regs);
86183- rem = __output_copy_user(handle, (void *) sp, dump_size);
86184+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
86185 dyn_size = dump_size - rem;
86186
86187 perf_output_skip(handle, rem);
86188@@ -4430,11 +4437,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
86189 values[n++] = perf_event_count(event);
86190 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
86191 values[n++] = enabled +
86192- atomic64_read(&event->child_total_time_enabled);
86193+ atomic64_read_unchecked(&event->child_total_time_enabled);
86194 }
86195 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
86196 values[n++] = running +
86197- atomic64_read(&event->child_total_time_running);
86198+ atomic64_read_unchecked(&event->child_total_time_running);
86199 }
86200 if (read_format & PERF_FORMAT_ID)
86201 values[n++] = primary_event_id(event);
86202@@ -6704,7 +6711,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
86203 event->parent = parent_event;
86204
86205 event->ns = get_pid_ns(task_active_pid_ns(current));
86206- event->id = atomic64_inc_return(&perf_event_id);
86207+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
86208
86209 event->state = PERF_EVENT_STATE_INACTIVE;
86210
86211@@ -7004,6 +7011,11 @@ SYSCALL_DEFINE5(perf_event_open,
86212 if (flags & ~PERF_FLAG_ALL)
86213 return -EINVAL;
86214
86215+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
86216+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
86217+ return -EACCES;
86218+#endif
86219+
86220 err = perf_copy_attr(attr_uptr, &attr);
86221 if (err)
86222 return err;
86223@@ -7339,10 +7351,10 @@ static void sync_child_event(struct perf_event *child_event,
86224 /*
86225 * Add back the child's count to the parent's count:
86226 */
86227- atomic64_add(child_val, &parent_event->child_count);
86228- atomic64_add(child_event->total_time_enabled,
86229+ atomic64_add_unchecked(child_val, &parent_event->child_count);
86230+ atomic64_add_unchecked(child_event->total_time_enabled,
86231 &parent_event->child_total_time_enabled);
86232- atomic64_add(child_event->total_time_running,
86233+ atomic64_add_unchecked(child_event->total_time_running,
86234 &parent_event->child_total_time_running);
86235
86236 /*
86237diff --git a/kernel/events/internal.h b/kernel/events/internal.h
86238index 569b2187..19940d9 100644
86239--- a/kernel/events/internal.h
86240+++ b/kernel/events/internal.h
86241@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
86242 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
86243 }
86244
86245-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
86246+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
86247 static inline unsigned long \
86248 func_name(struct perf_output_handle *handle, \
86249- const void *buf, unsigned long len) \
86250+ const void user *buf, unsigned long len) \
86251 { \
86252 unsigned long size, written; \
86253 \
86254@@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
86255 return 0;
86256 }
86257
86258-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
86259+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
86260
86261 static inline unsigned long
86262 memcpy_skip(void *dst, const void *src, unsigned long n)
86263@@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
86264 return 0;
86265 }
86266
86267-DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
86268+DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
86269
86270 #ifndef arch_perf_out_copy_user
86271 #define arch_perf_out_copy_user arch_perf_out_copy_user
86272@@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
86273 }
86274 #endif
86275
86276-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
86277+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
86278
86279 /* Callchain handling */
86280 extern struct perf_callchain_entry *
86281diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
86282index 307d87c..6466cbe 100644
86283--- a/kernel/events/uprobes.c
86284+++ b/kernel/events/uprobes.c
86285@@ -1666,7 +1666,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
86286 {
86287 struct page *page;
86288 uprobe_opcode_t opcode;
86289- int result;
86290+ long result;
86291
86292 pagefault_disable();
86293 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
86294diff --git a/kernel/exit.c b/kernel/exit.c
86295index 81b3d67..ef189a4 100644
86296--- a/kernel/exit.c
86297+++ b/kernel/exit.c
86298@@ -173,6 +173,10 @@ void release_task(struct task_struct * p)
86299 struct task_struct *leader;
86300 int zap_leader;
86301 repeat:
86302+#ifdef CONFIG_NET
86303+ gr_del_task_from_ip_table(p);
86304+#endif
86305+
86306 /* don't need to get the RCU readlock here - the process is dead and
86307 * can't be modifying its own credentials. But shut RCU-lockdep up */
86308 rcu_read_lock();
86309@@ -330,7 +334,7 @@ int allow_signal(int sig)
86310 * know it'll be handled, so that they don't get converted to
86311 * SIGKILL or just silently dropped.
86312 */
86313- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
86314+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
86315 recalc_sigpending();
86316 spin_unlock_irq(&current->sighand->siglock);
86317 return 0;
86318@@ -706,6 +710,8 @@ void do_exit(long code)
86319 struct task_struct *tsk = current;
86320 int group_dead;
86321
86322+ set_fs(USER_DS);
86323+
86324 profile_task_exit(tsk);
86325
86326 WARN_ON(blk_needs_flush_plug(tsk));
86327@@ -722,7 +728,6 @@ void do_exit(long code)
86328 * mm_release()->clear_child_tid() from writing to a user-controlled
86329 * kernel address.
86330 */
86331- set_fs(USER_DS);
86332
86333 ptrace_event(PTRACE_EVENT_EXIT, code);
86334
86335@@ -781,6 +786,9 @@ void do_exit(long code)
86336 tsk->exit_code = code;
86337 taskstats_exit(tsk, group_dead);
86338
86339+ gr_acl_handle_psacct(tsk, code);
86340+ gr_acl_handle_exit();
86341+
86342 exit_mm(tsk);
86343
86344 if (group_dead)
86345@@ -900,7 +908,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
86346 * Take down every thread in the group. This is called by fatal signals
86347 * as well as by sys_exit_group (below).
86348 */
86349-void
86350+__noreturn void
86351 do_group_exit(int exit_code)
86352 {
86353 struct signal_struct *sig = current->signal;
86354diff --git a/kernel/fork.c b/kernel/fork.c
86355index a17621c..b77fef8 100644
86356--- a/kernel/fork.c
86357+++ b/kernel/fork.c
86358@@ -319,7 +319,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86359 *stackend = STACK_END_MAGIC; /* for overflow detection */
86360
86361 #ifdef CONFIG_CC_STACKPROTECTOR
86362- tsk->stack_canary = get_random_int();
86363+ tsk->stack_canary = pax_get_random_long();
86364 #endif
86365
86366 /*
86367@@ -345,12 +345,80 @@ free_tsk:
86368 }
86369
86370 #ifdef CONFIG_MMU
86371-static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86372+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
86373+{
86374+ struct vm_area_struct *tmp;
86375+ unsigned long charge;
86376+ struct file *file;
86377+ int retval;
86378+
86379+ charge = 0;
86380+ if (mpnt->vm_flags & VM_ACCOUNT) {
86381+ unsigned long len = vma_pages(mpnt);
86382+
86383+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
86384+ goto fail_nomem;
86385+ charge = len;
86386+ }
86387+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
86388+ if (!tmp)
86389+ goto fail_nomem;
86390+ *tmp = *mpnt;
86391+ tmp->vm_mm = mm;
86392+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
86393+ retval = vma_dup_policy(mpnt, tmp);
86394+ if (retval)
86395+ goto fail_nomem_policy;
86396+ if (anon_vma_fork(tmp, mpnt))
86397+ goto fail_nomem_anon_vma_fork;
86398+ tmp->vm_flags &= ~VM_LOCKED;
86399+ tmp->vm_next = tmp->vm_prev = NULL;
86400+ tmp->vm_mirror = NULL;
86401+ file = tmp->vm_file;
86402+ if (file) {
86403+ struct inode *inode = file_inode(file);
86404+ struct address_space *mapping = file->f_mapping;
86405+
86406+ get_file(file);
86407+ if (tmp->vm_flags & VM_DENYWRITE)
86408+ atomic_dec(&inode->i_writecount);
86409+ mutex_lock(&mapping->i_mmap_mutex);
86410+ if (tmp->vm_flags & VM_SHARED)
86411+ mapping->i_mmap_writable++;
86412+ flush_dcache_mmap_lock(mapping);
86413+ /* insert tmp into the share list, just after mpnt */
86414+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
86415+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
86416+ else
86417+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
86418+ flush_dcache_mmap_unlock(mapping);
86419+ mutex_unlock(&mapping->i_mmap_mutex);
86420+ }
86421+
86422+ /*
86423+ * Clear hugetlb-related page reserves for children. This only
86424+ * affects MAP_PRIVATE mappings. Faults generated by the child
86425+ * are not guaranteed to succeed, even if read-only
86426+ */
86427+ if (is_vm_hugetlb_page(tmp))
86428+ reset_vma_resv_huge_pages(tmp);
86429+
86430+ return tmp;
86431+
86432+fail_nomem_anon_vma_fork:
86433+ mpol_put(vma_policy(tmp));
86434+fail_nomem_policy:
86435+ kmem_cache_free(vm_area_cachep, tmp);
86436+fail_nomem:
86437+ vm_unacct_memory(charge);
86438+ return NULL;
86439+}
86440+
86441+static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86442 {
86443 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
86444 struct rb_node **rb_link, *rb_parent;
86445 int retval;
86446- unsigned long charge;
86447
86448 uprobe_start_dup_mmap();
86449 down_write(&oldmm->mmap_sem);
86450@@ -379,55 +447,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86451
86452 prev = NULL;
86453 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
86454- struct file *file;
86455-
86456 if (mpnt->vm_flags & VM_DONTCOPY) {
86457 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
86458 -vma_pages(mpnt));
86459 continue;
86460 }
86461- charge = 0;
86462- if (mpnt->vm_flags & VM_ACCOUNT) {
86463- unsigned long len = vma_pages(mpnt);
86464-
86465- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
86466- goto fail_nomem;
86467- charge = len;
86468- }
86469- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
86470- if (!tmp)
86471- goto fail_nomem;
86472- *tmp = *mpnt;
86473- INIT_LIST_HEAD(&tmp->anon_vma_chain);
86474- retval = vma_dup_policy(mpnt, tmp);
86475- if (retval)
86476- goto fail_nomem_policy;
86477- tmp->vm_mm = mm;
86478- if (anon_vma_fork(tmp, mpnt))
86479- goto fail_nomem_anon_vma_fork;
86480- tmp->vm_flags &= ~VM_LOCKED;
86481- tmp->vm_next = tmp->vm_prev = NULL;
86482- file = tmp->vm_file;
86483- if (file) {
86484- struct inode *inode = file_inode(file);
86485- struct address_space *mapping = file->f_mapping;
86486-
86487- get_file(file);
86488- if (tmp->vm_flags & VM_DENYWRITE)
86489- atomic_dec(&inode->i_writecount);
86490- mutex_lock(&mapping->i_mmap_mutex);
86491- if (tmp->vm_flags & VM_SHARED)
86492- mapping->i_mmap_writable++;
86493- flush_dcache_mmap_lock(mapping);
86494- /* insert tmp into the share list, just after mpnt */
86495- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
86496- vma_nonlinear_insert(tmp,
86497- &mapping->i_mmap_nonlinear);
86498- else
86499- vma_interval_tree_insert_after(tmp, mpnt,
86500- &mapping->i_mmap);
86501- flush_dcache_mmap_unlock(mapping);
86502- mutex_unlock(&mapping->i_mmap_mutex);
86503+ tmp = dup_vma(mm, oldmm, mpnt);
86504+ if (!tmp) {
86505+ retval = -ENOMEM;
86506+ goto out;
86507 }
86508
86509 /*
86510@@ -459,6 +487,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86511 if (retval)
86512 goto out;
86513 }
86514+
86515+#ifdef CONFIG_PAX_SEGMEXEC
86516+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
86517+ struct vm_area_struct *mpnt_m;
86518+
86519+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
86520+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
86521+
86522+ if (!mpnt->vm_mirror)
86523+ continue;
86524+
86525+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
86526+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
86527+ mpnt->vm_mirror = mpnt_m;
86528+ } else {
86529+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
86530+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
86531+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
86532+ mpnt->vm_mirror->vm_mirror = mpnt;
86533+ }
86534+ }
86535+ BUG_ON(mpnt_m);
86536+ }
86537+#endif
86538+
86539 /* a new mm has just been created */
86540 arch_dup_mmap(oldmm, mm);
86541 retval = 0;
86542@@ -468,14 +521,6 @@ out:
86543 up_write(&oldmm->mmap_sem);
86544 uprobe_end_dup_mmap();
86545 return retval;
86546-fail_nomem_anon_vma_fork:
86547- mpol_put(vma_policy(tmp));
86548-fail_nomem_policy:
86549- kmem_cache_free(vm_area_cachep, tmp);
86550-fail_nomem:
86551- retval = -ENOMEM;
86552- vm_unacct_memory(charge);
86553- goto out;
86554 }
86555
86556 static inline int mm_alloc_pgd(struct mm_struct *mm)
86557@@ -689,8 +734,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
86558 return ERR_PTR(err);
86559
86560 mm = get_task_mm(task);
86561- if (mm && mm != current->mm &&
86562- !ptrace_may_access(task, mode)) {
86563+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
86564+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
86565 mmput(mm);
86566 mm = ERR_PTR(-EACCES);
86567 }
86568@@ -906,13 +951,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
86569 spin_unlock(&fs->lock);
86570 return -EAGAIN;
86571 }
86572- fs->users++;
86573+ atomic_inc(&fs->users);
86574 spin_unlock(&fs->lock);
86575 return 0;
86576 }
86577 tsk->fs = copy_fs_struct(fs);
86578 if (!tsk->fs)
86579 return -ENOMEM;
86580+ /* Carry through gr_chroot_dentry and is_chrooted instead
86581+ of recomputing it here. Already copied when the task struct
86582+ is duplicated. This allows pivot_root to not be treated as
86583+ a chroot
86584+ */
86585+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
86586+
86587 return 0;
86588 }
86589
86590@@ -1130,7 +1182,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
86591 * parts of the process environment (as per the clone
86592 * flags). The actual kick-off is left to the caller.
86593 */
86594-static struct task_struct *copy_process(unsigned long clone_flags,
86595+static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
86596 unsigned long stack_start,
86597 unsigned long stack_size,
86598 int __user *child_tidptr,
86599@@ -1202,6 +1254,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
86600 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
86601 #endif
86602 retval = -EAGAIN;
86603+
86604+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
86605+
86606 if (atomic_read(&p->real_cred->user->processes) >=
86607 task_rlimit(p, RLIMIT_NPROC)) {
86608 if (p->real_cred->user != INIT_USER &&
86609@@ -1449,6 +1504,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
86610 goto bad_fork_free_pid;
86611 }
86612
86613+ /* synchronizes with gr_set_acls()
86614+ we need to call this past the point of no return for fork()
86615+ */
86616+ gr_copy_label(p);
86617+
86618 if (likely(p->pid)) {
86619 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
86620
86621@@ -1537,6 +1597,8 @@ bad_fork_cleanup_count:
86622 bad_fork_free:
86623 free_task(p);
86624 fork_out:
86625+ gr_log_forkfail(retval);
86626+
86627 return ERR_PTR(retval);
86628 }
86629
86630@@ -1598,6 +1660,7 @@ long do_fork(unsigned long clone_flags,
86631
86632 p = copy_process(clone_flags, stack_start, stack_size,
86633 child_tidptr, NULL, trace);
86634+ add_latent_entropy();
86635 /*
86636 * Do this prior waking up the new thread - the thread pointer
86637 * might get invalid after that point, if the thread exits quickly.
86638@@ -1612,6 +1675,8 @@ long do_fork(unsigned long clone_flags,
86639 if (clone_flags & CLONE_PARENT_SETTID)
86640 put_user(nr, parent_tidptr);
86641
86642+ gr_handle_brute_check();
86643+
86644 if (clone_flags & CLONE_VFORK) {
86645 p->vfork_done = &vfork;
86646 init_completion(&vfork);
86647@@ -1728,7 +1793,7 @@ void __init proc_caches_init(void)
86648 mm_cachep = kmem_cache_create("mm_struct",
86649 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
86650 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
86651- vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
86652+ vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
86653 mmap_init();
86654 nsproxy_cache_init();
86655 }
86656@@ -1768,7 +1833,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
86657 return 0;
86658
86659 /* don't need lock here; in the worst case we'll do useless copy */
86660- if (fs->users == 1)
86661+ if (atomic_read(&fs->users) == 1)
86662 return 0;
86663
86664 *new_fsp = copy_fs_struct(fs);
86665@@ -1875,7 +1940,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
86666 fs = current->fs;
86667 spin_lock(&fs->lock);
86668 current->fs = new_fs;
86669- if (--fs->users)
86670+ gr_set_chroot_entries(current, &current->fs->root);
86671+ if (atomic_dec_return(&fs->users))
86672 new_fs = NULL;
86673 else
86674 new_fs = fs;
86675diff --git a/kernel/futex.c b/kernel/futex.c
86676index 6801b37..bb6becca 100644
86677--- a/kernel/futex.c
86678+++ b/kernel/futex.c
86679@@ -54,6 +54,7 @@
86680 #include <linux/mount.h>
86681 #include <linux/pagemap.h>
86682 #include <linux/syscalls.h>
86683+#include <linux/ptrace.h>
86684 #include <linux/signal.h>
86685 #include <linux/export.h>
86686 #include <linux/magic.h>
86687@@ -380,6 +381,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
86688 struct page *page, *page_head;
86689 int err, ro = 0;
86690
86691+#ifdef CONFIG_PAX_SEGMEXEC
86692+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
86693+ return -EFAULT;
86694+#endif
86695+
86696 /*
86697 * The futex address must be "naturally" aligned.
86698 */
86699@@ -579,7 +585,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
86700
86701 static int get_futex_value_locked(u32 *dest, u32 __user *from)
86702 {
86703- int ret;
86704+ unsigned long ret;
86705
86706 pagefault_disable();
86707 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
86708@@ -2886,6 +2892,7 @@ static void __init futex_detect_cmpxchg(void)
86709 {
86710 #ifndef CONFIG_HAVE_FUTEX_CMPXCHG
86711 u32 curval;
86712+ mm_segment_t oldfs;
86713
86714 /*
86715 * This will fail and we want it. Some arch implementations do
86716@@ -2897,8 +2904,11 @@ static void __init futex_detect_cmpxchg(void)
86717 * implementation, the non-functional ones will return
86718 * -ENOSYS.
86719 */
86720+ oldfs = get_fs();
86721+ set_fs(USER_DS);
86722 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
86723 futex_cmpxchg_enabled = 1;
86724+ set_fs(oldfs);
86725 #endif
86726 }
86727
86728diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
86729index f9f44fd..29885e4 100644
86730--- a/kernel/futex_compat.c
86731+++ b/kernel/futex_compat.c
86732@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
86733 return 0;
86734 }
86735
86736-static void __user *futex_uaddr(struct robust_list __user *entry,
86737+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
86738 compat_long_t futex_offset)
86739 {
86740 compat_uptr_t base = ptr_to_compat(entry);
86741diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
86742index f45b75b..bfac6d5 100644
86743--- a/kernel/gcov/base.c
86744+++ b/kernel/gcov/base.c
86745@@ -108,11 +108,6 @@ void gcov_enable_events(void)
86746 }
86747
86748 #ifdef CONFIG_MODULES
86749-static inline int within(void *addr, void *start, unsigned long size)
86750-{
86751- return ((addr >= start) && (addr < start + size));
86752-}
86753-
86754 /* Update list and generate events when modules are unloaded. */
86755 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
86756 void *data)
86757@@ -127,7 +122,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
86758
86759 /* Remove entries located in module from linked list. */
86760 while ((info = gcov_info_next(info))) {
86761- if (within(info, mod->module_core, mod->core_size)) {
86762+ if (within_module_core_rw((unsigned long)info, mod)) {
86763 gcov_info_unlink(prev, info);
86764 if (gcov_events_enabled)
86765 gcov_event(GCOV_REMOVE, info);
86766diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
86767index 0909436..6037d22 100644
86768--- a/kernel/hrtimer.c
86769+++ b/kernel/hrtimer.c
86770@@ -1439,7 +1439,7 @@ void hrtimer_peek_ahead_timers(void)
86771 local_irq_restore(flags);
86772 }
86773
86774-static void run_hrtimer_softirq(struct softirq_action *h)
86775+static __latent_entropy void run_hrtimer_softirq(void)
86776 {
86777 hrtimer_peek_ahead_timers();
86778 }
86779diff --git a/kernel/irq_work.c b/kernel/irq_work.c
86780index 55fcce6..0e4cf34 100644
86781--- a/kernel/irq_work.c
86782+++ b/kernel/irq_work.c
86783@@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
86784 return NOTIFY_OK;
86785 }
86786
86787-static struct notifier_block cpu_notify;
86788+static struct notifier_block cpu_notify = {
86789+ .notifier_call = irq_work_cpu_notify,
86790+ .priority = 0,
86791+};
86792
86793 static __init int irq_work_init_cpu_notifier(void)
86794 {
86795- cpu_notify.notifier_call = irq_work_cpu_notify;
86796- cpu_notify.priority = 0;
86797 register_cpu_notifier(&cpu_notify);
86798 return 0;
86799 }
86800diff --git a/kernel/jump_label.c b/kernel/jump_label.c
86801index 9019f15..9a3c42e 100644
86802--- a/kernel/jump_label.c
86803+++ b/kernel/jump_label.c
86804@@ -14,6 +14,7 @@
86805 #include <linux/err.h>
86806 #include <linux/static_key.h>
86807 #include <linux/jump_label_ratelimit.h>
86808+#include <linux/mm.h>
86809
86810 #ifdef HAVE_JUMP_LABEL
86811
86812@@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
86813
86814 size = (((unsigned long)stop - (unsigned long)start)
86815 / sizeof(struct jump_entry));
86816+ pax_open_kernel();
86817 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
86818+ pax_close_kernel();
86819 }
86820
86821 static void jump_label_update(struct static_key *key, int enable);
86822@@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
86823 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
86824 struct jump_entry *iter;
86825
86826+ pax_open_kernel();
86827 for (iter = iter_start; iter < iter_stop; iter++) {
86828 if (within_module_init(iter->code, mod))
86829 iter->code = 0;
86830 }
86831+ pax_close_kernel();
86832 }
86833
86834 static int
86835diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
86836index 3127ad5..159d880 100644
86837--- a/kernel/kallsyms.c
86838+++ b/kernel/kallsyms.c
86839@@ -11,6 +11,9 @@
86840 * Changed the compression method from stem compression to "table lookup"
86841 * compression (see scripts/kallsyms.c for a more complete description)
86842 */
86843+#ifdef CONFIG_GRKERNSEC_HIDESYM
86844+#define __INCLUDED_BY_HIDESYM 1
86845+#endif
86846 #include <linux/kallsyms.h>
86847 #include <linux/module.h>
86848 #include <linux/init.h>
86849@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
86850
86851 static inline int is_kernel_inittext(unsigned long addr)
86852 {
86853+ if (system_state != SYSTEM_BOOTING)
86854+ return 0;
86855+
86856 if (addr >= (unsigned long)_sinittext
86857 && addr <= (unsigned long)_einittext)
86858 return 1;
86859 return 0;
86860 }
86861
86862+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86863+#ifdef CONFIG_MODULES
86864+static inline int is_module_text(unsigned long addr)
86865+{
86866+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
86867+ return 1;
86868+
86869+ addr = ktla_ktva(addr);
86870+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
86871+}
86872+#else
86873+static inline int is_module_text(unsigned long addr)
86874+{
86875+ return 0;
86876+}
86877+#endif
86878+#endif
86879+
86880 static inline int is_kernel_text(unsigned long addr)
86881 {
86882 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
86883@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
86884
86885 static inline int is_kernel(unsigned long addr)
86886 {
86887+
86888+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86889+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
86890+ return 1;
86891+
86892+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
86893+#else
86894 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
86895+#endif
86896+
86897 return 1;
86898 return in_gate_area_no_mm(addr);
86899 }
86900
86901 static int is_ksym_addr(unsigned long addr)
86902 {
86903+
86904+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86905+ if (is_module_text(addr))
86906+ return 0;
86907+#endif
86908+
86909 if (all_var)
86910 return is_kernel(addr);
86911
86912@@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
86913
86914 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
86915 {
86916- iter->name[0] = '\0';
86917 iter->nameoff = get_symbol_offset(new_pos);
86918 iter->pos = new_pos;
86919 }
86920@@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
86921 {
86922 struct kallsym_iter *iter = m->private;
86923
86924+#ifdef CONFIG_GRKERNSEC_HIDESYM
86925+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
86926+ return 0;
86927+#endif
86928+
86929 /* Some debugging symbols have no name. Ignore them. */
86930 if (!iter->name[0])
86931 return 0;
86932@@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
86933 */
86934 type = iter->exported ? toupper(iter->type) :
86935 tolower(iter->type);
86936+
86937 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
86938 type, iter->name, iter->module_name);
86939 } else
86940@@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
86941 struct kallsym_iter *iter;
86942 int ret;
86943
86944- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
86945+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
86946 if (!iter)
86947 return -ENOMEM;
86948 reset_iter(iter, 0);
86949diff --git a/kernel/kcmp.c b/kernel/kcmp.c
86950index e30ac0f..3528cac 100644
86951--- a/kernel/kcmp.c
86952+++ b/kernel/kcmp.c
86953@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
86954 struct task_struct *task1, *task2;
86955 int ret;
86956
86957+#ifdef CONFIG_GRKERNSEC
86958+ return -ENOSYS;
86959+#endif
86960+
86961 rcu_read_lock();
86962
86963 /*
86964diff --git a/kernel/kexec.c b/kernel/kexec.c
86965index 60bafbe..a120f4f 100644
86966--- a/kernel/kexec.c
86967+++ b/kernel/kexec.c
86968@@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
86969 unsigned long flags)
86970 {
86971 struct compat_kexec_segment in;
86972- struct kexec_segment out, __user *ksegments;
86973+ struct kexec_segment out;
86974+ struct kexec_segment __user *ksegments;
86975 unsigned long i, result;
86976
86977 /* Don't allow clients that don't understand the native
86978diff --git a/kernel/kmod.c b/kernel/kmod.c
86979index 6b375af..eaff670 100644
86980--- a/kernel/kmod.c
86981+++ b/kernel/kmod.c
86982@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
86983 kfree(info->argv);
86984 }
86985
86986-static int call_modprobe(char *module_name, int wait)
86987+static int call_modprobe(char *module_name, char *module_param, int wait)
86988 {
86989 struct subprocess_info *info;
86990 static char *envp[] = {
86991@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
86992 NULL
86993 };
86994
86995- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
86996+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
86997 if (!argv)
86998 goto out;
86999
87000@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
87001 argv[1] = "-q";
87002 argv[2] = "--";
87003 argv[3] = module_name; /* check free_modprobe_argv() */
87004- argv[4] = NULL;
87005+ argv[4] = module_param;
87006+ argv[5] = NULL;
87007
87008 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
87009 NULL, free_modprobe_argv, NULL);
87010@@ -129,9 +130,8 @@ out:
87011 * If module auto-loading support is disabled then this function
87012 * becomes a no-operation.
87013 */
87014-int __request_module(bool wait, const char *fmt, ...)
87015+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
87016 {
87017- va_list args;
87018 char module_name[MODULE_NAME_LEN];
87019 unsigned int max_modprobes;
87020 int ret;
87021@@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
87022 if (!modprobe_path[0])
87023 return 0;
87024
87025- va_start(args, fmt);
87026- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
87027- va_end(args);
87028+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
87029 if (ret >= MODULE_NAME_LEN)
87030 return -ENAMETOOLONG;
87031
87032@@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
87033 if (ret)
87034 return ret;
87035
87036+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87037+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
87038+ /* hack to workaround consolekit/udisks stupidity */
87039+ read_lock(&tasklist_lock);
87040+ if (!strcmp(current->comm, "mount") &&
87041+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
87042+ read_unlock(&tasklist_lock);
87043+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
87044+ return -EPERM;
87045+ }
87046+ read_unlock(&tasklist_lock);
87047+ }
87048+#endif
87049+
87050 /* If modprobe needs a service that is in a module, we get a recursive
87051 * loop. Limit the number of running kmod threads to max_threads/2 or
87052 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
87053@@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
87054
87055 trace_module_request(module_name, wait, _RET_IP_);
87056
87057- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
87058+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
87059
87060 atomic_dec(&kmod_concurrent);
87061 return ret;
87062 }
87063+
87064+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
87065+{
87066+ va_list args;
87067+ int ret;
87068+
87069+ va_start(args, fmt);
87070+ ret = ____request_module(wait, module_param, fmt, args);
87071+ va_end(args);
87072+
87073+ return ret;
87074+}
87075+
87076+int __request_module(bool wait, const char *fmt, ...)
87077+{
87078+ va_list args;
87079+ int ret;
87080+
87081+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87082+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
87083+ char module_param[MODULE_NAME_LEN];
87084+
87085+ memset(module_param, 0, sizeof(module_param));
87086+
87087+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
87088+
87089+ va_start(args, fmt);
87090+ ret = ____request_module(wait, module_param, fmt, args);
87091+ va_end(args);
87092+
87093+ return ret;
87094+ }
87095+#endif
87096+
87097+ va_start(args, fmt);
87098+ ret = ____request_module(wait, NULL, fmt, args);
87099+ va_end(args);
87100+
87101+ return ret;
87102+}
87103+
87104 EXPORT_SYMBOL(__request_module);
87105 #endif /* CONFIG_MODULES */
87106
87107@@ -218,6 +271,20 @@ static int ____call_usermodehelper(void *data)
87108 */
87109 set_user_nice(current, 0);
87110
87111+#ifdef CONFIG_GRKERNSEC
87112+ /* this is race-free as far as userland is concerned as we copied
87113+ out the path to be used prior to this point and are now operating
87114+ on that copy
87115+ */
87116+ if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
87117+ strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
87118+ strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
87119+ printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
87120+ retval = -EPERM;
87121+ goto fail;
87122+ }
87123+#endif
87124+
87125 retval = -ENOMEM;
87126 new = prepare_kernel_cred(current);
87127 if (!new)
87128@@ -240,8 +307,8 @@ static int ____call_usermodehelper(void *data)
87129 commit_creds(new);
87130
87131 retval = do_execve(getname_kernel(sub_info->path),
87132- (const char __user *const __user *)sub_info->argv,
87133- (const char __user *const __user *)sub_info->envp);
87134+ (const char __user *const __force_user *)sub_info->argv,
87135+ (const char __user *const __force_user *)sub_info->envp);
87136 if (!retval)
87137 return 0;
87138
87139@@ -260,6 +327,10 @@ static int call_helper(void *data)
87140
87141 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
87142 {
87143+#ifdef CONFIG_GRKERNSEC
87144+ kfree(info->path);
87145+ info->path = info->origpath;
87146+#endif
87147 if (info->cleanup)
87148 (*info->cleanup)(info);
87149 kfree(info);
87150@@ -303,7 +374,7 @@ static int wait_for_helper(void *data)
87151 *
87152 * Thus the __user pointer cast is valid here.
87153 */
87154- sys_wait4(pid, (int __user *)&ret, 0, NULL);
87155+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
87156
87157 /*
87158 * If ret is 0, either ____call_usermodehelper failed and the
87159@@ -542,7 +613,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
87160 goto out;
87161
87162 INIT_WORK(&sub_info->work, __call_usermodehelper);
87163+#ifdef CONFIG_GRKERNSEC
87164+ sub_info->origpath = path;
87165+ sub_info->path = kstrdup(path, gfp_mask);
87166+#else
87167 sub_info->path = path;
87168+#endif
87169 sub_info->argv = argv;
87170 sub_info->envp = envp;
87171
87172@@ -650,7 +726,7 @@ EXPORT_SYMBOL(call_usermodehelper);
87173 static int proc_cap_handler(struct ctl_table *table, int write,
87174 void __user *buffer, size_t *lenp, loff_t *ppos)
87175 {
87176- struct ctl_table t;
87177+ ctl_table_no_const t;
87178 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
87179 kernel_cap_t new_cap;
87180 int err, i;
87181diff --git a/kernel/kprobes.c b/kernel/kprobes.c
87182index ceeadfc..11c18b6 100644
87183--- a/kernel/kprobes.c
87184+++ b/kernel/kprobes.c
87185@@ -31,6 +31,9 @@
87186 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
87187 * <prasanna@in.ibm.com> added function-return probes.
87188 */
87189+#ifdef CONFIG_GRKERNSEC_HIDESYM
87190+#define __INCLUDED_BY_HIDESYM 1
87191+#endif
87192 #include <linux/kprobes.h>
87193 #include <linux/hash.h>
87194 #include <linux/init.h>
87195@@ -135,12 +138,12 @@ enum kprobe_slot_state {
87196
87197 static void *alloc_insn_page(void)
87198 {
87199- return module_alloc(PAGE_SIZE);
87200+ return module_alloc_exec(PAGE_SIZE);
87201 }
87202
87203 static void free_insn_page(void *page)
87204 {
87205- module_free(NULL, page);
87206+ module_free_exec(NULL, page);
87207 }
87208
87209 struct kprobe_insn_cache kprobe_insn_slots = {
87210@@ -2151,11 +2154,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
87211 kprobe_type = "k";
87212
87213 if (sym)
87214- seq_printf(pi, "%p %s %s+0x%x %s ",
87215+ seq_printf(pi, "%pK %s %s+0x%x %s ",
87216 p->addr, kprobe_type, sym, offset,
87217 (modname ? modname : " "));
87218 else
87219- seq_printf(pi, "%p %s %p ",
87220+ seq_printf(pi, "%pK %s %pK ",
87221 p->addr, kprobe_type, p->addr);
87222
87223 if (!pp)
87224diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
87225index d945a94..0b7f45f 100644
87226--- a/kernel/ksysfs.c
87227+++ b/kernel/ksysfs.c
87228@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
87229 {
87230 if (count+1 > UEVENT_HELPER_PATH_LEN)
87231 return -ENOENT;
87232+ if (!capable(CAP_SYS_ADMIN))
87233+ return -EPERM;
87234 memcpy(uevent_helper, buf, count);
87235 uevent_helper[count] = '\0';
87236 if (count && uevent_helper[count-1] == '\n')
87237@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
87238 return count;
87239 }
87240
87241-static struct bin_attribute notes_attr = {
87242+static bin_attribute_no_const notes_attr __read_only = {
87243 .attr = {
87244 .name = "notes",
87245 .mode = S_IRUGO,
87246diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
87247index eb8a547..321d8e1 100644
87248--- a/kernel/locking/lockdep.c
87249+++ b/kernel/locking/lockdep.c
87250@@ -597,6 +597,10 @@ static int static_obj(void *obj)
87251 end = (unsigned long) &_end,
87252 addr = (unsigned long) obj;
87253
87254+#ifdef CONFIG_PAX_KERNEXEC
87255+ start = ktla_ktva(start);
87256+#endif
87257+
87258 /*
87259 * static variable?
87260 */
87261@@ -738,6 +742,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
87262 if (!static_obj(lock->key)) {
87263 debug_locks_off();
87264 printk("INFO: trying to register non-static key.\n");
87265+ printk("lock:%pS key:%pS.\n", lock, lock->key);
87266 printk("the code is fine but needs lockdep annotation.\n");
87267 printk("turning off the locking correctness validator.\n");
87268 dump_stack();
87269@@ -3082,7 +3087,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
87270 if (!class)
87271 return 0;
87272 }
87273- atomic_inc((atomic_t *)&class->ops);
87274+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
87275 if (very_verbose(class)) {
87276 printk("\nacquire class [%p] %s", class->key, class->name);
87277 if (class->name_version > 1)
87278diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
87279index ef43ac4..2720dfa 100644
87280--- a/kernel/locking/lockdep_proc.c
87281+++ b/kernel/locking/lockdep_proc.c
87282@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
87283 return 0;
87284 }
87285
87286- seq_printf(m, "%p", class->key);
87287+ seq_printf(m, "%pK", class->key);
87288 #ifdef CONFIG_DEBUG_LOCKDEP
87289 seq_printf(m, " OPS:%8ld", class->ops);
87290 #endif
87291@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
87292
87293 list_for_each_entry(entry, &class->locks_after, entry) {
87294 if (entry->distance == 1) {
87295- seq_printf(m, " -> [%p] ", entry->class->key);
87296+ seq_printf(m, " -> [%pK] ", entry->class->key);
87297 print_name(m, entry->class);
87298 seq_puts(m, "\n");
87299 }
87300@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
87301 if (!class->key)
87302 continue;
87303
87304- seq_printf(m, "[%p] ", class->key);
87305+ seq_printf(m, "[%pK] ", class->key);
87306 print_name(m, class);
87307 seq_puts(m, "\n");
87308 }
87309@@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
87310 if (!i)
87311 seq_line(m, '-', 40-namelen, namelen);
87312
87313- snprintf(ip, sizeof(ip), "[<%p>]",
87314+ snprintf(ip, sizeof(ip), "[<%pK>]",
87315 (void *)class->contention_point[i]);
87316 seq_printf(m, "%40s %14lu %29s %pS\n",
87317 name, stats->contention_point[i],
87318@@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
87319 if (!i)
87320 seq_line(m, '-', 40-namelen, namelen);
87321
87322- snprintf(ip, sizeof(ip), "[<%p>]",
87323+ snprintf(ip, sizeof(ip), "[<%pK>]",
87324 (void *)class->contending_point[i]);
87325 seq_printf(m, "%40s %14lu %29s %pS\n",
87326 name, stats->contending_point[i],
87327diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
87328index faf6f5b..dc9070a 100644
87329--- a/kernel/locking/mutex-debug.c
87330+++ b/kernel/locking/mutex-debug.c
87331@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
87332 }
87333
87334 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
87335- struct thread_info *ti)
87336+ struct task_struct *task)
87337 {
87338 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
87339
87340 /* Mark the current thread as blocked on the lock: */
87341- ti->task->blocked_on = waiter;
87342+ task->blocked_on = waiter;
87343 }
87344
87345 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
87346- struct thread_info *ti)
87347+ struct task_struct *task)
87348 {
87349 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
87350- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
87351- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
87352- ti->task->blocked_on = NULL;
87353+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
87354+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
87355+ task->blocked_on = NULL;
87356
87357 list_del_init(&waiter->list);
87358 waiter->task = NULL;
87359diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
87360index 0799fd3..d06ae3b 100644
87361--- a/kernel/locking/mutex-debug.h
87362+++ b/kernel/locking/mutex-debug.h
87363@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
87364 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
87365 extern void debug_mutex_add_waiter(struct mutex *lock,
87366 struct mutex_waiter *waiter,
87367- struct thread_info *ti);
87368+ struct task_struct *task);
87369 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
87370- struct thread_info *ti);
87371+ struct task_struct *task);
87372 extern void debug_mutex_unlock(struct mutex *lock);
87373 extern void debug_mutex_init(struct mutex *lock, const char *name,
87374 struct lock_class_key *key);
87375diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
87376index 4dd6e4c..df52693 100644
87377--- a/kernel/locking/mutex.c
87378+++ b/kernel/locking/mutex.c
87379@@ -135,7 +135,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
87380 node->locked = 1;
87381 return;
87382 }
87383- ACCESS_ONCE(prev->next) = node;
87384+ ACCESS_ONCE_RW(prev->next) = node;
87385 smp_wmb();
87386 /* Wait until the lock holder passes the lock down */
87387 while (!ACCESS_ONCE(node->locked))
87388@@ -156,7 +156,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
87389 while (!(next = ACCESS_ONCE(node->next)))
87390 arch_mutex_cpu_relax();
87391 }
87392- ACCESS_ONCE(next->locked) = 1;
87393+ ACCESS_ONCE_RW(next->locked) = 1;
87394 smp_wmb();
87395 }
87396
87397@@ -520,7 +520,7 @@ slowpath:
87398 goto skip_wait;
87399
87400 debug_mutex_lock_common(lock, &waiter);
87401- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
87402+ debug_mutex_add_waiter(lock, &waiter, task);
87403
87404 /* add waiting tasks to the end of the waitqueue (FIFO): */
87405 list_add_tail(&waiter.list, &lock->wait_list);
87406@@ -564,7 +564,7 @@ slowpath:
87407 schedule_preempt_disabled();
87408 spin_lock_mutex(&lock->wait_lock, flags);
87409 }
87410- mutex_remove_waiter(lock, &waiter, current_thread_info());
87411+ mutex_remove_waiter(lock, &waiter, task);
87412 /* set it to 0 if there are no waiters left: */
87413 if (likely(list_empty(&lock->wait_list)))
87414 atomic_set(&lock->count, 0);
87415@@ -601,7 +601,7 @@ skip_wait:
87416 return 0;
87417
87418 err:
87419- mutex_remove_waiter(lock, &waiter, task_thread_info(task));
87420+ mutex_remove_waiter(lock, &waiter, task);
87421 spin_unlock_mutex(&lock->wait_lock, flags);
87422 debug_mutex_free_waiter(&waiter);
87423 mutex_release(&lock->dep_map, 1, ip);
87424diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
87425index 1d96dd0..994ff19 100644
87426--- a/kernel/locking/rtmutex-tester.c
87427+++ b/kernel/locking/rtmutex-tester.c
87428@@ -22,7 +22,7 @@
87429 #define MAX_RT_TEST_MUTEXES 8
87430
87431 static spinlock_t rttest_lock;
87432-static atomic_t rttest_event;
87433+static atomic_unchecked_t rttest_event;
87434
87435 struct test_thread_data {
87436 int opcode;
87437@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87438
87439 case RTTEST_LOCKCONT:
87440 td->mutexes[td->opdata] = 1;
87441- td->event = atomic_add_return(1, &rttest_event);
87442+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87443 return 0;
87444
87445 case RTTEST_RESET:
87446@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87447 return 0;
87448
87449 case RTTEST_RESETEVENT:
87450- atomic_set(&rttest_event, 0);
87451+ atomic_set_unchecked(&rttest_event, 0);
87452 return 0;
87453
87454 default:
87455@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87456 return ret;
87457
87458 td->mutexes[id] = 1;
87459- td->event = atomic_add_return(1, &rttest_event);
87460+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87461 rt_mutex_lock(&mutexes[id]);
87462- td->event = atomic_add_return(1, &rttest_event);
87463+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87464 td->mutexes[id] = 4;
87465 return 0;
87466
87467@@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87468 return ret;
87469
87470 td->mutexes[id] = 1;
87471- td->event = atomic_add_return(1, &rttest_event);
87472+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87473 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
87474- td->event = atomic_add_return(1, &rttest_event);
87475+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87476 td->mutexes[id] = ret ? 0 : 4;
87477 return ret ? -EINTR : 0;
87478
87479@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87480 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
87481 return ret;
87482
87483- td->event = atomic_add_return(1, &rttest_event);
87484+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87485 rt_mutex_unlock(&mutexes[id]);
87486- td->event = atomic_add_return(1, &rttest_event);
87487+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87488 td->mutexes[id] = 0;
87489 return 0;
87490
87491@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87492 break;
87493
87494 td->mutexes[dat] = 2;
87495- td->event = atomic_add_return(1, &rttest_event);
87496+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87497 break;
87498
87499 default:
87500@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87501 return;
87502
87503 td->mutexes[dat] = 3;
87504- td->event = atomic_add_return(1, &rttest_event);
87505+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87506 break;
87507
87508 case RTTEST_LOCKNOWAIT:
87509@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87510 return;
87511
87512 td->mutexes[dat] = 1;
87513- td->event = atomic_add_return(1, &rttest_event);
87514+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87515 return;
87516
87517 default:
87518diff --git a/kernel/module.c b/kernel/module.c
87519index d24fcf2..2af3fd9 100644
87520--- a/kernel/module.c
87521+++ b/kernel/module.c
87522@@ -61,6 +61,7 @@
87523 #include <linux/pfn.h>
87524 #include <linux/bsearch.h>
87525 #include <linux/fips.h>
87526+#include <linux/grsecurity.h>
87527 #include <uapi/linux/module.h>
87528 #include "module-internal.h"
87529
87530@@ -157,7 +158,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
87531
87532 /* Bounds of module allocation, for speeding __module_address.
87533 * Protected by module_mutex. */
87534-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
87535+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
87536+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
87537
87538 int register_module_notifier(struct notifier_block * nb)
87539 {
87540@@ -324,7 +326,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
87541 return true;
87542
87543 list_for_each_entry_rcu(mod, &modules, list) {
87544- struct symsearch arr[] = {
87545+ struct symsearch modarr[] = {
87546 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
87547 NOT_GPL_ONLY, false },
87548 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
87549@@ -349,7 +351,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
87550 if (mod->state == MODULE_STATE_UNFORMED)
87551 continue;
87552
87553- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
87554+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
87555 return true;
87556 }
87557 return false;
87558@@ -489,7 +491,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
87559 if (!pcpusec->sh_size)
87560 return 0;
87561
87562- if (align > PAGE_SIZE) {
87563+ if (align-1 >= PAGE_SIZE) {
87564 pr_warn("%s: per-cpu alignment %li > %li\n",
87565 mod->name, align, PAGE_SIZE);
87566 align = PAGE_SIZE;
87567@@ -1062,7 +1064,7 @@ struct module_attribute module_uevent =
87568 static ssize_t show_coresize(struct module_attribute *mattr,
87569 struct module_kobject *mk, char *buffer)
87570 {
87571- return sprintf(buffer, "%u\n", mk->mod->core_size);
87572+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
87573 }
87574
87575 static struct module_attribute modinfo_coresize =
87576@@ -1071,7 +1073,7 @@ static struct module_attribute modinfo_coresize =
87577 static ssize_t show_initsize(struct module_attribute *mattr,
87578 struct module_kobject *mk, char *buffer)
87579 {
87580- return sprintf(buffer, "%u\n", mk->mod->init_size);
87581+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
87582 }
87583
87584 static struct module_attribute modinfo_initsize =
87585@@ -1163,12 +1165,29 @@ static int check_version(Elf_Shdr *sechdrs,
87586 goto bad_version;
87587 }
87588
87589+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
87590+ /*
87591+ * avoid potentially printing jibberish on attempted load
87592+ * of a module randomized with a different seed
87593+ */
87594+ pr_warn("no symbol version for %s\n", symname);
87595+#else
87596 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
87597+#endif
87598 return 0;
87599
87600 bad_version:
87601+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
87602+ /*
87603+ * avoid potentially printing jibberish on attempted load
87604+ * of a module randomized with a different seed
87605+ */
87606+ printk("attempted module disagrees about version of symbol %s\n",
87607+ symname);
87608+#else
87609 printk("%s: disagrees about version of symbol %s\n",
87610 mod->name, symname);
87611+#endif
87612 return 0;
87613 }
87614
87615@@ -1284,7 +1303,7 @@ resolve_symbol_wait(struct module *mod,
87616 */
87617 #ifdef CONFIG_SYSFS
87618
87619-#ifdef CONFIG_KALLSYMS
87620+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
87621 static inline bool sect_empty(const Elf_Shdr *sect)
87622 {
87623 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
87624@@ -1424,7 +1443,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
87625 {
87626 unsigned int notes, loaded, i;
87627 struct module_notes_attrs *notes_attrs;
87628- struct bin_attribute *nattr;
87629+ bin_attribute_no_const *nattr;
87630
87631 /* failed to create section attributes, so can't create notes */
87632 if (!mod->sect_attrs)
87633@@ -1536,7 +1555,7 @@ static void del_usage_links(struct module *mod)
87634 static int module_add_modinfo_attrs(struct module *mod)
87635 {
87636 struct module_attribute *attr;
87637- struct module_attribute *temp_attr;
87638+ module_attribute_no_const *temp_attr;
87639 int error = 0;
87640 int i;
87641
87642@@ -1757,21 +1776,21 @@ static void set_section_ro_nx(void *base,
87643
87644 static void unset_module_core_ro_nx(struct module *mod)
87645 {
87646- set_page_attributes(mod->module_core + mod->core_text_size,
87647- mod->module_core + mod->core_size,
87648+ set_page_attributes(mod->module_core_rw,
87649+ mod->module_core_rw + mod->core_size_rw,
87650 set_memory_x);
87651- set_page_attributes(mod->module_core,
87652- mod->module_core + mod->core_ro_size,
87653+ set_page_attributes(mod->module_core_rx,
87654+ mod->module_core_rx + mod->core_size_rx,
87655 set_memory_rw);
87656 }
87657
87658 static void unset_module_init_ro_nx(struct module *mod)
87659 {
87660- set_page_attributes(mod->module_init + mod->init_text_size,
87661- mod->module_init + mod->init_size,
87662+ set_page_attributes(mod->module_init_rw,
87663+ mod->module_init_rw + mod->init_size_rw,
87664 set_memory_x);
87665- set_page_attributes(mod->module_init,
87666- mod->module_init + mod->init_ro_size,
87667+ set_page_attributes(mod->module_init_rx,
87668+ mod->module_init_rx + mod->init_size_rx,
87669 set_memory_rw);
87670 }
87671
87672@@ -1784,14 +1803,14 @@ void set_all_modules_text_rw(void)
87673 list_for_each_entry_rcu(mod, &modules, list) {
87674 if (mod->state == MODULE_STATE_UNFORMED)
87675 continue;
87676- if ((mod->module_core) && (mod->core_text_size)) {
87677- set_page_attributes(mod->module_core,
87678- mod->module_core + mod->core_text_size,
87679+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
87680+ set_page_attributes(mod->module_core_rx,
87681+ mod->module_core_rx + mod->core_size_rx,
87682 set_memory_rw);
87683 }
87684- if ((mod->module_init) && (mod->init_text_size)) {
87685- set_page_attributes(mod->module_init,
87686- mod->module_init + mod->init_text_size,
87687+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
87688+ set_page_attributes(mod->module_init_rx,
87689+ mod->module_init_rx + mod->init_size_rx,
87690 set_memory_rw);
87691 }
87692 }
87693@@ -1807,14 +1826,14 @@ void set_all_modules_text_ro(void)
87694 list_for_each_entry_rcu(mod, &modules, list) {
87695 if (mod->state == MODULE_STATE_UNFORMED)
87696 continue;
87697- if ((mod->module_core) && (mod->core_text_size)) {
87698- set_page_attributes(mod->module_core,
87699- mod->module_core + mod->core_text_size,
87700+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
87701+ set_page_attributes(mod->module_core_rx,
87702+ mod->module_core_rx + mod->core_size_rx,
87703 set_memory_ro);
87704 }
87705- if ((mod->module_init) && (mod->init_text_size)) {
87706- set_page_attributes(mod->module_init,
87707- mod->module_init + mod->init_text_size,
87708+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
87709+ set_page_attributes(mod->module_init_rx,
87710+ mod->module_init_rx + mod->init_size_rx,
87711 set_memory_ro);
87712 }
87713 }
87714@@ -1865,16 +1884,19 @@ static void free_module(struct module *mod)
87715
87716 /* This may be NULL, but that's OK */
87717 unset_module_init_ro_nx(mod);
87718- module_free(mod, mod->module_init);
87719+ module_free(mod, mod->module_init_rw);
87720+ module_free_exec(mod, mod->module_init_rx);
87721 kfree(mod->args);
87722 percpu_modfree(mod);
87723
87724 /* Free lock-classes: */
87725- lockdep_free_key_range(mod->module_core, mod->core_size);
87726+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
87727+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
87728
87729 /* Finally, free the core (containing the module structure) */
87730 unset_module_core_ro_nx(mod);
87731- module_free(mod, mod->module_core);
87732+ module_free_exec(mod, mod->module_core_rx);
87733+ module_free(mod, mod->module_core_rw);
87734
87735 #ifdef CONFIG_MPU
87736 update_protections(current->mm);
87737@@ -1943,9 +1965,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
87738 int ret = 0;
87739 const struct kernel_symbol *ksym;
87740
87741+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87742+ int is_fs_load = 0;
87743+ int register_filesystem_found = 0;
87744+ char *p;
87745+
87746+ p = strstr(mod->args, "grsec_modharden_fs");
87747+ if (p) {
87748+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
87749+ /* copy \0 as well */
87750+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
87751+ is_fs_load = 1;
87752+ }
87753+#endif
87754+
87755 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
87756 const char *name = info->strtab + sym[i].st_name;
87757
87758+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87759+ /* it's a real shame this will never get ripped and copied
87760+ upstream! ;(
87761+ */
87762+ if (is_fs_load && !strcmp(name, "register_filesystem"))
87763+ register_filesystem_found = 1;
87764+#endif
87765+
87766 switch (sym[i].st_shndx) {
87767 case SHN_COMMON:
87768 /* We compiled with -fno-common. These are not
87769@@ -1966,7 +2010,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
87770 ksym = resolve_symbol_wait(mod, info, name);
87771 /* Ok if resolved. */
87772 if (ksym && !IS_ERR(ksym)) {
87773+ pax_open_kernel();
87774 sym[i].st_value = ksym->value;
87775+ pax_close_kernel();
87776 break;
87777 }
87778
87779@@ -1985,11 +2031,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
87780 secbase = (unsigned long)mod_percpu(mod);
87781 else
87782 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
87783+ pax_open_kernel();
87784 sym[i].st_value += secbase;
87785+ pax_close_kernel();
87786 break;
87787 }
87788 }
87789
87790+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87791+ if (is_fs_load && !register_filesystem_found) {
87792+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
87793+ ret = -EPERM;
87794+ }
87795+#endif
87796+
87797 return ret;
87798 }
87799
87800@@ -2073,22 +2128,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
87801 || s->sh_entsize != ~0UL
87802 || strstarts(sname, ".init"))
87803 continue;
87804- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
87805+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
87806+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
87807+ else
87808+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
87809 pr_debug("\t%s\n", sname);
87810 }
87811- switch (m) {
87812- case 0: /* executable */
87813- mod->core_size = debug_align(mod->core_size);
87814- mod->core_text_size = mod->core_size;
87815- break;
87816- case 1: /* RO: text and ro-data */
87817- mod->core_size = debug_align(mod->core_size);
87818- mod->core_ro_size = mod->core_size;
87819- break;
87820- case 3: /* whole core */
87821- mod->core_size = debug_align(mod->core_size);
87822- break;
87823- }
87824 }
87825
87826 pr_debug("Init section allocation order:\n");
87827@@ -2102,23 +2147,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
87828 || s->sh_entsize != ~0UL
87829 || !strstarts(sname, ".init"))
87830 continue;
87831- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
87832- | INIT_OFFSET_MASK);
87833+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
87834+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
87835+ else
87836+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
87837+ s->sh_entsize |= INIT_OFFSET_MASK;
87838 pr_debug("\t%s\n", sname);
87839 }
87840- switch (m) {
87841- case 0: /* executable */
87842- mod->init_size = debug_align(mod->init_size);
87843- mod->init_text_size = mod->init_size;
87844- break;
87845- case 1: /* RO: text and ro-data */
87846- mod->init_size = debug_align(mod->init_size);
87847- mod->init_ro_size = mod->init_size;
87848- break;
87849- case 3: /* whole init */
87850- mod->init_size = debug_align(mod->init_size);
87851- break;
87852- }
87853 }
87854 }
87855
87856@@ -2291,7 +2326,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
87857
87858 /* Put symbol section at end of init part of module. */
87859 symsect->sh_flags |= SHF_ALLOC;
87860- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
87861+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
87862 info->index.sym) | INIT_OFFSET_MASK;
87863 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
87864
87865@@ -2308,13 +2343,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
87866 }
87867
87868 /* Append room for core symbols at end of core part. */
87869- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
87870- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
87871- mod->core_size += strtab_size;
87872+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
87873+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
87874+ mod->core_size_rx += strtab_size;
87875
87876 /* Put string table section at end of init part of module. */
87877 strsect->sh_flags |= SHF_ALLOC;
87878- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
87879+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
87880 info->index.str) | INIT_OFFSET_MASK;
87881 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
87882 }
87883@@ -2332,12 +2367,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
87884 /* Make sure we get permanent strtab: don't use info->strtab. */
87885 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
87886
87887+ pax_open_kernel();
87888+
87889 /* Set types up while we still have access to sections. */
87890 for (i = 0; i < mod->num_symtab; i++)
87891 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
87892
87893- mod->core_symtab = dst = mod->module_core + info->symoffs;
87894- mod->core_strtab = s = mod->module_core + info->stroffs;
87895+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
87896+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
87897 src = mod->symtab;
87898 for (ndst = i = 0; i < mod->num_symtab; i++) {
87899 if (i == 0 ||
87900@@ -2349,6 +2386,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
87901 }
87902 }
87903 mod->core_num_syms = ndst;
87904+
87905+ pax_close_kernel();
87906 }
87907 #else
87908 static inline void layout_symtab(struct module *mod, struct load_info *info)
87909@@ -2382,17 +2421,33 @@ void * __weak module_alloc(unsigned long size)
87910 return vmalloc_exec(size);
87911 }
87912
87913-static void *module_alloc_update_bounds(unsigned long size)
87914+static void *module_alloc_update_bounds_rw(unsigned long size)
87915 {
87916 void *ret = module_alloc(size);
87917
87918 if (ret) {
87919 mutex_lock(&module_mutex);
87920 /* Update module bounds. */
87921- if ((unsigned long)ret < module_addr_min)
87922- module_addr_min = (unsigned long)ret;
87923- if ((unsigned long)ret + size > module_addr_max)
87924- module_addr_max = (unsigned long)ret + size;
87925+ if ((unsigned long)ret < module_addr_min_rw)
87926+ module_addr_min_rw = (unsigned long)ret;
87927+ if ((unsigned long)ret + size > module_addr_max_rw)
87928+ module_addr_max_rw = (unsigned long)ret + size;
87929+ mutex_unlock(&module_mutex);
87930+ }
87931+ return ret;
87932+}
87933+
87934+static void *module_alloc_update_bounds_rx(unsigned long size)
87935+{
87936+ void *ret = module_alloc_exec(size);
87937+
87938+ if (ret) {
87939+ mutex_lock(&module_mutex);
87940+ /* Update module bounds. */
87941+ if ((unsigned long)ret < module_addr_min_rx)
87942+ module_addr_min_rx = (unsigned long)ret;
87943+ if ((unsigned long)ret + size > module_addr_max_rx)
87944+ module_addr_max_rx = (unsigned long)ret + size;
87945 mutex_unlock(&module_mutex);
87946 }
87947 return ret;
87948@@ -2649,7 +2704,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
87949 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
87950
87951 if (info->index.sym == 0) {
87952+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
87953+ /*
87954+ * avoid potentially printing jibberish on attempted load
87955+ * of a module randomized with a different seed
87956+ */
87957+ pr_warn("module has no symbols (stripped?)\n");
87958+#else
87959 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
87960+#endif
87961 return ERR_PTR(-ENOEXEC);
87962 }
87963
87964@@ -2665,8 +2728,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
87965 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
87966 {
87967 const char *modmagic = get_modinfo(info, "vermagic");
87968+ const char *license = get_modinfo(info, "license");
87969 int err;
87970
87971+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
87972+ if (!license || !license_is_gpl_compatible(license))
87973+ return -ENOEXEC;
87974+#endif
87975+
87976 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
87977 modmagic = NULL;
87978
87979@@ -2691,7 +2760,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
87980 }
87981
87982 /* Set up license info based on the info section */
87983- set_license(mod, get_modinfo(info, "license"));
87984+ set_license(mod, license);
87985
87986 return 0;
87987 }
87988@@ -2785,7 +2854,7 @@ static int move_module(struct module *mod, struct load_info *info)
87989 void *ptr;
87990
87991 /* Do the allocs. */
87992- ptr = module_alloc_update_bounds(mod->core_size);
87993+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
87994 /*
87995 * The pointer to this block is stored in the module structure
87996 * which is inside the block. Just mark it as not being a
87997@@ -2795,11 +2864,11 @@ static int move_module(struct module *mod, struct load_info *info)
87998 if (!ptr)
87999 return -ENOMEM;
88000
88001- memset(ptr, 0, mod->core_size);
88002- mod->module_core = ptr;
88003+ memset(ptr, 0, mod->core_size_rw);
88004+ mod->module_core_rw = ptr;
88005
88006- if (mod->init_size) {
88007- ptr = module_alloc_update_bounds(mod->init_size);
88008+ if (mod->init_size_rw) {
88009+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
88010 /*
88011 * The pointer to this block is stored in the module structure
88012 * which is inside the block. This block doesn't need to be
88013@@ -2808,13 +2877,45 @@ static int move_module(struct module *mod, struct load_info *info)
88014 */
88015 kmemleak_ignore(ptr);
88016 if (!ptr) {
88017- module_free(mod, mod->module_core);
88018+ module_free(mod, mod->module_core_rw);
88019 return -ENOMEM;
88020 }
88021- memset(ptr, 0, mod->init_size);
88022- mod->module_init = ptr;
88023+ memset(ptr, 0, mod->init_size_rw);
88024+ mod->module_init_rw = ptr;
88025 } else
88026- mod->module_init = NULL;
88027+ mod->module_init_rw = NULL;
88028+
88029+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
88030+ kmemleak_not_leak(ptr);
88031+ if (!ptr) {
88032+ if (mod->module_init_rw)
88033+ module_free(mod, mod->module_init_rw);
88034+ module_free(mod, mod->module_core_rw);
88035+ return -ENOMEM;
88036+ }
88037+
88038+ pax_open_kernel();
88039+ memset(ptr, 0, mod->core_size_rx);
88040+ pax_close_kernel();
88041+ mod->module_core_rx = ptr;
88042+
88043+ if (mod->init_size_rx) {
88044+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
88045+ kmemleak_ignore(ptr);
88046+ if (!ptr && mod->init_size_rx) {
88047+ module_free_exec(mod, mod->module_core_rx);
88048+ if (mod->module_init_rw)
88049+ module_free(mod, mod->module_init_rw);
88050+ module_free(mod, mod->module_core_rw);
88051+ return -ENOMEM;
88052+ }
88053+
88054+ pax_open_kernel();
88055+ memset(ptr, 0, mod->init_size_rx);
88056+ pax_close_kernel();
88057+ mod->module_init_rx = ptr;
88058+ } else
88059+ mod->module_init_rx = NULL;
88060
88061 /* Transfer each section which specifies SHF_ALLOC */
88062 pr_debug("final section addresses:\n");
88063@@ -2825,16 +2926,45 @@ static int move_module(struct module *mod, struct load_info *info)
88064 if (!(shdr->sh_flags & SHF_ALLOC))
88065 continue;
88066
88067- if (shdr->sh_entsize & INIT_OFFSET_MASK)
88068- dest = mod->module_init
88069- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
88070- else
88071- dest = mod->module_core + shdr->sh_entsize;
88072+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
88073+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
88074+ dest = mod->module_init_rw
88075+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
88076+ else
88077+ dest = mod->module_init_rx
88078+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
88079+ } else {
88080+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
88081+ dest = mod->module_core_rw + shdr->sh_entsize;
88082+ else
88083+ dest = mod->module_core_rx + shdr->sh_entsize;
88084+ }
88085+
88086+ if (shdr->sh_type != SHT_NOBITS) {
88087+
88088+#ifdef CONFIG_PAX_KERNEXEC
88089+#ifdef CONFIG_X86_64
88090+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
88091+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
88092+#endif
88093+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
88094+ pax_open_kernel();
88095+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
88096+ pax_close_kernel();
88097+ } else
88098+#endif
88099
88100- if (shdr->sh_type != SHT_NOBITS)
88101 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
88102+ }
88103 /* Update sh_addr to point to copy in image. */
88104- shdr->sh_addr = (unsigned long)dest;
88105+
88106+#ifdef CONFIG_PAX_KERNEXEC
88107+ if (shdr->sh_flags & SHF_EXECINSTR)
88108+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
88109+ else
88110+#endif
88111+
88112+ shdr->sh_addr = (unsigned long)dest;
88113 pr_debug("\t0x%lx %s\n",
88114 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
88115 }
88116@@ -2891,12 +3021,12 @@ static void flush_module_icache(const struct module *mod)
88117 * Do it before processing of module parameters, so the module
88118 * can provide parameter accessor functions of its own.
88119 */
88120- if (mod->module_init)
88121- flush_icache_range((unsigned long)mod->module_init,
88122- (unsigned long)mod->module_init
88123- + mod->init_size);
88124- flush_icache_range((unsigned long)mod->module_core,
88125- (unsigned long)mod->module_core + mod->core_size);
88126+ if (mod->module_init_rx)
88127+ flush_icache_range((unsigned long)mod->module_init_rx,
88128+ (unsigned long)mod->module_init_rx
88129+ + mod->init_size_rx);
88130+ flush_icache_range((unsigned long)mod->module_core_rx,
88131+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
88132
88133 set_fs(old_fs);
88134 }
88135@@ -2953,8 +3083,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
88136 static void module_deallocate(struct module *mod, struct load_info *info)
88137 {
88138 percpu_modfree(mod);
88139- module_free(mod, mod->module_init);
88140- module_free(mod, mod->module_core);
88141+ module_free_exec(mod, mod->module_init_rx);
88142+ module_free_exec(mod, mod->module_core_rx);
88143+ module_free(mod, mod->module_init_rw);
88144+ module_free(mod, mod->module_core_rw);
88145 }
88146
88147 int __weak module_finalize(const Elf_Ehdr *hdr,
88148@@ -2967,7 +3099,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
88149 static int post_relocation(struct module *mod, const struct load_info *info)
88150 {
88151 /* Sort exception table now relocations are done. */
88152+ pax_open_kernel();
88153 sort_extable(mod->extable, mod->extable + mod->num_exentries);
88154+ pax_close_kernel();
88155
88156 /* Copy relocated percpu area over. */
88157 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
88158@@ -3021,16 +3155,16 @@ static int do_init_module(struct module *mod)
88159 MODULE_STATE_COMING, mod);
88160
88161 /* Set RO and NX regions for core */
88162- set_section_ro_nx(mod->module_core,
88163- mod->core_text_size,
88164- mod->core_ro_size,
88165- mod->core_size);
88166+ set_section_ro_nx(mod->module_core_rx,
88167+ mod->core_size_rx,
88168+ mod->core_size_rx,
88169+ mod->core_size_rx);
88170
88171 /* Set RO and NX regions for init */
88172- set_section_ro_nx(mod->module_init,
88173- mod->init_text_size,
88174- mod->init_ro_size,
88175- mod->init_size);
88176+ set_section_ro_nx(mod->module_init_rx,
88177+ mod->init_size_rx,
88178+ mod->init_size_rx,
88179+ mod->init_size_rx);
88180
88181 do_mod_ctors(mod);
88182 /* Start the module */
88183@@ -3091,11 +3225,12 @@ static int do_init_module(struct module *mod)
88184 mod->strtab = mod->core_strtab;
88185 #endif
88186 unset_module_init_ro_nx(mod);
88187- module_free(mod, mod->module_init);
88188- mod->module_init = NULL;
88189- mod->init_size = 0;
88190- mod->init_ro_size = 0;
88191- mod->init_text_size = 0;
88192+ module_free(mod, mod->module_init_rw);
88193+ module_free_exec(mod, mod->module_init_rx);
88194+ mod->module_init_rw = NULL;
88195+ mod->module_init_rx = NULL;
88196+ mod->init_size_rw = 0;
88197+ mod->init_size_rx = 0;
88198 mutex_unlock(&module_mutex);
88199 wake_up_all(&module_wq);
88200
88201@@ -3238,9 +3373,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
88202 if (err)
88203 goto free_unload;
88204
88205+ /* Now copy in args */
88206+ mod->args = strndup_user(uargs, ~0UL >> 1);
88207+ if (IS_ERR(mod->args)) {
88208+ err = PTR_ERR(mod->args);
88209+ goto free_unload;
88210+ }
88211+
88212 /* Set up MODINFO_ATTR fields */
88213 setup_modinfo(mod, info);
88214
88215+#ifdef CONFIG_GRKERNSEC_MODHARDEN
88216+ {
88217+ char *p, *p2;
88218+
88219+ if (strstr(mod->args, "grsec_modharden_netdev")) {
88220+ 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);
88221+ err = -EPERM;
88222+ goto free_modinfo;
88223+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
88224+ p += sizeof("grsec_modharden_normal") - 1;
88225+ p2 = strstr(p, "_");
88226+ if (p2) {
88227+ *p2 = '\0';
88228+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
88229+ *p2 = '_';
88230+ }
88231+ err = -EPERM;
88232+ goto free_modinfo;
88233+ }
88234+ }
88235+#endif
88236+
88237 /* Fix up syms, so that st_value is a pointer to location. */
88238 err = simplify_symbols(mod, info);
88239 if (err < 0)
88240@@ -3256,13 +3420,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
88241
88242 flush_module_icache(mod);
88243
88244- /* Now copy in args */
88245- mod->args = strndup_user(uargs, ~0UL >> 1);
88246- if (IS_ERR(mod->args)) {
88247- err = PTR_ERR(mod->args);
88248- goto free_arch_cleanup;
88249- }
88250-
88251 dynamic_debug_setup(info->debug, info->num_debug);
88252
88253 /* Finally it's fully formed, ready to start executing. */
88254@@ -3297,11 +3454,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
88255 ddebug_cleanup:
88256 dynamic_debug_remove(info->debug);
88257 synchronize_sched();
88258- kfree(mod->args);
88259- free_arch_cleanup:
88260 module_arch_cleanup(mod);
88261 free_modinfo:
88262 free_modinfo(mod);
88263+ kfree(mod->args);
88264 free_unload:
88265 module_unload_free(mod);
88266 unlink_mod:
88267@@ -3384,10 +3540,16 @@ static const char *get_ksymbol(struct module *mod,
88268 unsigned long nextval;
88269
88270 /* At worse, next value is at end of module */
88271- if (within_module_init(addr, mod))
88272- nextval = (unsigned long)mod->module_init+mod->init_text_size;
88273+ if (within_module_init_rx(addr, mod))
88274+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
88275+ else if (within_module_init_rw(addr, mod))
88276+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
88277+ else if (within_module_core_rx(addr, mod))
88278+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
88279+ else if (within_module_core_rw(addr, mod))
88280+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
88281 else
88282- nextval = (unsigned long)mod->module_core+mod->core_text_size;
88283+ return NULL;
88284
88285 /* Scan for closest preceding symbol, and next symbol. (ELF
88286 starts real symbols at 1). */
88287@@ -3638,7 +3800,7 @@ static int m_show(struct seq_file *m, void *p)
88288 return 0;
88289
88290 seq_printf(m, "%s %u",
88291- mod->name, mod->init_size + mod->core_size);
88292+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
88293 print_unload_info(m, mod);
88294
88295 /* Informative for users. */
88296@@ -3647,7 +3809,7 @@ static int m_show(struct seq_file *m, void *p)
88297 mod->state == MODULE_STATE_COMING ? "Loading":
88298 "Live");
88299 /* Used by oprofile and other similar tools. */
88300- seq_printf(m, " 0x%pK", mod->module_core);
88301+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
88302
88303 /* Taints info */
88304 if (mod->taints)
88305@@ -3683,7 +3845,17 @@ static const struct file_operations proc_modules_operations = {
88306
88307 static int __init proc_modules_init(void)
88308 {
88309+#ifndef CONFIG_GRKERNSEC_HIDESYM
88310+#ifdef CONFIG_GRKERNSEC_PROC_USER
88311+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
88312+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
88313+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
88314+#else
88315 proc_create("modules", 0, NULL, &proc_modules_operations);
88316+#endif
88317+#else
88318+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
88319+#endif
88320 return 0;
88321 }
88322 module_init(proc_modules_init);
88323@@ -3744,14 +3916,14 @@ struct module *__module_address(unsigned long addr)
88324 {
88325 struct module *mod;
88326
88327- if (addr < module_addr_min || addr > module_addr_max)
88328+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
88329+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
88330 return NULL;
88331
88332 list_for_each_entry_rcu(mod, &modules, list) {
88333 if (mod->state == MODULE_STATE_UNFORMED)
88334 continue;
88335- if (within_module_core(addr, mod)
88336- || within_module_init(addr, mod))
88337+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
88338 return mod;
88339 }
88340 return NULL;
88341@@ -3786,11 +3958,20 @@ bool is_module_text_address(unsigned long addr)
88342 */
88343 struct module *__module_text_address(unsigned long addr)
88344 {
88345- struct module *mod = __module_address(addr);
88346+ struct module *mod;
88347+
88348+#ifdef CONFIG_X86_32
88349+ addr = ktla_ktva(addr);
88350+#endif
88351+
88352+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
88353+ return NULL;
88354+
88355+ mod = __module_address(addr);
88356+
88357 if (mod) {
88358 /* Make sure it's within the text section. */
88359- if (!within(addr, mod->module_init, mod->init_text_size)
88360- && !within(addr, mod->module_core, mod->core_text_size))
88361+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
88362 mod = NULL;
88363 }
88364 return mod;
88365diff --git a/kernel/notifier.c b/kernel/notifier.c
88366index 2d5cc4c..d9ea600 100644
88367--- a/kernel/notifier.c
88368+++ b/kernel/notifier.c
88369@@ -5,6 +5,7 @@
88370 #include <linux/rcupdate.h>
88371 #include <linux/vmalloc.h>
88372 #include <linux/reboot.h>
88373+#include <linux/mm.h>
88374
88375 /*
88376 * Notifier list for kernel code which wants to be called
88377@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
88378 while ((*nl) != NULL) {
88379 if (n->priority > (*nl)->priority)
88380 break;
88381- nl = &((*nl)->next);
88382+ nl = (struct notifier_block **)&((*nl)->next);
88383 }
88384- n->next = *nl;
88385+ pax_open_kernel();
88386+ *(const void **)&n->next = *nl;
88387 rcu_assign_pointer(*nl, n);
88388+ pax_close_kernel();
88389 return 0;
88390 }
88391
88392@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
88393 return 0;
88394 if (n->priority > (*nl)->priority)
88395 break;
88396- nl = &((*nl)->next);
88397+ nl = (struct notifier_block **)&((*nl)->next);
88398 }
88399- n->next = *nl;
88400+ pax_open_kernel();
88401+ *(const void **)&n->next = *nl;
88402 rcu_assign_pointer(*nl, n);
88403+ pax_close_kernel();
88404 return 0;
88405 }
88406
88407@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
88408 {
88409 while ((*nl) != NULL) {
88410 if ((*nl) == n) {
88411+ pax_open_kernel();
88412 rcu_assign_pointer(*nl, n->next);
88413+ pax_close_kernel();
88414 return 0;
88415 }
88416- nl = &((*nl)->next);
88417+ nl = (struct notifier_block **)&((*nl)->next);
88418 }
88419 return -ENOENT;
88420 }
88421diff --git a/kernel/padata.c b/kernel/padata.c
88422index 161402f..598814c 100644
88423--- a/kernel/padata.c
88424+++ b/kernel/padata.c
88425@@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
88426 * seq_nr mod. number of cpus in use.
88427 */
88428
88429- seq_nr = atomic_inc_return(&pd->seq_nr);
88430+ seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
88431 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
88432
88433 return padata_index_to_cpu(pd, cpu_index);
88434@@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
88435 padata_init_pqueues(pd);
88436 padata_init_squeues(pd);
88437 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
88438- atomic_set(&pd->seq_nr, -1);
88439+ atomic_set_unchecked(&pd->seq_nr, -1);
88440 atomic_set(&pd->reorder_objects, 0);
88441 atomic_set(&pd->refcnt, 0);
88442 pd->pinst = pinst;
88443diff --git a/kernel/panic.c b/kernel/panic.c
88444index 6d63003..486a109 100644
88445--- a/kernel/panic.c
88446+++ b/kernel/panic.c
88447@@ -52,7 +52,7 @@ EXPORT_SYMBOL(panic_blink);
88448 /*
88449 * Stop ourself in panic -- architecture code may override this
88450 */
88451-void __weak panic_smp_self_stop(void)
88452+void __weak __noreturn panic_smp_self_stop(void)
88453 {
88454 while (1)
88455 cpu_relax();
88456@@ -407,7 +407,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
88457 disable_trace_on_warning();
88458
88459 pr_warn("------------[ cut here ]------------\n");
88460- pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
88461+ pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
88462 raw_smp_processor_id(), current->pid, file, line, caller);
88463
88464 if (args)
88465@@ -461,7 +461,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
88466 */
88467 void __stack_chk_fail(void)
88468 {
88469- panic("stack-protector: Kernel stack is corrupted in: %p\n",
88470+ dump_stack();
88471+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
88472 __builtin_return_address(0));
88473 }
88474 EXPORT_SYMBOL(__stack_chk_fail);
88475diff --git a/kernel/pid.c b/kernel/pid.c
88476index 9b9a266..c20ef80 100644
88477--- a/kernel/pid.c
88478+++ b/kernel/pid.c
88479@@ -33,6 +33,7 @@
88480 #include <linux/rculist.h>
88481 #include <linux/bootmem.h>
88482 #include <linux/hash.h>
88483+#include <linux/security.h>
88484 #include <linux/pid_namespace.h>
88485 #include <linux/init_task.h>
88486 #include <linux/syscalls.h>
88487@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
88488
88489 int pid_max = PID_MAX_DEFAULT;
88490
88491-#define RESERVED_PIDS 300
88492+#define RESERVED_PIDS 500
88493
88494 int pid_max_min = RESERVED_PIDS + 1;
88495 int pid_max_max = PID_MAX_LIMIT;
88496@@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
88497 */
88498 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
88499 {
88500+ struct task_struct *task;
88501+
88502 rcu_lockdep_assert(rcu_read_lock_held(),
88503 "find_task_by_pid_ns() needs rcu_read_lock()"
88504 " protection");
88505- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
88506+
88507+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
88508+
88509+ if (gr_pid_is_chrooted(task))
88510+ return NULL;
88511+
88512+ return task;
88513 }
88514
88515 struct task_struct *find_task_by_vpid(pid_t vnr)
88516@@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
88517 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
88518 }
88519
88520+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
88521+{
88522+ rcu_lockdep_assert(rcu_read_lock_held(),
88523+ "find_task_by_pid_ns() needs rcu_read_lock()"
88524+ " protection");
88525+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
88526+}
88527+
88528 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
88529 {
88530 struct pid *pid;
88531diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
88532index db95d8e..a0ca23f 100644
88533--- a/kernel/pid_namespace.c
88534+++ b/kernel/pid_namespace.c
88535@@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
88536 void __user *buffer, size_t *lenp, loff_t *ppos)
88537 {
88538 struct pid_namespace *pid_ns = task_active_pid_ns(current);
88539- struct ctl_table tmp = *table;
88540+ ctl_table_no_const tmp = *table;
88541
88542 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
88543 return -EPERM;
88544diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
88545index 3b89464..5e38379 100644
88546--- a/kernel/posix-cpu-timers.c
88547+++ b/kernel/posix-cpu-timers.c
88548@@ -1464,14 +1464,14 @@ struct k_clock clock_posix_cpu = {
88549
88550 static __init int init_posix_cpu_timers(void)
88551 {
88552- struct k_clock process = {
88553+ static struct k_clock process = {
88554 .clock_getres = process_cpu_clock_getres,
88555 .clock_get = process_cpu_clock_get,
88556 .timer_create = process_cpu_timer_create,
88557 .nsleep = process_cpu_nsleep,
88558 .nsleep_restart = process_cpu_nsleep_restart,
88559 };
88560- struct k_clock thread = {
88561+ static struct k_clock thread = {
88562 .clock_getres = thread_cpu_clock_getres,
88563 .clock_get = thread_cpu_clock_get,
88564 .timer_create = thread_cpu_timer_create,
88565diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
88566index 424c2d4..679242f 100644
88567--- a/kernel/posix-timers.c
88568+++ b/kernel/posix-timers.c
88569@@ -43,6 +43,7 @@
88570 #include <linux/hash.h>
88571 #include <linux/posix-clock.h>
88572 #include <linux/posix-timers.h>
88573+#include <linux/grsecurity.h>
88574 #include <linux/syscalls.h>
88575 #include <linux/wait.h>
88576 #include <linux/workqueue.h>
88577@@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
88578 * which we beg off on and pass to do_sys_settimeofday().
88579 */
88580
88581-static struct k_clock posix_clocks[MAX_CLOCKS];
88582+static struct k_clock *posix_clocks[MAX_CLOCKS];
88583
88584 /*
88585 * These ones are defined below.
88586@@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
88587 */
88588 static __init int init_posix_timers(void)
88589 {
88590- struct k_clock clock_realtime = {
88591+ static struct k_clock clock_realtime = {
88592 .clock_getres = hrtimer_get_res,
88593 .clock_get = posix_clock_realtime_get,
88594 .clock_set = posix_clock_realtime_set,
88595@@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
88596 .timer_get = common_timer_get,
88597 .timer_del = common_timer_del,
88598 };
88599- struct k_clock clock_monotonic = {
88600+ static struct k_clock clock_monotonic = {
88601 .clock_getres = hrtimer_get_res,
88602 .clock_get = posix_ktime_get_ts,
88603 .nsleep = common_nsleep,
88604@@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
88605 .timer_get = common_timer_get,
88606 .timer_del = common_timer_del,
88607 };
88608- struct k_clock clock_monotonic_raw = {
88609+ static struct k_clock clock_monotonic_raw = {
88610 .clock_getres = hrtimer_get_res,
88611 .clock_get = posix_get_monotonic_raw,
88612 };
88613- struct k_clock clock_realtime_coarse = {
88614+ static struct k_clock clock_realtime_coarse = {
88615 .clock_getres = posix_get_coarse_res,
88616 .clock_get = posix_get_realtime_coarse,
88617 };
88618- struct k_clock clock_monotonic_coarse = {
88619+ static struct k_clock clock_monotonic_coarse = {
88620 .clock_getres = posix_get_coarse_res,
88621 .clock_get = posix_get_monotonic_coarse,
88622 };
88623- struct k_clock clock_tai = {
88624+ static struct k_clock clock_tai = {
88625 .clock_getres = hrtimer_get_res,
88626 .clock_get = posix_get_tai,
88627 .nsleep = common_nsleep,
88628@@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
88629 .timer_get = common_timer_get,
88630 .timer_del = common_timer_del,
88631 };
88632- struct k_clock clock_boottime = {
88633+ static struct k_clock clock_boottime = {
88634 .clock_getres = hrtimer_get_res,
88635 .clock_get = posix_get_boottime,
88636 .nsleep = common_nsleep,
88637@@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
88638 return;
88639 }
88640
88641- posix_clocks[clock_id] = *new_clock;
88642+ posix_clocks[clock_id] = new_clock;
88643 }
88644 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
88645
88646@@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
88647 return (id & CLOCKFD_MASK) == CLOCKFD ?
88648 &clock_posix_dynamic : &clock_posix_cpu;
88649
88650- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
88651+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
88652 return NULL;
88653- return &posix_clocks[id];
88654+ return posix_clocks[id];
88655 }
88656
88657 static int common_timer_create(struct k_itimer *new_timer)
88658@@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
88659 struct k_clock *kc = clockid_to_kclock(which_clock);
88660 struct k_itimer *new_timer;
88661 int error, new_timer_id;
88662- sigevent_t event;
88663+ sigevent_t event = { };
88664 int it_id_set = IT_ID_NOT_SET;
88665
88666 if (!kc)
88667@@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
88668 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
88669 return -EFAULT;
88670
88671+ /* only the CLOCK_REALTIME clock can be set, all other clocks
88672+ have their clock_set fptr set to a nosettime dummy function
88673+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
88674+ call common_clock_set, which calls do_sys_settimeofday, which
88675+ we hook
88676+ */
88677+
88678 return kc->clock_set(which_clock, &new_tp);
88679 }
88680
88681diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
88682index 2fac9cc..56fef29 100644
88683--- a/kernel/power/Kconfig
88684+++ b/kernel/power/Kconfig
88685@@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
88686 config HIBERNATION
88687 bool "Hibernation (aka 'suspend to disk')"
88688 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
88689+ depends on !GRKERNSEC_KMEM
88690+ depends on !PAX_MEMORY_SANITIZE
88691 select HIBERNATE_CALLBACKS
88692 select LZO_COMPRESS
88693 select LZO_DECOMPRESS
88694diff --git a/kernel/power/process.c b/kernel/power/process.c
88695index 06ec886..9dba35e 100644
88696--- a/kernel/power/process.c
88697+++ b/kernel/power/process.c
88698@@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
88699 unsigned int elapsed_msecs;
88700 bool wakeup = false;
88701 int sleep_usecs = USEC_PER_MSEC;
88702+ bool timedout = false;
88703
88704 do_gettimeofday(&start);
88705
88706@@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
88707
88708 while (true) {
88709 todo = 0;
88710+ if (time_after(jiffies, end_time))
88711+ timedout = true;
88712 read_lock(&tasklist_lock);
88713 do_each_thread(g, p) {
88714 if (p == current || !freeze_task(p))
88715 continue;
88716
88717- if (!freezer_should_skip(p))
88718+ if (!freezer_should_skip(p)) {
88719 todo++;
88720+ if (timedout) {
88721+ printk(KERN_ERR "Task refusing to freeze:\n");
88722+ sched_show_task(p);
88723+ }
88724+ }
88725 } while_each_thread(g, p);
88726 read_unlock(&tasklist_lock);
88727
88728@@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
88729 todo += wq_busy;
88730 }
88731
88732- if (!todo || time_after(jiffies, end_time))
88733+ if (!todo || timedout)
88734 break;
88735
88736 if (pm_wakeup_pending()) {
88737diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
88738index 4dae9cb..039ffbb 100644
88739--- a/kernel/printk/printk.c
88740+++ b/kernel/printk/printk.c
88741@@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
88742 if (from_file && type != SYSLOG_ACTION_OPEN)
88743 return 0;
88744
88745+#ifdef CONFIG_GRKERNSEC_DMESG
88746+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
88747+ return -EPERM;
88748+#endif
88749+
88750 if (syslog_action_restricted(type)) {
88751 if (capable(CAP_SYSLOG))
88752 return 0;
88753diff --git a/kernel/profile.c b/kernel/profile.c
88754index ebdd9c1..612ee05 100644
88755--- a/kernel/profile.c
88756+++ b/kernel/profile.c
88757@@ -37,7 +37,7 @@ struct profile_hit {
88758 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
88759 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
88760
88761-static atomic_t *prof_buffer;
88762+static atomic_unchecked_t *prof_buffer;
88763 static unsigned long prof_len, prof_shift;
88764
88765 int prof_on __read_mostly;
88766@@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
88767 hits[i].pc = 0;
88768 continue;
88769 }
88770- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
88771+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
88772 hits[i].hits = hits[i].pc = 0;
88773 }
88774 }
88775@@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
88776 * Add the current hit(s) and flush the write-queue out
88777 * to the global buffer:
88778 */
88779- atomic_add(nr_hits, &prof_buffer[pc]);
88780+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
88781 for (i = 0; i < NR_PROFILE_HIT; ++i) {
88782- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
88783+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
88784 hits[i].pc = hits[i].hits = 0;
88785 }
88786 out:
88787@@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
88788 {
88789 unsigned long pc;
88790 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
88791- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
88792+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
88793 }
88794 #endif /* !CONFIG_SMP */
88795
88796@@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
88797 return -EFAULT;
88798 buf++; p++; count--; read++;
88799 }
88800- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
88801+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
88802 if (copy_to_user(buf, (void *)pnt, count))
88803 return -EFAULT;
88804 read += count;
88805@@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
88806 }
88807 #endif
88808 profile_discard_flip_buffers();
88809- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
88810+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
88811 return count;
88812 }
88813
88814diff --git a/kernel/ptrace.c b/kernel/ptrace.c
88815index 1f4bcb3..99cf7ab 100644
88816--- a/kernel/ptrace.c
88817+++ b/kernel/ptrace.c
88818@@ -327,7 +327,7 @@ static int ptrace_attach(struct task_struct *task, long request,
88819 if (seize)
88820 flags |= PT_SEIZED;
88821 rcu_read_lock();
88822- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
88823+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
88824 flags |= PT_PTRACE_CAP;
88825 rcu_read_unlock();
88826 task->ptrace = flags;
88827@@ -538,7 +538,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
88828 break;
88829 return -EIO;
88830 }
88831- if (copy_to_user(dst, buf, retval))
88832+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
88833 return -EFAULT;
88834 copied += retval;
88835 src += retval;
88836@@ -806,7 +806,7 @@ int ptrace_request(struct task_struct *child, long request,
88837 bool seized = child->ptrace & PT_SEIZED;
88838 int ret = -EIO;
88839 siginfo_t siginfo, *si;
88840- void __user *datavp = (void __user *) data;
88841+ void __user *datavp = (__force void __user *) data;
88842 unsigned long __user *datalp = datavp;
88843 unsigned long flags;
88844
88845@@ -1052,14 +1052,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
88846 goto out;
88847 }
88848
88849+ if (gr_handle_ptrace(child, request)) {
88850+ ret = -EPERM;
88851+ goto out_put_task_struct;
88852+ }
88853+
88854 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
88855 ret = ptrace_attach(child, request, addr, data);
88856 /*
88857 * Some architectures need to do book-keeping after
88858 * a ptrace attach.
88859 */
88860- if (!ret)
88861+ if (!ret) {
88862 arch_ptrace_attach(child);
88863+ gr_audit_ptrace(child);
88864+ }
88865 goto out_put_task_struct;
88866 }
88867
88868@@ -1087,7 +1094,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
88869 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
88870 if (copied != sizeof(tmp))
88871 return -EIO;
88872- return put_user(tmp, (unsigned long __user *)data);
88873+ return put_user(tmp, (__force unsigned long __user *)data);
88874 }
88875
88876 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
88877@@ -1181,7 +1188,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
88878 }
88879
88880 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
88881- compat_long_t addr, compat_long_t data)
88882+ compat_ulong_t addr, compat_ulong_t data)
88883 {
88884 struct task_struct *child;
88885 long ret;
88886@@ -1197,14 +1204,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
88887 goto out;
88888 }
88889
88890+ if (gr_handle_ptrace(child, request)) {
88891+ ret = -EPERM;
88892+ goto out_put_task_struct;
88893+ }
88894+
88895 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
88896 ret = ptrace_attach(child, request, addr, data);
88897 /*
88898 * Some architectures need to do book-keeping after
88899 * a ptrace attach.
88900 */
88901- if (!ret)
88902+ if (!ret) {
88903 arch_ptrace_attach(child);
88904+ gr_audit_ptrace(child);
88905+ }
88906 goto out_put_task_struct;
88907 }
88908
88909diff --git a/kernel/rcu/srcu.c b/kernel/rcu/srcu.c
88910index 3318d82..1a5b2d1 100644
88911--- a/kernel/rcu/srcu.c
88912+++ b/kernel/rcu/srcu.c
88913@@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
88914
88915 idx = ACCESS_ONCE(sp->completed) & 0x1;
88916 preempt_disable();
88917- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
88918+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
88919 smp_mb(); /* B */ /* Avoid leaking the critical section. */
88920- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
88921+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
88922 preempt_enable();
88923 return idx;
88924 }
88925diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
88926index 1254f31..16258dc 100644
88927--- a/kernel/rcu/tiny.c
88928+++ b/kernel/rcu/tiny.c
88929@@ -46,7 +46,7 @@
88930 /* Forward declarations for tiny_plugin.h. */
88931 struct rcu_ctrlblk;
88932 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
88933-static void rcu_process_callbacks(struct softirq_action *unused);
88934+static void rcu_process_callbacks(void);
88935 static void __call_rcu(struct rcu_head *head,
88936 void (*func)(struct rcu_head *rcu),
88937 struct rcu_ctrlblk *rcp);
88938@@ -312,7 +312,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
88939 false));
88940 }
88941
88942-static void rcu_process_callbacks(struct softirq_action *unused)
88943+static __latent_entropy void rcu_process_callbacks(void)
88944 {
88945 __rcu_process_callbacks(&rcu_sched_ctrlblk);
88946 __rcu_process_callbacks(&rcu_bh_ctrlblk);
88947diff --git a/kernel/rcu/torture.c b/kernel/rcu/torture.c
88948index 732f8ae..42c1919 100644
88949--- a/kernel/rcu/torture.c
88950+++ b/kernel/rcu/torture.c
88951@@ -174,12 +174,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
88952 { 0 };
88953 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
88954 { 0 };
88955-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
88956-static atomic_t n_rcu_torture_alloc;
88957-static atomic_t n_rcu_torture_alloc_fail;
88958-static atomic_t n_rcu_torture_free;
88959-static atomic_t n_rcu_torture_mberror;
88960-static atomic_t n_rcu_torture_error;
88961+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
88962+static atomic_unchecked_t n_rcu_torture_alloc;
88963+static atomic_unchecked_t n_rcu_torture_alloc_fail;
88964+static atomic_unchecked_t n_rcu_torture_free;
88965+static atomic_unchecked_t n_rcu_torture_mberror;
88966+static atomic_unchecked_t n_rcu_torture_error;
88967 static long n_rcu_torture_barrier_error;
88968 static long n_rcu_torture_boost_ktrerror;
88969 static long n_rcu_torture_boost_rterror;
88970@@ -297,11 +297,11 @@ rcu_torture_alloc(void)
88971
88972 spin_lock_bh(&rcu_torture_lock);
88973 if (list_empty(&rcu_torture_freelist)) {
88974- atomic_inc(&n_rcu_torture_alloc_fail);
88975+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
88976 spin_unlock_bh(&rcu_torture_lock);
88977 return NULL;
88978 }
88979- atomic_inc(&n_rcu_torture_alloc);
88980+ atomic_inc_unchecked(&n_rcu_torture_alloc);
88981 p = rcu_torture_freelist.next;
88982 list_del_init(p);
88983 spin_unlock_bh(&rcu_torture_lock);
88984@@ -314,7 +314,7 @@ rcu_torture_alloc(void)
88985 static void
88986 rcu_torture_free(struct rcu_torture *p)
88987 {
88988- atomic_inc(&n_rcu_torture_free);
88989+ atomic_inc_unchecked(&n_rcu_torture_free);
88990 spin_lock_bh(&rcu_torture_lock);
88991 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
88992 spin_unlock_bh(&rcu_torture_lock);
88993@@ -435,7 +435,7 @@ rcu_torture_cb(struct rcu_head *p)
88994 i = rp->rtort_pipe_count;
88995 if (i > RCU_TORTURE_PIPE_LEN)
88996 i = RCU_TORTURE_PIPE_LEN;
88997- atomic_inc(&rcu_torture_wcount[i]);
88998+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
88999 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
89000 rp->rtort_mbtest = 0;
89001 rcu_torture_free(rp);
89002@@ -823,7 +823,7 @@ rcu_torture_writer(void *arg)
89003 i = old_rp->rtort_pipe_count;
89004 if (i > RCU_TORTURE_PIPE_LEN)
89005 i = RCU_TORTURE_PIPE_LEN;
89006- atomic_inc(&rcu_torture_wcount[i]);
89007+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
89008 old_rp->rtort_pipe_count++;
89009 if (gp_normal == gp_exp)
89010 exp = !!(rcu_random(&rand) & 0x80);
89011@@ -841,7 +841,7 @@ rcu_torture_writer(void *arg)
89012 i = rp->rtort_pipe_count;
89013 if (i > RCU_TORTURE_PIPE_LEN)
89014 i = RCU_TORTURE_PIPE_LEN;
89015- atomic_inc(&rcu_torture_wcount[i]);
89016+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
89017 if (++rp->rtort_pipe_count >=
89018 RCU_TORTURE_PIPE_LEN) {
89019 rp->rtort_mbtest = 0;
89020@@ -940,7 +940,7 @@ static void rcu_torture_timer(unsigned long unused)
89021 return;
89022 }
89023 if (p->rtort_mbtest == 0)
89024- atomic_inc(&n_rcu_torture_mberror);
89025+ atomic_inc_unchecked(&n_rcu_torture_mberror);
89026 spin_lock(&rand_lock);
89027 cur_ops->read_delay(&rand);
89028 n_rcu_torture_timers++;
89029@@ -1010,7 +1010,7 @@ rcu_torture_reader(void *arg)
89030 continue;
89031 }
89032 if (p->rtort_mbtest == 0)
89033- atomic_inc(&n_rcu_torture_mberror);
89034+ atomic_inc_unchecked(&n_rcu_torture_mberror);
89035 cur_ops->read_delay(&rand);
89036 preempt_disable();
89037 pipe_count = p->rtort_pipe_count;
89038@@ -1068,15 +1068,15 @@ rcu_torture_printk(char *page)
89039 }
89040 page += sprintf(page, "%s%s ", torture_type, TORTURE_FLAG);
89041 page += sprintf(page,
89042- "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
89043+ "rtc: %pP ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
89044 rcu_torture_current,
89045 rcu_torture_current_version,
89046 list_empty(&rcu_torture_freelist),
89047- atomic_read(&n_rcu_torture_alloc),
89048- atomic_read(&n_rcu_torture_alloc_fail),
89049- atomic_read(&n_rcu_torture_free));
89050+ atomic_read_unchecked(&n_rcu_torture_alloc),
89051+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
89052+ atomic_read_unchecked(&n_rcu_torture_free));
89053 page += sprintf(page, "rtmbe: %d rtbke: %ld rtbre: %ld ",
89054- atomic_read(&n_rcu_torture_mberror),
89055+ atomic_read_unchecked(&n_rcu_torture_mberror),
89056 n_rcu_torture_boost_ktrerror,
89057 n_rcu_torture_boost_rterror);
89058 page += sprintf(page, "rtbf: %ld rtb: %ld nt: %ld ",
89059@@ -1095,14 +1095,14 @@ rcu_torture_printk(char *page)
89060 n_barrier_attempts,
89061 n_rcu_torture_barrier_error);
89062 page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG);
89063- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
89064+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
89065 n_rcu_torture_barrier_error != 0 ||
89066 n_rcu_torture_boost_ktrerror != 0 ||
89067 n_rcu_torture_boost_rterror != 0 ||
89068 n_rcu_torture_boost_failure != 0 ||
89069 i > 1) {
89070 page += sprintf(page, "!!! ");
89071- atomic_inc(&n_rcu_torture_error);
89072+ atomic_inc_unchecked(&n_rcu_torture_error);
89073 WARN_ON_ONCE(1);
89074 }
89075 page += sprintf(page, "Reader Pipe: ");
89076@@ -1116,7 +1116,7 @@ rcu_torture_printk(char *page)
89077 page += sprintf(page, "Free-Block Circulation: ");
89078 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
89079 page += sprintf(page, " %d",
89080- atomic_read(&rcu_torture_wcount[i]));
89081+ atomic_read_unchecked(&rcu_torture_wcount[i]));
89082 }
89083 page += sprintf(page, "\n");
89084 if (cur_ops->stats)
89085@@ -1839,7 +1839,7 @@ rcu_torture_cleanup(void)
89086
89087 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
89088
89089- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
89090+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
89091 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
89092 else if (n_online_successes != n_online_attempts ||
89093 n_offline_successes != n_offline_attempts)
89094@@ -1961,18 +1961,18 @@ rcu_torture_init(void)
89095
89096 rcu_torture_current = NULL;
89097 rcu_torture_current_version = 0;
89098- atomic_set(&n_rcu_torture_alloc, 0);
89099- atomic_set(&n_rcu_torture_alloc_fail, 0);
89100- atomic_set(&n_rcu_torture_free, 0);
89101- atomic_set(&n_rcu_torture_mberror, 0);
89102- atomic_set(&n_rcu_torture_error, 0);
89103+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
89104+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
89105+ atomic_set_unchecked(&n_rcu_torture_free, 0);
89106+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
89107+ atomic_set_unchecked(&n_rcu_torture_error, 0);
89108 n_rcu_torture_barrier_error = 0;
89109 n_rcu_torture_boost_ktrerror = 0;
89110 n_rcu_torture_boost_rterror = 0;
89111 n_rcu_torture_boost_failure = 0;
89112 n_rcu_torture_boosts = 0;
89113 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
89114- atomic_set(&rcu_torture_wcount[i], 0);
89115+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
89116 for_each_possible_cpu(cpu) {
89117 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
89118 per_cpu(rcu_torture_count, cpu)[i] = 0;
89119diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
89120index b3d116c..ebf6598 100644
89121--- a/kernel/rcu/tree.c
89122+++ b/kernel/rcu/tree.c
89123@@ -390,9 +390,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
89124 rcu_prepare_for_idle(smp_processor_id());
89125 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
89126 smp_mb__before_atomic_inc(); /* See above. */
89127- atomic_inc(&rdtp->dynticks);
89128+ atomic_inc_unchecked(&rdtp->dynticks);
89129 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
89130- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
89131+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
89132
89133 /*
89134 * It is illegal to enter an extended quiescent state while
89135@@ -510,10 +510,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
89136 int user)
89137 {
89138 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
89139- atomic_inc(&rdtp->dynticks);
89140+ atomic_inc_unchecked(&rdtp->dynticks);
89141 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
89142 smp_mb__after_atomic_inc(); /* See above. */
89143- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
89144+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
89145 rcu_cleanup_after_idle(smp_processor_id());
89146 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
89147 if (!user && !is_idle_task(current)) {
89148@@ -634,14 +634,14 @@ void rcu_nmi_enter(void)
89149 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
89150
89151 if (rdtp->dynticks_nmi_nesting == 0 &&
89152- (atomic_read(&rdtp->dynticks) & 0x1))
89153+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
89154 return;
89155 rdtp->dynticks_nmi_nesting++;
89156 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
89157- atomic_inc(&rdtp->dynticks);
89158+ atomic_inc_unchecked(&rdtp->dynticks);
89159 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
89160 smp_mb__after_atomic_inc(); /* See above. */
89161- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
89162+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
89163 }
89164
89165 /**
89166@@ -660,9 +660,9 @@ void rcu_nmi_exit(void)
89167 return;
89168 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
89169 smp_mb__before_atomic_inc(); /* See above. */
89170- atomic_inc(&rdtp->dynticks);
89171+ atomic_inc_unchecked(&rdtp->dynticks);
89172 smp_mb__after_atomic_inc(); /* Force delay to next write. */
89173- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
89174+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
89175 }
89176
89177 /**
89178@@ -675,7 +675,7 @@ void rcu_nmi_exit(void)
89179 */
89180 bool notrace __rcu_is_watching(void)
89181 {
89182- return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
89183+ return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
89184 }
89185
89186 /**
89187@@ -758,7 +758,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
89188 static int dyntick_save_progress_counter(struct rcu_data *rdp,
89189 bool *isidle, unsigned long *maxj)
89190 {
89191- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
89192+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
89193 rcu_sysidle_check_cpu(rdp, isidle, maxj);
89194 return (rdp->dynticks_snap & 0x1) == 0;
89195 }
89196@@ -781,7 +781,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
89197 unsigned int curr;
89198 unsigned int snap;
89199
89200- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
89201+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
89202 snap = (unsigned int)rdp->dynticks_snap;
89203
89204 /*
89205@@ -1450,9 +1450,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
89206 rdp = this_cpu_ptr(rsp->rda);
89207 rcu_preempt_check_blocked_tasks(rnp);
89208 rnp->qsmask = rnp->qsmaskinit;
89209- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
89210+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
89211 WARN_ON_ONCE(rnp->completed != rsp->completed);
89212- ACCESS_ONCE(rnp->completed) = rsp->completed;
89213+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
89214 if (rnp == rdp->mynode)
89215 __note_gp_changes(rsp, rnp, rdp);
89216 rcu_preempt_boost_start_gp(rnp);
89217@@ -1546,7 +1546,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
89218 rcu_for_each_node_breadth_first(rsp, rnp) {
89219 raw_spin_lock_irq(&rnp->lock);
89220 smp_mb__after_unlock_lock();
89221- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
89222+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
89223 rdp = this_cpu_ptr(rsp->rda);
89224 if (rnp == rdp->mynode)
89225 __note_gp_changes(rsp, rnp, rdp);
89226@@ -1912,7 +1912,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
89227 rsp->qlen += rdp->qlen;
89228 rdp->n_cbs_orphaned += rdp->qlen;
89229 rdp->qlen_lazy = 0;
89230- ACCESS_ONCE(rdp->qlen) = 0;
89231+ ACCESS_ONCE_RW(rdp->qlen) = 0;
89232 }
89233
89234 /*
89235@@ -2159,7 +2159,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
89236 }
89237 smp_mb(); /* List handling before counting for rcu_barrier(). */
89238 rdp->qlen_lazy -= count_lazy;
89239- ACCESS_ONCE(rdp->qlen) -= count;
89240+ ACCESS_ONCE_RW(rdp->qlen) -= count;
89241 rdp->n_cbs_invoked += count;
89242
89243 /* Reinstate batch limit if we have worked down the excess. */
89244@@ -2362,7 +2362,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
89245 /*
89246 * Do RCU core processing for the current CPU.
89247 */
89248-static void rcu_process_callbacks(struct softirq_action *unused)
89249+static void rcu_process_callbacks(void)
89250 {
89251 struct rcu_state *rsp;
89252
89253@@ -2470,7 +2470,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
89254 WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
89255 if (debug_rcu_head_queue(head)) {
89256 /* Probable double call_rcu(), so leak the callback. */
89257- ACCESS_ONCE(head->func) = rcu_leak_callback;
89258+ ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
89259 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
89260 return;
89261 }
89262@@ -2498,7 +2498,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
89263 local_irq_restore(flags);
89264 return;
89265 }
89266- ACCESS_ONCE(rdp->qlen)++;
89267+ ACCESS_ONCE_RW(rdp->qlen)++;
89268 if (lazy)
89269 rdp->qlen_lazy++;
89270 else
89271@@ -2707,11 +2707,11 @@ void synchronize_sched_expedited(void)
89272 * counter wrap on a 32-bit system. Quite a few more CPUs would of
89273 * course be required on a 64-bit system.
89274 */
89275- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
89276+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
89277 (ulong)atomic_long_read(&rsp->expedited_done) +
89278 ULONG_MAX / 8)) {
89279 synchronize_sched();
89280- atomic_long_inc(&rsp->expedited_wrap);
89281+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
89282 return;
89283 }
89284
89285@@ -2719,7 +2719,7 @@ void synchronize_sched_expedited(void)
89286 * Take a ticket. Note that atomic_inc_return() implies a
89287 * full memory barrier.
89288 */
89289- snap = atomic_long_inc_return(&rsp->expedited_start);
89290+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
89291 firstsnap = snap;
89292 get_online_cpus();
89293 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
89294@@ -2732,14 +2732,14 @@ void synchronize_sched_expedited(void)
89295 synchronize_sched_expedited_cpu_stop,
89296 NULL) == -EAGAIN) {
89297 put_online_cpus();
89298- atomic_long_inc(&rsp->expedited_tryfail);
89299+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
89300
89301 /* Check to see if someone else did our work for us. */
89302 s = atomic_long_read(&rsp->expedited_done);
89303 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
89304 /* ensure test happens before caller kfree */
89305 smp_mb__before_atomic_inc(); /* ^^^ */
89306- atomic_long_inc(&rsp->expedited_workdone1);
89307+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
89308 return;
89309 }
89310
89311@@ -2748,7 +2748,7 @@ void synchronize_sched_expedited(void)
89312 udelay(trycount * num_online_cpus());
89313 } else {
89314 wait_rcu_gp(call_rcu_sched);
89315- atomic_long_inc(&rsp->expedited_normal);
89316+ atomic_long_inc_unchecked(&rsp->expedited_normal);
89317 return;
89318 }
89319
89320@@ -2757,7 +2757,7 @@ void synchronize_sched_expedited(void)
89321 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
89322 /* ensure test happens before caller kfree */
89323 smp_mb__before_atomic_inc(); /* ^^^ */
89324- atomic_long_inc(&rsp->expedited_workdone2);
89325+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
89326 return;
89327 }
89328
89329@@ -2769,10 +2769,10 @@ void synchronize_sched_expedited(void)
89330 * period works for us.
89331 */
89332 get_online_cpus();
89333- snap = atomic_long_read(&rsp->expedited_start);
89334+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
89335 smp_mb(); /* ensure read is before try_stop_cpus(). */
89336 }
89337- atomic_long_inc(&rsp->expedited_stoppedcpus);
89338+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
89339
89340 /*
89341 * Everyone up to our most recent fetch is covered by our grace
89342@@ -2781,16 +2781,16 @@ void synchronize_sched_expedited(void)
89343 * than we did already did their update.
89344 */
89345 do {
89346- atomic_long_inc(&rsp->expedited_done_tries);
89347+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
89348 s = atomic_long_read(&rsp->expedited_done);
89349 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
89350 /* ensure test happens before caller kfree */
89351 smp_mb__before_atomic_inc(); /* ^^^ */
89352- atomic_long_inc(&rsp->expedited_done_lost);
89353+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
89354 break;
89355 }
89356 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
89357- atomic_long_inc(&rsp->expedited_done_exit);
89358+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
89359
89360 put_online_cpus();
89361 }
89362@@ -2996,7 +2996,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
89363 * ACCESS_ONCE() to prevent the compiler from speculating
89364 * the increment to precede the early-exit check.
89365 */
89366- ACCESS_ONCE(rsp->n_barrier_done)++;
89367+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
89368 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
89369 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
89370 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
89371@@ -3046,7 +3046,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
89372
89373 /* Increment ->n_barrier_done to prevent duplicate work. */
89374 smp_mb(); /* Keep increment after above mechanism. */
89375- ACCESS_ONCE(rsp->n_barrier_done)++;
89376+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
89377 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
89378 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
89379 smp_mb(); /* Keep increment before caller's subsequent code. */
89380@@ -3091,10 +3091,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
89381 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
89382 init_callback_list(rdp);
89383 rdp->qlen_lazy = 0;
89384- ACCESS_ONCE(rdp->qlen) = 0;
89385+ ACCESS_ONCE_RW(rdp->qlen) = 0;
89386 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
89387 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
89388- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
89389+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
89390 rdp->cpu = cpu;
89391 rdp->rsp = rsp;
89392 rcu_boot_init_nocb_percpu_data(rdp);
89393@@ -3128,8 +3128,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
89394 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
89395 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
89396 rcu_sysidle_init_percpu_data(rdp->dynticks);
89397- atomic_set(&rdp->dynticks->dynticks,
89398- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
89399+ atomic_set_unchecked(&rdp->dynticks->dynticks,
89400+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
89401 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
89402
89403 /* Add CPU to rcu_node bitmasks. */
89404diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
89405index 8c19873..bf83c57 100644
89406--- a/kernel/rcu/tree.h
89407+++ b/kernel/rcu/tree.h
89408@@ -87,11 +87,11 @@ struct rcu_dynticks {
89409 long long dynticks_nesting; /* Track irq/process nesting level. */
89410 /* Process level is worth LLONG_MAX/2. */
89411 int dynticks_nmi_nesting; /* Track NMI nesting level. */
89412- atomic_t dynticks; /* Even value for idle, else odd. */
89413+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
89414 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
89415 long long dynticks_idle_nesting;
89416 /* irq/process nesting level from idle. */
89417- atomic_t dynticks_idle; /* Even value for idle, else odd. */
89418+ atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
89419 /* "Idle" excludes userspace execution. */
89420 unsigned long dynticks_idle_jiffies;
89421 /* End of last non-NMI non-idle period. */
89422@@ -431,17 +431,17 @@ struct rcu_state {
89423 /* _rcu_barrier(). */
89424 /* End of fields guarded by barrier_mutex. */
89425
89426- atomic_long_t expedited_start; /* Starting ticket. */
89427- atomic_long_t expedited_done; /* Done ticket. */
89428- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
89429- atomic_long_t expedited_tryfail; /* # acquisition failures. */
89430- atomic_long_t expedited_workdone1; /* # done by others #1. */
89431- atomic_long_t expedited_workdone2; /* # done by others #2. */
89432- atomic_long_t expedited_normal; /* # fallbacks to normal. */
89433- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
89434- atomic_long_t expedited_done_tries; /* # tries to update _done. */
89435- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
89436- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
89437+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
89438+ atomic_long_t expedited_done; /* Done ticket. */
89439+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
89440+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
89441+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
89442+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
89443+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
89444+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
89445+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
89446+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
89447+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
89448
89449 unsigned long jiffies_force_qs; /* Time at which to invoke */
89450 /* force_quiescent_state(). */
89451diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
89452index 6e2ef4b..c15df94 100644
89453--- a/kernel/rcu/tree_plugin.h
89454+++ b/kernel/rcu/tree_plugin.h
89455@@ -758,7 +758,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
89456 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
89457 {
89458 return !rcu_preempted_readers_exp(rnp) &&
89459- ACCESS_ONCE(rnp->expmask) == 0;
89460+ ACCESS_ONCE_RW(rnp->expmask) == 0;
89461 }
89462
89463 /*
89464@@ -920,7 +920,7 @@ void synchronize_rcu_expedited(void)
89465
89466 /* Clean up and exit. */
89467 smp_mb(); /* ensure expedited GP seen before counter increment. */
89468- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
89469+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
89470 unlock_mb_ret:
89471 mutex_unlock(&sync_rcu_preempt_exp_mutex);
89472 mb_ret:
89473@@ -1496,7 +1496,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
89474 free_cpumask_var(cm);
89475 }
89476
89477-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
89478+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
89479 .store = &rcu_cpu_kthread_task,
89480 .thread_should_run = rcu_cpu_kthread_should_run,
89481 .thread_fn = rcu_cpu_kthread,
89482@@ -1965,7 +1965,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
89483 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
89484 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
89485 cpu, ticks_value, ticks_title,
89486- atomic_read(&rdtp->dynticks) & 0xfff,
89487+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
89488 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
89489 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
89490 fast_no_hz);
89491@@ -2129,7 +2129,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
89492
89493 /* Enqueue the callback on the nocb list and update counts. */
89494 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
89495- ACCESS_ONCE(*old_rhpp) = rhp;
89496+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
89497 atomic_long_add(rhcount, &rdp->nocb_q_count);
89498 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
89499
89500@@ -2302,12 +2302,12 @@ static int rcu_nocb_kthread(void *arg)
89501 * Extract queued callbacks, update counts, and wait
89502 * for a grace period to elapse.
89503 */
89504- ACCESS_ONCE(rdp->nocb_head) = NULL;
89505+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
89506 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
89507 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
89508 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
89509- ACCESS_ONCE(rdp->nocb_p_count) += c;
89510- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
89511+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
89512+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
89513 rcu_nocb_wait_gp(rdp);
89514
89515 /* Each pass through the following loop invokes a callback. */
89516@@ -2333,8 +2333,8 @@ static int rcu_nocb_kthread(void *arg)
89517 list = next;
89518 }
89519 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
89520- ACCESS_ONCE(rdp->nocb_p_count) -= c;
89521- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
89522+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
89523+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
89524 rdp->n_nocbs_invoked += c;
89525 }
89526 return 0;
89527@@ -2351,7 +2351,7 @@ static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
89528 {
89529 if (!rcu_nocb_need_deferred_wakeup(rdp))
89530 return;
89531- ACCESS_ONCE(rdp->nocb_defer_wakeup) = false;
89532+ ACCESS_ONCE_RW(rdp->nocb_defer_wakeup) = false;
89533 wake_up(&rdp->nocb_wq);
89534 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWakeEmpty"));
89535 }
89536@@ -2377,7 +2377,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
89537 t = kthread_run(rcu_nocb_kthread, rdp,
89538 "rcuo%c/%d", rsp->abbr, cpu);
89539 BUG_ON(IS_ERR(t));
89540- ACCESS_ONCE(rdp->nocb_kthread) = t;
89541+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
89542 }
89543 }
89544
89545@@ -2513,11 +2513,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
89546
89547 /* Record start of fully idle period. */
89548 j = jiffies;
89549- ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
89550+ ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
89551 smp_mb__before_atomic_inc();
89552- atomic_inc(&rdtp->dynticks_idle);
89553+ atomic_inc_unchecked(&rdtp->dynticks_idle);
89554 smp_mb__after_atomic_inc();
89555- WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
89556+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
89557 }
89558
89559 /*
89560@@ -2582,9 +2582,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
89561
89562 /* Record end of idle period. */
89563 smp_mb__before_atomic_inc();
89564- atomic_inc(&rdtp->dynticks_idle);
89565+ atomic_inc_unchecked(&rdtp->dynticks_idle);
89566 smp_mb__after_atomic_inc();
89567- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
89568+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
89569
89570 /*
89571 * If we are the timekeeping CPU, we are permitted to be non-idle
89572@@ -2625,7 +2625,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
89573 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
89574
89575 /* Pick up current idle and NMI-nesting counter and check. */
89576- cur = atomic_read(&rdtp->dynticks_idle);
89577+ cur = atomic_read_unchecked(&rdtp->dynticks_idle);
89578 if (cur & 0x1) {
89579 *isidle = false; /* We are not idle! */
89580 return;
89581@@ -2688,7 +2688,7 @@ static void rcu_sysidle(unsigned long j)
89582 case RCU_SYSIDLE_NOT:
89583
89584 /* First time all are idle, so note a short idle period. */
89585- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
89586+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
89587 break;
89588
89589 case RCU_SYSIDLE_SHORT:
89590@@ -2725,7 +2725,7 @@ static void rcu_sysidle(unsigned long j)
89591 static void rcu_sysidle_cancel(void)
89592 {
89593 smp_mb();
89594- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
89595+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
89596 }
89597
89598 /*
89599@@ -2773,7 +2773,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
89600 smp_mb(); /* grace period precedes setting inuse. */
89601
89602 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
89603- ACCESS_ONCE(rshp->inuse) = 0;
89604+ ACCESS_ONCE_RW(rshp->inuse) = 0;
89605 }
89606
89607 /*
89608diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
89609index 4def475..8ffddde 100644
89610--- a/kernel/rcu/tree_trace.c
89611+++ b/kernel/rcu/tree_trace.c
89612@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
89613 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
89614 rdp->passed_quiesce, rdp->qs_pending);
89615 seq_printf(m, " dt=%d/%llx/%d df=%lu",
89616- atomic_read(&rdp->dynticks->dynticks),
89617+ atomic_read_unchecked(&rdp->dynticks->dynticks),
89618 rdp->dynticks->dynticks_nesting,
89619 rdp->dynticks->dynticks_nmi_nesting,
89620 rdp->dynticks_fqs);
89621@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
89622 struct rcu_state *rsp = (struct rcu_state *)m->private;
89623
89624 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",
89625- atomic_long_read(&rsp->expedited_start),
89626+ atomic_long_read_unchecked(&rsp->expedited_start),
89627 atomic_long_read(&rsp->expedited_done),
89628- atomic_long_read(&rsp->expedited_wrap),
89629- atomic_long_read(&rsp->expedited_tryfail),
89630- atomic_long_read(&rsp->expedited_workdone1),
89631- atomic_long_read(&rsp->expedited_workdone2),
89632- atomic_long_read(&rsp->expedited_normal),
89633- atomic_long_read(&rsp->expedited_stoppedcpus),
89634- atomic_long_read(&rsp->expedited_done_tries),
89635- atomic_long_read(&rsp->expedited_done_lost),
89636- atomic_long_read(&rsp->expedited_done_exit));
89637+ atomic_long_read_unchecked(&rsp->expedited_wrap),
89638+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
89639+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
89640+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
89641+ atomic_long_read_unchecked(&rsp->expedited_normal),
89642+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
89643+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
89644+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
89645+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
89646 return 0;
89647 }
89648
89649diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
89650index c54609f..2e8829c 100644
89651--- a/kernel/rcu/update.c
89652+++ b/kernel/rcu/update.c
89653@@ -312,10 +312,10 @@ int rcu_jiffies_till_stall_check(void)
89654 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
89655 */
89656 if (till_stall_check < 3) {
89657- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
89658+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
89659 till_stall_check = 3;
89660 } else if (till_stall_check > 300) {
89661- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
89662+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
89663 till_stall_check = 300;
89664 }
89665 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
89666diff --git a/kernel/resource.c b/kernel/resource.c
89667index 3f285dc..5755f62 100644
89668--- a/kernel/resource.c
89669+++ b/kernel/resource.c
89670@@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
89671
89672 static int __init ioresources_init(void)
89673 {
89674+#ifdef CONFIG_GRKERNSEC_PROC_ADD
89675+#ifdef CONFIG_GRKERNSEC_PROC_USER
89676+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
89677+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
89678+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
89679+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
89680+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
89681+#endif
89682+#else
89683 proc_create("ioports", 0, NULL, &proc_ioports_operations);
89684 proc_create("iomem", 0, NULL, &proc_iomem_operations);
89685+#endif
89686 return 0;
89687 }
89688 __initcall(ioresources_init);
89689diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
89690index 4a07353..66b5291 100644
89691--- a/kernel/sched/auto_group.c
89692+++ b/kernel/sched/auto_group.c
89693@@ -11,7 +11,7 @@
89694
89695 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
89696 static struct autogroup autogroup_default;
89697-static atomic_t autogroup_seq_nr;
89698+static atomic_unchecked_t autogroup_seq_nr;
89699
89700 void __init autogroup_init(struct task_struct *init_task)
89701 {
89702@@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
89703
89704 kref_init(&ag->kref);
89705 init_rwsem(&ag->lock);
89706- ag->id = atomic_inc_return(&autogroup_seq_nr);
89707+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
89708 ag->tg = tg;
89709 #ifdef CONFIG_RT_GROUP_SCHED
89710 /*
89711diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
89712index a63f4dc..349bbb0 100644
89713--- a/kernel/sched/completion.c
89714+++ b/kernel/sched/completion.c
89715@@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
89716 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
89717 * or number of jiffies left till timeout) if completed.
89718 */
89719-long __sched
89720+long __sched __intentional_overflow(-1)
89721 wait_for_completion_interruptible_timeout(struct completion *x,
89722 unsigned long timeout)
89723 {
89724@@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
89725 *
89726 * Return: -ERESTARTSYS if interrupted, 0 if completed.
89727 */
89728-int __sched wait_for_completion_killable(struct completion *x)
89729+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
89730 {
89731 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
89732 if (t == -ERESTARTSYS)
89733@@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
89734 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
89735 * or number of jiffies left till timeout) if completed.
89736 */
89737-long __sched
89738+long __sched __intentional_overflow(-1)
89739 wait_for_completion_killable_timeout(struct completion *x,
89740 unsigned long timeout)
89741 {
89742diff --git a/kernel/sched/core.c b/kernel/sched/core.c
89743index f5c6635..ab9f223 100644
89744--- a/kernel/sched/core.c
89745+++ b/kernel/sched/core.c
89746@@ -1775,7 +1775,7 @@ void set_numabalancing_state(bool enabled)
89747 int sysctl_numa_balancing(struct ctl_table *table, int write,
89748 void __user *buffer, size_t *lenp, loff_t *ppos)
89749 {
89750- struct ctl_table t;
89751+ ctl_table_no_const t;
89752 int err;
89753 int state = numabalancing_enabled;
89754
89755@@ -3049,6 +3049,8 @@ int can_nice(const struct task_struct *p, const int nice)
89756 /* convert nice value [19,-20] to rlimit style value [1,40] */
89757 int nice_rlim = 20 - nice;
89758
89759+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
89760+
89761 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
89762 capable(CAP_SYS_NICE));
89763 }
89764@@ -3082,7 +3084,8 @@ SYSCALL_DEFINE1(nice, int, increment)
89765 if (nice > 19)
89766 nice = 19;
89767
89768- if (increment < 0 && !can_nice(current, nice))
89769+ if (increment < 0 && (!can_nice(current, nice) ||
89770+ gr_handle_chroot_nice()))
89771 return -EPERM;
89772
89773 retval = security_task_setnice(current, nice);
89774@@ -3332,6 +3335,7 @@ recheck:
89775 if (policy != p->policy && !rlim_rtprio)
89776 return -EPERM;
89777
89778+ gr_learn_resource(p, RLIMIT_RTPRIO, attr->sched_priority, 1);
89779 /* can't increase priority */
89780 if (attr->sched_priority > p->rt_priority &&
89781 attr->sched_priority > rlim_rtprio)
89782@@ -4781,7 +4785,7 @@ static void migrate_tasks(unsigned int dead_cpu)
89783
89784 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
89785
89786-static struct ctl_table sd_ctl_dir[] = {
89787+static ctl_table_no_const sd_ctl_dir[] __read_only = {
89788 {
89789 .procname = "sched_domain",
89790 .mode = 0555,
89791@@ -4798,17 +4802,17 @@ static struct ctl_table sd_ctl_root[] = {
89792 {}
89793 };
89794
89795-static struct ctl_table *sd_alloc_ctl_entry(int n)
89796+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
89797 {
89798- struct ctl_table *entry =
89799+ ctl_table_no_const *entry =
89800 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
89801
89802 return entry;
89803 }
89804
89805-static void sd_free_ctl_entry(struct ctl_table **tablep)
89806+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
89807 {
89808- struct ctl_table *entry;
89809+ ctl_table_no_const *entry;
89810
89811 /*
89812 * In the intermediate directories, both the child directory and
89813@@ -4816,22 +4820,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
89814 * will always be set. In the lowest directory the names are
89815 * static strings and all have proc handlers.
89816 */
89817- for (entry = *tablep; entry->mode; entry++) {
89818- if (entry->child)
89819- sd_free_ctl_entry(&entry->child);
89820+ for (entry = tablep; entry->mode; entry++) {
89821+ if (entry->child) {
89822+ sd_free_ctl_entry(entry->child);
89823+ pax_open_kernel();
89824+ entry->child = NULL;
89825+ pax_close_kernel();
89826+ }
89827 if (entry->proc_handler == NULL)
89828 kfree(entry->procname);
89829 }
89830
89831- kfree(*tablep);
89832- *tablep = NULL;
89833+ kfree(tablep);
89834 }
89835
89836 static int min_load_idx = 0;
89837 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
89838
89839 static void
89840-set_table_entry(struct ctl_table *entry,
89841+set_table_entry(ctl_table_no_const *entry,
89842 const char *procname, void *data, int maxlen,
89843 umode_t mode, proc_handler *proc_handler,
89844 bool load_idx)
89845@@ -4851,7 +4858,7 @@ set_table_entry(struct ctl_table *entry,
89846 static struct ctl_table *
89847 sd_alloc_ctl_domain_table(struct sched_domain *sd)
89848 {
89849- struct ctl_table *table = sd_alloc_ctl_entry(13);
89850+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
89851
89852 if (table == NULL)
89853 return NULL;
89854@@ -4886,9 +4893,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
89855 return table;
89856 }
89857
89858-static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
89859+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
89860 {
89861- struct ctl_table *entry, *table;
89862+ ctl_table_no_const *entry, *table;
89863 struct sched_domain *sd;
89864 int domain_num = 0, i;
89865 char buf[32];
89866@@ -4915,11 +4922,13 @@ static struct ctl_table_header *sd_sysctl_header;
89867 static void register_sched_domain_sysctl(void)
89868 {
89869 int i, cpu_num = num_possible_cpus();
89870- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
89871+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
89872 char buf[32];
89873
89874 WARN_ON(sd_ctl_dir[0].child);
89875+ pax_open_kernel();
89876 sd_ctl_dir[0].child = entry;
89877+ pax_close_kernel();
89878
89879 if (entry == NULL)
89880 return;
89881@@ -4942,8 +4951,12 @@ static void unregister_sched_domain_sysctl(void)
89882 if (sd_sysctl_header)
89883 unregister_sysctl_table(sd_sysctl_header);
89884 sd_sysctl_header = NULL;
89885- if (sd_ctl_dir[0].child)
89886- sd_free_ctl_entry(&sd_ctl_dir[0].child);
89887+ if (sd_ctl_dir[0].child) {
89888+ sd_free_ctl_entry(sd_ctl_dir[0].child);
89889+ pax_open_kernel();
89890+ sd_ctl_dir[0].child = NULL;
89891+ pax_close_kernel();
89892+ }
89893 }
89894 #else
89895 static void register_sched_domain_sysctl(void)
89896diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
89897index 9b4c4f3..665489b 100644
89898--- a/kernel/sched/fair.c
89899+++ b/kernel/sched/fair.c
89900@@ -1647,7 +1647,7 @@ void task_numa_fault(int last_cpupid, int node, int pages, int flags)
89901
89902 static void reset_ptenuma_scan(struct task_struct *p)
89903 {
89904- ACCESS_ONCE(p->mm->numa_scan_seq)++;
89905+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
89906 p->mm->numa_scan_offset = 0;
89907 }
89908
89909@@ -6851,7 +6851,7 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) { }
89910 * run_rebalance_domains is triggered when needed from the scheduler tick.
89911 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
89912 */
89913-static void run_rebalance_domains(struct softirq_action *h)
89914+static __latent_entropy void run_rebalance_domains(void)
89915 {
89916 struct rq *this_rq = this_rq();
89917 enum cpu_idle_type idle = this_rq->idle_balance ?
89918diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
89919index f964add..dcd823d 100644
89920--- a/kernel/sched/sched.h
89921+++ b/kernel/sched/sched.h
89922@@ -1157,7 +1157,7 @@ struct sched_class {
89923 #ifdef CONFIG_FAIR_GROUP_SCHED
89924 void (*task_move_group) (struct task_struct *p, int on_rq);
89925 #endif
89926-};
89927+} __do_const;
89928
89929 #define sched_class_highest (&stop_sched_class)
89930 #define for_each_class(class) \
89931diff --git a/kernel/signal.c b/kernel/signal.c
89932index 52f881d..1e9f941 100644
89933--- a/kernel/signal.c
89934+++ b/kernel/signal.c
89935@@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
89936
89937 int print_fatal_signals __read_mostly;
89938
89939-static void __user *sig_handler(struct task_struct *t, int sig)
89940+static __sighandler_t sig_handler(struct task_struct *t, int sig)
89941 {
89942 return t->sighand->action[sig - 1].sa.sa_handler;
89943 }
89944
89945-static int sig_handler_ignored(void __user *handler, int sig)
89946+static int sig_handler_ignored(__sighandler_t handler, int sig)
89947 {
89948 /* Is it explicitly or implicitly ignored? */
89949 return handler == SIG_IGN ||
89950@@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
89951
89952 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
89953 {
89954- void __user *handler;
89955+ __sighandler_t handler;
89956
89957 handler = sig_handler(t, sig);
89958
89959@@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
89960 atomic_inc(&user->sigpending);
89961 rcu_read_unlock();
89962
89963+ if (!override_rlimit)
89964+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
89965+
89966 if (override_rlimit ||
89967 atomic_read(&user->sigpending) <=
89968 task_rlimit(t, RLIMIT_SIGPENDING)) {
89969@@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
89970
89971 int unhandled_signal(struct task_struct *tsk, int sig)
89972 {
89973- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
89974+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
89975 if (is_global_init(tsk))
89976 return 1;
89977 if (handler != SIG_IGN && handler != SIG_DFL)
89978@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
89979 }
89980 }
89981
89982+ /* allow glibc communication via tgkill to other threads in our
89983+ thread group */
89984+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
89985+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
89986+ && gr_handle_signal(t, sig))
89987+ return -EPERM;
89988+
89989 return security_task_kill(t, info, sig, 0);
89990 }
89991
89992@@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
89993 return send_signal(sig, info, p, 1);
89994 }
89995
89996-static int
89997+int
89998 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
89999 {
90000 return send_signal(sig, info, t, 0);
90001@@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
90002 unsigned long int flags;
90003 int ret, blocked, ignored;
90004 struct k_sigaction *action;
90005+ int is_unhandled = 0;
90006
90007 spin_lock_irqsave(&t->sighand->siglock, flags);
90008 action = &t->sighand->action[sig-1];
90009@@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
90010 }
90011 if (action->sa.sa_handler == SIG_DFL)
90012 t->signal->flags &= ~SIGNAL_UNKILLABLE;
90013+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
90014+ is_unhandled = 1;
90015 ret = specific_send_sig_info(sig, info, t);
90016 spin_unlock_irqrestore(&t->sighand->siglock, flags);
90017
90018+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
90019+ normal operation */
90020+ if (is_unhandled) {
90021+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
90022+ gr_handle_crash(t, sig);
90023+ }
90024+
90025 return ret;
90026 }
90027
90028@@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
90029 ret = check_kill_permission(sig, info, p);
90030 rcu_read_unlock();
90031
90032- if (!ret && sig)
90033+ if (!ret && sig) {
90034 ret = do_send_sig_info(sig, info, p, true);
90035+ if (!ret)
90036+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
90037+ }
90038
90039 return ret;
90040 }
90041@@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
90042 int error = -ESRCH;
90043
90044 rcu_read_lock();
90045- p = find_task_by_vpid(pid);
90046+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
90047+ /* allow glibc communication via tgkill to other threads in our
90048+ thread group */
90049+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
90050+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
90051+ p = find_task_by_vpid_unrestricted(pid);
90052+ else
90053+#endif
90054+ p = find_task_by_vpid(pid);
90055 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
90056 error = check_kill_permission(sig, info, p);
90057 /*
90058@@ -3239,8 +3270,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
90059 }
90060 seg = get_fs();
90061 set_fs(KERNEL_DS);
90062- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
90063- (stack_t __force __user *) &uoss,
90064+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
90065+ (stack_t __force_user *) &uoss,
90066 compat_user_stack_pointer());
90067 set_fs(seg);
90068 if (ret >= 0 && uoss_ptr) {
90069diff --git a/kernel/smpboot.c b/kernel/smpboot.c
90070index eb89e18..a4e6792 100644
90071--- a/kernel/smpboot.c
90072+++ b/kernel/smpboot.c
90073@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
90074 }
90075 smpboot_unpark_thread(plug_thread, cpu);
90076 }
90077- list_add(&plug_thread->list, &hotplug_threads);
90078+ pax_list_add(&plug_thread->list, &hotplug_threads);
90079 out:
90080 mutex_unlock(&smpboot_threads_lock);
90081 return ret;
90082@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
90083 {
90084 get_online_cpus();
90085 mutex_lock(&smpboot_threads_lock);
90086- list_del(&plug_thread->list);
90087+ pax_list_del(&plug_thread->list);
90088 smpboot_destroy_threads(plug_thread);
90089 mutex_unlock(&smpboot_threads_lock);
90090 put_online_cpus();
90091diff --git a/kernel/softirq.c b/kernel/softirq.c
90092index 490fcbb..1e502c6 100644
90093--- a/kernel/softirq.c
90094+++ b/kernel/softirq.c
90095@@ -52,7 +52,7 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
90096 EXPORT_SYMBOL(irq_stat);
90097 #endif
90098
90099-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
90100+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
90101
90102 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
90103
90104@@ -267,7 +267,7 @@ restart:
90105 kstat_incr_softirqs_this_cpu(vec_nr);
90106
90107 trace_softirq_entry(vec_nr);
90108- h->action(h);
90109+ h->action();
90110 trace_softirq_exit(vec_nr);
90111 if (unlikely(prev_count != preempt_count())) {
90112 pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
90113@@ -427,7 +427,7 @@ void __raise_softirq_irqoff(unsigned int nr)
90114 or_softirq_pending(1UL << nr);
90115 }
90116
90117-void open_softirq(int nr, void (*action)(struct softirq_action *))
90118+void __init open_softirq(int nr, void (*action)(void))
90119 {
90120 softirq_vec[nr].action = action;
90121 }
90122@@ -479,7 +479,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
90123 }
90124 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
90125
90126-static void tasklet_action(struct softirq_action *a)
90127+static void tasklet_action(void)
90128 {
90129 struct tasklet_struct *list;
90130
90131@@ -515,7 +515,7 @@ static void tasklet_action(struct softirq_action *a)
90132 }
90133 }
90134
90135-static void tasklet_hi_action(struct softirq_action *a)
90136+static __latent_entropy void tasklet_hi_action(void)
90137 {
90138 struct tasklet_struct *list;
90139
90140@@ -742,7 +742,7 @@ static struct notifier_block cpu_nfb = {
90141 .notifier_call = cpu_callback
90142 };
90143
90144-static struct smp_hotplug_thread softirq_threads = {
90145+static struct smp_hotplug_thread softirq_threads __read_only = {
90146 .store = &ksoftirqd,
90147 .thread_should_run = ksoftirqd_should_run,
90148 .thread_fn = run_ksoftirqd,
90149diff --git a/kernel/sys.c b/kernel/sys.c
90150index c0a58be..784c618 100644
90151--- a/kernel/sys.c
90152+++ b/kernel/sys.c
90153@@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
90154 error = -EACCES;
90155 goto out;
90156 }
90157+
90158+ if (gr_handle_chroot_setpriority(p, niceval)) {
90159+ error = -EACCES;
90160+ goto out;
90161+ }
90162+
90163 no_nice = security_task_setnice(p, niceval);
90164 if (no_nice) {
90165 error = no_nice;
90166@@ -351,6 +357,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
90167 goto error;
90168 }
90169
90170+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
90171+ goto error;
90172+
90173 if (rgid != (gid_t) -1 ||
90174 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
90175 new->sgid = new->egid;
90176@@ -386,6 +395,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
90177 old = current_cred();
90178
90179 retval = -EPERM;
90180+
90181+ if (gr_check_group_change(kgid, kgid, kgid))
90182+ goto error;
90183+
90184 if (ns_capable(old->user_ns, CAP_SETGID))
90185 new->gid = new->egid = new->sgid = new->fsgid = kgid;
90186 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
90187@@ -403,7 +416,7 @@ error:
90188 /*
90189 * change the user struct in a credentials set to match the new UID
90190 */
90191-static int set_user(struct cred *new)
90192+int set_user(struct cred *new)
90193 {
90194 struct user_struct *new_user;
90195
90196@@ -483,6 +496,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
90197 goto error;
90198 }
90199
90200+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
90201+ goto error;
90202+
90203 if (!uid_eq(new->uid, old->uid)) {
90204 retval = set_user(new);
90205 if (retval < 0)
90206@@ -533,6 +549,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
90207 old = current_cred();
90208
90209 retval = -EPERM;
90210+
90211+ if (gr_check_crash_uid(kuid))
90212+ goto error;
90213+ if (gr_check_user_change(kuid, kuid, kuid))
90214+ goto error;
90215+
90216 if (ns_capable(old->user_ns, CAP_SETUID)) {
90217 new->suid = new->uid = kuid;
90218 if (!uid_eq(kuid, old->uid)) {
90219@@ -602,6 +624,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
90220 goto error;
90221 }
90222
90223+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
90224+ goto error;
90225+
90226 if (ruid != (uid_t) -1) {
90227 new->uid = kruid;
90228 if (!uid_eq(kruid, old->uid)) {
90229@@ -684,6 +709,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
90230 goto error;
90231 }
90232
90233+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
90234+ goto error;
90235+
90236 if (rgid != (gid_t) -1)
90237 new->gid = krgid;
90238 if (egid != (gid_t) -1)
90239@@ -745,12 +773,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
90240 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
90241 ns_capable(old->user_ns, CAP_SETUID)) {
90242 if (!uid_eq(kuid, old->fsuid)) {
90243+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
90244+ goto error;
90245+
90246 new->fsuid = kuid;
90247 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
90248 goto change_okay;
90249 }
90250 }
90251
90252+error:
90253 abort_creds(new);
90254 return old_fsuid;
90255
90256@@ -783,12 +815,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
90257 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
90258 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
90259 ns_capable(old->user_ns, CAP_SETGID)) {
90260+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
90261+ goto error;
90262+
90263 if (!gid_eq(kgid, old->fsgid)) {
90264 new->fsgid = kgid;
90265 goto change_okay;
90266 }
90267 }
90268
90269+error:
90270 abort_creds(new);
90271 return old_fsgid;
90272
90273@@ -1167,19 +1203,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
90274 return -EFAULT;
90275
90276 down_read(&uts_sem);
90277- error = __copy_to_user(&name->sysname, &utsname()->sysname,
90278+ error = __copy_to_user(name->sysname, &utsname()->sysname,
90279 __OLD_UTS_LEN);
90280 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
90281- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
90282+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
90283 __OLD_UTS_LEN);
90284 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
90285- error |= __copy_to_user(&name->release, &utsname()->release,
90286+ error |= __copy_to_user(name->release, &utsname()->release,
90287 __OLD_UTS_LEN);
90288 error |= __put_user(0, name->release + __OLD_UTS_LEN);
90289- error |= __copy_to_user(&name->version, &utsname()->version,
90290+ error |= __copy_to_user(name->version, &utsname()->version,
90291 __OLD_UTS_LEN);
90292 error |= __put_user(0, name->version + __OLD_UTS_LEN);
90293- error |= __copy_to_user(&name->machine, &utsname()->machine,
90294+ error |= __copy_to_user(name->machine, &utsname()->machine,
90295 __OLD_UTS_LEN);
90296 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
90297 up_read(&uts_sem);
90298@@ -1381,6 +1417,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
90299 */
90300 new_rlim->rlim_cur = 1;
90301 }
90302+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
90303+ is changed to a lower value. Since tasks can be created by the same
90304+ user in between this limit change and an execve by this task, force
90305+ a recheck only for this task by setting PF_NPROC_EXCEEDED
90306+ */
90307+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
90308+ tsk->flags |= PF_NPROC_EXCEEDED;
90309 }
90310 if (!retval) {
90311 if (old_rlim)
90312diff --git a/kernel/sysctl.c b/kernel/sysctl.c
90313index aae21e8..58d8c9a 100644
90314--- a/kernel/sysctl.c
90315+++ b/kernel/sysctl.c
90316@@ -94,7 +94,6 @@
90317
90318
90319 #if defined(CONFIG_SYSCTL)
90320-
90321 /* External variables not in a header file. */
90322 extern int max_threads;
90323 extern int suid_dumpable;
90324@@ -118,19 +117,18 @@ extern int blk_iopoll_enabled;
90325
90326 /* Constants used for minimum and maximum */
90327 #ifdef CONFIG_LOCKUP_DETECTOR
90328-static int sixty = 60;
90329+static int sixty __read_only = 60;
90330 #endif
90331
90332-static int __maybe_unused neg_one = -1;
90333-
90334-static int zero;
90335-static int __maybe_unused one = 1;
90336-static int __maybe_unused two = 2;
90337-static int __maybe_unused three = 3;
90338-static unsigned long one_ul = 1;
90339-static int one_hundred = 100;
90340+static int __maybe_unused neg_one __read_only = -1;
90341+static int zero __read_only = 0;
90342+static int __maybe_unused one __read_only = 1;
90343+static int __maybe_unused two __read_only = 2;
90344+static int __maybe_unused three __read_only = 3;
90345+static unsigned long one_ul __read_only = 1;
90346+static int one_hundred __read_only = 100;
90347 #ifdef CONFIG_PRINTK
90348-static int ten_thousand = 10000;
90349+static int ten_thousand __read_only = 10000;
90350 #endif
90351
90352 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
90353@@ -182,10 +180,8 @@ static int proc_taint(struct ctl_table *table, int write,
90354 void __user *buffer, size_t *lenp, loff_t *ppos);
90355 #endif
90356
90357-#ifdef CONFIG_PRINTK
90358 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
90359 void __user *buffer, size_t *lenp, loff_t *ppos);
90360-#endif
90361
90362 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
90363 void __user *buffer, size_t *lenp, loff_t *ppos);
90364@@ -216,6 +212,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
90365
90366 #endif
90367
90368+extern struct ctl_table grsecurity_table[];
90369+
90370 static struct ctl_table kern_table[];
90371 static struct ctl_table vm_table[];
90372 static struct ctl_table fs_table[];
90373@@ -230,6 +228,20 @@ extern struct ctl_table epoll_table[];
90374 int sysctl_legacy_va_layout;
90375 #endif
90376
90377+#ifdef CONFIG_PAX_SOFTMODE
90378+static ctl_table pax_table[] = {
90379+ {
90380+ .procname = "softmode",
90381+ .data = &pax_softmode,
90382+ .maxlen = sizeof(unsigned int),
90383+ .mode = 0600,
90384+ .proc_handler = &proc_dointvec,
90385+ },
90386+
90387+ { }
90388+};
90389+#endif
90390+
90391 /* The default sysctl tables: */
90392
90393 static struct ctl_table sysctl_base_table[] = {
90394@@ -278,6 +290,22 @@ static int max_extfrag_threshold = 1000;
90395 #endif
90396
90397 static struct ctl_table kern_table[] = {
90398+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
90399+ {
90400+ .procname = "grsecurity",
90401+ .mode = 0500,
90402+ .child = grsecurity_table,
90403+ },
90404+#endif
90405+
90406+#ifdef CONFIG_PAX_SOFTMODE
90407+ {
90408+ .procname = "pax",
90409+ .mode = 0500,
90410+ .child = pax_table,
90411+ },
90412+#endif
90413+
90414 {
90415 .procname = "sched_child_runs_first",
90416 .data = &sysctl_sched_child_runs_first,
90417@@ -640,7 +668,7 @@ static struct ctl_table kern_table[] = {
90418 .data = &modprobe_path,
90419 .maxlen = KMOD_PATH_LEN,
90420 .mode = 0644,
90421- .proc_handler = proc_dostring,
90422+ .proc_handler = proc_dostring_modpriv,
90423 },
90424 {
90425 .procname = "modules_disabled",
90426@@ -807,16 +835,20 @@ static struct ctl_table kern_table[] = {
90427 .extra1 = &zero,
90428 .extra2 = &one,
90429 },
90430+#endif
90431 {
90432 .procname = "kptr_restrict",
90433 .data = &kptr_restrict,
90434 .maxlen = sizeof(int),
90435 .mode = 0644,
90436 .proc_handler = proc_dointvec_minmax_sysadmin,
90437+#ifdef CONFIG_GRKERNSEC_HIDESYM
90438+ .extra1 = &two,
90439+#else
90440 .extra1 = &zero,
90441+#endif
90442 .extra2 = &two,
90443 },
90444-#endif
90445 {
90446 .procname = "ngroups_max",
90447 .data = &ngroups_max,
90448@@ -1061,10 +1093,17 @@ static struct ctl_table kern_table[] = {
90449 */
90450 {
90451 .procname = "perf_event_paranoid",
90452- .data = &sysctl_perf_event_paranoid,
90453- .maxlen = sizeof(sysctl_perf_event_paranoid),
90454+ .data = &sysctl_perf_event_legitimately_concerned,
90455+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
90456 .mode = 0644,
90457- .proc_handler = proc_dointvec,
90458+ /* go ahead, be a hero */
90459+ .proc_handler = proc_dointvec_minmax_sysadmin,
90460+ .extra1 = &neg_one,
90461+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
90462+ .extra2 = &three,
90463+#else
90464+ .extra2 = &two,
90465+#endif
90466 },
90467 {
90468 .procname = "perf_event_mlock_kb",
90469@@ -1335,6 +1374,13 @@ static struct ctl_table vm_table[] = {
90470 .proc_handler = proc_dointvec_minmax,
90471 .extra1 = &zero,
90472 },
90473+ {
90474+ .procname = "heap_stack_gap",
90475+ .data = &sysctl_heap_stack_gap,
90476+ .maxlen = sizeof(sysctl_heap_stack_gap),
90477+ .mode = 0644,
90478+ .proc_handler = proc_doulongvec_minmax,
90479+ },
90480 #else
90481 {
90482 .procname = "nr_trim_pages",
90483@@ -1799,6 +1845,16 @@ int proc_dostring(struct ctl_table *table, int write,
90484 buffer, lenp, ppos);
90485 }
90486
90487+int proc_dostring_modpriv(struct ctl_table *table, int write,
90488+ void __user *buffer, size_t *lenp, loff_t *ppos)
90489+{
90490+ if (write && !capable(CAP_SYS_MODULE))
90491+ return -EPERM;
90492+
90493+ return _proc_do_string(table->data, table->maxlen, write,
90494+ buffer, lenp, ppos);
90495+}
90496+
90497 static size_t proc_skip_spaces(char **buf)
90498 {
90499 size_t ret;
90500@@ -1904,6 +1960,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
90501 len = strlen(tmp);
90502 if (len > *size)
90503 len = *size;
90504+ if (len > sizeof(tmp))
90505+ len = sizeof(tmp);
90506 if (copy_to_user(*buf, tmp, len))
90507 return -EFAULT;
90508 *size -= len;
90509@@ -2068,7 +2126,7 @@ int proc_dointvec(struct ctl_table *table, int write,
90510 static int proc_taint(struct ctl_table *table, int write,
90511 void __user *buffer, size_t *lenp, loff_t *ppos)
90512 {
90513- struct ctl_table t;
90514+ ctl_table_no_const t;
90515 unsigned long tmptaint = get_taint();
90516 int err;
90517
90518@@ -2096,7 +2154,6 @@ static int proc_taint(struct ctl_table *table, int write,
90519 return err;
90520 }
90521
90522-#ifdef CONFIG_PRINTK
90523 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
90524 void __user *buffer, size_t *lenp, loff_t *ppos)
90525 {
90526@@ -2105,7 +2162,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
90527
90528 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
90529 }
90530-#endif
90531
90532 struct do_proc_dointvec_minmax_conv_param {
90533 int *min;
90534@@ -2652,6 +2708,12 @@ int proc_dostring(struct ctl_table *table, int write,
90535 return -ENOSYS;
90536 }
90537
90538+int proc_dostring_modpriv(struct ctl_table *table, int write,
90539+ void __user *buffer, size_t *lenp, loff_t *ppos)
90540+{
90541+ return -ENOSYS;
90542+}
90543+
90544 int proc_dointvec(struct ctl_table *table, int write,
90545 void __user *buffer, size_t *lenp, loff_t *ppos)
90546 {
90547@@ -2708,5 +2770,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
90548 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
90549 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
90550 EXPORT_SYMBOL(proc_dostring);
90551+EXPORT_SYMBOL(proc_dostring_modpriv);
90552 EXPORT_SYMBOL(proc_doulongvec_minmax);
90553 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
90554diff --git a/kernel/taskstats.c b/kernel/taskstats.c
90555index 13d2f7c..c93d0b0 100644
90556--- a/kernel/taskstats.c
90557+++ b/kernel/taskstats.c
90558@@ -28,9 +28,12 @@
90559 #include <linux/fs.h>
90560 #include <linux/file.h>
90561 #include <linux/pid_namespace.h>
90562+#include <linux/grsecurity.h>
90563 #include <net/genetlink.h>
90564 #include <linux/atomic.h>
90565
90566+extern int gr_is_taskstats_denied(int pid);
90567+
90568 /*
90569 * Maximum length of a cpumask that can be specified in
90570 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
90571@@ -576,6 +579,9 @@ err:
90572
90573 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
90574 {
90575+ if (gr_is_taskstats_denied(current->pid))
90576+ return -EACCES;
90577+
90578 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
90579 return cmd_attr_register_cpumask(info);
90580 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
90581diff --git a/kernel/time.c b/kernel/time.c
90582index 7c7964c..2a0d412 100644
90583--- a/kernel/time.c
90584+++ b/kernel/time.c
90585@@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
90586 return error;
90587
90588 if (tz) {
90589+ /* we log in do_settimeofday called below, so don't log twice
90590+ */
90591+ if (!tv)
90592+ gr_log_timechange();
90593+
90594 sys_tz = *tz;
90595 update_vsyscall_tz();
90596 if (firsttime) {
90597diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
90598index 88c9c65..7497ebc 100644
90599--- a/kernel/time/alarmtimer.c
90600+++ b/kernel/time/alarmtimer.c
90601@@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
90602 struct platform_device *pdev;
90603 int error = 0;
90604 int i;
90605- struct k_clock alarm_clock = {
90606+ static struct k_clock alarm_clock = {
90607 .clock_getres = alarm_clock_getres,
90608 .clock_get = alarm_clock_get,
90609 .timer_create = alarm_timer_create,
90610diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
90611index 5b40279..81e58db 100644
90612--- a/kernel/time/timekeeping.c
90613+++ b/kernel/time/timekeeping.c
90614@@ -15,6 +15,7 @@
90615 #include <linux/init.h>
90616 #include <linux/mm.h>
90617 #include <linux/sched.h>
90618+#include <linux/grsecurity.h>
90619 #include <linux/syscore_ops.h>
90620 #include <linux/clocksource.h>
90621 #include <linux/jiffies.h>
90622@@ -501,6 +502,8 @@ int do_settimeofday(const struct timespec *tv)
90623 if (!timespec_valid_strict(tv))
90624 return -EINVAL;
90625
90626+ gr_log_timechange();
90627+
90628 raw_spin_lock_irqsave(&timekeeper_lock, flags);
90629 write_seqcount_begin(&timekeeper_seq);
90630
90631diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
90632index 61ed862..3b52c65 100644
90633--- a/kernel/time/timer_list.c
90634+++ b/kernel/time/timer_list.c
90635@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
90636
90637 static void print_name_offset(struct seq_file *m, void *sym)
90638 {
90639+#ifdef CONFIG_GRKERNSEC_HIDESYM
90640+ SEQ_printf(m, "<%p>", NULL);
90641+#else
90642 char symname[KSYM_NAME_LEN];
90643
90644 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
90645 SEQ_printf(m, "<%pK>", sym);
90646 else
90647 SEQ_printf(m, "%s", symname);
90648+#endif
90649 }
90650
90651 static void
90652@@ -119,7 +123,11 @@ next_one:
90653 static void
90654 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
90655 {
90656+#ifdef CONFIG_GRKERNSEC_HIDESYM
90657+ SEQ_printf(m, " .base: %p\n", NULL);
90658+#else
90659 SEQ_printf(m, " .base: %pK\n", base);
90660+#endif
90661 SEQ_printf(m, " .index: %d\n",
90662 base->index);
90663 SEQ_printf(m, " .resolution: %Lu nsecs\n",
90664@@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
90665 {
90666 struct proc_dir_entry *pe;
90667
90668+#ifdef CONFIG_GRKERNSEC_PROC_ADD
90669+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
90670+#else
90671 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
90672+#endif
90673 if (!pe)
90674 return -ENOMEM;
90675 return 0;
90676diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
90677index 1fb08f2..ca4bb1e 100644
90678--- a/kernel/time/timer_stats.c
90679+++ b/kernel/time/timer_stats.c
90680@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
90681 static unsigned long nr_entries;
90682 static struct entry entries[MAX_ENTRIES];
90683
90684-static atomic_t overflow_count;
90685+static atomic_unchecked_t overflow_count;
90686
90687 /*
90688 * The entries are in a hash-table, for fast lookup:
90689@@ -140,7 +140,7 @@ static void reset_entries(void)
90690 nr_entries = 0;
90691 memset(entries, 0, sizeof(entries));
90692 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
90693- atomic_set(&overflow_count, 0);
90694+ atomic_set_unchecked(&overflow_count, 0);
90695 }
90696
90697 static struct entry *alloc_entry(void)
90698@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
90699 if (likely(entry))
90700 entry->count++;
90701 else
90702- atomic_inc(&overflow_count);
90703+ atomic_inc_unchecked(&overflow_count);
90704
90705 out_unlock:
90706 raw_spin_unlock_irqrestore(lock, flags);
90707@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
90708
90709 static void print_name_offset(struct seq_file *m, unsigned long addr)
90710 {
90711+#ifdef CONFIG_GRKERNSEC_HIDESYM
90712+ seq_printf(m, "<%p>", NULL);
90713+#else
90714 char symname[KSYM_NAME_LEN];
90715
90716 if (lookup_symbol_name(addr, symname) < 0)
90717- seq_printf(m, "<%p>", (void *)addr);
90718+ seq_printf(m, "<%pK>", (void *)addr);
90719 else
90720 seq_printf(m, "%s", symname);
90721+#endif
90722 }
90723
90724 static int tstats_show(struct seq_file *m, void *v)
90725@@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
90726
90727 seq_puts(m, "Timer Stats Version: v0.3\n");
90728 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
90729- if (atomic_read(&overflow_count))
90730- seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
90731+ if (atomic_read_unchecked(&overflow_count))
90732+ seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
90733 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
90734
90735 for (i = 0; i < nr_entries; i++) {
90736@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
90737 {
90738 struct proc_dir_entry *pe;
90739
90740+#ifdef CONFIG_GRKERNSEC_PROC_ADD
90741+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
90742+#else
90743 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
90744+#endif
90745 if (!pe)
90746 return -ENOMEM;
90747 return 0;
90748diff --git a/kernel/timer.c b/kernel/timer.c
90749index accfd24..e00f0c0 100644
90750--- a/kernel/timer.c
90751+++ b/kernel/timer.c
90752@@ -1366,7 +1366,7 @@ void update_process_times(int user_tick)
90753 /*
90754 * This function runs timers and the timer-tq in bottom half context.
90755 */
90756-static void run_timer_softirq(struct softirq_action *h)
90757+static __latent_entropy void run_timer_softirq(void)
90758 {
90759 struct tvec_base *base = __this_cpu_read(tvec_bases);
90760
90761@@ -1429,7 +1429,7 @@ static void process_timeout(unsigned long __data)
90762 *
90763 * In all cases the return value is guaranteed to be non-negative.
90764 */
90765-signed long __sched schedule_timeout(signed long timeout)
90766+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
90767 {
90768 struct timer_list timer;
90769 unsigned long expire;
90770diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
90771index b418cb0..f879a3d 100644
90772--- a/kernel/trace/blktrace.c
90773+++ b/kernel/trace/blktrace.c
90774@@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
90775 struct blk_trace *bt = filp->private_data;
90776 char buf[16];
90777
90778- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
90779+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
90780
90781 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
90782 }
90783@@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
90784 return 1;
90785
90786 bt = buf->chan->private_data;
90787- atomic_inc(&bt->dropped);
90788+ atomic_inc_unchecked(&bt->dropped);
90789 return 0;
90790 }
90791
90792@@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
90793
90794 bt->dir = dir;
90795 bt->dev = dev;
90796- atomic_set(&bt->dropped, 0);
90797+ atomic_set_unchecked(&bt->dropped, 0);
90798 INIT_LIST_HEAD(&bt->running_list);
90799
90800 ret = -EIO;
90801diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
90802index cd7f76d..553c805 100644
90803--- a/kernel/trace/ftrace.c
90804+++ b/kernel/trace/ftrace.c
90805@@ -1965,12 +1965,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
90806 if (unlikely(ftrace_disabled))
90807 return 0;
90808
90809+ ret = ftrace_arch_code_modify_prepare();
90810+ FTRACE_WARN_ON(ret);
90811+ if (ret)
90812+ return 0;
90813+
90814 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
90815+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
90816 if (ret) {
90817 ftrace_bug(ret, ip);
90818- return 0;
90819 }
90820- return 1;
90821+ return ret ? 0 : 1;
90822 }
90823
90824 /*
90825@@ -4177,8 +4182,10 @@ static int ftrace_process_locs(struct module *mod,
90826 if (!count)
90827 return 0;
90828
90829+ pax_open_kernel();
90830 sort(start, count, sizeof(*start),
90831 ftrace_cmp_ips, ftrace_swap_ips);
90832+ pax_close_kernel();
90833
90834 start_pg = ftrace_allocate_pages(count);
90835 if (!start_pg)
90836@@ -4909,8 +4916,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
90837 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
90838
90839 static int ftrace_graph_active;
90840-static struct notifier_block ftrace_suspend_notifier;
90841-
90842 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
90843 {
90844 return 0;
90845@@ -5086,6 +5091,10 @@ static void update_function_graph_func(void)
90846 ftrace_graph_entry = ftrace_graph_entry_test;
90847 }
90848
90849+static struct notifier_block ftrace_suspend_notifier = {
90850+ .notifier_call = ftrace_suspend_notifier_call
90851+};
90852+
90853 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
90854 trace_func_graph_ent_t entryfunc)
90855 {
90856@@ -5099,7 +5108,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
90857 goto out;
90858 }
90859
90860- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
90861 register_pm_notifier(&ftrace_suspend_notifier);
90862
90863 ftrace_graph_active++;
90864diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
90865index fc4da2d..f3e800b 100644
90866--- a/kernel/trace/ring_buffer.c
90867+++ b/kernel/trace/ring_buffer.c
90868@@ -352,9 +352,9 @@ struct buffer_data_page {
90869 */
90870 struct buffer_page {
90871 struct list_head list; /* list of buffer pages */
90872- local_t write; /* index for next write */
90873+ local_unchecked_t write; /* index for next write */
90874 unsigned read; /* index for next read */
90875- local_t entries; /* entries on this page */
90876+ local_unchecked_t entries; /* entries on this page */
90877 unsigned long real_end; /* real end of data */
90878 struct buffer_data_page *page; /* Actual data page */
90879 };
90880@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
90881 unsigned long last_overrun;
90882 local_t entries_bytes;
90883 local_t entries;
90884- local_t overrun;
90885- local_t commit_overrun;
90886+ local_unchecked_t overrun;
90887+ local_unchecked_t commit_overrun;
90888 local_t dropped_events;
90889 local_t committing;
90890 local_t commits;
90891@@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
90892 *
90893 * We add a counter to the write field to denote this.
90894 */
90895- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
90896- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
90897+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
90898+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
90899
90900 /*
90901 * Just make sure we have seen our old_write and synchronize
90902@@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
90903 * cmpxchg to only update if an interrupt did not already
90904 * do it for us. If the cmpxchg fails, we don't care.
90905 */
90906- (void)local_cmpxchg(&next_page->write, old_write, val);
90907- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
90908+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
90909+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
90910
90911 /*
90912 * No need to worry about races with clearing out the commit.
90913@@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
90914
90915 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
90916 {
90917- return local_read(&bpage->entries) & RB_WRITE_MASK;
90918+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
90919 }
90920
90921 static inline unsigned long rb_page_write(struct buffer_page *bpage)
90922 {
90923- return local_read(&bpage->write) & RB_WRITE_MASK;
90924+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
90925 }
90926
90927 static int
90928@@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
90929 * bytes consumed in ring buffer from here.
90930 * Increment overrun to account for the lost events.
90931 */
90932- local_add(page_entries, &cpu_buffer->overrun);
90933+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
90934 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
90935 }
90936
90937@@ -2064,7 +2064,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
90938 * it is our responsibility to update
90939 * the counters.
90940 */
90941- local_add(entries, &cpu_buffer->overrun);
90942+ local_add_unchecked(entries, &cpu_buffer->overrun);
90943 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
90944
90945 /*
90946@@ -2214,7 +2214,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
90947 if (tail == BUF_PAGE_SIZE)
90948 tail_page->real_end = 0;
90949
90950- local_sub(length, &tail_page->write);
90951+ local_sub_unchecked(length, &tail_page->write);
90952 return;
90953 }
90954
90955@@ -2249,7 +2249,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
90956 rb_event_set_padding(event);
90957
90958 /* Set the write back to the previous setting */
90959- local_sub(length, &tail_page->write);
90960+ local_sub_unchecked(length, &tail_page->write);
90961 return;
90962 }
90963
90964@@ -2261,7 +2261,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
90965
90966 /* Set write to end of buffer */
90967 length = (tail + length) - BUF_PAGE_SIZE;
90968- local_sub(length, &tail_page->write);
90969+ local_sub_unchecked(length, &tail_page->write);
90970 }
90971
90972 /*
90973@@ -2287,7 +2287,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
90974 * about it.
90975 */
90976 if (unlikely(next_page == commit_page)) {
90977- local_inc(&cpu_buffer->commit_overrun);
90978+ local_inc_unchecked(&cpu_buffer->commit_overrun);
90979 goto out_reset;
90980 }
90981
90982@@ -2343,7 +2343,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
90983 cpu_buffer->tail_page) &&
90984 (cpu_buffer->commit_page ==
90985 cpu_buffer->reader_page))) {
90986- local_inc(&cpu_buffer->commit_overrun);
90987+ local_inc_unchecked(&cpu_buffer->commit_overrun);
90988 goto out_reset;
90989 }
90990 }
90991@@ -2391,7 +2391,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
90992 length += RB_LEN_TIME_EXTEND;
90993
90994 tail_page = cpu_buffer->tail_page;
90995- write = local_add_return(length, &tail_page->write);
90996+ write = local_add_return_unchecked(length, &tail_page->write);
90997
90998 /* set write to only the index of the write */
90999 write &= RB_WRITE_MASK;
91000@@ -2415,7 +2415,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
91001 kmemcheck_annotate_bitfield(event, bitfield);
91002 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
91003
91004- local_inc(&tail_page->entries);
91005+ local_inc_unchecked(&tail_page->entries);
91006
91007 /*
91008 * If this is the first commit on the page, then update
91009@@ -2448,7 +2448,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
91010
91011 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
91012 unsigned long write_mask =
91013- local_read(&bpage->write) & ~RB_WRITE_MASK;
91014+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
91015 unsigned long event_length = rb_event_length(event);
91016 /*
91017 * This is on the tail page. It is possible that
91018@@ -2458,7 +2458,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
91019 */
91020 old_index += write_mask;
91021 new_index += write_mask;
91022- index = local_cmpxchg(&bpage->write, old_index, new_index);
91023+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
91024 if (index == old_index) {
91025 /* update counters */
91026 local_sub(event_length, &cpu_buffer->entries_bytes);
91027@@ -2850,7 +2850,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
91028
91029 /* Do the likely case first */
91030 if (likely(bpage->page == (void *)addr)) {
91031- local_dec(&bpage->entries);
91032+ local_dec_unchecked(&bpage->entries);
91033 return;
91034 }
91035
91036@@ -2862,7 +2862,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
91037 start = bpage;
91038 do {
91039 if (bpage->page == (void *)addr) {
91040- local_dec(&bpage->entries);
91041+ local_dec_unchecked(&bpage->entries);
91042 return;
91043 }
91044 rb_inc_page(cpu_buffer, &bpage);
91045@@ -3146,7 +3146,7 @@ static inline unsigned long
91046 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
91047 {
91048 return local_read(&cpu_buffer->entries) -
91049- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
91050+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
91051 }
91052
91053 /**
91054@@ -3235,7 +3235,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
91055 return 0;
91056
91057 cpu_buffer = buffer->buffers[cpu];
91058- ret = local_read(&cpu_buffer->overrun);
91059+ ret = local_read_unchecked(&cpu_buffer->overrun);
91060
91061 return ret;
91062 }
91063@@ -3258,7 +3258,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
91064 return 0;
91065
91066 cpu_buffer = buffer->buffers[cpu];
91067- ret = local_read(&cpu_buffer->commit_overrun);
91068+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
91069
91070 return ret;
91071 }
91072@@ -3343,7 +3343,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
91073 /* if you care about this being correct, lock the buffer */
91074 for_each_buffer_cpu(buffer, cpu) {
91075 cpu_buffer = buffer->buffers[cpu];
91076- overruns += local_read(&cpu_buffer->overrun);
91077+ overruns += local_read_unchecked(&cpu_buffer->overrun);
91078 }
91079
91080 return overruns;
91081@@ -3519,8 +3519,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
91082 /*
91083 * Reset the reader page to size zero.
91084 */
91085- local_set(&cpu_buffer->reader_page->write, 0);
91086- local_set(&cpu_buffer->reader_page->entries, 0);
91087+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
91088+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
91089 local_set(&cpu_buffer->reader_page->page->commit, 0);
91090 cpu_buffer->reader_page->real_end = 0;
91091
91092@@ -3554,7 +3554,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
91093 * want to compare with the last_overrun.
91094 */
91095 smp_mb();
91096- overwrite = local_read(&(cpu_buffer->overrun));
91097+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
91098
91099 /*
91100 * Here's the tricky part.
91101@@ -4124,8 +4124,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
91102
91103 cpu_buffer->head_page
91104 = list_entry(cpu_buffer->pages, struct buffer_page, list);
91105- local_set(&cpu_buffer->head_page->write, 0);
91106- local_set(&cpu_buffer->head_page->entries, 0);
91107+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
91108+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
91109 local_set(&cpu_buffer->head_page->page->commit, 0);
91110
91111 cpu_buffer->head_page->read = 0;
91112@@ -4135,14 +4135,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
91113
91114 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
91115 INIT_LIST_HEAD(&cpu_buffer->new_pages);
91116- local_set(&cpu_buffer->reader_page->write, 0);
91117- local_set(&cpu_buffer->reader_page->entries, 0);
91118+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
91119+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
91120 local_set(&cpu_buffer->reader_page->page->commit, 0);
91121 cpu_buffer->reader_page->read = 0;
91122
91123 local_set(&cpu_buffer->entries_bytes, 0);
91124- local_set(&cpu_buffer->overrun, 0);
91125- local_set(&cpu_buffer->commit_overrun, 0);
91126+ local_set_unchecked(&cpu_buffer->overrun, 0);
91127+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
91128 local_set(&cpu_buffer->dropped_events, 0);
91129 local_set(&cpu_buffer->entries, 0);
91130 local_set(&cpu_buffer->committing, 0);
91131@@ -4547,8 +4547,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
91132 rb_init_page(bpage);
91133 bpage = reader->page;
91134 reader->page = *data_page;
91135- local_set(&reader->write, 0);
91136- local_set(&reader->entries, 0);
91137+ local_set_unchecked(&reader->write, 0);
91138+ local_set_unchecked(&reader->entries, 0);
91139 reader->read = 0;
91140 *data_page = bpage;
91141
91142diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
91143index 24c1f23..781fd73f 100644
91144--- a/kernel/trace/trace.c
91145+++ b/kernel/trace/trace.c
91146@@ -3399,7 +3399,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
91147 return 0;
91148 }
91149
91150-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
91151+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
91152 {
91153 /* do nothing if flag is already set */
91154 if (!!(trace_flags & mask) == !!enabled)
91155diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
91156index 02b592f..f971546 100644
91157--- a/kernel/trace/trace.h
91158+++ b/kernel/trace/trace.h
91159@@ -1233,7 +1233,7 @@ extern const char *__stop___tracepoint_str[];
91160 void trace_printk_init_buffers(void);
91161 void trace_printk_start_comm(void);
91162 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
91163-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
91164+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
91165
91166 /*
91167 * Normal trace_printk() and friends allocates special buffers
91168diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
91169index 26dc348..8708ca7 100644
91170--- a/kernel/trace/trace_clock.c
91171+++ b/kernel/trace/trace_clock.c
91172@@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
91173 return now;
91174 }
91175
91176-static atomic64_t trace_counter;
91177+static atomic64_unchecked_t trace_counter;
91178
91179 /*
91180 * trace_clock_counter(): simply an atomic counter.
91181@@ -132,5 +132,5 @@ static atomic64_t trace_counter;
91182 */
91183 u64 notrace trace_clock_counter(void)
91184 {
91185- return atomic64_add_return(1, &trace_counter);
91186+ return atomic64_inc_return_unchecked(&trace_counter);
91187 }
91188diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
91189index 7b16d40..1b2875d 100644
91190--- a/kernel/trace/trace_events.c
91191+++ b/kernel/trace/trace_events.c
91192@@ -1681,7 +1681,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
91193 return 0;
91194 }
91195
91196-struct ftrace_module_file_ops;
91197 static void __add_event_to_tracers(struct ftrace_event_call *call);
91198
91199 /* Add an additional event_call dynamically */
91200diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
91201index 0abd9b8..6a663a2 100644
91202--- a/kernel/trace/trace_mmiotrace.c
91203+++ b/kernel/trace/trace_mmiotrace.c
91204@@ -24,7 +24,7 @@ struct header_iter {
91205 static struct trace_array *mmio_trace_array;
91206 static bool overrun_detected;
91207 static unsigned long prev_overruns;
91208-static atomic_t dropped_count;
91209+static atomic_unchecked_t dropped_count;
91210
91211 static void mmio_reset_data(struct trace_array *tr)
91212 {
91213@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
91214
91215 static unsigned long count_overruns(struct trace_iterator *iter)
91216 {
91217- unsigned long cnt = atomic_xchg(&dropped_count, 0);
91218+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
91219 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
91220
91221 if (over > prev_overruns)
91222@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
91223 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
91224 sizeof(*entry), 0, pc);
91225 if (!event) {
91226- atomic_inc(&dropped_count);
91227+ atomic_inc_unchecked(&dropped_count);
91228 return;
91229 }
91230 entry = ring_buffer_event_data(event);
91231@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
91232 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
91233 sizeof(*entry), 0, pc);
91234 if (!event) {
91235- atomic_inc(&dropped_count);
91236+ atomic_inc_unchecked(&dropped_count);
91237 return;
91238 }
91239 entry = ring_buffer_event_data(event);
91240diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
91241index ed32284..884d6c3 100644
91242--- a/kernel/trace/trace_output.c
91243+++ b/kernel/trace/trace_output.c
91244@@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
91245
91246 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
91247 if (!IS_ERR(p)) {
91248- p = mangle_path(s->buffer + s->len, p, "\n");
91249+ p = mangle_path(s->buffer + s->len, p, "\n\\");
91250 if (p) {
91251 s->len = p - s->buffer;
91252 return 1;
91253@@ -908,14 +908,16 @@ int register_ftrace_event(struct trace_event *event)
91254 goto out;
91255 }
91256
91257+ pax_open_kernel();
91258 if (event->funcs->trace == NULL)
91259- event->funcs->trace = trace_nop_print;
91260+ *(void **)&event->funcs->trace = trace_nop_print;
91261 if (event->funcs->raw == NULL)
91262- event->funcs->raw = trace_nop_print;
91263+ *(void **)&event->funcs->raw = trace_nop_print;
91264 if (event->funcs->hex == NULL)
91265- event->funcs->hex = trace_nop_print;
91266+ *(void **)&event->funcs->hex = trace_nop_print;
91267 if (event->funcs->binary == NULL)
91268- event->funcs->binary = trace_nop_print;
91269+ *(void **)&event->funcs->binary = trace_nop_print;
91270+ pax_close_kernel();
91271
91272 key = event->type & (EVENT_HASHSIZE - 1);
91273
91274diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
91275index e6be585..d73ae5e 100644
91276--- a/kernel/trace/trace_stack.c
91277+++ b/kernel/trace/trace_stack.c
91278@@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
91279 return;
91280
91281 /* we do not handle interrupt stacks yet */
91282- if (!object_is_on_stack(stack))
91283+ if (!object_starts_on_stack(stack))
91284 return;
91285
91286 local_irq_save(flags);
91287diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
91288index 80a57af..7f5a7ff 100644
91289--- a/kernel/user_namespace.c
91290+++ b/kernel/user_namespace.c
91291@@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
91292 !kgid_has_mapping(parent_ns, group))
91293 return -EPERM;
91294
91295+#ifdef CONFIG_GRKERNSEC
91296+ /*
91297+ * This doesn't really inspire confidence:
91298+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
91299+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
91300+ * Increases kernel attack surface in areas developers
91301+ * previously cared little about ("low importance due
91302+ * to requiring "root" capability")
91303+ * To be removed when this code receives *proper* review
91304+ */
91305+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
91306+ !capable(CAP_SETGID))
91307+ return -EPERM;
91308+#endif
91309+
91310 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
91311 if (!ns)
91312 return -ENOMEM;
91313@@ -865,7 +880,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
91314 if (atomic_read(&current->mm->mm_users) > 1)
91315 return -EINVAL;
91316
91317- if (current->fs->users != 1)
91318+ if (atomic_read(&current->fs->users) != 1)
91319 return -EINVAL;
91320
91321 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
91322diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
91323index 4f69f9a..7c6f8f8 100644
91324--- a/kernel/utsname_sysctl.c
91325+++ b/kernel/utsname_sysctl.c
91326@@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
91327 static int proc_do_uts_string(ctl_table *table, int write,
91328 void __user *buffer, size_t *lenp, loff_t *ppos)
91329 {
91330- struct ctl_table uts_table;
91331+ ctl_table_no_const uts_table;
91332 int r;
91333 memcpy(&uts_table, table, sizeof(uts_table));
91334 uts_table.data = get_uts(table, write);
91335diff --git a/kernel/watchdog.c b/kernel/watchdog.c
91336index 4431610..4265616 100644
91337--- a/kernel/watchdog.c
91338+++ b/kernel/watchdog.c
91339@@ -475,7 +475,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
91340 static void watchdog_nmi_disable(unsigned int cpu) { return; }
91341 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
91342
91343-static struct smp_hotplug_thread watchdog_threads = {
91344+static struct smp_hotplug_thread watchdog_threads __read_only = {
91345 .store = &softlockup_watchdog,
91346 .thread_should_run = watchdog_should_run,
91347 .thread_fn = watchdog,
91348diff --git a/kernel/workqueue.c b/kernel/workqueue.c
91349index 193e977..26dd63f 100644
91350--- a/kernel/workqueue.c
91351+++ b/kernel/workqueue.c
91352@@ -4678,7 +4678,7 @@ static void rebind_workers(struct worker_pool *pool)
91353 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
91354 worker_flags |= WORKER_REBOUND;
91355 worker_flags &= ~WORKER_UNBOUND;
91356- ACCESS_ONCE(worker->flags) = worker_flags;
91357+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
91358 }
91359
91360 spin_unlock_irq(&pool->lock);
91361diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
91362index a48abea..e108def 100644
91363--- a/lib/Kconfig.debug
91364+++ b/lib/Kconfig.debug
91365@@ -854,7 +854,7 @@ config DEBUG_MUTEXES
91366
91367 config DEBUG_WW_MUTEX_SLOWPATH
91368 bool "Wait/wound mutex debugging: Slowpath testing"
91369- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91370+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91371 select DEBUG_LOCK_ALLOC
91372 select DEBUG_SPINLOCK
91373 select DEBUG_MUTEXES
91374@@ -867,7 +867,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
91375
91376 config DEBUG_LOCK_ALLOC
91377 bool "Lock debugging: detect incorrect freeing of live locks"
91378- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91379+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91380 select DEBUG_SPINLOCK
91381 select DEBUG_MUTEXES
91382 select LOCKDEP
91383@@ -881,7 +881,7 @@ config DEBUG_LOCK_ALLOC
91384
91385 config PROVE_LOCKING
91386 bool "Lock debugging: prove locking correctness"
91387- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91388+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91389 select LOCKDEP
91390 select DEBUG_SPINLOCK
91391 select DEBUG_MUTEXES
91392@@ -932,7 +932,7 @@ config LOCKDEP
91393
91394 config LOCK_STAT
91395 bool "Lock usage statistics"
91396- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91397+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91398 select LOCKDEP
91399 select DEBUG_SPINLOCK
91400 select DEBUG_MUTEXES
91401@@ -1394,6 +1394,7 @@ config LATENCYTOP
91402 depends on DEBUG_KERNEL
91403 depends on STACKTRACE_SUPPORT
91404 depends on PROC_FS
91405+ depends on !GRKERNSEC_HIDESYM
91406 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
91407 select KALLSYMS
91408 select KALLSYMS_ALL
91409@@ -1410,7 +1411,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
91410 config DEBUG_STRICT_USER_COPY_CHECKS
91411 bool "Strict user copy size checks"
91412 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
91413- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
91414+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
91415 help
91416 Enabling this option turns a certain set of sanity checks for user
91417 copy operations into compile time failures.
91418@@ -1529,7 +1530,7 @@ endmenu # runtime tests
91419
91420 config PROVIDE_OHCI1394_DMA_INIT
91421 bool "Remote debugging over FireWire early on boot"
91422- depends on PCI && X86
91423+ depends on PCI && X86 && !GRKERNSEC
91424 help
91425 If you want to debug problems which hang or crash the kernel early
91426 on boot and the crashing machine has a FireWire port, you can use
91427diff --git a/lib/Makefile b/lib/Makefile
91428index 48140e3..de854e5 100644
91429--- a/lib/Makefile
91430+++ b/lib/Makefile
91431@@ -52,7 +52,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
91432 obj-$(CONFIG_BTREE) += btree.o
91433 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
91434 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
91435-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
91436+obj-y += list_debug.o
91437 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
91438
91439 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
91440diff --git a/lib/average.c b/lib/average.c
91441index 114d1be..ab0350c 100644
91442--- a/lib/average.c
91443+++ b/lib/average.c
91444@@ -55,7 +55,7 @@ struct ewma *ewma_add(struct ewma *avg, unsigned long val)
91445 {
91446 unsigned long internal = ACCESS_ONCE(avg->internal);
91447
91448- ACCESS_ONCE(avg->internal) = internal ?
91449+ ACCESS_ONCE_RW(avg->internal) = internal ?
91450 (((internal << avg->weight) - internal) +
91451 (val << avg->factor)) >> avg->weight :
91452 (val << avg->factor);
91453diff --git a/lib/bitmap.c b/lib/bitmap.c
91454index 06f7e4f..f3cf2b0 100644
91455--- a/lib/bitmap.c
91456+++ b/lib/bitmap.c
91457@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
91458 {
91459 int c, old_c, totaldigits, ndigits, nchunks, nbits;
91460 u32 chunk;
91461- const char __user __force *ubuf = (const char __user __force *)buf;
91462+ const char __user *ubuf = (const char __force_user *)buf;
91463
91464 bitmap_zero(maskp, nmaskbits);
91465
91466@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
91467 {
91468 if (!access_ok(VERIFY_READ, ubuf, ulen))
91469 return -EFAULT;
91470- return __bitmap_parse((const char __force *)ubuf,
91471+ return __bitmap_parse((const char __force_kernel *)ubuf,
91472 ulen, 1, maskp, nmaskbits);
91473
91474 }
91475@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
91476 {
91477 unsigned a, b;
91478 int c, old_c, totaldigits;
91479- const char __user __force *ubuf = (const char __user __force *)buf;
91480+ const char __user *ubuf = (const char __force_user *)buf;
91481 int exp_digit, in_range;
91482
91483 totaldigits = c = 0;
91484@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
91485 {
91486 if (!access_ok(VERIFY_READ, ubuf, ulen))
91487 return -EFAULT;
91488- return __bitmap_parselist((const char __force *)ubuf,
91489+ return __bitmap_parselist((const char __force_kernel *)ubuf,
91490 ulen, 1, maskp, nmaskbits);
91491 }
91492 EXPORT_SYMBOL(bitmap_parselist_user);
91493diff --git a/lib/bug.c b/lib/bug.c
91494index 1686034..a9c00c8 100644
91495--- a/lib/bug.c
91496+++ b/lib/bug.c
91497@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
91498 return BUG_TRAP_TYPE_NONE;
91499
91500 bug = find_bug(bugaddr);
91501+ if (!bug)
91502+ return BUG_TRAP_TYPE_NONE;
91503
91504 file = NULL;
91505 line = 0;
91506diff --git a/lib/debugobjects.c b/lib/debugobjects.c
91507index e0731c3..ad66444 100644
91508--- a/lib/debugobjects.c
91509+++ b/lib/debugobjects.c
91510@@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
91511 if (limit > 4)
91512 return;
91513
91514- is_on_stack = object_is_on_stack(addr);
91515+ is_on_stack = object_starts_on_stack(addr);
91516 if (is_on_stack == onstack)
91517 return;
91518
91519diff --git a/lib/devres.c b/lib/devres.c
91520index 8235331..5881053 100644
91521--- a/lib/devres.c
91522+++ b/lib/devres.c
91523@@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
91524 void devm_iounmap(struct device *dev, void __iomem *addr)
91525 {
91526 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
91527- (void *)addr));
91528+ (void __force *)addr));
91529 iounmap(addr);
91530 }
91531 EXPORT_SYMBOL(devm_iounmap);
91532@@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
91533 {
91534 ioport_unmap(addr);
91535 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
91536- devm_ioport_map_match, (void *)addr));
91537+ devm_ioport_map_match, (void __force *)addr));
91538 }
91539 EXPORT_SYMBOL(devm_ioport_unmap);
91540 #endif /* CONFIG_HAS_IOPORT */
91541diff --git a/lib/div64.c b/lib/div64.c
91542index 4382ad7..08aa558 100644
91543--- a/lib/div64.c
91544+++ b/lib/div64.c
91545@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
91546 EXPORT_SYMBOL(__div64_32);
91547
91548 #ifndef div_s64_rem
91549-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
91550+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
91551 {
91552 u64 quotient;
91553
91554@@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
91555 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
91556 */
91557 #ifndef div64_u64
91558-u64 div64_u64(u64 dividend, u64 divisor)
91559+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
91560 {
91561 u32 high = divisor >> 32;
91562 u64 quot;
91563diff --git a/lib/dma-debug.c b/lib/dma-debug.c
91564index 98f2d7e..899da5c 100644
91565--- a/lib/dma-debug.c
91566+++ b/lib/dma-debug.c
91567@@ -971,7 +971,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
91568
91569 void dma_debug_add_bus(struct bus_type *bus)
91570 {
91571- struct notifier_block *nb;
91572+ notifier_block_no_const *nb;
91573
91574 if (global_disable)
91575 return;
91576@@ -1148,7 +1148,7 @@ static void check_unmap(struct dma_debug_entry *ref)
91577
91578 static void check_for_stack(struct device *dev, void *addr)
91579 {
91580- if (object_is_on_stack(addr))
91581+ if (object_starts_on_stack(addr))
91582 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
91583 "stack [addr=%p]\n", addr);
91584 }
91585diff --git a/lib/hash.c b/lib/hash.c
91586index fea973f..386626f 100644
91587--- a/lib/hash.c
91588+++ b/lib/hash.c
91589@@ -14,7 +14,7 @@
91590 #include <linux/hash.h>
91591 #include <linux/cache.h>
91592
91593-static struct fast_hash_ops arch_hash_ops __read_mostly = {
91594+static struct fast_hash_ops arch_hash_ops __read_only = {
91595 .hash = jhash,
91596 .hash2 = jhash2,
91597 };
91598diff --git a/lib/inflate.c b/lib/inflate.c
91599index 013a761..c28f3fc 100644
91600--- a/lib/inflate.c
91601+++ b/lib/inflate.c
91602@@ -269,7 +269,7 @@ static void free(void *where)
91603 malloc_ptr = free_mem_ptr;
91604 }
91605 #else
91606-#define malloc(a) kmalloc(a, GFP_KERNEL)
91607+#define malloc(a) kmalloc((a), GFP_KERNEL)
91608 #define free(a) kfree(a)
91609 #endif
91610
91611diff --git a/lib/ioremap.c b/lib/ioremap.c
91612index 0c9216c..863bd89 100644
91613--- a/lib/ioremap.c
91614+++ b/lib/ioremap.c
91615@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
91616 unsigned long next;
91617
91618 phys_addr -= addr;
91619- pmd = pmd_alloc(&init_mm, pud, addr);
91620+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
91621 if (!pmd)
91622 return -ENOMEM;
91623 do {
91624@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
91625 unsigned long next;
91626
91627 phys_addr -= addr;
91628- pud = pud_alloc(&init_mm, pgd, addr);
91629+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
91630 if (!pud)
91631 return -ENOMEM;
91632 do {
91633diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
91634index bd2bea9..6b3c95e 100644
91635--- a/lib/is_single_threaded.c
91636+++ b/lib/is_single_threaded.c
91637@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
91638 struct task_struct *p, *t;
91639 bool ret;
91640
91641+ if (!mm)
91642+ return true;
91643+
91644 if (atomic_read(&task->signal->live) != 1)
91645 return false;
91646
91647diff --git a/lib/kobject.c b/lib/kobject.c
91648index cb14aea..8c53cdb 100644
91649--- a/lib/kobject.c
91650+++ b/lib/kobject.c
91651@@ -931,9 +931,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
91652
91653
91654 static DEFINE_SPINLOCK(kobj_ns_type_lock);
91655-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
91656+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
91657
91658-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
91659+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
91660 {
91661 enum kobj_ns_type type = ops->type;
91662 int error;
91663diff --git a/lib/list_debug.c b/lib/list_debug.c
91664index c24c2f7..f0296f4 100644
91665--- a/lib/list_debug.c
91666+++ b/lib/list_debug.c
91667@@ -11,7 +11,9 @@
91668 #include <linux/bug.h>
91669 #include <linux/kernel.h>
91670 #include <linux/rculist.h>
91671+#include <linux/mm.h>
91672
91673+#ifdef CONFIG_DEBUG_LIST
91674 /*
91675 * Insert a new entry between two known consecutive entries.
91676 *
91677@@ -19,21 +21,40 @@
91678 * the prev/next entries already!
91679 */
91680
91681+static bool __list_add_debug(struct list_head *new,
91682+ struct list_head *prev,
91683+ struct list_head *next)
91684+{
91685+ if (unlikely(next->prev != prev)) {
91686+ printk(KERN_ERR "list_add corruption. next->prev should be "
91687+ "prev (%p), but was %p. (next=%p).\n",
91688+ prev, next->prev, next);
91689+ BUG();
91690+ return false;
91691+ }
91692+ if (unlikely(prev->next != next)) {
91693+ printk(KERN_ERR "list_add corruption. prev->next should be "
91694+ "next (%p), but was %p. (prev=%p).\n",
91695+ next, prev->next, prev);
91696+ BUG();
91697+ return false;
91698+ }
91699+ if (unlikely(new == prev || new == next)) {
91700+ printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
91701+ new, prev, next);
91702+ BUG();
91703+ return false;
91704+ }
91705+ return true;
91706+}
91707+
91708 void __list_add(struct list_head *new,
91709- struct list_head *prev,
91710- struct list_head *next)
91711+ struct list_head *prev,
91712+ struct list_head *next)
91713 {
91714- WARN(next->prev != prev,
91715- "list_add corruption. next->prev should be "
91716- "prev (%p), but was %p. (next=%p).\n",
91717- prev, next->prev, next);
91718- WARN(prev->next != next,
91719- "list_add corruption. prev->next should be "
91720- "next (%p), but was %p. (prev=%p).\n",
91721- next, prev->next, prev);
91722- WARN(new == prev || new == next,
91723- "list_add double add: new=%p, prev=%p, next=%p.\n",
91724- new, prev, next);
91725+ if (!__list_add_debug(new, prev, next))
91726+ return;
91727+
91728 next->prev = new;
91729 new->next = next;
91730 new->prev = prev;
91731@@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
91732 }
91733 EXPORT_SYMBOL(__list_add);
91734
91735-void __list_del_entry(struct list_head *entry)
91736+static bool __list_del_entry_debug(struct list_head *entry)
91737 {
91738 struct list_head *prev, *next;
91739
91740 prev = entry->prev;
91741 next = entry->next;
91742
91743- if (WARN(next == LIST_POISON1,
91744- "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
91745- entry, LIST_POISON1) ||
91746- WARN(prev == LIST_POISON2,
91747- "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
91748- entry, LIST_POISON2) ||
91749- WARN(prev->next != entry,
91750- "list_del corruption. prev->next should be %p, "
91751- "but was %p\n", entry, prev->next) ||
91752- WARN(next->prev != entry,
91753- "list_del corruption. next->prev should be %p, "
91754- "but was %p\n", entry, next->prev))
91755+ if (unlikely(next == LIST_POISON1)) {
91756+ printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
91757+ entry, LIST_POISON1);
91758+ BUG();
91759+ return false;
91760+ }
91761+ if (unlikely(prev == LIST_POISON2)) {
91762+ printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
91763+ entry, LIST_POISON2);
91764+ BUG();
91765+ return false;
91766+ }
91767+ if (unlikely(entry->prev->next != entry)) {
91768+ printk(KERN_ERR "list_del corruption. prev->next should be %p, "
91769+ "but was %p\n", entry, prev->next);
91770+ BUG();
91771+ return false;
91772+ }
91773+ if (unlikely(entry->next->prev != entry)) {
91774+ printk(KERN_ERR "list_del corruption. next->prev should be %p, "
91775+ "but was %p\n", entry, next->prev);
91776+ BUG();
91777+ return false;
91778+ }
91779+ return true;
91780+}
91781+
91782+void __list_del_entry(struct list_head *entry)
91783+{
91784+ if (!__list_del_entry_debug(entry))
91785 return;
91786
91787- __list_del(prev, next);
91788+ __list_del(entry->prev, entry->next);
91789 }
91790 EXPORT_SYMBOL(__list_del_entry);
91791
91792@@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
91793 void __list_add_rcu(struct list_head *new,
91794 struct list_head *prev, struct list_head *next)
91795 {
91796- WARN(next->prev != prev,
91797- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
91798- prev, next->prev, next);
91799- WARN(prev->next != next,
91800- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
91801- next, prev->next, prev);
91802+ if (!__list_add_debug(new, prev, next))
91803+ return;
91804+
91805 new->next = next;
91806 new->prev = prev;
91807 rcu_assign_pointer(list_next_rcu(prev), new);
91808 next->prev = new;
91809 }
91810 EXPORT_SYMBOL(__list_add_rcu);
91811+#endif
91812+
91813+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
91814+{
91815+#ifdef CONFIG_DEBUG_LIST
91816+ if (!__list_add_debug(new, prev, next))
91817+ return;
91818+#endif
91819+
91820+ pax_open_kernel();
91821+ next->prev = new;
91822+ new->next = next;
91823+ new->prev = prev;
91824+ prev->next = new;
91825+ pax_close_kernel();
91826+}
91827+EXPORT_SYMBOL(__pax_list_add);
91828+
91829+void pax_list_del(struct list_head *entry)
91830+{
91831+#ifdef CONFIG_DEBUG_LIST
91832+ if (!__list_del_entry_debug(entry))
91833+ return;
91834+#endif
91835+
91836+ pax_open_kernel();
91837+ __list_del(entry->prev, entry->next);
91838+ entry->next = LIST_POISON1;
91839+ entry->prev = LIST_POISON2;
91840+ pax_close_kernel();
91841+}
91842+EXPORT_SYMBOL(pax_list_del);
91843+
91844+void pax_list_del_init(struct list_head *entry)
91845+{
91846+ pax_open_kernel();
91847+ __list_del(entry->prev, entry->next);
91848+ INIT_LIST_HEAD(entry);
91849+ pax_close_kernel();
91850+}
91851+EXPORT_SYMBOL(pax_list_del_init);
91852+
91853+void __pax_list_add_rcu(struct list_head *new,
91854+ struct list_head *prev, struct list_head *next)
91855+{
91856+#ifdef CONFIG_DEBUG_LIST
91857+ if (!__list_add_debug(new, prev, next))
91858+ return;
91859+#endif
91860+
91861+ pax_open_kernel();
91862+ new->next = next;
91863+ new->prev = prev;
91864+ rcu_assign_pointer(list_next_rcu(prev), new);
91865+ next->prev = new;
91866+ pax_close_kernel();
91867+}
91868+EXPORT_SYMBOL(__pax_list_add_rcu);
91869+
91870+void pax_list_del_rcu(struct list_head *entry)
91871+{
91872+#ifdef CONFIG_DEBUG_LIST
91873+ if (!__list_del_entry_debug(entry))
91874+ return;
91875+#endif
91876+
91877+ pax_open_kernel();
91878+ __list_del(entry->prev, entry->next);
91879+ entry->next = LIST_POISON1;
91880+ entry->prev = LIST_POISON2;
91881+ pax_close_kernel();
91882+}
91883+EXPORT_SYMBOL(pax_list_del_rcu);
91884diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
91885index 963b703..438bc51 100644
91886--- a/lib/percpu-refcount.c
91887+++ b/lib/percpu-refcount.c
91888@@ -29,7 +29,7 @@
91889 * can't hit 0 before we've added up all the percpu refs.
91890 */
91891
91892-#define PCPU_COUNT_BIAS (1U << 31)
91893+#define PCPU_COUNT_BIAS (1U << 30)
91894
91895 /**
91896 * percpu_ref_init - initialize a percpu refcount
91897diff --git a/lib/radix-tree.c b/lib/radix-tree.c
91898index bd4a8df..9e4804f 100644
91899--- a/lib/radix-tree.c
91900+++ b/lib/radix-tree.c
91901@@ -93,7 +93,7 @@ struct radix_tree_preload {
91902 int nr;
91903 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
91904 };
91905-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
91906+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
91907
91908 static inline void *ptr_to_indirect(void *ptr)
91909 {
91910diff --git a/lib/random32.c b/lib/random32.c
91911index 6148967..009bfe8 100644
91912--- a/lib/random32.c
91913+++ b/lib/random32.c
91914@@ -44,7 +44,7 @@
91915 static void __init prandom_state_selftest(void);
91916 #endif
91917
91918-static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
91919+static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
91920
91921 /**
91922 * prandom_u32_state - seeded pseudo-random number generator.
91923diff --git a/lib/rbtree.c b/lib/rbtree.c
91924index 65f4eff..2cfa167 100644
91925--- a/lib/rbtree.c
91926+++ b/lib/rbtree.c
91927@@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
91928 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
91929
91930 static const struct rb_augment_callbacks dummy_callbacks = {
91931- dummy_propagate, dummy_copy, dummy_rotate
91932+ .propagate = dummy_propagate,
91933+ .copy = dummy_copy,
91934+ .rotate = dummy_rotate
91935 };
91936
91937 void rb_insert_color(struct rb_node *node, struct rb_root *root)
91938diff --git a/lib/show_mem.c b/lib/show_mem.c
91939index 0922579..9d7adb9 100644
91940--- a/lib/show_mem.c
91941+++ b/lib/show_mem.c
91942@@ -44,6 +44,6 @@ void show_mem(unsigned int filter)
91943 quicklist_total_size());
91944 #endif
91945 #ifdef CONFIG_MEMORY_FAILURE
91946- printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages));
91947+ printk("%lu pages hwpoisoned\n", atomic_long_read_unchecked(&num_poisoned_pages));
91948 #endif
91949 }
91950diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
91951index bb2b201..46abaf9 100644
91952--- a/lib/strncpy_from_user.c
91953+++ b/lib/strncpy_from_user.c
91954@@ -21,7 +21,7 @@
91955 */
91956 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
91957 {
91958- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91959+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91960 long res = 0;
91961
91962 /*
91963diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
91964index a28df52..3d55877 100644
91965--- a/lib/strnlen_user.c
91966+++ b/lib/strnlen_user.c
91967@@ -26,7 +26,7 @@
91968 */
91969 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
91970 {
91971- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91972+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91973 long align, res = 0;
91974 unsigned long c;
91975
91976diff --git a/lib/swiotlb.c b/lib/swiotlb.c
91977index b604b83..c0547f6 100644
91978--- a/lib/swiotlb.c
91979+++ b/lib/swiotlb.c
91980@@ -674,7 +674,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
91981
91982 void
91983 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
91984- dma_addr_t dev_addr)
91985+ dma_addr_t dev_addr, struct dma_attrs *attrs)
91986 {
91987 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
91988
91989diff --git a/lib/usercopy.c b/lib/usercopy.c
91990index 4f5b1dd..7cab418 100644
91991--- a/lib/usercopy.c
91992+++ b/lib/usercopy.c
91993@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
91994 WARN(1, "Buffer overflow detected!\n");
91995 }
91996 EXPORT_SYMBOL(copy_from_user_overflow);
91997+
91998+void copy_to_user_overflow(void)
91999+{
92000+ WARN(1, "Buffer overflow detected!\n");
92001+}
92002+EXPORT_SYMBOL(copy_to_user_overflow);
92003diff --git a/lib/vsprintf.c b/lib/vsprintf.c
92004index 185b6d3..823c48c 100644
92005--- a/lib/vsprintf.c
92006+++ b/lib/vsprintf.c
92007@@ -16,6 +16,9 @@
92008 * - scnprintf and vscnprintf
92009 */
92010
92011+#ifdef CONFIG_GRKERNSEC_HIDESYM
92012+#define __INCLUDED_BY_HIDESYM 1
92013+#endif
92014 #include <stdarg.h>
92015 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
92016 #include <linux/types.h>
92017@@ -1179,7 +1182,11 @@ char *address_val(char *buf, char *end, const void *addr,
92018 return number(buf, end, num, spec);
92019 }
92020
92021+#ifdef CONFIG_GRKERNSEC_HIDESYM
92022+int kptr_restrict __read_mostly = 2;
92023+#else
92024 int kptr_restrict __read_mostly;
92025+#endif
92026
92027 /*
92028 * Show a '%p' thing. A kernel extension is that the '%p' is followed
92029@@ -1192,6 +1199,7 @@ int kptr_restrict __read_mostly;
92030 * - 'f' For simple symbolic function names without offset
92031 * - 'S' For symbolic direct pointers with offset
92032 * - 's' For symbolic direct pointers without offset
92033+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
92034 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
92035 * - 'B' For backtraced symbolic direct pointers with offset
92036 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
92037@@ -1259,12 +1267,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92038
92039 if (!ptr && *fmt != 'K') {
92040 /*
92041- * Print (null) with the same width as a pointer so it makes
92042+ * Print (nil) with the same width as a pointer so it makes
92043 * tabular output look nice.
92044 */
92045 if (spec.field_width == -1)
92046 spec.field_width = default_width;
92047- return string(buf, end, "(null)", spec);
92048+ return string(buf, end, "(nil)", spec);
92049 }
92050
92051 switch (*fmt) {
92052@@ -1274,6 +1282,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92053 /* Fallthrough */
92054 case 'S':
92055 case 's':
92056+#ifdef CONFIG_GRKERNSEC_HIDESYM
92057+ break;
92058+#else
92059+ return symbol_string(buf, end, ptr, spec, fmt);
92060+#endif
92061+ case 'A':
92062 case 'B':
92063 return symbol_string(buf, end, ptr, spec, fmt);
92064 case 'R':
92065@@ -1329,6 +1343,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92066 va_end(va);
92067 return buf;
92068 }
92069+ case 'P':
92070+ break;
92071 case 'K':
92072 /*
92073 * %pK cannot be used in IRQ context because its test
92074@@ -1386,6 +1402,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92075 ((const struct file *)ptr)->f_path.dentry,
92076 spec, fmt);
92077 }
92078+
92079+#ifdef CONFIG_GRKERNSEC_HIDESYM
92080+ /* 'P' = approved pointers to copy to userland,
92081+ as in the /proc/kallsyms case, as we make it display nothing
92082+ for non-root users, and the real contents for root users
92083+ Also ignore 'K' pointers, since we force their NULLing for non-root users
92084+ above
92085+ */
92086+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
92087+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
92088+ dump_stack();
92089+ ptr = NULL;
92090+ }
92091+#endif
92092+
92093 spec.flags |= SMALL;
92094 if (spec.field_width == -1) {
92095 spec.field_width = default_width;
92096@@ -2107,11 +2138,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
92097 typeof(type) value; \
92098 if (sizeof(type) == 8) { \
92099 args = PTR_ALIGN(args, sizeof(u32)); \
92100- *(u32 *)&value = *(u32 *)args; \
92101- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
92102+ *(u32 *)&value = *(const u32 *)args; \
92103+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
92104 } else { \
92105 args = PTR_ALIGN(args, sizeof(type)); \
92106- value = *(typeof(type) *)args; \
92107+ value = *(const typeof(type) *)args; \
92108 } \
92109 args += sizeof(type); \
92110 value; \
92111@@ -2174,7 +2205,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
92112 case FORMAT_TYPE_STR: {
92113 const char *str_arg = args;
92114 args += strlen(str_arg) + 1;
92115- str = string(str, end, (char *)str_arg, spec);
92116+ str = string(str, end, str_arg, spec);
92117 break;
92118 }
92119
92120diff --git a/localversion-grsec b/localversion-grsec
92121new file mode 100644
92122index 0000000..7cd6065
92123--- /dev/null
92124+++ b/localversion-grsec
92125@@ -0,0 +1 @@
92126+-grsec
92127diff --git a/mm/Kconfig b/mm/Kconfig
92128index 2888024..c15a810 100644
92129--- a/mm/Kconfig
92130+++ b/mm/Kconfig
92131@@ -326,10 +326,11 @@ config KSM
92132 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
92133
92134 config DEFAULT_MMAP_MIN_ADDR
92135- int "Low address space to protect from user allocation"
92136+ int "Low address space to protect from user allocation"
92137 depends on MMU
92138- default 4096
92139- help
92140+ default 32768 if ALPHA || ARM || PARISC || SPARC32
92141+ default 65536
92142+ help
92143 This is the portion of low virtual memory which should be protected
92144 from userspace allocation. Keeping a user from writing to low pages
92145 can help reduce the impact of kernel NULL pointer bugs.
92146@@ -360,7 +361,7 @@ config MEMORY_FAILURE
92147
92148 config HWPOISON_INJECT
92149 tristate "HWPoison pages injector"
92150- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
92151+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
92152 select PROC_PAGE_MONITOR
92153
92154 config NOMMU_INITIAL_TRIM_EXCESS
92155diff --git a/mm/backing-dev.c b/mm/backing-dev.c
92156index 09d9591..165bb75 100644
92157--- a/mm/backing-dev.c
92158+++ b/mm/backing-dev.c
92159@@ -12,7 +12,7 @@
92160 #include <linux/device.h>
92161 #include <trace/events/writeback.h>
92162
92163-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
92164+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
92165
92166 struct backing_dev_info default_backing_dev_info = {
92167 .name = "default",
92168@@ -533,7 +533,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
92169 return err;
92170
92171 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
92172- atomic_long_inc_return(&bdi_seq));
92173+ atomic_long_inc_return_unchecked(&bdi_seq));
92174 if (err) {
92175 bdi_destroy(bdi);
92176 return err;
92177diff --git a/mm/filemap.c b/mm/filemap.c
92178index 7a13f6a..e52e841 100644
92179--- a/mm/filemap.c
92180+++ b/mm/filemap.c
92181@@ -1766,7 +1766,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
92182 struct address_space *mapping = file->f_mapping;
92183
92184 if (!mapping->a_ops->readpage)
92185- return -ENOEXEC;
92186+ return -ENODEV;
92187 file_accessed(file);
92188 vma->vm_ops = &generic_file_vm_ops;
92189 return 0;
92190@@ -1948,7 +1948,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
92191
92192 while (bytes) {
92193 char __user *buf = iov->iov_base + base;
92194- int copy = min(bytes, iov->iov_len - base);
92195+ size_t copy = min(bytes, iov->iov_len - base);
92196
92197 base = 0;
92198 left = __copy_from_user_inatomic(vaddr, buf, copy);
92199@@ -1977,7 +1977,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
92200 BUG_ON(!in_atomic());
92201 kaddr = kmap_atomic(page);
92202 if (likely(i->nr_segs == 1)) {
92203- int left;
92204+ size_t left;
92205 char __user *buf = i->iov->iov_base + i->iov_offset;
92206 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
92207 copied = bytes - left;
92208@@ -2005,7 +2005,7 @@ size_t iov_iter_copy_from_user(struct page *page,
92209
92210 kaddr = kmap(page);
92211 if (likely(i->nr_segs == 1)) {
92212- int left;
92213+ size_t left;
92214 char __user *buf = i->iov->iov_base + i->iov_offset;
92215 left = __copy_from_user(kaddr + offset, buf, bytes);
92216 copied = bytes - left;
92217@@ -2035,7 +2035,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
92218 * zero-length segments (without overruning the iovec).
92219 */
92220 while (bytes || unlikely(i->count && !iov->iov_len)) {
92221- int copy;
92222+ size_t copy;
92223
92224 copy = min(bytes, iov->iov_len - base);
92225 BUG_ON(!i->count || i->count < copy);
92226@@ -2106,6 +2106,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
92227 *pos = i_size_read(inode);
92228
92229 if (limit != RLIM_INFINITY) {
92230+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
92231 if (*pos >= limit) {
92232 send_sig(SIGXFSZ, current, 0);
92233 return -EFBIG;
92234diff --git a/mm/fremap.c b/mm/fremap.c
92235index 34feba6..315fe78 100644
92236--- a/mm/fremap.c
92237+++ b/mm/fremap.c
92238@@ -179,6 +179,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
92239 retry:
92240 vma = find_vma(mm, start);
92241
92242+#ifdef CONFIG_PAX_SEGMEXEC
92243+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
92244+ goto out;
92245+#endif
92246+
92247 /*
92248 * Make sure the vma is shared, that it supports prefaulting,
92249 * and that the remapped range is valid and fully within
92250diff --git a/mm/highmem.c b/mm/highmem.c
92251index b32b70c..e512eb0 100644
92252--- a/mm/highmem.c
92253+++ b/mm/highmem.c
92254@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
92255 * So no dangers, even with speculative execution.
92256 */
92257 page = pte_page(pkmap_page_table[i]);
92258+ pax_open_kernel();
92259 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
92260-
92261+ pax_close_kernel();
92262 set_page_address(page, NULL);
92263 need_flush = 1;
92264 }
92265@@ -198,9 +199,11 @@ start:
92266 }
92267 }
92268 vaddr = PKMAP_ADDR(last_pkmap_nr);
92269+
92270+ pax_open_kernel();
92271 set_pte_at(&init_mm, vaddr,
92272 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
92273-
92274+ pax_close_kernel();
92275 pkmap_count[last_pkmap_nr] = 1;
92276 set_page_address(page, (void *)vaddr);
92277
92278diff --git a/mm/hugetlb.c b/mm/hugetlb.c
92279index 2de3c84..4ecaf1b 100644
92280--- a/mm/hugetlb.c
92281+++ b/mm/hugetlb.c
92282@@ -2069,15 +2069,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
92283 struct hstate *h = &default_hstate;
92284 unsigned long tmp;
92285 int ret;
92286+ ctl_table_no_const hugetlb_table;
92287
92288 tmp = h->max_huge_pages;
92289
92290 if (write && h->order >= MAX_ORDER)
92291 return -EINVAL;
92292
92293- table->data = &tmp;
92294- table->maxlen = sizeof(unsigned long);
92295- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
92296+ hugetlb_table = *table;
92297+ hugetlb_table.data = &tmp;
92298+ hugetlb_table.maxlen = sizeof(unsigned long);
92299+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
92300 if (ret)
92301 goto out;
92302
92303@@ -2122,15 +2124,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
92304 struct hstate *h = &default_hstate;
92305 unsigned long tmp;
92306 int ret;
92307+ ctl_table_no_const hugetlb_table;
92308
92309 tmp = h->nr_overcommit_huge_pages;
92310
92311 if (write && h->order >= MAX_ORDER)
92312 return -EINVAL;
92313
92314- table->data = &tmp;
92315- table->maxlen = sizeof(unsigned long);
92316- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
92317+ hugetlb_table = *table;
92318+ hugetlb_table.data = &tmp;
92319+ hugetlb_table.maxlen = sizeof(unsigned long);
92320+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
92321 if (ret)
92322 goto out;
92323
92324@@ -2599,6 +2603,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
92325 return 1;
92326 }
92327
92328+#ifdef CONFIG_PAX_SEGMEXEC
92329+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
92330+{
92331+ struct mm_struct *mm = vma->vm_mm;
92332+ struct vm_area_struct *vma_m;
92333+ unsigned long address_m;
92334+ pte_t *ptep_m;
92335+
92336+ vma_m = pax_find_mirror_vma(vma);
92337+ if (!vma_m)
92338+ return;
92339+
92340+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92341+ address_m = address + SEGMEXEC_TASK_SIZE;
92342+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
92343+ get_page(page_m);
92344+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
92345+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
92346+}
92347+#endif
92348+
92349 /*
92350 * Hugetlb_cow() should be called with page lock of the original hugepage held.
92351 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
92352@@ -2715,6 +2740,11 @@ retry_avoidcopy:
92353 make_huge_pte(vma, new_page, 1));
92354 page_remove_rmap(old_page);
92355 hugepage_add_new_anon_rmap(new_page, vma, address);
92356+
92357+#ifdef CONFIG_PAX_SEGMEXEC
92358+ pax_mirror_huge_pte(vma, address, new_page);
92359+#endif
92360+
92361 /* Make the old page be freed below */
92362 new_page = old_page;
92363 }
92364@@ -2879,6 +2909,10 @@ retry:
92365 && (vma->vm_flags & VM_SHARED)));
92366 set_huge_pte_at(mm, address, ptep, new_pte);
92367
92368+#ifdef CONFIG_PAX_SEGMEXEC
92369+ pax_mirror_huge_pte(vma, address, page);
92370+#endif
92371+
92372 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
92373 /* Optimization, do the COW without a second fault */
92374 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
92375@@ -2909,6 +2943,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92376 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
92377 struct hstate *h = hstate_vma(vma);
92378
92379+#ifdef CONFIG_PAX_SEGMEXEC
92380+ struct vm_area_struct *vma_m;
92381+#endif
92382+
92383 address &= huge_page_mask(h);
92384
92385 ptep = huge_pte_offset(mm, address);
92386@@ -2922,6 +2960,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92387 VM_FAULT_SET_HINDEX(hstate_index(h));
92388 }
92389
92390+#ifdef CONFIG_PAX_SEGMEXEC
92391+ vma_m = pax_find_mirror_vma(vma);
92392+ if (vma_m) {
92393+ unsigned long address_m;
92394+
92395+ if (vma->vm_start > vma_m->vm_start) {
92396+ address_m = address;
92397+ address -= SEGMEXEC_TASK_SIZE;
92398+ vma = vma_m;
92399+ h = hstate_vma(vma);
92400+ } else
92401+ address_m = address + SEGMEXEC_TASK_SIZE;
92402+
92403+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
92404+ return VM_FAULT_OOM;
92405+ address_m &= HPAGE_MASK;
92406+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
92407+ }
92408+#endif
92409+
92410 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
92411 if (!ptep)
92412 return VM_FAULT_OOM;
92413diff --git a/mm/internal.h b/mm/internal.h
92414index 3e91000..4741a60 100644
92415--- a/mm/internal.h
92416+++ b/mm/internal.h
92417@@ -94,6 +94,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
92418 * in mm/page_alloc.c
92419 */
92420 extern void __free_pages_bootmem(struct page *page, unsigned int order);
92421+extern void free_compound_page(struct page *page);
92422 extern void prep_compound_page(struct page *page, unsigned long order);
92423 #ifdef CONFIG_MEMORY_FAILURE
92424 extern bool is_free_buddy_page(struct page *page);
92425@@ -352,7 +353,7 @@ extern u32 hwpoison_filter_enable;
92426
92427 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
92428 unsigned long, unsigned long,
92429- unsigned long, unsigned long);
92430+ unsigned long, unsigned long) __intentional_overflow(-1);
92431
92432 extern void set_pageblock_order(void);
92433 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
92434diff --git a/mm/kmemleak.c b/mm/kmemleak.c
92435index 31f01c5..7015178 100644
92436--- a/mm/kmemleak.c
92437+++ b/mm/kmemleak.c
92438@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
92439
92440 for (i = 0; i < object->trace_len; i++) {
92441 void *ptr = (void *)object->trace[i];
92442- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
92443+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
92444 }
92445 }
92446
92447@@ -1853,7 +1853,7 @@ static int __init kmemleak_late_init(void)
92448 return -ENOMEM;
92449 }
92450
92451- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
92452+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
92453 &kmemleak_fops);
92454 if (!dentry)
92455 pr_warning("Failed to create the debugfs kmemleak file\n");
92456diff --git a/mm/maccess.c b/mm/maccess.c
92457index d53adf9..03a24bf 100644
92458--- a/mm/maccess.c
92459+++ b/mm/maccess.c
92460@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
92461 set_fs(KERNEL_DS);
92462 pagefault_disable();
92463 ret = __copy_from_user_inatomic(dst,
92464- (__force const void __user *)src, size);
92465+ (const void __force_user *)src, size);
92466 pagefault_enable();
92467 set_fs(old_fs);
92468
92469@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
92470
92471 set_fs(KERNEL_DS);
92472 pagefault_disable();
92473- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
92474+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
92475 pagefault_enable();
92476 set_fs(old_fs);
92477
92478diff --git a/mm/madvise.c b/mm/madvise.c
92479index 539eeb9..e24a987 100644
92480--- a/mm/madvise.c
92481+++ b/mm/madvise.c
92482@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
92483 pgoff_t pgoff;
92484 unsigned long new_flags = vma->vm_flags;
92485
92486+#ifdef CONFIG_PAX_SEGMEXEC
92487+ struct vm_area_struct *vma_m;
92488+#endif
92489+
92490 switch (behavior) {
92491 case MADV_NORMAL:
92492 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
92493@@ -126,6 +130,13 @@ success:
92494 /*
92495 * vm_flags is protected by the mmap_sem held in write mode.
92496 */
92497+
92498+#ifdef CONFIG_PAX_SEGMEXEC
92499+ vma_m = pax_find_mirror_vma(vma);
92500+ if (vma_m)
92501+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
92502+#endif
92503+
92504 vma->vm_flags = new_flags;
92505
92506 out:
92507@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
92508 struct vm_area_struct **prev,
92509 unsigned long start, unsigned long end)
92510 {
92511+
92512+#ifdef CONFIG_PAX_SEGMEXEC
92513+ struct vm_area_struct *vma_m;
92514+#endif
92515+
92516 *prev = vma;
92517 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
92518 return -EINVAL;
92519@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
92520 zap_page_range(vma, start, end - start, &details);
92521 } else
92522 zap_page_range(vma, start, end - start, NULL);
92523+
92524+#ifdef CONFIG_PAX_SEGMEXEC
92525+ vma_m = pax_find_mirror_vma(vma);
92526+ if (vma_m) {
92527+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
92528+ struct zap_details details = {
92529+ .nonlinear_vma = vma_m,
92530+ .last_index = ULONG_MAX,
92531+ };
92532+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
92533+ } else
92534+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
92535+ }
92536+#endif
92537+
92538 return 0;
92539 }
92540
92541@@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
92542 if (end < start)
92543 return error;
92544
92545+#ifdef CONFIG_PAX_SEGMEXEC
92546+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
92547+ if (end > SEGMEXEC_TASK_SIZE)
92548+ return error;
92549+ } else
92550+#endif
92551+
92552+ if (end > TASK_SIZE)
92553+ return error;
92554+
92555 error = 0;
92556 if (end == start)
92557 return error;
92558diff --git a/mm/memory-failure.c b/mm/memory-failure.c
92559index 90002ea..db1452d 100644
92560--- a/mm/memory-failure.c
92561+++ b/mm/memory-failure.c
92562@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
92563
92564 int sysctl_memory_failure_recovery __read_mostly = 1;
92565
92566-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
92567+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
92568
92569 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
92570
92571@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
92572 pfn, t->comm, t->pid);
92573 si.si_signo = SIGBUS;
92574 si.si_errno = 0;
92575- si.si_addr = (void *)addr;
92576+ si.si_addr = (void __user *)addr;
92577 #ifdef __ARCH_SI_TRAPNO
92578 si.si_trapno = trapno;
92579 #endif
92580@@ -762,7 +762,7 @@ static struct page_state {
92581 unsigned long res;
92582 char *msg;
92583 int (*action)(struct page *p, unsigned long pfn);
92584-} error_states[] = {
92585+} __do_const error_states[] = {
92586 { reserved, reserved, "reserved kernel", me_kernel },
92587 /*
92588 * free pages are specially detected outside this table:
92589@@ -1062,7 +1062,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
92590 nr_pages = 1 << compound_order(hpage);
92591 else /* normal page or thp */
92592 nr_pages = 1;
92593- atomic_long_add(nr_pages, &num_poisoned_pages);
92594+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
92595
92596 /*
92597 * We need/can do nothing about count=0 pages.
92598@@ -1092,7 +1092,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
92599 if (!PageHWPoison(hpage)
92600 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
92601 || (p != hpage && TestSetPageHWPoison(hpage))) {
92602- atomic_long_sub(nr_pages, &num_poisoned_pages);
92603+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92604 return 0;
92605 }
92606 set_page_hwpoison_huge_page(hpage);
92607@@ -1161,7 +1161,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
92608 }
92609 if (hwpoison_filter(p)) {
92610 if (TestClearPageHWPoison(p))
92611- atomic_long_sub(nr_pages, &num_poisoned_pages);
92612+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92613 unlock_page(hpage);
92614 put_page(hpage);
92615 return 0;
92616@@ -1383,7 +1383,7 @@ int unpoison_memory(unsigned long pfn)
92617 return 0;
92618 }
92619 if (TestClearPageHWPoison(p))
92620- atomic_long_dec(&num_poisoned_pages);
92621+ atomic_long_dec_unchecked(&num_poisoned_pages);
92622 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
92623 return 0;
92624 }
92625@@ -1397,7 +1397,7 @@ int unpoison_memory(unsigned long pfn)
92626 */
92627 if (TestClearPageHWPoison(page)) {
92628 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
92629- atomic_long_sub(nr_pages, &num_poisoned_pages);
92630+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92631 freeit = 1;
92632 if (PageHuge(page))
92633 clear_page_hwpoison_huge_page(page);
92634@@ -1522,11 +1522,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
92635 if (PageHuge(page)) {
92636 set_page_hwpoison_huge_page(hpage);
92637 dequeue_hwpoisoned_huge_page(hpage);
92638- atomic_long_add(1 << compound_order(hpage),
92639+ atomic_long_add_unchecked(1 << compound_order(hpage),
92640 &num_poisoned_pages);
92641 } else {
92642 SetPageHWPoison(page);
92643- atomic_long_inc(&num_poisoned_pages);
92644+ atomic_long_inc_unchecked(&num_poisoned_pages);
92645 }
92646 }
92647 return ret;
92648@@ -1565,7 +1565,7 @@ static int __soft_offline_page(struct page *page, int flags)
92649 put_page(page);
92650 pr_info("soft_offline: %#lx: invalidated\n", pfn);
92651 SetPageHWPoison(page);
92652- atomic_long_inc(&num_poisoned_pages);
92653+ atomic_long_inc_unchecked(&num_poisoned_pages);
92654 return 0;
92655 }
92656
92657@@ -1616,7 +1616,7 @@ static int __soft_offline_page(struct page *page, int flags)
92658 if (!is_free_buddy_page(page))
92659 pr_info("soft offline: %#lx: page leaked\n",
92660 pfn);
92661- atomic_long_inc(&num_poisoned_pages);
92662+ atomic_long_inc_unchecked(&num_poisoned_pages);
92663 }
92664 } else {
92665 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
92666@@ -1690,11 +1690,11 @@ int soft_offline_page(struct page *page, int flags)
92667 if (PageHuge(page)) {
92668 set_page_hwpoison_huge_page(hpage);
92669 dequeue_hwpoisoned_huge_page(hpage);
92670- atomic_long_add(1 << compound_order(hpage),
92671+ atomic_long_add_unchecked(1 << compound_order(hpage),
92672 &num_poisoned_pages);
92673 } else {
92674 SetPageHWPoison(page);
92675- atomic_long_inc(&num_poisoned_pages);
92676+ atomic_long_inc_unchecked(&num_poisoned_pages);
92677 }
92678 }
92679 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
92680diff --git a/mm/memory.c b/mm/memory.c
92681index 22dfa61..90d7ec5 100644
92682--- a/mm/memory.c
92683+++ b/mm/memory.c
92684@@ -403,6 +403,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
92685 free_pte_range(tlb, pmd, addr);
92686 } while (pmd++, addr = next, addr != end);
92687
92688+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
92689 start &= PUD_MASK;
92690 if (start < floor)
92691 return;
92692@@ -417,6 +418,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
92693 pmd = pmd_offset(pud, start);
92694 pud_clear(pud);
92695 pmd_free_tlb(tlb, pmd, start);
92696+#endif
92697+
92698 }
92699
92700 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
92701@@ -436,6 +439,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
92702 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
92703 } while (pud++, addr = next, addr != end);
92704
92705+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
92706 start &= PGDIR_MASK;
92707 if (start < floor)
92708 return;
92709@@ -450,6 +454,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
92710 pud = pud_offset(pgd, start);
92711 pgd_clear(pgd);
92712 pud_free_tlb(tlb, pud, start);
92713+#endif
92714+
92715 }
92716
92717 /*
92718@@ -1636,12 +1642,6 @@ no_page_table:
92719 return page;
92720 }
92721
92722-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
92723-{
92724- return stack_guard_page_start(vma, addr) ||
92725- stack_guard_page_end(vma, addr+PAGE_SIZE);
92726-}
92727-
92728 /**
92729 * __get_user_pages() - pin user pages in memory
92730 * @tsk: task_struct of target task
92731@@ -1728,10 +1728,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
92732
92733 i = 0;
92734
92735- do {
92736+ while (nr_pages) {
92737 struct vm_area_struct *vma;
92738
92739- vma = find_extend_vma(mm, start);
92740+ vma = find_vma(mm, start);
92741 if (!vma && in_gate_area(mm, start)) {
92742 unsigned long pg = start & PAGE_MASK;
92743 pgd_t *pgd;
92744@@ -1780,7 +1780,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
92745 goto next_page;
92746 }
92747
92748- if (!vma ||
92749+ if (!vma || start < vma->vm_start ||
92750 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
92751 !(vm_flags & vma->vm_flags))
92752 return i ? : -EFAULT;
92753@@ -1809,11 +1809,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
92754 int ret;
92755 unsigned int fault_flags = 0;
92756
92757- /* For mlock, just skip the stack guard page. */
92758- if (foll_flags & FOLL_MLOCK) {
92759- if (stack_guard_page(vma, start))
92760- goto next_page;
92761- }
92762 if (foll_flags & FOLL_WRITE)
92763 fault_flags |= FAULT_FLAG_WRITE;
92764 if (nonblocking)
92765@@ -1893,7 +1888,7 @@ next_page:
92766 start += page_increm * PAGE_SIZE;
92767 nr_pages -= page_increm;
92768 } while (nr_pages && start < vma->vm_end);
92769- } while (nr_pages);
92770+ }
92771 return i;
92772 }
92773 EXPORT_SYMBOL(__get_user_pages);
92774@@ -1929,12 +1924,17 @@ int fixup_user_fault(struct task_struct *tsk, struct mm_struct *mm,
92775 unsigned long address, unsigned int fault_flags)
92776 {
92777 struct vm_area_struct *vma;
92778+ vm_flags_t vm_flags;
92779 int ret;
92780
92781 vma = find_extend_vma(mm, address);
92782 if (!vma || address < vma->vm_start)
92783 return -EFAULT;
92784
92785+ vm_flags = (fault_flags & FAULT_FLAG_WRITE) ? VM_WRITE : VM_READ;
92786+ if (!(vm_flags & vma->vm_flags))
92787+ return -EFAULT;
92788+
92789 ret = handle_mm_fault(mm, vma, address, fault_flags);
92790 if (ret & VM_FAULT_ERROR) {
92791 if (ret & VM_FAULT_OOM)
92792@@ -2100,6 +2100,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
92793 page_add_file_rmap(page);
92794 set_pte_at(mm, addr, pte, mk_pte(page, prot));
92795
92796+#ifdef CONFIG_PAX_SEGMEXEC
92797+ pax_mirror_file_pte(vma, addr, page, ptl);
92798+#endif
92799+
92800 retval = 0;
92801 pte_unmap_unlock(pte, ptl);
92802 return retval;
92803@@ -2144,9 +2148,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
92804 if (!page_count(page))
92805 return -EINVAL;
92806 if (!(vma->vm_flags & VM_MIXEDMAP)) {
92807+
92808+#ifdef CONFIG_PAX_SEGMEXEC
92809+ struct vm_area_struct *vma_m;
92810+#endif
92811+
92812 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
92813 BUG_ON(vma->vm_flags & VM_PFNMAP);
92814 vma->vm_flags |= VM_MIXEDMAP;
92815+
92816+#ifdef CONFIG_PAX_SEGMEXEC
92817+ vma_m = pax_find_mirror_vma(vma);
92818+ if (vma_m)
92819+ vma_m->vm_flags |= VM_MIXEDMAP;
92820+#endif
92821+
92822 }
92823 return insert_page(vma, addr, page, vma->vm_page_prot);
92824 }
92825@@ -2229,6 +2245,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
92826 unsigned long pfn)
92827 {
92828 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
92829+ BUG_ON(vma->vm_mirror);
92830
92831 if (addr < vma->vm_start || addr >= vma->vm_end)
92832 return -EFAULT;
92833@@ -2476,7 +2493,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
92834
92835 BUG_ON(pud_huge(*pud));
92836
92837- pmd = pmd_alloc(mm, pud, addr);
92838+ pmd = (mm == &init_mm) ?
92839+ pmd_alloc_kernel(mm, pud, addr) :
92840+ pmd_alloc(mm, pud, addr);
92841 if (!pmd)
92842 return -ENOMEM;
92843 do {
92844@@ -2496,7 +2515,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
92845 unsigned long next;
92846 int err;
92847
92848- pud = pud_alloc(mm, pgd, addr);
92849+ pud = (mm == &init_mm) ?
92850+ pud_alloc_kernel(mm, pgd, addr) :
92851+ pud_alloc(mm, pgd, addr);
92852 if (!pud)
92853 return -ENOMEM;
92854 do {
92855@@ -2586,6 +2607,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
92856 copy_user_highpage(dst, src, va, vma);
92857 }
92858
92859+#ifdef CONFIG_PAX_SEGMEXEC
92860+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
92861+{
92862+ struct mm_struct *mm = vma->vm_mm;
92863+ spinlock_t *ptl;
92864+ pte_t *pte, entry;
92865+
92866+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
92867+ entry = *pte;
92868+ if (!pte_present(entry)) {
92869+ if (!pte_none(entry)) {
92870+ BUG_ON(pte_file(entry));
92871+ free_swap_and_cache(pte_to_swp_entry(entry));
92872+ pte_clear_not_present_full(mm, address, pte, 0);
92873+ }
92874+ } else {
92875+ struct page *page;
92876+
92877+ flush_cache_page(vma, address, pte_pfn(entry));
92878+ entry = ptep_clear_flush(vma, address, pte);
92879+ BUG_ON(pte_dirty(entry));
92880+ page = vm_normal_page(vma, address, entry);
92881+ if (page) {
92882+ update_hiwater_rss(mm);
92883+ if (PageAnon(page))
92884+ dec_mm_counter_fast(mm, MM_ANONPAGES);
92885+ else
92886+ dec_mm_counter_fast(mm, MM_FILEPAGES);
92887+ page_remove_rmap(page);
92888+ page_cache_release(page);
92889+ }
92890+ }
92891+ pte_unmap_unlock(pte, ptl);
92892+}
92893+
92894+/* PaX: if vma is mirrored, synchronize the mirror's PTE
92895+ *
92896+ * the ptl of the lower mapped page is held on entry and is not released on exit
92897+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
92898+ */
92899+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
92900+{
92901+ struct mm_struct *mm = vma->vm_mm;
92902+ unsigned long address_m;
92903+ spinlock_t *ptl_m;
92904+ struct vm_area_struct *vma_m;
92905+ pmd_t *pmd_m;
92906+ pte_t *pte_m, entry_m;
92907+
92908+ BUG_ON(!page_m || !PageAnon(page_m));
92909+
92910+ vma_m = pax_find_mirror_vma(vma);
92911+ if (!vma_m)
92912+ return;
92913+
92914+ BUG_ON(!PageLocked(page_m));
92915+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92916+ address_m = address + SEGMEXEC_TASK_SIZE;
92917+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
92918+ pte_m = pte_offset_map(pmd_m, address_m);
92919+ ptl_m = pte_lockptr(mm, pmd_m);
92920+ if (ptl != ptl_m) {
92921+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
92922+ if (!pte_none(*pte_m))
92923+ goto out;
92924+ }
92925+
92926+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
92927+ page_cache_get(page_m);
92928+ page_add_anon_rmap(page_m, vma_m, address_m);
92929+ inc_mm_counter_fast(mm, MM_ANONPAGES);
92930+ set_pte_at(mm, address_m, pte_m, entry_m);
92931+ update_mmu_cache(vma_m, address_m, pte_m);
92932+out:
92933+ if (ptl != ptl_m)
92934+ spin_unlock(ptl_m);
92935+ pte_unmap(pte_m);
92936+ unlock_page(page_m);
92937+}
92938+
92939+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
92940+{
92941+ struct mm_struct *mm = vma->vm_mm;
92942+ unsigned long address_m;
92943+ spinlock_t *ptl_m;
92944+ struct vm_area_struct *vma_m;
92945+ pmd_t *pmd_m;
92946+ pte_t *pte_m, entry_m;
92947+
92948+ BUG_ON(!page_m || PageAnon(page_m));
92949+
92950+ vma_m = pax_find_mirror_vma(vma);
92951+ if (!vma_m)
92952+ return;
92953+
92954+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92955+ address_m = address + SEGMEXEC_TASK_SIZE;
92956+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
92957+ pte_m = pte_offset_map(pmd_m, address_m);
92958+ ptl_m = pte_lockptr(mm, pmd_m);
92959+ if (ptl != ptl_m) {
92960+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
92961+ if (!pte_none(*pte_m))
92962+ goto out;
92963+ }
92964+
92965+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
92966+ page_cache_get(page_m);
92967+ page_add_file_rmap(page_m);
92968+ inc_mm_counter_fast(mm, MM_FILEPAGES);
92969+ set_pte_at(mm, address_m, pte_m, entry_m);
92970+ update_mmu_cache(vma_m, address_m, pte_m);
92971+out:
92972+ if (ptl != ptl_m)
92973+ spin_unlock(ptl_m);
92974+ pte_unmap(pte_m);
92975+}
92976+
92977+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
92978+{
92979+ struct mm_struct *mm = vma->vm_mm;
92980+ unsigned long address_m;
92981+ spinlock_t *ptl_m;
92982+ struct vm_area_struct *vma_m;
92983+ pmd_t *pmd_m;
92984+ pte_t *pte_m, entry_m;
92985+
92986+ vma_m = pax_find_mirror_vma(vma);
92987+ if (!vma_m)
92988+ return;
92989+
92990+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92991+ address_m = address + SEGMEXEC_TASK_SIZE;
92992+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
92993+ pte_m = pte_offset_map(pmd_m, address_m);
92994+ ptl_m = pte_lockptr(mm, pmd_m);
92995+ if (ptl != ptl_m) {
92996+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
92997+ if (!pte_none(*pte_m))
92998+ goto out;
92999+ }
93000+
93001+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
93002+ set_pte_at(mm, address_m, pte_m, entry_m);
93003+out:
93004+ if (ptl != ptl_m)
93005+ spin_unlock(ptl_m);
93006+ pte_unmap(pte_m);
93007+}
93008+
93009+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
93010+{
93011+ struct page *page_m;
93012+ pte_t entry;
93013+
93014+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
93015+ goto out;
93016+
93017+ entry = *pte;
93018+ page_m = vm_normal_page(vma, address, entry);
93019+ if (!page_m)
93020+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
93021+ else if (PageAnon(page_m)) {
93022+ if (pax_find_mirror_vma(vma)) {
93023+ pte_unmap_unlock(pte, ptl);
93024+ lock_page(page_m);
93025+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
93026+ if (pte_same(entry, *pte))
93027+ pax_mirror_anon_pte(vma, address, page_m, ptl);
93028+ else
93029+ unlock_page(page_m);
93030+ }
93031+ } else
93032+ pax_mirror_file_pte(vma, address, page_m, ptl);
93033+
93034+out:
93035+ pte_unmap_unlock(pte, ptl);
93036+}
93037+#endif
93038+
93039 /*
93040 * This routine handles present pages, when users try to write
93041 * to a shared page. It is done by copying the page to a new address
93042@@ -2810,6 +3011,12 @@ gotten:
93043 */
93044 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
93045 if (likely(pte_same(*page_table, orig_pte))) {
93046+
93047+#ifdef CONFIG_PAX_SEGMEXEC
93048+ if (pax_find_mirror_vma(vma))
93049+ BUG_ON(!trylock_page(new_page));
93050+#endif
93051+
93052 if (old_page) {
93053 if (!PageAnon(old_page)) {
93054 dec_mm_counter_fast(mm, MM_FILEPAGES);
93055@@ -2861,6 +3068,10 @@ gotten:
93056 page_remove_rmap(old_page);
93057 }
93058
93059+#ifdef CONFIG_PAX_SEGMEXEC
93060+ pax_mirror_anon_pte(vma, address, new_page, ptl);
93061+#endif
93062+
93063 /* Free the old page.. */
93064 new_page = old_page;
93065 ret |= VM_FAULT_WRITE;
93066@@ -3138,6 +3349,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
93067 swap_free(entry);
93068 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
93069 try_to_free_swap(page);
93070+
93071+#ifdef CONFIG_PAX_SEGMEXEC
93072+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
93073+#endif
93074+
93075 unlock_page(page);
93076 if (page != swapcache) {
93077 /*
93078@@ -3161,6 +3377,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
93079
93080 /* No need to invalidate - it was non-present before */
93081 update_mmu_cache(vma, address, page_table);
93082+
93083+#ifdef CONFIG_PAX_SEGMEXEC
93084+ pax_mirror_anon_pte(vma, address, page, ptl);
93085+#endif
93086+
93087 unlock:
93088 pte_unmap_unlock(page_table, ptl);
93089 out:
93090@@ -3180,40 +3401,6 @@ out_release:
93091 }
93092
93093 /*
93094- * This is like a special single-page "expand_{down|up}wards()",
93095- * except we must first make sure that 'address{-|+}PAGE_SIZE'
93096- * doesn't hit another vma.
93097- */
93098-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
93099-{
93100- address &= PAGE_MASK;
93101- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
93102- struct vm_area_struct *prev = vma->vm_prev;
93103-
93104- /*
93105- * Is there a mapping abutting this one below?
93106- *
93107- * That's only ok if it's the same stack mapping
93108- * that has gotten split..
93109- */
93110- if (prev && prev->vm_end == address)
93111- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
93112-
93113- expand_downwards(vma, address - PAGE_SIZE);
93114- }
93115- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
93116- struct vm_area_struct *next = vma->vm_next;
93117-
93118- /* As VM_GROWSDOWN but s/below/above/ */
93119- if (next && next->vm_start == address + PAGE_SIZE)
93120- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
93121-
93122- expand_upwards(vma, address + PAGE_SIZE);
93123- }
93124- return 0;
93125-}
93126-
93127-/*
93128 * We enter with non-exclusive mmap_sem (to exclude vma changes,
93129 * but allow concurrent faults), and pte mapped but not yet locked.
93130 * We return with mmap_sem still held, but pte unmapped and unlocked.
93131@@ -3222,27 +3409,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
93132 unsigned long address, pte_t *page_table, pmd_t *pmd,
93133 unsigned int flags)
93134 {
93135- struct page *page;
93136+ struct page *page = NULL;
93137 spinlock_t *ptl;
93138 pte_t entry;
93139
93140- pte_unmap(page_table);
93141-
93142- /* Check if we need to add a guard page to the stack */
93143- if (check_stack_guard_page(vma, address) < 0)
93144- return VM_FAULT_SIGBUS;
93145-
93146- /* Use the zero-page for reads */
93147 if (!(flags & FAULT_FLAG_WRITE)) {
93148 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
93149 vma->vm_page_prot));
93150- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
93151+ ptl = pte_lockptr(mm, pmd);
93152+ spin_lock(ptl);
93153 if (!pte_none(*page_table))
93154 goto unlock;
93155 goto setpte;
93156 }
93157
93158 /* Allocate our own private page. */
93159+ pte_unmap(page_table);
93160+
93161 if (unlikely(anon_vma_prepare(vma)))
93162 goto oom;
93163 page = alloc_zeroed_user_highpage_movable(vma, address);
93164@@ -3266,6 +3449,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
93165 if (!pte_none(*page_table))
93166 goto release;
93167
93168+#ifdef CONFIG_PAX_SEGMEXEC
93169+ if (pax_find_mirror_vma(vma))
93170+ BUG_ON(!trylock_page(page));
93171+#endif
93172+
93173 inc_mm_counter_fast(mm, MM_ANONPAGES);
93174 page_add_new_anon_rmap(page, vma, address);
93175 setpte:
93176@@ -3273,6 +3461,12 @@ setpte:
93177
93178 /* No need to invalidate - it was non-present before */
93179 update_mmu_cache(vma, address, page_table);
93180+
93181+#ifdef CONFIG_PAX_SEGMEXEC
93182+ if (page)
93183+ pax_mirror_anon_pte(vma, address, page, ptl);
93184+#endif
93185+
93186 unlock:
93187 pte_unmap_unlock(page_table, ptl);
93188 return 0;
93189@@ -3417,6 +3611,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93190 */
93191 /* Only go through if we didn't race with anybody else... */
93192 if (likely(pte_same(*page_table, orig_pte))) {
93193+
93194+#ifdef CONFIG_PAX_SEGMEXEC
93195+ if (anon && pax_find_mirror_vma(vma))
93196+ BUG_ON(!trylock_page(page));
93197+#endif
93198+
93199 flush_icache_page(vma, page);
93200 entry = mk_pte(page, vma->vm_page_prot);
93201 if (flags & FAULT_FLAG_WRITE)
93202@@ -3438,6 +3638,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93203
93204 /* no need to invalidate: a not-present page won't be cached */
93205 update_mmu_cache(vma, address, page_table);
93206+
93207+#ifdef CONFIG_PAX_SEGMEXEC
93208+ if (anon)
93209+ pax_mirror_anon_pte(vma, address, page, ptl);
93210+ else
93211+ pax_mirror_file_pte(vma, address, page, ptl);
93212+#endif
93213+
93214 } else {
93215 if (cow_page)
93216 mem_cgroup_uncharge_page(cow_page);
93217@@ -3685,6 +3893,12 @@ static int handle_pte_fault(struct mm_struct *mm,
93218 if (flags & FAULT_FLAG_WRITE)
93219 flush_tlb_fix_spurious_fault(vma, address);
93220 }
93221+
93222+#ifdef CONFIG_PAX_SEGMEXEC
93223+ pax_mirror_pte(vma, address, pte, pmd, ptl);
93224+ return 0;
93225+#endif
93226+
93227 unlock:
93228 pte_unmap_unlock(pte, ptl);
93229 return 0;
93230@@ -3701,9 +3915,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93231 pmd_t *pmd;
93232 pte_t *pte;
93233
93234+#ifdef CONFIG_PAX_SEGMEXEC
93235+ struct vm_area_struct *vma_m;
93236+#endif
93237+
93238 if (unlikely(is_vm_hugetlb_page(vma)))
93239 return hugetlb_fault(mm, vma, address, flags);
93240
93241+#ifdef CONFIG_PAX_SEGMEXEC
93242+ vma_m = pax_find_mirror_vma(vma);
93243+ if (vma_m) {
93244+ unsigned long address_m;
93245+ pgd_t *pgd_m;
93246+ pud_t *pud_m;
93247+ pmd_t *pmd_m;
93248+
93249+ if (vma->vm_start > vma_m->vm_start) {
93250+ address_m = address;
93251+ address -= SEGMEXEC_TASK_SIZE;
93252+ vma = vma_m;
93253+ } else
93254+ address_m = address + SEGMEXEC_TASK_SIZE;
93255+
93256+ pgd_m = pgd_offset(mm, address_m);
93257+ pud_m = pud_alloc(mm, pgd_m, address_m);
93258+ if (!pud_m)
93259+ return VM_FAULT_OOM;
93260+ pmd_m = pmd_alloc(mm, pud_m, address_m);
93261+ if (!pmd_m)
93262+ return VM_FAULT_OOM;
93263+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
93264+ return VM_FAULT_OOM;
93265+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
93266+ }
93267+#endif
93268+
93269 pgd = pgd_offset(mm, address);
93270 pud = pud_alloc(mm, pgd, address);
93271 if (!pud)
93272@@ -3834,6 +4080,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
93273 spin_unlock(&mm->page_table_lock);
93274 return 0;
93275 }
93276+
93277+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
93278+{
93279+ pud_t *new = pud_alloc_one(mm, address);
93280+ if (!new)
93281+ return -ENOMEM;
93282+
93283+ smp_wmb(); /* See comment in __pte_alloc */
93284+
93285+ spin_lock(&mm->page_table_lock);
93286+ if (pgd_present(*pgd)) /* Another has populated it */
93287+ pud_free(mm, new);
93288+ else
93289+ pgd_populate_kernel(mm, pgd, new);
93290+ spin_unlock(&mm->page_table_lock);
93291+ return 0;
93292+}
93293 #endif /* __PAGETABLE_PUD_FOLDED */
93294
93295 #ifndef __PAGETABLE_PMD_FOLDED
93296@@ -3864,6 +4127,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
93297 spin_unlock(&mm->page_table_lock);
93298 return 0;
93299 }
93300+
93301+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
93302+{
93303+ pmd_t *new = pmd_alloc_one(mm, address);
93304+ if (!new)
93305+ return -ENOMEM;
93306+
93307+ smp_wmb(); /* See comment in __pte_alloc */
93308+
93309+ spin_lock(&mm->page_table_lock);
93310+#ifndef __ARCH_HAS_4LEVEL_HACK
93311+ if (pud_present(*pud)) /* Another has populated it */
93312+ pmd_free(mm, new);
93313+ else
93314+ pud_populate_kernel(mm, pud, new);
93315+#else
93316+ if (pgd_present(*pud)) /* Another has populated it */
93317+ pmd_free(mm, new);
93318+ else
93319+ pgd_populate_kernel(mm, pud, new);
93320+#endif /* __ARCH_HAS_4LEVEL_HACK */
93321+ spin_unlock(&mm->page_table_lock);
93322+ return 0;
93323+}
93324 #endif /* __PAGETABLE_PMD_FOLDED */
93325
93326 #if !defined(__HAVE_ARCH_GATE_AREA)
93327@@ -3877,7 +4164,7 @@ static int __init gate_vma_init(void)
93328 gate_vma.vm_start = FIXADDR_USER_START;
93329 gate_vma.vm_end = FIXADDR_USER_END;
93330 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
93331- gate_vma.vm_page_prot = __P101;
93332+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
93333
93334 return 0;
93335 }
93336@@ -4011,8 +4298,8 @@ out:
93337 return ret;
93338 }
93339
93340-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
93341- void *buf, int len, int write)
93342+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
93343+ void *buf, size_t len, int write)
93344 {
93345 resource_size_t phys_addr;
93346 unsigned long prot = 0;
93347@@ -4038,8 +4325,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
93348 * Access another process' address space as given in mm. If non-NULL, use the
93349 * given task for page fault accounting.
93350 */
93351-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93352- unsigned long addr, void *buf, int len, int write)
93353+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93354+ unsigned long addr, void *buf, size_t len, int write)
93355 {
93356 struct vm_area_struct *vma;
93357 void *old_buf = buf;
93358@@ -4047,7 +4334,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93359 down_read(&mm->mmap_sem);
93360 /* ignore errors, just check how much was successfully transferred */
93361 while (len) {
93362- int bytes, ret, offset;
93363+ ssize_t bytes, ret, offset;
93364 void *maddr;
93365 struct page *page = NULL;
93366
93367@@ -4106,8 +4393,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93368 *
93369 * The caller must hold a reference on @mm.
93370 */
93371-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
93372- void *buf, int len, int write)
93373+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
93374+ void *buf, size_t len, int write)
93375 {
93376 return __access_remote_vm(NULL, mm, addr, buf, len, write);
93377 }
93378@@ -4117,11 +4404,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
93379 * Source/target buffer must be kernel space,
93380 * Do not walk the page table directly, use get_user_pages
93381 */
93382-int access_process_vm(struct task_struct *tsk, unsigned long addr,
93383- void *buf, int len, int write)
93384+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
93385+ void *buf, size_t len, int write)
93386 {
93387 struct mm_struct *mm;
93388- int ret;
93389+ ssize_t ret;
93390
93391 mm = get_task_mm(tsk);
93392 if (!mm)
93393diff --git a/mm/mempolicy.c b/mm/mempolicy.c
93394index ae3c8f3..fa4ee8e 100644
93395--- a/mm/mempolicy.c
93396+++ b/mm/mempolicy.c
93397@@ -746,6 +746,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
93398 unsigned long vmstart;
93399 unsigned long vmend;
93400
93401+#ifdef CONFIG_PAX_SEGMEXEC
93402+ struct vm_area_struct *vma_m;
93403+#endif
93404+
93405 vma = find_vma(mm, start);
93406 if (!vma || vma->vm_start > start)
93407 return -EFAULT;
93408@@ -789,6 +793,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
93409 err = vma_replace_policy(vma, new_pol);
93410 if (err)
93411 goto out;
93412+
93413+#ifdef CONFIG_PAX_SEGMEXEC
93414+ vma_m = pax_find_mirror_vma(vma);
93415+ if (vma_m) {
93416+ err = vma_replace_policy(vma_m, new_pol);
93417+ if (err)
93418+ goto out;
93419+ }
93420+#endif
93421+
93422 }
93423
93424 out:
93425@@ -1252,6 +1266,17 @@ static long do_mbind(unsigned long start, unsigned long len,
93426
93427 if (end < start)
93428 return -EINVAL;
93429+
93430+#ifdef CONFIG_PAX_SEGMEXEC
93431+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
93432+ if (end > SEGMEXEC_TASK_SIZE)
93433+ return -EINVAL;
93434+ } else
93435+#endif
93436+
93437+ if (end > TASK_SIZE)
93438+ return -EINVAL;
93439+
93440 if (end == start)
93441 return 0;
93442
93443@@ -1480,8 +1505,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
93444 */
93445 tcred = __task_cred(task);
93446 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
93447- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
93448- !capable(CAP_SYS_NICE)) {
93449+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
93450 rcu_read_unlock();
93451 err = -EPERM;
93452 goto out_put;
93453@@ -1512,6 +1536,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
93454 goto out;
93455 }
93456
93457+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
93458+ if (mm != current->mm &&
93459+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
93460+ mmput(mm);
93461+ err = -EPERM;
93462+ goto out;
93463+ }
93464+#endif
93465+
93466 err = do_migrate_pages(mm, old, new,
93467 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
93468
93469diff --git a/mm/migrate.c b/mm/migrate.c
93470index bed4880..a493f67 100644
93471--- a/mm/migrate.c
93472+++ b/mm/migrate.c
93473@@ -1485,8 +1485,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
93474 */
93475 tcred = __task_cred(task);
93476 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
93477- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
93478- !capable(CAP_SYS_NICE)) {
93479+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
93480 rcu_read_unlock();
93481 err = -EPERM;
93482 goto out;
93483diff --git a/mm/mlock.c b/mm/mlock.c
93484index b1eb536..091d154 100644
93485--- a/mm/mlock.c
93486+++ b/mm/mlock.c
93487@@ -14,6 +14,7 @@
93488 #include <linux/pagevec.h>
93489 #include <linux/mempolicy.h>
93490 #include <linux/syscalls.h>
93491+#include <linux/security.h>
93492 #include <linux/sched.h>
93493 #include <linux/export.h>
93494 #include <linux/rmap.h>
93495@@ -606,7 +607,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
93496 {
93497 unsigned long nstart, end, tmp;
93498 struct vm_area_struct * vma, * prev;
93499- int error;
93500+ int error = 0;
93501
93502 VM_BUG_ON(start & ~PAGE_MASK);
93503 VM_BUG_ON(len != PAGE_ALIGN(len));
93504@@ -615,6 +616,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
93505 return -EINVAL;
93506 if (end == start)
93507 return 0;
93508+ if (end > TASK_SIZE)
93509+ return -EINVAL;
93510+
93511 vma = find_vma(current->mm, start);
93512 if (!vma || vma->vm_start > start)
93513 return -ENOMEM;
93514@@ -626,6 +630,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
93515 for (nstart = start ; ; ) {
93516 vm_flags_t newflags;
93517
93518+#ifdef CONFIG_PAX_SEGMEXEC
93519+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
93520+ break;
93521+#endif
93522+
93523 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
93524
93525 newflags = vma->vm_flags & ~VM_LOCKED;
93526@@ -739,6 +748,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
93527 locked += current->mm->locked_vm;
93528
93529 /* check against resource limits */
93530+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
93531 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
93532 error = do_mlock(start, len, 1);
93533
93534@@ -776,6 +786,11 @@ static int do_mlockall(int flags)
93535 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
93536 vm_flags_t newflags;
93537
93538+#ifdef CONFIG_PAX_SEGMEXEC
93539+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
93540+ break;
93541+#endif
93542+
93543 newflags = vma->vm_flags & ~VM_LOCKED;
93544 if (flags & MCL_CURRENT)
93545 newflags |= VM_LOCKED;
93546@@ -807,8 +822,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
93547 lock_limit >>= PAGE_SHIFT;
93548
93549 ret = -ENOMEM;
93550+
93551+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
93552+
93553 down_write(&current->mm->mmap_sem);
93554-
93555 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
93556 capable(CAP_IPC_LOCK))
93557 ret = do_mlockall(flags);
93558diff --git a/mm/mmap.c b/mm/mmap.c
93559index 20ff0c3..a9eda98 100644
93560--- a/mm/mmap.c
93561+++ b/mm/mmap.c
93562@@ -36,6 +36,7 @@
93563 #include <linux/sched/sysctl.h>
93564 #include <linux/notifier.h>
93565 #include <linux/memory.h>
93566+#include <linux/random.h>
93567
93568 #include <asm/uaccess.h>
93569 #include <asm/cacheflush.h>
93570@@ -52,6 +53,16 @@
93571 #define arch_rebalance_pgtables(addr, len) (addr)
93572 #endif
93573
93574+static inline void verify_mm_writelocked(struct mm_struct *mm)
93575+{
93576+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
93577+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
93578+ up_read(&mm->mmap_sem);
93579+ BUG();
93580+ }
93581+#endif
93582+}
93583+
93584 static void unmap_region(struct mm_struct *mm,
93585 struct vm_area_struct *vma, struct vm_area_struct *prev,
93586 unsigned long start, unsigned long end);
93587@@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
93588 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
93589 *
93590 */
93591-pgprot_t protection_map[16] = {
93592+pgprot_t protection_map[16] __read_only = {
93593 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
93594 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
93595 };
93596
93597-pgprot_t vm_get_page_prot(unsigned long vm_flags)
93598+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
93599 {
93600- return __pgprot(pgprot_val(protection_map[vm_flags &
93601+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
93602 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
93603 pgprot_val(arch_vm_get_page_prot(vm_flags)));
93604+
93605+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
93606+ if (!(__supported_pte_mask & _PAGE_NX) &&
93607+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
93608+ (vm_flags & (VM_READ | VM_WRITE)))
93609+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
93610+#endif
93611+
93612+ return prot;
93613 }
93614 EXPORT_SYMBOL(vm_get_page_prot);
93615
93616@@ -90,6 +110,7 @@ unsigned long sysctl_overcommit_kbytes __read_mostly;
93617 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
93618 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
93619 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
93620+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
93621 /*
93622 * Make sure vm_committed_as in one cacheline and not cacheline shared with
93623 * other variables. It can be updated by several CPUs frequently.
93624@@ -246,6 +267,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
93625 struct vm_area_struct *next = vma->vm_next;
93626
93627 might_sleep();
93628+ BUG_ON(vma->vm_mirror);
93629 if (vma->vm_ops && vma->vm_ops->close)
93630 vma->vm_ops->close(vma);
93631 if (vma->vm_file)
93632@@ -290,6 +312,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
93633 * not page aligned -Ram Gupta
93634 */
93635 rlim = rlimit(RLIMIT_DATA);
93636+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
93637 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
93638 (mm->end_data - mm->start_data) > rlim)
93639 goto out;
93640@@ -940,6 +963,12 @@ static int
93641 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
93642 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
93643 {
93644+
93645+#ifdef CONFIG_PAX_SEGMEXEC
93646+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
93647+ return 0;
93648+#endif
93649+
93650 if (is_mergeable_vma(vma, file, vm_flags) &&
93651 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
93652 if (vma->vm_pgoff == vm_pgoff)
93653@@ -959,6 +988,12 @@ static int
93654 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
93655 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
93656 {
93657+
93658+#ifdef CONFIG_PAX_SEGMEXEC
93659+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
93660+ return 0;
93661+#endif
93662+
93663 if (is_mergeable_vma(vma, file, vm_flags) &&
93664 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
93665 pgoff_t vm_pglen;
93666@@ -1001,13 +1036,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
93667 struct vm_area_struct *vma_merge(struct mm_struct *mm,
93668 struct vm_area_struct *prev, unsigned long addr,
93669 unsigned long end, unsigned long vm_flags,
93670- struct anon_vma *anon_vma, struct file *file,
93671+ struct anon_vma *anon_vma, struct file *file,
93672 pgoff_t pgoff, struct mempolicy *policy)
93673 {
93674 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
93675 struct vm_area_struct *area, *next;
93676 int err;
93677
93678+#ifdef CONFIG_PAX_SEGMEXEC
93679+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
93680+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
93681+
93682+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
93683+#endif
93684+
93685 /*
93686 * We later require that vma->vm_flags == vm_flags,
93687 * so this tests vma->vm_flags & VM_SPECIAL, too.
93688@@ -1023,6 +1065,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
93689 if (next && next->vm_end == end) /* cases 6, 7, 8 */
93690 next = next->vm_next;
93691
93692+#ifdef CONFIG_PAX_SEGMEXEC
93693+ if (prev)
93694+ prev_m = pax_find_mirror_vma(prev);
93695+ if (area)
93696+ area_m = pax_find_mirror_vma(area);
93697+ if (next)
93698+ next_m = pax_find_mirror_vma(next);
93699+#endif
93700+
93701 /*
93702 * Can it merge with the predecessor?
93703 */
93704@@ -1042,9 +1093,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
93705 /* cases 1, 6 */
93706 err = vma_adjust(prev, prev->vm_start,
93707 next->vm_end, prev->vm_pgoff, NULL);
93708- } else /* cases 2, 5, 7 */
93709+
93710+#ifdef CONFIG_PAX_SEGMEXEC
93711+ if (!err && prev_m)
93712+ err = vma_adjust(prev_m, prev_m->vm_start,
93713+ next_m->vm_end, prev_m->vm_pgoff, NULL);
93714+#endif
93715+
93716+ } else { /* cases 2, 5, 7 */
93717 err = vma_adjust(prev, prev->vm_start,
93718 end, prev->vm_pgoff, NULL);
93719+
93720+#ifdef CONFIG_PAX_SEGMEXEC
93721+ if (!err && prev_m)
93722+ err = vma_adjust(prev_m, prev_m->vm_start,
93723+ end_m, prev_m->vm_pgoff, NULL);
93724+#endif
93725+
93726+ }
93727 if (err)
93728 return NULL;
93729 khugepaged_enter_vma_merge(prev);
93730@@ -1058,12 +1124,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
93731 mpol_equal(policy, vma_policy(next)) &&
93732 can_vma_merge_before(next, vm_flags,
93733 anon_vma, file, pgoff+pglen)) {
93734- if (prev && addr < prev->vm_end) /* case 4 */
93735+ if (prev && addr < prev->vm_end) { /* case 4 */
93736 err = vma_adjust(prev, prev->vm_start,
93737 addr, prev->vm_pgoff, NULL);
93738- else /* cases 3, 8 */
93739+
93740+#ifdef CONFIG_PAX_SEGMEXEC
93741+ if (!err && prev_m)
93742+ err = vma_adjust(prev_m, prev_m->vm_start,
93743+ addr_m, prev_m->vm_pgoff, NULL);
93744+#endif
93745+
93746+ } else { /* cases 3, 8 */
93747 err = vma_adjust(area, addr, next->vm_end,
93748 next->vm_pgoff - pglen, NULL);
93749+
93750+#ifdef CONFIG_PAX_SEGMEXEC
93751+ if (!err && area_m)
93752+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
93753+ next_m->vm_pgoff - pglen, NULL);
93754+#endif
93755+
93756+ }
93757 if (err)
93758 return NULL;
93759 khugepaged_enter_vma_merge(area);
93760@@ -1172,8 +1253,10 @@ none:
93761 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
93762 struct file *file, long pages)
93763 {
93764- const unsigned long stack_flags
93765- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
93766+
93767+#ifdef CONFIG_PAX_RANDMMAP
93768+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
93769+#endif
93770
93771 mm->total_vm += pages;
93772
93773@@ -1181,7 +1264,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
93774 mm->shared_vm += pages;
93775 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
93776 mm->exec_vm += pages;
93777- } else if (flags & stack_flags)
93778+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
93779 mm->stack_vm += pages;
93780 }
93781 #endif /* CONFIG_PROC_FS */
93782@@ -1211,6 +1294,7 @@ static inline int mlock_future_check(struct mm_struct *mm,
93783 locked += mm->locked_vm;
93784 lock_limit = rlimit(RLIMIT_MEMLOCK);
93785 lock_limit >>= PAGE_SHIFT;
93786+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
93787 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
93788 return -EAGAIN;
93789 }
93790@@ -1237,7 +1321,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93791 * (the exception is when the underlying filesystem is noexec
93792 * mounted, in which case we dont add PROT_EXEC.)
93793 */
93794- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
93795+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
93796 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
93797 prot |= PROT_EXEC;
93798
93799@@ -1263,7 +1347,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93800 /* Obtain the address to map to. we verify (or select) it and ensure
93801 * that it represents a valid section of the address space.
93802 */
93803- addr = get_unmapped_area(file, addr, len, pgoff, flags);
93804+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
93805 if (addr & ~PAGE_MASK)
93806 return addr;
93807
93808@@ -1274,6 +1358,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93809 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
93810 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
93811
93812+#ifdef CONFIG_PAX_MPROTECT
93813+ if (mm->pax_flags & MF_PAX_MPROTECT) {
93814+
93815+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
93816+ if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
93817+ mm->binfmt->handle_mmap)
93818+ mm->binfmt->handle_mmap(file);
93819+#endif
93820+
93821+#ifndef CONFIG_PAX_MPROTECT_COMPAT
93822+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
93823+ gr_log_rwxmmap(file);
93824+
93825+#ifdef CONFIG_PAX_EMUPLT
93826+ vm_flags &= ~VM_EXEC;
93827+#else
93828+ return -EPERM;
93829+#endif
93830+
93831+ }
93832+
93833+ if (!(vm_flags & VM_EXEC))
93834+ vm_flags &= ~VM_MAYEXEC;
93835+#else
93836+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
93837+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
93838+#endif
93839+ else
93840+ vm_flags &= ~VM_MAYWRITE;
93841+ }
93842+#endif
93843+
93844+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
93845+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
93846+ vm_flags &= ~VM_PAGEEXEC;
93847+#endif
93848+
93849 if (flags & MAP_LOCKED)
93850 if (!can_do_mlock())
93851 return -EPERM;
93852@@ -1361,6 +1482,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93853 vm_flags |= VM_NORESERVE;
93854 }
93855
93856+ if (!gr_acl_handle_mmap(file, prot))
93857+ return -EACCES;
93858+
93859 addr = mmap_region(file, addr, len, vm_flags, pgoff);
93860 if (!IS_ERR_VALUE(addr) &&
93861 ((vm_flags & VM_LOCKED) ||
93862@@ -1454,7 +1578,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
93863 vm_flags_t vm_flags = vma->vm_flags;
93864
93865 /* If it was private or non-writable, the write bit is already clear */
93866- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
93867+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
93868 return 0;
93869
93870 /* The backer wishes to know when pages are first written to? */
93871@@ -1500,7 +1624,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
93872 struct rb_node **rb_link, *rb_parent;
93873 unsigned long charged = 0;
93874
93875+#ifdef CONFIG_PAX_SEGMEXEC
93876+ struct vm_area_struct *vma_m = NULL;
93877+#endif
93878+
93879+ /*
93880+ * mm->mmap_sem is required to protect against another thread
93881+ * changing the mappings in case we sleep.
93882+ */
93883+ verify_mm_writelocked(mm);
93884+
93885 /* Check against address space limit. */
93886+
93887+#ifdef CONFIG_PAX_RANDMMAP
93888+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
93889+#endif
93890+
93891 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
93892 unsigned long nr_pages;
93893
93894@@ -1519,11 +1658,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
93895
93896 /* Clear old maps */
93897 error = -ENOMEM;
93898-munmap_back:
93899 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
93900 if (do_munmap(mm, addr, len))
93901 return -ENOMEM;
93902- goto munmap_back;
93903+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
93904 }
93905
93906 /*
93907@@ -1554,6 +1692,16 @@ munmap_back:
93908 goto unacct_error;
93909 }
93910
93911+#ifdef CONFIG_PAX_SEGMEXEC
93912+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
93913+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
93914+ if (!vma_m) {
93915+ error = -ENOMEM;
93916+ goto free_vma;
93917+ }
93918+ }
93919+#endif
93920+
93921 vma->vm_mm = mm;
93922 vma->vm_start = addr;
93923 vma->vm_end = addr + len;
93924@@ -1573,6 +1721,13 @@ munmap_back:
93925 if (error)
93926 goto unmap_and_free_vma;
93927
93928+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
93929+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
93930+ vma->vm_flags |= VM_PAGEEXEC;
93931+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
93932+ }
93933+#endif
93934+
93935 /* Can addr have changed??
93936 *
93937 * Answer: Yes, several device drivers can do it in their
93938@@ -1606,6 +1761,12 @@ munmap_back:
93939 }
93940
93941 vma_link(mm, vma, prev, rb_link, rb_parent);
93942+
93943+#ifdef CONFIG_PAX_SEGMEXEC
93944+ if (vma_m)
93945+ BUG_ON(pax_mirror_vma(vma_m, vma));
93946+#endif
93947+
93948 /* Once vma denies write, undo our temporary denial count */
93949 if (vm_flags & VM_DENYWRITE)
93950 allow_write_access(file);
93951@@ -1614,6 +1775,7 @@ out:
93952 perf_event_mmap(vma);
93953
93954 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
93955+ track_exec_limit(mm, addr, addr + len, vm_flags);
93956 if (vm_flags & VM_LOCKED) {
93957 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
93958 vma == get_gate_vma(current->mm)))
93959@@ -1646,6 +1808,12 @@ unmap_and_free_vma:
93960 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
93961 charged = 0;
93962 free_vma:
93963+
93964+#ifdef CONFIG_PAX_SEGMEXEC
93965+ if (vma_m)
93966+ kmem_cache_free(vm_area_cachep, vma_m);
93967+#endif
93968+
93969 kmem_cache_free(vm_area_cachep, vma);
93970 unacct_error:
93971 if (charged)
93972@@ -1653,7 +1821,63 @@ unacct_error:
93973 return error;
93974 }
93975
93976-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
93977+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
93978+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
93979+{
93980+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
93981+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
93982+
93983+ return 0;
93984+}
93985+#endif
93986+
93987+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
93988+{
93989+ if (!vma) {
93990+#ifdef CONFIG_STACK_GROWSUP
93991+ if (addr > sysctl_heap_stack_gap)
93992+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
93993+ else
93994+ vma = find_vma(current->mm, 0);
93995+ if (vma && (vma->vm_flags & VM_GROWSUP))
93996+ return false;
93997+#endif
93998+ return true;
93999+ }
94000+
94001+ if (addr + len > vma->vm_start)
94002+ return false;
94003+
94004+ if (vma->vm_flags & VM_GROWSDOWN)
94005+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
94006+#ifdef CONFIG_STACK_GROWSUP
94007+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
94008+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
94009+#endif
94010+ else if (offset)
94011+ return offset <= vma->vm_start - addr - len;
94012+
94013+ return true;
94014+}
94015+
94016+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
94017+{
94018+ if (vma->vm_start < len)
94019+ return -ENOMEM;
94020+
94021+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
94022+ if (offset <= vma->vm_start - len)
94023+ return vma->vm_start - len - offset;
94024+ else
94025+ return -ENOMEM;
94026+ }
94027+
94028+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
94029+ return vma->vm_start - len - sysctl_heap_stack_gap;
94030+ return -ENOMEM;
94031+}
94032+
94033+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
94034 {
94035 /*
94036 * We implement the search by looking for an rbtree node that
94037@@ -1701,11 +1925,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
94038 }
94039 }
94040
94041- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
94042+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
94043 check_current:
94044 /* Check if current node has a suitable gap */
94045 if (gap_start > high_limit)
94046 return -ENOMEM;
94047+
94048+ if (gap_end - gap_start > info->threadstack_offset)
94049+ gap_start += info->threadstack_offset;
94050+ else
94051+ gap_start = gap_end;
94052+
94053+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
94054+ if (gap_end - gap_start > sysctl_heap_stack_gap)
94055+ gap_start += sysctl_heap_stack_gap;
94056+ else
94057+ gap_start = gap_end;
94058+ }
94059+ if (vma->vm_flags & VM_GROWSDOWN) {
94060+ if (gap_end - gap_start > sysctl_heap_stack_gap)
94061+ gap_end -= sysctl_heap_stack_gap;
94062+ else
94063+ gap_end = gap_start;
94064+ }
94065 if (gap_end >= low_limit && gap_end - gap_start >= length)
94066 goto found;
94067
94068@@ -1755,7 +1997,7 @@ found:
94069 return gap_start;
94070 }
94071
94072-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
94073+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
94074 {
94075 struct mm_struct *mm = current->mm;
94076 struct vm_area_struct *vma;
94077@@ -1809,6 +2051,24 @@ check_current:
94078 gap_end = vma->vm_start;
94079 if (gap_end < low_limit)
94080 return -ENOMEM;
94081+
94082+ if (gap_end - gap_start > info->threadstack_offset)
94083+ gap_end -= info->threadstack_offset;
94084+ else
94085+ gap_end = gap_start;
94086+
94087+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
94088+ if (gap_end - gap_start > sysctl_heap_stack_gap)
94089+ gap_start += sysctl_heap_stack_gap;
94090+ else
94091+ gap_start = gap_end;
94092+ }
94093+ if (vma->vm_flags & VM_GROWSDOWN) {
94094+ if (gap_end - gap_start > sysctl_heap_stack_gap)
94095+ gap_end -= sysctl_heap_stack_gap;
94096+ else
94097+ gap_end = gap_start;
94098+ }
94099 if (gap_start <= high_limit && gap_end - gap_start >= length)
94100 goto found;
94101
94102@@ -1872,6 +2132,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94103 struct mm_struct *mm = current->mm;
94104 struct vm_area_struct *vma;
94105 struct vm_unmapped_area_info info;
94106+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
94107
94108 if (len > TASK_SIZE - mmap_min_addr)
94109 return -ENOMEM;
94110@@ -1879,11 +2140,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94111 if (flags & MAP_FIXED)
94112 return addr;
94113
94114+#ifdef CONFIG_PAX_RANDMMAP
94115+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
94116+#endif
94117+
94118 if (addr) {
94119 addr = PAGE_ALIGN(addr);
94120 vma = find_vma(mm, addr);
94121 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
94122- (!vma || addr + len <= vma->vm_start))
94123+ check_heap_stack_gap(vma, addr, len, offset))
94124 return addr;
94125 }
94126
94127@@ -1892,6 +2157,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94128 info.low_limit = mm->mmap_base;
94129 info.high_limit = TASK_SIZE;
94130 info.align_mask = 0;
94131+ info.threadstack_offset = offset;
94132 return vm_unmapped_area(&info);
94133 }
94134 #endif
94135@@ -1910,6 +2176,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94136 struct mm_struct *mm = current->mm;
94137 unsigned long addr = addr0;
94138 struct vm_unmapped_area_info info;
94139+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
94140
94141 /* requested length too big for entire address space */
94142 if (len > TASK_SIZE - mmap_min_addr)
94143@@ -1918,12 +2185,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94144 if (flags & MAP_FIXED)
94145 return addr;
94146
94147+#ifdef CONFIG_PAX_RANDMMAP
94148+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
94149+#endif
94150+
94151 /* requesting a specific address */
94152 if (addr) {
94153 addr = PAGE_ALIGN(addr);
94154 vma = find_vma(mm, addr);
94155 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
94156- (!vma || addr + len <= vma->vm_start))
94157+ check_heap_stack_gap(vma, addr, len, offset))
94158 return addr;
94159 }
94160
94161@@ -1932,6 +2203,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94162 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
94163 info.high_limit = mm->mmap_base;
94164 info.align_mask = 0;
94165+ info.threadstack_offset = offset;
94166 addr = vm_unmapped_area(&info);
94167
94168 /*
94169@@ -1944,6 +2216,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94170 VM_BUG_ON(addr != -ENOMEM);
94171 info.flags = 0;
94172 info.low_limit = TASK_UNMAPPED_BASE;
94173+
94174+#ifdef CONFIG_PAX_RANDMMAP
94175+ if (mm->pax_flags & MF_PAX_RANDMMAP)
94176+ info.low_limit += mm->delta_mmap;
94177+#endif
94178+
94179 info.high_limit = TASK_SIZE;
94180 addr = vm_unmapped_area(&info);
94181 }
94182@@ -2045,6 +2323,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
94183 return vma;
94184 }
94185
94186+#ifdef CONFIG_PAX_SEGMEXEC
94187+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
94188+{
94189+ struct vm_area_struct *vma_m;
94190+
94191+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
94192+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
94193+ BUG_ON(vma->vm_mirror);
94194+ return NULL;
94195+ }
94196+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
94197+ vma_m = vma->vm_mirror;
94198+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
94199+ BUG_ON(vma->vm_file != vma_m->vm_file);
94200+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
94201+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
94202+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
94203+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
94204+ return vma_m;
94205+}
94206+#endif
94207+
94208 /*
94209 * Verify that the stack growth is acceptable and
94210 * update accounting. This is shared with both the
94211@@ -2061,6 +2361,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
94212 return -ENOMEM;
94213
94214 /* Stack limit test */
94215+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
94216 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
94217 return -ENOMEM;
94218
94219@@ -2071,6 +2372,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
94220 locked = mm->locked_vm + grow;
94221 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
94222 limit >>= PAGE_SHIFT;
94223+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
94224 if (locked > limit && !capable(CAP_IPC_LOCK))
94225 return -ENOMEM;
94226 }
94227@@ -2100,37 +2402,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
94228 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
94229 * vma is the last one with address > vma->vm_end. Have to extend vma.
94230 */
94231+#ifndef CONFIG_IA64
94232+static
94233+#endif
94234 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
94235 {
94236 int error;
94237+ bool locknext;
94238
94239 if (!(vma->vm_flags & VM_GROWSUP))
94240 return -EFAULT;
94241
94242+ /* Also guard against wrapping around to address 0. */
94243+ if (address < PAGE_ALIGN(address+1))
94244+ address = PAGE_ALIGN(address+1);
94245+ else
94246+ return -ENOMEM;
94247+
94248 /*
94249 * We must make sure the anon_vma is allocated
94250 * so that the anon_vma locking is not a noop.
94251 */
94252 if (unlikely(anon_vma_prepare(vma)))
94253 return -ENOMEM;
94254+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
94255+ if (locknext && anon_vma_prepare(vma->vm_next))
94256+ return -ENOMEM;
94257 vma_lock_anon_vma(vma);
94258+ if (locknext)
94259+ vma_lock_anon_vma(vma->vm_next);
94260
94261 /*
94262 * vma->vm_start/vm_end cannot change under us because the caller
94263 * is required to hold the mmap_sem in read mode. We need the
94264- * anon_vma lock to serialize against concurrent expand_stacks.
94265- * Also guard against wrapping around to address 0.
94266+ * anon_vma locks to serialize against concurrent expand_stacks
94267+ * and expand_upwards.
94268 */
94269- if (address < PAGE_ALIGN(address+4))
94270- address = PAGE_ALIGN(address+4);
94271- else {
94272- vma_unlock_anon_vma(vma);
94273- return -ENOMEM;
94274- }
94275 error = 0;
94276
94277 /* Somebody else might have raced and expanded it already */
94278- if (address > vma->vm_end) {
94279+ 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)
94280+ error = -ENOMEM;
94281+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
94282 unsigned long size, grow;
94283
94284 size = address - vma->vm_start;
94285@@ -2165,6 +2478,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
94286 }
94287 }
94288 }
94289+ if (locknext)
94290+ vma_unlock_anon_vma(vma->vm_next);
94291 vma_unlock_anon_vma(vma);
94292 khugepaged_enter_vma_merge(vma);
94293 validate_mm(vma->vm_mm);
94294@@ -2179,6 +2494,8 @@ int expand_downwards(struct vm_area_struct *vma,
94295 unsigned long address)
94296 {
94297 int error;
94298+ bool lockprev = false;
94299+ struct vm_area_struct *prev;
94300
94301 /*
94302 * We must make sure the anon_vma is allocated
94303@@ -2192,6 +2509,15 @@ int expand_downwards(struct vm_area_struct *vma,
94304 if (error)
94305 return error;
94306
94307+ prev = vma->vm_prev;
94308+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
94309+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
94310+#endif
94311+ if (lockprev && anon_vma_prepare(prev))
94312+ return -ENOMEM;
94313+ if (lockprev)
94314+ vma_lock_anon_vma(prev);
94315+
94316 vma_lock_anon_vma(vma);
94317
94318 /*
94319@@ -2201,9 +2527,17 @@ int expand_downwards(struct vm_area_struct *vma,
94320 */
94321
94322 /* Somebody else might have raced and expanded it already */
94323- if (address < vma->vm_start) {
94324+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
94325+ error = -ENOMEM;
94326+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
94327 unsigned long size, grow;
94328
94329+#ifdef CONFIG_PAX_SEGMEXEC
94330+ struct vm_area_struct *vma_m;
94331+
94332+ vma_m = pax_find_mirror_vma(vma);
94333+#endif
94334+
94335 size = vma->vm_end - address;
94336 grow = (vma->vm_start - address) >> PAGE_SHIFT;
94337
94338@@ -2228,13 +2562,27 @@ int expand_downwards(struct vm_area_struct *vma,
94339 vma->vm_pgoff -= grow;
94340 anon_vma_interval_tree_post_update_vma(vma);
94341 vma_gap_update(vma);
94342+
94343+#ifdef CONFIG_PAX_SEGMEXEC
94344+ if (vma_m) {
94345+ anon_vma_interval_tree_pre_update_vma(vma_m);
94346+ vma_m->vm_start -= grow << PAGE_SHIFT;
94347+ vma_m->vm_pgoff -= grow;
94348+ anon_vma_interval_tree_post_update_vma(vma_m);
94349+ vma_gap_update(vma_m);
94350+ }
94351+#endif
94352+
94353 spin_unlock(&vma->vm_mm->page_table_lock);
94354
94355+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
94356 perf_event_mmap(vma);
94357 }
94358 }
94359 }
94360 vma_unlock_anon_vma(vma);
94361+ if (lockprev)
94362+ vma_unlock_anon_vma(prev);
94363 khugepaged_enter_vma_merge(vma);
94364 validate_mm(vma->vm_mm);
94365 return error;
94366@@ -2332,6 +2680,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
94367 do {
94368 long nrpages = vma_pages(vma);
94369
94370+#ifdef CONFIG_PAX_SEGMEXEC
94371+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
94372+ vma = remove_vma(vma);
94373+ continue;
94374+ }
94375+#endif
94376+
94377 if (vma->vm_flags & VM_ACCOUNT)
94378 nr_accounted += nrpages;
94379 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
94380@@ -2376,6 +2731,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
94381 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
94382 vma->vm_prev = NULL;
94383 do {
94384+
94385+#ifdef CONFIG_PAX_SEGMEXEC
94386+ if (vma->vm_mirror) {
94387+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
94388+ vma->vm_mirror->vm_mirror = NULL;
94389+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
94390+ vma->vm_mirror = NULL;
94391+ }
94392+#endif
94393+
94394 vma_rb_erase(vma, &mm->mm_rb);
94395 mm->map_count--;
94396 tail_vma = vma;
94397@@ -2401,14 +2766,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94398 struct vm_area_struct *new;
94399 int err = -ENOMEM;
94400
94401+#ifdef CONFIG_PAX_SEGMEXEC
94402+ struct vm_area_struct *vma_m, *new_m = NULL;
94403+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
94404+#endif
94405+
94406 if (is_vm_hugetlb_page(vma) && (addr &
94407 ~(huge_page_mask(hstate_vma(vma)))))
94408 return -EINVAL;
94409
94410+#ifdef CONFIG_PAX_SEGMEXEC
94411+ vma_m = pax_find_mirror_vma(vma);
94412+#endif
94413+
94414 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
94415 if (!new)
94416 goto out_err;
94417
94418+#ifdef CONFIG_PAX_SEGMEXEC
94419+ if (vma_m) {
94420+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
94421+ if (!new_m) {
94422+ kmem_cache_free(vm_area_cachep, new);
94423+ goto out_err;
94424+ }
94425+ }
94426+#endif
94427+
94428 /* most fields are the same, copy all, and then fixup */
94429 *new = *vma;
94430
94431@@ -2421,6 +2805,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94432 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
94433 }
94434
94435+#ifdef CONFIG_PAX_SEGMEXEC
94436+ if (vma_m) {
94437+ *new_m = *vma_m;
94438+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
94439+ new_m->vm_mirror = new;
94440+ new->vm_mirror = new_m;
94441+
94442+ if (new_below)
94443+ new_m->vm_end = addr_m;
94444+ else {
94445+ new_m->vm_start = addr_m;
94446+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
94447+ }
94448+ }
94449+#endif
94450+
94451 err = vma_dup_policy(vma, new);
94452 if (err)
94453 goto out_free_vma;
94454@@ -2440,6 +2840,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94455 else
94456 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
94457
94458+#ifdef CONFIG_PAX_SEGMEXEC
94459+ if (!err && vma_m) {
94460+ struct mempolicy *pol = vma_policy(new);
94461+
94462+ if (anon_vma_clone(new_m, vma_m))
94463+ goto out_free_mpol;
94464+
94465+ mpol_get(pol);
94466+ set_vma_policy(new_m, pol);
94467+
94468+ if (new_m->vm_file)
94469+ get_file(new_m->vm_file);
94470+
94471+ if (new_m->vm_ops && new_m->vm_ops->open)
94472+ new_m->vm_ops->open(new_m);
94473+
94474+ if (new_below)
94475+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
94476+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
94477+ else
94478+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
94479+
94480+ if (err) {
94481+ if (new_m->vm_ops && new_m->vm_ops->close)
94482+ new_m->vm_ops->close(new_m);
94483+ if (new_m->vm_file)
94484+ fput(new_m->vm_file);
94485+ mpol_put(pol);
94486+ }
94487+ }
94488+#endif
94489+
94490 /* Success. */
94491 if (!err)
94492 return 0;
94493@@ -2449,10 +2881,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94494 new->vm_ops->close(new);
94495 if (new->vm_file)
94496 fput(new->vm_file);
94497- unlink_anon_vmas(new);
94498 out_free_mpol:
94499 mpol_put(vma_policy(new));
94500 out_free_vma:
94501+
94502+#ifdef CONFIG_PAX_SEGMEXEC
94503+ if (new_m) {
94504+ unlink_anon_vmas(new_m);
94505+ kmem_cache_free(vm_area_cachep, new_m);
94506+ }
94507+#endif
94508+
94509+ unlink_anon_vmas(new);
94510 kmem_cache_free(vm_area_cachep, new);
94511 out_err:
94512 return err;
94513@@ -2465,6 +2905,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94514 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
94515 unsigned long addr, int new_below)
94516 {
94517+
94518+#ifdef CONFIG_PAX_SEGMEXEC
94519+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
94520+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
94521+ if (mm->map_count >= sysctl_max_map_count-1)
94522+ return -ENOMEM;
94523+ } else
94524+#endif
94525+
94526 if (mm->map_count >= sysctl_max_map_count)
94527 return -ENOMEM;
94528
94529@@ -2476,11 +2925,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
94530 * work. This now handles partial unmappings.
94531 * Jeremy Fitzhardinge <jeremy@goop.org>
94532 */
94533+#ifdef CONFIG_PAX_SEGMEXEC
94534 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94535 {
94536+ int ret = __do_munmap(mm, start, len);
94537+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
94538+ return ret;
94539+
94540+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
94541+}
94542+
94543+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94544+#else
94545+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94546+#endif
94547+{
94548 unsigned long end;
94549 struct vm_area_struct *vma, *prev, *last;
94550
94551+ /*
94552+ * mm->mmap_sem is required to protect against another thread
94553+ * changing the mappings in case we sleep.
94554+ */
94555+ verify_mm_writelocked(mm);
94556+
94557 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
94558 return -EINVAL;
94559
94560@@ -2555,6 +3023,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94561 /* Fix up all other VM information */
94562 remove_vma_list(mm, vma);
94563
94564+ track_exec_limit(mm, start, end, 0UL);
94565+
94566 return 0;
94567 }
94568
94569@@ -2563,6 +3033,13 @@ int vm_munmap(unsigned long start, size_t len)
94570 int ret;
94571 struct mm_struct *mm = current->mm;
94572
94573+
94574+#ifdef CONFIG_PAX_SEGMEXEC
94575+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
94576+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
94577+ return -EINVAL;
94578+#endif
94579+
94580 down_write(&mm->mmap_sem);
94581 ret = do_munmap(mm, start, len);
94582 up_write(&mm->mmap_sem);
94583@@ -2576,16 +3053,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
94584 return vm_munmap(addr, len);
94585 }
94586
94587-static inline void verify_mm_writelocked(struct mm_struct *mm)
94588-{
94589-#ifdef CONFIG_DEBUG_VM
94590- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
94591- WARN_ON(1);
94592- up_read(&mm->mmap_sem);
94593- }
94594-#endif
94595-}
94596-
94597 /*
94598 * this is really a simplified "do_mmap". it only handles
94599 * anonymous maps. eventually we may be able to do some
94600@@ -2599,6 +3066,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94601 struct rb_node ** rb_link, * rb_parent;
94602 pgoff_t pgoff = addr >> PAGE_SHIFT;
94603 int error;
94604+ unsigned long charged;
94605
94606 len = PAGE_ALIGN(len);
94607 if (!len)
94608@@ -2606,10 +3074,24 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94609
94610 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
94611
94612+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
94613+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
94614+ flags &= ~VM_EXEC;
94615+
94616+#ifdef CONFIG_PAX_MPROTECT
94617+ if (mm->pax_flags & MF_PAX_MPROTECT)
94618+ flags &= ~VM_MAYEXEC;
94619+#endif
94620+
94621+ }
94622+#endif
94623+
94624 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
94625 if (error & ~PAGE_MASK)
94626 return error;
94627
94628+ charged = len >> PAGE_SHIFT;
94629+
94630 error = mlock_future_check(mm, mm->def_flags, len);
94631 if (error)
94632 return error;
94633@@ -2623,21 +3105,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94634 /*
94635 * Clear old maps. this also does some error checking for us
94636 */
94637- munmap_back:
94638 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
94639 if (do_munmap(mm, addr, len))
94640 return -ENOMEM;
94641- goto munmap_back;
94642+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
94643 }
94644
94645 /* Check against address space limits *after* clearing old maps... */
94646- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
94647+ if (!may_expand_vm(mm, charged))
94648 return -ENOMEM;
94649
94650 if (mm->map_count > sysctl_max_map_count)
94651 return -ENOMEM;
94652
94653- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
94654+ if (security_vm_enough_memory_mm(mm, charged))
94655 return -ENOMEM;
94656
94657 /* Can we just expand an old private anonymous mapping? */
94658@@ -2651,7 +3132,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94659 */
94660 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94661 if (!vma) {
94662- vm_unacct_memory(len >> PAGE_SHIFT);
94663+ vm_unacct_memory(charged);
94664 return -ENOMEM;
94665 }
94666
94667@@ -2665,10 +3146,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94668 vma_link(mm, vma, prev, rb_link, rb_parent);
94669 out:
94670 perf_event_mmap(vma);
94671- mm->total_vm += len >> PAGE_SHIFT;
94672+ mm->total_vm += charged;
94673 if (flags & VM_LOCKED)
94674- mm->locked_vm += (len >> PAGE_SHIFT);
94675+ mm->locked_vm += charged;
94676 vma->vm_flags |= VM_SOFTDIRTY;
94677+ track_exec_limit(mm, addr, addr + len, flags);
94678 return addr;
94679 }
94680
94681@@ -2730,6 +3212,7 @@ void exit_mmap(struct mm_struct *mm)
94682 while (vma) {
94683 if (vma->vm_flags & VM_ACCOUNT)
94684 nr_accounted += vma_pages(vma);
94685+ vma->vm_mirror = NULL;
94686 vma = remove_vma(vma);
94687 }
94688 vm_unacct_memory(nr_accounted);
94689@@ -2747,6 +3230,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
94690 struct vm_area_struct *prev;
94691 struct rb_node **rb_link, *rb_parent;
94692
94693+#ifdef CONFIG_PAX_SEGMEXEC
94694+ struct vm_area_struct *vma_m = NULL;
94695+#endif
94696+
94697+ if (security_mmap_addr(vma->vm_start))
94698+ return -EPERM;
94699+
94700 /*
94701 * The vm_pgoff of a purely anonymous vma should be irrelevant
94702 * until its first write fault, when page's anon_vma and index
94703@@ -2770,7 +3260,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
94704 security_vm_enough_memory_mm(mm, vma_pages(vma)))
94705 return -ENOMEM;
94706
94707+#ifdef CONFIG_PAX_SEGMEXEC
94708+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
94709+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94710+ if (!vma_m)
94711+ return -ENOMEM;
94712+ }
94713+#endif
94714+
94715 vma_link(mm, vma, prev, rb_link, rb_parent);
94716+
94717+#ifdef CONFIG_PAX_SEGMEXEC
94718+ if (vma_m)
94719+ BUG_ON(pax_mirror_vma(vma_m, vma));
94720+#endif
94721+
94722 return 0;
94723 }
94724
94725@@ -2789,6 +3293,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
94726 struct rb_node **rb_link, *rb_parent;
94727 bool faulted_in_anon_vma = true;
94728
94729+ BUG_ON(vma->vm_mirror);
94730+
94731 /*
94732 * If anonymous vma has not yet been faulted, update new pgoff
94733 * to match new location, to increase its chance of merging.
94734@@ -2853,6 +3359,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
94735 return NULL;
94736 }
94737
94738+#ifdef CONFIG_PAX_SEGMEXEC
94739+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
94740+{
94741+ struct vm_area_struct *prev_m;
94742+ struct rb_node **rb_link_m, *rb_parent_m;
94743+ struct mempolicy *pol_m;
94744+
94745+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
94746+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
94747+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
94748+ *vma_m = *vma;
94749+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
94750+ if (anon_vma_clone(vma_m, vma))
94751+ return -ENOMEM;
94752+ pol_m = vma_policy(vma_m);
94753+ mpol_get(pol_m);
94754+ set_vma_policy(vma_m, pol_m);
94755+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
94756+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
94757+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
94758+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
94759+ if (vma_m->vm_file)
94760+ get_file(vma_m->vm_file);
94761+ if (vma_m->vm_ops && vma_m->vm_ops->open)
94762+ vma_m->vm_ops->open(vma_m);
94763+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
94764+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
94765+ vma_m->vm_mirror = vma;
94766+ vma->vm_mirror = vma_m;
94767+ return 0;
94768+}
94769+#endif
94770+
94771 /*
94772 * Return true if the calling process may expand its vm space by the passed
94773 * number of pages
94774@@ -2864,6 +3403,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
94775
94776 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
94777
94778+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
94779 if (cur + npages > lim)
94780 return 0;
94781 return 1;
94782@@ -2934,6 +3474,22 @@ int install_special_mapping(struct mm_struct *mm,
94783 vma->vm_start = addr;
94784 vma->vm_end = addr + len;
94785
94786+#ifdef CONFIG_PAX_MPROTECT
94787+ if (mm->pax_flags & MF_PAX_MPROTECT) {
94788+#ifndef CONFIG_PAX_MPROTECT_COMPAT
94789+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
94790+ return -EPERM;
94791+ if (!(vm_flags & VM_EXEC))
94792+ vm_flags &= ~VM_MAYEXEC;
94793+#else
94794+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
94795+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
94796+#endif
94797+ else
94798+ vm_flags &= ~VM_MAYWRITE;
94799+ }
94800+#endif
94801+
94802 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
94803 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
94804
94805diff --git a/mm/mprotect.c b/mm/mprotect.c
94806index 769a67a..414d24f 100644
94807--- a/mm/mprotect.c
94808+++ b/mm/mprotect.c
94809@@ -24,10 +24,18 @@
94810 #include <linux/migrate.h>
94811 #include <linux/perf_event.h>
94812 #include <linux/ksm.h>
94813+#include <linux/sched/sysctl.h>
94814+
94815+#ifdef CONFIG_PAX_MPROTECT
94816+#include <linux/elf.h>
94817+#include <linux/binfmts.h>
94818+#endif
94819+
94820 #include <asm/uaccess.h>
94821 #include <asm/pgtable.h>
94822 #include <asm/cacheflush.h>
94823 #include <asm/tlbflush.h>
94824+#include <asm/mmu_context.h>
94825
94826 #ifndef pgprot_modify
94827 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
94828@@ -214,6 +222,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
94829 return pages;
94830 }
94831
94832+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
94833+/* called while holding the mmap semaphor for writing except stack expansion */
94834+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
94835+{
94836+ unsigned long oldlimit, newlimit = 0UL;
94837+
94838+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
94839+ return;
94840+
94841+ spin_lock(&mm->page_table_lock);
94842+ oldlimit = mm->context.user_cs_limit;
94843+ if ((prot & VM_EXEC) && oldlimit < end)
94844+ /* USER_CS limit moved up */
94845+ newlimit = end;
94846+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
94847+ /* USER_CS limit moved down */
94848+ newlimit = start;
94849+
94850+ if (newlimit) {
94851+ mm->context.user_cs_limit = newlimit;
94852+
94853+#ifdef CONFIG_SMP
94854+ wmb();
94855+ cpus_clear(mm->context.cpu_user_cs_mask);
94856+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
94857+#endif
94858+
94859+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
94860+ }
94861+ spin_unlock(&mm->page_table_lock);
94862+ if (newlimit == end) {
94863+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
94864+
94865+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
94866+ if (is_vm_hugetlb_page(vma))
94867+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
94868+ else
94869+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
94870+ }
94871+}
94872+#endif
94873+
94874 int
94875 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
94876 unsigned long start, unsigned long end, unsigned long newflags)
94877@@ -226,11 +276,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
94878 int error;
94879 int dirty_accountable = 0;
94880
94881+#ifdef CONFIG_PAX_SEGMEXEC
94882+ struct vm_area_struct *vma_m = NULL;
94883+ unsigned long start_m, end_m;
94884+
94885+ start_m = start + SEGMEXEC_TASK_SIZE;
94886+ end_m = end + SEGMEXEC_TASK_SIZE;
94887+#endif
94888+
94889 if (newflags == oldflags) {
94890 *pprev = vma;
94891 return 0;
94892 }
94893
94894+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
94895+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
94896+
94897+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
94898+ return -ENOMEM;
94899+
94900+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
94901+ return -ENOMEM;
94902+ }
94903+
94904 /*
94905 * If we make a private mapping writable we increase our commit;
94906 * but (without finer accounting) cannot reduce our commit if we
94907@@ -247,6 +315,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
94908 }
94909 }
94910
94911+#ifdef CONFIG_PAX_SEGMEXEC
94912+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
94913+ if (start != vma->vm_start) {
94914+ error = split_vma(mm, vma, start, 1);
94915+ if (error)
94916+ goto fail;
94917+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
94918+ *pprev = (*pprev)->vm_next;
94919+ }
94920+
94921+ if (end != vma->vm_end) {
94922+ error = split_vma(mm, vma, end, 0);
94923+ if (error)
94924+ goto fail;
94925+ }
94926+
94927+ if (pax_find_mirror_vma(vma)) {
94928+ error = __do_munmap(mm, start_m, end_m - start_m);
94929+ if (error)
94930+ goto fail;
94931+ } else {
94932+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94933+ if (!vma_m) {
94934+ error = -ENOMEM;
94935+ goto fail;
94936+ }
94937+ vma->vm_flags = newflags;
94938+ error = pax_mirror_vma(vma_m, vma);
94939+ if (error) {
94940+ vma->vm_flags = oldflags;
94941+ goto fail;
94942+ }
94943+ }
94944+ }
94945+#endif
94946+
94947 /*
94948 * First try to merge with previous and/or next vma.
94949 */
94950@@ -277,9 +381,21 @@ success:
94951 * vm_flags and vm_page_prot are protected by the mmap_sem
94952 * held in write mode.
94953 */
94954+
94955+#ifdef CONFIG_PAX_SEGMEXEC
94956+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
94957+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
94958+#endif
94959+
94960 vma->vm_flags = newflags;
94961+
94962+#ifdef CONFIG_PAX_MPROTECT
94963+ if (mm->binfmt && mm->binfmt->handle_mprotect)
94964+ mm->binfmt->handle_mprotect(vma, newflags);
94965+#endif
94966+
94967 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
94968- vm_get_page_prot(newflags));
94969+ vm_get_page_prot(vma->vm_flags));
94970
94971 if (vma_wants_writenotify(vma)) {
94972 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
94973@@ -318,6 +434,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94974 end = start + len;
94975 if (end <= start)
94976 return -ENOMEM;
94977+
94978+#ifdef CONFIG_PAX_SEGMEXEC
94979+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
94980+ if (end > SEGMEXEC_TASK_SIZE)
94981+ return -EINVAL;
94982+ } else
94983+#endif
94984+
94985+ if (end > TASK_SIZE)
94986+ return -EINVAL;
94987+
94988 if (!arch_validate_prot(prot))
94989 return -EINVAL;
94990
94991@@ -325,7 +452,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94992 /*
94993 * Does the application expect PROT_READ to imply PROT_EXEC:
94994 */
94995- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
94996+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
94997 prot |= PROT_EXEC;
94998
94999 vm_flags = calc_vm_prot_bits(prot);
95000@@ -357,6 +484,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95001 if (start > vma->vm_start)
95002 prev = vma;
95003
95004+#ifdef CONFIG_PAX_MPROTECT
95005+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
95006+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
95007+#endif
95008+
95009 for (nstart = start ; ; ) {
95010 unsigned long newflags;
95011
95012@@ -367,6 +499,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95013
95014 /* newflags >> 4 shift VM_MAY% in place of VM_% */
95015 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
95016+ if (prot & (PROT_WRITE | PROT_EXEC))
95017+ gr_log_rwxmprotect(vma);
95018+
95019+ error = -EACCES;
95020+ goto out;
95021+ }
95022+
95023+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
95024 error = -EACCES;
95025 goto out;
95026 }
95027@@ -381,6 +521,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95028 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
95029 if (error)
95030 goto out;
95031+
95032+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
95033+
95034 nstart = tmp;
95035
95036 if (nstart < prev->vm_end)
95037diff --git a/mm/mremap.c b/mm/mremap.c
95038index 0843feb..c3cde48 100644
95039--- a/mm/mremap.c
95040+++ b/mm/mremap.c
95041@@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
95042 continue;
95043 pte = ptep_get_and_clear(mm, old_addr, old_pte);
95044 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
95045+
95046+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
95047+ if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
95048+ pte = pte_exprotect(pte);
95049+#endif
95050+
95051 pte = move_soft_dirty_pte(pte);
95052 set_pte_at(mm, new_addr, new_pte, pte);
95053 }
95054@@ -194,10 +200,17 @@ unsigned long move_page_tables(struct vm_area_struct *vma,
95055 break;
95056 if (pmd_trans_huge(*old_pmd)) {
95057 int err = 0;
95058- if (extent == HPAGE_PMD_SIZE)
95059+ if (extent == HPAGE_PMD_SIZE) {
95060+ VM_BUG_ON(vma->vm_file || !vma->anon_vma);
95061+ /* See comment in move_ptes() */
95062+ if (need_rmap_locks)
95063+ anon_vma_lock_write(vma->anon_vma);
95064 err = move_huge_pmd(vma, new_vma, old_addr,
95065 new_addr, old_end,
95066 old_pmd, new_pmd);
95067+ if (need_rmap_locks)
95068+ anon_vma_unlock_write(vma->anon_vma);
95069+ }
95070 if (err > 0) {
95071 need_flush = true;
95072 continue;
95073@@ -337,6 +350,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
95074 if (is_vm_hugetlb_page(vma))
95075 goto Einval;
95076
95077+#ifdef CONFIG_PAX_SEGMEXEC
95078+ if (pax_find_mirror_vma(vma))
95079+ goto Einval;
95080+#endif
95081+
95082 /* We can't remap across vm area boundaries */
95083 if (old_len > vma->vm_end - addr)
95084 goto Efault;
95085@@ -392,20 +410,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
95086 unsigned long ret = -EINVAL;
95087 unsigned long charged = 0;
95088 unsigned long map_flags;
95089+ unsigned long pax_task_size = TASK_SIZE;
95090
95091 if (new_addr & ~PAGE_MASK)
95092 goto out;
95093
95094- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
95095+#ifdef CONFIG_PAX_SEGMEXEC
95096+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
95097+ pax_task_size = SEGMEXEC_TASK_SIZE;
95098+#endif
95099+
95100+ pax_task_size -= PAGE_SIZE;
95101+
95102+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
95103 goto out;
95104
95105 /* Check if the location we're moving into overlaps the
95106 * old location at all, and fail if it does.
95107 */
95108- if ((new_addr <= addr) && (new_addr+new_len) > addr)
95109- goto out;
95110-
95111- if ((addr <= new_addr) && (addr+old_len) > new_addr)
95112+ if (addr + old_len > new_addr && new_addr + new_len > addr)
95113 goto out;
95114
95115 ret = do_munmap(mm, new_addr, new_len);
95116@@ -474,6 +497,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95117 unsigned long ret = -EINVAL;
95118 unsigned long charged = 0;
95119 bool locked = false;
95120+ unsigned long pax_task_size = TASK_SIZE;
95121
95122 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
95123 return ret;
95124@@ -495,6 +519,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95125 if (!new_len)
95126 return ret;
95127
95128+#ifdef CONFIG_PAX_SEGMEXEC
95129+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
95130+ pax_task_size = SEGMEXEC_TASK_SIZE;
95131+#endif
95132+
95133+ pax_task_size -= PAGE_SIZE;
95134+
95135+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
95136+ old_len > pax_task_size || addr > pax_task_size-old_len)
95137+ return ret;
95138+
95139 down_write(&current->mm->mmap_sem);
95140
95141 if (flags & MREMAP_FIXED) {
95142@@ -545,6 +580,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95143 new_addr = addr;
95144 }
95145 ret = addr;
95146+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
95147 goto out;
95148 }
95149 }
95150@@ -568,7 +604,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95151 goto out;
95152 }
95153
95154+ map_flags = vma->vm_flags;
95155 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
95156+ if (!(ret & ~PAGE_MASK)) {
95157+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
95158+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
95159+ }
95160 }
95161 out:
95162 if (ret & ~PAGE_MASK)
95163diff --git a/mm/nommu.c b/mm/nommu.c
95164index 8740213..f87e25b 100644
95165--- a/mm/nommu.c
95166+++ b/mm/nommu.c
95167@@ -65,7 +65,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
95168 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
95169 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
95170 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
95171-int heap_stack_gap = 0;
95172
95173 atomic_long_t mmap_pages_allocated;
95174
95175@@ -845,15 +844,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
95176 EXPORT_SYMBOL(find_vma);
95177
95178 /*
95179- * find a VMA
95180- * - we don't extend stack VMAs under NOMMU conditions
95181- */
95182-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
95183-{
95184- return find_vma(mm, addr);
95185-}
95186-
95187-/*
95188 * expand a stack to a given address
95189 * - not supported under NOMMU conditions
95190 */
95191@@ -1564,6 +1554,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
95192
95193 /* most fields are the same, copy all, and then fixup */
95194 *new = *vma;
95195+ INIT_LIST_HEAD(&new->anon_vma_chain);
95196 *region = *vma->vm_region;
95197 new->vm_region = region;
95198
95199@@ -1993,8 +1984,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
95200 }
95201 EXPORT_SYMBOL(generic_file_remap_pages);
95202
95203-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95204- unsigned long addr, void *buf, int len, int write)
95205+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95206+ unsigned long addr, void *buf, size_t len, int write)
95207 {
95208 struct vm_area_struct *vma;
95209
95210@@ -2035,8 +2026,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95211 *
95212 * The caller must hold a reference on @mm.
95213 */
95214-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
95215- void *buf, int len, int write)
95216+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
95217+ void *buf, size_t len, int write)
95218 {
95219 return __access_remote_vm(NULL, mm, addr, buf, len, write);
95220 }
95221@@ -2045,7 +2036,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
95222 * Access another process' address space.
95223 * - source/target buffer must be kernel space
95224 */
95225-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
95226+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
95227 {
95228 struct mm_struct *mm;
95229
95230diff --git a/mm/page-writeback.c b/mm/page-writeback.c
95231index 7106cb1..0805f48 100644
95232--- a/mm/page-writeback.c
95233+++ b/mm/page-writeback.c
95234@@ -685,7 +685,7 @@ static inline long long pos_ratio_polynom(unsigned long setpoint,
95235 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
95236 * - the bdi dirty thresh drops quickly due to change of JBOD workload
95237 */
95238-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
95239+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
95240 unsigned long thresh,
95241 unsigned long bg_thresh,
95242 unsigned long dirty,
95243diff --git a/mm/page_alloc.c b/mm/page_alloc.c
95244index 7387a67..67105e4 100644
95245--- a/mm/page_alloc.c
95246+++ b/mm/page_alloc.c
95247@@ -61,6 +61,7 @@
95248 #include <linux/page-debug-flags.h>
95249 #include <linux/hugetlb.h>
95250 #include <linux/sched/rt.h>
95251+#include <linux/random.h>
95252
95253 #include <asm/sections.h>
95254 #include <asm/tlbflush.h>
95255@@ -354,7 +355,7 @@ out:
95256 * This usage means that zero-order pages may not be compound.
95257 */
95258
95259-static void free_compound_page(struct page *page)
95260+void free_compound_page(struct page *page)
95261 {
95262 __free_pages_ok(page, compound_order(page));
95263 }
95264@@ -728,6 +729,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
95265 int i;
95266 int bad = 0;
95267
95268+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95269+ unsigned long index = 1UL << order;
95270+#endif
95271+
95272 trace_mm_page_free(page, order);
95273 kmemcheck_free_shadow(page, order);
95274
95275@@ -744,6 +749,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
95276 debug_check_no_obj_freed(page_address(page),
95277 PAGE_SIZE << order);
95278 }
95279+
95280+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95281+ for (; index; --index)
95282+ sanitize_highpage(page + index - 1);
95283+#endif
95284+
95285 arch_free_page(page, order);
95286 kernel_map_pages(page, 1 << order, 0);
95287
95288@@ -766,6 +777,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
95289 local_irq_restore(flags);
95290 }
95291
95292+#ifdef CONFIG_PAX_LATENT_ENTROPY
95293+bool __meminitdata extra_latent_entropy;
95294+
95295+static int __init setup_pax_extra_latent_entropy(char *str)
95296+{
95297+ extra_latent_entropy = true;
95298+ return 0;
95299+}
95300+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
95301+
95302+volatile u64 latent_entropy __latent_entropy;
95303+EXPORT_SYMBOL(latent_entropy);
95304+#endif
95305+
95306 void __init __free_pages_bootmem(struct page *page, unsigned int order)
95307 {
95308 unsigned int nr_pages = 1 << order;
95309@@ -781,6 +806,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
95310 __ClearPageReserved(p);
95311 set_page_count(p, 0);
95312
95313+#ifdef CONFIG_PAX_LATENT_ENTROPY
95314+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
95315+ u64 hash = 0;
95316+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
95317+ const u64 *data = lowmem_page_address(page);
95318+
95319+ for (index = 0; index < end; index++)
95320+ hash ^= hash + data[index];
95321+ latent_entropy ^= hash;
95322+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
95323+ }
95324+#endif
95325+
95326 page_zone(page)->managed_pages += nr_pages;
95327 set_page_refcounted(page);
95328 __free_pages(page, order);
95329@@ -897,8 +935,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
95330 arch_alloc_page(page, order);
95331 kernel_map_pages(page, 1 << order, 1);
95332
95333+#ifndef CONFIG_PAX_MEMORY_SANITIZE
95334 if (gfp_flags & __GFP_ZERO)
95335 prep_zero_page(page, order, gfp_flags);
95336+#endif
95337
95338 if (order && (gfp_flags & __GFP_COMP))
95339 prep_compound_page(page, order);
95340@@ -2401,7 +2441,7 @@ static void reset_alloc_batches(struct zonelist *zonelist,
95341 continue;
95342 mod_zone_page_state(zone, NR_ALLOC_BATCH,
95343 high_wmark_pages(zone) - low_wmark_pages(zone) -
95344- atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
95345+ atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
95346 }
95347 }
95348
95349@@ -6565,4 +6605,4 @@ void dump_page(struct page *page, char *reason)
95350 {
95351 dump_page_badflags(page, reason, 0);
95352 }
95353-EXPORT_SYMBOL_GPL(dump_page);
95354+EXPORT_SYMBOL(dump_page);
95355diff --git a/mm/page_io.c b/mm/page_io.c
95356index 7c59ef6..1358905 100644
95357--- a/mm/page_io.c
95358+++ b/mm/page_io.c
95359@@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
95360 struct file *swap_file = sis->swap_file;
95361 struct address_space *mapping = swap_file->f_mapping;
95362 struct iovec iov = {
95363- .iov_base = kmap(page),
95364+ .iov_base = (void __force_user *)kmap(page),
95365 .iov_len = PAGE_SIZE,
95366 };
95367
95368diff --git a/mm/percpu.c b/mm/percpu.c
95369index 036cfe0..980d0fa 100644
95370--- a/mm/percpu.c
95371+++ b/mm/percpu.c
95372@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
95373 static unsigned int pcpu_high_unit_cpu __read_mostly;
95374
95375 /* the address of the first chunk which starts with the kernel static area */
95376-void *pcpu_base_addr __read_mostly;
95377+void *pcpu_base_addr __read_only;
95378 EXPORT_SYMBOL_GPL(pcpu_base_addr);
95379
95380 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
95381diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
95382index fd26d04..0cea1b0 100644
95383--- a/mm/process_vm_access.c
95384+++ b/mm/process_vm_access.c
95385@@ -13,6 +13,7 @@
95386 #include <linux/uio.h>
95387 #include <linux/sched.h>
95388 #include <linux/highmem.h>
95389+#include <linux/security.h>
95390 #include <linux/ptrace.h>
95391 #include <linux/slab.h>
95392 #include <linux/syscalls.h>
95393@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
95394 size_t iov_l_curr_offset = 0;
95395 ssize_t iov_len;
95396
95397+ return -ENOSYS; // PaX: until properly audited
95398+
95399 /*
95400 * Work out how many pages of struct pages we're going to need
95401 * when eventually calling get_user_pages
95402 */
95403 for (i = 0; i < riovcnt; i++) {
95404 iov_len = rvec[i].iov_len;
95405- if (iov_len > 0) {
95406- nr_pages_iov = ((unsigned long)rvec[i].iov_base
95407- + iov_len)
95408- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
95409- / PAGE_SIZE + 1;
95410- nr_pages = max(nr_pages, nr_pages_iov);
95411- }
95412+ if (iov_len <= 0)
95413+ continue;
95414+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
95415+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
95416+ nr_pages = max(nr_pages, nr_pages_iov);
95417 }
95418
95419 if (nr_pages == 0)
95420@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
95421 goto free_proc_pages;
95422 }
95423
95424+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
95425+ rc = -EPERM;
95426+ goto put_task_struct;
95427+ }
95428+
95429 mm = mm_access(task, PTRACE_MODE_ATTACH);
95430 if (!mm || IS_ERR(mm)) {
95431 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
95432diff --git a/mm/rmap.c b/mm/rmap.c
95433index d3cbac5..0788da4 100644
95434--- a/mm/rmap.c
95435+++ b/mm/rmap.c
95436@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95437 struct anon_vma *anon_vma = vma->anon_vma;
95438 struct anon_vma_chain *avc;
95439
95440+#ifdef CONFIG_PAX_SEGMEXEC
95441+ struct anon_vma_chain *avc_m = NULL;
95442+#endif
95443+
95444 might_sleep();
95445 if (unlikely(!anon_vma)) {
95446 struct mm_struct *mm = vma->vm_mm;
95447@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95448 if (!avc)
95449 goto out_enomem;
95450
95451+#ifdef CONFIG_PAX_SEGMEXEC
95452+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
95453+ if (!avc_m)
95454+ goto out_enomem_free_avc;
95455+#endif
95456+
95457 anon_vma = find_mergeable_anon_vma(vma);
95458 allocated = NULL;
95459 if (!anon_vma) {
95460@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95461 /* page_table_lock to protect against threads */
95462 spin_lock(&mm->page_table_lock);
95463 if (likely(!vma->anon_vma)) {
95464+
95465+#ifdef CONFIG_PAX_SEGMEXEC
95466+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
95467+
95468+ if (vma_m) {
95469+ BUG_ON(vma_m->anon_vma);
95470+ vma_m->anon_vma = anon_vma;
95471+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
95472+ avc_m = NULL;
95473+ }
95474+#endif
95475+
95476 vma->anon_vma = anon_vma;
95477 anon_vma_chain_link(vma, avc, anon_vma);
95478 allocated = NULL;
95479@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95480
95481 if (unlikely(allocated))
95482 put_anon_vma(allocated);
95483+
95484+#ifdef CONFIG_PAX_SEGMEXEC
95485+ if (unlikely(avc_m))
95486+ anon_vma_chain_free(avc_m);
95487+#endif
95488+
95489 if (unlikely(avc))
95490 anon_vma_chain_free(avc);
95491 }
95492 return 0;
95493
95494 out_enomem_free_avc:
95495+
95496+#ifdef CONFIG_PAX_SEGMEXEC
95497+ if (avc_m)
95498+ anon_vma_chain_free(avc_m);
95499+#endif
95500+
95501 anon_vma_chain_free(avc);
95502 out_enomem:
95503 return -ENOMEM;
95504@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
95505 * Attach the anon_vmas from src to dst.
95506 * Returns 0 on success, -ENOMEM on failure.
95507 */
95508-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
95509+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
95510 {
95511 struct anon_vma_chain *avc, *pavc;
95512 struct anon_vma *root = NULL;
95513@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
95514 * the corresponding VMA in the parent process is attached to.
95515 * Returns 0 on success, non-zero on failure.
95516 */
95517-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
95518+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
95519 {
95520 struct anon_vma_chain *avc;
95521 struct anon_vma *anon_vma;
95522@@ -373,8 +407,10 @@ static void anon_vma_ctor(void *data)
95523 void __init anon_vma_init(void)
95524 {
95525 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
95526- 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
95527- anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
95528+ 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
95529+ anon_vma_ctor);
95530+ anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
95531+ SLAB_PANIC|SLAB_NO_SANITIZE);
95532 }
95533
95534 /*
95535diff --git a/mm/shmem.c b/mm/shmem.c
95536index 1f18c9d..3e03d33 100644
95537--- a/mm/shmem.c
95538+++ b/mm/shmem.c
95539@@ -33,7 +33,7 @@
95540 #include <linux/swap.h>
95541 #include <linux/aio.h>
95542
95543-static struct vfsmount *shm_mnt;
95544+struct vfsmount *shm_mnt;
95545
95546 #ifdef CONFIG_SHMEM
95547 /*
95548@@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
95549 #define BOGO_DIRENT_SIZE 20
95550
95551 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
95552-#define SHORT_SYMLINK_LEN 128
95553+#define SHORT_SYMLINK_LEN 64
95554
95555 /*
95556 * shmem_fallocate and shmem_writepage communicate via inode->i_private
95557@@ -2218,6 +2218,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
95558 static int shmem_xattr_validate(const char *name)
95559 {
95560 struct { const char *prefix; size_t len; } arr[] = {
95561+
95562+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
95563+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
95564+#endif
95565+
95566 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
95567 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
95568 };
95569@@ -2273,6 +2278,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
95570 if (err)
95571 return err;
95572
95573+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
95574+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
95575+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
95576+ return -EOPNOTSUPP;
95577+ if (size > 8)
95578+ return -EINVAL;
95579+ }
95580+#endif
95581+
95582 return simple_xattr_set(&info->xattrs, name, value, size, flags);
95583 }
95584
95585@@ -2585,8 +2599,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
95586 int err = -ENOMEM;
95587
95588 /* Round up to L1_CACHE_BYTES to resist false sharing */
95589- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
95590- L1_CACHE_BYTES), GFP_KERNEL);
95591+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
95592 if (!sbinfo)
95593 return -ENOMEM;
95594
95595diff --git a/mm/slab.c b/mm/slab.c
95596index b264214..83872cd 100644
95597--- a/mm/slab.c
95598+++ b/mm/slab.c
95599@@ -300,10 +300,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
95600 if ((x)->max_freeable < i) \
95601 (x)->max_freeable = i; \
95602 } while (0)
95603-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
95604-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
95605-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
95606-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
95607+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
95608+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
95609+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
95610+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
95611+#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
95612+#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
95613 #else
95614 #define STATS_INC_ACTIVE(x) do { } while (0)
95615 #define STATS_DEC_ACTIVE(x) do { } while (0)
95616@@ -320,6 +322,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
95617 #define STATS_INC_ALLOCMISS(x) do { } while (0)
95618 #define STATS_INC_FREEHIT(x) do { } while (0)
95619 #define STATS_INC_FREEMISS(x) do { } while (0)
95620+#define STATS_INC_SANITIZED(x) do { } while (0)
95621+#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
95622 #endif
95623
95624 #if DEBUG
95625@@ -403,7 +407,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
95626 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
95627 */
95628 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
95629- const struct page *page, void *obj)
95630+ const struct page *page, const void *obj)
95631 {
95632 u32 offset = (obj - page->s_mem);
95633 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
95634@@ -1489,12 +1493,12 @@ void __init kmem_cache_init(void)
95635 */
95636
95637 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
95638- kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
95639+ kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
95640
95641 if (INDEX_AC != INDEX_NODE)
95642 kmalloc_caches[INDEX_NODE] =
95643 create_kmalloc_cache("kmalloc-node",
95644- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
95645+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
95646
95647 slab_early_init = 0;
95648
95649@@ -3428,6 +3432,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
95650 struct array_cache *ac = cpu_cache_get(cachep);
95651
95652 check_irq_off();
95653+
95654+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95655+ if (pax_sanitize_slab) {
95656+ if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
95657+ memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
95658+
95659+ if (cachep->ctor)
95660+ cachep->ctor(objp);
95661+
95662+ STATS_INC_SANITIZED(cachep);
95663+ } else
95664+ STATS_INC_NOT_SANITIZED(cachep);
95665+ }
95666+#endif
95667+
95668 kmemleak_free_recursive(objp, cachep->flags);
95669 objp = cache_free_debugcheck(cachep, objp, caller);
95670
95671@@ -3656,6 +3675,7 @@ void kfree(const void *objp)
95672
95673 if (unlikely(ZERO_OR_NULL_PTR(objp)))
95674 return;
95675+ VM_BUG_ON(!virt_addr_valid(objp));
95676 local_irq_save(flags);
95677 kfree_debugcheck(objp);
95678 c = virt_to_cache(objp);
95679@@ -4097,14 +4117,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
95680 }
95681 /* cpu stats */
95682 {
95683- unsigned long allochit = atomic_read(&cachep->allochit);
95684- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
95685- unsigned long freehit = atomic_read(&cachep->freehit);
95686- unsigned long freemiss = atomic_read(&cachep->freemiss);
95687+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
95688+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
95689+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
95690+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
95691
95692 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
95693 allochit, allocmiss, freehit, freemiss);
95694 }
95695+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95696+ {
95697+ unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
95698+ unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
95699+
95700+ seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
95701+ }
95702+#endif
95703 #endif
95704 }
95705
95706@@ -4334,13 +4362,69 @@ static const struct file_operations proc_slabstats_operations = {
95707 static int __init slab_proc_init(void)
95708 {
95709 #ifdef CONFIG_DEBUG_SLAB_LEAK
95710- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
95711+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
95712 #endif
95713 return 0;
95714 }
95715 module_init(slab_proc_init);
95716 #endif
95717
95718+bool is_usercopy_object(const void *ptr)
95719+{
95720+ struct page *page;
95721+ struct kmem_cache *cachep;
95722+
95723+ if (ZERO_OR_NULL_PTR(ptr))
95724+ return false;
95725+
95726+ if (!slab_is_available())
95727+ return false;
95728+
95729+ if (!virt_addr_valid(ptr))
95730+ return false;
95731+
95732+ page = virt_to_head_page(ptr);
95733+
95734+ if (!PageSlab(page))
95735+ return false;
95736+
95737+ cachep = page->slab_cache;
95738+ return cachep->flags & SLAB_USERCOPY;
95739+}
95740+
95741+#ifdef CONFIG_PAX_USERCOPY
95742+const char *check_heap_object(const void *ptr, unsigned long n)
95743+{
95744+ struct page *page;
95745+ struct kmem_cache *cachep;
95746+ unsigned int objnr;
95747+ unsigned long offset;
95748+
95749+ if (ZERO_OR_NULL_PTR(ptr))
95750+ return "<null>";
95751+
95752+ if (!virt_addr_valid(ptr))
95753+ return NULL;
95754+
95755+ page = virt_to_head_page(ptr);
95756+
95757+ if (!PageSlab(page))
95758+ return NULL;
95759+
95760+ cachep = page->slab_cache;
95761+ if (!(cachep->flags & SLAB_USERCOPY))
95762+ return cachep->name;
95763+
95764+ objnr = obj_to_index(cachep, page, ptr);
95765+ BUG_ON(objnr >= cachep->num);
95766+ offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
95767+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
95768+ return NULL;
95769+
95770+ return cachep->name;
95771+}
95772+#endif
95773+
95774 /**
95775 * ksize - get the actual amount of memory allocated for a given object
95776 * @objp: Pointer to the object
95777diff --git a/mm/slab.h b/mm/slab.h
95778index 8184a7c..ab27737 100644
95779--- a/mm/slab.h
95780+++ b/mm/slab.h
95781@@ -32,6 +32,15 @@ extern struct list_head slab_caches;
95782 /* The slab cache that manages slab cache information */
95783 extern struct kmem_cache *kmem_cache;
95784
95785+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95786+#ifdef CONFIG_X86_64
95787+#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
95788+#else
95789+#define PAX_MEMORY_SANITIZE_VALUE '\xff'
95790+#endif
95791+extern bool pax_sanitize_slab;
95792+#endif
95793+
95794 unsigned long calculate_alignment(unsigned long flags,
95795 unsigned long align, unsigned long size);
95796
95797@@ -67,7 +76,8 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
95798
95799 /* Legal flag mask for kmem_cache_create(), for various configurations */
95800 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
95801- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
95802+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
95803+ SLAB_USERCOPY | SLAB_NO_SANITIZE)
95804
95805 #if defined(CONFIG_DEBUG_SLAB)
95806 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
95807@@ -257,6 +267,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
95808 return s;
95809
95810 page = virt_to_head_page(x);
95811+
95812+ BUG_ON(!PageSlab(page));
95813+
95814 cachep = page->slab_cache;
95815 if (slab_equal_or_root(cachep, s))
95816 return cachep;
95817diff --git a/mm/slab_common.c b/mm/slab_common.c
95818index 1ec3c61..2067c11 100644
95819--- a/mm/slab_common.c
95820+++ b/mm/slab_common.c
95821@@ -23,11 +23,22 @@
95822
95823 #include "slab.h"
95824
95825-enum slab_state slab_state;
95826+enum slab_state slab_state __read_only;
95827 LIST_HEAD(slab_caches);
95828 DEFINE_MUTEX(slab_mutex);
95829 struct kmem_cache *kmem_cache;
95830
95831+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95832+bool pax_sanitize_slab __read_only = true;
95833+static int __init pax_sanitize_slab_setup(char *str)
95834+{
95835+ pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
95836+ printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
95837+ return 1;
95838+}
95839+__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
95840+#endif
95841+
95842 #ifdef CONFIG_DEBUG_VM
95843 static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
95844 size_t size)
95845@@ -225,7 +236,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
95846 if (err)
95847 goto out_free_cache;
95848
95849- s->refcount = 1;
95850+ atomic_set(&s->refcount, 1);
95851 list_add(&s->list, &slab_caches);
95852 memcg_register_cache(s);
95853
95854@@ -278,8 +289,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
95855
95856 get_online_cpus();
95857 mutex_lock(&slab_mutex);
95858- s->refcount--;
95859- if (!s->refcount) {
95860+ if (atomic_dec_and_test(&s->refcount)) {
95861 list_del(&s->list);
95862
95863 if (!__kmem_cache_shutdown(s)) {
95864@@ -326,7 +336,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
95865 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
95866 name, size, err);
95867
95868- s->refcount = -1; /* Exempt from merging for now */
95869+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
95870 }
95871
95872 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
95873@@ -339,7 +349,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
95874
95875 create_boot_cache(s, name, size, flags);
95876 list_add(&s->list, &slab_caches);
95877- s->refcount = 1;
95878+ atomic_set(&s->refcount, 1);
95879 return s;
95880 }
95881
95882@@ -351,6 +361,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
95883 EXPORT_SYMBOL(kmalloc_dma_caches);
95884 #endif
95885
95886+#ifdef CONFIG_PAX_USERCOPY_SLABS
95887+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
95888+EXPORT_SYMBOL(kmalloc_usercopy_caches);
95889+#endif
95890+
95891 /*
95892 * Conversion table for small slabs sizes / 8 to the index in the
95893 * kmalloc array. This is necessary for slabs < 192 since we have non power
95894@@ -415,6 +430,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
95895 return kmalloc_dma_caches[index];
95896
95897 #endif
95898+
95899+#ifdef CONFIG_PAX_USERCOPY_SLABS
95900+ if (unlikely((flags & GFP_USERCOPY)))
95901+ return kmalloc_usercopy_caches[index];
95902+
95903+#endif
95904+
95905 return kmalloc_caches[index];
95906 }
95907
95908@@ -471,7 +493,7 @@ void __init create_kmalloc_caches(unsigned long flags)
95909 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
95910 if (!kmalloc_caches[i]) {
95911 kmalloc_caches[i] = create_kmalloc_cache(NULL,
95912- 1 << i, flags);
95913+ 1 << i, SLAB_USERCOPY | flags);
95914 }
95915
95916 /*
95917@@ -480,10 +502,10 @@ void __init create_kmalloc_caches(unsigned long flags)
95918 * earlier power of two caches
95919 */
95920 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
95921- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
95922+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
95923
95924 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
95925- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
95926+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
95927 }
95928
95929 /* Kmalloc array is now usable */
95930@@ -516,6 +538,23 @@ void __init create_kmalloc_caches(unsigned long flags)
95931 }
95932 }
95933 #endif
95934+
95935+#ifdef CONFIG_PAX_USERCOPY_SLABS
95936+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
95937+ struct kmem_cache *s = kmalloc_caches[i];
95938+
95939+ if (s) {
95940+ int size = kmalloc_size(i);
95941+ char *n = kasprintf(GFP_NOWAIT,
95942+ "usercopy-kmalloc-%d", size);
95943+
95944+ BUG_ON(!n);
95945+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
95946+ size, SLAB_USERCOPY | flags);
95947+ }
95948+ }
95949+#endif
95950+
95951 }
95952 #endif /* !CONFIG_SLOB */
95953
95954@@ -556,6 +595,9 @@ void print_slabinfo_header(struct seq_file *m)
95955 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
95956 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
95957 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
95958+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95959+ seq_puts(m, " : pax <sanitized> <not_sanitized>");
95960+#endif
95961 #endif
95962 seq_putc(m, '\n');
95963 }
95964diff --git a/mm/slob.c b/mm/slob.c
95965index 4bf8809..98a6914 100644
95966--- a/mm/slob.c
95967+++ b/mm/slob.c
95968@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
95969 /*
95970 * Return the size of a slob block.
95971 */
95972-static slobidx_t slob_units(slob_t *s)
95973+static slobidx_t slob_units(const slob_t *s)
95974 {
95975 if (s->units > 0)
95976 return s->units;
95977@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
95978 /*
95979 * Return the next free slob block pointer after this one.
95980 */
95981-static slob_t *slob_next(slob_t *s)
95982+static slob_t *slob_next(const slob_t *s)
95983 {
95984 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
95985 slobidx_t next;
95986@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
95987 /*
95988 * Returns true if s is the last free block in its page.
95989 */
95990-static int slob_last(slob_t *s)
95991+static int slob_last(const slob_t *s)
95992 {
95993 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
95994 }
95995
95996-static void *slob_new_pages(gfp_t gfp, int order, int node)
95997+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
95998 {
95999- void *page;
96000+ struct page *page;
96001
96002 #ifdef CONFIG_NUMA
96003 if (node != NUMA_NO_NODE)
96004@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
96005 if (!page)
96006 return NULL;
96007
96008- return page_address(page);
96009+ __SetPageSlab(page);
96010+ return page;
96011 }
96012
96013-static void slob_free_pages(void *b, int order)
96014+static void slob_free_pages(struct page *sp, int order)
96015 {
96016 if (current->reclaim_state)
96017 current->reclaim_state->reclaimed_slab += 1 << order;
96018- free_pages((unsigned long)b, order);
96019+ __ClearPageSlab(sp);
96020+ page_mapcount_reset(sp);
96021+ sp->private = 0;
96022+ __free_pages(sp, order);
96023 }
96024
96025 /*
96026@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
96027
96028 /* Not enough space: must allocate a new page */
96029 if (!b) {
96030- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
96031- if (!b)
96032+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
96033+ if (!sp)
96034 return NULL;
96035- sp = virt_to_page(b);
96036- __SetPageSlab(sp);
96037+ b = page_address(sp);
96038
96039 spin_lock_irqsave(&slob_lock, flags);
96040 sp->units = SLOB_UNITS(PAGE_SIZE);
96041 sp->freelist = b;
96042+ sp->private = 0;
96043 INIT_LIST_HEAD(&sp->list);
96044 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
96045 set_slob_page_free(sp, slob_list);
96046@@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
96047 if (slob_page_free(sp))
96048 clear_slob_page_free(sp);
96049 spin_unlock_irqrestore(&slob_lock, flags);
96050- __ClearPageSlab(sp);
96051- page_mapcount_reset(sp);
96052- slob_free_pages(b, 0);
96053+ slob_free_pages(sp, 0);
96054 return;
96055 }
96056
96057+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96058+ if (pax_sanitize_slab)
96059+ memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
96060+#endif
96061+
96062 if (!slob_page_free(sp)) {
96063 /* This slob page is about to become partially free. Easy! */
96064 sp->units = units;
96065@@ -424,11 +431,10 @@ out:
96066 */
96067
96068 static __always_inline void *
96069-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96070+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
96071 {
96072- unsigned int *m;
96073- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96074- void *ret;
96075+ slob_t *m;
96076+ void *ret = NULL;
96077
96078 gfp &= gfp_allowed_mask;
96079
96080@@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96081
96082 if (!m)
96083 return NULL;
96084- *m = size;
96085+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
96086+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
96087+ m[0].units = size;
96088+ m[1].units = align;
96089 ret = (void *)m + align;
96090
96091 trace_kmalloc_node(caller, ret,
96092 size, size + align, gfp, node);
96093 } else {
96094 unsigned int order = get_order(size);
96095+ struct page *page;
96096
96097 if (likely(order))
96098 gfp |= __GFP_COMP;
96099- ret = slob_new_pages(gfp, order, node);
96100+ page = slob_new_pages(gfp, order, node);
96101+ if (page) {
96102+ ret = page_address(page);
96103+ page->private = size;
96104+ }
96105
96106 trace_kmalloc_node(caller, ret,
96107 size, PAGE_SIZE << order, gfp, node);
96108 }
96109
96110- kmemleak_alloc(ret, size, 1, gfp);
96111+ return ret;
96112+}
96113+
96114+static __always_inline void *
96115+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96116+{
96117+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96118+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
96119+
96120+ if (!ZERO_OR_NULL_PTR(ret))
96121+ kmemleak_alloc(ret, size, 1, gfp);
96122 return ret;
96123 }
96124
96125@@ -493,34 +517,112 @@ void kfree(const void *block)
96126 return;
96127 kmemleak_free(block);
96128
96129+ VM_BUG_ON(!virt_addr_valid(block));
96130 sp = virt_to_page(block);
96131- if (PageSlab(sp)) {
96132+ VM_BUG_ON(!PageSlab(sp));
96133+ if (!sp->private) {
96134 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96135- unsigned int *m = (unsigned int *)(block - align);
96136- slob_free(m, *m + align);
96137- } else
96138+ slob_t *m = (slob_t *)(block - align);
96139+ slob_free(m, m[0].units + align);
96140+ } else {
96141+ __ClearPageSlab(sp);
96142+ page_mapcount_reset(sp);
96143+ sp->private = 0;
96144 __free_pages(sp, compound_order(sp));
96145+ }
96146 }
96147 EXPORT_SYMBOL(kfree);
96148
96149+bool is_usercopy_object(const void *ptr)
96150+{
96151+ if (!slab_is_available())
96152+ return false;
96153+
96154+ // PAX: TODO
96155+
96156+ return false;
96157+}
96158+
96159+#ifdef CONFIG_PAX_USERCOPY
96160+const char *check_heap_object(const void *ptr, unsigned long n)
96161+{
96162+ struct page *page;
96163+ const slob_t *free;
96164+ const void *base;
96165+ unsigned long flags;
96166+
96167+ if (ZERO_OR_NULL_PTR(ptr))
96168+ return "<null>";
96169+
96170+ if (!virt_addr_valid(ptr))
96171+ return NULL;
96172+
96173+ page = virt_to_head_page(ptr);
96174+ if (!PageSlab(page))
96175+ return NULL;
96176+
96177+ if (page->private) {
96178+ base = page;
96179+ if (base <= ptr && n <= page->private - (ptr - base))
96180+ return NULL;
96181+ return "<slob>";
96182+ }
96183+
96184+ /* some tricky double walking to find the chunk */
96185+ spin_lock_irqsave(&slob_lock, flags);
96186+ base = (void *)((unsigned long)ptr & PAGE_MASK);
96187+ free = page->freelist;
96188+
96189+ while (!slob_last(free) && (void *)free <= ptr) {
96190+ base = free + slob_units(free);
96191+ free = slob_next(free);
96192+ }
96193+
96194+ while (base < (void *)free) {
96195+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
96196+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
96197+ int offset;
96198+
96199+ if (ptr < base + align)
96200+ break;
96201+
96202+ offset = ptr - base - align;
96203+ if (offset >= m) {
96204+ base += size;
96205+ continue;
96206+ }
96207+
96208+ if (n > m - offset)
96209+ break;
96210+
96211+ spin_unlock_irqrestore(&slob_lock, flags);
96212+ return NULL;
96213+ }
96214+
96215+ spin_unlock_irqrestore(&slob_lock, flags);
96216+ return "<slob>";
96217+}
96218+#endif
96219+
96220 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
96221 size_t ksize(const void *block)
96222 {
96223 struct page *sp;
96224 int align;
96225- unsigned int *m;
96226+ slob_t *m;
96227
96228 BUG_ON(!block);
96229 if (unlikely(block == ZERO_SIZE_PTR))
96230 return 0;
96231
96232 sp = virt_to_page(block);
96233- if (unlikely(!PageSlab(sp)))
96234- return PAGE_SIZE << compound_order(sp);
96235+ VM_BUG_ON(!PageSlab(sp));
96236+ if (sp->private)
96237+ return sp->private;
96238
96239 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96240- m = (unsigned int *)(block - align);
96241- return SLOB_UNITS(*m) * SLOB_UNIT;
96242+ m = (slob_t *)(block - align);
96243+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
96244 }
96245 EXPORT_SYMBOL(ksize);
96246
96247@@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
96248
96249 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
96250 {
96251- void *b;
96252+ void *b = NULL;
96253
96254 flags &= gfp_allowed_mask;
96255
96256 lockdep_trace_alloc(flags);
96257
96258+#ifdef CONFIG_PAX_USERCOPY_SLABS
96259+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
96260+#else
96261 if (c->size < PAGE_SIZE) {
96262 b = slob_alloc(c->size, flags, c->align, node);
96263 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
96264 SLOB_UNITS(c->size) * SLOB_UNIT,
96265 flags, node);
96266 } else {
96267- b = slob_new_pages(flags, get_order(c->size), node);
96268+ struct page *sp;
96269+
96270+ sp = slob_new_pages(flags, get_order(c->size), node);
96271+ if (sp) {
96272+ b = page_address(sp);
96273+ sp->private = c->size;
96274+ }
96275 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
96276 PAGE_SIZE << get_order(c->size),
96277 flags, node);
96278 }
96279+#endif
96280
96281 if (b && c->ctor)
96282 c->ctor(b);
96283@@ -584,10 +696,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
96284
96285 static void __kmem_cache_free(void *b, int size)
96286 {
96287- if (size < PAGE_SIZE)
96288+ struct page *sp;
96289+
96290+ sp = virt_to_page(b);
96291+ BUG_ON(!PageSlab(sp));
96292+ if (!sp->private)
96293 slob_free(b, size);
96294 else
96295- slob_free_pages(b, get_order(size));
96296+ slob_free_pages(sp, get_order(size));
96297 }
96298
96299 static void kmem_rcu_free(struct rcu_head *head)
96300@@ -600,17 +716,31 @@ static void kmem_rcu_free(struct rcu_head *head)
96301
96302 void kmem_cache_free(struct kmem_cache *c, void *b)
96303 {
96304+ int size = c->size;
96305+
96306+#ifdef CONFIG_PAX_USERCOPY_SLABS
96307+ if (size + c->align < PAGE_SIZE) {
96308+ size += c->align;
96309+ b -= c->align;
96310+ }
96311+#endif
96312+
96313 kmemleak_free_recursive(b, c->flags);
96314 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
96315 struct slob_rcu *slob_rcu;
96316- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
96317- slob_rcu->size = c->size;
96318+ slob_rcu = b + (size - sizeof(struct slob_rcu));
96319+ slob_rcu->size = size;
96320 call_rcu(&slob_rcu->head, kmem_rcu_free);
96321 } else {
96322- __kmem_cache_free(b, c->size);
96323+ __kmem_cache_free(b, size);
96324 }
96325
96326+#ifdef CONFIG_PAX_USERCOPY_SLABS
96327+ trace_kfree(_RET_IP_, b);
96328+#else
96329 trace_kmem_cache_free(_RET_IP_, b);
96330+#endif
96331+
96332 }
96333 EXPORT_SYMBOL(kmem_cache_free);
96334
96335diff --git a/mm/slub.c b/mm/slub.c
96336index 25f14ad..ff4d0b7 100644
96337--- a/mm/slub.c
96338+++ b/mm/slub.c
96339@@ -207,7 +207,7 @@ struct track {
96340
96341 enum track_item { TRACK_ALLOC, TRACK_FREE };
96342
96343-#ifdef CONFIG_SYSFS
96344+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96345 static int sysfs_slab_add(struct kmem_cache *);
96346 static int sysfs_slab_alias(struct kmem_cache *, const char *);
96347 static void sysfs_slab_remove(struct kmem_cache *);
96348@@ -545,7 +545,7 @@ static void print_track(const char *s, struct track *t)
96349 if (!t->addr)
96350 return;
96351
96352- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
96353+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
96354 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
96355 #ifdef CONFIG_STACKTRACE
96356 {
96357@@ -2666,6 +2666,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
96358
96359 slab_free_hook(s, x);
96360
96361+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96362+ if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
96363+ memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
96364+ if (s->ctor)
96365+ s->ctor(x);
96366+ }
96367+#endif
96368+
96369 redo:
96370 /*
96371 * Determine the currently cpus per cpu slab.
96372@@ -2733,7 +2741,7 @@ static int slub_min_objects;
96373 * Merge control. If this is set then no merging of slab caches will occur.
96374 * (Could be removed. This was introduced to pacify the merge skeptics.)
96375 */
96376-static int slub_nomerge;
96377+static int slub_nomerge = 1;
96378
96379 /*
96380 * Calculate the order of allocation given an slab object size.
96381@@ -3014,6 +3022,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
96382 s->inuse = size;
96383
96384 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
96385+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96386+ (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
96387+#endif
96388 s->ctor)) {
96389 /*
96390 * Relocate free pointer after the object if it is not
96391@@ -3359,6 +3370,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
96392 EXPORT_SYMBOL(__kmalloc_node);
96393 #endif
96394
96395+bool is_usercopy_object(const void *ptr)
96396+{
96397+ struct page *page;
96398+ struct kmem_cache *s;
96399+
96400+ if (ZERO_OR_NULL_PTR(ptr))
96401+ return false;
96402+
96403+ if (!slab_is_available())
96404+ return false;
96405+
96406+ if (!virt_addr_valid(ptr))
96407+ return false;
96408+
96409+ page = virt_to_head_page(ptr);
96410+
96411+ if (!PageSlab(page))
96412+ return false;
96413+
96414+ s = page->slab_cache;
96415+ return s->flags & SLAB_USERCOPY;
96416+}
96417+
96418+#ifdef CONFIG_PAX_USERCOPY
96419+const char *check_heap_object(const void *ptr, unsigned long n)
96420+{
96421+ struct page *page;
96422+ struct kmem_cache *s;
96423+ unsigned long offset;
96424+
96425+ if (ZERO_OR_NULL_PTR(ptr))
96426+ return "<null>";
96427+
96428+ if (!virt_addr_valid(ptr))
96429+ return NULL;
96430+
96431+ page = virt_to_head_page(ptr);
96432+
96433+ if (!PageSlab(page))
96434+ return NULL;
96435+
96436+ s = page->slab_cache;
96437+ if (!(s->flags & SLAB_USERCOPY))
96438+ return s->name;
96439+
96440+ offset = (ptr - page_address(page)) % s->size;
96441+ if (offset <= s->object_size && n <= s->object_size - offset)
96442+ return NULL;
96443+
96444+ return s->name;
96445+}
96446+#endif
96447+
96448 size_t ksize(const void *object)
96449 {
96450 struct page *page;
96451@@ -3387,6 +3451,7 @@ void kfree(const void *x)
96452 if (unlikely(ZERO_OR_NULL_PTR(x)))
96453 return;
96454
96455+ VM_BUG_ON(!virt_addr_valid(x));
96456 page = virt_to_head_page(x);
96457 if (unlikely(!PageSlab(page))) {
96458 BUG_ON(!PageCompound(page));
96459@@ -3692,7 +3757,7 @@ static int slab_unmergeable(struct kmem_cache *s)
96460 /*
96461 * We may have set a slab to be unmergeable during bootstrap.
96462 */
96463- if (s->refcount < 0)
96464+ if (atomic_read(&s->refcount) < 0)
96465 return 1;
96466
96467 return 0;
96468@@ -3750,7 +3815,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
96469
96470 s = find_mergeable(memcg, size, align, flags, name, ctor);
96471 if (s) {
96472- s->refcount++;
96473+ atomic_inc(&s->refcount);
96474 /*
96475 * Adjust the object sizes so that we clear
96476 * the complete object on kzalloc.
96477@@ -3759,7 +3824,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
96478 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
96479
96480 if (sysfs_slab_alias(s, name)) {
96481- s->refcount--;
96482+ atomic_dec(&s->refcount);
96483 s = NULL;
96484 }
96485 }
96486@@ -3879,7 +3944,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
96487 }
96488 #endif
96489
96490-#ifdef CONFIG_SYSFS
96491+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96492 static int count_inuse(struct page *page)
96493 {
96494 return page->inuse;
96495@@ -4268,12 +4333,12 @@ static void resiliency_test(void)
96496 validate_slab_cache(kmalloc_caches[9]);
96497 }
96498 #else
96499-#ifdef CONFIG_SYSFS
96500+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96501 static void resiliency_test(void) {};
96502 #endif
96503 #endif
96504
96505-#ifdef CONFIG_SYSFS
96506+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96507 enum slab_stat_type {
96508 SL_ALL, /* All slabs */
96509 SL_PARTIAL, /* Only partially allocated slabs */
96510@@ -4519,7 +4584,7 @@ SLAB_ATTR_RO(ctor);
96511
96512 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
96513 {
96514- return sprintf(buf, "%d\n", s->refcount - 1);
96515+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
96516 }
96517 SLAB_ATTR_RO(aliases);
96518
96519@@ -4607,6 +4672,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
96520 SLAB_ATTR_RO(cache_dma);
96521 #endif
96522
96523+#ifdef CONFIG_PAX_USERCOPY_SLABS
96524+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
96525+{
96526+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
96527+}
96528+SLAB_ATTR_RO(usercopy);
96529+#endif
96530+
96531 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
96532 {
96533 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
96534@@ -4941,6 +5014,9 @@ static struct attribute *slab_attrs[] = {
96535 #ifdef CONFIG_ZONE_DMA
96536 &cache_dma_attr.attr,
96537 #endif
96538+#ifdef CONFIG_PAX_USERCOPY_SLABS
96539+ &usercopy_attr.attr,
96540+#endif
96541 #ifdef CONFIG_NUMA
96542 &remote_node_defrag_ratio_attr.attr,
96543 #endif
96544@@ -5173,6 +5249,7 @@ static char *create_unique_id(struct kmem_cache *s)
96545 return name;
96546 }
96547
96548+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96549 static int sysfs_slab_add(struct kmem_cache *s)
96550 {
96551 int err;
96552@@ -5230,6 +5307,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
96553 kobject_del(&s->kobj);
96554 kobject_put(&s->kobj);
96555 }
96556+#endif
96557
96558 /*
96559 * Need to buffer aliases during bootup until sysfs becomes
96560@@ -5243,6 +5321,7 @@ struct saved_alias {
96561
96562 static struct saved_alias *alias_list;
96563
96564+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96565 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
96566 {
96567 struct saved_alias *al;
96568@@ -5265,6 +5344,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
96569 alias_list = al;
96570 return 0;
96571 }
96572+#endif
96573
96574 static int __init slab_sysfs_init(void)
96575 {
96576diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
96577index 4cba9c2..b4f9fcc 100644
96578--- a/mm/sparse-vmemmap.c
96579+++ b/mm/sparse-vmemmap.c
96580@@ -131,7 +131,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
96581 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
96582 if (!p)
96583 return NULL;
96584- pud_populate(&init_mm, pud, p);
96585+ pud_populate_kernel(&init_mm, pud, p);
96586 }
96587 return pud;
96588 }
96589@@ -143,7 +143,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
96590 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
96591 if (!p)
96592 return NULL;
96593- pgd_populate(&init_mm, pgd, p);
96594+ pgd_populate_kernel(&init_mm, pgd, p);
96595 }
96596 return pgd;
96597 }
96598diff --git a/mm/sparse.c b/mm/sparse.c
96599index 63c3ea5..95c0858 100644
96600--- a/mm/sparse.c
96601+++ b/mm/sparse.c
96602@@ -748,7 +748,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
96603
96604 for (i = 0; i < PAGES_PER_SECTION; i++) {
96605 if (PageHWPoison(&memmap[i])) {
96606- atomic_long_sub(1, &num_poisoned_pages);
96607+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
96608 ClearPageHWPoison(&memmap[i]);
96609 }
96610 }
96611diff --git a/mm/swap.c b/mm/swap.c
96612index 0092097..33361ff 100644
96613--- a/mm/swap.c
96614+++ b/mm/swap.c
96615@@ -31,6 +31,7 @@
96616 #include <linux/memcontrol.h>
96617 #include <linux/gfp.h>
96618 #include <linux/uio.h>
96619+#include <linux/hugetlb.h>
96620
96621 #include "internal.h"
96622
96623@@ -76,6 +77,8 @@ static void __put_compound_page(struct page *page)
96624
96625 __page_cache_release(page);
96626 dtor = get_compound_page_dtor(page);
96627+ if (!PageHuge(page))
96628+ BUG_ON(dtor != free_compound_page);
96629 (*dtor)(page);
96630 }
96631
96632diff --git a/mm/swapfile.c b/mm/swapfile.c
96633index 4a7f7e6..22cddf5 100644
96634--- a/mm/swapfile.c
96635+++ b/mm/swapfile.c
96636@@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
96637
96638 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
96639 /* Activity counter to indicate that a swapon or swapoff has occurred */
96640-static atomic_t proc_poll_event = ATOMIC_INIT(0);
96641+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
96642
96643 static inline unsigned char swap_count(unsigned char ent)
96644 {
96645@@ -1959,7 +1959,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
96646 spin_unlock(&swap_lock);
96647
96648 err = 0;
96649- atomic_inc(&proc_poll_event);
96650+ atomic_inc_unchecked(&proc_poll_event);
96651 wake_up_interruptible(&proc_poll_wait);
96652
96653 out_dput:
96654@@ -1976,8 +1976,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
96655
96656 poll_wait(file, &proc_poll_wait, wait);
96657
96658- if (seq->poll_event != atomic_read(&proc_poll_event)) {
96659- seq->poll_event = atomic_read(&proc_poll_event);
96660+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
96661+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
96662 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
96663 }
96664
96665@@ -2075,7 +2075,7 @@ static int swaps_open(struct inode *inode, struct file *file)
96666 return ret;
96667
96668 seq = file->private_data;
96669- seq->poll_event = atomic_read(&proc_poll_event);
96670+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
96671 return 0;
96672 }
96673
96674@@ -2534,7 +2534,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
96675 (frontswap_map) ? "FS" : "");
96676
96677 mutex_unlock(&swapon_mutex);
96678- atomic_inc(&proc_poll_event);
96679+ atomic_inc_unchecked(&proc_poll_event);
96680 wake_up_interruptible(&proc_poll_wait);
96681
96682 if (S_ISREG(inode->i_mode))
96683diff --git a/mm/util.c b/mm/util.c
96684index a24aa22..a0d41ae 100644
96685--- a/mm/util.c
96686+++ b/mm/util.c
96687@@ -297,6 +297,12 @@ done:
96688 void arch_pick_mmap_layout(struct mm_struct *mm)
96689 {
96690 mm->mmap_base = TASK_UNMAPPED_BASE;
96691+
96692+#ifdef CONFIG_PAX_RANDMMAP
96693+ if (mm->pax_flags & MF_PAX_RANDMMAP)
96694+ mm->mmap_base += mm->delta_mmap;
96695+#endif
96696+
96697 mm->get_unmapped_area = arch_get_unmapped_area;
96698 }
96699 #endif
96700diff --git a/mm/vmalloc.c b/mm/vmalloc.c
96701index 0fdf968..d6686e8 100644
96702--- a/mm/vmalloc.c
96703+++ b/mm/vmalloc.c
96704@@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
96705
96706 pte = pte_offset_kernel(pmd, addr);
96707 do {
96708- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
96709- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
96710+
96711+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
96712+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
96713+ BUG_ON(!pte_exec(*pte));
96714+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
96715+ continue;
96716+ }
96717+#endif
96718+
96719+ {
96720+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
96721+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
96722+ }
96723 } while (pte++, addr += PAGE_SIZE, addr != end);
96724 }
96725
96726@@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
96727 pte = pte_alloc_kernel(pmd, addr);
96728 if (!pte)
96729 return -ENOMEM;
96730+
96731+ pax_open_kernel();
96732 do {
96733 struct page *page = pages[*nr];
96734
96735- if (WARN_ON(!pte_none(*pte)))
96736+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
96737+ if (pgprot_val(prot) & _PAGE_NX)
96738+#endif
96739+
96740+ if (!pte_none(*pte)) {
96741+ pax_close_kernel();
96742+ WARN_ON(1);
96743 return -EBUSY;
96744- if (WARN_ON(!page))
96745+ }
96746+ if (!page) {
96747+ pax_close_kernel();
96748+ WARN_ON(1);
96749 return -ENOMEM;
96750+ }
96751 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
96752 (*nr)++;
96753 } while (pte++, addr += PAGE_SIZE, addr != end);
96754+ pax_close_kernel();
96755 return 0;
96756 }
96757
96758@@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
96759 pmd_t *pmd;
96760 unsigned long next;
96761
96762- pmd = pmd_alloc(&init_mm, pud, addr);
96763+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
96764 if (!pmd)
96765 return -ENOMEM;
96766 do {
96767@@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
96768 pud_t *pud;
96769 unsigned long next;
96770
96771- pud = pud_alloc(&init_mm, pgd, addr);
96772+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
96773 if (!pud)
96774 return -ENOMEM;
96775 do {
96776@@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
96777 if (addr >= MODULES_VADDR && addr < MODULES_END)
96778 return 1;
96779 #endif
96780+
96781+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
96782+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
96783+ return 1;
96784+#endif
96785+
96786 return is_vmalloc_addr(x);
96787 }
96788
96789@@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
96790
96791 if (!pgd_none(*pgd)) {
96792 pud_t *pud = pud_offset(pgd, addr);
96793+#ifdef CONFIG_X86
96794+ if (!pud_large(*pud))
96795+#endif
96796 if (!pud_none(*pud)) {
96797 pmd_t *pmd = pmd_offset(pud, addr);
96798+#ifdef CONFIG_X86
96799+ if (!pmd_large(*pmd))
96800+#endif
96801 if (!pmd_none(*pmd)) {
96802 pte_t *ptep, pte;
96803
96804@@ -1309,6 +1345,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
96805 struct vm_struct *area;
96806
96807 BUG_ON(in_interrupt());
96808+
96809+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
96810+ if (flags & VM_KERNEXEC) {
96811+ if (start != VMALLOC_START || end != VMALLOC_END)
96812+ return NULL;
96813+ start = (unsigned long)MODULES_EXEC_VADDR;
96814+ end = (unsigned long)MODULES_EXEC_END;
96815+ }
96816+#endif
96817+
96818 if (flags & VM_IOREMAP)
96819 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
96820
96821@@ -1534,6 +1580,11 @@ void *vmap(struct page **pages, unsigned int count,
96822 if (count > totalram_pages)
96823 return NULL;
96824
96825+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
96826+ if (!(pgprot_val(prot) & _PAGE_NX))
96827+ flags |= VM_KERNEXEC;
96828+#endif
96829+
96830 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
96831 __builtin_return_address(0));
96832 if (!area)
96833@@ -1634,6 +1685,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
96834 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
96835 goto fail;
96836
96837+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
96838+ if (!(pgprot_val(prot) & _PAGE_NX))
96839+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
96840+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
96841+ else
96842+#endif
96843+
96844 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
96845 start, end, node, gfp_mask, caller);
96846 if (!area)
96847@@ -1810,10 +1868,9 @@ EXPORT_SYMBOL(vzalloc_node);
96848 * For tight control over page level allocator and protection flags
96849 * use __vmalloc() instead.
96850 */
96851-
96852 void *vmalloc_exec(unsigned long size)
96853 {
96854- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
96855+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
96856 NUMA_NO_NODE, __builtin_return_address(0));
96857 }
96858
96859@@ -2120,6 +2177,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
96860 {
96861 struct vm_struct *area;
96862
96863+ BUG_ON(vma->vm_mirror);
96864+
96865 size = PAGE_ALIGN(size);
96866
96867 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
96868@@ -2602,7 +2661,11 @@ static int s_show(struct seq_file *m, void *p)
96869 v->addr, v->addr + v->size, v->size);
96870
96871 if (v->caller)
96872+#ifdef CONFIG_GRKERNSEC_HIDESYM
96873+ seq_printf(m, " %pK", v->caller);
96874+#else
96875 seq_printf(m, " %pS", v->caller);
96876+#endif
96877
96878 if (v->nr_pages)
96879 seq_printf(m, " pages=%d", v->nr_pages);
96880diff --git a/mm/vmstat.c b/mm/vmstat.c
96881index def5dd2..4ce55cec 100644
96882--- a/mm/vmstat.c
96883+++ b/mm/vmstat.c
96884@@ -20,6 +20,7 @@
96885 #include <linux/writeback.h>
96886 #include <linux/compaction.h>
96887 #include <linux/mm_inline.h>
96888+#include <linux/grsecurity.h>
96889
96890 #include "internal.h"
96891
96892@@ -79,7 +80,7 @@ void vm_events_fold_cpu(int cpu)
96893 *
96894 * vm_stat contains the global counters
96895 */
96896-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
96897+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
96898 EXPORT_SYMBOL(vm_stat);
96899
96900 #ifdef CONFIG_SMP
96901@@ -423,7 +424,7 @@ static inline void fold_diff(int *diff)
96902
96903 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
96904 if (diff[i])
96905- atomic_long_add(diff[i], &vm_stat[i]);
96906+ atomic_long_add_unchecked(diff[i], &vm_stat[i]);
96907 }
96908
96909 /*
96910@@ -455,7 +456,7 @@ static void refresh_cpu_vm_stats(void)
96911 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
96912 if (v) {
96913
96914- atomic_long_add(v, &zone->vm_stat[i]);
96915+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
96916 global_diff[i] += v;
96917 #ifdef CONFIG_NUMA
96918 /* 3 seconds idle till flush */
96919@@ -517,7 +518,7 @@ void cpu_vm_stats_fold(int cpu)
96920
96921 v = p->vm_stat_diff[i];
96922 p->vm_stat_diff[i] = 0;
96923- atomic_long_add(v, &zone->vm_stat[i]);
96924+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
96925 global_diff[i] += v;
96926 }
96927 }
96928@@ -537,8 +538,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
96929 if (pset->vm_stat_diff[i]) {
96930 int v = pset->vm_stat_diff[i];
96931 pset->vm_stat_diff[i] = 0;
96932- atomic_long_add(v, &zone->vm_stat[i]);
96933- atomic_long_add(v, &vm_stat[i]);
96934+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
96935+ atomic_long_add_unchecked(v, &vm_stat[i]);
96936 }
96937 }
96938 #endif
96939@@ -1150,10 +1151,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
96940 stat_items_size += sizeof(struct vm_event_state);
96941 #endif
96942
96943- v = kmalloc(stat_items_size, GFP_KERNEL);
96944+ v = kzalloc(stat_items_size, GFP_KERNEL);
96945 m->private = v;
96946 if (!v)
96947 return ERR_PTR(-ENOMEM);
96948+
96949+#ifdef CONFIG_GRKERNSEC_PROC_ADD
96950+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
96951+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
96952+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
96953+ && !in_group_p(grsec_proc_gid)
96954+#endif
96955+ )
96956+ return (unsigned long *)m->private + *pos;
96957+#endif
96958+#endif
96959+
96960 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
96961 v[i] = global_page_state(i);
96962 v += NR_VM_ZONE_STAT_ITEMS;
96963@@ -1302,10 +1315,16 @@ static int __init setup_vmstat(void)
96964 put_online_cpus();
96965 #endif
96966 #ifdef CONFIG_PROC_FS
96967- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
96968- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
96969- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
96970- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
96971+ {
96972+ mode_t gr_mode = S_IRUGO;
96973+#ifdef CONFIG_GRKERNSEC_PROC_ADD
96974+ gr_mode = S_IRUSR;
96975+#endif
96976+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
96977+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
96978+ proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
96979+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
96980+ }
96981 #endif
96982 return 0;
96983 }
96984diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
96985index 175273f..1c63e05 100644
96986--- a/net/8021q/vlan.c
96987+++ b/net/8021q/vlan.c
96988@@ -474,7 +474,7 @@ out:
96989 return NOTIFY_DONE;
96990 }
96991
96992-static struct notifier_block vlan_notifier_block __read_mostly = {
96993+static struct notifier_block vlan_notifier_block = {
96994 .notifier_call = vlan_device_event,
96995 };
96996
96997@@ -549,8 +549,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
96998 err = -EPERM;
96999 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
97000 break;
97001- if ((args.u.name_type >= 0) &&
97002- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
97003+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
97004 struct vlan_net *vn;
97005
97006 vn = net_generic(net, vlan_net_id);
97007diff --git a/net/9p/client.c b/net/9p/client.c
97008index 9186550..e604a2f 100644
97009--- a/net/9p/client.c
97010+++ b/net/9p/client.c
97011@@ -588,7 +588,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
97012 len - inline_len);
97013 } else {
97014 err = copy_from_user(ename + inline_len,
97015- uidata, len - inline_len);
97016+ (char __force_user *)uidata, len - inline_len);
97017 if (err) {
97018 err = -EFAULT;
97019 goto out_err;
97020@@ -1560,7 +1560,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
97021 kernel_buf = 1;
97022 indata = data;
97023 } else
97024- indata = (__force char *)udata;
97025+ indata = (__force_kernel char *)udata;
97026 /*
97027 * response header len is 11
97028 * PDU Header(7) + IO Size (4)
97029@@ -1635,7 +1635,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
97030 kernel_buf = 1;
97031 odata = data;
97032 } else
97033- odata = (char *)udata;
97034+ odata = (char __force_kernel *)udata;
97035 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
97036 P9_ZC_HDR_SZ, kernel_buf, "dqd",
97037 fid->fid, offset, rsize);
97038diff --git a/net/9p/mod.c b/net/9p/mod.c
97039index 6ab36ae..6f1841b 100644
97040--- a/net/9p/mod.c
97041+++ b/net/9p/mod.c
97042@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
97043 void v9fs_register_trans(struct p9_trans_module *m)
97044 {
97045 spin_lock(&v9fs_trans_lock);
97046- list_add_tail(&m->list, &v9fs_trans_list);
97047+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
97048 spin_unlock(&v9fs_trans_lock);
97049 }
97050 EXPORT_SYMBOL(v9fs_register_trans);
97051@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
97052 void v9fs_unregister_trans(struct p9_trans_module *m)
97053 {
97054 spin_lock(&v9fs_trans_lock);
97055- list_del_init(&m->list);
97056+ pax_list_del_init((struct list_head *)&m->list);
97057 spin_unlock(&v9fs_trans_lock);
97058 }
97059 EXPORT_SYMBOL(v9fs_unregister_trans);
97060diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
97061index b7bd7f2..2498bf7 100644
97062--- a/net/9p/trans_fd.c
97063+++ b/net/9p/trans_fd.c
97064@@ -432,7 +432,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
97065 oldfs = get_fs();
97066 set_fs(get_ds());
97067 /* The cast to a user pointer is valid due to the set_fs() */
97068- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
97069+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
97070 set_fs(oldfs);
97071
97072 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
97073diff --git a/net/appletalk/atalk_proc.c b/net/appletalk/atalk_proc.c
97074index af46bc4..f9adfcd 100644
97075--- a/net/appletalk/atalk_proc.c
97076+++ b/net/appletalk/atalk_proc.c
97077@@ -256,7 +256,7 @@ int __init atalk_proc_init(void)
97078 struct proc_dir_entry *p;
97079 int rc = -ENOMEM;
97080
97081- atalk_proc_dir = proc_mkdir("atalk", init_net.proc_net);
97082+ atalk_proc_dir = proc_mkdir_restrict("atalk", init_net.proc_net);
97083 if (!atalk_proc_dir)
97084 goto out;
97085
97086diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
97087index 876fbe8..8bbea9f 100644
97088--- a/net/atm/atm_misc.c
97089+++ b/net/atm/atm_misc.c
97090@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
97091 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
97092 return 1;
97093 atm_return(vcc, truesize);
97094- atomic_inc(&vcc->stats->rx_drop);
97095+ atomic_inc_unchecked(&vcc->stats->rx_drop);
97096 return 0;
97097 }
97098 EXPORT_SYMBOL(atm_charge);
97099@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
97100 }
97101 }
97102 atm_return(vcc, guess);
97103- atomic_inc(&vcc->stats->rx_drop);
97104+ atomic_inc_unchecked(&vcc->stats->rx_drop);
97105 return NULL;
97106 }
97107 EXPORT_SYMBOL(atm_alloc_charge);
97108@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
97109
97110 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
97111 {
97112-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
97113+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
97114 __SONET_ITEMS
97115 #undef __HANDLE_ITEM
97116 }
97117@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
97118
97119 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
97120 {
97121-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
97122+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
97123 __SONET_ITEMS
97124 #undef __HANDLE_ITEM
97125 }
97126diff --git a/net/atm/lec.c b/net/atm/lec.c
97127index 5a2f602..9396143 100644
97128--- a/net/atm/lec.c
97129+++ b/net/atm/lec.c
97130@@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
97131 }
97132
97133 static struct lane2_ops lane2_ops = {
97134- lane2_resolve, /* resolve, spec 3.1.3 */
97135- lane2_associate_req, /* associate_req, spec 3.1.4 */
97136- NULL /* associate indicator, spec 3.1.5 */
97137+ .resolve = lane2_resolve,
97138+ .associate_req = lane2_associate_req,
97139+ .associate_indicator = NULL
97140 };
97141
97142 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
97143diff --git a/net/atm/lec.h b/net/atm/lec.h
97144index 4149db1..f2ab682 100644
97145--- a/net/atm/lec.h
97146+++ b/net/atm/lec.h
97147@@ -48,7 +48,7 @@ struct lane2_ops {
97148 const u8 *tlvs, u32 sizeoftlvs);
97149 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
97150 const u8 *tlvs, u32 sizeoftlvs);
97151-};
97152+} __no_const;
97153
97154 /*
97155 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
97156diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
97157index d1b2d9a..d549f7f 100644
97158--- a/net/atm/mpoa_caches.c
97159+++ b/net/atm/mpoa_caches.c
97160@@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
97161
97162
97163 static struct in_cache_ops ingress_ops = {
97164- in_cache_add_entry, /* add_entry */
97165- in_cache_get, /* get */
97166- in_cache_get_with_mask, /* get_with_mask */
97167- in_cache_get_by_vcc, /* get_by_vcc */
97168- in_cache_put, /* put */
97169- in_cache_remove_entry, /* remove_entry */
97170- cache_hit, /* cache_hit */
97171- clear_count_and_expired, /* clear_count */
97172- check_resolving_entries, /* check_resolving */
97173- refresh_entries, /* refresh */
97174- in_destroy_cache /* destroy_cache */
97175+ .add_entry = in_cache_add_entry,
97176+ .get = in_cache_get,
97177+ .get_with_mask = in_cache_get_with_mask,
97178+ .get_by_vcc = in_cache_get_by_vcc,
97179+ .put = in_cache_put,
97180+ .remove_entry = in_cache_remove_entry,
97181+ .cache_hit = cache_hit,
97182+ .clear_count = clear_count_and_expired,
97183+ .check_resolving = check_resolving_entries,
97184+ .refresh = refresh_entries,
97185+ .destroy_cache = in_destroy_cache
97186 };
97187
97188 static struct eg_cache_ops egress_ops = {
97189- eg_cache_add_entry, /* add_entry */
97190- eg_cache_get_by_cache_id, /* get_by_cache_id */
97191- eg_cache_get_by_tag, /* get_by_tag */
97192- eg_cache_get_by_vcc, /* get_by_vcc */
97193- eg_cache_get_by_src_ip, /* get_by_src_ip */
97194- eg_cache_put, /* put */
97195- eg_cache_remove_entry, /* remove_entry */
97196- update_eg_cache_entry, /* update */
97197- clear_expired, /* clear_expired */
97198- eg_destroy_cache /* destroy_cache */
97199+ .add_entry = eg_cache_add_entry,
97200+ .get_by_cache_id = eg_cache_get_by_cache_id,
97201+ .get_by_tag = eg_cache_get_by_tag,
97202+ .get_by_vcc = eg_cache_get_by_vcc,
97203+ .get_by_src_ip = eg_cache_get_by_src_ip,
97204+ .put = eg_cache_put,
97205+ .remove_entry = eg_cache_remove_entry,
97206+ .update = update_eg_cache_entry,
97207+ .clear_expired = clear_expired,
97208+ .destroy_cache = eg_destroy_cache
97209 };
97210
97211
97212diff --git a/net/atm/proc.c b/net/atm/proc.c
97213index bbb6461..cf04016 100644
97214--- a/net/atm/proc.c
97215+++ b/net/atm/proc.c
97216@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
97217 const struct k_atm_aal_stats *stats)
97218 {
97219 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
97220- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
97221- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
97222- atomic_read(&stats->rx_drop));
97223+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
97224+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
97225+ atomic_read_unchecked(&stats->rx_drop));
97226 }
97227
97228 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
97229diff --git a/net/atm/resources.c b/net/atm/resources.c
97230index 0447d5d..3cf4728 100644
97231--- a/net/atm/resources.c
97232+++ b/net/atm/resources.c
97233@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
97234 static void copy_aal_stats(struct k_atm_aal_stats *from,
97235 struct atm_aal_stats *to)
97236 {
97237-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
97238+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
97239 __AAL_STAT_ITEMS
97240 #undef __HANDLE_ITEM
97241 }
97242@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
97243 static void subtract_aal_stats(struct k_atm_aal_stats *from,
97244 struct atm_aal_stats *to)
97245 {
97246-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
97247+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
97248 __AAL_STAT_ITEMS
97249 #undef __HANDLE_ITEM
97250 }
97251diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
97252index 919a5ce..cc6b444 100644
97253--- a/net/ax25/sysctl_net_ax25.c
97254+++ b/net/ax25/sysctl_net_ax25.c
97255@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
97256 {
97257 char path[sizeof("net/ax25/") + IFNAMSIZ];
97258 int k;
97259- struct ctl_table *table;
97260+ ctl_table_no_const *table;
97261
97262 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
97263 if (!table)
97264diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
97265index 8323bce..a03130d 100644
97266--- a/net/batman-adv/bat_iv_ogm.c
97267+++ b/net/batman-adv/bat_iv_ogm.c
97268@@ -312,7 +312,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
97269
97270 /* randomize initial seqno to avoid collision */
97271 get_random_bytes(&random_seqno, sizeof(random_seqno));
97272- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
97273+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
97274
97275 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
97276 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
97277@@ -917,9 +917,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
97278 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
97279
97280 /* change sequence number to network order */
97281- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
97282+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
97283 batadv_ogm_packet->seqno = htonl(seqno);
97284- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
97285+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
97286
97287 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
97288
97289@@ -1594,7 +1594,7 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
97290 return;
97291
97292 /* could be changed by schedule_own_packet() */
97293- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
97294+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
97295
97296 if (ogm_packet->flags & BATADV_DIRECTLINK)
97297 has_directlink_flag = true;
97298diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
97299index 88df9b1..69cf7c0 100644
97300--- a/net/batman-adv/fragmentation.c
97301+++ b/net/batman-adv/fragmentation.c
97302@@ -445,7 +445,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
97303 frag_header.packet_type = BATADV_UNICAST_FRAG;
97304 frag_header.version = BATADV_COMPAT_VERSION;
97305 frag_header.ttl = BATADV_TTL;
97306- frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
97307+ frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
97308 frag_header.reserved = 0;
97309 frag_header.no = 0;
97310 frag_header.total_size = htons(skb->len);
97311diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
97312index f82c267..0e56d32 100644
97313--- a/net/batman-adv/soft-interface.c
97314+++ b/net/batman-adv/soft-interface.c
97315@@ -283,7 +283,7 @@ send:
97316 primary_if->net_dev->dev_addr, ETH_ALEN);
97317
97318 /* set broadcast sequence number */
97319- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
97320+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
97321 bcast_packet->seqno = htonl(seqno);
97322
97323 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
97324@@ -707,7 +707,7 @@ static int batadv_softif_init_late(struct net_device *dev)
97325 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
97326
97327 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
97328- atomic_set(&bat_priv->bcast_seqno, 1);
97329+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
97330 atomic_set(&bat_priv->tt.vn, 0);
97331 atomic_set(&bat_priv->tt.local_changes, 0);
97332 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
97333@@ -721,7 +721,7 @@ static int batadv_softif_init_late(struct net_device *dev)
97334
97335 /* randomize initial seqno to avoid collision */
97336 get_random_bytes(&random_seqno, sizeof(random_seqno));
97337- atomic_set(&bat_priv->frag_seqno, random_seqno);
97338+ atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
97339
97340 bat_priv->primary_if = NULL;
97341 bat_priv->num_ifaces = 0;
97342diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
97343index 78370ab..1cb3614 100644
97344--- a/net/batman-adv/types.h
97345+++ b/net/batman-adv/types.h
97346@@ -66,7 +66,7 @@ enum batadv_dhcp_recipient {
97347 struct batadv_hard_iface_bat_iv {
97348 unsigned char *ogm_buff;
97349 int ogm_buff_len;
97350- atomic_t ogm_seqno;
97351+ atomic_unchecked_t ogm_seqno;
97352 };
97353
97354 /**
97355@@ -714,7 +714,7 @@ struct batadv_priv {
97356 atomic_t bonding;
97357 atomic_t fragmentation;
97358 atomic_t packet_size_max;
97359- atomic_t frag_seqno;
97360+ atomic_unchecked_t frag_seqno;
97361 #ifdef CONFIG_BATMAN_ADV_BLA
97362 atomic_t bridge_loop_avoidance;
97363 #endif
97364@@ -730,7 +730,7 @@ struct batadv_priv {
97365 #endif
97366 uint32_t isolation_mark;
97367 uint32_t isolation_mark_mask;
97368- atomic_t bcast_seqno;
97369+ atomic_unchecked_t bcast_seqno;
97370 atomic_t bcast_queue_left;
97371 atomic_t batman_queue_left;
97372 char num_ifaces;
97373diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
97374index 7552f9e..074ce29 100644
97375--- a/net/bluetooth/hci_sock.c
97376+++ b/net/bluetooth/hci_sock.c
97377@@ -1052,7 +1052,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
97378 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
97379 }
97380
97381- len = min_t(unsigned int, len, sizeof(uf));
97382+ len = min((size_t)len, sizeof(uf));
97383 if (copy_from_user(&uf, optval, len)) {
97384 err = -EFAULT;
97385 break;
97386diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
97387index b0ad2c7..96f6a5e 100644
97388--- a/net/bluetooth/l2cap_core.c
97389+++ b/net/bluetooth/l2cap_core.c
97390@@ -3740,8 +3740,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
97391 break;
97392
97393 case L2CAP_CONF_RFC:
97394- if (olen == sizeof(rfc))
97395- memcpy(&rfc, (void *)val, olen);
97396+ if (olen != sizeof(rfc))
97397+ break;
97398+
97399+ memcpy(&rfc, (void *)val, olen);
97400
97401 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
97402 rfc.mode != chan->mode)
97403diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
97404index d58f76b..b69600a 100644
97405--- a/net/bluetooth/l2cap_sock.c
97406+++ b/net/bluetooth/l2cap_sock.c
97407@@ -625,7 +625,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
97408 struct sock *sk = sock->sk;
97409 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
97410 struct l2cap_options opts;
97411- int len, err = 0;
97412+ int err = 0;
97413+ size_t len = optlen;
97414 u32 opt;
97415
97416 BT_DBG("sk %p", sk);
97417@@ -652,7 +653,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
97418 opts.max_tx = chan->max_tx;
97419 opts.txwin_size = chan->tx_win;
97420
97421- len = min_t(unsigned int, sizeof(opts), optlen);
97422+ len = min(sizeof(opts), len);
97423 if (copy_from_user((char *) &opts, optval, len)) {
97424 err = -EFAULT;
97425 break;
97426@@ -734,7 +735,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
97427 struct bt_security sec;
97428 struct bt_power pwr;
97429 struct l2cap_conn *conn;
97430- int len, err = 0;
97431+ int err = 0;
97432+ size_t len = optlen;
97433 u32 opt;
97434
97435 BT_DBG("sk %p", sk);
97436@@ -757,7 +759,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
97437
97438 sec.level = BT_SECURITY_LOW;
97439
97440- len = min_t(unsigned int, sizeof(sec), optlen);
97441+ len = min(sizeof(sec), len);
97442 if (copy_from_user((char *) &sec, optval, len)) {
97443 err = -EFAULT;
97444 break;
97445@@ -857,7 +859,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
97446
97447 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
97448
97449- len = min_t(unsigned int, sizeof(pwr), optlen);
97450+ len = min(sizeof(pwr), len);
97451 if (copy_from_user((char *) &pwr, optval, len)) {
97452 err = -EFAULT;
97453 break;
97454diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
97455index 3c2d3e4..884855a 100644
97456--- a/net/bluetooth/rfcomm/sock.c
97457+++ b/net/bluetooth/rfcomm/sock.c
97458@@ -672,7 +672,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
97459 struct sock *sk = sock->sk;
97460 struct bt_security sec;
97461 int err = 0;
97462- size_t len;
97463+ size_t len = optlen;
97464 u32 opt;
97465
97466 BT_DBG("sk %p", sk);
97467@@ -694,7 +694,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
97468
97469 sec.level = BT_SECURITY_LOW;
97470
97471- len = min_t(unsigned int, sizeof(sec), optlen);
97472+ len = min(sizeof(sec), len);
97473 if (copy_from_user((char *) &sec, optval, len)) {
97474 err = -EFAULT;
97475 break;
97476diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
97477index f9c0980a..fcbbfeb 100644
97478--- a/net/bluetooth/rfcomm/tty.c
97479+++ b/net/bluetooth/rfcomm/tty.c
97480@@ -717,7 +717,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
97481 BT_DBG("tty %p id %d", tty, tty->index);
97482
97483 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
97484- dev->channel, dev->port.count);
97485+ dev->channel, atomic_read(&dev->port.count));
97486
97487 err = tty_port_open(&dev->port, tty, filp);
97488 if (err)
97489@@ -740,7 +740,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
97490 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
97491
97492 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
97493- dev->port.count);
97494+ atomic_read(&dev->port.count));
97495
97496 tty_port_close(&dev->port, tty, filp);
97497 }
97498diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
97499index 0e474b1..fb7109c 100644
97500--- a/net/bridge/netfilter/ebtables.c
97501+++ b/net/bridge/netfilter/ebtables.c
97502@@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
97503 tmp.valid_hooks = t->table->valid_hooks;
97504 }
97505 mutex_unlock(&ebt_mutex);
97506- if (copy_to_user(user, &tmp, *len) != 0) {
97507+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
97508 BUGPRINT("c2u Didn't work\n");
97509 ret = -EFAULT;
97510 break;
97511@@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
97512 goto out;
97513 tmp.valid_hooks = t->valid_hooks;
97514
97515- if (copy_to_user(user, &tmp, *len) != 0) {
97516+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
97517 ret = -EFAULT;
97518 break;
97519 }
97520@@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
97521 tmp.entries_size = t->table->entries_size;
97522 tmp.valid_hooks = t->table->valid_hooks;
97523
97524- if (copy_to_user(user, &tmp, *len) != 0) {
97525+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
97526 ret = -EFAULT;
97527 break;
97528 }
97529diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
97530index 0f45522..dab651f 100644
97531--- a/net/caif/cfctrl.c
97532+++ b/net/caif/cfctrl.c
97533@@ -10,6 +10,7 @@
97534 #include <linux/spinlock.h>
97535 #include <linux/slab.h>
97536 #include <linux/pkt_sched.h>
97537+#include <linux/sched.h>
97538 #include <net/caif/caif_layer.h>
97539 #include <net/caif/cfpkt.h>
97540 #include <net/caif/cfctrl.h>
97541@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
97542 memset(&dev_info, 0, sizeof(dev_info));
97543 dev_info.id = 0xff;
97544 cfsrvl_init(&this->serv, 0, &dev_info, false);
97545- atomic_set(&this->req_seq_no, 1);
97546- atomic_set(&this->rsp_seq_no, 1);
97547+ atomic_set_unchecked(&this->req_seq_no, 1);
97548+ atomic_set_unchecked(&this->rsp_seq_no, 1);
97549 this->serv.layer.receive = cfctrl_recv;
97550 sprintf(this->serv.layer.name, "ctrl");
97551 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
97552@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
97553 struct cfctrl_request_info *req)
97554 {
97555 spin_lock_bh(&ctrl->info_list_lock);
97556- atomic_inc(&ctrl->req_seq_no);
97557- req->sequence_no = atomic_read(&ctrl->req_seq_no);
97558+ atomic_inc_unchecked(&ctrl->req_seq_no);
97559+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
97560 list_add_tail(&req->list, &ctrl->list);
97561 spin_unlock_bh(&ctrl->info_list_lock);
97562 }
97563@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
97564 if (p != first)
97565 pr_warn("Requests are not received in order\n");
97566
97567- atomic_set(&ctrl->rsp_seq_no,
97568+ atomic_set_unchecked(&ctrl->rsp_seq_no,
97569 p->sequence_no);
97570 list_del(&p->list);
97571 goto out;
97572diff --git a/net/can/af_can.c b/net/can/af_can.c
97573index a27f8aa..67174a3 100644
97574--- a/net/can/af_can.c
97575+++ b/net/can/af_can.c
97576@@ -863,7 +863,7 @@ static const struct net_proto_family can_family_ops = {
97577 };
97578
97579 /* notifier block for netdevice event */
97580-static struct notifier_block can_netdev_notifier __read_mostly = {
97581+static struct notifier_block can_netdev_notifier = {
97582 .notifier_call = can_notifier,
97583 };
97584
97585diff --git a/net/can/bcm.c b/net/can/bcm.c
97586index dcb75c0..24b1b43 100644
97587--- a/net/can/bcm.c
97588+++ b/net/can/bcm.c
97589@@ -1624,7 +1624,7 @@ static int __init bcm_module_init(void)
97590 }
97591
97592 /* create /proc/net/can-bcm directory */
97593- proc_dir = proc_mkdir("can-bcm", init_net.proc_net);
97594+ proc_dir = proc_mkdir_restrict("can-bcm", init_net.proc_net);
97595 return 0;
97596 }
97597
97598diff --git a/net/can/gw.c b/net/can/gw.c
97599index ac31891..4799c17 100644
97600--- a/net/can/gw.c
97601+++ b/net/can/gw.c
97602@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
97603 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
97604
97605 static HLIST_HEAD(cgw_list);
97606-static struct notifier_block notifier;
97607
97608 static struct kmem_cache *cgw_cache __read_mostly;
97609
97610@@ -947,6 +946,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
97611 return err;
97612 }
97613
97614+static struct notifier_block notifier = {
97615+ .notifier_call = cgw_notifier
97616+};
97617+
97618 static __init int cgw_module_init(void)
97619 {
97620 /* sanitize given module parameter */
97621@@ -962,7 +965,6 @@ static __init int cgw_module_init(void)
97622 return -ENOMEM;
97623
97624 /* set notifier */
97625- notifier.notifier_call = cgw_notifier;
97626 register_netdevice_notifier(&notifier);
97627
97628 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
97629diff --git a/net/can/proc.c b/net/can/proc.c
97630index b543470..d2ddae2 100644
97631--- a/net/can/proc.c
97632+++ b/net/can/proc.c
97633@@ -468,7 +468,7 @@ static void can_remove_proc_readentry(const char *name)
97634 void can_init_proc(void)
97635 {
97636 /* create /proc/net/can directory */
97637- can_dir = proc_mkdir("can", init_net.proc_net);
97638+ can_dir = proc_mkdir_restrict("can", init_net.proc_net);
97639
97640 if (!can_dir) {
97641 printk(KERN_INFO "can: failed to create /proc/net/can . "
97642diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
97643index 30efc5c..cfa1bbc 100644
97644--- a/net/ceph/messenger.c
97645+++ b/net/ceph/messenger.c
97646@@ -187,7 +187,7 @@ static void con_fault(struct ceph_connection *con);
97647 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
97648
97649 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
97650-static atomic_t addr_str_seq = ATOMIC_INIT(0);
97651+static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
97652
97653 static struct page *zero_page; /* used in certain error cases */
97654
97655@@ -198,7 +198,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
97656 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
97657 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
97658
97659- i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
97660+ i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
97661 s = addr_str[i];
97662
97663 switch (ss->ss_family) {
97664diff --git a/net/compat.c b/net/compat.c
97665index f50161f..94fa415 100644
97666--- a/net/compat.c
97667+++ b/net/compat.c
97668@@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
97669 return -EFAULT;
97670 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
97671 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
97672- kmsg->msg_name = compat_ptr(tmp1);
97673- kmsg->msg_iov = compat_ptr(tmp2);
97674- kmsg->msg_control = compat_ptr(tmp3);
97675+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
97676+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
97677+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
97678 return 0;
97679 }
97680
97681@@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
97682
97683 if (kern_msg->msg_namelen) {
97684 if (mode == VERIFY_READ) {
97685- int err = move_addr_to_kernel(kern_msg->msg_name,
97686+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
97687 kern_msg->msg_namelen,
97688 kern_address);
97689 if (err < 0)
97690@@ -99,7 +99,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
97691 kern_msg->msg_name = NULL;
97692
97693 tot_len = iov_from_user_compat_to_kern(kern_iov,
97694- (struct compat_iovec __user *)kern_msg->msg_iov,
97695+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
97696 kern_msg->msg_iovlen);
97697 if (tot_len >= 0)
97698 kern_msg->msg_iov = kern_iov;
97699@@ -119,20 +119,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
97700
97701 #define CMSG_COMPAT_FIRSTHDR(msg) \
97702 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
97703- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
97704+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
97705 (struct compat_cmsghdr __user *)NULL)
97706
97707 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
97708 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
97709 (ucmlen) <= (unsigned long) \
97710 ((mhdr)->msg_controllen - \
97711- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
97712+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
97713
97714 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
97715 struct compat_cmsghdr __user *cmsg, int cmsg_len)
97716 {
97717 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
97718- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
97719+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
97720 msg->msg_controllen)
97721 return NULL;
97722 return (struct compat_cmsghdr __user *)ptr;
97723@@ -222,7 +222,7 @@ Efault:
97724
97725 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
97726 {
97727- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
97728+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
97729 struct compat_cmsghdr cmhdr;
97730 struct compat_timeval ctv;
97731 struct compat_timespec cts[3];
97732@@ -278,7 +278,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
97733
97734 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
97735 {
97736- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
97737+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
97738 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
97739 int fdnum = scm->fp->count;
97740 struct file **fp = scm->fp->fp;
97741@@ -366,7 +366,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
97742 return -EFAULT;
97743 old_fs = get_fs();
97744 set_fs(KERNEL_DS);
97745- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
97746+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
97747 set_fs(old_fs);
97748
97749 return err;
97750@@ -427,7 +427,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
97751 len = sizeof(ktime);
97752 old_fs = get_fs();
97753 set_fs(KERNEL_DS);
97754- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
97755+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
97756 set_fs(old_fs);
97757
97758 if (!err) {
97759@@ -570,7 +570,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
97760 case MCAST_JOIN_GROUP:
97761 case MCAST_LEAVE_GROUP:
97762 {
97763- struct compat_group_req __user *gr32 = (void *)optval;
97764+ struct compat_group_req __user *gr32 = (void __user *)optval;
97765 struct group_req __user *kgr =
97766 compat_alloc_user_space(sizeof(struct group_req));
97767 u32 interface;
97768@@ -591,7 +591,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
97769 case MCAST_BLOCK_SOURCE:
97770 case MCAST_UNBLOCK_SOURCE:
97771 {
97772- struct compat_group_source_req __user *gsr32 = (void *)optval;
97773+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
97774 struct group_source_req __user *kgsr = compat_alloc_user_space(
97775 sizeof(struct group_source_req));
97776 u32 interface;
97777@@ -612,7 +612,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
97778 }
97779 case MCAST_MSFILTER:
97780 {
97781- struct compat_group_filter __user *gf32 = (void *)optval;
97782+ struct compat_group_filter __user *gf32 = (void __user *)optval;
97783 struct group_filter __user *kgf;
97784 u32 interface, fmode, numsrc;
97785
97786@@ -650,7 +650,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
97787 char __user *optval, int __user *optlen,
97788 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
97789 {
97790- struct compat_group_filter __user *gf32 = (void *)optval;
97791+ struct compat_group_filter __user *gf32 = (void __user *)optval;
97792 struct group_filter __user *kgf;
97793 int __user *koptlen;
97794 u32 interface, fmode, numsrc;
97795@@ -803,7 +803,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
97796
97797 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
97798 return -EINVAL;
97799- if (copy_from_user(a, args, nas[call]))
97800+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
97801 return -EFAULT;
97802 a0 = a[0];
97803 a1 = a[1];
97804diff --git a/net/core/datagram.c b/net/core/datagram.c
97805index a16ed7b..eb44d17 100644
97806--- a/net/core/datagram.c
97807+++ b/net/core/datagram.c
97808@@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
97809 }
97810
97811 kfree_skb(skb);
97812- atomic_inc(&sk->sk_drops);
97813+ atomic_inc_unchecked(&sk->sk_drops);
97814 sk_mem_reclaim_partial(sk);
97815
97816 return err;
97817diff --git a/net/core/dev.c b/net/core/dev.c
97818index 45fa2f1..f3e28ec 100644
97819--- a/net/core/dev.c
97820+++ b/net/core/dev.c
97821@@ -1688,14 +1688,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
97822 {
97823 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
97824 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
97825- atomic_long_inc(&dev->rx_dropped);
97826+ atomic_long_inc_unchecked(&dev->rx_dropped);
97827 kfree_skb(skb);
97828 return NET_RX_DROP;
97829 }
97830 }
97831
97832 if (unlikely(!is_skb_forwardable(dev, skb))) {
97833- atomic_long_inc(&dev->rx_dropped);
97834+ atomic_long_inc_unchecked(&dev->rx_dropped);
97835 kfree_skb(skb);
97836 return NET_RX_DROP;
97837 }
97838@@ -2453,7 +2453,7 @@ static int illegal_highdma(const struct net_device *dev, struct sk_buff *skb)
97839
97840 struct dev_gso_cb {
97841 void (*destructor)(struct sk_buff *skb);
97842-};
97843+} __no_const;
97844
97845 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
97846
97847@@ -3227,7 +3227,7 @@ enqueue:
97848
97849 local_irq_restore(flags);
97850
97851- atomic_long_inc(&skb->dev->rx_dropped);
97852+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
97853 kfree_skb(skb);
97854 return NET_RX_DROP;
97855 }
97856@@ -3308,7 +3308,7 @@ int netif_rx_ni(struct sk_buff *skb)
97857 }
97858 EXPORT_SYMBOL(netif_rx_ni);
97859
97860-static void net_tx_action(struct softirq_action *h)
97861+static __latent_entropy void net_tx_action(void)
97862 {
97863 struct softnet_data *sd = &__get_cpu_var(softnet_data);
97864
97865@@ -3645,7 +3645,7 @@ ncls:
97866 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
97867 } else {
97868 drop:
97869- atomic_long_inc(&skb->dev->rx_dropped);
97870+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
97871 kfree_skb(skb);
97872 /* Jamal, now you will not able to escape explaining
97873 * me how you were going to use this. :-)
97874@@ -4331,7 +4331,7 @@ void netif_napi_del(struct napi_struct *napi)
97875 }
97876 EXPORT_SYMBOL(netif_napi_del);
97877
97878-static void net_rx_action(struct softirq_action *h)
97879+static __latent_entropy void net_rx_action(void)
97880 {
97881 struct softnet_data *sd = &__get_cpu_var(softnet_data);
97882 unsigned long time_limit = jiffies + 2;
97883@@ -6250,7 +6250,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
97884 } else {
97885 netdev_stats_to_stats64(storage, &dev->stats);
97886 }
97887- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
97888+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
97889 return storage;
97890 }
97891 EXPORT_SYMBOL(dev_get_stats);
97892diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
97893index cf999e0..c59a975 100644
97894--- a/net/core/dev_ioctl.c
97895+++ b/net/core/dev_ioctl.c
97896@@ -366,9 +366,13 @@ void dev_load(struct net *net, const char *name)
97897 if (no_module && capable(CAP_NET_ADMIN))
97898 no_module = request_module("netdev-%s", name);
97899 if (no_module && capable(CAP_SYS_MODULE)) {
97900+#ifdef CONFIG_GRKERNSEC_MODHARDEN
97901+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
97902+#else
97903 if (!request_module("%s", name))
97904 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
97905 name);
97906+#endif
97907 }
97908 }
97909 EXPORT_SYMBOL(dev_load);
97910diff --git a/net/core/filter.c b/net/core/filter.c
97911index ad30d62..21c0743 100644
97912--- a/net/core/filter.c
97913+++ b/net/core/filter.c
97914@@ -126,7 +126,7 @@ unsigned int sk_run_filter(const struct sk_buff *skb,
97915 void *ptr;
97916 u32 A = 0; /* Accumulator */
97917 u32 X = 0; /* Index Register */
97918- u32 mem[BPF_MEMWORDS]; /* Scratch Memory Store */
97919+ u32 mem[BPF_MEMWORDS] = {}; /* Scratch Memory Store */
97920 u32 tmp;
97921 int k;
97922
97923@@ -292,10 +292,10 @@ load_b:
97924 X = K;
97925 continue;
97926 case BPF_S_LD_MEM:
97927- A = mem[K];
97928+ A = mem[K&15];
97929 continue;
97930 case BPF_S_LDX_MEM:
97931- X = mem[K];
97932+ X = mem[K&15];
97933 continue;
97934 case BPF_S_MISC_TAX:
97935 X = A;
97936@@ -308,10 +308,10 @@ load_b:
97937 case BPF_S_RET_A:
97938 return A;
97939 case BPF_S_ST:
97940- mem[K] = A;
97941+ mem[K&15] = A;
97942 continue;
97943 case BPF_S_STX:
97944- mem[K] = X;
97945+ mem[K&15] = X;
97946 continue;
97947 case BPF_S_ANC_PROTOCOL:
97948 A = ntohs(skb->protocol);
97949@@ -355,6 +355,10 @@ load_b:
97950
97951 if (skb_is_nonlinear(skb))
97952 return 0;
97953+
97954+ if (skb->len < sizeof(struct nlattr))
97955+ return 0;
97956+
97957 if (A > skb->len - sizeof(struct nlattr))
97958 return 0;
97959
97960@@ -371,11 +375,15 @@ load_b:
97961
97962 if (skb_is_nonlinear(skb))
97963 return 0;
97964+
97965+ if (skb->len < sizeof(struct nlattr))
97966+ return 0;
97967+
97968 if (A > skb->len - sizeof(struct nlattr))
97969 return 0;
97970
97971 nla = (struct nlattr *)&skb->data[A];
97972- if (nla->nla_len > A - skb->len)
97973+ if (nla->nla_len > skb->len - A)
97974 return 0;
97975
97976 nla = nla_find_nested(nla, X);
97977@@ -391,9 +399,10 @@ load_b:
97978 continue;
97979 #endif
97980 default:
97981- WARN_RATELIMIT(1, "Unknown code:%u jt:%u tf:%u k:%u\n",
97982+ WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
97983 fentry->code, fentry->jt,
97984 fentry->jf, fentry->k);
97985+ BUG();
97986 return 0;
97987 }
97988 }
97989@@ -416,7 +425,7 @@ static int check_load_and_stores(struct sock_filter *filter, int flen)
97990 u16 *masks, memvalid = 0; /* one bit per cell, 16 cells */
97991 int pc, ret = 0;
97992
97993- BUILD_BUG_ON(BPF_MEMWORDS > 16);
97994+ BUILD_BUG_ON(BPF_MEMWORDS != 16);
97995 masks = kmalloc(flen * sizeof(*masks), GFP_KERNEL);
97996 if (!masks)
97997 return -ENOMEM;
97998@@ -679,7 +688,7 @@ int sk_unattached_filter_create(struct sk_filter **pfp,
97999 fp = kmalloc(sk_filter_size(fprog->len), GFP_KERNEL);
98000 if (!fp)
98001 return -ENOMEM;
98002- memcpy(fp->insns, fprog->filter, fsize);
98003+ memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
98004
98005 atomic_set(&fp->refcnt, 1);
98006 fp->len = fprog->len;
98007diff --git a/net/core/flow.c b/net/core/flow.c
98008index dfa602c..3103d88 100644
98009--- a/net/core/flow.c
98010+++ b/net/core/flow.c
98011@@ -61,7 +61,7 @@ struct flow_cache {
98012 struct timer_list rnd_timer;
98013 };
98014
98015-atomic_t flow_cache_genid = ATOMIC_INIT(0);
98016+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
98017 EXPORT_SYMBOL(flow_cache_genid);
98018 static struct flow_cache flow_cache_global;
98019 static struct kmem_cache *flow_cachep __read_mostly;
98020@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
98021
98022 static int flow_entry_valid(struct flow_cache_entry *fle)
98023 {
98024- if (atomic_read(&flow_cache_genid) != fle->genid)
98025+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
98026 return 0;
98027 if (fle->object && !fle->object->ops->check(fle->object))
98028 return 0;
98029@@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
98030 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
98031 fcp->hash_count++;
98032 }
98033- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
98034+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
98035 flo = fle->object;
98036 if (!flo)
98037 goto ret_object;
98038@@ -279,7 +279,7 @@ nocache:
98039 }
98040 flo = resolver(net, key, family, dir, flo, ctx);
98041 if (fle) {
98042- fle->genid = atomic_read(&flow_cache_genid);
98043+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
98044 if (!IS_ERR(flo))
98045 fle->object = flo;
98046 else
98047diff --git a/net/core/iovec.c b/net/core/iovec.c
98048index b618694..192bbba 100644
98049--- a/net/core/iovec.c
98050+++ b/net/core/iovec.c
98051@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
98052 if (m->msg_namelen) {
98053 if (mode == VERIFY_READ) {
98054 void __user *namep;
98055- namep = (void __user __force *) m->msg_name;
98056+ namep = (void __force_user *) m->msg_name;
98057 err = move_addr_to_kernel(namep, m->msg_namelen,
98058 address);
98059 if (err < 0)
98060@@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
98061 }
98062
98063 size = m->msg_iovlen * sizeof(struct iovec);
98064- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
98065+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
98066 return -EFAULT;
98067
98068 m->msg_iov = iov;
98069diff --git a/net/core/neighbour.c b/net/core/neighbour.c
98070index e161290..8149aea 100644
98071--- a/net/core/neighbour.c
98072+++ b/net/core/neighbour.c
98073@@ -2824,7 +2824,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
98074 void __user *buffer, size_t *lenp, loff_t *ppos)
98075 {
98076 int size, ret;
98077- struct ctl_table tmp = *ctl;
98078+ ctl_table_no_const tmp = *ctl;
98079
98080 tmp.extra1 = &zero;
98081 tmp.extra2 = &unres_qlen_max;
98082@@ -2886,7 +2886,7 @@ static int neigh_proc_dointvec_zero_intmax(struct ctl_table *ctl, int write,
98083 void __user *buffer,
98084 size_t *lenp, loff_t *ppos)
98085 {
98086- struct ctl_table tmp = *ctl;
98087+ ctl_table_no_const tmp = *ctl;
98088 int ret;
98089
98090 tmp.extra1 = &zero;
98091@@ -3058,11 +3058,12 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
98092 memset(&t->neigh_vars[NEIGH_VAR_GC_INTERVAL], 0,
98093 sizeof(t->neigh_vars[NEIGH_VAR_GC_INTERVAL]));
98094 } else {
98095+ struct neigh_table *ntable = container_of(p, struct neigh_table, parms);
98096 dev_name_source = "default";
98097- t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = (int *)(p + 1);
98098- t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = (int *)(p + 1) + 1;
98099- t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = (int *)(p + 1) + 2;
98100- t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = (int *)(p + 1) + 3;
98101+ t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = &ntable->gc_interval;
98102+ t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = &ntable->gc_thresh1;
98103+ t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = &ntable->gc_thresh2;
98104+ t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = &ntable->gc_thresh3;
98105 }
98106
98107 if (handler) {
98108diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
98109index 2bf8329..2eb1423 100644
98110--- a/net/core/net-procfs.c
98111+++ b/net/core/net-procfs.c
98112@@ -79,7 +79,13 @@ static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
98113 struct rtnl_link_stats64 temp;
98114 const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
98115
98116- seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98117+ if (gr_proc_is_restricted())
98118+ seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98119+ "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
98120+ dev->name, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL,
98121+ 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL);
98122+ else
98123+ seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98124 "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
98125 dev->name, stats->rx_bytes, stats->rx_packets,
98126 stats->rx_errors,
98127@@ -166,7 +172,7 @@ static int softnet_seq_show(struct seq_file *seq, void *v)
98128 return 0;
98129 }
98130
98131-static const struct seq_operations dev_seq_ops = {
98132+const struct seq_operations dev_seq_ops = {
98133 .start = dev_seq_start,
98134 .next = dev_seq_next,
98135 .stop = dev_seq_stop,
98136@@ -196,7 +202,7 @@ static const struct seq_operations softnet_seq_ops = {
98137
98138 static int softnet_seq_open(struct inode *inode, struct file *file)
98139 {
98140- return seq_open(file, &softnet_seq_ops);
98141+ return seq_open_restrict(file, &softnet_seq_ops);
98142 }
98143
98144 static const struct file_operations softnet_seq_fops = {
98145@@ -283,8 +289,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
98146 else
98147 seq_printf(seq, "%04x", ntohs(pt->type));
98148
98149+#ifdef CONFIG_GRKERNSEC_HIDESYM
98150+ seq_printf(seq, " %-8s %pf\n",
98151+ pt->dev ? pt->dev->name : "", NULL);
98152+#else
98153 seq_printf(seq, " %-8s %pf\n",
98154 pt->dev ? pt->dev->name : "", pt->func);
98155+#endif
98156 }
98157
98158 return 0;
98159diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
98160index 81d3a9a..a0bd7a8 100644
98161--- a/net/core/net_namespace.c
98162+++ b/net/core/net_namespace.c
98163@@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
98164 int error;
98165 LIST_HEAD(net_exit_list);
98166
98167- list_add_tail(&ops->list, list);
98168+ pax_list_add_tail((struct list_head *)&ops->list, list);
98169 if (ops->init || (ops->id && ops->size)) {
98170 for_each_net(net) {
98171 error = ops_init(ops, net);
98172@@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
98173
98174 out_undo:
98175 /* If I have an error cleanup all namespaces I initialized */
98176- list_del(&ops->list);
98177+ pax_list_del((struct list_head *)&ops->list);
98178 ops_exit_list(ops, &net_exit_list);
98179 ops_free_list(ops, &net_exit_list);
98180 return error;
98181@@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
98182 struct net *net;
98183 LIST_HEAD(net_exit_list);
98184
98185- list_del(&ops->list);
98186+ pax_list_del((struct list_head *)&ops->list);
98187 for_each_net(net)
98188 list_add_tail(&net->exit_list, &net_exit_list);
98189 ops_exit_list(ops, &net_exit_list);
98190@@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
98191 mutex_lock(&net_mutex);
98192 error = register_pernet_operations(&pernet_list, ops);
98193 if (!error && (first_device == &pernet_list))
98194- first_device = &ops->list;
98195+ first_device = (struct list_head *)&ops->list;
98196 mutex_unlock(&net_mutex);
98197 return error;
98198 }
98199diff --git a/net/core/netpoll.c b/net/core/netpoll.c
98200index df9e6b1..6e68e4e 100644
98201--- a/net/core/netpoll.c
98202+++ b/net/core/netpoll.c
98203@@ -435,7 +435,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
98204 struct udphdr *udph;
98205 struct iphdr *iph;
98206 struct ethhdr *eth;
98207- static atomic_t ip_ident;
98208+ static atomic_unchecked_t ip_ident;
98209 struct ipv6hdr *ip6h;
98210
98211 udp_len = len + sizeof(*udph);
98212@@ -506,7 +506,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
98213 put_unaligned(0x45, (unsigned char *)iph);
98214 iph->tos = 0;
98215 put_unaligned(htons(ip_len), &(iph->tot_len));
98216- iph->id = htons(atomic_inc_return(&ip_ident));
98217+ iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
98218 iph->frag_off = 0;
98219 iph->ttl = 64;
98220 iph->protocol = IPPROTO_UDP;
98221diff --git a/net/core/pktgen.c b/net/core/pktgen.c
98222index fdac61c..e5e5b46 100644
98223--- a/net/core/pktgen.c
98224+++ b/net/core/pktgen.c
98225@@ -3719,7 +3719,7 @@ static int __net_init pg_net_init(struct net *net)
98226 pn->net = net;
98227 INIT_LIST_HEAD(&pn->pktgen_threads);
98228 pn->pktgen_exiting = false;
98229- pn->proc_dir = proc_mkdir(PG_PROC_DIR, pn->net->proc_net);
98230+ pn->proc_dir = proc_mkdir_restrict(PG_PROC_DIR, pn->net->proc_net);
98231 if (!pn->proc_dir) {
98232 pr_warn("cannot create /proc/net/%s\n", PG_PROC_DIR);
98233 return -ENODEV;
98234diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
98235index 120eecc..cd1ec44 100644
98236--- a/net/core/rtnetlink.c
98237+++ b/net/core/rtnetlink.c
98238@@ -58,7 +58,7 @@ struct rtnl_link {
98239 rtnl_doit_func doit;
98240 rtnl_dumpit_func dumpit;
98241 rtnl_calcit_func calcit;
98242-};
98243+} __no_const;
98244
98245 static DEFINE_MUTEX(rtnl_mutex);
98246
98247@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
98248 if (rtnl_link_ops_get(ops->kind))
98249 return -EEXIST;
98250
98251- if (!ops->dellink)
98252- ops->dellink = unregister_netdevice_queue;
98253+ if (!ops->dellink) {
98254+ pax_open_kernel();
98255+ *(void **)&ops->dellink = unregister_netdevice_queue;
98256+ pax_close_kernel();
98257+ }
98258
98259- list_add_tail(&ops->list, &link_ops);
98260+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
98261 return 0;
98262 }
98263 EXPORT_SYMBOL_GPL(__rtnl_link_register);
98264@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
98265 for_each_net(net) {
98266 __rtnl_kill_links(net, ops);
98267 }
98268- list_del(&ops->list);
98269+ pax_list_del((struct list_head *)&ops->list);
98270 }
98271 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
98272
98273diff --git a/net/core/scm.c b/net/core/scm.c
98274index b442e7e..6f5b5a2 100644
98275--- a/net/core/scm.c
98276+++ b/net/core/scm.c
98277@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
98278 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
98279 {
98280 struct cmsghdr __user *cm
98281- = (__force struct cmsghdr __user *)msg->msg_control;
98282+ = (struct cmsghdr __force_user *)msg->msg_control;
98283 struct cmsghdr cmhdr;
98284 int cmlen = CMSG_LEN(len);
98285 int err;
98286@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
98287 err = -EFAULT;
98288 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
98289 goto out;
98290- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
98291+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
98292 goto out;
98293 cmlen = CMSG_SPACE(len);
98294 if (msg->msg_controllen < cmlen)
98295@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
98296 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
98297 {
98298 struct cmsghdr __user *cm
98299- = (__force struct cmsghdr __user*)msg->msg_control;
98300+ = (struct cmsghdr __force_user *)msg->msg_control;
98301
98302 int fdmax = 0;
98303 int fdnum = scm->fp->count;
98304@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
98305 if (fdnum < fdmax)
98306 fdmax = fdnum;
98307
98308- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
98309+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
98310 i++, cmfptr++)
98311 {
98312 struct socket *sock;
98313diff --git a/net/core/skbuff.c b/net/core/skbuff.c
98314index 90b96a1..cd18f16d 100644
98315--- a/net/core/skbuff.c
98316+++ b/net/core/skbuff.c
98317@@ -2003,7 +2003,7 @@ EXPORT_SYMBOL(__skb_checksum);
98318 __wsum skb_checksum(const struct sk_buff *skb, int offset,
98319 int len, __wsum csum)
98320 {
98321- const struct skb_checksum_ops ops = {
98322+ static const struct skb_checksum_ops ops = {
98323 .update = csum_partial_ext,
98324 .combine = csum_block_add_ext,
98325 };
98326@@ -3220,13 +3220,15 @@ void __init skb_init(void)
98327 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
98328 sizeof(struct sk_buff),
98329 0,
98330- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
98331+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
98332+ SLAB_NO_SANITIZE,
98333 NULL);
98334 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
98335 (2*sizeof(struct sk_buff)) +
98336 sizeof(atomic_t),
98337 0,
98338- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
98339+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
98340+ SLAB_NO_SANITIZE,
98341 NULL);
98342 }
98343
98344diff --git a/net/core/sock.c b/net/core/sock.c
98345index c0fc6bd..51d8326 100644
98346--- a/net/core/sock.c
98347+++ b/net/core/sock.c
98348@@ -393,7 +393,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
98349 struct sk_buff_head *list = &sk->sk_receive_queue;
98350
98351 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
98352- atomic_inc(&sk->sk_drops);
98353+ atomic_inc_unchecked(&sk->sk_drops);
98354 trace_sock_rcvqueue_full(sk, skb);
98355 return -ENOMEM;
98356 }
98357@@ -403,7 +403,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
98358 return err;
98359
98360 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
98361- atomic_inc(&sk->sk_drops);
98362+ atomic_inc_unchecked(&sk->sk_drops);
98363 return -ENOBUFS;
98364 }
98365
98366@@ -423,7 +423,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
98367 skb_dst_force(skb);
98368
98369 spin_lock_irqsave(&list->lock, flags);
98370- skb->dropcount = atomic_read(&sk->sk_drops);
98371+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
98372 __skb_queue_tail(list, skb);
98373 spin_unlock_irqrestore(&list->lock, flags);
98374
98375@@ -443,7 +443,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
98376 skb->dev = NULL;
98377
98378 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
98379- atomic_inc(&sk->sk_drops);
98380+ atomic_inc_unchecked(&sk->sk_drops);
98381 goto discard_and_relse;
98382 }
98383 if (nested)
98384@@ -461,7 +461,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
98385 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
98386 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
98387 bh_unlock_sock(sk);
98388- atomic_inc(&sk->sk_drops);
98389+ atomic_inc_unchecked(&sk->sk_drops);
98390 goto discard_and_relse;
98391 }
98392
98393@@ -949,12 +949,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
98394 struct timeval tm;
98395 } v;
98396
98397- int lv = sizeof(int);
98398- int len;
98399+ unsigned int lv = sizeof(int);
98400+ unsigned int len;
98401
98402 if (get_user(len, optlen))
98403 return -EFAULT;
98404- if (len < 0)
98405+ if (len > INT_MAX)
98406 return -EINVAL;
98407
98408 memset(&v, 0, sizeof(v));
98409@@ -1106,11 +1106,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
98410
98411 case SO_PEERNAME:
98412 {
98413- char address[128];
98414+ char address[_K_SS_MAXSIZE];
98415
98416 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
98417 return -ENOTCONN;
98418- if (lv < len)
98419+ if (lv < len || sizeof address < len)
98420 return -EINVAL;
98421 if (copy_to_user(optval, address, len))
98422 return -EFAULT;
98423@@ -1191,7 +1191,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
98424
98425 if (len > lv)
98426 len = lv;
98427- if (copy_to_user(optval, &v, len))
98428+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
98429 return -EFAULT;
98430 lenout:
98431 if (put_user(len, optlen))
98432@@ -2326,7 +2326,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
98433 */
98434 smp_wmb();
98435 atomic_set(&sk->sk_refcnt, 1);
98436- atomic_set(&sk->sk_drops, 0);
98437+ atomic_set_unchecked(&sk->sk_drops, 0);
98438 }
98439 EXPORT_SYMBOL(sock_init_data);
98440
98441@@ -2454,6 +2454,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
98442 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
98443 int level, int type)
98444 {
98445+ struct sock_extended_err ee;
98446 struct sock_exterr_skb *serr;
98447 struct sk_buff *skb, *skb2;
98448 int copied, err;
98449@@ -2475,7 +2476,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
98450 sock_recv_timestamp(msg, sk, skb);
98451
98452 serr = SKB_EXT_ERR(skb);
98453- put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
98454+ ee = serr->ee;
98455+ put_cmsg(msg, level, type, sizeof ee, &ee);
98456
98457 msg->msg_flags |= MSG_ERRQUEUE;
98458 err = copied;
98459diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
98460index a0e9cf6..ef7f9ed 100644
98461--- a/net/core/sock_diag.c
98462+++ b/net/core/sock_diag.c
98463@@ -9,26 +9,33 @@
98464 #include <linux/inet_diag.h>
98465 #include <linux/sock_diag.h>
98466
98467-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
98468+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
98469 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
98470 static DEFINE_MUTEX(sock_diag_table_mutex);
98471
98472 int sock_diag_check_cookie(void *sk, __u32 *cookie)
98473 {
98474+#ifndef CONFIG_GRKERNSEC_HIDESYM
98475 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
98476 cookie[1] != INET_DIAG_NOCOOKIE) &&
98477 ((u32)(unsigned long)sk != cookie[0] ||
98478 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
98479 return -ESTALE;
98480 else
98481+#endif
98482 return 0;
98483 }
98484 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
98485
98486 void sock_diag_save_cookie(void *sk, __u32 *cookie)
98487 {
98488+#ifdef CONFIG_GRKERNSEC_HIDESYM
98489+ cookie[0] = 0;
98490+ cookie[1] = 0;
98491+#else
98492 cookie[0] = (u32)(unsigned long)sk;
98493 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
98494+#endif
98495 }
98496 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
98497
98498@@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
98499 mutex_lock(&sock_diag_table_mutex);
98500 if (sock_diag_handlers[hndl->family])
98501 err = -EBUSY;
98502- else
98503+ else {
98504+ pax_open_kernel();
98505 sock_diag_handlers[hndl->family] = hndl;
98506+ pax_close_kernel();
98507+ }
98508 mutex_unlock(&sock_diag_table_mutex);
98509
98510 return err;
98511@@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
98512
98513 mutex_lock(&sock_diag_table_mutex);
98514 BUG_ON(sock_diag_handlers[family] != hnld);
98515+ pax_open_kernel();
98516 sock_diag_handlers[family] = NULL;
98517+ pax_close_kernel();
98518 mutex_unlock(&sock_diag_table_mutex);
98519 }
98520 EXPORT_SYMBOL_GPL(sock_diag_unregister);
98521diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
98522index cf9cd13..8b56af3 100644
98523--- a/net/core/sysctl_net_core.c
98524+++ b/net/core/sysctl_net_core.c
98525@@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
98526 {
98527 unsigned int orig_size, size;
98528 int ret, i;
98529- struct ctl_table tmp = {
98530+ ctl_table_no_const tmp = {
98531 .data = &size,
98532 .maxlen = sizeof(size),
98533 .mode = table->mode
98534@@ -200,7 +200,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
98535 void __user *buffer, size_t *lenp, loff_t *ppos)
98536 {
98537 char id[IFNAMSIZ];
98538- struct ctl_table tbl = {
98539+ ctl_table_no_const tbl = {
98540 .data = id,
98541 .maxlen = IFNAMSIZ,
98542 };
98543@@ -379,13 +379,12 @@ static struct ctl_table netns_core_table[] = {
98544
98545 static __net_init int sysctl_core_net_init(struct net *net)
98546 {
98547- struct ctl_table *tbl;
98548+ ctl_table_no_const *tbl = NULL;
98549
98550 net->core.sysctl_somaxconn = SOMAXCONN;
98551
98552- tbl = netns_core_table;
98553 if (!net_eq(net, &init_net)) {
98554- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
98555+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
98556 if (tbl == NULL)
98557 goto err_dup;
98558
98559@@ -395,17 +394,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
98560 if (net->user_ns != &init_user_ns) {
98561 tbl[0].procname = NULL;
98562 }
98563- }
98564-
98565- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
98566+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
98567+ } else
98568+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
98569 if (net->core.sysctl_hdr == NULL)
98570 goto err_reg;
98571
98572 return 0;
98573
98574 err_reg:
98575- if (tbl != netns_core_table)
98576- kfree(tbl);
98577+ kfree(tbl);
98578 err_dup:
98579 return -ENOMEM;
98580 }
98581@@ -420,7 +418,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
98582 kfree(tbl);
98583 }
98584
98585-static __net_initdata struct pernet_operations sysctl_core_ops = {
98586+static __net_initconst struct pernet_operations sysctl_core_ops = {
98587 .init = sysctl_core_net_init,
98588 .exit = sysctl_core_net_exit,
98589 };
98590diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
98591index 4c04848..f575934 100644
98592--- a/net/decnet/af_decnet.c
98593+++ b/net/decnet/af_decnet.c
98594@@ -465,6 +465,7 @@ static struct proto dn_proto = {
98595 .sysctl_rmem = sysctl_decnet_rmem,
98596 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
98597 .obj_size = sizeof(struct dn_sock),
98598+ .slab_flags = SLAB_USERCOPY,
98599 };
98600
98601 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
98602diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
98603index a603823..a36ee0b 100644
98604--- a/net/decnet/dn_dev.c
98605+++ b/net/decnet/dn_dev.c
98606@@ -200,7 +200,7 @@ static struct dn_dev_sysctl_table {
98607 .extra1 = &min_t3,
98608 .extra2 = &max_t3
98609 },
98610- {0}
98611+ { }
98612 },
98613 };
98614
98615diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
98616index 5325b54..a0d4d69 100644
98617--- a/net/decnet/sysctl_net_decnet.c
98618+++ b/net/decnet/sysctl_net_decnet.c
98619@@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
98620
98621 if (len > *lenp) len = *lenp;
98622
98623- if (copy_to_user(buffer, addr, len))
98624+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
98625 return -EFAULT;
98626
98627 *lenp = len;
98628@@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
98629
98630 if (len > *lenp) len = *lenp;
98631
98632- if (copy_to_user(buffer, devname, len))
98633+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
98634 return -EFAULT;
98635
98636 *lenp = len;
98637diff --git a/net/ieee802154/dgram.c b/net/ieee802154/dgram.c
98638index 1846c1f..96d4a9f 100644
98639--- a/net/ieee802154/dgram.c
98640+++ b/net/ieee802154/dgram.c
98641@@ -313,8 +313,9 @@ static int dgram_recvmsg(struct kiocb *iocb, struct sock *sk,
98642 if (saddr) {
98643 saddr->family = AF_IEEE802154;
98644 saddr->addr = mac_cb(skb)->sa;
98645+ }
98646+ if (addr_len)
98647 *addr_len = sizeof(*saddr);
98648- }
98649
98650 if (flags & MSG_TRUNC)
98651 copied = skb->len;
98652diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
98653index 19ab78a..bf575c9 100644
98654--- a/net/ipv4/af_inet.c
98655+++ b/net/ipv4/af_inet.c
98656@@ -1703,13 +1703,9 @@ static int __init inet_init(void)
98657
98658 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
98659
98660- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
98661- if (!sysctl_local_reserved_ports)
98662- goto out;
98663-
98664 rc = proto_register(&tcp_prot, 1);
98665 if (rc)
98666- goto out_free_reserved_ports;
98667+ goto out;
98668
98669 rc = proto_register(&udp_prot, 1);
98670 if (rc)
98671@@ -1816,8 +1812,6 @@ out_unregister_udp_proto:
98672 proto_unregister(&udp_prot);
98673 out_unregister_tcp_proto:
98674 proto_unregister(&tcp_prot);
98675-out_free_reserved_ports:
98676- kfree(sysctl_local_reserved_ports);
98677 goto out;
98678 }
98679
98680diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
98681index bdbf68b..deb4759 100644
98682--- a/net/ipv4/devinet.c
98683+++ b/net/ipv4/devinet.c
98684@@ -1543,7 +1543,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
98685 idx = 0;
98686 head = &net->dev_index_head[h];
98687 rcu_read_lock();
98688- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
98689+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
98690 net->dev_base_seq;
98691 hlist_for_each_entry_rcu(dev, head, index_hlist) {
98692 if (idx < s_idx)
98693@@ -1861,7 +1861,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
98694 idx = 0;
98695 head = &net->dev_index_head[h];
98696 rcu_read_lock();
98697- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
98698+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
98699 net->dev_base_seq;
98700 hlist_for_each_entry_rcu(dev, head, index_hlist) {
98701 if (idx < s_idx)
98702@@ -2096,7 +2096,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
98703 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
98704 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
98705
98706-static struct devinet_sysctl_table {
98707+static const struct devinet_sysctl_table {
98708 struct ctl_table_header *sysctl_header;
98709 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
98710 } devinet_sysctl = {
98711@@ -2218,7 +2218,7 @@ static __net_init int devinet_init_net(struct net *net)
98712 int err;
98713 struct ipv4_devconf *all, *dflt;
98714 #ifdef CONFIG_SYSCTL
98715- struct ctl_table *tbl = ctl_forward_entry;
98716+ ctl_table_no_const *tbl = NULL;
98717 struct ctl_table_header *forw_hdr;
98718 #endif
98719
98720@@ -2236,7 +2236,7 @@ static __net_init int devinet_init_net(struct net *net)
98721 goto err_alloc_dflt;
98722
98723 #ifdef CONFIG_SYSCTL
98724- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
98725+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
98726 if (tbl == NULL)
98727 goto err_alloc_ctl;
98728
98729@@ -2256,7 +2256,10 @@ static __net_init int devinet_init_net(struct net *net)
98730 goto err_reg_dflt;
98731
98732 err = -ENOMEM;
98733- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
98734+ if (!net_eq(net, &init_net))
98735+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
98736+ else
98737+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
98738 if (forw_hdr == NULL)
98739 goto err_reg_ctl;
98740 net->ipv4.forw_hdr = forw_hdr;
98741@@ -2272,8 +2275,7 @@ err_reg_ctl:
98742 err_reg_dflt:
98743 __devinet_sysctl_unregister(all);
98744 err_reg_all:
98745- if (tbl != ctl_forward_entry)
98746- kfree(tbl);
98747+ kfree(tbl);
98748 err_alloc_ctl:
98749 #endif
98750 if (dflt != &ipv4_devconf_dflt)
98751diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
98752index c7539e2..b455e51 100644
98753--- a/net/ipv4/fib_frontend.c
98754+++ b/net/ipv4/fib_frontend.c
98755@@ -1015,12 +1015,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
98756 #ifdef CONFIG_IP_ROUTE_MULTIPATH
98757 fib_sync_up(dev);
98758 #endif
98759- atomic_inc(&net->ipv4.dev_addr_genid);
98760+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
98761 rt_cache_flush(dev_net(dev));
98762 break;
98763 case NETDEV_DOWN:
98764 fib_del_ifaddr(ifa, NULL);
98765- atomic_inc(&net->ipv4.dev_addr_genid);
98766+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
98767 if (ifa->ifa_dev->ifa_list == NULL) {
98768 /* Last address was deleted from this interface.
98769 * Disable IP.
98770@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
98771 #ifdef CONFIG_IP_ROUTE_MULTIPATH
98772 fib_sync_up(dev);
98773 #endif
98774- atomic_inc(&net->ipv4.dev_addr_genid);
98775+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
98776 rt_cache_flush(net);
98777 break;
98778 case NETDEV_DOWN:
98779diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
98780index b53f0bf..3585b33 100644
98781--- a/net/ipv4/fib_semantics.c
98782+++ b/net/ipv4/fib_semantics.c
98783@@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
98784 nh->nh_saddr = inet_select_addr(nh->nh_dev,
98785 nh->nh_gw,
98786 nh->nh_parent->fib_scope);
98787- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
98788+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
98789
98790 return nh->nh_saddr;
98791 }
98792diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
98793index 0d1e2cb..4501a2c 100644
98794--- a/net/ipv4/inet_connection_sock.c
98795+++ b/net/ipv4/inet_connection_sock.c
98796@@ -29,7 +29,7 @@ const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
98797 EXPORT_SYMBOL(inet_csk_timer_bug_msg);
98798 #endif
98799
98800-unsigned long *sysctl_local_reserved_ports;
98801+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
98802 EXPORT_SYMBOL(sysctl_local_reserved_ports);
98803
98804 void inet_get_local_port_range(struct net *net, int *low, int *high)
98805diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
98806index 8b9cf27..0d8d592 100644
98807--- a/net/ipv4/inet_hashtables.c
98808+++ b/net/ipv4/inet_hashtables.c
98809@@ -18,6 +18,7 @@
98810 #include <linux/sched.h>
98811 #include <linux/slab.h>
98812 #include <linux/wait.h>
98813+#include <linux/security.h>
98814
98815 #include <net/inet_connection_sock.h>
98816 #include <net/inet_hashtables.h>
98817@@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
98818 return inet_ehashfn(net, laddr, lport, faddr, fport);
98819 }
98820
98821+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
98822+
98823 /*
98824 * Allocate and initialize a new local port bind bucket.
98825 * The bindhash mutex for snum's hash chain must be held here.
98826@@ -554,6 +557,8 @@ ok:
98827 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
98828 spin_unlock(&head->lock);
98829
98830+ gr_update_task_in_ip_table(current, inet_sk(sk));
98831+
98832 if (tw) {
98833 inet_twsk_deschedule(tw, death_row);
98834 while (twrefcnt) {
98835diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
98836index 48f4244..f56d83a 100644
98837--- a/net/ipv4/inetpeer.c
98838+++ b/net/ipv4/inetpeer.c
98839@@ -496,8 +496,8 @@ relookup:
98840 if (p) {
98841 p->daddr = *daddr;
98842 atomic_set(&p->refcnt, 1);
98843- atomic_set(&p->rid, 0);
98844- atomic_set(&p->ip_id_count,
98845+ atomic_set_unchecked(&p->rid, 0);
98846+ atomic_set_unchecked(&p->ip_id_count,
98847 (daddr->family == AF_INET) ?
98848 secure_ip_id(daddr->addr.a4) :
98849 secure_ipv6_id(daddr->addr.a6));
98850diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
98851index c10a3ce..dd71f84 100644
98852--- a/net/ipv4/ip_fragment.c
98853+++ b/net/ipv4/ip_fragment.c
98854@@ -283,7 +283,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
98855 return 0;
98856
98857 start = qp->rid;
98858- end = atomic_inc_return(&peer->rid);
98859+ end = atomic_inc_return_unchecked(&peer->rid);
98860 qp->rid = end;
98861
98862 rc = qp->q.fragments && (end - start) > max;
98863@@ -760,12 +760,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
98864
98865 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
98866 {
98867- struct ctl_table *table;
98868+ ctl_table_no_const *table = NULL;
98869 struct ctl_table_header *hdr;
98870
98871- table = ip4_frags_ns_ctl_table;
98872 if (!net_eq(net, &init_net)) {
98873- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
98874+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
98875 if (table == NULL)
98876 goto err_alloc;
98877
98878@@ -776,9 +775,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
98879 /* Don't export sysctls to unprivileged users */
98880 if (net->user_ns != &init_user_ns)
98881 table[0].procname = NULL;
98882- }
98883+ hdr = register_net_sysctl(net, "net/ipv4", table);
98884+ } else
98885+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
98886
98887- hdr = register_net_sysctl(net, "net/ipv4", table);
98888 if (hdr == NULL)
98889 goto err_reg;
98890
98891@@ -786,8 +786,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
98892 return 0;
98893
98894 err_reg:
98895- if (!net_eq(net, &init_net))
98896- kfree(table);
98897+ kfree(table);
98898 err_alloc:
98899 return -ENOMEM;
98900 }
98901diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
98902index ec4f762..4ce3645 100644
98903--- a/net/ipv4/ip_gre.c
98904+++ b/net/ipv4/ip_gre.c
98905@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
98906 module_param(log_ecn_error, bool, 0644);
98907 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
98908
98909-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
98910+static struct rtnl_link_ops ipgre_link_ops;
98911 static int ipgre_tunnel_init(struct net_device *dev);
98912
98913 static int ipgre_net_id __read_mostly;
98914@@ -732,7 +732,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
98915 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
98916 };
98917
98918-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
98919+static struct rtnl_link_ops ipgre_link_ops = {
98920 .kind = "gre",
98921 .maxtype = IFLA_GRE_MAX,
98922 .policy = ipgre_policy,
98923@@ -746,7 +746,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
98924 .fill_info = ipgre_fill_info,
98925 };
98926
98927-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
98928+static struct rtnl_link_ops ipgre_tap_ops = {
98929 .kind = "gretap",
98930 .maxtype = IFLA_GRE_MAX,
98931 .policy = ipgre_policy,
98932diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
98933index 580dd96..9fcef7e 100644
98934--- a/net/ipv4/ip_sockglue.c
98935+++ b/net/ipv4/ip_sockglue.c
98936@@ -1171,7 +1171,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
98937 len = min_t(unsigned int, len, opt->optlen);
98938 if (put_user(len, optlen))
98939 return -EFAULT;
98940- if (copy_to_user(optval, opt->__data, len))
98941+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
98942+ copy_to_user(optval, opt->__data, len))
98943 return -EFAULT;
98944 return 0;
98945 }
98946@@ -1302,7 +1303,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
98947 if (sk->sk_type != SOCK_STREAM)
98948 return -ENOPROTOOPT;
98949
98950- msg.msg_control = optval;
98951+ msg.msg_control = (void __force_kernel *)optval;
98952 msg.msg_controllen = len;
98953 msg.msg_flags = flags;
98954
98955diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
98956index 48eafae..defff53 100644
98957--- a/net/ipv4/ip_vti.c
98958+++ b/net/ipv4/ip_vti.c
98959@@ -44,7 +44,7 @@
98960 #include <net/net_namespace.h>
98961 #include <net/netns/generic.h>
98962
98963-static struct rtnl_link_ops vti_link_ops __read_mostly;
98964+static struct rtnl_link_ops vti_link_ops;
98965
98966 static int vti_net_id __read_mostly;
98967 static int vti_tunnel_init(struct net_device *dev);
98968@@ -360,7 +360,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
98969 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
98970 };
98971
98972-static struct rtnl_link_ops vti_link_ops __read_mostly = {
98973+static struct rtnl_link_ops vti_link_ops = {
98974 .kind = "vti",
98975 .maxtype = IFLA_VTI_MAX,
98976 .policy = vti_policy,
98977diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
98978index b3e86ea..18ce98c 100644
98979--- a/net/ipv4/ipconfig.c
98980+++ b/net/ipv4/ipconfig.c
98981@@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
98982
98983 mm_segment_t oldfs = get_fs();
98984 set_fs(get_ds());
98985- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
98986+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
98987 set_fs(oldfs);
98988 return res;
98989 }
98990@@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
98991
98992 mm_segment_t oldfs = get_fs();
98993 set_fs(get_ds());
98994- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
98995+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
98996 set_fs(oldfs);
98997 return res;
98998 }
98999@@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
99000
99001 mm_segment_t oldfs = get_fs();
99002 set_fs(get_ds());
99003- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
99004+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
99005 set_fs(oldfs);
99006 return res;
99007 }
99008diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
99009index 812b183..56cbe9c 100644
99010--- a/net/ipv4/ipip.c
99011+++ b/net/ipv4/ipip.c
99012@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
99013 static int ipip_net_id __read_mostly;
99014
99015 static int ipip_tunnel_init(struct net_device *dev);
99016-static struct rtnl_link_ops ipip_link_ops __read_mostly;
99017+static struct rtnl_link_ops ipip_link_ops;
99018
99019 static int ipip_err(struct sk_buff *skb, u32 info)
99020 {
99021@@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
99022 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
99023 };
99024
99025-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
99026+static struct rtnl_link_ops ipip_link_ops = {
99027 .kind = "ipip",
99028 .maxtype = IFLA_IPTUN_MAX,
99029 .policy = ipip_policy,
99030diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
99031index 59da7cd..e318de1 100644
99032--- a/net/ipv4/netfilter/arp_tables.c
99033+++ b/net/ipv4/netfilter/arp_tables.c
99034@@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
99035 #endif
99036
99037 static int get_info(struct net *net, void __user *user,
99038- const int *len, int compat)
99039+ int len, int compat)
99040 {
99041 char name[XT_TABLE_MAXNAMELEN];
99042 struct xt_table *t;
99043 int ret;
99044
99045- if (*len != sizeof(struct arpt_getinfo)) {
99046- duprintf("length %u != %Zu\n", *len,
99047+ if (len != sizeof(struct arpt_getinfo)) {
99048+ duprintf("length %u != %Zu\n", len,
99049 sizeof(struct arpt_getinfo));
99050 return -EINVAL;
99051 }
99052@@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
99053 info.size = private->size;
99054 strcpy(info.name, name);
99055
99056- if (copy_to_user(user, &info, *len) != 0)
99057+ if (copy_to_user(user, &info, len) != 0)
99058 ret = -EFAULT;
99059 else
99060 ret = 0;
99061@@ -1688,7 +1688,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
99062
99063 switch (cmd) {
99064 case ARPT_SO_GET_INFO:
99065- ret = get_info(sock_net(sk), user, len, 1);
99066+ ret = get_info(sock_net(sk), user, *len, 1);
99067 break;
99068 case ARPT_SO_GET_ENTRIES:
99069 ret = compat_get_entries(sock_net(sk), user, len);
99070@@ -1733,7 +1733,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
99071
99072 switch (cmd) {
99073 case ARPT_SO_GET_INFO:
99074- ret = get_info(sock_net(sk), user, len, 0);
99075+ ret = get_info(sock_net(sk), user, *len, 0);
99076 break;
99077
99078 case ARPT_SO_GET_ENTRIES:
99079diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
99080index 718dfbd..cef4152 100644
99081--- a/net/ipv4/netfilter/ip_tables.c
99082+++ b/net/ipv4/netfilter/ip_tables.c
99083@@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
99084 #endif
99085
99086 static int get_info(struct net *net, void __user *user,
99087- const int *len, int compat)
99088+ int len, int compat)
99089 {
99090 char name[XT_TABLE_MAXNAMELEN];
99091 struct xt_table *t;
99092 int ret;
99093
99094- if (*len != sizeof(struct ipt_getinfo)) {
99095- duprintf("length %u != %zu\n", *len,
99096+ if (len != sizeof(struct ipt_getinfo)) {
99097+ duprintf("length %u != %zu\n", len,
99098 sizeof(struct ipt_getinfo));
99099 return -EINVAL;
99100 }
99101@@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
99102 info.size = private->size;
99103 strcpy(info.name, name);
99104
99105- if (copy_to_user(user, &info, *len) != 0)
99106+ if (copy_to_user(user, &info, len) != 0)
99107 ret = -EFAULT;
99108 else
99109 ret = 0;
99110@@ -1971,7 +1971,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99111
99112 switch (cmd) {
99113 case IPT_SO_GET_INFO:
99114- ret = get_info(sock_net(sk), user, len, 1);
99115+ ret = get_info(sock_net(sk), user, *len, 1);
99116 break;
99117 case IPT_SO_GET_ENTRIES:
99118 ret = compat_get_entries(sock_net(sk), user, len);
99119@@ -2018,7 +2018,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99120
99121 switch (cmd) {
99122 case IPT_SO_GET_INFO:
99123- ret = get_info(sock_net(sk), user, len, 0);
99124+ ret = get_info(sock_net(sk), user, *len, 0);
99125 break;
99126
99127 case IPT_SO_GET_ENTRIES:
99128diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
99129index 2510c02..cfb34fa 100644
99130--- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
99131+++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
99132@@ -720,7 +720,7 @@ static int clusterip_net_init(struct net *net)
99133 spin_lock_init(&cn->lock);
99134
99135 #ifdef CONFIG_PROC_FS
99136- cn->procdir = proc_mkdir("ipt_CLUSTERIP", net->proc_net);
99137+ cn->procdir = proc_mkdir_restrict("ipt_CLUSTERIP", net->proc_net);
99138 if (!cn->procdir) {
99139 pr_err("Unable to proc dir entry\n");
99140 return -ENOMEM;
99141diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
99142index 2d11c09..3f153f8 100644
99143--- a/net/ipv4/ping.c
99144+++ b/net/ipv4/ping.c
99145@@ -59,7 +59,7 @@ struct ping_table {
99146 };
99147
99148 static struct ping_table ping_table;
99149-struct pingv6_ops pingv6_ops;
99150+struct pingv6_ops *pingv6_ops;
99151 EXPORT_SYMBOL_GPL(pingv6_ops);
99152
99153 static u16 ping_port_rover;
99154@@ -255,23 +255,28 @@ int ping_init_sock(struct sock *sk)
99155 struct group_info *group_info = get_current_groups();
99156 int i, j, count = group_info->ngroups;
99157 kgid_t low, high;
99158+ int ret = 0;
99159
99160 inet_get_ping_group_range_net(net, &low, &high);
99161 if (gid_lte(low, group) && gid_lte(group, high))
99162- return 0;
99163+ goto out_release_group;
99164
99165 for (i = 0; i < group_info->nblocks; i++) {
99166 int cp_count = min_t(int, NGROUPS_PER_BLOCK, count);
99167 for (j = 0; j < cp_count; j++) {
99168 kgid_t gid = group_info->blocks[i][j];
99169 if (gid_lte(low, gid) && gid_lte(gid, high))
99170- return 0;
99171+ goto out_release_group;
99172 }
99173
99174 count -= cp_count;
99175 }
99176
99177- return -EACCES;
99178+ ret = -EACCES;
99179+
99180+out_release_group:
99181+ put_group_info(group_info);
99182+ return ret;
99183 }
99184 EXPORT_SYMBOL_GPL(ping_init_sock);
99185
99186@@ -341,7 +346,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
99187 return -ENODEV;
99188 }
99189 }
99190- has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
99191+ has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
99192 scoped);
99193 rcu_read_unlock();
99194
99195@@ -549,7 +554,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
99196 }
99197 #if IS_ENABLED(CONFIG_IPV6)
99198 } else if (skb->protocol == htons(ETH_P_IPV6)) {
99199- harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
99200+ harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
99201 #endif
99202 }
99203
99204@@ -567,7 +572,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
99205 info, (u8 *)icmph);
99206 #if IS_ENABLED(CONFIG_IPV6)
99207 } else if (family == AF_INET6) {
99208- pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
99209+ pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
99210 info, (u8 *)icmph);
99211 #endif
99212 }
99213@@ -837,6 +842,8 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99214 {
99215 struct inet_sock *isk = inet_sk(sk);
99216 int family = sk->sk_family;
99217+ struct sockaddr_in *sin;
99218+ struct sockaddr_in6 *sin6;
99219 struct sk_buff *skb;
99220 int copied, err;
99221
99222@@ -846,12 +853,19 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99223 if (flags & MSG_OOB)
99224 goto out;
99225
99226+ if (addr_len) {
99227+ if (family == AF_INET)
99228+ *addr_len = sizeof(*sin);
99229+ else if (family == AF_INET6 && addr_len)
99230+ *addr_len = sizeof(*sin6);
99231+ }
99232+
99233 if (flags & MSG_ERRQUEUE) {
99234 if (family == AF_INET) {
99235 return ip_recv_error(sk, msg, len, addr_len);
99236 #if IS_ENABLED(CONFIG_IPV6)
99237 } else if (family == AF_INET6) {
99238- return pingv6_ops.ipv6_recv_error(sk, msg, len,
99239+ return pingv6_ops->ipv6_recv_error(sk, msg, len,
99240 addr_len);
99241 #endif
99242 }
99243@@ -883,7 +897,6 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99244 sin->sin_port = 0 /* skb->h.uh->source */;
99245 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
99246 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
99247- *addr_len = sizeof(*sin);
99248 }
99249
99250 if (isk->cmsg_flags)
99251@@ -905,14 +918,13 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99252 sin6->sin6_scope_id =
99253 ipv6_iface_scope_id(&sin6->sin6_addr,
99254 IP6CB(skb)->iif);
99255- *addr_len = sizeof(*sin6);
99256 }
99257
99258 if (inet6_sk(sk)->rxopt.all)
99259- pingv6_ops.ip6_datagram_recv_common_ctl(sk, msg, skb);
99260+ pingv6_ops->ip6_datagram_recv_common_ctl(sk, msg, skb);
99261 if (skb->protocol == htons(ETH_P_IPV6) &&
99262 inet6_sk(sk)->rxopt.all)
99263- pingv6_ops.ip6_datagram_recv_specific_ctl(sk, msg, skb);
99264+ pingv6_ops->ip6_datagram_recv_specific_ctl(sk, msg, skb);
99265 else if (skb->protocol == htons(ETH_P_IP) && isk->cmsg_flags)
99266 ip_cmsg_recv(msg, skb);
99267 #endif
99268@@ -1104,7 +1116,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
99269 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
99270 0, sock_i_ino(sp),
99271 atomic_read(&sp->sk_refcnt), sp,
99272- atomic_read(&sp->sk_drops));
99273+ atomic_read_unchecked(&sp->sk_drops));
99274 }
99275
99276 static int ping_v4_seq_show(struct seq_file *seq, void *v)
99277diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
99278index c04518f..824ebe5 100644
99279--- a/net/ipv4/raw.c
99280+++ b/net/ipv4/raw.c
99281@@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
99282 int raw_rcv(struct sock *sk, struct sk_buff *skb)
99283 {
99284 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
99285- atomic_inc(&sk->sk_drops);
99286+ atomic_inc_unchecked(&sk->sk_drops);
99287 kfree_skb(skb);
99288 return NET_RX_DROP;
99289 }
99290@@ -696,6 +696,9 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99291 if (flags & MSG_OOB)
99292 goto out;
99293
99294+ if (addr_len)
99295+ *addr_len = sizeof(*sin);
99296+
99297 if (flags & MSG_ERRQUEUE) {
99298 err = ip_recv_error(sk, msg, len, addr_len);
99299 goto out;
99300@@ -723,7 +726,6 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99301 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
99302 sin->sin_port = 0;
99303 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
99304- *addr_len = sizeof(*sin);
99305 }
99306 if (inet->cmsg_flags)
99307 ip_cmsg_recv(msg, skb);
99308@@ -748,16 +750,20 @@ static int raw_init(struct sock *sk)
99309
99310 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
99311 {
99312+ struct icmp_filter filter;
99313+
99314 if (optlen > sizeof(struct icmp_filter))
99315 optlen = sizeof(struct icmp_filter);
99316- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
99317+ if (copy_from_user(&filter, optval, optlen))
99318 return -EFAULT;
99319+ raw_sk(sk)->filter = filter;
99320 return 0;
99321 }
99322
99323 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
99324 {
99325 int len, ret = -EFAULT;
99326+ struct icmp_filter filter;
99327
99328 if (get_user(len, optlen))
99329 goto out;
99330@@ -767,8 +773,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
99331 if (len > sizeof(struct icmp_filter))
99332 len = sizeof(struct icmp_filter);
99333 ret = -EFAULT;
99334- if (put_user(len, optlen) ||
99335- copy_to_user(optval, &raw_sk(sk)->filter, len))
99336+ filter = raw_sk(sk)->filter;
99337+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
99338 goto out;
99339 ret = 0;
99340 out: return ret;
99341@@ -997,7 +1003,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
99342 0, 0L, 0,
99343 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
99344 0, sock_i_ino(sp),
99345- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
99346+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
99347 }
99348
99349 static int raw_seq_show(struct seq_file *seq, void *v)
99350diff --git a/net/ipv4/route.c b/net/ipv4/route.c
99351index 4c011ec..8fae66b 100644
99352--- a/net/ipv4/route.c
99353+++ b/net/ipv4/route.c
99354@@ -233,7 +233,7 @@ static const struct seq_operations rt_cache_seq_ops = {
99355
99356 static int rt_cache_seq_open(struct inode *inode, struct file *file)
99357 {
99358- return seq_open(file, &rt_cache_seq_ops);
99359+ return seq_open_restrict(file, &rt_cache_seq_ops);
99360 }
99361
99362 static const struct file_operations rt_cache_seq_fops = {
99363@@ -324,7 +324,7 @@ static const struct seq_operations rt_cpu_seq_ops = {
99364
99365 static int rt_cpu_seq_open(struct inode *inode, struct file *file)
99366 {
99367- return seq_open(file, &rt_cpu_seq_ops);
99368+ return seq_open_restrict(file, &rt_cpu_seq_ops);
99369 }
99370
99371 static const struct file_operations rt_cpu_seq_fops = {
99372@@ -362,7 +362,7 @@ static int rt_acct_proc_show(struct seq_file *m, void *v)
99373
99374 static int rt_acct_proc_open(struct inode *inode, struct file *file)
99375 {
99376- return single_open(file, rt_acct_proc_show, NULL);
99377+ return single_open_restrict(file, rt_acct_proc_show, NULL);
99378 }
99379
99380 static const struct file_operations rt_acct_proc_fops = {
99381@@ -2623,34 +2623,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
99382 .maxlen = sizeof(int),
99383 .mode = 0200,
99384 .proc_handler = ipv4_sysctl_rtcache_flush,
99385+ .extra1 = &init_net,
99386 },
99387 { },
99388 };
99389
99390 static __net_init int sysctl_route_net_init(struct net *net)
99391 {
99392- struct ctl_table *tbl;
99393+ ctl_table_no_const *tbl = NULL;
99394
99395- tbl = ipv4_route_flush_table;
99396 if (!net_eq(net, &init_net)) {
99397- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
99398+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
99399 if (tbl == NULL)
99400 goto err_dup;
99401
99402 /* Don't export sysctls to unprivileged users */
99403 if (net->user_ns != &init_user_ns)
99404 tbl[0].procname = NULL;
99405- }
99406- tbl[0].extra1 = net;
99407+ tbl[0].extra1 = net;
99408+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
99409+ } else
99410+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
99411
99412- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
99413 if (net->ipv4.route_hdr == NULL)
99414 goto err_reg;
99415 return 0;
99416
99417 err_reg:
99418- if (tbl != ipv4_route_flush_table)
99419- kfree(tbl);
99420+ kfree(tbl);
99421 err_dup:
99422 return -ENOMEM;
99423 }
99424@@ -2673,8 +2673,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
99425
99426 static __net_init int rt_genid_init(struct net *net)
99427 {
99428- atomic_set(&net->ipv4.rt_genid, 0);
99429- atomic_set(&net->fnhe_genid, 0);
99430+ atomic_set_unchecked(&net->ipv4.rt_genid, 0);
99431+ atomic_set_unchecked(&net->fnhe_genid, 0);
99432 get_random_bytes(&net->ipv4.dev_addr_genid,
99433 sizeof(net->ipv4.dev_addr_genid));
99434 return 0;
99435diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
99436index 44eba05..b36864b 100644
99437--- a/net/ipv4/sysctl_net_ipv4.c
99438+++ b/net/ipv4/sysctl_net_ipv4.c
99439@@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
99440 container_of(table->data, struct net, ipv4.sysctl_local_ports.range);
99441 int ret;
99442 int range[2];
99443- struct ctl_table tmp = {
99444+ ctl_table_no_const tmp = {
99445 .data = &range,
99446 .maxlen = sizeof(range),
99447 .mode = table->mode,
99448@@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
99449 int ret;
99450 gid_t urange[2];
99451 kgid_t low, high;
99452- struct ctl_table tmp = {
99453+ ctl_table_no_const tmp = {
99454 .data = &urange,
99455 .maxlen = sizeof(urange),
99456 .mode = table->mode,
99457@@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
99458 void __user *buffer, size_t *lenp, loff_t *ppos)
99459 {
99460 char val[TCP_CA_NAME_MAX];
99461- struct ctl_table tbl = {
99462+ ctl_table_no_const tbl = {
99463 .data = val,
99464 .maxlen = TCP_CA_NAME_MAX,
99465 };
99466@@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
99467 void __user *buffer, size_t *lenp,
99468 loff_t *ppos)
99469 {
99470- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
99471+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
99472 int ret;
99473
99474 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
99475@@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
99476 void __user *buffer, size_t *lenp,
99477 loff_t *ppos)
99478 {
99479- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
99480+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
99481 int ret;
99482
99483 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
99484@@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
99485 void __user *buffer, size_t *lenp,
99486 loff_t *ppos)
99487 {
99488- struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
99489+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
99490 struct tcp_fastopen_context *ctxt;
99491 int ret;
99492 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
99493@@ -438,7 +438,7 @@ static struct ctl_table ipv4_table[] = {
99494 },
99495 {
99496 .procname = "ip_local_reserved_ports",
99497- .data = NULL, /* initialized in sysctl_ipv4_init */
99498+ .data = sysctl_local_reserved_ports,
99499 .maxlen = 65536,
99500 .mode = 0644,
99501 .proc_handler = proc_do_large_bitmap,
99502@@ -843,13 +843,12 @@ static struct ctl_table ipv4_net_table[] = {
99503
99504 static __net_init int ipv4_sysctl_init_net(struct net *net)
99505 {
99506- struct ctl_table *table;
99507+ ctl_table_no_const *table = NULL;
99508
99509- table = ipv4_net_table;
99510 if (!net_eq(net, &init_net)) {
99511 int i;
99512
99513- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
99514+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
99515 if (table == NULL)
99516 goto err_alloc;
99517
99518@@ -872,15 +871,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
99519 net->ipv4.sysctl_local_ports.range[0] = 32768;
99520 net->ipv4.sysctl_local_ports.range[1] = 61000;
99521
99522- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
99523+ if (!net_eq(net, &init_net))
99524+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
99525+ else
99526+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
99527 if (net->ipv4.ipv4_hdr == NULL)
99528 goto err_reg;
99529
99530 return 0;
99531
99532 err_reg:
99533- if (!net_eq(net, &init_net))
99534- kfree(table);
99535+ kfree(table);
99536 err_alloc:
99537 return -ENOMEM;
99538 }
99539@@ -902,16 +903,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
99540 static __init int sysctl_ipv4_init(void)
99541 {
99542 struct ctl_table_header *hdr;
99543- struct ctl_table *i;
99544-
99545- for (i = ipv4_table; i->procname; i++) {
99546- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
99547- i->data = sysctl_local_reserved_ports;
99548- break;
99549- }
99550- }
99551- if (!i->procname)
99552- return -EINVAL;
99553
99554 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
99555 if (hdr == NULL)
99556diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
99557index eeaac39..dc29942 100644
99558--- a/net/ipv4/tcp_input.c
99559+++ b/net/ipv4/tcp_input.c
99560@@ -761,7 +761,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
99561 * without any lock. We want to make sure compiler wont store
99562 * intermediate values in this location.
99563 */
99564- ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
99565+ ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
99566 sk->sk_max_pacing_rate);
99567 }
99568
99569@@ -4485,7 +4485,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
99570 * simplifies code)
99571 */
99572 static void
99573-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
99574+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
99575 struct sk_buff *head, struct sk_buff *tail,
99576 u32 start, u32 end)
99577 {
99578@@ -5562,6 +5562,7 @@ discard:
99579 tcp_paws_reject(&tp->rx_opt, 0))
99580 goto discard_and_undo;
99581
99582+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
99583 if (th->syn) {
99584 /* We see SYN without ACK. It is attempt of
99585 * simultaneous connect with crossed SYNs.
99586@@ -5612,6 +5613,7 @@ discard:
99587 goto discard;
99588 #endif
99589 }
99590+#endif
99591 /* "fifth, if neither of the SYN or RST bits is set then
99592 * drop the segment and return."
99593 */
99594@@ -5658,7 +5660,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
99595 goto discard;
99596
99597 if (th->syn) {
99598- if (th->fin)
99599+ if (th->fin || th->urg || th->psh)
99600 goto discard;
99601 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
99602 return 1;
99603diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
99604index 1e4eac7..a66fa4a 100644
99605--- a/net/ipv4/tcp_ipv4.c
99606+++ b/net/ipv4/tcp_ipv4.c
99607@@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
99608 EXPORT_SYMBOL(sysctl_tcp_low_latency);
99609
99610
99611+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99612+extern int grsec_enable_blackhole;
99613+#endif
99614+
99615 #ifdef CONFIG_TCP_MD5SIG
99616 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
99617 __be32 daddr, __be32 saddr, const struct tcphdr *th);
99618@@ -1829,6 +1833,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
99619 return 0;
99620
99621 reset:
99622+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99623+ if (!grsec_enable_blackhole)
99624+#endif
99625 tcp_v4_send_reset(rsk, skb);
99626 discard:
99627 kfree_skb(skb);
99628@@ -1974,12 +1981,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
99629 TCP_SKB_CB(skb)->sacked = 0;
99630
99631 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
99632- if (!sk)
99633+ if (!sk) {
99634+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99635+ ret = 1;
99636+#endif
99637 goto no_tcp_socket;
99638-
99639+ }
99640 process:
99641- if (sk->sk_state == TCP_TIME_WAIT)
99642+ if (sk->sk_state == TCP_TIME_WAIT) {
99643+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99644+ ret = 2;
99645+#endif
99646 goto do_time_wait;
99647+ }
99648
99649 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
99650 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
99651@@ -2033,6 +2047,10 @@ csum_error:
99652 bad_packet:
99653 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
99654 } else {
99655+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99656+ if (!grsec_enable_blackhole || (ret == 1 &&
99657+ (skb->dev->flags & IFF_LOOPBACK)))
99658+#endif
99659 tcp_v4_send_reset(NULL, skb);
99660 }
99661
99662diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
99663index 7a436c5..1b05c59 100644
99664--- a/net/ipv4/tcp_minisocks.c
99665+++ b/net/ipv4/tcp_minisocks.c
99666@@ -27,6 +27,10 @@
99667 #include <net/inet_common.h>
99668 #include <net/xfrm.h>
99669
99670+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99671+extern int grsec_enable_blackhole;
99672+#endif
99673+
99674 int sysctl_tcp_syncookies __read_mostly = 1;
99675 EXPORT_SYMBOL(sysctl_tcp_syncookies);
99676
99677@@ -709,7 +713,10 @@ embryonic_reset:
99678 * avoid becoming vulnerable to outside attack aiming at
99679 * resetting legit local connections.
99680 */
99681- req->rsk_ops->send_reset(sk, skb);
99682+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99683+ if (!grsec_enable_blackhole)
99684+#endif
99685+ req->rsk_ops->send_reset(sk, skb);
99686 } else if (fastopen) { /* received a valid RST pkt */
99687 reqsk_fastopen_remove(sk, req, true);
99688 tcp_reset(sk);
99689diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
99690index 1f2d376..01d18c4 100644
99691--- a/net/ipv4/tcp_probe.c
99692+++ b/net/ipv4/tcp_probe.c
99693@@ -238,7 +238,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
99694 if (cnt + width >= len)
99695 break;
99696
99697- if (copy_to_user(buf + cnt, tbuf, width))
99698+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
99699 return -EFAULT;
99700 cnt += width;
99701 }
99702diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
99703index 64f0354..a81b39d 100644
99704--- a/net/ipv4/tcp_timer.c
99705+++ b/net/ipv4/tcp_timer.c
99706@@ -22,6 +22,10 @@
99707 #include <linux/gfp.h>
99708 #include <net/tcp.h>
99709
99710+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99711+extern int grsec_lastack_retries;
99712+#endif
99713+
99714 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
99715 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
99716 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
99717@@ -189,6 +193,13 @@ static int tcp_write_timeout(struct sock *sk)
99718 }
99719 }
99720
99721+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99722+ if ((sk->sk_state == TCP_LAST_ACK) &&
99723+ (grsec_lastack_retries > 0) &&
99724+ (grsec_lastack_retries < retry_until))
99725+ retry_until = grsec_lastack_retries;
99726+#endif
99727+
99728 if (retransmits_timed_out(sk, retry_until,
99729 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
99730 /* Has it gone just too far? */
99731diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
99732index 77bd16f..5f7174a 100644
99733--- a/net/ipv4/udp.c
99734+++ b/net/ipv4/udp.c
99735@@ -87,6 +87,7 @@
99736 #include <linux/types.h>
99737 #include <linux/fcntl.h>
99738 #include <linux/module.h>
99739+#include <linux/security.h>
99740 #include <linux/socket.h>
99741 #include <linux/sockios.h>
99742 #include <linux/igmp.h>
99743@@ -113,6 +114,10 @@
99744 #include <net/busy_poll.h>
99745 #include "udp_impl.h"
99746
99747+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99748+extern int grsec_enable_blackhole;
99749+#endif
99750+
99751 struct udp_table udp_table __read_mostly;
99752 EXPORT_SYMBOL(udp_table);
99753
99754@@ -615,6 +620,9 @@ found:
99755 return s;
99756 }
99757
99758+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
99759+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
99760+
99761 /*
99762 * This routine is called by the ICMP module when it gets some
99763 * sort of error condition. If err < 0 then the socket should
99764@@ -914,9 +922,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99765 dport = usin->sin_port;
99766 if (dport == 0)
99767 return -EINVAL;
99768+
99769+ err = gr_search_udp_sendmsg(sk, usin);
99770+ if (err)
99771+ return err;
99772 } else {
99773 if (sk->sk_state != TCP_ESTABLISHED)
99774 return -EDESTADDRREQ;
99775+
99776+ err = gr_search_udp_sendmsg(sk, NULL);
99777+ if (err)
99778+ return err;
99779+
99780 daddr = inet->inet_daddr;
99781 dport = inet->inet_dport;
99782 /* Open fast path for connected socket.
99783@@ -1163,7 +1180,7 @@ static unsigned int first_packet_length(struct sock *sk)
99784 IS_UDPLITE(sk));
99785 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
99786 IS_UDPLITE(sk));
99787- atomic_inc(&sk->sk_drops);
99788+ atomic_inc_unchecked(&sk->sk_drops);
99789 __skb_unlink(skb, rcvq);
99790 __skb_queue_tail(&list_kill, skb);
99791 }
99792@@ -1234,6 +1251,12 @@ int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99793 int is_udplite = IS_UDPLITE(sk);
99794 bool slow;
99795
99796+ /*
99797+ * Check any passed addresses
99798+ */
99799+ if (addr_len)
99800+ *addr_len = sizeof(*sin);
99801+
99802 if (flags & MSG_ERRQUEUE)
99803 return ip_recv_error(sk, msg, len, addr_len);
99804
99805@@ -1243,6 +1266,10 @@ try_again:
99806 if (!skb)
99807 goto out;
99808
99809+ err = gr_search_udp_recvmsg(sk, skb);
99810+ if (err)
99811+ goto out_free;
99812+
99813 ulen = skb->len - sizeof(struct udphdr);
99814 copied = len;
99815 if (copied > ulen)
99816@@ -1276,7 +1303,7 @@ try_again:
99817 if (unlikely(err)) {
99818 trace_kfree_skb(skb, udp_recvmsg);
99819 if (!peeked) {
99820- atomic_inc(&sk->sk_drops);
99821+ atomic_inc_unchecked(&sk->sk_drops);
99822 UDP_INC_STATS_USER(sock_net(sk),
99823 UDP_MIB_INERRORS, is_udplite);
99824 }
99825@@ -1295,7 +1322,6 @@ try_again:
99826 sin->sin_port = udp_hdr(skb)->source;
99827 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
99828 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
99829- *addr_len = sizeof(*sin);
99830 }
99831 if (inet->cmsg_flags)
99832 ip_cmsg_recv(msg, skb);
99833@@ -1566,7 +1592,7 @@ csum_error:
99834 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
99835 drop:
99836 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
99837- atomic_inc(&sk->sk_drops);
99838+ atomic_inc_unchecked(&sk->sk_drops);
99839 kfree_skb(skb);
99840 return -1;
99841 }
99842@@ -1585,7 +1611,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
99843 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
99844
99845 if (!skb1) {
99846- atomic_inc(&sk->sk_drops);
99847+ atomic_inc_unchecked(&sk->sk_drops);
99848 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
99849 IS_UDPLITE(sk));
99850 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
99851@@ -1786,6 +1812,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
99852 goto csum_error;
99853
99854 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
99855+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99856+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
99857+#endif
99858 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
99859
99860 /*
99861@@ -2350,7 +2379,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
99862 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
99863 0, sock_i_ino(sp),
99864 atomic_read(&sp->sk_refcnt), sp,
99865- atomic_read(&sp->sk_drops));
99866+ atomic_read_unchecked(&sp->sk_drops));
99867 }
99868
99869 int udp4_seq_show(struct seq_file *seq, void *v)
99870diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
99871index e1a6393..f634ce5 100644
99872--- a/net/ipv4/xfrm4_policy.c
99873+++ b/net/ipv4/xfrm4_policy.c
99874@@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
99875 fl4->flowi4_tos = iph->tos;
99876 }
99877
99878-static inline int xfrm4_garbage_collect(struct dst_ops *ops)
99879+static int xfrm4_garbage_collect(struct dst_ops *ops)
99880 {
99881 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
99882
99883- xfrm4_policy_afinfo.garbage_collect(net);
99884+ xfrm_garbage_collect_deferred(net);
99885 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
99886 }
99887
99888@@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
99889
99890 static int __net_init xfrm4_net_init(struct net *net)
99891 {
99892- struct ctl_table *table;
99893+ ctl_table_no_const *table = NULL;
99894 struct ctl_table_header *hdr;
99895
99896- table = xfrm4_policy_table;
99897 if (!net_eq(net, &init_net)) {
99898- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
99899+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
99900 if (!table)
99901 goto err_alloc;
99902
99903 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
99904- }
99905-
99906- hdr = register_net_sysctl(net, "net/ipv4", table);
99907+ hdr = register_net_sysctl(net, "net/ipv4", table);
99908+ } else
99909+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
99910 if (!hdr)
99911 goto err_reg;
99912
99913@@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
99914 return 0;
99915
99916 err_reg:
99917- if (!net_eq(net, &init_net))
99918- kfree(table);
99919+ kfree(table);
99920 err_alloc:
99921 return -ENOMEM;
99922 }
99923diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
99924index 6c7fa08..285086c 100644
99925--- a/net/ipv6/addrconf.c
99926+++ b/net/ipv6/addrconf.c
99927@@ -598,7 +598,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
99928 idx = 0;
99929 head = &net->dev_index_head[h];
99930 rcu_read_lock();
99931- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
99932+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
99933 net->dev_base_seq;
99934 hlist_for_each_entry_rcu(dev, head, index_hlist) {
99935 if (idx < s_idx)
99936@@ -2395,7 +2395,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
99937 p.iph.ihl = 5;
99938 p.iph.protocol = IPPROTO_IPV6;
99939 p.iph.ttl = 64;
99940- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
99941+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
99942
99943 if (ops->ndo_do_ioctl) {
99944 mm_segment_t oldfs = get_fs();
99945@@ -4146,7 +4146,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
99946 s_ip_idx = ip_idx = cb->args[2];
99947
99948 rcu_read_lock();
99949- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
99950+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
99951 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
99952 idx = 0;
99953 head = &net->dev_index_head[h];
99954@@ -4758,7 +4758,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
99955 dst_free(&ifp->rt->dst);
99956 break;
99957 }
99958- atomic_inc(&net->ipv6.dev_addr_genid);
99959+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
99960 rt_genid_bump_ipv6(net);
99961 }
99962
99963@@ -4779,7 +4779,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
99964 int *valp = ctl->data;
99965 int val = *valp;
99966 loff_t pos = *ppos;
99967- struct ctl_table lctl;
99968+ ctl_table_no_const lctl;
99969 int ret;
99970
99971 /*
99972@@ -4864,7 +4864,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
99973 int *valp = ctl->data;
99974 int val = *valp;
99975 loff_t pos = *ppos;
99976- struct ctl_table lctl;
99977+ ctl_table_no_const lctl;
99978 int ret;
99979
99980 /*
99981diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
99982index d935889..2f64330 100644
99983--- a/net/ipv6/af_inet6.c
99984+++ b/net/ipv6/af_inet6.c
99985@@ -776,7 +776,7 @@ static int __net_init inet6_net_init(struct net *net)
99986 net->ipv6.sysctl.bindv6only = 0;
99987 net->ipv6.sysctl.icmpv6_time = 1*HZ;
99988 net->ipv6.sysctl.flowlabel_consistency = 1;
99989- atomic_set(&net->ipv6.rt_genid, 0);
99990+ atomic_set_unchecked(&net->ipv6.rt_genid, 0);
99991
99992 err = ipv6_init_mibs(net);
99993 if (err)
99994diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
99995index c3bf2d2..1f00573 100644
99996--- a/net/ipv6/datagram.c
99997+++ b/net/ipv6/datagram.c
99998@@ -938,5 +938,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
99999 0,
100000 sock_i_ino(sp),
100001 atomic_read(&sp->sk_refcnt), sp,
100002- atomic_read(&sp->sk_drops));
100003+ atomic_read_unchecked(&sp->sk_drops));
100004 }
100005diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
100006index 7b32652..0bc348b 100644
100007--- a/net/ipv6/icmp.c
100008+++ b/net/ipv6/icmp.c
100009@@ -1005,7 +1005,7 @@ static struct ctl_table ipv6_icmp_table_template[] = {
100010
100011 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
100012 {
100013- struct ctl_table *table;
100014+ ctl_table_no_const *table;
100015
100016 table = kmemdup(ipv6_icmp_table_template,
100017 sizeof(ipv6_icmp_table_template),
100018diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
100019index f3ffb43..1172ba7 100644
100020--- a/net/ipv6/ip6_gre.c
100021+++ b/net/ipv6/ip6_gre.c
100022@@ -71,7 +71,7 @@ struct ip6gre_net {
100023 struct net_device *fb_tunnel_dev;
100024 };
100025
100026-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
100027+static struct rtnl_link_ops ip6gre_link_ops;
100028 static int ip6gre_tunnel_init(struct net_device *dev);
100029 static void ip6gre_tunnel_setup(struct net_device *dev);
100030 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
100031@@ -1291,7 +1291,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
100032 }
100033
100034
100035-static struct inet6_protocol ip6gre_protocol __read_mostly = {
100036+static struct inet6_protocol ip6gre_protocol = {
100037 .handler = ip6gre_rcv,
100038 .err_handler = ip6gre_err,
100039 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
100040@@ -1634,7 +1634,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
100041 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
100042 };
100043
100044-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
100045+static struct rtnl_link_ops ip6gre_link_ops = {
100046 .kind = "ip6gre",
100047 .maxtype = IFLA_GRE_MAX,
100048 .policy = ip6gre_policy,
100049@@ -1647,7 +1647,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
100050 .fill_info = ip6gre_fill_info,
100051 };
100052
100053-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
100054+static struct rtnl_link_ops ip6gre_tap_ops = {
100055 .kind = "ip6gretap",
100056 .maxtype = IFLA_GRE_MAX,
100057 .policy = ip6gre_policy,
100058diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
100059index 5db8d31..4a72c26 100644
100060--- a/net/ipv6/ip6_tunnel.c
100061+++ b/net/ipv6/ip6_tunnel.c
100062@@ -85,7 +85,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
100063
100064 static int ip6_tnl_dev_init(struct net_device *dev);
100065 static void ip6_tnl_dev_setup(struct net_device *dev);
100066-static struct rtnl_link_ops ip6_link_ops __read_mostly;
100067+static struct rtnl_link_ops ip6_link_ops;
100068
100069 static int ip6_tnl_net_id __read_mostly;
100070 struct ip6_tnl_net {
100071@@ -1714,7 +1714,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
100072 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
100073 };
100074
100075-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
100076+static struct rtnl_link_ops ip6_link_ops = {
100077 .kind = "ip6tnl",
100078 .maxtype = IFLA_IPTUN_MAX,
100079 .policy = ip6_tnl_policy,
100080diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
100081index 2d19272..3a46322 100644
100082--- a/net/ipv6/ip6_vti.c
100083+++ b/net/ipv6/ip6_vti.c
100084@@ -62,7 +62,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
100085
100086 static int vti6_dev_init(struct net_device *dev);
100087 static void vti6_dev_setup(struct net_device *dev);
100088-static struct rtnl_link_ops vti6_link_ops __read_mostly;
100089+static struct rtnl_link_ops vti6_link_ops;
100090
100091 static int vti6_net_id __read_mostly;
100092 struct vti6_net {
100093@@ -901,7 +901,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
100094 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
100095 };
100096
100097-static struct rtnl_link_ops vti6_link_ops __read_mostly = {
100098+static struct rtnl_link_ops vti6_link_ops = {
100099 .kind = "vti6",
100100 .maxtype = IFLA_VTI_MAX,
100101 .policy = vti6_policy,
100102diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
100103index 0a00f44..bec42b2 100644
100104--- a/net/ipv6/ipv6_sockglue.c
100105+++ b/net/ipv6/ipv6_sockglue.c
100106@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
100107 if (sk->sk_type != SOCK_STREAM)
100108 return -ENOPROTOOPT;
100109
100110- msg.msg_control = optval;
100111+ msg.msg_control = (void __force_kernel *)optval;
100112 msg.msg_controllen = len;
100113 msg.msg_flags = flags;
100114
100115diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
100116index 710238f..0fd1816 100644
100117--- a/net/ipv6/netfilter/ip6_tables.c
100118+++ b/net/ipv6/netfilter/ip6_tables.c
100119@@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
100120 #endif
100121
100122 static int get_info(struct net *net, void __user *user,
100123- const int *len, int compat)
100124+ int len, int compat)
100125 {
100126 char name[XT_TABLE_MAXNAMELEN];
100127 struct xt_table *t;
100128 int ret;
100129
100130- if (*len != sizeof(struct ip6t_getinfo)) {
100131- duprintf("length %u != %zu\n", *len,
100132+ if (len != sizeof(struct ip6t_getinfo)) {
100133+ duprintf("length %u != %zu\n", len,
100134 sizeof(struct ip6t_getinfo));
100135 return -EINVAL;
100136 }
100137@@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
100138 info.size = private->size;
100139 strcpy(info.name, name);
100140
100141- if (copy_to_user(user, &info, *len) != 0)
100142+ if (copy_to_user(user, &info, len) != 0)
100143 ret = -EFAULT;
100144 else
100145 ret = 0;
100146@@ -1981,7 +1981,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
100147
100148 switch (cmd) {
100149 case IP6T_SO_GET_INFO:
100150- ret = get_info(sock_net(sk), user, len, 1);
100151+ ret = get_info(sock_net(sk), user, *len, 1);
100152 break;
100153 case IP6T_SO_GET_ENTRIES:
100154 ret = compat_get_entries(sock_net(sk), user, len);
100155@@ -2028,7 +2028,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
100156
100157 switch (cmd) {
100158 case IP6T_SO_GET_INFO:
100159- ret = get_info(sock_net(sk), user, len, 0);
100160+ ret = get_info(sock_net(sk), user, *len, 0);
100161 break;
100162
100163 case IP6T_SO_GET_ENTRIES:
100164diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
100165index 767ab8d..c5ec70a 100644
100166--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
100167+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
100168@@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
100169
100170 static int nf_ct_frag6_sysctl_register(struct net *net)
100171 {
100172- struct ctl_table *table;
100173+ ctl_table_no_const *table = NULL;
100174 struct ctl_table_header *hdr;
100175
100176- table = nf_ct_frag6_sysctl_table;
100177 if (!net_eq(net, &init_net)) {
100178- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
100179+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
100180 GFP_KERNEL);
100181 if (table == NULL)
100182 goto err_alloc;
100183@@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
100184 table[0].data = &net->nf_frag.frags.timeout;
100185 table[1].data = &net->nf_frag.frags.low_thresh;
100186 table[2].data = &net->nf_frag.frags.high_thresh;
100187- }
100188-
100189- hdr = register_net_sysctl(net, "net/netfilter", table);
100190+ hdr = register_net_sysctl(net, "net/netfilter", table);
100191+ } else
100192+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
100193 if (hdr == NULL)
100194 goto err_reg;
100195
100196@@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
100197 return 0;
100198
100199 err_reg:
100200- if (!net_eq(net, &init_net))
100201- kfree(table);
100202+ kfree(table);
100203 err_alloc:
100204 return -ENOMEM;
100205 }
100206diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
100207index 827f795..7e28e82 100644
100208--- a/net/ipv6/output_core.c
100209+++ b/net/ipv6/output_core.c
100210@@ -9,8 +9,8 @@
100211
100212 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
100213 {
100214- static atomic_t ipv6_fragmentation_id;
100215- int old, new;
100216+ static atomic_unchecked_t ipv6_fragmentation_id;
100217+ int id;
100218
100219 #if IS_ENABLED(CONFIG_IPV6)
100220 if (rt && !(rt->dst.flags & DST_NOPEER)) {
100221@@ -26,13 +26,10 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
100222 }
100223 }
100224 #endif
100225- do {
100226- old = atomic_read(&ipv6_fragmentation_id);
100227- new = old + 1;
100228- if (!new)
100229- new = 1;
100230- } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
100231- fhdr->identification = htonl(new);
100232+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
100233+ if (!id)
100234+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
100235+ fhdr->identification = htonl(id);
100236 }
100237 EXPORT_SYMBOL(ipv6_select_ident);
100238
100239diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
100240index bda7429..469b26b 100644
100241--- a/net/ipv6/ping.c
100242+++ b/net/ipv6/ping.c
100243@@ -246,6 +246,24 @@ static struct pernet_operations ping_v6_net_ops = {
100244 };
100245 #endif
100246
100247+static struct pingv6_ops real_pingv6_ops = {
100248+ .ipv6_recv_error = ipv6_recv_error,
100249+ .ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl,
100250+ .ip6_datagram_recv_specific_ctl = ip6_datagram_recv_specific_ctl,
100251+ .icmpv6_err_convert = icmpv6_err_convert,
100252+ .ipv6_icmp_error = ipv6_icmp_error,
100253+ .ipv6_chk_addr = ipv6_chk_addr,
100254+};
100255+
100256+static struct pingv6_ops dummy_pingv6_ops = {
100257+ .ipv6_recv_error = dummy_ipv6_recv_error,
100258+ .ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl,
100259+ .ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl,
100260+ .icmpv6_err_convert = dummy_icmpv6_err_convert,
100261+ .ipv6_icmp_error = dummy_ipv6_icmp_error,
100262+ .ipv6_chk_addr = dummy_ipv6_chk_addr,
100263+};
100264+
100265 int __init pingv6_init(void)
100266 {
100267 #ifdef CONFIG_PROC_FS
100268@@ -253,13 +271,7 @@ int __init pingv6_init(void)
100269 if (ret)
100270 return ret;
100271 #endif
100272- pingv6_ops.ipv6_recv_error = ipv6_recv_error;
100273- pingv6_ops.ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl;
100274- pingv6_ops.ip6_datagram_recv_specific_ctl =
100275- ip6_datagram_recv_specific_ctl;
100276- pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
100277- pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
100278- pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
100279+ pingv6_ops = &real_pingv6_ops;
100280 return inet6_register_protosw(&pingv6_protosw);
100281 }
100282
100283@@ -268,14 +280,9 @@ int __init pingv6_init(void)
100284 */
100285 void pingv6_exit(void)
100286 {
100287- pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
100288- pingv6_ops.ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl;
100289- pingv6_ops.ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl;
100290- pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
100291- pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
100292- pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
100293 #ifdef CONFIG_PROC_FS
100294 unregister_pernet_subsys(&ping_v6_net_ops);
100295 #endif
100296+ pingv6_ops = &dummy_pingv6_ops;
100297 inet6_unregister_protosw(&pingv6_protosw);
100298 }
100299diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
100300index 091d066..139d410 100644
100301--- a/net/ipv6/proc.c
100302+++ b/net/ipv6/proc.c
100303@@ -309,7 +309,7 @@ static int __net_init ipv6_proc_init_net(struct net *net)
100304 if (!proc_create("snmp6", S_IRUGO, net->proc_net, &snmp6_seq_fops))
100305 goto proc_snmp6_fail;
100306
100307- net->mib.proc_net_devsnmp6 = proc_mkdir("dev_snmp6", net->proc_net);
100308+ net->mib.proc_net_devsnmp6 = proc_mkdir_restrict("dev_snmp6", net->proc_net);
100309 if (!net->mib.proc_net_devsnmp6)
100310 goto proc_dev_snmp6_fail;
100311 return 0;
100312diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
100313index 1f29996..46fe0c7 100644
100314--- a/net/ipv6/raw.c
100315+++ b/net/ipv6/raw.c
100316@@ -388,7 +388,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
100317 {
100318 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
100319 skb_checksum_complete(skb)) {
100320- atomic_inc(&sk->sk_drops);
100321+ atomic_inc_unchecked(&sk->sk_drops);
100322 kfree_skb(skb);
100323 return NET_RX_DROP;
100324 }
100325@@ -416,7 +416,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
100326 struct raw6_sock *rp = raw6_sk(sk);
100327
100328 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
100329- atomic_inc(&sk->sk_drops);
100330+ atomic_inc_unchecked(&sk->sk_drops);
100331 kfree_skb(skb);
100332 return NET_RX_DROP;
100333 }
100334@@ -440,7 +440,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
100335
100336 if (inet->hdrincl) {
100337 if (skb_checksum_complete(skb)) {
100338- atomic_inc(&sk->sk_drops);
100339+ atomic_inc_unchecked(&sk->sk_drops);
100340 kfree_skb(skb);
100341 return NET_RX_DROP;
100342 }
100343@@ -469,6 +469,9 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
100344 if (flags & MSG_OOB)
100345 return -EOPNOTSUPP;
100346
100347+ if (addr_len)
100348+ *addr_len=sizeof(*sin6);
100349+
100350 if (flags & MSG_ERRQUEUE)
100351 return ipv6_recv_error(sk, msg, len, addr_len);
100352
100353@@ -507,7 +510,6 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
100354 sin6->sin6_flowinfo = 0;
100355 sin6->sin6_scope_id = ipv6_iface_scope_id(&sin6->sin6_addr,
100356 IP6CB(skb)->iif);
100357- *addr_len = sizeof(*sin6);
100358 }
100359
100360 sock_recv_ts_and_drops(msg, sk, skb);
100361@@ -610,7 +612,7 @@ out:
100362 return err;
100363 }
100364
100365-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
100366+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
100367 struct flowi6 *fl6, struct dst_entry **dstp,
100368 unsigned int flags)
100369 {
100370@@ -922,12 +924,15 @@ do_confirm:
100371 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
100372 char __user *optval, int optlen)
100373 {
100374+ struct icmp6_filter filter;
100375+
100376 switch (optname) {
100377 case ICMPV6_FILTER:
100378 if (optlen > sizeof(struct icmp6_filter))
100379 optlen = sizeof(struct icmp6_filter);
100380- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
100381+ if (copy_from_user(&filter, optval, optlen))
100382 return -EFAULT;
100383+ raw6_sk(sk)->filter = filter;
100384 return 0;
100385 default:
100386 return -ENOPROTOOPT;
100387@@ -940,6 +945,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
100388 char __user *optval, int __user *optlen)
100389 {
100390 int len;
100391+ struct icmp6_filter filter;
100392
100393 switch (optname) {
100394 case ICMPV6_FILTER:
100395@@ -951,7 +957,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
100396 len = sizeof(struct icmp6_filter);
100397 if (put_user(len, optlen))
100398 return -EFAULT;
100399- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
100400+ filter = raw6_sk(sk)->filter;
100401+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
100402 return -EFAULT;
100403 return 0;
100404 default:
100405diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
100406index cc85a9b..526a133 100644
100407--- a/net/ipv6/reassembly.c
100408+++ b/net/ipv6/reassembly.c
100409@@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
100410
100411 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
100412 {
100413- struct ctl_table *table;
100414+ ctl_table_no_const *table = NULL;
100415 struct ctl_table_header *hdr;
100416
100417- table = ip6_frags_ns_ctl_table;
100418 if (!net_eq(net, &init_net)) {
100419- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
100420+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
100421 if (table == NULL)
100422 goto err_alloc;
100423
100424@@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
100425 /* Don't export sysctls to unprivileged users */
100426 if (net->user_ns != &init_user_ns)
100427 table[0].procname = NULL;
100428- }
100429+ hdr = register_net_sysctl(net, "net/ipv6", table);
100430+ } else
100431+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
100432
100433- hdr = register_net_sysctl(net, "net/ipv6", table);
100434 if (hdr == NULL)
100435 goto err_reg;
100436
100437@@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
100438 return 0;
100439
100440 err_reg:
100441- if (!net_eq(net, &init_net))
100442- kfree(table);
100443+ kfree(table);
100444 err_alloc:
100445 return -ENOMEM;
100446 }
100447diff --git a/net/ipv6/route.c b/net/ipv6/route.c
100448index fba54a4..73e374e 100644
100449--- a/net/ipv6/route.c
100450+++ b/net/ipv6/route.c
100451@@ -2972,7 +2972,7 @@ struct ctl_table ipv6_route_table_template[] = {
100452
100453 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
100454 {
100455- struct ctl_table *table;
100456+ ctl_table_no_const *table;
100457
100458 table = kmemdup(ipv6_route_table_template,
100459 sizeof(ipv6_route_table_template),
100460diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
100461index b4d74c8..b4f3fbe 100644
100462--- a/net/ipv6/sit.c
100463+++ b/net/ipv6/sit.c
100464@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
100465 static void ipip6_dev_free(struct net_device *dev);
100466 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
100467 __be32 *v4dst);
100468-static struct rtnl_link_ops sit_link_ops __read_mostly;
100469+static struct rtnl_link_ops sit_link_ops;
100470
100471 static int sit_net_id __read_mostly;
100472 struct sit_net {
100473@@ -1683,7 +1683,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
100474 unregister_netdevice_queue(dev, head);
100475 }
100476
100477-static struct rtnl_link_ops sit_link_ops __read_mostly = {
100478+static struct rtnl_link_ops sit_link_ops = {
100479 .kind = "sit",
100480 .maxtype = IFLA_IPTUN_MAX,
100481 .policy = ipip6_policy,
100482diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
100483index 7f405a1..eabef92 100644
100484--- a/net/ipv6/sysctl_net_ipv6.c
100485+++ b/net/ipv6/sysctl_net_ipv6.c
100486@@ -54,7 +54,7 @@ static struct ctl_table ipv6_rotable[] = {
100487
100488 static int __net_init ipv6_sysctl_net_init(struct net *net)
100489 {
100490- struct ctl_table *ipv6_table;
100491+ ctl_table_no_const *ipv6_table;
100492 struct ctl_table *ipv6_route_table;
100493 struct ctl_table *ipv6_icmp_table;
100494 int err;
100495diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
100496index 889079b..a04512c 100644
100497--- a/net/ipv6/tcp_ipv6.c
100498+++ b/net/ipv6/tcp_ipv6.c
100499@@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
100500 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
100501 }
100502
100503+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100504+extern int grsec_enable_blackhole;
100505+#endif
100506+
100507 static void tcp_v6_hash(struct sock *sk)
100508 {
100509 if (sk->sk_state != TCP_CLOSE) {
100510@@ -1412,6 +1416,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
100511 return 0;
100512
100513 reset:
100514+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100515+ if (!grsec_enable_blackhole)
100516+#endif
100517 tcp_v6_send_reset(sk, skb);
100518 discard:
100519 if (opt_skb)
100520@@ -1496,12 +1503,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
100521 TCP_SKB_CB(skb)->sacked = 0;
100522
100523 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
100524- if (!sk)
100525+ if (!sk) {
100526+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100527+ ret = 1;
100528+#endif
100529 goto no_tcp_socket;
100530+ }
100531
100532 process:
100533- if (sk->sk_state == TCP_TIME_WAIT)
100534+ if (sk->sk_state == TCP_TIME_WAIT) {
100535+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100536+ ret = 2;
100537+#endif
100538 goto do_time_wait;
100539+ }
100540
100541 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
100542 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
100543@@ -1553,6 +1568,10 @@ csum_error:
100544 bad_packet:
100545 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
100546 } else {
100547+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100548+ if (!grsec_enable_blackhole || (ret == 1 &&
100549+ (skb->dev->flags & IFF_LOOPBACK)))
100550+#endif
100551 tcp_v6_send_reset(NULL, skb);
100552 }
100553
100554diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
100555index 1e586d9..384a9c9 100644
100556--- a/net/ipv6/udp.c
100557+++ b/net/ipv6/udp.c
100558@@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
100559 udp_ipv6_hash_secret + net_hash_mix(net));
100560 }
100561
100562+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100563+extern int grsec_enable_blackhole;
100564+#endif
100565+
100566 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
100567 {
100568 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
100569@@ -392,6 +396,9 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
100570 int is_udp4;
100571 bool slow;
100572
100573+ if (addr_len)
100574+ *addr_len = sizeof(struct sockaddr_in6);
100575+
100576 if (flags & MSG_ERRQUEUE)
100577 return ipv6_recv_error(sk, msg, len, addr_len);
100578
100579@@ -435,7 +442,7 @@ try_again:
100580 if (unlikely(err)) {
100581 trace_kfree_skb(skb, udpv6_recvmsg);
100582 if (!peeked) {
100583- atomic_inc(&sk->sk_drops);
100584+ atomic_inc_unchecked(&sk->sk_drops);
100585 if (is_udp4)
100586 UDP_INC_STATS_USER(sock_net(sk),
100587 UDP_MIB_INERRORS,
100588@@ -475,7 +482,7 @@ try_again:
100589 ipv6_iface_scope_id(&sin6->sin6_addr,
100590 IP6CB(skb)->iif);
100591 }
100592- *addr_len = sizeof(*sin6);
100593+
100594 }
100595
100596 if (np->rxopt.all)
100597@@ -690,7 +697,7 @@ csum_error:
100598 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
100599 drop:
100600 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
100601- atomic_inc(&sk->sk_drops);
100602+ atomic_inc_unchecked(&sk->sk_drops);
100603 kfree_skb(skb);
100604 return -1;
100605 }
100606@@ -747,7 +754,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
100607 if (likely(skb1 == NULL))
100608 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
100609 if (!skb1) {
100610- atomic_inc(&sk->sk_drops);
100611+ atomic_inc_unchecked(&sk->sk_drops);
100612 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
100613 IS_UDPLITE(sk));
100614 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
100615@@ -886,6 +893,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
100616 goto csum_error;
100617
100618 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
100619+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100620+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
100621+#endif
100622 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
100623
100624 kfree_skb(skb);
100625diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
100626index 5f8e128..865d38e 100644
100627--- a/net/ipv6/xfrm6_policy.c
100628+++ b/net/ipv6/xfrm6_policy.c
100629@@ -212,11 +212,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
100630 }
100631 }
100632
100633-static inline int xfrm6_garbage_collect(struct dst_ops *ops)
100634+static int xfrm6_garbage_collect(struct dst_ops *ops)
100635 {
100636 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
100637
100638- xfrm6_policy_afinfo.garbage_collect(net);
100639+ xfrm_garbage_collect_deferred(net);
100640 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
100641 }
100642
100643@@ -329,19 +329,19 @@ static struct ctl_table xfrm6_policy_table[] = {
100644
100645 static int __net_init xfrm6_net_init(struct net *net)
100646 {
100647- struct ctl_table *table;
100648+ ctl_table_no_const *table = NULL;
100649 struct ctl_table_header *hdr;
100650
100651- table = xfrm6_policy_table;
100652 if (!net_eq(net, &init_net)) {
100653- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
100654+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
100655 if (!table)
100656 goto err_alloc;
100657
100658 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
100659- }
100660+ hdr = register_net_sysctl(net, "net/ipv6", table);
100661+ } else
100662+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
100663
100664- hdr = register_net_sysctl(net, "net/ipv6", table);
100665 if (!hdr)
100666 goto err_reg;
100667
100668@@ -349,8 +349,7 @@ static int __net_init xfrm6_net_init(struct net *net)
100669 return 0;
100670
100671 err_reg:
100672- if (!net_eq(net, &init_net))
100673- kfree(table);
100674+ kfree(table);
100675 err_alloc:
100676 return -ENOMEM;
100677 }
100678diff --git a/net/ipx/ipx_proc.c b/net/ipx/ipx_proc.c
100679index e15c16a..7cf07aa 100644
100680--- a/net/ipx/ipx_proc.c
100681+++ b/net/ipx/ipx_proc.c
100682@@ -289,7 +289,7 @@ int __init ipx_proc_init(void)
100683 struct proc_dir_entry *p;
100684 int rc = -ENOMEM;
100685
100686- ipx_proc_dir = proc_mkdir("ipx", init_net.proc_net);
100687+ ipx_proc_dir = proc_mkdir_restrict("ipx", init_net.proc_net);
100688
100689 if (!ipx_proc_dir)
100690 goto out;
100691diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
100692index 2ba8b97..6d33010 100644
100693--- a/net/irda/ircomm/ircomm_tty.c
100694+++ b/net/irda/ircomm/ircomm_tty.c
100695@@ -317,11 +317,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
100696 add_wait_queue(&port->open_wait, &wait);
100697
100698 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
100699- __FILE__, __LINE__, tty->driver->name, port->count);
100700+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
100701
100702 spin_lock_irqsave(&port->lock, flags);
100703 if (!tty_hung_up_p(filp))
100704- port->count--;
100705+ atomic_dec(&port->count);
100706 port->blocked_open++;
100707 spin_unlock_irqrestore(&port->lock, flags);
100708
100709@@ -356,7 +356,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
100710 }
100711
100712 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
100713- __FILE__, __LINE__, tty->driver->name, port->count);
100714+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
100715
100716 schedule();
100717 }
100718@@ -366,12 +366,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
100719
100720 spin_lock_irqsave(&port->lock, flags);
100721 if (!tty_hung_up_p(filp))
100722- port->count++;
100723+ atomic_inc(&port->count);
100724 port->blocked_open--;
100725 spin_unlock_irqrestore(&port->lock, flags);
100726
100727 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
100728- __FILE__, __LINE__, tty->driver->name, port->count);
100729+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
100730
100731 if (!retval)
100732 port->flags |= ASYNC_NORMAL_ACTIVE;
100733@@ -445,12 +445,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
100734
100735 /* ++ is not atomic, so this should be protected - Jean II */
100736 spin_lock_irqsave(&self->port.lock, flags);
100737- self->port.count++;
100738+ atomic_inc(&self->port.count);
100739 spin_unlock_irqrestore(&self->port.lock, flags);
100740 tty_port_tty_set(&self->port, tty);
100741
100742 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
100743- self->line, self->port.count);
100744+ self->line, atomic_read(&self->port.count));
100745
100746 /* Not really used by us, but lets do it anyway */
100747 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
100748@@ -987,7 +987,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
100749 tty_kref_put(port->tty);
100750 }
100751 port->tty = NULL;
100752- port->count = 0;
100753+ atomic_set(&port->count, 0);
100754 spin_unlock_irqrestore(&port->lock, flags);
100755
100756 wake_up_interruptible(&port->open_wait);
100757@@ -1344,7 +1344,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
100758 seq_putc(m, '\n');
100759
100760 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
100761- seq_printf(m, "Open count: %d\n", self->port.count);
100762+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
100763 seq_printf(m, "Max data size: %d\n", self->max_data_size);
100764 seq_printf(m, "Max header size: %d\n", self->max_header_size);
100765
100766diff --git a/net/irda/irproc.c b/net/irda/irproc.c
100767index b9ac598..f88cc56 100644
100768--- a/net/irda/irproc.c
100769+++ b/net/irda/irproc.c
100770@@ -66,7 +66,7 @@ void __init irda_proc_register(void)
100771 {
100772 int i;
100773
100774- proc_irda = proc_mkdir("irda", init_net.proc_net);
100775+ proc_irda = proc_mkdir_restrict("irda", init_net.proc_net);
100776 if (proc_irda == NULL)
100777 return;
100778
100779diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
100780index c4b7218..3e83259 100644
100781--- a/net/iucv/af_iucv.c
100782+++ b/net/iucv/af_iucv.c
100783@@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
100784
100785 write_lock_bh(&iucv_sk_list.lock);
100786
100787- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
100788+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
100789 while (__iucv_get_sock_by_name(name)) {
100790 sprintf(name, "%08x",
100791- atomic_inc_return(&iucv_sk_list.autobind_name));
100792+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
100793 }
100794
100795 write_unlock_bh(&iucv_sk_list.lock);
100796diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
100797index cd5b8ec..f205e6b 100644
100798--- a/net/iucv/iucv.c
100799+++ b/net/iucv/iucv.c
100800@@ -690,7 +690,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
100801 return NOTIFY_OK;
100802 }
100803
100804-static struct notifier_block __refdata iucv_cpu_notifier = {
100805+static struct notifier_block iucv_cpu_notifier = {
100806 .notifier_call = iucv_cpu_notify,
100807 };
100808
100809diff --git a/net/key/af_key.c b/net/key/af_key.c
100810index 7932697..a13d158 100644
100811--- a/net/key/af_key.c
100812+++ b/net/key/af_key.c
100813@@ -3052,10 +3052,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
100814 static u32 get_acqseq(void)
100815 {
100816 u32 res;
100817- static atomic_t acqseq;
100818+ static atomic_unchecked_t acqseq;
100819
100820 do {
100821- res = atomic_inc_return(&acqseq);
100822+ res = atomic_inc_return_unchecked(&acqseq);
100823 } while (!res);
100824 return res;
100825 }
100826diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
100827index 0b44d85..1a7f88b 100644
100828--- a/net/l2tp/l2tp_ip.c
100829+++ b/net/l2tp/l2tp_ip.c
100830@@ -518,6 +518,9 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
100831 if (flags & MSG_OOB)
100832 goto out;
100833
100834+ if (addr_len)
100835+ *addr_len = sizeof(*sin);
100836+
100837 skb = skb_recv_datagram(sk, flags, noblock, &err);
100838 if (!skb)
100839 goto out;
100840@@ -540,7 +543,6 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
100841 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
100842 sin->sin_port = 0;
100843 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
100844- *addr_len = sizeof(*sin);
100845 }
100846 if (inet->cmsg_flags)
100847 ip_cmsg_recv(msg, skb);
100848diff --git a/net/llc/llc_proc.c b/net/llc/llc_proc.c
100849index 1a3c7e0..80f8b0c 100644
100850--- a/net/llc/llc_proc.c
100851+++ b/net/llc/llc_proc.c
100852@@ -247,7 +247,7 @@ int __init llc_proc_init(void)
100853 int rc = -ENOMEM;
100854 struct proc_dir_entry *p;
100855
100856- llc_proc_dir = proc_mkdir("llc", init_net.proc_net);
100857+ llc_proc_dir = proc_mkdir_restrict("llc", init_net.proc_net);
100858 if (!llc_proc_dir)
100859 goto out;
100860
100861diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
100862index 453e974..b3a43a5 100644
100863--- a/net/mac80211/cfg.c
100864+++ b/net/mac80211/cfg.c
100865@@ -839,7 +839,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
100866 ret = ieee80211_vif_use_channel(sdata, chandef,
100867 IEEE80211_CHANCTX_EXCLUSIVE);
100868 }
100869- } else if (local->open_count == local->monitors) {
100870+ } else if (local_read(&local->open_count) == local->monitors) {
100871 local->_oper_chandef = *chandef;
100872 ieee80211_hw_config(local, 0);
100873 }
100874@@ -3356,7 +3356,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
100875 else
100876 local->probe_req_reg--;
100877
100878- if (!local->open_count)
100879+ if (!local_read(&local->open_count))
100880 break;
100881
100882 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
100883@@ -3819,8 +3819,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
100884 if (chanctx_conf) {
100885 *chandef = chanctx_conf->def;
100886 ret = 0;
100887- } else if (local->open_count > 0 &&
100888- local->open_count == local->monitors &&
100889+ } else if (local_read(&local->open_count) > 0 &&
100890+ local_read(&local->open_count) == local->monitors &&
100891 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
100892 if (local->use_chanctx)
100893 *chandef = local->monitor_chandef;
100894diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
100895index 6bd4984..d8805c5 100644
100896--- a/net/mac80211/ieee80211_i.h
100897+++ b/net/mac80211/ieee80211_i.h
100898@@ -28,6 +28,7 @@
100899 #include <net/ieee80211_radiotap.h>
100900 #include <net/cfg80211.h>
100901 #include <net/mac80211.h>
100902+#include <asm/local.h>
100903 #include "key.h"
100904 #include "sta_info.h"
100905 #include "debug.h"
100906@@ -994,7 +995,7 @@ struct ieee80211_local {
100907 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
100908 spinlock_t queue_stop_reason_lock;
100909
100910- int open_count;
100911+ local_t open_count;
100912 int monitors, cooked_mntrs;
100913 /* number of interfaces with corresponding FIF_ flags */
100914 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
100915diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
100916index ce1c443..6cd39e1 100644
100917--- a/net/mac80211/iface.c
100918+++ b/net/mac80211/iface.c
100919@@ -529,7 +529,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
100920 break;
100921 }
100922
100923- if (local->open_count == 0) {
100924+ if (local_read(&local->open_count) == 0) {
100925 res = drv_start(local);
100926 if (res)
100927 goto err_del_bss;
100928@@ -576,7 +576,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
100929 res = drv_add_interface(local, sdata);
100930 if (res)
100931 goto err_stop;
100932- } else if (local->monitors == 0 && local->open_count == 0) {
100933+ } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
100934 res = ieee80211_add_virtual_monitor(local);
100935 if (res)
100936 goto err_stop;
100937@@ -685,7 +685,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
100938 atomic_inc(&local->iff_promiscs);
100939
100940 if (coming_up)
100941- local->open_count++;
100942+ local_inc(&local->open_count);
100943
100944 if (hw_reconf_flags)
100945 ieee80211_hw_config(local, hw_reconf_flags);
100946@@ -723,7 +723,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
100947 err_del_interface:
100948 drv_remove_interface(local, sdata);
100949 err_stop:
100950- if (!local->open_count)
100951+ if (!local_read(&local->open_count))
100952 drv_stop(local);
100953 err_del_bss:
100954 sdata->bss = NULL;
100955@@ -874,7 +874,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
100956 }
100957
100958 if (going_down)
100959- local->open_count--;
100960+ local_dec(&local->open_count);
100961
100962 switch (sdata->vif.type) {
100963 case NL80211_IFTYPE_AP_VLAN:
100964@@ -933,7 +933,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
100965 }
100966 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
100967
100968- if (local->open_count == 0)
100969+ if (local_read(&local->open_count) == 0)
100970 ieee80211_clear_tx_pending(local);
100971
100972 /*
100973@@ -973,7 +973,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
100974
100975 ieee80211_recalc_ps(local, -1);
100976
100977- if (local->open_count == 0) {
100978+ if (local_read(&local->open_count) == 0) {
100979 ieee80211_stop_device(local);
100980
100981 /* no reconfiguring after stop! */
100982@@ -984,7 +984,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
100983 ieee80211_configure_filter(local);
100984 ieee80211_hw_config(local, hw_reconf_flags);
100985
100986- if (local->monitors == local->open_count)
100987+ if (local->monitors == local_read(&local->open_count))
100988 ieee80211_add_virtual_monitor(local);
100989 }
100990
100991diff --git a/net/mac80211/main.c b/net/mac80211/main.c
100992index c7a7a86..a74f57b 100644
100993--- a/net/mac80211/main.c
100994+++ b/net/mac80211/main.c
100995@@ -174,7 +174,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
100996 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
100997 IEEE80211_CONF_CHANGE_POWER);
100998
100999- if (changed && local->open_count) {
101000+ if (changed && local_read(&local->open_count)) {
101001 ret = drv_config(local, changed);
101002 /*
101003 * Goal:
101004diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
101005index d478b88..8c8d157 100644
101006--- a/net/mac80211/pm.c
101007+++ b/net/mac80211/pm.c
101008@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101009 struct ieee80211_sub_if_data *sdata;
101010 struct sta_info *sta;
101011
101012- if (!local->open_count)
101013+ if (!local_read(&local->open_count))
101014 goto suspend;
101015
101016 ieee80211_scan_cancel(local);
101017@@ -58,7 +58,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101018 cancel_work_sync(&local->dynamic_ps_enable_work);
101019 del_timer_sync(&local->dynamic_ps_timer);
101020
101021- local->wowlan = wowlan && local->open_count;
101022+ local->wowlan = wowlan && local_read(&local->open_count);
101023 if (local->wowlan) {
101024 int err = drv_suspend(local, wowlan);
101025 if (err < 0) {
101026@@ -123,7 +123,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101027 WARN_ON(!list_empty(&local->chanctx_list));
101028
101029 /* stop hardware - this must stop RX */
101030- if (local->open_count)
101031+ if (local_read(&local->open_count))
101032 ieee80211_stop_device(local);
101033
101034 suspend:
101035diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
101036index 22b223f..ab70070 100644
101037--- a/net/mac80211/rate.c
101038+++ b/net/mac80211/rate.c
101039@@ -734,7 +734,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
101040
101041 ASSERT_RTNL();
101042
101043- if (local->open_count)
101044+ if (local_read(&local->open_count))
101045 return -EBUSY;
101046
101047 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
101048diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
101049index 6ff1346..936ca9a 100644
101050--- a/net/mac80211/rc80211_pid_debugfs.c
101051+++ b/net/mac80211/rc80211_pid_debugfs.c
101052@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
101053
101054 spin_unlock_irqrestore(&events->lock, status);
101055
101056- if (copy_to_user(buf, pb, p))
101057+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
101058 return -EFAULT;
101059
101060 return p;
101061diff --git a/net/mac80211/util.c b/net/mac80211/util.c
101062index b8700d4..89086d5 100644
101063--- a/net/mac80211/util.c
101064+++ b/net/mac80211/util.c
101065@@ -1483,7 +1483,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
101066 }
101067 #endif
101068 /* everything else happens only if HW was up & running */
101069- if (!local->open_count)
101070+ if (!local_read(&local->open_count))
101071 goto wake_up;
101072
101073 /*
101074@@ -1708,7 +1708,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
101075 local->in_reconfig = false;
101076 barrier();
101077
101078- if (local->monitors == local->open_count && local->monitors > 0)
101079+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
101080 ieee80211_add_virtual_monitor(local);
101081
101082 /*
101083diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
101084index e9410d1..77b6378 100644
101085--- a/net/netfilter/Kconfig
101086+++ b/net/netfilter/Kconfig
101087@@ -1081,6 +1081,16 @@ config NETFILTER_XT_MATCH_ESP
101088
101089 To compile it as a module, choose M here. If unsure, say N.
101090
101091+config NETFILTER_XT_MATCH_GRADM
101092+ tristate '"gradm" match support'
101093+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
101094+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
101095+ ---help---
101096+ The gradm match allows to match on grsecurity RBAC being enabled.
101097+ It is useful when iptables rules are applied early on bootup to
101098+ prevent connections to the machine (except from a trusted host)
101099+ while the RBAC system is disabled.
101100+
101101 config NETFILTER_XT_MATCH_HASHLIMIT
101102 tristate '"hashlimit" match support'
101103 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
101104diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
101105index bffdad7..f9317d1 100644
101106--- a/net/netfilter/Makefile
101107+++ b/net/netfilter/Makefile
101108@@ -133,6 +133,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
101109 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
101110 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
101111 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
101112+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
101113 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
101114 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
101115 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
101116diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
101117index de770ec..3fc49d2 100644
101118--- a/net/netfilter/ipset/ip_set_core.c
101119+++ b/net/netfilter/ipset/ip_set_core.c
101120@@ -1922,7 +1922,7 @@ done:
101121 return ret;
101122 }
101123
101124-static struct nf_sockopt_ops so_set __read_mostly = {
101125+static struct nf_sockopt_ops so_set = {
101126 .pf = PF_INET,
101127 .get_optmin = SO_IP_SET,
101128 .get_optmax = SO_IP_SET + 1,
101129diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
101130index a8eb0a8..86f2de4 100644
101131--- a/net/netfilter/ipvs/ip_vs_conn.c
101132+++ b/net/netfilter/ipvs/ip_vs_conn.c
101133@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
101134 /* Increase the refcnt counter of the dest */
101135 ip_vs_dest_hold(dest);
101136
101137- conn_flags = atomic_read(&dest->conn_flags);
101138+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
101139 if (cp->protocol != IPPROTO_UDP)
101140 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
101141 flags = cp->flags;
101142@@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
101143
101144 cp->control = NULL;
101145 atomic_set(&cp->n_control, 0);
101146- atomic_set(&cp->in_pkts, 0);
101147+ atomic_set_unchecked(&cp->in_pkts, 0);
101148
101149 cp->packet_xmit = NULL;
101150 cp->app = NULL;
101151@@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
101152
101153 /* Don't drop the entry if its number of incoming packets is not
101154 located in [0, 8] */
101155- i = atomic_read(&cp->in_pkts);
101156+ i = atomic_read_unchecked(&cp->in_pkts);
101157 if (i > 8 || i < 0) return 0;
101158
101159 if (!todrop_rate[i]) return 0;
101160diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
101161index 4f26ee4..6a9d7c3 100644
101162--- a/net/netfilter/ipvs/ip_vs_core.c
101163+++ b/net/netfilter/ipvs/ip_vs_core.c
101164@@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
101165 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
101166 /* do not touch skb anymore */
101167
101168- atomic_inc(&cp->in_pkts);
101169+ atomic_inc_unchecked(&cp->in_pkts);
101170 ip_vs_conn_put(cp);
101171 return ret;
101172 }
101173@@ -1706,7 +1706,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
101174 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
101175 pkts = sysctl_sync_threshold(ipvs);
101176 else
101177- pkts = atomic_add_return(1, &cp->in_pkts);
101178+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
101179
101180 if (ipvs->sync_state & IP_VS_STATE_MASTER)
101181 ip_vs_sync_conn(net, cp, pkts);
101182diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
101183index 35be035..50f8834 100644
101184--- a/net/netfilter/ipvs/ip_vs_ctl.c
101185+++ b/net/netfilter/ipvs/ip_vs_ctl.c
101186@@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
101187 */
101188 ip_vs_rs_hash(ipvs, dest);
101189 }
101190- atomic_set(&dest->conn_flags, conn_flags);
101191+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
101192
101193 /* bind the service */
101194 old_svc = rcu_dereference_protected(dest->svc, 1);
101195@@ -1654,7 +1654,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
101196 * align with netns init in ip_vs_control_net_init()
101197 */
101198
101199-static struct ctl_table vs_vars[] = {
101200+static ctl_table_no_const vs_vars[] __read_only = {
101201 {
101202 .procname = "amemthresh",
101203 .maxlen = sizeof(int),
101204@@ -2075,7 +2075,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
101205 " %-7s %-6d %-10d %-10d\n",
101206 &dest->addr.in6,
101207 ntohs(dest->port),
101208- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
101209+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
101210 atomic_read(&dest->weight),
101211 atomic_read(&dest->activeconns),
101212 atomic_read(&dest->inactconns));
101213@@ -2086,7 +2086,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
101214 "%-7s %-6d %-10d %-10d\n",
101215 ntohl(dest->addr.ip),
101216 ntohs(dest->port),
101217- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
101218+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
101219 atomic_read(&dest->weight),
101220 atomic_read(&dest->activeconns),
101221 atomic_read(&dest->inactconns));
101222@@ -2564,7 +2564,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
101223
101224 entry.addr = dest->addr.ip;
101225 entry.port = dest->port;
101226- entry.conn_flags = atomic_read(&dest->conn_flags);
101227+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
101228 entry.weight = atomic_read(&dest->weight);
101229 entry.u_threshold = dest->u_threshold;
101230 entry.l_threshold = dest->l_threshold;
101231@@ -3107,7 +3107,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
101232 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
101233 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
101234 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
101235- (atomic_read(&dest->conn_flags) &
101236+ (atomic_read_unchecked(&dest->conn_flags) &
101237 IP_VS_CONN_F_FWD_MASK)) ||
101238 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
101239 atomic_read(&dest->weight)) ||
101240@@ -3580,7 +3580,7 @@ out:
101241 }
101242
101243
101244-static const struct genl_ops ip_vs_genl_ops[] __read_mostly = {
101245+static const struct genl_ops ip_vs_genl_ops[] = {
101246 {
101247 .cmd = IPVS_CMD_NEW_SERVICE,
101248 .flags = GENL_ADMIN_PERM,
101249@@ -3697,7 +3697,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
101250 {
101251 int idx;
101252 struct netns_ipvs *ipvs = net_ipvs(net);
101253- struct ctl_table *tbl;
101254+ ctl_table_no_const *tbl;
101255
101256 atomic_set(&ipvs->dropentry, 0);
101257 spin_lock_init(&ipvs->dropentry_lock);
101258diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
101259index ca056a3..9cf01ef 100644
101260--- a/net/netfilter/ipvs/ip_vs_lblc.c
101261+++ b/net/netfilter/ipvs/ip_vs_lblc.c
101262@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
101263 * IPVS LBLC sysctl table
101264 */
101265 #ifdef CONFIG_SYSCTL
101266-static struct ctl_table vs_vars_table[] = {
101267+static ctl_table_no_const vs_vars_table[] __read_only = {
101268 {
101269 .procname = "lblc_expiration",
101270 .data = NULL,
101271diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
101272index 3f21a2f..a112e85 100644
101273--- a/net/netfilter/ipvs/ip_vs_lblcr.c
101274+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
101275@@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
101276 * IPVS LBLCR sysctl table
101277 */
101278
101279-static struct ctl_table vs_vars_table[] = {
101280+static ctl_table_no_const vs_vars_table[] __read_only = {
101281 {
101282 .procname = "lblcr_expiration",
101283 .data = NULL,
101284diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
101285index db80126..ef7110e 100644
101286--- a/net/netfilter/ipvs/ip_vs_sync.c
101287+++ b/net/netfilter/ipvs/ip_vs_sync.c
101288@@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
101289 cp = cp->control;
101290 if (cp) {
101291 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
101292- pkts = atomic_add_return(1, &cp->in_pkts);
101293+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
101294 else
101295 pkts = sysctl_sync_threshold(ipvs);
101296 ip_vs_sync_conn(net, cp->control, pkts);
101297@@ -771,7 +771,7 @@ control:
101298 if (!cp)
101299 return;
101300 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
101301- pkts = atomic_add_return(1, &cp->in_pkts);
101302+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
101303 else
101304 pkts = sysctl_sync_threshold(ipvs);
101305 goto sloop;
101306@@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
101307
101308 if (opt)
101309 memcpy(&cp->in_seq, opt, sizeof(*opt));
101310- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
101311+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
101312 cp->state = state;
101313 cp->old_state = cp->state;
101314 /*
101315diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
101316index c47444e..b0961c6 100644
101317--- a/net/netfilter/ipvs/ip_vs_xmit.c
101318+++ b/net/netfilter/ipvs/ip_vs_xmit.c
101319@@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
101320 else
101321 rc = NF_ACCEPT;
101322 /* do not touch skb anymore */
101323- atomic_inc(&cp->in_pkts);
101324+ atomic_inc_unchecked(&cp->in_pkts);
101325 goto out;
101326 }
101327
101328@@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
101329 else
101330 rc = NF_ACCEPT;
101331 /* do not touch skb anymore */
101332- atomic_inc(&cp->in_pkts);
101333+ atomic_inc_unchecked(&cp->in_pkts);
101334 goto out;
101335 }
101336
101337diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
101338index a4b5e2a..13b1de3 100644
101339--- a/net/netfilter/nf_conntrack_acct.c
101340+++ b/net/netfilter/nf_conntrack_acct.c
101341@@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
101342 #ifdef CONFIG_SYSCTL
101343 static int nf_conntrack_acct_init_sysctl(struct net *net)
101344 {
101345- struct ctl_table *table;
101346+ ctl_table_no_const *table;
101347
101348 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
101349 GFP_KERNEL);
101350diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
101351index 356bef5..99932cb 100644
101352--- a/net/netfilter/nf_conntrack_core.c
101353+++ b/net/netfilter/nf_conntrack_core.c
101354@@ -1627,6 +1627,10 @@ void nf_conntrack_init_end(void)
101355 #define DYING_NULLS_VAL ((1<<30)+1)
101356 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
101357
101358+#ifdef CONFIG_GRKERNSEC_HIDESYM
101359+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
101360+#endif
101361+
101362 int nf_conntrack_init_net(struct net *net)
101363 {
101364 int ret;
101365@@ -1641,7 +1645,11 @@ int nf_conntrack_init_net(struct net *net)
101366 goto err_stat;
101367 }
101368
101369+#ifdef CONFIG_GRKERNSEC_HIDESYM
101370+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
101371+#else
101372 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
101373+#endif
101374 if (!net->ct.slabname) {
101375 ret = -ENOMEM;
101376 goto err_slabname;
101377diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
101378index 1df1761..ce8b88a 100644
101379--- a/net/netfilter/nf_conntrack_ecache.c
101380+++ b/net/netfilter/nf_conntrack_ecache.c
101381@@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
101382 #ifdef CONFIG_SYSCTL
101383 static int nf_conntrack_event_init_sysctl(struct net *net)
101384 {
101385- struct ctl_table *table;
101386+ ctl_table_no_const *table;
101387
101388 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
101389 GFP_KERNEL);
101390diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
101391index 974a2a4..52cc6ff 100644
101392--- a/net/netfilter/nf_conntrack_helper.c
101393+++ b/net/netfilter/nf_conntrack_helper.c
101394@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
101395
101396 static int nf_conntrack_helper_init_sysctl(struct net *net)
101397 {
101398- struct ctl_table *table;
101399+ ctl_table_no_const *table;
101400
101401 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
101402 GFP_KERNEL);
101403diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
101404index b65d586..beec902 100644
101405--- a/net/netfilter/nf_conntrack_proto.c
101406+++ b/net/netfilter/nf_conntrack_proto.c
101407@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
101408
101409 static void
101410 nf_ct_unregister_sysctl(struct ctl_table_header **header,
101411- struct ctl_table **table,
101412+ ctl_table_no_const **table,
101413 unsigned int users)
101414 {
101415 if (users > 0)
101416diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
101417index f641751..d3c5b51 100644
101418--- a/net/netfilter/nf_conntrack_standalone.c
101419+++ b/net/netfilter/nf_conntrack_standalone.c
101420@@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
101421
101422 static int nf_conntrack_standalone_init_sysctl(struct net *net)
101423 {
101424- struct ctl_table *table;
101425+ ctl_table_no_const *table;
101426
101427 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
101428 GFP_KERNEL);
101429diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
101430index 7a394df..bd91a8a 100644
101431--- a/net/netfilter/nf_conntrack_timestamp.c
101432+++ b/net/netfilter/nf_conntrack_timestamp.c
101433@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
101434 #ifdef CONFIG_SYSCTL
101435 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
101436 {
101437- struct ctl_table *table;
101438+ ctl_table_no_const *table;
101439
101440 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
101441 GFP_KERNEL);
101442diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
101443index 85296d4..8becdec 100644
101444--- a/net/netfilter/nf_log.c
101445+++ b/net/netfilter/nf_log.c
101446@@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
101447
101448 #ifdef CONFIG_SYSCTL
101449 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
101450-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
101451+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
101452
101453 static int nf_log_proc_dostring(struct ctl_table *table, int write,
101454 void __user *buffer, size_t *lenp, loff_t *ppos)
101455@@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
101456 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
101457 mutex_unlock(&nf_log_mutex);
101458 } else {
101459+ ctl_table_no_const nf_log_table = *table;
101460+
101461 mutex_lock(&nf_log_mutex);
101462 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
101463 lockdep_is_held(&nf_log_mutex));
101464 if (!logger)
101465- table->data = "NONE";
101466+ nf_log_table.data = "NONE";
101467 else
101468- table->data = logger->name;
101469- r = proc_dostring(table, write, buffer, lenp, ppos);
101470+ nf_log_table.data = logger->name;
101471+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
101472 mutex_unlock(&nf_log_mutex);
101473 }
101474
101475diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
101476index f042ae5..30ea486 100644
101477--- a/net/netfilter/nf_sockopt.c
101478+++ b/net/netfilter/nf_sockopt.c
101479@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
101480 }
101481 }
101482
101483- list_add(&reg->list, &nf_sockopts);
101484+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
101485 out:
101486 mutex_unlock(&nf_sockopt_mutex);
101487 return ret;
101488@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
101489 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
101490 {
101491 mutex_lock(&nf_sockopt_mutex);
101492- list_del(&reg->list);
101493+ pax_list_del((struct list_head *)&reg->list);
101494 mutex_unlock(&nf_sockopt_mutex);
101495 }
101496 EXPORT_SYMBOL(nf_unregister_sockopt);
101497diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
101498index adce01e..8d52d50 100644
101499--- a/net/netfilter/nf_tables_api.c
101500+++ b/net/netfilter/nf_tables_api.c
101501@@ -152,8 +152,8 @@ nf_tables_chain_type_lookup(const struct nft_af_info *afi,
101502 #ifdef CONFIG_MODULES
101503 if (autoload) {
101504 nfnl_unlock(NFNL_SUBSYS_NFTABLES);
101505- request_module("nft-chain-%u-%*.s", afi->family,
101506- nla_len(nla)-1, (const char *)nla_data(nla));
101507+ request_module("nft-chain-%u-%.*s", afi->family,
101508+ nla_len(nla), (const char *)nla_data(nla));
101509 nfnl_lock(NFNL_SUBSYS_NFTABLES);
101510 type = __nf_tables_chain_type_lookup(afi->family, nla);
101511 if (type != NULL)
101512@@ -1934,7 +1934,8 @@ static const struct nft_set_ops *nft_select_set_ops(const struct nlattr * const
101513
101514 static const struct nla_policy nft_set_policy[NFTA_SET_MAX + 1] = {
101515 [NFTA_SET_TABLE] = { .type = NLA_STRING },
101516- [NFTA_SET_NAME] = { .type = NLA_STRING },
101517+ [NFTA_SET_NAME] = { .type = NLA_STRING,
101518+ .len = IFNAMSIZ - 1 },
101519 [NFTA_SET_FLAGS] = { .type = NLA_U32 },
101520 [NFTA_SET_KEY_TYPE] = { .type = NLA_U32 },
101521 [NFTA_SET_KEY_LEN] = { .type = NLA_U32 },
101522diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
101523index a155d19..726b0f2 100644
101524--- a/net/netfilter/nfnetlink_log.c
101525+++ b/net/netfilter/nfnetlink_log.c
101526@@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
101527 struct nfnl_log_net {
101528 spinlock_t instances_lock;
101529 struct hlist_head instance_table[INSTANCE_BUCKETS];
101530- atomic_t global_seq;
101531+ atomic_unchecked_t global_seq;
101532 };
101533
101534 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
101535@@ -564,7 +564,7 @@ __build_packet_message(struct nfnl_log_net *log,
101536 /* global sequence number */
101537 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
101538 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
101539- htonl(atomic_inc_return(&log->global_seq))))
101540+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
101541 goto nla_put_failure;
101542
101543 if (data_len) {
101544diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
101545index 82cb823..5685dd5 100644
101546--- a/net/netfilter/nft_compat.c
101547+++ b/net/netfilter/nft_compat.c
101548@@ -216,7 +216,7 @@ target_dump_info(struct sk_buff *skb, const struct xt_target *t, const void *in)
101549 /* We want to reuse existing compat_to_user */
101550 old_fs = get_fs();
101551 set_fs(KERNEL_DS);
101552- t->compat_to_user(out, in);
101553+ t->compat_to_user((void __force_user *)out, in);
101554 set_fs(old_fs);
101555 ret = nla_put(skb, NFTA_TARGET_INFO, XT_ALIGN(t->targetsize), out);
101556 kfree(out);
101557@@ -403,7 +403,7 @@ match_dump_info(struct sk_buff *skb, const struct xt_match *m, const void *in)
101558 /* We want to reuse existing compat_to_user */
101559 old_fs = get_fs();
101560 set_fs(KERNEL_DS);
101561- m->compat_to_user(out, in);
101562+ m->compat_to_user((void __force_user *)out, in);
101563 set_fs(old_fs);
101564 ret = nla_put(skb, NFTA_MATCH_INFO, XT_ALIGN(m->matchsize), out);
101565 kfree(out);
101566diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
101567new file mode 100644
101568index 0000000..c566332
101569--- /dev/null
101570+++ b/net/netfilter/xt_gradm.c
101571@@ -0,0 +1,51 @@
101572+/*
101573+ * gradm match for netfilter
101574