]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-3.0-3.14.3-201405121814.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.14.3-201405121814.patch
CommitLineData
c6ed4e14
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 eed07f3..043f744 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 90c06ec..3517221 100644
8178--- a/arch/powerpc/include/asm/reg.h
8179+++ b/arch/powerpc/include/asm/reg.h
8180@@ -248,6 +248,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 af064d2..ce56147 100644
8522--- a/arch/powerpc/kernel/process.c
8523+++ b/arch/powerpc/kernel/process.c
8524@@ -1009,8 +1009,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@@ -1532,10 +1532,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@@ -1555,7 +1555,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@@ -1591,58 +1591,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 a67e00a..f71d8c7 100644
8657--- a/arch/powerpc/kernel/signal_32.c
8658+++ b/arch/powerpc/kernel/signal_32.c
8659@@ -1011,7 +1011,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 8d253c2..405b337 100644
8670--- a/arch/powerpc/kernel/signal_64.c
8671+++ b/arch/powerpc/kernel/signal_64.c
8672@@ -758,7 +758,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 f8842c4..e893775 100644
12671--- a/arch/x86/Makefile
12672+++ b/arch/x86/Makefile
12673@@ -71,14 +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 := $(call cc-option,-m64)
12686 KBUILD_AFLAGS += -m64
12687 KBUILD_CFLAGS += -m64
12688
12689@@ -111,6 +109,9 @@ else
12690 KBUILD_CFLAGS += -maccumulate-outgoing-args
12691 endif
12692
12693+# temporary until string.h is fixed
12694+KBUILD_CFLAGS += -ffreestanding
12695+
12696 # Make sure compiler does not have buggy stack-protector support.
12697 ifdef CONFIG_CC_STACKPROTECTOR
12698 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
12699@@ -268,3 +269,12 @@ define archhelp
12700 echo ' FDINITRD=file initrd for the booted kernel'
12701 echo ' kvmconfig - Enable additional options for guest kernel support'
12702 endef
12703+
12704+define OLD_LD
12705+
12706+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
12707+*** Please upgrade your binutils to 2.18 or newer
12708+endef
12709+
12710+archprepare:
12711+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
12712diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
12713index 878df7e..a803913 100644
12714--- a/arch/x86/boot/Makefile
12715+++ b/arch/x86/boot/Makefile
12716@@ -52,6 +52,9 @@ $(obj)/cpustr.h: $(obj)/mkcpustr FORCE
12717 # ---------------------------------------------------------------------------
12718
12719 KBUILD_CFLAGS := $(USERINCLUDE) $(REALMODE_CFLAGS) -D_SETUP
12720+ifdef CONSTIFY_PLUGIN
12721+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12722+endif
12723 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12724 GCOV_PROFILE := n
12725
12726diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
12727index 878e4b9..20537ab 100644
12728--- a/arch/x86/boot/bitops.h
12729+++ b/arch/x86/boot/bitops.h
12730@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12731 u8 v;
12732 const u32 *p = (const u32 *)addr;
12733
12734- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12735+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12736 return v;
12737 }
12738
12739@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12740
12741 static inline void set_bit(int nr, void *addr)
12742 {
12743- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12744+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12745 }
12746
12747 #endif /* BOOT_BITOPS_H */
12748diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
12749index 50f8c5e..4f84fff 100644
12750--- a/arch/x86/boot/boot.h
12751+++ b/arch/x86/boot/boot.h
12752@@ -84,7 +84,7 @@ static inline void io_delay(void)
12753 static inline u16 ds(void)
12754 {
12755 u16 seg;
12756- asm("movw %%ds,%0" : "=rm" (seg));
12757+ asm volatile("movw %%ds,%0" : "=rm" (seg));
12758 return seg;
12759 }
12760
12761@@ -180,7 +180,7 @@ static inline void wrgs32(u32 v, addr_t addr)
12762 static inline int memcmp(const void *s1, const void *s2, size_t len)
12763 {
12764 u8 diff;
12765- asm("repe; cmpsb; setnz %0"
12766+ asm volatile("repe; cmpsb; setnz %0"
12767 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
12768 return diff;
12769 }
12770diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
12771index 0fcd913..3bb5c42 100644
12772--- a/arch/x86/boot/compressed/Makefile
12773+++ b/arch/x86/boot/compressed/Makefile
12774@@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
12775 KBUILD_CFLAGS += -mno-mmx -mno-sse
12776 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
12777 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
12778+ifdef CONSTIFY_PLUGIN
12779+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12780+endif
12781
12782 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12783 GCOV_PROFILE := n
12784diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
12785index a53440e..c3dbf1e 100644
12786--- a/arch/x86/boot/compressed/efi_stub_32.S
12787+++ b/arch/x86/boot/compressed/efi_stub_32.S
12788@@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
12789 * parameter 2, ..., param n. To make things easy, we save the return
12790 * address of efi_call_phys in a global variable.
12791 */
12792- popl %ecx
12793- movl %ecx, saved_return_addr(%edx)
12794- /* get the function pointer into ECX*/
12795- popl %ecx
12796- movl %ecx, efi_rt_function_ptr(%edx)
12797+ popl saved_return_addr(%edx)
12798+ popl efi_rt_function_ptr(%edx)
12799
12800 /*
12801 * 3. Call the physical function.
12802 */
12803- call *%ecx
12804+ call *efi_rt_function_ptr(%edx)
12805
12806 /*
12807 * 4. Balance the stack. And because EAX contain the return value,
12808@@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
12809 1: popl %edx
12810 subl $1b, %edx
12811
12812- movl efi_rt_function_ptr(%edx), %ecx
12813- pushl %ecx
12814+ pushl efi_rt_function_ptr(%edx)
12815
12816 /*
12817 * 10. Push the saved return address onto the stack and return.
12818 */
12819- movl saved_return_addr(%edx), %ecx
12820- pushl %ecx
12821- ret
12822+ jmpl *saved_return_addr(%edx)
12823 ENDPROC(efi_call_phys)
12824 .previous
12825
12826diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
12827index f45ab7a..ebc015f 100644
12828--- a/arch/x86/boot/compressed/head_32.S
12829+++ b/arch/x86/boot/compressed/head_32.S
12830@@ -119,10 +119,10 @@ preferred_addr:
12831 addl %eax, %ebx
12832 notl %eax
12833 andl %eax, %ebx
12834- cmpl $LOAD_PHYSICAL_ADDR, %ebx
12835+ cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12836 jge 1f
12837 #endif
12838- movl $LOAD_PHYSICAL_ADDR, %ebx
12839+ movl $____LOAD_PHYSICAL_ADDR, %ebx
12840 1:
12841
12842 /* Target address to relocate to for decompression */
12843diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
12844index b10fa66..5ee0472 100644
12845--- a/arch/x86/boot/compressed/head_64.S
12846+++ b/arch/x86/boot/compressed/head_64.S
12847@@ -94,10 +94,10 @@ ENTRY(startup_32)
12848 addl %eax, %ebx
12849 notl %eax
12850 andl %eax, %ebx
12851- cmpl $LOAD_PHYSICAL_ADDR, %ebx
12852+ cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12853 jge 1f
12854 #endif
12855- movl $LOAD_PHYSICAL_ADDR, %ebx
12856+ movl $____LOAD_PHYSICAL_ADDR, %ebx
12857 1:
12858
12859 /* Target address to relocate to for decompression */
12860@@ -268,10 +268,10 @@ preferred_addr:
12861 addq %rax, %rbp
12862 notq %rax
12863 andq %rax, %rbp
12864- cmpq $LOAD_PHYSICAL_ADDR, %rbp
12865+ cmpq $____LOAD_PHYSICAL_ADDR, %rbp
12866 jge 1f
12867 #endif
12868- movq $LOAD_PHYSICAL_ADDR, %rbp
12869+ movq $____LOAD_PHYSICAL_ADDR, %rbp
12870 1:
12871
12872 /* Target address to relocate to for decompression */
12873@@ -363,8 +363,8 @@ gdt:
12874 .long gdt
12875 .word 0
12876 .quad 0x0000000000000000 /* NULL descriptor */
12877- .quad 0x00af9a000000ffff /* __KERNEL_CS */
12878- .quad 0x00cf92000000ffff /* __KERNEL_DS */
12879+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
12880+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
12881 .quad 0x0080890000000000 /* TS descriptor */
12882 .quad 0x0000000000000000 /* TS continued */
12883 gdt_end:
12884diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
12885index 196eaf3..c96716d 100644
12886--- a/arch/x86/boot/compressed/misc.c
12887+++ b/arch/x86/boot/compressed/misc.c
12888@@ -218,7 +218,7 @@ void __putstr(const char *s)
12889
12890 void *memset(void *s, int c, size_t n)
12891 {
12892- int i;
12893+ size_t i;
12894 char *ss = s;
12895
12896 for (i = 0; i < n; i++)
12897@@ -277,7 +277,7 @@ static void handle_relocations(void *output, unsigned long output_len)
12898 * Calculate the delta between where vmlinux was linked to load
12899 * and where it was actually loaded.
12900 */
12901- delta = min_addr - LOAD_PHYSICAL_ADDR;
12902+ delta = min_addr - ____LOAD_PHYSICAL_ADDR;
12903 if (!delta) {
12904 debug_putstr("No relocation needed... ");
12905 return;
12906@@ -347,7 +347,7 @@ static void parse_elf(void *output)
12907 Elf32_Ehdr ehdr;
12908 Elf32_Phdr *phdrs, *phdr;
12909 #endif
12910- void *dest;
12911+ void *dest, *prev;
12912 int i;
12913
12914 memcpy(&ehdr, output, sizeof(ehdr));
12915@@ -374,13 +374,16 @@ static void parse_elf(void *output)
12916 case PT_LOAD:
12917 #ifdef CONFIG_RELOCATABLE
12918 dest = output;
12919- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
12920+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
12921 #else
12922 dest = (void *)(phdr->p_paddr);
12923 #endif
12924 memcpy(dest,
12925 output + phdr->p_offset,
12926 phdr->p_filesz);
12927+ if (i)
12928+ memset(prev, 0xff, dest - prev);
12929+ prev = dest + phdr->p_filesz;
12930 break;
12931 default: /* Ignore other PT_* */ break;
12932 }
12933@@ -430,7 +433,7 @@ asmlinkage void *decompress_kernel(void *rmode, memptr heap,
12934 error("Destination address too large");
12935 #endif
12936 #ifndef CONFIG_RELOCATABLE
12937- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
12938+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
12939 error("Wrong destination address");
12940 #endif
12941
12942diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
12943index 100a9a1..bb3bdb0 100644
12944--- a/arch/x86/boot/cpucheck.c
12945+++ b/arch/x86/boot/cpucheck.c
12946@@ -117,9 +117,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12947 u32 ecx = MSR_K7_HWCR;
12948 u32 eax, edx;
12949
12950- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12951+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12952 eax &= ~(1 << 15);
12953- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12954+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12955
12956 get_cpuflags(); /* Make sure it really did something */
12957 err = check_cpuflags();
12958@@ -132,9 +132,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12959 u32 ecx = MSR_VIA_FCR;
12960 u32 eax, edx;
12961
12962- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12963+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12964 eax |= (1<<1)|(1<<7);
12965- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12966+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12967
12968 set_bit(X86_FEATURE_CX8, cpu.flags);
12969 err = check_cpuflags();
12970@@ -145,12 +145,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12971 u32 eax, edx;
12972 u32 level = 1;
12973
12974- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12975- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12976- asm("cpuid"
12977+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12978+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12979+ asm volatile("cpuid"
12980 : "+a" (level), "=d" (cpu.flags[0])
12981 : : "ecx", "ebx");
12982- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12983+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12984
12985 err = check_cpuflags();
12986 }
12987diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
12988index ec3b8ba..6a0db1f 100644
12989--- a/arch/x86/boot/header.S
12990+++ b/arch/x86/boot/header.S
12991@@ -416,10 +416,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
12992 # single linked list of
12993 # struct setup_data
12994
12995-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
12996+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
12997
12998 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
12999+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13000+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
13001+#else
13002 #define VO_INIT_SIZE (VO__end - VO__text)
13003+#endif
13004 #if ZO_INIT_SIZE > VO_INIT_SIZE
13005 #define INIT_SIZE ZO_INIT_SIZE
13006 #else
13007diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
13008index db75d07..8e6d0af 100644
13009--- a/arch/x86/boot/memory.c
13010+++ b/arch/x86/boot/memory.c
13011@@ -19,7 +19,7 @@
13012
13013 static int detect_memory_e820(void)
13014 {
13015- int count = 0;
13016+ unsigned int count = 0;
13017 struct biosregs ireg, oreg;
13018 struct e820entry *desc = boot_params.e820_map;
13019 static struct e820entry buf; /* static so it is zeroed */
13020diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
13021index 11e8c6e..fdbb1ed 100644
13022--- a/arch/x86/boot/video-vesa.c
13023+++ b/arch/x86/boot/video-vesa.c
13024@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
13025
13026 boot_params.screen_info.vesapm_seg = oreg.es;
13027 boot_params.screen_info.vesapm_off = oreg.di;
13028+ boot_params.screen_info.vesapm_size = oreg.cx;
13029 }
13030
13031 /*
13032diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
13033index 43eda28..5ab5fdb 100644
13034--- a/arch/x86/boot/video.c
13035+++ b/arch/x86/boot/video.c
13036@@ -96,7 +96,7 @@ static void store_mode_params(void)
13037 static unsigned int get_entry(void)
13038 {
13039 char entry_buf[4];
13040- int i, len = 0;
13041+ unsigned int i, len = 0;
13042 int key;
13043 unsigned int v;
13044
13045diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
13046index 9105655..41779c1 100644
13047--- a/arch/x86/crypto/aes-x86_64-asm_64.S
13048+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
13049@@ -8,6 +8,8 @@
13050 * including this sentence is retained in full.
13051 */
13052
13053+#include <asm/alternative-asm.h>
13054+
13055 .extern crypto_ft_tab
13056 .extern crypto_it_tab
13057 .extern crypto_fl_tab
13058@@ -70,6 +72,8 @@
13059 je B192; \
13060 leaq 32(r9),r9;
13061
13062+#define ret pax_force_retaddr; ret
13063+
13064 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
13065 movq r1,r2; \
13066 movq r3,r4; \
13067diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
13068index 477e9d7..c92c7d8 100644
13069--- a/arch/x86/crypto/aesni-intel_asm.S
13070+++ b/arch/x86/crypto/aesni-intel_asm.S
13071@@ -31,6 +31,7 @@
13072
13073 #include <linux/linkage.h>
13074 #include <asm/inst.h>
13075+#include <asm/alternative-asm.h>
13076
13077 #ifdef __x86_64__
13078 .data
13079@@ -205,7 +206,7 @@ enc: .octa 0x2
13080 * num_initial_blocks = b mod 4
13081 * encrypt the initial num_initial_blocks blocks and apply ghash on
13082 * the ciphertext
13083-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13084+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13085 * are clobbered
13086 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13087 */
13088@@ -214,8 +215,8 @@ enc: .octa 0x2
13089 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13090 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13091 mov arg7, %r10 # %r10 = AAD
13092- mov arg8, %r12 # %r12 = aadLen
13093- mov %r12, %r11
13094+ mov arg8, %r15 # %r15 = aadLen
13095+ mov %r15, %r11
13096 pxor %xmm\i, %xmm\i
13097 _get_AAD_loop\num_initial_blocks\operation:
13098 movd (%r10), \TMP1
13099@@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13100 psrldq $4, %xmm\i
13101 pxor \TMP1, %xmm\i
13102 add $4, %r10
13103- sub $4, %r12
13104+ sub $4, %r15
13105 jne _get_AAD_loop\num_initial_blocks\operation
13106 cmp $16, %r11
13107 je _get_AAD_loop2_done\num_initial_blocks\operation
13108- mov $16, %r12
13109+ mov $16, %r15
13110 _get_AAD_loop2\num_initial_blocks\operation:
13111 psrldq $4, %xmm\i
13112- sub $4, %r12
13113- cmp %r11, %r12
13114+ sub $4, %r15
13115+ cmp %r11, %r15
13116 jne _get_AAD_loop2\num_initial_blocks\operation
13117 _get_AAD_loop2_done\num_initial_blocks\operation:
13118 movdqa SHUF_MASK(%rip), %xmm14
13119@@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
13120 * num_initial_blocks = b mod 4
13121 * encrypt the initial num_initial_blocks blocks and apply ghash on
13122 * the ciphertext
13123-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13124+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13125 * are clobbered
13126 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13127 */
13128@@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
13129 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13130 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13131 mov arg7, %r10 # %r10 = AAD
13132- mov arg8, %r12 # %r12 = aadLen
13133- mov %r12, %r11
13134+ mov arg8, %r15 # %r15 = aadLen
13135+ mov %r15, %r11
13136 pxor %xmm\i, %xmm\i
13137 _get_AAD_loop\num_initial_blocks\operation:
13138 movd (%r10), \TMP1
13139@@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13140 psrldq $4, %xmm\i
13141 pxor \TMP1, %xmm\i
13142 add $4, %r10
13143- sub $4, %r12
13144+ sub $4, %r15
13145 jne _get_AAD_loop\num_initial_blocks\operation
13146 cmp $16, %r11
13147 je _get_AAD_loop2_done\num_initial_blocks\operation
13148- mov $16, %r12
13149+ mov $16, %r15
13150 _get_AAD_loop2\num_initial_blocks\operation:
13151 psrldq $4, %xmm\i
13152- sub $4, %r12
13153- cmp %r11, %r12
13154+ sub $4, %r15
13155+ cmp %r11, %r15
13156 jne _get_AAD_loop2\num_initial_blocks\operation
13157 _get_AAD_loop2_done\num_initial_blocks\operation:
13158 movdqa SHUF_MASK(%rip), %xmm14
13159@@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
13160 *
13161 *****************************************************************************/
13162 ENTRY(aesni_gcm_dec)
13163- push %r12
13164+ push %r15
13165 push %r13
13166 push %r14
13167 mov %rsp, %r14
13168@@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
13169 */
13170 sub $VARIABLE_OFFSET, %rsp
13171 and $~63, %rsp # align rsp to 64 bytes
13172- mov %arg6, %r12
13173- movdqu (%r12), %xmm13 # %xmm13 = HashKey
13174+ mov %arg6, %r15
13175+ movdqu (%r15), %xmm13 # %xmm13 = HashKey
13176 movdqa SHUF_MASK(%rip), %xmm2
13177 PSHUFB_XMM %xmm2, %xmm13
13178
13179@@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
13180 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
13181 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
13182 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
13183- mov %r13, %r12
13184- and $(3<<4), %r12
13185+ mov %r13, %r15
13186+ and $(3<<4), %r15
13187 jz _initial_num_blocks_is_0_decrypt
13188- cmp $(2<<4), %r12
13189+ cmp $(2<<4), %r15
13190 jb _initial_num_blocks_is_1_decrypt
13191 je _initial_num_blocks_is_2_decrypt
13192 _initial_num_blocks_is_3_decrypt:
13193@@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
13194 sub $16, %r11
13195 add %r13, %r11
13196 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
13197- lea SHIFT_MASK+16(%rip), %r12
13198- sub %r13, %r12
13199+ lea SHIFT_MASK+16(%rip), %r15
13200+ sub %r13, %r15
13201 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
13202 # (%r13 is the number of bytes in plaintext mod 16)
13203- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13204+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13205 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
13206
13207 movdqa %xmm1, %xmm2
13208 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
13209- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13210+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13211 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
13212 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
13213 pand %xmm1, %xmm2
13214@@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
13215 sub $1, %r13
13216 jne _less_than_8_bytes_left_decrypt
13217 _multiple_of_16_bytes_decrypt:
13218- mov arg8, %r12 # %r13 = aadLen (number of bytes)
13219- shl $3, %r12 # convert into number of bits
13220- movd %r12d, %xmm15 # len(A) in %xmm15
13221+ mov arg8, %r15 # %r13 = aadLen (number of bytes)
13222+ shl $3, %r15 # convert into number of bits
13223+ movd %r15d, %xmm15 # len(A) in %xmm15
13224 shl $3, %arg4 # len(C) in bits (*128)
13225 MOVQ_R64_XMM %arg4, %xmm1
13226 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13227@@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
13228 mov %r14, %rsp
13229 pop %r14
13230 pop %r13
13231- pop %r12
13232+ pop %r15
13233+ pax_force_retaddr
13234 ret
13235 ENDPROC(aesni_gcm_dec)
13236
13237@@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
13238 * poly = x^128 + x^127 + x^126 + x^121 + 1
13239 ***************************************************************************/
13240 ENTRY(aesni_gcm_enc)
13241- push %r12
13242+ push %r15
13243 push %r13
13244 push %r14
13245 mov %rsp, %r14
13246@@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
13247 #
13248 sub $VARIABLE_OFFSET, %rsp
13249 and $~63, %rsp
13250- mov %arg6, %r12
13251- movdqu (%r12), %xmm13
13252+ mov %arg6, %r15
13253+ movdqu (%r15), %xmm13
13254 movdqa SHUF_MASK(%rip), %xmm2
13255 PSHUFB_XMM %xmm2, %xmm13
13256
13257@@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
13258 movdqa %xmm13, HashKey(%rsp)
13259 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
13260 and $-16, %r13
13261- mov %r13, %r12
13262+ mov %r13, %r15
13263
13264 # Encrypt first few blocks
13265
13266- and $(3<<4), %r12
13267+ and $(3<<4), %r15
13268 jz _initial_num_blocks_is_0_encrypt
13269- cmp $(2<<4), %r12
13270+ cmp $(2<<4), %r15
13271 jb _initial_num_blocks_is_1_encrypt
13272 je _initial_num_blocks_is_2_encrypt
13273 _initial_num_blocks_is_3_encrypt:
13274@@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
13275 sub $16, %r11
13276 add %r13, %r11
13277 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
13278- lea SHIFT_MASK+16(%rip), %r12
13279- sub %r13, %r12
13280+ lea SHIFT_MASK+16(%rip), %r15
13281+ sub %r13, %r15
13282 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
13283 # (%r13 is the number of bytes in plaintext mod 16)
13284- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13285+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13286 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
13287 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
13288- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13289+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13290 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
13291 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
13292 movdqa SHUF_MASK(%rip), %xmm10
13293@@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
13294 sub $1, %r13
13295 jne _less_than_8_bytes_left_encrypt
13296 _multiple_of_16_bytes_encrypt:
13297- mov arg8, %r12 # %r12 = addLen (number of bytes)
13298- shl $3, %r12
13299- movd %r12d, %xmm15 # len(A) in %xmm15
13300+ mov arg8, %r15 # %r15 = addLen (number of bytes)
13301+ shl $3, %r15
13302+ movd %r15d, %xmm15 # len(A) in %xmm15
13303 shl $3, %arg4 # len(C) in bits (*128)
13304 MOVQ_R64_XMM %arg4, %xmm1
13305 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13306@@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
13307 mov %r14, %rsp
13308 pop %r14
13309 pop %r13
13310- pop %r12
13311+ pop %r15
13312+ pax_force_retaddr
13313 ret
13314 ENDPROC(aesni_gcm_enc)
13315
13316@@ -1722,6 +1725,7 @@ _key_expansion_256a:
13317 pxor %xmm1, %xmm0
13318 movaps %xmm0, (TKEYP)
13319 add $0x10, TKEYP
13320+ pax_force_retaddr
13321 ret
13322 ENDPROC(_key_expansion_128)
13323 ENDPROC(_key_expansion_256a)
13324@@ -1748,6 +1752,7 @@ _key_expansion_192a:
13325 shufps $0b01001110, %xmm2, %xmm1
13326 movaps %xmm1, 0x10(TKEYP)
13327 add $0x20, TKEYP
13328+ pax_force_retaddr
13329 ret
13330 ENDPROC(_key_expansion_192a)
13331
13332@@ -1768,6 +1773,7 @@ _key_expansion_192b:
13333
13334 movaps %xmm0, (TKEYP)
13335 add $0x10, TKEYP
13336+ pax_force_retaddr
13337 ret
13338 ENDPROC(_key_expansion_192b)
13339
13340@@ -1781,6 +1787,7 @@ _key_expansion_256b:
13341 pxor %xmm1, %xmm2
13342 movaps %xmm2, (TKEYP)
13343 add $0x10, TKEYP
13344+ pax_force_retaddr
13345 ret
13346 ENDPROC(_key_expansion_256b)
13347
13348@@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
13349 #ifndef __x86_64__
13350 popl KEYP
13351 #endif
13352+ pax_force_retaddr
13353 ret
13354 ENDPROC(aesni_set_key)
13355
13356@@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
13357 popl KLEN
13358 popl KEYP
13359 #endif
13360+ pax_force_retaddr
13361 ret
13362 ENDPROC(aesni_enc)
13363
13364@@ -1974,6 +1983,7 @@ _aesni_enc1:
13365 AESENC KEY STATE
13366 movaps 0x70(TKEYP), KEY
13367 AESENCLAST KEY STATE
13368+ pax_force_retaddr
13369 ret
13370 ENDPROC(_aesni_enc1)
13371
13372@@ -2083,6 +2093,7 @@ _aesni_enc4:
13373 AESENCLAST KEY STATE2
13374 AESENCLAST KEY STATE3
13375 AESENCLAST KEY STATE4
13376+ pax_force_retaddr
13377 ret
13378 ENDPROC(_aesni_enc4)
13379
13380@@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
13381 popl KLEN
13382 popl KEYP
13383 #endif
13384+ pax_force_retaddr
13385 ret
13386 ENDPROC(aesni_dec)
13387
13388@@ -2164,6 +2176,7 @@ _aesni_dec1:
13389 AESDEC KEY STATE
13390 movaps 0x70(TKEYP), KEY
13391 AESDECLAST KEY STATE
13392+ pax_force_retaddr
13393 ret
13394 ENDPROC(_aesni_dec1)
13395
13396@@ -2273,6 +2286,7 @@ _aesni_dec4:
13397 AESDECLAST KEY STATE2
13398 AESDECLAST KEY STATE3
13399 AESDECLAST KEY STATE4
13400+ pax_force_retaddr
13401 ret
13402 ENDPROC(_aesni_dec4)
13403
13404@@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
13405 popl KEYP
13406 popl LEN
13407 #endif
13408+ pax_force_retaddr
13409 ret
13410 ENDPROC(aesni_ecb_enc)
13411
13412@@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
13413 popl KEYP
13414 popl LEN
13415 #endif
13416+ pax_force_retaddr
13417 ret
13418 ENDPROC(aesni_ecb_dec)
13419
13420@@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
13421 popl LEN
13422 popl IVP
13423 #endif
13424+ pax_force_retaddr
13425 ret
13426 ENDPROC(aesni_cbc_enc)
13427
13428@@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
13429 popl LEN
13430 popl IVP
13431 #endif
13432+ pax_force_retaddr
13433 ret
13434 ENDPROC(aesni_cbc_dec)
13435
13436@@ -2550,6 +2568,7 @@ _aesni_inc_init:
13437 mov $1, TCTR_LOW
13438 MOVQ_R64_XMM TCTR_LOW INC
13439 MOVQ_R64_XMM CTR TCTR_LOW
13440+ pax_force_retaddr
13441 ret
13442 ENDPROC(_aesni_inc_init)
13443
13444@@ -2579,6 +2598,7 @@ _aesni_inc:
13445 .Linc_low:
13446 movaps CTR, IV
13447 PSHUFB_XMM BSWAP_MASK IV
13448+ pax_force_retaddr
13449 ret
13450 ENDPROC(_aesni_inc)
13451
13452@@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
13453 .Lctr_enc_ret:
13454 movups IV, (IVP)
13455 .Lctr_enc_just_ret:
13456+ pax_force_retaddr
13457 ret
13458 ENDPROC(aesni_ctr_enc)
13459
13460@@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
13461 pxor INC, STATE4
13462 movdqu STATE4, 0x70(OUTP)
13463
13464+ pax_force_retaddr
13465 ret
13466 ENDPROC(aesni_xts_crypt8)
13467
13468diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13469index 246c670..466e2d6 100644
13470--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
13471+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13472@@ -21,6 +21,7 @@
13473 */
13474
13475 #include <linux/linkage.h>
13476+#include <asm/alternative-asm.h>
13477
13478 .file "blowfish-x86_64-asm.S"
13479 .text
13480@@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
13481 jnz .L__enc_xor;
13482
13483 write_block();
13484+ pax_force_retaddr
13485 ret;
13486 .L__enc_xor:
13487 xor_block();
13488+ pax_force_retaddr
13489 ret;
13490 ENDPROC(__blowfish_enc_blk)
13491
13492@@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
13493
13494 movq %r11, %rbp;
13495
13496+ pax_force_retaddr
13497 ret;
13498 ENDPROC(blowfish_dec_blk)
13499
13500@@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
13501
13502 popq %rbx;
13503 popq %rbp;
13504+ pax_force_retaddr
13505 ret;
13506
13507 .L__enc_xor4:
13508@@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
13509
13510 popq %rbx;
13511 popq %rbp;
13512+ pax_force_retaddr
13513 ret;
13514 ENDPROC(__blowfish_enc_blk_4way)
13515
13516@@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
13517 popq %rbx;
13518 popq %rbp;
13519
13520+ pax_force_retaddr
13521 ret;
13522 ENDPROC(blowfish_dec_blk_4way)
13523diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13524index ce71f92..1dce7ec 100644
13525--- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13526+++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13527@@ -16,6 +16,7 @@
13528 */
13529
13530 #include <linux/linkage.h>
13531+#include <asm/alternative-asm.h>
13532
13533 #define CAMELLIA_TABLE_BYTE_LEN 272
13534
13535@@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13536 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
13537 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
13538 %rcx, (%r9));
13539+ pax_force_retaddr
13540 ret;
13541 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13542
13543@@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13544 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
13545 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
13546 %rax, (%r9));
13547+ pax_force_retaddr
13548 ret;
13549 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13550
13551@@ -780,6 +783,7 @@ __camellia_enc_blk16:
13552 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13553 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
13554
13555+ pax_force_retaddr
13556 ret;
13557
13558 .align 8
13559@@ -865,6 +869,7 @@ __camellia_dec_blk16:
13560 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13561 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
13562
13563+ pax_force_retaddr
13564 ret;
13565
13566 .align 8
13567@@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
13568 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13569 %xmm8, %rsi);
13570
13571+ pax_force_retaddr
13572 ret;
13573 ENDPROC(camellia_ecb_enc_16way)
13574
13575@@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
13576 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13577 %xmm8, %rsi);
13578
13579+ pax_force_retaddr
13580 ret;
13581 ENDPROC(camellia_ecb_dec_16way)
13582
13583@@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
13584 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13585 %xmm8, %rsi);
13586
13587+ pax_force_retaddr
13588 ret;
13589 ENDPROC(camellia_cbc_dec_16way)
13590
13591@@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
13592 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13593 %xmm8, %rsi);
13594
13595+ pax_force_retaddr
13596 ret;
13597 ENDPROC(camellia_ctr_16way)
13598
13599@@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
13600 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13601 %xmm8, %rsi);
13602
13603+ pax_force_retaddr
13604 ret;
13605 ENDPROC(camellia_xts_crypt_16way)
13606
13607diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13608index 0e0b886..5a3123c 100644
13609--- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13610+++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13611@@ -11,6 +11,7 @@
13612 */
13613
13614 #include <linux/linkage.h>
13615+#include <asm/alternative-asm.h>
13616
13617 #define CAMELLIA_TABLE_BYTE_LEN 272
13618
13619@@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13620 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
13621 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
13622 %rcx, (%r9));
13623+ pax_force_retaddr
13624 ret;
13625 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13626
13627@@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13628 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
13629 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
13630 %rax, (%r9));
13631+ pax_force_retaddr
13632 ret;
13633 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13634
13635@@ -820,6 +823,7 @@ __camellia_enc_blk32:
13636 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13637 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
13638
13639+ pax_force_retaddr
13640 ret;
13641
13642 .align 8
13643@@ -905,6 +909,7 @@ __camellia_dec_blk32:
13644 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13645 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
13646
13647+ pax_force_retaddr
13648 ret;
13649
13650 .align 8
13651@@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
13652
13653 vzeroupper;
13654
13655+ pax_force_retaddr
13656 ret;
13657 ENDPROC(camellia_ecb_enc_32way)
13658
13659@@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
13660
13661 vzeroupper;
13662
13663+ pax_force_retaddr
13664 ret;
13665 ENDPROC(camellia_ecb_dec_32way)
13666
13667@@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
13668
13669 vzeroupper;
13670
13671+ pax_force_retaddr
13672 ret;
13673 ENDPROC(camellia_cbc_dec_32way)
13674
13675@@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
13676
13677 vzeroupper;
13678
13679+ pax_force_retaddr
13680 ret;
13681 ENDPROC(camellia_ctr_32way)
13682
13683@@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
13684
13685 vzeroupper;
13686
13687+ pax_force_retaddr
13688 ret;
13689 ENDPROC(camellia_xts_crypt_32way)
13690
13691diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
13692index 310319c..db3d7b5 100644
13693--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
13694+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
13695@@ -21,6 +21,7 @@
13696 */
13697
13698 #include <linux/linkage.h>
13699+#include <asm/alternative-asm.h>
13700
13701 .file "camellia-x86_64-asm_64.S"
13702 .text
13703@@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
13704 enc_outunpack(mov, RT1);
13705
13706 movq RRBP, %rbp;
13707+ pax_force_retaddr
13708 ret;
13709
13710 .L__enc_xor:
13711 enc_outunpack(xor, RT1);
13712
13713 movq RRBP, %rbp;
13714+ pax_force_retaddr
13715 ret;
13716 ENDPROC(__camellia_enc_blk)
13717
13718@@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
13719 dec_outunpack();
13720
13721 movq RRBP, %rbp;
13722+ pax_force_retaddr
13723 ret;
13724 ENDPROC(camellia_dec_blk)
13725
13726@@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
13727
13728 movq RRBP, %rbp;
13729 popq %rbx;
13730+ pax_force_retaddr
13731 ret;
13732
13733 .L__enc2_xor:
13734@@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
13735
13736 movq RRBP, %rbp;
13737 popq %rbx;
13738+ pax_force_retaddr
13739 ret;
13740 ENDPROC(__camellia_enc_blk_2way)
13741
13742@@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
13743
13744 movq RRBP, %rbp;
13745 movq RXOR, %rbx;
13746+ pax_force_retaddr
13747 ret;
13748 ENDPROC(camellia_dec_blk_2way)
13749diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13750index c35fd5d..2d8c7db 100644
13751--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13752+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13753@@ -24,6 +24,7 @@
13754 */
13755
13756 #include <linux/linkage.h>
13757+#include <asm/alternative-asm.h>
13758
13759 .file "cast5-avx-x86_64-asm_64.S"
13760
13761@@ -281,6 +282,7 @@ __cast5_enc_blk16:
13762 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13763 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13764
13765+ pax_force_retaddr
13766 ret;
13767 ENDPROC(__cast5_enc_blk16)
13768
13769@@ -352,6 +354,7 @@ __cast5_dec_blk16:
13770 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13771 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13772
13773+ pax_force_retaddr
13774 ret;
13775
13776 .L__skip_dec:
13777@@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
13778 vmovdqu RR4, (6*4*4)(%r11);
13779 vmovdqu RL4, (7*4*4)(%r11);
13780
13781+ pax_force_retaddr
13782 ret;
13783 ENDPROC(cast5_ecb_enc_16way)
13784
13785@@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
13786 vmovdqu RR4, (6*4*4)(%r11);
13787 vmovdqu RL4, (7*4*4)(%r11);
13788
13789+ pax_force_retaddr
13790 ret;
13791 ENDPROC(cast5_ecb_dec_16way)
13792
13793@@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
13794 * %rdx: src
13795 */
13796
13797- pushq %r12;
13798+ pushq %r14;
13799
13800 movq %rsi, %r11;
13801- movq %rdx, %r12;
13802+ movq %rdx, %r14;
13803
13804 vmovdqu (0*16)(%rdx), RL1;
13805 vmovdqu (1*16)(%rdx), RR1;
13806@@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
13807 call __cast5_dec_blk16;
13808
13809 /* xor with src */
13810- vmovq (%r12), RX;
13811+ vmovq (%r14), RX;
13812 vpshufd $0x4f, RX, RX;
13813 vpxor RX, RR1, RR1;
13814- vpxor 0*16+8(%r12), RL1, RL1;
13815- vpxor 1*16+8(%r12), RR2, RR2;
13816- vpxor 2*16+8(%r12), RL2, RL2;
13817- vpxor 3*16+8(%r12), RR3, RR3;
13818- vpxor 4*16+8(%r12), RL3, RL3;
13819- vpxor 5*16+8(%r12), RR4, RR4;
13820- vpxor 6*16+8(%r12), RL4, RL4;
13821+ vpxor 0*16+8(%r14), RL1, RL1;
13822+ vpxor 1*16+8(%r14), RR2, RR2;
13823+ vpxor 2*16+8(%r14), RL2, RL2;
13824+ vpxor 3*16+8(%r14), RR3, RR3;
13825+ vpxor 4*16+8(%r14), RL3, RL3;
13826+ vpxor 5*16+8(%r14), RR4, RR4;
13827+ vpxor 6*16+8(%r14), RL4, RL4;
13828
13829 vmovdqu RR1, (0*16)(%r11);
13830 vmovdqu RL1, (1*16)(%r11);
13831@@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
13832 vmovdqu RR4, (6*16)(%r11);
13833 vmovdqu RL4, (7*16)(%r11);
13834
13835- popq %r12;
13836+ popq %r14;
13837
13838+ pax_force_retaddr
13839 ret;
13840 ENDPROC(cast5_cbc_dec_16way)
13841
13842@@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
13843 * %rcx: iv (big endian, 64bit)
13844 */
13845
13846- pushq %r12;
13847+ pushq %r14;
13848
13849 movq %rsi, %r11;
13850- movq %rdx, %r12;
13851+ movq %rdx, %r14;
13852
13853 vpcmpeqd RTMP, RTMP, RTMP;
13854 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
13855@@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
13856 call __cast5_enc_blk16;
13857
13858 /* dst = src ^ iv */
13859- vpxor (0*16)(%r12), RR1, RR1;
13860- vpxor (1*16)(%r12), RL1, RL1;
13861- vpxor (2*16)(%r12), RR2, RR2;
13862- vpxor (3*16)(%r12), RL2, RL2;
13863- vpxor (4*16)(%r12), RR3, RR3;
13864- vpxor (5*16)(%r12), RL3, RL3;
13865- vpxor (6*16)(%r12), RR4, RR4;
13866- vpxor (7*16)(%r12), RL4, RL4;
13867+ vpxor (0*16)(%r14), RR1, RR1;
13868+ vpxor (1*16)(%r14), RL1, RL1;
13869+ vpxor (2*16)(%r14), RR2, RR2;
13870+ vpxor (3*16)(%r14), RL2, RL2;
13871+ vpxor (4*16)(%r14), RR3, RR3;
13872+ vpxor (5*16)(%r14), RL3, RL3;
13873+ vpxor (6*16)(%r14), RR4, RR4;
13874+ vpxor (7*16)(%r14), RL4, RL4;
13875 vmovdqu RR1, (0*16)(%r11);
13876 vmovdqu RL1, (1*16)(%r11);
13877 vmovdqu RR2, (2*16)(%r11);
13878@@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
13879 vmovdqu RR4, (6*16)(%r11);
13880 vmovdqu RL4, (7*16)(%r11);
13881
13882- popq %r12;
13883+ popq %r14;
13884
13885+ pax_force_retaddr
13886 ret;
13887 ENDPROC(cast5_ctr_16way)
13888diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13889index e3531f8..e123f35 100644
13890--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13891+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13892@@ -24,6 +24,7 @@
13893 */
13894
13895 #include <linux/linkage.h>
13896+#include <asm/alternative-asm.h>
13897 #include "glue_helper-asm-avx.S"
13898
13899 .file "cast6-avx-x86_64-asm_64.S"
13900@@ -295,6 +296,7 @@ __cast6_enc_blk8:
13901 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13902 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13903
13904+ pax_force_retaddr
13905 ret;
13906 ENDPROC(__cast6_enc_blk8)
13907
13908@@ -340,6 +342,7 @@ __cast6_dec_blk8:
13909 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13910 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13911
13912+ pax_force_retaddr
13913 ret;
13914 ENDPROC(__cast6_dec_blk8)
13915
13916@@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
13917
13918 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13919
13920+ pax_force_retaddr
13921 ret;
13922 ENDPROC(cast6_ecb_enc_8way)
13923
13924@@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
13925
13926 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13927
13928+ pax_force_retaddr
13929 ret;
13930 ENDPROC(cast6_ecb_dec_8way)
13931
13932@@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
13933 * %rdx: src
13934 */
13935
13936- pushq %r12;
13937+ pushq %r14;
13938
13939 movq %rsi, %r11;
13940- movq %rdx, %r12;
13941+ movq %rdx, %r14;
13942
13943 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13944
13945 call __cast6_dec_blk8;
13946
13947- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13948+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13949
13950- popq %r12;
13951+ popq %r14;
13952
13953+ pax_force_retaddr
13954 ret;
13955 ENDPROC(cast6_cbc_dec_8way)
13956
13957@@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
13958 * %rcx: iv (little endian, 128bit)
13959 */
13960
13961- pushq %r12;
13962+ pushq %r14;
13963
13964 movq %rsi, %r11;
13965- movq %rdx, %r12;
13966+ movq %rdx, %r14;
13967
13968 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13969 RD2, RX, RKR, RKM);
13970
13971 call __cast6_enc_blk8;
13972
13973- store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13974+ store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13975
13976- popq %r12;
13977+ popq %r14;
13978
13979+ pax_force_retaddr
13980 ret;
13981 ENDPROC(cast6_ctr_8way)
13982
13983@@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
13984 /* dst <= regs xor IVs(in dst) */
13985 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13986
13987+ pax_force_retaddr
13988 ret;
13989 ENDPROC(cast6_xts_enc_8way)
13990
13991@@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
13992 /* dst <= regs xor IVs(in dst) */
13993 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13994
13995+ pax_force_retaddr
13996 ret;
13997 ENDPROC(cast6_xts_dec_8way)
13998diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13999index dbc4339..de6e120 100644
14000--- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
14001+++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
14002@@ -45,6 +45,7 @@
14003
14004 #include <asm/inst.h>
14005 #include <linux/linkage.h>
14006+#include <asm/alternative-asm.h>
14007
14008 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
14009
14010@@ -312,6 +313,7 @@ do_return:
14011 popq %rsi
14012 popq %rdi
14013 popq %rbx
14014+ pax_force_retaddr
14015 ret
14016
14017 ################################################################
14018diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
14019index 185fad4..ff4cd36 100644
14020--- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
14021+++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
14022@@ -18,6 +18,7 @@
14023
14024 #include <linux/linkage.h>
14025 #include <asm/inst.h>
14026+#include <asm/alternative-asm.h>
14027
14028 .data
14029
14030@@ -89,6 +90,7 @@ __clmul_gf128mul_ble:
14031 psrlq $1, T2
14032 pxor T2, T1
14033 pxor T1, DATA
14034+ pax_force_retaddr
14035 ret
14036 ENDPROC(__clmul_gf128mul_ble)
14037
14038@@ -101,6 +103,7 @@ ENTRY(clmul_ghash_mul)
14039 call __clmul_gf128mul_ble
14040 PSHUFB_XMM BSWAP DATA
14041 movups DATA, (%rdi)
14042+ pax_force_retaddr
14043 ret
14044 ENDPROC(clmul_ghash_mul)
14045
14046@@ -128,5 +131,6 @@ ENTRY(clmul_ghash_update)
14047 PSHUFB_XMM BSWAP DATA
14048 movups DATA, (%rdi)
14049 .Lupdate_just_ret:
14050+ pax_force_retaddr
14051 ret
14052 ENDPROC(clmul_ghash_update)
14053diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14054index 9279e0b..c4b3d2c 100644
14055--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
14056+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14057@@ -1,4 +1,5 @@
14058 #include <linux/linkage.h>
14059+#include <asm/alternative-asm.h>
14060
14061 # enter salsa20_encrypt_bytes
14062 ENTRY(salsa20_encrypt_bytes)
14063@@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
14064 add %r11,%rsp
14065 mov %rdi,%rax
14066 mov %rsi,%rdx
14067+ pax_force_retaddr
14068 ret
14069 # bytesatleast65:
14070 ._bytesatleast65:
14071@@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
14072 add %r11,%rsp
14073 mov %rdi,%rax
14074 mov %rsi,%rdx
14075+ pax_force_retaddr
14076 ret
14077 ENDPROC(salsa20_keysetup)
14078
14079@@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
14080 add %r11,%rsp
14081 mov %rdi,%rax
14082 mov %rsi,%rdx
14083+ pax_force_retaddr
14084 ret
14085 ENDPROC(salsa20_ivsetup)
14086diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14087index 2f202f4..d9164d6 100644
14088--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14089+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14090@@ -24,6 +24,7 @@
14091 */
14092
14093 #include <linux/linkage.h>
14094+#include <asm/alternative-asm.h>
14095 #include "glue_helper-asm-avx.S"
14096
14097 .file "serpent-avx-x86_64-asm_64.S"
14098@@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
14099 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14100 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14101
14102+ pax_force_retaddr
14103 ret;
14104 ENDPROC(__serpent_enc_blk8_avx)
14105
14106@@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
14107 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14108 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14109
14110+ pax_force_retaddr
14111 ret;
14112 ENDPROC(__serpent_dec_blk8_avx)
14113
14114@@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
14115
14116 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14117
14118+ pax_force_retaddr
14119 ret;
14120 ENDPROC(serpent_ecb_enc_8way_avx)
14121
14122@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
14123
14124 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14125
14126+ pax_force_retaddr
14127 ret;
14128 ENDPROC(serpent_ecb_dec_8way_avx)
14129
14130@@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
14131
14132 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14133
14134+ pax_force_retaddr
14135 ret;
14136 ENDPROC(serpent_cbc_dec_8way_avx)
14137
14138@@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
14139
14140 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14141
14142+ pax_force_retaddr
14143 ret;
14144 ENDPROC(serpent_ctr_8way_avx)
14145
14146@@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
14147 /* dst <= regs xor IVs(in dst) */
14148 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14149
14150+ pax_force_retaddr
14151 ret;
14152 ENDPROC(serpent_xts_enc_8way_avx)
14153
14154@@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
14155 /* dst <= regs xor IVs(in dst) */
14156 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14157
14158+ pax_force_retaddr
14159 ret;
14160 ENDPROC(serpent_xts_dec_8way_avx)
14161diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
14162index b222085..abd483c 100644
14163--- a/arch/x86/crypto/serpent-avx2-asm_64.S
14164+++ b/arch/x86/crypto/serpent-avx2-asm_64.S
14165@@ -15,6 +15,7 @@
14166 */
14167
14168 #include <linux/linkage.h>
14169+#include <asm/alternative-asm.h>
14170 #include "glue_helper-asm-avx2.S"
14171
14172 .file "serpent-avx2-asm_64.S"
14173@@ -610,6 +611,7 @@ __serpent_enc_blk16:
14174 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14175 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14176
14177+ pax_force_retaddr
14178 ret;
14179 ENDPROC(__serpent_enc_blk16)
14180
14181@@ -664,6 +666,7 @@ __serpent_dec_blk16:
14182 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14183 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14184
14185+ pax_force_retaddr
14186 ret;
14187 ENDPROC(__serpent_dec_blk16)
14188
14189@@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
14190
14191 vzeroupper;
14192
14193+ pax_force_retaddr
14194 ret;
14195 ENDPROC(serpent_ecb_enc_16way)
14196
14197@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
14198
14199 vzeroupper;
14200
14201+ pax_force_retaddr
14202 ret;
14203 ENDPROC(serpent_ecb_dec_16way)
14204
14205@@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
14206
14207 vzeroupper;
14208
14209+ pax_force_retaddr
14210 ret;
14211 ENDPROC(serpent_cbc_dec_16way)
14212
14213@@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
14214
14215 vzeroupper;
14216
14217+ pax_force_retaddr
14218 ret;
14219 ENDPROC(serpent_ctr_16way)
14220
14221@@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
14222
14223 vzeroupper;
14224
14225+ pax_force_retaddr
14226 ret;
14227 ENDPROC(serpent_xts_enc_16way)
14228
14229@@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
14230
14231 vzeroupper;
14232
14233+ pax_force_retaddr
14234 ret;
14235 ENDPROC(serpent_xts_dec_16way)
14236diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14237index acc066c..1559cc4 100644
14238--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14239+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14240@@ -25,6 +25,7 @@
14241 */
14242
14243 #include <linux/linkage.h>
14244+#include <asm/alternative-asm.h>
14245
14246 .file "serpent-sse2-x86_64-asm_64.S"
14247 .text
14248@@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
14249 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14250 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14251
14252+ pax_force_retaddr
14253 ret;
14254
14255 .L__enc_xor8:
14256 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14257 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14258
14259+ pax_force_retaddr
14260 ret;
14261 ENDPROC(__serpent_enc_blk_8way)
14262
14263@@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
14264 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14265 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14266
14267+ pax_force_retaddr
14268 ret;
14269 ENDPROC(serpent_dec_blk_8way)
14270diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
14271index a410950..9dfe7ad 100644
14272--- a/arch/x86/crypto/sha1_ssse3_asm.S
14273+++ b/arch/x86/crypto/sha1_ssse3_asm.S
14274@@ -29,6 +29,7 @@
14275 */
14276
14277 #include <linux/linkage.h>
14278+#include <asm/alternative-asm.h>
14279
14280 #define CTX %rdi // arg1
14281 #define BUF %rsi // arg2
14282@@ -75,9 +76,9 @@
14283
14284 push %rbx
14285 push %rbp
14286- push %r12
14287+ push %r14
14288
14289- mov %rsp, %r12
14290+ mov %rsp, %r14
14291 sub $64, %rsp # allocate workspace
14292 and $~15, %rsp # align stack
14293
14294@@ -99,11 +100,12 @@
14295 xor %rax, %rax
14296 rep stosq
14297
14298- mov %r12, %rsp # deallocate workspace
14299+ mov %r14, %rsp # deallocate workspace
14300
14301- pop %r12
14302+ pop %r14
14303 pop %rbp
14304 pop %rbx
14305+ pax_force_retaddr
14306 ret
14307
14308 ENDPROC(\name)
14309diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
14310index 642f156..51a513c 100644
14311--- a/arch/x86/crypto/sha256-avx-asm.S
14312+++ b/arch/x86/crypto/sha256-avx-asm.S
14313@@ -49,6 +49,7 @@
14314
14315 #ifdef CONFIG_AS_AVX
14316 #include <linux/linkage.h>
14317+#include <asm/alternative-asm.h>
14318
14319 ## assume buffers not aligned
14320 #define VMOVDQ vmovdqu
14321@@ -460,6 +461,7 @@ done_hash:
14322 popq %r13
14323 popq %rbp
14324 popq %rbx
14325+ pax_force_retaddr
14326 ret
14327 ENDPROC(sha256_transform_avx)
14328
14329diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
14330index 9e86944..3795e6a 100644
14331--- a/arch/x86/crypto/sha256-avx2-asm.S
14332+++ b/arch/x86/crypto/sha256-avx2-asm.S
14333@@ -50,6 +50,7 @@
14334
14335 #ifdef CONFIG_AS_AVX2
14336 #include <linux/linkage.h>
14337+#include <asm/alternative-asm.h>
14338
14339 ## assume buffers not aligned
14340 #define VMOVDQ vmovdqu
14341@@ -720,6 +721,7 @@ done_hash:
14342 popq %r12
14343 popq %rbp
14344 popq %rbx
14345+ pax_force_retaddr
14346 ret
14347 ENDPROC(sha256_transform_rorx)
14348
14349diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
14350index f833b74..8c62a9e 100644
14351--- a/arch/x86/crypto/sha256-ssse3-asm.S
14352+++ b/arch/x86/crypto/sha256-ssse3-asm.S
14353@@ -47,6 +47,7 @@
14354 ########################################################################
14355
14356 #include <linux/linkage.h>
14357+#include <asm/alternative-asm.h>
14358
14359 ## assume buffers not aligned
14360 #define MOVDQ movdqu
14361@@ -471,6 +472,7 @@ done_hash:
14362 popq %rbp
14363 popq %rbx
14364
14365+ pax_force_retaddr
14366 ret
14367 ENDPROC(sha256_transform_ssse3)
14368
14369diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
14370index 974dde9..a823ff9 100644
14371--- a/arch/x86/crypto/sha512-avx-asm.S
14372+++ b/arch/x86/crypto/sha512-avx-asm.S
14373@@ -49,6 +49,7 @@
14374
14375 #ifdef CONFIG_AS_AVX
14376 #include <linux/linkage.h>
14377+#include <asm/alternative-asm.h>
14378
14379 .text
14380
14381@@ -364,6 +365,7 @@ updateblock:
14382 mov frame_RSPSAVE(%rsp), %rsp
14383
14384 nowork:
14385+ pax_force_retaddr
14386 ret
14387 ENDPROC(sha512_transform_avx)
14388
14389diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
14390index 568b961..ed20c37 100644
14391--- a/arch/x86/crypto/sha512-avx2-asm.S
14392+++ b/arch/x86/crypto/sha512-avx2-asm.S
14393@@ -51,6 +51,7 @@
14394
14395 #ifdef CONFIG_AS_AVX2
14396 #include <linux/linkage.h>
14397+#include <asm/alternative-asm.h>
14398
14399 .text
14400
14401@@ -678,6 +679,7 @@ done_hash:
14402
14403 # Restore Stack Pointer
14404 mov frame_RSPSAVE(%rsp), %rsp
14405+ pax_force_retaddr
14406 ret
14407 ENDPROC(sha512_transform_rorx)
14408
14409diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
14410index fb56855..6edd768 100644
14411--- a/arch/x86/crypto/sha512-ssse3-asm.S
14412+++ b/arch/x86/crypto/sha512-ssse3-asm.S
14413@@ -48,6 +48,7 @@
14414 ########################################################################
14415
14416 #include <linux/linkage.h>
14417+#include <asm/alternative-asm.h>
14418
14419 .text
14420
14421@@ -363,6 +364,7 @@ updateblock:
14422 mov frame_RSPSAVE(%rsp), %rsp
14423
14424 nowork:
14425+ pax_force_retaddr
14426 ret
14427 ENDPROC(sha512_transform_ssse3)
14428
14429diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14430index 0505813..b067311 100644
14431--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14432+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14433@@ -24,6 +24,7 @@
14434 */
14435
14436 #include <linux/linkage.h>
14437+#include <asm/alternative-asm.h>
14438 #include "glue_helper-asm-avx.S"
14439
14440 .file "twofish-avx-x86_64-asm_64.S"
14441@@ -284,6 +285,7 @@ __twofish_enc_blk8:
14442 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
14443 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
14444
14445+ pax_force_retaddr
14446 ret;
14447 ENDPROC(__twofish_enc_blk8)
14448
14449@@ -324,6 +326,7 @@ __twofish_dec_blk8:
14450 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
14451 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
14452
14453+ pax_force_retaddr
14454 ret;
14455 ENDPROC(__twofish_dec_blk8)
14456
14457@@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
14458
14459 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14460
14461+ pax_force_retaddr
14462 ret;
14463 ENDPROC(twofish_ecb_enc_8way)
14464
14465@@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
14466
14467 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14468
14469+ pax_force_retaddr
14470 ret;
14471 ENDPROC(twofish_ecb_dec_8way)
14472
14473@@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
14474 * %rdx: src
14475 */
14476
14477- pushq %r12;
14478+ pushq %r14;
14479
14480 movq %rsi, %r11;
14481- movq %rdx, %r12;
14482+ movq %rdx, %r14;
14483
14484 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14485
14486 call __twofish_dec_blk8;
14487
14488- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14489+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14490
14491- popq %r12;
14492+ popq %r14;
14493
14494+ pax_force_retaddr
14495 ret;
14496 ENDPROC(twofish_cbc_dec_8way)
14497
14498@@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
14499 * %rcx: iv (little endian, 128bit)
14500 */
14501
14502- pushq %r12;
14503+ pushq %r14;
14504
14505 movq %rsi, %r11;
14506- movq %rdx, %r12;
14507+ movq %rdx, %r14;
14508
14509 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14510 RD2, RX0, RX1, RY0);
14511
14512 call __twofish_enc_blk8;
14513
14514- store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14515+ store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14516
14517- popq %r12;
14518+ popq %r14;
14519
14520+ pax_force_retaddr
14521 ret;
14522 ENDPROC(twofish_ctr_8way)
14523
14524@@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
14525 /* dst <= regs xor IVs(in dst) */
14526 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14527
14528+ pax_force_retaddr
14529 ret;
14530 ENDPROC(twofish_xts_enc_8way)
14531
14532@@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
14533 /* dst <= regs xor IVs(in dst) */
14534 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14535
14536+ pax_force_retaddr
14537 ret;
14538 ENDPROC(twofish_xts_dec_8way)
14539diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14540index 1c3b7ce..02f578d 100644
14541--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14542+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14543@@ -21,6 +21,7 @@
14544 */
14545
14546 #include <linux/linkage.h>
14547+#include <asm/alternative-asm.h>
14548
14549 .file "twofish-x86_64-asm-3way.S"
14550 .text
14551@@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
14552 popq %r13;
14553 popq %r14;
14554 popq %r15;
14555+ pax_force_retaddr
14556 ret;
14557
14558 .L__enc_xor3:
14559@@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
14560 popq %r13;
14561 popq %r14;
14562 popq %r15;
14563+ pax_force_retaddr
14564 ret;
14565 ENDPROC(__twofish_enc_blk_3way)
14566
14567@@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
14568 popq %r13;
14569 popq %r14;
14570 popq %r15;
14571+ pax_force_retaddr
14572 ret;
14573 ENDPROC(twofish_dec_blk_3way)
14574diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
14575index a039d21..524b8b2 100644
14576--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
14577+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
14578@@ -22,6 +22,7 @@
14579
14580 #include <linux/linkage.h>
14581 #include <asm/asm-offsets.h>
14582+#include <asm/alternative-asm.h>
14583
14584 #define a_offset 0
14585 #define b_offset 4
14586@@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
14587
14588 popq R1
14589 movq $1,%rax
14590+ pax_force_retaddr
14591 ret
14592 ENDPROC(twofish_enc_blk)
14593
14594@@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
14595
14596 popq R1
14597 movq $1,%rax
14598+ pax_force_retaddr
14599 ret
14600 ENDPROC(twofish_dec_blk)
14601diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
14602index d21ff89..6da8e6e 100644
14603--- a/arch/x86/ia32/ia32_aout.c
14604+++ b/arch/x86/ia32/ia32_aout.c
14605@@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
14606 unsigned long dump_start, dump_size;
14607 struct user32 dump;
14608
14609+ memset(&dump, 0, sizeof(dump));
14610+
14611 fs = get_fs();
14612 set_fs(KERNEL_DS);
14613 has_dumped = 1;
14614diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
14615index 2206757..85cbcfa 100644
14616--- a/arch/x86/ia32/ia32_signal.c
14617+++ b/arch/x86/ia32/ia32_signal.c
14618@@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
14619 if (__get_user(set.sig[0], &frame->sc.oldmask)
14620 || (_COMPAT_NSIG_WORDS > 1
14621 && __copy_from_user((((char *) &set.sig) + 4),
14622- &frame->extramask,
14623+ frame->extramask,
14624 sizeof(frame->extramask))))
14625 goto badframe;
14626
14627@@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
14628 sp -= frame_size;
14629 /* Align the stack pointer according to the i386 ABI,
14630 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
14631- sp = ((sp + 4) & -16ul) - 4;
14632+ sp = ((sp - 12) & -16ul) - 4;
14633 return (void __user *) sp;
14634 }
14635
14636@@ -386,7 +386,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14637 restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14638 sigreturn);
14639 else
14640- restorer = &frame->retcode;
14641+ restorer = frame->retcode;
14642 }
14643
14644 put_user_try {
14645@@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14646 * These are actually not used anymore, but left because some
14647 * gdb versions depend on them as a marker.
14648 */
14649- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14650+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14651 } put_user_catch(err);
14652
14653 if (err)
14654@@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14655 0xb8,
14656 __NR_ia32_rt_sigreturn,
14657 0x80cd,
14658- 0,
14659+ 0
14660 };
14661
14662 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
14663@@ -461,16 +461,18 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14664
14665 if (ksig->ka.sa.sa_flags & SA_RESTORER)
14666 restorer = ksig->ka.sa.sa_restorer;
14667+ else if (current->mm->context.vdso)
14668+ /* Return stub is in 32bit vsyscall page */
14669+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
14670 else
14671- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14672- rt_sigreturn);
14673+ restorer = frame->retcode;
14674 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
14675
14676 /*
14677 * Not actually used anymore, but left because some gdb
14678 * versions need it.
14679 */
14680- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14681+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14682 } put_user_catch(err);
14683
14684 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
14685diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
14686index 4299eb0..c0687a7 100644
14687--- a/arch/x86/ia32/ia32entry.S
14688+++ b/arch/x86/ia32/ia32entry.S
14689@@ -15,8 +15,10 @@
14690 #include <asm/irqflags.h>
14691 #include <asm/asm.h>
14692 #include <asm/smap.h>
14693+#include <asm/pgtable.h>
14694 #include <linux/linkage.h>
14695 #include <linux/err.h>
14696+#include <asm/alternative-asm.h>
14697
14698 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14699 #include <linux/elf-em.h>
14700@@ -62,12 +64,12 @@
14701 */
14702 .macro LOAD_ARGS32 offset, _r9=0
14703 .if \_r9
14704- movl \offset+16(%rsp),%r9d
14705+ movl \offset+R9(%rsp),%r9d
14706 .endif
14707- movl \offset+40(%rsp),%ecx
14708- movl \offset+48(%rsp),%edx
14709- movl \offset+56(%rsp),%esi
14710- movl \offset+64(%rsp),%edi
14711+ movl \offset+RCX(%rsp),%ecx
14712+ movl \offset+RDX(%rsp),%edx
14713+ movl \offset+RSI(%rsp),%esi
14714+ movl \offset+RDI(%rsp),%edi
14715 movl %eax,%eax /* zero extension */
14716 .endm
14717
14718@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
14719 ENDPROC(native_irq_enable_sysexit)
14720 #endif
14721
14722+ .macro pax_enter_kernel_user
14723+ pax_set_fptr_mask
14724+#ifdef CONFIG_PAX_MEMORY_UDEREF
14725+ call pax_enter_kernel_user
14726+#endif
14727+ .endm
14728+
14729+ .macro pax_exit_kernel_user
14730+#ifdef CONFIG_PAX_MEMORY_UDEREF
14731+ call pax_exit_kernel_user
14732+#endif
14733+#ifdef CONFIG_PAX_RANDKSTACK
14734+ pushq %rax
14735+ pushq %r11
14736+ call pax_randomize_kstack
14737+ popq %r11
14738+ popq %rax
14739+#endif
14740+ .endm
14741+
14742+ .macro pax_erase_kstack
14743+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14744+ call pax_erase_kstack
14745+#endif
14746+ .endm
14747+
14748 /*
14749 * 32bit SYSENTER instruction entry.
14750 *
14751@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
14752 CFI_REGISTER rsp,rbp
14753 SWAPGS_UNSAFE_STACK
14754 movq PER_CPU_VAR(kernel_stack), %rsp
14755- addq $(KERNEL_STACK_OFFSET),%rsp
14756- /*
14757- * No need to follow this irqs on/off section: the syscall
14758- * disabled irqs, here we enable it straight after entry:
14759- */
14760- ENABLE_INTERRUPTS(CLBR_NONE)
14761 movl %ebp,%ebp /* zero extension */
14762 pushq_cfi $__USER32_DS
14763 /*CFI_REL_OFFSET ss,0*/
14764@@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
14765 CFI_REL_OFFSET rsp,0
14766 pushfq_cfi
14767 /*CFI_REL_OFFSET rflags,0*/
14768- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
14769- CFI_REGISTER rip,r10
14770+ orl $X86_EFLAGS_IF,(%rsp)
14771+ GET_THREAD_INFO(%r11)
14772+ movl TI_sysenter_return(%r11), %r11d
14773+ CFI_REGISTER rip,r11
14774 pushq_cfi $__USER32_CS
14775 /*CFI_REL_OFFSET cs,0*/
14776 movl %eax, %eax
14777- pushq_cfi %r10
14778+ pushq_cfi %r11
14779 CFI_REL_OFFSET rip,0
14780 pushq_cfi %rax
14781 cld
14782 SAVE_ARGS 0,1,0
14783+ pax_enter_kernel_user
14784+
14785+#ifdef CONFIG_PAX_RANDKSTACK
14786+ pax_erase_kstack
14787+#endif
14788+
14789+ /*
14790+ * No need to follow this irqs on/off section: the syscall
14791+ * disabled irqs, here we enable it straight after entry:
14792+ */
14793+ ENABLE_INTERRUPTS(CLBR_NONE)
14794 /* no need to do an access_ok check here because rbp has been
14795 32bit zero extended */
14796+
14797+#ifdef CONFIG_PAX_MEMORY_UDEREF
14798+ addq pax_user_shadow_base,%rbp
14799+ ASM_PAX_OPEN_USERLAND
14800+#endif
14801+
14802 ASM_STAC
14803 1: movl (%rbp),%ebp
14804 _ASM_EXTABLE(1b,ia32_badarg)
14805 ASM_CLAC
14806- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14807- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14808+
14809+#ifdef CONFIG_PAX_MEMORY_UDEREF
14810+ ASM_PAX_CLOSE_USERLAND
14811+#endif
14812+
14813+ GET_THREAD_INFO(%r11)
14814+ orl $TS_COMPAT,TI_status(%r11)
14815+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14816 CFI_REMEMBER_STATE
14817 jnz sysenter_tracesys
14818 cmpq $(IA32_NR_syscalls-1),%rax
14819@@ -162,15 +209,18 @@ sysenter_do_call:
14820 sysenter_dispatch:
14821 call *ia32_sys_call_table(,%rax,8)
14822 movq %rax,RAX-ARGOFFSET(%rsp)
14823+ GET_THREAD_INFO(%r11)
14824 DISABLE_INTERRUPTS(CLBR_NONE)
14825 TRACE_IRQS_OFF
14826- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14827+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14828 jnz sysexit_audit
14829 sysexit_from_sys_call:
14830- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14831+ pax_exit_kernel_user
14832+ pax_erase_kstack
14833+ andl $~TS_COMPAT,TI_status(%r11)
14834 /* clear IF, that popfq doesn't enable interrupts early */
14835- andl $~0x200,EFLAGS-R11(%rsp)
14836- movl RIP-R11(%rsp),%edx /* User %eip */
14837+ andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
14838+ movl RIP(%rsp),%edx /* User %eip */
14839 CFI_REGISTER rip,rdx
14840 RESTORE_ARGS 0,24,0,0,0,0
14841 xorq %r8,%r8
14842@@ -193,6 +243,9 @@ sysexit_from_sys_call:
14843 movl %eax,%esi /* 2nd arg: syscall number */
14844 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
14845 call __audit_syscall_entry
14846+
14847+ pax_erase_kstack
14848+
14849 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
14850 cmpq $(IA32_NR_syscalls-1),%rax
14851 ja ia32_badsys
14852@@ -204,7 +257,7 @@ sysexit_from_sys_call:
14853 .endm
14854
14855 .macro auditsys_exit exit
14856- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14857+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14858 jnz ia32_ret_from_sys_call
14859 TRACE_IRQS_ON
14860 ENABLE_INTERRUPTS(CLBR_NONE)
14861@@ -215,11 +268,12 @@ sysexit_from_sys_call:
14862 1: setbe %al /* 1 if error, 0 if not */
14863 movzbl %al,%edi /* zero-extend that into %edi */
14864 call __audit_syscall_exit
14865+ GET_THREAD_INFO(%r11)
14866 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
14867 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
14868 DISABLE_INTERRUPTS(CLBR_NONE)
14869 TRACE_IRQS_OFF
14870- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14871+ testl %edi,TI_flags(%r11)
14872 jz \exit
14873 CLEAR_RREGS -ARGOFFSET
14874 jmp int_with_check
14875@@ -237,7 +291,7 @@ sysexit_audit:
14876
14877 sysenter_tracesys:
14878 #ifdef CONFIG_AUDITSYSCALL
14879- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14880+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14881 jz sysenter_auditsys
14882 #endif
14883 SAVE_REST
14884@@ -249,6 +303,9 @@ sysenter_tracesys:
14885 RESTORE_REST
14886 cmpq $(IA32_NR_syscalls-1),%rax
14887 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
14888+
14889+ pax_erase_kstack
14890+
14891 jmp sysenter_do_call
14892 CFI_ENDPROC
14893 ENDPROC(ia32_sysenter_target)
14894@@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
14895 ENTRY(ia32_cstar_target)
14896 CFI_STARTPROC32 simple
14897 CFI_SIGNAL_FRAME
14898- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
14899+ CFI_DEF_CFA rsp,0
14900 CFI_REGISTER rip,rcx
14901 /*CFI_REGISTER rflags,r11*/
14902 SWAPGS_UNSAFE_STACK
14903 movl %esp,%r8d
14904 CFI_REGISTER rsp,r8
14905 movq PER_CPU_VAR(kernel_stack),%rsp
14906+ SAVE_ARGS 8*6,0,0
14907+ pax_enter_kernel_user
14908+
14909+#ifdef CONFIG_PAX_RANDKSTACK
14910+ pax_erase_kstack
14911+#endif
14912+
14913 /*
14914 * No need to follow this irqs on/off section: the syscall
14915 * disabled irqs and here we enable it straight after entry:
14916 */
14917 ENABLE_INTERRUPTS(CLBR_NONE)
14918- SAVE_ARGS 8,0,0
14919 movl %eax,%eax /* zero extension */
14920 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14921 movq %rcx,RIP-ARGOFFSET(%rsp)
14922@@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
14923 /* no need to do an access_ok check here because r8 has been
14924 32bit zero extended */
14925 /* hardware stack frame is complete now */
14926+
14927+#ifdef CONFIG_PAX_MEMORY_UDEREF
14928+ ASM_PAX_OPEN_USERLAND
14929+ movq pax_user_shadow_base,%r8
14930+ addq RSP-ARGOFFSET(%rsp),%r8
14931+#endif
14932+
14933 ASM_STAC
14934 1: movl (%r8),%r9d
14935 _ASM_EXTABLE(1b,ia32_badarg)
14936 ASM_CLAC
14937- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14938- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14939+
14940+#ifdef CONFIG_PAX_MEMORY_UDEREF
14941+ ASM_PAX_CLOSE_USERLAND
14942+#endif
14943+
14944+ GET_THREAD_INFO(%r11)
14945+ orl $TS_COMPAT,TI_status(%r11)
14946+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14947 CFI_REMEMBER_STATE
14948 jnz cstar_tracesys
14949 cmpq $IA32_NR_syscalls-1,%rax
14950@@ -319,13 +395,16 @@ cstar_do_call:
14951 cstar_dispatch:
14952 call *ia32_sys_call_table(,%rax,8)
14953 movq %rax,RAX-ARGOFFSET(%rsp)
14954+ GET_THREAD_INFO(%r11)
14955 DISABLE_INTERRUPTS(CLBR_NONE)
14956 TRACE_IRQS_OFF
14957- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14958+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14959 jnz sysretl_audit
14960 sysretl_from_sys_call:
14961- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14962- RESTORE_ARGS 0,-ARG_SKIP,0,0,0
14963+ pax_exit_kernel_user
14964+ pax_erase_kstack
14965+ andl $~TS_COMPAT,TI_status(%r11)
14966+ RESTORE_ARGS 0,-ORIG_RAX,0,0,0
14967 movl RIP-ARGOFFSET(%rsp),%ecx
14968 CFI_REGISTER rip,rcx
14969 movl EFLAGS-ARGOFFSET(%rsp),%r11d
14970@@ -352,7 +431,7 @@ sysretl_audit:
14971
14972 cstar_tracesys:
14973 #ifdef CONFIG_AUDITSYSCALL
14974- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14975+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14976 jz cstar_auditsys
14977 #endif
14978 xchgl %r9d,%ebp
14979@@ -366,11 +445,19 @@ cstar_tracesys:
14980 xchgl %ebp,%r9d
14981 cmpq $(IA32_NR_syscalls-1),%rax
14982 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
14983+
14984+ pax_erase_kstack
14985+
14986 jmp cstar_do_call
14987 END(ia32_cstar_target)
14988
14989 ia32_badarg:
14990 ASM_CLAC
14991+
14992+#ifdef CONFIG_PAX_MEMORY_UDEREF
14993+ ASM_PAX_CLOSE_USERLAND
14994+#endif
14995+
14996 movq $-EFAULT,%rax
14997 jmp ia32_sysret
14998 CFI_ENDPROC
14999@@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
15000 CFI_REL_OFFSET rip,RIP-RIP
15001 PARAVIRT_ADJUST_EXCEPTION_FRAME
15002 SWAPGS
15003- /*
15004- * No need to follow this irqs on/off section: the syscall
15005- * disabled irqs and here we enable it straight after entry:
15006- */
15007- ENABLE_INTERRUPTS(CLBR_NONE)
15008 movl %eax,%eax
15009 pushq_cfi %rax
15010 cld
15011 /* note the registers are not zero extended to the sf.
15012 this could be a problem. */
15013 SAVE_ARGS 0,1,0
15014- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15015- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15016+ pax_enter_kernel_user
15017+
15018+#ifdef CONFIG_PAX_RANDKSTACK
15019+ pax_erase_kstack
15020+#endif
15021+
15022+ /*
15023+ * No need to follow this irqs on/off section: the syscall
15024+ * disabled irqs and here we enable it straight after entry:
15025+ */
15026+ ENABLE_INTERRUPTS(CLBR_NONE)
15027+ GET_THREAD_INFO(%r11)
15028+ orl $TS_COMPAT,TI_status(%r11)
15029+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
15030 jnz ia32_tracesys
15031 cmpq $(IA32_NR_syscalls-1),%rax
15032 ja ia32_badsys
15033@@ -442,6 +536,9 @@ ia32_tracesys:
15034 RESTORE_REST
15035 cmpq $(IA32_NR_syscalls-1),%rax
15036 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
15037+
15038+ pax_erase_kstack
15039+
15040 jmp ia32_do_call
15041 END(ia32_syscall)
15042
15043diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
15044index 8e0ceec..af13504 100644
15045--- a/arch/x86/ia32/sys_ia32.c
15046+++ b/arch/x86/ia32/sys_ia32.c
15047@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
15048 */
15049 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
15050 {
15051- typeof(ubuf->st_uid) uid = 0;
15052- typeof(ubuf->st_gid) gid = 0;
15053+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
15054+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
15055 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
15056 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
15057 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
15058diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
15059index 372231c..51b537d 100644
15060--- a/arch/x86/include/asm/alternative-asm.h
15061+++ b/arch/x86/include/asm/alternative-asm.h
15062@@ -18,6 +18,45 @@
15063 .endm
15064 #endif
15065
15066+#ifdef KERNEXEC_PLUGIN
15067+ .macro pax_force_retaddr_bts rip=0
15068+ btsq $63,\rip(%rsp)
15069+ .endm
15070+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
15071+ .macro pax_force_retaddr rip=0, reload=0
15072+ btsq $63,\rip(%rsp)
15073+ .endm
15074+ .macro pax_force_fptr ptr
15075+ btsq $63,\ptr
15076+ .endm
15077+ .macro pax_set_fptr_mask
15078+ .endm
15079+#endif
15080+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15081+ .macro pax_force_retaddr rip=0, reload=0
15082+ .if \reload
15083+ pax_set_fptr_mask
15084+ .endif
15085+ orq %r12,\rip(%rsp)
15086+ .endm
15087+ .macro pax_force_fptr ptr
15088+ orq %r12,\ptr
15089+ .endm
15090+ .macro pax_set_fptr_mask
15091+ movabs $0x8000000000000000,%r12
15092+ .endm
15093+#endif
15094+#else
15095+ .macro pax_force_retaddr rip=0, reload=0
15096+ .endm
15097+ .macro pax_force_fptr ptr
15098+ .endm
15099+ .macro pax_force_retaddr_bts rip=0
15100+ .endm
15101+ .macro pax_set_fptr_mask
15102+ .endm
15103+#endif
15104+
15105 .macro altinstruction_entry orig alt feature orig_len alt_len
15106 .long \orig - .
15107 .long \alt - .
15108diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
15109index 0a3f9c9..c9d081d 100644
15110--- a/arch/x86/include/asm/alternative.h
15111+++ b/arch/x86/include/asm/alternative.h
15112@@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15113 ".pushsection .discard,\"aw\",@progbits\n" \
15114 DISCARD_ENTRY(1) \
15115 ".popsection\n" \
15116- ".pushsection .altinstr_replacement, \"ax\"\n" \
15117+ ".pushsection .altinstr_replacement, \"a\"\n" \
15118 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
15119 ".popsection"
15120
15121@@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15122 DISCARD_ENTRY(1) \
15123 DISCARD_ENTRY(2) \
15124 ".popsection\n" \
15125- ".pushsection .altinstr_replacement, \"ax\"\n" \
15126+ ".pushsection .altinstr_replacement, \"a\"\n" \
15127 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
15128 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
15129 ".popsection"
15130diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
15131index 1d2091a..f5074c1 100644
15132--- a/arch/x86/include/asm/apic.h
15133+++ b/arch/x86/include/asm/apic.h
15134@@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
15135
15136 #ifdef CONFIG_X86_LOCAL_APIC
15137
15138-extern unsigned int apic_verbosity;
15139+extern int apic_verbosity;
15140 extern int local_apic_timer_c2_ok;
15141
15142 extern int disable_apic;
15143diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
15144index 20370c6..a2eb9b0 100644
15145--- a/arch/x86/include/asm/apm.h
15146+++ b/arch/x86/include/asm/apm.h
15147@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
15148 __asm__ __volatile__(APM_DO_ZERO_SEGS
15149 "pushl %%edi\n\t"
15150 "pushl %%ebp\n\t"
15151- "lcall *%%cs:apm_bios_entry\n\t"
15152+ "lcall *%%ss:apm_bios_entry\n\t"
15153 "setc %%al\n\t"
15154 "popl %%ebp\n\t"
15155 "popl %%edi\n\t"
15156@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
15157 __asm__ __volatile__(APM_DO_ZERO_SEGS
15158 "pushl %%edi\n\t"
15159 "pushl %%ebp\n\t"
15160- "lcall *%%cs:apm_bios_entry\n\t"
15161+ "lcall *%%ss:apm_bios_entry\n\t"
15162 "setc %%bl\n\t"
15163 "popl %%ebp\n\t"
15164 "popl %%edi\n\t"
15165diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
15166index b17f4f4..9620151 100644
15167--- a/arch/x86/include/asm/atomic.h
15168+++ b/arch/x86/include/asm/atomic.h
15169@@ -23,7 +23,18 @@
15170 */
15171 static inline int atomic_read(const atomic_t *v)
15172 {
15173- return (*(volatile int *)&(v)->counter);
15174+ return (*(volatile const int *)&(v)->counter);
15175+}
15176+
15177+/**
15178+ * atomic_read_unchecked - read atomic variable
15179+ * @v: pointer of type atomic_unchecked_t
15180+ *
15181+ * Atomically reads the value of @v.
15182+ */
15183+static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
15184+{
15185+ return (*(volatile const int *)&(v)->counter);
15186 }
15187
15188 /**
15189@@ -39,6 +50,18 @@ static inline void atomic_set(atomic_t *v, int i)
15190 }
15191
15192 /**
15193+ * atomic_set_unchecked - set atomic variable
15194+ * @v: pointer of type atomic_unchecked_t
15195+ * @i: required value
15196+ *
15197+ * Atomically sets the value of @v to @i.
15198+ */
15199+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
15200+{
15201+ v->counter = i;
15202+}
15203+
15204+/**
15205 * atomic_add - add integer to atomic variable
15206 * @i: integer value to add
15207 * @v: pointer of type atomic_t
15208@@ -47,7 +70,29 @@ static inline void atomic_set(atomic_t *v, int i)
15209 */
15210 static inline void atomic_add(int i, atomic_t *v)
15211 {
15212- asm volatile(LOCK_PREFIX "addl %1,%0"
15213+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
15214+
15215+#ifdef CONFIG_PAX_REFCOUNT
15216+ "jno 0f\n"
15217+ LOCK_PREFIX "subl %1,%0\n"
15218+ "int $4\n0:\n"
15219+ _ASM_EXTABLE(0b, 0b)
15220+#endif
15221+
15222+ : "+m" (v->counter)
15223+ : "ir" (i));
15224+}
15225+
15226+/**
15227+ * atomic_add_unchecked - add integer to atomic variable
15228+ * @i: integer value to add
15229+ * @v: pointer of type atomic_unchecked_t
15230+ *
15231+ * Atomically adds @i to @v.
15232+ */
15233+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
15234+{
15235+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
15236 : "+m" (v->counter)
15237 : "ir" (i));
15238 }
15239@@ -61,7 +106,29 @@ static inline void atomic_add(int i, atomic_t *v)
15240 */
15241 static inline void atomic_sub(int i, atomic_t *v)
15242 {
15243- asm volatile(LOCK_PREFIX "subl %1,%0"
15244+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
15245+
15246+#ifdef CONFIG_PAX_REFCOUNT
15247+ "jno 0f\n"
15248+ LOCK_PREFIX "addl %1,%0\n"
15249+ "int $4\n0:\n"
15250+ _ASM_EXTABLE(0b, 0b)
15251+#endif
15252+
15253+ : "+m" (v->counter)
15254+ : "ir" (i));
15255+}
15256+
15257+/**
15258+ * atomic_sub_unchecked - subtract integer from atomic variable
15259+ * @i: integer value to subtract
15260+ * @v: pointer of type atomic_unchecked_t
15261+ *
15262+ * Atomically subtracts @i from @v.
15263+ */
15264+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
15265+{
15266+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
15267 : "+m" (v->counter)
15268 : "ir" (i));
15269 }
15270@@ -77,7 +144,7 @@ static inline void atomic_sub(int i, atomic_t *v)
15271 */
15272 static inline int atomic_sub_and_test(int i, atomic_t *v)
15273 {
15274- GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
15275+ GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
15276 }
15277
15278 /**
15279@@ -88,7 +155,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
15280 */
15281 static inline void atomic_inc(atomic_t *v)
15282 {
15283- asm volatile(LOCK_PREFIX "incl %0"
15284+ asm volatile(LOCK_PREFIX "incl %0\n"
15285+
15286+#ifdef CONFIG_PAX_REFCOUNT
15287+ "jno 0f\n"
15288+ LOCK_PREFIX "decl %0\n"
15289+ "int $4\n0:\n"
15290+ _ASM_EXTABLE(0b, 0b)
15291+#endif
15292+
15293+ : "+m" (v->counter));
15294+}
15295+
15296+/**
15297+ * atomic_inc_unchecked - increment atomic variable
15298+ * @v: pointer of type atomic_unchecked_t
15299+ *
15300+ * Atomically increments @v by 1.
15301+ */
15302+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
15303+{
15304+ asm volatile(LOCK_PREFIX "incl %0\n"
15305 : "+m" (v->counter));
15306 }
15307
15308@@ -100,7 +187,27 @@ static inline void atomic_inc(atomic_t *v)
15309 */
15310 static inline void atomic_dec(atomic_t *v)
15311 {
15312- asm volatile(LOCK_PREFIX "decl %0"
15313+ asm volatile(LOCK_PREFIX "decl %0\n"
15314+
15315+#ifdef CONFIG_PAX_REFCOUNT
15316+ "jno 0f\n"
15317+ LOCK_PREFIX "incl %0\n"
15318+ "int $4\n0:\n"
15319+ _ASM_EXTABLE(0b, 0b)
15320+#endif
15321+
15322+ : "+m" (v->counter));
15323+}
15324+
15325+/**
15326+ * atomic_dec_unchecked - decrement atomic variable
15327+ * @v: pointer of type atomic_unchecked_t
15328+ *
15329+ * Atomically decrements @v by 1.
15330+ */
15331+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
15332+{
15333+ asm volatile(LOCK_PREFIX "decl %0\n"
15334 : "+m" (v->counter));
15335 }
15336
15337@@ -114,7 +221,7 @@ static inline void atomic_dec(atomic_t *v)
15338 */
15339 static inline int atomic_dec_and_test(atomic_t *v)
15340 {
15341- GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
15342+ GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
15343 }
15344
15345 /**
15346@@ -127,7 +234,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
15347 */
15348 static inline int atomic_inc_and_test(atomic_t *v)
15349 {
15350- GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
15351+ GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
15352+}
15353+
15354+/**
15355+ * atomic_inc_and_test_unchecked - increment and test
15356+ * @v: pointer of type atomic_unchecked_t
15357+ *
15358+ * Atomically increments @v by 1
15359+ * and returns true if the result is zero, or false for all
15360+ * other cases.
15361+ */
15362+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
15363+{
15364+ GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
15365 }
15366
15367 /**
15368@@ -141,7 +261,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
15369 */
15370 static inline int atomic_add_negative(int i, atomic_t *v)
15371 {
15372- GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
15373+ GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
15374 }
15375
15376 /**
15377@@ -153,6 +273,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
15378 */
15379 static inline int atomic_add_return(int i, atomic_t *v)
15380 {
15381+ return i + xadd_check_overflow(&v->counter, i);
15382+}
15383+
15384+/**
15385+ * atomic_add_return_unchecked - add integer and return
15386+ * @i: integer value to add
15387+ * @v: pointer of type atomic_unchecked_t
15388+ *
15389+ * Atomically adds @i to @v and returns @i + @v
15390+ */
15391+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
15392+{
15393 return i + xadd(&v->counter, i);
15394 }
15395
15396@@ -169,9 +301,18 @@ static inline int atomic_sub_return(int i, atomic_t *v)
15397 }
15398
15399 #define atomic_inc_return(v) (atomic_add_return(1, v))
15400+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
15401+{
15402+ return atomic_add_return_unchecked(1, v);
15403+}
15404 #define atomic_dec_return(v) (atomic_sub_return(1, v))
15405
15406-static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
15407+static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
15408+{
15409+ return cmpxchg(&v->counter, old, new);
15410+}
15411+
15412+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
15413 {
15414 return cmpxchg(&v->counter, old, new);
15415 }
15416@@ -181,6 +322,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
15417 return xchg(&v->counter, new);
15418 }
15419
15420+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
15421+{
15422+ return xchg(&v->counter, new);
15423+}
15424+
15425 /**
15426 * __atomic_add_unless - add unless the number is already a given value
15427 * @v: pointer of type atomic_t
15428@@ -190,14 +336,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
15429 * Atomically adds @a to @v, so long as @v was not already @u.
15430 * Returns the old value of @v.
15431 */
15432-static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15433+static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
15434 {
15435- int c, old;
15436+ int c, old, new;
15437 c = atomic_read(v);
15438 for (;;) {
15439- if (unlikely(c == (u)))
15440+ if (unlikely(c == u))
15441 break;
15442- old = atomic_cmpxchg((v), c, c + (a));
15443+
15444+ asm volatile("addl %2,%0\n"
15445+
15446+#ifdef CONFIG_PAX_REFCOUNT
15447+ "jno 0f\n"
15448+ "subl %2,%0\n"
15449+ "int $4\n0:\n"
15450+ _ASM_EXTABLE(0b, 0b)
15451+#endif
15452+
15453+ : "=r" (new)
15454+ : "0" (c), "ir" (a));
15455+
15456+ old = atomic_cmpxchg(v, c, new);
15457 if (likely(old == c))
15458 break;
15459 c = old;
15460@@ -206,6 +365,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15461 }
15462
15463 /**
15464+ * atomic_inc_not_zero_hint - increment if not null
15465+ * @v: pointer of type atomic_t
15466+ * @hint: probable value of the atomic before the increment
15467+ *
15468+ * This version of atomic_inc_not_zero() gives a hint of probable
15469+ * value of the atomic. This helps processor to not read the memory
15470+ * before doing the atomic read/modify/write cycle, lowering
15471+ * number of bus transactions on some arches.
15472+ *
15473+ * Returns: 0 if increment was not done, 1 otherwise.
15474+ */
15475+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
15476+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
15477+{
15478+ int val, c = hint, new;
15479+
15480+ /* sanity test, should be removed by compiler if hint is a constant */
15481+ if (!hint)
15482+ return __atomic_add_unless(v, 1, 0);
15483+
15484+ do {
15485+ asm volatile("incl %0\n"
15486+
15487+#ifdef CONFIG_PAX_REFCOUNT
15488+ "jno 0f\n"
15489+ "decl %0\n"
15490+ "int $4\n0:\n"
15491+ _ASM_EXTABLE(0b, 0b)
15492+#endif
15493+
15494+ : "=r" (new)
15495+ : "0" (c));
15496+
15497+ val = atomic_cmpxchg(v, c, new);
15498+ if (val == c)
15499+ return 1;
15500+ c = val;
15501+ } while (c);
15502+
15503+ return 0;
15504+}
15505+
15506+/**
15507 * atomic_inc_short - increment of a short integer
15508 * @v: pointer to type int
15509 *
15510@@ -234,14 +436,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
15511 #endif
15512
15513 /* These are x86-specific, used by some header files */
15514-#define atomic_clear_mask(mask, addr) \
15515- asm volatile(LOCK_PREFIX "andl %0,%1" \
15516- : : "r" (~(mask)), "m" (*(addr)) : "memory")
15517+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
15518+{
15519+ asm volatile(LOCK_PREFIX "andl %1,%0"
15520+ : "+m" (v->counter)
15521+ : "r" (~(mask))
15522+ : "memory");
15523+}
15524
15525-#define atomic_set_mask(mask, addr) \
15526- asm volatile(LOCK_PREFIX "orl %0,%1" \
15527- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
15528- : "memory")
15529+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15530+{
15531+ asm volatile(LOCK_PREFIX "andl %1,%0"
15532+ : "+m" (v->counter)
15533+ : "r" (~(mask))
15534+ : "memory");
15535+}
15536+
15537+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
15538+{
15539+ asm volatile(LOCK_PREFIX "orl %1,%0"
15540+ : "+m" (v->counter)
15541+ : "r" (mask)
15542+ : "memory");
15543+}
15544+
15545+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15546+{
15547+ asm volatile(LOCK_PREFIX "orl %1,%0"
15548+ : "+m" (v->counter)
15549+ : "r" (mask)
15550+ : "memory");
15551+}
15552
15553 /* Atomic operations are already serializing on x86 */
15554 #define smp_mb__before_atomic_dec() barrier()
15555diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
15556index b154de7..bf18a5a 100644
15557--- a/arch/x86/include/asm/atomic64_32.h
15558+++ b/arch/x86/include/asm/atomic64_32.h
15559@@ -12,6 +12,14 @@ typedef struct {
15560 u64 __aligned(8) counter;
15561 } atomic64_t;
15562
15563+#ifdef CONFIG_PAX_REFCOUNT
15564+typedef struct {
15565+ u64 __aligned(8) counter;
15566+} atomic64_unchecked_t;
15567+#else
15568+typedef atomic64_t atomic64_unchecked_t;
15569+#endif
15570+
15571 #define ATOMIC64_INIT(val) { (val) }
15572
15573 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
15574@@ -37,21 +45,31 @@ typedef struct {
15575 ATOMIC64_DECL_ONE(sym##_386)
15576
15577 ATOMIC64_DECL_ONE(add_386);
15578+ATOMIC64_DECL_ONE(add_unchecked_386);
15579 ATOMIC64_DECL_ONE(sub_386);
15580+ATOMIC64_DECL_ONE(sub_unchecked_386);
15581 ATOMIC64_DECL_ONE(inc_386);
15582+ATOMIC64_DECL_ONE(inc_unchecked_386);
15583 ATOMIC64_DECL_ONE(dec_386);
15584+ATOMIC64_DECL_ONE(dec_unchecked_386);
15585 #endif
15586
15587 #define alternative_atomic64(f, out, in...) \
15588 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
15589
15590 ATOMIC64_DECL(read);
15591+ATOMIC64_DECL(read_unchecked);
15592 ATOMIC64_DECL(set);
15593+ATOMIC64_DECL(set_unchecked);
15594 ATOMIC64_DECL(xchg);
15595 ATOMIC64_DECL(add_return);
15596+ATOMIC64_DECL(add_return_unchecked);
15597 ATOMIC64_DECL(sub_return);
15598+ATOMIC64_DECL(sub_return_unchecked);
15599 ATOMIC64_DECL(inc_return);
15600+ATOMIC64_DECL(inc_return_unchecked);
15601 ATOMIC64_DECL(dec_return);
15602+ATOMIC64_DECL(dec_return_unchecked);
15603 ATOMIC64_DECL(dec_if_positive);
15604 ATOMIC64_DECL(inc_not_zero);
15605 ATOMIC64_DECL(add_unless);
15606@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
15607 }
15608
15609 /**
15610+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
15611+ * @p: pointer to type atomic64_unchecked_t
15612+ * @o: expected value
15613+ * @n: new value
15614+ *
15615+ * Atomically sets @v to @n if it was equal to @o and returns
15616+ * the old value.
15617+ */
15618+
15619+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
15620+{
15621+ return cmpxchg64(&v->counter, o, n);
15622+}
15623+
15624+/**
15625 * atomic64_xchg - xchg atomic64 variable
15626 * @v: pointer to type atomic64_t
15627 * @n: value to assign
15628@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
15629 }
15630
15631 /**
15632+ * atomic64_set_unchecked - set atomic64 variable
15633+ * @v: pointer to type atomic64_unchecked_t
15634+ * @n: value to assign
15635+ *
15636+ * Atomically sets the value of @v to @n.
15637+ */
15638+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
15639+{
15640+ unsigned high = (unsigned)(i >> 32);
15641+ unsigned low = (unsigned)i;
15642+ alternative_atomic64(set, /* no output */,
15643+ "S" (v), "b" (low), "c" (high)
15644+ : "eax", "edx", "memory");
15645+}
15646+
15647+/**
15648 * atomic64_read - read atomic64 variable
15649 * @v: pointer to type atomic64_t
15650 *
15651@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
15652 }
15653
15654 /**
15655+ * atomic64_read_unchecked - read atomic64 variable
15656+ * @v: pointer to type atomic64_unchecked_t
15657+ *
15658+ * Atomically reads the value of @v and returns it.
15659+ */
15660+static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
15661+{
15662+ long long r;
15663+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
15664+ return r;
15665+ }
15666+
15667+/**
15668 * atomic64_add_return - add and return
15669 * @i: integer value to add
15670 * @v: pointer to type atomic64_t
15671@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
15672 return i;
15673 }
15674
15675+/**
15676+ * atomic64_add_return_unchecked - add and return
15677+ * @i: integer value to add
15678+ * @v: pointer to type atomic64_unchecked_t
15679+ *
15680+ * Atomically adds @i to @v and returns @i + *@v
15681+ */
15682+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
15683+{
15684+ alternative_atomic64(add_return_unchecked,
15685+ ASM_OUTPUT2("+A" (i), "+c" (v)),
15686+ ASM_NO_INPUT_CLOBBER("memory"));
15687+ return i;
15688+}
15689+
15690 /*
15691 * Other variants with different arithmetic operators:
15692 */
15693@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
15694 return a;
15695 }
15696
15697+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15698+{
15699+ long long a;
15700+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
15701+ "S" (v) : "memory", "ecx");
15702+ return a;
15703+}
15704+
15705 static inline long long atomic64_dec_return(atomic64_t *v)
15706 {
15707 long long a;
15708@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
15709 }
15710
15711 /**
15712+ * atomic64_add_unchecked - add integer to atomic64 variable
15713+ * @i: integer value to add
15714+ * @v: pointer to type atomic64_unchecked_t
15715+ *
15716+ * Atomically adds @i to @v.
15717+ */
15718+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
15719+{
15720+ __alternative_atomic64(add_unchecked, add_return_unchecked,
15721+ ASM_OUTPUT2("+A" (i), "+c" (v)),
15722+ ASM_NO_INPUT_CLOBBER("memory"));
15723+ return i;
15724+}
15725+
15726+/**
15727 * atomic64_sub - subtract the atomic64 variable
15728 * @i: integer value to subtract
15729 * @v: pointer to type atomic64_t
15730diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
15731index 46e9052..ae45136 100644
15732--- a/arch/x86/include/asm/atomic64_64.h
15733+++ b/arch/x86/include/asm/atomic64_64.h
15734@@ -18,7 +18,19 @@
15735 */
15736 static inline long atomic64_read(const atomic64_t *v)
15737 {
15738- return (*(volatile long *)&(v)->counter);
15739+ return (*(volatile const long *)&(v)->counter);
15740+}
15741+
15742+/**
15743+ * atomic64_read_unchecked - read atomic64 variable
15744+ * @v: pointer of type atomic64_unchecked_t
15745+ *
15746+ * Atomically reads the value of @v.
15747+ * Doesn't imply a read memory barrier.
15748+ */
15749+static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
15750+{
15751+ return (*(volatile const long *)&(v)->counter);
15752 }
15753
15754 /**
15755@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
15756 }
15757
15758 /**
15759+ * atomic64_set_unchecked - set atomic64 variable
15760+ * @v: pointer to type atomic64_unchecked_t
15761+ * @i: required value
15762+ *
15763+ * Atomically sets the value of @v to @i.
15764+ */
15765+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
15766+{
15767+ v->counter = i;
15768+}
15769+
15770+/**
15771 * atomic64_add - add integer to atomic64 variable
15772 * @i: integer value to add
15773 * @v: pointer to type atomic64_t
15774@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
15775 */
15776 static inline void atomic64_add(long i, atomic64_t *v)
15777 {
15778+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
15779+
15780+#ifdef CONFIG_PAX_REFCOUNT
15781+ "jno 0f\n"
15782+ LOCK_PREFIX "subq %1,%0\n"
15783+ "int $4\n0:\n"
15784+ _ASM_EXTABLE(0b, 0b)
15785+#endif
15786+
15787+ : "=m" (v->counter)
15788+ : "er" (i), "m" (v->counter));
15789+}
15790+
15791+/**
15792+ * atomic64_add_unchecked - add integer to atomic64 variable
15793+ * @i: integer value to add
15794+ * @v: pointer to type atomic64_unchecked_t
15795+ *
15796+ * Atomically adds @i to @v.
15797+ */
15798+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
15799+{
15800 asm volatile(LOCK_PREFIX "addq %1,%0"
15801 : "=m" (v->counter)
15802 : "er" (i), "m" (v->counter));
15803@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
15804 */
15805 static inline void atomic64_sub(long i, atomic64_t *v)
15806 {
15807- asm volatile(LOCK_PREFIX "subq %1,%0"
15808+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
15809+
15810+#ifdef CONFIG_PAX_REFCOUNT
15811+ "jno 0f\n"
15812+ LOCK_PREFIX "addq %1,%0\n"
15813+ "int $4\n0:\n"
15814+ _ASM_EXTABLE(0b, 0b)
15815+#endif
15816+
15817+ : "=m" (v->counter)
15818+ : "er" (i), "m" (v->counter));
15819+}
15820+
15821+/**
15822+ * atomic64_sub_unchecked - subtract the atomic64 variable
15823+ * @i: integer value to subtract
15824+ * @v: pointer to type atomic64_unchecked_t
15825+ *
15826+ * Atomically subtracts @i from @v.
15827+ */
15828+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
15829+{
15830+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
15831 : "=m" (v->counter)
15832 : "er" (i), "m" (v->counter));
15833 }
15834@@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
15835 */
15836 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15837 {
15838- GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
15839+ GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
15840 }
15841
15842 /**
15843@@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15844 */
15845 static inline void atomic64_inc(atomic64_t *v)
15846 {
15847+ asm volatile(LOCK_PREFIX "incq %0\n"
15848+
15849+#ifdef CONFIG_PAX_REFCOUNT
15850+ "jno 0f\n"
15851+ LOCK_PREFIX "decq %0\n"
15852+ "int $4\n0:\n"
15853+ _ASM_EXTABLE(0b, 0b)
15854+#endif
15855+
15856+ : "=m" (v->counter)
15857+ : "m" (v->counter));
15858+}
15859+
15860+/**
15861+ * atomic64_inc_unchecked - increment atomic64 variable
15862+ * @v: pointer to type atomic64_unchecked_t
15863+ *
15864+ * Atomically increments @v by 1.
15865+ */
15866+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
15867+{
15868 asm volatile(LOCK_PREFIX "incq %0"
15869 : "=m" (v->counter)
15870 : "m" (v->counter));
15871@@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
15872 */
15873 static inline void atomic64_dec(atomic64_t *v)
15874 {
15875- asm volatile(LOCK_PREFIX "decq %0"
15876+ asm volatile(LOCK_PREFIX "decq %0\n"
15877+
15878+#ifdef CONFIG_PAX_REFCOUNT
15879+ "jno 0f\n"
15880+ LOCK_PREFIX "incq %0\n"
15881+ "int $4\n0:\n"
15882+ _ASM_EXTABLE(0b, 0b)
15883+#endif
15884+
15885+ : "=m" (v->counter)
15886+ : "m" (v->counter));
15887+}
15888+
15889+/**
15890+ * atomic64_dec_unchecked - decrement atomic64 variable
15891+ * @v: pointer to type atomic64_t
15892+ *
15893+ * Atomically decrements @v by 1.
15894+ */
15895+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
15896+{
15897+ asm volatile(LOCK_PREFIX "decq %0\n"
15898 : "=m" (v->counter)
15899 : "m" (v->counter));
15900 }
15901@@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
15902 */
15903 static inline int atomic64_dec_and_test(atomic64_t *v)
15904 {
15905- GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
15906+ GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
15907 }
15908
15909 /**
15910@@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
15911 */
15912 static inline int atomic64_inc_and_test(atomic64_t *v)
15913 {
15914- GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
15915+ GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
15916 }
15917
15918 /**
15919@@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
15920 */
15921 static inline int atomic64_add_negative(long i, atomic64_t *v)
15922 {
15923- GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
15924+ GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
15925 }
15926
15927 /**
15928@@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
15929 */
15930 static inline long atomic64_add_return(long i, atomic64_t *v)
15931 {
15932+ return i + xadd_check_overflow(&v->counter, i);
15933+}
15934+
15935+/**
15936+ * atomic64_add_return_unchecked - add and return
15937+ * @i: integer value to add
15938+ * @v: pointer to type atomic64_unchecked_t
15939+ *
15940+ * Atomically adds @i to @v and returns @i + @v
15941+ */
15942+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
15943+{
15944 return i + xadd(&v->counter, i);
15945 }
15946
15947@@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
15948 }
15949
15950 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
15951+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15952+{
15953+ return atomic64_add_return_unchecked(1, v);
15954+}
15955 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
15956
15957 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15958@@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15959 return cmpxchg(&v->counter, old, new);
15960 }
15961
15962+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
15963+{
15964+ return cmpxchg(&v->counter, old, new);
15965+}
15966+
15967 static inline long atomic64_xchg(atomic64_t *v, long new)
15968 {
15969 return xchg(&v->counter, new);
15970@@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
15971 */
15972 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
15973 {
15974- long c, old;
15975+ long c, old, new;
15976 c = atomic64_read(v);
15977 for (;;) {
15978- if (unlikely(c == (u)))
15979+ if (unlikely(c == u))
15980 break;
15981- old = atomic64_cmpxchg((v), c, c + (a));
15982+
15983+ asm volatile("add %2,%0\n"
15984+
15985+#ifdef CONFIG_PAX_REFCOUNT
15986+ "jno 0f\n"
15987+ "sub %2,%0\n"
15988+ "int $4\n0:\n"
15989+ _ASM_EXTABLE(0b, 0b)
15990+#endif
15991+
15992+ : "=r" (new)
15993+ : "0" (c), "ir" (a));
15994+
15995+ old = atomic64_cmpxchg(v, c, new);
15996 if (likely(old == c))
15997 break;
15998 c = old;
15999 }
16000- return c != (u);
16001+ return c != u;
16002 }
16003
16004 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
16005diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
16006index 9fc1af7..fc71228 100644
16007--- a/arch/x86/include/asm/bitops.h
16008+++ b/arch/x86/include/asm/bitops.h
16009@@ -49,7 +49,7 @@
16010 * a mask operation on a byte.
16011 */
16012 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
16013-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
16014+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
16015 #define CONST_MASK(nr) (1 << ((nr) & 7))
16016
16017 /**
16018@@ -205,7 +205,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
16019 */
16020 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
16021 {
16022- GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16023+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16024 }
16025
16026 /**
16027@@ -251,7 +251,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
16028 */
16029 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
16030 {
16031- GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16032+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16033 }
16034
16035 /**
16036@@ -304,7 +304,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
16037 */
16038 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
16039 {
16040- GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16041+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16042 }
16043
16044 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
16045@@ -345,7 +345,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
16046 *
16047 * Undefined if no bit exists, so code should check against 0 first.
16048 */
16049-static inline unsigned long __ffs(unsigned long word)
16050+static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
16051 {
16052 asm("rep; bsf %1,%0"
16053 : "=r" (word)
16054@@ -359,7 +359,7 @@ static inline unsigned long __ffs(unsigned long word)
16055 *
16056 * Undefined if no zero exists, so code should check against ~0UL first.
16057 */
16058-static inline unsigned long ffz(unsigned long word)
16059+static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
16060 {
16061 asm("rep; bsf %1,%0"
16062 : "=r" (word)
16063@@ -373,7 +373,7 @@ static inline unsigned long ffz(unsigned long word)
16064 *
16065 * Undefined if no set bit exists, so code should check against 0 first.
16066 */
16067-static inline unsigned long __fls(unsigned long word)
16068+static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
16069 {
16070 asm("bsr %1,%0"
16071 : "=r" (word)
16072@@ -436,7 +436,7 @@ static inline int ffs(int x)
16073 * set bit if value is nonzero. The last (most significant) bit is
16074 * at position 32.
16075 */
16076-static inline int fls(int x)
16077+static inline int __intentional_overflow(-1) fls(int x)
16078 {
16079 int r;
16080
16081@@ -478,7 +478,7 @@ static inline int fls(int x)
16082 * at position 64.
16083 */
16084 #ifdef CONFIG_X86_64
16085-static __always_inline int fls64(__u64 x)
16086+static __always_inline long fls64(__u64 x)
16087 {
16088 int bitpos = -1;
16089 /*
16090diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
16091index 4fa687a..60f2d39 100644
16092--- a/arch/x86/include/asm/boot.h
16093+++ b/arch/x86/include/asm/boot.h
16094@@ -6,10 +6,15 @@
16095 #include <uapi/asm/boot.h>
16096
16097 /* Physical address where kernel should be loaded. */
16098-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16099+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16100 + (CONFIG_PHYSICAL_ALIGN - 1)) \
16101 & ~(CONFIG_PHYSICAL_ALIGN - 1))
16102
16103+#ifndef __ASSEMBLY__
16104+extern unsigned char __LOAD_PHYSICAL_ADDR[];
16105+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
16106+#endif
16107+
16108 /* Minimum kernel alignment, as a power of two */
16109 #ifdef CONFIG_X86_64
16110 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
16111diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
16112index 48f99f1..d78ebf9 100644
16113--- a/arch/x86/include/asm/cache.h
16114+++ b/arch/x86/include/asm/cache.h
16115@@ -5,12 +5,13 @@
16116
16117 /* L1 cache line size */
16118 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
16119-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
16120+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
16121
16122 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
16123+#define __read_only __attribute__((__section__(".data..read_only")))
16124
16125 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
16126-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
16127+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
16128
16129 #ifdef CONFIG_X86_VSMP
16130 #ifdef CONFIG_SMP
16131diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
16132index 9863ee3..4a1f8e1 100644
16133--- a/arch/x86/include/asm/cacheflush.h
16134+++ b/arch/x86/include/asm/cacheflush.h
16135@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
16136 unsigned long pg_flags = pg->flags & _PGMT_MASK;
16137
16138 if (pg_flags == _PGMT_DEFAULT)
16139- return -1;
16140+ return ~0UL;
16141 else if (pg_flags == _PGMT_WC)
16142 return _PAGE_CACHE_WC;
16143 else if (pg_flags == _PGMT_UC_MINUS)
16144diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
16145index cb4c73b..c473c29 100644
16146--- a/arch/x86/include/asm/calling.h
16147+++ b/arch/x86/include/asm/calling.h
16148@@ -82,103 +82,113 @@ For 32-bit we have the following conventions - kernel is built with
16149 #define RSP 152
16150 #define SS 160
16151
16152-#define ARGOFFSET R11
16153-#define SWFRAME ORIG_RAX
16154+#define ARGOFFSET R15
16155
16156 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
16157- subq $9*8+\addskip, %rsp
16158- CFI_ADJUST_CFA_OFFSET 9*8+\addskip
16159- movq_cfi rdi, 8*8
16160- movq_cfi rsi, 7*8
16161- movq_cfi rdx, 6*8
16162+ subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
16163+ CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
16164+ movq_cfi rdi, RDI
16165+ movq_cfi rsi, RSI
16166+ movq_cfi rdx, RDX
16167
16168 .if \save_rcx
16169- movq_cfi rcx, 5*8
16170+ movq_cfi rcx, RCX
16171 .endif
16172
16173- movq_cfi rax, 4*8
16174+ movq_cfi rax, RAX
16175
16176 .if \save_r891011
16177- movq_cfi r8, 3*8
16178- movq_cfi r9, 2*8
16179- movq_cfi r10, 1*8
16180- movq_cfi r11, 0*8
16181+ movq_cfi r8, R8
16182+ movq_cfi r9, R9
16183+ movq_cfi r10, R10
16184+ movq_cfi r11, R11
16185 .endif
16186
16187+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16188+ movq_cfi r12, R12
16189+#endif
16190+
16191 .endm
16192
16193-#define ARG_SKIP (9*8)
16194+#define ARG_SKIP ORIG_RAX
16195
16196 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
16197 rstor_r8910=1, rstor_rdx=1
16198+
16199+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16200+ movq_cfi_restore R12, r12
16201+#endif
16202+
16203 .if \rstor_r11
16204- movq_cfi_restore 0*8, r11
16205+ movq_cfi_restore R11, r11
16206 .endif
16207
16208 .if \rstor_r8910
16209- movq_cfi_restore 1*8, r10
16210- movq_cfi_restore 2*8, r9
16211- movq_cfi_restore 3*8, r8
16212+ movq_cfi_restore R10, r10
16213+ movq_cfi_restore R9, r9
16214+ movq_cfi_restore R8, r8
16215 .endif
16216
16217 .if \rstor_rax
16218- movq_cfi_restore 4*8, rax
16219+ movq_cfi_restore RAX, rax
16220 .endif
16221
16222 .if \rstor_rcx
16223- movq_cfi_restore 5*8, rcx
16224+ movq_cfi_restore RCX, rcx
16225 .endif
16226
16227 .if \rstor_rdx
16228- movq_cfi_restore 6*8, rdx
16229+ movq_cfi_restore RDX, rdx
16230 .endif
16231
16232- movq_cfi_restore 7*8, rsi
16233- movq_cfi_restore 8*8, rdi
16234+ movq_cfi_restore RSI, rsi
16235+ movq_cfi_restore RDI, rdi
16236
16237- .if ARG_SKIP+\addskip > 0
16238- addq $ARG_SKIP+\addskip, %rsp
16239- CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
16240+ .if ORIG_RAX+\addskip > 0
16241+ addq $ORIG_RAX+\addskip, %rsp
16242+ CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
16243 .endif
16244 .endm
16245
16246- .macro LOAD_ARGS offset, skiprax=0
16247- movq \offset(%rsp), %r11
16248- movq \offset+8(%rsp), %r10
16249- movq \offset+16(%rsp), %r9
16250- movq \offset+24(%rsp), %r8
16251- movq \offset+40(%rsp), %rcx
16252- movq \offset+48(%rsp), %rdx
16253- movq \offset+56(%rsp), %rsi
16254- movq \offset+64(%rsp), %rdi
16255+ .macro LOAD_ARGS skiprax=0
16256+ movq R11(%rsp), %r11
16257+ movq R10(%rsp), %r10
16258+ movq R9(%rsp), %r9
16259+ movq R8(%rsp), %r8
16260+ movq RCX(%rsp), %rcx
16261+ movq RDX(%rsp), %rdx
16262+ movq RSI(%rsp), %rsi
16263+ movq RDI(%rsp), %rdi
16264 .if \skiprax
16265 .else
16266- movq \offset+72(%rsp), %rax
16267+ movq RAX(%rsp), %rax
16268 .endif
16269 .endm
16270
16271-#define REST_SKIP (6*8)
16272-
16273 .macro SAVE_REST
16274- subq $REST_SKIP, %rsp
16275- CFI_ADJUST_CFA_OFFSET REST_SKIP
16276- movq_cfi rbx, 5*8
16277- movq_cfi rbp, 4*8
16278- movq_cfi r12, 3*8
16279- movq_cfi r13, 2*8
16280- movq_cfi r14, 1*8
16281- movq_cfi r15, 0*8
16282+ movq_cfi rbx, RBX
16283+ movq_cfi rbp, RBP
16284+
16285+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16286+ movq_cfi r12, R12
16287+#endif
16288+
16289+ movq_cfi r13, R13
16290+ movq_cfi r14, R14
16291+ movq_cfi r15, R15
16292 .endm
16293
16294 .macro RESTORE_REST
16295- movq_cfi_restore 0*8, r15
16296- movq_cfi_restore 1*8, r14
16297- movq_cfi_restore 2*8, r13
16298- movq_cfi_restore 3*8, r12
16299- movq_cfi_restore 4*8, rbp
16300- movq_cfi_restore 5*8, rbx
16301- addq $REST_SKIP, %rsp
16302- CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
16303+ movq_cfi_restore R15, r15
16304+ movq_cfi_restore R14, r14
16305+ movq_cfi_restore R13, r13
16306+
16307+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16308+ movq_cfi_restore R12, r12
16309+#endif
16310+
16311+ movq_cfi_restore RBP, rbp
16312+ movq_cfi_restore RBX, rbx
16313 .endm
16314
16315 .macro SAVE_ALL
16316diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
16317index f50de69..2b0a458 100644
16318--- a/arch/x86/include/asm/checksum_32.h
16319+++ b/arch/x86/include/asm/checksum_32.h
16320@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
16321 int len, __wsum sum,
16322 int *src_err_ptr, int *dst_err_ptr);
16323
16324+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
16325+ int len, __wsum sum,
16326+ int *src_err_ptr, int *dst_err_ptr);
16327+
16328+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
16329+ int len, __wsum sum,
16330+ int *src_err_ptr, int *dst_err_ptr);
16331+
16332 /*
16333 * Note: when you get a NULL pointer exception here this means someone
16334 * passed in an incorrect kernel address to one of these functions.
16335@@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
16336
16337 might_sleep();
16338 stac();
16339- ret = csum_partial_copy_generic((__force void *)src, dst,
16340+ ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
16341 len, sum, err_ptr, NULL);
16342 clac();
16343
16344@@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
16345 might_sleep();
16346 if (access_ok(VERIFY_WRITE, dst, len)) {
16347 stac();
16348- ret = csum_partial_copy_generic(src, (__force void *)dst,
16349+ ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
16350 len, sum, NULL, err_ptr);
16351 clac();
16352 return ret;
16353diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
16354index d47786a..2d8883e 100644
16355--- a/arch/x86/include/asm/cmpxchg.h
16356+++ b/arch/x86/include/asm/cmpxchg.h
16357@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
16358 __compiletime_error("Bad argument size for cmpxchg");
16359 extern void __xadd_wrong_size(void)
16360 __compiletime_error("Bad argument size for xadd");
16361+extern void __xadd_check_overflow_wrong_size(void)
16362+ __compiletime_error("Bad argument size for xadd_check_overflow");
16363 extern void __add_wrong_size(void)
16364 __compiletime_error("Bad argument size for add");
16365+extern void __add_check_overflow_wrong_size(void)
16366+ __compiletime_error("Bad argument size for add_check_overflow");
16367
16368 /*
16369 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
16370@@ -67,6 +71,38 @@ extern void __add_wrong_size(void)
16371 __ret; \
16372 })
16373
16374+#ifdef CONFIG_PAX_REFCOUNT
16375+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
16376+ ({ \
16377+ __typeof__ (*(ptr)) __ret = (arg); \
16378+ switch (sizeof(*(ptr))) { \
16379+ case __X86_CASE_L: \
16380+ asm volatile (lock #op "l %0, %1\n" \
16381+ "jno 0f\n" \
16382+ "mov %0,%1\n" \
16383+ "int $4\n0:\n" \
16384+ _ASM_EXTABLE(0b, 0b) \
16385+ : "+r" (__ret), "+m" (*(ptr)) \
16386+ : : "memory", "cc"); \
16387+ break; \
16388+ case __X86_CASE_Q: \
16389+ asm volatile (lock #op "q %q0, %1\n" \
16390+ "jno 0f\n" \
16391+ "mov %0,%1\n" \
16392+ "int $4\n0:\n" \
16393+ _ASM_EXTABLE(0b, 0b) \
16394+ : "+r" (__ret), "+m" (*(ptr)) \
16395+ : : "memory", "cc"); \
16396+ break; \
16397+ default: \
16398+ __ ## op ## _check_overflow_wrong_size(); \
16399+ } \
16400+ __ret; \
16401+ })
16402+#else
16403+#define __xchg_op_check_overflow(ptr, arg, op, lock) __xchg_op(ptr, arg, op, lock)
16404+#endif
16405+
16406 /*
16407 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
16408 * Since this is generally used to protect other memory information, we
16409@@ -167,6 +203,9 @@ extern void __add_wrong_size(void)
16410 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
16411 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
16412
16413+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
16414+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
16415+
16416 #define __add(ptr, inc, lock) \
16417 ({ \
16418 __typeof__ (*(ptr)) __ret = (inc); \
16419diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
16420index 59c6c40..5e0b22c 100644
16421--- a/arch/x86/include/asm/compat.h
16422+++ b/arch/x86/include/asm/compat.h
16423@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
16424 typedef u32 compat_uint_t;
16425 typedef u32 compat_ulong_t;
16426 typedef u64 __attribute__((aligned(4))) compat_u64;
16427-typedef u32 compat_uptr_t;
16428+typedef u32 __user compat_uptr_t;
16429
16430 struct compat_timespec {
16431 compat_time_t tv_sec;
16432diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
16433index 5f12968..a383517 100644
16434--- a/arch/x86/include/asm/cpufeature.h
16435+++ b/arch/x86/include/asm/cpufeature.h
16436@@ -203,7 +203,7 @@
16437 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
16438 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
16439 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
16440-
16441+#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
16442
16443 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
16444 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
16445@@ -211,7 +211,7 @@
16446 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
16447 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
16448 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
16449-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
16450+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
16451 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
16452 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
16453 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
16454@@ -358,6 +358,7 @@ extern const char * const x86_power_flags[32];
16455 #undef cpu_has_centaur_mcr
16456 #define cpu_has_centaur_mcr 0
16457
16458+#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
16459 #endif /* CONFIG_X86_64 */
16460
16461 #if __GNUC__ >= 4
16462@@ -410,7 +411,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16463
16464 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
16465 t_warn:
16466- warn_pre_alternatives();
16467+ if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
16468+ warn_pre_alternatives();
16469 return false;
16470 #endif
16471
16472@@ -430,7 +432,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16473 ".section .discard,\"aw\",@progbits\n"
16474 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16475 ".previous\n"
16476- ".section .altinstr_replacement,\"ax\"\n"
16477+ ".section .altinstr_replacement,\"a\"\n"
16478 "3: movb $1,%0\n"
16479 "4:\n"
16480 ".previous\n"
16481@@ -467,7 +469,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16482 " .byte 2b - 1b\n" /* src len */
16483 " .byte 4f - 3f\n" /* repl len */
16484 ".previous\n"
16485- ".section .altinstr_replacement,\"ax\"\n"
16486+ ".section .altinstr_replacement,\"a\"\n"
16487 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
16488 "4:\n"
16489 ".previous\n"
16490@@ -500,7 +502,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16491 ".section .discard,\"aw\",@progbits\n"
16492 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16493 ".previous\n"
16494- ".section .altinstr_replacement,\"ax\"\n"
16495+ ".section .altinstr_replacement,\"a\"\n"
16496 "3: movb $0,%0\n"
16497 "4:\n"
16498 ".previous\n"
16499@@ -514,7 +516,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16500 ".section .discard,\"aw\",@progbits\n"
16501 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
16502 ".previous\n"
16503- ".section .altinstr_replacement,\"ax\"\n"
16504+ ".section .altinstr_replacement,\"a\"\n"
16505 "5: movb $1,%0\n"
16506 "6:\n"
16507 ".previous\n"
16508diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
16509index 50d033a..37deb26 100644
16510--- a/arch/x86/include/asm/desc.h
16511+++ b/arch/x86/include/asm/desc.h
16512@@ -4,6 +4,7 @@
16513 #include <asm/desc_defs.h>
16514 #include <asm/ldt.h>
16515 #include <asm/mmu.h>
16516+#include <asm/pgtable.h>
16517
16518 #include <linux/smp.h>
16519 #include <linux/percpu.h>
16520@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16521
16522 desc->type = (info->read_exec_only ^ 1) << 1;
16523 desc->type |= info->contents << 2;
16524+ desc->type |= info->seg_not_present ^ 1;
16525
16526 desc->s = 1;
16527 desc->dpl = 0x3;
16528@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16529 }
16530
16531 extern struct desc_ptr idt_descr;
16532-extern gate_desc idt_table[];
16533-extern struct desc_ptr debug_idt_descr;
16534-extern gate_desc debug_idt_table[];
16535-
16536-struct gdt_page {
16537- struct desc_struct gdt[GDT_ENTRIES];
16538-} __attribute__((aligned(PAGE_SIZE)));
16539-
16540-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
16541+extern gate_desc idt_table[IDT_ENTRIES];
16542+extern const struct desc_ptr debug_idt_descr;
16543+extern gate_desc debug_idt_table[IDT_ENTRIES];
16544
16545+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
16546 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
16547 {
16548- return per_cpu(gdt_page, cpu).gdt;
16549+ return cpu_gdt_table[cpu];
16550 }
16551
16552 #ifdef CONFIG_X86_64
16553@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
16554 unsigned long base, unsigned dpl, unsigned flags,
16555 unsigned short seg)
16556 {
16557- gate->a = (seg << 16) | (base & 0xffff);
16558- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
16559+ gate->gate.offset_low = base;
16560+ gate->gate.seg = seg;
16561+ gate->gate.reserved = 0;
16562+ gate->gate.type = type;
16563+ gate->gate.s = 0;
16564+ gate->gate.dpl = dpl;
16565+ gate->gate.p = 1;
16566+ gate->gate.offset_high = base >> 16;
16567 }
16568
16569 #endif
16570@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
16571
16572 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
16573 {
16574+ pax_open_kernel();
16575 memcpy(&idt[entry], gate, sizeof(*gate));
16576+ pax_close_kernel();
16577 }
16578
16579 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
16580 {
16581+ pax_open_kernel();
16582 memcpy(&ldt[entry], desc, 8);
16583+ pax_close_kernel();
16584 }
16585
16586 static inline void
16587@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
16588 default: size = sizeof(*gdt); break;
16589 }
16590
16591+ pax_open_kernel();
16592 memcpy(&gdt[entry], desc, size);
16593+ pax_close_kernel();
16594 }
16595
16596 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
16597@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
16598
16599 static inline void native_load_tr_desc(void)
16600 {
16601+ pax_open_kernel();
16602 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
16603+ pax_close_kernel();
16604 }
16605
16606 static inline void native_load_gdt(const struct desc_ptr *dtr)
16607@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
16608 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
16609 unsigned int i;
16610
16611+ pax_open_kernel();
16612 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
16613 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
16614+ pax_close_kernel();
16615 }
16616
16617 #define _LDT_empty(info) \
16618@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
16619 preempt_enable();
16620 }
16621
16622-static inline unsigned long get_desc_base(const struct desc_struct *desc)
16623+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
16624 {
16625 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
16626 }
16627@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
16628 }
16629
16630 #ifdef CONFIG_X86_64
16631-static inline void set_nmi_gate(int gate, void *addr)
16632+static inline void set_nmi_gate(int gate, const void *addr)
16633 {
16634 gate_desc s;
16635
16636@@ -321,14 +334,14 @@ static inline void set_nmi_gate(int gate, void *addr)
16637 #endif
16638
16639 #ifdef CONFIG_TRACING
16640-extern struct desc_ptr trace_idt_descr;
16641-extern gate_desc trace_idt_table[];
16642+extern const struct desc_ptr trace_idt_descr;
16643+extern gate_desc trace_idt_table[IDT_ENTRIES];
16644 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16645 {
16646 write_idt_entry(trace_idt_table, entry, gate);
16647 }
16648
16649-static inline void _trace_set_gate(int gate, unsigned type, void *addr,
16650+static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
16651 unsigned dpl, unsigned ist, unsigned seg)
16652 {
16653 gate_desc s;
16654@@ -348,7 +361,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16655 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
16656 #endif
16657
16658-static inline void _set_gate(int gate, unsigned type, void *addr,
16659+static inline void _set_gate(int gate, unsigned type, const void *addr,
16660 unsigned dpl, unsigned ist, unsigned seg)
16661 {
16662 gate_desc s;
16663@@ -371,9 +384,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
16664 #define set_intr_gate(n, addr) \
16665 do { \
16666 BUG_ON((unsigned)n > 0xFF); \
16667- _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
16668+ _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
16669 __KERNEL_CS); \
16670- _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
16671+ _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
16672 0, 0, __KERNEL_CS); \
16673 } while (0)
16674
16675@@ -401,19 +414,19 @@ static inline void alloc_system_vector(int vector)
16676 /*
16677 * This routine sets up an interrupt gate at directory privilege level 3.
16678 */
16679-static inline void set_system_intr_gate(unsigned int n, void *addr)
16680+static inline void set_system_intr_gate(unsigned int n, const void *addr)
16681 {
16682 BUG_ON((unsigned)n > 0xFF);
16683 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
16684 }
16685
16686-static inline void set_system_trap_gate(unsigned int n, void *addr)
16687+static inline void set_system_trap_gate(unsigned int n, const void *addr)
16688 {
16689 BUG_ON((unsigned)n > 0xFF);
16690 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
16691 }
16692
16693-static inline void set_trap_gate(unsigned int n, void *addr)
16694+static inline void set_trap_gate(unsigned int n, const void *addr)
16695 {
16696 BUG_ON((unsigned)n > 0xFF);
16697 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
16698@@ -422,16 +435,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
16699 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
16700 {
16701 BUG_ON((unsigned)n > 0xFF);
16702- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
16703+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
16704 }
16705
16706-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
16707+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
16708 {
16709 BUG_ON((unsigned)n > 0xFF);
16710 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
16711 }
16712
16713-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
16714+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
16715 {
16716 BUG_ON((unsigned)n > 0xFF);
16717 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
16718@@ -503,4 +516,17 @@ static inline void load_current_idt(void)
16719 else
16720 load_idt((const struct desc_ptr *)&idt_descr);
16721 }
16722+
16723+#ifdef CONFIG_X86_32
16724+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
16725+{
16726+ struct desc_struct d;
16727+
16728+ if (likely(limit))
16729+ limit = (limit - 1UL) >> PAGE_SHIFT;
16730+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
16731+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
16732+}
16733+#endif
16734+
16735 #endif /* _ASM_X86_DESC_H */
16736diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
16737index 278441f..b95a174 100644
16738--- a/arch/x86/include/asm/desc_defs.h
16739+++ b/arch/x86/include/asm/desc_defs.h
16740@@ -31,6 +31,12 @@ struct desc_struct {
16741 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
16742 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
16743 };
16744+ struct {
16745+ u16 offset_low;
16746+ u16 seg;
16747+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
16748+ unsigned offset_high: 16;
16749+ } gate;
16750 };
16751 } __attribute__((packed));
16752
16753diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
16754index ced283a..ffe04cc 100644
16755--- a/arch/x86/include/asm/div64.h
16756+++ b/arch/x86/include/asm/div64.h
16757@@ -39,7 +39,7 @@
16758 __mod; \
16759 })
16760
16761-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16762+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16763 {
16764 union {
16765 u64 v64;
16766diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
16767index 9c999c1..3860cb8 100644
16768--- a/arch/x86/include/asm/elf.h
16769+++ b/arch/x86/include/asm/elf.h
16770@@ -243,7 +243,25 @@ extern int force_personality32;
16771 the loader. We need to make sure that it is out of the way of the program
16772 that it will "exec", and that there is sufficient room for the brk. */
16773
16774+#ifdef CONFIG_PAX_SEGMEXEC
16775+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
16776+#else
16777 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
16778+#endif
16779+
16780+#ifdef CONFIG_PAX_ASLR
16781+#ifdef CONFIG_X86_32
16782+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
16783+
16784+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16785+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16786+#else
16787+#define PAX_ELF_ET_DYN_BASE 0x400000UL
16788+
16789+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16790+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16791+#endif
16792+#endif
16793
16794 /* This yields a mask that user programs can use to figure out what
16795 instruction set this CPU supports. This could be done in user space,
16796@@ -296,16 +314,12 @@ do { \
16797
16798 #define ARCH_DLINFO \
16799 do { \
16800- if (vdso_enabled) \
16801- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16802- (unsigned long)current->mm->context.vdso); \
16803+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16804 } while (0)
16805
16806 #define ARCH_DLINFO_X32 \
16807 do { \
16808- if (vdso_enabled) \
16809- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16810- (unsigned long)current->mm->context.vdso); \
16811+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16812 } while (0)
16813
16814 #define AT_SYSINFO 32
16815@@ -320,7 +334,7 @@ else \
16816
16817 #endif /* !CONFIG_X86_32 */
16818
16819-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
16820+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
16821
16822 #define VDSO_ENTRY \
16823 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
16824@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
16825 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
16826 #define compat_arch_setup_additional_pages syscall32_setup_pages
16827
16828-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
16829-#define arch_randomize_brk arch_randomize_brk
16830-
16831 /*
16832 * True on X86_32 or when emulating IA32 on X86_64
16833 */
16834diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
16835index 77a99ac..39ff7f5 100644
16836--- a/arch/x86/include/asm/emergency-restart.h
16837+++ b/arch/x86/include/asm/emergency-restart.h
16838@@ -1,6 +1,6 @@
16839 #ifndef _ASM_X86_EMERGENCY_RESTART_H
16840 #define _ASM_X86_EMERGENCY_RESTART_H
16841
16842-extern void machine_emergency_restart(void);
16843+extern void machine_emergency_restart(void) __noreturn;
16844
16845 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
16846diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
16847index d3d7469..677ef72 100644
16848--- a/arch/x86/include/asm/floppy.h
16849+++ b/arch/x86/include/asm/floppy.h
16850@@ -229,18 +229,18 @@ static struct fd_routine_l {
16851 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
16852 } fd_routine[] = {
16853 {
16854- request_dma,
16855- free_dma,
16856- get_dma_residue,
16857- dma_mem_alloc,
16858- hard_dma_setup
16859+ ._request_dma = request_dma,
16860+ ._free_dma = free_dma,
16861+ ._get_dma_residue = get_dma_residue,
16862+ ._dma_mem_alloc = dma_mem_alloc,
16863+ ._dma_setup = hard_dma_setup
16864 },
16865 {
16866- vdma_request_dma,
16867- vdma_nop,
16868- vdma_get_dma_residue,
16869- vdma_mem_alloc,
16870- vdma_dma_setup
16871+ ._request_dma = vdma_request_dma,
16872+ ._free_dma = vdma_nop,
16873+ ._get_dma_residue = vdma_get_dma_residue,
16874+ ._dma_mem_alloc = vdma_mem_alloc,
16875+ ._dma_setup = vdma_dma_setup
16876 }
16877 };
16878
16879diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
16880index cea1c76..6c0d79b 100644
16881--- a/arch/x86/include/asm/fpu-internal.h
16882+++ b/arch/x86/include/asm/fpu-internal.h
16883@@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16884 #define user_insn(insn, output, input...) \
16885 ({ \
16886 int err; \
16887+ pax_open_userland(); \
16888 asm volatile(ASM_STAC "\n" \
16889- "1:" #insn "\n\t" \
16890+ "1:" \
16891+ __copyuser_seg \
16892+ #insn "\n\t" \
16893 "2: " ASM_CLAC "\n" \
16894 ".section .fixup,\"ax\"\n" \
16895 "3: movl $-1,%[err]\n" \
16896@@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16897 _ASM_EXTABLE(1b, 3b) \
16898 : [err] "=r" (err), output \
16899 : "0"(0), input); \
16900+ pax_close_userland(); \
16901 err; \
16902 })
16903
16904@@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
16905 "fnclex\n\t"
16906 "emms\n\t"
16907 "fildl %P[addr]" /* set F?P to defined value */
16908- : : [addr] "m" (tsk->thread.fpu.has_fpu));
16909+ : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
16910 }
16911
16912 return fpu_restore_checking(&tsk->thread.fpu);
16913diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
16914index b4c1f54..e290c08 100644
16915--- a/arch/x86/include/asm/futex.h
16916+++ b/arch/x86/include/asm/futex.h
16917@@ -12,6 +12,7 @@
16918 #include <asm/smap.h>
16919
16920 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
16921+ typecheck(u32 __user *, uaddr); \
16922 asm volatile("\t" ASM_STAC "\n" \
16923 "1:\t" insn "\n" \
16924 "2:\t" ASM_CLAC "\n" \
16925@@ -20,15 +21,16 @@
16926 "\tjmp\t2b\n" \
16927 "\t.previous\n" \
16928 _ASM_EXTABLE(1b, 3b) \
16929- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
16930+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
16931 : "i" (-EFAULT), "0" (oparg), "1" (0))
16932
16933 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
16934+ typecheck(u32 __user *, uaddr); \
16935 asm volatile("\t" ASM_STAC "\n" \
16936 "1:\tmovl %2, %0\n" \
16937 "\tmovl\t%0, %3\n" \
16938 "\t" insn "\n" \
16939- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
16940+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
16941 "\tjnz\t1b\n" \
16942 "3:\t" ASM_CLAC "\n" \
16943 "\t.section .fixup,\"ax\"\n" \
16944@@ -38,7 +40,7 @@
16945 _ASM_EXTABLE(1b, 4b) \
16946 _ASM_EXTABLE(2b, 4b) \
16947 : "=&a" (oldval), "=&r" (ret), \
16948- "+m" (*uaddr), "=&r" (tem) \
16949+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
16950 : "r" (oparg), "i" (-EFAULT), "1" (0))
16951
16952 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16953@@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16954
16955 pagefault_disable();
16956
16957+ pax_open_userland();
16958 switch (op) {
16959 case FUTEX_OP_SET:
16960- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
16961+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
16962 break;
16963 case FUTEX_OP_ADD:
16964- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
16965+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
16966 uaddr, oparg);
16967 break;
16968 case FUTEX_OP_OR:
16969@@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16970 default:
16971 ret = -ENOSYS;
16972 }
16973+ pax_close_userland();
16974
16975 pagefault_enable();
16976
16977diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
16978index 67d69b8..50e4b77 100644
16979--- a/arch/x86/include/asm/hw_irq.h
16980+++ b/arch/x86/include/asm/hw_irq.h
16981@@ -165,8 +165,8 @@ extern void setup_ioapic_dest(void);
16982 extern void enable_IO_APIC(void);
16983
16984 /* Statistics */
16985-extern atomic_t irq_err_count;
16986-extern atomic_t irq_mis_count;
16987+extern atomic_unchecked_t irq_err_count;
16988+extern atomic_unchecked_t irq_mis_count;
16989
16990 /* EISA */
16991 extern void eisa_set_level_irq(unsigned int irq);
16992diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
16993index a203659..9889f1c 100644
16994--- a/arch/x86/include/asm/i8259.h
16995+++ b/arch/x86/include/asm/i8259.h
16996@@ -62,7 +62,7 @@ struct legacy_pic {
16997 void (*init)(int auto_eoi);
16998 int (*irq_pending)(unsigned int irq);
16999 void (*make_irq)(unsigned int irq);
17000-};
17001+} __do_const;
17002
17003 extern struct legacy_pic *legacy_pic;
17004 extern struct legacy_pic null_legacy_pic;
17005diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
17006index 91d9c69..dfae7d0 100644
17007--- a/arch/x86/include/asm/io.h
17008+++ b/arch/x86/include/asm/io.h
17009@@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
17010 "m" (*(volatile type __force *)addr) barrier); }
17011
17012 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
17013-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
17014-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
17015+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
17016+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
17017
17018 build_mmio_read(__readb, "b", unsigned char, "=q", )
17019-build_mmio_read(__readw, "w", unsigned short, "=r", )
17020-build_mmio_read(__readl, "l", unsigned int, "=r", )
17021+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
17022+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
17023
17024 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
17025 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
17026@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
17027 return ioremap_nocache(offset, size);
17028 }
17029
17030-extern void iounmap(volatile void __iomem *addr);
17031+extern void iounmap(const volatile void __iomem *addr);
17032
17033 extern void set_iounmap_nonlazy(void);
17034
17035@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
17036
17037 #include <linux/vmalloc.h>
17038
17039+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
17040+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
17041+{
17042+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17043+}
17044+
17045+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
17046+{
17047+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17048+}
17049+
17050 /*
17051 * Convert a virtual cached pointer to an uncached pointer
17052 */
17053diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
17054index bba3cf8..06bc8da 100644
17055--- a/arch/x86/include/asm/irqflags.h
17056+++ b/arch/x86/include/asm/irqflags.h
17057@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
17058 sti; \
17059 sysexit
17060
17061+#define GET_CR0_INTO_RDI mov %cr0, %rdi
17062+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
17063+#define GET_CR3_INTO_RDI mov %cr3, %rdi
17064+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
17065+
17066 #else
17067 #define INTERRUPT_RETURN iret
17068 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
17069diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
17070index 9454c16..e4100e3 100644
17071--- a/arch/x86/include/asm/kprobes.h
17072+++ b/arch/x86/include/asm/kprobes.h
17073@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
17074 #define RELATIVEJUMP_SIZE 5
17075 #define RELATIVECALL_OPCODE 0xe8
17076 #define RELATIVE_ADDR_SIZE 4
17077-#define MAX_STACK_SIZE 64
17078-#define MIN_STACK_SIZE(ADDR) \
17079- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
17080- THREAD_SIZE - (unsigned long)(ADDR))) \
17081- ? (MAX_STACK_SIZE) \
17082- : (((unsigned long)current_thread_info()) + \
17083- THREAD_SIZE - (unsigned long)(ADDR)))
17084+#define MAX_STACK_SIZE 64UL
17085+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
17086
17087 #define flush_insn_slot(p) do { } while (0)
17088
17089diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
17090index 4ad6560..75c7bdd 100644
17091--- a/arch/x86/include/asm/local.h
17092+++ b/arch/x86/include/asm/local.h
17093@@ -10,33 +10,97 @@ typedef struct {
17094 atomic_long_t a;
17095 } local_t;
17096
17097+typedef struct {
17098+ atomic_long_unchecked_t a;
17099+} local_unchecked_t;
17100+
17101 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
17102
17103 #define local_read(l) atomic_long_read(&(l)->a)
17104+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
17105 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
17106+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
17107
17108 static inline void local_inc(local_t *l)
17109 {
17110- asm volatile(_ASM_INC "%0"
17111+ asm volatile(_ASM_INC "%0\n"
17112+
17113+#ifdef CONFIG_PAX_REFCOUNT
17114+ "jno 0f\n"
17115+ _ASM_DEC "%0\n"
17116+ "int $4\n0:\n"
17117+ _ASM_EXTABLE(0b, 0b)
17118+#endif
17119+
17120+ : "+m" (l->a.counter));
17121+}
17122+
17123+static inline void local_inc_unchecked(local_unchecked_t *l)
17124+{
17125+ asm volatile(_ASM_INC "%0\n"
17126 : "+m" (l->a.counter));
17127 }
17128
17129 static inline void local_dec(local_t *l)
17130 {
17131- asm volatile(_ASM_DEC "%0"
17132+ asm volatile(_ASM_DEC "%0\n"
17133+
17134+#ifdef CONFIG_PAX_REFCOUNT
17135+ "jno 0f\n"
17136+ _ASM_INC "%0\n"
17137+ "int $4\n0:\n"
17138+ _ASM_EXTABLE(0b, 0b)
17139+#endif
17140+
17141+ : "+m" (l->a.counter));
17142+}
17143+
17144+static inline void local_dec_unchecked(local_unchecked_t *l)
17145+{
17146+ asm volatile(_ASM_DEC "%0\n"
17147 : "+m" (l->a.counter));
17148 }
17149
17150 static inline void local_add(long i, local_t *l)
17151 {
17152- asm volatile(_ASM_ADD "%1,%0"
17153+ asm volatile(_ASM_ADD "%1,%0\n"
17154+
17155+#ifdef CONFIG_PAX_REFCOUNT
17156+ "jno 0f\n"
17157+ _ASM_SUB "%1,%0\n"
17158+ "int $4\n0:\n"
17159+ _ASM_EXTABLE(0b, 0b)
17160+#endif
17161+
17162+ : "+m" (l->a.counter)
17163+ : "ir" (i));
17164+}
17165+
17166+static inline void local_add_unchecked(long i, local_unchecked_t *l)
17167+{
17168+ asm volatile(_ASM_ADD "%1,%0\n"
17169 : "+m" (l->a.counter)
17170 : "ir" (i));
17171 }
17172
17173 static inline void local_sub(long i, local_t *l)
17174 {
17175- asm volatile(_ASM_SUB "%1,%0"
17176+ asm volatile(_ASM_SUB "%1,%0\n"
17177+
17178+#ifdef CONFIG_PAX_REFCOUNT
17179+ "jno 0f\n"
17180+ _ASM_ADD "%1,%0\n"
17181+ "int $4\n0:\n"
17182+ _ASM_EXTABLE(0b, 0b)
17183+#endif
17184+
17185+ : "+m" (l->a.counter)
17186+ : "ir" (i));
17187+}
17188+
17189+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
17190+{
17191+ asm volatile(_ASM_SUB "%1,%0\n"
17192 : "+m" (l->a.counter)
17193 : "ir" (i));
17194 }
17195@@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
17196 */
17197 static inline int local_sub_and_test(long i, local_t *l)
17198 {
17199- GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
17200+ GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
17201 }
17202
17203 /**
17204@@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
17205 */
17206 static inline int local_dec_and_test(local_t *l)
17207 {
17208- GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
17209+ GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
17210 }
17211
17212 /**
17213@@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
17214 */
17215 static inline int local_inc_and_test(local_t *l)
17216 {
17217- GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
17218+ GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
17219 }
17220
17221 /**
17222@@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
17223 */
17224 static inline int local_add_negative(long i, local_t *l)
17225 {
17226- GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
17227+ GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
17228 }
17229
17230 /**
17231@@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
17232 static inline long local_add_return(long i, local_t *l)
17233 {
17234 long __i = i;
17235+ asm volatile(_ASM_XADD "%0, %1\n"
17236+
17237+#ifdef CONFIG_PAX_REFCOUNT
17238+ "jno 0f\n"
17239+ _ASM_MOV "%0,%1\n"
17240+ "int $4\n0:\n"
17241+ _ASM_EXTABLE(0b, 0b)
17242+#endif
17243+
17244+ : "+r" (i), "+m" (l->a.counter)
17245+ : : "memory");
17246+ return i + __i;
17247+}
17248+
17249+/**
17250+ * local_add_return_unchecked - add and return
17251+ * @i: integer value to add
17252+ * @l: pointer to type local_unchecked_t
17253+ *
17254+ * Atomically adds @i to @l and returns @i + @l
17255+ */
17256+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
17257+{
17258+ long __i = i;
17259 asm volatile(_ASM_XADD "%0, %1;"
17260 : "+r" (i), "+m" (l->a.counter)
17261 : : "memory");
17262@@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
17263
17264 #define local_cmpxchg(l, o, n) \
17265 (cmpxchg_local(&((l)->a.counter), (o), (n)))
17266+#define local_cmpxchg_unchecked(l, o, n) \
17267+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
17268 /* Always has a lock prefix */
17269 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
17270
17271diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
17272new file mode 100644
17273index 0000000..2bfd3ba
17274--- /dev/null
17275+++ b/arch/x86/include/asm/mman.h
17276@@ -0,0 +1,15 @@
17277+#ifndef _X86_MMAN_H
17278+#define _X86_MMAN_H
17279+
17280+#include <uapi/asm/mman.h>
17281+
17282+#ifdef __KERNEL__
17283+#ifndef __ASSEMBLY__
17284+#ifdef CONFIG_X86_32
17285+#define arch_mmap_check i386_mmap_check
17286+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
17287+#endif
17288+#endif
17289+#endif
17290+
17291+#endif /* X86_MMAN_H */
17292diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
17293index 5f55e69..e20bfb1 100644
17294--- a/arch/x86/include/asm/mmu.h
17295+++ b/arch/x86/include/asm/mmu.h
17296@@ -9,7 +9,7 @@
17297 * we put the segment information here.
17298 */
17299 typedef struct {
17300- void *ldt;
17301+ struct desc_struct *ldt;
17302 int size;
17303
17304 #ifdef CONFIG_X86_64
17305@@ -18,7 +18,19 @@ typedef struct {
17306 #endif
17307
17308 struct mutex lock;
17309- void *vdso;
17310+ unsigned long vdso;
17311+
17312+#ifdef CONFIG_X86_32
17313+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17314+ unsigned long user_cs_base;
17315+ unsigned long user_cs_limit;
17316+
17317+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17318+ cpumask_t cpu_user_cs_mask;
17319+#endif
17320+
17321+#endif
17322+#endif
17323 } mm_context_t;
17324
17325 #ifdef CONFIG_SMP
17326diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
17327index be12c53..4d24039 100644
17328--- a/arch/x86/include/asm/mmu_context.h
17329+++ b/arch/x86/include/asm/mmu_context.h
17330@@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
17331
17332 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
17333 {
17334+
17335+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17336+ if (!(static_cpu_has(X86_FEATURE_PCID))) {
17337+ unsigned int i;
17338+ pgd_t *pgd;
17339+
17340+ pax_open_kernel();
17341+ pgd = get_cpu_pgd(smp_processor_id(), kernel);
17342+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
17343+ set_pgd_batched(pgd+i, native_make_pgd(0));
17344+ pax_close_kernel();
17345+ }
17346+#endif
17347+
17348 #ifdef CONFIG_SMP
17349 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
17350 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
17351@@ -34,16 +48,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17352 struct task_struct *tsk)
17353 {
17354 unsigned cpu = smp_processor_id();
17355+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17356+ int tlbstate = TLBSTATE_OK;
17357+#endif
17358
17359 if (likely(prev != next)) {
17360 #ifdef CONFIG_SMP
17361+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17362+ tlbstate = this_cpu_read(cpu_tlbstate.state);
17363+#endif
17364 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17365 this_cpu_write(cpu_tlbstate.active_mm, next);
17366 #endif
17367 cpumask_set_cpu(cpu, mm_cpumask(next));
17368
17369 /* Re-load page tables */
17370+#ifdef CONFIG_PAX_PER_CPU_PGD
17371+ pax_open_kernel();
17372+
17373+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17374+ if (static_cpu_has(X86_FEATURE_PCID))
17375+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17376+ else
17377+#endif
17378+
17379+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17380+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17381+ pax_close_kernel();
17382+ 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));
17383+
17384+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17385+ if (static_cpu_has(X86_FEATURE_PCID)) {
17386+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17387+ u64 descriptor[2];
17388+ descriptor[0] = PCID_USER;
17389+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17390+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17391+ descriptor[0] = PCID_KERNEL;
17392+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17393+ }
17394+ } else {
17395+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17396+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17397+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17398+ else
17399+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17400+ }
17401+ } else
17402+#endif
17403+
17404+ load_cr3(get_cpu_pgd(cpu, kernel));
17405+#else
17406 load_cr3(next->pgd);
17407+#endif
17408
17409 /* Stop flush ipis for the previous mm */
17410 cpumask_clear_cpu(cpu, mm_cpumask(prev));
17411@@ -51,9 +108,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17412 /* Load the LDT, if the LDT is different: */
17413 if (unlikely(prev->context.ldt != next->context.ldt))
17414 load_LDT_nolock(&next->context);
17415+
17416+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17417+ if (!(__supported_pte_mask & _PAGE_NX)) {
17418+ smp_mb__before_clear_bit();
17419+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
17420+ smp_mb__after_clear_bit();
17421+ cpu_set(cpu, next->context.cpu_user_cs_mask);
17422+ }
17423+#endif
17424+
17425+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17426+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
17427+ prev->context.user_cs_limit != next->context.user_cs_limit))
17428+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17429+#ifdef CONFIG_SMP
17430+ else if (unlikely(tlbstate != TLBSTATE_OK))
17431+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17432+#endif
17433+#endif
17434+
17435 }
17436+ else {
17437+
17438+#ifdef CONFIG_PAX_PER_CPU_PGD
17439+ pax_open_kernel();
17440+
17441+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17442+ if (static_cpu_has(X86_FEATURE_PCID))
17443+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17444+ else
17445+#endif
17446+
17447+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17448+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17449+ pax_close_kernel();
17450+ 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));
17451+
17452+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17453+ if (static_cpu_has(X86_FEATURE_PCID)) {
17454+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17455+ u64 descriptor[2];
17456+ descriptor[0] = PCID_USER;
17457+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17458+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17459+ descriptor[0] = PCID_KERNEL;
17460+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17461+ }
17462+ } else {
17463+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17464+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17465+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17466+ else
17467+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17468+ }
17469+ } else
17470+#endif
17471+
17472+ load_cr3(get_cpu_pgd(cpu, kernel));
17473+#endif
17474+
17475 #ifdef CONFIG_SMP
17476- else {
17477 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17478 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
17479
17480@@ -70,11 +185,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17481 * tlb flush IPI delivery. We must reload CR3
17482 * to make sure to use no freed page tables.
17483 */
17484+
17485+#ifndef CONFIG_PAX_PER_CPU_PGD
17486 load_cr3(next->pgd);
17487+#endif
17488+
17489 load_LDT_nolock(&next->context);
17490+
17491+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17492+ if (!(__supported_pte_mask & _PAGE_NX))
17493+ cpu_set(cpu, next->context.cpu_user_cs_mask);
17494+#endif
17495+
17496+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17497+#ifdef CONFIG_PAX_PAGEEXEC
17498+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
17499+#endif
17500+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17501+#endif
17502+
17503 }
17504+#endif
17505 }
17506-#endif
17507 }
17508
17509 #define activate_mm(prev, next) \
17510diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
17511index e3b7819..b257c64 100644
17512--- a/arch/x86/include/asm/module.h
17513+++ b/arch/x86/include/asm/module.h
17514@@ -5,6 +5,7 @@
17515
17516 #ifdef CONFIG_X86_64
17517 /* X86_64 does not define MODULE_PROC_FAMILY */
17518+#define MODULE_PROC_FAMILY ""
17519 #elif defined CONFIG_M486
17520 #define MODULE_PROC_FAMILY "486 "
17521 #elif defined CONFIG_M586
17522@@ -57,8 +58,20 @@
17523 #error unknown processor family
17524 #endif
17525
17526-#ifdef CONFIG_X86_32
17527-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
17528+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
17529+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
17530+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
17531+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
17532+#else
17533+#define MODULE_PAX_KERNEXEC ""
17534 #endif
17535
17536+#ifdef CONFIG_PAX_MEMORY_UDEREF
17537+#define MODULE_PAX_UDEREF "UDEREF "
17538+#else
17539+#define MODULE_PAX_UDEREF ""
17540+#endif
17541+
17542+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
17543+
17544 #endif /* _ASM_X86_MODULE_H */
17545diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
17546index 86f9301..b365cda 100644
17547--- a/arch/x86/include/asm/nmi.h
17548+++ b/arch/x86/include/asm/nmi.h
17549@@ -40,11 +40,11 @@ struct nmiaction {
17550 nmi_handler_t handler;
17551 unsigned long flags;
17552 const char *name;
17553-};
17554+} __do_const;
17555
17556 #define register_nmi_handler(t, fn, fg, n, init...) \
17557 ({ \
17558- static struct nmiaction init fn##_na = { \
17559+ static const struct nmiaction init fn##_na = { \
17560 .handler = (fn), \
17561 .name = (n), \
17562 .flags = (fg), \
17563@@ -52,7 +52,7 @@ struct nmiaction {
17564 __register_nmi_handler((t), &fn##_na); \
17565 })
17566
17567-int __register_nmi_handler(unsigned int, struct nmiaction *);
17568+int __register_nmi_handler(unsigned int, const struct nmiaction *);
17569
17570 void unregister_nmi_handler(unsigned int, const char *);
17571
17572diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
17573index 775873d..de5f0304 100644
17574--- a/arch/x86/include/asm/page.h
17575+++ b/arch/x86/include/asm/page.h
17576@@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17577 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
17578
17579 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
17580+#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
17581
17582 #define __boot_va(x) __va(x)
17583 #define __boot_pa(x) __pa(x)
17584diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
17585index 0f1ddee..e2fc3d1 100644
17586--- a/arch/x86/include/asm/page_64.h
17587+++ b/arch/x86/include/asm/page_64.h
17588@@ -7,9 +7,9 @@
17589
17590 /* duplicated to the one in bootmem.h */
17591 extern unsigned long max_pfn;
17592-extern unsigned long phys_base;
17593+extern const unsigned long phys_base;
17594
17595-static inline unsigned long __phys_addr_nodebug(unsigned long x)
17596+static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
17597 {
17598 unsigned long y = x - __START_KERNEL_map;
17599
17600diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
17601index cd6e1610..70f4418 100644
17602--- a/arch/x86/include/asm/paravirt.h
17603+++ b/arch/x86/include/asm/paravirt.h
17604@@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
17605 return (pmd_t) { ret };
17606 }
17607
17608-static inline pmdval_t pmd_val(pmd_t pmd)
17609+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
17610 {
17611 pmdval_t ret;
17612
17613@@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
17614 val);
17615 }
17616
17617+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17618+{
17619+ pgdval_t val = native_pgd_val(pgd);
17620+
17621+ if (sizeof(pgdval_t) > sizeof(long))
17622+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
17623+ val, (u64)val >> 32);
17624+ else
17625+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
17626+ val);
17627+}
17628+
17629 static inline void pgd_clear(pgd_t *pgdp)
17630 {
17631 set_pgd(pgdp, __pgd(0));
17632@@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
17633 pv_mmu_ops.set_fixmap(idx, phys, flags);
17634 }
17635
17636+#ifdef CONFIG_PAX_KERNEXEC
17637+static inline unsigned long pax_open_kernel(void)
17638+{
17639+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
17640+}
17641+
17642+static inline unsigned long pax_close_kernel(void)
17643+{
17644+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
17645+}
17646+#else
17647+static inline unsigned long pax_open_kernel(void) { return 0; }
17648+static inline unsigned long pax_close_kernel(void) { return 0; }
17649+#endif
17650+
17651 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
17652
17653 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
17654@@ -906,7 +933,7 @@ extern void default_banner(void);
17655
17656 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
17657 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
17658-#define PARA_INDIRECT(addr) *%cs:addr
17659+#define PARA_INDIRECT(addr) *%ss:addr
17660 #endif
17661
17662 #define INTERRUPT_RETURN \
17663@@ -981,6 +1008,21 @@ extern void default_banner(void);
17664 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
17665 CLBR_NONE, \
17666 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
17667+
17668+#define GET_CR0_INTO_RDI \
17669+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
17670+ mov %rax,%rdi
17671+
17672+#define SET_RDI_INTO_CR0 \
17673+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
17674+
17675+#define GET_CR3_INTO_RDI \
17676+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
17677+ mov %rax,%rdi
17678+
17679+#define SET_RDI_INTO_CR3 \
17680+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
17681+
17682 #endif /* CONFIG_X86_32 */
17683
17684 #endif /* __ASSEMBLY__ */
17685diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
17686index 7549b8b..f0edfda 100644
17687--- a/arch/x86/include/asm/paravirt_types.h
17688+++ b/arch/x86/include/asm/paravirt_types.h
17689@@ -84,7 +84,7 @@ struct pv_init_ops {
17690 */
17691 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
17692 unsigned long addr, unsigned len);
17693-};
17694+} __no_const __no_randomize_layout;
17695
17696
17697 struct pv_lazy_ops {
17698@@ -92,13 +92,13 @@ struct pv_lazy_ops {
17699 void (*enter)(void);
17700 void (*leave)(void);
17701 void (*flush)(void);
17702-};
17703+} __no_randomize_layout;
17704
17705 struct pv_time_ops {
17706 unsigned long long (*sched_clock)(void);
17707 unsigned long long (*steal_clock)(int cpu);
17708 unsigned long (*get_tsc_khz)(void);
17709-};
17710+} __no_const __no_randomize_layout;
17711
17712 struct pv_cpu_ops {
17713 /* hooks for various privileged instructions */
17714@@ -192,7 +192,7 @@ struct pv_cpu_ops {
17715
17716 void (*start_context_switch)(struct task_struct *prev);
17717 void (*end_context_switch)(struct task_struct *next);
17718-};
17719+} __no_const __no_randomize_layout;
17720
17721 struct pv_irq_ops {
17722 /*
17723@@ -215,7 +215,7 @@ struct pv_irq_ops {
17724 #ifdef CONFIG_X86_64
17725 void (*adjust_exception_frame)(void);
17726 #endif
17727-};
17728+} __no_randomize_layout;
17729
17730 struct pv_apic_ops {
17731 #ifdef CONFIG_X86_LOCAL_APIC
17732@@ -223,7 +223,7 @@ struct pv_apic_ops {
17733 unsigned long start_eip,
17734 unsigned long start_esp);
17735 #endif
17736-};
17737+} __no_const __no_randomize_layout;
17738
17739 struct pv_mmu_ops {
17740 unsigned long (*read_cr2)(void);
17741@@ -313,6 +313,7 @@ struct pv_mmu_ops {
17742 struct paravirt_callee_save make_pud;
17743
17744 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
17745+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
17746 #endif /* PAGETABLE_LEVELS == 4 */
17747 #endif /* PAGETABLE_LEVELS >= 3 */
17748
17749@@ -324,7 +325,13 @@ struct pv_mmu_ops {
17750 an mfn. We can tell which is which from the index. */
17751 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
17752 phys_addr_t phys, pgprot_t flags);
17753-};
17754+
17755+#ifdef CONFIG_PAX_KERNEXEC
17756+ unsigned long (*pax_open_kernel)(void);
17757+ unsigned long (*pax_close_kernel)(void);
17758+#endif
17759+
17760+} __no_randomize_layout;
17761
17762 struct arch_spinlock;
17763 #ifdef CONFIG_SMP
17764@@ -336,11 +343,14 @@ typedef u16 __ticket_t;
17765 struct pv_lock_ops {
17766 struct paravirt_callee_save lock_spinning;
17767 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
17768-};
17769+} __no_randomize_layout;
17770
17771 /* This contains all the paravirt structures: we get a convenient
17772 * number for each function using the offset which we use to indicate
17773- * what to patch. */
17774+ * what to patch.
17775+ * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
17776+ */
17777+
17778 struct paravirt_patch_template {
17779 struct pv_init_ops pv_init_ops;
17780 struct pv_time_ops pv_time_ops;
17781@@ -349,7 +359,7 @@ struct paravirt_patch_template {
17782 struct pv_apic_ops pv_apic_ops;
17783 struct pv_mmu_ops pv_mmu_ops;
17784 struct pv_lock_ops pv_lock_ops;
17785-};
17786+} __no_randomize_layout;
17787
17788 extern struct pv_info pv_info;
17789 extern struct pv_init_ops pv_init_ops;
17790diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
17791index c4412e9..90e88c5 100644
17792--- a/arch/x86/include/asm/pgalloc.h
17793+++ b/arch/x86/include/asm/pgalloc.h
17794@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
17795 pmd_t *pmd, pte_t *pte)
17796 {
17797 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17798+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
17799+}
17800+
17801+static inline void pmd_populate_user(struct mm_struct *mm,
17802+ pmd_t *pmd, pte_t *pte)
17803+{
17804+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17805 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
17806 }
17807
17808@@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
17809
17810 #ifdef CONFIG_X86_PAE
17811 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
17812+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
17813+{
17814+ pud_populate(mm, pudp, pmd);
17815+}
17816 #else /* !CONFIG_X86_PAE */
17817 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17818 {
17819 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17820 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
17821 }
17822+
17823+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17824+{
17825+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17826+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
17827+}
17828 #endif /* CONFIG_X86_PAE */
17829
17830 #if PAGETABLE_LEVELS > 3
17831@@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17832 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
17833 }
17834
17835+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17836+{
17837+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
17838+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
17839+}
17840+
17841 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
17842 {
17843 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
17844diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
17845index 0d193e2..bf59aeb 100644
17846--- a/arch/x86/include/asm/pgtable-2level.h
17847+++ b/arch/x86/include/asm/pgtable-2level.h
17848@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
17849
17850 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17851 {
17852+ pax_open_kernel();
17853 *pmdp = pmd;
17854+ pax_close_kernel();
17855 }
17856
17857 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17858diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
17859index 81bb91b..9392125 100644
17860--- a/arch/x86/include/asm/pgtable-3level.h
17861+++ b/arch/x86/include/asm/pgtable-3level.h
17862@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17863
17864 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17865 {
17866+ pax_open_kernel();
17867 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
17868+ pax_close_kernel();
17869 }
17870
17871 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17872 {
17873+ pax_open_kernel();
17874 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
17875+ pax_close_kernel();
17876 }
17877
17878 /*
17879diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
17880index bbc8b12..f228861 100644
17881--- a/arch/x86/include/asm/pgtable.h
17882+++ b/arch/x86/include/asm/pgtable.h
17883@@ -45,6 +45,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17884
17885 #ifndef __PAGETABLE_PUD_FOLDED
17886 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
17887+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
17888 #define pgd_clear(pgd) native_pgd_clear(pgd)
17889 #endif
17890
17891@@ -82,12 +83,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17892
17893 #define arch_end_context_switch(prev) do {} while(0)
17894
17895+#define pax_open_kernel() native_pax_open_kernel()
17896+#define pax_close_kernel() native_pax_close_kernel()
17897 #endif /* CONFIG_PARAVIRT */
17898
17899+#define __HAVE_ARCH_PAX_OPEN_KERNEL
17900+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
17901+
17902+#ifdef CONFIG_PAX_KERNEXEC
17903+static inline unsigned long native_pax_open_kernel(void)
17904+{
17905+ unsigned long cr0;
17906+
17907+ preempt_disable();
17908+ barrier();
17909+ cr0 = read_cr0() ^ X86_CR0_WP;
17910+ BUG_ON(cr0 & X86_CR0_WP);
17911+ write_cr0(cr0);
17912+ return cr0 ^ X86_CR0_WP;
17913+}
17914+
17915+static inline unsigned long native_pax_close_kernel(void)
17916+{
17917+ unsigned long cr0;
17918+
17919+ cr0 = read_cr0() ^ X86_CR0_WP;
17920+ BUG_ON(!(cr0 & X86_CR0_WP));
17921+ write_cr0(cr0);
17922+ barrier();
17923+ preempt_enable_no_resched();
17924+ return cr0 ^ X86_CR0_WP;
17925+}
17926+#else
17927+static inline unsigned long native_pax_open_kernel(void) { return 0; }
17928+static inline unsigned long native_pax_close_kernel(void) { return 0; }
17929+#endif
17930+
17931 /*
17932 * The following only work if pte_present() is true.
17933 * Undefined behaviour if not..
17934 */
17935+static inline int pte_user(pte_t pte)
17936+{
17937+ return pte_val(pte) & _PAGE_USER;
17938+}
17939+
17940 static inline int pte_dirty(pte_t pte)
17941 {
17942 return pte_flags(pte) & _PAGE_DIRTY;
17943@@ -148,6 +188,11 @@ static inline unsigned long pud_pfn(pud_t pud)
17944 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
17945 }
17946
17947+static inline unsigned long pgd_pfn(pgd_t pgd)
17948+{
17949+ return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
17950+}
17951+
17952 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
17953
17954 static inline int pmd_large(pmd_t pte)
17955@@ -201,9 +246,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
17956 return pte_clear_flags(pte, _PAGE_RW);
17957 }
17958
17959+static inline pte_t pte_mkread(pte_t pte)
17960+{
17961+ return __pte(pte_val(pte) | _PAGE_USER);
17962+}
17963+
17964 static inline pte_t pte_mkexec(pte_t pte)
17965 {
17966- return pte_clear_flags(pte, _PAGE_NX);
17967+#ifdef CONFIG_X86_PAE
17968+ if (__supported_pte_mask & _PAGE_NX)
17969+ return pte_clear_flags(pte, _PAGE_NX);
17970+ else
17971+#endif
17972+ return pte_set_flags(pte, _PAGE_USER);
17973+}
17974+
17975+static inline pte_t pte_exprotect(pte_t pte)
17976+{
17977+#ifdef CONFIG_X86_PAE
17978+ if (__supported_pte_mask & _PAGE_NX)
17979+ return pte_set_flags(pte, _PAGE_NX);
17980+ else
17981+#endif
17982+ return pte_clear_flags(pte, _PAGE_USER);
17983 }
17984
17985 static inline pte_t pte_mkdirty(pte_t pte)
17986@@ -430,6 +495,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
17987 #endif
17988
17989 #ifndef __ASSEMBLY__
17990+
17991+#ifdef CONFIG_PAX_PER_CPU_PGD
17992+extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
17993+enum cpu_pgd_type {kernel = 0, user = 1};
17994+static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
17995+{
17996+ return cpu_pgd[cpu][type];
17997+}
17998+#endif
17999+
18000 #include <linux/mm_types.h>
18001 #include <linux/mmdebug.h>
18002 #include <linux/log2.h>
18003@@ -570,7 +645,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
18004 * Currently stuck as a macro due to indirect forward reference to
18005 * linux/mmzone.h's __section_mem_map_addr() definition:
18006 */
18007-#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
18008+#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
18009
18010 /* Find an entry in the second-level page table.. */
18011 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
18012@@ -610,7 +685,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
18013 * Currently stuck as a macro due to indirect forward reference to
18014 * linux/mmzone.h's __section_mem_map_addr() definition:
18015 */
18016-#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
18017+#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
18018
18019 /* to find an entry in a page-table-directory. */
18020 static inline unsigned long pud_index(unsigned long address)
18021@@ -625,7 +700,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
18022
18023 static inline int pgd_bad(pgd_t pgd)
18024 {
18025- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
18026+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
18027 }
18028
18029 static inline int pgd_none(pgd_t pgd)
18030@@ -648,7 +723,12 @@ static inline int pgd_none(pgd_t pgd)
18031 * pgd_offset() returns a (pgd_t *)
18032 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
18033 */
18034-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
18035+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
18036+
18037+#ifdef CONFIG_PAX_PER_CPU_PGD
18038+#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
18039+#endif
18040+
18041 /*
18042 * a shortcut which implies the use of the kernel's pgd, instead
18043 * of a process's
18044@@ -659,6 +739,23 @@ static inline int pgd_none(pgd_t pgd)
18045 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
18046 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
18047
18048+#ifdef CONFIG_X86_32
18049+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
18050+#else
18051+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
18052+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
18053+
18054+#ifdef CONFIG_PAX_MEMORY_UDEREF
18055+#ifdef __ASSEMBLY__
18056+#define pax_user_shadow_base pax_user_shadow_base(%rip)
18057+#else
18058+extern unsigned long pax_user_shadow_base;
18059+extern pgdval_t clone_pgd_mask;
18060+#endif
18061+#endif
18062+
18063+#endif
18064+
18065 #ifndef __ASSEMBLY__
18066
18067 extern int direct_gbpages;
18068@@ -825,11 +922,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
18069 * dst and src can be on the same page, but the range must not overlap,
18070 * and must not cross a page boundary.
18071 */
18072-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
18073+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
18074 {
18075- memcpy(dst, src, count * sizeof(pgd_t));
18076+ pax_open_kernel();
18077+ while (count--)
18078+ *dst++ = *src++;
18079+ pax_close_kernel();
18080 }
18081
18082+#ifdef CONFIG_PAX_PER_CPU_PGD
18083+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
18084+#endif
18085+
18086+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18087+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
18088+#else
18089+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
18090+#endif
18091+
18092 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
18093 static inline int page_level_shift(enum pg_level level)
18094 {
18095diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
18096index 9ee3221..b979c6b 100644
18097--- a/arch/x86/include/asm/pgtable_32.h
18098+++ b/arch/x86/include/asm/pgtable_32.h
18099@@ -25,9 +25,6 @@
18100 struct mm_struct;
18101 struct vm_area_struct;
18102
18103-extern pgd_t swapper_pg_dir[1024];
18104-extern pgd_t initial_page_table[1024];
18105-
18106 static inline void pgtable_cache_init(void) { }
18107 static inline void check_pgt_cache(void) { }
18108 void paging_init(void);
18109@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
18110 # include <asm/pgtable-2level.h>
18111 #endif
18112
18113+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
18114+extern pgd_t initial_page_table[PTRS_PER_PGD];
18115+#ifdef CONFIG_X86_PAE
18116+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
18117+#endif
18118+
18119 #if defined(CONFIG_HIGHPTE)
18120 #define pte_offset_map(dir, address) \
18121 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
18122@@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
18123 /* Clear a kernel PTE and flush it from the TLB */
18124 #define kpte_clear_flush(ptep, vaddr) \
18125 do { \
18126+ pax_open_kernel(); \
18127 pte_clear(&init_mm, (vaddr), (ptep)); \
18128+ pax_close_kernel(); \
18129 __flush_tlb_one((vaddr)); \
18130 } while (0)
18131
18132 #endif /* !__ASSEMBLY__ */
18133
18134+#define HAVE_ARCH_UNMAPPED_AREA
18135+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
18136+
18137 /*
18138 * kern_addr_valid() is (1) for FLATMEM and (0) for
18139 * SPARSEMEM and DISCONTIGMEM
18140diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
18141index ed5903b..c7fe163 100644
18142--- a/arch/x86/include/asm/pgtable_32_types.h
18143+++ b/arch/x86/include/asm/pgtable_32_types.h
18144@@ -8,7 +8,7 @@
18145 */
18146 #ifdef CONFIG_X86_PAE
18147 # include <asm/pgtable-3level_types.h>
18148-# define PMD_SIZE (1UL << PMD_SHIFT)
18149+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
18150 # define PMD_MASK (~(PMD_SIZE - 1))
18151 #else
18152 # include <asm/pgtable-2level_types.h>
18153@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
18154 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
18155 #endif
18156
18157+#ifdef CONFIG_PAX_KERNEXEC
18158+#ifndef __ASSEMBLY__
18159+extern unsigned char MODULES_EXEC_VADDR[];
18160+extern unsigned char MODULES_EXEC_END[];
18161+#endif
18162+#include <asm/boot.h>
18163+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
18164+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
18165+#else
18166+#define ktla_ktva(addr) (addr)
18167+#define ktva_ktla(addr) (addr)
18168+#endif
18169+
18170 #define MODULES_VADDR VMALLOC_START
18171 #define MODULES_END VMALLOC_END
18172 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
18173diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
18174index e22c1db..23a625a 100644
18175--- a/arch/x86/include/asm/pgtable_64.h
18176+++ b/arch/x86/include/asm/pgtable_64.h
18177@@ -16,10 +16,14 @@
18178
18179 extern pud_t level3_kernel_pgt[512];
18180 extern pud_t level3_ident_pgt[512];
18181+extern pud_t level3_vmalloc_start_pgt[512];
18182+extern pud_t level3_vmalloc_end_pgt[512];
18183+extern pud_t level3_vmemmap_pgt[512];
18184+extern pud_t level2_vmemmap_pgt[512];
18185 extern pmd_t level2_kernel_pgt[512];
18186 extern pmd_t level2_fixmap_pgt[512];
18187-extern pmd_t level2_ident_pgt[512];
18188-extern pgd_t init_level4_pgt[];
18189+extern pmd_t level2_ident_pgt[512*2];
18190+extern pgd_t init_level4_pgt[512];
18191
18192 #define swapper_pg_dir init_level4_pgt
18193
18194@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18195
18196 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18197 {
18198+ pax_open_kernel();
18199 *pmdp = pmd;
18200+ pax_close_kernel();
18201 }
18202
18203 static inline void native_pmd_clear(pmd_t *pmd)
18204@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
18205
18206 static inline void native_set_pud(pud_t *pudp, pud_t pud)
18207 {
18208+ pax_open_kernel();
18209 *pudp = pud;
18210+ pax_close_kernel();
18211 }
18212
18213 static inline void native_pud_clear(pud_t *pud)
18214@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
18215
18216 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
18217 {
18218+ pax_open_kernel();
18219+ *pgdp = pgd;
18220+ pax_close_kernel();
18221+}
18222+
18223+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
18224+{
18225 *pgdp = pgd;
18226 }
18227
18228diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
18229index c883bf7..19970b3 100644
18230--- a/arch/x86/include/asm/pgtable_64_types.h
18231+++ b/arch/x86/include/asm/pgtable_64_types.h
18232@@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
18233 #define MODULES_VADDR (__START_KERNEL_map + KERNEL_IMAGE_SIZE)
18234 #define MODULES_END _AC(0xffffffffff000000, UL)
18235 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
18236+#define MODULES_EXEC_VADDR MODULES_VADDR
18237+#define MODULES_EXEC_END MODULES_END
18238+
18239+#define ktla_ktva(addr) (addr)
18240+#define ktva_ktla(addr) (addr)
18241
18242 #define EARLY_DYNAMIC_PAGE_TABLES 64
18243
18244diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
18245index 94e40f1..ebd03e4 100644
18246--- a/arch/x86/include/asm/pgtable_types.h
18247+++ b/arch/x86/include/asm/pgtable_types.h
18248@@ -16,13 +16,12 @@
18249 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
18250 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
18251 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
18252-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
18253+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
18254 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
18255 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
18256 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
18257-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
18258-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
18259-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
18260+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
18261+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
18262 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
18263
18264 /* If _PAGE_BIT_PRESENT is clear, we use these: */
18265@@ -40,7 +39,6 @@
18266 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
18267 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
18268 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
18269-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
18270 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
18271 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
18272 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
18273@@ -87,8 +85,10 @@
18274
18275 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
18276 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
18277-#else
18278+#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
18279 #define _PAGE_NX (_AT(pteval_t, 0))
18280+#else
18281+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
18282 #endif
18283
18284 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
18285@@ -147,6 +147,9 @@
18286 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
18287 _PAGE_ACCESSED)
18288
18289+#define PAGE_READONLY_NOEXEC PAGE_READONLY
18290+#define PAGE_SHARED_NOEXEC PAGE_SHARED
18291+
18292 #define __PAGE_KERNEL_EXEC \
18293 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
18294 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
18295@@ -157,7 +160,7 @@
18296 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
18297 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
18298 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
18299-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
18300+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
18301 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
18302 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
18303 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
18304@@ -219,8 +222,8 @@
18305 * bits are combined, this will alow user to access the high address mapped
18306 * VDSO in the presence of CONFIG_COMPAT_VDSO
18307 */
18308-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
18309-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
18310+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18311+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18312 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
18313 #endif
18314
18315@@ -258,7 +261,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
18316 {
18317 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
18318 }
18319+#endif
18320
18321+#if PAGETABLE_LEVELS == 3
18322+#include <asm-generic/pgtable-nopud.h>
18323+#endif
18324+
18325+#if PAGETABLE_LEVELS == 2
18326+#include <asm-generic/pgtable-nopmd.h>
18327+#endif
18328+
18329+#ifndef __ASSEMBLY__
18330 #if PAGETABLE_LEVELS > 3
18331 typedef struct { pudval_t pud; } pud_t;
18332
18333@@ -272,8 +285,6 @@ static inline pudval_t native_pud_val(pud_t pud)
18334 return pud.pud;
18335 }
18336 #else
18337-#include <asm-generic/pgtable-nopud.h>
18338-
18339 static inline pudval_t native_pud_val(pud_t pud)
18340 {
18341 return native_pgd_val(pud.pgd);
18342@@ -293,8 +304,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
18343 return pmd.pmd;
18344 }
18345 #else
18346-#include <asm-generic/pgtable-nopmd.h>
18347-
18348 static inline pmdval_t native_pmd_val(pmd_t pmd)
18349 {
18350 return native_pgd_val(pmd.pud.pgd);
18351@@ -334,7 +343,6 @@ typedef struct page *pgtable_t;
18352
18353 extern pteval_t __supported_pte_mask;
18354 extern void set_nx(void);
18355-extern int nx_enabled;
18356
18357 #define pgprot_writecombine pgprot_writecombine
18358 extern pgprot_t pgprot_writecombine(pgprot_t prot);
18359diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
18360index c8b0519..fd29e73 100644
18361--- a/arch/x86/include/asm/preempt.h
18362+++ b/arch/x86/include/asm/preempt.h
18363@@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
18364 */
18365 static __always_inline bool __preempt_count_dec_and_test(void)
18366 {
18367- GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
18368+ GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
18369 }
18370
18371 /*
18372diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
18373index fdedd38..95c02c2 100644
18374--- a/arch/x86/include/asm/processor.h
18375+++ b/arch/x86/include/asm/processor.h
18376@@ -128,7 +128,7 @@ struct cpuinfo_x86 {
18377 /* Index into per_cpu list: */
18378 u16 cpu_index;
18379 u32 microcode;
18380-} __attribute__((__aligned__(SMP_CACHE_BYTES)));
18381+} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
18382
18383 #define X86_VENDOR_INTEL 0
18384 #define X86_VENDOR_CYRIX 1
18385@@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
18386 : "memory");
18387 }
18388
18389+/* invpcid (%rdx),%rax */
18390+#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
18391+
18392+#define INVPCID_SINGLE_ADDRESS 0UL
18393+#define INVPCID_SINGLE_CONTEXT 1UL
18394+#define INVPCID_ALL_GLOBAL 2UL
18395+#define INVPCID_ALL_MONGLOBAL 3UL
18396+
18397+#define PCID_KERNEL 0UL
18398+#define PCID_USER 1UL
18399+#define PCID_NOFLUSH (1UL << 63)
18400+
18401 static inline void load_cr3(pgd_t *pgdir)
18402 {
18403- write_cr3(__pa(pgdir));
18404+ write_cr3(__pa(pgdir) | PCID_KERNEL);
18405 }
18406
18407 #ifdef CONFIG_X86_32
18408@@ -283,7 +295,7 @@ struct tss_struct {
18409
18410 } ____cacheline_aligned;
18411
18412-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
18413+extern struct tss_struct init_tss[NR_CPUS];
18414
18415 /*
18416 * Save the original ist values for checking stack pointers during debugging
18417@@ -470,6 +482,7 @@ struct thread_struct {
18418 unsigned short ds;
18419 unsigned short fsindex;
18420 unsigned short gsindex;
18421+ unsigned short ss;
18422 #endif
18423 #ifdef CONFIG_X86_32
18424 unsigned long ip;
18425@@ -579,29 +592,8 @@ static inline void load_sp0(struct tss_struct *tss,
18426 extern unsigned long mmu_cr4_features;
18427 extern u32 *trampoline_cr4_features;
18428
18429-static inline void set_in_cr4(unsigned long mask)
18430-{
18431- unsigned long cr4;
18432-
18433- mmu_cr4_features |= mask;
18434- if (trampoline_cr4_features)
18435- *trampoline_cr4_features = mmu_cr4_features;
18436- cr4 = read_cr4();
18437- cr4 |= mask;
18438- write_cr4(cr4);
18439-}
18440-
18441-static inline void clear_in_cr4(unsigned long mask)
18442-{
18443- unsigned long cr4;
18444-
18445- mmu_cr4_features &= ~mask;
18446- if (trampoline_cr4_features)
18447- *trampoline_cr4_features = mmu_cr4_features;
18448- cr4 = read_cr4();
18449- cr4 &= ~mask;
18450- write_cr4(cr4);
18451-}
18452+extern void set_in_cr4(unsigned long mask);
18453+extern void clear_in_cr4(unsigned long mask);
18454
18455 typedef struct {
18456 unsigned long seg;
18457@@ -827,11 +819,18 @@ static inline void spin_lock_prefetch(const void *x)
18458 */
18459 #define TASK_SIZE PAGE_OFFSET
18460 #define TASK_SIZE_MAX TASK_SIZE
18461+
18462+#ifdef CONFIG_PAX_SEGMEXEC
18463+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
18464+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
18465+#else
18466 #define STACK_TOP TASK_SIZE
18467-#define STACK_TOP_MAX STACK_TOP
18468+#endif
18469+
18470+#define STACK_TOP_MAX TASK_SIZE
18471
18472 #define INIT_THREAD { \
18473- .sp0 = sizeof(init_stack) + (long)&init_stack, \
18474+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18475 .vm86_info = NULL, \
18476 .sysenter_cs = __KERNEL_CS, \
18477 .io_bitmap_ptr = NULL, \
18478@@ -845,7 +844,7 @@ static inline void spin_lock_prefetch(const void *x)
18479 */
18480 #define INIT_TSS { \
18481 .x86_tss = { \
18482- .sp0 = sizeof(init_stack) + (long)&init_stack, \
18483+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18484 .ss0 = __KERNEL_DS, \
18485 .ss1 = __KERNEL_CS, \
18486 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
18487@@ -856,11 +855,7 @@ static inline void spin_lock_prefetch(const void *x)
18488 extern unsigned long thread_saved_pc(struct task_struct *tsk);
18489
18490 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
18491-#define KSTK_TOP(info) \
18492-({ \
18493- unsigned long *__ptr = (unsigned long *)(info); \
18494- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
18495-})
18496+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
18497
18498 /*
18499 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
18500@@ -875,7 +870,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18501 #define task_pt_regs(task) \
18502 ({ \
18503 struct pt_regs *__regs__; \
18504- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
18505+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
18506 __regs__ - 1; \
18507 })
18508
18509@@ -885,13 +880,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18510 /*
18511 * User space process size. 47bits minus one guard page.
18512 */
18513-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
18514+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
18515
18516 /* This decides where the kernel will search for a free chunk of vm
18517 * space during mmap's.
18518 */
18519 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
18520- 0xc0000000 : 0xFFFFe000)
18521+ 0xc0000000 : 0xFFFFf000)
18522
18523 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
18524 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
18525@@ -902,11 +897,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18526 #define STACK_TOP_MAX TASK_SIZE_MAX
18527
18528 #define INIT_THREAD { \
18529- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18530+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18531 }
18532
18533 #define INIT_TSS { \
18534- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18535+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18536 }
18537
18538 /*
18539@@ -934,6 +929,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
18540 */
18541 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
18542
18543+#ifdef CONFIG_PAX_SEGMEXEC
18544+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
18545+#endif
18546+
18547 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
18548
18549 /* Get/set a process' ability to use the timestamp counter instruction */
18550@@ -960,7 +959,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
18551 return 0;
18552 }
18553
18554-extern unsigned long arch_align_stack(unsigned long sp);
18555+#define arch_align_stack(x) ((x) & ~0xfUL)
18556 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
18557
18558 void default_idle(void);
18559@@ -970,6 +969,6 @@ bool xen_set_default_idle(void);
18560 #define xen_set_default_idle 0
18561 #endif
18562
18563-void stop_this_cpu(void *dummy);
18564+void stop_this_cpu(void *dummy) __noreturn;
18565 void df_debug(struct pt_regs *regs, long error_code);
18566 #endif /* _ASM_X86_PROCESSOR_H */
18567diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
18568index 14fd6fd..6740420 100644
18569--- a/arch/x86/include/asm/ptrace.h
18570+++ b/arch/x86/include/asm/ptrace.h
18571@@ -84,28 +84,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
18572 }
18573
18574 /*
18575- * user_mode_vm(regs) determines whether a register set came from user mode.
18576+ * user_mode(regs) determines whether a register set came from user mode.
18577 * This is true if V8086 mode was enabled OR if the register set was from
18578 * protected mode with RPL-3 CS value. This tricky test checks that with
18579 * one comparison. Many places in the kernel can bypass this full check
18580- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
18581+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
18582+ * be used.
18583 */
18584-static inline int user_mode(struct pt_regs *regs)
18585+static inline int user_mode_novm(struct pt_regs *regs)
18586 {
18587 #ifdef CONFIG_X86_32
18588 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
18589 #else
18590- return !!(regs->cs & 3);
18591+ return !!(regs->cs & SEGMENT_RPL_MASK);
18592 #endif
18593 }
18594
18595-static inline int user_mode_vm(struct pt_regs *regs)
18596+static inline int user_mode(struct pt_regs *regs)
18597 {
18598 #ifdef CONFIG_X86_32
18599 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
18600 USER_RPL;
18601 #else
18602- return user_mode(regs);
18603+ return user_mode_novm(regs);
18604 #endif
18605 }
18606
18607@@ -121,15 +122,16 @@ static inline int v8086_mode(struct pt_regs *regs)
18608 #ifdef CONFIG_X86_64
18609 static inline bool user_64bit_mode(struct pt_regs *regs)
18610 {
18611+ unsigned long cs = regs->cs & 0xffff;
18612 #ifndef CONFIG_PARAVIRT
18613 /*
18614 * On non-paravirt systems, this is the only long mode CPL 3
18615 * selector. We do not allow long mode selectors in the LDT.
18616 */
18617- return regs->cs == __USER_CS;
18618+ return cs == __USER_CS;
18619 #else
18620 /* Headers are too twisted for this to go in paravirt.h. */
18621- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
18622+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
18623 #endif
18624 }
18625
18626@@ -180,9 +182,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
18627 * Traps from the kernel do not save sp and ss.
18628 * Use the helper function to retrieve sp.
18629 */
18630- if (offset == offsetof(struct pt_regs, sp) &&
18631- regs->cs == __KERNEL_CS)
18632- return kernel_stack_pointer(regs);
18633+ if (offset == offsetof(struct pt_regs, sp)) {
18634+ unsigned long cs = regs->cs & 0xffff;
18635+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
18636+ return kernel_stack_pointer(regs);
18637+ }
18638 #endif
18639 return *(unsigned long *)((unsigned long)regs + offset);
18640 }
18641diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
18642index 9c6b890..5305f53 100644
18643--- a/arch/x86/include/asm/realmode.h
18644+++ b/arch/x86/include/asm/realmode.h
18645@@ -22,16 +22,14 @@ struct real_mode_header {
18646 #endif
18647 /* APM/BIOS reboot */
18648 u32 machine_real_restart_asm;
18649-#ifdef CONFIG_X86_64
18650 u32 machine_real_restart_seg;
18651-#endif
18652 };
18653
18654 /* This must match data at trampoline_32/64.S */
18655 struct trampoline_header {
18656 #ifdef CONFIG_X86_32
18657 u32 start;
18658- u16 gdt_pad;
18659+ u16 boot_cs;
18660 u16 gdt_limit;
18661 u32 gdt_base;
18662 #else
18663diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
18664index a82c4f1..ac45053 100644
18665--- a/arch/x86/include/asm/reboot.h
18666+++ b/arch/x86/include/asm/reboot.h
18667@@ -6,13 +6,13 @@
18668 struct pt_regs;
18669
18670 struct machine_ops {
18671- void (*restart)(char *cmd);
18672- void (*halt)(void);
18673- void (*power_off)(void);
18674+ void (* __noreturn restart)(char *cmd);
18675+ void (* __noreturn halt)(void);
18676+ void (* __noreturn power_off)(void);
18677 void (*shutdown)(void);
18678 void (*crash_shutdown)(struct pt_regs *);
18679- void (*emergency_restart)(void);
18680-};
18681+ void (* __noreturn emergency_restart)(void);
18682+} __no_const;
18683
18684 extern struct machine_ops machine_ops;
18685
18686diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
18687index 8f7866a..e442f20 100644
18688--- a/arch/x86/include/asm/rmwcc.h
18689+++ b/arch/x86/include/asm/rmwcc.h
18690@@ -3,7 +3,34 @@
18691
18692 #ifdef CC_HAVE_ASM_GOTO
18693
18694-#define __GEN_RMWcc(fullop, var, cc, ...) \
18695+#ifdef CONFIG_PAX_REFCOUNT
18696+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18697+do { \
18698+ asm_volatile_goto (fullop \
18699+ ";jno 0f\n" \
18700+ fullantiop \
18701+ ";int $4\n0:\n" \
18702+ _ASM_EXTABLE(0b, 0b) \
18703+ ";j" cc " %l[cc_label]" \
18704+ : : "m" (var), ## __VA_ARGS__ \
18705+ : "memory" : cc_label); \
18706+ return 0; \
18707+cc_label: \
18708+ return 1; \
18709+} while (0)
18710+#else
18711+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18712+do { \
18713+ asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
18714+ : : "m" (var), ## __VA_ARGS__ \
18715+ : "memory" : cc_label); \
18716+ return 0; \
18717+cc_label: \
18718+ return 1; \
18719+} while (0)
18720+#endif
18721+
18722+#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18723 do { \
18724 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
18725 : : "m" (var), ## __VA_ARGS__ \
18726@@ -13,15 +40,46 @@ cc_label: \
18727 return 1; \
18728 } while (0)
18729
18730-#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18731- __GEN_RMWcc(op " " arg0, var, cc)
18732+#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18733+ __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18734
18735-#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18736- __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
18737+#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18738+ __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18739+
18740+#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18741+ __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
18742+
18743+#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18744+ __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
18745
18746 #else /* !CC_HAVE_ASM_GOTO */
18747
18748-#define __GEN_RMWcc(fullop, var, cc, ...) \
18749+#ifdef CONFIG_PAX_REFCOUNT
18750+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18751+do { \
18752+ char c; \
18753+ asm volatile (fullop \
18754+ ";jno 0f\n" \
18755+ fullantiop \
18756+ ";int $4\n0:\n" \
18757+ _ASM_EXTABLE(0b, 0b) \
18758+ "; set" cc " %1" \
18759+ : "+m" (var), "=qm" (c) \
18760+ : __VA_ARGS__ : "memory"); \
18761+ return c != 0; \
18762+} while (0)
18763+#else
18764+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18765+do { \
18766+ char c; \
18767+ asm volatile (fullop "; set" cc " %1" \
18768+ : "+m" (var), "=qm" (c) \
18769+ : __VA_ARGS__ : "memory"); \
18770+ return c != 0; \
18771+} while (0)
18772+#endif
18773+
18774+#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18775 do { \
18776 char c; \
18777 asm volatile (fullop "; set" cc " %1" \
18778@@ -30,11 +88,17 @@ do { \
18779 return c != 0; \
18780 } while (0)
18781
18782-#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18783- __GEN_RMWcc(op " " arg0, var, cc)
18784+#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18785+ __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18786+
18787+#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18788+ __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18789+
18790+#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18791+ __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
18792
18793-#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18794- __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
18795+#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18796+ __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
18797
18798 #endif /* CC_HAVE_ASM_GOTO */
18799
18800diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
18801index cad82c9..2e5c5c1 100644
18802--- a/arch/x86/include/asm/rwsem.h
18803+++ b/arch/x86/include/asm/rwsem.h
18804@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
18805 {
18806 asm volatile("# beginning down_read\n\t"
18807 LOCK_PREFIX _ASM_INC "(%1)\n\t"
18808+
18809+#ifdef CONFIG_PAX_REFCOUNT
18810+ "jno 0f\n"
18811+ LOCK_PREFIX _ASM_DEC "(%1)\n"
18812+ "int $4\n0:\n"
18813+ _ASM_EXTABLE(0b, 0b)
18814+#endif
18815+
18816 /* adds 0x00000001 */
18817 " jns 1f\n"
18818 " call call_rwsem_down_read_failed\n"
18819@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
18820 "1:\n\t"
18821 " mov %1,%2\n\t"
18822 " add %3,%2\n\t"
18823+
18824+#ifdef CONFIG_PAX_REFCOUNT
18825+ "jno 0f\n"
18826+ "sub %3,%2\n"
18827+ "int $4\n0:\n"
18828+ _ASM_EXTABLE(0b, 0b)
18829+#endif
18830+
18831 " jle 2f\n\t"
18832 LOCK_PREFIX " cmpxchg %2,%0\n\t"
18833 " jnz 1b\n\t"
18834@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
18835 long tmp;
18836 asm volatile("# beginning down_write\n\t"
18837 LOCK_PREFIX " xadd %1,(%2)\n\t"
18838+
18839+#ifdef CONFIG_PAX_REFCOUNT
18840+ "jno 0f\n"
18841+ "mov %1,(%2)\n"
18842+ "int $4\n0:\n"
18843+ _ASM_EXTABLE(0b, 0b)
18844+#endif
18845+
18846 /* adds 0xffff0001, returns the old value */
18847 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
18848 /* was the active mask 0 before? */
18849@@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
18850 long tmp;
18851 asm volatile("# beginning __up_read\n\t"
18852 LOCK_PREFIX " xadd %1,(%2)\n\t"
18853+
18854+#ifdef CONFIG_PAX_REFCOUNT
18855+ "jno 0f\n"
18856+ "mov %1,(%2)\n"
18857+ "int $4\n0:\n"
18858+ _ASM_EXTABLE(0b, 0b)
18859+#endif
18860+
18861 /* subtracts 1, returns the old value */
18862 " jns 1f\n\t"
18863 " call call_rwsem_wake\n" /* expects old value in %edx */
18864@@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
18865 long tmp;
18866 asm volatile("# beginning __up_write\n\t"
18867 LOCK_PREFIX " xadd %1,(%2)\n\t"
18868+
18869+#ifdef CONFIG_PAX_REFCOUNT
18870+ "jno 0f\n"
18871+ "mov %1,(%2)\n"
18872+ "int $4\n0:\n"
18873+ _ASM_EXTABLE(0b, 0b)
18874+#endif
18875+
18876 /* subtracts 0xffff0001, returns the old value */
18877 " jns 1f\n\t"
18878 " call call_rwsem_wake\n" /* expects old value in %edx */
18879@@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18880 {
18881 asm volatile("# beginning __downgrade_write\n\t"
18882 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
18883+
18884+#ifdef CONFIG_PAX_REFCOUNT
18885+ "jno 0f\n"
18886+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
18887+ "int $4\n0:\n"
18888+ _ASM_EXTABLE(0b, 0b)
18889+#endif
18890+
18891 /*
18892 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
18893 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
18894@@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18895 */
18896 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18897 {
18898- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
18899+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
18900+
18901+#ifdef CONFIG_PAX_REFCOUNT
18902+ "jno 0f\n"
18903+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
18904+ "int $4\n0:\n"
18905+ _ASM_EXTABLE(0b, 0b)
18906+#endif
18907+
18908 : "+m" (sem->count)
18909 : "er" (delta));
18910 }
18911@@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18912 */
18913 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
18914 {
18915- return delta + xadd(&sem->count, delta);
18916+ return delta + xadd_check_overflow(&sem->count, delta);
18917 }
18918
18919 #endif /* __KERNEL__ */
18920diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
18921index 6f1c3a8..7744f19 100644
18922--- a/arch/x86/include/asm/segment.h
18923+++ b/arch/x86/include/asm/segment.h
18924@@ -64,10 +64,15 @@
18925 * 26 - ESPFIX small SS
18926 * 27 - per-cpu [ offset to per-cpu data area ]
18927 * 28 - stack_canary-20 [ for stack protector ]
18928- * 29 - unused
18929- * 30 - unused
18930+ * 29 - PCI BIOS CS
18931+ * 30 - PCI BIOS DS
18932 * 31 - TSS for double fault handler
18933 */
18934+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
18935+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
18936+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
18937+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
18938+
18939 #define GDT_ENTRY_TLS_MIN 6
18940 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
18941
18942@@ -79,6 +84,8 @@
18943
18944 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
18945
18946+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
18947+
18948 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
18949
18950 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
18951@@ -104,6 +111,12 @@
18952 #define __KERNEL_STACK_CANARY 0
18953 #endif
18954
18955+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
18956+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
18957+
18958+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
18959+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
18960+
18961 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
18962
18963 /*
18964@@ -141,7 +154,7 @@
18965 */
18966
18967 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
18968-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
18969+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
18970
18971
18972 #else
18973@@ -165,6 +178,8 @@
18974 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
18975 #define __USER32_DS __USER_DS
18976
18977+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
18978+
18979 #define GDT_ENTRY_TSS 8 /* needs two entries */
18980 #define GDT_ENTRY_LDT 10 /* needs two entries */
18981 #define GDT_ENTRY_TLS_MIN 12
18982@@ -173,6 +188,8 @@
18983 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
18984 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
18985
18986+#define GDT_ENTRY_UDEREF_KERNEL_DS 16
18987+
18988 /* TLS indexes for 64bit - hardcoded in arch_prctl */
18989 #define FS_TLS 0
18990 #define GS_TLS 1
18991@@ -180,12 +197,14 @@
18992 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
18993 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
18994
18995-#define GDT_ENTRIES 16
18996+#define GDT_ENTRIES 17
18997
18998 #endif
18999
19000 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
19001+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
19002 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
19003+#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
19004 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
19005 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
19006 #ifndef CONFIG_PARAVIRT
19007@@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
19008 {
19009 unsigned long __limit;
19010 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
19011- return __limit + 1;
19012+ return __limit;
19013 }
19014
19015 #endif /* !__ASSEMBLY__ */
19016diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
19017index 8d3120f..352b440 100644
19018--- a/arch/x86/include/asm/smap.h
19019+++ b/arch/x86/include/asm/smap.h
19020@@ -25,11 +25,40 @@
19021
19022 #include <asm/alternative-asm.h>
19023
19024+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19025+#define ASM_PAX_OPEN_USERLAND \
19026+ 661: jmp 663f; \
19027+ .pushsection .altinstr_replacement, "a" ; \
19028+ 662: pushq %rax; nop; \
19029+ .popsection ; \
19030+ .pushsection .altinstructions, "a" ; \
19031+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19032+ .popsection ; \
19033+ call __pax_open_userland; \
19034+ popq %rax; \
19035+ 663:
19036+
19037+#define ASM_PAX_CLOSE_USERLAND \
19038+ 661: jmp 663f; \
19039+ .pushsection .altinstr_replacement, "a" ; \
19040+ 662: pushq %rax; nop; \
19041+ .popsection; \
19042+ .pushsection .altinstructions, "a" ; \
19043+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19044+ .popsection; \
19045+ call __pax_close_userland; \
19046+ popq %rax; \
19047+ 663:
19048+#else
19049+#define ASM_PAX_OPEN_USERLAND
19050+#define ASM_PAX_CLOSE_USERLAND
19051+#endif
19052+
19053 #ifdef CONFIG_X86_SMAP
19054
19055 #define ASM_CLAC \
19056 661: ASM_NOP3 ; \
19057- .pushsection .altinstr_replacement, "ax" ; \
19058+ .pushsection .altinstr_replacement, "a" ; \
19059 662: __ASM_CLAC ; \
19060 .popsection ; \
19061 .pushsection .altinstructions, "a" ; \
19062@@ -38,7 +67,7 @@
19063
19064 #define ASM_STAC \
19065 661: ASM_NOP3 ; \
19066- .pushsection .altinstr_replacement, "ax" ; \
19067+ .pushsection .altinstr_replacement, "a" ; \
19068 662: __ASM_STAC ; \
19069 .popsection ; \
19070 .pushsection .altinstructions, "a" ; \
19071@@ -56,6 +85,37 @@
19072
19073 #include <asm/alternative.h>
19074
19075+#define __HAVE_ARCH_PAX_OPEN_USERLAND
19076+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
19077+
19078+extern void __pax_open_userland(void);
19079+static __always_inline unsigned long pax_open_userland(void)
19080+{
19081+
19082+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19083+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
19084+ :
19085+ : [open] "i" (__pax_open_userland)
19086+ : "memory", "rax");
19087+#endif
19088+
19089+ return 0;
19090+}
19091+
19092+extern void __pax_close_userland(void);
19093+static __always_inline unsigned long pax_close_userland(void)
19094+{
19095+
19096+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19097+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
19098+ :
19099+ : [close] "i" (__pax_close_userland)
19100+ : "memory", "rax");
19101+#endif
19102+
19103+ return 0;
19104+}
19105+
19106 #ifdef CONFIG_X86_SMAP
19107
19108 static __always_inline void clac(void)
19109diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
19110index 8cd27e0..7f05ec8 100644
19111--- a/arch/x86/include/asm/smp.h
19112+++ b/arch/x86/include/asm/smp.h
19113@@ -35,7 +35,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
19114 /* cpus sharing the last level cache: */
19115 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
19116 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
19117-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
19118+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
19119
19120 static inline struct cpumask *cpu_sibling_mask(int cpu)
19121 {
19122@@ -78,7 +78,7 @@ struct smp_ops {
19123
19124 void (*send_call_func_ipi)(const struct cpumask *mask);
19125 void (*send_call_func_single_ipi)(int cpu);
19126-};
19127+} __no_const;
19128
19129 /* Globals due to paravirt */
19130 extern void set_cpu_sibling_map(int cpu);
19131@@ -190,14 +190,8 @@ extern unsigned disabled_cpus;
19132 extern int safe_smp_processor_id(void);
19133
19134 #elif defined(CONFIG_X86_64_SMP)
19135-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19136-
19137-#define stack_smp_processor_id() \
19138-({ \
19139- struct thread_info *ti; \
19140- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
19141- ti->cpu; \
19142-})
19143+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19144+#define stack_smp_processor_id() raw_smp_processor_id()
19145 #define safe_smp_processor_id() smp_processor_id()
19146
19147 #endif
19148diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
19149index 0f62f54..cb5d0dd 100644
19150--- a/arch/x86/include/asm/spinlock.h
19151+++ b/arch/x86/include/asm/spinlock.h
19152@@ -222,6 +222,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
19153 static inline void arch_read_lock(arch_rwlock_t *rw)
19154 {
19155 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
19156+
19157+#ifdef CONFIG_PAX_REFCOUNT
19158+ "jno 0f\n"
19159+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
19160+ "int $4\n0:\n"
19161+ _ASM_EXTABLE(0b, 0b)
19162+#endif
19163+
19164 "jns 1f\n"
19165 "call __read_lock_failed\n\t"
19166 "1:\n"
19167@@ -231,6 +239,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
19168 static inline void arch_write_lock(arch_rwlock_t *rw)
19169 {
19170 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
19171+
19172+#ifdef CONFIG_PAX_REFCOUNT
19173+ "jno 0f\n"
19174+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
19175+ "int $4\n0:\n"
19176+ _ASM_EXTABLE(0b, 0b)
19177+#endif
19178+
19179 "jz 1f\n"
19180 "call __write_lock_failed\n\t"
19181 "1:\n"
19182@@ -260,13 +276,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
19183
19184 static inline void arch_read_unlock(arch_rwlock_t *rw)
19185 {
19186- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
19187+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
19188+
19189+#ifdef CONFIG_PAX_REFCOUNT
19190+ "jno 0f\n"
19191+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
19192+ "int $4\n0:\n"
19193+ _ASM_EXTABLE(0b, 0b)
19194+#endif
19195+
19196 :"+m" (rw->lock) : : "memory");
19197 }
19198
19199 static inline void arch_write_unlock(arch_rwlock_t *rw)
19200 {
19201- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
19202+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
19203+
19204+#ifdef CONFIG_PAX_REFCOUNT
19205+ "jno 0f\n"
19206+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
19207+ "int $4\n0:\n"
19208+ _ASM_EXTABLE(0b, 0b)
19209+#endif
19210+
19211 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
19212 }
19213
19214diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
19215index 6a99859..03cb807 100644
19216--- a/arch/x86/include/asm/stackprotector.h
19217+++ b/arch/x86/include/asm/stackprotector.h
19218@@ -47,7 +47,7 @@
19219 * head_32 for boot CPU and setup_per_cpu_areas() for others.
19220 */
19221 #define GDT_STACK_CANARY_INIT \
19222- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
19223+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
19224
19225 /*
19226 * Initialize the stackprotector canary value.
19227@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
19228
19229 static inline void load_stack_canary_segment(void)
19230 {
19231-#ifdef CONFIG_X86_32
19232+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
19233 asm volatile ("mov %0, %%gs" : : "r" (0));
19234 #endif
19235 }
19236diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
19237index 70bbe39..4ae2bd4 100644
19238--- a/arch/x86/include/asm/stacktrace.h
19239+++ b/arch/x86/include/asm/stacktrace.h
19240@@ -11,28 +11,20 @@
19241
19242 extern int kstack_depth_to_print;
19243
19244-struct thread_info;
19245+struct task_struct;
19246 struct stacktrace_ops;
19247
19248-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
19249- unsigned long *stack,
19250- unsigned long bp,
19251- const struct stacktrace_ops *ops,
19252- void *data,
19253- unsigned long *end,
19254- int *graph);
19255+typedef unsigned long walk_stack_t(struct task_struct *task,
19256+ void *stack_start,
19257+ unsigned long *stack,
19258+ unsigned long bp,
19259+ const struct stacktrace_ops *ops,
19260+ void *data,
19261+ unsigned long *end,
19262+ int *graph);
19263
19264-extern unsigned long
19265-print_context_stack(struct thread_info *tinfo,
19266- unsigned long *stack, unsigned long bp,
19267- const struct stacktrace_ops *ops, void *data,
19268- unsigned long *end, int *graph);
19269-
19270-extern unsigned long
19271-print_context_stack_bp(struct thread_info *tinfo,
19272- unsigned long *stack, unsigned long bp,
19273- const struct stacktrace_ops *ops, void *data,
19274- unsigned long *end, int *graph);
19275+extern walk_stack_t print_context_stack;
19276+extern walk_stack_t print_context_stack_bp;
19277
19278 /* Generic stack tracer with callbacks */
19279
19280@@ -40,7 +32,7 @@ struct stacktrace_ops {
19281 void (*address)(void *data, unsigned long address, int reliable);
19282 /* On negative return stop dumping */
19283 int (*stack)(void *data, char *name);
19284- walk_stack_t walk_stack;
19285+ walk_stack_t *walk_stack;
19286 };
19287
19288 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
19289diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
19290index d7f3b3b..3cc39f1 100644
19291--- a/arch/x86/include/asm/switch_to.h
19292+++ b/arch/x86/include/asm/switch_to.h
19293@@ -108,7 +108,7 @@ do { \
19294 "call __switch_to\n\t" \
19295 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
19296 __switch_canary \
19297- "movq %P[thread_info](%%rsi),%%r8\n\t" \
19298+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
19299 "movq %%rax,%%rdi\n\t" \
19300 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
19301 "jnz ret_from_fork\n\t" \
19302@@ -119,7 +119,7 @@ do { \
19303 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
19304 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
19305 [_tif_fork] "i" (_TIF_FORK), \
19306- [thread_info] "i" (offsetof(struct task_struct, stack)), \
19307+ [thread_info] "m" (current_tinfo), \
19308 [current_task] "m" (current_task) \
19309 __switch_canary_iparam \
19310 : "memory", "cc" __EXTRA_CLOBBER)
19311diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
19312index e1940c0..ac50dd8 100644
19313--- a/arch/x86/include/asm/thread_info.h
19314+++ b/arch/x86/include/asm/thread_info.h
19315@@ -10,6 +10,7 @@
19316 #include <linux/compiler.h>
19317 #include <asm/page.h>
19318 #include <asm/types.h>
19319+#include <asm/percpu.h>
19320
19321 /*
19322 * low level task data that entry.S needs immediate access to
19323@@ -23,7 +24,6 @@ struct exec_domain;
19324 #include <linux/atomic.h>
19325
19326 struct thread_info {
19327- struct task_struct *task; /* main task structure */
19328 struct exec_domain *exec_domain; /* execution domain */
19329 __u32 flags; /* low level flags */
19330 __u32 status; /* thread synchronous flags */
19331@@ -32,19 +32,13 @@ struct thread_info {
19332 mm_segment_t addr_limit;
19333 struct restart_block restart_block;
19334 void __user *sysenter_return;
19335-#ifdef CONFIG_X86_32
19336- unsigned long previous_esp; /* ESP of the previous stack in
19337- case of nested (IRQ) stacks
19338- */
19339- __u8 supervisor_stack[0];
19340-#endif
19341+ unsigned long lowest_stack;
19342 unsigned int sig_on_uaccess_error:1;
19343 unsigned int uaccess_err:1; /* uaccess failed */
19344 };
19345
19346-#define INIT_THREAD_INFO(tsk) \
19347+#define INIT_THREAD_INFO \
19348 { \
19349- .task = &tsk, \
19350 .exec_domain = &default_exec_domain, \
19351 .flags = 0, \
19352 .cpu = 0, \
19353@@ -55,7 +49,7 @@ struct thread_info {
19354 }, \
19355 }
19356
19357-#define init_thread_info (init_thread_union.thread_info)
19358+#define init_thread_info (init_thread_union.stack)
19359 #define init_stack (init_thread_union.stack)
19360
19361 #else /* !__ASSEMBLY__ */
19362@@ -95,6 +89,7 @@ struct thread_info {
19363 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
19364 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
19365 #define TIF_X32 30 /* 32-bit native x86-64 binary */
19366+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
19367
19368 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
19369 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
19370@@ -118,17 +113,18 @@ struct thread_info {
19371 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
19372 #define _TIF_ADDR32 (1 << TIF_ADDR32)
19373 #define _TIF_X32 (1 << TIF_X32)
19374+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
19375
19376 /* work to do in syscall_trace_enter() */
19377 #define _TIF_WORK_SYSCALL_ENTRY \
19378 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
19379 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
19380- _TIF_NOHZ)
19381+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
19382
19383 /* work to do in syscall_trace_leave() */
19384 #define _TIF_WORK_SYSCALL_EXIT \
19385 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
19386- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
19387+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
19388
19389 /* work to do on interrupt/exception return */
19390 #define _TIF_WORK_MASK \
19391@@ -139,7 +135,7 @@ struct thread_info {
19392 /* work to do on any return to user space */
19393 #define _TIF_ALLWORK_MASK \
19394 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
19395- _TIF_NOHZ)
19396+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
19397
19398 /* Only used for 64 bit */
19399 #define _TIF_DO_NOTIFY_MASK \
19400@@ -153,6 +149,23 @@ struct thread_info {
19401 #define _TIF_WORK_CTXSW_PREV (_TIF_WORK_CTXSW|_TIF_USER_RETURN_NOTIFY)
19402 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
19403
19404+#ifdef __ASSEMBLY__
19405+/* how to get the thread information struct from ASM */
19406+#define GET_THREAD_INFO(reg) \
19407+ mov PER_CPU_VAR(current_tinfo), reg
19408+
19409+/* use this one if reg already contains %esp */
19410+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
19411+#else
19412+/* how to get the thread information struct from C */
19413+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
19414+
19415+static __always_inline struct thread_info *current_thread_info(void)
19416+{
19417+ return this_cpu_read_stable(current_tinfo);
19418+}
19419+#endif
19420+
19421 #ifdef CONFIG_X86_32
19422
19423 #define STACK_WARN (THREAD_SIZE/8)
19424@@ -169,31 +182,10 @@ struct thread_info {
19425 sp; \
19426 })
19427
19428-/* how to get the thread information struct from C */
19429-static inline struct thread_info *current_thread_info(void)
19430-{
19431- return (struct thread_info *)
19432- (current_stack_pointer & ~(THREAD_SIZE - 1));
19433-}
19434-
19435-#else /* !__ASSEMBLY__ */
19436-
19437-/* how to get the thread information struct from ASM */
19438-#define GET_THREAD_INFO(reg) \
19439- movl $-THREAD_SIZE, reg; \
19440- andl %esp, reg
19441-
19442-/* use this one if reg already contains %esp */
19443-#define GET_THREAD_INFO_WITH_ESP(reg) \
19444- andl $-THREAD_SIZE, reg
19445-
19446 #endif
19447
19448 #else /* X86_32 */
19449
19450-#include <asm/percpu.h>
19451-#define KERNEL_STACK_OFFSET (5*8)
19452-
19453 /*
19454 * macros/functions for gaining access to the thread information structure
19455 * preempt_count needs to be 1 initially, until the scheduler is functional.
19456@@ -201,27 +193,8 @@ static inline struct thread_info *current_thread_info(void)
19457 #ifndef __ASSEMBLY__
19458 DECLARE_PER_CPU(unsigned long, kernel_stack);
19459
19460-static inline struct thread_info *current_thread_info(void)
19461-{
19462- struct thread_info *ti;
19463- ti = (void *)(this_cpu_read_stable(kernel_stack) +
19464- KERNEL_STACK_OFFSET - THREAD_SIZE);
19465- return ti;
19466-}
19467-
19468-#else /* !__ASSEMBLY__ */
19469-
19470-/* how to get the thread information struct from ASM */
19471-#define GET_THREAD_INFO(reg) \
19472- movq PER_CPU_VAR(kernel_stack),reg ; \
19473- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
19474-
19475-/*
19476- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
19477- * a certain register (to be used in assembler memory operands).
19478- */
19479-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
19480-
19481+/* how to get the current stack pointer from C */
19482+register unsigned long current_stack_pointer asm("rsp") __used;
19483 #endif
19484
19485 #endif /* !X86_32 */
19486@@ -280,5 +253,12 @@ static inline bool is_ia32_task(void)
19487 extern void arch_task_cache_init(void);
19488 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
19489 extern void arch_release_task_struct(struct task_struct *tsk);
19490+
19491+#define __HAVE_THREAD_FUNCTIONS
19492+#define task_thread_info(task) (&(task)->tinfo)
19493+#define task_stack_page(task) ((task)->stack)
19494+#define setup_thread_stack(p, org) do {} while (0)
19495+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
19496+
19497 #endif
19498 #endif /* _ASM_X86_THREAD_INFO_H */
19499diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
19500index 04905bf..49203ca 100644
19501--- a/arch/x86/include/asm/tlbflush.h
19502+++ b/arch/x86/include/asm/tlbflush.h
19503@@ -17,18 +17,44 @@
19504
19505 static inline void __native_flush_tlb(void)
19506 {
19507+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19508+ u64 descriptor[2];
19509+
19510+ descriptor[0] = PCID_KERNEL;
19511+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
19512+ return;
19513+ }
19514+
19515+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19516+ if (static_cpu_has(X86_FEATURE_PCID)) {
19517+ unsigned int cpu = raw_get_cpu();
19518+
19519+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
19520+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
19521+ raw_put_cpu_no_resched();
19522+ return;
19523+ }
19524+#endif
19525+
19526 native_write_cr3(native_read_cr3());
19527 }
19528
19529 static inline void __native_flush_tlb_global_irq_disabled(void)
19530 {
19531- unsigned long cr4;
19532+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19533+ u64 descriptor[2];
19534
19535- cr4 = native_read_cr4();
19536- /* clear PGE */
19537- native_write_cr4(cr4 & ~X86_CR4_PGE);
19538- /* write old PGE again and flush TLBs */
19539- native_write_cr4(cr4);
19540+ descriptor[0] = PCID_KERNEL;
19541+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
19542+ } else {
19543+ unsigned long cr4;
19544+
19545+ cr4 = native_read_cr4();
19546+ /* clear PGE */
19547+ native_write_cr4(cr4 & ~X86_CR4_PGE);
19548+ /* write old PGE again and flush TLBs */
19549+ native_write_cr4(cr4);
19550+ }
19551 }
19552
19553 static inline void __native_flush_tlb_global(void)
19554@@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
19555
19556 static inline void __native_flush_tlb_single(unsigned long addr)
19557 {
19558+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19559+ u64 descriptor[2];
19560+
19561+ descriptor[0] = PCID_KERNEL;
19562+ descriptor[1] = addr;
19563+
19564+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19565+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
19566+ if (addr < TASK_SIZE_MAX)
19567+ descriptor[1] += pax_user_shadow_base;
19568+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19569+ }
19570+
19571+ descriptor[0] = PCID_USER;
19572+ descriptor[1] = addr;
19573+#endif
19574+
19575+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19576+ return;
19577+ }
19578+
19579+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19580+ if (static_cpu_has(X86_FEATURE_PCID)) {
19581+ unsigned int cpu = raw_get_cpu();
19582+
19583+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
19584+ asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19585+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
19586+ raw_put_cpu_no_resched();
19587+
19588+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
19589+ addr += pax_user_shadow_base;
19590+ }
19591+#endif
19592+
19593 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19594 }
19595
19596diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
19597index 0d592e0..f58a222 100644
19598--- a/arch/x86/include/asm/uaccess.h
19599+++ b/arch/x86/include/asm/uaccess.h
19600@@ -7,6 +7,7 @@
19601 #include <linux/compiler.h>
19602 #include <linux/thread_info.h>
19603 #include <linux/string.h>
19604+#include <linux/spinlock.h>
19605 #include <asm/asm.h>
19606 #include <asm/page.h>
19607 #include <asm/smap.h>
19608@@ -29,7 +30,12 @@
19609
19610 #define get_ds() (KERNEL_DS)
19611 #define get_fs() (current_thread_info()->addr_limit)
19612+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19613+void __set_fs(mm_segment_t x);
19614+void set_fs(mm_segment_t x);
19615+#else
19616 #define set_fs(x) (current_thread_info()->addr_limit = (x))
19617+#endif
19618
19619 #define segment_eq(a, b) ((a).seg == (b).seg)
19620
19621@@ -85,8 +91,34 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un
19622 * checks that the pointer is in the user space range - after calling
19623 * this function, memory access functions may still return -EFAULT.
19624 */
19625-#define access_ok(type, addr, size) \
19626- likely(!__range_not_ok(addr, size, user_addr_max()))
19627+extern int _cond_resched(void);
19628+#define access_ok_noprefault(type, addr, size) (likely(!__range_not_ok(addr, size, user_addr_max())))
19629+#define access_ok(type, addr, size) \
19630+({ \
19631+ long __size = size; \
19632+ unsigned long __addr = (unsigned long)addr; \
19633+ unsigned long __addr_ao = __addr & PAGE_MASK; \
19634+ unsigned long __end_ao = __addr + __size - 1; \
19635+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
19636+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
19637+ while(__addr_ao <= __end_ao) { \
19638+ char __c_ao; \
19639+ __addr_ao += PAGE_SIZE; \
19640+ if (__size > PAGE_SIZE) \
19641+ _cond_resched(); \
19642+ if (__get_user(__c_ao, (char __user *)__addr)) \
19643+ break; \
19644+ if (type != VERIFY_WRITE) { \
19645+ __addr = __addr_ao; \
19646+ continue; \
19647+ } \
19648+ if (__put_user(__c_ao, (char __user *)__addr)) \
19649+ break; \
19650+ __addr = __addr_ao; \
19651+ } \
19652+ } \
19653+ __ret_ao; \
19654+})
19655
19656 /*
19657 * The exception table consists of pairs of addresses relative to the
19658@@ -176,10 +208,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19659 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
19660 __chk_user_ptr(ptr); \
19661 might_fault(); \
19662+ pax_open_userland(); \
19663 asm volatile("call __get_user_%P3" \
19664 : "=a" (__ret_gu), "=r" (__val_gu) \
19665 : "0" (ptr), "i" (sizeof(*(ptr)))); \
19666 (x) = (__typeof__(*(ptr))) __val_gu; \
19667+ pax_close_userland(); \
19668 __ret_gu; \
19669 })
19670
19671@@ -187,13 +221,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19672 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
19673 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
19674
19675-
19676+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19677+#define __copyuser_seg "gs;"
19678+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
19679+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
19680+#else
19681+#define __copyuser_seg
19682+#define __COPYUSER_SET_ES
19683+#define __COPYUSER_RESTORE_ES
19684+#endif
19685
19686 #ifdef CONFIG_X86_32
19687 #define __put_user_asm_u64(x, addr, err, errret) \
19688 asm volatile(ASM_STAC "\n" \
19689- "1: movl %%eax,0(%2)\n" \
19690- "2: movl %%edx,4(%2)\n" \
19691+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
19692+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
19693 "3: " ASM_CLAC "\n" \
19694 ".section .fixup,\"ax\"\n" \
19695 "4: movl %3,%0\n" \
19696@@ -206,8 +248,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19697
19698 #define __put_user_asm_ex_u64(x, addr) \
19699 asm volatile(ASM_STAC "\n" \
19700- "1: movl %%eax,0(%1)\n" \
19701- "2: movl %%edx,4(%1)\n" \
19702+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
19703+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
19704 "3: " ASM_CLAC "\n" \
19705 _ASM_EXTABLE_EX(1b, 2b) \
19706 _ASM_EXTABLE_EX(2b, 3b) \
19707@@ -257,7 +299,8 @@ extern void __put_user_8(void);
19708 __typeof__(*(ptr)) __pu_val; \
19709 __chk_user_ptr(ptr); \
19710 might_fault(); \
19711- __pu_val = x; \
19712+ __pu_val = (x); \
19713+ pax_open_userland(); \
19714 switch (sizeof(*(ptr))) { \
19715 case 1: \
19716 __put_user_x(1, __pu_val, ptr, __ret_pu); \
19717@@ -275,6 +318,7 @@ extern void __put_user_8(void);
19718 __put_user_x(X, __pu_val, ptr, __ret_pu); \
19719 break; \
19720 } \
19721+ pax_close_userland(); \
19722 __ret_pu; \
19723 })
19724
19725@@ -355,8 +399,10 @@ do { \
19726 } while (0)
19727
19728 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19729+do { \
19730+ pax_open_userland(); \
19731 asm volatile(ASM_STAC "\n" \
19732- "1: mov"itype" %2,%"rtype"1\n" \
19733+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
19734 "2: " ASM_CLAC "\n" \
19735 ".section .fixup,\"ax\"\n" \
19736 "3: mov %3,%0\n" \
19737@@ -364,8 +410,10 @@ do { \
19738 " jmp 2b\n" \
19739 ".previous\n" \
19740 _ASM_EXTABLE(1b, 3b) \
19741- : "=r" (err), ltype(x) \
19742- : "m" (__m(addr)), "i" (errret), "0" (err))
19743+ : "=r" (err), ltype (x) \
19744+ : "m" (__m(addr)), "i" (errret), "0" (err)); \
19745+ pax_close_userland(); \
19746+} while (0)
19747
19748 #define __get_user_size_ex(x, ptr, size) \
19749 do { \
19750@@ -389,7 +437,7 @@ do { \
19751 } while (0)
19752
19753 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
19754- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
19755+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
19756 "2:\n" \
19757 _ASM_EXTABLE_EX(1b, 2b) \
19758 : ltype(x) : "m" (__m(addr)))
19759@@ -406,13 +454,24 @@ do { \
19760 int __gu_err; \
19761 unsigned long __gu_val; \
19762 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
19763- (x) = (__force __typeof__(*(ptr)))__gu_val; \
19764+ (x) = (__typeof__(*(ptr)))__gu_val; \
19765 __gu_err; \
19766 })
19767
19768 /* FIXME: this hack is definitely wrong -AK */
19769 struct __large_struct { unsigned long buf[100]; };
19770-#define __m(x) (*(struct __large_struct __user *)(x))
19771+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19772+#define ____m(x) \
19773+({ \
19774+ unsigned long ____x = (unsigned long)(x); \
19775+ if (____x < pax_user_shadow_base) \
19776+ ____x += pax_user_shadow_base; \
19777+ (typeof(x))____x; \
19778+})
19779+#else
19780+#define ____m(x) (x)
19781+#endif
19782+#define __m(x) (*(struct __large_struct __user *)____m(x))
19783
19784 /*
19785 * Tell gcc we read from memory instead of writing: this is because
19786@@ -420,8 +479,10 @@ struct __large_struct { unsigned long buf[100]; };
19787 * aliasing issues.
19788 */
19789 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19790+do { \
19791+ pax_open_userland(); \
19792 asm volatile(ASM_STAC "\n" \
19793- "1: mov"itype" %"rtype"1,%2\n" \
19794+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
19795 "2: " ASM_CLAC "\n" \
19796 ".section .fixup,\"ax\"\n" \
19797 "3: mov %3,%0\n" \
19798@@ -429,10 +490,12 @@ struct __large_struct { unsigned long buf[100]; };
19799 ".previous\n" \
19800 _ASM_EXTABLE(1b, 3b) \
19801 : "=r"(err) \
19802- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
19803+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
19804+ pax_close_userland(); \
19805+} while (0)
19806
19807 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
19808- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
19809+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
19810 "2:\n" \
19811 _ASM_EXTABLE_EX(1b, 2b) \
19812 : : ltype(x), "m" (__m(addr)))
19813@@ -442,11 +505,13 @@ struct __large_struct { unsigned long buf[100]; };
19814 */
19815 #define uaccess_try do { \
19816 current_thread_info()->uaccess_err = 0; \
19817+ pax_open_userland(); \
19818 stac(); \
19819 barrier();
19820
19821 #define uaccess_catch(err) \
19822 clac(); \
19823+ pax_close_userland(); \
19824 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
19825 } while (0)
19826
19827@@ -471,8 +536,12 @@ struct __large_struct { unsigned long buf[100]; };
19828 * On error, the variable @x is set to zero.
19829 */
19830
19831+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19832+#define __get_user(x, ptr) get_user((x), (ptr))
19833+#else
19834 #define __get_user(x, ptr) \
19835 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
19836+#endif
19837
19838 /**
19839 * __put_user: - Write a simple value into user space, with less checking.
19840@@ -494,8 +563,12 @@ struct __large_struct { unsigned long buf[100]; };
19841 * Returns zero on success, or -EFAULT on error.
19842 */
19843
19844+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19845+#define __put_user(x, ptr) put_user((x), (ptr))
19846+#else
19847 #define __put_user(x, ptr) \
19848 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
19849+#endif
19850
19851 #define __get_user_unaligned __get_user
19852 #define __put_user_unaligned __put_user
19853@@ -513,7 +586,7 @@ struct __large_struct { unsigned long buf[100]; };
19854 #define get_user_ex(x, ptr) do { \
19855 unsigned long __gue_val; \
19856 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
19857- (x) = (__force __typeof__(*(ptr)))__gue_val; \
19858+ (x) = (__typeof__(*(ptr)))__gue_val; \
19859 } while (0)
19860
19861 #define put_user_try uaccess_try
19862@@ -542,18 +615,19 @@ extern void __cmpxchg_wrong_size(void)
19863 __typeof__(ptr) __uval = (uval); \
19864 __typeof__(*(ptr)) __old = (old); \
19865 __typeof__(*(ptr)) __new = (new); \
19866+ pax_open_userland(); \
19867 switch (size) { \
19868 case 1: \
19869 { \
19870 asm volatile("\t" ASM_STAC "\n" \
19871- "1:\t" LOCK_PREFIX "cmpxchgb %4, %2\n" \
19872+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgb %4, %2\n"\
19873 "2:\t" ASM_CLAC "\n" \
19874 "\t.section .fixup, \"ax\"\n" \
19875 "3:\tmov %3, %0\n" \
19876 "\tjmp 2b\n" \
19877 "\t.previous\n" \
19878 _ASM_EXTABLE(1b, 3b) \
19879- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19880+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19881 : "i" (-EFAULT), "q" (__new), "1" (__old) \
19882 : "memory" \
19883 ); \
19884@@ -562,14 +636,14 @@ extern void __cmpxchg_wrong_size(void)
19885 case 2: \
19886 { \
19887 asm volatile("\t" ASM_STAC "\n" \
19888- "1:\t" LOCK_PREFIX "cmpxchgw %4, %2\n" \
19889+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgw %4, %2\n"\
19890 "2:\t" ASM_CLAC "\n" \
19891 "\t.section .fixup, \"ax\"\n" \
19892 "3:\tmov %3, %0\n" \
19893 "\tjmp 2b\n" \
19894 "\t.previous\n" \
19895 _ASM_EXTABLE(1b, 3b) \
19896- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19897+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19898 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19899 : "memory" \
19900 ); \
19901@@ -578,14 +652,14 @@ extern void __cmpxchg_wrong_size(void)
19902 case 4: \
19903 { \
19904 asm volatile("\t" ASM_STAC "\n" \
19905- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n" \
19906+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"\
19907 "2:\t" ASM_CLAC "\n" \
19908 "\t.section .fixup, \"ax\"\n" \
19909 "3:\tmov %3, %0\n" \
19910 "\tjmp 2b\n" \
19911 "\t.previous\n" \
19912 _ASM_EXTABLE(1b, 3b) \
19913- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19914+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19915 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19916 : "memory" \
19917 ); \
19918@@ -597,14 +671,14 @@ extern void __cmpxchg_wrong_size(void)
19919 __cmpxchg_wrong_size(); \
19920 \
19921 asm volatile("\t" ASM_STAC "\n" \
19922- "1:\t" LOCK_PREFIX "cmpxchgq %4, %2\n" \
19923+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgq %4, %2\n"\
19924 "2:\t" ASM_CLAC "\n" \
19925 "\t.section .fixup, \"ax\"\n" \
19926 "3:\tmov %3, %0\n" \
19927 "\tjmp 2b\n" \
19928 "\t.previous\n" \
19929 _ASM_EXTABLE(1b, 3b) \
19930- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19931+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19932 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19933 : "memory" \
19934 ); \
19935@@ -613,6 +687,7 @@ extern void __cmpxchg_wrong_size(void)
19936 default: \
19937 __cmpxchg_wrong_size(); \
19938 } \
19939+ pax_close_userland(); \
19940 *__uval = __old; \
19941 __ret; \
19942 })
19943@@ -636,17 +711,6 @@ extern struct movsl_mask {
19944
19945 #define ARCH_HAS_NOCACHE_UACCESS 1
19946
19947-#ifdef CONFIG_X86_32
19948-# include <asm/uaccess_32.h>
19949-#else
19950-# include <asm/uaccess_64.h>
19951-#endif
19952-
19953-unsigned long __must_check _copy_from_user(void *to, const void __user *from,
19954- unsigned n);
19955-unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19956- unsigned n);
19957-
19958 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19959 # define copy_user_diag __compiletime_error
19960 #else
19961@@ -656,7 +720,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19962 extern void copy_user_diag("copy_from_user() buffer size is too small")
19963 copy_from_user_overflow(void);
19964 extern void copy_user_diag("copy_to_user() buffer size is too small")
19965-copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19966+copy_to_user_overflow(void);
19967
19968 #undef copy_user_diag
19969
19970@@ -669,7 +733,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
19971
19972 extern void
19973 __compiletime_warning("copy_to_user() buffer size is not provably correct")
19974-__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19975+__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
19976 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
19977
19978 #else
19979@@ -684,10 +748,16 @@ __copy_from_user_overflow(int size, unsigned long count)
19980
19981 #endif
19982
19983+#ifdef CONFIG_X86_32
19984+# include <asm/uaccess_32.h>
19985+#else
19986+# include <asm/uaccess_64.h>
19987+#endif
19988+
19989 static inline unsigned long __must_check
19990 copy_from_user(void *to, const void __user *from, unsigned long n)
19991 {
19992- int sz = __compiletime_object_size(to);
19993+ size_t sz = __compiletime_object_size(to);
19994
19995 might_fault();
19996
19997@@ -709,12 +779,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19998 * case, and do only runtime checking for non-constant sizes.
19999 */
20000
20001- if (likely(sz < 0 || sz >= n))
20002- n = _copy_from_user(to, from, n);
20003- else if(__builtin_constant_p(n))
20004- copy_from_user_overflow();
20005- else
20006- __copy_from_user_overflow(sz, n);
20007+ if (likely(sz != (size_t)-1 && sz < n)) {
20008+ if(__builtin_constant_p(n))
20009+ copy_from_user_overflow();
20010+ else
20011+ __copy_from_user_overflow(sz, n);
20012+ } if (access_ok(VERIFY_READ, from, n))
20013+ n = __copy_from_user(to, from, n);
20014+ else if ((long)n > 0)
20015+ memset(to, 0, n);
20016
20017 return n;
20018 }
20019@@ -722,17 +795,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
20020 static inline unsigned long __must_check
20021 copy_to_user(void __user *to, const void *from, unsigned long n)
20022 {
20023- int sz = __compiletime_object_size(from);
20024+ size_t sz = __compiletime_object_size(from);
20025
20026 might_fault();
20027
20028 /* See the comment in copy_from_user() above. */
20029- if (likely(sz < 0 || sz >= n))
20030- n = _copy_to_user(to, from, n);
20031- else if(__builtin_constant_p(n))
20032- copy_to_user_overflow();
20033- else
20034- __copy_to_user_overflow(sz, n);
20035+ if (likely(sz != (size_t)-1 && sz < n)) {
20036+ if(__builtin_constant_p(n))
20037+ copy_to_user_overflow();
20038+ else
20039+ __copy_to_user_overflow(sz, n);
20040+ } else if (access_ok(VERIFY_WRITE, to, n))
20041+ n = __copy_to_user(to, from, n);
20042
20043 return n;
20044 }
20045diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
20046index 3c03a5d..1071638 100644
20047--- a/arch/x86/include/asm/uaccess_32.h
20048+++ b/arch/x86/include/asm/uaccess_32.h
20049@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
20050 static __always_inline unsigned long __must_check
20051 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
20052 {
20053+ if ((long)n < 0)
20054+ return n;
20055+
20056+ check_object_size(from, n, true);
20057+
20058 if (__builtin_constant_p(n)) {
20059 unsigned long ret;
20060
20061@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
20062 __copy_to_user(void __user *to, const void *from, unsigned long n)
20063 {
20064 might_fault();
20065+
20066 return __copy_to_user_inatomic(to, from, n);
20067 }
20068
20069 static __always_inline unsigned long
20070 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
20071 {
20072+ if ((long)n < 0)
20073+ return n;
20074+
20075 /* Avoid zeroing the tail if the copy fails..
20076 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
20077 * but as the zeroing behaviour is only significant when n is not
20078@@ -137,6 +146,12 @@ static __always_inline unsigned long
20079 __copy_from_user(void *to, const void __user *from, unsigned long n)
20080 {
20081 might_fault();
20082+
20083+ if ((long)n < 0)
20084+ return n;
20085+
20086+ check_object_size(to, n, false);
20087+
20088 if (__builtin_constant_p(n)) {
20089 unsigned long ret;
20090
20091@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
20092 const void __user *from, unsigned long n)
20093 {
20094 might_fault();
20095+
20096+ if ((long)n < 0)
20097+ return n;
20098+
20099 if (__builtin_constant_p(n)) {
20100 unsigned long ret;
20101
20102@@ -181,7 +200,10 @@ static __always_inline unsigned long
20103 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
20104 unsigned long n)
20105 {
20106- return __copy_from_user_ll_nocache_nozero(to, from, n);
20107+ if ((long)n < 0)
20108+ return n;
20109+
20110+ return __copy_from_user_ll_nocache_nozero(to, from, n);
20111 }
20112
20113 #endif /* _ASM_X86_UACCESS_32_H */
20114diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
20115index 12a26b9..206c200 100644
20116--- a/arch/x86/include/asm/uaccess_64.h
20117+++ b/arch/x86/include/asm/uaccess_64.h
20118@@ -10,6 +10,9 @@
20119 #include <asm/alternative.h>
20120 #include <asm/cpufeature.h>
20121 #include <asm/page.h>
20122+#include <asm/pgtable.h>
20123+
20124+#define set_fs(x) (current_thread_info()->addr_limit = (x))
20125
20126 /*
20127 * Copy To/From Userspace
20128@@ -17,14 +20,14 @@
20129
20130 /* Handles exceptions in both to and from, but doesn't do access_ok */
20131 __must_check unsigned long
20132-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
20133+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
20134 __must_check unsigned long
20135-copy_user_generic_string(void *to, const void *from, unsigned len);
20136+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
20137 __must_check unsigned long
20138-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
20139+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
20140
20141 static __always_inline __must_check unsigned long
20142-copy_user_generic(void *to, const void *from, unsigned len)
20143+copy_user_generic(void *to, const void *from, unsigned long len)
20144 {
20145 unsigned ret;
20146
20147@@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
20148 }
20149
20150 __must_check unsigned long
20151-copy_in_user(void __user *to, const void __user *from, unsigned len);
20152+copy_in_user(void __user *to, const void __user *from, unsigned long len);
20153
20154 static __always_inline __must_check
20155-int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
20156+unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
20157 {
20158- int ret = 0;
20159+ size_t sz = __compiletime_object_size(dst);
20160+ unsigned ret = 0;
20161+
20162+ if (size > INT_MAX)
20163+ return size;
20164+
20165+ check_object_size(dst, size, false);
20166+
20167+#ifdef CONFIG_PAX_MEMORY_UDEREF
20168+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20169+ return size;
20170+#endif
20171+
20172+ if (unlikely(sz != (size_t)-1 && sz < size)) {
20173+ if(__builtin_constant_p(size))
20174+ copy_from_user_overflow();
20175+ else
20176+ __copy_from_user_overflow(sz, size);
20177+ return size;
20178+ }
20179
20180 if (!__builtin_constant_p(size))
20181- return copy_user_generic(dst, (__force void *)src, size);
20182+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20183 switch (size) {
20184- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
20185+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
20186 ret, "b", "b", "=q", 1);
20187 return ret;
20188- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
20189+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
20190 ret, "w", "w", "=r", 2);
20191 return ret;
20192- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
20193+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
20194 ret, "l", "k", "=r", 4);
20195 return ret;
20196- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
20197+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20198 ret, "q", "", "=r", 8);
20199 return ret;
20200 case 10:
20201- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
20202+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20203 ret, "q", "", "=r", 10);
20204 if (unlikely(ret))
20205 return ret;
20206 __get_user_asm(*(u16 *)(8 + (char *)dst),
20207- (u16 __user *)(8 + (char __user *)src),
20208+ (const u16 __user *)(8 + (const char __user *)src),
20209 ret, "w", "w", "=r", 2);
20210 return ret;
20211 case 16:
20212- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
20213+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20214 ret, "q", "", "=r", 16);
20215 if (unlikely(ret))
20216 return ret;
20217 __get_user_asm(*(u64 *)(8 + (char *)dst),
20218- (u64 __user *)(8 + (char __user *)src),
20219+ (const u64 __user *)(8 + (const char __user *)src),
20220 ret, "q", "", "=r", 8);
20221 return ret;
20222 default:
20223- return copy_user_generic(dst, (__force void *)src, size);
20224+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20225 }
20226 }
20227
20228 static __always_inline __must_check
20229-int __copy_from_user(void *dst, const void __user *src, unsigned size)
20230+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
20231 {
20232 might_fault();
20233 return __copy_from_user_nocheck(dst, src, size);
20234 }
20235
20236 static __always_inline __must_check
20237-int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
20238+unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
20239 {
20240- int ret = 0;
20241+ size_t sz = __compiletime_object_size(src);
20242+ unsigned ret = 0;
20243+
20244+ if (size > INT_MAX)
20245+ return size;
20246+
20247+ check_object_size(src, size, true);
20248+
20249+#ifdef CONFIG_PAX_MEMORY_UDEREF
20250+ if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20251+ return size;
20252+#endif
20253+
20254+ if (unlikely(sz != (size_t)-1 && sz < size)) {
20255+ if(__builtin_constant_p(size))
20256+ copy_to_user_overflow();
20257+ else
20258+ __copy_to_user_overflow(sz, size);
20259+ return size;
20260+ }
20261
20262 if (!__builtin_constant_p(size))
20263- return copy_user_generic((__force void *)dst, src, size);
20264+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20265 switch (size) {
20266- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
20267+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
20268 ret, "b", "b", "iq", 1);
20269 return ret;
20270- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
20271+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
20272 ret, "w", "w", "ir", 2);
20273 return ret;
20274- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
20275+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
20276 ret, "l", "k", "ir", 4);
20277 return ret;
20278- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
20279+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20280 ret, "q", "", "er", 8);
20281 return ret;
20282 case 10:
20283- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20284+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20285 ret, "q", "", "er", 10);
20286 if (unlikely(ret))
20287 return ret;
20288 asm("":::"memory");
20289- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
20290+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
20291 ret, "w", "w", "ir", 2);
20292 return ret;
20293 case 16:
20294- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20295+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20296 ret, "q", "", "er", 16);
20297 if (unlikely(ret))
20298 return ret;
20299 asm("":::"memory");
20300- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
20301+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
20302 ret, "q", "", "er", 8);
20303 return ret;
20304 default:
20305- return copy_user_generic((__force void *)dst, src, size);
20306+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20307 }
20308 }
20309
20310 static __always_inline __must_check
20311-int __copy_to_user(void __user *dst, const void *src, unsigned size)
20312+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
20313 {
20314 might_fault();
20315 return __copy_to_user_nocheck(dst, src, size);
20316 }
20317
20318 static __always_inline __must_check
20319-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20320+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20321 {
20322- int ret = 0;
20323+ unsigned ret = 0;
20324
20325 might_fault();
20326+
20327+ if (size > INT_MAX)
20328+ return size;
20329+
20330+#ifdef CONFIG_PAX_MEMORY_UDEREF
20331+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20332+ return size;
20333+ if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20334+ return size;
20335+#endif
20336+
20337 if (!__builtin_constant_p(size))
20338- return copy_user_generic((__force void *)dst,
20339- (__force void *)src, size);
20340+ return copy_user_generic((__force_kernel void *)____m(dst),
20341+ (__force_kernel const void *)____m(src), size);
20342 switch (size) {
20343 case 1: {
20344 u8 tmp;
20345- __get_user_asm(tmp, (u8 __user *)src,
20346+ __get_user_asm(tmp, (const u8 __user *)src,
20347 ret, "b", "b", "=q", 1);
20348 if (likely(!ret))
20349 __put_user_asm(tmp, (u8 __user *)dst,
20350@@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20351 }
20352 case 2: {
20353 u16 tmp;
20354- __get_user_asm(tmp, (u16 __user *)src,
20355+ __get_user_asm(tmp, (const u16 __user *)src,
20356 ret, "w", "w", "=r", 2);
20357 if (likely(!ret))
20358 __put_user_asm(tmp, (u16 __user *)dst,
20359@@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20360
20361 case 4: {
20362 u32 tmp;
20363- __get_user_asm(tmp, (u32 __user *)src,
20364+ __get_user_asm(tmp, (const u32 __user *)src,
20365 ret, "l", "k", "=r", 4);
20366 if (likely(!ret))
20367 __put_user_asm(tmp, (u32 __user *)dst,
20368@@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20369 }
20370 case 8: {
20371 u64 tmp;
20372- __get_user_asm(tmp, (u64 __user *)src,
20373+ __get_user_asm(tmp, (const u64 __user *)src,
20374 ret, "q", "", "=r", 8);
20375 if (likely(!ret))
20376 __put_user_asm(tmp, (u64 __user *)dst,
20377@@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20378 return ret;
20379 }
20380 default:
20381- return copy_user_generic((__force void *)dst,
20382- (__force void *)src, size);
20383+ return copy_user_generic((__force_kernel void *)____m(dst),
20384+ (__force_kernel const void *)____m(src), size);
20385 }
20386 }
20387
20388-static __must_check __always_inline int
20389-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
20390+static __must_check __always_inline unsigned long
20391+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
20392 {
20393 return __copy_from_user_nocheck(dst, src, size);
20394 }
20395
20396-static __must_check __always_inline int
20397-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
20398+static __must_check __always_inline unsigned long
20399+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
20400 {
20401 return __copy_to_user_nocheck(dst, src, size);
20402 }
20403
20404-extern long __copy_user_nocache(void *dst, const void __user *src,
20405- unsigned size, int zerorest);
20406+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
20407+ unsigned long size, int zerorest);
20408
20409-static inline int
20410-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
20411+static inline unsigned long
20412+__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
20413 {
20414 might_fault();
20415+
20416+ if (size > INT_MAX)
20417+ return size;
20418+
20419+#ifdef CONFIG_PAX_MEMORY_UDEREF
20420+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20421+ return size;
20422+#endif
20423+
20424 return __copy_user_nocache(dst, src, size, 1);
20425 }
20426
20427-static inline int
20428+static inline unsigned long
20429 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
20430- unsigned size)
20431+ unsigned long size)
20432 {
20433+ if (size > INT_MAX)
20434+ return size;
20435+
20436+#ifdef CONFIG_PAX_MEMORY_UDEREF
20437+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20438+ return size;
20439+#endif
20440+
20441 return __copy_user_nocache(dst, src, size, 0);
20442 }
20443
20444 unsigned long
20445-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
20446+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
20447
20448 #endif /* _ASM_X86_UACCESS_64_H */
20449diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
20450index 5b238981..77fdd78 100644
20451--- a/arch/x86/include/asm/word-at-a-time.h
20452+++ b/arch/x86/include/asm/word-at-a-time.h
20453@@ -11,7 +11,7 @@
20454 * and shift, for example.
20455 */
20456 struct word_at_a_time {
20457- const unsigned long one_bits, high_bits;
20458+ unsigned long one_bits, high_bits;
20459 };
20460
20461 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
20462diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
20463index e45e4da..44e8572 100644
20464--- a/arch/x86/include/asm/x86_init.h
20465+++ b/arch/x86/include/asm/x86_init.h
20466@@ -129,7 +129,7 @@ struct x86_init_ops {
20467 struct x86_init_timers timers;
20468 struct x86_init_iommu iommu;
20469 struct x86_init_pci pci;
20470-};
20471+} __no_const;
20472
20473 /**
20474 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
20475@@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
20476 void (*setup_percpu_clockev)(void);
20477 void (*early_percpu_clock_init)(void);
20478 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
20479-};
20480+} __no_const;
20481
20482 struct timespec;
20483
20484@@ -168,7 +168,7 @@ struct x86_platform_ops {
20485 void (*save_sched_clock_state)(void);
20486 void (*restore_sched_clock_state)(void);
20487 void (*apic_post_init)(void);
20488-};
20489+} __no_const;
20490
20491 struct pci_dev;
20492 struct msi_msg;
20493@@ -185,7 +185,7 @@ struct x86_msi_ops {
20494 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
20495 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
20496 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
20497-};
20498+} __no_const;
20499
20500 struct IO_APIC_route_entry;
20501 struct io_apic_irq_attr;
20502@@ -206,7 +206,7 @@ struct x86_io_apic_ops {
20503 unsigned int destination, int vector,
20504 struct io_apic_irq_attr *attr);
20505 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
20506-};
20507+} __no_const;
20508
20509 extern struct x86_init_ops x86_init;
20510 extern struct x86_cpuinit_ops x86_cpuinit;
20511diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
20512index 3e276eb..2eb3c30 100644
20513--- a/arch/x86/include/asm/xen/page.h
20514+++ b/arch/x86/include/asm/xen/page.h
20515@@ -56,7 +56,7 @@ extern int m2p_remove_override(struct page *page,
20516 extern struct page *m2p_find_override(unsigned long mfn);
20517 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
20518
20519-static inline unsigned long pfn_to_mfn(unsigned long pfn)
20520+static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
20521 {
20522 unsigned long mfn;
20523
20524diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
20525index 6c1d741..39e6ecf 100644
20526--- a/arch/x86/include/asm/xsave.h
20527+++ b/arch/x86/include/asm/xsave.h
20528@@ -80,8 +80,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20529 if (unlikely(err))
20530 return -EFAULT;
20531
20532+ pax_open_userland();
20533 __asm__ __volatile__(ASM_STAC "\n"
20534- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
20535+ "1:"
20536+ __copyuser_seg
20537+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
20538 "2: " ASM_CLAC "\n"
20539 ".section .fixup,\"ax\"\n"
20540 "3: movl $-1,%[err]\n"
20541@@ -91,18 +94,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20542 : [err] "=r" (err)
20543 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
20544 : "memory");
20545+ pax_close_userland();
20546 return err;
20547 }
20548
20549 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20550 {
20551 int err;
20552- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
20553+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
20554 u32 lmask = mask;
20555 u32 hmask = mask >> 32;
20556
20557+ pax_open_userland();
20558 __asm__ __volatile__(ASM_STAC "\n"
20559- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20560+ "1:"
20561+ __copyuser_seg
20562+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20563 "2: " ASM_CLAC "\n"
20564 ".section .fixup,\"ax\"\n"
20565 "3: movl $-1,%[err]\n"
20566@@ -112,6 +119,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20567 : [err] "=r" (err)
20568 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
20569 : "memory"); /* memory required? */
20570+ pax_close_userland();
20571 return err;
20572 }
20573
20574diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
20575index bbae024..e1528f9 100644
20576--- a/arch/x86/include/uapi/asm/e820.h
20577+++ b/arch/x86/include/uapi/asm/e820.h
20578@@ -63,7 +63,7 @@ struct e820map {
20579 #define ISA_START_ADDRESS 0xa0000
20580 #define ISA_END_ADDRESS 0x100000
20581
20582-#define BIOS_BEGIN 0x000a0000
20583+#define BIOS_BEGIN 0x000c0000
20584 #define BIOS_END 0x00100000
20585
20586 #define BIOS_ROM_BASE 0xffe00000
20587diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
20588index 7b0a55a..ad115bf 100644
20589--- a/arch/x86/include/uapi/asm/ptrace-abi.h
20590+++ b/arch/x86/include/uapi/asm/ptrace-abi.h
20591@@ -49,7 +49,6 @@
20592 #define EFLAGS 144
20593 #define RSP 152
20594 #define SS 160
20595-#define ARGOFFSET R11
20596 #endif /* __ASSEMBLY__ */
20597
20598 /* top of stack page */
20599diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
20600index cb648c8..91cb07e 100644
20601--- a/arch/x86/kernel/Makefile
20602+++ b/arch/x86/kernel/Makefile
20603@@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
20604 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
20605 obj-$(CONFIG_IRQ_WORK) += irq_work.o
20606 obj-y += probe_roms.o
20607-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
20608+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
20609 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
20610 obj-y += syscall_$(BITS).o
20611 obj-$(CONFIG_X86_64) += vsyscall_64.o
20612diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
20613index 1dac942..19c8b0c 100644
20614--- a/arch/x86/kernel/acpi/boot.c
20615+++ b/arch/x86/kernel/acpi/boot.c
20616@@ -1312,7 +1312,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
20617 * If your system is blacklisted here, but you find that acpi=force
20618 * works for you, please contact linux-acpi@vger.kernel.org
20619 */
20620-static struct dmi_system_id __initdata acpi_dmi_table[] = {
20621+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
20622 /*
20623 * Boxes that need ACPI disabled
20624 */
20625@@ -1387,7 +1387,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
20626 };
20627
20628 /* second table for DMI checks that should run after early-quirks */
20629-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
20630+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
20631 /*
20632 * HP laptops which use a DSDT reporting as HP/SB400/10000,
20633 * which includes some code which overrides all temperature
20634diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
20635index 3a2ae4c..9db31d6 100644
20636--- a/arch/x86/kernel/acpi/sleep.c
20637+++ b/arch/x86/kernel/acpi/sleep.c
20638@@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
20639 #else /* CONFIG_64BIT */
20640 #ifdef CONFIG_SMP
20641 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
20642+
20643+ pax_open_kernel();
20644 early_gdt_descr.address =
20645 (unsigned long)get_cpu_gdt_table(smp_processor_id());
20646+ pax_close_kernel();
20647+
20648 initial_gs = per_cpu_offset(smp_processor_id());
20649 #endif
20650 initial_code = (unsigned long)wakeup_long64;
20651diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
20652index 665c6b7..eae4d56 100644
20653--- a/arch/x86/kernel/acpi/wakeup_32.S
20654+++ b/arch/x86/kernel/acpi/wakeup_32.S
20655@@ -29,13 +29,11 @@ wakeup_pmode_return:
20656 # and restore the stack ... but you need gdt for this to work
20657 movl saved_context_esp, %esp
20658
20659- movl %cs:saved_magic, %eax
20660- cmpl $0x12345678, %eax
20661+ cmpl $0x12345678, saved_magic
20662 jne bogus_magic
20663
20664 # jump to place where we left off
20665- movl saved_eip, %eax
20666- jmp *%eax
20667+ jmp *(saved_eip)
20668
20669 bogus_magic:
20670 jmp bogus_magic
20671diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
20672index df94598..f3b29bf 100644
20673--- a/arch/x86/kernel/alternative.c
20674+++ b/arch/x86/kernel/alternative.c
20675@@ -269,6 +269,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20676 */
20677 for (a = start; a < end; a++) {
20678 instr = (u8 *)&a->instr_offset + a->instr_offset;
20679+
20680+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20681+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20682+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20683+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20684+#endif
20685+
20686 replacement = (u8 *)&a->repl_offset + a->repl_offset;
20687 BUG_ON(a->replacementlen > a->instrlen);
20688 BUG_ON(a->instrlen > sizeof(insnbuf));
20689@@ -300,10 +307,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
20690 for (poff = start; poff < end; poff++) {
20691 u8 *ptr = (u8 *)poff + *poff;
20692
20693+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20694+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20695+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20696+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20697+#endif
20698+
20699 if (!*poff || ptr < text || ptr >= text_end)
20700 continue;
20701 /* turn DS segment override prefix into lock prefix */
20702- if (*ptr == 0x3e)
20703+ if (*ktla_ktva(ptr) == 0x3e)
20704 text_poke(ptr, ((unsigned char []){0xf0}), 1);
20705 }
20706 mutex_unlock(&text_mutex);
20707@@ -318,10 +331,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
20708 for (poff = start; poff < end; poff++) {
20709 u8 *ptr = (u8 *)poff + *poff;
20710
20711+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20712+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20713+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20714+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20715+#endif
20716+
20717 if (!*poff || ptr < text || ptr >= text_end)
20718 continue;
20719 /* turn lock prefix into DS segment override prefix */
20720- if (*ptr == 0xf0)
20721+ if (*ktla_ktva(ptr) == 0xf0)
20722 text_poke(ptr, ((unsigned char []){0x3E}), 1);
20723 }
20724 mutex_unlock(&text_mutex);
20725@@ -458,7 +477,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
20726
20727 BUG_ON(p->len > MAX_PATCH_LEN);
20728 /* prep the buffer with the original instructions */
20729- memcpy(insnbuf, p->instr, p->len);
20730+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
20731 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
20732 (unsigned long)p->instr, p->len);
20733
20734@@ -505,7 +524,7 @@ void __init alternative_instructions(void)
20735 if (!uniproc_patched || num_possible_cpus() == 1)
20736 free_init_pages("SMP alternatives",
20737 (unsigned long)__smp_locks,
20738- (unsigned long)__smp_locks_end);
20739+ PAGE_ALIGN((unsigned long)__smp_locks_end));
20740 #endif
20741
20742 apply_paravirt(__parainstructions, __parainstructions_end);
20743@@ -525,13 +544,17 @@ void __init alternative_instructions(void)
20744 * instructions. And on the local CPU you need to be protected again NMI or MCE
20745 * handlers seeing an inconsistent instruction while you patch.
20746 */
20747-void *__init_or_module text_poke_early(void *addr, const void *opcode,
20748+void *__kprobes text_poke_early(void *addr, const void *opcode,
20749 size_t len)
20750 {
20751 unsigned long flags;
20752 local_irq_save(flags);
20753- memcpy(addr, opcode, len);
20754+
20755+ pax_open_kernel();
20756+ memcpy(ktla_ktva(addr), opcode, len);
20757 sync_core();
20758+ pax_close_kernel();
20759+
20760 local_irq_restore(flags);
20761 /* Could also do a CLFLUSH here to speed up CPU recovery; but
20762 that causes hangs on some VIA CPUs. */
20763@@ -553,36 +576,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
20764 */
20765 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
20766 {
20767- unsigned long flags;
20768- char *vaddr;
20769+ unsigned char *vaddr = ktla_ktva(addr);
20770 struct page *pages[2];
20771- int i;
20772+ size_t i;
20773
20774 if (!core_kernel_text((unsigned long)addr)) {
20775- pages[0] = vmalloc_to_page(addr);
20776- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
20777+ pages[0] = vmalloc_to_page(vaddr);
20778+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
20779 } else {
20780- pages[0] = virt_to_page(addr);
20781+ pages[0] = virt_to_page(vaddr);
20782 WARN_ON(!PageReserved(pages[0]));
20783- pages[1] = virt_to_page(addr + PAGE_SIZE);
20784+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
20785 }
20786 BUG_ON(!pages[0]);
20787- local_irq_save(flags);
20788- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
20789- if (pages[1])
20790- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
20791- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
20792- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
20793- clear_fixmap(FIX_TEXT_POKE0);
20794- if (pages[1])
20795- clear_fixmap(FIX_TEXT_POKE1);
20796- local_flush_tlb();
20797- sync_core();
20798- /* Could also do a CLFLUSH here to speed up CPU recovery; but
20799- that causes hangs on some VIA CPUs. */
20800+ text_poke_early(addr, opcode, len);
20801 for (i = 0; i < len; i++)
20802- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
20803- local_irq_restore(flags);
20804+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
20805 return addr;
20806 }
20807
20808@@ -602,7 +611,7 @@ int poke_int3_handler(struct pt_regs *regs)
20809 if (likely(!bp_patching_in_progress))
20810 return 0;
20811
20812- if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
20813+ if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
20814 return 0;
20815
20816 /* set up the specified breakpoint handler */
20817@@ -636,7 +645,7 @@ int poke_int3_handler(struct pt_regs *regs)
20818 */
20819 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
20820 {
20821- unsigned char int3 = 0xcc;
20822+ const unsigned char int3 = 0xcc;
20823
20824 bp_int3_handler = handler;
20825 bp_int3_addr = (u8 *)addr + sizeof(int3);
20826diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
20827index 7f26c9a..694544e 100644
20828--- a/arch/x86/kernel/apic/apic.c
20829+++ b/arch/x86/kernel/apic/apic.c
20830@@ -198,7 +198,7 @@ int first_system_vector = 0xfe;
20831 /*
20832 * Debug level, exported for io_apic.c
20833 */
20834-unsigned int apic_verbosity;
20835+int apic_verbosity;
20836
20837 int pic_mode;
20838
20839@@ -1992,7 +1992,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
20840 apic_write(APIC_ESR, 0);
20841 v = apic_read(APIC_ESR);
20842 ack_APIC_irq();
20843- atomic_inc(&irq_err_count);
20844+ atomic_inc_unchecked(&irq_err_count);
20845
20846 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x",
20847 smp_processor_id(), v);
20848diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
20849index 2c621a6..fa2b1ae 100644
20850--- a/arch/x86/kernel/apic/apic_flat_64.c
20851+++ b/arch/x86/kernel/apic/apic_flat_64.c
20852@@ -154,7 +154,7 @@ static int flat_probe(void)
20853 return 1;
20854 }
20855
20856-static struct apic apic_flat = {
20857+static struct apic apic_flat __read_only = {
20858 .name = "flat",
20859 .probe = flat_probe,
20860 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
20861@@ -268,7 +268,7 @@ static int physflat_probe(void)
20862 return 0;
20863 }
20864
20865-static struct apic apic_physflat = {
20866+static struct apic apic_physflat __read_only = {
20867
20868 .name = "physical flat",
20869 .probe = physflat_probe,
20870diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
20871index 191ce75..2db6d63 100644
20872--- a/arch/x86/kernel/apic/apic_noop.c
20873+++ b/arch/x86/kernel/apic/apic_noop.c
20874@@ -118,7 +118,7 @@ static void noop_apic_write(u32 reg, u32 v)
20875 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
20876 }
20877
20878-struct apic apic_noop = {
20879+struct apic apic_noop __read_only = {
20880 .name = "noop",
20881 .probe = noop_probe,
20882 .acpi_madt_oem_check = NULL,
20883diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
20884index d50e364..543bee3 100644
20885--- a/arch/x86/kernel/apic/bigsmp_32.c
20886+++ b/arch/x86/kernel/apic/bigsmp_32.c
20887@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
20888 return dmi_bigsmp;
20889 }
20890
20891-static struct apic apic_bigsmp = {
20892+static struct apic apic_bigsmp __read_only = {
20893
20894 .name = "bigsmp",
20895 .probe = probe_bigsmp,
20896diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
20897index c552247..587a316 100644
20898--- a/arch/x86/kernel/apic/es7000_32.c
20899+++ b/arch/x86/kernel/apic/es7000_32.c
20900@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
20901 return ret && es7000_apic_is_cluster();
20902 }
20903
20904-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
20905-static struct apic __refdata apic_es7000_cluster = {
20906+static struct apic apic_es7000_cluster __read_only = {
20907
20908 .name = "es7000",
20909 .probe = probe_es7000,
20910@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
20911 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
20912 };
20913
20914-static struct apic __refdata apic_es7000 = {
20915+static struct apic apic_es7000 __read_only = {
20916
20917 .name = "es7000",
20918 .probe = probe_es7000,
20919diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
20920index 6ad4658..38a7b5c 100644
20921--- a/arch/x86/kernel/apic/io_apic.c
20922+++ b/arch/x86/kernel/apic/io_apic.c
20923@@ -1057,7 +1057,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
20924 }
20925 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
20926
20927-void lock_vector_lock(void)
20928+void lock_vector_lock(void) __acquires(vector_lock)
20929 {
20930 /* Used to the online set of cpus does not change
20931 * during assign_irq_vector.
20932@@ -1065,7 +1065,7 @@ void lock_vector_lock(void)
20933 raw_spin_lock(&vector_lock);
20934 }
20935
20936-void unlock_vector_lock(void)
20937+void unlock_vector_lock(void) __releases(vector_lock)
20938 {
20939 raw_spin_unlock(&vector_lock);
20940 }
20941@@ -2364,7 +2364,7 @@ static void ack_apic_edge(struct irq_data *data)
20942 ack_APIC_irq();
20943 }
20944
20945-atomic_t irq_mis_count;
20946+atomic_unchecked_t irq_mis_count;
20947
20948 #ifdef CONFIG_GENERIC_PENDING_IRQ
20949 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
20950@@ -2505,7 +2505,7 @@ static void ack_apic_level(struct irq_data *data)
20951 * at the cpu.
20952 */
20953 if (!(v & (1 << (i & 0x1f)))) {
20954- atomic_inc(&irq_mis_count);
20955+ atomic_inc_unchecked(&irq_mis_count);
20956
20957 eoi_ioapic_irq(irq, cfg);
20958 }
20959diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
20960index 1e42e8f..daacf44 100644
20961--- a/arch/x86/kernel/apic/numaq_32.c
20962+++ b/arch/x86/kernel/apic/numaq_32.c
20963@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
20964 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
20965 }
20966
20967-/* Use __refdata to keep false positive warning calm. */
20968-static struct apic __refdata apic_numaq = {
20969+static struct apic apic_numaq __read_only = {
20970
20971 .name = "NUMAQ",
20972 .probe = probe_numaq,
20973diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
20974index eb35ef9..f184a21 100644
20975--- a/arch/x86/kernel/apic/probe_32.c
20976+++ b/arch/x86/kernel/apic/probe_32.c
20977@@ -72,7 +72,7 @@ static int probe_default(void)
20978 return 1;
20979 }
20980
20981-static struct apic apic_default = {
20982+static struct apic apic_default __read_only = {
20983
20984 .name = "default",
20985 .probe = probe_default,
20986diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
20987index 00146f9..5e299b8 100644
20988--- a/arch/x86/kernel/apic/summit_32.c
20989+++ b/arch/x86/kernel/apic/summit_32.c
20990@@ -485,7 +485,7 @@ void setup_summit(void)
20991 }
20992 #endif
20993
20994-static struct apic apic_summit = {
20995+static struct apic apic_summit __read_only = {
20996
20997 .name = "summit",
20998 .probe = probe_summit,
20999diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
21000index cac85ee..01fa741 100644
21001--- a/arch/x86/kernel/apic/x2apic_cluster.c
21002+++ b/arch/x86/kernel/apic/x2apic_cluster.c
21003@@ -182,7 +182,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
21004 return notifier_from_errno(err);
21005 }
21006
21007-static struct notifier_block __refdata x2apic_cpu_notifier = {
21008+static struct notifier_block x2apic_cpu_notifier = {
21009 .notifier_call = update_clusterinfo,
21010 };
21011
21012@@ -234,7 +234,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
21013 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
21014 }
21015
21016-static struct apic apic_x2apic_cluster = {
21017+static struct apic apic_x2apic_cluster __read_only = {
21018
21019 .name = "cluster x2apic",
21020 .probe = x2apic_cluster_probe,
21021diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
21022index de231e3..1d1b2ee 100644
21023--- a/arch/x86/kernel/apic/x2apic_phys.c
21024+++ b/arch/x86/kernel/apic/x2apic_phys.c
21025@@ -88,7 +88,7 @@ static int x2apic_phys_probe(void)
21026 return apic == &apic_x2apic_phys;
21027 }
21028
21029-static struct apic apic_x2apic_phys = {
21030+static struct apic apic_x2apic_phys __read_only = {
21031
21032 .name = "physical x2apic",
21033 .probe = x2apic_phys_probe,
21034diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
21035index d263b13..963258b 100644
21036--- a/arch/x86/kernel/apic/x2apic_uv_x.c
21037+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
21038@@ -350,7 +350,7 @@ static int uv_probe(void)
21039 return apic == &apic_x2apic_uv_x;
21040 }
21041
21042-static struct apic __refdata apic_x2apic_uv_x = {
21043+static struct apic apic_x2apic_uv_x __read_only = {
21044
21045 .name = "UV large system",
21046 .probe = uv_probe,
21047diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
21048index 3ab0343..814c4787 100644
21049--- a/arch/x86/kernel/apm_32.c
21050+++ b/arch/x86/kernel/apm_32.c
21051@@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
21052 * This is for buggy BIOS's that refer to (real mode) segment 0x40
21053 * even though they are called in protected mode.
21054 */
21055-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
21056+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
21057 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
21058
21059 static const char driver_version[] = "1.16ac"; /* no spaces */
21060@@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
21061 BUG_ON(cpu != 0);
21062 gdt = get_cpu_gdt_table(cpu);
21063 save_desc_40 = gdt[0x40 / 8];
21064+
21065+ pax_open_kernel();
21066 gdt[0x40 / 8] = bad_bios_desc;
21067+ pax_close_kernel();
21068
21069 apm_irq_save(flags);
21070 APM_DO_SAVE_SEGS;
21071@@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
21072 &call->esi);
21073 APM_DO_RESTORE_SEGS;
21074 apm_irq_restore(flags);
21075+
21076+ pax_open_kernel();
21077 gdt[0x40 / 8] = save_desc_40;
21078+ pax_close_kernel();
21079+
21080 put_cpu();
21081
21082 return call->eax & 0xff;
21083@@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
21084 BUG_ON(cpu != 0);
21085 gdt = get_cpu_gdt_table(cpu);
21086 save_desc_40 = gdt[0x40 / 8];
21087+
21088+ pax_open_kernel();
21089 gdt[0x40 / 8] = bad_bios_desc;
21090+ pax_close_kernel();
21091
21092 apm_irq_save(flags);
21093 APM_DO_SAVE_SEGS;
21094@@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
21095 &call->eax);
21096 APM_DO_RESTORE_SEGS;
21097 apm_irq_restore(flags);
21098+
21099+ pax_open_kernel();
21100 gdt[0x40 / 8] = save_desc_40;
21101+ pax_close_kernel();
21102+
21103 put_cpu();
21104 return error;
21105 }
21106@@ -2362,12 +2376,15 @@ static int __init apm_init(void)
21107 * code to that CPU.
21108 */
21109 gdt = get_cpu_gdt_table(0);
21110+
21111+ pax_open_kernel();
21112 set_desc_base(&gdt[APM_CS >> 3],
21113 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
21114 set_desc_base(&gdt[APM_CS_16 >> 3],
21115 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
21116 set_desc_base(&gdt[APM_DS >> 3],
21117 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
21118+ pax_close_kernel();
21119
21120 proc_create("apm", 0, NULL, &apm_file_ops);
21121
21122diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
21123index 9f6b934..cf5ffb3 100644
21124--- a/arch/x86/kernel/asm-offsets.c
21125+++ b/arch/x86/kernel/asm-offsets.c
21126@@ -32,6 +32,8 @@ void common(void) {
21127 OFFSET(TI_flags, thread_info, flags);
21128 OFFSET(TI_status, thread_info, status);
21129 OFFSET(TI_addr_limit, thread_info, addr_limit);
21130+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
21131+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
21132
21133 BLANK();
21134 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
21135@@ -52,8 +54,26 @@ void common(void) {
21136 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
21137 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
21138 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
21139+
21140+#ifdef CONFIG_PAX_KERNEXEC
21141+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
21142 #endif
21143
21144+#ifdef CONFIG_PAX_MEMORY_UDEREF
21145+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
21146+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
21147+#ifdef CONFIG_X86_64
21148+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
21149+#endif
21150+#endif
21151+
21152+#endif
21153+
21154+ BLANK();
21155+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
21156+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
21157+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
21158+
21159 #ifdef CONFIG_XEN
21160 BLANK();
21161 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
21162diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
21163index e7c798b..2b2019b 100644
21164--- a/arch/x86/kernel/asm-offsets_64.c
21165+++ b/arch/x86/kernel/asm-offsets_64.c
21166@@ -77,6 +77,7 @@ int main(void)
21167 BLANK();
21168 #undef ENTRY
21169
21170+ DEFINE(TSS_size, sizeof(struct tss_struct));
21171 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
21172 BLANK();
21173
21174diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
21175index 7fd54f0..0691410 100644
21176--- a/arch/x86/kernel/cpu/Makefile
21177+++ b/arch/x86/kernel/cpu/Makefile
21178@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
21179 CFLAGS_REMOVE_perf_event.o = -pg
21180 endif
21181
21182-# Make sure load_percpu_segment has no stackprotector
21183-nostackp := $(call cc-option, -fno-stack-protector)
21184-CFLAGS_common.o := $(nostackp)
21185-
21186 obj-y := intel_cacheinfo.o scattered.o topology.o
21187 obj-y += proc.o capflags.o powerflags.o common.o
21188 obj-y += rdrand.o
21189diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
21190index c67ffa6..f41fbbf 100644
21191--- a/arch/x86/kernel/cpu/amd.c
21192+++ b/arch/x86/kernel/cpu/amd.c
21193@@ -752,7 +752,7 @@ static void init_amd(struct cpuinfo_x86 *c)
21194 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
21195 {
21196 /* AMD errata T13 (order #21922) */
21197- if ((c->x86 == 6)) {
21198+ if (c->x86 == 6) {
21199 /* Duron Rev A0 */
21200 if (c->x86_model == 3 && c->x86_mask == 0)
21201 size = 64;
21202diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
21203index 8e28bf2..bf5c0d2 100644
21204--- a/arch/x86/kernel/cpu/common.c
21205+++ b/arch/x86/kernel/cpu/common.c
21206@@ -88,60 +88,6 @@ static const struct cpu_dev default_cpu = {
21207
21208 static const struct cpu_dev *this_cpu = &default_cpu;
21209
21210-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
21211-#ifdef CONFIG_X86_64
21212- /*
21213- * We need valid kernel segments for data and code in long mode too
21214- * IRET will check the segment types kkeil 2000/10/28
21215- * Also sysret mandates a special GDT layout
21216- *
21217- * TLS descriptors are currently at a different place compared to i386.
21218- * Hopefully nobody expects them at a fixed place (Wine?)
21219- */
21220- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
21221- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
21222- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
21223- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
21224- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
21225- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
21226-#else
21227- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
21228- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21229- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
21230- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
21231- /*
21232- * Segments used for calling PnP BIOS have byte granularity.
21233- * They code segments and data segments have fixed 64k limits,
21234- * the transfer segment sizes are set at run time.
21235- */
21236- /* 32-bit code */
21237- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21238- /* 16-bit code */
21239- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
21240- /* 16-bit data */
21241- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
21242- /* 16-bit data */
21243- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
21244- /* 16-bit data */
21245- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
21246- /*
21247- * The APM segments have byte granularity and their bases
21248- * are set at run time. All have 64k limits.
21249- */
21250- /* 32-bit code */
21251- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21252- /* 16-bit code */
21253- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
21254- /* data */
21255- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
21256-
21257- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21258- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21259- GDT_STACK_CANARY_INIT
21260-#endif
21261-} };
21262-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
21263-
21264 static int __init x86_xsave_setup(char *s)
21265 {
21266 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
21267@@ -293,6 +239,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
21268 }
21269 }
21270
21271+#ifdef CONFIG_X86_64
21272+static __init int setup_disable_pcid(char *arg)
21273+{
21274+ setup_clear_cpu_cap(X86_FEATURE_PCID);
21275+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
21276+
21277+#ifdef CONFIG_PAX_MEMORY_UDEREF
21278+ if (clone_pgd_mask != ~(pgdval_t)0UL)
21279+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21280+#endif
21281+
21282+ return 1;
21283+}
21284+__setup("nopcid", setup_disable_pcid);
21285+
21286+static void setup_pcid(struct cpuinfo_x86 *c)
21287+{
21288+ if (!cpu_has(c, X86_FEATURE_PCID)) {
21289+ clear_cpu_cap(c, X86_FEATURE_INVPCID);
21290+
21291+#ifdef CONFIG_PAX_MEMORY_UDEREF
21292+ if (clone_pgd_mask != ~(pgdval_t)0UL) {
21293+ pax_open_kernel();
21294+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21295+ pax_close_kernel();
21296+ printk("PAX: slow and weak UDEREF enabled\n");
21297+ } else
21298+ printk("PAX: UDEREF disabled\n");
21299+#endif
21300+
21301+ return;
21302+ }
21303+
21304+ printk("PAX: PCID detected\n");
21305+ set_in_cr4(X86_CR4_PCIDE);
21306+
21307+#ifdef CONFIG_PAX_MEMORY_UDEREF
21308+ pax_open_kernel();
21309+ clone_pgd_mask = ~(pgdval_t)0UL;
21310+ pax_close_kernel();
21311+ if (pax_user_shadow_base)
21312+ printk("PAX: weak UDEREF enabled\n");
21313+ else {
21314+ set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
21315+ printk("PAX: strong UDEREF enabled\n");
21316+ }
21317+#endif
21318+
21319+ if (cpu_has(c, X86_FEATURE_INVPCID))
21320+ printk("PAX: INVPCID detected\n");
21321+}
21322+#endif
21323+
21324 /*
21325 * Some CPU features depend on higher CPUID levels, which may not always
21326 * be available due to CPUID level capping or broken virtualization
21327@@ -393,7 +392,7 @@ void switch_to_new_gdt(int cpu)
21328 {
21329 struct desc_ptr gdt_descr;
21330
21331- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
21332+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
21333 gdt_descr.size = GDT_SIZE - 1;
21334 load_gdt(&gdt_descr);
21335 /* Reload the per-cpu base */
21336@@ -883,6 +882,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21337 setup_smep(c);
21338 setup_smap(c);
21339
21340+#ifdef CONFIG_X86_64
21341+ setup_pcid(c);
21342+#endif
21343+
21344 /*
21345 * The vendor-specific functions might have changed features.
21346 * Now we do "generic changes."
21347@@ -891,6 +894,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21348 /* Filter out anything that depends on CPUID levels we don't have */
21349 filter_cpuid_features(c, true);
21350
21351+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
21352+ setup_clear_cpu_cap(X86_FEATURE_SEP);
21353+#endif
21354+
21355 /* If the model name is still unset, do table lookup. */
21356 if (!c->x86_model_id[0]) {
21357 const char *p;
21358@@ -1078,10 +1085,12 @@ static __init int setup_disablecpuid(char *arg)
21359 }
21360 __setup("clearcpuid=", setup_disablecpuid);
21361
21362+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
21363+EXPORT_PER_CPU_SYMBOL(current_tinfo);
21364+
21365 #ifdef CONFIG_X86_64
21366-struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21367-struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
21368- (unsigned long) debug_idt_table };
21369+struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21370+const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
21371
21372 DEFINE_PER_CPU_FIRST(union irq_stack_union,
21373 irq_stack_union) __aligned(PAGE_SIZE) __visible;
21374@@ -1095,7 +1104,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
21375 EXPORT_PER_CPU_SYMBOL(current_task);
21376
21377 DEFINE_PER_CPU(unsigned long, kernel_stack) =
21378- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
21379+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
21380 EXPORT_PER_CPU_SYMBOL(kernel_stack);
21381
21382 DEFINE_PER_CPU(char *, irq_stack_ptr) =
21383@@ -1245,7 +1254,7 @@ void cpu_init(void)
21384 load_ucode_ap();
21385
21386 cpu = stack_smp_processor_id();
21387- t = &per_cpu(init_tss, cpu);
21388+ t = init_tss + cpu;
21389 oist = &per_cpu(orig_ist, cpu);
21390
21391 #ifdef CONFIG_NUMA
21392@@ -1280,7 +1289,6 @@ void cpu_init(void)
21393 wrmsrl(MSR_KERNEL_GS_BASE, 0);
21394 barrier();
21395
21396- x86_configure_nx();
21397 enable_x2apic();
21398
21399 /*
21400@@ -1332,7 +1340,7 @@ void cpu_init(void)
21401 {
21402 int cpu = smp_processor_id();
21403 struct task_struct *curr = current;
21404- struct tss_struct *t = &per_cpu(init_tss, cpu);
21405+ struct tss_struct *t = init_tss + cpu;
21406 struct thread_struct *thread = &curr->thread;
21407
21408 show_ucode_info_early();
21409diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
21410index 0641113..06f5ba4 100644
21411--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
21412+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
21413@@ -1014,6 +1014,22 @@ static struct attribute *default_attrs[] = {
21414 };
21415
21416 #ifdef CONFIG_AMD_NB
21417+static struct attribute *default_attrs_amd_nb[] = {
21418+ &type.attr,
21419+ &level.attr,
21420+ &coherency_line_size.attr,
21421+ &physical_line_partition.attr,
21422+ &ways_of_associativity.attr,
21423+ &number_of_sets.attr,
21424+ &size.attr,
21425+ &shared_cpu_map.attr,
21426+ &shared_cpu_list.attr,
21427+ NULL,
21428+ NULL,
21429+ NULL,
21430+ NULL
21431+};
21432+
21433 static struct attribute **amd_l3_attrs(void)
21434 {
21435 static struct attribute **attrs;
21436@@ -1024,18 +1040,7 @@ static struct attribute **amd_l3_attrs(void)
21437
21438 n = ARRAY_SIZE(default_attrs);
21439
21440- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
21441- n += 2;
21442-
21443- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
21444- n += 1;
21445-
21446- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
21447- if (attrs == NULL)
21448- return attrs = default_attrs;
21449-
21450- for (n = 0; default_attrs[n]; n++)
21451- attrs[n] = default_attrs[n];
21452+ attrs = default_attrs_amd_nb;
21453
21454 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
21455 attrs[n++] = &cache_disable_0.attr;
21456@@ -1086,6 +1091,13 @@ static struct kobj_type ktype_cache = {
21457 .default_attrs = default_attrs,
21458 };
21459
21460+#ifdef CONFIG_AMD_NB
21461+static struct kobj_type ktype_cache_amd_nb = {
21462+ .sysfs_ops = &sysfs_ops,
21463+ .default_attrs = default_attrs_amd_nb,
21464+};
21465+#endif
21466+
21467 static struct kobj_type ktype_percpu_entry = {
21468 .sysfs_ops = &sysfs_ops,
21469 };
21470@@ -1151,20 +1163,26 @@ static int cache_add_dev(struct device *dev)
21471 return retval;
21472 }
21473
21474+#ifdef CONFIG_AMD_NB
21475+ amd_l3_attrs();
21476+#endif
21477+
21478 for (i = 0; i < num_cache_leaves; i++) {
21479+ struct kobj_type *ktype;
21480+
21481 this_object = INDEX_KOBJECT_PTR(cpu, i);
21482 this_object->cpu = cpu;
21483 this_object->index = i;
21484
21485 this_leaf = CPUID4_INFO_IDX(cpu, i);
21486
21487- ktype_cache.default_attrs = default_attrs;
21488+ ktype = &ktype_cache;
21489 #ifdef CONFIG_AMD_NB
21490 if (this_leaf->base.nb)
21491- ktype_cache.default_attrs = amd_l3_attrs();
21492+ ktype = &ktype_cache_amd_nb;
21493 #endif
21494 retval = kobject_init_and_add(&(this_object->kobj),
21495- &ktype_cache,
21496+ ktype,
21497 per_cpu(ici_cache_kobject, cpu),
21498 "index%1lu", i);
21499 if (unlikely(retval)) {
21500diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
21501index 4d5419b..95f11bb 100644
21502--- a/arch/x86/kernel/cpu/mcheck/mce.c
21503+++ b/arch/x86/kernel/cpu/mcheck/mce.c
21504@@ -45,6 +45,7 @@
21505 #include <asm/processor.h>
21506 #include <asm/mce.h>
21507 #include <asm/msr.h>
21508+#include <asm/local.h>
21509
21510 #include "mce-internal.h"
21511
21512@@ -258,7 +259,7 @@ static void print_mce(struct mce *m)
21513 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
21514 m->cs, m->ip);
21515
21516- if (m->cs == __KERNEL_CS)
21517+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
21518 print_symbol("{%s}", m->ip);
21519 pr_cont("\n");
21520 }
21521@@ -291,10 +292,10 @@ static void print_mce(struct mce *m)
21522
21523 #define PANIC_TIMEOUT 5 /* 5 seconds */
21524
21525-static atomic_t mce_paniced;
21526+static atomic_unchecked_t mce_paniced;
21527
21528 static int fake_panic;
21529-static atomic_t mce_fake_paniced;
21530+static atomic_unchecked_t mce_fake_paniced;
21531
21532 /* Panic in progress. Enable interrupts and wait for final IPI */
21533 static void wait_for_panic(void)
21534@@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21535 /*
21536 * Make sure only one CPU runs in machine check panic
21537 */
21538- if (atomic_inc_return(&mce_paniced) > 1)
21539+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
21540 wait_for_panic();
21541 barrier();
21542
21543@@ -326,7 +327,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21544 console_verbose();
21545 } else {
21546 /* Don't log too much for fake panic */
21547- if (atomic_inc_return(&mce_fake_paniced) > 1)
21548+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
21549 return;
21550 }
21551 /* First print corrected ones that are still unlogged */
21552@@ -365,7 +366,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21553 if (!fake_panic) {
21554 if (panic_timeout == 0)
21555 panic_timeout = mca_cfg.panic_timeout;
21556- panic(msg);
21557+ panic("%s", msg);
21558 } else
21559 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
21560 }
21561@@ -695,7 +696,7 @@ static int mce_timed_out(u64 *t)
21562 * might have been modified by someone else.
21563 */
21564 rmb();
21565- if (atomic_read(&mce_paniced))
21566+ if (atomic_read_unchecked(&mce_paniced))
21567 wait_for_panic();
21568 if (!mca_cfg.monarch_timeout)
21569 goto out;
21570@@ -1666,7 +1667,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
21571 }
21572
21573 /* Call the installed machine check handler for this CPU setup. */
21574-void (*machine_check_vector)(struct pt_regs *, long error_code) =
21575+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
21576 unexpected_machine_check;
21577
21578 /*
21579@@ -1689,7 +1690,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21580 return;
21581 }
21582
21583+ pax_open_kernel();
21584 machine_check_vector = do_machine_check;
21585+ pax_close_kernel();
21586
21587 __mcheck_cpu_init_generic();
21588 __mcheck_cpu_init_vendor(c);
21589@@ -1703,7 +1706,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21590 */
21591
21592 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
21593-static int mce_chrdev_open_count; /* #times opened */
21594+static local_t mce_chrdev_open_count; /* #times opened */
21595 static int mce_chrdev_open_exclu; /* already open exclusive? */
21596
21597 static int mce_chrdev_open(struct inode *inode, struct file *file)
21598@@ -1711,7 +1714,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21599 spin_lock(&mce_chrdev_state_lock);
21600
21601 if (mce_chrdev_open_exclu ||
21602- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
21603+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
21604 spin_unlock(&mce_chrdev_state_lock);
21605
21606 return -EBUSY;
21607@@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21608
21609 if (file->f_flags & O_EXCL)
21610 mce_chrdev_open_exclu = 1;
21611- mce_chrdev_open_count++;
21612+ local_inc(&mce_chrdev_open_count);
21613
21614 spin_unlock(&mce_chrdev_state_lock);
21615
21616@@ -1730,7 +1733,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
21617 {
21618 spin_lock(&mce_chrdev_state_lock);
21619
21620- mce_chrdev_open_count--;
21621+ local_dec(&mce_chrdev_open_count);
21622 mce_chrdev_open_exclu = 0;
21623
21624 spin_unlock(&mce_chrdev_state_lock);
21625@@ -2406,7 +2409,7 @@ static __init void mce_init_banks(void)
21626
21627 for (i = 0; i < mca_cfg.banks; i++) {
21628 struct mce_bank *b = &mce_banks[i];
21629- struct device_attribute *a = &b->attr;
21630+ device_attribute_no_const *a = &b->attr;
21631
21632 sysfs_attr_init(&a->attr);
21633 a->attr.name = b->attrname;
21634@@ -2474,7 +2477,7 @@ struct dentry *mce_get_debugfs_dir(void)
21635 static void mce_reset(void)
21636 {
21637 cpu_missing = 0;
21638- atomic_set(&mce_fake_paniced, 0);
21639+ atomic_set_unchecked(&mce_fake_paniced, 0);
21640 atomic_set(&mce_executing, 0);
21641 atomic_set(&mce_callin, 0);
21642 atomic_set(&global_nwo, 0);
21643diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
21644index a304298..49b6d06 100644
21645--- a/arch/x86/kernel/cpu/mcheck/p5.c
21646+++ b/arch/x86/kernel/cpu/mcheck/p5.c
21647@@ -10,6 +10,7 @@
21648 #include <asm/processor.h>
21649 #include <asm/mce.h>
21650 #include <asm/msr.h>
21651+#include <asm/pgtable.h>
21652
21653 /* By default disabled */
21654 int mce_p5_enabled __read_mostly;
21655@@ -48,7 +49,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
21656 if (!cpu_has(c, X86_FEATURE_MCE))
21657 return;
21658
21659+ pax_open_kernel();
21660 machine_check_vector = pentium_machine_check;
21661+ pax_close_kernel();
21662 /* Make sure the vector pointer is visible before we enable MCEs: */
21663 wmb();
21664
21665diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
21666index 7dc5564..1273569 100644
21667--- a/arch/x86/kernel/cpu/mcheck/winchip.c
21668+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
21669@@ -9,6 +9,7 @@
21670 #include <asm/processor.h>
21671 #include <asm/mce.h>
21672 #include <asm/msr.h>
21673+#include <asm/pgtable.h>
21674
21675 /* Machine check handler for WinChip C6: */
21676 static void winchip_machine_check(struct pt_regs *regs, long error_code)
21677@@ -22,7 +23,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
21678 {
21679 u32 lo, hi;
21680
21681+ pax_open_kernel();
21682 machine_check_vector = winchip_machine_check;
21683+ pax_close_kernel();
21684 /* Make sure the vector pointer is visible before we enable MCEs: */
21685 wmb();
21686
21687diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
21688index 15c9876..0a43909 100644
21689--- a/arch/x86/kernel/cpu/microcode/core.c
21690+++ b/arch/x86/kernel/cpu/microcode/core.c
21691@@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21692 return NOTIFY_OK;
21693 }
21694
21695-static struct notifier_block __refdata mc_cpu_notifier = {
21696+static struct notifier_block mc_cpu_notifier = {
21697 .notifier_call = mc_cpu_callback,
21698 };
21699
21700diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
21701index a276fa7..e66810f 100644
21702--- a/arch/x86/kernel/cpu/microcode/intel.c
21703+++ b/arch/x86/kernel/cpu/microcode/intel.c
21704@@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21705
21706 static int get_ucode_user(void *to, const void *from, size_t n)
21707 {
21708- return copy_from_user(to, from, n);
21709+ return copy_from_user(to, (const void __force_user *)from, n);
21710 }
21711
21712 static enum ucode_state
21713 request_microcode_user(int cpu, const void __user *buf, size_t size)
21714 {
21715- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21716+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21717 }
21718
21719 static void microcode_fini_cpu(int cpu)
21720diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
21721index f961de9..8a9d332 100644
21722--- a/arch/x86/kernel/cpu/mtrr/main.c
21723+++ b/arch/x86/kernel/cpu/mtrr/main.c
21724@@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
21725 u64 size_or_mask, size_and_mask;
21726 static bool mtrr_aps_delayed_init;
21727
21728-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
21729+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
21730
21731 const struct mtrr_ops *mtrr_if;
21732
21733diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
21734index df5e41f..816c719 100644
21735--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
21736+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
21737@@ -25,7 +25,7 @@ struct mtrr_ops {
21738 int (*validate_add_page)(unsigned long base, unsigned long size,
21739 unsigned int type);
21740 int (*have_wrcomb)(void);
21741-};
21742+} __do_const;
21743
21744 extern int generic_get_free_region(unsigned long base, unsigned long size,
21745 int replace_reg);
21746diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
21747index 79f9f84..38ace52 100644
21748--- a/arch/x86/kernel/cpu/perf_event.c
21749+++ b/arch/x86/kernel/cpu/perf_event.c
21750@@ -1351,7 +1351,7 @@ static void __init pmu_check_apic(void)
21751 pr_info("no hardware sampling interrupt available.\n");
21752 }
21753
21754-static struct attribute_group x86_pmu_format_group = {
21755+static attribute_group_no_const x86_pmu_format_group = {
21756 .name = "format",
21757 .attrs = NULL,
21758 };
21759@@ -1450,7 +1450,7 @@ static struct attribute *events_attr[] = {
21760 NULL,
21761 };
21762
21763-static struct attribute_group x86_pmu_events_group = {
21764+static attribute_group_no_const x86_pmu_events_group = {
21765 .name = "events",
21766 .attrs = events_attr,
21767 };
21768@@ -1971,7 +1971,7 @@ static unsigned long get_segment_base(unsigned int segment)
21769 if (idx > GDT_ENTRIES)
21770 return 0;
21771
21772- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
21773+ desc = get_cpu_gdt_table(smp_processor_id());
21774 }
21775
21776 return get_desc_base(desc + idx);
21777@@ -2061,7 +2061,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
21778 break;
21779
21780 perf_callchain_store(entry, frame.return_address);
21781- fp = frame.next_frame;
21782+ fp = (const void __force_user *)frame.next_frame;
21783 }
21784 }
21785
21786diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21787index 639d128..e92d7e5 100644
21788--- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21789+++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21790@@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
21791 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
21792 {
21793 struct attribute **attrs;
21794- struct attribute_group *attr_group;
21795+ attribute_group_no_const *attr_group;
21796 int i = 0, j;
21797
21798 while (amd_iommu_v2_event_descs[i].attr.attr.name)
21799diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
21800index aa333d9..f9db700 100644
21801--- a/arch/x86/kernel/cpu/perf_event_intel.c
21802+++ b/arch/x86/kernel/cpu/perf_event_intel.c
21803@@ -2309,10 +2309,10 @@ __init int intel_pmu_init(void)
21804 x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
21805
21806 if (boot_cpu_has(X86_FEATURE_PDCM)) {
21807- u64 capabilities;
21808+ u64 capabilities = x86_pmu.intel_cap.capabilities;
21809
21810- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
21811- x86_pmu.intel_cap.capabilities = capabilities;
21812+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
21813+ x86_pmu.intel_cap.capabilities = capabilities;
21814 }
21815
21816 intel_ds_init();
21817diff --git a/arch/x86/kernel/cpu/perf_event_intel_rapl.c b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21818index 5ad35ad..e0a3960 100644
21819--- a/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21820+++ b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21821@@ -425,7 +425,7 @@ static struct attribute *rapl_events_cln_attr[] = {
21822 NULL,
21823 };
21824
21825-static struct attribute_group rapl_pmu_events_group = {
21826+static attribute_group_no_const rapl_pmu_events_group __read_only = {
21827 .name = "events",
21828 .attrs = NULL, /* patched at runtime */
21829 };
21830diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21831index 047f540..afdeba0 100644
21832--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21833+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21834@@ -3326,7 +3326,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
21835 static int __init uncore_type_init(struct intel_uncore_type *type)
21836 {
21837 struct intel_uncore_pmu *pmus;
21838- struct attribute_group *attr_group;
21839+ attribute_group_no_const *attr_group;
21840 struct attribute **attrs;
21841 int i, j;
21842
21843diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21844index a80ab71..4089da5 100644
21845--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21846+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21847@@ -498,7 +498,7 @@ struct intel_uncore_box {
21848 struct uncore_event_desc {
21849 struct kobj_attribute attr;
21850 const char *config;
21851-};
21852+} __do_const;
21853
21854 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
21855 { \
21856diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
21857index 7d9481c..99c7e4b 100644
21858--- a/arch/x86/kernel/cpuid.c
21859+++ b/arch/x86/kernel/cpuid.c
21860@@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
21861 return notifier_from_errno(err);
21862 }
21863
21864-static struct notifier_block __refdata cpuid_class_cpu_notifier =
21865+static struct notifier_block cpuid_class_cpu_notifier =
21866 {
21867 .notifier_call = cpuid_class_cpu_callback,
21868 };
21869diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
21870index a57902e..ebaae2a 100644
21871--- a/arch/x86/kernel/crash.c
21872+++ b/arch/x86/kernel/crash.c
21873@@ -57,10 +57,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
21874 {
21875 #ifdef CONFIG_X86_32
21876 struct pt_regs fixed_regs;
21877-#endif
21878
21879-#ifdef CONFIG_X86_32
21880- if (!user_mode_vm(regs)) {
21881+ if (!user_mode(regs)) {
21882 crash_fixup_ss_esp(&fixed_regs, regs);
21883 regs = &fixed_regs;
21884 }
21885diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
21886index afa64ad..dce67dd 100644
21887--- a/arch/x86/kernel/crash_dump_64.c
21888+++ b/arch/x86/kernel/crash_dump_64.c
21889@@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
21890 return -ENOMEM;
21891
21892 if (userbuf) {
21893- if (copy_to_user(buf, vaddr + offset, csize)) {
21894+ if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
21895 iounmap(vaddr);
21896 return -EFAULT;
21897 }
21898diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
21899index f6dfd93..892ade4 100644
21900--- a/arch/x86/kernel/doublefault.c
21901+++ b/arch/x86/kernel/doublefault.c
21902@@ -12,7 +12,7 @@
21903
21904 #define DOUBLEFAULT_STACKSIZE (1024)
21905 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
21906-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
21907+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
21908
21909 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
21910
21911@@ -22,7 +22,7 @@ static void doublefault_fn(void)
21912 unsigned long gdt, tss;
21913
21914 native_store_gdt(&gdt_desc);
21915- gdt = gdt_desc.address;
21916+ gdt = (unsigned long)gdt_desc.address;
21917
21918 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
21919
21920@@ -59,10 +59,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
21921 /* 0x2 bit is always set */
21922 .flags = X86_EFLAGS_SF | 0x2,
21923 .sp = STACK_START,
21924- .es = __USER_DS,
21925+ .es = __KERNEL_DS,
21926 .cs = __KERNEL_CS,
21927 .ss = __KERNEL_DS,
21928- .ds = __USER_DS,
21929+ .ds = __KERNEL_DS,
21930 .fs = __KERNEL_PERCPU,
21931
21932 .__cr3 = __pa_nodebug(swapper_pg_dir),
21933diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
21934index d9c12d3..7858b62 100644
21935--- a/arch/x86/kernel/dumpstack.c
21936+++ b/arch/x86/kernel/dumpstack.c
21937@@ -2,6 +2,9 @@
21938 * Copyright (C) 1991, 1992 Linus Torvalds
21939 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
21940 */
21941+#ifdef CONFIG_GRKERNSEC_HIDESYM
21942+#define __INCLUDED_BY_HIDESYM 1
21943+#endif
21944 #include <linux/kallsyms.h>
21945 #include <linux/kprobes.h>
21946 #include <linux/uaccess.h>
21947@@ -40,16 +43,14 @@ void printk_address(unsigned long address)
21948 static void
21949 print_ftrace_graph_addr(unsigned long addr, void *data,
21950 const struct stacktrace_ops *ops,
21951- struct thread_info *tinfo, int *graph)
21952+ struct task_struct *task, int *graph)
21953 {
21954- struct task_struct *task;
21955 unsigned long ret_addr;
21956 int index;
21957
21958 if (addr != (unsigned long)return_to_handler)
21959 return;
21960
21961- task = tinfo->task;
21962 index = task->curr_ret_stack;
21963
21964 if (!task->ret_stack || index < *graph)
21965@@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21966 static inline void
21967 print_ftrace_graph_addr(unsigned long addr, void *data,
21968 const struct stacktrace_ops *ops,
21969- struct thread_info *tinfo, int *graph)
21970+ struct task_struct *task, int *graph)
21971 { }
21972 #endif
21973
21974@@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21975 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
21976 */
21977
21978-static inline int valid_stack_ptr(struct thread_info *tinfo,
21979- void *p, unsigned int size, void *end)
21980+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
21981 {
21982- void *t = tinfo;
21983 if (end) {
21984 if (p < end && p >= (end-THREAD_SIZE))
21985 return 1;
21986@@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
21987 }
21988
21989 unsigned long
21990-print_context_stack(struct thread_info *tinfo,
21991+print_context_stack(struct task_struct *task, void *stack_start,
21992 unsigned long *stack, unsigned long bp,
21993 const struct stacktrace_ops *ops, void *data,
21994 unsigned long *end, int *graph)
21995 {
21996 struct stack_frame *frame = (struct stack_frame *)bp;
21997
21998- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
21999+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
22000 unsigned long addr;
22001
22002 addr = *stack;
22003@@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
22004 } else {
22005 ops->address(data, addr, 0);
22006 }
22007- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
22008+ print_ftrace_graph_addr(addr, data, ops, task, graph);
22009 }
22010 stack++;
22011 }
22012@@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
22013 EXPORT_SYMBOL_GPL(print_context_stack);
22014
22015 unsigned long
22016-print_context_stack_bp(struct thread_info *tinfo,
22017+print_context_stack_bp(struct task_struct *task, void *stack_start,
22018 unsigned long *stack, unsigned long bp,
22019 const struct stacktrace_ops *ops, void *data,
22020 unsigned long *end, int *graph)
22021@@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
22022 struct stack_frame *frame = (struct stack_frame *)bp;
22023 unsigned long *ret_addr = &frame->return_address;
22024
22025- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
22026+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
22027 unsigned long addr = *ret_addr;
22028
22029 if (!__kernel_text_address(addr))
22030@@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
22031 ops->address(data, addr, 1);
22032 frame = frame->next_frame;
22033 ret_addr = &frame->return_address;
22034- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
22035+ print_ftrace_graph_addr(addr, data, ops, task, graph);
22036 }
22037
22038 return (unsigned long)frame;
22039@@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
22040 static void print_trace_address(void *data, unsigned long addr, int reliable)
22041 {
22042 touch_nmi_watchdog();
22043- printk(data);
22044+ printk("%s", (char *)data);
22045 printk_stack_address(addr, reliable);
22046 }
22047
22048@@ -224,6 +223,8 @@ unsigned __kprobes long oops_begin(void)
22049 }
22050 EXPORT_SYMBOL_GPL(oops_begin);
22051
22052+extern void gr_handle_kernel_exploit(void);
22053+
22054 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
22055 {
22056 if (regs && kexec_should_crash(current))
22057@@ -245,7 +246,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
22058 panic("Fatal exception in interrupt");
22059 if (panic_on_oops)
22060 panic("Fatal exception");
22061- do_exit(signr);
22062+
22063+ gr_handle_kernel_exploit();
22064+
22065+ do_group_exit(signr);
22066 }
22067
22068 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
22069@@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
22070 print_modules();
22071 show_regs(regs);
22072 #ifdef CONFIG_X86_32
22073- if (user_mode_vm(regs)) {
22074+ if (user_mode(regs)) {
22075 sp = regs->sp;
22076 ss = regs->ss & 0xffff;
22077 } else {
22078@@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
22079 unsigned long flags = oops_begin();
22080 int sig = SIGSEGV;
22081
22082- if (!user_mode_vm(regs))
22083+ if (!user_mode(regs))
22084 report_bug(regs->ip, regs);
22085
22086 if (__die(str, regs, err))
22087diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
22088index f2a1770..10fa52d 100644
22089--- a/arch/x86/kernel/dumpstack_32.c
22090+++ b/arch/x86/kernel/dumpstack_32.c
22091@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22092 bp = stack_frame(task, regs);
22093
22094 for (;;) {
22095- struct thread_info *context;
22096+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
22097
22098- context = (struct thread_info *)
22099- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
22100- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
22101+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
22102
22103- stack = (unsigned long *)context->previous_esp;
22104- if (!stack)
22105+ if (stack_start == task_stack_page(task))
22106 break;
22107+ stack = *(unsigned long **)stack_start;
22108 if (ops->stack(data, "IRQ") < 0)
22109 break;
22110 touch_nmi_watchdog();
22111@@ -87,27 +85,28 @@ void show_regs(struct pt_regs *regs)
22112 int i;
22113
22114 show_regs_print_info(KERN_EMERG);
22115- __show_regs(regs, !user_mode_vm(regs));
22116+ __show_regs(regs, !user_mode(regs));
22117
22118 /*
22119 * When in-kernel, we also print out the stack and code at the
22120 * time of the fault..
22121 */
22122- if (!user_mode_vm(regs)) {
22123+ if (!user_mode(regs)) {
22124 unsigned int code_prologue = code_bytes * 43 / 64;
22125 unsigned int code_len = code_bytes;
22126 unsigned char c;
22127 u8 *ip;
22128+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
22129
22130 pr_emerg("Stack:\n");
22131 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
22132
22133 pr_emerg("Code:");
22134
22135- ip = (u8 *)regs->ip - code_prologue;
22136+ ip = (u8 *)regs->ip - code_prologue + cs_base;
22137 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
22138 /* try starting at IP */
22139- ip = (u8 *)regs->ip;
22140+ ip = (u8 *)regs->ip + cs_base;
22141 code_len = code_len - code_prologue + 1;
22142 }
22143 for (i = 0; i < code_len; i++, ip++) {
22144@@ -116,7 +115,7 @@ void show_regs(struct pt_regs *regs)
22145 pr_cont(" Bad EIP value.");
22146 break;
22147 }
22148- if (ip == (u8 *)regs->ip)
22149+ if (ip == (u8 *)regs->ip + cs_base)
22150 pr_cont(" <%02x>", c);
22151 else
22152 pr_cont(" %02x", c);
22153@@ -129,6 +128,7 @@ int is_valid_bugaddr(unsigned long ip)
22154 {
22155 unsigned short ud2;
22156
22157+ ip = ktla_ktva(ip);
22158 if (ip < PAGE_OFFSET)
22159 return 0;
22160 if (probe_kernel_address((unsigned short *)ip, ud2))
22161@@ -136,3 +136,15 @@ int is_valid_bugaddr(unsigned long ip)
22162
22163 return ud2 == 0x0b0f;
22164 }
22165+
22166+#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22167+void pax_check_alloca(unsigned long size)
22168+{
22169+ unsigned long sp = (unsigned long)&sp, stack_left;
22170+
22171+ /* all kernel stacks are of the same size */
22172+ stack_left = sp & (THREAD_SIZE - 1);
22173+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
22174+}
22175+EXPORT_SYMBOL(pax_check_alloca);
22176+#endif
22177diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
22178index addb207..921706b 100644
22179--- a/arch/x86/kernel/dumpstack_64.c
22180+++ b/arch/x86/kernel/dumpstack_64.c
22181@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22182 unsigned long *irq_stack_end =
22183 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
22184 unsigned used = 0;
22185- struct thread_info *tinfo;
22186 int graph = 0;
22187 unsigned long dummy;
22188+ void *stack_start;
22189
22190 if (!task)
22191 task = current;
22192@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22193 * current stack address. If the stacks consist of nested
22194 * exceptions
22195 */
22196- tinfo = task_thread_info(task);
22197 for (;;) {
22198 char *id;
22199 unsigned long *estack_end;
22200+
22201 estack_end = in_exception_stack(cpu, (unsigned long)stack,
22202 &used, &id);
22203
22204@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22205 if (ops->stack(data, id) < 0)
22206 break;
22207
22208- bp = ops->walk_stack(tinfo, stack, bp, ops,
22209+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
22210 data, estack_end, &graph);
22211 ops->stack(data, "<EOE>");
22212 /*
22213@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22214 * second-to-last pointer (index -2 to end) in the
22215 * exception stack:
22216 */
22217+ if ((u16)estack_end[-1] != __KERNEL_DS)
22218+ goto out;
22219 stack = (unsigned long *) estack_end[-2];
22220 continue;
22221 }
22222@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22223 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
22224 if (ops->stack(data, "IRQ") < 0)
22225 break;
22226- bp = ops->walk_stack(tinfo, stack, bp,
22227+ bp = ops->walk_stack(task, irq_stack, stack, bp,
22228 ops, data, irq_stack_end, &graph);
22229 /*
22230 * We link to the next stack (which would be
22231@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22232 /*
22233 * This handles the process stack:
22234 */
22235- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
22236+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
22237+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
22238+out:
22239 put_cpu();
22240 }
22241 EXPORT_SYMBOL(dump_trace);
22242@@ -300,3 +304,50 @@ int is_valid_bugaddr(unsigned long ip)
22243
22244 return ud2 == 0x0b0f;
22245 }
22246+
22247+#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22248+void pax_check_alloca(unsigned long size)
22249+{
22250+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
22251+ unsigned cpu, used;
22252+ char *id;
22253+
22254+ /* check the process stack first */
22255+ stack_start = (unsigned long)task_stack_page(current);
22256+ stack_end = stack_start + THREAD_SIZE;
22257+ if (likely(stack_start <= sp && sp < stack_end)) {
22258+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
22259+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
22260+ return;
22261+ }
22262+
22263+ cpu = get_cpu();
22264+
22265+ /* check the irq stacks */
22266+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
22267+ stack_start = stack_end - IRQ_STACK_SIZE;
22268+ if (stack_start <= sp && sp < stack_end) {
22269+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
22270+ put_cpu();
22271+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
22272+ return;
22273+ }
22274+
22275+ /* check the exception stacks */
22276+ used = 0;
22277+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
22278+ stack_start = stack_end - EXCEPTION_STKSZ;
22279+ if (stack_end && stack_start <= sp && sp < stack_end) {
22280+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
22281+ put_cpu();
22282+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
22283+ return;
22284+ }
22285+
22286+ put_cpu();
22287+
22288+ /* unknown stack */
22289+ BUG();
22290+}
22291+EXPORT_SYMBOL(pax_check_alloca);
22292+#endif
22293diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
22294index 988c00a..4f673b6 100644
22295--- a/arch/x86/kernel/e820.c
22296+++ b/arch/x86/kernel/e820.c
22297@@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
22298
22299 static void early_panic(char *msg)
22300 {
22301- early_printk(msg);
22302- panic(msg);
22303+ early_printk("%s", msg);
22304+ panic("%s", msg);
22305 }
22306
22307 static int userdef __initdata;
22308diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
22309index 01d1c18..8073693 100644
22310--- a/arch/x86/kernel/early_printk.c
22311+++ b/arch/x86/kernel/early_printk.c
22312@@ -7,6 +7,7 @@
22313 #include <linux/pci_regs.h>
22314 #include <linux/pci_ids.h>
22315 #include <linux/errno.h>
22316+#include <linux/sched.h>
22317 #include <asm/io.h>
22318 #include <asm/processor.h>
22319 #include <asm/fcntl.h>
22320diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
22321index a2a4f46..6cab058 100644
22322--- a/arch/x86/kernel/entry_32.S
22323+++ b/arch/x86/kernel/entry_32.S
22324@@ -177,13 +177,153 @@
22325 /*CFI_REL_OFFSET gs, PT_GS*/
22326 .endm
22327 .macro SET_KERNEL_GS reg
22328+
22329+#ifdef CONFIG_CC_STACKPROTECTOR
22330 movl $(__KERNEL_STACK_CANARY), \reg
22331+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
22332+ movl $(__USER_DS), \reg
22333+#else
22334+ xorl \reg, \reg
22335+#endif
22336+
22337 movl \reg, %gs
22338 .endm
22339
22340 #endif /* CONFIG_X86_32_LAZY_GS */
22341
22342-.macro SAVE_ALL
22343+.macro pax_enter_kernel
22344+#ifdef CONFIG_PAX_KERNEXEC
22345+ call pax_enter_kernel
22346+#endif
22347+.endm
22348+
22349+.macro pax_exit_kernel
22350+#ifdef CONFIG_PAX_KERNEXEC
22351+ call pax_exit_kernel
22352+#endif
22353+.endm
22354+
22355+#ifdef CONFIG_PAX_KERNEXEC
22356+ENTRY(pax_enter_kernel)
22357+#ifdef CONFIG_PARAVIRT
22358+ pushl %eax
22359+ pushl %ecx
22360+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
22361+ mov %eax, %esi
22362+#else
22363+ mov %cr0, %esi
22364+#endif
22365+ bts $16, %esi
22366+ jnc 1f
22367+ mov %cs, %esi
22368+ cmp $__KERNEL_CS, %esi
22369+ jz 3f
22370+ ljmp $__KERNEL_CS, $3f
22371+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
22372+2:
22373+#ifdef CONFIG_PARAVIRT
22374+ mov %esi, %eax
22375+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
22376+#else
22377+ mov %esi, %cr0
22378+#endif
22379+3:
22380+#ifdef CONFIG_PARAVIRT
22381+ popl %ecx
22382+ popl %eax
22383+#endif
22384+ ret
22385+ENDPROC(pax_enter_kernel)
22386+
22387+ENTRY(pax_exit_kernel)
22388+#ifdef CONFIG_PARAVIRT
22389+ pushl %eax
22390+ pushl %ecx
22391+#endif
22392+ mov %cs, %esi
22393+ cmp $__KERNEXEC_KERNEL_CS, %esi
22394+ jnz 2f
22395+#ifdef CONFIG_PARAVIRT
22396+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
22397+ mov %eax, %esi
22398+#else
22399+ mov %cr0, %esi
22400+#endif
22401+ btr $16, %esi
22402+ ljmp $__KERNEL_CS, $1f
22403+1:
22404+#ifdef CONFIG_PARAVIRT
22405+ mov %esi, %eax
22406+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
22407+#else
22408+ mov %esi, %cr0
22409+#endif
22410+2:
22411+#ifdef CONFIG_PARAVIRT
22412+ popl %ecx
22413+ popl %eax
22414+#endif
22415+ ret
22416+ENDPROC(pax_exit_kernel)
22417+#endif
22418+
22419+ .macro pax_erase_kstack
22420+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22421+ call pax_erase_kstack
22422+#endif
22423+ .endm
22424+
22425+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22426+/*
22427+ * ebp: thread_info
22428+ */
22429+ENTRY(pax_erase_kstack)
22430+ pushl %edi
22431+ pushl %ecx
22432+ pushl %eax
22433+
22434+ mov TI_lowest_stack(%ebp), %edi
22435+ mov $-0xBEEF, %eax
22436+ std
22437+
22438+1: mov %edi, %ecx
22439+ and $THREAD_SIZE_asm - 1, %ecx
22440+ shr $2, %ecx
22441+ repne scasl
22442+ jecxz 2f
22443+
22444+ cmp $2*16, %ecx
22445+ jc 2f
22446+
22447+ mov $2*16, %ecx
22448+ repe scasl
22449+ jecxz 2f
22450+ jne 1b
22451+
22452+2: cld
22453+ mov %esp, %ecx
22454+ sub %edi, %ecx
22455+
22456+ cmp $THREAD_SIZE_asm, %ecx
22457+ jb 3f
22458+ ud2
22459+3:
22460+
22461+ shr $2, %ecx
22462+ rep stosl
22463+
22464+ mov TI_task_thread_sp0(%ebp), %edi
22465+ sub $128, %edi
22466+ mov %edi, TI_lowest_stack(%ebp)
22467+
22468+ popl %eax
22469+ popl %ecx
22470+ popl %edi
22471+ ret
22472+ENDPROC(pax_erase_kstack)
22473+#endif
22474+
22475+.macro __SAVE_ALL _DS
22476 cld
22477 PUSH_GS
22478 pushl_cfi %fs
22479@@ -206,7 +346,7 @@
22480 CFI_REL_OFFSET ecx, 0
22481 pushl_cfi %ebx
22482 CFI_REL_OFFSET ebx, 0
22483- movl $(__USER_DS), %edx
22484+ movl $\_DS, %edx
22485 movl %edx, %ds
22486 movl %edx, %es
22487 movl $(__KERNEL_PERCPU), %edx
22488@@ -214,6 +354,15 @@
22489 SET_KERNEL_GS %edx
22490 .endm
22491
22492+.macro SAVE_ALL
22493+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22494+ __SAVE_ALL __KERNEL_DS
22495+ pax_enter_kernel
22496+#else
22497+ __SAVE_ALL __USER_DS
22498+#endif
22499+.endm
22500+
22501 .macro RESTORE_INT_REGS
22502 popl_cfi %ebx
22503 CFI_RESTORE ebx
22504@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
22505 popfl_cfi
22506 jmp syscall_exit
22507 CFI_ENDPROC
22508-END(ret_from_fork)
22509+ENDPROC(ret_from_fork)
22510
22511 ENTRY(ret_from_kernel_thread)
22512 CFI_STARTPROC
22513@@ -344,7 +493,15 @@ ret_from_intr:
22514 andl $SEGMENT_RPL_MASK, %eax
22515 #endif
22516 cmpl $USER_RPL, %eax
22517+
22518+#ifdef CONFIG_PAX_KERNEXEC
22519+ jae resume_userspace
22520+
22521+ pax_exit_kernel
22522+ jmp resume_kernel
22523+#else
22524 jb resume_kernel # not returning to v8086 or userspace
22525+#endif
22526
22527 ENTRY(resume_userspace)
22528 LOCKDEP_SYS_EXIT
22529@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
22530 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
22531 # int/exception return?
22532 jne work_pending
22533- jmp restore_all
22534-END(ret_from_exception)
22535+ jmp restore_all_pax
22536+ENDPROC(ret_from_exception)
22537
22538 #ifdef CONFIG_PREEMPT
22539 ENTRY(resume_kernel)
22540@@ -369,7 +526,7 @@ need_resched:
22541 jz restore_all
22542 call preempt_schedule_irq
22543 jmp need_resched
22544-END(resume_kernel)
22545+ENDPROC(resume_kernel)
22546 #endif
22547 CFI_ENDPROC
22548 /*
22549@@ -403,30 +560,45 @@ sysenter_past_esp:
22550 /*CFI_REL_OFFSET cs, 0*/
22551 /*
22552 * Push current_thread_info()->sysenter_return to the stack.
22553- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
22554- * pushed above; +8 corresponds to copy_thread's esp0 setting.
22555 */
22556- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
22557+ pushl_cfi $0
22558 CFI_REL_OFFSET eip, 0
22559
22560 pushl_cfi %eax
22561 SAVE_ALL
22562+ GET_THREAD_INFO(%ebp)
22563+ movl TI_sysenter_return(%ebp),%ebp
22564+ movl %ebp,PT_EIP(%esp)
22565 ENABLE_INTERRUPTS(CLBR_NONE)
22566
22567 /*
22568 * Load the potential sixth argument from user stack.
22569 * Careful about security.
22570 */
22571+ movl PT_OLDESP(%esp),%ebp
22572+
22573+#ifdef CONFIG_PAX_MEMORY_UDEREF
22574+ mov PT_OLDSS(%esp),%ds
22575+1: movl %ds:(%ebp),%ebp
22576+ push %ss
22577+ pop %ds
22578+#else
22579 cmpl $__PAGE_OFFSET-3,%ebp
22580 jae syscall_fault
22581 ASM_STAC
22582 1: movl (%ebp),%ebp
22583 ASM_CLAC
22584+#endif
22585+
22586 movl %ebp,PT_EBP(%esp)
22587 _ASM_EXTABLE(1b,syscall_fault)
22588
22589 GET_THREAD_INFO(%ebp)
22590
22591+#ifdef CONFIG_PAX_RANDKSTACK
22592+ pax_erase_kstack
22593+#endif
22594+
22595 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22596 jnz sysenter_audit
22597 sysenter_do_call:
22598@@ -441,12 +613,24 @@ sysenter_do_call:
22599 testl $_TIF_ALLWORK_MASK, %ecx
22600 jne sysexit_audit
22601 sysenter_exit:
22602+
22603+#ifdef CONFIG_PAX_RANDKSTACK
22604+ pushl_cfi %eax
22605+ movl %esp, %eax
22606+ call pax_randomize_kstack
22607+ popl_cfi %eax
22608+#endif
22609+
22610+ pax_erase_kstack
22611+
22612 /* if something modifies registers it must also disable sysexit */
22613 movl PT_EIP(%esp), %edx
22614 movl PT_OLDESP(%esp), %ecx
22615 xorl %ebp,%ebp
22616 TRACE_IRQS_ON
22617 1: mov PT_FS(%esp), %fs
22618+2: mov PT_DS(%esp), %ds
22619+3: mov PT_ES(%esp), %es
22620 PTGS_TO_GS
22621 ENABLE_INTERRUPTS_SYSEXIT
22622
22623@@ -463,6 +647,9 @@ sysenter_audit:
22624 movl %eax,%edx /* 2nd arg: syscall number */
22625 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
22626 call __audit_syscall_entry
22627+
22628+ pax_erase_kstack
22629+
22630 pushl_cfi %ebx
22631 movl PT_EAX(%esp),%eax /* reload syscall number */
22632 jmp sysenter_do_call
22633@@ -488,10 +675,16 @@ sysexit_audit:
22634
22635 CFI_ENDPROC
22636 .pushsection .fixup,"ax"
22637-2: movl $0,PT_FS(%esp)
22638+4: movl $0,PT_FS(%esp)
22639+ jmp 1b
22640+5: movl $0,PT_DS(%esp)
22641+ jmp 1b
22642+6: movl $0,PT_ES(%esp)
22643 jmp 1b
22644 .popsection
22645- _ASM_EXTABLE(1b,2b)
22646+ _ASM_EXTABLE(1b,4b)
22647+ _ASM_EXTABLE(2b,5b)
22648+ _ASM_EXTABLE(3b,6b)
22649 PTGS_TO_GS_EX
22650 ENDPROC(ia32_sysenter_target)
22651
22652@@ -506,6 +699,11 @@ ENTRY(system_call)
22653 pushl_cfi %eax # save orig_eax
22654 SAVE_ALL
22655 GET_THREAD_INFO(%ebp)
22656+
22657+#ifdef CONFIG_PAX_RANDKSTACK
22658+ pax_erase_kstack
22659+#endif
22660+
22661 # system call tracing in operation / emulation
22662 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22663 jnz syscall_trace_entry
22664@@ -524,6 +722,15 @@ syscall_exit:
22665 testl $_TIF_ALLWORK_MASK, %ecx # current->work
22666 jne syscall_exit_work
22667
22668+restore_all_pax:
22669+
22670+#ifdef CONFIG_PAX_RANDKSTACK
22671+ movl %esp, %eax
22672+ call pax_randomize_kstack
22673+#endif
22674+
22675+ pax_erase_kstack
22676+
22677 restore_all:
22678 TRACE_IRQS_IRET
22679 restore_all_notrace:
22680@@ -580,14 +787,34 @@ ldt_ss:
22681 * compensating for the offset by changing to the ESPFIX segment with
22682 * a base address that matches for the difference.
22683 */
22684-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
22685+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
22686 mov %esp, %edx /* load kernel esp */
22687 mov PT_OLDESP(%esp), %eax /* load userspace esp */
22688 mov %dx, %ax /* eax: new kernel esp */
22689 sub %eax, %edx /* offset (low word is 0) */
22690+#ifdef CONFIG_SMP
22691+ movl PER_CPU_VAR(cpu_number), %ebx
22692+ shll $PAGE_SHIFT_asm, %ebx
22693+ addl $cpu_gdt_table, %ebx
22694+#else
22695+ movl $cpu_gdt_table, %ebx
22696+#endif
22697 shr $16, %edx
22698- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
22699- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
22700+
22701+#ifdef CONFIG_PAX_KERNEXEC
22702+ mov %cr0, %esi
22703+ btr $16, %esi
22704+ mov %esi, %cr0
22705+#endif
22706+
22707+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
22708+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
22709+
22710+#ifdef CONFIG_PAX_KERNEXEC
22711+ bts $16, %esi
22712+ mov %esi, %cr0
22713+#endif
22714+
22715 pushl_cfi $__ESPFIX_SS
22716 pushl_cfi %eax /* new kernel esp */
22717 /* Disable interrupts, but do not irqtrace this section: we
22718@@ -616,20 +843,18 @@ work_resched:
22719 movl TI_flags(%ebp), %ecx
22720 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
22721 # than syscall tracing?
22722- jz restore_all
22723+ jz restore_all_pax
22724 testb $_TIF_NEED_RESCHED, %cl
22725 jnz work_resched
22726
22727 work_notifysig: # deal with pending signals and
22728 # notify-resume requests
22729+ movl %esp, %eax
22730 #ifdef CONFIG_VM86
22731 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
22732- movl %esp, %eax
22733 jne work_notifysig_v86 # returning to kernel-space or
22734 # vm86-space
22735 1:
22736-#else
22737- movl %esp, %eax
22738 #endif
22739 TRACE_IRQS_ON
22740 ENABLE_INTERRUPTS(CLBR_NONE)
22741@@ -650,7 +875,7 @@ work_notifysig_v86:
22742 movl %eax, %esp
22743 jmp 1b
22744 #endif
22745-END(work_pending)
22746+ENDPROC(work_pending)
22747
22748 # perform syscall exit tracing
22749 ALIGN
22750@@ -658,11 +883,14 @@ syscall_trace_entry:
22751 movl $-ENOSYS,PT_EAX(%esp)
22752 movl %esp, %eax
22753 call syscall_trace_enter
22754+
22755+ pax_erase_kstack
22756+
22757 /* What it returned is what we'll actually use. */
22758 cmpl $(NR_syscalls), %eax
22759 jnae syscall_call
22760 jmp syscall_exit
22761-END(syscall_trace_entry)
22762+ENDPROC(syscall_trace_entry)
22763
22764 # perform syscall exit tracing
22765 ALIGN
22766@@ -675,21 +903,25 @@ syscall_exit_work:
22767 movl %esp, %eax
22768 call syscall_trace_leave
22769 jmp resume_userspace
22770-END(syscall_exit_work)
22771+ENDPROC(syscall_exit_work)
22772 CFI_ENDPROC
22773
22774 RING0_INT_FRAME # can't unwind into user space anyway
22775 syscall_fault:
22776+#ifdef CONFIG_PAX_MEMORY_UDEREF
22777+ push %ss
22778+ pop %ds
22779+#endif
22780 ASM_CLAC
22781 GET_THREAD_INFO(%ebp)
22782 movl $-EFAULT,PT_EAX(%esp)
22783 jmp resume_userspace
22784-END(syscall_fault)
22785+ENDPROC(syscall_fault)
22786
22787 syscall_badsys:
22788 movl $-ENOSYS,PT_EAX(%esp)
22789 jmp resume_userspace
22790-END(syscall_badsys)
22791+ENDPROC(syscall_badsys)
22792 CFI_ENDPROC
22793 /*
22794 * End of kprobes section
22795@@ -705,8 +937,15 @@ END(syscall_badsys)
22796 * normal stack and adjusts ESP with the matching offset.
22797 */
22798 /* fixup the stack */
22799- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
22800- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
22801+#ifdef CONFIG_SMP
22802+ movl PER_CPU_VAR(cpu_number), %ebx
22803+ shll $PAGE_SHIFT_asm, %ebx
22804+ addl $cpu_gdt_table, %ebx
22805+#else
22806+ movl $cpu_gdt_table, %ebx
22807+#endif
22808+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
22809+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
22810 shl $16, %eax
22811 addl %esp, %eax /* the adjusted stack pointer */
22812 pushl_cfi $__KERNEL_DS
22813@@ -759,7 +998,7 @@ vector=vector+1
22814 .endr
22815 2: jmp common_interrupt
22816 .endr
22817-END(irq_entries_start)
22818+ENDPROC(irq_entries_start)
22819
22820 .previous
22821 END(interrupt)
22822@@ -820,7 +1059,7 @@ ENTRY(coprocessor_error)
22823 pushl_cfi $do_coprocessor_error
22824 jmp error_code
22825 CFI_ENDPROC
22826-END(coprocessor_error)
22827+ENDPROC(coprocessor_error)
22828
22829 ENTRY(simd_coprocessor_error)
22830 RING0_INT_FRAME
22831@@ -833,7 +1072,7 @@ ENTRY(simd_coprocessor_error)
22832 .section .altinstructions,"a"
22833 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
22834 .previous
22835-.section .altinstr_replacement,"ax"
22836+.section .altinstr_replacement,"a"
22837 663: pushl $do_simd_coprocessor_error
22838 664:
22839 .previous
22840@@ -842,7 +1081,7 @@ ENTRY(simd_coprocessor_error)
22841 #endif
22842 jmp error_code
22843 CFI_ENDPROC
22844-END(simd_coprocessor_error)
22845+ENDPROC(simd_coprocessor_error)
22846
22847 ENTRY(device_not_available)
22848 RING0_INT_FRAME
22849@@ -851,18 +1090,18 @@ ENTRY(device_not_available)
22850 pushl_cfi $do_device_not_available
22851 jmp error_code
22852 CFI_ENDPROC
22853-END(device_not_available)
22854+ENDPROC(device_not_available)
22855
22856 #ifdef CONFIG_PARAVIRT
22857 ENTRY(native_iret)
22858 iret
22859 _ASM_EXTABLE(native_iret, iret_exc)
22860-END(native_iret)
22861+ENDPROC(native_iret)
22862
22863 ENTRY(native_irq_enable_sysexit)
22864 sti
22865 sysexit
22866-END(native_irq_enable_sysexit)
22867+ENDPROC(native_irq_enable_sysexit)
22868 #endif
22869
22870 ENTRY(overflow)
22871@@ -872,7 +1111,7 @@ ENTRY(overflow)
22872 pushl_cfi $do_overflow
22873 jmp error_code
22874 CFI_ENDPROC
22875-END(overflow)
22876+ENDPROC(overflow)
22877
22878 ENTRY(bounds)
22879 RING0_INT_FRAME
22880@@ -881,7 +1120,7 @@ ENTRY(bounds)
22881 pushl_cfi $do_bounds
22882 jmp error_code
22883 CFI_ENDPROC
22884-END(bounds)
22885+ENDPROC(bounds)
22886
22887 ENTRY(invalid_op)
22888 RING0_INT_FRAME
22889@@ -890,7 +1129,7 @@ ENTRY(invalid_op)
22890 pushl_cfi $do_invalid_op
22891 jmp error_code
22892 CFI_ENDPROC
22893-END(invalid_op)
22894+ENDPROC(invalid_op)
22895
22896 ENTRY(coprocessor_segment_overrun)
22897 RING0_INT_FRAME
22898@@ -899,7 +1138,7 @@ ENTRY(coprocessor_segment_overrun)
22899 pushl_cfi $do_coprocessor_segment_overrun
22900 jmp error_code
22901 CFI_ENDPROC
22902-END(coprocessor_segment_overrun)
22903+ENDPROC(coprocessor_segment_overrun)
22904
22905 ENTRY(invalid_TSS)
22906 RING0_EC_FRAME
22907@@ -907,7 +1146,7 @@ ENTRY(invalid_TSS)
22908 pushl_cfi $do_invalid_TSS
22909 jmp error_code
22910 CFI_ENDPROC
22911-END(invalid_TSS)
22912+ENDPROC(invalid_TSS)
22913
22914 ENTRY(segment_not_present)
22915 RING0_EC_FRAME
22916@@ -915,7 +1154,7 @@ ENTRY(segment_not_present)
22917 pushl_cfi $do_segment_not_present
22918 jmp error_code
22919 CFI_ENDPROC
22920-END(segment_not_present)
22921+ENDPROC(segment_not_present)
22922
22923 ENTRY(stack_segment)
22924 RING0_EC_FRAME
22925@@ -923,7 +1162,7 @@ ENTRY(stack_segment)
22926 pushl_cfi $do_stack_segment
22927 jmp error_code
22928 CFI_ENDPROC
22929-END(stack_segment)
22930+ENDPROC(stack_segment)
22931
22932 ENTRY(alignment_check)
22933 RING0_EC_FRAME
22934@@ -931,7 +1170,7 @@ ENTRY(alignment_check)
22935 pushl_cfi $do_alignment_check
22936 jmp error_code
22937 CFI_ENDPROC
22938-END(alignment_check)
22939+ENDPROC(alignment_check)
22940
22941 ENTRY(divide_error)
22942 RING0_INT_FRAME
22943@@ -940,7 +1179,7 @@ ENTRY(divide_error)
22944 pushl_cfi $do_divide_error
22945 jmp error_code
22946 CFI_ENDPROC
22947-END(divide_error)
22948+ENDPROC(divide_error)
22949
22950 #ifdef CONFIG_X86_MCE
22951 ENTRY(machine_check)
22952@@ -950,7 +1189,7 @@ ENTRY(machine_check)
22953 pushl_cfi machine_check_vector
22954 jmp error_code
22955 CFI_ENDPROC
22956-END(machine_check)
22957+ENDPROC(machine_check)
22958 #endif
22959
22960 ENTRY(spurious_interrupt_bug)
22961@@ -960,7 +1199,7 @@ ENTRY(spurious_interrupt_bug)
22962 pushl_cfi $do_spurious_interrupt_bug
22963 jmp error_code
22964 CFI_ENDPROC
22965-END(spurious_interrupt_bug)
22966+ENDPROC(spurious_interrupt_bug)
22967 /*
22968 * End of kprobes section
22969 */
22970@@ -1070,7 +1309,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
22971
22972 ENTRY(mcount)
22973 ret
22974-END(mcount)
22975+ENDPROC(mcount)
22976
22977 ENTRY(ftrace_caller)
22978 cmpl $0, function_trace_stop
22979@@ -1103,7 +1342,7 @@ ftrace_graph_call:
22980 .globl ftrace_stub
22981 ftrace_stub:
22982 ret
22983-END(ftrace_caller)
22984+ENDPROC(ftrace_caller)
22985
22986 ENTRY(ftrace_regs_caller)
22987 pushf /* push flags before compare (in cs location) */
22988@@ -1207,7 +1446,7 @@ trace:
22989 popl %ecx
22990 popl %eax
22991 jmp ftrace_stub
22992-END(mcount)
22993+ENDPROC(mcount)
22994 #endif /* CONFIG_DYNAMIC_FTRACE */
22995 #endif /* CONFIG_FUNCTION_TRACER */
22996
22997@@ -1225,7 +1464,7 @@ ENTRY(ftrace_graph_caller)
22998 popl %ecx
22999 popl %eax
23000 ret
23001-END(ftrace_graph_caller)
23002+ENDPROC(ftrace_graph_caller)
23003
23004 .globl return_to_handler
23005 return_to_handler:
23006@@ -1291,15 +1530,18 @@ error_code:
23007 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
23008 REG_TO_PTGS %ecx
23009 SET_KERNEL_GS %ecx
23010- movl $(__USER_DS), %ecx
23011+ movl $(__KERNEL_DS), %ecx
23012 movl %ecx, %ds
23013 movl %ecx, %es
23014+
23015+ pax_enter_kernel
23016+
23017 TRACE_IRQS_OFF
23018 movl %esp,%eax # pt_regs pointer
23019 call *%edi
23020 jmp ret_from_exception
23021 CFI_ENDPROC
23022-END(page_fault)
23023+ENDPROC(page_fault)
23024
23025 /*
23026 * Debug traps and NMI can happen at the one SYSENTER instruction
23027@@ -1342,7 +1584,7 @@ debug_stack_correct:
23028 call do_debug
23029 jmp ret_from_exception
23030 CFI_ENDPROC
23031-END(debug)
23032+ENDPROC(debug)
23033
23034 /*
23035 * NMI is doubly nasty. It can happen _while_ we're handling
23036@@ -1380,6 +1622,9 @@ nmi_stack_correct:
23037 xorl %edx,%edx # zero error code
23038 movl %esp,%eax # pt_regs pointer
23039 call do_nmi
23040+
23041+ pax_exit_kernel
23042+
23043 jmp restore_all_notrace
23044 CFI_ENDPROC
23045
23046@@ -1416,12 +1661,15 @@ nmi_espfix_stack:
23047 FIXUP_ESPFIX_STACK # %eax == %esp
23048 xorl %edx,%edx # zero error code
23049 call do_nmi
23050+
23051+ pax_exit_kernel
23052+
23053 RESTORE_REGS
23054 lss 12+4(%esp), %esp # back to espfix stack
23055 CFI_ADJUST_CFA_OFFSET -24
23056 jmp irq_return
23057 CFI_ENDPROC
23058-END(nmi)
23059+ENDPROC(nmi)
23060
23061 ENTRY(int3)
23062 RING0_INT_FRAME
23063@@ -1434,14 +1682,14 @@ ENTRY(int3)
23064 call do_int3
23065 jmp ret_from_exception
23066 CFI_ENDPROC
23067-END(int3)
23068+ENDPROC(int3)
23069
23070 ENTRY(general_protection)
23071 RING0_EC_FRAME
23072 pushl_cfi $do_general_protection
23073 jmp error_code
23074 CFI_ENDPROC
23075-END(general_protection)
23076+ENDPROC(general_protection)
23077
23078 #ifdef CONFIG_KVM_GUEST
23079 ENTRY(async_page_fault)
23080@@ -1450,7 +1698,7 @@ ENTRY(async_page_fault)
23081 pushl_cfi $do_async_page_fault
23082 jmp error_code
23083 CFI_ENDPROC
23084-END(async_page_fault)
23085+ENDPROC(async_page_fault)
23086 #endif
23087
23088 /*
23089diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
23090index 1e96c36..3ff710a 100644
23091--- a/arch/x86/kernel/entry_64.S
23092+++ b/arch/x86/kernel/entry_64.S
23093@@ -59,6 +59,8 @@
23094 #include <asm/context_tracking.h>
23095 #include <asm/smap.h>
23096 #include <linux/err.h>
23097+#include <asm/pgtable.h>
23098+#include <asm/alternative-asm.h>
23099
23100 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
23101 #include <linux/elf-em.h>
23102@@ -80,8 +82,9 @@
23103 #ifdef CONFIG_DYNAMIC_FTRACE
23104
23105 ENTRY(function_hook)
23106+ pax_force_retaddr
23107 retq
23108-END(function_hook)
23109+ENDPROC(function_hook)
23110
23111 /* skip is set if stack has been adjusted */
23112 .macro ftrace_caller_setup skip=0
23113@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
23114 #endif
23115
23116 GLOBAL(ftrace_stub)
23117+ pax_force_retaddr
23118 retq
23119-END(ftrace_caller)
23120+ENDPROC(ftrace_caller)
23121
23122 ENTRY(ftrace_regs_caller)
23123 /* Save the current flags before compare (in SS location)*/
23124@@ -191,7 +195,7 @@ ftrace_restore_flags:
23125 popfq
23126 jmp ftrace_stub
23127
23128-END(ftrace_regs_caller)
23129+ENDPROC(ftrace_regs_caller)
23130
23131
23132 #else /* ! CONFIG_DYNAMIC_FTRACE */
23133@@ -212,6 +216,7 @@ ENTRY(function_hook)
23134 #endif
23135
23136 GLOBAL(ftrace_stub)
23137+ pax_force_retaddr
23138 retq
23139
23140 trace:
23141@@ -225,12 +230,13 @@ trace:
23142 #endif
23143 subq $MCOUNT_INSN_SIZE, %rdi
23144
23145+ pax_force_fptr ftrace_trace_function
23146 call *ftrace_trace_function
23147
23148 MCOUNT_RESTORE_FRAME
23149
23150 jmp ftrace_stub
23151-END(function_hook)
23152+ENDPROC(function_hook)
23153 #endif /* CONFIG_DYNAMIC_FTRACE */
23154 #endif /* CONFIG_FUNCTION_TRACER */
23155
23156@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
23157
23158 MCOUNT_RESTORE_FRAME
23159
23160+ pax_force_retaddr
23161 retq
23162-END(ftrace_graph_caller)
23163+ENDPROC(ftrace_graph_caller)
23164
23165 GLOBAL(return_to_handler)
23166 subq $24, %rsp
23167@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
23168 movq 8(%rsp), %rdx
23169 movq (%rsp), %rax
23170 addq $24, %rsp
23171+ pax_force_fptr %rdi
23172 jmp *%rdi
23173+ENDPROC(return_to_handler)
23174 #endif
23175
23176
23177@@ -284,6 +293,430 @@ ENTRY(native_usergs_sysret64)
23178 ENDPROC(native_usergs_sysret64)
23179 #endif /* CONFIG_PARAVIRT */
23180
23181+ .macro ljmpq sel, off
23182+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
23183+ .byte 0x48; ljmp *1234f(%rip)
23184+ .pushsection .rodata
23185+ .align 16
23186+ 1234: .quad \off; .word \sel
23187+ .popsection
23188+#else
23189+ pushq $\sel
23190+ pushq $\off
23191+ lretq
23192+#endif
23193+ .endm
23194+
23195+ .macro pax_enter_kernel
23196+ pax_set_fptr_mask
23197+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23198+ call pax_enter_kernel
23199+#endif
23200+ .endm
23201+
23202+ .macro pax_exit_kernel
23203+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23204+ call pax_exit_kernel
23205+#endif
23206+
23207+ .endm
23208+
23209+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23210+ENTRY(pax_enter_kernel)
23211+ pushq %rdi
23212+
23213+#ifdef CONFIG_PARAVIRT
23214+ PV_SAVE_REGS(CLBR_RDI)
23215+#endif
23216+
23217+#ifdef CONFIG_PAX_KERNEXEC
23218+ GET_CR0_INTO_RDI
23219+ bts $16,%rdi
23220+ jnc 3f
23221+ mov %cs,%edi
23222+ cmp $__KERNEL_CS,%edi
23223+ jnz 2f
23224+1:
23225+#endif
23226+
23227+#ifdef CONFIG_PAX_MEMORY_UDEREF
23228+ 661: jmp 111f
23229+ .pushsection .altinstr_replacement, "a"
23230+ 662: ASM_NOP2
23231+ .popsection
23232+ .pushsection .altinstructions, "a"
23233+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23234+ .popsection
23235+ GET_CR3_INTO_RDI
23236+ cmp $0,%dil
23237+ jnz 112f
23238+ mov $__KERNEL_DS,%edi
23239+ mov %edi,%ss
23240+ jmp 111f
23241+112: cmp $1,%dil
23242+ jz 113f
23243+ ud2
23244+113: sub $4097,%rdi
23245+ bts $63,%rdi
23246+ SET_RDI_INTO_CR3
23247+ mov $__UDEREF_KERNEL_DS,%edi
23248+ mov %edi,%ss
23249+111:
23250+#endif
23251+
23252+#ifdef CONFIG_PARAVIRT
23253+ PV_RESTORE_REGS(CLBR_RDI)
23254+#endif
23255+
23256+ popq %rdi
23257+ pax_force_retaddr
23258+ retq
23259+
23260+#ifdef CONFIG_PAX_KERNEXEC
23261+2: ljmpq __KERNEL_CS,1b
23262+3: ljmpq __KERNEXEC_KERNEL_CS,4f
23263+4: SET_RDI_INTO_CR0
23264+ jmp 1b
23265+#endif
23266+ENDPROC(pax_enter_kernel)
23267+
23268+ENTRY(pax_exit_kernel)
23269+ pushq %rdi
23270+
23271+#ifdef CONFIG_PARAVIRT
23272+ PV_SAVE_REGS(CLBR_RDI)
23273+#endif
23274+
23275+#ifdef CONFIG_PAX_KERNEXEC
23276+ mov %cs,%rdi
23277+ cmp $__KERNEXEC_KERNEL_CS,%edi
23278+ jz 2f
23279+ GET_CR0_INTO_RDI
23280+ bts $16,%rdi
23281+ jnc 4f
23282+1:
23283+#endif
23284+
23285+#ifdef CONFIG_PAX_MEMORY_UDEREF
23286+ 661: jmp 111f
23287+ .pushsection .altinstr_replacement, "a"
23288+ 662: ASM_NOP2
23289+ .popsection
23290+ .pushsection .altinstructions, "a"
23291+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23292+ .popsection
23293+ mov %ss,%edi
23294+ cmp $__UDEREF_KERNEL_DS,%edi
23295+ jnz 111f
23296+ GET_CR3_INTO_RDI
23297+ cmp $0,%dil
23298+ jz 112f
23299+ ud2
23300+112: add $4097,%rdi
23301+ bts $63,%rdi
23302+ SET_RDI_INTO_CR3
23303+ mov $__KERNEL_DS,%edi
23304+ mov %edi,%ss
23305+111:
23306+#endif
23307+
23308+#ifdef CONFIG_PARAVIRT
23309+ PV_RESTORE_REGS(CLBR_RDI);
23310+#endif
23311+
23312+ popq %rdi
23313+ pax_force_retaddr
23314+ retq
23315+
23316+#ifdef CONFIG_PAX_KERNEXEC
23317+2: GET_CR0_INTO_RDI
23318+ btr $16,%rdi
23319+ jnc 4f
23320+ ljmpq __KERNEL_CS,3f
23321+3: SET_RDI_INTO_CR0
23322+ jmp 1b
23323+4: ud2
23324+ jmp 4b
23325+#endif
23326+ENDPROC(pax_exit_kernel)
23327+#endif
23328+
23329+ .macro pax_enter_kernel_user
23330+ pax_set_fptr_mask
23331+#ifdef CONFIG_PAX_MEMORY_UDEREF
23332+ call pax_enter_kernel_user
23333+#endif
23334+ .endm
23335+
23336+ .macro pax_exit_kernel_user
23337+#ifdef CONFIG_PAX_MEMORY_UDEREF
23338+ call pax_exit_kernel_user
23339+#endif
23340+#ifdef CONFIG_PAX_RANDKSTACK
23341+ pushq %rax
23342+ pushq %r11
23343+ call pax_randomize_kstack
23344+ popq %r11
23345+ popq %rax
23346+#endif
23347+ .endm
23348+
23349+#ifdef CONFIG_PAX_MEMORY_UDEREF
23350+ENTRY(pax_enter_kernel_user)
23351+ pushq %rdi
23352+ pushq %rbx
23353+
23354+#ifdef CONFIG_PARAVIRT
23355+ PV_SAVE_REGS(CLBR_RDI)
23356+#endif
23357+
23358+ 661: jmp 111f
23359+ .pushsection .altinstr_replacement, "a"
23360+ 662: ASM_NOP2
23361+ .popsection
23362+ .pushsection .altinstructions, "a"
23363+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23364+ .popsection
23365+ GET_CR3_INTO_RDI
23366+ cmp $1,%dil
23367+ jnz 4f
23368+ sub $4097,%rdi
23369+ bts $63,%rdi
23370+ SET_RDI_INTO_CR3
23371+ jmp 3f
23372+111:
23373+
23374+ GET_CR3_INTO_RDI
23375+ mov %rdi,%rbx
23376+ add $__START_KERNEL_map,%rbx
23377+ sub phys_base(%rip),%rbx
23378+
23379+#ifdef CONFIG_PARAVIRT
23380+ cmpl $0, pv_info+PARAVIRT_enabled
23381+ jz 1f
23382+ pushq %rdi
23383+ i = 0
23384+ .rept USER_PGD_PTRS
23385+ mov i*8(%rbx),%rsi
23386+ mov $0,%sil
23387+ lea i*8(%rbx),%rdi
23388+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23389+ i = i + 1
23390+ .endr
23391+ popq %rdi
23392+ jmp 2f
23393+1:
23394+#endif
23395+
23396+ i = 0
23397+ .rept USER_PGD_PTRS
23398+ movb $0,i*8(%rbx)
23399+ i = i + 1
23400+ .endr
23401+
23402+2: SET_RDI_INTO_CR3
23403+
23404+#ifdef CONFIG_PAX_KERNEXEC
23405+ GET_CR0_INTO_RDI
23406+ bts $16,%rdi
23407+ SET_RDI_INTO_CR0
23408+#endif
23409+
23410+3:
23411+
23412+#ifdef CONFIG_PARAVIRT
23413+ PV_RESTORE_REGS(CLBR_RDI)
23414+#endif
23415+
23416+ popq %rbx
23417+ popq %rdi
23418+ pax_force_retaddr
23419+ retq
23420+4: ud2
23421+ENDPROC(pax_enter_kernel_user)
23422+
23423+ENTRY(pax_exit_kernel_user)
23424+ pushq %rdi
23425+ pushq %rbx
23426+
23427+#ifdef CONFIG_PARAVIRT
23428+ PV_SAVE_REGS(CLBR_RDI)
23429+#endif
23430+
23431+ GET_CR3_INTO_RDI
23432+ 661: jmp 1f
23433+ .pushsection .altinstr_replacement, "a"
23434+ 662: ASM_NOP2
23435+ .popsection
23436+ .pushsection .altinstructions, "a"
23437+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23438+ .popsection
23439+ cmp $0,%dil
23440+ jnz 3f
23441+ add $4097,%rdi
23442+ bts $63,%rdi
23443+ SET_RDI_INTO_CR3
23444+ jmp 2f
23445+1:
23446+
23447+ mov %rdi,%rbx
23448+
23449+#ifdef CONFIG_PAX_KERNEXEC
23450+ GET_CR0_INTO_RDI
23451+ btr $16,%rdi
23452+ jnc 3f
23453+ SET_RDI_INTO_CR0
23454+#endif
23455+
23456+ add $__START_KERNEL_map,%rbx
23457+ sub phys_base(%rip),%rbx
23458+
23459+#ifdef CONFIG_PARAVIRT
23460+ cmpl $0, pv_info+PARAVIRT_enabled
23461+ jz 1f
23462+ i = 0
23463+ .rept USER_PGD_PTRS
23464+ mov i*8(%rbx),%rsi
23465+ mov $0x67,%sil
23466+ lea i*8(%rbx),%rdi
23467+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23468+ i = i + 1
23469+ .endr
23470+ jmp 2f
23471+1:
23472+#endif
23473+
23474+ i = 0
23475+ .rept USER_PGD_PTRS
23476+ movb $0x67,i*8(%rbx)
23477+ i = i + 1
23478+ .endr
23479+2:
23480+
23481+#ifdef CONFIG_PARAVIRT
23482+ PV_RESTORE_REGS(CLBR_RDI)
23483+#endif
23484+
23485+ popq %rbx
23486+ popq %rdi
23487+ pax_force_retaddr
23488+ retq
23489+3: ud2
23490+ENDPROC(pax_exit_kernel_user)
23491+#endif
23492+
23493+ .macro pax_enter_kernel_nmi
23494+ pax_set_fptr_mask
23495+
23496+#ifdef CONFIG_PAX_KERNEXEC
23497+ GET_CR0_INTO_RDI
23498+ bts $16,%rdi
23499+ jc 110f
23500+ SET_RDI_INTO_CR0
23501+ or $2,%ebx
23502+110:
23503+#endif
23504+
23505+#ifdef CONFIG_PAX_MEMORY_UDEREF
23506+ 661: jmp 111f
23507+ .pushsection .altinstr_replacement, "a"
23508+ 662: ASM_NOP2
23509+ .popsection
23510+ .pushsection .altinstructions, "a"
23511+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23512+ .popsection
23513+ GET_CR3_INTO_RDI
23514+ cmp $0,%dil
23515+ jz 111f
23516+ sub $4097,%rdi
23517+ or $4,%ebx
23518+ bts $63,%rdi
23519+ SET_RDI_INTO_CR3
23520+ mov $__UDEREF_KERNEL_DS,%edi
23521+ mov %edi,%ss
23522+111:
23523+#endif
23524+ .endm
23525+
23526+ .macro pax_exit_kernel_nmi
23527+#ifdef CONFIG_PAX_KERNEXEC
23528+ btr $1,%ebx
23529+ jnc 110f
23530+ GET_CR0_INTO_RDI
23531+ btr $16,%rdi
23532+ SET_RDI_INTO_CR0
23533+110:
23534+#endif
23535+
23536+#ifdef CONFIG_PAX_MEMORY_UDEREF
23537+ btr $2,%ebx
23538+ jnc 111f
23539+ GET_CR3_INTO_RDI
23540+ add $4097,%rdi
23541+ bts $63,%rdi
23542+ SET_RDI_INTO_CR3
23543+ mov $__KERNEL_DS,%edi
23544+ mov %edi,%ss
23545+111:
23546+#endif
23547+ .endm
23548+
23549+ .macro pax_erase_kstack
23550+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23551+ call pax_erase_kstack
23552+#endif
23553+ .endm
23554+
23555+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23556+ENTRY(pax_erase_kstack)
23557+ pushq %rdi
23558+ pushq %rcx
23559+ pushq %rax
23560+ pushq %r11
23561+
23562+ GET_THREAD_INFO(%r11)
23563+ mov TI_lowest_stack(%r11), %rdi
23564+ mov $-0xBEEF, %rax
23565+ std
23566+
23567+1: mov %edi, %ecx
23568+ and $THREAD_SIZE_asm - 1, %ecx
23569+ shr $3, %ecx
23570+ repne scasq
23571+ jecxz 2f
23572+
23573+ cmp $2*8, %ecx
23574+ jc 2f
23575+
23576+ mov $2*8, %ecx
23577+ repe scasq
23578+ jecxz 2f
23579+ jne 1b
23580+
23581+2: cld
23582+ mov %esp, %ecx
23583+ sub %edi, %ecx
23584+
23585+ cmp $THREAD_SIZE_asm, %rcx
23586+ jb 3f
23587+ ud2
23588+3:
23589+
23590+ shr $3, %ecx
23591+ rep stosq
23592+
23593+ mov TI_task_thread_sp0(%r11), %rdi
23594+ sub $256, %rdi
23595+ mov %rdi, TI_lowest_stack(%r11)
23596+
23597+ popq %r11
23598+ popq %rax
23599+ popq %rcx
23600+ popq %rdi
23601+ pax_force_retaddr
23602+ ret
23603+ENDPROC(pax_erase_kstack)
23604+#endif
23605
23606 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
23607 #ifdef CONFIG_TRACE_IRQFLAGS
23608@@ -320,7 +753,7 @@ ENDPROC(native_usergs_sysret64)
23609 .endm
23610
23611 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
23612- bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
23613+ bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
23614 jnc 1f
23615 TRACE_IRQS_ON_DEBUG
23616 1:
23617@@ -358,27 +791,6 @@ ENDPROC(native_usergs_sysret64)
23618 movq \tmp,R11+\offset(%rsp)
23619 .endm
23620
23621- .macro FAKE_STACK_FRAME child_rip
23622- /* push in order ss, rsp, eflags, cs, rip */
23623- xorl %eax, %eax
23624- pushq_cfi $__KERNEL_DS /* ss */
23625- /*CFI_REL_OFFSET ss,0*/
23626- pushq_cfi %rax /* rsp */
23627- CFI_REL_OFFSET rsp,0
23628- pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
23629- /*CFI_REL_OFFSET rflags,0*/
23630- pushq_cfi $__KERNEL_CS /* cs */
23631- /*CFI_REL_OFFSET cs,0*/
23632- pushq_cfi \child_rip /* rip */
23633- CFI_REL_OFFSET rip,0
23634- pushq_cfi %rax /* orig rax */
23635- .endm
23636-
23637- .macro UNFAKE_STACK_FRAME
23638- addq $8*6, %rsp
23639- CFI_ADJUST_CFA_OFFSET -(6*8)
23640- .endm
23641-
23642 /*
23643 * initial frame state for interrupts (and exceptions without error code)
23644 */
23645@@ -445,25 +857,26 @@ ENDPROC(native_usergs_sysret64)
23646 /* save partial stack frame */
23647 .macro SAVE_ARGS_IRQ
23648 cld
23649- /* start from rbp in pt_regs and jump over */
23650- movq_cfi rdi, (RDI-RBP)
23651- movq_cfi rsi, (RSI-RBP)
23652- movq_cfi rdx, (RDX-RBP)
23653- movq_cfi rcx, (RCX-RBP)
23654- movq_cfi rax, (RAX-RBP)
23655- movq_cfi r8, (R8-RBP)
23656- movq_cfi r9, (R9-RBP)
23657- movq_cfi r10, (R10-RBP)
23658- movq_cfi r11, (R11-RBP)
23659+ /* start from r15 in pt_regs and jump over */
23660+ movq_cfi rdi, RDI
23661+ movq_cfi rsi, RSI
23662+ movq_cfi rdx, RDX
23663+ movq_cfi rcx, RCX
23664+ movq_cfi rax, RAX
23665+ movq_cfi r8, R8
23666+ movq_cfi r9, R9
23667+ movq_cfi r10, R10
23668+ movq_cfi r11, R11
23669+ movq_cfi r12, R12
23670
23671 /* Save rbp so that we can unwind from get_irq_regs() */
23672- movq_cfi rbp, 0
23673+ movq_cfi rbp, RBP
23674
23675 /* Save previous stack value */
23676 movq %rsp, %rsi
23677
23678- leaq -RBP(%rsp),%rdi /* arg1 for handler */
23679- testl $3, CS-RBP(%rsi)
23680+ movq %rsp,%rdi /* arg1 for handler */
23681+ testb $3, CS(%rsi)
23682 je 1f
23683 SWAPGS
23684 /*
23685@@ -483,6 +896,18 @@ ENDPROC(native_usergs_sysret64)
23686 0x06 /* DW_OP_deref */, \
23687 0x08 /* DW_OP_const1u */, SS+8-RBP, \
23688 0x22 /* DW_OP_plus */
23689+
23690+#ifdef CONFIG_PAX_MEMORY_UDEREF
23691+ testb $3, CS(%rdi)
23692+ jnz 1f
23693+ pax_enter_kernel
23694+ jmp 2f
23695+1: pax_enter_kernel_user
23696+2:
23697+#else
23698+ pax_enter_kernel
23699+#endif
23700+
23701 /* We entered an interrupt context - irqs are off: */
23702 TRACE_IRQS_OFF
23703 .endm
23704@@ -514,9 +939,52 @@ ENTRY(save_paranoid)
23705 js 1f /* negative -> in kernel */
23706 SWAPGS
23707 xorl %ebx,%ebx
23708-1: ret
23709+1:
23710+#ifdef CONFIG_PAX_MEMORY_UDEREF
23711+ testb $3, CS+8(%rsp)
23712+ jnz 1f
23713+ pax_enter_kernel
23714+ jmp 2f
23715+1: pax_enter_kernel_user
23716+2:
23717+#else
23718+ pax_enter_kernel
23719+#endif
23720+ pax_force_retaddr
23721+ ret
23722 CFI_ENDPROC
23723-END(save_paranoid)
23724+ENDPROC(save_paranoid)
23725+
23726+ENTRY(save_paranoid_nmi)
23727+ XCPT_FRAME 1 RDI+8
23728+ cld
23729+ movq_cfi rdi, RDI+8
23730+ movq_cfi rsi, RSI+8
23731+ movq_cfi rdx, RDX+8
23732+ movq_cfi rcx, RCX+8
23733+ movq_cfi rax, RAX+8
23734+ movq_cfi r8, R8+8
23735+ movq_cfi r9, R9+8
23736+ movq_cfi r10, R10+8
23737+ movq_cfi r11, R11+8
23738+ movq_cfi rbx, RBX+8
23739+ movq_cfi rbp, RBP+8
23740+ movq_cfi r12, R12+8
23741+ movq_cfi r13, R13+8
23742+ movq_cfi r14, R14+8
23743+ movq_cfi r15, R15+8
23744+ movl $1,%ebx
23745+ movl $MSR_GS_BASE,%ecx
23746+ rdmsr
23747+ testl %edx,%edx
23748+ js 1f /* negative -> in kernel */
23749+ SWAPGS
23750+ xorl %ebx,%ebx
23751+1: pax_enter_kernel_nmi
23752+ pax_force_retaddr
23753+ ret
23754+ CFI_ENDPROC
23755+ENDPROC(save_paranoid_nmi)
23756 .popsection
23757
23758 /*
23759@@ -538,7 +1006,7 @@ ENTRY(ret_from_fork)
23760
23761 RESTORE_REST
23762
23763- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23764+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23765 jz 1f
23766
23767 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
23768@@ -548,15 +1016,13 @@ ENTRY(ret_from_fork)
23769 jmp ret_from_sys_call # go to the SYSRET fastpath
23770
23771 1:
23772- subq $REST_SKIP, %rsp # leave space for volatiles
23773- CFI_ADJUST_CFA_OFFSET REST_SKIP
23774 movq %rbp, %rdi
23775 call *%rbx
23776 movl $0, RAX(%rsp)
23777 RESTORE_REST
23778 jmp int_ret_from_sys_call
23779 CFI_ENDPROC
23780-END(ret_from_fork)
23781+ENDPROC(ret_from_fork)
23782
23783 /*
23784 * System call entry. Up to 6 arguments in registers are supported.
23785@@ -593,7 +1059,7 @@ END(ret_from_fork)
23786 ENTRY(system_call)
23787 CFI_STARTPROC simple
23788 CFI_SIGNAL_FRAME
23789- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
23790+ CFI_DEF_CFA rsp,0
23791 CFI_REGISTER rip,rcx
23792 /*CFI_REGISTER rflags,r11*/
23793 SWAPGS_UNSAFE_STACK
23794@@ -606,16 +1072,23 @@ GLOBAL(system_call_after_swapgs)
23795
23796 movq %rsp,PER_CPU_VAR(old_rsp)
23797 movq PER_CPU_VAR(kernel_stack),%rsp
23798+ SAVE_ARGS 8*6,0
23799+ pax_enter_kernel_user
23800+
23801+#ifdef CONFIG_PAX_RANDKSTACK
23802+ pax_erase_kstack
23803+#endif
23804+
23805 /*
23806 * No need to follow this irqs off/on section - it's straight
23807 * and short:
23808 */
23809 ENABLE_INTERRUPTS(CLBR_NONE)
23810- SAVE_ARGS 8,0
23811 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
23812 movq %rcx,RIP-ARGOFFSET(%rsp)
23813 CFI_REL_OFFSET rip,RIP-ARGOFFSET
23814- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23815+ GET_THREAD_INFO(%rcx)
23816+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
23817 jnz tracesys
23818 system_call_fastpath:
23819 #if __SYSCALL_MASK == ~0
23820@@ -639,10 +1112,13 @@ sysret_check:
23821 LOCKDEP_SYS_EXIT
23822 DISABLE_INTERRUPTS(CLBR_NONE)
23823 TRACE_IRQS_OFF
23824- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
23825+ GET_THREAD_INFO(%rcx)
23826+ movl TI_flags(%rcx),%edx
23827 andl %edi,%edx
23828 jnz sysret_careful
23829 CFI_REMEMBER_STATE
23830+ pax_exit_kernel_user
23831+ pax_erase_kstack
23832 /*
23833 * sysretq will re-enable interrupts:
23834 */
23835@@ -701,6 +1177,9 @@ auditsys:
23836 movq %rax,%rsi /* 2nd arg: syscall number */
23837 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
23838 call __audit_syscall_entry
23839+
23840+ pax_erase_kstack
23841+
23842 LOAD_ARGS 0 /* reload call-clobbered registers */
23843 jmp system_call_fastpath
23844
23845@@ -722,7 +1201,7 @@ sysret_audit:
23846 /* Do syscall tracing */
23847 tracesys:
23848 #ifdef CONFIG_AUDITSYSCALL
23849- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23850+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
23851 jz auditsys
23852 #endif
23853 SAVE_REST
23854@@ -730,12 +1209,15 @@ tracesys:
23855 FIXUP_TOP_OF_STACK %rdi
23856 movq %rsp,%rdi
23857 call syscall_trace_enter
23858+
23859+ pax_erase_kstack
23860+
23861 /*
23862 * Reload arg registers from stack in case ptrace changed them.
23863 * We don't reload %rax because syscall_trace_enter() returned
23864 * the value it wants us to use in the table lookup.
23865 */
23866- LOAD_ARGS ARGOFFSET, 1
23867+ LOAD_ARGS 1
23868 RESTORE_REST
23869 #if __SYSCALL_MASK == ~0
23870 cmpq $__NR_syscall_max,%rax
23871@@ -765,7 +1247,9 @@ GLOBAL(int_with_check)
23872 andl %edi,%edx
23873 jnz int_careful
23874 andl $~TS_COMPAT,TI_status(%rcx)
23875- jmp retint_swapgs
23876+ pax_exit_kernel_user
23877+ pax_erase_kstack
23878+ jmp retint_swapgs_pax
23879
23880 /* Either reschedule or signal or syscall exit tracking needed. */
23881 /* First do a reschedule test. */
23882@@ -811,7 +1295,7 @@ int_restore_rest:
23883 TRACE_IRQS_OFF
23884 jmp int_with_check
23885 CFI_ENDPROC
23886-END(system_call)
23887+ENDPROC(system_call)
23888
23889 .macro FORK_LIKE func
23890 ENTRY(stub_\func)
23891@@ -824,9 +1308,10 @@ ENTRY(stub_\func)
23892 DEFAULT_FRAME 0 8 /* offset 8: return address */
23893 call sys_\func
23894 RESTORE_TOP_OF_STACK %r11, 8
23895- ret $REST_SKIP /* pop extended registers */
23896+ pax_force_retaddr
23897+ ret
23898 CFI_ENDPROC
23899-END(stub_\func)
23900+ENDPROC(stub_\func)
23901 .endm
23902
23903 .macro FIXED_FRAME label,func
23904@@ -836,9 +1321,10 @@ ENTRY(\label)
23905 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
23906 call \func
23907 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
23908+ pax_force_retaddr
23909 ret
23910 CFI_ENDPROC
23911-END(\label)
23912+ENDPROC(\label)
23913 .endm
23914
23915 FORK_LIKE clone
23916@@ -846,19 +1332,6 @@ END(\label)
23917 FORK_LIKE vfork
23918 FIXED_FRAME stub_iopl, sys_iopl
23919
23920-ENTRY(ptregscall_common)
23921- DEFAULT_FRAME 1 8 /* offset 8: return address */
23922- RESTORE_TOP_OF_STACK %r11, 8
23923- movq_cfi_restore R15+8, r15
23924- movq_cfi_restore R14+8, r14
23925- movq_cfi_restore R13+8, r13
23926- movq_cfi_restore R12+8, r12
23927- movq_cfi_restore RBP+8, rbp
23928- movq_cfi_restore RBX+8, rbx
23929- ret $REST_SKIP /* pop extended registers */
23930- CFI_ENDPROC
23931-END(ptregscall_common)
23932-
23933 ENTRY(stub_execve)
23934 CFI_STARTPROC
23935 addq $8, %rsp
23936@@ -870,7 +1343,7 @@ ENTRY(stub_execve)
23937 RESTORE_REST
23938 jmp int_ret_from_sys_call
23939 CFI_ENDPROC
23940-END(stub_execve)
23941+ENDPROC(stub_execve)
23942
23943 /*
23944 * sigreturn is special because it needs to restore all registers on return.
23945@@ -887,7 +1360,7 @@ ENTRY(stub_rt_sigreturn)
23946 RESTORE_REST
23947 jmp int_ret_from_sys_call
23948 CFI_ENDPROC
23949-END(stub_rt_sigreturn)
23950+ENDPROC(stub_rt_sigreturn)
23951
23952 #ifdef CONFIG_X86_X32_ABI
23953 ENTRY(stub_x32_rt_sigreturn)
23954@@ -901,7 +1374,7 @@ ENTRY(stub_x32_rt_sigreturn)
23955 RESTORE_REST
23956 jmp int_ret_from_sys_call
23957 CFI_ENDPROC
23958-END(stub_x32_rt_sigreturn)
23959+ENDPROC(stub_x32_rt_sigreturn)
23960
23961 ENTRY(stub_x32_execve)
23962 CFI_STARTPROC
23963@@ -915,7 +1388,7 @@ ENTRY(stub_x32_execve)
23964 RESTORE_REST
23965 jmp int_ret_from_sys_call
23966 CFI_ENDPROC
23967-END(stub_x32_execve)
23968+ENDPROC(stub_x32_execve)
23969
23970 #endif
23971
23972@@ -952,7 +1425,7 @@ vector=vector+1
23973 2: jmp common_interrupt
23974 .endr
23975 CFI_ENDPROC
23976-END(irq_entries_start)
23977+ENDPROC(irq_entries_start)
23978
23979 .previous
23980 END(interrupt)
23981@@ -969,8 +1442,8 @@ END(interrupt)
23982 /* 0(%rsp): ~(interrupt number) */
23983 .macro interrupt func
23984 /* reserve pt_regs for scratch regs and rbp */
23985- subq $ORIG_RAX-RBP, %rsp
23986- CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
23987+ subq $ORIG_RAX, %rsp
23988+ CFI_ADJUST_CFA_OFFSET ORIG_RAX
23989 SAVE_ARGS_IRQ
23990 call \func
23991 .endm
23992@@ -997,14 +1470,14 @@ ret_from_intr:
23993
23994 /* Restore saved previous stack */
23995 popq %rsi
23996- CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
23997- leaq ARGOFFSET-RBP(%rsi), %rsp
23998+ CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
23999+ movq %rsi, %rsp
24000 CFI_DEF_CFA_REGISTER rsp
24001- CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
24002+ CFI_ADJUST_CFA_OFFSET -ARGOFFSET
24003
24004 exit_intr:
24005 GET_THREAD_INFO(%rcx)
24006- testl $3,CS-ARGOFFSET(%rsp)
24007+ testb $3,CS-ARGOFFSET(%rsp)
24008 je retint_kernel
24009
24010 /* Interrupt came from user space */
24011@@ -1026,12 +1499,16 @@ retint_swapgs: /* return to user-space */
24012 * The iretq could re-enable interrupts:
24013 */
24014 DISABLE_INTERRUPTS(CLBR_ANY)
24015+ pax_exit_kernel_user
24016+retint_swapgs_pax:
24017 TRACE_IRQS_IRETQ
24018 SWAPGS
24019 jmp restore_args
24020
24021 retint_restore_args: /* return to kernel space */
24022 DISABLE_INTERRUPTS(CLBR_ANY)
24023+ pax_exit_kernel
24024+ pax_force_retaddr (RIP-ARGOFFSET)
24025 /*
24026 * The iretq could re-enable interrupts:
24027 */
24028@@ -1112,7 +1589,7 @@ ENTRY(retint_kernel)
24029 #endif
24030
24031 CFI_ENDPROC
24032-END(common_interrupt)
24033+ENDPROC(common_interrupt)
24034 /*
24035 * End of kprobes section
24036 */
24037@@ -1130,7 +1607,7 @@ ENTRY(\sym)
24038 interrupt \do_sym
24039 jmp ret_from_intr
24040 CFI_ENDPROC
24041-END(\sym)
24042+ENDPROC(\sym)
24043 .endm
24044
24045 #ifdef CONFIG_TRACING
24046@@ -1218,7 +1695,7 @@ ENTRY(\sym)
24047 call \do_sym
24048 jmp error_exit /* %ebx: no swapgs flag */
24049 CFI_ENDPROC
24050-END(\sym)
24051+ENDPROC(\sym)
24052 .endm
24053
24054 .macro paranoidzeroentry sym do_sym
24055@@ -1236,10 +1713,10 @@ ENTRY(\sym)
24056 call \do_sym
24057 jmp paranoid_exit /* %ebx: no swapgs flag */
24058 CFI_ENDPROC
24059-END(\sym)
24060+ENDPROC(\sym)
24061 .endm
24062
24063-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
24064+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
24065 .macro paranoidzeroentry_ist sym do_sym ist
24066 ENTRY(\sym)
24067 INTR_FRAME
24068@@ -1252,12 +1729,18 @@ ENTRY(\sym)
24069 TRACE_IRQS_OFF_DEBUG
24070 movq %rsp,%rdi /* pt_regs pointer */
24071 xorl %esi,%esi /* no error code */
24072+#ifdef CONFIG_SMP
24073+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
24074+ lea init_tss(%r13), %r13
24075+#else
24076+ lea init_tss(%rip), %r13
24077+#endif
24078 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
24079 call \do_sym
24080 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
24081 jmp paranoid_exit /* %ebx: no swapgs flag */
24082 CFI_ENDPROC
24083-END(\sym)
24084+ENDPROC(\sym)
24085 .endm
24086
24087 .macro errorentry sym do_sym
24088@@ -1275,7 +1758,7 @@ ENTRY(\sym)
24089 call \do_sym
24090 jmp error_exit /* %ebx: no swapgs flag */
24091 CFI_ENDPROC
24092-END(\sym)
24093+ENDPROC(\sym)
24094 .endm
24095
24096 #ifdef CONFIG_TRACING
24097@@ -1306,7 +1789,7 @@ ENTRY(\sym)
24098 call \do_sym
24099 jmp paranoid_exit /* %ebx: no swapgs flag */
24100 CFI_ENDPROC
24101-END(\sym)
24102+ENDPROC(\sym)
24103 .endm
24104
24105 zeroentry divide_error do_divide_error
24106@@ -1336,9 +1819,10 @@ gs_change:
24107 2: mfence /* workaround */
24108 SWAPGS
24109 popfq_cfi
24110+ pax_force_retaddr
24111 ret
24112 CFI_ENDPROC
24113-END(native_load_gs_index)
24114+ENDPROC(native_load_gs_index)
24115
24116 _ASM_EXTABLE(gs_change,bad_gs)
24117 .section .fixup,"ax"
24118@@ -1366,9 +1850,10 @@ ENTRY(do_softirq_own_stack)
24119 CFI_DEF_CFA_REGISTER rsp
24120 CFI_ADJUST_CFA_OFFSET -8
24121 decl PER_CPU_VAR(irq_count)
24122+ pax_force_retaddr
24123 ret
24124 CFI_ENDPROC
24125-END(do_softirq_own_stack)
24126+ENDPROC(do_softirq_own_stack)
24127
24128 #ifdef CONFIG_XEN
24129 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
24130@@ -1406,7 +1891,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
24131 decl PER_CPU_VAR(irq_count)
24132 jmp error_exit
24133 CFI_ENDPROC
24134-END(xen_do_hypervisor_callback)
24135+ENDPROC(xen_do_hypervisor_callback)
24136
24137 /*
24138 * Hypervisor uses this for application faults while it executes.
24139@@ -1465,7 +1950,7 @@ ENTRY(xen_failsafe_callback)
24140 SAVE_ALL
24141 jmp error_exit
24142 CFI_ENDPROC
24143-END(xen_failsafe_callback)
24144+ENDPROC(xen_failsafe_callback)
24145
24146 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
24147 xen_hvm_callback_vector xen_evtchn_do_upcall
24148@@ -1517,18 +2002,33 @@ ENTRY(paranoid_exit)
24149 DEFAULT_FRAME
24150 DISABLE_INTERRUPTS(CLBR_NONE)
24151 TRACE_IRQS_OFF_DEBUG
24152- testl %ebx,%ebx /* swapgs needed? */
24153+ testl $1,%ebx /* swapgs needed? */
24154 jnz paranoid_restore
24155- testl $3,CS(%rsp)
24156+ testb $3,CS(%rsp)
24157 jnz paranoid_userspace
24158+#ifdef CONFIG_PAX_MEMORY_UDEREF
24159+ pax_exit_kernel
24160+ TRACE_IRQS_IRETQ 0
24161+ SWAPGS_UNSAFE_STACK
24162+ RESTORE_ALL 8
24163+ pax_force_retaddr_bts
24164+ jmp irq_return
24165+#endif
24166 paranoid_swapgs:
24167+#ifdef CONFIG_PAX_MEMORY_UDEREF
24168+ pax_exit_kernel_user
24169+#else
24170+ pax_exit_kernel
24171+#endif
24172 TRACE_IRQS_IRETQ 0
24173 SWAPGS_UNSAFE_STACK
24174 RESTORE_ALL 8
24175 jmp irq_return
24176 paranoid_restore:
24177+ pax_exit_kernel
24178 TRACE_IRQS_IRETQ_DEBUG 0
24179 RESTORE_ALL 8
24180+ pax_force_retaddr_bts
24181 jmp irq_return
24182 paranoid_userspace:
24183 GET_THREAD_INFO(%rcx)
24184@@ -1557,7 +2057,7 @@ paranoid_schedule:
24185 TRACE_IRQS_OFF
24186 jmp paranoid_userspace
24187 CFI_ENDPROC
24188-END(paranoid_exit)
24189+ENDPROC(paranoid_exit)
24190
24191 /*
24192 * Exception entry point. This expects an error code/orig_rax on the stack.
24193@@ -1584,12 +2084,23 @@ ENTRY(error_entry)
24194 movq_cfi r14, R14+8
24195 movq_cfi r15, R15+8
24196 xorl %ebx,%ebx
24197- testl $3,CS+8(%rsp)
24198+ testb $3,CS+8(%rsp)
24199 je error_kernelspace
24200 error_swapgs:
24201 SWAPGS
24202 error_sti:
24203+#ifdef CONFIG_PAX_MEMORY_UDEREF
24204+ testb $3, CS+8(%rsp)
24205+ jnz 1f
24206+ pax_enter_kernel
24207+ jmp 2f
24208+1: pax_enter_kernel_user
24209+2:
24210+#else
24211+ pax_enter_kernel
24212+#endif
24213 TRACE_IRQS_OFF
24214+ pax_force_retaddr
24215 ret
24216
24217 /*
24218@@ -1616,7 +2127,7 @@ bstep_iret:
24219 movq %rcx,RIP+8(%rsp)
24220 jmp error_swapgs
24221 CFI_ENDPROC
24222-END(error_entry)
24223+ENDPROC(error_entry)
24224
24225
24226 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
24227@@ -1627,7 +2138,7 @@ ENTRY(error_exit)
24228 DISABLE_INTERRUPTS(CLBR_NONE)
24229 TRACE_IRQS_OFF
24230 GET_THREAD_INFO(%rcx)
24231- testl %eax,%eax
24232+ testl $1,%eax
24233 jne retint_kernel
24234 LOCKDEP_SYS_EXIT_IRQ
24235 movl TI_flags(%rcx),%edx
24236@@ -1636,7 +2147,7 @@ ENTRY(error_exit)
24237 jnz retint_careful
24238 jmp retint_swapgs
24239 CFI_ENDPROC
24240-END(error_exit)
24241+ENDPROC(error_exit)
24242
24243 /*
24244 * Test if a given stack is an NMI stack or not.
24245@@ -1694,9 +2205,11 @@ ENTRY(nmi)
24246 * If %cs was not the kernel segment, then the NMI triggered in user
24247 * space, which means it is definitely not nested.
24248 */
24249+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
24250+ je 1f
24251 cmpl $__KERNEL_CS, 16(%rsp)
24252 jne first_nmi
24253-
24254+1:
24255 /*
24256 * Check the special variable on the stack to see if NMIs are
24257 * executing.
24258@@ -1730,8 +2243,7 @@ nested_nmi:
24259
24260 1:
24261 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
24262- leaq -1*8(%rsp), %rdx
24263- movq %rdx, %rsp
24264+ subq $8, %rsp
24265 CFI_ADJUST_CFA_OFFSET 1*8
24266 leaq -10*8(%rsp), %rdx
24267 pushq_cfi $__KERNEL_DS
24268@@ -1749,6 +2261,7 @@ nested_nmi_out:
24269 CFI_RESTORE rdx
24270
24271 /* No need to check faults here */
24272+# pax_force_retaddr_bts
24273 INTERRUPT_RETURN
24274
24275 CFI_RESTORE_STATE
24276@@ -1845,13 +2358,13 @@ end_repeat_nmi:
24277 subq $ORIG_RAX-R15, %rsp
24278 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
24279 /*
24280- * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
24281+ * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
24282 * as we should not be calling schedule in NMI context.
24283 * Even with normal interrupts enabled. An NMI should not be
24284 * setting NEED_RESCHED or anything that normal interrupts and
24285 * exceptions might do.
24286 */
24287- call save_paranoid
24288+ call save_paranoid_nmi
24289 DEFAULT_FRAME 0
24290
24291 /*
24292@@ -1861,9 +2374,9 @@ end_repeat_nmi:
24293 * NMI itself takes a page fault, the page fault that was preempted
24294 * will read the information from the NMI page fault and not the
24295 * origin fault. Save it off and restore it if it changes.
24296- * Use the r12 callee-saved register.
24297+ * Use the r13 callee-saved register.
24298 */
24299- movq %cr2, %r12
24300+ movq %cr2, %r13
24301
24302 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
24303 movq %rsp,%rdi
24304@@ -1872,31 +2385,36 @@ end_repeat_nmi:
24305
24306 /* Did the NMI take a page fault? Restore cr2 if it did */
24307 movq %cr2, %rcx
24308- cmpq %rcx, %r12
24309+ cmpq %rcx, %r13
24310 je 1f
24311- movq %r12, %cr2
24312+ movq %r13, %cr2
24313 1:
24314
24315- testl %ebx,%ebx /* swapgs needed? */
24316+ testl $1,%ebx /* swapgs needed? */
24317 jnz nmi_restore
24318 nmi_swapgs:
24319 SWAPGS_UNSAFE_STACK
24320 nmi_restore:
24321+ pax_exit_kernel_nmi
24322 /* Pop the extra iret frame at once */
24323 RESTORE_ALL 6*8
24324+ testb $3, 8(%rsp)
24325+ jnz 1f
24326+ pax_force_retaddr_bts
24327+1:
24328
24329 /* Clear the NMI executing stack variable */
24330 movq $0, 5*8(%rsp)
24331 jmp irq_return
24332 CFI_ENDPROC
24333-END(nmi)
24334+ENDPROC(nmi)
24335
24336 ENTRY(ignore_sysret)
24337 CFI_STARTPROC
24338 mov $-ENOSYS,%eax
24339 sysret
24340 CFI_ENDPROC
24341-END(ignore_sysret)
24342+ENDPROC(ignore_sysret)
24343
24344 /*
24345 * End of kprobes section
24346diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
24347index 1ffc32d..e52c745 100644
24348--- a/arch/x86/kernel/ftrace.c
24349+++ b/arch/x86/kernel/ftrace.c
24350@@ -104,6 +104,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
24351 {
24352 unsigned char replaced[MCOUNT_INSN_SIZE];
24353
24354+ ip = ktla_ktva(ip);
24355+
24356 /*
24357 * Note: Due to modules and __init, code can
24358 * disappear and change, we need to protect against faulting
24359@@ -229,7 +231,7 @@ static int update_ftrace_func(unsigned long ip, void *new)
24360 unsigned char old[MCOUNT_INSN_SIZE];
24361 int ret;
24362
24363- memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
24364+ memcpy(old, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE);
24365
24366 ftrace_update_func = ip;
24367 /* Make sure the breakpoints see the ftrace_update_func update */
24368@@ -306,7 +308,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
24369 * kernel identity mapping to modify code.
24370 */
24371 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
24372- ip = (unsigned long)__va(__pa_symbol(ip));
24373+ ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
24374
24375 return probe_kernel_write((void *)ip, val, size);
24376 }
24377@@ -316,7 +318,7 @@ static int add_break(unsigned long ip, const char *old)
24378 unsigned char replaced[MCOUNT_INSN_SIZE];
24379 unsigned char brk = BREAKPOINT_INSTRUCTION;
24380
24381- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
24382+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
24383 return -EFAULT;
24384
24385 /* Make sure it is what we expect it to be */
24386@@ -664,7 +666,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
24387 return ret;
24388
24389 fail_update:
24390- probe_kernel_write((void *)ip, &old_code[0], 1);
24391+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
24392 goto out;
24393 }
24394
24395diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
24396index 85126cc..1bbce17 100644
24397--- a/arch/x86/kernel/head64.c
24398+++ b/arch/x86/kernel/head64.c
24399@@ -67,12 +67,12 @@ again:
24400 pgd = *pgd_p;
24401
24402 /*
24403- * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
24404- * critical -- __PAGE_OFFSET would point us back into the dynamic
24405+ * The use of __early_va rather than __va here is critical:
24406+ * __va would point us back into the dynamic
24407 * range and we might end up looping forever...
24408 */
24409 if (pgd)
24410- pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24411+ pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
24412 else {
24413 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24414 reset_early_page_tables();
24415@@ -82,13 +82,13 @@ again:
24416 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
24417 for (i = 0; i < PTRS_PER_PUD; i++)
24418 pud_p[i] = 0;
24419- *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24420+ *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
24421 }
24422 pud_p += pud_index(address);
24423 pud = *pud_p;
24424
24425 if (pud)
24426- pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24427+ pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
24428 else {
24429 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24430 reset_early_page_tables();
24431@@ -98,7 +98,7 @@ again:
24432 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
24433 for (i = 0; i < PTRS_PER_PMD; i++)
24434 pmd_p[i] = 0;
24435- *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24436+ *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
24437 }
24438 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
24439 pmd_p[pmd_index(address)] = pmd;
24440@@ -175,7 +175,6 @@ asmlinkage void __init x86_64_start_kernel(char * real_mode_data)
24441 if (console_loglevel == 10)
24442 early_printk("Kernel alive\n");
24443
24444- clear_page(init_level4_pgt);
24445 /* set init_level4_pgt kernel high mapping*/
24446 init_level4_pgt[511] = early_level4_pgt[511];
24447
24448diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
24449index f36bd42..56ee1534 100644
24450--- a/arch/x86/kernel/head_32.S
24451+++ b/arch/x86/kernel/head_32.S
24452@@ -26,6 +26,12 @@
24453 /* Physical address */
24454 #define pa(X) ((X) - __PAGE_OFFSET)
24455
24456+#ifdef CONFIG_PAX_KERNEXEC
24457+#define ta(X) (X)
24458+#else
24459+#define ta(X) ((X) - __PAGE_OFFSET)
24460+#endif
24461+
24462 /*
24463 * References to members of the new_cpu_data structure.
24464 */
24465@@ -55,11 +61,7 @@
24466 * and small than max_low_pfn, otherwise will waste some page table entries
24467 */
24468
24469-#if PTRS_PER_PMD > 1
24470-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
24471-#else
24472-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
24473-#endif
24474+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
24475
24476 /* Number of possible pages in the lowmem region */
24477 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
24478@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
24479 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24480
24481 /*
24482+ * Real beginning of normal "text" segment
24483+ */
24484+ENTRY(stext)
24485+ENTRY(_stext)
24486+
24487+/*
24488 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
24489 * %esi points to the real-mode code as a 32-bit pointer.
24490 * CS and DS must be 4 GB flat segments, but we don't depend on
24491@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24492 * can.
24493 */
24494 __HEAD
24495+
24496+#ifdef CONFIG_PAX_KERNEXEC
24497+ jmp startup_32
24498+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
24499+.fill PAGE_SIZE-5,1,0xcc
24500+#endif
24501+
24502 ENTRY(startup_32)
24503 movl pa(stack_start),%ecx
24504
24505@@ -106,6 +121,59 @@ ENTRY(startup_32)
24506 2:
24507 leal -__PAGE_OFFSET(%ecx),%esp
24508
24509+#ifdef CONFIG_SMP
24510+ movl $pa(cpu_gdt_table),%edi
24511+ movl $__per_cpu_load,%eax
24512+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
24513+ rorl $16,%eax
24514+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
24515+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
24516+ movl $__per_cpu_end - 1,%eax
24517+ subl $__per_cpu_start,%eax
24518+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
24519+#endif
24520+
24521+#ifdef CONFIG_PAX_MEMORY_UDEREF
24522+ movl $NR_CPUS,%ecx
24523+ movl $pa(cpu_gdt_table),%edi
24524+1:
24525+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
24526+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
24527+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
24528+ addl $PAGE_SIZE_asm,%edi
24529+ loop 1b
24530+#endif
24531+
24532+#ifdef CONFIG_PAX_KERNEXEC
24533+ movl $pa(boot_gdt),%edi
24534+ movl $__LOAD_PHYSICAL_ADDR,%eax
24535+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
24536+ rorl $16,%eax
24537+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
24538+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
24539+ rorl $16,%eax
24540+
24541+ ljmp $(__BOOT_CS),$1f
24542+1:
24543+
24544+ movl $NR_CPUS,%ecx
24545+ movl $pa(cpu_gdt_table),%edi
24546+ addl $__PAGE_OFFSET,%eax
24547+1:
24548+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
24549+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
24550+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
24551+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
24552+ rorl $16,%eax
24553+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
24554+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
24555+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
24556+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
24557+ rorl $16,%eax
24558+ addl $PAGE_SIZE_asm,%edi
24559+ loop 1b
24560+#endif
24561+
24562 /*
24563 * Clear BSS first so that there are no surprises...
24564 */
24565@@ -201,8 +269,11 @@ ENTRY(startup_32)
24566 movl %eax, pa(max_pfn_mapped)
24567
24568 /* Do early initialization of the fixmap area */
24569- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24570- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
24571+#ifdef CONFIG_COMPAT_VDSO
24572+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
24573+#else
24574+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
24575+#endif
24576 #else /* Not PAE */
24577
24578 page_pde_offset = (__PAGE_OFFSET >> 20);
24579@@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24580 movl %eax, pa(max_pfn_mapped)
24581
24582 /* Do early initialization of the fixmap area */
24583- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24584- movl %eax,pa(initial_page_table+0xffc)
24585+#ifdef CONFIG_COMPAT_VDSO
24586+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
24587+#else
24588+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
24589+#endif
24590 #endif
24591
24592 #ifdef CONFIG_PARAVIRT
24593@@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24594 cmpl $num_subarch_entries, %eax
24595 jae bad_subarch
24596
24597- movl pa(subarch_entries)(,%eax,4), %eax
24598- subl $__PAGE_OFFSET, %eax
24599- jmp *%eax
24600+ jmp *pa(subarch_entries)(,%eax,4)
24601
24602 bad_subarch:
24603 WEAK(lguest_entry)
24604@@ -261,10 +333,10 @@ WEAK(xen_entry)
24605 __INITDATA
24606
24607 subarch_entries:
24608- .long default_entry /* normal x86/PC */
24609- .long lguest_entry /* lguest hypervisor */
24610- .long xen_entry /* Xen hypervisor */
24611- .long default_entry /* Moorestown MID */
24612+ .long ta(default_entry) /* normal x86/PC */
24613+ .long ta(lguest_entry) /* lguest hypervisor */
24614+ .long ta(xen_entry) /* Xen hypervisor */
24615+ .long ta(default_entry) /* Moorestown MID */
24616 num_subarch_entries = (. - subarch_entries) / 4
24617 .previous
24618 #else
24619@@ -354,6 +426,7 @@ default_entry:
24620 movl pa(mmu_cr4_features),%eax
24621 movl %eax,%cr4
24622
24623+#ifdef CONFIG_X86_PAE
24624 testb $X86_CR4_PAE, %al # check if PAE is enabled
24625 jz enable_paging
24626
24627@@ -382,6 +455,9 @@ default_entry:
24628 /* Make changes effective */
24629 wrmsr
24630
24631+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
24632+#endif
24633+
24634 enable_paging:
24635
24636 /*
24637@@ -449,14 +525,20 @@ is486:
24638 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
24639 movl %eax,%ss # after changing gdt.
24640
24641- movl $(__USER_DS),%eax # DS/ES contains default USER segment
24642+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
24643 movl %eax,%ds
24644 movl %eax,%es
24645
24646 movl $(__KERNEL_PERCPU), %eax
24647 movl %eax,%fs # set this cpu's percpu
24648
24649+#ifdef CONFIG_CC_STACKPROTECTOR
24650 movl $(__KERNEL_STACK_CANARY),%eax
24651+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
24652+ movl $(__USER_DS),%eax
24653+#else
24654+ xorl %eax,%eax
24655+#endif
24656 movl %eax,%gs
24657
24658 xorl %eax,%eax # Clear LDT
24659@@ -512,8 +594,11 @@ setup_once:
24660 * relocation. Manually set base address in stack canary
24661 * segment descriptor.
24662 */
24663- movl $gdt_page,%eax
24664+ movl $cpu_gdt_table,%eax
24665 movl $stack_canary,%ecx
24666+#ifdef CONFIG_SMP
24667+ addl $__per_cpu_load,%ecx
24668+#endif
24669 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
24670 shrl $16, %ecx
24671 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
24672@@ -548,7 +633,7 @@ ENTRY(early_idt_handler)
24673 cmpl $2,(%esp) # X86_TRAP_NMI
24674 je is_nmi # Ignore NMI
24675
24676- cmpl $2,%ss:early_recursion_flag
24677+ cmpl $1,%ss:early_recursion_flag
24678 je hlt_loop
24679 incl %ss:early_recursion_flag
24680
24681@@ -586,8 +671,8 @@ ENTRY(early_idt_handler)
24682 pushl (20+6*4)(%esp) /* trapno */
24683 pushl $fault_msg
24684 call printk
24685-#endif
24686 call dump_stack
24687+#endif
24688 hlt_loop:
24689 hlt
24690 jmp hlt_loop
24691@@ -607,8 +692,11 @@ ENDPROC(early_idt_handler)
24692 /* This is the default interrupt "handler" :-) */
24693 ALIGN
24694 ignore_int:
24695- cld
24696 #ifdef CONFIG_PRINTK
24697+ cmpl $2,%ss:early_recursion_flag
24698+ je hlt_loop
24699+ incl %ss:early_recursion_flag
24700+ cld
24701 pushl %eax
24702 pushl %ecx
24703 pushl %edx
24704@@ -617,9 +705,6 @@ ignore_int:
24705 movl $(__KERNEL_DS),%eax
24706 movl %eax,%ds
24707 movl %eax,%es
24708- cmpl $2,early_recursion_flag
24709- je hlt_loop
24710- incl early_recursion_flag
24711 pushl 16(%esp)
24712 pushl 24(%esp)
24713 pushl 32(%esp)
24714@@ -653,29 +738,34 @@ ENTRY(setup_once_ref)
24715 /*
24716 * BSS section
24717 */
24718-__PAGE_ALIGNED_BSS
24719- .align PAGE_SIZE
24720 #ifdef CONFIG_X86_PAE
24721+.section .initial_pg_pmd,"a",@progbits
24722 initial_pg_pmd:
24723 .fill 1024*KPMDS,4,0
24724 #else
24725+.section .initial_page_table,"a",@progbits
24726 ENTRY(initial_page_table)
24727 .fill 1024,4,0
24728 #endif
24729+.section .initial_pg_fixmap,"a",@progbits
24730 initial_pg_fixmap:
24731 .fill 1024,4,0
24732+.section .empty_zero_page,"a",@progbits
24733 ENTRY(empty_zero_page)
24734 .fill 4096,1,0
24735+.section .swapper_pg_dir,"a",@progbits
24736 ENTRY(swapper_pg_dir)
24737+#ifdef CONFIG_X86_PAE
24738+ .fill 4,8,0
24739+#else
24740 .fill 1024,4,0
24741+#endif
24742
24743 /*
24744 * This starts the data section.
24745 */
24746 #ifdef CONFIG_X86_PAE
24747-__PAGE_ALIGNED_DATA
24748- /* Page-aligned for the benefit of paravirt? */
24749- .align PAGE_SIZE
24750+.section .initial_page_table,"a",@progbits
24751 ENTRY(initial_page_table)
24752 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
24753 # if KPMDS == 3
24754@@ -694,12 +784,20 @@ ENTRY(initial_page_table)
24755 # error "Kernel PMDs should be 1, 2 or 3"
24756 # endif
24757 .align PAGE_SIZE /* needs to be page-sized too */
24758+
24759+#ifdef CONFIG_PAX_PER_CPU_PGD
24760+ENTRY(cpu_pgd)
24761+ .rept 2*NR_CPUS
24762+ .fill 4,8,0
24763+ .endr
24764+#endif
24765+
24766 #endif
24767
24768 .data
24769 .balign 4
24770 ENTRY(stack_start)
24771- .long init_thread_union+THREAD_SIZE
24772+ .long init_thread_union+THREAD_SIZE-8
24773
24774 __INITRODATA
24775 int_msg:
24776@@ -727,7 +825,7 @@ fault_msg:
24777 * segment size, and 32-bit linear address value:
24778 */
24779
24780- .data
24781+.section .rodata,"a",@progbits
24782 .globl boot_gdt_descr
24783 .globl idt_descr
24784
24785@@ -736,7 +834,7 @@ fault_msg:
24786 .word 0 # 32 bit align gdt_desc.address
24787 boot_gdt_descr:
24788 .word __BOOT_DS+7
24789- .long boot_gdt - __PAGE_OFFSET
24790+ .long pa(boot_gdt)
24791
24792 .word 0 # 32-bit align idt_desc.address
24793 idt_descr:
24794@@ -747,7 +845,7 @@ idt_descr:
24795 .word 0 # 32 bit align gdt_desc.address
24796 ENTRY(early_gdt_descr)
24797 .word GDT_ENTRIES*8-1
24798- .long gdt_page /* Overwritten for secondary CPUs */
24799+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
24800
24801 /*
24802 * The boot_gdt must mirror the equivalent in setup.S and is
24803@@ -756,5 +854,65 @@ ENTRY(early_gdt_descr)
24804 .align L1_CACHE_BYTES
24805 ENTRY(boot_gdt)
24806 .fill GDT_ENTRY_BOOT_CS,8,0
24807- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
24808- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
24809+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
24810+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
24811+
24812+ .align PAGE_SIZE_asm
24813+ENTRY(cpu_gdt_table)
24814+ .rept NR_CPUS
24815+ .quad 0x0000000000000000 /* NULL descriptor */
24816+ .quad 0x0000000000000000 /* 0x0b reserved */
24817+ .quad 0x0000000000000000 /* 0x13 reserved */
24818+ .quad 0x0000000000000000 /* 0x1b reserved */
24819+
24820+#ifdef CONFIG_PAX_KERNEXEC
24821+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
24822+#else
24823+ .quad 0x0000000000000000 /* 0x20 unused */
24824+#endif
24825+
24826+ .quad 0x0000000000000000 /* 0x28 unused */
24827+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
24828+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
24829+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
24830+ .quad 0x0000000000000000 /* 0x4b reserved */
24831+ .quad 0x0000000000000000 /* 0x53 reserved */
24832+ .quad 0x0000000000000000 /* 0x5b reserved */
24833+
24834+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
24835+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
24836+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
24837+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
24838+
24839+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
24840+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
24841+
24842+ /*
24843+ * Segments used for calling PnP BIOS have byte granularity.
24844+ * The code segments and data segments have fixed 64k limits,
24845+ * the transfer segment sizes are set at run time.
24846+ */
24847+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
24848+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
24849+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
24850+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
24851+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
24852+
24853+ /*
24854+ * The APM segments have byte granularity and their bases
24855+ * are set at run time. All have 64k limits.
24856+ */
24857+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
24858+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
24859+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
24860+
24861+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
24862+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
24863+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
24864+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
24865+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
24866+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
24867+
24868+ /* Be sure this is zeroed to avoid false validations in Xen */
24869+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
24870+ .endr
24871diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
24872index a468c0a..c7dec74 100644
24873--- a/arch/x86/kernel/head_64.S
24874+++ b/arch/x86/kernel/head_64.S
24875@@ -20,6 +20,8 @@
24876 #include <asm/processor-flags.h>
24877 #include <asm/percpu.h>
24878 #include <asm/nops.h>
24879+#include <asm/cpufeature.h>
24880+#include <asm/alternative-asm.h>
24881
24882 #ifdef CONFIG_PARAVIRT
24883 #include <asm/asm-offsets.h>
24884@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
24885 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
24886 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
24887 L3_START_KERNEL = pud_index(__START_KERNEL_map)
24888+L4_VMALLOC_START = pgd_index(VMALLOC_START)
24889+L3_VMALLOC_START = pud_index(VMALLOC_START)
24890+L4_VMALLOC_END = pgd_index(VMALLOC_END)
24891+L3_VMALLOC_END = pud_index(VMALLOC_END)
24892+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
24893+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
24894
24895 .text
24896 __HEAD
24897@@ -89,11 +97,24 @@ startup_64:
24898 * Fixup the physical addresses in the page table
24899 */
24900 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
24901+ addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
24902+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
24903+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
24904+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
24905+ addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
24906
24907- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
24908- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
24909+ addq %rbp, level3_ident_pgt + (0*8)(%rip)
24910+#ifndef CONFIG_XEN
24911+ addq %rbp, level3_ident_pgt + (1*8)(%rip)
24912+#endif
24913+
24914+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
24915+
24916+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
24917+ addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
24918
24919 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
24920+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
24921
24922 /*
24923 * Set up the identity mapping for the switchover. These
24924@@ -177,8 +198,8 @@ ENTRY(secondary_startup_64)
24925 movq $(init_level4_pgt - __START_KERNEL_map), %rax
24926 1:
24927
24928- /* Enable PAE mode and PGE */
24929- movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
24930+ /* Enable PAE mode and PSE/PGE */
24931+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
24932 movq %rcx, %cr4
24933
24934 /* Setup early boot stage 4 level pagetables. */
24935@@ -199,10 +220,19 @@ ENTRY(secondary_startup_64)
24936 movl $MSR_EFER, %ecx
24937 rdmsr
24938 btsl $_EFER_SCE, %eax /* Enable System Call */
24939- btl $20,%edi /* No Execute supported? */
24940+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
24941 jnc 1f
24942 btsl $_EFER_NX, %eax
24943 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
24944+#ifndef CONFIG_EFI
24945+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
24946+#endif
24947+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
24948+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
24949+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
24950+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
24951+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
24952+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
24953 1: wrmsr /* Make changes effective */
24954
24955 /* Setup cr0 */
24956@@ -282,6 +312,7 @@ ENTRY(secondary_startup_64)
24957 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
24958 * address given in m16:64.
24959 */
24960+ pax_set_fptr_mask
24961 movq initial_code(%rip),%rax
24962 pushq $0 # fake return address to stop unwinder
24963 pushq $__KERNEL_CS # set correct cs
24964@@ -313,7 +344,7 @@ ENDPROC(start_cpu0)
24965 .quad INIT_PER_CPU_VAR(irq_stack_union)
24966
24967 GLOBAL(stack_start)
24968- .quad init_thread_union+THREAD_SIZE-8
24969+ .quad init_thread_union+THREAD_SIZE-16
24970 .word 0
24971 __FINITDATA
24972
24973@@ -391,7 +422,7 @@ ENTRY(early_idt_handler)
24974 call dump_stack
24975 #ifdef CONFIG_KALLSYMS
24976 leaq early_idt_ripmsg(%rip),%rdi
24977- movq 40(%rsp),%rsi # %rip again
24978+ movq 88(%rsp),%rsi # %rip again
24979 call __print_symbol
24980 #endif
24981 #endif /* EARLY_PRINTK */
24982@@ -420,6 +451,7 @@ ENDPROC(early_idt_handler)
24983 early_recursion_flag:
24984 .long 0
24985
24986+ .section .rodata,"a",@progbits
24987 #ifdef CONFIG_EARLY_PRINTK
24988 early_idt_msg:
24989 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
24990@@ -447,29 +479,52 @@ NEXT_PAGE(early_level4_pgt)
24991 NEXT_PAGE(early_dynamic_pgts)
24992 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
24993
24994- .data
24995+ .section .rodata,"a",@progbits
24996
24997-#ifndef CONFIG_XEN
24998 NEXT_PAGE(init_level4_pgt)
24999- .fill 512,8,0
25000-#else
25001-NEXT_PAGE(init_level4_pgt)
25002- .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25003 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
25004 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25005+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
25006+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
25007+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
25008+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
25009+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
25010+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
25011 .org init_level4_pgt + L4_START_KERNEL*8, 0
25012 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
25013 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
25014
25015+#ifdef CONFIG_PAX_PER_CPU_PGD
25016+NEXT_PAGE(cpu_pgd)
25017+ .rept 2*NR_CPUS
25018+ .fill 512,8,0
25019+ .endr
25020+#endif
25021+
25022 NEXT_PAGE(level3_ident_pgt)
25023 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25024+#ifdef CONFIG_XEN
25025 .fill 511, 8, 0
25026+#else
25027+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
25028+ .fill 510,8,0
25029+#endif
25030+
25031+NEXT_PAGE(level3_vmalloc_start_pgt)
25032+ .fill 512,8,0
25033+
25034+NEXT_PAGE(level3_vmalloc_end_pgt)
25035+ .fill 512,8,0
25036+
25037+NEXT_PAGE(level3_vmemmap_pgt)
25038+ .fill L3_VMEMMAP_START,8,0
25039+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
25040+
25041 NEXT_PAGE(level2_ident_pgt)
25042- /* Since I easily can, map the first 1G.
25043+ /* Since I easily can, map the first 2G.
25044 * Don't set NX because code runs from these pages.
25045 */
25046- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
25047-#endif
25048+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
25049
25050 NEXT_PAGE(level3_kernel_pgt)
25051 .fill L3_START_KERNEL,8,0
25052@@ -477,6 +532,9 @@ NEXT_PAGE(level3_kernel_pgt)
25053 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
25054 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
25055
25056+NEXT_PAGE(level2_vmemmap_pgt)
25057+ .fill 512,8,0
25058+
25059 NEXT_PAGE(level2_kernel_pgt)
25060 /*
25061 * 512 MB kernel mapping. We spend a full page on this pagetable
25062@@ -494,28 +552,64 @@ NEXT_PAGE(level2_kernel_pgt)
25063 NEXT_PAGE(level2_fixmap_pgt)
25064 .fill 506,8,0
25065 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
25066- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
25067- .fill 5,8,0
25068+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
25069+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
25070+ .fill 4,8,0
25071
25072 NEXT_PAGE(level1_fixmap_pgt)
25073 .fill 512,8,0
25074
25075+NEXT_PAGE(level1_vsyscall_pgt)
25076+ .fill 512,8,0
25077+
25078 #undef PMDS
25079
25080- .data
25081+ .align PAGE_SIZE
25082+ENTRY(cpu_gdt_table)
25083+ .rept NR_CPUS
25084+ .quad 0x0000000000000000 /* NULL descriptor */
25085+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
25086+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
25087+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
25088+ .quad 0x00cffb000000ffff /* __USER32_CS */
25089+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
25090+ .quad 0x00affb000000ffff /* __USER_CS */
25091+
25092+#ifdef CONFIG_PAX_KERNEXEC
25093+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
25094+#else
25095+ .quad 0x0 /* unused */
25096+#endif
25097+
25098+ .quad 0,0 /* TSS */
25099+ .quad 0,0 /* LDT */
25100+ .quad 0,0,0 /* three TLS descriptors */
25101+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
25102+ /* asm/segment.h:GDT_ENTRIES must match this */
25103+
25104+#ifdef CONFIG_PAX_MEMORY_UDEREF
25105+ .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
25106+#else
25107+ .quad 0x0 /* unused */
25108+#endif
25109+
25110+ /* zero the remaining page */
25111+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
25112+ .endr
25113+
25114 .align 16
25115 .globl early_gdt_descr
25116 early_gdt_descr:
25117 .word GDT_ENTRIES*8-1
25118 early_gdt_descr_base:
25119- .quad INIT_PER_CPU_VAR(gdt_page)
25120+ .quad cpu_gdt_table
25121
25122 ENTRY(phys_base)
25123 /* This must match the first entry in level2_kernel_pgt */
25124 .quad 0x0000000000000000
25125
25126 #include "../../x86/xen/xen-head.S"
25127-
25128- __PAGE_ALIGNED_BSS
25129+
25130+ .section .rodata,"a",@progbits
25131 NEXT_PAGE(empty_zero_page)
25132 .skip PAGE_SIZE
25133diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
25134index 05fd74f..c3548b1 100644
25135--- a/arch/x86/kernel/i386_ksyms_32.c
25136+++ b/arch/x86/kernel/i386_ksyms_32.c
25137@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
25138 EXPORT_SYMBOL(cmpxchg8b_emu);
25139 #endif
25140
25141+EXPORT_SYMBOL_GPL(cpu_gdt_table);
25142+
25143 /* Networking helper routines. */
25144 EXPORT_SYMBOL(csum_partial_copy_generic);
25145+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
25146+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
25147
25148 EXPORT_SYMBOL(__get_user_1);
25149 EXPORT_SYMBOL(__get_user_2);
25150@@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
25151 EXPORT_SYMBOL(___preempt_schedule_context);
25152 #endif
25153 #endif
25154+
25155+#ifdef CONFIG_PAX_KERNEXEC
25156+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
25157+#endif
25158+
25159+#ifdef CONFIG_PAX_PER_CPU_PGD
25160+EXPORT_SYMBOL(cpu_pgd);
25161+#endif
25162diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
25163index d5dd808..b6432cf 100644
25164--- a/arch/x86/kernel/i387.c
25165+++ b/arch/x86/kernel/i387.c
25166@@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
25167 static inline bool interrupted_user_mode(void)
25168 {
25169 struct pt_regs *regs = get_irq_regs();
25170- return regs && user_mode_vm(regs);
25171+ return regs && user_mode(regs);
25172 }
25173
25174 /*
25175diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
25176index 2e977b5..5f2c273 100644
25177--- a/arch/x86/kernel/i8259.c
25178+++ b/arch/x86/kernel/i8259.c
25179@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
25180 static void make_8259A_irq(unsigned int irq)
25181 {
25182 disable_irq_nosync(irq);
25183- io_apic_irqs &= ~(1<<irq);
25184+ io_apic_irqs &= ~(1UL<<irq);
25185 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
25186 i8259A_chip.name);
25187 enable_irq(irq);
25188@@ -209,7 +209,7 @@ spurious_8259A_irq:
25189 "spurious 8259A interrupt: IRQ%d.\n", irq);
25190 spurious_irq_mask |= irqmask;
25191 }
25192- atomic_inc(&irq_err_count);
25193+ atomic_inc_unchecked(&irq_err_count);
25194 /*
25195 * Theoretically we do not have to handle this IRQ,
25196 * but in Linux this does not cause problems and is
25197@@ -332,14 +332,16 @@ static void init_8259A(int auto_eoi)
25198 /* (slave's support for AEOI in flat mode is to be investigated) */
25199 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
25200
25201+ pax_open_kernel();
25202 if (auto_eoi)
25203 /*
25204 * In AEOI mode we just have to mask the interrupt
25205 * when acking.
25206 */
25207- i8259A_chip.irq_mask_ack = disable_8259A_irq;
25208+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
25209 else
25210- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25211+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25212+ pax_close_kernel();
25213
25214 udelay(100); /* wait for 8259A to initialize */
25215
25216diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
25217index a979b5b..1d6db75 100644
25218--- a/arch/x86/kernel/io_delay.c
25219+++ b/arch/x86/kernel/io_delay.c
25220@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
25221 * Quirk table for systems that misbehave (lock up, etc.) if port
25222 * 0x80 is used:
25223 */
25224-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
25225+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
25226 {
25227 .callback = dmi_io_delay_0xed_port,
25228 .ident = "Compaq Presario V6000",
25229diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
25230index 4ddaf66..49d5c18 100644
25231--- a/arch/x86/kernel/ioport.c
25232+++ b/arch/x86/kernel/ioport.c
25233@@ -6,6 +6,7 @@
25234 #include <linux/sched.h>
25235 #include <linux/kernel.h>
25236 #include <linux/capability.h>
25237+#include <linux/security.h>
25238 #include <linux/errno.h>
25239 #include <linux/types.h>
25240 #include <linux/ioport.h>
25241@@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25242 return -EINVAL;
25243 if (turn_on && !capable(CAP_SYS_RAWIO))
25244 return -EPERM;
25245+#ifdef CONFIG_GRKERNSEC_IO
25246+ if (turn_on && grsec_disable_privio) {
25247+ gr_handle_ioperm();
25248+ return -ENODEV;
25249+ }
25250+#endif
25251
25252 /*
25253 * If it's the first ioperm() call in this thread's lifetime, set the
25254@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25255 * because the ->io_bitmap_max value must match the bitmap
25256 * contents:
25257 */
25258- tss = &per_cpu(init_tss, get_cpu());
25259+ tss = init_tss + get_cpu();
25260
25261 if (turn_on)
25262 bitmap_clear(t->io_bitmap_ptr, from, num);
25263@@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
25264 if (level > old) {
25265 if (!capable(CAP_SYS_RAWIO))
25266 return -EPERM;
25267+#ifdef CONFIG_GRKERNSEC_IO
25268+ if (grsec_disable_privio) {
25269+ gr_handle_iopl();
25270+ return -ENODEV;
25271+ }
25272+#endif
25273 }
25274 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
25275 t->iopl = level << 12;
25276diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
25277index d99f31d..1c0f466 100644
25278--- a/arch/x86/kernel/irq.c
25279+++ b/arch/x86/kernel/irq.c
25280@@ -21,7 +21,7 @@
25281 #define CREATE_TRACE_POINTS
25282 #include <asm/trace/irq_vectors.h>
25283
25284-atomic_t irq_err_count;
25285+atomic_unchecked_t irq_err_count;
25286
25287 /* Function pointer for generic interrupt vector handling */
25288 void (*x86_platform_ipi_callback)(void) = NULL;
25289@@ -125,9 +125,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
25290 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
25291 seq_printf(p, " Machine check polls\n");
25292 #endif
25293- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
25294+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
25295 #if defined(CONFIG_X86_IO_APIC)
25296- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
25297+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
25298 #endif
25299 return 0;
25300 }
25301@@ -167,7 +167,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
25302
25303 u64 arch_irq_stat(void)
25304 {
25305- u64 sum = atomic_read(&irq_err_count);
25306+ u64 sum = atomic_read_unchecked(&irq_err_count);
25307 return sum;
25308 }
25309
25310diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
25311index d7fcbed..96e715a 100644
25312--- a/arch/x86/kernel/irq_32.c
25313+++ b/arch/x86/kernel/irq_32.c
25314@@ -29,6 +29,8 @@ EXPORT_PER_CPU_SYMBOL(irq_regs);
25315
25316 #ifdef CONFIG_DEBUG_STACKOVERFLOW
25317
25318+extern void gr_handle_kernel_exploit(void);
25319+
25320 int sysctl_panic_on_stackoverflow __read_mostly;
25321
25322 /* Debugging check for stack overflow: is there less than 1KB free? */
25323@@ -39,13 +41,14 @@ static int check_stack_overflow(void)
25324 __asm__ __volatile__("andl %%esp,%0" :
25325 "=r" (sp) : "0" (THREAD_SIZE - 1));
25326
25327- return sp < (sizeof(struct thread_info) + STACK_WARN);
25328+ return sp < STACK_WARN;
25329 }
25330
25331 static void print_stack_overflow(void)
25332 {
25333 printk(KERN_WARNING "low stack detected by irq handler\n");
25334 dump_stack();
25335+ gr_handle_kernel_exploit();
25336 if (sysctl_panic_on_stackoverflow)
25337 panic("low stack detected by irq handler - check messages\n");
25338 }
25339@@ -59,8 +62,8 @@ static inline void print_stack_overflow(void) { }
25340 * per-CPU IRQ handling contexts (thread information and stack)
25341 */
25342 union irq_ctx {
25343- struct thread_info tinfo;
25344- u32 stack[THREAD_SIZE/sizeof(u32)];
25345+ unsigned long previous_esp;
25346+ u32 stack[THREAD_SIZE/sizeof(u32)];
25347 } __attribute__((aligned(THREAD_SIZE)));
25348
25349 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
25350@@ -80,10 +83,9 @@ static void call_on_stack(void *func, void *stack)
25351 static inline int
25352 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25353 {
25354- union irq_ctx *curctx, *irqctx;
25355+ union irq_ctx *irqctx;
25356 u32 *isp, arg1, arg2;
25357
25358- curctx = (union irq_ctx *) current_thread_info();
25359 irqctx = __this_cpu_read(hardirq_ctx);
25360
25361 /*
25362@@ -92,13 +94,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25363 * handler) we can't do that and just have to keep using the
25364 * current stack (which is the irq stack already after all)
25365 */
25366- if (unlikely(curctx == irqctx))
25367+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
25368 return 0;
25369
25370 /* build the stack frame on the IRQ stack */
25371- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
25372- irqctx->tinfo.task = curctx->tinfo.task;
25373- irqctx->tinfo.previous_esp = current_stack_pointer;
25374+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
25375+ irqctx->previous_esp = current_stack_pointer;
25376+
25377+#ifdef CONFIG_PAX_MEMORY_UDEREF
25378+ __set_fs(MAKE_MM_SEG(0));
25379+#endif
25380
25381 if (unlikely(overflow))
25382 call_on_stack(print_stack_overflow, isp);
25383@@ -110,6 +115,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25384 : "0" (irq), "1" (desc), "2" (isp),
25385 "D" (desc->handle_irq)
25386 : "memory", "cc", "ecx");
25387+
25388+#ifdef CONFIG_PAX_MEMORY_UDEREF
25389+ __set_fs(current_thread_info()->addr_limit);
25390+#endif
25391+
25392 return 1;
25393 }
25394
25395@@ -118,48 +128,34 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25396 */
25397 void irq_ctx_init(int cpu)
25398 {
25399- union irq_ctx *irqctx;
25400-
25401 if (per_cpu(hardirq_ctx, cpu))
25402 return;
25403
25404- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
25405- THREADINFO_GFP,
25406- THREAD_SIZE_ORDER));
25407- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
25408- irqctx->tinfo.cpu = cpu;
25409- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
25410-
25411- per_cpu(hardirq_ctx, cpu) = irqctx;
25412-
25413- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
25414- THREADINFO_GFP,
25415- THREAD_SIZE_ORDER));
25416- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
25417- irqctx->tinfo.cpu = cpu;
25418- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
25419-
25420- per_cpu(softirq_ctx, cpu) = irqctx;
25421-
25422- printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
25423- cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
25424+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25425+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25426 }
25427
25428 void do_softirq_own_stack(void)
25429 {
25430- struct thread_info *curctx;
25431 union irq_ctx *irqctx;
25432 u32 *isp;
25433
25434- curctx = current_thread_info();
25435 irqctx = __this_cpu_read(softirq_ctx);
25436- irqctx->tinfo.task = curctx->task;
25437- irqctx->tinfo.previous_esp = current_stack_pointer;
25438+ irqctx->previous_esp = current_stack_pointer;
25439
25440 /* build the stack frame on the softirq stack */
25441- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
25442+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
25443+
25444+#ifdef CONFIG_PAX_MEMORY_UDEREF
25445+ __set_fs(MAKE_MM_SEG(0));
25446+#endif
25447
25448 call_on_stack(__do_softirq, isp);
25449+
25450+#ifdef CONFIG_PAX_MEMORY_UDEREF
25451+ __set_fs(current_thread_info()->addr_limit);
25452+#endif
25453+
25454 }
25455
25456 bool handle_irq(unsigned irq, struct pt_regs *regs)
25457@@ -173,7 +169,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
25458 if (unlikely(!desc))
25459 return false;
25460
25461- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25462+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25463 if (unlikely(overflow))
25464 print_stack_overflow();
25465 desc->handle_irq(irq, desc);
25466diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
25467index 4d1c746..55a22d6 100644
25468--- a/arch/x86/kernel/irq_64.c
25469+++ b/arch/x86/kernel/irq_64.c
25470@@ -26,6 +26,8 @@ EXPORT_PER_CPU_SYMBOL(irq_stat);
25471 DEFINE_PER_CPU(struct pt_regs *, irq_regs);
25472 EXPORT_PER_CPU_SYMBOL(irq_regs);
25473
25474+extern void gr_handle_kernel_exploit(void);
25475+
25476 int sysctl_panic_on_stackoverflow;
25477
25478 /*
25479@@ -44,7 +46,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25480 u64 estack_top, estack_bottom;
25481 u64 curbase = (u64)task_stack_page(current);
25482
25483- if (user_mode_vm(regs))
25484+ if (user_mode(regs))
25485 return;
25486
25487 if (regs->sp >= curbase + sizeof(struct thread_info) +
25488@@ -69,6 +71,8 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25489 irq_stack_top, irq_stack_bottom,
25490 estack_top, estack_bottom);
25491
25492+ gr_handle_kernel_exploit();
25493+
25494 if (sysctl_panic_on_stackoverflow)
25495 panic("low stack detected by irq handler - check messages\n");
25496 #endif
25497diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
25498index 26d5a55..a01160a 100644
25499--- a/arch/x86/kernel/jump_label.c
25500+++ b/arch/x86/kernel/jump_label.c
25501@@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25502 * Jump label is enabled for the first time.
25503 * So we expect a default_nop...
25504 */
25505- if (unlikely(memcmp((void *)entry->code, default_nop, 5)
25506+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
25507 != 0))
25508 bug_at((void *)entry->code, __LINE__);
25509 } else {
25510@@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25511 * ...otherwise expect an ideal_nop. Otherwise
25512 * something went horribly wrong.
25513 */
25514- if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
25515+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
25516 != 0))
25517 bug_at((void *)entry->code, __LINE__);
25518 }
25519@@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
25520 * are converting the default nop to the ideal nop.
25521 */
25522 if (init) {
25523- if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
25524+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
25525 bug_at((void *)entry->code, __LINE__);
25526 } else {
25527 code.jump = 0xe9;
25528 code.offset = entry->target -
25529 (entry->code + JUMP_LABEL_NOP_SIZE);
25530- if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
25531+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
25532 bug_at((void *)entry->code, __LINE__);
25533 }
25534 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
25535diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
25536index 7ec1d5f..5a7d130 100644
25537--- a/arch/x86/kernel/kgdb.c
25538+++ b/arch/x86/kernel/kgdb.c
25539@@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
25540 #ifdef CONFIG_X86_32
25541 switch (regno) {
25542 case GDB_SS:
25543- if (!user_mode_vm(regs))
25544+ if (!user_mode(regs))
25545 *(unsigned long *)mem = __KERNEL_DS;
25546 break;
25547 case GDB_SP:
25548- if (!user_mode_vm(regs))
25549+ if (!user_mode(regs))
25550 *(unsigned long *)mem = kernel_stack_pointer(regs);
25551 break;
25552 case GDB_GS:
25553@@ -228,7 +228,10 @@ static void kgdb_correct_hw_break(void)
25554 bp->attr.bp_addr = breakinfo[breakno].addr;
25555 bp->attr.bp_len = breakinfo[breakno].len;
25556 bp->attr.bp_type = breakinfo[breakno].type;
25557- info->address = breakinfo[breakno].addr;
25558+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
25559+ info->address = ktla_ktva(breakinfo[breakno].addr);
25560+ else
25561+ info->address = breakinfo[breakno].addr;
25562 info->len = breakinfo[breakno].len;
25563 info->type = breakinfo[breakno].type;
25564 val = arch_install_hw_breakpoint(bp);
25565@@ -475,12 +478,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
25566 case 'k':
25567 /* clear the trace bit */
25568 linux_regs->flags &= ~X86_EFLAGS_TF;
25569- atomic_set(&kgdb_cpu_doing_single_step, -1);
25570+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
25571
25572 /* set the trace bit if we're stepping */
25573 if (remcomInBuffer[0] == 's') {
25574 linux_regs->flags |= X86_EFLAGS_TF;
25575- atomic_set(&kgdb_cpu_doing_single_step,
25576+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
25577 raw_smp_processor_id());
25578 }
25579
25580@@ -545,7 +548,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
25581
25582 switch (cmd) {
25583 case DIE_DEBUG:
25584- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
25585+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
25586 if (user_mode(regs))
25587 return single_step_cont(regs, args);
25588 break;
25589@@ -750,11 +753,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25590 #endif /* CONFIG_DEBUG_RODATA */
25591
25592 bpt->type = BP_BREAKPOINT;
25593- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
25594+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
25595 BREAK_INSTR_SIZE);
25596 if (err)
25597 return err;
25598- err = probe_kernel_write((char *)bpt->bpt_addr,
25599+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25600 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
25601 #ifdef CONFIG_DEBUG_RODATA
25602 if (!err)
25603@@ -767,7 +770,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25604 return -EBUSY;
25605 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
25606 BREAK_INSTR_SIZE);
25607- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25608+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25609 if (err)
25610 return err;
25611 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
25612@@ -792,13 +795,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
25613 if (mutex_is_locked(&text_mutex))
25614 goto knl_write;
25615 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
25616- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25617+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25618 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
25619 goto knl_write;
25620 return err;
25621 knl_write:
25622 #endif /* CONFIG_DEBUG_RODATA */
25623- return probe_kernel_write((char *)bpt->bpt_addr,
25624+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25625 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
25626 }
25627
25628diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
25629index 79a3f96..6ba030a 100644
25630--- a/arch/x86/kernel/kprobes/core.c
25631+++ b/arch/x86/kernel/kprobes/core.c
25632@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
25633 s32 raddr;
25634 } __packed *insn;
25635
25636- insn = (struct __arch_relative_insn *)from;
25637+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
25638+
25639+ pax_open_kernel();
25640 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
25641 insn->op = op;
25642+ pax_close_kernel();
25643 }
25644
25645 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
25646@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
25647 kprobe_opcode_t opcode;
25648 kprobe_opcode_t *orig_opcodes = opcodes;
25649
25650- if (search_exception_tables((unsigned long)opcodes))
25651+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
25652 return 0; /* Page fault may occur on this address. */
25653
25654 retry:
25655@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
25656 * for the first byte, we can recover the original instruction
25657 * from it and kp->opcode.
25658 */
25659- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25660+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25661 buf[0] = kp->opcode;
25662- return (unsigned long)buf;
25663+ return ktva_ktla((unsigned long)buf);
25664 }
25665
25666 /*
25667@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25668 /* Another subsystem puts a breakpoint, failed to recover */
25669 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
25670 return 0;
25671+ pax_open_kernel();
25672 memcpy(dest, insn.kaddr, insn.length);
25673+ pax_close_kernel();
25674
25675 #ifdef CONFIG_X86_64
25676 if (insn_rip_relative(&insn)) {
25677@@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25678 return 0;
25679 }
25680 disp = (u8 *) dest + insn_offset_displacement(&insn);
25681+ pax_open_kernel();
25682 *(s32 *) disp = (s32) newdisp;
25683+ pax_close_kernel();
25684 }
25685 #endif
25686 return insn.length;
25687@@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25688 * nor set current_kprobe, because it doesn't use single
25689 * stepping.
25690 */
25691- regs->ip = (unsigned long)p->ainsn.insn;
25692+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25693 preempt_enable_no_resched();
25694 return;
25695 }
25696@@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25697 regs->flags &= ~X86_EFLAGS_IF;
25698 /* single step inline if the instruction is an int3 */
25699 if (p->opcode == BREAKPOINT_INSTRUCTION)
25700- regs->ip = (unsigned long)p->addr;
25701+ regs->ip = ktla_ktva((unsigned long)p->addr);
25702 else
25703- regs->ip = (unsigned long)p->ainsn.insn;
25704+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25705 }
25706
25707 /*
25708@@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
25709 setup_singlestep(p, regs, kcb, 0);
25710 return 1;
25711 }
25712- } else if (*addr != BREAKPOINT_INSTRUCTION) {
25713+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
25714 /*
25715 * The breakpoint instruction was removed right
25716 * after we hit it. Another cpu has removed
25717@@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
25718 " movq %rax, 152(%rsp)\n"
25719 RESTORE_REGS_STRING
25720 " popfq\n"
25721+#ifdef KERNEXEC_PLUGIN
25722+ " btsq $63,(%rsp)\n"
25723+#endif
25724 #else
25725 " pushf\n"
25726 SAVE_REGS_STRING
25727@@ -779,7 +789,7 @@ static void __kprobes
25728 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
25729 {
25730 unsigned long *tos = stack_addr(regs);
25731- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
25732+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
25733 unsigned long orig_ip = (unsigned long)p->addr;
25734 kprobe_opcode_t *insn = p->ainsn.insn;
25735
25736@@ -961,7 +971,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
25737 struct die_args *args = data;
25738 int ret = NOTIFY_DONE;
25739
25740- if (args->regs && user_mode_vm(args->regs))
25741+ if (args->regs && user_mode(args->regs))
25742 return ret;
25743
25744 switch (val) {
25745diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
25746index 898160b..758cde8 100644
25747--- a/arch/x86/kernel/kprobes/opt.c
25748+++ b/arch/x86/kernel/kprobes/opt.c
25749@@ -79,6 +79,7 @@ found:
25750 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
25751 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25752 {
25753+ pax_open_kernel();
25754 #ifdef CONFIG_X86_64
25755 *addr++ = 0x48;
25756 *addr++ = 0xbf;
25757@@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
25758 *addr++ = 0xb8;
25759 #endif
25760 *(unsigned long *)addr = val;
25761+ pax_close_kernel();
25762 }
25763
25764 asm (
25765@@ -335,7 +337,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25766 * Verify if the address gap is in 2GB range, because this uses
25767 * a relative jump.
25768 */
25769- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
25770+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
25771 if (abs(rel) > 0x7fffffff)
25772 return -ERANGE;
25773
25774@@ -350,16 +352,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25775 op->optinsn.size = ret;
25776
25777 /* Copy arch-dep-instance from template */
25778- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
25779+ pax_open_kernel();
25780+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
25781+ pax_close_kernel();
25782
25783 /* Set probe information */
25784 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
25785
25786 /* Set probe function call */
25787- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
25788+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
25789
25790 /* Set returning jmp instruction at the tail of out-of-line buffer */
25791- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
25792+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
25793 (u8 *)op->kp.addr + op->optinsn.size);
25794
25795 flush_icache_range((unsigned long) buf,
25796@@ -384,7 +388,7 @@ void __kprobes arch_optimize_kprobes(struct list_head *oplist)
25797 WARN_ON(kprobe_disabled(&op->kp));
25798
25799 /* Backup instructions which will be replaced by jump address */
25800- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
25801+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
25802 RELATIVE_ADDR_SIZE);
25803
25804 insn_buf[0] = RELATIVEJUMP_OPCODE;
25805@@ -433,7 +437,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
25806 /* This kprobe is really able to run optimized path. */
25807 op = container_of(p, struct optimized_kprobe, kp);
25808 /* Detour through copied instructions */
25809- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
25810+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
25811 if (!reenter)
25812 reset_current_kprobe();
25813 preempt_enable_no_resched();
25814diff --git a/arch/x86/kernel/ksysfs.c b/arch/x86/kernel/ksysfs.c
25815index c2bedae..25e7ab6 100644
25816--- a/arch/x86/kernel/ksysfs.c
25817+++ b/arch/x86/kernel/ksysfs.c
25818@@ -184,7 +184,7 @@ out:
25819
25820 static struct kobj_attribute type_attr = __ATTR_RO(type);
25821
25822-static struct bin_attribute data_attr = {
25823+static bin_attribute_no_const data_attr __read_only = {
25824 .attr = {
25825 .name = "data",
25826 .mode = S_IRUGO,
25827diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
25828index af1d14a..37b8776 100644
25829--- a/arch/x86/kernel/ldt.c
25830+++ b/arch/x86/kernel/ldt.c
25831@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
25832 if (reload) {
25833 #ifdef CONFIG_SMP
25834 preempt_disable();
25835- load_LDT(pc);
25836+ load_LDT_nolock(pc);
25837 if (!cpumask_equal(mm_cpumask(current->mm),
25838 cpumask_of(smp_processor_id())))
25839 smp_call_function(flush_ldt, current->mm, 1);
25840 preempt_enable();
25841 #else
25842- load_LDT(pc);
25843+ load_LDT_nolock(pc);
25844 #endif
25845 }
25846 if (oldsize) {
25847@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
25848 return err;
25849
25850 for (i = 0; i < old->size; i++)
25851- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
25852+ write_ldt_entry(new->ldt, i, old->ldt + i);
25853 return 0;
25854 }
25855
25856@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
25857 retval = copy_ldt(&mm->context, &old_mm->context);
25858 mutex_unlock(&old_mm->context.lock);
25859 }
25860+
25861+ if (tsk == current) {
25862+ mm->context.vdso = 0;
25863+
25864+#ifdef CONFIG_X86_32
25865+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25866+ mm->context.user_cs_base = 0UL;
25867+ mm->context.user_cs_limit = ~0UL;
25868+
25869+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
25870+ cpus_clear(mm->context.cpu_user_cs_mask);
25871+#endif
25872+
25873+#endif
25874+#endif
25875+
25876+ }
25877+
25878 return retval;
25879 }
25880
25881@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
25882 }
25883 }
25884
25885+#ifdef CONFIG_PAX_SEGMEXEC
25886+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
25887+ error = -EINVAL;
25888+ goto out_unlock;
25889+ }
25890+#endif
25891+
25892 /*
25893 * On x86-64 we do not support 16-bit segments due to
25894 * IRET leaking the high bits of the kernel stack address.
25895diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
25896index 1667b1d..16492c5 100644
25897--- a/arch/x86/kernel/machine_kexec_32.c
25898+++ b/arch/x86/kernel/machine_kexec_32.c
25899@@ -25,7 +25,7 @@
25900 #include <asm/cacheflush.h>
25901 #include <asm/debugreg.h>
25902
25903-static void set_idt(void *newidt, __u16 limit)
25904+static void set_idt(struct desc_struct *newidt, __u16 limit)
25905 {
25906 struct desc_ptr curidt;
25907
25908@@ -37,7 +37,7 @@ static void set_idt(void *newidt, __u16 limit)
25909 }
25910
25911
25912-static void set_gdt(void *newgdt, __u16 limit)
25913+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
25914 {
25915 struct desc_ptr curgdt;
25916
25917@@ -215,7 +215,7 @@ void machine_kexec(struct kimage *image)
25918 }
25919
25920 control_page = page_address(image->control_code_page);
25921- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
25922+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
25923
25924 relocate_kernel_ptr = control_page;
25925 page_list[PA_CONTROL_PAGE] = __pa(control_page);
25926diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
25927index 18be189..4a9fe40 100644
25928--- a/arch/x86/kernel/module.c
25929+++ b/arch/x86/kernel/module.c
25930@@ -43,15 +43,60 @@ do { \
25931 } while (0)
25932 #endif
25933
25934-void *module_alloc(unsigned long size)
25935+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
25936 {
25937- if (PAGE_ALIGN(size) > MODULES_LEN)
25938+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
25939 return NULL;
25940 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
25941- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
25942+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
25943 NUMA_NO_NODE, __builtin_return_address(0));
25944 }
25945
25946+void *module_alloc(unsigned long size)
25947+{
25948+
25949+#ifdef CONFIG_PAX_KERNEXEC
25950+ return __module_alloc(size, PAGE_KERNEL);
25951+#else
25952+ return __module_alloc(size, PAGE_KERNEL_EXEC);
25953+#endif
25954+
25955+}
25956+
25957+#ifdef CONFIG_PAX_KERNEXEC
25958+#ifdef CONFIG_X86_32
25959+void *module_alloc_exec(unsigned long size)
25960+{
25961+ struct vm_struct *area;
25962+
25963+ if (size == 0)
25964+ return NULL;
25965+
25966+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
25967+ return area ? area->addr : NULL;
25968+}
25969+EXPORT_SYMBOL(module_alloc_exec);
25970+
25971+void module_free_exec(struct module *mod, void *module_region)
25972+{
25973+ vunmap(module_region);
25974+}
25975+EXPORT_SYMBOL(module_free_exec);
25976+#else
25977+void module_free_exec(struct module *mod, void *module_region)
25978+{
25979+ module_free(mod, module_region);
25980+}
25981+EXPORT_SYMBOL(module_free_exec);
25982+
25983+void *module_alloc_exec(unsigned long size)
25984+{
25985+ return __module_alloc(size, PAGE_KERNEL_RX);
25986+}
25987+EXPORT_SYMBOL(module_alloc_exec);
25988+#endif
25989+#endif
25990+
25991 #ifdef CONFIG_X86_32
25992 int apply_relocate(Elf32_Shdr *sechdrs,
25993 const char *strtab,
25994@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25995 unsigned int i;
25996 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
25997 Elf32_Sym *sym;
25998- uint32_t *location;
25999+ uint32_t *plocation, location;
26000
26001 DEBUGP("Applying relocate section %u to %u\n",
26002 relsec, sechdrs[relsec].sh_info);
26003 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
26004 /* This is where to make the change */
26005- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
26006- + rel[i].r_offset;
26007+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
26008+ location = (uint32_t)plocation;
26009+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
26010+ plocation = ktla_ktva((void *)plocation);
26011 /* This is the symbol it is referring to. Note that all
26012 undefined symbols have been resolved. */
26013 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
26014@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26015 switch (ELF32_R_TYPE(rel[i].r_info)) {
26016 case R_386_32:
26017 /* We add the value into the location given */
26018- *location += sym->st_value;
26019+ pax_open_kernel();
26020+ *plocation += sym->st_value;
26021+ pax_close_kernel();
26022 break;
26023 case R_386_PC32:
26024 /* Add the value, subtract its position */
26025- *location += sym->st_value - (uint32_t)location;
26026+ pax_open_kernel();
26027+ *plocation += sym->st_value - location;
26028+ pax_close_kernel();
26029 break;
26030 default:
26031 pr_err("%s: Unknown relocation: %u\n",
26032@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
26033 case R_X86_64_NONE:
26034 break;
26035 case R_X86_64_64:
26036+ pax_open_kernel();
26037 *(u64 *)loc = val;
26038+ pax_close_kernel();
26039 break;
26040 case R_X86_64_32:
26041+ pax_open_kernel();
26042 *(u32 *)loc = val;
26043+ pax_close_kernel();
26044 if (val != *(u32 *)loc)
26045 goto overflow;
26046 break;
26047 case R_X86_64_32S:
26048+ pax_open_kernel();
26049 *(s32 *)loc = val;
26050+ pax_close_kernel();
26051 if ((s64)val != *(s32 *)loc)
26052 goto overflow;
26053 break;
26054 case R_X86_64_PC32:
26055 val -= (u64)loc;
26056+ pax_open_kernel();
26057 *(u32 *)loc = val;
26058+ pax_close_kernel();
26059+
26060 #if 0
26061 if ((s64)val != *(s32 *)loc)
26062 goto overflow;
26063diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
26064index 05266b5..3432443 100644
26065--- a/arch/x86/kernel/msr.c
26066+++ b/arch/x86/kernel/msr.c
26067@@ -37,6 +37,7 @@
26068 #include <linux/notifier.h>
26069 #include <linux/uaccess.h>
26070 #include <linux/gfp.h>
26071+#include <linux/grsecurity.h>
26072
26073 #include <asm/processor.h>
26074 #include <asm/msr.h>
26075@@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
26076 int err = 0;
26077 ssize_t bytes = 0;
26078
26079+#ifdef CONFIG_GRKERNSEC_KMEM
26080+ gr_handle_msr_write();
26081+ return -EPERM;
26082+#endif
26083+
26084 if (count % 8)
26085 return -EINVAL; /* Invalid chunk size */
26086
26087@@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
26088 err = -EBADF;
26089 break;
26090 }
26091+#ifdef CONFIG_GRKERNSEC_KMEM
26092+ gr_handle_msr_write();
26093+ return -EPERM;
26094+#endif
26095 if (copy_from_user(&regs, uregs, sizeof regs)) {
26096 err = -EFAULT;
26097 break;
26098@@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
26099 return notifier_from_errno(err);
26100 }
26101
26102-static struct notifier_block __refdata msr_class_cpu_notifier = {
26103+static struct notifier_block msr_class_cpu_notifier = {
26104 .notifier_call = msr_class_cpu_callback,
26105 };
26106
26107diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
26108index 6fcb49c..5b3f4ff 100644
26109--- a/arch/x86/kernel/nmi.c
26110+++ b/arch/x86/kernel/nmi.c
26111@@ -138,7 +138,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
26112 return handled;
26113 }
26114
26115-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26116+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
26117 {
26118 struct nmi_desc *desc = nmi_to_desc(type);
26119 unsigned long flags;
26120@@ -162,9 +162,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26121 * event confuses some handlers (kdump uses this flag)
26122 */
26123 if (action->flags & NMI_FLAG_FIRST)
26124- list_add_rcu(&action->list, &desc->head);
26125+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
26126 else
26127- list_add_tail_rcu(&action->list, &desc->head);
26128+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
26129
26130 spin_unlock_irqrestore(&desc->lock, flags);
26131 return 0;
26132@@ -187,7 +187,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
26133 if (!strcmp(n->name, name)) {
26134 WARN(in_nmi(),
26135 "Trying to free NMI (%s) from NMI context!\n", n->name);
26136- list_del_rcu(&n->list);
26137+ pax_list_del_rcu((struct list_head *)&n->list);
26138 break;
26139 }
26140 }
26141@@ -512,6 +512,17 @@ static inline void nmi_nesting_postprocess(void)
26142 dotraplinkage notrace __kprobes void
26143 do_nmi(struct pt_regs *regs, long error_code)
26144 {
26145+
26146+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26147+ if (!user_mode(regs)) {
26148+ unsigned long cs = regs->cs & 0xFFFF;
26149+ unsigned long ip = ktva_ktla(regs->ip);
26150+
26151+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
26152+ regs->ip = ip;
26153+ }
26154+#endif
26155+
26156 nmi_nesting_preprocess(regs);
26157
26158 nmi_enter();
26159diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
26160index 6d9582e..f746287 100644
26161--- a/arch/x86/kernel/nmi_selftest.c
26162+++ b/arch/x86/kernel/nmi_selftest.c
26163@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
26164 {
26165 /* trap all the unknown NMIs we may generate */
26166 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
26167- __initdata);
26168+ __initconst);
26169 }
26170
26171 static void __init cleanup_nmi_testsuite(void)
26172@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
26173 unsigned long timeout;
26174
26175 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
26176- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
26177+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
26178 nmi_fail = FAILURE;
26179 return;
26180 }
26181diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
26182index bbb6c73..24a58ef 100644
26183--- a/arch/x86/kernel/paravirt-spinlocks.c
26184+++ b/arch/x86/kernel/paravirt-spinlocks.c
26185@@ -8,7 +8,7 @@
26186
26187 #include <asm/paravirt.h>
26188
26189-struct pv_lock_ops pv_lock_ops = {
26190+struct pv_lock_ops pv_lock_ops __read_only = {
26191 #ifdef CONFIG_SMP
26192 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
26193 .unlock_kick = paravirt_nop,
26194diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
26195index 1b10af8..0b58cbc 100644
26196--- a/arch/x86/kernel/paravirt.c
26197+++ b/arch/x86/kernel/paravirt.c
26198@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
26199 {
26200 return x;
26201 }
26202+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26203+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
26204+#endif
26205
26206 void __init default_banner(void)
26207 {
26208@@ -142,15 +145,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
26209 if (opfunc == NULL)
26210 /* If there's no function, patch it with a ud2a (BUG) */
26211 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
26212- else if (opfunc == _paravirt_nop)
26213+ else if (opfunc == (void *)_paravirt_nop)
26214 /* If the operation is a nop, then nop the callsite */
26215 ret = paravirt_patch_nop();
26216
26217 /* identity functions just return their single argument */
26218- else if (opfunc == _paravirt_ident_32)
26219+ else if (opfunc == (void *)_paravirt_ident_32)
26220 ret = paravirt_patch_ident_32(insnbuf, len);
26221- else if (opfunc == _paravirt_ident_64)
26222+ else if (opfunc == (void *)_paravirt_ident_64)
26223 ret = paravirt_patch_ident_64(insnbuf, len);
26224+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26225+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
26226+ ret = paravirt_patch_ident_64(insnbuf, len);
26227+#endif
26228
26229 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
26230 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
26231@@ -175,7 +182,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
26232 if (insn_len > len || start == NULL)
26233 insn_len = len;
26234 else
26235- memcpy(insnbuf, start, insn_len);
26236+ memcpy(insnbuf, ktla_ktva(start), insn_len);
26237
26238 return insn_len;
26239 }
26240@@ -299,7 +306,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
26241 return this_cpu_read(paravirt_lazy_mode);
26242 }
26243
26244-struct pv_info pv_info = {
26245+struct pv_info pv_info __read_only = {
26246 .name = "bare hardware",
26247 .paravirt_enabled = 0,
26248 .kernel_rpl = 0,
26249@@ -310,16 +317,16 @@ struct pv_info pv_info = {
26250 #endif
26251 };
26252
26253-struct pv_init_ops pv_init_ops = {
26254+struct pv_init_ops pv_init_ops __read_only = {
26255 .patch = native_patch,
26256 };
26257
26258-struct pv_time_ops pv_time_ops = {
26259+struct pv_time_ops pv_time_ops __read_only = {
26260 .sched_clock = native_sched_clock,
26261 .steal_clock = native_steal_clock,
26262 };
26263
26264-__visible struct pv_irq_ops pv_irq_ops = {
26265+__visible struct pv_irq_ops pv_irq_ops __read_only = {
26266 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
26267 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
26268 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
26269@@ -331,7 +338,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
26270 #endif
26271 };
26272
26273-__visible struct pv_cpu_ops pv_cpu_ops = {
26274+__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
26275 .cpuid = native_cpuid,
26276 .get_debugreg = native_get_debugreg,
26277 .set_debugreg = native_set_debugreg,
26278@@ -389,21 +396,26 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
26279 .end_context_switch = paravirt_nop,
26280 };
26281
26282-struct pv_apic_ops pv_apic_ops = {
26283+struct pv_apic_ops pv_apic_ops __read_only= {
26284 #ifdef CONFIG_X86_LOCAL_APIC
26285 .startup_ipi_hook = paravirt_nop,
26286 #endif
26287 };
26288
26289-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
26290+#ifdef CONFIG_X86_32
26291+#ifdef CONFIG_X86_PAE
26292+/* 64-bit pagetable entries */
26293+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
26294+#else
26295 /* 32-bit pagetable entries */
26296 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
26297+#endif
26298 #else
26299 /* 64-bit pagetable entries */
26300 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
26301 #endif
26302
26303-struct pv_mmu_ops pv_mmu_ops = {
26304+struct pv_mmu_ops pv_mmu_ops __read_only = {
26305
26306 .read_cr2 = native_read_cr2,
26307 .write_cr2 = native_write_cr2,
26308@@ -453,6 +465,7 @@ struct pv_mmu_ops pv_mmu_ops = {
26309 .make_pud = PTE_IDENT,
26310
26311 .set_pgd = native_set_pgd,
26312+ .set_pgd_batched = native_set_pgd_batched,
26313 #endif
26314 #endif /* PAGETABLE_LEVELS >= 3 */
26315
26316@@ -473,6 +486,12 @@ struct pv_mmu_ops pv_mmu_ops = {
26317 },
26318
26319 .set_fixmap = native_set_fixmap,
26320+
26321+#ifdef CONFIG_PAX_KERNEXEC
26322+ .pax_open_kernel = native_pax_open_kernel,
26323+ .pax_close_kernel = native_pax_close_kernel,
26324+#endif
26325+
26326 };
26327
26328 EXPORT_SYMBOL_GPL(pv_time_ops);
26329diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
26330index 299d493..2ccb0ee 100644
26331--- a/arch/x86/kernel/pci-calgary_64.c
26332+++ b/arch/x86/kernel/pci-calgary_64.c
26333@@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
26334 tce_space = be64_to_cpu(readq(target));
26335 tce_space = tce_space & TAR_SW_BITS;
26336
26337- tce_space = tce_space & (~specified_table_size);
26338+ tce_space = tce_space & (~(unsigned long)specified_table_size);
26339 info->tce_space = (u64 *)__va(tce_space);
26340 }
26341 }
26342diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
26343index 35ccf75..7a15747 100644
26344--- a/arch/x86/kernel/pci-iommu_table.c
26345+++ b/arch/x86/kernel/pci-iommu_table.c
26346@@ -2,7 +2,7 @@
26347 #include <asm/iommu_table.h>
26348 #include <linux/string.h>
26349 #include <linux/kallsyms.h>
26350-
26351+#include <linux/sched.h>
26352
26353 #define DEBUG 1
26354
26355diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
26356index 6c483ba..d10ce2f 100644
26357--- a/arch/x86/kernel/pci-swiotlb.c
26358+++ b/arch/x86/kernel/pci-swiotlb.c
26359@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
26360 void *vaddr, dma_addr_t dma_addr,
26361 struct dma_attrs *attrs)
26362 {
26363- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
26364+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
26365 }
26366
26367 static struct dma_map_ops swiotlb_dma_ops = {
26368diff --git a/arch/x86/kernel/preempt.S b/arch/x86/kernel/preempt.S
26369index ca7f0d5..8996469 100644
26370--- a/arch/x86/kernel/preempt.S
26371+++ b/arch/x86/kernel/preempt.S
26372@@ -3,12 +3,14 @@
26373 #include <asm/dwarf2.h>
26374 #include <asm/asm.h>
26375 #include <asm/calling.h>
26376+#include <asm/alternative-asm.h>
26377
26378 ENTRY(___preempt_schedule)
26379 CFI_STARTPROC
26380 SAVE_ALL
26381 call preempt_schedule
26382 RESTORE_ALL
26383+ pax_force_retaddr
26384 ret
26385 CFI_ENDPROC
26386
26387@@ -19,6 +21,7 @@ ENTRY(___preempt_schedule_context)
26388 SAVE_ALL
26389 call preempt_schedule_context
26390 RESTORE_ALL
26391+ pax_force_retaddr
26392 ret
26393 CFI_ENDPROC
26394
26395diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
26396index 3fb8d95..254dc51 100644
26397--- a/arch/x86/kernel/process.c
26398+++ b/arch/x86/kernel/process.c
26399@@ -36,7 +36,8 @@
26400 * section. Since TSS's are completely CPU-local, we want them
26401 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
26402 */
26403-__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
26404+struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
26405+EXPORT_SYMBOL(init_tss);
26406
26407 #ifdef CONFIG_X86_64
26408 static DEFINE_PER_CPU(unsigned char, is_idle);
26409@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
26410 task_xstate_cachep =
26411 kmem_cache_create("task_xstate", xstate_size,
26412 __alignof__(union thread_xstate),
26413- SLAB_PANIC | SLAB_NOTRACK, NULL);
26414+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
26415 }
26416
26417 /*
26418@@ -105,7 +106,7 @@ void exit_thread(void)
26419 unsigned long *bp = t->io_bitmap_ptr;
26420
26421 if (bp) {
26422- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
26423+ struct tss_struct *tss = init_tss + get_cpu();
26424
26425 t->io_bitmap_ptr = NULL;
26426 clear_thread_flag(TIF_IO_BITMAP);
26427@@ -125,6 +126,9 @@ void flush_thread(void)
26428 {
26429 struct task_struct *tsk = current;
26430
26431+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
26432+ loadsegment(gs, 0);
26433+#endif
26434 flush_ptrace_hw_breakpoint(tsk);
26435 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
26436 drop_init_fpu(tsk);
26437@@ -271,7 +275,7 @@ static void __exit_idle(void)
26438 void exit_idle(void)
26439 {
26440 /* idle loop has pid 0 */
26441- if (current->pid)
26442+ if (task_pid_nr(current))
26443 return;
26444 __exit_idle();
26445 }
26446@@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
26447 return ret;
26448 }
26449 #endif
26450-void stop_this_cpu(void *dummy)
26451+__noreturn void stop_this_cpu(void *dummy)
26452 {
26453 local_irq_disable();
26454 /*
26455@@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
26456 }
26457 early_param("idle", idle_setup);
26458
26459-unsigned long arch_align_stack(unsigned long sp)
26460+#ifdef CONFIG_PAX_RANDKSTACK
26461+void pax_randomize_kstack(struct pt_regs *regs)
26462 {
26463- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
26464- sp -= get_random_int() % 8192;
26465- return sp & ~0xf;
26466-}
26467+ struct thread_struct *thread = &current->thread;
26468+ unsigned long time;
26469
26470-unsigned long arch_randomize_brk(struct mm_struct *mm)
26471-{
26472- unsigned long range_end = mm->brk + 0x02000000;
26473- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
26474-}
26475+ if (!randomize_va_space)
26476+ return;
26477+
26478+ if (v8086_mode(regs))
26479+ return;
26480
26481+ rdtscl(time);
26482+
26483+ /* P4 seems to return a 0 LSB, ignore it */
26484+#ifdef CONFIG_MPENTIUM4
26485+ time &= 0x3EUL;
26486+ time <<= 2;
26487+#elif defined(CONFIG_X86_64)
26488+ time &= 0xFUL;
26489+ time <<= 4;
26490+#else
26491+ time &= 0x1FUL;
26492+ time <<= 3;
26493+#endif
26494+
26495+ thread->sp0 ^= time;
26496+ load_sp0(init_tss + smp_processor_id(), thread);
26497+
26498+#ifdef CONFIG_X86_64
26499+ this_cpu_write(kernel_stack, thread->sp0);
26500+#endif
26501+}
26502+#endif
26503diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
26504index 0de43e9..056b840 100644
26505--- a/arch/x86/kernel/process_32.c
26506+++ b/arch/x86/kernel/process_32.c
26507@@ -64,6 +64,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
26508 unsigned long thread_saved_pc(struct task_struct *tsk)
26509 {
26510 return ((unsigned long *)tsk->thread.sp)[3];
26511+//XXX return tsk->thread.eip;
26512 }
26513
26514 void __show_regs(struct pt_regs *regs, int all)
26515@@ -73,19 +74,18 @@ void __show_regs(struct pt_regs *regs, int all)
26516 unsigned long sp;
26517 unsigned short ss, gs;
26518
26519- if (user_mode_vm(regs)) {
26520+ if (user_mode(regs)) {
26521 sp = regs->sp;
26522 ss = regs->ss & 0xffff;
26523- gs = get_user_gs(regs);
26524 } else {
26525 sp = kernel_stack_pointer(regs);
26526 savesegment(ss, ss);
26527- savesegment(gs, gs);
26528 }
26529+ gs = get_user_gs(regs);
26530
26531 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
26532 (u16)regs->cs, regs->ip, regs->flags,
26533- smp_processor_id());
26534+ raw_smp_processor_id());
26535 print_symbol("EIP is at %s\n", regs->ip);
26536
26537 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
26538@@ -132,20 +132,21 @@ void release_thread(struct task_struct *dead_task)
26539 int copy_thread(unsigned long clone_flags, unsigned long sp,
26540 unsigned long arg, struct task_struct *p)
26541 {
26542- struct pt_regs *childregs = task_pt_regs(p);
26543+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
26544 struct task_struct *tsk;
26545 int err;
26546
26547 p->thread.sp = (unsigned long) childregs;
26548 p->thread.sp0 = (unsigned long) (childregs+1);
26549+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26550
26551 if (unlikely(p->flags & PF_KTHREAD)) {
26552 /* kernel thread */
26553 memset(childregs, 0, sizeof(struct pt_regs));
26554 p->thread.ip = (unsigned long) ret_from_kernel_thread;
26555- task_user_gs(p) = __KERNEL_STACK_CANARY;
26556- childregs->ds = __USER_DS;
26557- childregs->es = __USER_DS;
26558+ savesegment(gs, childregs->gs);
26559+ childregs->ds = __KERNEL_DS;
26560+ childregs->es = __KERNEL_DS;
26561 childregs->fs = __KERNEL_PERCPU;
26562 childregs->bx = sp; /* function */
26563 childregs->bp = arg;
26564@@ -252,7 +253,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26565 struct thread_struct *prev = &prev_p->thread,
26566 *next = &next_p->thread;
26567 int cpu = smp_processor_id();
26568- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26569+ struct tss_struct *tss = init_tss + cpu;
26570 fpu_switch_t fpu;
26571
26572 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
26573@@ -276,6 +277,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26574 */
26575 lazy_save_gs(prev->gs);
26576
26577+#ifdef CONFIG_PAX_MEMORY_UDEREF
26578+ __set_fs(task_thread_info(next_p)->addr_limit);
26579+#endif
26580+
26581 /*
26582 * Load the per-thread Thread-Local Storage descriptor.
26583 */
26584@@ -314,6 +319,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26585 */
26586 arch_end_context_switch(next_p);
26587
26588+ this_cpu_write(current_task, next_p);
26589+ this_cpu_write(current_tinfo, &next_p->tinfo);
26590+
26591 /*
26592 * Restore %gs if needed (which is common)
26593 */
26594@@ -322,8 +330,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26595
26596 switch_fpu_finish(next_p, fpu);
26597
26598- this_cpu_write(current_task, next_p);
26599-
26600 return prev_p;
26601 }
26602
26603@@ -353,4 +359,3 @@ unsigned long get_wchan(struct task_struct *p)
26604 } while (count++ < 16);
26605 return 0;
26606 }
26607-
26608diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
26609index 9c0280f..5bbb1c0 100644
26610--- a/arch/x86/kernel/process_64.c
26611+++ b/arch/x86/kernel/process_64.c
26612@@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26613 struct pt_regs *childregs;
26614 struct task_struct *me = current;
26615
26616- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
26617+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
26618 childregs = task_pt_regs(p);
26619 p->thread.sp = (unsigned long) childregs;
26620 p->thread.usersp = me->thread.usersp;
26621+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26622 set_tsk_thread_flag(p, TIF_FORK);
26623 p->thread.fpu_counter = 0;
26624 p->thread.io_bitmap_ptr = NULL;
26625@@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26626 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
26627 savesegment(es, p->thread.es);
26628 savesegment(ds, p->thread.ds);
26629+ savesegment(ss, p->thread.ss);
26630+ BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
26631 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26632
26633 if (unlikely(p->flags & PF_KTHREAD)) {
26634@@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26635 struct thread_struct *prev = &prev_p->thread;
26636 struct thread_struct *next = &next_p->thread;
26637 int cpu = smp_processor_id();
26638- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26639+ struct tss_struct *tss = init_tss + cpu;
26640 unsigned fsindex, gsindex;
26641 fpu_switch_t fpu;
26642
26643@@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26644 if (unlikely(next->ds | prev->ds))
26645 loadsegment(ds, next->ds);
26646
26647+ savesegment(ss, prev->ss);
26648+ if (unlikely(next->ss != prev->ss))
26649+ loadsegment(ss, next->ss);
26650
26651 /* We must save %fs and %gs before load_TLS() because
26652 * %fs and %gs may be cleared by load_TLS().
26653@@ -362,6 +368,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26654 prev->usersp = this_cpu_read(old_rsp);
26655 this_cpu_write(old_rsp, next->usersp);
26656 this_cpu_write(current_task, next_p);
26657+ this_cpu_write(current_tinfo, &next_p->tinfo);
26658
26659 /*
26660 * If it were not for PREEMPT_ACTIVE we could guarantee that the
26661@@ -371,9 +378,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26662 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
26663 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
26664
26665- this_cpu_write(kernel_stack,
26666- (unsigned long)task_stack_page(next_p) +
26667- THREAD_SIZE - KERNEL_STACK_OFFSET);
26668+ this_cpu_write(kernel_stack, next->sp0);
26669
26670 /*
26671 * Now maybe reload the debug registers and handle I/O bitmaps
26672@@ -442,12 +447,11 @@ unsigned long get_wchan(struct task_struct *p)
26673 if (!p || p == current || p->state == TASK_RUNNING)
26674 return 0;
26675 stack = (unsigned long)task_stack_page(p);
26676- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
26677+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
26678 return 0;
26679 fp = *(u64 *)(p->thread.sp);
26680 do {
26681- if (fp < (unsigned long)stack ||
26682- fp >= (unsigned long)stack+THREAD_SIZE)
26683+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
26684 return 0;
26685 ip = *(u64 *)(fp+8);
26686 if (!in_sched_functions(ip))
26687diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
26688index 7461f50..1334029 100644
26689--- a/arch/x86/kernel/ptrace.c
26690+++ b/arch/x86/kernel/ptrace.c
26691@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
26692 {
26693 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
26694 unsigned long sp = (unsigned long)&regs->sp;
26695- struct thread_info *tinfo;
26696
26697- if (context == (sp & ~(THREAD_SIZE - 1)))
26698+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
26699 return sp;
26700
26701- tinfo = (struct thread_info *)context;
26702- if (tinfo->previous_esp)
26703- return tinfo->previous_esp;
26704+ sp = *(unsigned long *)context;
26705+ if (sp)
26706+ return sp;
26707
26708 return (unsigned long)regs;
26709 }
26710@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
26711 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
26712 {
26713 int i;
26714- int dr7 = 0;
26715+ unsigned long dr7 = 0;
26716 struct arch_hw_breakpoint *info;
26717
26718 for (i = 0; i < HBP_NUM; i++) {
26719@@ -822,7 +821,7 @@ long arch_ptrace(struct task_struct *child, long request,
26720 unsigned long addr, unsigned long data)
26721 {
26722 int ret;
26723- unsigned long __user *datap = (unsigned long __user *)data;
26724+ unsigned long __user *datap = (__force unsigned long __user *)data;
26725
26726 switch (request) {
26727 /* read the word at location addr in the USER area. */
26728@@ -907,14 +906,14 @@ long arch_ptrace(struct task_struct *child, long request,
26729 if ((int) addr < 0)
26730 return -EIO;
26731 ret = do_get_thread_area(child, addr,
26732- (struct user_desc __user *)data);
26733+ (__force struct user_desc __user *) data);
26734 break;
26735
26736 case PTRACE_SET_THREAD_AREA:
26737 if ((int) addr < 0)
26738 return -EIO;
26739 ret = do_set_thread_area(child, addr,
26740- (struct user_desc __user *)data, 0);
26741+ (__force struct user_desc __user *) data, 0);
26742 break;
26743 #endif
26744
26745@@ -1292,7 +1291,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
26746
26747 #ifdef CONFIG_X86_64
26748
26749-static struct user_regset x86_64_regsets[] __read_mostly = {
26750+static user_regset_no_const x86_64_regsets[] __read_only = {
26751 [REGSET_GENERAL] = {
26752 .core_note_type = NT_PRSTATUS,
26753 .n = sizeof(struct user_regs_struct) / sizeof(long),
26754@@ -1333,7 +1332,7 @@ static const struct user_regset_view user_x86_64_view = {
26755 #endif /* CONFIG_X86_64 */
26756
26757 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
26758-static struct user_regset x86_32_regsets[] __read_mostly = {
26759+static user_regset_no_const x86_32_regsets[] __read_only = {
26760 [REGSET_GENERAL] = {
26761 .core_note_type = NT_PRSTATUS,
26762 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
26763@@ -1386,7 +1385,7 @@ static const struct user_regset_view user_x86_32_view = {
26764 */
26765 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
26766
26767-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26768+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26769 {
26770 #ifdef CONFIG_X86_64
26771 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
26772@@ -1421,7 +1420,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
26773 memset(info, 0, sizeof(*info));
26774 info->si_signo = SIGTRAP;
26775 info->si_code = si_code;
26776- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
26777+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
26778 }
26779
26780 void user_single_step_siginfo(struct task_struct *tsk,
26781@@ -1450,6 +1449,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
26782 # define IS_IA32 0
26783 #endif
26784
26785+#ifdef CONFIG_GRKERNSEC_SETXID
26786+extern void gr_delayed_cred_worker(void);
26787+#endif
26788+
26789 /*
26790 * We must return the syscall number to actually look up in the table.
26791 * This can be -1L to skip running any syscall at all.
26792@@ -1460,6 +1463,11 @@ long syscall_trace_enter(struct pt_regs *regs)
26793
26794 user_exit();
26795
26796+#ifdef CONFIG_GRKERNSEC_SETXID
26797+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26798+ gr_delayed_cred_worker();
26799+#endif
26800+
26801 /*
26802 * If we stepped into a sysenter/syscall insn, it trapped in
26803 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
26804@@ -1515,6 +1523,11 @@ void syscall_trace_leave(struct pt_regs *regs)
26805 */
26806 user_exit();
26807
26808+#ifdef CONFIG_GRKERNSEC_SETXID
26809+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26810+ gr_delayed_cred_worker();
26811+#endif
26812+
26813 audit_syscall_exit(regs);
26814
26815 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
26816diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
26817index 2f355d2..e75ed0a 100644
26818--- a/arch/x86/kernel/pvclock.c
26819+++ b/arch/x86/kernel/pvclock.c
26820@@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
26821 reset_hung_task_detector();
26822 }
26823
26824-static atomic64_t last_value = ATOMIC64_INIT(0);
26825+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
26826
26827 void pvclock_resume(void)
26828 {
26829- atomic64_set(&last_value, 0);
26830+ atomic64_set_unchecked(&last_value, 0);
26831 }
26832
26833 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
26834@@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
26835 * updating at the same time, and one of them could be slightly behind,
26836 * making the assumption that last_value always go forward fail to hold.
26837 */
26838- last = atomic64_read(&last_value);
26839+ last = atomic64_read_unchecked(&last_value);
26840 do {
26841 if (ret < last)
26842 return last;
26843- last = atomic64_cmpxchg(&last_value, last, ret);
26844+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
26845 } while (unlikely(last != ret));
26846
26847 return ret;
26848diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
26849index c752cb4..866c432 100644
26850--- a/arch/x86/kernel/reboot.c
26851+++ b/arch/x86/kernel/reboot.c
26852@@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
26853
26854 void __noreturn machine_real_restart(unsigned int type)
26855 {
26856+
26857+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
26858+ struct desc_struct *gdt;
26859+#endif
26860+
26861 local_irq_disable();
26862
26863 /*
26864@@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
26865
26866 /* Jump to the identity-mapped low memory code */
26867 #ifdef CONFIG_X86_32
26868- asm volatile("jmpl *%0" : :
26869+
26870+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
26871+ gdt = get_cpu_gdt_table(smp_processor_id());
26872+ pax_open_kernel();
26873+#ifdef CONFIG_PAX_MEMORY_UDEREF
26874+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
26875+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
26876+ loadsegment(ds, __KERNEL_DS);
26877+ loadsegment(es, __KERNEL_DS);
26878+ loadsegment(ss, __KERNEL_DS);
26879+#endif
26880+#ifdef CONFIG_PAX_KERNEXEC
26881+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
26882+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
26883+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
26884+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
26885+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
26886+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
26887+#endif
26888+ pax_close_kernel();
26889+#endif
26890+
26891+ asm volatile("ljmpl *%0" : :
26892 "rm" (real_mode_header->machine_real_restart_asm),
26893 "a" (type));
26894 #else
26895@@ -470,7 +497,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
26896 * try to force a triple fault and then cycle between hitting the keyboard
26897 * controller and doing that
26898 */
26899-static void native_machine_emergency_restart(void)
26900+static void __noreturn native_machine_emergency_restart(void)
26901 {
26902 int i;
26903 int attempt = 0;
26904@@ -593,13 +620,13 @@ void native_machine_shutdown(void)
26905 #endif
26906 }
26907
26908-static void __machine_emergency_restart(int emergency)
26909+static void __noreturn __machine_emergency_restart(int emergency)
26910 {
26911 reboot_emergency = emergency;
26912 machine_ops.emergency_restart();
26913 }
26914
26915-static void native_machine_restart(char *__unused)
26916+static void __noreturn native_machine_restart(char *__unused)
26917 {
26918 pr_notice("machine restart\n");
26919
26920@@ -608,7 +635,7 @@ static void native_machine_restart(char *__unused)
26921 __machine_emergency_restart(0);
26922 }
26923
26924-static void native_machine_halt(void)
26925+static void __noreturn native_machine_halt(void)
26926 {
26927 /* Stop other cpus and apics */
26928 machine_shutdown();
26929@@ -618,7 +645,7 @@ static void native_machine_halt(void)
26930 stop_this_cpu(NULL);
26931 }
26932
26933-static void native_machine_power_off(void)
26934+static void __noreturn native_machine_power_off(void)
26935 {
26936 if (pm_power_off) {
26937 if (!reboot_force)
26938@@ -627,9 +654,10 @@ static void native_machine_power_off(void)
26939 }
26940 /* A fallback in case there is no PM info available */
26941 tboot_shutdown(TB_SHUTDOWN_HALT);
26942+ unreachable();
26943 }
26944
26945-struct machine_ops machine_ops = {
26946+struct machine_ops machine_ops __read_only = {
26947 .power_off = native_machine_power_off,
26948 .shutdown = native_machine_shutdown,
26949 .emergency_restart = native_machine_emergency_restart,
26950diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
26951index c8e41e9..64049ef 100644
26952--- a/arch/x86/kernel/reboot_fixups_32.c
26953+++ b/arch/x86/kernel/reboot_fixups_32.c
26954@@ -57,7 +57,7 @@ struct device_fixup {
26955 unsigned int vendor;
26956 unsigned int device;
26957 void (*reboot_fixup)(struct pci_dev *);
26958-};
26959+} __do_const;
26960
26961 /*
26962 * PCI ids solely used for fixups_table go here
26963diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
26964index 3fd2c69..a444264 100644
26965--- a/arch/x86/kernel/relocate_kernel_64.S
26966+++ b/arch/x86/kernel/relocate_kernel_64.S
26967@@ -96,8 +96,7 @@ relocate_kernel:
26968
26969 /* jump to identity mapped page */
26970 addq $(identity_mapped - relocate_kernel), %r8
26971- pushq %r8
26972- ret
26973+ jmp *%r8
26974
26975 identity_mapped:
26976 /* set return address to 0 if not preserving context */
26977diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
26978index ce72964..be8aea7 100644
26979--- a/arch/x86/kernel/setup.c
26980+++ b/arch/x86/kernel/setup.c
26981@@ -110,6 +110,7 @@
26982 #include <asm/mce.h>
26983 #include <asm/alternative.h>
26984 #include <asm/prom.h>
26985+#include <asm/boot.h>
26986
26987 /*
26988 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
26989@@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
26990 #endif
26991
26992
26993-#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
26994-__visible unsigned long mmu_cr4_features;
26995+#ifdef CONFIG_X86_64
26996+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
26997+#elif defined(CONFIG_X86_PAE)
26998+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
26999 #else
27000-__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
27001+__visible unsigned long mmu_cr4_features __read_only;
27002 #endif
27003
27004+void set_in_cr4(unsigned long mask)
27005+{
27006+ unsigned long cr4 = read_cr4();
27007+
27008+ if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
27009+ return;
27010+
27011+ pax_open_kernel();
27012+ mmu_cr4_features |= mask;
27013+ pax_close_kernel();
27014+
27015+ if (trampoline_cr4_features)
27016+ *trampoline_cr4_features = mmu_cr4_features;
27017+ cr4 |= mask;
27018+ write_cr4(cr4);
27019+}
27020+EXPORT_SYMBOL(set_in_cr4);
27021+
27022+void clear_in_cr4(unsigned long mask)
27023+{
27024+ unsigned long cr4 = read_cr4();
27025+
27026+ if (!(cr4 & mask) && cr4 == mmu_cr4_features)
27027+ return;
27028+
27029+ pax_open_kernel();
27030+ mmu_cr4_features &= ~mask;
27031+ pax_close_kernel();
27032+
27033+ if (trampoline_cr4_features)
27034+ *trampoline_cr4_features = mmu_cr4_features;
27035+ cr4 &= ~mask;
27036+ write_cr4(cr4);
27037+}
27038+EXPORT_SYMBOL(clear_in_cr4);
27039+
27040 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
27041 int bootloader_type, bootloader_version;
27042
27043@@ -772,7 +811,7 @@ static void __init trim_bios_range(void)
27044 * area (640->1Mb) as ram even though it is not.
27045 * take them out.
27046 */
27047- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
27048+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
27049
27050 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
27051 }
27052@@ -780,7 +819,7 @@ static void __init trim_bios_range(void)
27053 /* called before trim_bios_range() to spare extra sanitize */
27054 static void __init e820_add_kernel_range(void)
27055 {
27056- u64 start = __pa_symbol(_text);
27057+ u64 start = __pa_symbol(ktla_ktva(_text));
27058 u64 size = __pa_symbol(_end) - start;
27059
27060 /*
27061@@ -856,8 +895,12 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
27062
27063 void __init setup_arch(char **cmdline_p)
27064 {
27065+#ifdef CONFIG_X86_32
27066+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
27067+#else
27068 memblock_reserve(__pa_symbol(_text),
27069 (unsigned long)__bss_stop - (unsigned long)_text);
27070+#endif
27071
27072 early_reserve_initrd();
27073
27074@@ -947,14 +990,14 @@ void __init setup_arch(char **cmdline_p)
27075
27076 if (!boot_params.hdr.root_flags)
27077 root_mountflags &= ~MS_RDONLY;
27078- init_mm.start_code = (unsigned long) _text;
27079- init_mm.end_code = (unsigned long) _etext;
27080+ init_mm.start_code = ktla_ktva((unsigned long) _text);
27081+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
27082 init_mm.end_data = (unsigned long) _edata;
27083 init_mm.brk = _brk_end;
27084
27085- code_resource.start = __pa_symbol(_text);
27086- code_resource.end = __pa_symbol(_etext)-1;
27087- data_resource.start = __pa_symbol(_etext);
27088+ code_resource.start = __pa_symbol(ktla_ktva(_text));
27089+ code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
27090+ data_resource.start = __pa_symbol(_sdata);
27091 data_resource.end = __pa_symbol(_edata)-1;
27092 bss_resource.start = __pa_symbol(__bss_start);
27093 bss_resource.end = __pa_symbol(__bss_stop)-1;
27094diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
27095index 5cdff03..80fa283 100644
27096--- a/arch/x86/kernel/setup_percpu.c
27097+++ b/arch/x86/kernel/setup_percpu.c
27098@@ -21,19 +21,17 @@
27099 #include <asm/cpu.h>
27100 #include <asm/stackprotector.h>
27101
27102-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
27103+#ifdef CONFIG_SMP
27104+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
27105 EXPORT_PER_CPU_SYMBOL(cpu_number);
27106+#endif
27107
27108-#ifdef CONFIG_X86_64
27109 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
27110-#else
27111-#define BOOT_PERCPU_OFFSET 0
27112-#endif
27113
27114 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
27115 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
27116
27117-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
27118+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
27119 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
27120 };
27121 EXPORT_SYMBOL(__per_cpu_offset);
27122@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
27123 {
27124 #ifdef CONFIG_NEED_MULTIPLE_NODES
27125 pg_data_t *last = NULL;
27126- unsigned int cpu;
27127+ int cpu;
27128
27129 for_each_possible_cpu(cpu) {
27130 int node = early_cpu_to_node(cpu);
27131@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
27132 {
27133 #ifdef CONFIG_X86_32
27134 struct desc_struct gdt;
27135+ unsigned long base = per_cpu_offset(cpu);
27136
27137- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
27138- 0x2 | DESCTYPE_S, 0x8);
27139- gdt.s = 1;
27140+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
27141+ 0x83 | DESCTYPE_S, 0xC);
27142 write_gdt_entry(get_cpu_gdt_table(cpu),
27143 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
27144 #endif
27145@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
27146 /* alrighty, percpu areas up and running */
27147 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
27148 for_each_possible_cpu(cpu) {
27149+#ifdef CONFIG_CC_STACKPROTECTOR
27150+#ifdef CONFIG_X86_32
27151+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
27152+#endif
27153+#endif
27154 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
27155 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
27156 per_cpu(cpu_number, cpu) = cpu;
27157@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
27158 */
27159 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
27160 #endif
27161+#ifdef CONFIG_CC_STACKPROTECTOR
27162+#ifdef CONFIG_X86_32
27163+ if (!cpu)
27164+ per_cpu(stack_canary.canary, cpu) = canary;
27165+#endif
27166+#endif
27167 /*
27168 * Up to this point, the boot CPU has been using .init.data
27169 * area. Reload any changed state for the boot CPU.
27170diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
27171index 9e5de68..16c53cb 100644
27172--- a/arch/x86/kernel/signal.c
27173+++ b/arch/x86/kernel/signal.c
27174@@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
27175 * Align the stack pointer according to the i386 ABI,
27176 * i.e. so that on function entry ((sp + 4) & 15) == 0.
27177 */
27178- sp = ((sp + 4) & -16ul) - 4;
27179+ sp = ((sp - 12) & -16ul) - 4;
27180 #else /* !CONFIG_X86_32 */
27181 sp = round_down(sp, 16) - 8;
27182 #endif
27183@@ -298,9 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
27184 }
27185
27186 if (current->mm->context.vdso)
27187- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
27188+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
27189 else
27190- restorer = &frame->retcode;
27191+ restorer = (void __user *)&frame->retcode;
27192 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27193 restorer = ksig->ka.sa.sa_restorer;
27194
27195@@ -314,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
27196 * reasons and because gdb uses it as a signature to notice
27197 * signal handler stack frames.
27198 */
27199- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
27200+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
27201
27202 if (err)
27203 return -EFAULT;
27204@@ -361,7 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27205 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
27206
27207 /* Set up to return from userspace. */
27208- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
27209+ if (current->mm->context.vdso)
27210+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
27211+ else
27212+ restorer = (void __user *)&frame->retcode;
27213 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27214 restorer = ksig->ka.sa.sa_restorer;
27215 put_user_ex(restorer, &frame->pretcode);
27216@@ -373,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27217 * reasons and because gdb uses it as a signature to notice
27218 * signal handler stack frames.
27219 */
27220- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
27221+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
27222 } put_user_catch(err);
27223
27224 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
27225@@ -609,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27226 {
27227 int usig = signr_convert(ksig->sig);
27228 sigset_t *set = sigmask_to_save();
27229- compat_sigset_t *cset = (compat_sigset_t *) set;
27230+ sigset_t sigcopy;
27231+ compat_sigset_t *cset;
27232+
27233+ sigcopy = *set;
27234+
27235+ cset = (compat_sigset_t *) &sigcopy;
27236
27237 /* Set up the stack frame */
27238 if (is_ia32_frame()) {
27239@@ -620,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27240 } else if (is_x32_frame()) {
27241 return x32_setup_rt_frame(ksig, cset, regs);
27242 } else {
27243- return __setup_rt_frame(ksig->sig, ksig, set, regs);
27244+ return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
27245 }
27246 }
27247
27248diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
27249index 7c3a5a6..f0a8961 100644
27250--- a/arch/x86/kernel/smp.c
27251+++ b/arch/x86/kernel/smp.c
27252@@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
27253
27254 __setup("nonmi_ipi", nonmi_ipi_setup);
27255
27256-struct smp_ops smp_ops = {
27257+struct smp_ops smp_ops __read_only = {
27258 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
27259 .smp_prepare_cpus = native_smp_prepare_cpus,
27260 .smp_cpus_done = native_smp_cpus_done,
27261diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
27262index a32da80..30c97f1 100644
27263--- a/arch/x86/kernel/smpboot.c
27264+++ b/arch/x86/kernel/smpboot.c
27265@@ -229,14 +229,18 @@ static void notrace start_secondary(void *unused)
27266
27267 enable_start_cpu0 = 0;
27268
27269-#ifdef CONFIG_X86_32
27270- /* switch away from the initial page table */
27271- load_cr3(swapper_pg_dir);
27272- __flush_tlb_all();
27273-#endif
27274-
27275 /* otherwise gcc will move up smp_processor_id before the cpu_init */
27276 barrier();
27277+
27278+ /* switch away from the initial page table */
27279+#ifdef CONFIG_PAX_PER_CPU_PGD
27280+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
27281+ __flush_tlb_all();
27282+#elif defined(CONFIG_X86_32)
27283+ load_cr3(swapper_pg_dir);
27284+ __flush_tlb_all();
27285+#endif
27286+
27287 /*
27288 * Check TSC synchronization with the BP:
27289 */
27290@@ -749,8 +753,9 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27291 alternatives_enable_smp();
27292
27293 idle->thread.sp = (unsigned long) (((struct pt_regs *)
27294- (THREAD_SIZE + task_stack_page(idle))) - 1);
27295+ (THREAD_SIZE - 16 + task_stack_page(idle))) - 1);
27296 per_cpu(current_task, cpu) = idle;
27297+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
27298
27299 #ifdef CONFIG_X86_32
27300 /* Stack for startup_32 can be just as for start_secondary onwards */
27301@@ -758,11 +763,13 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27302 #else
27303 clear_tsk_thread_flag(idle, TIF_FORK);
27304 initial_gs = per_cpu_offset(cpu);
27305- per_cpu(kernel_stack, cpu) =
27306- (unsigned long)task_stack_page(idle) -
27307- KERNEL_STACK_OFFSET + THREAD_SIZE;
27308+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27309 #endif
27310+
27311+ pax_open_kernel();
27312 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
27313+ pax_close_kernel();
27314+
27315 initial_code = (unsigned long)start_secondary;
27316 stack_start = idle->thread.sp;
27317
27318@@ -911,6 +918,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
27319 /* the FPU context is blank, nobody can own it */
27320 __cpu_disable_lazy_restore(cpu);
27321
27322+#ifdef CONFIG_PAX_PER_CPU_PGD
27323+ clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
27324+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27325+ KERNEL_PGD_PTRS);
27326+ clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
27327+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27328+ KERNEL_PGD_PTRS);
27329+#endif
27330+
27331 err = do_boot_cpu(apicid, cpu, tidle);
27332 if (err) {
27333 pr_debug("do_boot_cpu failed %d\n", err);
27334diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
27335index 9b4d51d..5d28b58 100644
27336--- a/arch/x86/kernel/step.c
27337+++ b/arch/x86/kernel/step.c
27338@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27339 struct desc_struct *desc;
27340 unsigned long base;
27341
27342- seg &= ~7UL;
27343+ seg >>= 3;
27344
27345 mutex_lock(&child->mm->context.lock);
27346- if (unlikely((seg >> 3) >= child->mm->context.size))
27347+ if (unlikely(seg >= child->mm->context.size))
27348 addr = -1L; /* bogus selector, access would fault */
27349 else {
27350 desc = child->mm->context.ldt + seg;
27351@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27352 addr += base;
27353 }
27354 mutex_unlock(&child->mm->context.lock);
27355- }
27356+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
27357+ addr = ktla_ktva(addr);
27358
27359 return addr;
27360 }
27361@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
27362 unsigned char opcode[15];
27363 unsigned long addr = convert_ip_to_linear(child, regs);
27364
27365+ if (addr == -EINVAL)
27366+ return 0;
27367+
27368 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
27369 for (i = 0; i < copied; i++) {
27370 switch (opcode[i]) {
27371diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
27372new file mode 100644
27373index 0000000..5877189
27374--- /dev/null
27375+++ b/arch/x86/kernel/sys_i386_32.c
27376@@ -0,0 +1,189 @@
27377+/*
27378+ * This file contains various random system calls that
27379+ * have a non-standard calling sequence on the Linux/i386
27380+ * platform.
27381+ */
27382+
27383+#include <linux/errno.h>
27384+#include <linux/sched.h>
27385+#include <linux/mm.h>
27386+#include <linux/fs.h>
27387+#include <linux/smp.h>
27388+#include <linux/sem.h>
27389+#include <linux/msg.h>
27390+#include <linux/shm.h>
27391+#include <linux/stat.h>
27392+#include <linux/syscalls.h>
27393+#include <linux/mman.h>
27394+#include <linux/file.h>
27395+#include <linux/utsname.h>
27396+#include <linux/ipc.h>
27397+#include <linux/elf.h>
27398+
27399+#include <linux/uaccess.h>
27400+#include <linux/unistd.h>
27401+
27402+#include <asm/syscalls.h>
27403+
27404+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
27405+{
27406+ unsigned long pax_task_size = TASK_SIZE;
27407+
27408+#ifdef CONFIG_PAX_SEGMEXEC
27409+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
27410+ pax_task_size = SEGMEXEC_TASK_SIZE;
27411+#endif
27412+
27413+ if (flags & MAP_FIXED)
27414+ if (len > pax_task_size || addr > pax_task_size - len)
27415+ return -EINVAL;
27416+
27417+ return 0;
27418+}
27419+
27420+/*
27421+ * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
27422+ */
27423+static unsigned long get_align_mask(void)
27424+{
27425+ if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
27426+ return 0;
27427+
27428+ if (!(current->flags & PF_RANDOMIZE))
27429+ return 0;
27430+
27431+ return va_align.mask;
27432+}
27433+
27434+unsigned long
27435+arch_get_unmapped_area(struct file *filp, unsigned long addr,
27436+ unsigned long len, unsigned long pgoff, unsigned long flags)
27437+{
27438+ struct mm_struct *mm = current->mm;
27439+ struct vm_area_struct *vma;
27440+ unsigned long pax_task_size = TASK_SIZE;
27441+ struct vm_unmapped_area_info info;
27442+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27443+
27444+#ifdef CONFIG_PAX_SEGMEXEC
27445+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27446+ pax_task_size = SEGMEXEC_TASK_SIZE;
27447+#endif
27448+
27449+ pax_task_size -= PAGE_SIZE;
27450+
27451+ if (len > pax_task_size)
27452+ return -ENOMEM;
27453+
27454+ if (flags & MAP_FIXED)
27455+ return addr;
27456+
27457+#ifdef CONFIG_PAX_RANDMMAP
27458+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27459+#endif
27460+
27461+ if (addr) {
27462+ addr = PAGE_ALIGN(addr);
27463+ if (pax_task_size - len >= addr) {
27464+ vma = find_vma(mm, addr);
27465+ if (check_heap_stack_gap(vma, addr, len, offset))
27466+ return addr;
27467+ }
27468+ }
27469+
27470+ info.flags = 0;
27471+ info.length = len;
27472+ info.align_mask = filp ? get_align_mask() : 0;
27473+ info.align_offset = pgoff << PAGE_SHIFT;
27474+ info.threadstack_offset = offset;
27475+
27476+#ifdef CONFIG_PAX_PAGEEXEC
27477+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
27478+ info.low_limit = 0x00110000UL;
27479+ info.high_limit = mm->start_code;
27480+
27481+#ifdef CONFIG_PAX_RANDMMAP
27482+ if (mm->pax_flags & MF_PAX_RANDMMAP)
27483+ info.low_limit += mm->delta_mmap & 0x03FFF000UL;
27484+#endif
27485+
27486+ if (info.low_limit < info.high_limit) {
27487+ addr = vm_unmapped_area(&info);
27488+ if (!IS_ERR_VALUE(addr))
27489+ return addr;
27490+ }
27491+ } else
27492+#endif
27493+
27494+ info.low_limit = mm->mmap_base;
27495+ info.high_limit = pax_task_size;
27496+
27497+ return vm_unmapped_area(&info);
27498+}
27499+
27500+unsigned long
27501+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27502+ const unsigned long len, const unsigned long pgoff,
27503+ const unsigned long flags)
27504+{
27505+ struct vm_area_struct *vma;
27506+ struct mm_struct *mm = current->mm;
27507+ unsigned long addr = addr0, pax_task_size = TASK_SIZE;
27508+ struct vm_unmapped_area_info info;
27509+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27510+
27511+#ifdef CONFIG_PAX_SEGMEXEC
27512+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27513+ pax_task_size = SEGMEXEC_TASK_SIZE;
27514+#endif
27515+
27516+ pax_task_size -= PAGE_SIZE;
27517+
27518+ /* requested length too big for entire address space */
27519+ if (len > pax_task_size)
27520+ return -ENOMEM;
27521+
27522+ if (flags & MAP_FIXED)
27523+ return addr;
27524+
27525+#ifdef CONFIG_PAX_PAGEEXEC
27526+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
27527+ goto bottomup;
27528+#endif
27529+
27530+#ifdef CONFIG_PAX_RANDMMAP
27531+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27532+#endif
27533+
27534+ /* requesting a specific address */
27535+ if (addr) {
27536+ addr = PAGE_ALIGN(addr);
27537+ if (pax_task_size - len >= addr) {
27538+ vma = find_vma(mm, addr);
27539+ if (check_heap_stack_gap(vma, addr, len, offset))
27540+ return addr;
27541+ }
27542+ }
27543+
27544+ info.flags = VM_UNMAPPED_AREA_TOPDOWN;
27545+ info.length = len;
27546+ info.low_limit = PAGE_SIZE;
27547+ info.high_limit = mm->mmap_base;
27548+ info.align_mask = filp ? get_align_mask() : 0;
27549+ info.align_offset = pgoff << PAGE_SHIFT;
27550+ info.threadstack_offset = offset;
27551+
27552+ addr = vm_unmapped_area(&info);
27553+ if (!(addr & ~PAGE_MASK))
27554+ return addr;
27555+ VM_BUG_ON(addr != -ENOMEM);
27556+
27557+bottomup:
27558+ /*
27559+ * A failed mmap() very likely causes application failure,
27560+ * so fall back to the bottom-up function here. This scenario
27561+ * can happen with large stack limits and large mmap()
27562+ * allocations.
27563+ */
27564+ return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
27565+}
27566diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
27567index 30277e2..5664a29 100644
27568--- a/arch/x86/kernel/sys_x86_64.c
27569+++ b/arch/x86/kernel/sys_x86_64.c
27570@@ -81,8 +81,8 @@ out:
27571 return error;
27572 }
27573
27574-static void find_start_end(unsigned long flags, unsigned long *begin,
27575- unsigned long *end)
27576+static void find_start_end(struct mm_struct *mm, unsigned long flags,
27577+ unsigned long *begin, unsigned long *end)
27578 {
27579 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
27580 unsigned long new_begin;
27581@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
27582 *begin = new_begin;
27583 }
27584 } else {
27585- *begin = current->mm->mmap_legacy_base;
27586+ *begin = mm->mmap_legacy_base;
27587 *end = TASK_SIZE;
27588 }
27589 }
27590@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27591 struct vm_area_struct *vma;
27592 struct vm_unmapped_area_info info;
27593 unsigned long begin, end;
27594+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27595
27596 if (flags & MAP_FIXED)
27597 return addr;
27598
27599- find_start_end(flags, &begin, &end);
27600+ find_start_end(mm, flags, &begin, &end);
27601
27602 if (len > end)
27603 return -ENOMEM;
27604
27605+#ifdef CONFIG_PAX_RANDMMAP
27606+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27607+#endif
27608+
27609 if (addr) {
27610 addr = PAGE_ALIGN(addr);
27611 vma = find_vma(mm, addr);
27612- if (end - len >= addr &&
27613- (!vma || addr + len <= vma->vm_start))
27614+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27615 return addr;
27616 }
27617
27618@@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27619 info.high_limit = end;
27620 info.align_mask = filp ? get_align_mask() : 0;
27621 info.align_offset = pgoff << PAGE_SHIFT;
27622+ info.threadstack_offset = offset;
27623 return vm_unmapped_area(&info);
27624 }
27625
27626@@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27627 struct mm_struct *mm = current->mm;
27628 unsigned long addr = addr0;
27629 struct vm_unmapped_area_info info;
27630+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27631
27632 /* requested length too big for entire address space */
27633 if (len > TASK_SIZE)
27634@@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27635 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
27636 goto bottomup;
27637
27638+#ifdef CONFIG_PAX_RANDMMAP
27639+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27640+#endif
27641+
27642 /* requesting a specific address */
27643 if (addr) {
27644 addr = PAGE_ALIGN(addr);
27645 vma = find_vma(mm, addr);
27646- if (TASK_SIZE - len >= addr &&
27647- (!vma || addr + len <= vma->vm_start))
27648+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27649 return addr;
27650 }
27651
27652@@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27653 info.high_limit = mm->mmap_base;
27654 info.align_mask = filp ? get_align_mask() : 0;
27655 info.align_offset = pgoff << PAGE_SHIFT;
27656+ info.threadstack_offset = offset;
27657 addr = vm_unmapped_area(&info);
27658 if (!(addr & ~PAGE_MASK))
27659 return addr;
27660diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
27661index 91a4496..bb87552 100644
27662--- a/arch/x86/kernel/tboot.c
27663+++ b/arch/x86/kernel/tboot.c
27664@@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
27665
27666 void tboot_shutdown(u32 shutdown_type)
27667 {
27668- void (*shutdown)(void);
27669+ void (* __noreturn shutdown)(void);
27670
27671 if (!tboot_enabled())
27672 return;
27673@@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
27674
27675 switch_to_tboot_pt();
27676
27677- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
27678+ shutdown = (void *)(unsigned long)tboot->shutdown_entry;
27679 shutdown();
27680
27681 /* should not reach here */
27682@@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
27683 return -ENODEV;
27684 }
27685
27686-static atomic_t ap_wfs_count;
27687+static atomic_unchecked_t ap_wfs_count;
27688
27689 static int tboot_wait_for_aps(int num_aps)
27690 {
27691@@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
27692 {
27693 switch (action) {
27694 case CPU_DYING:
27695- atomic_inc(&ap_wfs_count);
27696+ atomic_inc_unchecked(&ap_wfs_count);
27697 if (num_online_cpus() == 1)
27698- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
27699+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
27700 return NOTIFY_BAD;
27701 break;
27702 }
27703@@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
27704
27705 tboot_create_trampoline();
27706
27707- atomic_set(&ap_wfs_count, 0);
27708+ atomic_set_unchecked(&ap_wfs_count, 0);
27709 register_hotcpu_notifier(&tboot_cpu_notifier);
27710
27711 #ifdef CONFIG_DEBUG_FS
27712diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
27713index 24d3c91..d06b473 100644
27714--- a/arch/x86/kernel/time.c
27715+++ b/arch/x86/kernel/time.c
27716@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
27717 {
27718 unsigned long pc = instruction_pointer(regs);
27719
27720- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
27721+ if (!user_mode(regs) && in_lock_functions(pc)) {
27722 #ifdef CONFIG_FRAME_POINTER
27723- return *(unsigned long *)(regs->bp + sizeof(long));
27724+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
27725 #else
27726 unsigned long *sp =
27727 (unsigned long *)kernel_stack_pointer(regs);
27728@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
27729 * or above a saved flags. Eflags has bits 22-31 zero,
27730 * kernel addresses don't.
27731 */
27732+
27733+#ifdef CONFIG_PAX_KERNEXEC
27734+ return ktla_ktva(sp[0]);
27735+#else
27736 if (sp[0] >> 22)
27737 return sp[0];
27738 if (sp[1] >> 22)
27739 return sp[1];
27740 #endif
27741+
27742+#endif
27743 }
27744 return pc;
27745 }
27746diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
27747index f7fec09..9991981 100644
27748--- a/arch/x86/kernel/tls.c
27749+++ b/arch/x86/kernel/tls.c
27750@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
27751 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
27752 return -EINVAL;
27753
27754+#ifdef CONFIG_PAX_SEGMEXEC
27755+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
27756+ return -EINVAL;
27757+#endif
27758+
27759 set_tls_desc(p, idx, &info, 1);
27760
27761 return 0;
27762@@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
27763
27764 if (kbuf)
27765 info = kbuf;
27766- else if (__copy_from_user(infobuf, ubuf, count))
27767+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
27768 return -EFAULT;
27769 else
27770 info = infobuf;
27771diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
27772index 1c113db..287b42e 100644
27773--- a/arch/x86/kernel/tracepoint.c
27774+++ b/arch/x86/kernel/tracepoint.c
27775@@ -9,11 +9,11 @@
27776 #include <linux/atomic.h>
27777
27778 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
27779-struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27780+const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27781 (unsigned long) trace_idt_table };
27782
27783 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27784-gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
27785+gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
27786
27787 static int trace_irq_vector_refcount;
27788 static DEFINE_MUTEX(irq_vector_mutex);
27789diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
27790index 57409f6..e2c17e1 100644
27791--- a/arch/x86/kernel/traps.c
27792+++ b/arch/x86/kernel/traps.c
27793@@ -66,7 +66,7 @@
27794 #include <asm/proto.h>
27795
27796 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27797-gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
27798+gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
27799 #else
27800 #include <asm/processor-flags.h>
27801 #include <asm/setup.h>
27802@@ -75,7 +75,7 @@ asmlinkage int system_call(void);
27803 #endif
27804
27805 /* Must be page-aligned because the real IDT is used in a fixmap. */
27806-gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
27807+gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
27808
27809 DECLARE_BITMAP(used_vectors, NR_VECTORS);
27810 EXPORT_SYMBOL_GPL(used_vectors);
27811@@ -107,11 +107,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
27812 }
27813
27814 static int __kprobes
27815-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27816+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
27817 struct pt_regs *regs, long error_code)
27818 {
27819 #ifdef CONFIG_X86_32
27820- if (regs->flags & X86_VM_MASK) {
27821+ if (v8086_mode(regs)) {
27822 /*
27823 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
27824 * On nmi (interrupt 2), do_trap should not be called.
27825@@ -124,12 +124,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27826 return -1;
27827 }
27828 #endif
27829- if (!user_mode(regs)) {
27830+ if (!user_mode_novm(regs)) {
27831 if (!fixup_exception(regs)) {
27832 tsk->thread.error_code = error_code;
27833 tsk->thread.trap_nr = trapnr;
27834+
27835+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27836+ if (trapnr == X86_TRAP_SS && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
27837+ str = "PAX: suspicious stack segment fault";
27838+#endif
27839+
27840 die(str, regs, error_code);
27841 }
27842+
27843+#ifdef CONFIG_PAX_REFCOUNT
27844+ if (trapnr == X86_TRAP_OF)
27845+ pax_report_refcount_overflow(regs);
27846+#endif
27847+
27848 return 0;
27849 }
27850
27851@@ -137,7 +149,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27852 }
27853
27854 static void __kprobes
27855-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27856+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
27857 long error_code, siginfo_t *info)
27858 {
27859 struct task_struct *tsk = current;
27860@@ -161,7 +173,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27861 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
27862 printk_ratelimit()) {
27863 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
27864- tsk->comm, tsk->pid, str,
27865+ tsk->comm, task_pid_nr(tsk), str,
27866 regs->ip, regs->sp, error_code);
27867 print_vma_addr(" in ", regs->ip);
27868 pr_cont("\n");
27869@@ -273,7 +285,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
27870 conditional_sti(regs);
27871
27872 #ifdef CONFIG_X86_32
27873- if (regs->flags & X86_VM_MASK) {
27874+ if (v8086_mode(regs)) {
27875 local_irq_enable();
27876 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
27877 goto exit;
27878@@ -281,18 +293,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
27879 #endif
27880
27881 tsk = current;
27882- if (!user_mode(regs)) {
27883+ if (!user_mode_novm(regs)) {
27884 if (fixup_exception(regs))
27885 goto exit;
27886
27887 tsk->thread.error_code = error_code;
27888 tsk->thread.trap_nr = X86_TRAP_GP;
27889 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
27890- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
27891+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
27892+
27893+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27894+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
27895+ die("PAX: suspicious general protection fault", regs, error_code);
27896+ else
27897+#endif
27898+
27899 die("general protection fault", regs, error_code);
27900+ }
27901 goto exit;
27902 }
27903
27904+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27905+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
27906+ struct mm_struct *mm = tsk->mm;
27907+ unsigned long limit;
27908+
27909+ down_write(&mm->mmap_sem);
27910+ limit = mm->context.user_cs_limit;
27911+ if (limit < TASK_SIZE) {
27912+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
27913+ up_write(&mm->mmap_sem);
27914+ return;
27915+ }
27916+ up_write(&mm->mmap_sem);
27917+ }
27918+#endif
27919+
27920 tsk->thread.error_code = error_code;
27921 tsk->thread.trap_nr = X86_TRAP_GP;
27922
27923@@ -453,7 +489,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27924 /* It's safe to allow irq's after DR6 has been saved */
27925 preempt_conditional_sti(regs);
27926
27927- if (regs->flags & X86_VM_MASK) {
27928+ if (v8086_mode(regs)) {
27929 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
27930 X86_TRAP_DB);
27931 preempt_conditional_cli(regs);
27932@@ -468,7 +504,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27933 * We already checked v86 mode above, so we can check for kernel mode
27934 * by just checking the CPL of CS.
27935 */
27936- if ((dr6 & DR_STEP) && !user_mode(regs)) {
27937+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
27938 tsk->thread.debugreg6 &= ~DR_STEP;
27939 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
27940 regs->flags &= ~X86_EFLAGS_TF;
27941@@ -500,7 +536,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
27942 return;
27943 conditional_sti(regs);
27944
27945- if (!user_mode_vm(regs))
27946+ if (!user_mode(regs))
27947 {
27948 if (!fixup_exception(regs)) {
27949 task->thread.error_code = error_code;
27950diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
27951index cfbe99f..a6e8fa7 100644
27952--- a/arch/x86/kernel/tsc.c
27953+++ b/arch/x86/kernel/tsc.c
27954@@ -150,7 +150,7 @@ static void cyc2ns_write_end(int cpu, struct cyc2ns_data *data)
27955 */
27956 smp_wmb();
27957
27958- ACCESS_ONCE(c2n->head) = data;
27959+ ACCESS_ONCE_RW(c2n->head) = data;
27960 }
27961
27962 /*
27963diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
27964index 2ed8459..7cf329f 100644
27965--- a/arch/x86/kernel/uprobes.c
27966+++ b/arch/x86/kernel/uprobes.c
27967@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
27968 int ret = NOTIFY_DONE;
27969
27970 /* We are only interested in userspace traps */
27971- if (regs && !user_mode_vm(regs))
27972+ if (regs && !user_mode(regs))
27973 return NOTIFY_DONE;
27974
27975 switch (val) {
27976@@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
27977
27978 if (ncopied != rasize) {
27979 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
27980- "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
27981+ "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
27982
27983 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
27984 }
27985diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
27986index b9242ba..50c5edd 100644
27987--- a/arch/x86/kernel/verify_cpu.S
27988+++ b/arch/x86/kernel/verify_cpu.S
27989@@ -20,6 +20,7 @@
27990 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
27991 * arch/x86/kernel/trampoline_64.S: secondary processor verification
27992 * arch/x86/kernel/head_32.S: processor startup
27993+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
27994 *
27995 * verify_cpu, returns the status of longmode and SSE in register %eax.
27996 * 0: Success 1: Failure
27997diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
27998index e8edcf5..27f9344 100644
27999--- a/arch/x86/kernel/vm86_32.c
28000+++ b/arch/x86/kernel/vm86_32.c
28001@@ -44,6 +44,7 @@
28002 #include <linux/ptrace.h>
28003 #include <linux/audit.h>
28004 #include <linux/stddef.h>
28005+#include <linux/grsecurity.h>
28006
28007 #include <asm/uaccess.h>
28008 #include <asm/io.h>
28009@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
28010 do_exit(SIGSEGV);
28011 }
28012
28013- tss = &per_cpu(init_tss, get_cpu());
28014+ tss = init_tss + get_cpu();
28015 current->thread.sp0 = current->thread.saved_sp0;
28016 current->thread.sysenter_cs = __KERNEL_CS;
28017 load_sp0(tss, &current->thread);
28018@@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
28019
28020 if (tsk->thread.saved_sp0)
28021 return -EPERM;
28022+
28023+#ifdef CONFIG_GRKERNSEC_VM86
28024+ if (!capable(CAP_SYS_RAWIO)) {
28025+ gr_handle_vm86();
28026+ return -EPERM;
28027+ }
28028+#endif
28029+
28030 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
28031 offsetof(struct kernel_vm86_struct, vm86plus) -
28032 sizeof(info.regs));
28033@@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
28034 int tmp;
28035 struct vm86plus_struct __user *v86;
28036
28037+#ifdef CONFIG_GRKERNSEC_VM86
28038+ if (!capable(CAP_SYS_RAWIO)) {
28039+ gr_handle_vm86();
28040+ return -EPERM;
28041+ }
28042+#endif
28043+
28044 tsk = current;
28045 switch (cmd) {
28046 case VM86_REQUEST_IRQ:
28047@@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
28048 tsk->thread.saved_fs = info->regs32->fs;
28049 tsk->thread.saved_gs = get_user_gs(info->regs32);
28050
28051- tss = &per_cpu(init_tss, get_cpu());
28052+ tss = init_tss + get_cpu();
28053 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
28054 if (cpu_has_sep)
28055 tsk->thread.sysenter_cs = 0;
28056@@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
28057 goto cannot_handle;
28058 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
28059 goto cannot_handle;
28060- intr_ptr = (unsigned long __user *) (i << 2);
28061+ intr_ptr = (__force unsigned long __user *) (i << 2);
28062 if (get_user(segoffs, intr_ptr))
28063 goto cannot_handle;
28064 if ((segoffs >> 16) == BIOSSEG)
28065diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
28066index da6b35a..977e9cf 100644
28067--- a/arch/x86/kernel/vmlinux.lds.S
28068+++ b/arch/x86/kernel/vmlinux.lds.S
28069@@ -26,6 +26,13 @@
28070 #include <asm/page_types.h>
28071 #include <asm/cache.h>
28072 #include <asm/boot.h>
28073+#include <asm/segment.h>
28074+
28075+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28076+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
28077+#else
28078+#define __KERNEL_TEXT_OFFSET 0
28079+#endif
28080
28081 #undef i386 /* in case the preprocessor is a 32bit one */
28082
28083@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
28084
28085 PHDRS {
28086 text PT_LOAD FLAGS(5); /* R_E */
28087+#ifdef CONFIG_X86_32
28088+ module PT_LOAD FLAGS(5); /* R_E */
28089+#endif
28090+#ifdef CONFIG_XEN
28091+ rodata PT_LOAD FLAGS(5); /* R_E */
28092+#else
28093+ rodata PT_LOAD FLAGS(4); /* R__ */
28094+#endif
28095 data PT_LOAD FLAGS(6); /* RW_ */
28096-#ifdef CONFIG_X86_64
28097+ init.begin PT_LOAD FLAGS(6); /* RW_ */
28098 #ifdef CONFIG_SMP
28099 percpu PT_LOAD FLAGS(6); /* RW_ */
28100 #endif
28101+ text.init PT_LOAD FLAGS(5); /* R_E */
28102+ text.exit PT_LOAD FLAGS(5); /* R_E */
28103 init PT_LOAD FLAGS(7); /* RWE */
28104-#endif
28105 note PT_NOTE FLAGS(0); /* ___ */
28106 }
28107
28108 SECTIONS
28109 {
28110 #ifdef CONFIG_X86_32
28111- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
28112- phys_startup_32 = startup_32 - LOAD_OFFSET;
28113+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
28114 #else
28115- . = __START_KERNEL;
28116- phys_startup_64 = startup_64 - LOAD_OFFSET;
28117+ . = __START_KERNEL;
28118 #endif
28119
28120 /* Text and read-only data */
28121- .text : AT(ADDR(.text) - LOAD_OFFSET) {
28122- _text = .;
28123+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28124 /* bootstrapping code */
28125+#ifdef CONFIG_X86_32
28126+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28127+#else
28128+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28129+#endif
28130+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28131+ _text = .;
28132 HEAD_TEXT
28133 . = ALIGN(8);
28134 _stext = .;
28135@@ -104,13 +124,47 @@ SECTIONS
28136 IRQENTRY_TEXT
28137 *(.fixup)
28138 *(.gnu.warning)
28139- /* End of text section */
28140- _etext = .;
28141 } :text = 0x9090
28142
28143- NOTES :text :note
28144+ . += __KERNEL_TEXT_OFFSET;
28145
28146- EXCEPTION_TABLE(16) :text = 0x9090
28147+#ifdef CONFIG_X86_32
28148+ . = ALIGN(PAGE_SIZE);
28149+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
28150+
28151+#ifdef CONFIG_PAX_KERNEXEC
28152+ MODULES_EXEC_VADDR = .;
28153+ BYTE(0)
28154+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
28155+ . = ALIGN(HPAGE_SIZE) - 1;
28156+ MODULES_EXEC_END = .;
28157+#endif
28158+
28159+ } :module
28160+#endif
28161+
28162+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
28163+ /* End of text section */
28164+ BYTE(0)
28165+ _etext = . - __KERNEL_TEXT_OFFSET;
28166+ }
28167+
28168+#ifdef CONFIG_X86_32
28169+ . = ALIGN(PAGE_SIZE);
28170+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
28171+ . = ALIGN(PAGE_SIZE);
28172+ *(.empty_zero_page)
28173+ *(.initial_pg_fixmap)
28174+ *(.initial_pg_pmd)
28175+ *(.initial_page_table)
28176+ *(.swapper_pg_dir)
28177+ } :rodata
28178+#endif
28179+
28180+ . = ALIGN(PAGE_SIZE);
28181+ NOTES :rodata :note
28182+
28183+ EXCEPTION_TABLE(16) :rodata
28184
28185 #if defined(CONFIG_DEBUG_RODATA)
28186 /* .text should occupy whole number of pages */
28187@@ -122,16 +176,20 @@ SECTIONS
28188
28189 /* Data */
28190 .data : AT(ADDR(.data) - LOAD_OFFSET) {
28191+
28192+#ifdef CONFIG_PAX_KERNEXEC
28193+ . = ALIGN(HPAGE_SIZE);
28194+#else
28195+ . = ALIGN(PAGE_SIZE);
28196+#endif
28197+
28198 /* Start of data section */
28199 _sdata = .;
28200
28201 /* init_task */
28202 INIT_TASK_DATA(THREAD_SIZE)
28203
28204-#ifdef CONFIG_X86_32
28205- /* 32 bit has nosave before _edata */
28206 NOSAVE_DATA
28207-#endif
28208
28209 PAGE_ALIGNED_DATA(PAGE_SIZE)
28210
28211@@ -172,12 +230,19 @@ SECTIONS
28212 #endif /* CONFIG_X86_64 */
28213
28214 /* Init code and data - will be freed after init */
28215- . = ALIGN(PAGE_SIZE);
28216 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
28217+ BYTE(0)
28218+
28219+#ifdef CONFIG_PAX_KERNEXEC
28220+ . = ALIGN(HPAGE_SIZE);
28221+#else
28222+ . = ALIGN(PAGE_SIZE);
28223+#endif
28224+
28225 __init_begin = .; /* paired with __init_end */
28226- }
28227+ } :init.begin
28228
28229-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
28230+#ifdef CONFIG_SMP
28231 /*
28232 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
28233 * output PHDR, so the next output section - .init.text - should
28234@@ -186,12 +251,27 @@ SECTIONS
28235 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
28236 #endif
28237
28238- INIT_TEXT_SECTION(PAGE_SIZE)
28239-#ifdef CONFIG_X86_64
28240- :init
28241-#endif
28242+ . = ALIGN(PAGE_SIZE);
28243+ init_begin = .;
28244+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
28245+ VMLINUX_SYMBOL(_sinittext) = .;
28246+ INIT_TEXT
28247+ VMLINUX_SYMBOL(_einittext) = .;
28248+ . = ALIGN(PAGE_SIZE);
28249+ } :text.init
28250
28251- INIT_DATA_SECTION(16)
28252+ /*
28253+ * .exit.text is discard at runtime, not link time, to deal with
28254+ * references from .altinstructions and .eh_frame
28255+ */
28256+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28257+ EXIT_TEXT
28258+ . = ALIGN(16);
28259+ } :text.exit
28260+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
28261+
28262+ . = ALIGN(PAGE_SIZE);
28263+ INIT_DATA_SECTION(16) :init
28264
28265 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
28266 __x86_cpu_dev_start = .;
28267@@ -262,19 +342,12 @@ SECTIONS
28268 }
28269
28270 . = ALIGN(8);
28271- /*
28272- * .exit.text is discard at runtime, not link time, to deal with
28273- * references from .altinstructions and .eh_frame
28274- */
28275- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
28276- EXIT_TEXT
28277- }
28278
28279 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
28280 EXIT_DATA
28281 }
28282
28283-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
28284+#ifndef CONFIG_SMP
28285 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
28286 #endif
28287
28288@@ -293,16 +366,10 @@ SECTIONS
28289 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
28290 __smp_locks = .;
28291 *(.smp_locks)
28292- . = ALIGN(PAGE_SIZE);
28293 __smp_locks_end = .;
28294+ . = ALIGN(PAGE_SIZE);
28295 }
28296
28297-#ifdef CONFIG_X86_64
28298- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
28299- NOSAVE_DATA
28300- }
28301-#endif
28302-
28303 /* BSS */
28304 . = ALIGN(PAGE_SIZE);
28305 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
28306@@ -318,6 +385,7 @@ SECTIONS
28307 __brk_base = .;
28308 . += 64 * 1024; /* 64k alignment slop space */
28309 *(.brk_reservation) /* areas brk users have reserved */
28310+ . = ALIGN(HPAGE_SIZE);
28311 __brk_limit = .;
28312 }
28313
28314@@ -344,13 +412,12 @@ SECTIONS
28315 * for the boot processor.
28316 */
28317 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
28318-INIT_PER_CPU(gdt_page);
28319 INIT_PER_CPU(irq_stack_union);
28320
28321 /*
28322 * Build-time check on the image size:
28323 */
28324-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
28325+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
28326 "kernel image bigger than KERNEL_IMAGE_SIZE");
28327
28328 #ifdef CONFIG_SMP
28329diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
28330index 1f96f93..6f29be7 100644
28331--- a/arch/x86/kernel/vsyscall_64.c
28332+++ b/arch/x86/kernel/vsyscall_64.c
28333@@ -56,15 +56,13 @@
28334 DEFINE_VVAR(int, vgetcpu_mode);
28335 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
28336
28337-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
28338+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
28339
28340 static int __init vsyscall_setup(char *str)
28341 {
28342 if (str) {
28343 if (!strcmp("emulate", str))
28344 vsyscall_mode = EMULATE;
28345- else if (!strcmp("native", str))
28346- vsyscall_mode = NATIVE;
28347 else if (!strcmp("none", str))
28348 vsyscall_mode = NONE;
28349 else
28350@@ -101,7 +99,7 @@ void update_vsyscall(struct timekeeper *tk)
28351 vdata->monotonic_time_sec = tk->xtime_sec
28352 + tk->wall_to_monotonic.tv_sec;
28353 vdata->monotonic_time_snsec = tk->xtime_nsec
28354- + (tk->wall_to_monotonic.tv_nsec
28355+ + ((u64)tk->wall_to_monotonic.tv_nsec
28356 << tk->shift);
28357 while (vdata->monotonic_time_snsec >=
28358 (((u64)NSEC_PER_SEC) << tk->shift)) {
28359@@ -323,8 +321,7 @@ do_ret:
28360 return true;
28361
28362 sigsegv:
28363- force_sig(SIGSEGV, current);
28364- return true;
28365+ do_group_exit(SIGKILL);
28366 }
28367
28368 /*
28369@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
28370 extern char __vvar_page;
28371 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
28372
28373- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
28374- vsyscall_mode == NATIVE
28375- ? PAGE_KERNEL_VSYSCALL
28376- : PAGE_KERNEL_VVAR);
28377+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
28378 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
28379 (unsigned long)VSYSCALL_START);
28380
28381diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
28382index 04068192..4d75aa6 100644
28383--- a/arch/x86/kernel/x8664_ksyms_64.c
28384+++ b/arch/x86/kernel/x8664_ksyms_64.c
28385@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
28386 EXPORT_SYMBOL(copy_user_generic_unrolled);
28387 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
28388 EXPORT_SYMBOL(__copy_user_nocache);
28389-EXPORT_SYMBOL(_copy_from_user);
28390-EXPORT_SYMBOL(_copy_to_user);
28391
28392 EXPORT_SYMBOL(copy_page);
28393 EXPORT_SYMBOL(clear_page);
28394@@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
28395 EXPORT_SYMBOL(___preempt_schedule_context);
28396 #endif
28397 #endif
28398+
28399+#ifdef CONFIG_PAX_PER_CPU_PGD
28400+EXPORT_SYMBOL(cpu_pgd);
28401+#endif
28402diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
28403index e48b674..a451dd9 100644
28404--- a/arch/x86/kernel/x86_init.c
28405+++ b/arch/x86/kernel/x86_init.c
28406@@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
28407 static void default_nmi_init(void) { };
28408 static int default_i8042_detect(void) { return 1; };
28409
28410-struct x86_platform_ops x86_platform = {
28411+struct x86_platform_ops x86_platform __read_only = {
28412 .calibrate_tsc = native_calibrate_tsc,
28413 .get_wallclock = mach_get_cmos_time,
28414 .set_wallclock = mach_set_rtc_mmss,
28415@@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
28416 EXPORT_SYMBOL_GPL(x86_platform);
28417
28418 #if defined(CONFIG_PCI_MSI)
28419-struct x86_msi_ops x86_msi = {
28420+struct x86_msi_ops x86_msi __read_only = {
28421 .setup_msi_irqs = native_setup_msi_irqs,
28422 .compose_msi_msg = native_compose_msi_msg,
28423 .teardown_msi_irq = native_teardown_msi_irq,
28424@@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
28425 }
28426 #endif
28427
28428-struct x86_io_apic_ops x86_io_apic_ops = {
28429+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
28430 .init = native_io_apic_init_mappings,
28431 .read = native_io_apic_read,
28432 .write = native_io_apic_write,
28433diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
28434index a4b451c..8dfe1ad 100644
28435--- a/arch/x86/kernel/xsave.c
28436+++ b/arch/x86/kernel/xsave.c
28437@@ -164,18 +164,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28438
28439 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
28440 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
28441- err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28442+ err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28443
28444 if (!use_xsave())
28445 return err;
28446
28447- err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
28448+ err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
28449
28450 /*
28451 * Read the xstate_bv which we copied (directly from the cpu or
28452 * from the state in task struct) to the user buffers.
28453 */
28454- err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28455+ err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28456
28457 /*
28458 * For legacy compatible, we always set FP/SSE bits in the bit
28459@@ -190,7 +190,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28460 */
28461 xstate_bv |= XSTATE_FPSSE;
28462
28463- err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28464+ err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28465
28466 return err;
28467 }
28468@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
28469 {
28470 int err;
28471
28472+ buf = (struct xsave_struct __user *)____m(buf);
28473 if (use_xsave())
28474 err = xsave_user(buf);
28475 else if (use_fxsr())
28476@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
28477 */
28478 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
28479 {
28480+ buf = (void __user *)____m(buf);
28481 if (use_xsave()) {
28482 if ((unsigned long)buf % 64 || fx_only) {
28483 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
28484diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
28485index c697625..a032162 100644
28486--- a/arch/x86/kvm/cpuid.c
28487+++ b/arch/x86/kvm/cpuid.c
28488@@ -156,15 +156,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
28489 struct kvm_cpuid2 *cpuid,
28490 struct kvm_cpuid_entry2 __user *entries)
28491 {
28492- int r;
28493+ int r, i;
28494
28495 r = -E2BIG;
28496 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
28497 goto out;
28498 r = -EFAULT;
28499- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
28500- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28501+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28502 goto out;
28503+ for (i = 0; i < cpuid->nent; ++i) {
28504+ struct kvm_cpuid_entry2 cpuid_entry;
28505+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
28506+ goto out;
28507+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
28508+ }
28509 vcpu->arch.cpuid_nent = cpuid->nent;
28510 kvm_apic_set_version(vcpu);
28511 kvm_x86_ops->cpuid_update(vcpu);
28512@@ -179,15 +184,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
28513 struct kvm_cpuid2 *cpuid,
28514 struct kvm_cpuid_entry2 __user *entries)
28515 {
28516- int r;
28517+ int r, i;
28518
28519 r = -E2BIG;
28520 if (cpuid->nent < vcpu->arch.cpuid_nent)
28521 goto out;
28522 r = -EFAULT;
28523- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
28524- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28525+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28526 goto out;
28527+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
28528+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
28529+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
28530+ goto out;
28531+ }
28532 return 0;
28533
28534 out:
28535diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
28536index 9736529..ab4f54c 100644
28537--- a/arch/x86/kvm/lapic.c
28538+++ b/arch/x86/kvm/lapic.c
28539@@ -55,7 +55,7 @@
28540 #define APIC_BUS_CYCLE_NS 1
28541
28542 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
28543-#define apic_debug(fmt, arg...)
28544+#define apic_debug(fmt, arg...) do {} while (0)
28545
28546 #define APIC_LVT_NUM 6
28547 /* 14 is the version for Xeon and Pentium 8.4.8*/
28548diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
28549index cba218a..1cc1bed 100644
28550--- a/arch/x86/kvm/paging_tmpl.h
28551+++ b/arch/x86/kvm/paging_tmpl.h
28552@@ -331,7 +331,7 @@ retry_walk:
28553 if (unlikely(kvm_is_error_hva(host_addr)))
28554 goto error;
28555
28556- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
28557+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
28558 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
28559 goto error;
28560 walker->ptep_user[walker->level - 1] = ptep_user;
28561diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
28562index 2de1bc0..22251ee 100644
28563--- a/arch/x86/kvm/svm.c
28564+++ b/arch/x86/kvm/svm.c
28565@@ -3508,7 +3508,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
28566 int cpu = raw_smp_processor_id();
28567
28568 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
28569+
28570+ pax_open_kernel();
28571 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
28572+ pax_close_kernel();
28573+
28574 load_TR_desc();
28575 }
28576
28577@@ -3911,6 +3915,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
28578 #endif
28579 #endif
28580
28581+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28582+ __set_fs(current_thread_info()->addr_limit);
28583+#endif
28584+
28585 reload_tss(vcpu);
28586
28587 local_irq_disable();
28588diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
28589index 3927528..fc19971 100644
28590--- a/arch/x86/kvm/vmx.c
28591+++ b/arch/x86/kvm/vmx.c
28592@@ -1320,12 +1320,12 @@ static void vmcs_write64(unsigned long field, u64 value)
28593 #endif
28594 }
28595
28596-static void vmcs_clear_bits(unsigned long field, u32 mask)
28597+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
28598 {
28599 vmcs_writel(field, vmcs_readl(field) & ~mask);
28600 }
28601
28602-static void vmcs_set_bits(unsigned long field, u32 mask)
28603+static void vmcs_set_bits(unsigned long field, unsigned long mask)
28604 {
28605 vmcs_writel(field, vmcs_readl(field) | mask);
28606 }
28607@@ -1585,7 +1585,11 @@ static void reload_tss(void)
28608 struct desc_struct *descs;
28609
28610 descs = (void *)gdt->address;
28611+
28612+ pax_open_kernel();
28613 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
28614+ pax_close_kernel();
28615+
28616 load_TR_desc();
28617 }
28618
28619@@ -1809,6 +1813,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
28620 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
28621 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
28622
28623+#ifdef CONFIG_PAX_PER_CPU_PGD
28624+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28625+#endif
28626+
28627 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
28628 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
28629 vmx->loaded_vmcs->cpu = cpu;
28630@@ -2098,7 +2106,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
28631 * reads and returns guest's timestamp counter "register"
28632 * guest_tsc = host_tsc + tsc_offset -- 21.3
28633 */
28634-static u64 guest_read_tsc(void)
28635+static u64 __intentional_overflow(-1) guest_read_tsc(void)
28636 {
28637 u64 host_tsc, tsc_offset;
28638
28639@@ -3024,8 +3032,11 @@ static __init int hardware_setup(void)
28640 if (!cpu_has_vmx_flexpriority())
28641 flexpriority_enabled = 0;
28642
28643- if (!cpu_has_vmx_tpr_shadow())
28644- kvm_x86_ops->update_cr8_intercept = NULL;
28645+ if (!cpu_has_vmx_tpr_shadow()) {
28646+ pax_open_kernel();
28647+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28648+ pax_close_kernel();
28649+ }
28650
28651 if (enable_ept && !cpu_has_vmx_ept_2m_page())
28652 kvm_disable_largepages();
28653@@ -3036,13 +3047,15 @@ static __init int hardware_setup(void)
28654 if (!cpu_has_vmx_apicv())
28655 enable_apicv = 0;
28656
28657+ pax_open_kernel();
28658 if (enable_apicv)
28659- kvm_x86_ops->update_cr8_intercept = NULL;
28660+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28661 else {
28662- kvm_x86_ops->hwapic_irr_update = NULL;
28663- kvm_x86_ops->deliver_posted_interrupt = NULL;
28664- kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28665+ *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
28666+ *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
28667+ *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28668 }
28669+ pax_close_kernel();
28670
28671 if (nested)
28672 nested_vmx_setup_ctls_msrs();
28673@@ -4165,7 +4178,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28674
28675 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
28676 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
28677+
28678+#ifndef CONFIG_PAX_PER_CPU_PGD
28679 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28680+#endif
28681
28682 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
28683 #ifdef CONFIG_X86_64
28684@@ -4187,7 +4203,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28685 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
28686 vmx->host_idt_base = dt.address;
28687
28688- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
28689+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
28690
28691 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
28692 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
28693@@ -7265,6 +7281,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28694 "jmp 2f \n\t"
28695 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
28696 "2: "
28697+
28698+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28699+ "ljmp %[cs],$3f\n\t"
28700+ "3: "
28701+#endif
28702+
28703 /* Save guest registers, load host registers, keep flags */
28704 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
28705 "pop %0 \n\t"
28706@@ -7317,6 +7339,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28707 #endif
28708 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
28709 [wordsize]"i"(sizeof(ulong))
28710+
28711+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28712+ ,[cs]"i"(__KERNEL_CS)
28713+#endif
28714+
28715 : "cc", "memory"
28716 #ifdef CONFIG_X86_64
28717 , "rax", "rbx", "rdi", "rsi"
28718@@ -7330,7 +7357,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28719 if (debugctlmsr)
28720 update_debugctlmsr(debugctlmsr);
28721
28722-#ifndef CONFIG_X86_64
28723+#ifdef CONFIG_X86_32
28724 /*
28725 * The sysexit path does not restore ds/es, so we must set them to
28726 * a reasonable value ourselves.
28727@@ -7339,8 +7366,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28728 * may be executed in interrupt context, which saves and restore segments
28729 * around it, nullifying its effect.
28730 */
28731- loadsegment(ds, __USER_DS);
28732- loadsegment(es, __USER_DS);
28733+ loadsegment(ds, __KERNEL_DS);
28734+ loadsegment(es, __KERNEL_DS);
28735+ loadsegment(ss, __KERNEL_DS);
28736+
28737+#ifdef CONFIG_PAX_KERNEXEC
28738+ loadsegment(fs, __KERNEL_PERCPU);
28739+#endif
28740+
28741+#ifdef CONFIG_PAX_MEMORY_UDEREF
28742+ __set_fs(current_thread_info()->addr_limit);
28743+#endif
28744+
28745 #endif
28746
28747 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
28748diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
28749index 2b85784..ad70e19 100644
28750--- a/arch/x86/kvm/x86.c
28751+++ b/arch/x86/kvm/x86.c
28752@@ -1777,8 +1777,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
28753 {
28754 struct kvm *kvm = vcpu->kvm;
28755 int lm = is_long_mode(vcpu);
28756- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28757- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28758+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28759+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28760 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
28761 : kvm->arch.xen_hvm_config.blob_size_32;
28762 u32 page_num = data & ~PAGE_MASK;
28763@@ -2689,6 +2689,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
28764 if (n < msr_list.nmsrs)
28765 goto out;
28766 r = -EFAULT;
28767+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
28768+ goto out;
28769 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
28770 num_msrs_to_save * sizeof(u32)))
28771 goto out;
28772@@ -5503,7 +5505,7 @@ static struct notifier_block pvclock_gtod_notifier = {
28773 };
28774 #endif
28775
28776-int kvm_arch_init(void *opaque)
28777+int kvm_arch_init(const void *opaque)
28778 {
28779 int r;
28780 struct kvm_x86_ops *ops = opaque;
28781diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
28782index ad1fb5f..fe30b66 100644
28783--- a/arch/x86/lguest/boot.c
28784+++ b/arch/x86/lguest/boot.c
28785@@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
28786 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
28787 * Launcher to reboot us.
28788 */
28789-static void lguest_restart(char *reason)
28790+static __noreturn void lguest_restart(char *reason)
28791 {
28792 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
28793+ BUG();
28794 }
28795
28796 /*G:050
28797diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
28798index 00933d5..3a64af9 100644
28799--- a/arch/x86/lib/atomic64_386_32.S
28800+++ b/arch/x86/lib/atomic64_386_32.S
28801@@ -48,6 +48,10 @@ BEGIN(read)
28802 movl (v), %eax
28803 movl 4(v), %edx
28804 RET_ENDP
28805+BEGIN(read_unchecked)
28806+ movl (v), %eax
28807+ movl 4(v), %edx
28808+RET_ENDP
28809 #undef v
28810
28811 #define v %esi
28812@@ -55,6 +59,10 @@ BEGIN(set)
28813 movl %ebx, (v)
28814 movl %ecx, 4(v)
28815 RET_ENDP
28816+BEGIN(set_unchecked)
28817+ movl %ebx, (v)
28818+ movl %ecx, 4(v)
28819+RET_ENDP
28820 #undef v
28821
28822 #define v %esi
28823@@ -70,6 +78,20 @@ RET_ENDP
28824 BEGIN(add)
28825 addl %eax, (v)
28826 adcl %edx, 4(v)
28827+
28828+#ifdef CONFIG_PAX_REFCOUNT
28829+ jno 0f
28830+ subl %eax, (v)
28831+ sbbl %edx, 4(v)
28832+ int $4
28833+0:
28834+ _ASM_EXTABLE(0b, 0b)
28835+#endif
28836+
28837+RET_ENDP
28838+BEGIN(add_unchecked)
28839+ addl %eax, (v)
28840+ adcl %edx, 4(v)
28841 RET_ENDP
28842 #undef v
28843
28844@@ -77,6 +99,24 @@ RET_ENDP
28845 BEGIN(add_return)
28846 addl (v), %eax
28847 adcl 4(v), %edx
28848+
28849+#ifdef CONFIG_PAX_REFCOUNT
28850+ into
28851+1234:
28852+ _ASM_EXTABLE(1234b, 2f)
28853+#endif
28854+
28855+ movl %eax, (v)
28856+ movl %edx, 4(v)
28857+
28858+#ifdef CONFIG_PAX_REFCOUNT
28859+2:
28860+#endif
28861+
28862+RET_ENDP
28863+BEGIN(add_return_unchecked)
28864+ addl (v), %eax
28865+ adcl 4(v), %edx
28866 movl %eax, (v)
28867 movl %edx, 4(v)
28868 RET_ENDP
28869@@ -86,6 +126,20 @@ RET_ENDP
28870 BEGIN(sub)
28871 subl %eax, (v)
28872 sbbl %edx, 4(v)
28873+
28874+#ifdef CONFIG_PAX_REFCOUNT
28875+ jno 0f
28876+ addl %eax, (v)
28877+ adcl %edx, 4(v)
28878+ int $4
28879+0:
28880+ _ASM_EXTABLE(0b, 0b)
28881+#endif
28882+
28883+RET_ENDP
28884+BEGIN(sub_unchecked)
28885+ subl %eax, (v)
28886+ sbbl %edx, 4(v)
28887 RET_ENDP
28888 #undef v
28889
28890@@ -96,6 +150,27 @@ BEGIN(sub_return)
28891 sbbl $0, %edx
28892 addl (v), %eax
28893 adcl 4(v), %edx
28894+
28895+#ifdef CONFIG_PAX_REFCOUNT
28896+ into
28897+1234:
28898+ _ASM_EXTABLE(1234b, 2f)
28899+#endif
28900+
28901+ movl %eax, (v)
28902+ movl %edx, 4(v)
28903+
28904+#ifdef CONFIG_PAX_REFCOUNT
28905+2:
28906+#endif
28907+
28908+RET_ENDP
28909+BEGIN(sub_return_unchecked)
28910+ negl %edx
28911+ negl %eax
28912+ sbbl $0, %edx
28913+ addl (v), %eax
28914+ adcl 4(v), %edx
28915 movl %eax, (v)
28916 movl %edx, 4(v)
28917 RET_ENDP
28918@@ -105,6 +180,20 @@ RET_ENDP
28919 BEGIN(inc)
28920 addl $1, (v)
28921 adcl $0, 4(v)
28922+
28923+#ifdef CONFIG_PAX_REFCOUNT
28924+ jno 0f
28925+ subl $1, (v)
28926+ sbbl $0, 4(v)
28927+ int $4
28928+0:
28929+ _ASM_EXTABLE(0b, 0b)
28930+#endif
28931+
28932+RET_ENDP
28933+BEGIN(inc_unchecked)
28934+ addl $1, (v)
28935+ adcl $0, 4(v)
28936 RET_ENDP
28937 #undef v
28938
28939@@ -114,6 +203,26 @@ BEGIN(inc_return)
28940 movl 4(v), %edx
28941 addl $1, %eax
28942 adcl $0, %edx
28943+
28944+#ifdef CONFIG_PAX_REFCOUNT
28945+ into
28946+1234:
28947+ _ASM_EXTABLE(1234b, 2f)
28948+#endif
28949+
28950+ movl %eax, (v)
28951+ movl %edx, 4(v)
28952+
28953+#ifdef CONFIG_PAX_REFCOUNT
28954+2:
28955+#endif
28956+
28957+RET_ENDP
28958+BEGIN(inc_return_unchecked)
28959+ movl (v), %eax
28960+ movl 4(v), %edx
28961+ addl $1, %eax
28962+ adcl $0, %edx
28963 movl %eax, (v)
28964 movl %edx, 4(v)
28965 RET_ENDP
28966@@ -123,6 +232,20 @@ RET_ENDP
28967 BEGIN(dec)
28968 subl $1, (v)
28969 sbbl $0, 4(v)
28970+
28971+#ifdef CONFIG_PAX_REFCOUNT
28972+ jno 0f
28973+ addl $1, (v)
28974+ adcl $0, 4(v)
28975+ int $4
28976+0:
28977+ _ASM_EXTABLE(0b, 0b)
28978+#endif
28979+
28980+RET_ENDP
28981+BEGIN(dec_unchecked)
28982+ subl $1, (v)
28983+ sbbl $0, 4(v)
28984 RET_ENDP
28985 #undef v
28986
28987@@ -132,6 +255,26 @@ BEGIN(dec_return)
28988 movl 4(v), %edx
28989 subl $1, %eax
28990 sbbl $0, %edx
28991+
28992+#ifdef CONFIG_PAX_REFCOUNT
28993+ into
28994+1234:
28995+ _ASM_EXTABLE(1234b, 2f)
28996+#endif
28997+
28998+ movl %eax, (v)
28999+ movl %edx, 4(v)
29000+
29001+#ifdef CONFIG_PAX_REFCOUNT
29002+2:
29003+#endif
29004+
29005+RET_ENDP
29006+BEGIN(dec_return_unchecked)
29007+ movl (v), %eax
29008+ movl 4(v), %edx
29009+ subl $1, %eax
29010+ sbbl $0, %edx
29011 movl %eax, (v)
29012 movl %edx, 4(v)
29013 RET_ENDP
29014@@ -143,6 +286,13 @@ BEGIN(add_unless)
29015 adcl %edx, %edi
29016 addl (v), %eax
29017 adcl 4(v), %edx
29018+
29019+#ifdef CONFIG_PAX_REFCOUNT
29020+ into
29021+1234:
29022+ _ASM_EXTABLE(1234b, 2f)
29023+#endif
29024+
29025 cmpl %eax, %ecx
29026 je 3f
29027 1:
29028@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
29029 1:
29030 addl $1, %eax
29031 adcl $0, %edx
29032+
29033+#ifdef CONFIG_PAX_REFCOUNT
29034+ into
29035+1234:
29036+ _ASM_EXTABLE(1234b, 2f)
29037+#endif
29038+
29039 movl %eax, (v)
29040 movl %edx, 4(v)
29041 movl $1, %eax
29042@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
29043 movl 4(v), %edx
29044 subl $1, %eax
29045 sbbl $0, %edx
29046+
29047+#ifdef CONFIG_PAX_REFCOUNT
29048+ into
29049+1234:
29050+ _ASM_EXTABLE(1234b, 1f)
29051+#endif
29052+
29053 js 1f
29054 movl %eax, (v)
29055 movl %edx, 4(v)
29056diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
29057index f5cc9eb..51fa319 100644
29058--- a/arch/x86/lib/atomic64_cx8_32.S
29059+++ b/arch/x86/lib/atomic64_cx8_32.S
29060@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
29061 CFI_STARTPROC
29062
29063 read64 %ecx
29064+ pax_force_retaddr
29065 ret
29066 CFI_ENDPROC
29067 ENDPROC(atomic64_read_cx8)
29068
29069+ENTRY(atomic64_read_unchecked_cx8)
29070+ CFI_STARTPROC
29071+
29072+ read64 %ecx
29073+ pax_force_retaddr
29074+ ret
29075+ CFI_ENDPROC
29076+ENDPROC(atomic64_read_unchecked_cx8)
29077+
29078 ENTRY(atomic64_set_cx8)
29079 CFI_STARTPROC
29080
29081@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
29082 cmpxchg8b (%esi)
29083 jne 1b
29084
29085+ pax_force_retaddr
29086 ret
29087 CFI_ENDPROC
29088 ENDPROC(atomic64_set_cx8)
29089
29090+ENTRY(atomic64_set_unchecked_cx8)
29091+ CFI_STARTPROC
29092+
29093+1:
29094+/* we don't need LOCK_PREFIX since aligned 64-bit writes
29095+ * are atomic on 586 and newer */
29096+ cmpxchg8b (%esi)
29097+ jne 1b
29098+
29099+ pax_force_retaddr
29100+ ret
29101+ CFI_ENDPROC
29102+ENDPROC(atomic64_set_unchecked_cx8)
29103+
29104 ENTRY(atomic64_xchg_cx8)
29105 CFI_STARTPROC
29106
29107@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
29108 cmpxchg8b (%esi)
29109 jne 1b
29110
29111+ pax_force_retaddr
29112 ret
29113 CFI_ENDPROC
29114 ENDPROC(atomic64_xchg_cx8)
29115
29116-.macro addsub_return func ins insc
29117-ENTRY(atomic64_\func\()_return_cx8)
29118+.macro addsub_return func ins insc unchecked=""
29119+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
29120 CFI_STARTPROC
29121 SAVE ebp
29122 SAVE ebx
29123@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
29124 movl %edx, %ecx
29125 \ins\()l %esi, %ebx
29126 \insc\()l %edi, %ecx
29127+
29128+.ifb \unchecked
29129+#ifdef CONFIG_PAX_REFCOUNT
29130+ into
29131+2:
29132+ _ASM_EXTABLE(2b, 3f)
29133+#endif
29134+.endif
29135+
29136 LOCK_PREFIX
29137 cmpxchg8b (%ebp)
29138 jne 1b
29139-
29140-10:
29141 movl %ebx, %eax
29142 movl %ecx, %edx
29143+
29144+.ifb \unchecked
29145+#ifdef CONFIG_PAX_REFCOUNT
29146+3:
29147+#endif
29148+.endif
29149+
29150 RESTORE edi
29151 RESTORE esi
29152 RESTORE ebx
29153 RESTORE ebp
29154+ pax_force_retaddr
29155 ret
29156 CFI_ENDPROC
29157-ENDPROC(atomic64_\func\()_return_cx8)
29158+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
29159 .endm
29160
29161 addsub_return add add adc
29162 addsub_return sub sub sbb
29163+addsub_return add add adc _unchecked
29164+addsub_return sub sub sbb _unchecked
29165
29166-.macro incdec_return func ins insc
29167-ENTRY(atomic64_\func\()_return_cx8)
29168+.macro incdec_return func ins insc unchecked=""
29169+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
29170 CFI_STARTPROC
29171 SAVE ebx
29172
29173@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
29174 movl %edx, %ecx
29175 \ins\()l $1, %ebx
29176 \insc\()l $0, %ecx
29177+
29178+.ifb \unchecked
29179+#ifdef CONFIG_PAX_REFCOUNT
29180+ into
29181+2:
29182+ _ASM_EXTABLE(2b, 3f)
29183+#endif
29184+.endif
29185+
29186 LOCK_PREFIX
29187 cmpxchg8b (%esi)
29188 jne 1b
29189
29190-10:
29191 movl %ebx, %eax
29192 movl %ecx, %edx
29193+
29194+.ifb \unchecked
29195+#ifdef CONFIG_PAX_REFCOUNT
29196+3:
29197+#endif
29198+.endif
29199+
29200 RESTORE ebx
29201+ pax_force_retaddr
29202 ret
29203 CFI_ENDPROC
29204-ENDPROC(atomic64_\func\()_return_cx8)
29205+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
29206 .endm
29207
29208 incdec_return inc add adc
29209 incdec_return dec sub sbb
29210+incdec_return inc add adc _unchecked
29211+incdec_return dec sub sbb _unchecked
29212
29213 ENTRY(atomic64_dec_if_positive_cx8)
29214 CFI_STARTPROC
29215@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
29216 movl %edx, %ecx
29217 subl $1, %ebx
29218 sbb $0, %ecx
29219+
29220+#ifdef CONFIG_PAX_REFCOUNT
29221+ into
29222+1234:
29223+ _ASM_EXTABLE(1234b, 2f)
29224+#endif
29225+
29226 js 2f
29227 LOCK_PREFIX
29228 cmpxchg8b (%esi)
29229@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
29230 movl %ebx, %eax
29231 movl %ecx, %edx
29232 RESTORE ebx
29233+ pax_force_retaddr
29234 ret
29235 CFI_ENDPROC
29236 ENDPROC(atomic64_dec_if_positive_cx8)
29237@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
29238 movl %edx, %ecx
29239 addl %ebp, %ebx
29240 adcl %edi, %ecx
29241+
29242+#ifdef CONFIG_PAX_REFCOUNT
29243+ into
29244+1234:
29245+ _ASM_EXTABLE(1234b, 3f)
29246+#endif
29247+
29248 LOCK_PREFIX
29249 cmpxchg8b (%esi)
29250 jne 1b
29251@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
29252 CFI_ADJUST_CFA_OFFSET -8
29253 RESTORE ebx
29254 RESTORE ebp
29255+ pax_force_retaddr
29256 ret
29257 4:
29258 cmpl %edx, 4(%esp)
29259@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
29260 xorl %ecx, %ecx
29261 addl $1, %ebx
29262 adcl %edx, %ecx
29263+
29264+#ifdef CONFIG_PAX_REFCOUNT
29265+ into
29266+1234:
29267+ _ASM_EXTABLE(1234b, 3f)
29268+#endif
29269+
29270 LOCK_PREFIX
29271 cmpxchg8b (%esi)
29272 jne 1b
29273@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
29274 movl $1, %eax
29275 3:
29276 RESTORE ebx
29277+ pax_force_retaddr
29278 ret
29279 CFI_ENDPROC
29280 ENDPROC(atomic64_inc_not_zero_cx8)
29281diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
29282index e78b8ee..7e173a8 100644
29283--- a/arch/x86/lib/checksum_32.S
29284+++ b/arch/x86/lib/checksum_32.S
29285@@ -29,7 +29,8 @@
29286 #include <asm/dwarf2.h>
29287 #include <asm/errno.h>
29288 #include <asm/asm.h>
29289-
29290+#include <asm/segment.h>
29291+
29292 /*
29293 * computes a partial checksum, e.g. for TCP/UDP fragments
29294 */
29295@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
29296
29297 #define ARGBASE 16
29298 #define FP 12
29299-
29300-ENTRY(csum_partial_copy_generic)
29301+
29302+ENTRY(csum_partial_copy_generic_to_user)
29303 CFI_STARTPROC
29304+
29305+#ifdef CONFIG_PAX_MEMORY_UDEREF
29306+ pushl_cfi %gs
29307+ popl_cfi %es
29308+ jmp csum_partial_copy_generic
29309+#endif
29310+
29311+ENTRY(csum_partial_copy_generic_from_user)
29312+
29313+#ifdef CONFIG_PAX_MEMORY_UDEREF
29314+ pushl_cfi %gs
29315+ popl_cfi %ds
29316+#endif
29317+
29318+ENTRY(csum_partial_copy_generic)
29319 subl $4,%esp
29320 CFI_ADJUST_CFA_OFFSET 4
29321 pushl_cfi %edi
29322@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
29323 jmp 4f
29324 SRC(1: movw (%esi), %bx )
29325 addl $2, %esi
29326-DST( movw %bx, (%edi) )
29327+DST( movw %bx, %es:(%edi) )
29328 addl $2, %edi
29329 addw %bx, %ax
29330 adcl $0, %eax
29331@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
29332 SRC(1: movl (%esi), %ebx )
29333 SRC( movl 4(%esi), %edx )
29334 adcl %ebx, %eax
29335-DST( movl %ebx, (%edi) )
29336+DST( movl %ebx, %es:(%edi) )
29337 adcl %edx, %eax
29338-DST( movl %edx, 4(%edi) )
29339+DST( movl %edx, %es:4(%edi) )
29340
29341 SRC( movl 8(%esi), %ebx )
29342 SRC( movl 12(%esi), %edx )
29343 adcl %ebx, %eax
29344-DST( movl %ebx, 8(%edi) )
29345+DST( movl %ebx, %es:8(%edi) )
29346 adcl %edx, %eax
29347-DST( movl %edx, 12(%edi) )
29348+DST( movl %edx, %es:12(%edi) )
29349
29350 SRC( movl 16(%esi), %ebx )
29351 SRC( movl 20(%esi), %edx )
29352 adcl %ebx, %eax
29353-DST( movl %ebx, 16(%edi) )
29354+DST( movl %ebx, %es:16(%edi) )
29355 adcl %edx, %eax
29356-DST( movl %edx, 20(%edi) )
29357+DST( movl %edx, %es:20(%edi) )
29358
29359 SRC( movl 24(%esi), %ebx )
29360 SRC( movl 28(%esi), %edx )
29361 adcl %ebx, %eax
29362-DST( movl %ebx, 24(%edi) )
29363+DST( movl %ebx, %es:24(%edi) )
29364 adcl %edx, %eax
29365-DST( movl %edx, 28(%edi) )
29366+DST( movl %edx, %es:28(%edi) )
29367
29368 lea 32(%esi), %esi
29369 lea 32(%edi), %edi
29370@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
29371 shrl $2, %edx # This clears CF
29372 SRC(3: movl (%esi), %ebx )
29373 adcl %ebx, %eax
29374-DST( movl %ebx, (%edi) )
29375+DST( movl %ebx, %es:(%edi) )
29376 lea 4(%esi), %esi
29377 lea 4(%edi), %edi
29378 dec %edx
29379@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
29380 jb 5f
29381 SRC( movw (%esi), %cx )
29382 leal 2(%esi), %esi
29383-DST( movw %cx, (%edi) )
29384+DST( movw %cx, %es:(%edi) )
29385 leal 2(%edi), %edi
29386 je 6f
29387 shll $16,%ecx
29388 SRC(5: movb (%esi), %cl )
29389-DST( movb %cl, (%edi) )
29390+DST( movb %cl, %es:(%edi) )
29391 6: addl %ecx, %eax
29392 adcl $0, %eax
29393 7:
29394@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
29395
29396 6001:
29397 movl ARGBASE+20(%esp), %ebx # src_err_ptr
29398- movl $-EFAULT, (%ebx)
29399+ movl $-EFAULT, %ss:(%ebx)
29400
29401 # zero the complete destination - computing the rest
29402 # is too much work
29403@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
29404
29405 6002:
29406 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29407- movl $-EFAULT,(%ebx)
29408+ movl $-EFAULT,%ss:(%ebx)
29409 jmp 5000b
29410
29411 .previous
29412
29413+ pushl_cfi %ss
29414+ popl_cfi %ds
29415+ pushl_cfi %ss
29416+ popl_cfi %es
29417 popl_cfi %ebx
29418 CFI_RESTORE ebx
29419 popl_cfi %esi
29420@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
29421 popl_cfi %ecx # equivalent to addl $4,%esp
29422 ret
29423 CFI_ENDPROC
29424-ENDPROC(csum_partial_copy_generic)
29425+ENDPROC(csum_partial_copy_generic_to_user)
29426
29427 #else
29428
29429 /* Version for PentiumII/PPro */
29430
29431 #define ROUND1(x) \
29432+ nop; nop; nop; \
29433 SRC(movl x(%esi), %ebx ) ; \
29434 addl %ebx, %eax ; \
29435- DST(movl %ebx, x(%edi) ) ;
29436+ DST(movl %ebx, %es:x(%edi)) ;
29437
29438 #define ROUND(x) \
29439+ nop; nop; nop; \
29440 SRC(movl x(%esi), %ebx ) ; \
29441 adcl %ebx, %eax ; \
29442- DST(movl %ebx, x(%edi) ) ;
29443+ DST(movl %ebx, %es:x(%edi)) ;
29444
29445 #define ARGBASE 12
29446-
29447-ENTRY(csum_partial_copy_generic)
29448+
29449+ENTRY(csum_partial_copy_generic_to_user)
29450 CFI_STARTPROC
29451+
29452+#ifdef CONFIG_PAX_MEMORY_UDEREF
29453+ pushl_cfi %gs
29454+ popl_cfi %es
29455+ jmp csum_partial_copy_generic
29456+#endif
29457+
29458+ENTRY(csum_partial_copy_generic_from_user)
29459+
29460+#ifdef CONFIG_PAX_MEMORY_UDEREF
29461+ pushl_cfi %gs
29462+ popl_cfi %ds
29463+#endif
29464+
29465+ENTRY(csum_partial_copy_generic)
29466 pushl_cfi %ebx
29467 CFI_REL_OFFSET ebx, 0
29468 pushl_cfi %edi
29469@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
29470 subl %ebx, %edi
29471 lea -1(%esi),%edx
29472 andl $-32,%edx
29473- lea 3f(%ebx,%ebx), %ebx
29474+ lea 3f(%ebx,%ebx,2), %ebx
29475 testl %esi, %esi
29476 jmp *%ebx
29477 1: addl $64,%esi
29478@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
29479 jb 5f
29480 SRC( movw (%esi), %dx )
29481 leal 2(%esi), %esi
29482-DST( movw %dx, (%edi) )
29483+DST( movw %dx, %es:(%edi) )
29484 leal 2(%edi), %edi
29485 je 6f
29486 shll $16,%edx
29487 5:
29488 SRC( movb (%esi), %dl )
29489-DST( movb %dl, (%edi) )
29490+DST( movb %dl, %es:(%edi) )
29491 6: addl %edx, %eax
29492 adcl $0, %eax
29493 7:
29494 .section .fixup, "ax"
29495 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
29496- movl $-EFAULT, (%ebx)
29497+ movl $-EFAULT, %ss:(%ebx)
29498 # zero the complete destination (computing the rest is too much work)
29499 movl ARGBASE+8(%esp),%edi # dst
29500 movl ARGBASE+12(%esp),%ecx # len
29501@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
29502 rep; stosb
29503 jmp 7b
29504 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29505- movl $-EFAULT, (%ebx)
29506+ movl $-EFAULT, %ss:(%ebx)
29507 jmp 7b
29508 .previous
29509
29510+#ifdef CONFIG_PAX_MEMORY_UDEREF
29511+ pushl_cfi %ss
29512+ popl_cfi %ds
29513+ pushl_cfi %ss
29514+ popl_cfi %es
29515+#endif
29516+
29517 popl_cfi %esi
29518 CFI_RESTORE esi
29519 popl_cfi %edi
29520@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
29521 CFI_RESTORE ebx
29522 ret
29523 CFI_ENDPROC
29524-ENDPROC(csum_partial_copy_generic)
29525+ENDPROC(csum_partial_copy_generic_to_user)
29526
29527 #undef ROUND
29528 #undef ROUND1
29529diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
29530index f2145cf..cea889d 100644
29531--- a/arch/x86/lib/clear_page_64.S
29532+++ b/arch/x86/lib/clear_page_64.S
29533@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
29534 movl $4096/8,%ecx
29535 xorl %eax,%eax
29536 rep stosq
29537+ pax_force_retaddr
29538 ret
29539 CFI_ENDPROC
29540 ENDPROC(clear_page_c)
29541@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
29542 movl $4096,%ecx
29543 xorl %eax,%eax
29544 rep stosb
29545+ pax_force_retaddr
29546 ret
29547 CFI_ENDPROC
29548 ENDPROC(clear_page_c_e)
29549@@ -43,6 +45,7 @@ ENTRY(clear_page)
29550 leaq 64(%rdi),%rdi
29551 jnz .Lloop
29552 nop
29553+ pax_force_retaddr
29554 ret
29555 CFI_ENDPROC
29556 .Lclear_page_end:
29557@@ -58,7 +61,7 @@ ENDPROC(clear_page)
29558
29559 #include <asm/cpufeature.h>
29560
29561- .section .altinstr_replacement,"ax"
29562+ .section .altinstr_replacement,"a"
29563 1: .byte 0xeb /* jmp <disp8> */
29564 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
29565 2: .byte 0xeb /* jmp <disp8> */
29566diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
29567index 1e572c5..2a162cd 100644
29568--- a/arch/x86/lib/cmpxchg16b_emu.S
29569+++ b/arch/x86/lib/cmpxchg16b_emu.S
29570@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
29571
29572 popf
29573 mov $1, %al
29574+ pax_force_retaddr
29575 ret
29576
29577 not_same:
29578 popf
29579 xor %al,%al
29580+ pax_force_retaddr
29581 ret
29582
29583 CFI_ENDPROC
29584diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
29585index 176cca6..e0d658e 100644
29586--- a/arch/x86/lib/copy_page_64.S
29587+++ b/arch/x86/lib/copy_page_64.S
29588@@ -9,6 +9,7 @@ copy_page_rep:
29589 CFI_STARTPROC
29590 movl $4096/8, %ecx
29591 rep movsq
29592+ pax_force_retaddr
29593 ret
29594 CFI_ENDPROC
29595 ENDPROC(copy_page_rep)
29596@@ -24,8 +25,8 @@ ENTRY(copy_page)
29597 CFI_ADJUST_CFA_OFFSET 2*8
29598 movq %rbx, (%rsp)
29599 CFI_REL_OFFSET rbx, 0
29600- movq %r12, 1*8(%rsp)
29601- CFI_REL_OFFSET r12, 1*8
29602+ movq %r13, 1*8(%rsp)
29603+ CFI_REL_OFFSET r13, 1*8
29604
29605 movl $(4096/64)-5, %ecx
29606 .p2align 4
29607@@ -38,7 +39,7 @@ ENTRY(copy_page)
29608 movq 0x8*4(%rsi), %r9
29609 movq 0x8*5(%rsi), %r10
29610 movq 0x8*6(%rsi), %r11
29611- movq 0x8*7(%rsi), %r12
29612+ movq 0x8*7(%rsi), %r13
29613
29614 prefetcht0 5*64(%rsi)
29615
29616@@ -49,7 +50,7 @@ ENTRY(copy_page)
29617 movq %r9, 0x8*4(%rdi)
29618 movq %r10, 0x8*5(%rdi)
29619 movq %r11, 0x8*6(%rdi)
29620- movq %r12, 0x8*7(%rdi)
29621+ movq %r13, 0x8*7(%rdi)
29622
29623 leaq 64 (%rsi), %rsi
29624 leaq 64 (%rdi), %rdi
29625@@ -68,7 +69,7 @@ ENTRY(copy_page)
29626 movq 0x8*4(%rsi), %r9
29627 movq 0x8*5(%rsi), %r10
29628 movq 0x8*6(%rsi), %r11
29629- movq 0x8*7(%rsi), %r12
29630+ movq 0x8*7(%rsi), %r13
29631
29632 movq %rax, 0x8*0(%rdi)
29633 movq %rbx, 0x8*1(%rdi)
29634@@ -77,7 +78,7 @@ ENTRY(copy_page)
29635 movq %r9, 0x8*4(%rdi)
29636 movq %r10, 0x8*5(%rdi)
29637 movq %r11, 0x8*6(%rdi)
29638- movq %r12, 0x8*7(%rdi)
29639+ movq %r13, 0x8*7(%rdi)
29640
29641 leaq 64(%rdi), %rdi
29642 leaq 64(%rsi), %rsi
29643@@ -85,10 +86,11 @@ ENTRY(copy_page)
29644
29645 movq (%rsp), %rbx
29646 CFI_RESTORE rbx
29647- movq 1*8(%rsp), %r12
29648- CFI_RESTORE r12
29649+ movq 1*8(%rsp), %r13
29650+ CFI_RESTORE r13
29651 addq $2*8, %rsp
29652 CFI_ADJUST_CFA_OFFSET -2*8
29653+ pax_force_retaddr
29654 ret
29655 .Lcopy_page_end:
29656 CFI_ENDPROC
29657@@ -99,7 +101,7 @@ ENDPROC(copy_page)
29658
29659 #include <asm/cpufeature.h>
29660
29661- .section .altinstr_replacement,"ax"
29662+ .section .altinstr_replacement,"a"
29663 1: .byte 0xeb /* jmp <disp8> */
29664 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
29665 2:
29666diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
29667index dee945d..a84067b 100644
29668--- a/arch/x86/lib/copy_user_64.S
29669+++ b/arch/x86/lib/copy_user_64.S
29670@@ -18,31 +18,7 @@
29671 #include <asm/alternative-asm.h>
29672 #include <asm/asm.h>
29673 #include <asm/smap.h>
29674-
29675-/*
29676- * By placing feature2 after feature1 in altinstructions section, we logically
29677- * implement:
29678- * If CPU has feature2, jmp to alt2 is used
29679- * else if CPU has feature1, jmp to alt1 is used
29680- * else jmp to orig is used.
29681- */
29682- .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
29683-0:
29684- .byte 0xe9 /* 32bit jump */
29685- .long \orig-1f /* by default jump to orig */
29686-1:
29687- .section .altinstr_replacement,"ax"
29688-2: .byte 0xe9 /* near jump with 32bit immediate */
29689- .long \alt1-1b /* offset */ /* or alternatively to alt1 */
29690-3: .byte 0xe9 /* near jump with 32bit immediate */
29691- .long \alt2-1b /* offset */ /* or alternatively to alt2 */
29692- .previous
29693-
29694- .section .altinstructions,"a"
29695- altinstruction_entry 0b,2b,\feature1,5,5
29696- altinstruction_entry 0b,3b,\feature2,5,5
29697- .previous
29698- .endm
29699+#include <asm/pgtable.h>
29700
29701 .macro ALIGN_DESTINATION
29702 #ifdef FIX_ALIGNMENT
29703@@ -70,52 +46,6 @@
29704 #endif
29705 .endm
29706
29707-/* Standard copy_to_user with segment limit checking */
29708-ENTRY(_copy_to_user)
29709- CFI_STARTPROC
29710- GET_THREAD_INFO(%rax)
29711- movq %rdi,%rcx
29712- addq %rdx,%rcx
29713- jc bad_to_user
29714- cmpq TI_addr_limit(%rax),%rcx
29715- ja bad_to_user
29716- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29717- copy_user_generic_unrolled,copy_user_generic_string, \
29718- copy_user_enhanced_fast_string
29719- CFI_ENDPROC
29720-ENDPROC(_copy_to_user)
29721-
29722-/* Standard copy_from_user with segment limit checking */
29723-ENTRY(_copy_from_user)
29724- CFI_STARTPROC
29725- GET_THREAD_INFO(%rax)
29726- movq %rsi,%rcx
29727- addq %rdx,%rcx
29728- jc bad_from_user
29729- cmpq TI_addr_limit(%rax),%rcx
29730- ja bad_from_user
29731- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29732- copy_user_generic_unrolled,copy_user_generic_string, \
29733- copy_user_enhanced_fast_string
29734- CFI_ENDPROC
29735-ENDPROC(_copy_from_user)
29736-
29737- .section .fixup,"ax"
29738- /* must zero dest */
29739-ENTRY(bad_from_user)
29740-bad_from_user:
29741- CFI_STARTPROC
29742- movl %edx,%ecx
29743- xorl %eax,%eax
29744- rep
29745- stosb
29746-bad_to_user:
29747- movl %edx,%eax
29748- ret
29749- CFI_ENDPROC
29750-ENDPROC(bad_from_user)
29751- .previous
29752-
29753 /*
29754 * copy_user_generic_unrolled - memory copy with exception handling.
29755 * This version is for CPUs like P4 that don't have efficient micro
29756@@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
29757 */
29758 ENTRY(copy_user_generic_unrolled)
29759 CFI_STARTPROC
29760+ ASM_PAX_OPEN_USERLAND
29761 ASM_STAC
29762 cmpl $8,%edx
29763 jb 20f /* less then 8 bytes, go to byte copy loop */
29764@@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
29765 jnz 21b
29766 23: xor %eax,%eax
29767 ASM_CLAC
29768+ ASM_PAX_CLOSE_USERLAND
29769+ pax_force_retaddr
29770 ret
29771
29772 .section .fixup,"ax"
29773@@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
29774 */
29775 ENTRY(copy_user_generic_string)
29776 CFI_STARTPROC
29777+ ASM_PAX_OPEN_USERLAND
29778 ASM_STAC
29779 cmpl $8,%edx
29780 jb 2f /* less than 8 bytes, go to byte copy loop */
29781@@ -249,6 +183,8 @@ ENTRY(copy_user_generic_string)
29782 movsb
29783 xorl %eax,%eax
29784 ASM_CLAC
29785+ ASM_PAX_CLOSE_USERLAND
29786+ pax_force_retaddr
29787 ret
29788
29789 .section .fixup,"ax"
29790@@ -276,12 +212,15 @@ ENDPROC(copy_user_generic_string)
29791 */
29792 ENTRY(copy_user_enhanced_fast_string)
29793 CFI_STARTPROC
29794+ ASM_PAX_OPEN_USERLAND
29795 ASM_STAC
29796 movl %edx,%ecx
29797 1: rep
29798 movsb
29799 xorl %eax,%eax
29800 ASM_CLAC
29801+ ASM_PAX_CLOSE_USERLAND
29802+ pax_force_retaddr
29803 ret
29804
29805 .section .fixup,"ax"
29806diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
29807index 6a4f43c..c70fb52 100644
29808--- a/arch/x86/lib/copy_user_nocache_64.S
29809+++ b/arch/x86/lib/copy_user_nocache_64.S
29810@@ -8,6 +8,7 @@
29811
29812 #include <linux/linkage.h>
29813 #include <asm/dwarf2.h>
29814+#include <asm/alternative-asm.h>
29815
29816 #define FIX_ALIGNMENT 1
29817
29818@@ -16,6 +17,7 @@
29819 #include <asm/thread_info.h>
29820 #include <asm/asm.h>
29821 #include <asm/smap.h>
29822+#include <asm/pgtable.h>
29823
29824 .macro ALIGN_DESTINATION
29825 #ifdef FIX_ALIGNMENT
29826@@ -49,6 +51,16 @@
29827 */
29828 ENTRY(__copy_user_nocache)
29829 CFI_STARTPROC
29830+
29831+#ifdef CONFIG_PAX_MEMORY_UDEREF
29832+ mov pax_user_shadow_base,%rcx
29833+ cmp %rcx,%rsi
29834+ jae 1f
29835+ add %rcx,%rsi
29836+1:
29837+#endif
29838+
29839+ ASM_PAX_OPEN_USERLAND
29840 ASM_STAC
29841 cmpl $8,%edx
29842 jb 20f /* less then 8 bytes, go to byte copy loop */
29843@@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
29844 jnz 21b
29845 23: xorl %eax,%eax
29846 ASM_CLAC
29847+ ASM_PAX_CLOSE_USERLAND
29848 sfence
29849+ pax_force_retaddr
29850 ret
29851
29852 .section .fixup,"ax"
29853diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
29854index 2419d5f..fe52d0e 100644
29855--- a/arch/x86/lib/csum-copy_64.S
29856+++ b/arch/x86/lib/csum-copy_64.S
29857@@ -9,6 +9,7 @@
29858 #include <asm/dwarf2.h>
29859 #include <asm/errno.h>
29860 #include <asm/asm.h>
29861+#include <asm/alternative-asm.h>
29862
29863 /*
29864 * Checksum copy with exception handling.
29865@@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
29866 CFI_ADJUST_CFA_OFFSET 7*8
29867 movq %rbx, 2*8(%rsp)
29868 CFI_REL_OFFSET rbx, 2*8
29869- movq %r12, 3*8(%rsp)
29870- CFI_REL_OFFSET r12, 3*8
29871+ movq %r15, 3*8(%rsp)
29872+ CFI_REL_OFFSET r15, 3*8
29873 movq %r14, 4*8(%rsp)
29874 CFI_REL_OFFSET r14, 4*8
29875 movq %r13, 5*8(%rsp)
29876@@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
29877 movl %edx, %ecx
29878
29879 xorl %r9d, %r9d
29880- movq %rcx, %r12
29881+ movq %rcx, %r15
29882
29883- shrq $6, %r12
29884+ shrq $6, %r15
29885 jz .Lhandle_tail /* < 64 */
29886
29887 clc
29888
29889 /* main loop. clear in 64 byte blocks */
29890 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
29891- /* r11: temp3, rdx: temp4, r12 loopcnt */
29892+ /* r11: temp3, rdx: temp4, r15 loopcnt */
29893 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
29894 .p2align 4
29895 .Lloop:
29896@@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
29897 adcq %r14, %rax
29898 adcq %r13, %rax
29899
29900- decl %r12d
29901+ decl %r15d
29902
29903 dest
29904 movq %rbx, (%rsi)
29905@@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
29906 .Lende:
29907 movq 2*8(%rsp), %rbx
29908 CFI_RESTORE rbx
29909- movq 3*8(%rsp), %r12
29910- CFI_RESTORE r12
29911+ movq 3*8(%rsp), %r15
29912+ CFI_RESTORE r15
29913 movq 4*8(%rsp), %r14
29914 CFI_RESTORE r14
29915 movq 5*8(%rsp), %r13
29916@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
29917 CFI_RESTORE rbp
29918 addq $7*8, %rsp
29919 CFI_ADJUST_CFA_OFFSET -7*8
29920+ pax_force_retaddr
29921 ret
29922 CFI_RESTORE_STATE
29923
29924diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
29925index 7609e0e..b449b98 100644
29926--- a/arch/x86/lib/csum-wrappers_64.c
29927+++ b/arch/x86/lib/csum-wrappers_64.c
29928@@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
29929 len -= 2;
29930 }
29931 }
29932+ pax_open_userland();
29933 stac();
29934- isum = csum_partial_copy_generic((__force const void *)src,
29935+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
29936 dst, len, isum, errp, NULL);
29937 clac();
29938+ pax_close_userland();
29939 if (unlikely(*errp))
29940 goto out_err;
29941
29942@@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
29943 }
29944
29945 *errp = 0;
29946+ pax_open_userland();
29947 stac();
29948- ret = csum_partial_copy_generic(src, (void __force *)dst,
29949+ ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
29950 len, isum, NULL, errp);
29951 clac();
29952+ pax_close_userland();
29953 return ret;
29954 }
29955 EXPORT_SYMBOL(csum_partial_copy_to_user);
29956diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
29957index a451235..1daa956 100644
29958--- a/arch/x86/lib/getuser.S
29959+++ b/arch/x86/lib/getuser.S
29960@@ -33,17 +33,40 @@
29961 #include <asm/thread_info.h>
29962 #include <asm/asm.h>
29963 #include <asm/smap.h>
29964+#include <asm/segment.h>
29965+#include <asm/pgtable.h>
29966+#include <asm/alternative-asm.h>
29967+
29968+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
29969+#define __copyuser_seg gs;
29970+#else
29971+#define __copyuser_seg
29972+#endif
29973
29974 .text
29975 ENTRY(__get_user_1)
29976 CFI_STARTPROC
29977+
29978+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29979 GET_THREAD_INFO(%_ASM_DX)
29980 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29981 jae bad_get_user
29982 ASM_STAC
29983-1: movzbl (%_ASM_AX),%edx
29984+
29985+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29986+ mov pax_user_shadow_base,%_ASM_DX
29987+ cmp %_ASM_DX,%_ASM_AX
29988+ jae 1234f
29989+ add %_ASM_DX,%_ASM_AX
29990+1234:
29991+#endif
29992+
29993+#endif
29994+
29995+1: __copyuser_seg movzbl (%_ASM_AX),%edx
29996 xor %eax,%eax
29997 ASM_CLAC
29998+ pax_force_retaddr
29999 ret
30000 CFI_ENDPROC
30001 ENDPROC(__get_user_1)
30002@@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
30003 ENTRY(__get_user_2)
30004 CFI_STARTPROC
30005 add $1,%_ASM_AX
30006+
30007+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30008 jc bad_get_user
30009 GET_THREAD_INFO(%_ASM_DX)
30010 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30011 jae bad_get_user
30012 ASM_STAC
30013-2: movzwl -1(%_ASM_AX),%edx
30014+
30015+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30016+ mov pax_user_shadow_base,%_ASM_DX
30017+ cmp %_ASM_DX,%_ASM_AX
30018+ jae 1234f
30019+ add %_ASM_DX,%_ASM_AX
30020+1234:
30021+#endif
30022+
30023+#endif
30024+
30025+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
30026 xor %eax,%eax
30027 ASM_CLAC
30028+ pax_force_retaddr
30029 ret
30030 CFI_ENDPROC
30031 ENDPROC(__get_user_2)
30032@@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
30033 ENTRY(__get_user_4)
30034 CFI_STARTPROC
30035 add $3,%_ASM_AX
30036+
30037+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30038 jc bad_get_user
30039 GET_THREAD_INFO(%_ASM_DX)
30040 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30041 jae bad_get_user
30042 ASM_STAC
30043-3: movl -3(%_ASM_AX),%edx
30044+
30045+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30046+ mov pax_user_shadow_base,%_ASM_DX
30047+ cmp %_ASM_DX,%_ASM_AX
30048+ jae 1234f
30049+ add %_ASM_DX,%_ASM_AX
30050+1234:
30051+#endif
30052+
30053+#endif
30054+
30055+3: __copyuser_seg movl -3(%_ASM_AX),%edx
30056 xor %eax,%eax
30057 ASM_CLAC
30058+ pax_force_retaddr
30059 ret
30060 CFI_ENDPROC
30061 ENDPROC(__get_user_4)
30062@@ -86,10 +137,20 @@ ENTRY(__get_user_8)
30063 GET_THREAD_INFO(%_ASM_DX)
30064 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30065 jae bad_get_user
30066+
30067+#ifdef CONFIG_PAX_MEMORY_UDEREF
30068+ mov pax_user_shadow_base,%_ASM_DX
30069+ cmp %_ASM_DX,%_ASM_AX
30070+ jae 1234f
30071+ add %_ASM_DX,%_ASM_AX
30072+1234:
30073+#endif
30074+
30075 ASM_STAC
30076 4: movq -7(%_ASM_AX),%rdx
30077 xor %eax,%eax
30078 ASM_CLAC
30079+ pax_force_retaddr
30080 ret
30081 #else
30082 add $7,%_ASM_AX
30083@@ -98,10 +159,11 @@ ENTRY(__get_user_8)
30084 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30085 jae bad_get_user_8
30086 ASM_STAC
30087-4: movl -7(%_ASM_AX),%edx
30088-5: movl -3(%_ASM_AX),%ecx
30089+4: __copyuser_seg movl -7(%_ASM_AX),%edx
30090+5: __copyuser_seg movl -3(%_ASM_AX),%ecx
30091 xor %eax,%eax
30092 ASM_CLAC
30093+ pax_force_retaddr
30094 ret
30095 #endif
30096 CFI_ENDPROC
30097@@ -113,6 +175,7 @@ bad_get_user:
30098 xor %edx,%edx
30099 mov $(-EFAULT),%_ASM_AX
30100 ASM_CLAC
30101+ pax_force_retaddr
30102 ret
30103 CFI_ENDPROC
30104 END(bad_get_user)
30105@@ -124,6 +187,7 @@ bad_get_user_8:
30106 xor %ecx,%ecx
30107 mov $(-EFAULT),%_ASM_AX
30108 ASM_CLAC
30109+ pax_force_retaddr
30110 ret
30111 CFI_ENDPROC
30112 END(bad_get_user_8)
30113diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
30114index 54fcffe..7be149e 100644
30115--- a/arch/x86/lib/insn.c
30116+++ b/arch/x86/lib/insn.c
30117@@ -20,8 +20,10 @@
30118
30119 #ifdef __KERNEL__
30120 #include <linux/string.h>
30121+#include <asm/pgtable_types.h>
30122 #else
30123 #include <string.h>
30124+#define ktla_ktva(addr) addr
30125 #endif
30126 #include <asm/inat.h>
30127 #include <asm/insn.h>
30128@@ -53,8 +55,8 @@
30129 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
30130 {
30131 memset(insn, 0, sizeof(*insn));
30132- insn->kaddr = kaddr;
30133- insn->next_byte = kaddr;
30134+ insn->kaddr = ktla_ktva(kaddr);
30135+ insn->next_byte = ktla_ktva(kaddr);
30136 insn->x86_64 = x86_64 ? 1 : 0;
30137 insn->opnd_bytes = 4;
30138 if (x86_64)
30139diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
30140index 05a95e7..326f2fa 100644
30141--- a/arch/x86/lib/iomap_copy_64.S
30142+++ b/arch/x86/lib/iomap_copy_64.S
30143@@ -17,6 +17,7 @@
30144
30145 #include <linux/linkage.h>
30146 #include <asm/dwarf2.h>
30147+#include <asm/alternative-asm.h>
30148
30149 /*
30150 * override generic version in lib/iomap_copy.c
30151@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
30152 CFI_STARTPROC
30153 movl %edx,%ecx
30154 rep movsd
30155+ pax_force_retaddr
30156 ret
30157 CFI_ENDPROC
30158 ENDPROC(__iowrite32_copy)
30159diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
30160index 56313a3..0db417e 100644
30161--- a/arch/x86/lib/memcpy_64.S
30162+++ b/arch/x86/lib/memcpy_64.S
30163@@ -24,7 +24,7 @@
30164 * This gets patched over the unrolled variant (below) via the
30165 * alternative instructions framework:
30166 */
30167- .section .altinstr_replacement, "ax", @progbits
30168+ .section .altinstr_replacement, "a", @progbits
30169 .Lmemcpy_c:
30170 movq %rdi, %rax
30171 movq %rdx, %rcx
30172@@ -33,6 +33,7 @@
30173 rep movsq
30174 movl %edx, %ecx
30175 rep movsb
30176+ pax_force_retaddr
30177 ret
30178 .Lmemcpy_e:
30179 .previous
30180@@ -44,11 +45,12 @@
30181 * This gets patched over the unrolled variant (below) via the
30182 * alternative instructions framework:
30183 */
30184- .section .altinstr_replacement, "ax", @progbits
30185+ .section .altinstr_replacement, "a", @progbits
30186 .Lmemcpy_c_e:
30187 movq %rdi, %rax
30188 movq %rdx, %rcx
30189 rep movsb
30190+ pax_force_retaddr
30191 ret
30192 .Lmemcpy_e_e:
30193 .previous
30194@@ -136,6 +138,7 @@ ENTRY(memcpy)
30195 movq %r9, 1*8(%rdi)
30196 movq %r10, -2*8(%rdi, %rdx)
30197 movq %r11, -1*8(%rdi, %rdx)
30198+ pax_force_retaddr
30199 retq
30200 .p2align 4
30201 .Lless_16bytes:
30202@@ -148,6 +151,7 @@ ENTRY(memcpy)
30203 movq -1*8(%rsi, %rdx), %r9
30204 movq %r8, 0*8(%rdi)
30205 movq %r9, -1*8(%rdi, %rdx)
30206+ pax_force_retaddr
30207 retq
30208 .p2align 4
30209 .Lless_8bytes:
30210@@ -161,6 +165,7 @@ ENTRY(memcpy)
30211 movl -4(%rsi, %rdx), %r8d
30212 movl %ecx, (%rdi)
30213 movl %r8d, -4(%rdi, %rdx)
30214+ pax_force_retaddr
30215 retq
30216 .p2align 4
30217 .Lless_3bytes:
30218@@ -179,6 +184,7 @@ ENTRY(memcpy)
30219 movb %cl, (%rdi)
30220
30221 .Lend:
30222+ pax_force_retaddr
30223 retq
30224 CFI_ENDPROC
30225 ENDPROC(memcpy)
30226diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
30227index 65268a6..dd1de11 100644
30228--- a/arch/x86/lib/memmove_64.S
30229+++ b/arch/x86/lib/memmove_64.S
30230@@ -202,14 +202,16 @@ ENTRY(memmove)
30231 movb (%rsi), %r11b
30232 movb %r11b, (%rdi)
30233 13:
30234+ pax_force_retaddr
30235 retq
30236 CFI_ENDPROC
30237
30238- .section .altinstr_replacement,"ax"
30239+ .section .altinstr_replacement,"a"
30240 .Lmemmove_begin_forward_efs:
30241 /* Forward moving data. */
30242 movq %rdx, %rcx
30243 rep movsb
30244+ pax_force_retaddr
30245 retq
30246 .Lmemmove_end_forward_efs:
30247 .previous
30248diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
30249index 2dcb380..2eb79fe 100644
30250--- a/arch/x86/lib/memset_64.S
30251+++ b/arch/x86/lib/memset_64.S
30252@@ -16,7 +16,7 @@
30253 *
30254 * rax original destination
30255 */
30256- .section .altinstr_replacement, "ax", @progbits
30257+ .section .altinstr_replacement, "a", @progbits
30258 .Lmemset_c:
30259 movq %rdi,%r9
30260 movq %rdx,%rcx
30261@@ -30,6 +30,7 @@
30262 movl %edx,%ecx
30263 rep stosb
30264 movq %r9,%rax
30265+ pax_force_retaddr
30266 ret
30267 .Lmemset_e:
30268 .previous
30269@@ -45,13 +46,14 @@
30270 *
30271 * rax original destination
30272 */
30273- .section .altinstr_replacement, "ax", @progbits
30274+ .section .altinstr_replacement, "a", @progbits
30275 .Lmemset_c_e:
30276 movq %rdi,%r9
30277 movb %sil,%al
30278 movq %rdx,%rcx
30279 rep stosb
30280 movq %r9,%rax
30281+ pax_force_retaddr
30282 ret
30283 .Lmemset_e_e:
30284 .previous
30285@@ -118,6 +120,7 @@ ENTRY(__memset)
30286
30287 .Lende:
30288 movq %r10,%rax
30289+ pax_force_retaddr
30290 ret
30291
30292 CFI_RESTORE_STATE
30293diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
30294index c9f2d9b..e7fd2c0 100644
30295--- a/arch/x86/lib/mmx_32.c
30296+++ b/arch/x86/lib/mmx_32.c
30297@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30298 {
30299 void *p;
30300 int i;
30301+ unsigned long cr0;
30302
30303 if (unlikely(in_interrupt()))
30304 return __memcpy(to, from, len);
30305@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30306 kernel_fpu_begin();
30307
30308 __asm__ __volatile__ (
30309- "1: prefetch (%0)\n" /* This set is 28 bytes */
30310- " prefetch 64(%0)\n"
30311- " prefetch 128(%0)\n"
30312- " prefetch 192(%0)\n"
30313- " prefetch 256(%0)\n"
30314+ "1: prefetch (%1)\n" /* This set is 28 bytes */
30315+ " prefetch 64(%1)\n"
30316+ " prefetch 128(%1)\n"
30317+ " prefetch 192(%1)\n"
30318+ " prefetch 256(%1)\n"
30319 "2: \n"
30320 ".section .fixup, \"ax\"\n"
30321- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30322+ "3: \n"
30323+
30324+#ifdef CONFIG_PAX_KERNEXEC
30325+ " movl %%cr0, %0\n"
30326+ " movl %0, %%eax\n"
30327+ " andl $0xFFFEFFFF, %%eax\n"
30328+ " movl %%eax, %%cr0\n"
30329+#endif
30330+
30331+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30332+
30333+#ifdef CONFIG_PAX_KERNEXEC
30334+ " movl %0, %%cr0\n"
30335+#endif
30336+
30337 " jmp 2b\n"
30338 ".previous\n"
30339 _ASM_EXTABLE(1b, 3b)
30340- : : "r" (from));
30341+ : "=&r" (cr0) : "r" (from) : "ax");
30342
30343 for ( ; i > 5; i--) {
30344 __asm__ __volatile__ (
30345- "1: prefetch 320(%0)\n"
30346- "2: movq (%0), %%mm0\n"
30347- " movq 8(%0), %%mm1\n"
30348- " movq 16(%0), %%mm2\n"
30349- " movq 24(%0), %%mm3\n"
30350- " movq %%mm0, (%1)\n"
30351- " movq %%mm1, 8(%1)\n"
30352- " movq %%mm2, 16(%1)\n"
30353- " movq %%mm3, 24(%1)\n"
30354- " movq 32(%0), %%mm0\n"
30355- " movq 40(%0), %%mm1\n"
30356- " movq 48(%0), %%mm2\n"
30357- " movq 56(%0), %%mm3\n"
30358- " movq %%mm0, 32(%1)\n"
30359- " movq %%mm1, 40(%1)\n"
30360- " movq %%mm2, 48(%1)\n"
30361- " movq %%mm3, 56(%1)\n"
30362+ "1: prefetch 320(%1)\n"
30363+ "2: movq (%1), %%mm0\n"
30364+ " movq 8(%1), %%mm1\n"
30365+ " movq 16(%1), %%mm2\n"
30366+ " movq 24(%1), %%mm3\n"
30367+ " movq %%mm0, (%2)\n"
30368+ " movq %%mm1, 8(%2)\n"
30369+ " movq %%mm2, 16(%2)\n"
30370+ " movq %%mm3, 24(%2)\n"
30371+ " movq 32(%1), %%mm0\n"
30372+ " movq 40(%1), %%mm1\n"
30373+ " movq 48(%1), %%mm2\n"
30374+ " movq 56(%1), %%mm3\n"
30375+ " movq %%mm0, 32(%2)\n"
30376+ " movq %%mm1, 40(%2)\n"
30377+ " movq %%mm2, 48(%2)\n"
30378+ " movq %%mm3, 56(%2)\n"
30379 ".section .fixup, \"ax\"\n"
30380- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30381+ "3:\n"
30382+
30383+#ifdef CONFIG_PAX_KERNEXEC
30384+ " movl %%cr0, %0\n"
30385+ " movl %0, %%eax\n"
30386+ " andl $0xFFFEFFFF, %%eax\n"
30387+ " movl %%eax, %%cr0\n"
30388+#endif
30389+
30390+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30391+
30392+#ifdef CONFIG_PAX_KERNEXEC
30393+ " movl %0, %%cr0\n"
30394+#endif
30395+
30396 " jmp 2b\n"
30397 ".previous\n"
30398 _ASM_EXTABLE(1b, 3b)
30399- : : "r" (from), "r" (to) : "memory");
30400+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30401
30402 from += 64;
30403 to += 64;
30404@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
30405 static void fast_copy_page(void *to, void *from)
30406 {
30407 int i;
30408+ unsigned long cr0;
30409
30410 kernel_fpu_begin();
30411
30412@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
30413 * but that is for later. -AV
30414 */
30415 __asm__ __volatile__(
30416- "1: prefetch (%0)\n"
30417- " prefetch 64(%0)\n"
30418- " prefetch 128(%0)\n"
30419- " prefetch 192(%0)\n"
30420- " prefetch 256(%0)\n"
30421+ "1: prefetch (%1)\n"
30422+ " prefetch 64(%1)\n"
30423+ " prefetch 128(%1)\n"
30424+ " prefetch 192(%1)\n"
30425+ " prefetch 256(%1)\n"
30426 "2: \n"
30427 ".section .fixup, \"ax\"\n"
30428- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30429+ "3: \n"
30430+
30431+#ifdef CONFIG_PAX_KERNEXEC
30432+ " movl %%cr0, %0\n"
30433+ " movl %0, %%eax\n"
30434+ " andl $0xFFFEFFFF, %%eax\n"
30435+ " movl %%eax, %%cr0\n"
30436+#endif
30437+
30438+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30439+
30440+#ifdef CONFIG_PAX_KERNEXEC
30441+ " movl %0, %%cr0\n"
30442+#endif
30443+
30444 " jmp 2b\n"
30445 ".previous\n"
30446- _ASM_EXTABLE(1b, 3b) : : "r" (from));
30447+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30448
30449 for (i = 0; i < (4096-320)/64; i++) {
30450 __asm__ __volatile__ (
30451- "1: prefetch 320(%0)\n"
30452- "2: movq (%0), %%mm0\n"
30453- " movntq %%mm0, (%1)\n"
30454- " movq 8(%0), %%mm1\n"
30455- " movntq %%mm1, 8(%1)\n"
30456- " movq 16(%0), %%mm2\n"
30457- " movntq %%mm2, 16(%1)\n"
30458- " movq 24(%0), %%mm3\n"
30459- " movntq %%mm3, 24(%1)\n"
30460- " movq 32(%0), %%mm4\n"
30461- " movntq %%mm4, 32(%1)\n"
30462- " movq 40(%0), %%mm5\n"
30463- " movntq %%mm5, 40(%1)\n"
30464- " movq 48(%0), %%mm6\n"
30465- " movntq %%mm6, 48(%1)\n"
30466- " movq 56(%0), %%mm7\n"
30467- " movntq %%mm7, 56(%1)\n"
30468+ "1: prefetch 320(%1)\n"
30469+ "2: movq (%1), %%mm0\n"
30470+ " movntq %%mm0, (%2)\n"
30471+ " movq 8(%1), %%mm1\n"
30472+ " movntq %%mm1, 8(%2)\n"
30473+ " movq 16(%1), %%mm2\n"
30474+ " movntq %%mm2, 16(%2)\n"
30475+ " movq 24(%1), %%mm3\n"
30476+ " movntq %%mm3, 24(%2)\n"
30477+ " movq 32(%1), %%mm4\n"
30478+ " movntq %%mm4, 32(%2)\n"
30479+ " movq 40(%1), %%mm5\n"
30480+ " movntq %%mm5, 40(%2)\n"
30481+ " movq 48(%1), %%mm6\n"
30482+ " movntq %%mm6, 48(%2)\n"
30483+ " movq 56(%1), %%mm7\n"
30484+ " movntq %%mm7, 56(%2)\n"
30485 ".section .fixup, \"ax\"\n"
30486- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30487+ "3:\n"
30488+
30489+#ifdef CONFIG_PAX_KERNEXEC
30490+ " movl %%cr0, %0\n"
30491+ " movl %0, %%eax\n"
30492+ " andl $0xFFFEFFFF, %%eax\n"
30493+ " movl %%eax, %%cr0\n"
30494+#endif
30495+
30496+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30497+
30498+#ifdef CONFIG_PAX_KERNEXEC
30499+ " movl %0, %%cr0\n"
30500+#endif
30501+
30502 " jmp 2b\n"
30503 ".previous\n"
30504- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
30505+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30506
30507 from += 64;
30508 to += 64;
30509@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
30510 static void fast_copy_page(void *to, void *from)
30511 {
30512 int i;
30513+ unsigned long cr0;
30514
30515 kernel_fpu_begin();
30516
30517 __asm__ __volatile__ (
30518- "1: prefetch (%0)\n"
30519- " prefetch 64(%0)\n"
30520- " prefetch 128(%0)\n"
30521- " prefetch 192(%0)\n"
30522- " prefetch 256(%0)\n"
30523+ "1: prefetch (%1)\n"
30524+ " prefetch 64(%1)\n"
30525+ " prefetch 128(%1)\n"
30526+ " prefetch 192(%1)\n"
30527+ " prefetch 256(%1)\n"
30528 "2: \n"
30529 ".section .fixup, \"ax\"\n"
30530- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30531+ "3: \n"
30532+
30533+#ifdef CONFIG_PAX_KERNEXEC
30534+ " movl %%cr0, %0\n"
30535+ " movl %0, %%eax\n"
30536+ " andl $0xFFFEFFFF, %%eax\n"
30537+ " movl %%eax, %%cr0\n"
30538+#endif
30539+
30540+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30541+
30542+#ifdef CONFIG_PAX_KERNEXEC
30543+ " movl %0, %%cr0\n"
30544+#endif
30545+
30546 " jmp 2b\n"
30547 ".previous\n"
30548- _ASM_EXTABLE(1b, 3b) : : "r" (from));
30549+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30550
30551 for (i = 0; i < 4096/64; i++) {
30552 __asm__ __volatile__ (
30553- "1: prefetch 320(%0)\n"
30554- "2: movq (%0), %%mm0\n"
30555- " movq 8(%0), %%mm1\n"
30556- " movq 16(%0), %%mm2\n"
30557- " movq 24(%0), %%mm3\n"
30558- " movq %%mm0, (%1)\n"
30559- " movq %%mm1, 8(%1)\n"
30560- " movq %%mm2, 16(%1)\n"
30561- " movq %%mm3, 24(%1)\n"
30562- " movq 32(%0), %%mm0\n"
30563- " movq 40(%0), %%mm1\n"
30564- " movq 48(%0), %%mm2\n"
30565- " movq 56(%0), %%mm3\n"
30566- " movq %%mm0, 32(%1)\n"
30567- " movq %%mm1, 40(%1)\n"
30568- " movq %%mm2, 48(%1)\n"
30569- " movq %%mm3, 56(%1)\n"
30570+ "1: prefetch 320(%1)\n"
30571+ "2: movq (%1), %%mm0\n"
30572+ " movq 8(%1), %%mm1\n"
30573+ " movq 16(%1), %%mm2\n"
30574+ " movq 24(%1), %%mm3\n"
30575+ " movq %%mm0, (%2)\n"
30576+ " movq %%mm1, 8(%2)\n"
30577+ " movq %%mm2, 16(%2)\n"
30578+ " movq %%mm3, 24(%2)\n"
30579+ " movq 32(%1), %%mm0\n"
30580+ " movq 40(%1), %%mm1\n"
30581+ " movq 48(%1), %%mm2\n"
30582+ " movq 56(%1), %%mm3\n"
30583+ " movq %%mm0, 32(%2)\n"
30584+ " movq %%mm1, 40(%2)\n"
30585+ " movq %%mm2, 48(%2)\n"
30586+ " movq %%mm3, 56(%2)\n"
30587 ".section .fixup, \"ax\"\n"
30588- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30589+ "3:\n"
30590+
30591+#ifdef CONFIG_PAX_KERNEXEC
30592+ " movl %%cr0, %0\n"
30593+ " movl %0, %%eax\n"
30594+ " andl $0xFFFEFFFF, %%eax\n"
30595+ " movl %%eax, %%cr0\n"
30596+#endif
30597+
30598+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30599+
30600+#ifdef CONFIG_PAX_KERNEXEC
30601+ " movl %0, %%cr0\n"
30602+#endif
30603+
30604 " jmp 2b\n"
30605 ".previous\n"
30606 _ASM_EXTABLE(1b, 3b)
30607- : : "r" (from), "r" (to) : "memory");
30608+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30609
30610 from += 64;
30611 to += 64;
30612diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
30613index f6d13ee..d789440 100644
30614--- a/arch/x86/lib/msr-reg.S
30615+++ b/arch/x86/lib/msr-reg.S
30616@@ -3,6 +3,7 @@
30617 #include <asm/dwarf2.h>
30618 #include <asm/asm.h>
30619 #include <asm/msr.h>
30620+#include <asm/alternative-asm.h>
30621
30622 #ifdef CONFIG_X86_64
30623 /*
30624@@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
30625 movl %edi, 28(%r10)
30626 popq_cfi %rbp
30627 popq_cfi %rbx
30628+ pax_force_retaddr
30629 ret
30630 3:
30631 CFI_RESTORE_STATE
30632diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
30633index fc6ba17..d4d989d 100644
30634--- a/arch/x86/lib/putuser.S
30635+++ b/arch/x86/lib/putuser.S
30636@@ -16,7 +16,9 @@
30637 #include <asm/errno.h>
30638 #include <asm/asm.h>
30639 #include <asm/smap.h>
30640-
30641+#include <asm/segment.h>
30642+#include <asm/pgtable.h>
30643+#include <asm/alternative-asm.h>
30644
30645 /*
30646 * __put_user_X
30647@@ -30,57 +32,125 @@
30648 * as they get called from within inline assembly.
30649 */
30650
30651-#define ENTER CFI_STARTPROC ; \
30652- GET_THREAD_INFO(%_ASM_BX)
30653-#define EXIT ASM_CLAC ; \
30654- ret ; \
30655+#define ENTER CFI_STARTPROC
30656+#define EXIT ASM_CLAC ; \
30657+ pax_force_retaddr ; \
30658+ ret ; \
30659 CFI_ENDPROC
30660
30661+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30662+#define _DEST %_ASM_CX,%_ASM_BX
30663+#else
30664+#define _DEST %_ASM_CX
30665+#endif
30666+
30667+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30668+#define __copyuser_seg gs;
30669+#else
30670+#define __copyuser_seg
30671+#endif
30672+
30673 .text
30674 ENTRY(__put_user_1)
30675 ENTER
30676+
30677+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30678+ GET_THREAD_INFO(%_ASM_BX)
30679 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
30680 jae bad_put_user
30681 ASM_STAC
30682-1: movb %al,(%_ASM_CX)
30683+
30684+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30685+ mov pax_user_shadow_base,%_ASM_BX
30686+ cmp %_ASM_BX,%_ASM_CX
30687+ jb 1234f
30688+ xor %ebx,%ebx
30689+1234:
30690+#endif
30691+
30692+#endif
30693+
30694+1: __copyuser_seg movb %al,(_DEST)
30695 xor %eax,%eax
30696 EXIT
30697 ENDPROC(__put_user_1)
30698
30699 ENTRY(__put_user_2)
30700 ENTER
30701+
30702+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30703+ GET_THREAD_INFO(%_ASM_BX)
30704 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30705 sub $1,%_ASM_BX
30706 cmp %_ASM_BX,%_ASM_CX
30707 jae bad_put_user
30708 ASM_STAC
30709-2: movw %ax,(%_ASM_CX)
30710+
30711+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30712+ mov pax_user_shadow_base,%_ASM_BX
30713+ cmp %_ASM_BX,%_ASM_CX
30714+ jb 1234f
30715+ xor %ebx,%ebx
30716+1234:
30717+#endif
30718+
30719+#endif
30720+
30721+2: __copyuser_seg movw %ax,(_DEST)
30722 xor %eax,%eax
30723 EXIT
30724 ENDPROC(__put_user_2)
30725
30726 ENTRY(__put_user_4)
30727 ENTER
30728+
30729+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30730+ GET_THREAD_INFO(%_ASM_BX)
30731 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30732 sub $3,%_ASM_BX
30733 cmp %_ASM_BX,%_ASM_CX
30734 jae bad_put_user
30735 ASM_STAC
30736-3: movl %eax,(%_ASM_CX)
30737+
30738+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30739+ mov pax_user_shadow_base,%_ASM_BX
30740+ cmp %_ASM_BX,%_ASM_CX
30741+ jb 1234f
30742+ xor %ebx,%ebx
30743+1234:
30744+#endif
30745+
30746+#endif
30747+
30748+3: __copyuser_seg movl %eax,(_DEST)
30749 xor %eax,%eax
30750 EXIT
30751 ENDPROC(__put_user_4)
30752
30753 ENTRY(__put_user_8)
30754 ENTER
30755+
30756+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30757+ GET_THREAD_INFO(%_ASM_BX)
30758 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30759 sub $7,%_ASM_BX
30760 cmp %_ASM_BX,%_ASM_CX
30761 jae bad_put_user
30762 ASM_STAC
30763-4: mov %_ASM_AX,(%_ASM_CX)
30764+
30765+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30766+ mov pax_user_shadow_base,%_ASM_BX
30767+ cmp %_ASM_BX,%_ASM_CX
30768+ jb 1234f
30769+ xor %ebx,%ebx
30770+1234:
30771+#endif
30772+
30773+#endif
30774+
30775+4: __copyuser_seg mov %_ASM_AX,(_DEST)
30776 #ifdef CONFIG_X86_32
30777-5: movl %edx,4(%_ASM_CX)
30778+5: __copyuser_seg movl %edx,4(_DEST)
30779 #endif
30780 xor %eax,%eax
30781 EXIT
30782diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
30783index 1cad221..de671ee 100644
30784--- a/arch/x86/lib/rwlock.S
30785+++ b/arch/x86/lib/rwlock.S
30786@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
30787 FRAME
30788 0: LOCK_PREFIX
30789 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30790+
30791+#ifdef CONFIG_PAX_REFCOUNT
30792+ jno 1234f
30793+ LOCK_PREFIX
30794+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30795+ int $4
30796+1234:
30797+ _ASM_EXTABLE(1234b, 1234b)
30798+#endif
30799+
30800 1: rep; nop
30801 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
30802 jne 1b
30803 LOCK_PREFIX
30804 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30805+
30806+#ifdef CONFIG_PAX_REFCOUNT
30807+ jno 1234f
30808+ LOCK_PREFIX
30809+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30810+ int $4
30811+1234:
30812+ _ASM_EXTABLE(1234b, 1234b)
30813+#endif
30814+
30815 jnz 0b
30816 ENDFRAME
30817+ pax_force_retaddr
30818 ret
30819 CFI_ENDPROC
30820 END(__write_lock_failed)
30821@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
30822 FRAME
30823 0: LOCK_PREFIX
30824 READ_LOCK_SIZE(inc) (%__lock_ptr)
30825+
30826+#ifdef CONFIG_PAX_REFCOUNT
30827+ jno 1234f
30828+ LOCK_PREFIX
30829+ READ_LOCK_SIZE(dec) (%__lock_ptr)
30830+ int $4
30831+1234:
30832+ _ASM_EXTABLE(1234b, 1234b)
30833+#endif
30834+
30835 1: rep; nop
30836 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
30837 js 1b
30838 LOCK_PREFIX
30839 READ_LOCK_SIZE(dec) (%__lock_ptr)
30840+
30841+#ifdef CONFIG_PAX_REFCOUNT
30842+ jno 1234f
30843+ LOCK_PREFIX
30844+ READ_LOCK_SIZE(inc) (%__lock_ptr)
30845+ int $4
30846+1234:
30847+ _ASM_EXTABLE(1234b, 1234b)
30848+#endif
30849+
30850 js 0b
30851 ENDFRAME
30852+ pax_force_retaddr
30853 ret
30854 CFI_ENDPROC
30855 END(__read_lock_failed)
30856diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
30857index 5dff5f0..cadebf4 100644
30858--- a/arch/x86/lib/rwsem.S
30859+++ b/arch/x86/lib/rwsem.S
30860@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
30861 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30862 CFI_RESTORE __ASM_REG(dx)
30863 restore_common_regs
30864+ pax_force_retaddr
30865 ret
30866 CFI_ENDPROC
30867 ENDPROC(call_rwsem_down_read_failed)
30868@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
30869 movq %rax,%rdi
30870 call rwsem_down_write_failed
30871 restore_common_regs
30872+ pax_force_retaddr
30873 ret
30874 CFI_ENDPROC
30875 ENDPROC(call_rwsem_down_write_failed)
30876@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
30877 movq %rax,%rdi
30878 call rwsem_wake
30879 restore_common_regs
30880-1: ret
30881+1: pax_force_retaddr
30882+ ret
30883 CFI_ENDPROC
30884 ENDPROC(call_rwsem_wake)
30885
30886@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
30887 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30888 CFI_RESTORE __ASM_REG(dx)
30889 restore_common_regs
30890+ pax_force_retaddr
30891 ret
30892 CFI_ENDPROC
30893 ENDPROC(call_rwsem_downgrade_wake)
30894diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
30895index a63efd6..8149fbe 100644
30896--- a/arch/x86/lib/thunk_64.S
30897+++ b/arch/x86/lib/thunk_64.S
30898@@ -8,6 +8,7 @@
30899 #include <linux/linkage.h>
30900 #include <asm/dwarf2.h>
30901 #include <asm/calling.h>
30902+#include <asm/alternative-asm.h>
30903
30904 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
30905 .macro THUNK name, func, put_ret_addr_in_rdi=0
30906@@ -15,11 +16,11 @@
30907 \name:
30908 CFI_STARTPROC
30909
30910- /* this one pushes 9 elems, the next one would be %rIP */
30911- SAVE_ARGS
30912+ /* this one pushes 15+1 elems, the next one would be %rIP */
30913+ SAVE_ARGS 8
30914
30915 .if \put_ret_addr_in_rdi
30916- movq_cfi_restore 9*8, rdi
30917+ movq_cfi_restore RIP, rdi
30918 .endif
30919
30920 call \func
30921@@ -38,8 +39,9 @@
30922
30923 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
30924 CFI_STARTPROC
30925- SAVE_ARGS
30926+ SAVE_ARGS 8
30927 restore:
30928- RESTORE_ARGS
30929+ RESTORE_ARGS 1,8
30930+ pax_force_retaddr
30931 ret
30932 CFI_ENDPROC
30933diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
30934index e2f5e21..4b22130 100644
30935--- a/arch/x86/lib/usercopy_32.c
30936+++ b/arch/x86/lib/usercopy_32.c
30937@@ -42,11 +42,13 @@ do { \
30938 int __d0; \
30939 might_fault(); \
30940 __asm__ __volatile__( \
30941+ __COPYUSER_SET_ES \
30942 ASM_STAC "\n" \
30943 "0: rep; stosl\n" \
30944 " movl %2,%0\n" \
30945 "1: rep; stosb\n" \
30946 "2: " ASM_CLAC "\n" \
30947+ __COPYUSER_RESTORE_ES \
30948 ".section .fixup,\"ax\"\n" \
30949 "3: lea 0(%2,%0,4),%0\n" \
30950 " jmp 2b\n" \
30951@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
30952
30953 #ifdef CONFIG_X86_INTEL_USERCOPY
30954 static unsigned long
30955-__copy_user_intel(void __user *to, const void *from, unsigned long size)
30956+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
30957 {
30958 int d0, d1;
30959 __asm__ __volatile__(
30960@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30961 " .align 2,0x90\n"
30962 "3: movl 0(%4), %%eax\n"
30963 "4: movl 4(%4), %%edx\n"
30964- "5: movl %%eax, 0(%3)\n"
30965- "6: movl %%edx, 4(%3)\n"
30966+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
30967+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
30968 "7: movl 8(%4), %%eax\n"
30969 "8: movl 12(%4),%%edx\n"
30970- "9: movl %%eax, 8(%3)\n"
30971- "10: movl %%edx, 12(%3)\n"
30972+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
30973+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
30974 "11: movl 16(%4), %%eax\n"
30975 "12: movl 20(%4), %%edx\n"
30976- "13: movl %%eax, 16(%3)\n"
30977- "14: movl %%edx, 20(%3)\n"
30978+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
30979+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
30980 "15: movl 24(%4), %%eax\n"
30981 "16: movl 28(%4), %%edx\n"
30982- "17: movl %%eax, 24(%3)\n"
30983- "18: movl %%edx, 28(%3)\n"
30984+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
30985+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
30986 "19: movl 32(%4), %%eax\n"
30987 "20: movl 36(%4), %%edx\n"
30988- "21: movl %%eax, 32(%3)\n"
30989- "22: movl %%edx, 36(%3)\n"
30990+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
30991+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
30992 "23: movl 40(%4), %%eax\n"
30993 "24: movl 44(%4), %%edx\n"
30994- "25: movl %%eax, 40(%3)\n"
30995- "26: movl %%edx, 44(%3)\n"
30996+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
30997+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
30998 "27: movl 48(%4), %%eax\n"
30999 "28: movl 52(%4), %%edx\n"
31000- "29: movl %%eax, 48(%3)\n"
31001- "30: movl %%edx, 52(%3)\n"
31002+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
31003+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
31004 "31: movl 56(%4), %%eax\n"
31005 "32: movl 60(%4), %%edx\n"
31006- "33: movl %%eax, 56(%3)\n"
31007- "34: movl %%edx, 60(%3)\n"
31008+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
31009+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
31010 " addl $-64, %0\n"
31011 " addl $64, %4\n"
31012 " addl $64, %3\n"
31013@@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
31014 " shrl $2, %0\n"
31015 " andl $3, %%eax\n"
31016 " cld\n"
31017+ __COPYUSER_SET_ES
31018 "99: rep; movsl\n"
31019 "36: movl %%eax, %0\n"
31020 "37: rep; movsb\n"
31021 "100:\n"
31022+ __COPYUSER_RESTORE_ES
31023+ ".section .fixup,\"ax\"\n"
31024+ "101: lea 0(%%eax,%0,4),%0\n"
31025+ " jmp 100b\n"
31026+ ".previous\n"
31027+ _ASM_EXTABLE(1b,100b)
31028+ _ASM_EXTABLE(2b,100b)
31029+ _ASM_EXTABLE(3b,100b)
31030+ _ASM_EXTABLE(4b,100b)
31031+ _ASM_EXTABLE(5b,100b)
31032+ _ASM_EXTABLE(6b,100b)
31033+ _ASM_EXTABLE(7b,100b)
31034+ _ASM_EXTABLE(8b,100b)
31035+ _ASM_EXTABLE(9b,100b)
31036+ _ASM_EXTABLE(10b,100b)
31037+ _ASM_EXTABLE(11b,100b)
31038+ _ASM_EXTABLE(12b,100b)
31039+ _ASM_EXTABLE(13b,100b)
31040+ _ASM_EXTABLE(14b,100b)
31041+ _ASM_EXTABLE(15b,100b)
31042+ _ASM_EXTABLE(16b,100b)
31043+ _ASM_EXTABLE(17b,100b)
31044+ _ASM_EXTABLE(18b,100b)
31045+ _ASM_EXTABLE(19b,100b)
31046+ _ASM_EXTABLE(20b,100b)
31047+ _ASM_EXTABLE(21b,100b)
31048+ _ASM_EXTABLE(22b,100b)
31049+ _ASM_EXTABLE(23b,100b)
31050+ _ASM_EXTABLE(24b,100b)
31051+ _ASM_EXTABLE(25b,100b)
31052+ _ASM_EXTABLE(26b,100b)
31053+ _ASM_EXTABLE(27b,100b)
31054+ _ASM_EXTABLE(28b,100b)
31055+ _ASM_EXTABLE(29b,100b)
31056+ _ASM_EXTABLE(30b,100b)
31057+ _ASM_EXTABLE(31b,100b)
31058+ _ASM_EXTABLE(32b,100b)
31059+ _ASM_EXTABLE(33b,100b)
31060+ _ASM_EXTABLE(34b,100b)
31061+ _ASM_EXTABLE(35b,100b)
31062+ _ASM_EXTABLE(36b,100b)
31063+ _ASM_EXTABLE(37b,100b)
31064+ _ASM_EXTABLE(99b,101b)
31065+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
31066+ : "1"(to), "2"(from), "0"(size)
31067+ : "eax", "edx", "memory");
31068+ return size;
31069+}
31070+
31071+static unsigned long
31072+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
31073+{
31074+ int d0, d1;
31075+ __asm__ __volatile__(
31076+ " .align 2,0x90\n"
31077+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
31078+ " cmpl $67, %0\n"
31079+ " jbe 3f\n"
31080+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
31081+ " .align 2,0x90\n"
31082+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
31083+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
31084+ "5: movl %%eax, 0(%3)\n"
31085+ "6: movl %%edx, 4(%3)\n"
31086+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
31087+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
31088+ "9: movl %%eax, 8(%3)\n"
31089+ "10: movl %%edx, 12(%3)\n"
31090+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
31091+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
31092+ "13: movl %%eax, 16(%3)\n"
31093+ "14: movl %%edx, 20(%3)\n"
31094+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
31095+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
31096+ "17: movl %%eax, 24(%3)\n"
31097+ "18: movl %%edx, 28(%3)\n"
31098+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
31099+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
31100+ "21: movl %%eax, 32(%3)\n"
31101+ "22: movl %%edx, 36(%3)\n"
31102+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
31103+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
31104+ "25: movl %%eax, 40(%3)\n"
31105+ "26: movl %%edx, 44(%3)\n"
31106+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
31107+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
31108+ "29: movl %%eax, 48(%3)\n"
31109+ "30: movl %%edx, 52(%3)\n"
31110+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
31111+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
31112+ "33: movl %%eax, 56(%3)\n"
31113+ "34: movl %%edx, 60(%3)\n"
31114+ " addl $-64, %0\n"
31115+ " addl $64, %4\n"
31116+ " addl $64, %3\n"
31117+ " cmpl $63, %0\n"
31118+ " ja 1b\n"
31119+ "35: movl %0, %%eax\n"
31120+ " shrl $2, %0\n"
31121+ " andl $3, %%eax\n"
31122+ " cld\n"
31123+ "99: rep; "__copyuser_seg" movsl\n"
31124+ "36: movl %%eax, %0\n"
31125+ "37: rep; "__copyuser_seg" movsb\n"
31126+ "100:\n"
31127 ".section .fixup,\"ax\"\n"
31128 "101: lea 0(%%eax,%0,4),%0\n"
31129 " jmp 100b\n"
31130@@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
31131 int d0, d1;
31132 __asm__ __volatile__(
31133 " .align 2,0x90\n"
31134- "0: movl 32(%4), %%eax\n"
31135+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31136 " cmpl $67, %0\n"
31137 " jbe 2f\n"
31138- "1: movl 64(%4), %%eax\n"
31139+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31140 " .align 2,0x90\n"
31141- "2: movl 0(%4), %%eax\n"
31142- "21: movl 4(%4), %%edx\n"
31143+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31144+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31145 " movl %%eax, 0(%3)\n"
31146 " movl %%edx, 4(%3)\n"
31147- "3: movl 8(%4), %%eax\n"
31148- "31: movl 12(%4),%%edx\n"
31149+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31150+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31151 " movl %%eax, 8(%3)\n"
31152 " movl %%edx, 12(%3)\n"
31153- "4: movl 16(%4), %%eax\n"
31154- "41: movl 20(%4), %%edx\n"
31155+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31156+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31157 " movl %%eax, 16(%3)\n"
31158 " movl %%edx, 20(%3)\n"
31159- "10: movl 24(%4), %%eax\n"
31160- "51: movl 28(%4), %%edx\n"
31161+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31162+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31163 " movl %%eax, 24(%3)\n"
31164 " movl %%edx, 28(%3)\n"
31165- "11: movl 32(%4), %%eax\n"
31166- "61: movl 36(%4), %%edx\n"
31167+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31168+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31169 " movl %%eax, 32(%3)\n"
31170 " movl %%edx, 36(%3)\n"
31171- "12: movl 40(%4), %%eax\n"
31172- "71: movl 44(%4), %%edx\n"
31173+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31174+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31175 " movl %%eax, 40(%3)\n"
31176 " movl %%edx, 44(%3)\n"
31177- "13: movl 48(%4), %%eax\n"
31178- "81: movl 52(%4), %%edx\n"
31179+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31180+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31181 " movl %%eax, 48(%3)\n"
31182 " movl %%edx, 52(%3)\n"
31183- "14: movl 56(%4), %%eax\n"
31184- "91: movl 60(%4), %%edx\n"
31185+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31186+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31187 " movl %%eax, 56(%3)\n"
31188 " movl %%edx, 60(%3)\n"
31189 " addl $-64, %0\n"
31190@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
31191 " shrl $2, %0\n"
31192 " andl $3, %%eax\n"
31193 " cld\n"
31194- "6: rep; movsl\n"
31195+ "6: rep; "__copyuser_seg" movsl\n"
31196 " movl %%eax,%0\n"
31197- "7: rep; movsb\n"
31198+ "7: rep; "__copyuser_seg" movsb\n"
31199 "8:\n"
31200 ".section .fixup,\"ax\"\n"
31201 "9: lea 0(%%eax,%0,4),%0\n"
31202@@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
31203
31204 __asm__ __volatile__(
31205 " .align 2,0x90\n"
31206- "0: movl 32(%4), %%eax\n"
31207+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31208 " cmpl $67, %0\n"
31209 " jbe 2f\n"
31210- "1: movl 64(%4), %%eax\n"
31211+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31212 " .align 2,0x90\n"
31213- "2: movl 0(%4), %%eax\n"
31214- "21: movl 4(%4), %%edx\n"
31215+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31216+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31217 " movnti %%eax, 0(%3)\n"
31218 " movnti %%edx, 4(%3)\n"
31219- "3: movl 8(%4), %%eax\n"
31220- "31: movl 12(%4),%%edx\n"
31221+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31222+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31223 " movnti %%eax, 8(%3)\n"
31224 " movnti %%edx, 12(%3)\n"
31225- "4: movl 16(%4), %%eax\n"
31226- "41: movl 20(%4), %%edx\n"
31227+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31228+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31229 " movnti %%eax, 16(%3)\n"
31230 " movnti %%edx, 20(%3)\n"
31231- "10: movl 24(%4), %%eax\n"
31232- "51: movl 28(%4), %%edx\n"
31233+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31234+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31235 " movnti %%eax, 24(%3)\n"
31236 " movnti %%edx, 28(%3)\n"
31237- "11: movl 32(%4), %%eax\n"
31238- "61: movl 36(%4), %%edx\n"
31239+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31240+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31241 " movnti %%eax, 32(%3)\n"
31242 " movnti %%edx, 36(%3)\n"
31243- "12: movl 40(%4), %%eax\n"
31244- "71: movl 44(%4), %%edx\n"
31245+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31246+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31247 " movnti %%eax, 40(%3)\n"
31248 " movnti %%edx, 44(%3)\n"
31249- "13: movl 48(%4), %%eax\n"
31250- "81: movl 52(%4), %%edx\n"
31251+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31252+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31253 " movnti %%eax, 48(%3)\n"
31254 " movnti %%edx, 52(%3)\n"
31255- "14: movl 56(%4), %%eax\n"
31256- "91: movl 60(%4), %%edx\n"
31257+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31258+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31259 " movnti %%eax, 56(%3)\n"
31260 " movnti %%edx, 60(%3)\n"
31261 " addl $-64, %0\n"
31262@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
31263 " shrl $2, %0\n"
31264 " andl $3, %%eax\n"
31265 " cld\n"
31266- "6: rep; movsl\n"
31267+ "6: rep; "__copyuser_seg" movsl\n"
31268 " movl %%eax,%0\n"
31269- "7: rep; movsb\n"
31270+ "7: rep; "__copyuser_seg" movsb\n"
31271 "8:\n"
31272 ".section .fixup,\"ax\"\n"
31273 "9: lea 0(%%eax,%0,4),%0\n"
31274@@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
31275
31276 __asm__ __volatile__(
31277 " .align 2,0x90\n"
31278- "0: movl 32(%4), %%eax\n"
31279+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31280 " cmpl $67, %0\n"
31281 " jbe 2f\n"
31282- "1: movl 64(%4), %%eax\n"
31283+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31284 " .align 2,0x90\n"
31285- "2: movl 0(%4), %%eax\n"
31286- "21: movl 4(%4), %%edx\n"
31287+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31288+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31289 " movnti %%eax, 0(%3)\n"
31290 " movnti %%edx, 4(%3)\n"
31291- "3: movl 8(%4), %%eax\n"
31292- "31: movl 12(%4),%%edx\n"
31293+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31294+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31295 " movnti %%eax, 8(%3)\n"
31296 " movnti %%edx, 12(%3)\n"
31297- "4: movl 16(%4), %%eax\n"
31298- "41: movl 20(%4), %%edx\n"
31299+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31300+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31301 " movnti %%eax, 16(%3)\n"
31302 " movnti %%edx, 20(%3)\n"
31303- "10: movl 24(%4), %%eax\n"
31304- "51: movl 28(%4), %%edx\n"
31305+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31306+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31307 " movnti %%eax, 24(%3)\n"
31308 " movnti %%edx, 28(%3)\n"
31309- "11: movl 32(%4), %%eax\n"
31310- "61: movl 36(%4), %%edx\n"
31311+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31312+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31313 " movnti %%eax, 32(%3)\n"
31314 " movnti %%edx, 36(%3)\n"
31315- "12: movl 40(%4), %%eax\n"
31316- "71: movl 44(%4), %%edx\n"
31317+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31318+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31319 " movnti %%eax, 40(%3)\n"
31320 " movnti %%edx, 44(%3)\n"
31321- "13: movl 48(%4), %%eax\n"
31322- "81: movl 52(%4), %%edx\n"
31323+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31324+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31325 " movnti %%eax, 48(%3)\n"
31326 " movnti %%edx, 52(%3)\n"
31327- "14: movl 56(%4), %%eax\n"
31328- "91: movl 60(%4), %%edx\n"
31329+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31330+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31331 " movnti %%eax, 56(%3)\n"
31332 " movnti %%edx, 60(%3)\n"
31333 " addl $-64, %0\n"
31334@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
31335 " shrl $2, %0\n"
31336 " andl $3, %%eax\n"
31337 " cld\n"
31338- "6: rep; movsl\n"
31339+ "6: rep; "__copyuser_seg" movsl\n"
31340 " movl %%eax,%0\n"
31341- "7: rep; movsb\n"
31342+ "7: rep; "__copyuser_seg" movsb\n"
31343 "8:\n"
31344 ".section .fixup,\"ax\"\n"
31345 "9: lea 0(%%eax,%0,4),%0\n"
31346@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
31347 */
31348 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
31349 unsigned long size);
31350-unsigned long __copy_user_intel(void __user *to, const void *from,
31351+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
31352+ unsigned long size);
31353+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
31354 unsigned long size);
31355 unsigned long __copy_user_zeroing_intel_nocache(void *to,
31356 const void __user *from, unsigned long size);
31357 #endif /* CONFIG_X86_INTEL_USERCOPY */
31358
31359 /* Generic arbitrary sized copy. */
31360-#define __copy_user(to, from, size) \
31361+#define __copy_user(to, from, size, prefix, set, restore) \
31362 do { \
31363 int __d0, __d1, __d2; \
31364 __asm__ __volatile__( \
31365+ set \
31366 " cmp $7,%0\n" \
31367 " jbe 1f\n" \
31368 " movl %1,%0\n" \
31369 " negl %0\n" \
31370 " andl $7,%0\n" \
31371 " subl %0,%3\n" \
31372- "4: rep; movsb\n" \
31373+ "4: rep; "prefix"movsb\n" \
31374 " movl %3,%0\n" \
31375 " shrl $2,%0\n" \
31376 " andl $3,%3\n" \
31377 " .align 2,0x90\n" \
31378- "0: rep; movsl\n" \
31379+ "0: rep; "prefix"movsl\n" \
31380 " movl %3,%0\n" \
31381- "1: rep; movsb\n" \
31382+ "1: rep; "prefix"movsb\n" \
31383 "2:\n" \
31384+ restore \
31385 ".section .fixup,\"ax\"\n" \
31386 "5: addl %3,%0\n" \
31387 " jmp 2b\n" \
31388@@ -538,14 +650,14 @@ do { \
31389 " negl %0\n" \
31390 " andl $7,%0\n" \
31391 " subl %0,%3\n" \
31392- "4: rep; movsb\n" \
31393+ "4: rep; "__copyuser_seg"movsb\n" \
31394 " movl %3,%0\n" \
31395 " shrl $2,%0\n" \
31396 " andl $3,%3\n" \
31397 " .align 2,0x90\n" \
31398- "0: rep; movsl\n" \
31399+ "0: rep; "__copyuser_seg"movsl\n" \
31400 " movl %3,%0\n" \
31401- "1: rep; movsb\n" \
31402+ "1: rep; "__copyuser_seg"movsb\n" \
31403 "2:\n" \
31404 ".section .fixup,\"ax\"\n" \
31405 "5: addl %3,%0\n" \
31406@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
31407 {
31408 stac();
31409 if (movsl_is_ok(to, from, n))
31410- __copy_user(to, from, n);
31411+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
31412 else
31413- n = __copy_user_intel(to, from, n);
31414+ n = __generic_copy_to_user_intel(to, from, n);
31415 clac();
31416 return n;
31417 }
31418@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
31419 {
31420 stac();
31421 if (movsl_is_ok(to, from, n))
31422- __copy_user(to, from, n);
31423+ __copy_user(to, from, n, __copyuser_seg, "", "");
31424 else
31425- n = __copy_user_intel((void __user *)to,
31426- (const void *)from, n);
31427+ n = __generic_copy_from_user_intel(to, from, n);
31428 clac();
31429 return n;
31430 }
31431@@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
31432 if (n > 64 && cpu_has_xmm2)
31433 n = __copy_user_intel_nocache(to, from, n);
31434 else
31435- __copy_user(to, from, n);
31436+ __copy_user(to, from, n, __copyuser_seg, "", "");
31437 #else
31438- __copy_user(to, from, n);
31439+ __copy_user(to, from, n, __copyuser_seg, "", "");
31440 #endif
31441 clac();
31442 return n;
31443 }
31444 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
31445
31446-/**
31447- * copy_to_user: - Copy a block of data into user space.
31448- * @to: Destination address, in user space.
31449- * @from: Source address, in kernel space.
31450- * @n: Number of bytes to copy.
31451- *
31452- * Context: User context only. This function may sleep.
31453- *
31454- * Copy data from kernel space to user space.
31455- *
31456- * Returns number of bytes that could not be copied.
31457- * On success, this will be zero.
31458- */
31459-unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
31460+#ifdef CONFIG_PAX_MEMORY_UDEREF
31461+void __set_fs(mm_segment_t x)
31462 {
31463- if (access_ok(VERIFY_WRITE, to, n))
31464- n = __copy_to_user(to, from, n);
31465- return n;
31466+ switch (x.seg) {
31467+ case 0:
31468+ loadsegment(gs, 0);
31469+ break;
31470+ case TASK_SIZE_MAX:
31471+ loadsegment(gs, __USER_DS);
31472+ break;
31473+ case -1UL:
31474+ loadsegment(gs, __KERNEL_DS);
31475+ break;
31476+ default:
31477+ BUG();
31478+ }
31479 }
31480-EXPORT_SYMBOL(_copy_to_user);
31481+EXPORT_SYMBOL(__set_fs);
31482
31483-/**
31484- * copy_from_user: - Copy a block of data from user space.
31485- * @to: Destination address, in kernel space.
31486- * @from: Source address, in user space.
31487- * @n: Number of bytes to copy.
31488- *
31489- * Context: User context only. This function may sleep.
31490- *
31491- * Copy data from user space to kernel space.
31492- *
31493- * Returns number of bytes that could not be copied.
31494- * On success, this will be zero.
31495- *
31496- * If some data could not be copied, this function will pad the copied
31497- * data to the requested size using zero bytes.
31498- */
31499-unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
31500+void set_fs(mm_segment_t x)
31501 {
31502- if (access_ok(VERIFY_READ, from, n))
31503- n = __copy_from_user(to, from, n);
31504- else
31505- memset(to, 0, n);
31506- return n;
31507+ current_thread_info()->addr_limit = x;
31508+ __set_fs(x);
31509 }
31510-EXPORT_SYMBOL(_copy_from_user);
31511+EXPORT_SYMBOL(set_fs);
31512+#endif
31513diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
31514index c905e89..01ab928 100644
31515--- a/arch/x86/lib/usercopy_64.c
31516+++ b/arch/x86/lib/usercopy_64.c
31517@@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31518 might_fault();
31519 /* no memory constraint because it doesn't change any memory gcc knows
31520 about */
31521+ pax_open_userland();
31522 stac();
31523 asm volatile(
31524 " testq %[size8],%[size8]\n"
31525@@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31526 _ASM_EXTABLE(0b,3b)
31527 _ASM_EXTABLE(1b,2b)
31528 : [size8] "=&c"(size), [dst] "=&D" (__d0)
31529- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
31530+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
31531 [zero] "r" (0UL), [eight] "r" (8UL));
31532 clac();
31533+ pax_close_userland();
31534 return size;
31535 }
31536 EXPORT_SYMBOL(__clear_user);
31537@@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
31538 }
31539 EXPORT_SYMBOL(clear_user);
31540
31541-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
31542+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
31543 {
31544- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
31545- return copy_user_generic((__force void *)to, (__force void *)from, len);
31546- }
31547- return len;
31548+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
31549+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
31550+ return len;
31551 }
31552 EXPORT_SYMBOL(copy_in_user);
31553
31554@@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
31555 * it is not necessary to optimize tail handling.
31556 */
31557 __visible unsigned long
31558-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31559+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
31560 {
31561 char c;
31562 unsigned zero_len;
31563
31564+ clac();
31565+ pax_close_userland();
31566 for (; len; --len, to++) {
31567 if (__get_user_nocheck(c, from++, sizeof(char)))
31568 break;
31569@@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31570 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
31571 if (__put_user_nocheck(c, to++, sizeof(char)))
31572 break;
31573- clac();
31574 return len;
31575 }
31576diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
31577index 6a19ad9..1c48f9a 100644
31578--- a/arch/x86/mm/Makefile
31579+++ b/arch/x86/mm/Makefile
31580@@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
31581 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
31582
31583 obj-$(CONFIG_MEMTEST) += memtest.o
31584+
31585+quote:="
31586+obj-$(CONFIG_X86_64) += uderef_64.o
31587+CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
31588diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
31589index 903ec1e..c4166b2 100644
31590--- a/arch/x86/mm/extable.c
31591+++ b/arch/x86/mm/extable.c
31592@@ -6,12 +6,24 @@
31593 static inline unsigned long
31594 ex_insn_addr(const struct exception_table_entry *x)
31595 {
31596- return (unsigned long)&x->insn + x->insn;
31597+ unsigned long reloc = 0;
31598+
31599+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31600+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31601+#endif
31602+
31603+ return (unsigned long)&x->insn + x->insn + reloc;
31604 }
31605 static inline unsigned long
31606 ex_fixup_addr(const struct exception_table_entry *x)
31607 {
31608- return (unsigned long)&x->fixup + x->fixup;
31609+ unsigned long reloc = 0;
31610+
31611+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31612+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31613+#endif
31614+
31615+ return (unsigned long)&x->fixup + x->fixup + reloc;
31616 }
31617
31618 int fixup_exception(struct pt_regs *regs)
31619@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
31620 unsigned long new_ip;
31621
31622 #ifdef CONFIG_PNPBIOS
31623- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
31624+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
31625 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
31626 extern u32 pnp_bios_is_utter_crap;
31627 pnp_bios_is_utter_crap = 1;
31628@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
31629 i += 4;
31630 p->fixup -= i;
31631 i += 4;
31632+
31633+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31634+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
31635+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31636+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31637+#endif
31638+
31639 }
31640 }
31641
31642diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
31643index a10c8c7..35a5abb 100644
31644--- a/arch/x86/mm/fault.c
31645+++ b/arch/x86/mm/fault.c
31646@@ -14,11 +14,18 @@
31647 #include <linux/hugetlb.h> /* hstate_index_to_shift */
31648 #include <linux/prefetch.h> /* prefetchw */
31649 #include <linux/context_tracking.h> /* exception_enter(), ... */
31650+#include <linux/unistd.h>
31651+#include <linux/compiler.h>
31652
31653 #include <asm/traps.h> /* dotraplinkage, ... */
31654 #include <asm/pgalloc.h> /* pgd_*(), ... */
31655 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
31656 #include <asm/fixmap.h> /* VSYSCALL_START */
31657+#include <asm/tlbflush.h>
31658+
31659+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31660+#include <asm/stacktrace.h>
31661+#endif
31662
31663 #define CREATE_TRACE_POINTS
31664 #include <asm/trace/exceptions.h>
31665@@ -59,7 +66,7 @@ static inline int __kprobes kprobes_fault(struct pt_regs *regs)
31666 int ret = 0;
31667
31668 /* kprobe_running() needs smp_processor_id() */
31669- if (kprobes_built_in() && !user_mode_vm(regs)) {
31670+ if (kprobes_built_in() && !user_mode(regs)) {
31671 preempt_disable();
31672 if (kprobe_running() && kprobe_fault_handler(regs, 14))
31673 ret = 1;
31674@@ -120,7 +127,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
31675 return !instr_lo || (instr_lo>>1) == 1;
31676 case 0x00:
31677 /* Prefetch instruction is 0x0F0D or 0x0F18 */
31678- if (probe_kernel_address(instr, opcode))
31679+ if (user_mode(regs)) {
31680+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31681+ return 0;
31682+ } else if (probe_kernel_address(instr, opcode))
31683 return 0;
31684
31685 *prefetch = (instr_lo == 0xF) &&
31686@@ -154,7 +164,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
31687 while (instr < max_instr) {
31688 unsigned char opcode;
31689
31690- if (probe_kernel_address(instr, opcode))
31691+ if (user_mode(regs)) {
31692+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31693+ break;
31694+ } else if (probe_kernel_address(instr, opcode))
31695 break;
31696
31697 instr++;
31698@@ -185,6 +198,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
31699 force_sig_info(si_signo, &info, tsk);
31700 }
31701
31702+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31703+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
31704+#endif
31705+
31706+#ifdef CONFIG_PAX_EMUTRAMP
31707+static int pax_handle_fetch_fault(struct pt_regs *regs);
31708+#endif
31709+
31710+#ifdef CONFIG_PAX_PAGEEXEC
31711+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
31712+{
31713+ pgd_t *pgd;
31714+ pud_t *pud;
31715+ pmd_t *pmd;
31716+
31717+ pgd = pgd_offset(mm, address);
31718+ if (!pgd_present(*pgd))
31719+ return NULL;
31720+ pud = pud_offset(pgd, address);
31721+ if (!pud_present(*pud))
31722+ return NULL;
31723+ pmd = pmd_offset(pud, address);
31724+ if (!pmd_present(*pmd))
31725+ return NULL;
31726+ return pmd;
31727+}
31728+#endif
31729+
31730 DEFINE_SPINLOCK(pgd_lock);
31731 LIST_HEAD(pgd_list);
31732
31733@@ -235,10 +276,27 @@ void vmalloc_sync_all(void)
31734 for (address = VMALLOC_START & PMD_MASK;
31735 address >= TASK_SIZE && address < FIXADDR_TOP;
31736 address += PMD_SIZE) {
31737+
31738+#ifdef CONFIG_PAX_PER_CPU_PGD
31739+ unsigned long cpu;
31740+#else
31741 struct page *page;
31742+#endif
31743
31744 spin_lock(&pgd_lock);
31745+
31746+#ifdef CONFIG_PAX_PER_CPU_PGD
31747+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31748+ pgd_t *pgd = get_cpu_pgd(cpu, user);
31749+ pmd_t *ret;
31750+
31751+ ret = vmalloc_sync_one(pgd, address);
31752+ if (!ret)
31753+ break;
31754+ pgd = get_cpu_pgd(cpu, kernel);
31755+#else
31756 list_for_each_entry(page, &pgd_list, lru) {
31757+ pgd_t *pgd;
31758 spinlock_t *pgt_lock;
31759 pmd_t *ret;
31760
31761@@ -246,8 +304,14 @@ void vmalloc_sync_all(void)
31762 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31763
31764 spin_lock(pgt_lock);
31765- ret = vmalloc_sync_one(page_address(page), address);
31766+ pgd = page_address(page);
31767+#endif
31768+
31769+ ret = vmalloc_sync_one(pgd, address);
31770+
31771+#ifndef CONFIG_PAX_PER_CPU_PGD
31772 spin_unlock(pgt_lock);
31773+#endif
31774
31775 if (!ret)
31776 break;
31777@@ -281,6 +345,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31778 * an interrupt in the middle of a task switch..
31779 */
31780 pgd_paddr = read_cr3();
31781+
31782+#ifdef CONFIG_PAX_PER_CPU_PGD
31783+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
31784+ vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
31785+#endif
31786+
31787 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
31788 if (!pmd_k)
31789 return -1;
31790@@ -376,11 +446,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31791 * happen within a race in page table update. In the later
31792 * case just flush:
31793 */
31794- pgd = pgd_offset(current->active_mm, address);
31795+
31796 pgd_ref = pgd_offset_k(address);
31797 if (pgd_none(*pgd_ref))
31798 return -1;
31799
31800+#ifdef CONFIG_PAX_PER_CPU_PGD
31801+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
31802+ pgd = pgd_offset_cpu(smp_processor_id(), user, address);
31803+ if (pgd_none(*pgd)) {
31804+ set_pgd(pgd, *pgd_ref);
31805+ arch_flush_lazy_mmu_mode();
31806+ } else {
31807+ BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
31808+ }
31809+ pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
31810+#else
31811+ pgd = pgd_offset(current->active_mm, address);
31812+#endif
31813+
31814 if (pgd_none(*pgd)) {
31815 set_pgd(pgd, *pgd_ref);
31816 arch_flush_lazy_mmu_mode();
31817@@ -546,7 +630,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
31818 static int is_errata100(struct pt_regs *regs, unsigned long address)
31819 {
31820 #ifdef CONFIG_X86_64
31821- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
31822+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
31823 return 1;
31824 #endif
31825 return 0;
31826@@ -573,7 +657,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
31827 }
31828
31829 static const char nx_warning[] = KERN_CRIT
31830-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
31831+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
31832
31833 static void
31834 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31835@@ -582,15 +666,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31836 if (!oops_may_print())
31837 return;
31838
31839- if (error_code & PF_INSTR) {
31840+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
31841 unsigned int level;
31842
31843 pte_t *pte = lookup_address(address, &level);
31844
31845 if (pte && pte_present(*pte) && !pte_exec(*pte))
31846- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
31847+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
31848 }
31849
31850+#ifdef CONFIG_PAX_KERNEXEC
31851+ if (init_mm.start_code <= address && address < init_mm.end_code) {
31852+ if (current->signal->curr_ip)
31853+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
31854+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
31855+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31856+ else
31857+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
31858+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31859+ }
31860+#endif
31861+
31862 printk(KERN_ALERT "BUG: unable to handle kernel ");
31863 if (address < PAGE_SIZE)
31864 printk(KERN_CONT "NULL pointer dereference");
31865@@ -771,6 +867,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
31866 return;
31867 }
31868 #endif
31869+
31870+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31871+ if (pax_is_fetch_fault(regs, error_code, address)) {
31872+
31873+#ifdef CONFIG_PAX_EMUTRAMP
31874+ switch (pax_handle_fetch_fault(regs)) {
31875+ case 2:
31876+ return;
31877+ }
31878+#endif
31879+
31880+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31881+ do_group_exit(SIGKILL);
31882+ }
31883+#endif
31884+
31885 /* Kernel addresses are always protection faults: */
31886 if (address >= TASK_SIZE)
31887 error_code |= PF_PROT;
31888@@ -856,7 +968,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
31889 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
31890 printk(KERN_ERR
31891 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
31892- tsk->comm, tsk->pid, address);
31893+ tsk->comm, task_pid_nr(tsk), address);
31894 code = BUS_MCEERR_AR;
31895 }
31896 #endif
31897@@ -910,6 +1022,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
31898 return 1;
31899 }
31900
31901+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31902+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
31903+{
31904+ pte_t *pte;
31905+ pmd_t *pmd;
31906+ spinlock_t *ptl;
31907+ unsigned char pte_mask;
31908+
31909+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
31910+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
31911+ return 0;
31912+
31913+ /* PaX: it's our fault, let's handle it if we can */
31914+
31915+ /* PaX: take a look at read faults before acquiring any locks */
31916+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
31917+ /* instruction fetch attempt from a protected page in user mode */
31918+ up_read(&mm->mmap_sem);
31919+
31920+#ifdef CONFIG_PAX_EMUTRAMP
31921+ switch (pax_handle_fetch_fault(regs)) {
31922+ case 2:
31923+ return 1;
31924+ }
31925+#endif
31926+
31927+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31928+ do_group_exit(SIGKILL);
31929+ }
31930+
31931+ pmd = pax_get_pmd(mm, address);
31932+ if (unlikely(!pmd))
31933+ return 0;
31934+
31935+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
31936+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
31937+ pte_unmap_unlock(pte, ptl);
31938+ return 0;
31939+ }
31940+
31941+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
31942+ /* write attempt to a protected page in user mode */
31943+ pte_unmap_unlock(pte, ptl);
31944+ return 0;
31945+ }
31946+
31947+#ifdef CONFIG_SMP
31948+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
31949+#else
31950+ if (likely(address > get_limit(regs->cs)))
31951+#endif
31952+ {
31953+ set_pte(pte, pte_mkread(*pte));
31954+ __flush_tlb_one(address);
31955+ pte_unmap_unlock(pte, ptl);
31956+ up_read(&mm->mmap_sem);
31957+ return 1;
31958+ }
31959+
31960+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
31961+
31962+ /*
31963+ * PaX: fill DTLB with user rights and retry
31964+ */
31965+ __asm__ __volatile__ (
31966+ "orb %2,(%1)\n"
31967+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
31968+/*
31969+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
31970+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
31971+ * page fault when examined during a TLB load attempt. this is true not only
31972+ * for PTEs holding a non-present entry but also present entries that will
31973+ * raise a page fault (such as those set up by PaX, or the copy-on-write
31974+ * mechanism). in effect it means that we do *not* need to flush the TLBs
31975+ * for our target pages since their PTEs are simply not in the TLBs at all.
31976+
31977+ * the best thing in omitting it is that we gain around 15-20% speed in the
31978+ * fast path of the page fault handler and can get rid of tracing since we
31979+ * can no longer flush unintended entries.
31980+ */
31981+ "invlpg (%0)\n"
31982+#endif
31983+ __copyuser_seg"testb $0,(%0)\n"
31984+ "xorb %3,(%1)\n"
31985+ :
31986+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
31987+ : "memory", "cc");
31988+ pte_unmap_unlock(pte, ptl);
31989+ up_read(&mm->mmap_sem);
31990+ return 1;
31991+}
31992+#endif
31993+
31994 /*
31995 * Handle a spurious fault caused by a stale TLB entry.
31996 *
31997@@ -976,6 +1181,9 @@ int show_unhandled_signals = 1;
31998 static inline int
31999 access_error(unsigned long error_code, struct vm_area_struct *vma)
32000 {
32001+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
32002+ return 1;
32003+
32004 if (error_code & PF_WRITE) {
32005 /* write, present and write, not present: */
32006 if (unlikely(!(vma->vm_flags & VM_WRITE)))
32007@@ -1010,7 +1218,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
32008 if (error_code & PF_USER)
32009 return false;
32010
32011- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
32012+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
32013 return false;
32014
32015 return true;
32016@@ -1038,6 +1246,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32017 tsk = current;
32018 mm = tsk->mm;
32019
32020+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32021+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
32022+ if (!search_exception_tables(regs->ip)) {
32023+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32024+ bad_area_nosemaphore(regs, error_code, address);
32025+ return;
32026+ }
32027+ if (address < pax_user_shadow_base) {
32028+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32029+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
32030+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
32031+ } else
32032+ address -= pax_user_shadow_base;
32033+ }
32034+#endif
32035+
32036 /*
32037 * Detect and handle instructions that would cause a page fault for
32038 * both a tracked kernel page and a userspace page.
32039@@ -1115,7 +1339,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32040 * User-mode registers count as a user access even for any
32041 * potential system fault or CPU buglet:
32042 */
32043- if (user_mode_vm(regs)) {
32044+ if (user_mode(regs)) {
32045 local_irq_enable();
32046 error_code |= PF_USER;
32047 flags |= FAULT_FLAG_USER;
32048@@ -1162,6 +1386,11 @@ retry:
32049 might_sleep();
32050 }
32051
32052+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
32053+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
32054+ return;
32055+#endif
32056+
32057 vma = find_vma(mm, address);
32058 if (unlikely(!vma)) {
32059 bad_area(regs, error_code, address);
32060@@ -1173,18 +1402,24 @@ retry:
32061 bad_area(regs, error_code, address);
32062 return;
32063 }
32064- if (error_code & PF_USER) {
32065- /*
32066- * Accessing the stack below %sp is always a bug.
32067- * The large cushion allows instructions like enter
32068- * and pusha to work. ("enter $65535, $31" pushes
32069- * 32 pointers and then decrements %sp by 65535.)
32070- */
32071- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
32072- bad_area(regs, error_code, address);
32073- return;
32074- }
32075+ /*
32076+ * Accessing the stack below %sp is always a bug.
32077+ * The large cushion allows instructions like enter
32078+ * and pusha to work. ("enter $65535, $31" pushes
32079+ * 32 pointers and then decrements %sp by 65535.)
32080+ */
32081+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
32082+ bad_area(regs, error_code, address);
32083+ return;
32084 }
32085+
32086+#ifdef CONFIG_PAX_SEGMEXEC
32087+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
32088+ bad_area(regs, error_code, address);
32089+ return;
32090+ }
32091+#endif
32092+
32093 if (unlikely(expand_stack(vma, address))) {
32094 bad_area(regs, error_code, address);
32095 return;
32096@@ -1296,3 +1531,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
32097 exception_exit(prev_state);
32098 }
32099 #endif /* CONFIG_TRACING */
32100+
32101+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32102+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
32103+{
32104+ struct mm_struct *mm = current->mm;
32105+ unsigned long ip = regs->ip;
32106+
32107+ if (v8086_mode(regs))
32108+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
32109+
32110+#ifdef CONFIG_PAX_PAGEEXEC
32111+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
32112+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
32113+ return true;
32114+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
32115+ return true;
32116+ return false;
32117+ }
32118+#endif
32119+
32120+#ifdef CONFIG_PAX_SEGMEXEC
32121+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
32122+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
32123+ return true;
32124+ return false;
32125+ }
32126+#endif
32127+
32128+ return false;
32129+}
32130+#endif
32131+
32132+#ifdef CONFIG_PAX_EMUTRAMP
32133+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
32134+{
32135+ int err;
32136+
32137+ do { /* PaX: libffi trampoline emulation */
32138+ unsigned char mov, jmp;
32139+ unsigned int addr1, addr2;
32140+
32141+#ifdef CONFIG_X86_64
32142+ if ((regs->ip + 9) >> 32)
32143+ break;
32144+#endif
32145+
32146+ err = get_user(mov, (unsigned char __user *)regs->ip);
32147+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32148+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
32149+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32150+
32151+ if (err)
32152+ break;
32153+
32154+ if (mov == 0xB8 && jmp == 0xE9) {
32155+ regs->ax = addr1;
32156+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
32157+ return 2;
32158+ }
32159+ } while (0);
32160+
32161+ do { /* PaX: gcc trampoline emulation #1 */
32162+ unsigned char mov1, mov2;
32163+ unsigned short jmp;
32164+ unsigned int addr1, addr2;
32165+
32166+#ifdef CONFIG_X86_64
32167+ if ((regs->ip + 11) >> 32)
32168+ break;
32169+#endif
32170+
32171+ err = get_user(mov1, (unsigned char __user *)regs->ip);
32172+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32173+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
32174+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32175+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
32176+
32177+ if (err)
32178+ break;
32179+
32180+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
32181+ regs->cx = addr1;
32182+ regs->ax = addr2;
32183+ regs->ip = addr2;
32184+ return 2;
32185+ }
32186+ } while (0);
32187+
32188+ do { /* PaX: gcc trampoline emulation #2 */
32189+ unsigned char mov, jmp;
32190+ unsigned int addr1, addr2;
32191+
32192+#ifdef CONFIG_X86_64
32193+ if ((regs->ip + 9) >> 32)
32194+ break;
32195+#endif
32196+
32197+ err = get_user(mov, (unsigned char __user *)regs->ip);
32198+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32199+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
32200+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32201+
32202+ if (err)
32203+ break;
32204+
32205+ if (mov == 0xB9 && jmp == 0xE9) {
32206+ regs->cx = addr1;
32207+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
32208+ return 2;
32209+ }
32210+ } while (0);
32211+
32212+ return 1; /* PaX in action */
32213+}
32214+
32215+#ifdef CONFIG_X86_64
32216+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
32217+{
32218+ int err;
32219+
32220+ do { /* PaX: libffi trampoline emulation */
32221+ unsigned short mov1, mov2, jmp1;
32222+ unsigned char stcclc, jmp2;
32223+ unsigned long addr1, addr2;
32224+
32225+ err = get_user(mov1, (unsigned short __user *)regs->ip);
32226+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
32227+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
32228+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
32229+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
32230+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
32231+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
32232+
32233+ if (err)
32234+ break;
32235+
32236+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32237+ regs->r11 = addr1;
32238+ regs->r10 = addr2;
32239+ if (stcclc == 0xF8)
32240+ regs->flags &= ~X86_EFLAGS_CF;
32241+ else
32242+ regs->flags |= X86_EFLAGS_CF;
32243+ regs->ip = addr1;
32244+ return 2;
32245+ }
32246+ } while (0);
32247+
32248+ do { /* PaX: gcc trampoline emulation #1 */
32249+ unsigned short mov1, mov2, jmp1;
32250+ unsigned char jmp2;
32251+ unsigned int addr1;
32252+ unsigned long addr2;
32253+
32254+ err = get_user(mov1, (unsigned short __user *)regs->ip);
32255+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
32256+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
32257+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
32258+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
32259+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
32260+
32261+ if (err)
32262+ break;
32263+
32264+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32265+ regs->r11 = addr1;
32266+ regs->r10 = addr2;
32267+ regs->ip = addr1;
32268+ return 2;
32269+ }
32270+ } while (0);
32271+
32272+ do { /* PaX: gcc trampoline emulation #2 */
32273+ unsigned short mov1, mov2, jmp1;
32274+ unsigned char jmp2;
32275+ unsigned long addr1, addr2;
32276+
32277+ err = get_user(mov1, (unsigned short __user *)regs->ip);
32278+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
32279+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
32280+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
32281+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
32282+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
32283+
32284+ if (err)
32285+ break;
32286+
32287+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32288+ regs->r11 = addr1;
32289+ regs->r10 = addr2;
32290+ regs->ip = addr1;
32291+ return 2;
32292+ }
32293+ } while (0);
32294+
32295+ return 1; /* PaX in action */
32296+}
32297+#endif
32298+
32299+/*
32300+ * PaX: decide what to do with offenders (regs->ip = fault address)
32301+ *
32302+ * returns 1 when task should be killed
32303+ * 2 when gcc trampoline was detected
32304+ */
32305+static int pax_handle_fetch_fault(struct pt_regs *regs)
32306+{
32307+ if (v8086_mode(regs))
32308+ return 1;
32309+
32310+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
32311+ return 1;
32312+
32313+#ifdef CONFIG_X86_32
32314+ return pax_handle_fetch_fault_32(regs);
32315+#else
32316+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
32317+ return pax_handle_fetch_fault_32(regs);
32318+ else
32319+ return pax_handle_fetch_fault_64(regs);
32320+#endif
32321+}
32322+#endif
32323+
32324+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32325+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
32326+{
32327+ long i;
32328+
32329+ printk(KERN_ERR "PAX: bytes at PC: ");
32330+ for (i = 0; i < 20; i++) {
32331+ unsigned char c;
32332+ if (get_user(c, (unsigned char __force_user *)pc+i))
32333+ printk(KERN_CONT "?? ");
32334+ else
32335+ printk(KERN_CONT "%02x ", c);
32336+ }
32337+ printk("\n");
32338+
32339+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
32340+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
32341+ unsigned long c;
32342+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
32343+#ifdef CONFIG_X86_32
32344+ printk(KERN_CONT "???????? ");
32345+#else
32346+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
32347+ printk(KERN_CONT "???????? ???????? ");
32348+ else
32349+ printk(KERN_CONT "???????????????? ");
32350+#endif
32351+ } else {
32352+#ifdef CONFIG_X86_64
32353+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
32354+ printk(KERN_CONT "%08x ", (unsigned int)c);
32355+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
32356+ } else
32357+#endif
32358+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
32359+ }
32360+ }
32361+ printk("\n");
32362+}
32363+#endif
32364+
32365+/**
32366+ * probe_kernel_write(): safely attempt to write to a location
32367+ * @dst: address to write to
32368+ * @src: pointer to the data that shall be written
32369+ * @size: size of the data chunk
32370+ *
32371+ * Safely write to address @dst from the buffer at @src. If a kernel fault
32372+ * happens, handle that and return -EFAULT.
32373+ */
32374+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
32375+{
32376+ long ret;
32377+ mm_segment_t old_fs = get_fs();
32378+
32379+ set_fs(KERNEL_DS);
32380+ pagefault_disable();
32381+ pax_open_kernel();
32382+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
32383+ pax_close_kernel();
32384+ pagefault_enable();
32385+ set_fs(old_fs);
32386+
32387+ return ret ? -EFAULT : 0;
32388+}
32389diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
32390index 207d9aef..69030980 100644
32391--- a/arch/x86/mm/gup.c
32392+++ b/arch/x86/mm/gup.c
32393@@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
32394 addr = start;
32395 len = (unsigned long) nr_pages << PAGE_SHIFT;
32396 end = start + len;
32397- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
32398+ if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32399 (void __user *)start, len)))
32400 return 0;
32401
32402@@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
32403 goto slow_irqon;
32404 #endif
32405
32406+ if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32407+ (void __user *)start, len)))
32408+ return 0;
32409+
32410 /*
32411 * XXX: batch / limit 'nr', to avoid large irq off latency
32412 * needs some instrumenting to determine the common sizes used by
32413diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
32414index 4500142..53a363c 100644
32415--- a/arch/x86/mm/highmem_32.c
32416+++ b/arch/x86/mm/highmem_32.c
32417@@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
32418 idx = type + KM_TYPE_NR*smp_processor_id();
32419 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32420 BUG_ON(!pte_none(*(kmap_pte-idx)));
32421+
32422+ pax_open_kernel();
32423 set_pte(kmap_pte-idx, mk_pte(page, prot));
32424+ pax_close_kernel();
32425+
32426 arch_flush_lazy_mmu_mode();
32427
32428 return (void *)vaddr;
32429diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
32430index 8c9f647..57cb402 100644
32431--- a/arch/x86/mm/hugetlbpage.c
32432+++ b/arch/x86/mm/hugetlbpage.c
32433@@ -90,23 +90,24 @@ int pmd_huge_support(void)
32434 #ifdef CONFIG_HUGETLB_PAGE
32435 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
32436 unsigned long addr, unsigned long len,
32437- unsigned long pgoff, unsigned long flags)
32438+ unsigned long pgoff, unsigned long flags, unsigned long offset)
32439 {
32440 struct hstate *h = hstate_file(file);
32441 struct vm_unmapped_area_info info;
32442-
32443+
32444 info.flags = 0;
32445 info.length = len;
32446 info.low_limit = current->mm->mmap_legacy_base;
32447 info.high_limit = TASK_SIZE;
32448 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32449 info.align_offset = 0;
32450+ info.threadstack_offset = offset;
32451 return vm_unmapped_area(&info);
32452 }
32453
32454 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32455 unsigned long addr0, unsigned long len,
32456- unsigned long pgoff, unsigned long flags)
32457+ unsigned long pgoff, unsigned long flags, unsigned long offset)
32458 {
32459 struct hstate *h = hstate_file(file);
32460 struct vm_unmapped_area_info info;
32461@@ -118,6 +119,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32462 info.high_limit = current->mm->mmap_base;
32463 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32464 info.align_offset = 0;
32465+ info.threadstack_offset = offset;
32466 addr = vm_unmapped_area(&info);
32467
32468 /*
32469@@ -130,6 +132,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32470 VM_BUG_ON(addr != -ENOMEM);
32471 info.flags = 0;
32472 info.low_limit = TASK_UNMAPPED_BASE;
32473+
32474+#ifdef CONFIG_PAX_RANDMMAP
32475+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
32476+ info.low_limit += current->mm->delta_mmap;
32477+#endif
32478+
32479 info.high_limit = TASK_SIZE;
32480 addr = vm_unmapped_area(&info);
32481 }
32482@@ -144,10 +152,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32483 struct hstate *h = hstate_file(file);
32484 struct mm_struct *mm = current->mm;
32485 struct vm_area_struct *vma;
32486+ unsigned long pax_task_size = TASK_SIZE;
32487+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
32488
32489 if (len & ~huge_page_mask(h))
32490 return -EINVAL;
32491- if (len > TASK_SIZE)
32492+
32493+#ifdef CONFIG_PAX_SEGMEXEC
32494+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
32495+ pax_task_size = SEGMEXEC_TASK_SIZE;
32496+#endif
32497+
32498+ pax_task_size -= PAGE_SIZE;
32499+
32500+ if (len > pax_task_size)
32501 return -ENOMEM;
32502
32503 if (flags & MAP_FIXED) {
32504@@ -156,19 +174,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32505 return addr;
32506 }
32507
32508+#ifdef CONFIG_PAX_RANDMMAP
32509+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
32510+#endif
32511+
32512 if (addr) {
32513 addr = ALIGN(addr, huge_page_size(h));
32514 vma = find_vma(mm, addr);
32515- if (TASK_SIZE - len >= addr &&
32516- (!vma || addr + len <= vma->vm_start))
32517+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
32518 return addr;
32519 }
32520 if (mm->get_unmapped_area == arch_get_unmapped_area)
32521 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
32522- pgoff, flags);
32523+ pgoff, flags, offset);
32524 else
32525 return hugetlb_get_unmapped_area_topdown(file, addr, len,
32526- pgoff, flags);
32527+ pgoff, flags, offset);
32528 }
32529 #endif /* CONFIG_HUGETLB_PAGE */
32530
32531diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
32532index f971306..e83e0f6 100644
32533--- a/arch/x86/mm/init.c
32534+++ b/arch/x86/mm/init.c
32535@@ -4,6 +4,7 @@
32536 #include <linux/swap.h>
32537 #include <linux/memblock.h>
32538 #include <linux/bootmem.h> /* for max_low_pfn */
32539+#include <linux/tboot.h>
32540
32541 #include <asm/cacheflush.h>
32542 #include <asm/e820.h>
32543@@ -17,6 +18,8 @@
32544 #include <asm/proto.h>
32545 #include <asm/dma.h> /* for MAX_DMA_PFN */
32546 #include <asm/microcode.h>
32547+#include <asm/desc.h>
32548+#include <asm/bios_ebda.h>
32549
32550 #include "mm_internal.h"
32551
32552@@ -563,7 +566,18 @@ void __init init_mem_mapping(void)
32553 early_ioremap_page_table_range_init();
32554 #endif
32555
32556+#ifdef CONFIG_PAX_PER_CPU_PGD
32557+ clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
32558+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32559+ KERNEL_PGD_PTRS);
32560+ clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
32561+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32562+ KERNEL_PGD_PTRS);
32563+ load_cr3(get_cpu_pgd(0, kernel));
32564+#else
32565 load_cr3(swapper_pg_dir);
32566+#endif
32567+
32568 __flush_tlb_all();
32569
32570 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
32571@@ -579,10 +593,40 @@ void __init init_mem_mapping(void)
32572 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
32573 * mmio resources as well as potential bios/acpi data regions.
32574 */
32575+
32576+#ifdef CONFIG_GRKERNSEC_KMEM
32577+static unsigned int ebda_start __read_only;
32578+static unsigned int ebda_end __read_only;
32579+#endif
32580+
32581 int devmem_is_allowed(unsigned long pagenr)
32582 {
32583- if (pagenr < 256)
32584+#ifdef CONFIG_GRKERNSEC_KMEM
32585+ /* allow BDA */
32586+ if (!pagenr)
32587 return 1;
32588+ /* allow EBDA */
32589+ if (pagenr >= ebda_start && pagenr < ebda_end)
32590+ return 1;
32591+ /* if tboot is in use, allow access to its hardcoded serial log range */
32592+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
32593+ return 1;
32594+#else
32595+ if (!pagenr)
32596+ return 1;
32597+#ifdef CONFIG_VM86
32598+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
32599+ return 1;
32600+#endif
32601+#endif
32602+
32603+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
32604+ return 1;
32605+#ifdef CONFIG_GRKERNSEC_KMEM
32606+ /* throw out everything else below 1MB */
32607+ if (pagenr <= 256)
32608+ return 0;
32609+#endif
32610 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
32611 return 0;
32612 if (!page_is_ram(pagenr))
32613@@ -628,8 +672,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
32614 #endif
32615 }
32616
32617+#ifdef CONFIG_GRKERNSEC_KMEM
32618+static inline void gr_init_ebda(void)
32619+{
32620+ unsigned int ebda_addr;
32621+ unsigned int ebda_size = 0;
32622+
32623+ ebda_addr = get_bios_ebda();
32624+ if (ebda_addr) {
32625+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
32626+ ebda_size <<= 10;
32627+ }
32628+ if (ebda_addr && ebda_size) {
32629+ ebda_start = ebda_addr >> PAGE_SHIFT;
32630+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
32631+ } else {
32632+ ebda_start = 0x9f000 >> PAGE_SHIFT;
32633+ ebda_end = 0xa0000 >> PAGE_SHIFT;
32634+ }
32635+}
32636+#else
32637+static inline void gr_init_ebda(void) { }
32638+#endif
32639+
32640 void free_initmem(void)
32641 {
32642+#ifdef CONFIG_PAX_KERNEXEC
32643+#ifdef CONFIG_X86_32
32644+ /* PaX: limit KERNEL_CS to actual size */
32645+ unsigned long addr, limit;
32646+ struct desc_struct d;
32647+ int cpu;
32648+#else
32649+ pgd_t *pgd;
32650+ pud_t *pud;
32651+ pmd_t *pmd;
32652+ unsigned long addr, end;
32653+#endif
32654+#endif
32655+
32656+ gr_init_ebda();
32657+
32658+#ifdef CONFIG_PAX_KERNEXEC
32659+#ifdef CONFIG_X86_32
32660+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
32661+ limit = (limit - 1UL) >> PAGE_SHIFT;
32662+
32663+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
32664+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32665+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
32666+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
32667+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
32668+ }
32669+
32670+ /* PaX: make KERNEL_CS read-only */
32671+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
32672+ if (!paravirt_enabled())
32673+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
32674+/*
32675+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
32676+ pgd = pgd_offset_k(addr);
32677+ pud = pud_offset(pgd, addr);
32678+ pmd = pmd_offset(pud, addr);
32679+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32680+ }
32681+*/
32682+#ifdef CONFIG_X86_PAE
32683+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
32684+/*
32685+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
32686+ pgd = pgd_offset_k(addr);
32687+ pud = pud_offset(pgd, addr);
32688+ pmd = pmd_offset(pud, addr);
32689+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32690+ }
32691+*/
32692+#endif
32693+
32694+#ifdef CONFIG_MODULES
32695+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
32696+#endif
32697+
32698+#else
32699+ /* PaX: make kernel code/rodata read-only, rest non-executable */
32700+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
32701+ pgd = pgd_offset_k(addr);
32702+ pud = pud_offset(pgd, addr);
32703+ pmd = pmd_offset(pud, addr);
32704+ if (!pmd_present(*pmd))
32705+ continue;
32706+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
32707+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32708+ else
32709+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32710+ }
32711+
32712+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
32713+ end = addr + KERNEL_IMAGE_SIZE;
32714+ for (; addr < end; addr += PMD_SIZE) {
32715+ pgd = pgd_offset_k(addr);
32716+ pud = pud_offset(pgd, addr);
32717+ pmd = pmd_offset(pud, addr);
32718+ if (!pmd_present(*pmd))
32719+ continue;
32720+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
32721+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32722+ }
32723+#endif
32724+
32725+ flush_tlb_all();
32726+#endif
32727+
32728 free_init_pages("unused kernel",
32729 (unsigned long)(&__init_begin),
32730 (unsigned long)(&__init_end));
32731diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
32732index e395048..cd38278 100644
32733--- a/arch/x86/mm/init_32.c
32734+++ b/arch/x86/mm/init_32.c
32735@@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
32736 bool __read_mostly __vmalloc_start_set = false;
32737
32738 /*
32739- * Creates a middle page table and puts a pointer to it in the
32740- * given global directory entry. This only returns the gd entry
32741- * in non-PAE compilation mode, since the middle layer is folded.
32742- */
32743-static pmd_t * __init one_md_table_init(pgd_t *pgd)
32744-{
32745- pud_t *pud;
32746- pmd_t *pmd_table;
32747-
32748-#ifdef CONFIG_X86_PAE
32749- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
32750- pmd_table = (pmd_t *)alloc_low_page();
32751- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
32752- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
32753- pud = pud_offset(pgd, 0);
32754- BUG_ON(pmd_table != pmd_offset(pud, 0));
32755-
32756- return pmd_table;
32757- }
32758-#endif
32759- pud = pud_offset(pgd, 0);
32760- pmd_table = pmd_offset(pud, 0);
32761-
32762- return pmd_table;
32763-}
32764-
32765-/*
32766 * Create a page table and place a pointer to it in a middle page
32767 * directory entry:
32768 */
32769@@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
32770 pte_t *page_table = (pte_t *)alloc_low_page();
32771
32772 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
32773+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32774+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
32775+#else
32776 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
32777+#endif
32778 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
32779 }
32780
32781 return pte_offset_kernel(pmd, 0);
32782 }
32783
32784+static pmd_t * __init one_md_table_init(pgd_t *pgd)
32785+{
32786+ pud_t *pud;
32787+ pmd_t *pmd_table;
32788+
32789+ pud = pud_offset(pgd, 0);
32790+ pmd_table = pmd_offset(pud, 0);
32791+
32792+ return pmd_table;
32793+}
32794+
32795 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
32796 {
32797 int pgd_idx = pgd_index(vaddr);
32798@@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32799 int pgd_idx, pmd_idx;
32800 unsigned long vaddr;
32801 pgd_t *pgd;
32802+ pud_t *pud;
32803 pmd_t *pmd;
32804 pte_t *pte = NULL;
32805 unsigned long count = page_table_range_init_count(start, end);
32806@@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32807 pgd = pgd_base + pgd_idx;
32808
32809 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
32810- pmd = one_md_table_init(pgd);
32811- pmd = pmd + pmd_index(vaddr);
32812+ pud = pud_offset(pgd, vaddr);
32813+ pmd = pmd_offset(pud, vaddr);
32814+
32815+#ifdef CONFIG_X86_PAE
32816+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32817+#endif
32818+
32819 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
32820 pmd++, pmd_idx++) {
32821 pte = page_table_kmap_check(one_page_table_init(pmd),
32822@@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32823 }
32824 }
32825
32826-static inline int is_kernel_text(unsigned long addr)
32827+static inline int is_kernel_text(unsigned long start, unsigned long end)
32828 {
32829- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
32830- return 1;
32831- return 0;
32832+ if ((start >= ktla_ktva((unsigned long)_etext) ||
32833+ end <= ktla_ktva((unsigned long)_stext)) &&
32834+ (start >= ktla_ktva((unsigned long)_einittext) ||
32835+ end <= ktla_ktva((unsigned long)_sinittext)) &&
32836+
32837+#ifdef CONFIG_ACPI_SLEEP
32838+ (start >= (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
32839+#endif
32840+
32841+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
32842+ return 0;
32843+ return 1;
32844 }
32845
32846 /*
32847@@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
32848 unsigned long last_map_addr = end;
32849 unsigned long start_pfn, end_pfn;
32850 pgd_t *pgd_base = swapper_pg_dir;
32851- int pgd_idx, pmd_idx, pte_ofs;
32852+ unsigned int pgd_idx, pmd_idx, pte_ofs;
32853 unsigned long pfn;
32854 pgd_t *pgd;
32855+ pud_t *pud;
32856 pmd_t *pmd;
32857 pte_t *pte;
32858 unsigned pages_2m, pages_4k;
32859@@ -291,8 +295,13 @@ repeat:
32860 pfn = start_pfn;
32861 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32862 pgd = pgd_base + pgd_idx;
32863- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
32864- pmd = one_md_table_init(pgd);
32865+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
32866+ pud = pud_offset(pgd, 0);
32867+ pmd = pmd_offset(pud, 0);
32868+
32869+#ifdef CONFIG_X86_PAE
32870+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32871+#endif
32872
32873 if (pfn >= end_pfn)
32874 continue;
32875@@ -304,14 +313,13 @@ repeat:
32876 #endif
32877 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
32878 pmd++, pmd_idx++) {
32879- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
32880+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
32881
32882 /*
32883 * Map with big pages if possible, otherwise
32884 * create normal page tables:
32885 */
32886 if (use_pse) {
32887- unsigned int addr2;
32888 pgprot_t prot = PAGE_KERNEL_LARGE;
32889 /*
32890 * first pass will use the same initial
32891@@ -322,11 +330,7 @@ repeat:
32892 _PAGE_PSE);
32893
32894 pfn &= PMD_MASK >> PAGE_SHIFT;
32895- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
32896- PAGE_OFFSET + PAGE_SIZE-1;
32897-
32898- if (is_kernel_text(addr) ||
32899- is_kernel_text(addr2))
32900+ if (is_kernel_text(address, address + PMD_SIZE))
32901 prot = PAGE_KERNEL_LARGE_EXEC;
32902
32903 pages_2m++;
32904@@ -343,7 +347,7 @@ repeat:
32905 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32906 pte += pte_ofs;
32907 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
32908- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
32909+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
32910 pgprot_t prot = PAGE_KERNEL;
32911 /*
32912 * first pass will use the same initial
32913@@ -351,7 +355,7 @@ repeat:
32914 */
32915 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
32916
32917- if (is_kernel_text(addr))
32918+ if (is_kernel_text(address, address + PAGE_SIZE))
32919 prot = PAGE_KERNEL_EXEC;
32920
32921 pages_4k++;
32922@@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
32923
32924 pud = pud_offset(pgd, va);
32925 pmd = pmd_offset(pud, va);
32926- if (!pmd_present(*pmd))
32927+ if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
32928 break;
32929
32930 /* should not be large page here */
32931@@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
32932
32933 static void __init pagetable_init(void)
32934 {
32935- pgd_t *pgd_base = swapper_pg_dir;
32936-
32937- permanent_kmaps_init(pgd_base);
32938+ permanent_kmaps_init(swapper_pg_dir);
32939 }
32940
32941-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32942+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32943 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32944
32945 /* user-defined highmem size */
32946@@ -787,10 +789,10 @@ void __init mem_init(void)
32947 ((unsigned long)&__init_end -
32948 (unsigned long)&__init_begin) >> 10,
32949
32950- (unsigned long)&_etext, (unsigned long)&_edata,
32951- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
32952+ (unsigned long)&_sdata, (unsigned long)&_edata,
32953+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
32954
32955- (unsigned long)&_text, (unsigned long)&_etext,
32956+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
32957 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
32958
32959 /*
32960@@ -883,6 +885,7 @@ void set_kernel_text_rw(void)
32961 if (!kernel_set_to_readonly)
32962 return;
32963
32964+ start = ktla_ktva(start);
32965 pr_debug("Set kernel text: %lx - %lx for read write\n",
32966 start, start+size);
32967
32968@@ -897,6 +900,7 @@ void set_kernel_text_ro(void)
32969 if (!kernel_set_to_readonly)
32970 return;
32971
32972+ start = ktla_ktva(start);
32973 pr_debug("Set kernel text: %lx - %lx for read only\n",
32974 start, start+size);
32975
32976@@ -925,6 +929,7 @@ void mark_rodata_ro(void)
32977 unsigned long start = PFN_ALIGN(_text);
32978 unsigned long size = PFN_ALIGN(_etext) - start;
32979
32980+ start = ktla_ktva(start);
32981 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
32982 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
32983 size >> 10);
32984diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
32985index f35c66c..84b95ef 100644
32986--- a/arch/x86/mm/init_64.c
32987+++ b/arch/x86/mm/init_64.c
32988@@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
32989 * around without checking the pgd every time.
32990 */
32991
32992-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
32993+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
32994 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32995
32996 int force_personality32;
32997@@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32998
32999 for (address = start; address <= end; address += PGDIR_SIZE) {
33000 const pgd_t *pgd_ref = pgd_offset_k(address);
33001+
33002+#ifdef CONFIG_PAX_PER_CPU_PGD
33003+ unsigned long cpu;
33004+#else
33005 struct page *page;
33006+#endif
33007
33008 if (pgd_none(*pgd_ref))
33009 continue;
33010
33011 spin_lock(&pgd_lock);
33012+
33013+#ifdef CONFIG_PAX_PER_CPU_PGD
33014+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33015+ pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
33016+
33017+ if (pgd_none(*pgd))
33018+ set_pgd(pgd, *pgd_ref);
33019+ else
33020+ BUG_ON(pgd_page_vaddr(*pgd)
33021+ != pgd_page_vaddr(*pgd_ref));
33022+ pgd = pgd_offset_cpu(cpu, kernel, address);
33023+#else
33024 list_for_each_entry(page, &pgd_list, lru) {
33025 pgd_t *pgd;
33026 spinlock_t *pgt_lock;
33027@@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
33028 /* the pgt_lock only for Xen */
33029 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
33030 spin_lock(pgt_lock);
33031+#endif
33032
33033 if (pgd_none(*pgd))
33034 set_pgd(pgd, *pgd_ref);
33035@@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
33036 BUG_ON(pgd_page_vaddr(*pgd)
33037 != pgd_page_vaddr(*pgd_ref));
33038
33039+#ifndef CONFIG_PAX_PER_CPU_PGD
33040 spin_unlock(pgt_lock);
33041+#endif
33042+
33043 }
33044 spin_unlock(&pgd_lock);
33045 }
33046@@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
33047 {
33048 if (pgd_none(*pgd)) {
33049 pud_t *pud = (pud_t *)spp_getpage();
33050- pgd_populate(&init_mm, pgd, pud);
33051+ pgd_populate_kernel(&init_mm, pgd, pud);
33052 if (pud != pud_offset(pgd, 0))
33053 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
33054 pud, pud_offset(pgd, 0));
33055@@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
33056 {
33057 if (pud_none(*pud)) {
33058 pmd_t *pmd = (pmd_t *) spp_getpage();
33059- pud_populate(&init_mm, pud, pmd);
33060+ pud_populate_kernel(&init_mm, pud, pmd);
33061 if (pmd != pmd_offset(pud, 0))
33062 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
33063 pmd, pmd_offset(pud, 0));
33064@@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
33065 pmd = fill_pmd(pud, vaddr);
33066 pte = fill_pte(pmd, vaddr);
33067
33068+ pax_open_kernel();
33069 set_pte(pte, new_pte);
33070+ pax_close_kernel();
33071
33072 /*
33073 * It's enough to flush this one mapping.
33074@@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
33075 pgd = pgd_offset_k((unsigned long)__va(phys));
33076 if (pgd_none(*pgd)) {
33077 pud = (pud_t *) spp_getpage();
33078- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
33079- _PAGE_USER));
33080+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
33081 }
33082 pud = pud_offset(pgd, (unsigned long)__va(phys));
33083 if (pud_none(*pud)) {
33084 pmd = (pmd_t *) spp_getpage();
33085- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
33086- _PAGE_USER));
33087+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
33088 }
33089 pmd = pmd_offset(pud, phys);
33090 BUG_ON(!pmd_none(*pmd));
33091@@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
33092 prot);
33093
33094 spin_lock(&init_mm.page_table_lock);
33095- pud_populate(&init_mm, pud, pmd);
33096+ pud_populate_kernel(&init_mm, pud, pmd);
33097 spin_unlock(&init_mm.page_table_lock);
33098 }
33099 __flush_tlb_all();
33100@@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
33101 page_size_mask);
33102
33103 spin_lock(&init_mm.page_table_lock);
33104- pgd_populate(&init_mm, pgd, pud);
33105+ pgd_populate_kernel(&init_mm, pgd, pud);
33106 spin_unlock(&init_mm.page_table_lock);
33107 pgd_changed = true;
33108 }
33109@@ -1188,8 +1209,8 @@ int kern_addr_valid(unsigned long addr)
33110 static struct vm_area_struct gate_vma = {
33111 .vm_start = VSYSCALL_START,
33112 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
33113- .vm_page_prot = PAGE_READONLY_EXEC,
33114- .vm_flags = VM_READ | VM_EXEC
33115+ .vm_page_prot = PAGE_READONLY,
33116+ .vm_flags = VM_READ
33117 };
33118
33119 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
33120@@ -1223,7 +1244,7 @@ int in_gate_area_no_mm(unsigned long addr)
33121
33122 const char *arch_vma_name(struct vm_area_struct *vma)
33123 {
33124- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
33125+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
33126 return "[vdso]";
33127 if (vma == &gate_vma)
33128 return "[vsyscall]";
33129diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
33130index 7b179b4..6bd17777 100644
33131--- a/arch/x86/mm/iomap_32.c
33132+++ b/arch/x86/mm/iomap_32.c
33133@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
33134 type = kmap_atomic_idx_push();
33135 idx = type + KM_TYPE_NR * smp_processor_id();
33136 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
33137+
33138+ pax_open_kernel();
33139 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
33140+ pax_close_kernel();
33141+
33142 arch_flush_lazy_mmu_mode();
33143
33144 return (void *)vaddr;
33145diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
33146index 799580c..72f9fe0 100644
33147--- a/arch/x86/mm/ioremap.c
33148+++ b/arch/x86/mm/ioremap.c
33149@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
33150 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
33151 int is_ram = page_is_ram(pfn);
33152
33153- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
33154+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
33155 return NULL;
33156 WARN_ON_ONCE(is_ram);
33157 }
33158@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
33159 *
33160 * Caller must ensure there is only one unmapping for the same pointer.
33161 */
33162-void iounmap(volatile void __iomem *addr)
33163+void iounmap(const volatile void __iomem *addr)
33164 {
33165 struct vm_struct *p, *o;
33166
33167@@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
33168
33169 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
33170 if (page_is_ram(start >> PAGE_SHIFT))
33171+#ifdef CONFIG_HIGHMEM
33172+ if ((start >> PAGE_SHIFT) < max_low_pfn)
33173+#endif
33174 return __va(phys);
33175
33176 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
33177@@ -322,6 +325,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
33178 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
33179 {
33180 if (page_is_ram(phys >> PAGE_SHIFT))
33181+#ifdef CONFIG_HIGHMEM
33182+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
33183+#endif
33184 return;
33185
33186 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
33187@@ -339,7 +345,7 @@ static int __init early_ioremap_debug_setup(char *str)
33188 early_param("early_ioremap_debug", early_ioremap_debug_setup);
33189
33190 static __initdata int after_paging_init;
33191-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
33192+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
33193
33194 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
33195 {
33196@@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
33197 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
33198
33199 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
33200- memset(bm_pte, 0, sizeof(bm_pte));
33201- pmd_populate_kernel(&init_mm, pmd, bm_pte);
33202+ pmd_populate_user(&init_mm, pmd, bm_pte);
33203
33204 /*
33205 * The boot-ioremap range spans multiple pmds, for which
33206diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
33207index d87dd6d..bf3fa66 100644
33208--- a/arch/x86/mm/kmemcheck/kmemcheck.c
33209+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
33210@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
33211 * memory (e.g. tracked pages)? For now, we need this to avoid
33212 * invoking kmemcheck for PnP BIOS calls.
33213 */
33214- if (regs->flags & X86_VM_MASK)
33215+ if (v8086_mode(regs))
33216 return false;
33217- if (regs->cs != __KERNEL_CS)
33218+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
33219 return false;
33220
33221 pte = kmemcheck_pte_lookup(address);
33222diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
33223index 25e7e13..1964579 100644
33224--- a/arch/x86/mm/mmap.c
33225+++ b/arch/x86/mm/mmap.c
33226@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
33227 * Leave an at least ~128 MB hole with possible stack randomization.
33228 */
33229 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
33230-#define MAX_GAP (TASK_SIZE/6*5)
33231+#define MAX_GAP (pax_task_size/6*5)
33232
33233 static int mmap_is_legacy(void)
33234 {
33235@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
33236 return rnd << PAGE_SHIFT;
33237 }
33238
33239-static unsigned long mmap_base(void)
33240+static unsigned long mmap_base(struct mm_struct *mm)
33241 {
33242 unsigned long gap = rlimit(RLIMIT_STACK);
33243+ unsigned long pax_task_size = TASK_SIZE;
33244+
33245+#ifdef CONFIG_PAX_SEGMEXEC
33246+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
33247+ pax_task_size = SEGMEXEC_TASK_SIZE;
33248+#endif
33249
33250 if (gap < MIN_GAP)
33251 gap = MIN_GAP;
33252 else if (gap > MAX_GAP)
33253 gap = MAX_GAP;
33254
33255- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
33256+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
33257 }
33258
33259 /*
33260 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
33261 * does, but not when emulating X86_32
33262 */
33263-static unsigned long mmap_legacy_base(void)
33264+static unsigned long mmap_legacy_base(struct mm_struct *mm)
33265 {
33266- if (mmap_is_ia32())
33267+ if (mmap_is_ia32()) {
33268+
33269+#ifdef CONFIG_PAX_SEGMEXEC
33270+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
33271+ return SEGMEXEC_TASK_UNMAPPED_BASE;
33272+ else
33273+#endif
33274+
33275 return TASK_UNMAPPED_BASE;
33276- else
33277+ } else
33278 return TASK_UNMAPPED_BASE + mmap_rnd();
33279 }
33280
33281@@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
33282 */
33283 void arch_pick_mmap_layout(struct mm_struct *mm)
33284 {
33285- mm->mmap_legacy_base = mmap_legacy_base();
33286- mm->mmap_base = mmap_base();
33287+ mm->mmap_legacy_base = mmap_legacy_base(mm);
33288+ mm->mmap_base = mmap_base(mm);
33289+
33290+#ifdef CONFIG_PAX_RANDMMAP
33291+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
33292+ mm->mmap_legacy_base += mm->delta_mmap;
33293+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
33294+ }
33295+#endif
33296
33297 if (mmap_is_legacy()) {
33298 mm->mmap_base = mm->mmap_legacy_base;
33299diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
33300index 0057a7a..95c7edd 100644
33301--- a/arch/x86/mm/mmio-mod.c
33302+++ b/arch/x86/mm/mmio-mod.c
33303@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
33304 break;
33305 default:
33306 {
33307- unsigned char *ip = (unsigned char *)instptr;
33308+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
33309 my_trace->opcode = MMIO_UNKNOWN_OP;
33310 my_trace->width = 0;
33311 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
33312@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
33313 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33314 void __iomem *addr)
33315 {
33316- static atomic_t next_id;
33317+ static atomic_unchecked_t next_id;
33318 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
33319 /* These are page-unaligned. */
33320 struct mmiotrace_map map = {
33321@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33322 .private = trace
33323 },
33324 .phys = offset,
33325- .id = atomic_inc_return(&next_id)
33326+ .id = atomic_inc_return_unchecked(&next_id)
33327 };
33328 map.map_id = trace->id;
33329
33330@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
33331 ioremap_trace_core(offset, size, addr);
33332 }
33333
33334-static void iounmap_trace_core(volatile void __iomem *addr)
33335+static void iounmap_trace_core(const volatile void __iomem *addr)
33336 {
33337 struct mmiotrace_map map = {
33338 .phys = 0,
33339@@ -328,7 +328,7 @@ not_enabled:
33340 }
33341 }
33342
33343-void mmiotrace_iounmap(volatile void __iomem *addr)
33344+void mmiotrace_iounmap(const volatile void __iomem *addr)
33345 {
33346 might_sleep();
33347 if (is_enabled()) /* recheck and proper locking in *_core() */
33348diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
33349index 27aa0455..0eb1406 100644
33350--- a/arch/x86/mm/numa.c
33351+++ b/arch/x86/mm/numa.c
33352@@ -478,7 +478,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
33353 return true;
33354 }
33355
33356-static int __init numa_register_memblks(struct numa_meminfo *mi)
33357+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
33358 {
33359 unsigned long uninitialized_var(pfn_align);
33360 int i, nid;
33361diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
33362index 461bc82..4e091a3 100644
33363--- a/arch/x86/mm/pageattr-test.c
33364+++ b/arch/x86/mm/pageattr-test.c
33365@@ -35,7 +35,7 @@ enum {
33366
33367 static int pte_testbit(pte_t pte)
33368 {
33369- return pte_flags(pte) & _PAGE_UNUSED1;
33370+ return pte_flags(pte) & _PAGE_CPA_TEST;
33371 }
33372
33373 struct split_state {
33374diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
33375index a348868..3c64310 100644
33376--- a/arch/x86/mm/pageattr.c
33377+++ b/arch/x86/mm/pageattr.c
33378@@ -262,7 +262,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33379 */
33380 #ifdef CONFIG_PCI_BIOS
33381 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
33382- pgprot_val(forbidden) |= _PAGE_NX;
33383+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33384 #endif
33385
33386 /*
33387@@ -270,9 +270,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33388 * Does not cover __inittext since that is gone later on. On
33389 * 64bit we do not enforce !NX on the low mapping
33390 */
33391- if (within(address, (unsigned long)_text, (unsigned long)_etext))
33392- pgprot_val(forbidden) |= _PAGE_NX;
33393+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
33394+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33395
33396+#ifdef CONFIG_DEBUG_RODATA
33397 /*
33398 * The .rodata section needs to be read-only. Using the pfn
33399 * catches all aliases.
33400@@ -280,6 +281,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33401 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
33402 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
33403 pgprot_val(forbidden) |= _PAGE_RW;
33404+#endif
33405
33406 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
33407 /*
33408@@ -318,6 +320,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33409 }
33410 #endif
33411
33412+#ifdef CONFIG_PAX_KERNEXEC
33413+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
33414+ pgprot_val(forbidden) |= _PAGE_RW;
33415+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33416+ }
33417+#endif
33418+
33419 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
33420
33421 return prot;
33422@@ -416,23 +425,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
33423 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
33424 {
33425 /* change init_mm */
33426+ pax_open_kernel();
33427 set_pte_atomic(kpte, pte);
33428+
33429 #ifdef CONFIG_X86_32
33430 if (!SHARED_KERNEL_PMD) {
33431+
33432+#ifdef CONFIG_PAX_PER_CPU_PGD
33433+ unsigned long cpu;
33434+#else
33435 struct page *page;
33436+#endif
33437
33438+#ifdef CONFIG_PAX_PER_CPU_PGD
33439+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33440+ pgd_t *pgd = get_cpu_pgd(cpu, kernel);
33441+#else
33442 list_for_each_entry(page, &pgd_list, lru) {
33443- pgd_t *pgd;
33444+ pgd_t *pgd = (pgd_t *)page_address(page);
33445+#endif
33446+
33447 pud_t *pud;
33448 pmd_t *pmd;
33449
33450- pgd = (pgd_t *)page_address(page) + pgd_index(address);
33451+ pgd += pgd_index(address);
33452 pud = pud_offset(pgd, address);
33453 pmd = pmd_offset(pud, address);
33454 set_pte_atomic((pte_t *)pmd, pte);
33455 }
33456 }
33457 #endif
33458+ pax_close_kernel();
33459 }
33460
33461 static int
33462diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
33463index 6574388..87e9bef 100644
33464--- a/arch/x86/mm/pat.c
33465+++ b/arch/x86/mm/pat.c
33466@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
33467
33468 if (!entry) {
33469 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
33470- current->comm, current->pid, start, end - 1);
33471+ current->comm, task_pid_nr(current), start, end - 1);
33472 return -EINVAL;
33473 }
33474
33475@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33476
33477 while (cursor < to) {
33478 if (!devmem_is_allowed(pfn)) {
33479- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
33480- current->comm, from, to - 1);
33481+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
33482+ current->comm, from, to - 1, cursor);
33483 return 0;
33484 }
33485 cursor += PAGE_SIZE;
33486@@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
33487 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
33488 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
33489 "for [mem %#010Lx-%#010Lx]\n",
33490- current->comm, current->pid,
33491+ current->comm, task_pid_nr(current),
33492 cattr_name(flags),
33493 base, (unsigned long long)(base + size-1));
33494 return -EINVAL;
33495@@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33496 flags = lookup_memtype(paddr);
33497 if (want_flags != flags) {
33498 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
33499- current->comm, current->pid,
33500+ current->comm, task_pid_nr(current),
33501 cattr_name(want_flags),
33502 (unsigned long long)paddr,
33503 (unsigned long long)(paddr + size - 1),
33504@@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33505 free_memtype(paddr, paddr + size);
33506 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
33507 " for [mem %#010Lx-%#010Lx], got %s\n",
33508- current->comm, current->pid,
33509+ current->comm, task_pid_nr(current),
33510 cattr_name(want_flags),
33511 (unsigned long long)paddr,
33512 (unsigned long long)(paddr + size - 1),
33513diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
33514index 415f6c4..d319983 100644
33515--- a/arch/x86/mm/pat_rbtree.c
33516+++ b/arch/x86/mm/pat_rbtree.c
33517@@ -160,7 +160,7 @@ success:
33518
33519 failure:
33520 printk(KERN_INFO "%s:%d conflicting memory types "
33521- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
33522+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
33523 end, cattr_name(found_type), cattr_name(match->type));
33524 return -EBUSY;
33525 }
33526diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
33527index 9f0614d..92ae64a 100644
33528--- a/arch/x86/mm/pf_in.c
33529+++ b/arch/x86/mm/pf_in.c
33530@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
33531 int i;
33532 enum reason_type rv = OTHERS;
33533
33534- p = (unsigned char *)ins_addr;
33535+ p = (unsigned char *)ktla_ktva(ins_addr);
33536 p += skip_prefix(p, &prf);
33537 p += get_opcode(p, &opcode);
33538
33539@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
33540 struct prefix_bits prf;
33541 int i;
33542
33543- p = (unsigned char *)ins_addr;
33544+ p = (unsigned char *)ktla_ktva(ins_addr);
33545 p += skip_prefix(p, &prf);
33546 p += get_opcode(p, &opcode);
33547
33548@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
33549 struct prefix_bits prf;
33550 int i;
33551
33552- p = (unsigned char *)ins_addr;
33553+ p = (unsigned char *)ktla_ktva(ins_addr);
33554 p += skip_prefix(p, &prf);
33555 p += get_opcode(p, &opcode);
33556
33557@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
33558 struct prefix_bits prf;
33559 int i;
33560
33561- p = (unsigned char *)ins_addr;
33562+ p = (unsigned char *)ktla_ktva(ins_addr);
33563 p += skip_prefix(p, &prf);
33564 p += get_opcode(p, &opcode);
33565 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
33566@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
33567 struct prefix_bits prf;
33568 int i;
33569
33570- p = (unsigned char *)ins_addr;
33571+ p = (unsigned char *)ktla_ktva(ins_addr);
33572 p += skip_prefix(p, &prf);
33573 p += get_opcode(p, &opcode);
33574 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
33575diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
33576index c96314a..433b127 100644
33577--- a/arch/x86/mm/pgtable.c
33578+++ b/arch/x86/mm/pgtable.c
33579@@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
33580 list_del(&page->lru);
33581 }
33582
33583-#define UNSHARED_PTRS_PER_PGD \
33584- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33585+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33586+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
33587
33588+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
33589+{
33590+ unsigned int count = USER_PGD_PTRS;
33591
33592+ if (!pax_user_shadow_base)
33593+ return;
33594+
33595+ while (count--)
33596+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
33597+}
33598+#endif
33599+
33600+#ifdef CONFIG_PAX_PER_CPU_PGD
33601+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
33602+{
33603+ unsigned int count = USER_PGD_PTRS;
33604+
33605+ while (count--) {
33606+ pgd_t pgd;
33607+
33608+#ifdef CONFIG_X86_64
33609+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
33610+#else
33611+ pgd = *src++;
33612+#endif
33613+
33614+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33615+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
33616+#endif
33617+
33618+ *dst++ = pgd;
33619+ }
33620+
33621+}
33622+#endif
33623+
33624+#ifdef CONFIG_X86_64
33625+#define pxd_t pud_t
33626+#define pyd_t pgd_t
33627+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
33628+#define pgtable_pxd_page_ctor(page) true
33629+#define pgtable_pxd_page_dtor(page)
33630+#define pxd_free(mm, pud) pud_free((mm), (pud))
33631+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
33632+#define pyd_offset(mm, address) pgd_offset((mm), (address))
33633+#define PYD_SIZE PGDIR_SIZE
33634+#else
33635+#define pxd_t pmd_t
33636+#define pyd_t pud_t
33637+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
33638+#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
33639+#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
33640+#define pxd_free(mm, pud) pmd_free((mm), (pud))
33641+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
33642+#define pyd_offset(mm, address) pud_offset((mm), (address))
33643+#define PYD_SIZE PUD_SIZE
33644+#endif
33645+
33646+#ifdef CONFIG_PAX_PER_CPU_PGD
33647+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
33648+static inline void pgd_dtor(pgd_t *pgd) {}
33649+#else
33650 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
33651 {
33652 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
33653@@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
33654 pgd_list_del(pgd);
33655 spin_unlock(&pgd_lock);
33656 }
33657+#endif
33658
33659 /*
33660 * List of all pgd's needed for non-PAE so it can invalidate entries
33661@@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
33662 * -- nyc
33663 */
33664
33665-#ifdef CONFIG_X86_PAE
33666+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
33667 /*
33668 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
33669 * updating the top-level pagetable entries to guarantee the
33670@@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
33671 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
33672 * and initialize the kernel pmds here.
33673 */
33674-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
33675+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33676
33677 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33678 {
33679@@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33680 */
33681 flush_tlb_mm(mm);
33682 }
33683+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
33684+#define PREALLOCATED_PXDS USER_PGD_PTRS
33685 #else /* !CONFIG_X86_PAE */
33686
33687 /* No need to prepopulate any pagetable entries in non-PAE modes. */
33688-#define PREALLOCATED_PMDS 0
33689+#define PREALLOCATED_PXDS 0
33690
33691 #endif /* CONFIG_X86_PAE */
33692
33693-static void free_pmds(pmd_t *pmds[])
33694+static void free_pxds(pxd_t *pxds[])
33695 {
33696 int i;
33697
33698- for(i = 0; i < PREALLOCATED_PMDS; i++)
33699- if (pmds[i]) {
33700- pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
33701- free_page((unsigned long)pmds[i]);
33702+ for(i = 0; i < PREALLOCATED_PXDS; i++)
33703+ if (pxds[i]) {
33704+ pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
33705+ free_page((unsigned long)pxds[i]);
33706 }
33707 }
33708
33709-static int preallocate_pmds(pmd_t *pmds[])
33710+static int preallocate_pxds(pxd_t *pxds[])
33711 {
33712 int i;
33713 bool failed = false;
33714
33715- for(i = 0; i < PREALLOCATED_PMDS; i++) {
33716- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
33717- if (!pmd)
33718+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
33719+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
33720+ if (!pxd)
33721 failed = true;
33722- if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
33723- free_page((unsigned long)pmd);
33724- pmd = NULL;
33725+ if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
33726+ free_page((unsigned long)pxd);
33727+ pxd = NULL;
33728 failed = true;
33729 }
33730- pmds[i] = pmd;
33731+ pxds[i] = pxd;
33732 }
33733
33734 if (failed) {
33735- free_pmds(pmds);
33736+ free_pxds(pxds);
33737 return -ENOMEM;
33738 }
33739
33740@@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
33741 * preallocate which never got a corresponding vma will need to be
33742 * freed manually.
33743 */
33744-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
33745+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
33746 {
33747 int i;
33748
33749- for(i = 0; i < PREALLOCATED_PMDS; i++) {
33750+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
33751 pgd_t pgd = pgdp[i];
33752
33753 if (pgd_val(pgd) != 0) {
33754- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
33755+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
33756
33757- pgdp[i] = native_make_pgd(0);
33758+ set_pgd(pgdp + i, native_make_pgd(0));
33759
33760- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
33761- pmd_free(mm, pmd);
33762+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
33763+ pxd_free(mm, pxd);
33764 }
33765 }
33766 }
33767
33768-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
33769+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
33770 {
33771- pud_t *pud;
33772+ pyd_t *pyd;
33773 int i;
33774
33775- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
33776+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
33777 return;
33778
33779- pud = pud_offset(pgd, 0);
33780-
33781- for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
33782- pmd_t *pmd = pmds[i];
33783+#ifdef CONFIG_X86_64
33784+ pyd = pyd_offset(mm, 0L);
33785+#else
33786+ pyd = pyd_offset(pgd, 0L);
33787+#endif
33788
33789+ for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
33790+ pxd_t *pxd = pxds[i];
33791 if (i >= KERNEL_PGD_BOUNDARY)
33792- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33793- sizeof(pmd_t) * PTRS_PER_PMD);
33794+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33795+ sizeof(pxd_t) * PTRS_PER_PMD);
33796
33797- pud_populate(mm, pud, pmd);
33798+ pyd_populate(mm, pyd, pxd);
33799 }
33800 }
33801
33802 pgd_t *pgd_alloc(struct mm_struct *mm)
33803 {
33804 pgd_t *pgd;
33805- pmd_t *pmds[PREALLOCATED_PMDS];
33806+ pxd_t *pxds[PREALLOCATED_PXDS];
33807
33808 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
33809
33810@@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33811
33812 mm->pgd = pgd;
33813
33814- if (preallocate_pmds(pmds) != 0)
33815+ if (preallocate_pxds(pxds) != 0)
33816 goto out_free_pgd;
33817
33818 if (paravirt_pgd_alloc(mm) != 0)
33819- goto out_free_pmds;
33820+ goto out_free_pxds;
33821
33822 /*
33823 * Make sure that pre-populating the pmds is atomic with
33824@@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33825 spin_lock(&pgd_lock);
33826
33827 pgd_ctor(mm, pgd);
33828- pgd_prepopulate_pmd(mm, pgd, pmds);
33829+ pgd_prepopulate_pxd(mm, pgd, pxds);
33830
33831 spin_unlock(&pgd_lock);
33832
33833 return pgd;
33834
33835-out_free_pmds:
33836- free_pmds(pmds);
33837+out_free_pxds:
33838+ free_pxds(pxds);
33839 out_free_pgd:
33840 free_page((unsigned long)pgd);
33841 out:
33842@@ -313,7 +380,7 @@ out:
33843
33844 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
33845 {
33846- pgd_mop_up_pmds(mm, pgd);
33847+ pgd_mop_up_pxds(mm, pgd);
33848 pgd_dtor(pgd);
33849 paravirt_pgd_free(mm, pgd);
33850 free_page((unsigned long)pgd);
33851diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
33852index a69bcb8..19068ab 100644
33853--- a/arch/x86/mm/pgtable_32.c
33854+++ b/arch/x86/mm/pgtable_32.c
33855@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
33856 return;
33857 }
33858 pte = pte_offset_kernel(pmd, vaddr);
33859+
33860+ pax_open_kernel();
33861 if (pte_val(pteval))
33862 set_pte_at(&init_mm, vaddr, pte, pteval);
33863 else
33864 pte_clear(&init_mm, vaddr, pte);
33865+ pax_close_kernel();
33866
33867 /*
33868 * It's enough to flush this one mapping.
33869diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
33870index e666cbb..61788c45 100644
33871--- a/arch/x86/mm/physaddr.c
33872+++ b/arch/x86/mm/physaddr.c
33873@@ -10,7 +10,7 @@
33874 #ifdef CONFIG_X86_64
33875
33876 #ifdef CONFIG_DEBUG_VIRTUAL
33877-unsigned long __phys_addr(unsigned long x)
33878+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33879 {
33880 unsigned long y = x - __START_KERNEL_map;
33881
33882@@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
33883 #else
33884
33885 #ifdef CONFIG_DEBUG_VIRTUAL
33886-unsigned long __phys_addr(unsigned long x)
33887+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33888 {
33889 unsigned long phys_addr = x - PAGE_OFFSET;
33890 /* VMALLOC_* aren't constants */
33891diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
33892index 90555bf..f5f1828 100644
33893--- a/arch/x86/mm/setup_nx.c
33894+++ b/arch/x86/mm/setup_nx.c
33895@@ -5,8 +5,10 @@
33896 #include <asm/pgtable.h>
33897 #include <asm/proto.h>
33898
33899+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33900 static int disable_nx;
33901
33902+#ifndef CONFIG_PAX_PAGEEXEC
33903 /*
33904 * noexec = on|off
33905 *
33906@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
33907 return 0;
33908 }
33909 early_param("noexec", noexec_setup);
33910+#endif
33911+
33912+#endif
33913
33914 void x86_configure_nx(void)
33915 {
33916+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33917 if (cpu_has_nx && !disable_nx)
33918 __supported_pte_mask |= _PAGE_NX;
33919 else
33920+#endif
33921 __supported_pte_mask &= ~_PAGE_NX;
33922 }
33923
33924diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
33925index dd8dda1..9e9b0f6 100644
33926--- a/arch/x86/mm/tlb.c
33927+++ b/arch/x86/mm/tlb.c
33928@@ -48,7 +48,11 @@ void leave_mm(int cpu)
33929 BUG();
33930 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
33931 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
33932+
33933+#ifndef CONFIG_PAX_PER_CPU_PGD
33934 load_cr3(swapper_pg_dir);
33935+#endif
33936+
33937 }
33938 }
33939 EXPORT_SYMBOL_GPL(leave_mm);
33940diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
33941new file mode 100644
33942index 0000000..dace51c
33943--- /dev/null
33944+++ b/arch/x86/mm/uderef_64.c
33945@@ -0,0 +1,37 @@
33946+#include <linux/mm.h>
33947+#include <asm/pgtable.h>
33948+#include <asm/uaccess.h>
33949+
33950+#ifdef CONFIG_PAX_MEMORY_UDEREF
33951+/* PaX: due to the special call convention these functions must
33952+ * - remain leaf functions under all configurations,
33953+ * - never be called directly, only dereferenced from the wrappers.
33954+ */
33955+void __pax_open_userland(void)
33956+{
33957+ unsigned int cpu;
33958+
33959+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
33960+ return;
33961+
33962+ cpu = raw_get_cpu();
33963+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
33964+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
33965+ raw_put_cpu_no_resched();
33966+}
33967+EXPORT_SYMBOL(__pax_open_userland);
33968+
33969+void __pax_close_userland(void)
33970+{
33971+ unsigned int cpu;
33972+
33973+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
33974+ return;
33975+
33976+ cpu = raw_get_cpu();
33977+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
33978+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
33979+ raw_put_cpu_no_resched();
33980+}
33981+EXPORT_SYMBOL(__pax_close_userland);
33982+#endif
33983diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
33984index 0149575..f746de8 100644
33985--- a/arch/x86/net/bpf_jit.S
33986+++ b/arch/x86/net/bpf_jit.S
33987@@ -9,6 +9,7 @@
33988 */
33989 #include <linux/linkage.h>
33990 #include <asm/dwarf2.h>
33991+#include <asm/alternative-asm.h>
33992
33993 /*
33994 * Calling convention :
33995@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
33996 jle bpf_slow_path_word
33997 mov (SKBDATA,%rsi),%eax
33998 bswap %eax /* ntohl() */
33999+ pax_force_retaddr
34000 ret
34001
34002 sk_load_half:
34003@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
34004 jle bpf_slow_path_half
34005 movzwl (SKBDATA,%rsi),%eax
34006 rol $8,%ax # ntohs()
34007+ pax_force_retaddr
34008 ret
34009
34010 sk_load_byte:
34011@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
34012 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
34013 jle bpf_slow_path_byte
34014 movzbl (SKBDATA,%rsi),%eax
34015+ pax_force_retaddr
34016 ret
34017
34018 /**
34019@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
34020 movzbl (SKBDATA,%rsi),%ebx
34021 and $15,%bl
34022 shl $2,%bl
34023+ pax_force_retaddr
34024 ret
34025
34026 /* rsi contains offset and can be scratched */
34027@@ -109,6 +114,7 @@ bpf_slow_path_word:
34028 js bpf_error
34029 mov -12(%rbp),%eax
34030 bswap %eax
34031+ pax_force_retaddr
34032 ret
34033
34034 bpf_slow_path_half:
34035@@ -117,12 +123,14 @@ bpf_slow_path_half:
34036 mov -12(%rbp),%ax
34037 rol $8,%ax
34038 movzwl %ax,%eax
34039+ pax_force_retaddr
34040 ret
34041
34042 bpf_slow_path_byte:
34043 bpf_slow_path_common(1)
34044 js bpf_error
34045 movzbl -12(%rbp),%eax
34046+ pax_force_retaddr
34047 ret
34048
34049 bpf_slow_path_byte_msh:
34050@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
34051 and $15,%al
34052 shl $2,%al
34053 xchg %eax,%ebx
34054+ pax_force_retaddr
34055 ret
34056
34057 #define sk_negative_common(SIZE) \
34058@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
34059 sk_negative_common(4)
34060 mov (%rax), %eax
34061 bswap %eax
34062+ pax_force_retaddr
34063 ret
34064
34065 bpf_slow_path_half_neg:
34066@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
34067 mov (%rax),%ax
34068 rol $8,%ax
34069 movzwl %ax,%eax
34070+ pax_force_retaddr
34071 ret
34072
34073 bpf_slow_path_byte_neg:
34074@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
34075 .globl sk_load_byte_negative_offset
34076 sk_negative_common(1)
34077 movzbl (%rax), %eax
34078+ pax_force_retaddr
34079 ret
34080
34081 bpf_slow_path_byte_msh_neg:
34082@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
34083 and $15,%al
34084 shl $2,%al
34085 xchg %eax,%ebx
34086+ pax_force_retaddr
34087 ret
34088
34089 bpf_error:
34090@@ -197,4 +210,5 @@ bpf_error:
34091 xor %eax,%eax
34092 mov -8(%rbp),%rbx
34093 leaveq
34094+ pax_force_retaddr
34095 ret
34096diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
34097index 4ed75dd..3cf24f0b 100644
34098--- a/arch/x86/net/bpf_jit_comp.c
34099+++ b/arch/x86/net/bpf_jit_comp.c
34100@@ -50,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
34101 return ptr + len;
34102 }
34103
34104+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34105+#define MAX_INSTR_CODE_SIZE 96
34106+#else
34107+#define MAX_INSTR_CODE_SIZE 64
34108+#endif
34109+
34110 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
34111
34112 #define EMIT1(b1) EMIT(b1, 1)
34113 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
34114 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
34115 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
34116+
34117+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34118+/* original constant will appear in ecx */
34119+#define DILUTE_CONST_SEQUENCE(_off, _key) \
34120+do { \
34121+ /* mov ecx, randkey */ \
34122+ EMIT1(0xb9); \
34123+ EMIT(_key, 4); \
34124+ /* xor ecx, randkey ^ off */ \
34125+ EMIT2(0x81, 0xf1); \
34126+ EMIT((_key) ^ (_off), 4); \
34127+} while (0)
34128+
34129+#define EMIT1_off32(b1, _off) \
34130+do { \
34131+ switch (b1) { \
34132+ case 0x05: /* add eax, imm32 */ \
34133+ case 0x2d: /* sub eax, imm32 */ \
34134+ case 0x25: /* and eax, imm32 */ \
34135+ case 0x0d: /* or eax, imm32 */ \
34136+ case 0xb8: /* mov eax, imm32 */ \
34137+ case 0x35: /* xor eax, imm32 */ \
34138+ case 0x3d: /* cmp eax, imm32 */ \
34139+ case 0xa9: /* test eax, imm32 */ \
34140+ DILUTE_CONST_SEQUENCE(_off, randkey); \
34141+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
34142+ break; \
34143+ case 0xbb: /* mov ebx, imm32 */ \
34144+ DILUTE_CONST_SEQUENCE(_off, randkey); \
34145+ /* mov ebx, ecx */ \
34146+ EMIT2(0x89, 0xcb); \
34147+ break; \
34148+ case 0xbe: /* mov esi, imm32 */ \
34149+ DILUTE_CONST_SEQUENCE(_off, randkey); \
34150+ /* mov esi, ecx */ \
34151+ EMIT2(0x89, 0xce); \
34152+ break; \
34153+ case 0xe8: /* call rel imm32, always to known funcs */ \
34154+ EMIT1(b1); \
34155+ EMIT(_off, 4); \
34156+ break; \
34157+ case 0xe9: /* jmp rel imm32 */ \
34158+ EMIT1(b1); \
34159+ EMIT(_off, 4); \
34160+ /* prevent fall-through, we're not called if off = 0 */ \
34161+ EMIT(0xcccccccc, 4); \
34162+ EMIT(0xcccccccc, 4); \
34163+ break; \
34164+ default: \
34165+ BUILD_BUG(); \
34166+ } \
34167+} while (0)
34168+
34169+#define EMIT2_off32(b1, b2, _off) \
34170+do { \
34171+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
34172+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
34173+ EMIT(randkey, 4); \
34174+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
34175+ EMIT((_off) - randkey, 4); \
34176+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
34177+ DILUTE_CONST_SEQUENCE(_off, randkey); \
34178+ /* imul eax, ecx */ \
34179+ EMIT3(0x0f, 0xaf, 0xc1); \
34180+ } else { \
34181+ BUILD_BUG(); \
34182+ } \
34183+} while (0)
34184+#else
34185 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
34186+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
34187+#endif
34188
34189 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
34190 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
34191@@ -91,6 +168,24 @@ do { \
34192 #define X86_JBE 0x76
34193 #define X86_JA 0x77
34194
34195+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34196+#define APPEND_FLOW_VERIFY() \
34197+do { \
34198+ /* mov ecx, randkey */ \
34199+ EMIT1(0xb9); \
34200+ EMIT(randkey, 4); \
34201+ /* cmp ecx, randkey */ \
34202+ EMIT2(0x81, 0xf9); \
34203+ EMIT(randkey, 4); \
34204+ /* jz after 8 int 3s */ \
34205+ EMIT2(0x74, 0x08); \
34206+ EMIT(0xcccccccc, 4); \
34207+ EMIT(0xcccccccc, 4); \
34208+} while (0)
34209+#else
34210+#define APPEND_FLOW_VERIFY() do { } while (0)
34211+#endif
34212+
34213 #define EMIT_COND_JMP(op, offset) \
34214 do { \
34215 if (is_near(offset)) \
34216@@ -98,6 +193,7 @@ do { \
34217 else { \
34218 EMIT2(0x0f, op + 0x10); \
34219 EMIT(offset, 4); /* jxx .+off32 */ \
34220+ APPEND_FLOW_VERIFY(); \
34221 } \
34222 } while (0)
34223
34224@@ -145,55 +241,54 @@ static int pkt_type_offset(void)
34225 return -1;
34226 }
34227
34228-struct bpf_binary_header {
34229- unsigned int pages;
34230- /* Note : for security reasons, bpf code will follow a randomly
34231- * sized amount of int3 instructions
34232- */
34233- u8 image[];
34234-};
34235-
34236-static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
34237+/* Note : for security reasons, bpf code will follow a randomly
34238+ * sized amount of int3 instructions
34239+ */
34240+static u8 *bpf_alloc_binary(unsigned int proglen,
34241 u8 **image_ptr)
34242 {
34243 unsigned int sz, hole;
34244- struct bpf_binary_header *header;
34245+ u8 *header;
34246
34247 /* Most of BPF filters are really small,
34248 * but if some of them fill a page, allow at least
34249 * 128 extra bytes to insert a random section of int3
34250 */
34251- sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
34252- header = module_alloc(sz);
34253+ sz = round_up(proglen + 128, PAGE_SIZE);
34254+ header = module_alloc_exec(sz);
34255 if (!header)
34256 return NULL;
34257
34258+ pax_open_kernel();
34259 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
34260+ pax_close_kernel();
34261
34262- header->pages = sz / PAGE_SIZE;
34263- hole = sz - (proglen + sizeof(*header));
34264+ hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
34265
34266 /* insert a random number of int3 instructions before BPF code */
34267- *image_ptr = &header->image[prandom_u32() % hole];
34268+ *image_ptr = &header[prandom_u32() % hole];
34269 return header;
34270 }
34271
34272 void bpf_jit_compile(struct sk_filter *fp)
34273 {
34274- u8 temp[64];
34275+ u8 temp[MAX_INSTR_CODE_SIZE];
34276 u8 *prog;
34277 unsigned int proglen, oldproglen = 0;
34278 int ilen, i;
34279 int t_offset, f_offset;
34280 u8 t_op, f_op, seen = 0, pass;
34281 u8 *image = NULL;
34282- struct bpf_binary_header *header = NULL;
34283+ u8 *header = NULL;
34284 u8 *func;
34285 int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
34286 unsigned int cleanup_addr; /* epilogue code offset */
34287 unsigned int *addrs;
34288 const struct sock_filter *filter = fp->insns;
34289 int flen = fp->len;
34290+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34291+ unsigned int randkey;
34292+#endif
34293
34294 if (!bpf_jit_enable)
34295 return;
34296@@ -203,10 +298,10 @@ void bpf_jit_compile(struct sk_filter *fp)
34297 return;
34298
34299 /* Before first pass, make a rough estimation of addrs[]
34300- * each bpf instruction is translated to less than 64 bytes
34301+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
34302 */
34303 for (proglen = 0, i = 0; i < flen; i++) {
34304- proglen += 64;
34305+ proglen += MAX_INSTR_CODE_SIZE;
34306 addrs[i] = proglen;
34307 }
34308 cleanup_addr = proglen; /* epilogue address */
34309@@ -285,6 +380,10 @@ void bpf_jit_compile(struct sk_filter *fp)
34310 for (i = 0; i < flen; i++) {
34311 unsigned int K = filter[i].k;
34312
34313+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34314+ randkey = prandom_u32();
34315+#endif
34316+
34317 switch (filter[i].code) {
34318 case BPF_S_ALU_ADD_X: /* A += X; */
34319 seen |= SEEN_XREG;
34320@@ -317,10 +416,8 @@ void bpf_jit_compile(struct sk_filter *fp)
34321 case BPF_S_ALU_MUL_K: /* A *= K */
34322 if (is_imm8(K))
34323 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
34324- else {
34325- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
34326- EMIT(K, 4);
34327- }
34328+ else
34329+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
34330 break;
34331 case BPF_S_ALU_DIV_X: /* A /= X; */
34332 seen |= SEEN_XREG;
34333@@ -364,7 +461,11 @@ void bpf_jit_compile(struct sk_filter *fp)
34334 break;
34335 }
34336 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
34337+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34338+ DILUTE_CONST_SEQUENCE(K, randkey);
34339+#else
34340 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
34341+#endif
34342 EMIT2(0xf7, 0xf1); /* div %ecx */
34343 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
34344 break;
34345@@ -372,7 +473,11 @@ void bpf_jit_compile(struct sk_filter *fp)
34346 if (K == 1)
34347 break;
34348 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
34349+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34350+ DILUTE_CONST_SEQUENCE(K, randkey);
34351+#else
34352 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
34353+#endif
34354 EMIT2(0xf7, 0xf1); /* div %ecx */
34355 break;
34356 case BPF_S_ALU_AND_X:
34357@@ -643,8 +748,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
34358 if (is_imm8(K)) {
34359 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
34360 } else {
34361- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
34362- EMIT(K, 4);
34363+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
34364 }
34365 } else {
34366 EMIT2(0x89,0xde); /* mov %ebx,%esi */
34367@@ -734,10 +838,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
34368 if (unlikely(proglen + ilen > oldproglen)) {
34369 pr_err("bpb_jit_compile fatal error\n");
34370 kfree(addrs);
34371- module_free(NULL, header);
34372+ module_free_exec(NULL, image);
34373 return;
34374 }
34375+ pax_open_kernel();
34376 memcpy(image + proglen, temp, ilen);
34377+ pax_close_kernel();
34378 }
34379 proglen += ilen;
34380 addrs[i] = proglen;
34381@@ -770,7 +876,6 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
34382
34383 if (image) {
34384 bpf_flush_icache(header, image + proglen);
34385- set_memory_ro((unsigned long)header, header->pages);
34386 fp->bpf_func = (void *)image;
34387 }
34388 out:
34389@@ -782,10 +887,9 @@ static void bpf_jit_free_deferred(struct work_struct *work)
34390 {
34391 struct sk_filter *fp = container_of(work, struct sk_filter, work);
34392 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
34393- struct bpf_binary_header *header = (void *)addr;
34394
34395- set_memory_rw(addr, header->pages);
34396- module_free(NULL, header);
34397+ set_memory_rw(addr, 1);
34398+ module_free_exec(NULL, (void *)addr);
34399 kfree(fp);
34400 }
34401
34402diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
34403index 5d04be5..2beeaa2 100644
34404--- a/arch/x86/oprofile/backtrace.c
34405+++ b/arch/x86/oprofile/backtrace.c
34406@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
34407 struct stack_frame_ia32 *fp;
34408 unsigned long bytes;
34409
34410- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34411+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34412 if (bytes != 0)
34413 return NULL;
34414
34415- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
34416+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
34417
34418 oprofile_add_trace(bufhead[0].return_address);
34419
34420@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
34421 struct stack_frame bufhead[2];
34422 unsigned long bytes;
34423
34424- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34425+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34426 if (bytes != 0)
34427 return NULL;
34428
34429@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
34430 {
34431 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
34432
34433- if (!user_mode_vm(regs)) {
34434+ if (!user_mode(regs)) {
34435 unsigned long stack = kernel_stack_pointer(regs);
34436 if (depth)
34437 dump_trace(NULL, regs, (unsigned long *)stack, 0,
34438diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
34439index 6890d84..1dad1f1 100644
34440--- a/arch/x86/oprofile/nmi_int.c
34441+++ b/arch/x86/oprofile/nmi_int.c
34442@@ -23,6 +23,7 @@
34443 #include <asm/nmi.h>
34444 #include <asm/msr.h>
34445 #include <asm/apic.h>
34446+#include <asm/pgtable.h>
34447
34448 #include "op_counter.h"
34449 #include "op_x86_model.h"
34450@@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
34451 if (ret)
34452 return ret;
34453
34454- if (!model->num_virt_counters)
34455- model->num_virt_counters = model->num_counters;
34456+ if (!model->num_virt_counters) {
34457+ pax_open_kernel();
34458+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
34459+ pax_close_kernel();
34460+ }
34461
34462 mux_init(ops);
34463
34464diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
34465index 50d86c0..7985318 100644
34466--- a/arch/x86/oprofile/op_model_amd.c
34467+++ b/arch/x86/oprofile/op_model_amd.c
34468@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
34469 num_counters = AMD64_NUM_COUNTERS;
34470 }
34471
34472- op_amd_spec.num_counters = num_counters;
34473- op_amd_spec.num_controls = num_counters;
34474- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34475+ pax_open_kernel();
34476+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
34477+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
34478+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34479+ pax_close_kernel();
34480
34481 return 0;
34482 }
34483diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
34484index d90528e..0127e2b 100644
34485--- a/arch/x86/oprofile/op_model_ppro.c
34486+++ b/arch/x86/oprofile/op_model_ppro.c
34487@@ -19,6 +19,7 @@
34488 #include <asm/msr.h>
34489 #include <asm/apic.h>
34490 #include <asm/nmi.h>
34491+#include <asm/pgtable.h>
34492
34493 #include "op_x86_model.h"
34494 #include "op_counter.h"
34495@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
34496
34497 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
34498
34499- op_arch_perfmon_spec.num_counters = num_counters;
34500- op_arch_perfmon_spec.num_controls = num_counters;
34501+ pax_open_kernel();
34502+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
34503+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
34504+ pax_close_kernel();
34505 }
34506
34507 static int arch_perfmon_init(struct oprofile_operations *ignore)
34508diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
34509index 71e8a67..6a313bb 100644
34510--- a/arch/x86/oprofile/op_x86_model.h
34511+++ b/arch/x86/oprofile/op_x86_model.h
34512@@ -52,7 +52,7 @@ struct op_x86_model_spec {
34513 void (*switch_ctrl)(struct op_x86_model_spec const *model,
34514 struct op_msrs const * const msrs);
34515 #endif
34516-};
34517+} __do_const;
34518
34519 struct op_counter_config;
34520
34521diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
34522index 84b9d67..260e5ff 100644
34523--- a/arch/x86/pci/intel_mid_pci.c
34524+++ b/arch/x86/pci/intel_mid_pci.c
34525@@ -245,7 +245,7 @@ int __init intel_mid_pci_init(void)
34526 pr_info("Intel MID platform detected, using MID PCI ops\n");
34527 pci_mmcfg_late_init();
34528 pcibios_enable_irq = intel_mid_pci_irq_enable;
34529- pci_root_ops = intel_mid_pci_ops;
34530+ memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
34531 pci_soc_mode = 1;
34532 /* Continue with standard init */
34533 return 1;
34534diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
34535index 372e9b8..e775a6c 100644
34536--- a/arch/x86/pci/irq.c
34537+++ b/arch/x86/pci/irq.c
34538@@ -50,7 +50,7 @@ struct irq_router {
34539 struct irq_router_handler {
34540 u16 vendor;
34541 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
34542-};
34543+} __do_const;
34544
34545 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
34546 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
34547@@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
34548 return 0;
34549 }
34550
34551-static __initdata struct irq_router_handler pirq_routers[] = {
34552+static __initconst const struct irq_router_handler pirq_routers[] = {
34553 { PCI_VENDOR_ID_INTEL, intel_router_probe },
34554 { PCI_VENDOR_ID_AL, ali_router_probe },
34555 { PCI_VENDOR_ID_ITE, ite_router_probe },
34556@@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
34557 static void __init pirq_find_router(struct irq_router *r)
34558 {
34559 struct irq_routing_table *rt = pirq_table;
34560- struct irq_router_handler *h;
34561+ const struct irq_router_handler *h;
34562
34563 #ifdef CONFIG_PCI_BIOS
34564 if (!rt->signature) {
34565@@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
34566 return 0;
34567 }
34568
34569-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
34570+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
34571 {
34572 .callback = fix_broken_hp_bios_irq9,
34573 .ident = "HP Pavilion N5400 Series Laptop",
34574diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
34575index c77b24a..c979855 100644
34576--- a/arch/x86/pci/pcbios.c
34577+++ b/arch/x86/pci/pcbios.c
34578@@ -79,7 +79,7 @@ union bios32 {
34579 static struct {
34580 unsigned long address;
34581 unsigned short segment;
34582-} bios32_indirect = { 0, __KERNEL_CS };
34583+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
34584
34585 /*
34586 * Returns the entry point for the given service, NULL on error
34587@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
34588 unsigned long length; /* %ecx */
34589 unsigned long entry; /* %edx */
34590 unsigned long flags;
34591+ struct desc_struct d, *gdt;
34592
34593 local_irq_save(flags);
34594- __asm__("lcall *(%%edi); cld"
34595+
34596+ gdt = get_cpu_gdt_table(smp_processor_id());
34597+
34598+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
34599+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34600+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
34601+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34602+
34603+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
34604 : "=a" (return_code),
34605 "=b" (address),
34606 "=c" (length),
34607 "=d" (entry)
34608 : "0" (service),
34609 "1" (0),
34610- "D" (&bios32_indirect));
34611+ "D" (&bios32_indirect),
34612+ "r"(__PCIBIOS_DS)
34613+ : "memory");
34614+
34615+ pax_open_kernel();
34616+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
34617+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
34618+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
34619+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
34620+ pax_close_kernel();
34621+
34622 local_irq_restore(flags);
34623
34624 switch (return_code) {
34625- case 0:
34626- return address + entry;
34627- case 0x80: /* Not present */
34628- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34629- return 0;
34630- default: /* Shouldn't happen */
34631- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34632- service, return_code);
34633+ case 0: {
34634+ int cpu;
34635+ unsigned char flags;
34636+
34637+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
34638+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
34639+ printk(KERN_WARNING "bios32_service: not valid\n");
34640 return 0;
34641+ }
34642+ address = address + PAGE_OFFSET;
34643+ length += 16UL; /* some BIOSs underreport this... */
34644+ flags = 4;
34645+ if (length >= 64*1024*1024) {
34646+ length >>= PAGE_SHIFT;
34647+ flags |= 8;
34648+ }
34649+
34650+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
34651+ gdt = get_cpu_gdt_table(cpu);
34652+ pack_descriptor(&d, address, length, 0x9b, flags);
34653+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34654+ pack_descriptor(&d, address, length, 0x93, flags);
34655+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34656+ }
34657+ return entry;
34658+ }
34659+ case 0x80: /* Not present */
34660+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34661+ return 0;
34662+ default: /* Shouldn't happen */
34663+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34664+ service, return_code);
34665+ return 0;
34666 }
34667 }
34668
34669 static struct {
34670 unsigned long address;
34671 unsigned short segment;
34672-} pci_indirect = { 0, __KERNEL_CS };
34673+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
34674
34675-static int pci_bios_present;
34676+static int pci_bios_present __read_only;
34677
34678 static int check_pcibios(void)
34679 {
34680@@ -131,11 +174,13 @@ static int check_pcibios(void)
34681 unsigned long flags, pcibios_entry;
34682
34683 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
34684- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
34685+ pci_indirect.address = pcibios_entry;
34686
34687 local_irq_save(flags);
34688- __asm__(
34689- "lcall *(%%edi); cld\n\t"
34690+ __asm__("movw %w6, %%ds\n\t"
34691+ "lcall *%%ss:(%%edi); cld\n\t"
34692+ "push %%ss\n\t"
34693+ "pop %%ds\n\t"
34694 "jc 1f\n\t"
34695 "xor %%ah, %%ah\n"
34696 "1:"
34697@@ -144,7 +189,8 @@ static int check_pcibios(void)
34698 "=b" (ebx),
34699 "=c" (ecx)
34700 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
34701- "D" (&pci_indirect)
34702+ "D" (&pci_indirect),
34703+ "r" (__PCIBIOS_DS)
34704 : "memory");
34705 local_irq_restore(flags);
34706
34707@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34708
34709 switch (len) {
34710 case 1:
34711- __asm__("lcall *(%%esi); cld\n\t"
34712+ __asm__("movw %w6, %%ds\n\t"
34713+ "lcall *%%ss:(%%esi); cld\n\t"
34714+ "push %%ss\n\t"
34715+ "pop %%ds\n\t"
34716 "jc 1f\n\t"
34717 "xor %%ah, %%ah\n"
34718 "1:"
34719@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34720 : "1" (PCIBIOS_READ_CONFIG_BYTE),
34721 "b" (bx),
34722 "D" ((long)reg),
34723- "S" (&pci_indirect));
34724+ "S" (&pci_indirect),
34725+ "r" (__PCIBIOS_DS));
34726 /*
34727 * Zero-extend the result beyond 8 bits, do not trust the
34728 * BIOS having done it:
34729@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34730 *value &= 0xff;
34731 break;
34732 case 2:
34733- __asm__("lcall *(%%esi); cld\n\t"
34734+ __asm__("movw %w6, %%ds\n\t"
34735+ "lcall *%%ss:(%%esi); cld\n\t"
34736+ "push %%ss\n\t"
34737+ "pop %%ds\n\t"
34738 "jc 1f\n\t"
34739 "xor %%ah, %%ah\n"
34740 "1:"
34741@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34742 : "1" (PCIBIOS_READ_CONFIG_WORD),
34743 "b" (bx),
34744 "D" ((long)reg),
34745- "S" (&pci_indirect));
34746+ "S" (&pci_indirect),
34747+ "r" (__PCIBIOS_DS));
34748 /*
34749 * Zero-extend the result beyond 16 bits, do not trust the
34750 * BIOS having done it:
34751@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34752 *value &= 0xffff;
34753 break;
34754 case 4:
34755- __asm__("lcall *(%%esi); cld\n\t"
34756+ __asm__("movw %w6, %%ds\n\t"
34757+ "lcall *%%ss:(%%esi); cld\n\t"
34758+ "push %%ss\n\t"
34759+ "pop %%ds\n\t"
34760 "jc 1f\n\t"
34761 "xor %%ah, %%ah\n"
34762 "1:"
34763@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34764 : "1" (PCIBIOS_READ_CONFIG_DWORD),
34765 "b" (bx),
34766 "D" ((long)reg),
34767- "S" (&pci_indirect));
34768+ "S" (&pci_indirect),
34769+ "r" (__PCIBIOS_DS));
34770 break;
34771 }
34772
34773@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34774
34775 switch (len) {
34776 case 1:
34777- __asm__("lcall *(%%esi); cld\n\t"
34778+ __asm__("movw %w6, %%ds\n\t"
34779+ "lcall *%%ss:(%%esi); cld\n\t"
34780+ "push %%ss\n\t"
34781+ "pop %%ds\n\t"
34782 "jc 1f\n\t"
34783 "xor %%ah, %%ah\n"
34784 "1:"
34785@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34786 "c" (value),
34787 "b" (bx),
34788 "D" ((long)reg),
34789- "S" (&pci_indirect));
34790+ "S" (&pci_indirect),
34791+ "r" (__PCIBIOS_DS));
34792 break;
34793 case 2:
34794- __asm__("lcall *(%%esi); cld\n\t"
34795+ __asm__("movw %w6, %%ds\n\t"
34796+ "lcall *%%ss:(%%esi); cld\n\t"
34797+ "push %%ss\n\t"
34798+ "pop %%ds\n\t"
34799 "jc 1f\n\t"
34800 "xor %%ah, %%ah\n"
34801 "1:"
34802@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34803 "c" (value),
34804 "b" (bx),
34805 "D" ((long)reg),
34806- "S" (&pci_indirect));
34807+ "S" (&pci_indirect),
34808+ "r" (__PCIBIOS_DS));
34809 break;
34810 case 4:
34811- __asm__("lcall *(%%esi); cld\n\t"
34812+ __asm__("movw %w6, %%ds\n\t"
34813+ "lcall *%%ss:(%%esi); cld\n\t"
34814+ "push %%ss\n\t"
34815+ "pop %%ds\n\t"
34816 "jc 1f\n\t"
34817 "xor %%ah, %%ah\n"
34818 "1:"
34819@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34820 "c" (value),
34821 "b" (bx),
34822 "D" ((long)reg),
34823- "S" (&pci_indirect));
34824+ "S" (&pci_indirect),
34825+ "r" (__PCIBIOS_DS));
34826 break;
34827 }
34828
34829@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34830
34831 DBG("PCI: Fetching IRQ routing table... ");
34832 __asm__("push %%es\n\t"
34833+ "movw %w8, %%ds\n\t"
34834 "push %%ds\n\t"
34835 "pop %%es\n\t"
34836- "lcall *(%%esi); cld\n\t"
34837+ "lcall *%%ss:(%%esi); cld\n\t"
34838 "pop %%es\n\t"
34839+ "push %%ss\n\t"
34840+ "pop %%ds\n"
34841 "jc 1f\n\t"
34842 "xor %%ah, %%ah\n"
34843 "1:"
34844@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34845 "1" (0),
34846 "D" ((long) &opt),
34847 "S" (&pci_indirect),
34848- "m" (opt)
34849+ "m" (opt),
34850+ "r" (__PCIBIOS_DS)
34851 : "memory");
34852 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
34853 if (ret & 0xff00)
34854@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34855 {
34856 int ret;
34857
34858- __asm__("lcall *(%%esi); cld\n\t"
34859+ __asm__("movw %w5, %%ds\n\t"
34860+ "lcall *%%ss:(%%esi); cld\n\t"
34861+ "push %%ss\n\t"
34862+ "pop %%ds\n"
34863 "jc 1f\n\t"
34864 "xor %%ah, %%ah\n"
34865 "1:"
34866@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34867 : "0" (PCIBIOS_SET_PCI_HW_INT),
34868 "b" ((dev->bus->number << 8) | dev->devfn),
34869 "c" ((irq << 8) | (pin + 10)),
34870- "S" (&pci_indirect));
34871+ "S" (&pci_indirect),
34872+ "r" (__PCIBIOS_DS));
34873 return !(ret & 0xff00);
34874 }
34875 EXPORT_SYMBOL(pcibios_set_irq_routing);
34876diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
34877index 9ee3491..872192f 100644
34878--- a/arch/x86/platform/efi/efi_32.c
34879+++ b/arch/x86/platform/efi/efi_32.c
34880@@ -59,11 +59,22 @@ void efi_call_phys_prelog(void)
34881 {
34882 struct desc_ptr gdt_descr;
34883
34884+#ifdef CONFIG_PAX_KERNEXEC
34885+ struct desc_struct d;
34886+#endif
34887+
34888 local_irq_save(efi_rt_eflags);
34889
34890 load_cr3(initial_page_table);
34891 __flush_tlb_all();
34892
34893+#ifdef CONFIG_PAX_KERNEXEC
34894+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
34895+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34896+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
34897+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34898+#endif
34899+
34900 gdt_descr.address = __pa(get_cpu_gdt_table(0));
34901 gdt_descr.size = GDT_SIZE - 1;
34902 load_gdt(&gdt_descr);
34903@@ -73,11 +84,24 @@ void efi_call_phys_epilog(void)
34904 {
34905 struct desc_ptr gdt_descr;
34906
34907+#ifdef CONFIG_PAX_KERNEXEC
34908+ struct desc_struct d;
34909+
34910+ memset(&d, 0, sizeof d);
34911+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34912+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34913+#endif
34914+
34915 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
34916 gdt_descr.size = GDT_SIZE - 1;
34917 load_gdt(&gdt_descr);
34918
34919+#ifdef CONFIG_PAX_PER_CPU_PGD
34920+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34921+#else
34922 load_cr3(swapper_pg_dir);
34923+#endif
34924+
34925 __flush_tlb_all();
34926
34927 local_irq_restore(efi_rt_eflags);
34928diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
34929index 666b74a..673d88f 100644
34930--- a/arch/x86/platform/efi/efi_64.c
34931+++ b/arch/x86/platform/efi/efi_64.c
34932@@ -97,6 +97,11 @@ void __init efi_call_phys_prelog(void)
34933 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
34934 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
34935 }
34936+
34937+#ifdef CONFIG_PAX_PER_CPU_PGD
34938+ load_cr3(swapper_pg_dir);
34939+#endif
34940+
34941 __flush_tlb_all();
34942 }
34943
34944@@ -114,6 +119,11 @@ void __init efi_call_phys_epilog(void)
34945 for (pgd = 0; pgd < n_pgds; pgd++)
34946 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
34947 kfree(save_pgd);
34948+
34949+#ifdef CONFIG_PAX_PER_CPU_PGD
34950+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34951+#endif
34952+
34953 __flush_tlb_all();
34954 local_irq_restore(efi_flags);
34955 early_code_mapping_set_exec(0);
34956diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
34957index fbe66e6..eae5e38 100644
34958--- a/arch/x86/platform/efi/efi_stub_32.S
34959+++ b/arch/x86/platform/efi/efi_stub_32.S
34960@@ -6,7 +6,9 @@
34961 */
34962
34963 #include <linux/linkage.h>
34964+#include <linux/init.h>
34965 #include <asm/page_types.h>
34966+#include <asm/segment.h>
34967
34968 /*
34969 * efi_call_phys(void *, ...) is a function with variable parameters.
34970@@ -20,7 +22,7 @@
34971 * service functions will comply with gcc calling convention, too.
34972 */
34973
34974-.text
34975+__INIT
34976 ENTRY(efi_call_phys)
34977 /*
34978 * 0. The function can only be called in Linux kernel. So CS has been
34979@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
34980 * The mapping of lower virtual memory has been created in prelog and
34981 * epilog.
34982 */
34983- movl $1f, %edx
34984- subl $__PAGE_OFFSET, %edx
34985- jmp *%edx
34986+#ifdef CONFIG_PAX_KERNEXEC
34987+ movl $(__KERNEXEC_EFI_DS), %edx
34988+ mov %edx, %ds
34989+ mov %edx, %es
34990+ mov %edx, %ss
34991+ addl $2f,(1f)
34992+ ljmp *(1f)
34993+
34994+__INITDATA
34995+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
34996+.previous
34997+
34998+2:
34999+ subl $2b,(1b)
35000+#else
35001+ jmp 1f-__PAGE_OFFSET
35002 1:
35003+#endif
35004
35005 /*
35006 * 2. Now on the top of stack is the return
35007@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
35008 * parameter 2, ..., param n. To make things easy, we save the return
35009 * address of efi_call_phys in a global variable.
35010 */
35011- popl %edx
35012- movl %edx, saved_return_addr
35013- /* get the function pointer into ECX*/
35014- popl %ecx
35015- movl %ecx, efi_rt_function_ptr
35016- movl $2f, %edx
35017- subl $__PAGE_OFFSET, %edx
35018- pushl %edx
35019+ popl (saved_return_addr)
35020+ popl (efi_rt_function_ptr)
35021
35022 /*
35023 * 3. Clear PG bit in %CR0.
35024@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
35025 /*
35026 * 5. Call the physical function.
35027 */
35028- jmp *%ecx
35029+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
35030
35031-2:
35032 /*
35033 * 6. After EFI runtime service returns, control will return to
35034 * following instruction. We'd better readjust stack pointer first.
35035@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
35036 movl %cr0, %edx
35037 orl $0x80000000, %edx
35038 movl %edx, %cr0
35039- jmp 1f
35040-1:
35041+
35042 /*
35043 * 8. Now restore the virtual mode from flat mode by
35044 * adding EIP with PAGE_OFFSET.
35045 */
35046- movl $1f, %edx
35047- jmp *%edx
35048+#ifdef CONFIG_PAX_KERNEXEC
35049+ movl $(__KERNEL_DS), %edx
35050+ mov %edx, %ds
35051+ mov %edx, %es
35052+ mov %edx, %ss
35053+ ljmp $(__KERNEL_CS),$1f
35054+#else
35055+ jmp 1f+__PAGE_OFFSET
35056+#endif
35057 1:
35058
35059 /*
35060 * 9. Balance the stack. And because EAX contain the return value,
35061 * we'd better not clobber it.
35062 */
35063- leal efi_rt_function_ptr, %edx
35064- movl (%edx), %ecx
35065- pushl %ecx
35066+ pushl (efi_rt_function_ptr)
35067
35068 /*
35069- * 10. Push the saved return address onto the stack and return.
35070+ * 10. Return to the saved return address.
35071 */
35072- leal saved_return_addr, %edx
35073- movl (%edx), %ecx
35074- pushl %ecx
35075- ret
35076+ jmpl *(saved_return_addr)
35077 ENDPROC(efi_call_phys)
35078 .previous
35079
35080-.data
35081+__INITDATA
35082 saved_return_addr:
35083 .long 0
35084 efi_rt_function_ptr:
35085diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
35086index 88073b1..1cc2f53 100644
35087--- a/arch/x86/platform/efi/efi_stub_64.S
35088+++ b/arch/x86/platform/efi/efi_stub_64.S
35089@@ -7,6 +7,7 @@
35090 */
35091
35092 #include <linux/linkage.h>
35093+#include <asm/alternative-asm.h>
35094
35095 #define SAVE_XMM \
35096 mov %rsp, %rax; \
35097@@ -77,6 +78,7 @@ ENTRY(efi_call0)
35098 RESTORE_PGT
35099 addq $32, %rsp
35100 RESTORE_XMM
35101+ pax_force_retaddr 0, 1
35102 ret
35103 ENDPROC(efi_call0)
35104
35105@@ -89,6 +91,7 @@ ENTRY(efi_call1)
35106 RESTORE_PGT
35107 addq $32, %rsp
35108 RESTORE_XMM
35109+ pax_force_retaddr 0, 1
35110 ret
35111 ENDPROC(efi_call1)
35112
35113@@ -101,6 +104,7 @@ ENTRY(efi_call2)
35114 RESTORE_PGT
35115 addq $32, %rsp
35116 RESTORE_XMM
35117+ pax_force_retaddr 0, 1
35118 ret
35119 ENDPROC(efi_call2)
35120
35121@@ -114,6 +118,7 @@ ENTRY(efi_call3)
35122 RESTORE_PGT
35123 addq $32, %rsp
35124 RESTORE_XMM
35125+ pax_force_retaddr 0, 1
35126 ret
35127 ENDPROC(efi_call3)
35128
35129@@ -128,6 +133,7 @@ ENTRY(efi_call4)
35130 RESTORE_PGT
35131 addq $32, %rsp
35132 RESTORE_XMM
35133+ pax_force_retaddr 0, 1
35134 ret
35135 ENDPROC(efi_call4)
35136
35137@@ -143,6 +149,7 @@ ENTRY(efi_call5)
35138 RESTORE_PGT
35139 addq $48, %rsp
35140 RESTORE_XMM
35141+ pax_force_retaddr 0, 1
35142 ret
35143 ENDPROC(efi_call5)
35144
35145@@ -161,6 +168,7 @@ ENTRY(efi_call6)
35146 RESTORE_PGT
35147 addq $48, %rsp
35148 RESTORE_XMM
35149+ pax_force_retaddr 0, 1
35150 ret
35151 ENDPROC(efi_call6)
35152
35153diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
35154index 1bbedc4..eb795b5 100644
35155--- a/arch/x86/platform/intel-mid/intel-mid.c
35156+++ b/arch/x86/platform/intel-mid/intel-mid.c
35157@@ -71,9 +71,10 @@ static void intel_mid_power_off(void)
35158 {
35159 };
35160
35161-static void intel_mid_reboot(void)
35162+static void __noreturn intel_mid_reboot(void)
35163 {
35164 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
35165+ BUG();
35166 }
35167
35168 static unsigned long __init intel_mid_calibrate_tsc(void)
35169diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
35170index d6ee929..3637cb5 100644
35171--- a/arch/x86/platform/olpc/olpc_dt.c
35172+++ b/arch/x86/platform/olpc/olpc_dt.c
35173@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
35174 return res;
35175 }
35176
35177-static struct of_pdt_ops prom_olpc_ops __initdata = {
35178+static struct of_pdt_ops prom_olpc_ops __initconst = {
35179 .nextprop = olpc_dt_nextprop,
35180 .getproplen = olpc_dt_getproplen,
35181 .getproperty = olpc_dt_getproperty,
35182diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
35183index 424f4c9..f2a2988 100644
35184--- a/arch/x86/power/cpu.c
35185+++ b/arch/x86/power/cpu.c
35186@@ -137,11 +137,8 @@ static void do_fpu_end(void)
35187 static void fix_processor_context(void)
35188 {
35189 int cpu = smp_processor_id();
35190- struct tss_struct *t = &per_cpu(init_tss, cpu);
35191-#ifdef CONFIG_X86_64
35192- struct desc_struct *desc = get_cpu_gdt_table(cpu);
35193- tss_desc tss;
35194-#endif
35195+ struct tss_struct *t = init_tss + cpu;
35196+
35197 set_tss_desc(cpu, t); /*
35198 * This just modifies memory; should not be
35199 * necessary. But... This is necessary, because
35200@@ -150,10 +147,6 @@ static void fix_processor_context(void)
35201 */
35202
35203 #ifdef CONFIG_X86_64
35204- memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
35205- tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
35206- write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
35207-
35208 syscall_init(); /* This sets MSR_*STAR and related */
35209 #endif
35210 load_TR_desc(); /* This does ltr */
35211diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
35212index bad628a..a102610 100644
35213--- a/arch/x86/realmode/init.c
35214+++ b/arch/x86/realmode/init.c
35215@@ -68,7 +68,13 @@ void __init setup_real_mode(void)
35216 __va(real_mode_header->trampoline_header);
35217
35218 #ifdef CONFIG_X86_32
35219- trampoline_header->start = __pa_symbol(startup_32_smp);
35220+ trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
35221+
35222+#ifdef CONFIG_PAX_KERNEXEC
35223+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
35224+#endif
35225+
35226+ trampoline_header->boot_cs = __BOOT_CS;
35227 trampoline_header->gdt_limit = __BOOT_DS + 7;
35228 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
35229 #else
35230@@ -84,7 +90,7 @@ void __init setup_real_mode(void)
35231 *trampoline_cr4_features = read_cr4();
35232
35233 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
35234- trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
35235+ trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
35236 trampoline_pgd[511] = init_level4_pgt[511].pgd;
35237 #endif
35238 }
35239diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
35240index 3497f14..cc73b92 100644
35241--- a/arch/x86/realmode/rm/Makefile
35242+++ b/arch/x86/realmode/rm/Makefile
35243@@ -66,5 +66,8 @@ $(obj)/realmode.relocs: $(obj)/realmode.elf FORCE
35244
35245 KBUILD_CFLAGS := $(LINUXINCLUDE) $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \
35246 -I$(srctree)/arch/x86/boot
35247+ifdef CONSTIFY_PLUGIN
35248+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
35249+endif
35250 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
35251 GCOV_PROFILE := n
35252diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
35253index a28221d..93c40f1 100644
35254--- a/arch/x86/realmode/rm/header.S
35255+++ b/arch/x86/realmode/rm/header.S
35256@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
35257 #endif
35258 /* APM/BIOS reboot */
35259 .long pa_machine_real_restart_asm
35260-#ifdef CONFIG_X86_64
35261+#ifdef CONFIG_X86_32
35262+ .long __KERNEL_CS
35263+#else
35264 .long __KERNEL32_CS
35265 #endif
35266 END(real_mode_header)
35267diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
35268index 48ddd76..c26749f 100644
35269--- a/arch/x86/realmode/rm/trampoline_32.S
35270+++ b/arch/x86/realmode/rm/trampoline_32.S
35271@@ -24,6 +24,12 @@
35272 #include <asm/page_types.h>
35273 #include "realmode.h"
35274
35275+#ifdef CONFIG_PAX_KERNEXEC
35276+#define ta(X) (X)
35277+#else
35278+#define ta(X) (pa_ ## X)
35279+#endif
35280+
35281 .text
35282 .code16
35283
35284@@ -38,8 +44,6 @@ ENTRY(trampoline_start)
35285
35286 cli # We should be safe anyway
35287
35288- movl tr_start, %eax # where we need to go
35289-
35290 movl $0xA5A5A5A5, trampoline_status
35291 # write marker for master knows we're running
35292
35293@@ -55,7 +59,7 @@ ENTRY(trampoline_start)
35294 movw $1, %dx # protected mode (PE) bit
35295 lmsw %dx # into protected mode
35296
35297- ljmpl $__BOOT_CS, $pa_startup_32
35298+ ljmpl *(trampoline_header)
35299
35300 .section ".text32","ax"
35301 .code32
35302@@ -66,7 +70,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
35303 .balign 8
35304 GLOBAL(trampoline_header)
35305 tr_start: .space 4
35306- tr_gdt_pad: .space 2
35307+ tr_boot_cs: .space 2
35308 tr_gdt: .space 6
35309 END(trampoline_header)
35310
35311diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
35312index dac7b20..72dbaca 100644
35313--- a/arch/x86/realmode/rm/trampoline_64.S
35314+++ b/arch/x86/realmode/rm/trampoline_64.S
35315@@ -93,6 +93,7 @@ ENTRY(startup_32)
35316 movl %edx, %gs
35317
35318 movl pa_tr_cr4, %eax
35319+ andl $~X86_CR4_PCIDE, %eax
35320 movl %eax, %cr4 # Enable PAE mode
35321
35322 # Setup trampoline 4 level pagetables
35323@@ -106,7 +107,7 @@ ENTRY(startup_32)
35324 wrmsr
35325
35326 # Enable paging and in turn activate Long Mode
35327- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
35328+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
35329 movl %eax, %cr0
35330
35331 /*
35332diff --git a/arch/x86/realmode/rm/wakeup_asm.S b/arch/x86/realmode/rm/wakeup_asm.S
35333index 9e7e147..25a4158 100644
35334--- a/arch/x86/realmode/rm/wakeup_asm.S
35335+++ b/arch/x86/realmode/rm/wakeup_asm.S
35336@@ -126,11 +126,10 @@ ENTRY(wakeup_start)
35337 lgdtl pmode_gdt
35338
35339 /* This really couldn't... */
35340- movl pmode_entry, %eax
35341 movl pmode_cr0, %ecx
35342 movl %ecx, %cr0
35343- ljmpl $__KERNEL_CS, $pa_startup_32
35344- /* -> jmp *%eax in trampoline_32.S */
35345+
35346+ ljmpl *pmode_entry
35347 #else
35348 jmp trampoline_start
35349 #endif
35350diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
35351index e812034..c747134 100644
35352--- a/arch/x86/tools/Makefile
35353+++ b/arch/x86/tools/Makefile
35354@@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
35355
35356 $(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
35357
35358-HOST_EXTRACFLAGS += -I$(srctree)/tools/include
35359+HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
35360 hostprogs-y += relocs
35361 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
35362 relocs: $(obj)/relocs
35363diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
35364index cfbdbdb..1aa763c 100644
35365--- a/arch/x86/tools/relocs.c
35366+++ b/arch/x86/tools/relocs.c
35367@@ -1,5 +1,7 @@
35368 /* This is included from relocs_32/64.c */
35369
35370+#include "../../../include/generated/autoconf.h"
35371+
35372 #define ElfW(type) _ElfW(ELF_BITS, type)
35373 #define _ElfW(bits, type) __ElfW(bits, type)
35374 #define __ElfW(bits, type) Elf##bits##_##type
35375@@ -11,6 +13,7 @@
35376 #define Elf_Sym ElfW(Sym)
35377
35378 static Elf_Ehdr ehdr;
35379+static Elf_Phdr *phdr;
35380
35381 struct relocs {
35382 uint32_t *offset;
35383@@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
35384 }
35385 }
35386
35387+static void read_phdrs(FILE *fp)
35388+{
35389+ unsigned int i;
35390+
35391+ phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
35392+ if (!phdr) {
35393+ die("Unable to allocate %d program headers\n",
35394+ ehdr.e_phnum);
35395+ }
35396+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
35397+ die("Seek to %d failed: %s\n",
35398+ ehdr.e_phoff, strerror(errno));
35399+ }
35400+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
35401+ die("Cannot read ELF program headers: %s\n",
35402+ strerror(errno));
35403+ }
35404+ for(i = 0; i < ehdr.e_phnum; i++) {
35405+ phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
35406+ phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
35407+ phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
35408+ phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
35409+ phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
35410+ phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
35411+ phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
35412+ phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
35413+ }
35414+
35415+}
35416+
35417 static void read_shdrs(FILE *fp)
35418 {
35419- int i;
35420+ unsigned int i;
35421 Elf_Shdr shdr;
35422
35423 secs = calloc(ehdr.e_shnum, sizeof(struct section));
35424@@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
35425
35426 static void read_strtabs(FILE *fp)
35427 {
35428- int i;
35429+ unsigned int i;
35430 for (i = 0; i < ehdr.e_shnum; i++) {
35431 struct section *sec = &secs[i];
35432 if (sec->shdr.sh_type != SHT_STRTAB) {
35433@@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
35434
35435 static void read_symtabs(FILE *fp)
35436 {
35437- int i,j;
35438+ unsigned int i,j;
35439 for (i = 0; i < ehdr.e_shnum; i++) {
35440 struct section *sec = &secs[i];
35441 if (sec->shdr.sh_type != SHT_SYMTAB) {
35442@@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
35443 }
35444
35445
35446-static void read_relocs(FILE *fp)
35447+static void read_relocs(FILE *fp, int use_real_mode)
35448 {
35449- int i,j;
35450+ unsigned int i,j;
35451+ uint32_t base;
35452+
35453 for (i = 0; i < ehdr.e_shnum; i++) {
35454 struct section *sec = &secs[i];
35455 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35456@@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
35457 die("Cannot read symbol table: %s\n",
35458 strerror(errno));
35459 }
35460+ base = 0;
35461+
35462+#ifdef CONFIG_X86_32
35463+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
35464+ if (phdr[j].p_type != PT_LOAD )
35465+ continue;
35466+ 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)
35467+ continue;
35468+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
35469+ break;
35470+ }
35471+#endif
35472+
35473 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
35474 Elf_Rel *rel = &sec->reltab[j];
35475- rel->r_offset = elf_addr_to_cpu(rel->r_offset);
35476+ rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
35477 rel->r_info = elf_xword_to_cpu(rel->r_info);
35478 #if (SHT_REL_TYPE == SHT_RELA)
35479 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
35480@@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
35481
35482 static void print_absolute_symbols(void)
35483 {
35484- int i;
35485+ unsigned int i;
35486 const char *format;
35487
35488 if (ELF_BITS == 64)
35489@@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
35490 for (i = 0; i < ehdr.e_shnum; i++) {
35491 struct section *sec = &secs[i];
35492 char *sym_strtab;
35493- int j;
35494+ unsigned int j;
35495
35496 if (sec->shdr.sh_type != SHT_SYMTAB) {
35497 continue;
35498@@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
35499
35500 static void print_absolute_relocs(void)
35501 {
35502- int i, printed = 0;
35503+ unsigned int i, printed = 0;
35504 const char *format;
35505
35506 if (ELF_BITS == 64)
35507@@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
35508 struct section *sec_applies, *sec_symtab;
35509 char *sym_strtab;
35510 Elf_Sym *sh_symtab;
35511- int j;
35512+ unsigned int j;
35513 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35514 continue;
35515 }
35516@@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
35517 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
35518 Elf_Sym *sym, const char *symname))
35519 {
35520- int i;
35521+ unsigned int i;
35522 /* Walk through the relocations */
35523 for (i = 0; i < ehdr.e_shnum; i++) {
35524 char *sym_strtab;
35525 Elf_Sym *sh_symtab;
35526 struct section *sec_applies, *sec_symtab;
35527- int j;
35528+ unsigned int j;
35529 struct section *sec = &secs[i];
35530
35531 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35532@@ -822,6 +870,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35533 {
35534 unsigned r_type = ELF32_R_TYPE(rel->r_info);
35535 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
35536+ char *sym_strtab = sec->link->link->strtab;
35537+
35538+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
35539+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
35540+ return 0;
35541+
35542+#ifdef CONFIG_PAX_KERNEXEC
35543+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
35544+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
35545+ return 0;
35546+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
35547+ return 0;
35548+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
35549+ return 0;
35550+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
35551+ return 0;
35552+#endif
35553
35554 switch (r_type) {
35555 case R_386_NONE:
35556@@ -960,7 +1025,7 @@ static int write32_as_text(uint32_t v, FILE *f)
35557
35558 static void emit_relocs(int as_text, int use_real_mode)
35559 {
35560- int i;
35561+ unsigned int i;
35562 int (*write_reloc)(uint32_t, FILE *) = write32;
35563 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35564 const char *symname);
35565@@ -1060,10 +1125,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
35566 {
35567 regex_init(use_real_mode);
35568 read_ehdr(fp);
35569+ read_phdrs(fp);
35570 read_shdrs(fp);
35571 read_strtabs(fp);
35572 read_symtabs(fp);
35573- read_relocs(fp);
35574+ read_relocs(fp, use_real_mode);
35575 if (ELF_BITS == 64)
35576 percpu_init();
35577 if (show_absolute_syms) {
35578diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
35579index 80ffa5b..a33bd15 100644
35580--- a/arch/x86/um/tls_32.c
35581+++ b/arch/x86/um/tls_32.c
35582@@ -260,7 +260,7 @@ out:
35583 if (unlikely(task == current &&
35584 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
35585 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
35586- "without flushed TLS.", current->pid);
35587+ "without flushed TLS.", task_pid_nr(current));
35588 }
35589
35590 return 0;
35591diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
35592index fd14be1..e3c79c0 100644
35593--- a/arch/x86/vdso/Makefile
35594+++ b/arch/x86/vdso/Makefile
35595@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
35596 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
35597 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
35598
35599-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
35600+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
35601 GCOV_PROFILE := n
35602
35603 #
35604diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
35605index d6bfb87..876ee18 100644
35606--- a/arch/x86/vdso/vdso32-setup.c
35607+++ b/arch/x86/vdso/vdso32-setup.c
35608@@ -25,6 +25,7 @@
35609 #include <asm/tlbflush.h>
35610 #include <asm/vdso.h>
35611 #include <asm/proto.h>
35612+#include <asm/mman.h>
35613
35614 enum {
35615 VDSO_DISABLED = 0,
35616@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
35617 void enable_sep_cpu(void)
35618 {
35619 int cpu = get_cpu();
35620- struct tss_struct *tss = &per_cpu(init_tss, cpu);
35621+ struct tss_struct *tss = init_tss + cpu;
35622
35623 if (!boot_cpu_has(X86_FEATURE_SEP)) {
35624 put_cpu();
35625@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
35626 gate_vma.vm_start = FIXADDR_USER_START;
35627 gate_vma.vm_end = FIXADDR_USER_END;
35628 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
35629- gate_vma.vm_page_prot = __P101;
35630+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
35631
35632 return 0;
35633 }
35634@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35635 if (compat)
35636 addr = VDSO_HIGH_BASE;
35637 else {
35638- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
35639+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
35640 if (IS_ERR_VALUE(addr)) {
35641 ret = addr;
35642 goto up_fail;
35643 }
35644 }
35645
35646- current->mm->context.vdso = (void *)addr;
35647+ current->mm->context.vdso = addr;
35648
35649 if (compat_uses_vma || !compat) {
35650 /*
35651@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35652 }
35653
35654 current_thread_info()->sysenter_return =
35655- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35656+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35657
35658 up_fail:
35659 if (ret)
35660- current->mm->context.vdso = NULL;
35661+ current->mm->context.vdso = 0;
35662
35663 up_write(&mm->mmap_sem);
35664
35665@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
35666
35667 const char *arch_vma_name(struct vm_area_struct *vma)
35668 {
35669- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
35670+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
35671 return "[vdso]";
35672+
35673+#ifdef CONFIG_PAX_SEGMEXEC
35674+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
35675+ return "[vdso]";
35676+#endif
35677+
35678 return NULL;
35679 }
35680
35681@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
35682 * Check to see if the corresponding task was created in compat vdso
35683 * mode.
35684 */
35685- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
35686+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
35687 return &gate_vma;
35688 return NULL;
35689 }
35690diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
35691index 431e875..cbb23f3 100644
35692--- a/arch/x86/vdso/vma.c
35693+++ b/arch/x86/vdso/vma.c
35694@@ -16,8 +16,6 @@
35695 #include <asm/vdso.h>
35696 #include <asm/page.h>
35697
35698-unsigned int __read_mostly vdso_enabled = 1;
35699-
35700 extern char vdso_start[], vdso_end[];
35701 extern unsigned short vdso_sync_cpuid;
35702
35703@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
35704 * unaligned here as a result of stack start randomization.
35705 */
35706 addr = PAGE_ALIGN(addr);
35707- addr = align_vdso_addr(addr);
35708
35709 return addr;
35710 }
35711@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
35712 unsigned size)
35713 {
35714 struct mm_struct *mm = current->mm;
35715- unsigned long addr;
35716+ unsigned long addr = 0;
35717 int ret;
35718
35719- if (!vdso_enabled)
35720- return 0;
35721-
35722 down_write(&mm->mmap_sem);
35723+
35724+#ifdef CONFIG_PAX_RANDMMAP
35725+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
35726+#endif
35727+
35728 addr = vdso_addr(mm->start_stack, size);
35729+ addr = align_vdso_addr(addr);
35730 addr = get_unmapped_area(NULL, addr, size, 0, 0);
35731 if (IS_ERR_VALUE(addr)) {
35732 ret = addr;
35733 goto up_fail;
35734 }
35735
35736- current->mm->context.vdso = (void *)addr;
35737+ mm->context.vdso = addr;
35738
35739 ret = install_special_mapping(mm, addr, size,
35740 VM_READ|VM_EXEC|
35741 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
35742 pages);
35743- if (ret) {
35744- current->mm->context.vdso = NULL;
35745- goto up_fail;
35746- }
35747+ if (ret)
35748+ mm->context.vdso = 0;
35749
35750 up_fail:
35751 up_write(&mm->mmap_sem);
35752@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35753 vdsox32_size);
35754 }
35755 #endif
35756-
35757-static __init int vdso_setup(char *s)
35758-{
35759- vdso_enabled = simple_strtoul(s, NULL, 0);
35760- return 0;
35761-}
35762-__setup("vdso=", vdso_setup);
35763diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
35764index 01b9026..1e476df 100644
35765--- a/arch/x86/xen/Kconfig
35766+++ b/arch/x86/xen/Kconfig
35767@@ -9,6 +9,7 @@ config XEN
35768 select XEN_HAVE_PVMMU
35769 depends on X86_64 || (X86_32 && X86_PAE && !X86_VISWS)
35770 depends on X86_TSC
35771+ depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
35772 help
35773 This is the Linux Xen port. Enabling this will allow the
35774 kernel to boot in a paravirtualized environment under the
35775diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
35776index 201d09a..e4723e5 100644
35777--- a/arch/x86/xen/enlighten.c
35778+++ b/arch/x86/xen/enlighten.c
35779@@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
35780
35781 struct shared_info xen_dummy_shared_info;
35782
35783-void *xen_initial_gdt;
35784-
35785 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
35786 __read_mostly int xen_have_vector_callback;
35787 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
35788@@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
35789 {
35790 unsigned long va = dtr->address;
35791 unsigned int size = dtr->size + 1;
35792- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35793- unsigned long frames[pages];
35794+ unsigned long frames[65536 / PAGE_SIZE];
35795 int f;
35796
35797 /*
35798@@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35799 {
35800 unsigned long va = dtr->address;
35801 unsigned int size = dtr->size + 1;
35802- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35803- unsigned long frames[pages];
35804+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
35805 int f;
35806
35807 /*
35808@@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35809 * 8-byte entries, or 16 4k pages..
35810 */
35811
35812- BUG_ON(size > 65536);
35813+ BUG_ON(size > GDT_SIZE);
35814 BUG_ON(va & ~PAGE_MASK);
35815
35816 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
35817@@ -989,7 +985,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
35818 return 0;
35819 }
35820
35821-static void set_xen_basic_apic_ops(void)
35822+static void __init set_xen_basic_apic_ops(void)
35823 {
35824 apic->read = xen_apic_read;
35825 apic->write = xen_apic_write;
35826@@ -1295,30 +1291,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
35827 #endif
35828 };
35829
35830-static void xen_reboot(int reason)
35831+static __noreturn void xen_reboot(int reason)
35832 {
35833 struct sched_shutdown r = { .reason = reason };
35834
35835- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
35836- BUG();
35837+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
35838+ BUG();
35839 }
35840
35841-static void xen_restart(char *msg)
35842+static __noreturn void xen_restart(char *msg)
35843 {
35844 xen_reboot(SHUTDOWN_reboot);
35845 }
35846
35847-static void xen_emergency_restart(void)
35848+static __noreturn void xen_emergency_restart(void)
35849 {
35850 xen_reboot(SHUTDOWN_reboot);
35851 }
35852
35853-static void xen_machine_halt(void)
35854+static __noreturn void xen_machine_halt(void)
35855 {
35856 xen_reboot(SHUTDOWN_poweroff);
35857 }
35858
35859-static void xen_machine_power_off(void)
35860+static __noreturn void xen_machine_power_off(void)
35861 {
35862 if (pm_power_off)
35863 pm_power_off();
35864@@ -1564,7 +1560,17 @@ asmlinkage void __init xen_start_kernel(void)
35865 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
35866
35867 /* Work out if we support NX */
35868- x86_configure_nx();
35869+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
35870+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
35871+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
35872+ unsigned l, h;
35873+
35874+ __supported_pte_mask |= _PAGE_NX;
35875+ rdmsr(MSR_EFER, l, h);
35876+ l |= EFER_NX;
35877+ wrmsr(MSR_EFER, l, h);
35878+ }
35879+#endif
35880
35881 /* Get mfn list */
35882 xen_build_dynamic_phys_to_machine();
35883@@ -1592,13 +1598,6 @@ asmlinkage void __init xen_start_kernel(void)
35884
35885 machine_ops = xen_machine_ops;
35886
35887- /*
35888- * The only reliable way to retain the initial address of the
35889- * percpu gdt_page is to remember it here, so we can go and
35890- * mark it RW later, when the initial percpu area is freed.
35891- */
35892- xen_initial_gdt = &per_cpu(gdt_page, 0);
35893-
35894 xen_smp_init();
35895
35896 #ifdef CONFIG_ACPI_NUMA
35897diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
35898index 2423ef0..4f6fb5b 100644
35899--- a/arch/x86/xen/mmu.c
35900+++ b/arch/x86/xen/mmu.c
35901@@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
35902 return val;
35903 }
35904
35905-static pteval_t pte_pfn_to_mfn(pteval_t val)
35906+static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
35907 {
35908 if (val & _PAGE_PRESENT) {
35909 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
35910@@ -1904,6 +1904,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35911 /* L3_k[510] -> level2_kernel_pgt
35912 * L3_i[511] -> level2_fixmap_pgt */
35913 convert_pfn_mfn(level3_kernel_pgt);
35914+ convert_pfn_mfn(level3_vmalloc_start_pgt);
35915+ convert_pfn_mfn(level3_vmalloc_end_pgt);
35916+ convert_pfn_mfn(level3_vmemmap_pgt);
35917 }
35918 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
35919 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
35920@@ -1933,8 +1936,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35921 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
35922 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
35923 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
35924+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
35925+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
35926+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
35927 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
35928 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
35929+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
35930 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
35931 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
35932
35933@@ -2123,6 +2130,7 @@ static void __init xen_post_allocator_init(void)
35934 pv_mmu_ops.set_pud = xen_set_pud;
35935 #if PAGETABLE_LEVELS == 4
35936 pv_mmu_ops.set_pgd = xen_set_pgd;
35937+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
35938 #endif
35939
35940 /* This will work as long as patching hasn't happened yet
35941@@ -2201,6 +2209,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
35942 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
35943 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
35944 .set_pgd = xen_set_pgd_hyper,
35945+ .set_pgd_batched = xen_set_pgd_hyper,
35946
35947 .alloc_pud = xen_alloc_pmd_init,
35948 .release_pud = xen_release_pmd_init,
35949diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
35950index a18eadd..2e2f10e 100644
35951--- a/arch/x86/xen/smp.c
35952+++ b/arch/x86/xen/smp.c
35953@@ -283,17 +283,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
35954
35955 if (xen_pv_domain()) {
35956 if (!xen_feature(XENFEAT_writable_page_tables))
35957- /* We've switched to the "real" per-cpu gdt, so make
35958- * sure the old memory can be recycled. */
35959- make_lowmem_page_readwrite(xen_initial_gdt);
35960-
35961 #ifdef CONFIG_X86_32
35962 /*
35963 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
35964 * expects __USER_DS
35965 */
35966- loadsegment(ds, __USER_DS);
35967- loadsegment(es, __USER_DS);
35968+ loadsegment(ds, __KERNEL_DS);
35969+ loadsegment(es, __KERNEL_DS);
35970 #endif
35971
35972 xen_filter_cpu_maps();
35973@@ -372,7 +368,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35974 #ifdef CONFIG_X86_32
35975 /* Note: PVH is not yet supported on x86_32. */
35976 ctxt->user_regs.fs = __KERNEL_PERCPU;
35977- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
35978+ savesegment(gs, ctxt->user_regs.gs);
35979 #endif
35980 ctxt->user_regs.eip = (unsigned long)cpu_bringup_and_idle;
35981
35982@@ -381,8 +377,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35983 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
35984 ctxt->flags = VGCF_IN_KERNEL;
35985 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
35986- ctxt->user_regs.ds = __USER_DS;
35987- ctxt->user_regs.es = __USER_DS;
35988+ ctxt->user_regs.ds = __KERNEL_DS;
35989+ ctxt->user_regs.es = __KERNEL_DS;
35990 ctxt->user_regs.ss = __KERNEL_DS;
35991
35992 xen_copy_trap_info(ctxt->trap_ctxt);
35993@@ -437,13 +433,12 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
35994 int rc;
35995
35996 per_cpu(current_task, cpu) = idle;
35997+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
35998 #ifdef CONFIG_X86_32
35999 irq_ctx_init(cpu);
36000 #else
36001 clear_tsk_thread_flag(idle, TIF_FORK);
36002- per_cpu(kernel_stack, cpu) =
36003- (unsigned long)task_stack_page(idle) -
36004- KERNEL_STACK_OFFSET + THREAD_SIZE;
36005+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
36006 #endif
36007 xen_setup_runstate_info(cpu);
36008 xen_setup_timer(cpu);
36009@@ -719,7 +714,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
36010
36011 void __init xen_smp_init(void)
36012 {
36013- smp_ops = xen_smp_ops;
36014+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
36015 xen_fill_possible_map();
36016 }
36017
36018diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
36019index 33ca6e4..0ded929 100644
36020--- a/arch/x86/xen/xen-asm_32.S
36021+++ b/arch/x86/xen/xen-asm_32.S
36022@@ -84,14 +84,14 @@ ENTRY(xen_iret)
36023 ESP_OFFSET=4 # bytes pushed onto stack
36024
36025 /*
36026- * Store vcpu_info pointer for easy access. Do it this way to
36027- * avoid having to reload %fs
36028+ * Store vcpu_info pointer for easy access.
36029 */
36030 #ifdef CONFIG_SMP
36031- GET_THREAD_INFO(%eax)
36032- movl %ss:TI_cpu(%eax), %eax
36033- movl %ss:__per_cpu_offset(,%eax,4), %eax
36034- mov %ss:xen_vcpu(%eax), %eax
36035+ push %fs
36036+ mov $(__KERNEL_PERCPU), %eax
36037+ mov %eax, %fs
36038+ mov PER_CPU_VAR(xen_vcpu), %eax
36039+ pop %fs
36040 #else
36041 movl %ss:xen_vcpu, %eax
36042 #endif
36043diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
36044index 485b695..fda3e7c 100644
36045--- a/arch/x86/xen/xen-head.S
36046+++ b/arch/x86/xen/xen-head.S
36047@@ -39,6 +39,17 @@ ENTRY(startup_xen)
36048 #ifdef CONFIG_X86_32
36049 mov %esi,xen_start_info
36050 mov $init_thread_union+THREAD_SIZE,%esp
36051+#ifdef CONFIG_SMP
36052+ movl $cpu_gdt_table,%edi
36053+ movl $__per_cpu_load,%eax
36054+ movw %ax,__KERNEL_PERCPU + 2(%edi)
36055+ rorl $16,%eax
36056+ movb %al,__KERNEL_PERCPU + 4(%edi)
36057+ movb %ah,__KERNEL_PERCPU + 7(%edi)
36058+ movl $__per_cpu_end - 1,%eax
36059+ subl $__per_cpu_start,%eax
36060+ movw %ax,__KERNEL_PERCPU + 0(%edi)
36061+#endif
36062 #else
36063 mov %rsi,xen_start_info
36064 mov $init_thread_union+THREAD_SIZE,%rsp
36065diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
36066index 1cb6f4c..9981524 100644
36067--- a/arch/x86/xen/xen-ops.h
36068+++ b/arch/x86/xen/xen-ops.h
36069@@ -10,8 +10,6 @@
36070 extern const char xen_hypervisor_callback[];
36071 extern const char xen_failsafe_callback[];
36072
36073-extern void *xen_initial_gdt;
36074-
36075 struct trap_info;
36076 void xen_copy_trap_info(struct trap_info *traps);
36077
36078diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
36079index 525bd3d..ef888b1 100644
36080--- a/arch/xtensa/variants/dc232b/include/variant/core.h
36081+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
36082@@ -119,9 +119,9 @@
36083 ----------------------------------------------------------------------*/
36084
36085 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
36086-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
36087 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
36088 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
36089+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36090
36091 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
36092 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
36093diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
36094index 2f33760..835e50a 100644
36095--- a/arch/xtensa/variants/fsf/include/variant/core.h
36096+++ b/arch/xtensa/variants/fsf/include/variant/core.h
36097@@ -11,6 +11,7 @@
36098 #ifndef _XTENSA_CORE_H
36099 #define _XTENSA_CORE_H
36100
36101+#include <linux/const.h>
36102
36103 /****************************************************************************
36104 Parameters Useful for Any Code, USER or PRIVILEGED
36105@@ -112,9 +113,9 @@
36106 ----------------------------------------------------------------------*/
36107
36108 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
36109-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
36110 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
36111 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
36112+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36113
36114 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
36115 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
36116diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
36117index af00795..2bb8105 100644
36118--- a/arch/xtensa/variants/s6000/include/variant/core.h
36119+++ b/arch/xtensa/variants/s6000/include/variant/core.h
36120@@ -11,6 +11,7 @@
36121 #ifndef _XTENSA_CORE_CONFIGURATION_H
36122 #define _XTENSA_CORE_CONFIGURATION_H
36123
36124+#include <linux/const.h>
36125
36126 /****************************************************************************
36127 Parameters Useful for Any Code, USER or PRIVILEGED
36128@@ -118,9 +119,9 @@
36129 ----------------------------------------------------------------------*/
36130
36131 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
36132-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
36133 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
36134 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
36135+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36136
36137 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
36138 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
36139diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
36140index 4e491d9..c8e18e4 100644
36141--- a/block/blk-cgroup.c
36142+++ b/block/blk-cgroup.c
36143@@ -812,7 +812,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
36144 static struct cgroup_subsys_state *
36145 blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
36146 {
36147- static atomic64_t id_seq = ATOMIC64_INIT(0);
36148+ static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
36149 struct blkcg *blkcg;
36150
36151 if (!parent_css) {
36152@@ -826,7 +826,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
36153
36154 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
36155 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
36156- blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
36157+ blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
36158 done:
36159 spin_lock_init(&blkcg->lock);
36160 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
36161diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
36162index 1855bf5..af12b06 100644
36163--- a/block/blk-iopoll.c
36164+++ b/block/blk-iopoll.c
36165@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
36166 }
36167 EXPORT_SYMBOL(blk_iopoll_complete);
36168
36169-static void blk_iopoll_softirq(struct softirq_action *h)
36170+static __latent_entropy void blk_iopoll_softirq(void)
36171 {
36172 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
36173 int rearm = 0, budget = blk_iopoll_budget;
36174diff --git a/block/blk-map.c b/block/blk-map.c
36175index ae4ae10..c470b8d 100644
36176--- a/block/blk-map.c
36177+++ b/block/blk-map.c
36178@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
36179 if (!len || !kbuf)
36180 return -EINVAL;
36181
36182- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
36183+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
36184 if (do_copy)
36185 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
36186 else
36187diff --git a/block/blk-softirq.c b/block/blk-softirq.c
36188index 57790c1..5e988dd 100644
36189--- a/block/blk-softirq.c
36190+++ b/block/blk-softirq.c
36191@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
36192 * Softirq action handler - move entries to local list and loop over them
36193 * while passing them to the queue registered handler.
36194 */
36195-static void blk_done_softirq(struct softirq_action *h)
36196+static __latent_entropy void blk_done_softirq(void)
36197 {
36198 struct list_head *cpu_list, local_list;
36199
36200diff --git a/block/bsg.c b/block/bsg.c
36201index 420a5a9..23834aa 100644
36202--- a/block/bsg.c
36203+++ b/block/bsg.c
36204@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
36205 struct sg_io_v4 *hdr, struct bsg_device *bd,
36206 fmode_t has_write_perm)
36207 {
36208+ unsigned char tmpcmd[sizeof(rq->__cmd)];
36209+ unsigned char *cmdptr;
36210+
36211 if (hdr->request_len > BLK_MAX_CDB) {
36212 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
36213 if (!rq->cmd)
36214 return -ENOMEM;
36215- }
36216+ cmdptr = rq->cmd;
36217+ } else
36218+ cmdptr = tmpcmd;
36219
36220- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
36221+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
36222 hdr->request_len))
36223 return -EFAULT;
36224
36225+ if (cmdptr != rq->cmd)
36226+ memcpy(rq->cmd, cmdptr, hdr->request_len);
36227+
36228 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
36229 if (blk_verify_command(rq->cmd, has_write_perm))
36230 return -EPERM;
36231diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
36232index fbd5a67..f24fd95 100644
36233--- a/block/compat_ioctl.c
36234+++ b/block/compat_ioctl.c
36235@@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
36236 cgc = compat_alloc_user_space(sizeof(*cgc));
36237 cgc32 = compat_ptr(arg);
36238
36239- if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
36240+ if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
36241 get_user(data, &cgc32->buffer) ||
36242 put_user(compat_ptr(data), &cgc->buffer) ||
36243 copy_in_user(&cgc->buflen, &cgc32->buflen,
36244@@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
36245 err |= __get_user(f->spec1, &uf->spec1);
36246 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
36247 err |= __get_user(name, &uf->name);
36248- f->name = compat_ptr(name);
36249+ f->name = (void __force_kernel *)compat_ptr(name);
36250 if (err) {
36251 err = -EFAULT;
36252 goto out;
36253diff --git a/block/genhd.c b/block/genhd.c
36254index 791f419..89f21c4 100644
36255--- a/block/genhd.c
36256+++ b/block/genhd.c
36257@@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
36258
36259 /*
36260 * Register device numbers dev..(dev+range-1)
36261- * range must be nonzero
36262+ * Noop if @range is zero.
36263 * The hash chain is sorted on range, so that subranges can override.
36264 */
36265 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
36266 struct kobject *(*probe)(dev_t, int *, void *),
36267 int (*lock)(dev_t, void *), void *data)
36268 {
36269- kobj_map(bdev_map, devt, range, module, probe, lock, data);
36270+ if (range)
36271+ kobj_map(bdev_map, devt, range, module, probe, lock, data);
36272 }
36273
36274 EXPORT_SYMBOL(blk_register_region);
36275
36276+/* undo blk_register_region(), noop if @range is zero */
36277 void blk_unregister_region(dev_t devt, unsigned long range)
36278 {
36279- kobj_unmap(bdev_map, devt, range);
36280+ if (range)
36281+ kobj_unmap(bdev_map, devt, range);
36282 }
36283
36284 EXPORT_SYMBOL(blk_unregister_region);
36285diff --git a/block/partitions/efi.c b/block/partitions/efi.c
36286index dc51f46..d5446a8 100644
36287--- a/block/partitions/efi.c
36288+++ b/block/partitions/efi.c
36289@@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
36290 if (!gpt)
36291 return NULL;
36292
36293+ if (!le32_to_cpu(gpt->num_partition_entries))
36294+ return NULL;
36295+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
36296+ if (!pte)
36297+ return NULL;
36298+
36299 count = le32_to_cpu(gpt->num_partition_entries) *
36300 le32_to_cpu(gpt->sizeof_partition_entry);
36301- if (!count)
36302- return NULL;
36303- pte = kmalloc(count, GFP_KERNEL);
36304- if (!pte)
36305- return NULL;
36306-
36307 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
36308 (u8 *) pte, count) < count) {
36309 kfree(pte);
36310diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
36311index 2648797..92ed21f 100644
36312--- a/block/scsi_ioctl.c
36313+++ b/block/scsi_ioctl.c
36314@@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
36315 return put_user(0, p);
36316 }
36317
36318-static int sg_get_timeout(struct request_queue *q)
36319+static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
36320 {
36321 return jiffies_to_clock_t(q->sg_timeout);
36322 }
36323@@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
36324 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
36325 struct sg_io_hdr *hdr, fmode_t mode)
36326 {
36327- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
36328+ unsigned char tmpcmd[sizeof(rq->__cmd)];
36329+ unsigned char *cmdptr;
36330+
36331+ if (rq->cmd != rq->__cmd)
36332+ cmdptr = rq->cmd;
36333+ else
36334+ cmdptr = tmpcmd;
36335+
36336+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
36337 return -EFAULT;
36338+
36339+ if (cmdptr != rq->cmd)
36340+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
36341+
36342 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
36343 return -EPERM;
36344
36345@@ -417,6 +429,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36346 int err;
36347 unsigned int in_len, out_len, bytes, opcode, cmdlen;
36348 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
36349+ unsigned char tmpcmd[sizeof(rq->__cmd)];
36350+ unsigned char *cmdptr;
36351
36352 if (!sic)
36353 return -EINVAL;
36354@@ -450,9 +464,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36355 */
36356 err = -EFAULT;
36357 rq->cmd_len = cmdlen;
36358- if (copy_from_user(rq->cmd, sic->data, cmdlen))
36359+
36360+ if (rq->cmd != rq->__cmd)
36361+ cmdptr = rq->cmd;
36362+ else
36363+ cmdptr = tmpcmd;
36364+
36365+ if (copy_from_user(cmdptr, sic->data, cmdlen))
36366 goto error;
36367
36368+ if (rq->cmd != cmdptr)
36369+ memcpy(rq->cmd, cmdptr, cmdlen);
36370+
36371 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
36372 goto error;
36373
36374diff --git a/crypto/cryptd.c b/crypto/cryptd.c
36375index 7bdd61b..afec999 100644
36376--- a/crypto/cryptd.c
36377+++ b/crypto/cryptd.c
36378@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
36379
36380 struct cryptd_blkcipher_request_ctx {
36381 crypto_completion_t complete;
36382-};
36383+} __no_const;
36384
36385 struct cryptd_hash_ctx {
36386 struct crypto_shash *child;
36387@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
36388
36389 struct cryptd_aead_request_ctx {
36390 crypto_completion_t complete;
36391-};
36392+} __no_const;
36393
36394 static void cryptd_queue_worker(struct work_struct *work);
36395
36396diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
36397index 309d345..1632720 100644
36398--- a/crypto/pcrypt.c
36399+++ b/crypto/pcrypt.c
36400@@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
36401 int ret;
36402
36403 pinst->kobj.kset = pcrypt_kset;
36404- ret = kobject_add(&pinst->kobj, NULL, name);
36405+ ret = kobject_add(&pinst->kobj, NULL, "%s", name);
36406 if (!ret)
36407 kobject_uevent(&pinst->kobj, KOBJ_ADD);
36408
36409diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
36410index 15dddc1..b61cf0c 100644
36411--- a/drivers/acpi/acpica/hwxfsleep.c
36412+++ b/drivers/acpi/acpica/hwxfsleep.c
36413@@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
36414 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
36415
36416 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
36417- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36418- acpi_hw_extended_sleep},
36419- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36420- acpi_hw_extended_wake_prep},
36421- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
36422+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36423+ .extended_function = acpi_hw_extended_sleep},
36424+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36425+ .extended_function = acpi_hw_extended_wake_prep},
36426+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
36427+ .extended_function = acpi_hw_extended_wake}
36428 };
36429
36430 /*
36431diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
36432index e5bcd91..74f050d 100644
36433--- a/drivers/acpi/apei/apei-internal.h
36434+++ b/drivers/acpi/apei/apei-internal.h
36435@@ -19,7 +19,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
36436 struct apei_exec_ins_type {
36437 u32 flags;
36438 apei_exec_ins_func_t run;
36439-};
36440+} __do_const;
36441
36442 struct apei_exec_context {
36443 u32 ip;
36444diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
36445index dab7cb7..f0d2994 100644
36446--- a/drivers/acpi/apei/ghes.c
36447+++ b/drivers/acpi/apei/ghes.c
36448@@ -500,7 +500,7 @@ static void __ghes_print_estatus(const char *pfx,
36449 const struct acpi_hest_generic *generic,
36450 const struct acpi_generic_status *estatus)
36451 {
36452- static atomic_t seqno;
36453+ static atomic_unchecked_t seqno;
36454 unsigned int curr_seqno;
36455 char pfx_seq[64];
36456
36457@@ -511,7 +511,7 @@ static void __ghes_print_estatus(const char *pfx,
36458 else
36459 pfx = KERN_ERR;
36460 }
36461- curr_seqno = atomic_inc_return(&seqno);
36462+ curr_seqno = atomic_inc_return_unchecked(&seqno);
36463 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
36464 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
36465 pfx_seq, generic->header.source_id);
36466diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
36467index a83e3c6..c3d617f 100644
36468--- a/drivers/acpi/bgrt.c
36469+++ b/drivers/acpi/bgrt.c
36470@@ -86,8 +86,10 @@ static int __init bgrt_init(void)
36471 if (!bgrt_image)
36472 return -ENODEV;
36473
36474- bin_attr_image.private = bgrt_image;
36475- bin_attr_image.size = bgrt_image_size;
36476+ pax_open_kernel();
36477+ *(void **)&bin_attr_image.private = bgrt_image;
36478+ *(size_t *)&bin_attr_image.size = bgrt_image_size;
36479+ pax_close_kernel();
36480
36481 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
36482 if (!bgrt_kobj)
36483diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
36484index afec452..c5d8b96 100644
36485--- a/drivers/acpi/blacklist.c
36486+++ b/drivers/acpi/blacklist.c
36487@@ -51,7 +51,7 @@ struct acpi_blacklist_item {
36488 u32 is_critical_error;
36489 };
36490
36491-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
36492+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
36493
36494 /*
36495 * POLICY: If *anything* doesn't work, put it on the blacklist.
36496@@ -163,7 +163,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
36497 return 0;
36498 }
36499
36500-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
36501+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
36502 {
36503 .callback = dmi_disable_osi_vista,
36504 .ident = "Fujitsu Siemens",
36505diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
36506index c68e724..e863008 100644
36507--- a/drivers/acpi/custom_method.c
36508+++ b/drivers/acpi/custom_method.c
36509@@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
36510 struct acpi_table_header table;
36511 acpi_status status;
36512
36513+#ifdef CONFIG_GRKERNSEC_KMEM
36514+ return -EPERM;
36515+#endif
36516+
36517 if (!(*ppos)) {
36518 /* parse the table header to get the table length */
36519 if (count <= sizeof(struct acpi_table_header))
36520diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
36521index 3dca36d..abaf070 100644
36522--- a/drivers/acpi/processor_idle.c
36523+++ b/drivers/acpi/processor_idle.c
36524@@ -952,7 +952,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
36525 {
36526 int i, count = CPUIDLE_DRIVER_STATE_START;
36527 struct acpi_processor_cx *cx;
36528- struct cpuidle_state *state;
36529+ cpuidle_state_no_const *state;
36530 struct cpuidle_driver *drv = &acpi_idle_driver;
36531
36532 if (!pr->flags.power_setup_done)
36533diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
36534index 91a32ce..d77fcaf 100644
36535--- a/drivers/acpi/sysfs.c
36536+++ b/drivers/acpi/sysfs.c
36537@@ -425,11 +425,11 @@ static u32 num_counters;
36538 static struct attribute **all_attrs;
36539 static u32 acpi_gpe_count;
36540
36541-static struct attribute_group interrupt_stats_attr_group = {
36542+static attribute_group_no_const interrupt_stats_attr_group = {
36543 .name = "interrupts",
36544 };
36545
36546-static struct kobj_attribute *counter_attrs;
36547+static kobj_attribute_no_const *counter_attrs;
36548
36549 static void delete_gpe_attr_array(void)
36550 {
36551diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
36552index 36605ab..6ef6d4b 100644
36553--- a/drivers/ata/libahci.c
36554+++ b/drivers/ata/libahci.c
36555@@ -1239,7 +1239,7 @@ int ahci_kick_engine(struct ata_port *ap)
36556 }
36557 EXPORT_SYMBOL_GPL(ahci_kick_engine);
36558
36559-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36560+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36561 struct ata_taskfile *tf, int is_cmd, u16 flags,
36562 unsigned long timeout_msec)
36563 {
36564diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
36565index 8cb2522..a815e54 100644
36566--- a/drivers/ata/libata-core.c
36567+++ b/drivers/ata/libata-core.c
36568@@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
36569 static void ata_dev_xfermask(struct ata_device *dev);
36570 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
36571
36572-atomic_t ata_print_id = ATOMIC_INIT(0);
36573+atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
36574
36575 struct ata_force_param {
36576 const char *name;
36577@@ -4851,7 +4851,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
36578 struct ata_port *ap;
36579 unsigned int tag;
36580
36581- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36582+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36583 ap = qc->ap;
36584
36585 qc->flags = 0;
36586@@ -4867,7 +4867,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
36587 struct ata_port *ap;
36588 struct ata_link *link;
36589
36590- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36591+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36592 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
36593 ap = qc->ap;
36594 link = qc->dev->link;
36595@@ -5986,6 +5986,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36596 return;
36597
36598 spin_lock(&lock);
36599+ pax_open_kernel();
36600
36601 for (cur = ops->inherits; cur; cur = cur->inherits) {
36602 void **inherit = (void **)cur;
36603@@ -5999,8 +6000,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36604 if (IS_ERR(*pp))
36605 *pp = NULL;
36606
36607- ops->inherits = NULL;
36608+ *(struct ata_port_operations **)&ops->inherits = NULL;
36609
36610+ pax_close_kernel();
36611 spin_unlock(&lock);
36612 }
36613
36614@@ -6193,7 +6195,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
36615
36616 /* give ports names and add SCSI hosts */
36617 for (i = 0; i < host->n_ports; i++) {
36618- host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
36619+ host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
36620 host->ports[i]->local_port_no = i + 1;
36621 }
36622
36623diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
36624index ef8567d..8bdbd03 100644
36625--- a/drivers/ata/libata-scsi.c
36626+++ b/drivers/ata/libata-scsi.c
36627@@ -4147,7 +4147,7 @@ int ata_sas_port_init(struct ata_port *ap)
36628
36629 if (rc)
36630 return rc;
36631- ap->print_id = atomic_inc_return(&ata_print_id);
36632+ ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
36633 return 0;
36634 }
36635 EXPORT_SYMBOL_GPL(ata_sas_port_init);
36636diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
36637index 45b5ab3..98446b8 100644
36638--- a/drivers/ata/libata.h
36639+++ b/drivers/ata/libata.h
36640@@ -53,7 +53,7 @@ enum {
36641 ATA_DNXFER_QUIET = (1 << 31),
36642 };
36643
36644-extern atomic_t ata_print_id;
36645+extern atomic_unchecked_t ata_print_id;
36646 extern int atapi_passthru16;
36647 extern int libata_fua;
36648 extern int libata_noacpi;
36649diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
36650index 73492dd..ca2bff5 100644
36651--- a/drivers/ata/pata_arasan_cf.c
36652+++ b/drivers/ata/pata_arasan_cf.c
36653@@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
36654 /* Handle platform specific quirks */
36655 if (quirk) {
36656 if (quirk & CF_BROKEN_PIO) {
36657- ap->ops->set_piomode = NULL;
36658+ pax_open_kernel();
36659+ *(void **)&ap->ops->set_piomode = NULL;
36660+ pax_close_kernel();
36661 ap->pio_mask = 0;
36662 }
36663 if (quirk & CF_BROKEN_MWDMA)
36664diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
36665index f9b983a..887b9d8 100644
36666--- a/drivers/atm/adummy.c
36667+++ b/drivers/atm/adummy.c
36668@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
36669 vcc->pop(vcc, skb);
36670 else
36671 dev_kfree_skb_any(skb);
36672- atomic_inc(&vcc->stats->tx);
36673+ atomic_inc_unchecked(&vcc->stats->tx);
36674
36675 return 0;
36676 }
36677diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
36678index 62a7607..cc4be104 100644
36679--- a/drivers/atm/ambassador.c
36680+++ b/drivers/atm/ambassador.c
36681@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
36682 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
36683
36684 // VC layer stats
36685- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36686+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36687
36688 // free the descriptor
36689 kfree (tx_descr);
36690@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36691 dump_skb ("<<<", vc, skb);
36692
36693 // VC layer stats
36694- atomic_inc(&atm_vcc->stats->rx);
36695+ atomic_inc_unchecked(&atm_vcc->stats->rx);
36696 __net_timestamp(skb);
36697 // end of our responsibility
36698 atm_vcc->push (atm_vcc, skb);
36699@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36700 } else {
36701 PRINTK (KERN_INFO, "dropped over-size frame");
36702 // should we count this?
36703- atomic_inc(&atm_vcc->stats->rx_drop);
36704+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36705 }
36706
36707 } else {
36708@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
36709 }
36710
36711 if (check_area (skb->data, skb->len)) {
36712- atomic_inc(&atm_vcc->stats->tx_err);
36713+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
36714 return -ENOMEM; // ?
36715 }
36716
36717diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
36718index 0e3f8f9..765a7a5 100644
36719--- a/drivers/atm/atmtcp.c
36720+++ b/drivers/atm/atmtcp.c
36721@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36722 if (vcc->pop) vcc->pop(vcc,skb);
36723 else dev_kfree_skb(skb);
36724 if (dev_data) return 0;
36725- atomic_inc(&vcc->stats->tx_err);
36726+ atomic_inc_unchecked(&vcc->stats->tx_err);
36727 return -ENOLINK;
36728 }
36729 size = skb->len+sizeof(struct atmtcp_hdr);
36730@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36731 if (!new_skb) {
36732 if (vcc->pop) vcc->pop(vcc,skb);
36733 else dev_kfree_skb(skb);
36734- atomic_inc(&vcc->stats->tx_err);
36735+ atomic_inc_unchecked(&vcc->stats->tx_err);
36736 return -ENOBUFS;
36737 }
36738 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
36739@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36740 if (vcc->pop) vcc->pop(vcc,skb);
36741 else dev_kfree_skb(skb);
36742 out_vcc->push(out_vcc,new_skb);
36743- atomic_inc(&vcc->stats->tx);
36744- atomic_inc(&out_vcc->stats->rx);
36745+ atomic_inc_unchecked(&vcc->stats->tx);
36746+ atomic_inc_unchecked(&out_vcc->stats->rx);
36747 return 0;
36748 }
36749
36750@@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36751 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
36752 read_unlock(&vcc_sklist_lock);
36753 if (!out_vcc) {
36754- atomic_inc(&vcc->stats->tx_err);
36755+ atomic_inc_unchecked(&vcc->stats->tx_err);
36756 goto done;
36757 }
36758 skb_pull(skb,sizeof(struct atmtcp_hdr));
36759@@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36760 __net_timestamp(new_skb);
36761 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
36762 out_vcc->push(out_vcc,new_skb);
36763- atomic_inc(&vcc->stats->tx);
36764- atomic_inc(&out_vcc->stats->rx);
36765+ atomic_inc_unchecked(&vcc->stats->tx);
36766+ atomic_inc_unchecked(&out_vcc->stats->rx);
36767 done:
36768 if (vcc->pop) vcc->pop(vcc,skb);
36769 else dev_kfree_skb(skb);
36770diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
36771index b1955ba..b179940 100644
36772--- a/drivers/atm/eni.c
36773+++ b/drivers/atm/eni.c
36774@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
36775 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
36776 vcc->dev->number);
36777 length = 0;
36778- atomic_inc(&vcc->stats->rx_err);
36779+ atomic_inc_unchecked(&vcc->stats->rx_err);
36780 }
36781 else {
36782 length = ATM_CELL_SIZE-1; /* no HEC */
36783@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36784 size);
36785 }
36786 eff = length = 0;
36787- atomic_inc(&vcc->stats->rx_err);
36788+ atomic_inc_unchecked(&vcc->stats->rx_err);
36789 }
36790 else {
36791 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
36792@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36793 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
36794 vcc->dev->number,vcc->vci,length,size << 2,descr);
36795 length = eff = 0;
36796- atomic_inc(&vcc->stats->rx_err);
36797+ atomic_inc_unchecked(&vcc->stats->rx_err);
36798 }
36799 }
36800 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
36801@@ -767,7 +767,7 @@ rx_dequeued++;
36802 vcc->push(vcc,skb);
36803 pushed++;
36804 }
36805- atomic_inc(&vcc->stats->rx);
36806+ atomic_inc_unchecked(&vcc->stats->rx);
36807 }
36808 wake_up(&eni_dev->rx_wait);
36809 }
36810@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
36811 PCI_DMA_TODEVICE);
36812 if (vcc->pop) vcc->pop(vcc,skb);
36813 else dev_kfree_skb_irq(skb);
36814- atomic_inc(&vcc->stats->tx);
36815+ atomic_inc_unchecked(&vcc->stats->tx);
36816 wake_up(&eni_dev->tx_wait);
36817 dma_complete++;
36818 }
36819diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
36820index b41c948..a002b17 100644
36821--- a/drivers/atm/firestream.c
36822+++ b/drivers/atm/firestream.c
36823@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
36824 }
36825 }
36826
36827- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36828+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36829
36830 fs_dprintk (FS_DEBUG_TXMEM, "i");
36831 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
36832@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36833 #endif
36834 skb_put (skb, qe->p1 & 0xffff);
36835 ATM_SKB(skb)->vcc = atm_vcc;
36836- atomic_inc(&atm_vcc->stats->rx);
36837+ atomic_inc_unchecked(&atm_vcc->stats->rx);
36838 __net_timestamp(skb);
36839 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
36840 atm_vcc->push (atm_vcc, skb);
36841@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36842 kfree (pe);
36843 }
36844 if (atm_vcc)
36845- atomic_inc(&atm_vcc->stats->rx_drop);
36846+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36847 break;
36848 case 0x1f: /* Reassembly abort: no buffers. */
36849 /* Silently increment error counter. */
36850 if (atm_vcc)
36851- atomic_inc(&atm_vcc->stats->rx_drop);
36852+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36853 break;
36854 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
36855 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
36856diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
36857index 204814e..cede831 100644
36858--- a/drivers/atm/fore200e.c
36859+++ b/drivers/atm/fore200e.c
36860@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
36861 #endif
36862 /* check error condition */
36863 if (*entry->status & STATUS_ERROR)
36864- atomic_inc(&vcc->stats->tx_err);
36865+ atomic_inc_unchecked(&vcc->stats->tx_err);
36866 else
36867- atomic_inc(&vcc->stats->tx);
36868+ atomic_inc_unchecked(&vcc->stats->tx);
36869 }
36870 }
36871
36872@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36873 if (skb == NULL) {
36874 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
36875
36876- atomic_inc(&vcc->stats->rx_drop);
36877+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36878 return -ENOMEM;
36879 }
36880
36881@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36882
36883 dev_kfree_skb_any(skb);
36884
36885- atomic_inc(&vcc->stats->rx_drop);
36886+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36887 return -ENOMEM;
36888 }
36889
36890 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36891
36892 vcc->push(vcc, skb);
36893- atomic_inc(&vcc->stats->rx);
36894+ atomic_inc_unchecked(&vcc->stats->rx);
36895
36896 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36897
36898@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
36899 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
36900 fore200e->atm_dev->number,
36901 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
36902- atomic_inc(&vcc->stats->rx_err);
36903+ atomic_inc_unchecked(&vcc->stats->rx_err);
36904 }
36905 }
36906
36907@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
36908 goto retry_here;
36909 }
36910
36911- atomic_inc(&vcc->stats->tx_err);
36912+ atomic_inc_unchecked(&vcc->stats->tx_err);
36913
36914 fore200e->tx_sat++;
36915 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
36916diff --git a/drivers/atm/he.c b/drivers/atm/he.c
36917index aa6be26..f70a785 100644
36918--- a/drivers/atm/he.c
36919+++ b/drivers/atm/he.c
36920@@ -1690,7 +1690,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36921
36922 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
36923 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
36924- atomic_inc(&vcc->stats->rx_drop);
36925+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36926 goto return_host_buffers;
36927 }
36928
36929@@ -1717,7 +1717,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36930 RBRQ_LEN_ERR(he_dev->rbrq_head)
36931 ? "LEN_ERR" : "",
36932 vcc->vpi, vcc->vci);
36933- atomic_inc(&vcc->stats->rx_err);
36934+ atomic_inc_unchecked(&vcc->stats->rx_err);
36935 goto return_host_buffers;
36936 }
36937
36938@@ -1769,7 +1769,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36939 vcc->push(vcc, skb);
36940 spin_lock(&he_dev->global_lock);
36941
36942- atomic_inc(&vcc->stats->rx);
36943+ atomic_inc_unchecked(&vcc->stats->rx);
36944
36945 return_host_buffers:
36946 ++pdus_assembled;
36947@@ -2095,7 +2095,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
36948 tpd->vcc->pop(tpd->vcc, tpd->skb);
36949 else
36950 dev_kfree_skb_any(tpd->skb);
36951- atomic_inc(&tpd->vcc->stats->tx_err);
36952+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
36953 }
36954 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
36955 return;
36956@@ -2507,7 +2507,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36957 vcc->pop(vcc, skb);
36958 else
36959 dev_kfree_skb_any(skb);
36960- atomic_inc(&vcc->stats->tx_err);
36961+ atomic_inc_unchecked(&vcc->stats->tx_err);
36962 return -EINVAL;
36963 }
36964
36965@@ -2518,7 +2518,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36966 vcc->pop(vcc, skb);
36967 else
36968 dev_kfree_skb_any(skb);
36969- atomic_inc(&vcc->stats->tx_err);
36970+ atomic_inc_unchecked(&vcc->stats->tx_err);
36971 return -EINVAL;
36972 }
36973 #endif
36974@@ -2530,7 +2530,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36975 vcc->pop(vcc, skb);
36976 else
36977 dev_kfree_skb_any(skb);
36978- atomic_inc(&vcc->stats->tx_err);
36979+ atomic_inc_unchecked(&vcc->stats->tx_err);
36980 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36981 return -ENOMEM;
36982 }
36983@@ -2572,7 +2572,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36984 vcc->pop(vcc, skb);
36985 else
36986 dev_kfree_skb_any(skb);
36987- atomic_inc(&vcc->stats->tx_err);
36988+ atomic_inc_unchecked(&vcc->stats->tx_err);
36989 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36990 return -ENOMEM;
36991 }
36992@@ -2603,7 +2603,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36993 __enqueue_tpd(he_dev, tpd, cid);
36994 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36995
36996- atomic_inc(&vcc->stats->tx);
36997+ atomic_inc_unchecked(&vcc->stats->tx);
36998
36999 return 0;
37000 }
37001diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
37002index 1dc0519..1aadaf7 100644
37003--- a/drivers/atm/horizon.c
37004+++ b/drivers/atm/horizon.c
37005@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
37006 {
37007 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
37008 // VC layer stats
37009- atomic_inc(&vcc->stats->rx);
37010+ atomic_inc_unchecked(&vcc->stats->rx);
37011 __net_timestamp(skb);
37012 // end of our responsibility
37013 vcc->push (vcc, skb);
37014@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
37015 dev->tx_iovec = NULL;
37016
37017 // VC layer stats
37018- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
37019+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
37020
37021 // free the skb
37022 hrz_kfree_skb (skb);
37023diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
37024index 1bdf104..9dc44b1 100644
37025--- a/drivers/atm/idt77252.c
37026+++ b/drivers/atm/idt77252.c
37027@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
37028 else
37029 dev_kfree_skb(skb);
37030
37031- atomic_inc(&vcc->stats->tx);
37032+ atomic_inc_unchecked(&vcc->stats->tx);
37033 }
37034
37035 atomic_dec(&scq->used);
37036@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37037 if ((sb = dev_alloc_skb(64)) == NULL) {
37038 printk("%s: Can't allocate buffers for aal0.\n",
37039 card->name);
37040- atomic_add(i, &vcc->stats->rx_drop);
37041+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
37042 break;
37043 }
37044 if (!atm_charge(vcc, sb->truesize)) {
37045 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
37046 card->name);
37047- atomic_add(i - 1, &vcc->stats->rx_drop);
37048+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
37049 dev_kfree_skb(sb);
37050 break;
37051 }
37052@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37053 ATM_SKB(sb)->vcc = vcc;
37054 __net_timestamp(sb);
37055 vcc->push(vcc, sb);
37056- atomic_inc(&vcc->stats->rx);
37057+ atomic_inc_unchecked(&vcc->stats->rx);
37058
37059 cell += ATM_CELL_PAYLOAD;
37060 }
37061@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37062 "(CDC: %08x)\n",
37063 card->name, len, rpp->len, readl(SAR_REG_CDC));
37064 recycle_rx_pool_skb(card, rpp);
37065- atomic_inc(&vcc->stats->rx_err);
37066+ atomic_inc_unchecked(&vcc->stats->rx_err);
37067 return;
37068 }
37069 if (stat & SAR_RSQE_CRC) {
37070 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
37071 recycle_rx_pool_skb(card, rpp);
37072- atomic_inc(&vcc->stats->rx_err);
37073+ atomic_inc_unchecked(&vcc->stats->rx_err);
37074 return;
37075 }
37076 if (skb_queue_len(&rpp->queue) > 1) {
37077@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37078 RXPRINTK("%s: Can't alloc RX skb.\n",
37079 card->name);
37080 recycle_rx_pool_skb(card, rpp);
37081- atomic_inc(&vcc->stats->rx_err);
37082+ atomic_inc_unchecked(&vcc->stats->rx_err);
37083 return;
37084 }
37085 if (!atm_charge(vcc, skb->truesize)) {
37086@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37087 __net_timestamp(skb);
37088
37089 vcc->push(vcc, skb);
37090- atomic_inc(&vcc->stats->rx);
37091+ atomic_inc_unchecked(&vcc->stats->rx);
37092
37093 return;
37094 }
37095@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37096 __net_timestamp(skb);
37097
37098 vcc->push(vcc, skb);
37099- atomic_inc(&vcc->stats->rx);
37100+ atomic_inc_unchecked(&vcc->stats->rx);
37101
37102 if (skb->truesize > SAR_FB_SIZE_3)
37103 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
37104@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
37105 if (vcc->qos.aal != ATM_AAL0) {
37106 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
37107 card->name, vpi, vci);
37108- atomic_inc(&vcc->stats->rx_drop);
37109+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37110 goto drop;
37111 }
37112
37113 if ((sb = dev_alloc_skb(64)) == NULL) {
37114 printk("%s: Can't allocate buffers for AAL0.\n",
37115 card->name);
37116- atomic_inc(&vcc->stats->rx_err);
37117+ atomic_inc_unchecked(&vcc->stats->rx_err);
37118 goto drop;
37119 }
37120
37121@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
37122 ATM_SKB(sb)->vcc = vcc;
37123 __net_timestamp(sb);
37124 vcc->push(vcc, sb);
37125- atomic_inc(&vcc->stats->rx);
37126+ atomic_inc_unchecked(&vcc->stats->rx);
37127
37128 drop:
37129 skb_pull(queue, 64);
37130@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37131
37132 if (vc == NULL) {
37133 printk("%s: NULL connection in send().\n", card->name);
37134- atomic_inc(&vcc->stats->tx_err);
37135+ atomic_inc_unchecked(&vcc->stats->tx_err);
37136 dev_kfree_skb(skb);
37137 return -EINVAL;
37138 }
37139 if (!test_bit(VCF_TX, &vc->flags)) {
37140 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
37141- atomic_inc(&vcc->stats->tx_err);
37142+ atomic_inc_unchecked(&vcc->stats->tx_err);
37143 dev_kfree_skb(skb);
37144 return -EINVAL;
37145 }
37146@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37147 break;
37148 default:
37149 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
37150- atomic_inc(&vcc->stats->tx_err);
37151+ atomic_inc_unchecked(&vcc->stats->tx_err);
37152 dev_kfree_skb(skb);
37153 return -EINVAL;
37154 }
37155
37156 if (skb_shinfo(skb)->nr_frags != 0) {
37157 printk("%s: No scatter-gather yet.\n", card->name);
37158- atomic_inc(&vcc->stats->tx_err);
37159+ atomic_inc_unchecked(&vcc->stats->tx_err);
37160 dev_kfree_skb(skb);
37161 return -EINVAL;
37162 }
37163@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37164
37165 err = queue_skb(card, vc, skb, oam);
37166 if (err) {
37167- atomic_inc(&vcc->stats->tx_err);
37168+ atomic_inc_unchecked(&vcc->stats->tx_err);
37169 dev_kfree_skb(skb);
37170 return err;
37171 }
37172@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
37173 skb = dev_alloc_skb(64);
37174 if (!skb) {
37175 printk("%s: Out of memory in send_oam().\n", card->name);
37176- atomic_inc(&vcc->stats->tx_err);
37177+ atomic_inc_unchecked(&vcc->stats->tx_err);
37178 return -ENOMEM;
37179 }
37180 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
37181diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
37182index 4217f29..88f547a 100644
37183--- a/drivers/atm/iphase.c
37184+++ b/drivers/atm/iphase.c
37185@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
37186 status = (u_short) (buf_desc_ptr->desc_mode);
37187 if (status & (RX_CER | RX_PTE | RX_OFL))
37188 {
37189- atomic_inc(&vcc->stats->rx_err);
37190+ atomic_inc_unchecked(&vcc->stats->rx_err);
37191 IF_ERR(printk("IA: bad packet, dropping it");)
37192 if (status & RX_CER) {
37193 IF_ERR(printk(" cause: packet CRC error\n");)
37194@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
37195 len = dma_addr - buf_addr;
37196 if (len > iadev->rx_buf_sz) {
37197 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
37198- atomic_inc(&vcc->stats->rx_err);
37199+ atomic_inc_unchecked(&vcc->stats->rx_err);
37200 goto out_free_desc;
37201 }
37202
37203@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37204 ia_vcc = INPH_IA_VCC(vcc);
37205 if (ia_vcc == NULL)
37206 {
37207- atomic_inc(&vcc->stats->rx_err);
37208+ atomic_inc_unchecked(&vcc->stats->rx_err);
37209 atm_return(vcc, skb->truesize);
37210 dev_kfree_skb_any(skb);
37211 goto INCR_DLE;
37212@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37213 if ((length > iadev->rx_buf_sz) || (length >
37214 (skb->len - sizeof(struct cpcs_trailer))))
37215 {
37216- atomic_inc(&vcc->stats->rx_err);
37217+ atomic_inc_unchecked(&vcc->stats->rx_err);
37218 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
37219 length, skb->len);)
37220 atm_return(vcc, skb->truesize);
37221@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37222
37223 IF_RX(printk("rx_dle_intr: skb push");)
37224 vcc->push(vcc,skb);
37225- atomic_inc(&vcc->stats->rx);
37226+ atomic_inc_unchecked(&vcc->stats->rx);
37227 iadev->rx_pkt_cnt++;
37228 }
37229 INCR_DLE:
37230@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
37231 {
37232 struct k_sonet_stats *stats;
37233 stats = &PRIV(_ia_dev[board])->sonet_stats;
37234- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
37235- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
37236- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
37237- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
37238- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
37239- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
37240- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
37241- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
37242- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
37243+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
37244+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
37245+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
37246+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
37247+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
37248+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
37249+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
37250+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
37251+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
37252 }
37253 ia_cmds.status = 0;
37254 break;
37255@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
37256 if ((desc == 0) || (desc > iadev->num_tx_desc))
37257 {
37258 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
37259- atomic_inc(&vcc->stats->tx);
37260+ atomic_inc_unchecked(&vcc->stats->tx);
37261 if (vcc->pop)
37262 vcc->pop(vcc, skb);
37263 else
37264@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
37265 ATM_DESC(skb) = vcc->vci;
37266 skb_queue_tail(&iadev->tx_dma_q, skb);
37267
37268- atomic_inc(&vcc->stats->tx);
37269+ atomic_inc_unchecked(&vcc->stats->tx);
37270 iadev->tx_pkt_cnt++;
37271 /* Increment transaction counter */
37272 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
37273
37274 #if 0
37275 /* add flow control logic */
37276- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
37277+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
37278 if (iavcc->vc_desc_cnt > 10) {
37279 vcc->tx_quota = vcc->tx_quota * 3 / 4;
37280 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
37281diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
37282index fa7d701..1e404c7 100644
37283--- a/drivers/atm/lanai.c
37284+++ b/drivers/atm/lanai.c
37285@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
37286 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
37287 lanai_endtx(lanai, lvcc);
37288 lanai_free_skb(lvcc->tx.atmvcc, skb);
37289- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
37290+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
37291 }
37292
37293 /* Try to fill the buffer - don't call unless there is backlog */
37294@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
37295 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
37296 __net_timestamp(skb);
37297 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
37298- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
37299+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
37300 out:
37301 lvcc->rx.buf.ptr = end;
37302 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
37303@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37304 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
37305 "vcc %d\n", lanai->number, (unsigned int) s, vci);
37306 lanai->stats.service_rxnotaal5++;
37307- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37308+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37309 return 0;
37310 }
37311 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
37312@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37313 int bytes;
37314 read_unlock(&vcc_sklist_lock);
37315 DPRINTK("got trashed rx pdu on vci %d\n", vci);
37316- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37317+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37318 lvcc->stats.x.aal5.service_trash++;
37319 bytes = (SERVICE_GET_END(s) * 16) -
37320 (((unsigned long) lvcc->rx.buf.ptr) -
37321@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37322 }
37323 if (s & SERVICE_STREAM) {
37324 read_unlock(&vcc_sklist_lock);
37325- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37326+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37327 lvcc->stats.x.aal5.service_stream++;
37328 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
37329 "PDU on VCI %d!\n", lanai->number, vci);
37330@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37331 return 0;
37332 }
37333 DPRINTK("got rx crc error on vci %d\n", vci);
37334- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37335+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37336 lvcc->stats.x.aal5.service_rxcrc++;
37337 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
37338 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
37339diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
37340index 9587e95..b45c5cb 100644
37341--- a/drivers/atm/nicstar.c
37342+++ b/drivers/atm/nicstar.c
37343@@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37344 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
37345 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
37346 card->index);
37347- atomic_inc(&vcc->stats->tx_err);
37348+ atomic_inc_unchecked(&vcc->stats->tx_err);
37349 dev_kfree_skb_any(skb);
37350 return -EINVAL;
37351 }
37352@@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37353 if (!vc->tx) {
37354 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
37355 card->index);
37356- atomic_inc(&vcc->stats->tx_err);
37357+ atomic_inc_unchecked(&vcc->stats->tx_err);
37358 dev_kfree_skb_any(skb);
37359 return -EINVAL;
37360 }
37361@@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37362 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
37363 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
37364 card->index);
37365- atomic_inc(&vcc->stats->tx_err);
37366+ atomic_inc_unchecked(&vcc->stats->tx_err);
37367 dev_kfree_skb_any(skb);
37368 return -EINVAL;
37369 }
37370
37371 if (skb_shinfo(skb)->nr_frags != 0) {
37372 printk("nicstar%d: No scatter-gather yet.\n", card->index);
37373- atomic_inc(&vcc->stats->tx_err);
37374+ atomic_inc_unchecked(&vcc->stats->tx_err);
37375 dev_kfree_skb_any(skb);
37376 return -EINVAL;
37377 }
37378@@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37379 }
37380
37381 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
37382- atomic_inc(&vcc->stats->tx_err);
37383+ atomic_inc_unchecked(&vcc->stats->tx_err);
37384 dev_kfree_skb_any(skb);
37385 return -EIO;
37386 }
37387- atomic_inc(&vcc->stats->tx);
37388+ atomic_inc_unchecked(&vcc->stats->tx);
37389
37390 return 0;
37391 }
37392@@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37393 printk
37394 ("nicstar%d: Can't allocate buffers for aal0.\n",
37395 card->index);
37396- atomic_add(i, &vcc->stats->rx_drop);
37397+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
37398 break;
37399 }
37400 if (!atm_charge(vcc, sb->truesize)) {
37401 RXPRINTK
37402 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
37403 card->index);
37404- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37405+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37406 dev_kfree_skb_any(sb);
37407 break;
37408 }
37409@@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37410 ATM_SKB(sb)->vcc = vcc;
37411 __net_timestamp(sb);
37412 vcc->push(vcc, sb);
37413- atomic_inc(&vcc->stats->rx);
37414+ atomic_inc_unchecked(&vcc->stats->rx);
37415 cell += ATM_CELL_PAYLOAD;
37416 }
37417
37418@@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37419 if (iovb == NULL) {
37420 printk("nicstar%d: Out of iovec buffers.\n",
37421 card->index);
37422- atomic_inc(&vcc->stats->rx_drop);
37423+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37424 recycle_rx_buf(card, skb);
37425 return;
37426 }
37427@@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37428 small or large buffer itself. */
37429 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
37430 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
37431- atomic_inc(&vcc->stats->rx_err);
37432+ atomic_inc_unchecked(&vcc->stats->rx_err);
37433 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37434 NS_MAX_IOVECS);
37435 NS_PRV_IOVCNT(iovb) = 0;
37436@@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37437 ("nicstar%d: Expected a small buffer, and this is not one.\n",
37438 card->index);
37439 which_list(card, skb);
37440- atomic_inc(&vcc->stats->rx_err);
37441+ atomic_inc_unchecked(&vcc->stats->rx_err);
37442 recycle_rx_buf(card, skb);
37443 vc->rx_iov = NULL;
37444 recycle_iov_buf(card, iovb);
37445@@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37446 ("nicstar%d: Expected a large buffer, and this is not one.\n",
37447 card->index);
37448 which_list(card, skb);
37449- atomic_inc(&vcc->stats->rx_err);
37450+ atomic_inc_unchecked(&vcc->stats->rx_err);
37451 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37452 NS_PRV_IOVCNT(iovb));
37453 vc->rx_iov = NULL;
37454@@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37455 printk(" - PDU size mismatch.\n");
37456 else
37457 printk(".\n");
37458- atomic_inc(&vcc->stats->rx_err);
37459+ atomic_inc_unchecked(&vcc->stats->rx_err);
37460 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37461 NS_PRV_IOVCNT(iovb));
37462 vc->rx_iov = NULL;
37463@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37464 /* skb points to a small buffer */
37465 if (!atm_charge(vcc, skb->truesize)) {
37466 push_rxbufs(card, skb);
37467- atomic_inc(&vcc->stats->rx_drop);
37468+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37469 } else {
37470 skb_put(skb, len);
37471 dequeue_sm_buf(card, skb);
37472@@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37473 ATM_SKB(skb)->vcc = vcc;
37474 __net_timestamp(skb);
37475 vcc->push(vcc, skb);
37476- atomic_inc(&vcc->stats->rx);
37477+ atomic_inc_unchecked(&vcc->stats->rx);
37478 }
37479 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
37480 struct sk_buff *sb;
37481@@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37482 if (len <= NS_SMBUFSIZE) {
37483 if (!atm_charge(vcc, sb->truesize)) {
37484 push_rxbufs(card, sb);
37485- atomic_inc(&vcc->stats->rx_drop);
37486+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37487 } else {
37488 skb_put(sb, len);
37489 dequeue_sm_buf(card, sb);
37490@@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37491 ATM_SKB(sb)->vcc = vcc;
37492 __net_timestamp(sb);
37493 vcc->push(vcc, sb);
37494- atomic_inc(&vcc->stats->rx);
37495+ atomic_inc_unchecked(&vcc->stats->rx);
37496 }
37497
37498 push_rxbufs(card, skb);
37499@@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37500
37501 if (!atm_charge(vcc, skb->truesize)) {
37502 push_rxbufs(card, skb);
37503- atomic_inc(&vcc->stats->rx_drop);
37504+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37505 } else {
37506 dequeue_lg_buf(card, skb);
37507 #ifdef NS_USE_DESTRUCTORS
37508@@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37509 ATM_SKB(skb)->vcc = vcc;
37510 __net_timestamp(skb);
37511 vcc->push(vcc, skb);
37512- atomic_inc(&vcc->stats->rx);
37513+ atomic_inc_unchecked(&vcc->stats->rx);
37514 }
37515
37516 push_rxbufs(card, sb);
37517@@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37518 printk
37519 ("nicstar%d: Out of huge buffers.\n",
37520 card->index);
37521- atomic_inc(&vcc->stats->rx_drop);
37522+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37523 recycle_iovec_rx_bufs(card,
37524 (struct iovec *)
37525 iovb->data,
37526@@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37527 card->hbpool.count++;
37528 } else
37529 dev_kfree_skb_any(hb);
37530- atomic_inc(&vcc->stats->rx_drop);
37531+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37532 } else {
37533 /* Copy the small buffer to the huge buffer */
37534 sb = (struct sk_buff *)iov->iov_base;
37535@@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37536 #endif /* NS_USE_DESTRUCTORS */
37537 __net_timestamp(hb);
37538 vcc->push(vcc, hb);
37539- atomic_inc(&vcc->stats->rx);
37540+ atomic_inc_unchecked(&vcc->stats->rx);
37541 }
37542 }
37543
37544diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
37545index e3fb496..d9646bf 100644
37546--- a/drivers/atm/solos-pci.c
37547+++ b/drivers/atm/solos-pci.c
37548@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
37549 }
37550 atm_charge(vcc, skb->truesize);
37551 vcc->push(vcc, skb);
37552- atomic_inc(&vcc->stats->rx);
37553+ atomic_inc_unchecked(&vcc->stats->rx);
37554 break;
37555
37556 case PKT_STATUS:
37557@@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
37558 vcc = SKB_CB(oldskb)->vcc;
37559
37560 if (vcc) {
37561- atomic_inc(&vcc->stats->tx);
37562+ atomic_inc_unchecked(&vcc->stats->tx);
37563 solos_pop(vcc, oldskb);
37564 } else {
37565 dev_kfree_skb_irq(oldskb);
37566diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
37567index 0215934..ce9f5b1 100644
37568--- a/drivers/atm/suni.c
37569+++ b/drivers/atm/suni.c
37570@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
37571
37572
37573 #define ADD_LIMITED(s,v) \
37574- atomic_add((v),&stats->s); \
37575- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
37576+ atomic_add_unchecked((v),&stats->s); \
37577+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
37578
37579
37580 static void suni_hz(unsigned long from_timer)
37581diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
37582index 5120a96..e2572bd 100644
37583--- a/drivers/atm/uPD98402.c
37584+++ b/drivers/atm/uPD98402.c
37585@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
37586 struct sonet_stats tmp;
37587 int error = 0;
37588
37589- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37590+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37591 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
37592 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
37593 if (zero && !error) {
37594@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
37595
37596
37597 #define ADD_LIMITED(s,v) \
37598- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
37599- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
37600- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37601+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
37602+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
37603+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37604
37605
37606 static void stat_event(struct atm_dev *dev)
37607@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
37608 if (reason & uPD98402_INT_PFM) stat_event(dev);
37609 if (reason & uPD98402_INT_PCO) {
37610 (void) GET(PCOCR); /* clear interrupt cause */
37611- atomic_add(GET(HECCT),
37612+ atomic_add_unchecked(GET(HECCT),
37613 &PRIV(dev)->sonet_stats.uncorr_hcs);
37614 }
37615 if ((reason & uPD98402_INT_RFO) &&
37616@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
37617 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
37618 uPD98402_INT_LOS),PIMR); /* enable them */
37619 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
37620- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37621- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
37622- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
37623+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37624+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
37625+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
37626 return 0;
37627 }
37628
37629diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
37630index 969c3c2..9b72956 100644
37631--- a/drivers/atm/zatm.c
37632+++ b/drivers/atm/zatm.c
37633@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37634 }
37635 if (!size) {
37636 dev_kfree_skb_irq(skb);
37637- if (vcc) atomic_inc(&vcc->stats->rx_err);
37638+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
37639 continue;
37640 }
37641 if (!atm_charge(vcc,skb->truesize)) {
37642@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37643 skb->len = size;
37644 ATM_SKB(skb)->vcc = vcc;
37645 vcc->push(vcc,skb);
37646- atomic_inc(&vcc->stats->rx);
37647+ atomic_inc_unchecked(&vcc->stats->rx);
37648 }
37649 zout(pos & 0xffff,MTA(mbx));
37650 #if 0 /* probably a stupid idea */
37651@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
37652 skb_queue_head(&zatm_vcc->backlog,skb);
37653 break;
37654 }
37655- atomic_inc(&vcc->stats->tx);
37656+ atomic_inc_unchecked(&vcc->stats->tx);
37657 wake_up(&zatm_vcc->tx_wait);
37658 }
37659
37660diff --git a/drivers/base/bus.c b/drivers/base/bus.c
37661index 59dc808..f10c74e 100644
37662--- a/drivers/base/bus.c
37663+++ b/drivers/base/bus.c
37664@@ -1124,7 +1124,7 @@ int subsys_interface_register(struct subsys_interface *sif)
37665 return -EINVAL;
37666
37667 mutex_lock(&subsys->p->mutex);
37668- list_add_tail(&sif->node, &subsys->p->interfaces);
37669+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
37670 if (sif->add_dev) {
37671 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37672 while ((dev = subsys_dev_iter_next(&iter)))
37673@@ -1149,7 +1149,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
37674 subsys = sif->subsys;
37675
37676 mutex_lock(&subsys->p->mutex);
37677- list_del_init(&sif->node);
37678+ pax_list_del_init((struct list_head *)&sif->node);
37679 if (sif->remove_dev) {
37680 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37681 while ((dev = subsys_dev_iter_next(&iter)))
37682diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
37683index 25798db..15f130e 100644
37684--- a/drivers/base/devtmpfs.c
37685+++ b/drivers/base/devtmpfs.c
37686@@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
37687 if (!thread)
37688 return 0;
37689
37690- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
37691+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
37692 if (err)
37693 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
37694 else
37695@@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
37696 *err = sys_unshare(CLONE_NEWNS);
37697 if (*err)
37698 goto out;
37699- *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
37700+ *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
37701 if (*err)
37702 goto out;
37703- sys_chdir("/.."); /* will traverse into overmounted root */
37704- sys_chroot(".");
37705+ sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
37706+ sys_chroot((char __force_user *)".");
37707 complete(&setup_done);
37708 while (1) {
37709 spin_lock(&req_lock);
37710diff --git a/drivers/base/node.c b/drivers/base/node.c
37711index bc9f43b..29703b8 100644
37712--- a/drivers/base/node.c
37713+++ b/drivers/base/node.c
37714@@ -620,7 +620,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
37715 struct node_attr {
37716 struct device_attribute attr;
37717 enum node_states state;
37718-};
37719+} __do_const;
37720
37721 static ssize_t show_node_state(struct device *dev,
37722 struct device_attribute *attr, char *buf)
37723diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
37724index bfb8955..4ebff34 100644
37725--- a/drivers/base/power/domain.c
37726+++ b/drivers/base/power/domain.c
37727@@ -1809,9 +1809,9 @@ int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td)
37728
37729 if (dev->power.subsys_data->domain_data) {
37730 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
37731- gpd_data->ops = (struct gpd_dev_ops){ NULL };
37732+ memset(&gpd_data->ops, 0, sizeof(gpd_data->ops));
37733 if (clear_td)
37734- gpd_data->td = (struct gpd_timing_data){ 0 };
37735+ memset(&gpd_data->td, 0, sizeof(gpd_data->td));
37736
37737 if (--gpd_data->refcount == 0) {
37738 dev->power.subsys_data->domain_data = NULL;
37739@@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
37740 {
37741 struct cpuidle_driver *cpuidle_drv;
37742 struct gpd_cpu_data *cpu_data;
37743- struct cpuidle_state *idle_state;
37744+ cpuidle_state_no_const *idle_state;
37745 int ret = 0;
37746
37747 if (IS_ERR_OR_NULL(genpd) || state < 0)
37748@@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
37749 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
37750 {
37751 struct gpd_cpu_data *cpu_data;
37752- struct cpuidle_state *idle_state;
37753+ cpuidle_state_no_const *idle_state;
37754 int ret = 0;
37755
37756 if (IS_ERR_OR_NULL(genpd))
37757diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
37758index 03e089a..0e9560c 100644
37759--- a/drivers/base/power/sysfs.c
37760+++ b/drivers/base/power/sysfs.c
37761@@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
37762 return -EIO;
37763 }
37764 }
37765- return sprintf(buf, p);
37766+ return sprintf(buf, "%s", p);
37767 }
37768
37769 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
37770diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
37771index 2d56f41..8830f19 100644
37772--- a/drivers/base/power/wakeup.c
37773+++ b/drivers/base/power/wakeup.c
37774@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
37775 * They need to be modified together atomically, so it's better to use one
37776 * atomic variable to hold them both.
37777 */
37778-static atomic_t combined_event_count = ATOMIC_INIT(0);
37779+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
37780
37781 #define IN_PROGRESS_BITS (sizeof(int) * 4)
37782 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
37783
37784 static void split_counters(unsigned int *cnt, unsigned int *inpr)
37785 {
37786- unsigned int comb = atomic_read(&combined_event_count);
37787+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
37788
37789 *cnt = (comb >> IN_PROGRESS_BITS);
37790 *inpr = comb & MAX_IN_PROGRESS;
37791@@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
37792 ws->start_prevent_time = ws->last_time;
37793
37794 /* Increment the counter of events in progress. */
37795- cec = atomic_inc_return(&combined_event_count);
37796+ cec = atomic_inc_return_unchecked(&combined_event_count);
37797
37798 trace_wakeup_source_activate(ws->name, cec);
37799 }
37800@@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
37801 * Increment the counter of registered wakeup events and decrement the
37802 * couter of wakeup events in progress simultaneously.
37803 */
37804- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
37805+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
37806 trace_wakeup_source_deactivate(ws->name, cec);
37807
37808 split_counters(&cnt, &inpr);
37809diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
37810index e8d11b6..7b1b36f 100644
37811--- a/drivers/base/syscore.c
37812+++ b/drivers/base/syscore.c
37813@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
37814 void register_syscore_ops(struct syscore_ops *ops)
37815 {
37816 mutex_lock(&syscore_ops_lock);
37817- list_add_tail(&ops->node, &syscore_ops_list);
37818+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
37819 mutex_unlock(&syscore_ops_lock);
37820 }
37821 EXPORT_SYMBOL_GPL(register_syscore_ops);
37822@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
37823 void unregister_syscore_ops(struct syscore_ops *ops)
37824 {
37825 mutex_lock(&syscore_ops_lock);
37826- list_del(&ops->node);
37827+ pax_list_del((struct list_head *)&ops->node);
37828 mutex_unlock(&syscore_ops_lock);
37829 }
37830 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
37831diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
37832index 036e8ab..6221dec 100644
37833--- a/drivers/block/cciss.c
37834+++ b/drivers/block/cciss.c
37835@@ -3011,7 +3011,7 @@ static void start_io(ctlr_info_t *h)
37836 while (!list_empty(&h->reqQ)) {
37837 c = list_entry(h->reqQ.next, CommandList_struct, list);
37838 /* can't do anything if fifo is full */
37839- if ((h->access.fifo_full(h))) {
37840+ if ((h->access->fifo_full(h))) {
37841 dev_warn(&h->pdev->dev, "fifo full\n");
37842 break;
37843 }
37844@@ -3021,7 +3021,7 @@ static void start_io(ctlr_info_t *h)
37845 h->Qdepth--;
37846
37847 /* Tell the controller execute command */
37848- h->access.submit_command(h, c);
37849+ h->access->submit_command(h, c);
37850
37851 /* Put job onto the completed Q */
37852 addQ(&h->cmpQ, c);
37853@@ -3447,17 +3447,17 @@ startio:
37854
37855 static inline unsigned long get_next_completion(ctlr_info_t *h)
37856 {
37857- return h->access.command_completed(h);
37858+ return h->access->command_completed(h);
37859 }
37860
37861 static inline int interrupt_pending(ctlr_info_t *h)
37862 {
37863- return h->access.intr_pending(h);
37864+ return h->access->intr_pending(h);
37865 }
37866
37867 static inline long interrupt_not_for_us(ctlr_info_t *h)
37868 {
37869- return ((h->access.intr_pending(h) == 0) ||
37870+ return ((h->access->intr_pending(h) == 0) ||
37871 (h->interrupts_enabled == 0));
37872 }
37873
37874@@ -3490,7 +3490,7 @@ static inline u32 next_command(ctlr_info_t *h)
37875 u32 a;
37876
37877 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
37878- return h->access.command_completed(h);
37879+ return h->access->command_completed(h);
37880
37881 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
37882 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
37883@@ -4047,7 +4047,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
37884 trans_support & CFGTBL_Trans_use_short_tags);
37885
37886 /* Change the access methods to the performant access methods */
37887- h->access = SA5_performant_access;
37888+ h->access = &SA5_performant_access;
37889 h->transMethod = CFGTBL_Trans_Performant;
37890
37891 return;
37892@@ -4327,7 +4327,7 @@ static int cciss_pci_init(ctlr_info_t *h)
37893 if (prod_index < 0)
37894 return -ENODEV;
37895 h->product_name = products[prod_index].product_name;
37896- h->access = *(products[prod_index].access);
37897+ h->access = products[prod_index].access;
37898
37899 if (cciss_board_disabled(h)) {
37900 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
37901@@ -5059,7 +5059,7 @@ reinit_after_soft_reset:
37902 }
37903
37904 /* make sure the board interrupts are off */
37905- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37906+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37907 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
37908 if (rc)
37909 goto clean2;
37910@@ -5109,7 +5109,7 @@ reinit_after_soft_reset:
37911 * fake ones to scoop up any residual completions.
37912 */
37913 spin_lock_irqsave(&h->lock, flags);
37914- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37915+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37916 spin_unlock_irqrestore(&h->lock, flags);
37917 free_irq(h->intr[h->intr_mode], h);
37918 rc = cciss_request_irq(h, cciss_msix_discard_completions,
37919@@ -5129,9 +5129,9 @@ reinit_after_soft_reset:
37920 dev_info(&h->pdev->dev, "Board READY.\n");
37921 dev_info(&h->pdev->dev,
37922 "Waiting for stale completions to drain.\n");
37923- h->access.set_intr_mask(h, CCISS_INTR_ON);
37924+ h->access->set_intr_mask(h, CCISS_INTR_ON);
37925 msleep(10000);
37926- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37927+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37928
37929 rc = controller_reset_failed(h->cfgtable);
37930 if (rc)
37931@@ -5154,7 +5154,7 @@ reinit_after_soft_reset:
37932 cciss_scsi_setup(h);
37933
37934 /* Turn the interrupts on so we can service requests */
37935- h->access.set_intr_mask(h, CCISS_INTR_ON);
37936+ h->access->set_intr_mask(h, CCISS_INTR_ON);
37937
37938 /* Get the firmware version */
37939 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
37940@@ -5226,7 +5226,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
37941 kfree(flush_buf);
37942 if (return_code != IO_OK)
37943 dev_warn(&h->pdev->dev, "Error flushing cache\n");
37944- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37945+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37946 free_irq(h->intr[h->intr_mode], h);
37947 }
37948
37949diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
37950index 7fda30e..2f27946 100644
37951--- a/drivers/block/cciss.h
37952+++ b/drivers/block/cciss.h
37953@@ -101,7 +101,7 @@ struct ctlr_info
37954 /* information about each logical volume */
37955 drive_info_struct *drv[CISS_MAX_LUN];
37956
37957- struct access_method access;
37958+ struct access_method *access;
37959
37960 /* queue and queue Info */
37961 struct list_head reqQ;
37962@@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
37963 }
37964
37965 static struct access_method SA5_access = {
37966- SA5_submit_command,
37967- SA5_intr_mask,
37968- SA5_fifo_full,
37969- SA5_intr_pending,
37970- SA5_completed,
37971+ .submit_command = SA5_submit_command,
37972+ .set_intr_mask = SA5_intr_mask,
37973+ .fifo_full = SA5_fifo_full,
37974+ .intr_pending = SA5_intr_pending,
37975+ .command_completed = SA5_completed,
37976 };
37977
37978 static struct access_method SA5B_access = {
37979- SA5_submit_command,
37980- SA5B_intr_mask,
37981- SA5_fifo_full,
37982- SA5B_intr_pending,
37983- SA5_completed,
37984+ .submit_command = SA5_submit_command,
37985+ .set_intr_mask = SA5B_intr_mask,
37986+ .fifo_full = SA5_fifo_full,
37987+ .intr_pending = SA5B_intr_pending,
37988+ .command_completed = SA5_completed,
37989 };
37990
37991 static struct access_method SA5_performant_access = {
37992- SA5_submit_command,
37993- SA5_performant_intr_mask,
37994- SA5_fifo_full,
37995- SA5_performant_intr_pending,
37996- SA5_performant_completed,
37997+ .submit_command = SA5_submit_command,
37998+ .set_intr_mask = SA5_performant_intr_mask,
37999+ .fifo_full = SA5_fifo_full,
38000+ .intr_pending = SA5_performant_intr_pending,
38001+ .command_completed = SA5_performant_completed,
38002 };
38003
38004 struct board_type {
38005diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
38006index 2b94403..fd6ad1f 100644
38007--- a/drivers/block/cpqarray.c
38008+++ b/drivers/block/cpqarray.c
38009@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
38010 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
38011 goto Enomem4;
38012 }
38013- hba[i]->access.set_intr_mask(hba[i], 0);
38014+ hba[i]->access->set_intr_mask(hba[i], 0);
38015 if (request_irq(hba[i]->intr, do_ida_intr,
38016 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
38017 {
38018@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
38019 add_timer(&hba[i]->timer);
38020
38021 /* Enable IRQ now that spinlock and rate limit timer are set up */
38022- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
38023+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
38024
38025 for(j=0; j<NWD; j++) {
38026 struct gendisk *disk = ida_gendisk[i][j];
38027@@ -694,7 +694,7 @@ DBGINFO(
38028 for(i=0; i<NR_PRODUCTS; i++) {
38029 if (board_id == products[i].board_id) {
38030 c->product_name = products[i].product_name;
38031- c->access = *(products[i].access);
38032+ c->access = products[i].access;
38033 break;
38034 }
38035 }
38036@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
38037 hba[ctlr]->intr = intr;
38038 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
38039 hba[ctlr]->product_name = products[j].product_name;
38040- hba[ctlr]->access = *(products[j].access);
38041+ hba[ctlr]->access = products[j].access;
38042 hba[ctlr]->ctlr = ctlr;
38043 hba[ctlr]->board_id = board_id;
38044 hba[ctlr]->pci_dev = NULL; /* not PCI */
38045@@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
38046
38047 while((c = h->reqQ) != NULL) {
38048 /* Can't do anything if we're busy */
38049- if (h->access.fifo_full(h) == 0)
38050+ if (h->access->fifo_full(h) == 0)
38051 return;
38052
38053 /* Get the first entry from the request Q */
38054@@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
38055 h->Qdepth--;
38056
38057 /* Tell the controller to do our bidding */
38058- h->access.submit_command(h, c);
38059+ h->access->submit_command(h, c);
38060
38061 /* Get onto the completion Q */
38062 addQ(&h->cmpQ, c);
38063@@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
38064 unsigned long flags;
38065 __u32 a,a1;
38066
38067- istat = h->access.intr_pending(h);
38068+ istat = h->access->intr_pending(h);
38069 /* Is this interrupt for us? */
38070 if (istat == 0)
38071 return IRQ_NONE;
38072@@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
38073 */
38074 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
38075 if (istat & FIFO_NOT_EMPTY) {
38076- while((a = h->access.command_completed(h))) {
38077+ while((a = h->access->command_completed(h))) {
38078 a1 = a; a &= ~3;
38079 if ((c = h->cmpQ) == NULL)
38080 {
38081@@ -1448,11 +1448,11 @@ static int sendcmd(
38082 /*
38083 * Disable interrupt
38084 */
38085- info_p->access.set_intr_mask(info_p, 0);
38086+ info_p->access->set_intr_mask(info_p, 0);
38087 /* Make sure there is room in the command FIFO */
38088 /* Actually it should be completely empty at this time. */
38089 for (i = 200000; i > 0; i--) {
38090- temp = info_p->access.fifo_full(info_p);
38091+ temp = info_p->access->fifo_full(info_p);
38092 if (temp != 0) {
38093 break;
38094 }
38095@@ -1465,7 +1465,7 @@ DBG(
38096 /*
38097 * Send the cmd
38098 */
38099- info_p->access.submit_command(info_p, c);
38100+ info_p->access->submit_command(info_p, c);
38101 complete = pollcomplete(ctlr);
38102
38103 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
38104@@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
38105 * we check the new geometry. Then turn interrupts back on when
38106 * we're done.
38107 */
38108- host->access.set_intr_mask(host, 0);
38109+ host->access->set_intr_mask(host, 0);
38110 getgeometry(ctlr);
38111- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
38112+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
38113
38114 for(i=0; i<NWD; i++) {
38115 struct gendisk *disk = ida_gendisk[ctlr][i];
38116@@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
38117 /* Wait (up to 2 seconds) for a command to complete */
38118
38119 for (i = 200000; i > 0; i--) {
38120- done = hba[ctlr]->access.command_completed(hba[ctlr]);
38121+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
38122 if (done == 0) {
38123 udelay(10); /* a short fixed delay */
38124 } else
38125diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
38126index be73e9d..7fbf140 100644
38127--- a/drivers/block/cpqarray.h
38128+++ b/drivers/block/cpqarray.h
38129@@ -99,7 +99,7 @@ struct ctlr_info {
38130 drv_info_t drv[NWD];
38131 struct proc_dir_entry *proc;
38132
38133- struct access_method access;
38134+ struct access_method *access;
38135
38136 cmdlist_t *reqQ;
38137 cmdlist_t *cmpQ;
38138diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
38139index 0e06f0c..c47b81d 100644
38140--- a/drivers/block/drbd/drbd_int.h
38141+++ b/drivers/block/drbd/drbd_int.h
38142@@ -582,7 +582,7 @@ struct drbd_epoch {
38143 struct drbd_tconn *tconn;
38144 struct list_head list;
38145 unsigned int barrier_nr;
38146- atomic_t epoch_size; /* increased on every request added. */
38147+ atomic_unchecked_t epoch_size; /* increased on every request added. */
38148 atomic_t active; /* increased on every req. added, and dec on every finished. */
38149 unsigned long flags;
38150 };
38151@@ -1022,7 +1022,7 @@ struct drbd_conf {
38152 unsigned int al_tr_number;
38153 int al_tr_cycle;
38154 wait_queue_head_t seq_wait;
38155- atomic_t packet_seq;
38156+ atomic_unchecked_t packet_seq;
38157 unsigned int peer_seq;
38158 spinlock_t peer_seq_lock;
38159 unsigned int minor;
38160@@ -1573,7 +1573,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
38161 char __user *uoptval;
38162 int err;
38163
38164- uoptval = (char __user __force *)optval;
38165+ uoptval = (char __force_user *)optval;
38166
38167 set_fs(KERNEL_DS);
38168 if (level == SOL_SOCKET)
38169diff --git a/drivers/block/drbd/drbd_interval.c b/drivers/block/drbd/drbd_interval.c
38170index 89c497c..9c736ae 100644
38171--- a/drivers/block/drbd/drbd_interval.c
38172+++ b/drivers/block/drbd/drbd_interval.c
38173@@ -67,9 +67,9 @@ static void augment_rotate(struct rb_node *rb_old, struct rb_node *rb_new)
38174 }
38175
38176 static const struct rb_augment_callbacks augment_callbacks = {
38177- augment_propagate,
38178- augment_copy,
38179- augment_rotate,
38180+ .propagate = augment_propagate,
38181+ .copy = augment_copy,
38182+ .rotate = augment_rotate,
38183 };
38184
38185 /**
38186diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
38187index 929468e..7d934eb 100644
38188--- a/drivers/block/drbd/drbd_main.c
38189+++ b/drivers/block/drbd/drbd_main.c
38190@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
38191 p->sector = sector;
38192 p->block_id = block_id;
38193 p->blksize = blksize;
38194- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
38195+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
38196 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
38197 }
38198
38199@@ -1622,7 +1622,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
38200 return -EIO;
38201 p->sector = cpu_to_be64(req->i.sector);
38202 p->block_id = (unsigned long)req;
38203- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
38204+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
38205 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
38206 if (mdev->state.conn >= C_SYNC_SOURCE &&
38207 mdev->state.conn <= C_PAUSED_SYNC_T)
38208@@ -2577,8 +2577,8 @@ void conn_destroy(struct kref *kref)
38209 {
38210 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
38211
38212- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
38213- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
38214+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
38215+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
38216 kfree(tconn->current_epoch);
38217
38218 idr_destroy(&tconn->volumes);
38219diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
38220index c706d50..5e1b472 100644
38221--- a/drivers/block/drbd/drbd_nl.c
38222+++ b/drivers/block/drbd/drbd_nl.c
38223@@ -3440,7 +3440,7 @@ out:
38224
38225 void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
38226 {
38227- static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
38228+ static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
38229 struct sk_buff *msg;
38230 struct drbd_genlmsghdr *d_out;
38231 unsigned seq;
38232@@ -3453,7 +3453,7 @@ void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
38233 return;
38234 }
38235
38236- seq = atomic_inc_return(&drbd_genl_seq);
38237+ seq = atomic_inc_return_unchecked(&drbd_genl_seq);
38238 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
38239 if (!msg)
38240 goto failed;
38241diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
38242index d073305..4998fea 100644
38243--- a/drivers/block/drbd/drbd_receiver.c
38244+++ b/drivers/block/drbd/drbd_receiver.c
38245@@ -834,7 +834,7 @@ int drbd_connected(struct drbd_conf *mdev)
38246 {
38247 int err;
38248
38249- atomic_set(&mdev->packet_seq, 0);
38250+ atomic_set_unchecked(&mdev->packet_seq, 0);
38251 mdev->peer_seq = 0;
38252
38253 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
38254@@ -1193,7 +1193,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
38255 do {
38256 next_epoch = NULL;
38257
38258- epoch_size = atomic_read(&epoch->epoch_size);
38259+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
38260
38261 switch (ev & ~EV_CLEANUP) {
38262 case EV_PUT:
38263@@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
38264 rv = FE_DESTROYED;
38265 } else {
38266 epoch->flags = 0;
38267- atomic_set(&epoch->epoch_size, 0);
38268+ atomic_set_unchecked(&epoch->epoch_size, 0);
38269 /* atomic_set(&epoch->active, 0); is already zero */
38270 if (rv == FE_STILL_LIVE)
38271 rv = FE_RECYCLED;
38272@@ -1451,7 +1451,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
38273 conn_wait_active_ee_empty(tconn);
38274 drbd_flush(tconn);
38275
38276- if (atomic_read(&tconn->current_epoch->epoch_size)) {
38277+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
38278 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
38279 if (epoch)
38280 break;
38281@@ -1464,11 +1464,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
38282 }
38283
38284 epoch->flags = 0;
38285- atomic_set(&epoch->epoch_size, 0);
38286+ atomic_set_unchecked(&epoch->epoch_size, 0);
38287 atomic_set(&epoch->active, 0);
38288
38289 spin_lock(&tconn->epoch_lock);
38290- if (atomic_read(&tconn->current_epoch->epoch_size)) {
38291+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
38292 list_add(&epoch->list, &tconn->current_epoch->list);
38293 tconn->current_epoch = epoch;
38294 tconn->epochs++;
38295@@ -2164,7 +2164,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
38296
38297 err = wait_for_and_update_peer_seq(mdev, peer_seq);
38298 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
38299- atomic_inc(&tconn->current_epoch->epoch_size);
38300+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
38301 err2 = drbd_drain_block(mdev, pi->size);
38302 if (!err)
38303 err = err2;
38304@@ -2198,7 +2198,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
38305
38306 spin_lock(&tconn->epoch_lock);
38307 peer_req->epoch = tconn->current_epoch;
38308- atomic_inc(&peer_req->epoch->epoch_size);
38309+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
38310 atomic_inc(&peer_req->epoch->active);
38311 spin_unlock(&tconn->epoch_lock);
38312
38313@@ -4345,7 +4345,7 @@ struct data_cmd {
38314 int expect_payload;
38315 size_t pkt_size;
38316 int (*fn)(struct drbd_tconn *, struct packet_info *);
38317-};
38318+} __do_const;
38319
38320 static struct data_cmd drbd_cmd_handler[] = {
38321 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
38322@@ -4465,7 +4465,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
38323 if (!list_empty(&tconn->current_epoch->list))
38324 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
38325 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
38326- atomic_set(&tconn->current_epoch->epoch_size, 0);
38327+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
38328 tconn->send.seen_any_write_yet = false;
38329
38330 conn_info(tconn, "Connection closed\n");
38331@@ -5221,7 +5221,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
38332 struct asender_cmd {
38333 size_t pkt_size;
38334 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
38335-};
38336+} __do_const;
38337
38338 static struct asender_cmd asender_tbl[] = {
38339 [P_PING] = { 0, got_Ping },
38340diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
38341index 2023043..dab515c 100644
38342--- a/drivers/block/floppy.c
38343+++ b/drivers/block/floppy.c
38344@@ -3053,7 +3053,10 @@ static int raw_cmd_copyout(int cmd, void __user *param,
38345 int ret;
38346
38347 while (ptr) {
38348- ret = copy_to_user(param, ptr, sizeof(*ptr));
38349+ struct floppy_raw_cmd cmd = *ptr;
38350+ cmd.next = NULL;
38351+ cmd.kernel_data = NULL;
38352+ ret = copy_to_user(param, &cmd, sizeof(cmd));
38353 if (ret)
38354 return -EFAULT;
38355 param += sizeof(struct floppy_raw_cmd);
38356@@ -3107,10 +3110,11 @@ loop:
38357 return -ENOMEM;
38358 *rcmd = ptr;
38359 ret = copy_from_user(ptr, param, sizeof(*ptr));
38360- if (ret)
38361- return -EFAULT;
38362 ptr->next = NULL;
38363 ptr->buffer_length = 0;
38364+ ptr->kernel_data = NULL;
38365+ if (ret)
38366+ return -EFAULT;
38367 param += sizeof(struct floppy_raw_cmd);
38368 if (ptr->cmd_count > 33)
38369 /* the command may now also take up the space
38370@@ -3126,7 +3130,6 @@ loop:
38371 for (i = 0; i < 16; i++)
38372 ptr->reply[i] = 0;
38373 ptr->resultcode = 0;
38374- ptr->kernel_data = NULL;
38375
38376 if (ptr->flags & (FD_RAW_READ | FD_RAW_WRITE)) {
38377 if (ptr->length <= 0)
38378diff --git a/drivers/block/loop.c b/drivers/block/loop.c
38379index 66e8c3b..9b68dd9 100644
38380--- a/drivers/block/loop.c
38381+++ b/drivers/block/loop.c
38382@@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
38383
38384 file_start_write(file);
38385 set_fs(get_ds());
38386- bw = file->f_op->write(file, buf, len, &pos);
38387+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
38388 set_fs(old_fs);
38389 file_end_write(file);
38390 if (likely(bw == len))
38391diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c
38392index 091b9ea..f5428f8 100644
38393--- a/drivers/block/null_blk.c
38394+++ b/drivers/block/null_blk.c
38395@@ -382,15 +382,25 @@ static int null_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
38396 return 0;
38397 }
38398
38399-static struct blk_mq_ops null_mq_ops = {
38400- .queue_rq = null_queue_rq,
38401- .map_queue = blk_mq_map_queue,
38402+static struct blk_mq_ops null_mq_single_ops = {
38403+ .queue_rq = null_queue_rq,
38404+ .map_queue = blk_mq_map_queue,
38405 .init_hctx = null_init_hctx,
38406 .complete = null_softirq_done_fn,
38407+ .alloc_hctx = blk_mq_alloc_single_hw_queue,
38408+ .free_hctx = blk_mq_free_single_hw_queue,
38409+};
38410+
38411+static struct blk_mq_ops null_mq_per_node_ops = {
38412+ .queue_rq = null_queue_rq,
38413+ .map_queue = blk_mq_map_queue,
38414+ .init_hctx = null_init_hctx,
38415+ .alloc_hctx = null_alloc_hctx,
38416+ .free_hctx = null_free_hctx,
38417 };
38418
38419 static struct blk_mq_reg null_mq_reg = {
38420- .ops = &null_mq_ops,
38421+ .ops = &null_mq_single_ops,
38422 .queue_depth = 64,
38423 .cmd_size = sizeof(struct nullb_cmd),
38424 .flags = BLK_MQ_F_SHOULD_MERGE,
38425@@ -521,13 +531,8 @@ static int null_add_dev(void)
38426 null_mq_reg.queue_depth = hw_queue_depth;
38427 null_mq_reg.nr_hw_queues = submit_queues;
38428
38429- if (use_per_node_hctx) {
38430- null_mq_reg.ops->alloc_hctx = null_alloc_hctx;
38431- null_mq_reg.ops->free_hctx = null_free_hctx;
38432- } else {
38433- null_mq_reg.ops->alloc_hctx = blk_mq_alloc_single_hw_queue;
38434- null_mq_reg.ops->free_hctx = blk_mq_free_single_hw_queue;
38435- }
38436+ if (use_per_node_hctx)
38437+ null_mq_reg.ops = &null_mq_per_node_ops;
38438
38439 nullb->q = blk_mq_init_queue(&null_mq_reg, nullb);
38440 } else if (queue_mode == NULL_Q_BIO) {
38441diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
38442index a2af73d..c0b8f61 100644
38443--- a/drivers/block/pktcdvd.c
38444+++ b/drivers/block/pktcdvd.c
38445@@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
38446
38447 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
38448 {
38449- return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
38450+ return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
38451 }
38452
38453 /*
38454@@ -1888,7 +1888,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
38455 return -EROFS;
38456 }
38457 pd->settings.fp = ti.fp;
38458- pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
38459+ pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
38460
38461 if (ti.nwa_v) {
38462 pd->nwa = be32_to_cpu(ti.next_writable);
38463diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
38464index e5565fb..71be10b4 100644
38465--- a/drivers/block/smart1,2.h
38466+++ b/drivers/block/smart1,2.h
38467@@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
38468 }
38469
38470 static struct access_method smart4_access = {
38471- smart4_submit_command,
38472- smart4_intr_mask,
38473- smart4_fifo_full,
38474- smart4_intr_pending,
38475- smart4_completed,
38476+ .submit_command = smart4_submit_command,
38477+ .set_intr_mask = smart4_intr_mask,
38478+ .fifo_full = smart4_fifo_full,
38479+ .intr_pending = smart4_intr_pending,
38480+ .command_completed = smart4_completed,
38481 };
38482
38483 /*
38484@@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
38485 }
38486
38487 static struct access_method smart2_access = {
38488- smart2_submit_command,
38489- smart2_intr_mask,
38490- smart2_fifo_full,
38491- smart2_intr_pending,
38492- smart2_completed,
38493+ .submit_command = smart2_submit_command,
38494+ .set_intr_mask = smart2_intr_mask,
38495+ .fifo_full = smart2_fifo_full,
38496+ .intr_pending = smart2_intr_pending,
38497+ .command_completed = smart2_completed,
38498 };
38499
38500 /*
38501@@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
38502 }
38503
38504 static struct access_method smart2e_access = {
38505- smart2e_submit_command,
38506- smart2e_intr_mask,
38507- smart2e_fifo_full,
38508- smart2e_intr_pending,
38509- smart2e_completed,
38510+ .submit_command = smart2e_submit_command,
38511+ .set_intr_mask = smart2e_intr_mask,
38512+ .fifo_full = smart2e_fifo_full,
38513+ .intr_pending = smart2e_intr_pending,
38514+ .command_completed = smart2e_completed,
38515 };
38516
38517 /*
38518@@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
38519 }
38520
38521 static struct access_method smart1_access = {
38522- smart1_submit_command,
38523- smart1_intr_mask,
38524- smart1_fifo_full,
38525- smart1_intr_pending,
38526- smart1_completed,
38527+ .submit_command = smart1_submit_command,
38528+ .set_intr_mask = smart1_intr_mask,
38529+ .fifo_full = smart1_fifo_full,
38530+ .intr_pending = smart1_intr_pending,
38531+ .command_completed = smart1_completed,
38532 };
38533diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
38534index f038dba..bb74c08 100644
38535--- a/drivers/bluetooth/btwilink.c
38536+++ b/drivers/bluetooth/btwilink.c
38537@@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
38538
38539 static int bt_ti_probe(struct platform_device *pdev)
38540 {
38541- static struct ti_st *hst;
38542+ struct ti_st *hst;
38543 struct hci_dev *hdev;
38544 int err;
38545
38546diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
38547index 8a3aff7..d7538c2 100644
38548--- a/drivers/cdrom/cdrom.c
38549+++ b/drivers/cdrom/cdrom.c
38550@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
38551 ENSURE(reset, CDC_RESET);
38552 ENSURE(generic_packet, CDC_GENERIC_PACKET);
38553 cdi->mc_flags = 0;
38554- cdo->n_minors = 0;
38555 cdi->options = CDO_USE_FFLAGS;
38556
38557 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
38558@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
38559 else
38560 cdi->cdda_method = CDDA_OLD;
38561
38562- if (!cdo->generic_packet)
38563- cdo->generic_packet = cdrom_dummy_generic_packet;
38564+ if (!cdo->generic_packet) {
38565+ pax_open_kernel();
38566+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
38567+ pax_close_kernel();
38568+ }
38569
38570 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
38571 mutex_lock(&cdrom_mutex);
38572@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
38573 if (cdi->exit)
38574 cdi->exit(cdi);
38575
38576- cdi->ops->n_minors--;
38577 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
38578 }
38579
38580@@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
38581 */
38582 nr = nframes;
38583 do {
38584- cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38585+ cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38586 if (cgc.buffer)
38587 break;
38588
38589@@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
38590 struct cdrom_device_info *cdi;
38591 int ret;
38592
38593- ret = scnprintf(info + *pos, max_size - *pos, header);
38594+ ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
38595 if (!ret)
38596 return 1;
38597
38598diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
38599index 51e75ad..39c4c76 100644
38600--- a/drivers/cdrom/gdrom.c
38601+++ b/drivers/cdrom/gdrom.c
38602@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
38603 .audio_ioctl = gdrom_audio_ioctl,
38604 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
38605 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
38606- .n_minors = 1,
38607 };
38608
38609 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
38610diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
38611index 1386749..5430258 100644
38612--- a/drivers/char/Kconfig
38613+++ b/drivers/char/Kconfig
38614@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
38615
38616 config DEVKMEM
38617 bool "/dev/kmem virtual device support"
38618- default y
38619+ default n
38620+ depends on !GRKERNSEC_KMEM
38621 help
38622 Say Y here if you want to support the /dev/kmem device. The
38623 /dev/kmem device is rarely used, but can be used for certain
38624@@ -577,6 +578,7 @@ config DEVPORT
38625 bool
38626 depends on !M68K
38627 depends on ISA || PCI
38628+ depends on !GRKERNSEC_KMEM
38629 default y
38630
38631 source "drivers/s390/char/Kconfig"
38632diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
38633index a48e05b..6bac831 100644
38634--- a/drivers/char/agp/compat_ioctl.c
38635+++ b/drivers/char/agp/compat_ioctl.c
38636@@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
38637 return -ENOMEM;
38638 }
38639
38640- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
38641+ if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
38642 sizeof(*usegment) * ureserve.seg_count)) {
38643 kfree(usegment);
38644 kfree(ksegment);
38645diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
38646index 1b19239..963967b 100644
38647--- a/drivers/char/agp/frontend.c
38648+++ b/drivers/char/agp/frontend.c
38649@@ -731,6 +731,7 @@ static int agpioc_info_wrap(struct agp_file_private *priv, void __user *arg)
38650
38651 agp_copy_info(agp_bridge, &kerninfo);
38652
38653+ memset(&userinfo, 0, sizeof(userinfo));
38654 userinfo.version.major = kerninfo.version.major;
38655 userinfo.version.minor = kerninfo.version.minor;
38656 userinfo.bridge_id = kerninfo.device->vendor |
38657@@ -819,7 +820,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38658 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
38659 return -EFAULT;
38660
38661- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
38662+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
38663 return -EFAULT;
38664
38665 client = agp_find_client_by_pid(reserve.pid);
38666@@ -849,7 +850,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38667 if (segment == NULL)
38668 return -ENOMEM;
38669
38670- if (copy_from_user(segment, (void __user *) reserve.seg_list,
38671+ if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
38672 sizeof(struct agp_segment) * reserve.seg_count)) {
38673 kfree(segment);
38674 return -EFAULT;
38675diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
38676index 4f94375..413694e 100644
38677--- a/drivers/char/genrtc.c
38678+++ b/drivers/char/genrtc.c
38679@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
38680 switch (cmd) {
38681
38682 case RTC_PLL_GET:
38683+ memset(&pll, 0, sizeof(pll));
38684 if (get_rtc_pll(&pll))
38685 return -EINVAL;
38686 else
38687diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
38688index d5d4cd8..22d561d 100644
38689--- a/drivers/char/hpet.c
38690+++ b/drivers/char/hpet.c
38691@@ -575,7 +575,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
38692 }
38693
38694 static int
38695-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
38696+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
38697 struct hpet_info *info)
38698 {
38699 struct hpet_timer __iomem *timer;
38700diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
38701index 86fe45c..c0ea948 100644
38702--- a/drivers/char/hw_random/intel-rng.c
38703+++ b/drivers/char/hw_random/intel-rng.c
38704@@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
38705
38706 if (no_fwh_detect)
38707 return -ENODEV;
38708- printk(warning);
38709+ printk("%s", warning);
38710 return -EBUSY;
38711 }
38712
38713diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
38714index ec4e10f..f2a763b 100644
38715--- a/drivers/char/ipmi/ipmi_msghandler.c
38716+++ b/drivers/char/ipmi/ipmi_msghandler.c
38717@@ -420,7 +420,7 @@ struct ipmi_smi {
38718 struct proc_dir_entry *proc_dir;
38719 char proc_dir_name[10];
38720
38721- atomic_t stats[IPMI_NUM_STATS];
38722+ atomic_unchecked_t stats[IPMI_NUM_STATS];
38723
38724 /*
38725 * run_to_completion duplicate of smb_info, smi_info
38726@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
38727
38728
38729 #define ipmi_inc_stat(intf, stat) \
38730- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
38731+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
38732 #define ipmi_get_stat(intf, stat) \
38733- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
38734+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
38735
38736 static int is_lan_addr(struct ipmi_addr *addr)
38737 {
38738@@ -2883,7 +2883,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
38739 INIT_LIST_HEAD(&intf->cmd_rcvrs);
38740 init_waitqueue_head(&intf->waitq);
38741 for (i = 0; i < IPMI_NUM_STATS; i++)
38742- atomic_set(&intf->stats[i], 0);
38743+ atomic_set_unchecked(&intf->stats[i], 0);
38744
38745 intf->proc_dir = NULL;
38746
38747diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
38748index 03f4189..e79f5e0 100644
38749--- a/drivers/char/ipmi/ipmi_si_intf.c
38750+++ b/drivers/char/ipmi/ipmi_si_intf.c
38751@@ -280,7 +280,7 @@ struct smi_info {
38752 unsigned char slave_addr;
38753
38754 /* Counters and things for the proc filesystem. */
38755- atomic_t stats[SI_NUM_STATS];
38756+ atomic_unchecked_t stats[SI_NUM_STATS];
38757
38758 struct task_struct *thread;
38759
38760@@ -289,9 +289,9 @@ struct smi_info {
38761 };
38762
38763 #define smi_inc_stat(smi, stat) \
38764- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
38765+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
38766 #define smi_get_stat(smi, stat) \
38767- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
38768+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
38769
38770 #define SI_MAX_PARMS 4
38771
38772@@ -3339,7 +3339,7 @@ static int try_smi_init(struct smi_info *new_smi)
38773 atomic_set(&new_smi->req_events, 0);
38774 new_smi->run_to_completion = 0;
38775 for (i = 0; i < SI_NUM_STATS; i++)
38776- atomic_set(&new_smi->stats[i], 0);
38777+ atomic_set_unchecked(&new_smi->stats[i], 0);
38778
38779 new_smi->interrupt_disabled = 1;
38780 atomic_set(&new_smi->stop_operation, 0);
38781diff --git a/drivers/char/mem.c b/drivers/char/mem.c
38782index 92c5937..1be4e4d 100644
38783--- a/drivers/char/mem.c
38784+++ b/drivers/char/mem.c
38785@@ -18,6 +18,7 @@
38786 #include <linux/raw.h>
38787 #include <linux/tty.h>
38788 #include <linux/capability.h>
38789+#include <linux/security.h>
38790 #include <linux/ptrace.h>
38791 #include <linux/device.h>
38792 #include <linux/highmem.h>
38793@@ -36,6 +37,10 @@
38794
38795 #define DEVPORT_MINOR 4
38796
38797+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38798+extern const struct file_operations grsec_fops;
38799+#endif
38800+
38801 static inline unsigned long size_inside_page(unsigned long start,
38802 unsigned long size)
38803 {
38804@@ -67,9 +72,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38805
38806 while (cursor < to) {
38807 if (!devmem_is_allowed(pfn)) {
38808+#ifdef CONFIG_GRKERNSEC_KMEM
38809+ gr_handle_mem_readwrite(from, to);
38810+#else
38811 printk(KERN_INFO
38812 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
38813 current->comm, from, to);
38814+#endif
38815 return 0;
38816 }
38817 cursor += PAGE_SIZE;
38818@@ -77,6 +86,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38819 }
38820 return 1;
38821 }
38822+#elif defined(CONFIG_GRKERNSEC_KMEM)
38823+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38824+{
38825+ return 0;
38826+}
38827 #else
38828 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38829 {
38830@@ -119,6 +133,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38831
38832 while (count > 0) {
38833 unsigned long remaining;
38834+ char *temp;
38835
38836 sz = size_inside_page(p, count);
38837
38838@@ -134,7 +149,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38839 if (!ptr)
38840 return -EFAULT;
38841
38842- remaining = copy_to_user(buf, ptr, sz);
38843+#ifdef CONFIG_PAX_USERCOPY
38844+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38845+ if (!temp) {
38846+ unxlate_dev_mem_ptr(p, ptr);
38847+ return -ENOMEM;
38848+ }
38849+ memcpy(temp, ptr, sz);
38850+#else
38851+ temp = ptr;
38852+#endif
38853+
38854+ remaining = copy_to_user(buf, temp, sz);
38855+
38856+#ifdef CONFIG_PAX_USERCOPY
38857+ kfree(temp);
38858+#endif
38859+
38860 unxlate_dev_mem_ptr(p, ptr);
38861 if (remaining)
38862 return -EFAULT;
38863@@ -363,9 +394,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38864 size_t count, loff_t *ppos)
38865 {
38866 unsigned long p = *ppos;
38867- ssize_t low_count, read, sz;
38868+ ssize_t low_count, read, sz, err = 0;
38869 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
38870- int err = 0;
38871
38872 read = 0;
38873 if (p < (unsigned long) high_memory) {
38874@@ -387,6 +417,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38875 }
38876 #endif
38877 while (low_count > 0) {
38878+ char *temp;
38879+
38880 sz = size_inside_page(p, low_count);
38881
38882 /*
38883@@ -396,7 +428,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38884 */
38885 kbuf = xlate_dev_kmem_ptr((char *)p);
38886
38887- if (copy_to_user(buf, kbuf, sz))
38888+#ifdef CONFIG_PAX_USERCOPY
38889+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38890+ if (!temp)
38891+ return -ENOMEM;
38892+ memcpy(temp, kbuf, sz);
38893+#else
38894+ temp = kbuf;
38895+#endif
38896+
38897+ err = copy_to_user(buf, temp, sz);
38898+
38899+#ifdef CONFIG_PAX_USERCOPY
38900+ kfree(temp);
38901+#endif
38902+
38903+ if (err)
38904 return -EFAULT;
38905 buf += sz;
38906 p += sz;
38907@@ -821,6 +868,9 @@ static const struct memdev {
38908 #ifdef CONFIG_PRINTK
38909 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
38910 #endif
38911+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38912+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
38913+#endif
38914 };
38915
38916 static int memory_open(struct inode *inode, struct file *filp)
38917@@ -892,7 +942,7 @@ static int __init chr_dev_init(void)
38918 continue;
38919
38920 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
38921- NULL, devlist[minor].name);
38922+ NULL, "%s", devlist[minor].name);
38923 }
38924
38925 return tty_init();
38926diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
38927index 9df78e2..01ba9ae 100644
38928--- a/drivers/char/nvram.c
38929+++ b/drivers/char/nvram.c
38930@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
38931
38932 spin_unlock_irq(&rtc_lock);
38933
38934- if (copy_to_user(buf, contents, tmp - contents))
38935+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
38936 return -EFAULT;
38937
38938 *ppos = i;
38939diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
38940index 8320abd..ec48108 100644
38941--- a/drivers/char/pcmcia/synclink_cs.c
38942+++ b/drivers/char/pcmcia/synclink_cs.c
38943@@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38944
38945 if (debug_level >= DEBUG_LEVEL_INFO)
38946 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
38947- __FILE__, __LINE__, info->device_name, port->count);
38948+ __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
38949
38950- WARN_ON(!port->count);
38951+ WARN_ON(!atomic_read(&port->count));
38952
38953 if (tty_port_close_start(port, tty, filp) == 0)
38954 goto cleanup;
38955@@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38956 cleanup:
38957 if (debug_level >= DEBUG_LEVEL_INFO)
38958 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
38959- tty->driver->name, port->count);
38960+ tty->driver->name, atomic_read(&port->count));
38961 }
38962
38963 /* Wait until the transmitter is empty.
38964@@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38965
38966 if (debug_level >= DEBUG_LEVEL_INFO)
38967 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
38968- __FILE__, __LINE__, tty->driver->name, port->count);
38969+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
38970
38971 /* If port is closing, signal caller to try again */
38972 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
38973@@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38974 goto cleanup;
38975 }
38976 spin_lock(&port->lock);
38977- port->count++;
38978+ atomic_inc(&port->count);
38979 spin_unlock(&port->lock);
38980 spin_unlock_irqrestore(&info->netlock, flags);
38981
38982- if (port->count == 1) {
38983+ if (atomic_read(&port->count) == 1) {
38984 /* 1st open on this device, init hardware */
38985 retval = startup(info, tty);
38986 if (retval < 0)
38987@@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38988 unsigned short new_crctype;
38989
38990 /* return error if TTY interface open */
38991- if (info->port.count)
38992+ if (atomic_read(&info->port.count))
38993 return -EBUSY;
38994
38995 switch (encoding)
38996@@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
38997
38998 /* arbitrate between network and tty opens */
38999 spin_lock_irqsave(&info->netlock, flags);
39000- if (info->port.count != 0 || info->netcount != 0) {
39001+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
39002 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
39003 spin_unlock_irqrestore(&info->netlock, flags);
39004 return -EBUSY;
39005@@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39006 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
39007
39008 /* return error if TTY interface open */
39009- if (info->port.count)
39010+ if (atomic_read(&info->port.count))
39011 return -EBUSY;
39012
39013 if (cmd != SIOCWANDEV)
39014diff --git a/drivers/char/random.c b/drivers/char/random.c
39015index 429b75b..a7f4145 100644
39016--- a/drivers/char/random.c
39017+++ b/drivers/char/random.c
39018@@ -270,10 +270,17 @@
39019 /*
39020 * Configuration information
39021 */
39022+#ifdef CONFIG_GRKERNSEC_RANDNET
39023+#define INPUT_POOL_SHIFT 14
39024+#define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
39025+#define OUTPUT_POOL_SHIFT 12
39026+#define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
39027+#else
39028 #define INPUT_POOL_SHIFT 12
39029 #define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
39030 #define OUTPUT_POOL_SHIFT 10
39031 #define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
39032+#endif
39033 #define SEC_XFER_SIZE 512
39034 #define EXTRACT_SIZE 10
39035
39036@@ -284,9 +291,6 @@
39037 /*
39038 * To allow fractional bits to be tracked, the entropy_count field is
39039 * denominated in units of 1/8th bits.
39040- *
39041- * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
39042- * credit_entropy_bits() needs to be 64 bits wide.
39043 */
39044 #define ENTROPY_SHIFT 3
39045 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
39046@@ -361,12 +365,19 @@ static struct poolinfo {
39047 #define S(x) ilog2(x)+5, (x), (x)*4, (x)*32, (x) << (ENTROPY_SHIFT+5)
39048 int tap1, tap2, tap3, tap4, tap5;
39049 } poolinfo_table[] = {
39050+#ifdef CONFIG_GRKERNSEC_RANDNET
39051+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
39052+ { S(512), 411, 308, 208, 104, 1 },
39053+ /* x^128 + x^104 + x^76 + x^51 + x^25 + x + 1 -- 105 */
39054+ { S(128), 104, 76, 51, 25, 1 },
39055+#else
39056 /* was: x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 */
39057 /* x^128 + x^104 + x^76 + x^51 +x^25 + x + 1 */
39058 { S(128), 104, 76, 51, 25, 1 },
39059 /* was: x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 */
39060 /* x^32 + x^26 + x^19 + x^14 + x^7 + x + 1 */
39061 { S(32), 26, 19, 14, 7, 1 },
39062+#endif
39063 #if 0
39064 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
39065 { S(2048), 1638, 1231, 819, 411, 1 },
39066@@ -433,9 +444,9 @@ struct entropy_store {
39067 };
39068
39069 static void push_to_pool(struct work_struct *work);
39070-static __u32 input_pool_data[INPUT_POOL_WORDS];
39071-static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
39072-static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
39073+static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
39074+static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
39075+static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
39076
39077 static struct entropy_store input_pool = {
39078 .poolinfo = &poolinfo_table[0],
39079@@ -524,8 +535,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
39080 input_rotate = (input_rotate + (i ? 7 : 14)) & 31;
39081 }
39082
39083- ACCESS_ONCE(r->input_rotate) = input_rotate;
39084- ACCESS_ONCE(r->add_ptr) = i;
39085+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
39086+ ACCESS_ONCE_RW(r->add_ptr) = i;
39087 smp_wmb();
39088
39089 if (out)
39090@@ -632,7 +643,7 @@ retry:
39091 /* The +2 corresponds to the /4 in the denominator */
39092
39093 do {
39094- unsigned int anfrac = min(pnfrac, pool_size/2);
39095+ u64 anfrac = min(pnfrac, pool_size/2);
39096 unsigned int add =
39097 ((pool_size - entropy_count)*anfrac*3) >> s;
39098
39099@@ -1151,7 +1162,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
39100
39101 extract_buf(r, tmp);
39102 i = min_t(int, nbytes, EXTRACT_SIZE);
39103- if (copy_to_user(buf, tmp, i)) {
39104+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
39105 ret = -EFAULT;
39106 break;
39107 }
39108@@ -1507,7 +1518,7 @@ EXPORT_SYMBOL(generate_random_uuid);
39109 #include <linux/sysctl.h>
39110
39111 static int min_read_thresh = 8, min_write_thresh;
39112-static int max_read_thresh = INPUT_POOL_WORDS * 32;
39113+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
39114 static int max_write_thresh = INPUT_POOL_WORDS * 32;
39115 static char sysctl_bootid[16];
39116
39117@@ -1523,7 +1534,7 @@ static char sysctl_bootid[16];
39118 static int proc_do_uuid(struct ctl_table *table, int write,
39119 void __user *buffer, size_t *lenp, loff_t *ppos)
39120 {
39121- struct ctl_table fake_table;
39122+ ctl_table_no_const fake_table;
39123 unsigned char buf[64], tmp_uuid[16], *uuid;
39124
39125 uuid = table->data;
39126@@ -1553,7 +1564,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
39127 static int proc_do_entropy(ctl_table *table, int write,
39128 void __user *buffer, size_t *lenp, loff_t *ppos)
39129 {
39130- ctl_table fake_table;
39131+ ctl_table_no_const fake_table;
39132 int entropy_count;
39133
39134 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
39135diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
39136index 7cc1fe22..b602d6b 100644
39137--- a/drivers/char/sonypi.c
39138+++ b/drivers/char/sonypi.c
39139@@ -54,6 +54,7 @@
39140
39141 #include <asm/uaccess.h>
39142 #include <asm/io.h>
39143+#include <asm/local.h>
39144
39145 #include <linux/sonypi.h>
39146
39147@@ -490,7 +491,7 @@ static struct sonypi_device {
39148 spinlock_t fifo_lock;
39149 wait_queue_head_t fifo_proc_list;
39150 struct fasync_struct *fifo_async;
39151- int open_count;
39152+ local_t open_count;
39153 int model;
39154 struct input_dev *input_jog_dev;
39155 struct input_dev *input_key_dev;
39156@@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
39157 static int sonypi_misc_release(struct inode *inode, struct file *file)
39158 {
39159 mutex_lock(&sonypi_device.lock);
39160- sonypi_device.open_count--;
39161+ local_dec(&sonypi_device.open_count);
39162 mutex_unlock(&sonypi_device.lock);
39163 return 0;
39164 }
39165@@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
39166 {
39167 mutex_lock(&sonypi_device.lock);
39168 /* Flush input queue on first open */
39169- if (!sonypi_device.open_count)
39170+ if (!local_read(&sonypi_device.open_count))
39171 kfifo_reset(&sonypi_device.fifo);
39172- sonypi_device.open_count++;
39173+ local_inc(&sonypi_device.open_count);
39174 mutex_unlock(&sonypi_device.lock);
39175
39176 return 0;
39177diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
39178index b9a57fa..5bb9e38 100644
39179--- a/drivers/char/tpm/tpm_acpi.c
39180+++ b/drivers/char/tpm/tpm_acpi.c
39181@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
39182 virt = acpi_os_map_memory(start, len);
39183 if (!virt) {
39184 kfree(log->bios_event_log);
39185+ log->bios_event_log = NULL;
39186 printk("%s: ERROR - Unable to map memory\n", __func__);
39187 return -EIO;
39188 }
39189
39190- memcpy_fromio(log->bios_event_log, virt, len);
39191+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
39192
39193 acpi_os_unmap_memory(virt, len);
39194 return 0;
39195diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
39196index 59f7cb2..bac8b6d 100644
39197--- a/drivers/char/tpm/tpm_eventlog.c
39198+++ b/drivers/char/tpm/tpm_eventlog.c
39199@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
39200 event = addr;
39201
39202 if ((event->event_type == 0 && event->event_size == 0) ||
39203- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
39204+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
39205 return NULL;
39206
39207 return addr;
39208@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
39209 return NULL;
39210
39211 if ((event->event_type == 0 && event->event_size == 0) ||
39212- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
39213+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
39214 return NULL;
39215
39216 (*pos)++;
39217@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
39218 int i;
39219
39220 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
39221- seq_putc(m, data[i]);
39222+ if (!seq_putc(m, data[i]))
39223+ return -EFAULT;
39224
39225 return 0;
39226 }
39227diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
39228index 6928d09..ff6abe8 100644
39229--- a/drivers/char/virtio_console.c
39230+++ b/drivers/char/virtio_console.c
39231@@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
39232 if (to_user) {
39233 ssize_t ret;
39234
39235- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
39236+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
39237 if (ret)
39238 return -EFAULT;
39239 } else {
39240@@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
39241 if (!port_has_data(port) && !port->host_connected)
39242 return 0;
39243
39244- return fill_readbuf(port, ubuf, count, true);
39245+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
39246 }
39247
39248 static int wait_port_writable(struct port *port, bool nonblock)
39249diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
39250index 57a078e..c17cde8 100644
39251--- a/drivers/clk/clk-composite.c
39252+++ b/drivers/clk/clk-composite.c
39253@@ -146,7 +146,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
39254 struct clk *clk;
39255 struct clk_init_data init;
39256 struct clk_composite *composite;
39257- struct clk_ops *clk_composite_ops;
39258+ clk_ops_no_const *clk_composite_ops;
39259
39260 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
39261 if (!composite) {
39262diff --git a/drivers/clk/socfpga/clk.c b/drivers/clk/socfpga/clk.c
39263index 5983a26..65d5f46 100644
39264--- a/drivers/clk/socfpga/clk.c
39265+++ b/drivers/clk/socfpga/clk.c
39266@@ -22,6 +22,7 @@
39267 #include <linux/clk-provider.h>
39268 #include <linux/io.h>
39269 #include <linux/of.h>
39270+#include <asm/pgtable.h>
39271
39272 /* Clock Manager offsets */
39273 #define CLKMGR_CTRL 0x0
39274@@ -150,8 +151,10 @@ static __init struct clk *socfpga_clk_init(struct device_node *node,
39275 streq(clk_name, "periph_pll") ||
39276 streq(clk_name, "sdram_pll")) {
39277 socfpga_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
39278- clk_pll_ops.enable = clk_gate_ops.enable;
39279- clk_pll_ops.disable = clk_gate_ops.disable;
39280+ pax_open_kernel();
39281+ *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
39282+ *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
39283+ pax_close_kernel();
39284 }
39285
39286 clk = clk_register(NULL, &socfpga_clk->hw.hw);
39287@@ -242,7 +245,7 @@ static unsigned long socfpga_clk_recalc_rate(struct clk_hw *hwclk,
39288 return parent_rate / div;
39289 }
39290
39291-static struct clk_ops gateclk_ops = {
39292+static clk_ops_no_const gateclk_ops __read_only = {
39293 .recalc_rate = socfpga_clk_recalc_rate,
39294 .get_parent = socfpga_clk_get_parent,
39295 .set_parent = socfpga_clk_set_parent,
39296diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
39297index 18448a7..d5fad43 100644
39298--- a/drivers/cpufreq/acpi-cpufreq.c
39299+++ b/drivers/cpufreq/acpi-cpufreq.c
39300@@ -676,8 +676,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
39301 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
39302 per_cpu(acfreq_data, cpu) = data;
39303
39304- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
39305- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
39306+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
39307+ pax_open_kernel();
39308+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
39309+ pax_close_kernel();
39310+ }
39311
39312 result = acpi_processor_register_performance(data->acpi_data, cpu);
39313 if (result)
39314@@ -810,7 +813,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
39315 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
39316 break;
39317 case ACPI_ADR_SPACE_FIXED_HARDWARE:
39318- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
39319+ pax_open_kernel();
39320+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
39321+ pax_close_kernel();
39322 break;
39323 default:
39324 break;
39325@@ -905,8 +910,10 @@ static void __init acpi_cpufreq_boost_init(void)
39326 if (!msrs)
39327 return;
39328
39329- acpi_cpufreq_driver.boost_supported = true;
39330- acpi_cpufreq_driver.boost_enabled = boost_state(0);
39331+ pax_open_kernel();
39332+ *(bool *)&acpi_cpufreq_driver.boost_supported = true;
39333+ *(bool *)&acpi_cpufreq_driver.boost_enabled = boost_state(0);
39334+ pax_close_kernel();
39335 get_online_cpus();
39336
39337 /* Force all MSRs to the same value */
39338diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
39339index 199b52b..e3503bb 100644
39340--- a/drivers/cpufreq/cpufreq.c
39341+++ b/drivers/cpufreq/cpufreq.c
39342@@ -1970,7 +1970,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
39343 #endif
39344
39345 mutex_lock(&cpufreq_governor_mutex);
39346- list_del(&governor->governor_list);
39347+ pax_list_del(&governor->governor_list);
39348 mutex_unlock(&cpufreq_governor_mutex);
39349 return;
39350 }
39351@@ -2200,7 +2200,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
39352 return NOTIFY_OK;
39353 }
39354
39355-static struct notifier_block __refdata cpufreq_cpu_notifier = {
39356+static struct notifier_block cpufreq_cpu_notifier = {
39357 .notifier_call = cpufreq_cpu_callback,
39358 };
39359
39360@@ -2240,13 +2240,17 @@ int cpufreq_boost_trigger_state(int state)
39361 return 0;
39362
39363 write_lock_irqsave(&cpufreq_driver_lock, flags);
39364- cpufreq_driver->boost_enabled = state;
39365+ pax_open_kernel();
39366+ *(bool *)&cpufreq_driver->boost_enabled = state;
39367+ pax_close_kernel();
39368 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39369
39370 ret = cpufreq_driver->set_boost(state);
39371 if (ret) {
39372 write_lock_irqsave(&cpufreq_driver_lock, flags);
39373- cpufreq_driver->boost_enabled = !state;
39374+ pax_open_kernel();
39375+ *(bool *)&cpufreq_driver->boost_enabled = !state;
39376+ pax_close_kernel();
39377 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39378
39379 pr_err("%s: Cannot %s BOOST\n", __func__,
39380@@ -2300,8 +2304,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39381
39382 pr_debug("trying to register driver %s\n", driver_data->name);
39383
39384- if (driver_data->setpolicy)
39385- driver_data->flags |= CPUFREQ_CONST_LOOPS;
39386+ if (driver_data->setpolicy) {
39387+ pax_open_kernel();
39388+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
39389+ pax_close_kernel();
39390+ }
39391
39392 write_lock_irqsave(&cpufreq_driver_lock, flags);
39393 if (cpufreq_driver) {
39394@@ -2316,8 +2323,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39395 * Check if driver provides function to enable boost -
39396 * if not, use cpufreq_boost_set_sw as default
39397 */
39398- if (!cpufreq_driver->set_boost)
39399- cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39400+ if (!cpufreq_driver->set_boost) {
39401+ pax_open_kernel();
39402+ *(void **)&cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39403+ pax_close_kernel();
39404+ }
39405
39406 ret = cpufreq_sysfs_create_file(&boost.attr);
39407 if (ret) {
39408diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
39409index ba43991..23858ffb 100644
39410--- a/drivers/cpufreq/cpufreq_governor.c
39411+++ b/drivers/cpufreq/cpufreq_governor.c
39412@@ -191,7 +191,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39413 struct dbs_data *dbs_data;
39414 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
39415 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
39416- struct od_ops *od_ops = NULL;
39417+ const struct od_ops *od_ops = NULL;
39418 struct od_dbs_tuners *od_tuners = NULL;
39419 struct cs_dbs_tuners *cs_tuners = NULL;
39420 struct cpu_dbs_common_info *cpu_cdbs;
39421@@ -257,7 +257,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39422
39423 if ((cdata->governor == GOV_CONSERVATIVE) &&
39424 (!policy->governor->initialized)) {
39425- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39426+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39427
39428 cpufreq_register_notifier(cs_ops->notifier_block,
39429 CPUFREQ_TRANSITION_NOTIFIER);
39430@@ -277,7 +277,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39431
39432 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
39433 (policy->governor->initialized == 1)) {
39434- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39435+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39436
39437 cpufreq_unregister_notifier(cs_ops->notifier_block,
39438 CPUFREQ_TRANSITION_NOTIFIER);
39439diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
39440index bfb9ae1..e1d3a7e 100644
39441--- a/drivers/cpufreq/cpufreq_governor.h
39442+++ b/drivers/cpufreq/cpufreq_governor.h
39443@@ -205,7 +205,7 @@ struct common_dbs_data {
39444 void (*exit)(struct dbs_data *dbs_data);
39445
39446 /* Governor specific ops, see below */
39447- void *gov_ops;
39448+ const void *gov_ops;
39449 };
39450
39451 /* Governor Per policy data */
39452@@ -225,7 +225,7 @@ struct od_ops {
39453 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
39454 unsigned int freq_next, unsigned int relation);
39455 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
39456-};
39457+} __no_const;
39458
39459 struct cs_ops {
39460 struct notifier_block *notifier_block;
39461diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
39462index 18d4091..434be15 100644
39463--- a/drivers/cpufreq/cpufreq_ondemand.c
39464+++ b/drivers/cpufreq/cpufreq_ondemand.c
39465@@ -521,7 +521,7 @@ static void od_exit(struct dbs_data *dbs_data)
39466
39467 define_get_cpu_dbs_routines(od_cpu_dbs_info);
39468
39469-static struct od_ops od_ops = {
39470+static struct od_ops od_ops __read_only = {
39471 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
39472 .powersave_bias_target = generic_powersave_bias_target,
39473 .freq_increase = dbs_freq_increase,
39474@@ -576,14 +576,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
39475 (struct cpufreq_policy *, unsigned int, unsigned int),
39476 unsigned int powersave_bias)
39477 {
39478- od_ops.powersave_bias_target = f;
39479+ pax_open_kernel();
39480+ *(void **)&od_ops.powersave_bias_target = f;
39481+ pax_close_kernel();
39482 od_set_powersave_bias(powersave_bias);
39483 }
39484 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
39485
39486 void od_unregister_powersave_bias_handler(void)
39487 {
39488- od_ops.powersave_bias_target = generic_powersave_bias_target;
39489+ pax_open_kernel();
39490+ *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
39491+ pax_close_kernel();
39492 od_set_powersave_bias(0);
39493 }
39494 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
39495diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
39496index 2cd36b9..8f07fae 100644
39497--- a/drivers/cpufreq/intel_pstate.c
39498+++ b/drivers/cpufreq/intel_pstate.c
39499@@ -124,10 +124,10 @@ struct pstate_funcs {
39500 struct cpu_defaults {
39501 struct pstate_adjust_policy pid_policy;
39502 struct pstate_funcs funcs;
39503-};
39504+} __do_const;
39505
39506 static struct pstate_adjust_policy pid_params;
39507-static struct pstate_funcs pstate_funcs;
39508+static struct pstate_funcs *pstate_funcs;
39509
39510 struct perf_limits {
39511 int no_turbo;
39512@@ -518,7 +518,7 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
39513
39514 cpu->pstate.current_pstate = pstate;
39515
39516- pstate_funcs.set(cpu, pstate);
39517+ pstate_funcs->set(cpu, pstate);
39518 }
39519
39520 static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps)
39521@@ -540,12 +540,12 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
39522 {
39523 sprintf(cpu->name, "Intel 2nd generation core");
39524
39525- cpu->pstate.min_pstate = pstate_funcs.get_min();
39526- cpu->pstate.max_pstate = pstate_funcs.get_max();
39527- cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
39528+ cpu->pstate.min_pstate = pstate_funcs->get_min();
39529+ cpu->pstate.max_pstate = pstate_funcs->get_max();
39530+ cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
39531
39532- if (pstate_funcs.get_vid)
39533- pstate_funcs.get_vid(cpu);
39534+ if (pstate_funcs->get_vid)
39535+ pstate_funcs->get_vid(cpu);
39536
39537 /*
39538 * goto max pstate so we don't slow up boot if we are built-in if we are
39539@@ -832,9 +832,9 @@ static int intel_pstate_msrs_not_valid(void)
39540 rdmsrl(MSR_IA32_APERF, aperf);
39541 rdmsrl(MSR_IA32_MPERF, mperf);
39542
39543- if (!pstate_funcs.get_max() ||
39544- !pstate_funcs.get_min() ||
39545- !pstate_funcs.get_turbo())
39546+ if (!pstate_funcs->get_max() ||
39547+ !pstate_funcs->get_min() ||
39548+ !pstate_funcs->get_turbo())
39549 return -ENODEV;
39550
39551 rdmsrl(MSR_IA32_APERF, tmp);
39552@@ -848,7 +848,7 @@ static int intel_pstate_msrs_not_valid(void)
39553 return 0;
39554 }
39555
39556-static void copy_pid_params(struct pstate_adjust_policy *policy)
39557+static void copy_pid_params(const struct pstate_adjust_policy *policy)
39558 {
39559 pid_params.sample_rate_ms = policy->sample_rate_ms;
39560 pid_params.p_gain_pct = policy->p_gain_pct;
39561@@ -860,11 +860,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
39562
39563 static void copy_cpu_funcs(struct pstate_funcs *funcs)
39564 {
39565- pstate_funcs.get_max = funcs->get_max;
39566- pstate_funcs.get_min = funcs->get_min;
39567- pstate_funcs.get_turbo = funcs->get_turbo;
39568- pstate_funcs.set = funcs->set;
39569- pstate_funcs.get_vid = funcs->get_vid;
39570+ pstate_funcs = funcs;
39571 }
39572
39573 #if IS_ENABLED(CONFIG_ACPI)
39574diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
39575index 3d1cba9..0ab21d2 100644
39576--- a/drivers/cpufreq/p4-clockmod.c
39577+++ b/drivers/cpufreq/p4-clockmod.c
39578@@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39579 case 0x0F: /* Core Duo */
39580 case 0x16: /* Celeron Core */
39581 case 0x1C: /* Atom */
39582- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39583+ pax_open_kernel();
39584+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39585+ pax_close_kernel();
39586 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
39587 case 0x0D: /* Pentium M (Dothan) */
39588- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39589+ pax_open_kernel();
39590+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39591+ pax_close_kernel();
39592 /* fall through */
39593 case 0x09: /* Pentium M (Banias) */
39594 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
39595@@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39596
39597 /* on P-4s, the TSC runs with constant frequency independent whether
39598 * throttling is active or not. */
39599- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39600+ pax_open_kernel();
39601+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39602+ pax_close_kernel();
39603
39604 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
39605 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
39606diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
39607index 724ffbd..f06aaaa 100644
39608--- a/drivers/cpufreq/sparc-us3-cpufreq.c
39609+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
39610@@ -18,14 +18,12 @@
39611 #include <asm/head.h>
39612 #include <asm/timer.h>
39613
39614-static struct cpufreq_driver *cpufreq_us3_driver;
39615-
39616 struct us3_freq_percpu_info {
39617 struct cpufreq_frequency_table table[4];
39618 };
39619
39620 /* Indexed by cpu number. */
39621-static struct us3_freq_percpu_info *us3_freq_table;
39622+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
39623
39624 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
39625 * in the Safari config register.
39626@@ -156,18 +154,28 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
39627
39628 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
39629 {
39630- if (cpufreq_us3_driver) {
39631- cpufreq_frequency_table_put_attr(policy->cpu);
39632- us3_freq_target(policy, 0);
39633- }
39634+ cpufreq_frequency_table_put_attr(policy->cpu);
39635+ us3_freq_target(policy, 0);
39636
39637 return 0;
39638 }
39639
39640+static int __init us3_freq_init(void);
39641+static void __exit us3_freq_exit(void);
39642+
39643+static struct cpufreq_driver cpufreq_us3_driver = {
39644+ .init = us3_freq_cpu_init,
39645+ .verify = cpufreq_generic_frequency_table_verify,
39646+ .target_index = us3_freq_target,
39647+ .get = us3_freq_get,
39648+ .exit = us3_freq_cpu_exit,
39649+ .name = "UltraSPARC-III",
39650+
39651+};
39652+
39653 static int __init us3_freq_init(void)
39654 {
39655 unsigned long manuf, impl, ver;
39656- int ret;
39657
39658 if (tlb_type != cheetah && tlb_type != cheetah_plus)
39659 return -ENODEV;
39660@@ -180,55 +188,15 @@ static int __init us3_freq_init(void)
39661 (impl == CHEETAH_IMPL ||
39662 impl == CHEETAH_PLUS_IMPL ||
39663 impl == JAGUAR_IMPL ||
39664- impl == PANTHER_IMPL)) {
39665- struct cpufreq_driver *driver;
39666-
39667- ret = -ENOMEM;
39668- driver = kzalloc(sizeof(*driver), GFP_KERNEL);
39669- if (!driver)
39670- goto err_out;
39671-
39672- us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
39673- GFP_KERNEL);
39674- if (!us3_freq_table)
39675- goto err_out;
39676-
39677- driver->init = us3_freq_cpu_init;
39678- driver->verify = cpufreq_generic_frequency_table_verify;
39679- driver->target_index = us3_freq_target;
39680- driver->get = us3_freq_get;
39681- driver->exit = us3_freq_cpu_exit;
39682- strcpy(driver->name, "UltraSPARC-III");
39683-
39684- cpufreq_us3_driver = driver;
39685- ret = cpufreq_register_driver(driver);
39686- if (ret)
39687- goto err_out;
39688-
39689- return 0;
39690-
39691-err_out:
39692- if (driver) {
39693- kfree(driver);
39694- cpufreq_us3_driver = NULL;
39695- }
39696- kfree(us3_freq_table);
39697- us3_freq_table = NULL;
39698- return ret;
39699- }
39700+ impl == PANTHER_IMPL))
39701+ return cpufreq_register_driver(&cpufreq_us3_driver);
39702
39703 return -ENODEV;
39704 }
39705
39706 static void __exit us3_freq_exit(void)
39707 {
39708- if (cpufreq_us3_driver) {
39709- cpufreq_unregister_driver(cpufreq_us3_driver);
39710- kfree(cpufreq_us3_driver);
39711- cpufreq_us3_driver = NULL;
39712- kfree(us3_freq_table);
39713- us3_freq_table = NULL;
39714- }
39715+ cpufreq_unregister_driver(&cpufreq_us3_driver);
39716 }
39717
39718 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
39719diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
39720index 4e1daca..e707b61 100644
39721--- a/drivers/cpufreq/speedstep-centrino.c
39722+++ b/drivers/cpufreq/speedstep-centrino.c
39723@@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
39724 !cpu_has(cpu, X86_FEATURE_EST))
39725 return -ENODEV;
39726
39727- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
39728- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39729+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
39730+ pax_open_kernel();
39731+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39732+ pax_close_kernel();
39733+ }
39734
39735 if (policy->cpu != 0)
39736 return -ENODEV;
39737diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
39738index 06dbe7c..c2c8671 100644
39739--- a/drivers/cpuidle/driver.c
39740+++ b/drivers/cpuidle/driver.c
39741@@ -202,7 +202,7 @@ static int poll_idle(struct cpuidle_device *dev,
39742
39743 static void poll_idle_init(struct cpuidle_driver *drv)
39744 {
39745- struct cpuidle_state *state = &drv->states[0];
39746+ cpuidle_state_no_const *state = &drv->states[0];
39747
39748 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
39749 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
39750diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
39751index ca89412..a7b9c49 100644
39752--- a/drivers/cpuidle/governor.c
39753+++ b/drivers/cpuidle/governor.c
39754@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
39755 mutex_lock(&cpuidle_lock);
39756 if (__cpuidle_find_governor(gov->name) == NULL) {
39757 ret = 0;
39758- list_add_tail(&gov->governor_list, &cpuidle_governors);
39759+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
39760 if (!cpuidle_curr_governor ||
39761 cpuidle_curr_governor->rating < gov->rating)
39762 cpuidle_switch_governor(gov);
39763diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
39764index e918b6d..f87ea80 100644
39765--- a/drivers/cpuidle/sysfs.c
39766+++ b/drivers/cpuidle/sysfs.c
39767@@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
39768 NULL
39769 };
39770
39771-static struct attribute_group cpuidle_attr_group = {
39772+static attribute_group_no_const cpuidle_attr_group = {
39773 .attrs = cpuidle_default_attrs,
39774 .name = "cpuidle",
39775 };
39776diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
39777index 12fea3e..1e28f47 100644
39778--- a/drivers/crypto/hifn_795x.c
39779+++ b/drivers/crypto/hifn_795x.c
39780@@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
39781 MODULE_PARM_DESC(hifn_pll_ref,
39782 "PLL reference clock (pci[freq] or ext[freq], default ext)");
39783
39784-static atomic_t hifn_dev_number;
39785+static atomic_unchecked_t hifn_dev_number;
39786
39787 #define ACRYPTO_OP_DECRYPT 0
39788 #define ACRYPTO_OP_ENCRYPT 1
39789@@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
39790 goto err_out_disable_pci_device;
39791
39792 snprintf(name, sizeof(name), "hifn%d",
39793- atomic_inc_return(&hifn_dev_number)-1);
39794+ atomic_inc_return_unchecked(&hifn_dev_number)-1);
39795
39796 err = pci_request_regions(pdev, name);
39797 if (err)
39798diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
39799index a0b2f7e..1b6f028 100644
39800--- a/drivers/devfreq/devfreq.c
39801+++ b/drivers/devfreq/devfreq.c
39802@@ -607,7 +607,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
39803 goto err_out;
39804 }
39805
39806- list_add(&governor->node, &devfreq_governor_list);
39807+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
39808
39809 list_for_each_entry(devfreq, &devfreq_list, node) {
39810 int ret = 0;
39811@@ -695,7 +695,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
39812 }
39813 }
39814
39815- list_del(&governor->node);
39816+ pax_list_del((struct list_head *)&governor->node);
39817 err_out:
39818 mutex_unlock(&devfreq_list_lock);
39819
39820diff --git a/drivers/dma/sh/shdma-base.c b/drivers/dma/sh/shdma-base.c
39821index 2e7b394..1371a64 100644
39822--- a/drivers/dma/sh/shdma-base.c
39823+++ b/drivers/dma/sh/shdma-base.c
39824@@ -267,8 +267,8 @@ static int shdma_alloc_chan_resources(struct dma_chan *chan)
39825 schan->slave_id = -EINVAL;
39826 }
39827
39828- schan->desc = kcalloc(NR_DESCS_PER_CHANNEL,
39829- sdev->desc_size, GFP_KERNEL);
39830+ schan->desc = kcalloc(sdev->desc_size,
39831+ NR_DESCS_PER_CHANNEL, GFP_KERNEL);
39832 if (!schan->desc) {
39833 ret = -ENOMEM;
39834 goto edescalloc;
39835diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
39836index 0d765c0..60b7480 100644
39837--- a/drivers/dma/sh/shdmac.c
39838+++ b/drivers/dma/sh/shdmac.c
39839@@ -511,7 +511,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
39840 return ret;
39841 }
39842
39843-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
39844+static struct notifier_block sh_dmae_nmi_notifier = {
39845 .notifier_call = sh_dmae_nmi_handler,
39846
39847 /* Run before NMI debug handler and KGDB */
39848diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
39849index 592af5f..bb1d583 100644
39850--- a/drivers/edac/edac_device.c
39851+++ b/drivers/edac/edac_device.c
39852@@ -477,9 +477,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
39853 */
39854 int edac_device_alloc_index(void)
39855 {
39856- static atomic_t device_indexes = ATOMIC_INIT(0);
39857+ static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
39858
39859- return atomic_inc_return(&device_indexes) - 1;
39860+ return atomic_inc_return_unchecked(&device_indexes) - 1;
39861 }
39862 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
39863
39864diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
39865index b335c6a..db65b44 100644
39866--- a/drivers/edac/edac_mc_sysfs.c
39867+++ b/drivers/edac/edac_mc_sysfs.c
39868@@ -152,7 +152,7 @@ static const char * const edac_caps[] = {
39869 struct dev_ch_attribute {
39870 struct device_attribute attr;
39871 int channel;
39872-};
39873+} __do_const;
39874
39875 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
39876 struct dev_ch_attribute dev_attr_legacy_##_name = \
39877@@ -1009,14 +1009,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
39878 }
39879
39880 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
39881+ pax_open_kernel();
39882 if (mci->get_sdram_scrub_rate) {
39883- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39884- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39885+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39886+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39887 }
39888 if (mci->set_sdram_scrub_rate) {
39889- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39890- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39891+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39892+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39893 }
39894+ pax_close_kernel();
39895 err = device_create_file(&mci->dev,
39896 &dev_attr_sdram_scrub_rate);
39897 if (err) {
39898diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
39899index 2cf44b4d..6dd2dc7 100644
39900--- a/drivers/edac/edac_pci.c
39901+++ b/drivers/edac/edac_pci.c
39902@@ -29,7 +29,7 @@
39903
39904 static DEFINE_MUTEX(edac_pci_ctls_mutex);
39905 static LIST_HEAD(edac_pci_list);
39906-static atomic_t pci_indexes = ATOMIC_INIT(0);
39907+static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
39908
39909 /*
39910 * edac_pci_alloc_ctl_info
39911@@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
39912 */
39913 int edac_pci_alloc_index(void)
39914 {
39915- return atomic_inc_return(&pci_indexes) - 1;
39916+ return atomic_inc_return_unchecked(&pci_indexes) - 1;
39917 }
39918 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
39919
39920diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
39921index e8658e4..22746d6 100644
39922--- a/drivers/edac/edac_pci_sysfs.c
39923+++ b/drivers/edac/edac_pci_sysfs.c
39924@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
39925 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
39926 static int edac_pci_poll_msec = 1000; /* one second workq period */
39927
39928-static atomic_t pci_parity_count = ATOMIC_INIT(0);
39929-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
39930+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
39931+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
39932
39933 static struct kobject *edac_pci_top_main_kobj;
39934 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
39935@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
39936 void *value;
39937 ssize_t(*show) (void *, char *);
39938 ssize_t(*store) (void *, const char *, size_t);
39939-};
39940+} __do_const;
39941
39942 /* Set of show/store abstract level functions for PCI Parity object */
39943 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
39944@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39945 edac_printk(KERN_CRIT, EDAC_PCI,
39946 "Signaled System Error on %s\n",
39947 pci_name(dev));
39948- atomic_inc(&pci_nonparity_count);
39949+ atomic_inc_unchecked(&pci_nonparity_count);
39950 }
39951
39952 if (status & (PCI_STATUS_PARITY)) {
39953@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39954 "Master Data Parity Error on %s\n",
39955 pci_name(dev));
39956
39957- atomic_inc(&pci_parity_count);
39958+ atomic_inc_unchecked(&pci_parity_count);
39959 }
39960
39961 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39962@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39963 "Detected Parity Error on %s\n",
39964 pci_name(dev));
39965
39966- atomic_inc(&pci_parity_count);
39967+ atomic_inc_unchecked(&pci_parity_count);
39968 }
39969 }
39970
39971@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39972 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
39973 "Signaled System Error on %s\n",
39974 pci_name(dev));
39975- atomic_inc(&pci_nonparity_count);
39976+ atomic_inc_unchecked(&pci_nonparity_count);
39977 }
39978
39979 if (status & (PCI_STATUS_PARITY)) {
39980@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39981 "Master Data Parity Error on "
39982 "%s\n", pci_name(dev));
39983
39984- atomic_inc(&pci_parity_count);
39985+ atomic_inc_unchecked(&pci_parity_count);
39986 }
39987
39988 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39989@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39990 "Detected Parity Error on %s\n",
39991 pci_name(dev));
39992
39993- atomic_inc(&pci_parity_count);
39994+ atomic_inc_unchecked(&pci_parity_count);
39995 }
39996 }
39997 }
39998@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
39999 if (!check_pci_errors)
40000 return;
40001
40002- before_count = atomic_read(&pci_parity_count);
40003+ before_count = atomic_read_unchecked(&pci_parity_count);
40004
40005 /* scan all PCI devices looking for a Parity Error on devices and
40006 * bridges.
40007@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
40008 /* Only if operator has selected panic on PCI Error */
40009 if (edac_pci_get_panic_on_pe()) {
40010 /* If the count is different 'after' from 'before' */
40011- if (before_count != atomic_read(&pci_parity_count))
40012+ if (before_count != atomic_read_unchecked(&pci_parity_count))
40013 panic("EDAC: PCI Parity Error");
40014 }
40015 }
40016diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
40017index 51b7e3a..aa8a3e8 100644
40018--- a/drivers/edac/mce_amd.h
40019+++ b/drivers/edac/mce_amd.h
40020@@ -77,7 +77,7 @@ struct amd_decoder_ops {
40021 bool (*mc0_mce)(u16, u8);
40022 bool (*mc1_mce)(u16, u8);
40023 bool (*mc2_mce)(u16, u8);
40024-};
40025+} __no_const;
40026
40027 void amd_report_gart_errors(bool);
40028 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
40029diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
40030index 57ea7f4..af06b76 100644
40031--- a/drivers/firewire/core-card.c
40032+++ b/drivers/firewire/core-card.c
40033@@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
40034 const struct fw_card_driver *driver,
40035 struct device *device)
40036 {
40037- static atomic_t index = ATOMIC_INIT(-1);
40038+ static atomic_unchecked_t index = ATOMIC_INIT(-1);
40039
40040- card->index = atomic_inc_return(&index);
40041+ card->index = atomic_inc_return_unchecked(&index);
40042 card->driver = driver;
40043 card->device = device;
40044 card->current_tlabel = 0;
40045@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
40046
40047 void fw_core_remove_card(struct fw_card *card)
40048 {
40049- struct fw_card_driver dummy_driver = dummy_driver_template;
40050+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
40051
40052 card->driver->update_phy_reg(card, 4,
40053 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
40054diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
40055index 2c6d5e1..a2cca6b 100644
40056--- a/drivers/firewire/core-device.c
40057+++ b/drivers/firewire/core-device.c
40058@@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
40059 struct config_rom_attribute {
40060 struct device_attribute attr;
40061 u32 key;
40062-};
40063+} __do_const;
40064
40065 static ssize_t show_immediate(struct device *dev,
40066 struct device_attribute *dattr, char *buf)
40067diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
40068index eb6935c..3cc2bfa 100644
40069--- a/drivers/firewire/core-transaction.c
40070+++ b/drivers/firewire/core-transaction.c
40071@@ -38,6 +38,7 @@
40072 #include <linux/timer.h>
40073 #include <linux/types.h>
40074 #include <linux/workqueue.h>
40075+#include <linux/sched.h>
40076
40077 #include <asm/byteorder.h>
40078
40079diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
40080index c98764a..551b520 100644
40081--- a/drivers/firewire/core.h
40082+++ b/drivers/firewire/core.h
40083@@ -111,6 +111,7 @@ struct fw_card_driver {
40084
40085 int (*stop_iso)(struct fw_iso_context *ctx);
40086 };
40087+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
40088
40089 void fw_card_initialize(struct fw_card *card,
40090 const struct fw_card_driver *driver, struct device *device);
40091diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
40092index 8db6632..9bbc8ca 100644
40093--- a/drivers/firewire/ohci.c
40094+++ b/drivers/firewire/ohci.c
40095@@ -2049,10 +2049,12 @@ static void bus_reset_work(struct work_struct *work)
40096 be32_to_cpu(ohci->next_header));
40097 }
40098
40099+#ifndef CONFIG_GRKERNSEC
40100 if (param_remote_dma) {
40101 reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
40102 reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
40103 }
40104+#endif
40105
40106 spin_unlock_irq(&ohci->lock);
40107
40108@@ -2584,8 +2586,10 @@ static int ohci_enable_phys_dma(struct fw_card *card,
40109 unsigned long flags;
40110 int n, ret = 0;
40111
40112+#ifndef CONFIG_GRKERNSEC
40113 if (param_remote_dma)
40114 return 0;
40115+#endif
40116
40117 /*
40118 * FIXME: Make sure this bitmask is cleared when we clear the busReset
40119diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
40120index 94a58a0..f5eba42 100644
40121--- a/drivers/firmware/dmi-id.c
40122+++ b/drivers/firmware/dmi-id.c
40123@@ -16,7 +16,7 @@
40124 struct dmi_device_attribute{
40125 struct device_attribute dev_attr;
40126 int field;
40127-};
40128+} __do_const;
40129 #define to_dmi_dev_attr(_dev_attr) \
40130 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
40131
40132diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
40133index 17afc51..0ef90cd 100644
40134--- a/drivers/firmware/dmi_scan.c
40135+++ b/drivers/firmware/dmi_scan.c
40136@@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
40137 if (buf == NULL)
40138 return -1;
40139
40140- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
40141+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
40142
40143 dmi_unmap(buf);
40144 return 0;
40145diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
40146index 1491dd4..aa910db 100644
40147--- a/drivers/firmware/efi/cper.c
40148+++ b/drivers/firmware/efi/cper.c
40149@@ -41,12 +41,12 @@
40150 */
40151 u64 cper_next_record_id(void)
40152 {
40153- static atomic64_t seq;
40154+ static atomic64_unchecked_t seq;
40155
40156- if (!atomic64_read(&seq))
40157- atomic64_set(&seq, ((u64)get_seconds()) << 32);
40158+ if (!atomic64_read_unchecked(&seq))
40159+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
40160
40161- return atomic64_inc_return(&seq);
40162+ return atomic64_inc_return_unchecked(&seq);
40163 }
40164 EXPORT_SYMBOL_GPL(cper_next_record_id);
40165
40166diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
40167index 4753bac..02861a2 100644
40168--- a/drivers/firmware/efi/efi.c
40169+++ b/drivers/firmware/efi/efi.c
40170@@ -120,14 +120,16 @@ static struct attribute_group efi_subsys_attr_group = {
40171 };
40172
40173 static struct efivars generic_efivars;
40174-static struct efivar_operations generic_ops;
40175+static efivar_operations_no_const generic_ops __read_only;
40176
40177 static int generic_ops_register(void)
40178 {
40179- generic_ops.get_variable = efi.get_variable;
40180- generic_ops.set_variable = efi.set_variable;
40181- generic_ops.get_next_variable = efi.get_next_variable;
40182- generic_ops.query_variable_store = efi_query_variable_store;
40183+ pax_open_kernel();
40184+ *(void **)&generic_ops.get_variable = efi.get_variable;
40185+ *(void **)&generic_ops.set_variable = efi.set_variable;
40186+ *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
40187+ *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
40188+ pax_close_kernel();
40189
40190 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
40191 }
40192diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
40193index 3dc2482..7bd2f61 100644
40194--- a/drivers/firmware/efi/efivars.c
40195+++ b/drivers/firmware/efi/efivars.c
40196@@ -456,7 +456,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
40197 static int
40198 create_efivars_bin_attributes(void)
40199 {
40200- struct bin_attribute *attr;
40201+ bin_attribute_no_const *attr;
40202 int error;
40203
40204 /* new_var */
40205diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
40206index 2a90ba6..07f3733 100644
40207--- a/drivers/firmware/google/memconsole.c
40208+++ b/drivers/firmware/google/memconsole.c
40209@@ -147,7 +147,9 @@ static int __init memconsole_init(void)
40210 if (!found_memconsole())
40211 return -ENODEV;
40212
40213- memconsole_bin_attr.size = memconsole_length;
40214+ pax_open_kernel();
40215+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
40216+ pax_close_kernel();
40217
40218 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
40219
40220diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
40221index 1e98a98..b444372 100644
40222--- a/drivers/gpio/gpio-em.c
40223+++ b/drivers/gpio/gpio-em.c
40224@@ -278,7 +278,7 @@ static int em_gio_probe(struct platform_device *pdev)
40225 struct em_gio_priv *p;
40226 struct resource *io[2], *irq[2];
40227 struct gpio_chip *gpio_chip;
40228- struct irq_chip *irq_chip;
40229+ irq_chip_no_const *irq_chip;
40230 const char *name = dev_name(&pdev->dev);
40231 int ret;
40232
40233diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
40234index f5bf3c3..7baaa59 100644
40235--- a/drivers/gpio/gpio-ich.c
40236+++ b/drivers/gpio/gpio-ich.c
40237@@ -71,7 +71,7 @@ struct ichx_desc {
40238 /* Some chipsets have quirks, let these use their own request/get */
40239 int (*request)(struct gpio_chip *chip, unsigned offset);
40240 int (*get)(struct gpio_chip *chip, unsigned offset);
40241-};
40242+} __do_const;
40243
40244 static struct {
40245 spinlock_t lock;
40246diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
40247index ca76ce7..68b384b 100644
40248--- a/drivers/gpio/gpio-rcar.c
40249+++ b/drivers/gpio/gpio-rcar.c
40250@@ -355,7 +355,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
40251 struct gpio_rcar_priv *p;
40252 struct resource *io, *irq;
40253 struct gpio_chip *gpio_chip;
40254- struct irq_chip *irq_chip;
40255+ irq_chip_no_const *irq_chip;
40256 const char *name = dev_name(&pdev->dev);
40257 int ret;
40258
40259diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
40260index 9902732..64b62dd 100644
40261--- a/drivers/gpio/gpio-vr41xx.c
40262+++ b/drivers/gpio/gpio-vr41xx.c
40263@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
40264 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
40265 maskl, pendl, maskh, pendh);
40266
40267- atomic_inc(&irq_err_count);
40268+ atomic_inc_unchecked(&irq_err_count);
40269
40270 return -EINVAL;
40271 }
40272diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
40273index 3b7d32d..05c2f74 100644
40274--- a/drivers/gpu/drm/drm_crtc.c
40275+++ b/drivers/gpu/drm/drm_crtc.c
40276@@ -3123,7 +3123,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
40277 goto done;
40278 }
40279
40280- if (copy_to_user(&enum_ptr[copied].name,
40281+ if (copy_to_user(enum_ptr[copied].name,
40282 &prop_enum->name, DRM_PROP_NAME_LEN)) {
40283 ret = -EFAULT;
40284 goto done;
40285diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
40286index 345be03..158368d 100644
40287--- a/drivers/gpu/drm/drm_drv.c
40288+++ b/drivers/gpu/drm/drm_drv.c
40289@@ -233,7 +233,7 @@ module_exit(drm_core_exit);
40290 /**
40291 * Copy and IOCTL return string to user space
40292 */
40293-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
40294+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
40295 {
40296 int len;
40297
40298@@ -303,7 +303,7 @@ long drm_ioctl(struct file *filp,
40299 struct drm_file *file_priv = filp->private_data;
40300 struct drm_device *dev;
40301 const struct drm_ioctl_desc *ioctl = NULL;
40302- drm_ioctl_t *func;
40303+ drm_ioctl_no_const_t func;
40304 unsigned int nr = DRM_IOCTL_NR(cmd);
40305 int retcode = -EINVAL;
40306 char stack_kdata[128];
40307diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
40308index 7f2af9a..1561914 100644
40309--- a/drivers/gpu/drm/drm_fops.c
40310+++ b/drivers/gpu/drm/drm_fops.c
40311@@ -97,7 +97,7 @@ int drm_open(struct inode *inode, struct file *filp)
40312 if (drm_device_is_unplugged(dev))
40313 return -ENODEV;
40314
40315- if (!dev->open_count++)
40316+ if (local_inc_return(&dev->open_count) == 1)
40317 need_setup = 1;
40318 mutex_lock(&dev->struct_mutex);
40319 old_imapping = inode->i_mapping;
40320@@ -127,7 +127,7 @@ err_undo:
40321 iput(container_of(dev->dev_mapping, struct inode, i_data));
40322 dev->dev_mapping = old_mapping;
40323 mutex_unlock(&dev->struct_mutex);
40324- dev->open_count--;
40325+ local_dec(&dev->open_count);
40326 return retcode;
40327 }
40328 EXPORT_SYMBOL(drm_open);
40329@@ -463,7 +463,7 @@ int drm_release(struct inode *inode, struct file *filp)
40330
40331 mutex_lock(&drm_global_mutex);
40332
40333- DRM_DEBUG("open_count = %d\n", dev->open_count);
40334+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
40335
40336 if (dev->driver->preclose)
40337 dev->driver->preclose(dev, file_priv);
40338@@ -472,10 +472,10 @@ int drm_release(struct inode *inode, struct file *filp)
40339 * Begin inline drm_release
40340 */
40341
40342- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
40343+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
40344 task_pid_nr(current),
40345 (long)old_encode_dev(file_priv->minor->device),
40346- dev->open_count);
40347+ local_read(&dev->open_count));
40348
40349 /* Release any auth tokens that might point to this file_priv,
40350 (do that under the drm_global_mutex) */
40351@@ -573,7 +573,7 @@ int drm_release(struct inode *inode, struct file *filp)
40352 * End inline drm_release
40353 */
40354
40355- if (!--dev->open_count) {
40356+ if (local_dec_and_test(&dev->open_count)) {
40357 retcode = drm_lastclose(dev);
40358 if (drm_device_is_unplugged(dev))
40359 drm_put_dev(dev);
40360diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
40361index 3d2e91c..d31c4c9 100644
40362--- a/drivers/gpu/drm/drm_global.c
40363+++ b/drivers/gpu/drm/drm_global.c
40364@@ -36,7 +36,7 @@
40365 struct drm_global_item {
40366 struct mutex mutex;
40367 void *object;
40368- int refcount;
40369+ atomic_t refcount;
40370 };
40371
40372 static struct drm_global_item glob[DRM_GLOBAL_NUM];
40373@@ -49,7 +49,7 @@ void drm_global_init(void)
40374 struct drm_global_item *item = &glob[i];
40375 mutex_init(&item->mutex);
40376 item->object = NULL;
40377- item->refcount = 0;
40378+ atomic_set(&item->refcount, 0);
40379 }
40380 }
40381
40382@@ -59,7 +59,7 @@ void drm_global_release(void)
40383 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
40384 struct drm_global_item *item = &glob[i];
40385 BUG_ON(item->object != NULL);
40386- BUG_ON(item->refcount != 0);
40387+ BUG_ON(atomic_read(&item->refcount) != 0);
40388 }
40389 }
40390
40391@@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40392 struct drm_global_item *item = &glob[ref->global_type];
40393
40394 mutex_lock(&item->mutex);
40395- if (item->refcount == 0) {
40396+ if (atomic_read(&item->refcount) == 0) {
40397 item->object = kzalloc(ref->size, GFP_KERNEL);
40398 if (unlikely(item->object == NULL)) {
40399 ret = -ENOMEM;
40400@@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40401 goto out_err;
40402
40403 }
40404- ++item->refcount;
40405+ atomic_inc(&item->refcount);
40406 ref->object = item->object;
40407 mutex_unlock(&item->mutex);
40408 return 0;
40409@@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
40410 struct drm_global_item *item = &glob[ref->global_type];
40411
40412 mutex_lock(&item->mutex);
40413- BUG_ON(item->refcount == 0);
40414+ BUG_ON(atomic_read(&item->refcount) == 0);
40415 BUG_ON(ref->object != item->object);
40416- if (--item->refcount == 0) {
40417+ if (atomic_dec_and_test(&item->refcount)) {
40418 ref->release(ref);
40419 item->object = NULL;
40420 }
40421diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
40422index 7473035..a48b9c5 100644
40423--- a/drivers/gpu/drm/drm_info.c
40424+++ b/drivers/gpu/drm/drm_info.c
40425@@ -75,10 +75,13 @@ int drm_vm_info(struct seq_file *m, void *data)
40426 struct drm_local_map *map;
40427 struct drm_map_list *r_list;
40428
40429- /* Hardcoded from _DRM_FRAME_BUFFER,
40430- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
40431- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
40432- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
40433+ static const char * const types[] = {
40434+ [_DRM_FRAME_BUFFER] = "FB",
40435+ [_DRM_REGISTERS] = "REG",
40436+ [_DRM_SHM] = "SHM",
40437+ [_DRM_AGP] = "AGP",
40438+ [_DRM_SCATTER_GATHER] = "SG",
40439+ [_DRM_CONSISTENT] = "PCI"};
40440 const char *type;
40441 int i;
40442
40443@@ -89,7 +92,7 @@ int drm_vm_info(struct seq_file *m, void *data)
40444 map = r_list->map;
40445 if (!map)
40446 continue;
40447- if (map->type < 0 || map->type > 5)
40448+ if (map->type >= ARRAY_SIZE(types))
40449 type = "??";
40450 else
40451 type = types[map->type];
40452@@ -261,7 +264,11 @@ int drm_vma_info(struct seq_file *m, void *data)
40453 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
40454 vma->vm_flags & VM_LOCKED ? 'l' : '-',
40455 vma->vm_flags & VM_IO ? 'i' : '-',
40456+#ifdef CONFIG_GRKERNSEC_HIDESYM
40457+ 0);
40458+#else
40459 vma->vm_pgoff);
40460+#endif
40461
40462 #if defined(__i386__)
40463 pgprot = pgprot_val(vma->vm_page_prot);
40464diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
40465index 2f4c4343..dd12cd2 100644
40466--- a/drivers/gpu/drm/drm_ioc32.c
40467+++ b/drivers/gpu/drm/drm_ioc32.c
40468@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
40469 request = compat_alloc_user_space(nbytes);
40470 if (!access_ok(VERIFY_WRITE, request, nbytes))
40471 return -EFAULT;
40472- list = (struct drm_buf_desc *) (request + 1);
40473+ list = (struct drm_buf_desc __user *) (request + 1);
40474
40475 if (__put_user(count, &request->count)
40476 || __put_user(list, &request->list))
40477@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
40478 request = compat_alloc_user_space(nbytes);
40479 if (!access_ok(VERIFY_WRITE, request, nbytes))
40480 return -EFAULT;
40481- list = (struct drm_buf_pub *) (request + 1);
40482+ list = (struct drm_buf_pub __user *) (request + 1);
40483
40484 if (__put_user(count, &request->count)
40485 || __put_user(list, &request->list))
40486@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
40487 return 0;
40488 }
40489
40490-drm_ioctl_compat_t *drm_compat_ioctls[] = {
40491+drm_ioctl_compat_t drm_compat_ioctls[] = {
40492 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
40493 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
40494 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
40495@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
40496 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40497 {
40498 unsigned int nr = DRM_IOCTL_NR(cmd);
40499- drm_ioctl_compat_t *fn;
40500 int ret;
40501
40502 /* Assume that ioctls without an explicit compat routine will just
40503@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40504 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
40505 return drm_ioctl(filp, cmd, arg);
40506
40507- fn = drm_compat_ioctls[nr];
40508-
40509- if (fn != NULL)
40510- ret = (*fn) (filp, cmd, arg);
40511+ if (drm_compat_ioctls[nr] != NULL)
40512+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
40513 else
40514 ret = drm_ioctl(filp, cmd, arg);
40515
40516diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
40517index 98a33c580..8fd1c2b 100644
40518--- a/drivers/gpu/drm/drm_stub.c
40519+++ b/drivers/gpu/drm/drm_stub.c
40520@@ -409,7 +409,7 @@ void drm_unplug_dev(struct drm_device *dev)
40521
40522 drm_device_set_unplugged(dev);
40523
40524- if (dev->open_count == 0) {
40525+ if (local_read(&dev->open_count) == 0) {
40526 drm_put_dev(dev);
40527 }
40528 mutex_unlock(&drm_global_mutex);
40529diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
40530index c22c309..ae758c3 100644
40531--- a/drivers/gpu/drm/drm_sysfs.c
40532+++ b/drivers/gpu/drm/drm_sysfs.c
40533@@ -505,7 +505,7 @@ static void drm_sysfs_release(struct device *dev)
40534 */
40535 int drm_sysfs_device_add(struct drm_minor *minor)
40536 {
40537- char *minor_str;
40538+ const char *minor_str;
40539 int r;
40540
40541 if (minor->type == DRM_MINOR_CONTROL)
40542diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
40543index d4d16ed..8fb0b51 100644
40544--- a/drivers/gpu/drm/i810/i810_drv.h
40545+++ b/drivers/gpu/drm/i810/i810_drv.h
40546@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
40547 int page_flipping;
40548
40549 wait_queue_head_t irq_queue;
40550- atomic_t irq_received;
40551- atomic_t irq_emitted;
40552+ atomic_unchecked_t irq_received;
40553+ atomic_unchecked_t irq_emitted;
40554
40555 int front_offset;
40556 } drm_i810_private_t;
40557diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
40558index b2b46c5..feb9fe7 100644
40559--- a/drivers/gpu/drm/i915/i915_debugfs.c
40560+++ b/drivers/gpu/drm/i915/i915_debugfs.c
40561@@ -713,7 +713,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
40562 I915_READ(GTIMR));
40563 }
40564 seq_printf(m, "Interrupts received: %d\n",
40565- atomic_read(&dev_priv->irq_received));
40566+ atomic_read_unchecked(&dev_priv->irq_received));
40567 for_each_ring(ring, dev_priv, i) {
40568 if (INTEL_INFO(dev)->gen >= 6) {
40569 seq_printf(m,
40570diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
40571index 15a74f9..4278889 100644
40572--- a/drivers/gpu/drm/i915/i915_dma.c
40573+++ b/drivers/gpu/drm/i915/i915_dma.c
40574@@ -1273,7 +1273,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
40575 bool can_switch;
40576
40577 spin_lock(&dev->count_lock);
40578- can_switch = (dev->open_count == 0);
40579+ can_switch = (local_read(&dev->open_count) == 0);
40580 spin_unlock(&dev->count_lock);
40581 return can_switch;
40582 }
40583diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
40584index df77e20..d3fda9f 100644
40585--- a/drivers/gpu/drm/i915/i915_drv.h
40586+++ b/drivers/gpu/drm/i915/i915_drv.h
40587@@ -1361,7 +1361,7 @@ typedef struct drm_i915_private {
40588 drm_dma_handle_t *status_page_dmah;
40589 struct resource mch_res;
40590
40591- atomic_t irq_received;
40592+ atomic_unchecked_t irq_received;
40593
40594 /* protects the irq masks */
40595 spinlock_t irq_lock;
40596diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40597index d269ecf..6d857bc 100644
40598--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40599+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40600@@ -860,9 +860,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
40601
40602 static int
40603 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
40604- int count)
40605+ unsigned int count)
40606 {
40607- int i;
40608+ unsigned int i;
40609 unsigned relocs_total = 0;
40610 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
40611
40612diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
40613index 3c59584..500f2e9 100644
40614--- a/drivers/gpu/drm/i915/i915_ioc32.c
40615+++ b/drivers/gpu/drm/i915/i915_ioc32.c
40616@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
40617 (unsigned long)request);
40618 }
40619
40620-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40621+static drm_ioctl_compat_t i915_compat_ioctls[] = {
40622 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
40623 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
40624 [DRM_I915_GETPARAM] = compat_i915_getparam,
40625@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40626 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40627 {
40628 unsigned int nr = DRM_IOCTL_NR(cmd);
40629- drm_ioctl_compat_t *fn = NULL;
40630 int ret;
40631
40632 if (nr < DRM_COMMAND_BASE)
40633 return drm_compat_ioctl(filp, cmd, arg);
40634
40635- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
40636- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40637-
40638- if (fn != NULL)
40639+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
40640+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40641 ret = (*fn) (filp, cmd, arg);
40642- else
40643+ } else
40644 ret = drm_ioctl(filp, cmd, arg);
40645
40646 return ret;
40647diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
40648index d554169..f4426bb 100644
40649--- a/drivers/gpu/drm/i915/i915_irq.c
40650+++ b/drivers/gpu/drm/i915/i915_irq.c
40651@@ -1438,7 +1438,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
40652 int pipe;
40653 u32 pipe_stats[I915_MAX_PIPES];
40654
40655- atomic_inc(&dev_priv->irq_received);
40656+ atomic_inc_unchecked(&dev_priv->irq_received);
40657
40658 while (true) {
40659 iir = I915_READ(VLV_IIR);
40660@@ -1751,7 +1751,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
40661 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
40662 irqreturn_t ret = IRQ_NONE;
40663
40664- atomic_inc(&dev_priv->irq_received);
40665+ atomic_inc_unchecked(&dev_priv->irq_received);
40666
40667 /* We get interrupts on unclaimed registers, so check for this before we
40668 * do any I915_{READ,WRITE}. */
40669@@ -1821,7 +1821,7 @@ static irqreturn_t gen8_irq_handler(int irq, void *arg)
40670 uint32_t tmp = 0;
40671 enum pipe pipe;
40672
40673- atomic_inc(&dev_priv->irq_received);
40674+ atomic_inc_unchecked(&dev_priv->irq_received);
40675
40676 master_ctl = I915_READ(GEN8_MASTER_IRQ);
40677 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
40678@@ -2645,7 +2645,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
40679 {
40680 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40681
40682- atomic_set(&dev_priv->irq_received, 0);
40683+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40684
40685 I915_WRITE(HWSTAM, 0xeffe);
40686
40687@@ -2663,7 +2663,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
40688 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40689 int pipe;
40690
40691- atomic_set(&dev_priv->irq_received, 0);
40692+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40693
40694 /* VLV magic */
40695 I915_WRITE(VLV_IMR, 0);
40696@@ -2694,7 +2694,7 @@ static void gen8_irq_preinstall(struct drm_device *dev)
40697 struct drm_i915_private *dev_priv = dev->dev_private;
40698 int pipe;
40699
40700- atomic_set(&dev_priv->irq_received, 0);
40701+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40702
40703 I915_WRITE(GEN8_MASTER_IRQ, 0);
40704 POSTING_READ(GEN8_MASTER_IRQ);
40705@@ -3018,7 +3018,7 @@ static void gen8_irq_uninstall(struct drm_device *dev)
40706 if (!dev_priv)
40707 return;
40708
40709- atomic_set(&dev_priv->irq_received, 0);
40710+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40711
40712 I915_WRITE(GEN8_MASTER_IRQ, 0);
40713
40714@@ -3112,7 +3112,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
40715 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40716 int pipe;
40717
40718- atomic_set(&dev_priv->irq_received, 0);
40719+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40720
40721 for_each_pipe(pipe)
40722 I915_WRITE(PIPESTAT(pipe), 0);
40723@@ -3198,7 +3198,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
40724 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
40725 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40726
40727- atomic_inc(&dev_priv->irq_received);
40728+ atomic_inc_unchecked(&dev_priv->irq_received);
40729
40730 iir = I915_READ16(IIR);
40731 if (iir == 0)
40732@@ -3277,7 +3277,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
40733 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40734 int pipe;
40735
40736- atomic_set(&dev_priv->irq_received, 0);
40737+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40738
40739 if (I915_HAS_HOTPLUG(dev)) {
40740 I915_WRITE(PORT_HOTPLUG_EN, 0);
40741@@ -3384,7 +3384,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
40742 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40743 int pipe, ret = IRQ_NONE;
40744
40745- atomic_inc(&dev_priv->irq_received);
40746+ atomic_inc_unchecked(&dev_priv->irq_received);
40747
40748 iir = I915_READ(IIR);
40749 do {
40750@@ -3511,7 +3511,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
40751 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40752 int pipe;
40753
40754- atomic_set(&dev_priv->irq_received, 0);
40755+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40756
40757 I915_WRITE(PORT_HOTPLUG_EN, 0);
40758 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
40759@@ -3627,7 +3627,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
40760 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
40761 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40762
40763- atomic_inc(&dev_priv->irq_received);
40764+ atomic_inc_unchecked(&dev_priv->irq_received);
40765
40766 iir = I915_READ(IIR);
40767
40768diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
40769index 9b8a7c7..60f6003 100644
40770--- a/drivers/gpu/drm/i915/intel_display.c
40771+++ b/drivers/gpu/drm/i915/intel_display.c
40772@@ -10776,13 +10776,13 @@ struct intel_quirk {
40773 int subsystem_vendor;
40774 int subsystem_device;
40775 void (*hook)(struct drm_device *dev);
40776-};
40777+} __do_const;
40778
40779 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
40780 struct intel_dmi_quirk {
40781 void (*hook)(struct drm_device *dev);
40782 const struct dmi_system_id (*dmi_id_list)[];
40783-};
40784+} __do_const;
40785
40786 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40787 {
40788@@ -10790,18 +10790,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40789 return 1;
40790 }
40791
40792-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40793+static const struct dmi_system_id intel_dmi_quirks_table[] = {
40794 {
40795- .dmi_id_list = &(const struct dmi_system_id[]) {
40796- {
40797- .callback = intel_dmi_reverse_brightness,
40798- .ident = "NCR Corporation",
40799- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40800- DMI_MATCH(DMI_PRODUCT_NAME, ""),
40801- },
40802- },
40803- { } /* terminating entry */
40804+ .callback = intel_dmi_reverse_brightness,
40805+ .ident = "NCR Corporation",
40806+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40807+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
40808 },
40809+ },
40810+ { } /* terminating entry */
40811+};
40812+
40813+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40814+ {
40815+ .dmi_id_list = &intel_dmi_quirks_table,
40816 .hook = quirk_invert_brightness,
40817 },
40818 };
40819diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
40820index fe45321..836fdca 100644
40821--- a/drivers/gpu/drm/mga/mga_drv.h
40822+++ b/drivers/gpu/drm/mga/mga_drv.h
40823@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
40824 u32 clear_cmd;
40825 u32 maccess;
40826
40827- atomic_t vbl_received; /**< Number of vblanks received. */
40828+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
40829 wait_queue_head_t fence_queue;
40830- atomic_t last_fence_retired;
40831+ atomic_unchecked_t last_fence_retired;
40832 u32 next_fence_to_post;
40833
40834 unsigned int fb_cpp;
40835diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
40836index 86b4bb8..ae237ad 100644
40837--- a/drivers/gpu/drm/mga/mga_ioc32.c
40838+++ b/drivers/gpu/drm/mga/mga_ioc32.c
40839@@ -190,7 +190,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
40840 return 0;
40841 }
40842
40843-drm_ioctl_compat_t *mga_compat_ioctls[] = {
40844+drm_ioctl_compat_t mga_compat_ioctls[] = {
40845 [DRM_MGA_INIT] = compat_mga_init,
40846 [DRM_MGA_GETPARAM] = compat_mga_getparam,
40847 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
40848@@ -208,18 +208,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
40849 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40850 {
40851 unsigned int nr = DRM_IOCTL_NR(cmd);
40852- drm_ioctl_compat_t *fn = NULL;
40853 int ret;
40854
40855 if (nr < DRM_COMMAND_BASE)
40856 return drm_compat_ioctl(filp, cmd, arg);
40857
40858- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
40859- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40860-
40861- if (fn != NULL)
40862+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
40863+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40864 ret = (*fn) (filp, cmd, arg);
40865- else
40866+ } else
40867 ret = drm_ioctl(filp, cmd, arg);
40868
40869 return ret;
40870diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
40871index 1b071b8..de8601a 100644
40872--- a/drivers/gpu/drm/mga/mga_irq.c
40873+++ b/drivers/gpu/drm/mga/mga_irq.c
40874@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
40875 if (crtc != 0)
40876 return 0;
40877
40878- return atomic_read(&dev_priv->vbl_received);
40879+ return atomic_read_unchecked(&dev_priv->vbl_received);
40880 }
40881
40882
40883@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40884 /* VBLANK interrupt */
40885 if (status & MGA_VLINEPEN) {
40886 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
40887- atomic_inc(&dev_priv->vbl_received);
40888+ atomic_inc_unchecked(&dev_priv->vbl_received);
40889 drm_handle_vblank(dev, 0);
40890 handled = 1;
40891 }
40892@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40893 if ((prim_start & ~0x03) != (prim_end & ~0x03))
40894 MGA_WRITE(MGA_PRIMEND, prim_end);
40895
40896- atomic_inc(&dev_priv->last_fence_retired);
40897+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
40898 wake_up(&dev_priv->fence_queue);
40899 handled = 1;
40900 }
40901@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
40902 * using fences.
40903 */
40904 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * HZ,
40905- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
40906+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
40907 - *sequence) <= (1 << 23)));
40908
40909 *sequence = cur_fence;
40910diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
40911index 4c3feaa..26391ce 100644
40912--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
40913+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
40914@@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
40915 struct bit_table {
40916 const char id;
40917 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
40918-};
40919+} __no_const;
40920
40921 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
40922
40923diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
40924index 23ca7a5..b6c955d 100644
40925--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
40926+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
40927@@ -97,7 +97,6 @@ struct nouveau_drm {
40928 struct drm_global_reference mem_global_ref;
40929 struct ttm_bo_global_ref bo_global_ref;
40930 struct ttm_bo_device bdev;
40931- atomic_t validate_sequence;
40932 int (*move)(struct nouveau_channel *,
40933 struct ttm_buffer_object *,
40934 struct ttm_mem_reg *, struct ttm_mem_reg *);
40935diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40936index c1a7e5a..38b8539 100644
40937--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40938+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40939@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
40940 unsigned long arg)
40941 {
40942 unsigned int nr = DRM_IOCTL_NR(cmd);
40943- drm_ioctl_compat_t *fn = NULL;
40944+ drm_ioctl_compat_t fn = NULL;
40945 int ret;
40946
40947 if (nr < DRM_COMMAND_BASE)
40948diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40949index d45d50d..72a5dd2 100644
40950--- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
40951+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40952@@ -130,11 +130,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40953 }
40954
40955 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
40956- nouveau_vram_manager_init,
40957- nouveau_vram_manager_fini,
40958- nouveau_vram_manager_new,
40959- nouveau_vram_manager_del,
40960- nouveau_vram_manager_debug
40961+ .init = nouveau_vram_manager_init,
40962+ .takedown = nouveau_vram_manager_fini,
40963+ .get_node = nouveau_vram_manager_new,
40964+ .put_node = nouveau_vram_manager_del,
40965+ .debug = nouveau_vram_manager_debug
40966 };
40967
40968 static int
40969@@ -199,11 +199,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40970 }
40971
40972 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
40973- nouveau_gart_manager_init,
40974- nouveau_gart_manager_fini,
40975- nouveau_gart_manager_new,
40976- nouveau_gart_manager_del,
40977- nouveau_gart_manager_debug
40978+ .init = nouveau_gart_manager_init,
40979+ .takedown = nouveau_gart_manager_fini,
40980+ .get_node = nouveau_gart_manager_new,
40981+ .put_node = nouveau_gart_manager_del,
40982+ .debug = nouveau_gart_manager_debug
40983 };
40984
40985 #include <core/subdev/vm/nv04.h>
40986@@ -271,11 +271,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40987 }
40988
40989 const struct ttm_mem_type_manager_func nv04_gart_manager = {
40990- nv04_gart_manager_init,
40991- nv04_gart_manager_fini,
40992- nv04_gart_manager_new,
40993- nv04_gart_manager_del,
40994- nv04_gart_manager_debug
40995+ .init = nv04_gart_manager_init,
40996+ .takedown = nv04_gart_manager_fini,
40997+ .get_node = nv04_gart_manager_new,
40998+ .put_node = nv04_gart_manager_del,
40999+ .debug = nv04_gart_manager_debug
41000 };
41001
41002 int
41003diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
41004index 471347e..5adc6b9 100644
41005--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
41006+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
41007@@ -67,7 +67,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
41008 bool can_switch;
41009
41010 spin_lock(&dev->count_lock);
41011- can_switch = (dev->open_count == 0);
41012+ can_switch = (local_read(&dev->open_count) == 0);
41013 spin_unlock(&dev->count_lock);
41014 return can_switch;
41015 }
41016diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
41017index eb89653..613cf71 100644
41018--- a/drivers/gpu/drm/qxl/qxl_cmd.c
41019+++ b/drivers/gpu/drm/qxl/qxl_cmd.c
41020@@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
41021 int ret;
41022
41023 mutex_lock(&qdev->async_io_mutex);
41024- irq_num = atomic_read(&qdev->irq_received_io_cmd);
41025+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
41026 if (qdev->last_sent_io_cmd > irq_num) {
41027 if (intr)
41028 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
41029- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41030+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41031 else
41032 ret = wait_event_timeout(qdev->io_cmd_event,
41033- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41034+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41035 /* 0 is timeout, just bail the "hw" has gone away */
41036 if (ret <= 0)
41037 goto out;
41038- irq_num = atomic_read(&qdev->irq_received_io_cmd);
41039+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
41040 }
41041 outb(val, addr);
41042 qdev->last_sent_io_cmd = irq_num + 1;
41043 if (intr)
41044 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
41045- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41046+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41047 else
41048 ret = wait_event_timeout(qdev->io_cmd_event,
41049- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41050+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41051 out:
41052 if (ret > 0)
41053 ret = 0;
41054diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
41055index c3c2bbd..bc3c0fb 100644
41056--- a/drivers/gpu/drm/qxl/qxl_debugfs.c
41057+++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
41058@@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
41059 struct drm_info_node *node = (struct drm_info_node *) m->private;
41060 struct qxl_device *qdev = node->minor->dev->dev_private;
41061
41062- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
41063- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
41064- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
41065- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
41066+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
41067+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
41068+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
41069+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
41070 seq_printf(m, "%d\n", qdev->irq_received_error);
41071 return 0;
41072 }
41073diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
41074index 36ed40b..0397633 100644
41075--- a/drivers/gpu/drm/qxl/qxl_drv.h
41076+++ b/drivers/gpu/drm/qxl/qxl_drv.h
41077@@ -290,10 +290,10 @@ struct qxl_device {
41078 unsigned int last_sent_io_cmd;
41079
41080 /* interrupt handling */
41081- atomic_t irq_received;
41082- atomic_t irq_received_display;
41083- atomic_t irq_received_cursor;
41084- atomic_t irq_received_io_cmd;
41085+ atomic_unchecked_t irq_received;
41086+ atomic_unchecked_t irq_received_display;
41087+ atomic_unchecked_t irq_received_cursor;
41088+ atomic_unchecked_t irq_received_io_cmd;
41089 unsigned irq_received_error;
41090 wait_queue_head_t display_event;
41091 wait_queue_head_t cursor_event;
41092diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
41093index 0bb86e6..d41416d 100644
41094--- a/drivers/gpu/drm/qxl/qxl_ioctl.c
41095+++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
41096@@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
41097
41098 /* TODO copy slow path code from i915 */
41099 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
41100- 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);
41101+ 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);
41102
41103 {
41104 struct qxl_drawable *draw = fb_cmd;
41105@@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
41106 struct drm_qxl_reloc reloc;
41107
41108 if (copy_from_user(&reloc,
41109- &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
41110+ &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
41111 sizeof(reloc))) {
41112 ret = -EFAULT;
41113 goto out_free_bos;
41114@@ -294,10 +294,10 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
41115
41116 for (cmd_num = 0; cmd_num < execbuffer->commands_num; ++cmd_num) {
41117
41118- struct drm_qxl_command *commands =
41119- (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
41120+ struct drm_qxl_command __user *commands =
41121+ (struct drm_qxl_command __user *)(uintptr_t)execbuffer->commands;
41122
41123- if (copy_from_user(&user_cmd, &commands[cmd_num],
41124+ if (copy_from_user(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
41125 sizeof(user_cmd)))
41126 return -EFAULT;
41127
41128diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
41129index 28f84b4..fb3e224 100644
41130--- a/drivers/gpu/drm/qxl/qxl_irq.c
41131+++ b/drivers/gpu/drm/qxl/qxl_irq.c
41132@@ -33,19 +33,19 @@ irqreturn_t qxl_irq_handler(int irq, void *arg)
41133
41134 pending = xchg(&qdev->ram_header->int_pending, 0);
41135
41136- atomic_inc(&qdev->irq_received);
41137+ atomic_inc_unchecked(&qdev->irq_received);
41138
41139 if (pending & QXL_INTERRUPT_DISPLAY) {
41140- atomic_inc(&qdev->irq_received_display);
41141+ atomic_inc_unchecked(&qdev->irq_received_display);
41142 wake_up_all(&qdev->display_event);
41143 qxl_queue_garbage_collect(qdev, false);
41144 }
41145 if (pending & QXL_INTERRUPT_CURSOR) {
41146- atomic_inc(&qdev->irq_received_cursor);
41147+ atomic_inc_unchecked(&qdev->irq_received_cursor);
41148 wake_up_all(&qdev->cursor_event);
41149 }
41150 if (pending & QXL_INTERRUPT_IO_CMD) {
41151- atomic_inc(&qdev->irq_received_io_cmd);
41152+ atomic_inc_unchecked(&qdev->irq_received_io_cmd);
41153 wake_up_all(&qdev->io_cmd_event);
41154 }
41155 if (pending & QXL_INTERRUPT_ERROR) {
41156@@ -82,10 +82,10 @@ int qxl_irq_init(struct qxl_device *qdev)
41157 init_waitqueue_head(&qdev->io_cmd_event);
41158 INIT_WORK(&qdev->client_monitors_config_work,
41159 qxl_client_monitors_config_work_func);
41160- atomic_set(&qdev->irq_received, 0);
41161- atomic_set(&qdev->irq_received_display, 0);
41162- atomic_set(&qdev->irq_received_cursor, 0);
41163- atomic_set(&qdev->irq_received_io_cmd, 0);
41164+ atomic_set_unchecked(&qdev->irq_received, 0);
41165+ atomic_set_unchecked(&qdev->irq_received_display, 0);
41166+ atomic_set_unchecked(&qdev->irq_received_cursor, 0);
41167+ atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
41168 qdev->irq_received_error = 0;
41169 ret = drm_irq_install(qdev->ddev);
41170 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
41171diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
41172index c7e7e65..7dddd4d 100644
41173--- a/drivers/gpu/drm/qxl/qxl_ttm.c
41174+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
41175@@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
41176 }
41177 }
41178
41179-static struct vm_operations_struct qxl_ttm_vm_ops;
41180+static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
41181 static const struct vm_operations_struct *ttm_vm_ops;
41182
41183 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41184@@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
41185 return r;
41186 if (unlikely(ttm_vm_ops == NULL)) {
41187 ttm_vm_ops = vma->vm_ops;
41188+ pax_open_kernel();
41189 qxl_ttm_vm_ops = *ttm_vm_ops;
41190 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
41191+ pax_close_kernel();
41192 }
41193 vma->vm_ops = &qxl_ttm_vm_ops;
41194 return 0;
41195@@ -560,25 +562,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
41196 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
41197 {
41198 #if defined(CONFIG_DEBUG_FS)
41199- static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
41200- static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
41201- unsigned i;
41202+ static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
41203+ {
41204+ .name = "qxl_mem_mm",
41205+ .show = &qxl_mm_dump_table,
41206+ },
41207+ {
41208+ .name = "qxl_surf_mm",
41209+ .show = &qxl_mm_dump_table,
41210+ }
41211+ };
41212
41213- for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
41214- if (i == 0)
41215- sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
41216- else
41217- sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
41218- qxl_mem_types_list[i].name = qxl_mem_types_names[i];
41219- qxl_mem_types_list[i].show = &qxl_mm_dump_table;
41220- qxl_mem_types_list[i].driver_features = 0;
41221- if (i == 0)
41222- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
41223- else
41224- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
41225+ pax_open_kernel();
41226+ *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
41227+ *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
41228+ pax_close_kernel();
41229
41230- }
41231- return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
41232+ return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
41233 #else
41234 return 0;
41235 #endif
41236diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
41237index 59459fe..be26b31 100644
41238--- a/drivers/gpu/drm/r128/r128_cce.c
41239+++ b/drivers/gpu/drm/r128/r128_cce.c
41240@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
41241
41242 /* GH: Simple idle check.
41243 */
41244- atomic_set(&dev_priv->idle_count, 0);
41245+ atomic_set_unchecked(&dev_priv->idle_count, 0);
41246
41247 /* We don't support anything other than bus-mastering ring mode,
41248 * but the ring can be in either AGP or PCI space for the ring
41249diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
41250index 5bf3f5f..7000661 100644
41251--- a/drivers/gpu/drm/r128/r128_drv.h
41252+++ b/drivers/gpu/drm/r128/r128_drv.h
41253@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
41254 int is_pci;
41255 unsigned long cce_buffers_offset;
41256
41257- atomic_t idle_count;
41258+ atomic_unchecked_t idle_count;
41259
41260 int page_flipping;
41261 int current_page;
41262 u32 crtc_offset;
41263 u32 crtc_offset_cntl;
41264
41265- atomic_t vbl_received;
41266+ atomic_unchecked_t vbl_received;
41267
41268 u32 color_fmt;
41269 unsigned int front_offset;
41270diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
41271index b0d0fd3..a6fbbe4 100644
41272--- a/drivers/gpu/drm/r128/r128_ioc32.c
41273+++ b/drivers/gpu/drm/r128/r128_ioc32.c
41274@@ -178,7 +178,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
41275 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
41276 }
41277
41278-drm_ioctl_compat_t *r128_compat_ioctls[] = {
41279+drm_ioctl_compat_t r128_compat_ioctls[] = {
41280 [DRM_R128_INIT] = compat_r128_init,
41281 [DRM_R128_DEPTH] = compat_r128_depth,
41282 [DRM_R128_STIPPLE] = compat_r128_stipple,
41283@@ -197,18 +197,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
41284 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41285 {
41286 unsigned int nr = DRM_IOCTL_NR(cmd);
41287- drm_ioctl_compat_t *fn = NULL;
41288 int ret;
41289
41290 if (nr < DRM_COMMAND_BASE)
41291 return drm_compat_ioctl(filp, cmd, arg);
41292
41293- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
41294- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
41295-
41296- if (fn != NULL)
41297+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
41298+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
41299 ret = (*fn) (filp, cmd, arg);
41300- else
41301+ } else
41302 ret = drm_ioctl(filp, cmd, arg);
41303
41304 return ret;
41305diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
41306index c2ae496..30b5993 100644
41307--- a/drivers/gpu/drm/r128/r128_irq.c
41308+++ b/drivers/gpu/drm/r128/r128_irq.c
41309@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
41310 if (crtc != 0)
41311 return 0;
41312
41313- return atomic_read(&dev_priv->vbl_received);
41314+ return atomic_read_unchecked(&dev_priv->vbl_received);
41315 }
41316
41317 irqreturn_t r128_driver_irq_handler(int irq, void *arg)
41318@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(int irq, void *arg)
41319 /* VBLANK interrupt */
41320 if (status & R128_CRTC_VBLANK_INT) {
41321 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
41322- atomic_inc(&dev_priv->vbl_received);
41323+ atomic_inc_unchecked(&dev_priv->vbl_received);
41324 drm_handle_vblank(dev, 0);
41325 return IRQ_HANDLED;
41326 }
41327diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
41328index e806dac..f81d32f 100644
41329--- a/drivers/gpu/drm/r128/r128_state.c
41330+++ b/drivers/gpu/drm/r128/r128_state.c
41331@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
41332
41333 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
41334 {
41335- if (atomic_read(&dev_priv->idle_count) == 0)
41336+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
41337 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
41338 else
41339- atomic_set(&dev_priv->idle_count, 0);
41340+ atomic_set_unchecked(&dev_priv->idle_count, 0);
41341 }
41342
41343 #endif
41344diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
41345index 4a85bb6..aaea819 100644
41346--- a/drivers/gpu/drm/radeon/mkregtable.c
41347+++ b/drivers/gpu/drm/radeon/mkregtable.c
41348@@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
41349 regex_t mask_rex;
41350 regmatch_t match[4];
41351 char buf[1024];
41352- size_t end;
41353+ long end;
41354 int len;
41355 int done = 0;
41356 int r;
41357 unsigned o;
41358 struct offset *offset;
41359 char last_reg_s[10];
41360- int last_reg;
41361+ unsigned long last_reg;
41362
41363 if (regcomp
41364 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
41365diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
41366index 044bc98..50ced9b 100644
41367--- a/drivers/gpu/drm/radeon/radeon_device.c
41368+++ b/drivers/gpu/drm/radeon/radeon_device.c
41369@@ -1125,7 +1125,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
41370 bool can_switch;
41371
41372 spin_lock(&dev->count_lock);
41373- can_switch = (dev->open_count == 0);
41374+ can_switch = (local_read(&dev->open_count) == 0);
41375 spin_unlock(&dev->count_lock);
41376 return can_switch;
41377 }
41378diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
41379index dafd812..1bf20c7 100644
41380--- a/drivers/gpu/drm/radeon/radeon_drv.h
41381+++ b/drivers/gpu/drm/radeon/radeon_drv.h
41382@@ -262,7 +262,7 @@ typedef struct drm_radeon_private {
41383
41384 /* SW interrupt */
41385 wait_queue_head_t swi_queue;
41386- atomic_t swi_emitted;
41387+ atomic_unchecked_t swi_emitted;
41388 int vblank_crtc;
41389 uint32_t irq_enable_reg;
41390 uint32_t r500_disp_irq_reg;
41391diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
41392index bdb0f93..5ff558f 100644
41393--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
41394+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
41395@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
41396 request = compat_alloc_user_space(sizeof(*request));
41397 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
41398 || __put_user(req32.param, &request->param)
41399- || __put_user((void __user *)(unsigned long)req32.value,
41400+ || __put_user((unsigned long)req32.value,
41401 &request->value))
41402 return -EFAULT;
41403
41404@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
41405 #define compat_radeon_cp_setparam NULL
41406 #endif /* X86_64 || IA64 */
41407
41408-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
41409+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
41410 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
41411 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
41412 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
41413@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
41414 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41415 {
41416 unsigned int nr = DRM_IOCTL_NR(cmd);
41417- drm_ioctl_compat_t *fn = NULL;
41418 int ret;
41419
41420 if (nr < DRM_COMMAND_BASE)
41421 return drm_compat_ioctl(filp, cmd, arg);
41422
41423- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
41424- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
41425-
41426- if (fn != NULL)
41427+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
41428+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
41429 ret = (*fn) (filp, cmd, arg);
41430- else
41431+ } else
41432 ret = drm_ioctl(filp, cmd, arg);
41433
41434 return ret;
41435diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
41436index 244b19b..c19226d 100644
41437--- a/drivers/gpu/drm/radeon/radeon_irq.c
41438+++ b/drivers/gpu/drm/radeon/radeon_irq.c
41439@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
41440 unsigned int ret;
41441 RING_LOCALS;
41442
41443- atomic_inc(&dev_priv->swi_emitted);
41444- ret = atomic_read(&dev_priv->swi_emitted);
41445+ atomic_inc_unchecked(&dev_priv->swi_emitted);
41446+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
41447
41448 BEGIN_RING(4);
41449 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
41450@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
41451 drm_radeon_private_t *dev_priv =
41452 (drm_radeon_private_t *) dev->dev_private;
41453
41454- atomic_set(&dev_priv->swi_emitted, 0);
41455+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
41456 init_waitqueue_head(&dev_priv->swi_queue);
41457
41458 dev->max_vblank_count = 0x001fffff;
41459diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
41460index 956ab7f..fbd36d8 100644
41461--- a/drivers/gpu/drm/radeon/radeon_state.c
41462+++ b/drivers/gpu/drm/radeon/radeon_state.c
41463@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
41464 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
41465 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
41466
41467- if (copy_from_user(&depth_boxes, clear->depth_boxes,
41468+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || copy_from_user(&depth_boxes, clear->depth_boxes,
41469 sarea_priv->nbox * sizeof(depth_boxes[0])))
41470 return -EFAULT;
41471
41472@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
41473 {
41474 drm_radeon_private_t *dev_priv = dev->dev_private;
41475 drm_radeon_getparam_t *param = data;
41476- int value;
41477+ int value = 0;
41478
41479 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
41480
41481diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
41482index 040a2a1..eae4e54 100644
41483--- a/drivers/gpu/drm/radeon/radeon_ttm.c
41484+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
41485@@ -790,7 +790,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
41486 man->size = size >> PAGE_SHIFT;
41487 }
41488
41489-static struct vm_operations_struct radeon_ttm_vm_ops;
41490+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
41491 static const struct vm_operations_struct *ttm_vm_ops = NULL;
41492
41493 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41494@@ -831,8 +831,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
41495 }
41496 if (unlikely(ttm_vm_ops == NULL)) {
41497 ttm_vm_ops = vma->vm_ops;
41498+ pax_open_kernel();
41499 radeon_ttm_vm_ops = *ttm_vm_ops;
41500 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
41501+ pax_close_kernel();
41502 }
41503 vma->vm_ops = &radeon_ttm_vm_ops;
41504 return 0;
41505diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
41506index 9336006..ce78aa7 100644
41507--- a/drivers/gpu/drm/tegra/dc.c
41508+++ b/drivers/gpu/drm/tegra/dc.c
41509@@ -1057,7 +1057,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
41510 }
41511
41512 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
41513- dc->debugfs_files[i].data = dc;
41514+ *(void **)&dc->debugfs_files[i].data = dc;
41515
41516 err = drm_debugfs_create_files(dc->debugfs_files,
41517 ARRAY_SIZE(debugfs_files),
41518diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c
41519index d452faab..f8cbc6a 100644
41520--- a/drivers/gpu/drm/tegra/dsi.c
41521+++ b/drivers/gpu/drm/tegra/dsi.c
41522@@ -53,7 +53,7 @@ struct tegra_dsi {
41523 struct clk *clk_lp;
41524 struct clk *clk;
41525
41526- struct drm_info_list *debugfs_files;
41527+ drm_info_list_no_const *debugfs_files;
41528 struct drm_minor *minor;
41529 struct dentry *debugfs;
41530
41531diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
41532index 6928015..c9853e7 100644
41533--- a/drivers/gpu/drm/tegra/hdmi.c
41534+++ b/drivers/gpu/drm/tegra/hdmi.c
41535@@ -59,7 +59,7 @@ struct tegra_hdmi {
41536 bool stereo;
41537 bool dvi;
41538
41539- struct drm_info_list *debugfs_files;
41540+ drm_info_list_no_const *debugfs_files;
41541 struct drm_minor *minor;
41542 struct dentry *debugfs;
41543 };
41544diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41545index c58eba33..83c2728 100644
41546--- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
41547+++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41548@@ -141,10 +141,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
41549 }
41550
41551 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
41552- ttm_bo_man_init,
41553- ttm_bo_man_takedown,
41554- ttm_bo_man_get_node,
41555- ttm_bo_man_put_node,
41556- ttm_bo_man_debug
41557+ .init = ttm_bo_man_init,
41558+ .takedown = ttm_bo_man_takedown,
41559+ .get_node = ttm_bo_man_get_node,
41560+ .put_node = ttm_bo_man_put_node,
41561+ .debug = ttm_bo_man_debug
41562 };
41563 EXPORT_SYMBOL(ttm_bo_manager_func);
41564diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
41565index dbc2def..0a9f710 100644
41566--- a/drivers/gpu/drm/ttm/ttm_memory.c
41567+++ b/drivers/gpu/drm/ttm/ttm_memory.c
41568@@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
41569 zone->glob = glob;
41570 glob->zone_kernel = zone;
41571 ret = kobject_init_and_add(
41572- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41573+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41574 if (unlikely(ret != 0)) {
41575 kobject_put(&zone->kobj);
41576 return ret;
41577@@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
41578 zone->glob = glob;
41579 glob->zone_dma32 = zone;
41580 ret = kobject_init_and_add(
41581- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41582+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41583 if (unlikely(ret != 0)) {
41584 kobject_put(&zone->kobj);
41585 return ret;
41586diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41587index 863bef9..cba15cf 100644
41588--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
41589+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41590@@ -391,9 +391,9 @@ out:
41591 static unsigned long
41592 ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41593 {
41594- static atomic_t start_pool = ATOMIC_INIT(0);
41595+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
41596 unsigned i;
41597- unsigned pool_offset = atomic_add_return(1, &start_pool);
41598+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
41599 struct ttm_page_pool *pool;
41600 int shrink_pages = sc->nr_to_scan;
41601 unsigned long freed = 0;
41602diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
41603index dbadd49..1b7457b 100644
41604--- a/drivers/gpu/drm/udl/udl_fb.c
41605+++ b/drivers/gpu/drm/udl/udl_fb.c
41606@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
41607 fb_deferred_io_cleanup(info);
41608 kfree(info->fbdefio);
41609 info->fbdefio = NULL;
41610- info->fbops->fb_mmap = udl_fb_mmap;
41611 }
41612
41613 pr_warn("released /dev/fb%d user=%d count=%d\n",
41614diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
41615index ad02732..144f5ed 100644
41616--- a/drivers/gpu/drm/via/via_drv.h
41617+++ b/drivers/gpu/drm/via/via_drv.h
41618@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
41619 typedef uint32_t maskarray_t[5];
41620
41621 typedef struct drm_via_irq {
41622- atomic_t irq_received;
41623+ atomic_unchecked_t irq_received;
41624 uint32_t pending_mask;
41625 uint32_t enable_mask;
41626 wait_queue_head_t irq_queue;
41627@@ -75,7 +75,7 @@ typedef struct drm_via_private {
41628 struct timeval last_vblank;
41629 int last_vblank_valid;
41630 unsigned usec_per_vblank;
41631- atomic_t vbl_received;
41632+ atomic_unchecked_t vbl_received;
41633 drm_via_state_t hc_state;
41634 char pci_buf[VIA_PCI_BUF_SIZE];
41635 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
41636diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
41637index 1319433..a993b0c 100644
41638--- a/drivers/gpu/drm/via/via_irq.c
41639+++ b/drivers/gpu/drm/via/via_irq.c
41640@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
41641 if (crtc != 0)
41642 return 0;
41643
41644- return atomic_read(&dev_priv->vbl_received);
41645+ return atomic_read_unchecked(&dev_priv->vbl_received);
41646 }
41647
41648 irqreturn_t via_driver_irq_handler(int irq, void *arg)
41649@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41650
41651 status = VIA_READ(VIA_REG_INTERRUPT);
41652 if (status & VIA_IRQ_VBLANK_PENDING) {
41653- atomic_inc(&dev_priv->vbl_received);
41654- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
41655+ atomic_inc_unchecked(&dev_priv->vbl_received);
41656+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
41657 do_gettimeofday(&cur_vblank);
41658 if (dev_priv->last_vblank_valid) {
41659 dev_priv->usec_per_vblank =
41660@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41661 dev_priv->last_vblank = cur_vblank;
41662 dev_priv->last_vblank_valid = 1;
41663 }
41664- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
41665+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
41666 DRM_DEBUG("US per vblank is: %u\n",
41667 dev_priv->usec_per_vblank);
41668 }
41669@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41670
41671 for (i = 0; i < dev_priv->num_irqs; ++i) {
41672 if (status & cur_irq->pending_mask) {
41673- atomic_inc(&cur_irq->irq_received);
41674+ atomic_inc_unchecked(&cur_irq->irq_received);
41675 wake_up(&cur_irq->irq_queue);
41676 handled = 1;
41677 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
41678@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
41679 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41680 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
41681 masks[irq][4]));
41682- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
41683+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
41684 } else {
41685 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41686 (((cur_irq_sequence =
41687- atomic_read(&cur_irq->irq_received)) -
41688+ atomic_read_unchecked(&cur_irq->irq_received)) -
41689 *sequence) <= (1 << 23)));
41690 }
41691 *sequence = cur_irq_sequence;
41692@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
41693 }
41694
41695 for (i = 0; i < dev_priv->num_irqs; ++i) {
41696- atomic_set(&cur_irq->irq_received, 0);
41697+ atomic_set_unchecked(&cur_irq->irq_received, 0);
41698 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
41699 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
41700 init_waitqueue_head(&cur_irq->irq_queue);
41701@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
41702 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
41703 case VIA_IRQ_RELATIVE:
41704 irqwait->request.sequence +=
41705- atomic_read(&cur_irq->irq_received);
41706+ atomic_read_unchecked(&cur_irq->irq_received);
41707 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
41708 case VIA_IRQ_ABSOLUTE:
41709 break;
41710diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41711index 0783155..b29e18e 100644
41712--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41713+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41714@@ -437,7 +437,7 @@ struct vmw_private {
41715 * Fencing and IRQs.
41716 */
41717
41718- atomic_t marker_seq;
41719+ atomic_unchecked_t marker_seq;
41720 wait_queue_head_t fence_queue;
41721 wait_queue_head_t fifo_queue;
41722 int fence_queue_waiters; /* Protected by hw_mutex */
41723diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41724index 6ccd993..618d592 100644
41725--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41726+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41727@@ -154,7 +154,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
41728 (unsigned int) min,
41729 (unsigned int) fifo->capabilities);
41730
41731- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41732+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41733 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
41734 vmw_marker_queue_init(&fifo->marker_queue);
41735 return vmw_fifo_send_fence(dev_priv, &dummy);
41736@@ -372,7 +372,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
41737 if (reserveable)
41738 iowrite32(bytes, fifo_mem +
41739 SVGA_FIFO_RESERVED);
41740- return fifo_mem + (next_cmd >> 2);
41741+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
41742 } else {
41743 need_bounce = true;
41744 }
41745@@ -492,7 +492,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41746
41747 fm = vmw_fifo_reserve(dev_priv, bytes);
41748 if (unlikely(fm == NULL)) {
41749- *seqno = atomic_read(&dev_priv->marker_seq);
41750+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41751 ret = -ENOMEM;
41752 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
41753 false, 3*HZ);
41754@@ -500,7 +500,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41755 }
41756
41757 do {
41758- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
41759+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
41760 } while (*seqno == 0);
41761
41762 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
41763diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41764index b1273e8..9c274fd 100644
41765--- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41766+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41767@@ -164,9 +164,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
41768 }
41769
41770 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
41771- vmw_gmrid_man_init,
41772- vmw_gmrid_man_takedown,
41773- vmw_gmrid_man_get_node,
41774- vmw_gmrid_man_put_node,
41775- vmw_gmrid_man_debug
41776+ .init = vmw_gmrid_man_init,
41777+ .takedown = vmw_gmrid_man_takedown,
41778+ .get_node = vmw_gmrid_man_get_node,
41779+ .put_node = vmw_gmrid_man_put_node,
41780+ .debug = vmw_gmrid_man_debug
41781 };
41782diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41783index 47b7094..698ba09 100644
41784--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41785+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41786@@ -236,7 +236,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
41787 int ret;
41788
41789 num_clips = arg->num_clips;
41790- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41791+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41792
41793 if (unlikely(num_clips == 0))
41794 return 0;
41795@@ -320,7 +320,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
41796 int ret;
41797
41798 num_clips = arg->num_clips;
41799- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41800+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41801
41802 if (unlikely(num_clips == 0))
41803 return 0;
41804diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41805index 0c42376..6febe77 100644
41806--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41807+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41808@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
41809 * emitted. Then the fence is stale and signaled.
41810 */
41811
41812- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
41813+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
41814 > VMW_FENCE_WRAP);
41815
41816 return ret;
41817@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
41818
41819 if (fifo_idle)
41820 down_read(&fifo_state->rwsem);
41821- signal_seq = atomic_read(&dev_priv->marker_seq);
41822+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
41823 ret = 0;
41824
41825 for (;;) {
41826diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41827index 8a8725c2..afed796 100644
41828--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41829+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41830@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
41831 while (!vmw_lag_lt(queue, us)) {
41832 spin_lock(&queue->lock);
41833 if (list_empty(&queue->head))
41834- seqno = atomic_read(&dev_priv->marker_seq);
41835+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41836 else {
41837 marker = list_first_entry(&queue->head,
41838 struct vmw_marker, head);
41839diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
41840index ec0ae2d..dc0780b 100644
41841--- a/drivers/gpu/vga/vga_switcheroo.c
41842+++ b/drivers/gpu/vga/vga_switcheroo.c
41843@@ -643,7 +643,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
41844
41845 /* this version is for the case where the power switch is separate
41846 to the device being powered down. */
41847-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
41848+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
41849 {
41850 /* copy over all the bus versions */
41851 if (dev->bus && dev->bus->pm) {
41852@@ -688,7 +688,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
41853 return ret;
41854 }
41855
41856-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
41857+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
41858 {
41859 /* copy over all the bus versions */
41860 if (dev->bus && dev->bus->pm) {
41861diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
41862index cc32a6f..02a4b1c 100644
41863--- a/drivers/hid/hid-core.c
41864+++ b/drivers/hid/hid-core.c
41865@@ -2421,7 +2421,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
41866
41867 int hid_add_device(struct hid_device *hdev)
41868 {
41869- static atomic_t id = ATOMIC_INIT(0);
41870+ static atomic_unchecked_t id = ATOMIC_INIT(0);
41871 int ret;
41872
41873 if (WARN_ON(hdev->status & HID_STAT_ADDED))
41874@@ -2455,7 +2455,7 @@ int hid_add_device(struct hid_device *hdev)
41875 /* XXX hack, any other cleaner solution after the driver core
41876 * is converted to allow more than 20 bytes as the device name? */
41877 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
41878- hdev->vendor, hdev->product, atomic_inc_return(&id));
41879+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
41880
41881 hid_debug_register(hdev, dev_name(&hdev->dev));
41882 ret = device_add(&hdev->dev);
41883diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
41884index c13fb5b..55a3802 100644
41885--- a/drivers/hid/hid-wiimote-debug.c
41886+++ b/drivers/hid/hid-wiimote-debug.c
41887@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
41888 else if (size == 0)
41889 return -EIO;
41890
41891- if (copy_to_user(u, buf, size))
41892+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
41893 return -EFAULT;
41894
41895 *off += size;
41896diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
41897index cedc6da..2c3da2a 100644
41898--- a/drivers/hid/uhid.c
41899+++ b/drivers/hid/uhid.c
41900@@ -47,7 +47,7 @@ struct uhid_device {
41901 struct mutex report_lock;
41902 wait_queue_head_t report_wait;
41903 atomic_t report_done;
41904- atomic_t report_id;
41905+ atomic_unchecked_t report_id;
41906 struct uhid_event report_buf;
41907 };
41908
41909@@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
41910
41911 spin_lock_irqsave(&uhid->qlock, flags);
41912 ev->type = UHID_FEATURE;
41913- ev->u.feature.id = atomic_inc_return(&uhid->report_id);
41914+ ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
41915 ev->u.feature.rnum = rnum;
41916 ev->u.feature.rtype = report_type;
41917
41918@@ -446,7 +446,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
41919 spin_lock_irqsave(&uhid->qlock, flags);
41920
41921 /* id for old report; drop it silently */
41922- if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
41923+ if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
41924 goto unlock;
41925 if (atomic_read(&uhid->report_done))
41926 goto unlock;
41927diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
41928index 69ea36f..8dbf4bb 100644
41929--- a/drivers/hv/channel.c
41930+++ b/drivers/hv/channel.c
41931@@ -364,8 +364,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
41932 int ret = 0;
41933 int t;
41934
41935- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
41936- atomic_inc(&vmbus_connection.next_gpadl_handle);
41937+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
41938+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
41939
41940 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
41941 if (ret)
41942diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
41943index bcb4950..61dba6c 100644
41944--- a/drivers/hv/hv.c
41945+++ b/drivers/hv/hv.c
41946@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
41947 u64 output_address = (output) ? virt_to_phys(output) : 0;
41948 u32 output_address_hi = output_address >> 32;
41949 u32 output_address_lo = output_address & 0xFFFFFFFF;
41950- void *hypercall_page = hv_context.hypercall_page;
41951+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
41952
41953 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
41954 "=a"(hv_status_lo) : "d" (control_hi),
41955@@ -154,7 +154,7 @@ int hv_init(void)
41956 /* See if the hypercall page is already set */
41957 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
41958
41959- virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
41960+ virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
41961
41962 if (!virtaddr)
41963 goto cleanup;
41964diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
41965index 7e17a54..a50a33d 100644
41966--- a/drivers/hv/hv_balloon.c
41967+++ b/drivers/hv/hv_balloon.c
41968@@ -464,7 +464,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
41969
41970 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
41971 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
41972-static atomic_t trans_id = ATOMIC_INIT(0);
41973+static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
41974
41975 static int dm_ring_size = (5 * PAGE_SIZE);
41976
41977@@ -886,7 +886,7 @@ static void hot_add_req(struct work_struct *dummy)
41978 pr_info("Memory hot add failed\n");
41979
41980 dm->state = DM_INITIALIZED;
41981- resp.hdr.trans_id = atomic_inc_return(&trans_id);
41982+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41983 vmbus_sendpacket(dm->dev->channel, &resp,
41984 sizeof(struct dm_hot_add_response),
41985 (unsigned long)NULL,
41986@@ -960,7 +960,7 @@ static void post_status(struct hv_dynmem_device *dm)
41987 memset(&status, 0, sizeof(struct dm_status));
41988 status.hdr.type = DM_STATUS_REPORT;
41989 status.hdr.size = sizeof(struct dm_status);
41990- status.hdr.trans_id = atomic_inc_return(&trans_id);
41991+ status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41992
41993 /*
41994 * The host expects the guest to report free memory.
41995@@ -980,7 +980,7 @@ static void post_status(struct hv_dynmem_device *dm)
41996 * send the status. This can happen if we were interrupted
41997 * after we picked our transaction ID.
41998 */
41999- if (status.hdr.trans_id != atomic_read(&trans_id))
42000+ if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
42001 return;
42002
42003 vmbus_sendpacket(dm->dev->channel, &status,
42004@@ -1108,7 +1108,7 @@ static void balloon_up(struct work_struct *dummy)
42005 */
42006
42007 do {
42008- bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
42009+ bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42010 ret = vmbus_sendpacket(dm_device.dev->channel,
42011 bl_resp,
42012 bl_resp->hdr.size,
42013@@ -1152,7 +1152,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
42014
42015 memset(&resp, 0, sizeof(struct dm_unballoon_response));
42016 resp.hdr.type = DM_UNBALLOON_RESPONSE;
42017- resp.hdr.trans_id = atomic_inc_return(&trans_id);
42018+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42019 resp.hdr.size = sizeof(struct dm_unballoon_response);
42020
42021 vmbus_sendpacket(dm_device.dev->channel, &resp,
42022@@ -1215,7 +1215,7 @@ static void version_resp(struct hv_dynmem_device *dm,
42023 memset(&version_req, 0, sizeof(struct dm_version_request));
42024 version_req.hdr.type = DM_VERSION_REQUEST;
42025 version_req.hdr.size = sizeof(struct dm_version_request);
42026- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
42027+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42028 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
42029 version_req.is_last_attempt = 1;
42030
42031@@ -1385,7 +1385,7 @@ static int balloon_probe(struct hv_device *dev,
42032 memset(&version_req, 0, sizeof(struct dm_version_request));
42033 version_req.hdr.type = DM_VERSION_REQUEST;
42034 version_req.hdr.size = sizeof(struct dm_version_request);
42035- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
42036+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42037 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
42038 version_req.is_last_attempt = 0;
42039
42040@@ -1416,7 +1416,7 @@ static int balloon_probe(struct hv_device *dev,
42041 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
42042 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
42043 cap_msg.hdr.size = sizeof(struct dm_capabilities);
42044- cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
42045+ cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42046
42047 cap_msg.caps.cap_bits.balloon = 1;
42048 cap_msg.caps.cap_bits.hot_add = 1;
42049diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
42050index e055176..c22ff1f 100644
42051--- a/drivers/hv/hyperv_vmbus.h
42052+++ b/drivers/hv/hyperv_vmbus.h
42053@@ -602,7 +602,7 @@ enum vmbus_connect_state {
42054 struct vmbus_connection {
42055 enum vmbus_connect_state conn_state;
42056
42057- atomic_t next_gpadl_handle;
42058+ atomic_unchecked_t next_gpadl_handle;
42059
42060 /*
42061 * Represents channel interrupts. Each bit position represents a
42062diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
42063index 077bb1b..d433d74 100644
42064--- a/drivers/hv/vmbus_drv.c
42065+++ b/drivers/hv/vmbus_drv.c
42066@@ -844,10 +844,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
42067 {
42068 int ret = 0;
42069
42070- static atomic_t device_num = ATOMIC_INIT(0);
42071+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
42072
42073 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
42074- atomic_inc_return(&device_num));
42075+ atomic_inc_return_unchecked(&device_num));
42076
42077 child_device_obj->device.bus = &hv_bus;
42078 child_device_obj->device.parent = &hv_acpi_dev->dev;
42079diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
42080index 579bdf9..75118b5 100644
42081--- a/drivers/hwmon/acpi_power_meter.c
42082+++ b/drivers/hwmon/acpi_power_meter.c
42083@@ -116,7 +116,7 @@ struct sensor_template {
42084 struct device_attribute *devattr,
42085 const char *buf, size_t count);
42086 int index;
42087-};
42088+} __do_const;
42089
42090 /* Averaging interval */
42091 static int update_avg_interval(struct acpi_power_meter_resource *resource)
42092@@ -631,7 +631,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
42093 struct sensor_template *attrs)
42094 {
42095 struct device *dev = &resource->acpi_dev->dev;
42096- struct sensor_device_attribute *sensors =
42097+ sensor_device_attribute_no_const *sensors =
42098 &resource->sensors[resource->num_sensors];
42099 int res = 0;
42100
42101diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
42102index 3288f13..71cfb4e 100644
42103--- a/drivers/hwmon/applesmc.c
42104+++ b/drivers/hwmon/applesmc.c
42105@@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
42106 {
42107 struct applesmc_node_group *grp;
42108 struct applesmc_dev_attr *node;
42109- struct attribute *attr;
42110+ attribute_no_const *attr;
42111 int ret, i;
42112
42113 for (grp = groups; grp->format; grp++) {
42114diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
42115index ae208f6..48b6c5b 100644
42116--- a/drivers/hwmon/asus_atk0110.c
42117+++ b/drivers/hwmon/asus_atk0110.c
42118@@ -147,10 +147,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
42119 struct atk_sensor_data {
42120 struct list_head list;
42121 struct atk_data *data;
42122- struct device_attribute label_attr;
42123- struct device_attribute input_attr;
42124- struct device_attribute limit1_attr;
42125- struct device_attribute limit2_attr;
42126+ device_attribute_no_const label_attr;
42127+ device_attribute_no_const input_attr;
42128+ device_attribute_no_const limit1_attr;
42129+ device_attribute_no_const limit2_attr;
42130 char label_attr_name[ATTR_NAME_SIZE];
42131 char input_attr_name[ATTR_NAME_SIZE];
42132 char limit1_attr_name[ATTR_NAME_SIZE];
42133@@ -270,7 +270,7 @@ static ssize_t atk_name_show(struct device *dev,
42134 static struct device_attribute atk_name_attr =
42135 __ATTR(name, 0444, atk_name_show, NULL);
42136
42137-static void atk_init_attribute(struct device_attribute *attr, char *name,
42138+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
42139 sysfs_show_func show)
42140 {
42141 sysfs_attr_init(&attr->attr);
42142diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
42143index bbb0b0d..9fe1332 100644
42144--- a/drivers/hwmon/coretemp.c
42145+++ b/drivers/hwmon/coretemp.c
42146@@ -823,7 +823,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
42147 return NOTIFY_OK;
42148 }
42149
42150-static struct notifier_block coretemp_cpu_notifier __refdata = {
42151+static struct notifier_block coretemp_cpu_notifier = {
42152 .notifier_call = coretemp_cpu_callback,
42153 };
42154
42155diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
42156index 632f1dc..57e6a58 100644
42157--- a/drivers/hwmon/ibmaem.c
42158+++ b/drivers/hwmon/ibmaem.c
42159@@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
42160 struct aem_rw_sensor_template *rw)
42161 {
42162 struct device *dev = &data->pdev->dev;
42163- struct sensor_device_attribute *sensors = data->sensors;
42164+ sensor_device_attribute_no_const *sensors = data->sensors;
42165 int err;
42166
42167 /* Set up read-only sensors */
42168diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
42169index 708081b..fe2d4ab 100644
42170--- a/drivers/hwmon/iio_hwmon.c
42171+++ b/drivers/hwmon/iio_hwmon.c
42172@@ -73,7 +73,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
42173 {
42174 struct device *dev = &pdev->dev;
42175 struct iio_hwmon_state *st;
42176- struct sensor_device_attribute *a;
42177+ sensor_device_attribute_no_const *a;
42178 int ret, i;
42179 int in_i = 1, temp_i = 1, curr_i = 1;
42180 enum iio_chan_type type;
42181diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
42182index 38d5a63..cf2c2ea 100644
42183--- a/drivers/hwmon/nct6775.c
42184+++ b/drivers/hwmon/nct6775.c
42185@@ -944,10 +944,10 @@ static struct attribute_group *
42186 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
42187 int repeat)
42188 {
42189- struct attribute_group *group;
42190+ attribute_group_no_const *group;
42191 struct sensor_device_attr_u *su;
42192- struct sensor_device_attribute *a;
42193- struct sensor_device_attribute_2 *a2;
42194+ sensor_device_attribute_no_const *a;
42195+ sensor_device_attribute_2_no_const *a2;
42196 struct attribute **attrs;
42197 struct sensor_device_template **t;
42198 int i, count;
42199diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
42200index 291d11f..3f0dbbd 100644
42201--- a/drivers/hwmon/pmbus/pmbus_core.c
42202+++ b/drivers/hwmon/pmbus/pmbus_core.c
42203@@ -783,7 +783,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
42204 return 0;
42205 }
42206
42207-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
42208+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
42209 const char *name,
42210 umode_t mode,
42211 ssize_t (*show)(struct device *dev,
42212@@ -800,7 +800,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
42213 dev_attr->store = store;
42214 }
42215
42216-static void pmbus_attr_init(struct sensor_device_attribute *a,
42217+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
42218 const char *name,
42219 umode_t mode,
42220 ssize_t (*show)(struct device *dev,
42221@@ -822,7 +822,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
42222 u16 reg, u8 mask)
42223 {
42224 struct pmbus_boolean *boolean;
42225- struct sensor_device_attribute *a;
42226+ sensor_device_attribute_no_const *a;
42227
42228 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
42229 if (!boolean)
42230@@ -847,7 +847,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
42231 bool update, bool readonly)
42232 {
42233 struct pmbus_sensor *sensor;
42234- struct device_attribute *a;
42235+ device_attribute_no_const *a;
42236
42237 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
42238 if (!sensor)
42239@@ -878,7 +878,7 @@ static int pmbus_add_label(struct pmbus_data *data,
42240 const char *lstring, int index)
42241 {
42242 struct pmbus_label *label;
42243- struct device_attribute *a;
42244+ device_attribute_no_const *a;
42245
42246 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
42247 if (!label)
42248diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
42249index 97cd45a..ac54d8b 100644
42250--- a/drivers/hwmon/sht15.c
42251+++ b/drivers/hwmon/sht15.c
42252@@ -169,7 +169,7 @@ struct sht15_data {
42253 int supply_uv;
42254 bool supply_uv_valid;
42255 struct work_struct update_supply_work;
42256- atomic_t interrupt_handled;
42257+ atomic_unchecked_t interrupt_handled;
42258 };
42259
42260 /**
42261@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
42262 ret = gpio_direction_input(data->pdata->gpio_data);
42263 if (ret)
42264 return ret;
42265- atomic_set(&data->interrupt_handled, 0);
42266+ atomic_set_unchecked(&data->interrupt_handled, 0);
42267
42268 enable_irq(gpio_to_irq(data->pdata->gpio_data));
42269 if (gpio_get_value(data->pdata->gpio_data) == 0) {
42270 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
42271 /* Only relevant if the interrupt hasn't occurred. */
42272- if (!atomic_read(&data->interrupt_handled))
42273+ if (!atomic_read_unchecked(&data->interrupt_handled))
42274 schedule_work(&data->read_work);
42275 }
42276 ret = wait_event_timeout(data->wait_queue,
42277@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
42278
42279 /* First disable the interrupt */
42280 disable_irq_nosync(irq);
42281- atomic_inc(&data->interrupt_handled);
42282+ atomic_inc_unchecked(&data->interrupt_handled);
42283 /* Then schedule a reading work struct */
42284 if (data->state != SHT15_READING_NOTHING)
42285 schedule_work(&data->read_work);
42286@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
42287 * If not, then start the interrupt again - care here as could
42288 * have gone low in meantime so verify it hasn't!
42289 */
42290- atomic_set(&data->interrupt_handled, 0);
42291+ atomic_set_unchecked(&data->interrupt_handled, 0);
42292 enable_irq(gpio_to_irq(data->pdata->gpio_data));
42293 /* If still not occurred or another handler was scheduled */
42294 if (gpio_get_value(data->pdata->gpio_data)
42295- || atomic_read(&data->interrupt_handled))
42296+ || atomic_read_unchecked(&data->interrupt_handled))
42297 return;
42298 }
42299
42300diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
42301index 38944e9..ae9e5ed 100644
42302--- a/drivers/hwmon/via-cputemp.c
42303+++ b/drivers/hwmon/via-cputemp.c
42304@@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
42305 return NOTIFY_OK;
42306 }
42307
42308-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
42309+static struct notifier_block via_cputemp_cpu_notifier = {
42310 .notifier_call = via_cputemp_cpu_callback,
42311 };
42312
42313diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
42314index 41fc683..a39cfea 100644
42315--- a/drivers/i2c/busses/i2c-amd756-s4882.c
42316+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
42317@@ -43,7 +43,7 @@
42318 extern struct i2c_adapter amd756_smbus;
42319
42320 static struct i2c_adapter *s4882_adapter;
42321-static struct i2c_algorithm *s4882_algo;
42322+static i2c_algorithm_no_const *s4882_algo;
42323
42324 /* Wrapper access functions for multiplexed SMBus */
42325 static DEFINE_MUTEX(amd756_lock);
42326diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
42327index 721f7eb..0fd2a09 100644
42328--- a/drivers/i2c/busses/i2c-diolan-u2c.c
42329+++ b/drivers/i2c/busses/i2c-diolan-u2c.c
42330@@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
42331 /* usb layer */
42332
42333 /* Send command to device, and get response. */
42334-static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
42335+static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
42336 {
42337 int ret = 0;
42338 int actual;
42339diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
42340index b170bdf..3c76427 100644
42341--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
42342+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
42343@@ -41,7 +41,7 @@
42344 extern struct i2c_adapter *nforce2_smbus;
42345
42346 static struct i2c_adapter *s4985_adapter;
42347-static struct i2c_algorithm *s4985_algo;
42348+static i2c_algorithm_no_const *s4985_algo;
42349
42350 /* Wrapper access functions for multiplexed SMBus */
42351 static DEFINE_MUTEX(nforce2_lock);
42352diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
42353index 80b47e8..1a6040d9 100644
42354--- a/drivers/i2c/i2c-dev.c
42355+++ b/drivers/i2c/i2c-dev.c
42356@@ -277,7 +277,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
42357 break;
42358 }
42359
42360- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
42361+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
42362 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
42363 if (IS_ERR(rdwr_pa[i].buf)) {
42364 res = PTR_ERR(rdwr_pa[i].buf);
42365diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
42366index 0b510ba..4fbb5085 100644
42367--- a/drivers/ide/ide-cd.c
42368+++ b/drivers/ide/ide-cd.c
42369@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
42370 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
42371 if ((unsigned long)buf & alignment
42372 || blk_rq_bytes(rq) & q->dma_pad_mask
42373- || object_is_on_stack(buf))
42374+ || object_starts_on_stack(buf))
42375 drive->dma = 0;
42376 }
42377 }
42378diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
42379index acc911a..8700c3c 100644
42380--- a/drivers/iio/industrialio-core.c
42381+++ b/drivers/iio/industrialio-core.c
42382@@ -527,7 +527,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
42383 }
42384
42385 static
42386-int __iio_device_attr_init(struct device_attribute *dev_attr,
42387+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
42388 const char *postfix,
42389 struct iio_chan_spec const *chan,
42390 ssize_t (*readfunc)(struct device *dev,
42391diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
42392index c323917..6ddea8b 100644
42393--- a/drivers/infiniband/core/cm.c
42394+++ b/drivers/infiniband/core/cm.c
42395@@ -115,7 +115,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
42396
42397 struct cm_counter_group {
42398 struct kobject obj;
42399- atomic_long_t counter[CM_ATTR_COUNT];
42400+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
42401 };
42402
42403 struct cm_counter_attribute {
42404@@ -1398,7 +1398,7 @@ static void cm_dup_req_handler(struct cm_work *work,
42405 struct ib_mad_send_buf *msg = NULL;
42406 int ret;
42407
42408- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42409+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42410 counter[CM_REQ_COUNTER]);
42411
42412 /* Quick state check to discard duplicate REQs. */
42413@@ -1785,7 +1785,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
42414 if (!cm_id_priv)
42415 return;
42416
42417- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42418+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42419 counter[CM_REP_COUNTER]);
42420 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
42421 if (ret)
42422@@ -1952,7 +1952,7 @@ static int cm_rtu_handler(struct cm_work *work)
42423 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
42424 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
42425 spin_unlock_irq(&cm_id_priv->lock);
42426- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42427+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42428 counter[CM_RTU_COUNTER]);
42429 goto out;
42430 }
42431@@ -2135,7 +2135,7 @@ static int cm_dreq_handler(struct cm_work *work)
42432 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
42433 dreq_msg->local_comm_id);
42434 if (!cm_id_priv) {
42435- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42436+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42437 counter[CM_DREQ_COUNTER]);
42438 cm_issue_drep(work->port, work->mad_recv_wc);
42439 return -EINVAL;
42440@@ -2160,7 +2160,7 @@ static int cm_dreq_handler(struct cm_work *work)
42441 case IB_CM_MRA_REP_RCVD:
42442 break;
42443 case IB_CM_TIMEWAIT:
42444- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42445+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42446 counter[CM_DREQ_COUNTER]);
42447 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42448 goto unlock;
42449@@ -2174,7 +2174,7 @@ static int cm_dreq_handler(struct cm_work *work)
42450 cm_free_msg(msg);
42451 goto deref;
42452 case IB_CM_DREQ_RCVD:
42453- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42454+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42455 counter[CM_DREQ_COUNTER]);
42456 goto unlock;
42457 default:
42458@@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
42459 ib_modify_mad(cm_id_priv->av.port->mad_agent,
42460 cm_id_priv->msg, timeout)) {
42461 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
42462- atomic_long_inc(&work->port->
42463+ atomic_long_inc_unchecked(&work->port->
42464 counter_group[CM_RECV_DUPLICATES].
42465 counter[CM_MRA_COUNTER]);
42466 goto out;
42467@@ -2550,7 +2550,7 @@ static int cm_mra_handler(struct cm_work *work)
42468 break;
42469 case IB_CM_MRA_REQ_RCVD:
42470 case IB_CM_MRA_REP_RCVD:
42471- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42472+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42473 counter[CM_MRA_COUNTER]);
42474 /* fall through */
42475 default:
42476@@ -2712,7 +2712,7 @@ static int cm_lap_handler(struct cm_work *work)
42477 case IB_CM_LAP_IDLE:
42478 break;
42479 case IB_CM_MRA_LAP_SENT:
42480- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42481+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42482 counter[CM_LAP_COUNTER]);
42483 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42484 goto unlock;
42485@@ -2728,7 +2728,7 @@ static int cm_lap_handler(struct cm_work *work)
42486 cm_free_msg(msg);
42487 goto deref;
42488 case IB_CM_LAP_RCVD:
42489- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42490+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42491 counter[CM_LAP_COUNTER]);
42492 goto unlock;
42493 default:
42494@@ -3012,7 +3012,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
42495 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
42496 if (cur_cm_id_priv) {
42497 spin_unlock_irq(&cm.lock);
42498- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42499+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42500 counter[CM_SIDR_REQ_COUNTER]);
42501 goto out; /* Duplicate message. */
42502 }
42503@@ -3224,10 +3224,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
42504 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
42505 msg->retries = 1;
42506
42507- atomic_long_add(1 + msg->retries,
42508+ atomic_long_add_unchecked(1 + msg->retries,
42509 &port->counter_group[CM_XMIT].counter[attr_index]);
42510 if (msg->retries)
42511- atomic_long_add(msg->retries,
42512+ atomic_long_add_unchecked(msg->retries,
42513 &port->counter_group[CM_XMIT_RETRIES].
42514 counter[attr_index]);
42515
42516@@ -3437,7 +3437,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
42517 }
42518
42519 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
42520- atomic_long_inc(&port->counter_group[CM_RECV].
42521+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
42522 counter[attr_id - CM_ATTR_ID_OFFSET]);
42523
42524 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
42525@@ -3668,7 +3668,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
42526 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
42527
42528 return sprintf(buf, "%ld\n",
42529- atomic_long_read(&group->counter[cm_attr->index]));
42530+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
42531 }
42532
42533 static const struct sysfs_ops cm_counter_ops = {
42534diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
42535index 9f5ad7c..588cd84 100644
42536--- a/drivers/infiniband/core/fmr_pool.c
42537+++ b/drivers/infiniband/core/fmr_pool.c
42538@@ -98,8 +98,8 @@ struct ib_fmr_pool {
42539
42540 struct task_struct *thread;
42541
42542- atomic_t req_ser;
42543- atomic_t flush_ser;
42544+ atomic_unchecked_t req_ser;
42545+ atomic_unchecked_t flush_ser;
42546
42547 wait_queue_head_t force_wait;
42548 };
42549@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42550 struct ib_fmr_pool *pool = pool_ptr;
42551
42552 do {
42553- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
42554+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
42555 ib_fmr_batch_release(pool);
42556
42557- atomic_inc(&pool->flush_ser);
42558+ atomic_inc_unchecked(&pool->flush_ser);
42559 wake_up_interruptible(&pool->force_wait);
42560
42561 if (pool->flush_function)
42562@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42563 }
42564
42565 set_current_state(TASK_INTERRUPTIBLE);
42566- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
42567+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
42568 !kthread_should_stop())
42569 schedule();
42570 __set_current_state(TASK_RUNNING);
42571@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
42572 pool->dirty_watermark = params->dirty_watermark;
42573 pool->dirty_len = 0;
42574 spin_lock_init(&pool->pool_lock);
42575- atomic_set(&pool->req_ser, 0);
42576- atomic_set(&pool->flush_ser, 0);
42577+ atomic_set_unchecked(&pool->req_ser, 0);
42578+ atomic_set_unchecked(&pool->flush_ser, 0);
42579 init_waitqueue_head(&pool->force_wait);
42580
42581 pool->thread = kthread_run(ib_fmr_cleanup_thread,
42582@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
42583 }
42584 spin_unlock_irq(&pool->pool_lock);
42585
42586- serial = atomic_inc_return(&pool->req_ser);
42587+ serial = atomic_inc_return_unchecked(&pool->req_ser);
42588 wake_up_process(pool->thread);
42589
42590 if (wait_event_interruptible(pool->force_wait,
42591- atomic_read(&pool->flush_ser) - serial >= 0))
42592+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
42593 return -EINTR;
42594
42595 return 0;
42596@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
42597 } else {
42598 list_add_tail(&fmr->list, &pool->dirty_list);
42599 if (++pool->dirty_len >= pool->dirty_watermark) {
42600- atomic_inc(&pool->req_ser);
42601+ atomic_inc_unchecked(&pool->req_ser);
42602 wake_up_process(pool->thread);
42603 }
42604 }
42605diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
42606index 41b1195..27971a0 100644
42607--- a/drivers/infiniband/hw/cxgb4/mem.c
42608+++ b/drivers/infiniband/hw/cxgb4/mem.c
42609@@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42610 int err;
42611 struct fw_ri_tpte tpt;
42612 u32 stag_idx;
42613- static atomic_t key;
42614+ static atomic_unchecked_t key;
42615
42616 if (c4iw_fatal_error(rdev))
42617 return -EIO;
42618@@ -266,7 +266,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42619 if (rdev->stats.stag.cur > rdev->stats.stag.max)
42620 rdev->stats.stag.max = rdev->stats.stag.cur;
42621 mutex_unlock(&rdev->stats.lock);
42622- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
42623+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
42624 }
42625 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
42626 __func__, stag_state, type, pdid, stag_idx);
42627diff --git a/drivers/infiniband/hw/ipath/ipath_dma.c b/drivers/infiniband/hw/ipath/ipath_dma.c
42628index 644c2c7..ecf0879 100644
42629--- a/drivers/infiniband/hw/ipath/ipath_dma.c
42630+++ b/drivers/infiniband/hw/ipath/ipath_dma.c
42631@@ -176,17 +176,17 @@ static void ipath_dma_free_coherent(struct ib_device *dev, size_t size,
42632 }
42633
42634 struct ib_dma_mapping_ops ipath_dma_mapping_ops = {
42635- ipath_mapping_error,
42636- ipath_dma_map_single,
42637- ipath_dma_unmap_single,
42638- ipath_dma_map_page,
42639- ipath_dma_unmap_page,
42640- ipath_map_sg,
42641- ipath_unmap_sg,
42642- ipath_sg_dma_address,
42643- ipath_sg_dma_len,
42644- ipath_sync_single_for_cpu,
42645- ipath_sync_single_for_device,
42646- ipath_dma_alloc_coherent,
42647- ipath_dma_free_coherent
42648+ .mapping_error = ipath_mapping_error,
42649+ .map_single = ipath_dma_map_single,
42650+ .unmap_single = ipath_dma_unmap_single,
42651+ .map_page = ipath_dma_map_page,
42652+ .unmap_page = ipath_dma_unmap_page,
42653+ .map_sg = ipath_map_sg,
42654+ .unmap_sg = ipath_unmap_sg,
42655+ .dma_address = ipath_sg_dma_address,
42656+ .dma_len = ipath_sg_dma_len,
42657+ .sync_single_for_cpu = ipath_sync_single_for_cpu,
42658+ .sync_single_for_device = ipath_sync_single_for_device,
42659+ .alloc_coherent = ipath_dma_alloc_coherent,
42660+ .free_coherent = ipath_dma_free_coherent
42661 };
42662diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
42663index 79b3dbc..96e5fcc 100644
42664--- a/drivers/infiniband/hw/ipath/ipath_rc.c
42665+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
42666@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42667 struct ib_atomic_eth *ateth;
42668 struct ipath_ack_entry *e;
42669 u64 vaddr;
42670- atomic64_t *maddr;
42671+ atomic64_unchecked_t *maddr;
42672 u64 sdata;
42673 u32 rkey;
42674 u8 next;
42675@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42676 IB_ACCESS_REMOTE_ATOMIC)))
42677 goto nack_acc_unlck;
42678 /* Perform atomic OP and save result. */
42679- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42680+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42681 sdata = be64_to_cpu(ateth->swap_data);
42682 e = &qp->s_ack_queue[qp->r_head_ack_queue];
42683 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
42684- (u64) atomic64_add_return(sdata, maddr) - sdata :
42685+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42686 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42687 be64_to_cpu(ateth->compare_data),
42688 sdata);
42689diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
42690index 1f95bba..9530f87 100644
42691--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
42692+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
42693@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
42694 unsigned long flags;
42695 struct ib_wc wc;
42696 u64 sdata;
42697- atomic64_t *maddr;
42698+ atomic64_unchecked_t *maddr;
42699 enum ib_wc_status send_status;
42700
42701 /*
42702@@ -382,11 +382,11 @@ again:
42703 IB_ACCESS_REMOTE_ATOMIC)))
42704 goto acc_err;
42705 /* Perform atomic OP and save result. */
42706- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42707+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42708 sdata = wqe->wr.wr.atomic.compare_add;
42709 *(u64 *) sqp->s_sge.sge.vaddr =
42710 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
42711- (u64) atomic64_add_return(sdata, maddr) - sdata :
42712+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42713 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42714 sdata, wqe->wr.wr.atomic.swap);
42715 goto send_comp;
42716diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
42717index f2a3f48..673ec79 100644
42718--- a/drivers/infiniband/hw/mlx4/mad.c
42719+++ b/drivers/infiniband/hw/mlx4/mad.c
42720@@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
42721
42722 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
42723 {
42724- return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
42725+ return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
42726 cpu_to_be64(0xff00000000000000LL);
42727 }
42728
42729diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
42730index 25b2cdf..099ff97 100644
42731--- a/drivers/infiniband/hw/mlx4/mcg.c
42732+++ b/drivers/infiniband/hw/mlx4/mcg.c
42733@@ -1040,7 +1040,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
42734 {
42735 char name[20];
42736
42737- atomic_set(&ctx->tid, 0);
42738+ atomic_set_unchecked(&ctx->tid, 0);
42739 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
42740 ctx->mcg_wq = create_singlethread_workqueue(name);
42741 if (!ctx->mcg_wq)
42742diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42743index a230683..3723f2d 100644
42744--- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
42745+++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42746@@ -408,7 +408,7 @@ struct mlx4_ib_demux_ctx {
42747 struct list_head mcg_mgid0_list;
42748 struct workqueue_struct *mcg_wq;
42749 struct mlx4_ib_demux_pv_ctx **tun;
42750- atomic_t tid;
42751+ atomic_unchecked_t tid;
42752 int flushing; /* flushing the work queue */
42753 };
42754
42755diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
42756index 9d3e5c1..6f166df 100644
42757--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
42758+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
42759@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
42760 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
42761 }
42762
42763-int mthca_QUERY_FW(struct mthca_dev *dev)
42764+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
42765 {
42766 struct mthca_mailbox *mailbox;
42767 u32 *outbox;
42768@@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42769 CMD_TIME_CLASS_B);
42770 }
42771
42772-int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42773+int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42774 int num_mtt)
42775 {
42776 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
42777@@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
42778 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
42779 }
42780
42781-int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42782+int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42783 int eq_num)
42784 {
42785 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
42786@@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
42787 CMD_TIME_CLASS_B);
42788 }
42789
42790-int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42791+int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42792 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
42793 void *in_mad, void *response_mad)
42794 {
42795diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
42796index 87897b9..7e79542 100644
42797--- a/drivers/infiniband/hw/mthca/mthca_main.c
42798+++ b/drivers/infiniband/hw/mthca/mthca_main.c
42799@@ -692,7 +692,7 @@ err_close:
42800 return err;
42801 }
42802
42803-static int mthca_setup_hca(struct mthca_dev *dev)
42804+static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
42805 {
42806 int err;
42807
42808diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
42809index ed9a989..6aa5dc2 100644
42810--- a/drivers/infiniband/hw/mthca/mthca_mr.c
42811+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
42812@@ -81,7 +81,7 @@ struct mthca_mpt_entry {
42813 * through the bitmaps)
42814 */
42815
42816-static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42817+static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42818 {
42819 int o;
42820 int m;
42821@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
42822 return key;
42823 }
42824
42825-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42826+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42827 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
42828 {
42829 struct mthca_mailbox *mailbox;
42830@@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
42831 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
42832 }
42833
42834-int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42835+int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42836 u64 *buffer_list, int buffer_size_shift,
42837 int list_len, u64 iova, u64 total_size,
42838 u32 access, struct mthca_mr *mr)
42839diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
42840index 42dde06..1257310 100644
42841--- a/drivers/infiniband/hw/mthca/mthca_provider.c
42842+++ b/drivers/infiniband/hw/mthca/mthca_provider.c
42843@@ -764,7 +764,7 @@ unlock:
42844 return 0;
42845 }
42846
42847-static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42848+static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42849 {
42850 struct mthca_dev *dev = to_mdev(ibcq->device);
42851 struct mthca_cq *cq = to_mcq(ibcq);
42852diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
42853index 353c7b0..c6ce921 100644
42854--- a/drivers/infiniband/hw/nes/nes.c
42855+++ b/drivers/infiniband/hw/nes/nes.c
42856@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
42857 LIST_HEAD(nes_adapter_list);
42858 static LIST_HEAD(nes_dev_list);
42859
42860-atomic_t qps_destroyed;
42861+atomic_unchecked_t qps_destroyed;
42862
42863 static unsigned int ee_flsh_adapter;
42864 static unsigned int sysfs_nonidx_addr;
42865@@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
42866 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
42867 struct nes_adapter *nesadapter = nesdev->nesadapter;
42868
42869- atomic_inc(&qps_destroyed);
42870+ atomic_inc_unchecked(&qps_destroyed);
42871
42872 /* Free the control structures */
42873
42874diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
42875index 33cc589..3bd6538 100644
42876--- a/drivers/infiniband/hw/nes/nes.h
42877+++ b/drivers/infiniband/hw/nes/nes.h
42878@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
42879 extern unsigned int wqm_quanta;
42880 extern struct list_head nes_adapter_list;
42881
42882-extern atomic_t cm_connects;
42883-extern atomic_t cm_accepts;
42884-extern atomic_t cm_disconnects;
42885-extern atomic_t cm_closes;
42886-extern atomic_t cm_connecteds;
42887-extern atomic_t cm_connect_reqs;
42888-extern atomic_t cm_rejects;
42889-extern atomic_t mod_qp_timouts;
42890-extern atomic_t qps_created;
42891-extern atomic_t qps_destroyed;
42892-extern atomic_t sw_qps_destroyed;
42893+extern atomic_unchecked_t cm_connects;
42894+extern atomic_unchecked_t cm_accepts;
42895+extern atomic_unchecked_t cm_disconnects;
42896+extern atomic_unchecked_t cm_closes;
42897+extern atomic_unchecked_t cm_connecteds;
42898+extern atomic_unchecked_t cm_connect_reqs;
42899+extern atomic_unchecked_t cm_rejects;
42900+extern atomic_unchecked_t mod_qp_timouts;
42901+extern atomic_unchecked_t qps_created;
42902+extern atomic_unchecked_t qps_destroyed;
42903+extern atomic_unchecked_t sw_qps_destroyed;
42904 extern u32 mh_detected;
42905 extern u32 mh_pauses_sent;
42906 extern u32 cm_packets_sent;
42907@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
42908 extern u32 cm_packets_received;
42909 extern u32 cm_packets_dropped;
42910 extern u32 cm_packets_retrans;
42911-extern atomic_t cm_listens_created;
42912-extern atomic_t cm_listens_destroyed;
42913+extern atomic_unchecked_t cm_listens_created;
42914+extern atomic_unchecked_t cm_listens_destroyed;
42915 extern u32 cm_backlog_drops;
42916-extern atomic_t cm_loopbacks;
42917-extern atomic_t cm_nodes_created;
42918-extern atomic_t cm_nodes_destroyed;
42919-extern atomic_t cm_accel_dropped_pkts;
42920-extern atomic_t cm_resets_recvd;
42921-extern atomic_t pau_qps_created;
42922-extern atomic_t pau_qps_destroyed;
42923+extern atomic_unchecked_t cm_loopbacks;
42924+extern atomic_unchecked_t cm_nodes_created;
42925+extern atomic_unchecked_t cm_nodes_destroyed;
42926+extern atomic_unchecked_t cm_accel_dropped_pkts;
42927+extern atomic_unchecked_t cm_resets_recvd;
42928+extern atomic_unchecked_t pau_qps_created;
42929+extern atomic_unchecked_t pau_qps_destroyed;
42930
42931 extern u32 int_mod_timer_init;
42932 extern u32 int_mod_cq_depth_256;
42933diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
42934index 9c9f2f5..2559190 100644
42935--- a/drivers/infiniband/hw/nes/nes_cm.c
42936+++ b/drivers/infiniband/hw/nes/nes_cm.c
42937@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
42938 u32 cm_packets_retrans;
42939 u32 cm_packets_created;
42940 u32 cm_packets_received;
42941-atomic_t cm_listens_created;
42942-atomic_t cm_listens_destroyed;
42943+atomic_unchecked_t cm_listens_created;
42944+atomic_unchecked_t cm_listens_destroyed;
42945 u32 cm_backlog_drops;
42946-atomic_t cm_loopbacks;
42947-atomic_t cm_nodes_created;
42948-atomic_t cm_nodes_destroyed;
42949-atomic_t cm_accel_dropped_pkts;
42950-atomic_t cm_resets_recvd;
42951+atomic_unchecked_t cm_loopbacks;
42952+atomic_unchecked_t cm_nodes_created;
42953+atomic_unchecked_t cm_nodes_destroyed;
42954+atomic_unchecked_t cm_accel_dropped_pkts;
42955+atomic_unchecked_t cm_resets_recvd;
42956
42957 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
42958 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
42959@@ -133,28 +133,28 @@ static void print_core(struct nes_cm_core *core);
42960 /* instance of function pointers for client API */
42961 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
42962 static struct nes_cm_ops nes_cm_api = {
42963- mini_cm_accelerated,
42964- mini_cm_listen,
42965- mini_cm_del_listen,
42966- mini_cm_connect,
42967- mini_cm_close,
42968- mini_cm_accept,
42969- mini_cm_reject,
42970- mini_cm_recv_pkt,
42971- mini_cm_dealloc_core,
42972- mini_cm_get,
42973- mini_cm_set
42974+ .accelerated = mini_cm_accelerated,
42975+ .listen = mini_cm_listen,
42976+ .stop_listener = mini_cm_del_listen,
42977+ .connect = mini_cm_connect,
42978+ .close = mini_cm_close,
42979+ .accept = mini_cm_accept,
42980+ .reject = mini_cm_reject,
42981+ .recv_pkt = mini_cm_recv_pkt,
42982+ .destroy_cm_core = mini_cm_dealloc_core,
42983+ .get = mini_cm_get,
42984+ .set = mini_cm_set
42985 };
42986
42987 static struct nes_cm_core *g_cm_core;
42988
42989-atomic_t cm_connects;
42990-atomic_t cm_accepts;
42991-atomic_t cm_disconnects;
42992-atomic_t cm_closes;
42993-atomic_t cm_connecteds;
42994-atomic_t cm_connect_reqs;
42995-atomic_t cm_rejects;
42996+atomic_unchecked_t cm_connects;
42997+atomic_unchecked_t cm_accepts;
42998+atomic_unchecked_t cm_disconnects;
42999+atomic_unchecked_t cm_closes;
43000+atomic_unchecked_t cm_connecteds;
43001+atomic_unchecked_t cm_connect_reqs;
43002+atomic_unchecked_t cm_rejects;
43003
43004 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
43005 {
43006@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
43007 kfree(listener);
43008 listener = NULL;
43009 ret = 0;
43010- atomic_inc(&cm_listens_destroyed);
43011+ atomic_inc_unchecked(&cm_listens_destroyed);
43012 } else {
43013 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
43014 }
43015@@ -1465,7 +1465,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
43016 cm_node->rem_mac);
43017
43018 add_hte_node(cm_core, cm_node);
43019- atomic_inc(&cm_nodes_created);
43020+ atomic_inc_unchecked(&cm_nodes_created);
43021
43022 return cm_node;
43023 }
43024@@ -1523,7 +1523,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
43025 }
43026
43027 atomic_dec(&cm_core->node_cnt);
43028- atomic_inc(&cm_nodes_destroyed);
43029+ atomic_inc_unchecked(&cm_nodes_destroyed);
43030 nesqp = cm_node->nesqp;
43031 if (nesqp) {
43032 nesqp->cm_node = NULL;
43033@@ -1587,7 +1587,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
43034
43035 static void drop_packet(struct sk_buff *skb)
43036 {
43037- atomic_inc(&cm_accel_dropped_pkts);
43038+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
43039 dev_kfree_skb_any(skb);
43040 }
43041
43042@@ -1650,7 +1650,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
43043 {
43044
43045 int reset = 0; /* whether to send reset in case of err.. */
43046- atomic_inc(&cm_resets_recvd);
43047+ atomic_inc_unchecked(&cm_resets_recvd);
43048 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
43049 " refcnt=%d\n", cm_node, cm_node->state,
43050 atomic_read(&cm_node->ref_count));
43051@@ -2291,7 +2291,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
43052 rem_ref_cm_node(cm_node->cm_core, cm_node);
43053 return NULL;
43054 }
43055- atomic_inc(&cm_loopbacks);
43056+ atomic_inc_unchecked(&cm_loopbacks);
43057 loopbackremotenode->loopbackpartner = cm_node;
43058 loopbackremotenode->tcp_cntxt.rcv_wscale =
43059 NES_CM_DEFAULT_RCV_WND_SCALE;
43060@@ -2566,7 +2566,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
43061 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
43062 else {
43063 rem_ref_cm_node(cm_core, cm_node);
43064- atomic_inc(&cm_accel_dropped_pkts);
43065+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
43066 dev_kfree_skb_any(skb);
43067 }
43068 break;
43069@@ -2874,7 +2874,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
43070
43071 if ((cm_id) && (cm_id->event_handler)) {
43072 if (issue_disconn) {
43073- atomic_inc(&cm_disconnects);
43074+ atomic_inc_unchecked(&cm_disconnects);
43075 cm_event.event = IW_CM_EVENT_DISCONNECT;
43076 cm_event.status = disconn_status;
43077 cm_event.local_addr = cm_id->local_addr;
43078@@ -2896,7 +2896,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
43079 }
43080
43081 if (issue_close) {
43082- atomic_inc(&cm_closes);
43083+ atomic_inc_unchecked(&cm_closes);
43084 nes_disconnect(nesqp, 1);
43085
43086 cm_id->provider_data = nesqp;
43087@@ -3034,7 +3034,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
43088
43089 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
43090 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
43091- atomic_inc(&cm_accepts);
43092+ atomic_inc_unchecked(&cm_accepts);
43093
43094 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
43095 netdev_refcnt_read(nesvnic->netdev));
43096@@ -3223,7 +3223,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
43097 struct nes_cm_core *cm_core;
43098 u8 *start_buff;
43099
43100- atomic_inc(&cm_rejects);
43101+ atomic_inc_unchecked(&cm_rejects);
43102 cm_node = (struct nes_cm_node *)cm_id->provider_data;
43103 loopback = cm_node->loopbackpartner;
43104 cm_core = cm_node->cm_core;
43105@@ -3285,7 +3285,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
43106 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
43107 ntohs(laddr->sin_port));
43108
43109- atomic_inc(&cm_connects);
43110+ atomic_inc_unchecked(&cm_connects);
43111 nesqp->active_conn = 1;
43112
43113 /* cache the cm_id in the qp */
43114@@ -3397,7 +3397,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
43115 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
43116 return err;
43117 }
43118- atomic_inc(&cm_listens_created);
43119+ atomic_inc_unchecked(&cm_listens_created);
43120 }
43121
43122 cm_id->add_ref(cm_id);
43123@@ -3504,7 +3504,7 @@ static void cm_event_connected(struct nes_cm_event *event)
43124
43125 if (nesqp->destroyed)
43126 return;
43127- atomic_inc(&cm_connecteds);
43128+ atomic_inc_unchecked(&cm_connecteds);
43129 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
43130 " local port 0x%04X. jiffies = %lu.\n",
43131 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
43132@@ -3685,7 +3685,7 @@ static void cm_event_reset(struct nes_cm_event *event)
43133
43134 cm_id->add_ref(cm_id);
43135 ret = cm_id->event_handler(cm_id, &cm_event);
43136- atomic_inc(&cm_closes);
43137+ atomic_inc_unchecked(&cm_closes);
43138 cm_event.event = IW_CM_EVENT_CLOSE;
43139 cm_event.status = 0;
43140 cm_event.provider_data = cm_id->provider_data;
43141@@ -3725,7 +3725,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
43142 return;
43143 cm_id = cm_node->cm_id;
43144
43145- atomic_inc(&cm_connect_reqs);
43146+ atomic_inc_unchecked(&cm_connect_reqs);
43147 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
43148 cm_node, cm_id, jiffies);
43149
43150@@ -3769,7 +3769,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
43151 return;
43152 cm_id = cm_node->cm_id;
43153
43154- atomic_inc(&cm_connect_reqs);
43155+ atomic_inc_unchecked(&cm_connect_reqs);
43156 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
43157 cm_node, cm_id, jiffies);
43158
43159diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
43160index 4166452..fc952c3 100644
43161--- a/drivers/infiniband/hw/nes/nes_mgt.c
43162+++ b/drivers/infiniband/hw/nes/nes_mgt.c
43163@@ -40,8 +40,8 @@
43164 #include "nes.h"
43165 #include "nes_mgt.h"
43166
43167-atomic_t pau_qps_created;
43168-atomic_t pau_qps_destroyed;
43169+atomic_unchecked_t pau_qps_created;
43170+atomic_unchecked_t pau_qps_destroyed;
43171
43172 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
43173 {
43174@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
43175 {
43176 struct sk_buff *skb;
43177 unsigned long flags;
43178- atomic_inc(&pau_qps_destroyed);
43179+ atomic_inc_unchecked(&pau_qps_destroyed);
43180
43181 /* Free packets that have not yet been forwarded */
43182 /* Lock is acquired by skb_dequeue when removing the skb */
43183@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
43184 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
43185 skb_queue_head_init(&nesqp->pau_list);
43186 spin_lock_init(&nesqp->pau_lock);
43187- atomic_inc(&pau_qps_created);
43188+ atomic_inc_unchecked(&pau_qps_created);
43189 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
43190 }
43191
43192diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
43193index 49eb511..a774366 100644
43194--- a/drivers/infiniband/hw/nes/nes_nic.c
43195+++ b/drivers/infiniband/hw/nes/nes_nic.c
43196@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
43197 target_stat_values[++index] = mh_detected;
43198 target_stat_values[++index] = mh_pauses_sent;
43199 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
43200- target_stat_values[++index] = atomic_read(&cm_connects);
43201- target_stat_values[++index] = atomic_read(&cm_accepts);
43202- target_stat_values[++index] = atomic_read(&cm_disconnects);
43203- target_stat_values[++index] = atomic_read(&cm_connecteds);
43204- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
43205- target_stat_values[++index] = atomic_read(&cm_rejects);
43206- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
43207- target_stat_values[++index] = atomic_read(&qps_created);
43208- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
43209- target_stat_values[++index] = atomic_read(&qps_destroyed);
43210- target_stat_values[++index] = atomic_read(&cm_closes);
43211+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
43212+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
43213+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
43214+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
43215+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
43216+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
43217+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
43218+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
43219+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
43220+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
43221+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
43222 target_stat_values[++index] = cm_packets_sent;
43223 target_stat_values[++index] = cm_packets_bounced;
43224 target_stat_values[++index] = cm_packets_created;
43225 target_stat_values[++index] = cm_packets_received;
43226 target_stat_values[++index] = cm_packets_dropped;
43227 target_stat_values[++index] = cm_packets_retrans;
43228- target_stat_values[++index] = atomic_read(&cm_listens_created);
43229- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
43230+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
43231+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
43232 target_stat_values[++index] = cm_backlog_drops;
43233- target_stat_values[++index] = atomic_read(&cm_loopbacks);
43234- target_stat_values[++index] = atomic_read(&cm_nodes_created);
43235- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
43236- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
43237- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
43238+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
43239+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
43240+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
43241+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
43242+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
43243 target_stat_values[++index] = nesadapter->free_4kpbl;
43244 target_stat_values[++index] = nesadapter->free_256pbl;
43245 target_stat_values[++index] = int_mod_timer_init;
43246 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
43247 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
43248 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
43249- target_stat_values[++index] = atomic_read(&pau_qps_created);
43250- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
43251+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
43252+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
43253 }
43254
43255 /**
43256diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
43257index eb62461..2b7fc71 100644
43258--- a/drivers/infiniband/hw/nes/nes_verbs.c
43259+++ b/drivers/infiniband/hw/nes/nes_verbs.c
43260@@ -46,9 +46,9 @@
43261
43262 #include <rdma/ib_umem.h>
43263
43264-atomic_t mod_qp_timouts;
43265-atomic_t qps_created;
43266-atomic_t sw_qps_destroyed;
43267+atomic_unchecked_t mod_qp_timouts;
43268+atomic_unchecked_t qps_created;
43269+atomic_unchecked_t sw_qps_destroyed;
43270
43271 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
43272
43273@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
43274 if (init_attr->create_flags)
43275 return ERR_PTR(-EINVAL);
43276
43277- atomic_inc(&qps_created);
43278+ atomic_inc_unchecked(&qps_created);
43279 switch (init_attr->qp_type) {
43280 case IB_QPT_RC:
43281 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
43282@@ -1466,7 +1466,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
43283 struct iw_cm_event cm_event;
43284 int ret = 0;
43285
43286- atomic_inc(&sw_qps_destroyed);
43287+ atomic_inc_unchecked(&sw_qps_destroyed);
43288 nesqp->destroyed = 1;
43289
43290 /* Blow away the connection if it exists. */
43291diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
43292index 1946101..09766d2 100644
43293--- a/drivers/infiniband/hw/qib/qib.h
43294+++ b/drivers/infiniband/hw/qib/qib.h
43295@@ -52,6 +52,7 @@
43296 #include <linux/kref.h>
43297 #include <linux/sched.h>
43298 #include <linux/kthread.h>
43299+#include <linux/slab.h>
43300
43301 #include "qib_common.h"
43302 #include "qib_verbs.h"
43303diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
43304index 24c41ba..102d71f 100644
43305--- a/drivers/input/gameport/gameport.c
43306+++ b/drivers/input/gameport/gameport.c
43307@@ -490,14 +490,14 @@ EXPORT_SYMBOL(gameport_set_phys);
43308 */
43309 static void gameport_init_port(struct gameport *gameport)
43310 {
43311- static atomic_t gameport_no = ATOMIC_INIT(0);
43312+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
43313
43314 __module_get(THIS_MODULE);
43315
43316 mutex_init(&gameport->drv_mutex);
43317 device_initialize(&gameport->dev);
43318 dev_set_name(&gameport->dev, "gameport%lu",
43319- (unsigned long)atomic_inc_return(&gameport_no) - 1);
43320+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
43321 gameport->dev.bus = &gameport_bus;
43322 gameport->dev.release = gameport_release_port;
43323 if (gameport->parent)
43324diff --git a/drivers/input/input.c b/drivers/input/input.c
43325index 1c4c0db..6f7abe3 100644
43326--- a/drivers/input/input.c
43327+++ b/drivers/input/input.c
43328@@ -1772,7 +1772,7 @@ EXPORT_SYMBOL_GPL(input_class);
43329 */
43330 struct input_dev *input_allocate_device(void)
43331 {
43332- static atomic_t input_no = ATOMIC_INIT(0);
43333+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
43334 struct input_dev *dev;
43335
43336 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
43337@@ -1787,7 +1787,7 @@ struct input_dev *input_allocate_device(void)
43338 INIT_LIST_HEAD(&dev->node);
43339
43340 dev_set_name(&dev->dev, "input%ld",
43341- (unsigned long) atomic_inc_return(&input_no) - 1);
43342+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
43343
43344 __module_get(THIS_MODULE);
43345 }
43346diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
43347index 4a95b22..874c182 100644
43348--- a/drivers/input/joystick/sidewinder.c
43349+++ b/drivers/input/joystick/sidewinder.c
43350@@ -30,6 +30,7 @@
43351 #include <linux/kernel.h>
43352 #include <linux/module.h>
43353 #include <linux/slab.h>
43354+#include <linux/sched.h>
43355 #include <linux/input.h>
43356 #include <linux/gameport.h>
43357 #include <linux/jiffies.h>
43358diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
43359index 603fe0d..f63decc 100644
43360--- a/drivers/input/joystick/xpad.c
43361+++ b/drivers/input/joystick/xpad.c
43362@@ -737,7 +737,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
43363
43364 static int xpad_led_probe(struct usb_xpad *xpad)
43365 {
43366- static atomic_t led_seq = ATOMIC_INIT(0);
43367+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
43368 long led_no;
43369 struct xpad_led *led;
43370 struct led_classdev *led_cdev;
43371@@ -750,7 +750,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
43372 if (!led)
43373 return -ENOMEM;
43374
43375- led_no = (long)atomic_inc_return(&led_seq) - 1;
43376+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
43377
43378 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
43379 led->xpad = xpad;
43380diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
43381index e204f26..8459f15 100644
43382--- a/drivers/input/misc/ims-pcu.c
43383+++ b/drivers/input/misc/ims-pcu.c
43384@@ -1621,7 +1621,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
43385
43386 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
43387 {
43388- static atomic_t device_no = ATOMIC_INIT(0);
43389+ static atomic_unchecked_t device_no = ATOMIC_INIT(0);
43390
43391 const struct ims_pcu_device_info *info;
43392 u8 device_id;
43393@@ -1653,7 +1653,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
43394 }
43395
43396 /* Device appears to be operable, complete initialization */
43397- pcu->device_no = atomic_inc_return(&device_no) - 1;
43398+ pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
43399
43400 error = ims_pcu_setup_backlight(pcu);
43401 if (error)
43402diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
43403index 2f0b39d..7370f13 100644
43404--- a/drivers/input/mouse/psmouse.h
43405+++ b/drivers/input/mouse/psmouse.h
43406@@ -116,7 +116,7 @@ struct psmouse_attribute {
43407 ssize_t (*set)(struct psmouse *psmouse, void *data,
43408 const char *buf, size_t count);
43409 bool protect;
43410-};
43411+} __do_const;
43412 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
43413
43414 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
43415diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
43416index b604564..3f14ae4 100644
43417--- a/drivers/input/mousedev.c
43418+++ b/drivers/input/mousedev.c
43419@@ -744,7 +744,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
43420
43421 spin_unlock_irq(&client->packet_lock);
43422
43423- if (copy_to_user(buffer, data, count))
43424+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
43425 return -EFAULT;
43426
43427 return count;
43428diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
43429index 8f4c4ab..5fc8a45 100644
43430--- a/drivers/input/serio/serio.c
43431+++ b/drivers/input/serio/serio.c
43432@@ -505,7 +505,7 @@ static void serio_release_port(struct device *dev)
43433 */
43434 static void serio_init_port(struct serio *serio)
43435 {
43436- static atomic_t serio_no = ATOMIC_INIT(0);
43437+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
43438
43439 __module_get(THIS_MODULE);
43440
43441@@ -516,7 +516,7 @@ static void serio_init_port(struct serio *serio)
43442 mutex_init(&serio->drv_mutex);
43443 device_initialize(&serio->dev);
43444 dev_set_name(&serio->dev, "serio%ld",
43445- (long)atomic_inc_return(&serio_no) - 1);
43446+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
43447 serio->dev.bus = &serio_bus;
43448 serio->dev.release = serio_release_port;
43449 serio->dev.groups = serio_device_attr_groups;
43450diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
43451index c9a02fe..0debc75 100644
43452--- a/drivers/input/serio/serio_raw.c
43453+++ b/drivers/input/serio/serio_raw.c
43454@@ -292,7 +292,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
43455
43456 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
43457 {
43458- static atomic_t serio_raw_no = ATOMIC_INIT(0);
43459+ static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
43460 struct serio_raw *serio_raw;
43461 int err;
43462
43463@@ -303,7 +303,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
43464 }
43465
43466 snprintf(serio_raw->name, sizeof(serio_raw->name),
43467- "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
43468+ "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
43469 kref_init(&serio_raw->kref);
43470 INIT_LIST_HEAD(&serio_raw->client_list);
43471 init_waitqueue_head(&serio_raw->wait);
43472diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
43473index e5555fc..937986d 100644
43474--- a/drivers/iommu/iommu.c
43475+++ b/drivers/iommu/iommu.c
43476@@ -588,7 +588,7 @@ static struct notifier_block iommu_bus_nb = {
43477 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
43478 {
43479 bus_register_notifier(bus, &iommu_bus_nb);
43480- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
43481+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
43482 }
43483
43484 /**
43485diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
43486index 228632c9..edfe331 100644
43487--- a/drivers/iommu/irq_remapping.c
43488+++ b/drivers/iommu/irq_remapping.c
43489@@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
43490 void panic_if_irq_remap(const char *msg)
43491 {
43492 if (irq_remapping_enabled)
43493- panic(msg);
43494+ panic("%s", msg);
43495 }
43496
43497 static void ir_ack_apic_edge(struct irq_data *data)
43498@@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
43499
43500 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
43501 {
43502- chip->irq_print_chip = ir_print_prefix;
43503- chip->irq_ack = ir_ack_apic_edge;
43504- chip->irq_eoi = ir_ack_apic_level;
43505- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43506+ pax_open_kernel();
43507+ *(void **)&chip->irq_print_chip = ir_print_prefix;
43508+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
43509+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
43510+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43511+ pax_close_kernel();
43512 }
43513
43514 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
43515diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
43516index 341c601..e5f407e 100644
43517--- a/drivers/irqchip/irq-gic.c
43518+++ b/drivers/irqchip/irq-gic.c
43519@@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
43520 * Supported arch specific GIC irq extension.
43521 * Default make them NULL.
43522 */
43523-struct irq_chip gic_arch_extn = {
43524+irq_chip_no_const gic_arch_extn = {
43525 .irq_eoi = NULL,
43526 .irq_mask = NULL,
43527 .irq_unmask = NULL,
43528@@ -332,7 +332,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
43529 chained_irq_exit(chip, desc);
43530 }
43531
43532-static struct irq_chip gic_chip = {
43533+static irq_chip_no_const gic_chip __read_only = {
43534 .name = "GIC",
43535 .irq_mask = gic_mask_irq,
43536 .irq_unmask = gic_unmask_irq,
43537diff --git a/drivers/irqchip/irq-renesas-irqc.c b/drivers/irqchip/irq-renesas-irqc.c
43538index 8777065..a4a9967 100644
43539--- a/drivers/irqchip/irq-renesas-irqc.c
43540+++ b/drivers/irqchip/irq-renesas-irqc.c
43541@@ -151,7 +151,7 @@ static int irqc_probe(struct platform_device *pdev)
43542 struct irqc_priv *p;
43543 struct resource *io;
43544 struct resource *irq;
43545- struct irq_chip *irq_chip;
43546+ irq_chip_no_const *irq_chip;
43547 const char *name = dev_name(&pdev->dev);
43548 int ret;
43549 int k;
43550diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
43551index ac6f72b..81150f2 100644
43552--- a/drivers/isdn/capi/capi.c
43553+++ b/drivers/isdn/capi/capi.c
43554@@ -81,8 +81,8 @@ struct capiminor {
43555
43556 struct capi20_appl *ap;
43557 u32 ncci;
43558- atomic_t datahandle;
43559- atomic_t msgid;
43560+ atomic_unchecked_t datahandle;
43561+ atomic_unchecked_t msgid;
43562
43563 struct tty_port port;
43564 int ttyinstop;
43565@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
43566 capimsg_setu16(s, 2, mp->ap->applid);
43567 capimsg_setu8 (s, 4, CAPI_DATA_B3);
43568 capimsg_setu8 (s, 5, CAPI_RESP);
43569- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
43570+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
43571 capimsg_setu32(s, 8, mp->ncci);
43572 capimsg_setu16(s, 12, datahandle);
43573 }
43574@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
43575 mp->outbytes -= len;
43576 spin_unlock_bh(&mp->outlock);
43577
43578- datahandle = atomic_inc_return(&mp->datahandle);
43579+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
43580 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
43581 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43582 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43583 capimsg_setu16(skb->data, 2, mp->ap->applid);
43584 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
43585 capimsg_setu8 (skb->data, 5, CAPI_REQ);
43586- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
43587+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
43588 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
43589 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
43590 capimsg_setu16(skb->data, 16, len); /* Data length */
43591diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
43592index c44950d..10ac276 100644
43593--- a/drivers/isdn/gigaset/bas-gigaset.c
43594+++ b/drivers/isdn/gigaset/bas-gigaset.c
43595@@ -2564,22 +2564,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
43596
43597
43598 static const struct gigaset_ops gigops = {
43599- gigaset_write_cmd,
43600- gigaset_write_room,
43601- gigaset_chars_in_buffer,
43602- gigaset_brkchars,
43603- gigaset_init_bchannel,
43604- gigaset_close_bchannel,
43605- gigaset_initbcshw,
43606- gigaset_freebcshw,
43607- gigaset_reinitbcshw,
43608- gigaset_initcshw,
43609- gigaset_freecshw,
43610- gigaset_set_modem_ctrl,
43611- gigaset_baud_rate,
43612- gigaset_set_line_ctrl,
43613- gigaset_isoc_send_skb,
43614- gigaset_isoc_input,
43615+ .write_cmd = gigaset_write_cmd,
43616+ .write_room = gigaset_write_room,
43617+ .chars_in_buffer = gigaset_chars_in_buffer,
43618+ .brkchars = gigaset_brkchars,
43619+ .init_bchannel = gigaset_init_bchannel,
43620+ .close_bchannel = gigaset_close_bchannel,
43621+ .initbcshw = gigaset_initbcshw,
43622+ .freebcshw = gigaset_freebcshw,
43623+ .reinitbcshw = gigaset_reinitbcshw,
43624+ .initcshw = gigaset_initcshw,
43625+ .freecshw = gigaset_freecshw,
43626+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43627+ .baud_rate = gigaset_baud_rate,
43628+ .set_line_ctrl = gigaset_set_line_ctrl,
43629+ .send_skb = gigaset_isoc_send_skb,
43630+ .handle_input = gigaset_isoc_input,
43631 };
43632
43633 /* bas_gigaset_init
43634diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
43635index 600c79b..3752bab 100644
43636--- a/drivers/isdn/gigaset/interface.c
43637+++ b/drivers/isdn/gigaset/interface.c
43638@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
43639 }
43640 tty->driver_data = cs;
43641
43642- ++cs->port.count;
43643+ atomic_inc(&cs->port.count);
43644
43645- if (cs->port.count == 1) {
43646+ if (atomic_read(&cs->port.count) == 1) {
43647 tty_port_tty_set(&cs->port, tty);
43648 cs->port.low_latency = 1;
43649 }
43650@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
43651
43652 if (!cs->connected)
43653 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
43654- else if (!cs->port.count)
43655+ else if (!atomic_read(&cs->port.count))
43656 dev_warn(cs->dev, "%s: device not opened\n", __func__);
43657- else if (!--cs->port.count)
43658+ else if (!atomic_dec_return(&cs->port.count))
43659 tty_port_tty_set(&cs->port, NULL);
43660
43661 mutex_unlock(&cs->mutex);
43662diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
43663index 8c91fd5..14f13ce 100644
43664--- a/drivers/isdn/gigaset/ser-gigaset.c
43665+++ b/drivers/isdn/gigaset/ser-gigaset.c
43666@@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
43667 }
43668
43669 static const struct gigaset_ops ops = {
43670- gigaset_write_cmd,
43671- gigaset_write_room,
43672- gigaset_chars_in_buffer,
43673- gigaset_brkchars,
43674- gigaset_init_bchannel,
43675- gigaset_close_bchannel,
43676- gigaset_initbcshw,
43677- gigaset_freebcshw,
43678- gigaset_reinitbcshw,
43679- gigaset_initcshw,
43680- gigaset_freecshw,
43681- gigaset_set_modem_ctrl,
43682- gigaset_baud_rate,
43683- gigaset_set_line_ctrl,
43684- gigaset_m10x_send_skb, /* asyncdata.c */
43685- gigaset_m10x_input, /* asyncdata.c */
43686+ .write_cmd = gigaset_write_cmd,
43687+ .write_room = gigaset_write_room,
43688+ .chars_in_buffer = gigaset_chars_in_buffer,
43689+ .brkchars = gigaset_brkchars,
43690+ .init_bchannel = gigaset_init_bchannel,
43691+ .close_bchannel = gigaset_close_bchannel,
43692+ .initbcshw = gigaset_initbcshw,
43693+ .freebcshw = gigaset_freebcshw,
43694+ .reinitbcshw = gigaset_reinitbcshw,
43695+ .initcshw = gigaset_initcshw,
43696+ .freecshw = gigaset_freecshw,
43697+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43698+ .baud_rate = gigaset_baud_rate,
43699+ .set_line_ctrl = gigaset_set_line_ctrl,
43700+ .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
43701+ .handle_input = gigaset_m10x_input, /* asyncdata.c */
43702 };
43703
43704
43705diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
43706index d0a41cb..b953e50 100644
43707--- a/drivers/isdn/gigaset/usb-gigaset.c
43708+++ b/drivers/isdn/gigaset/usb-gigaset.c
43709@@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
43710 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
43711 memcpy(cs->hw.usb->bchars, buf, 6);
43712 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
43713- 0, 0, &buf, 6, 2000);
43714+ 0, 0, buf, 6, 2000);
43715 }
43716
43717 static void gigaset_freebcshw(struct bc_state *bcs)
43718@@ -869,22 +869,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
43719 }
43720
43721 static const struct gigaset_ops ops = {
43722- gigaset_write_cmd,
43723- gigaset_write_room,
43724- gigaset_chars_in_buffer,
43725- gigaset_brkchars,
43726- gigaset_init_bchannel,
43727- gigaset_close_bchannel,
43728- gigaset_initbcshw,
43729- gigaset_freebcshw,
43730- gigaset_reinitbcshw,
43731- gigaset_initcshw,
43732- gigaset_freecshw,
43733- gigaset_set_modem_ctrl,
43734- gigaset_baud_rate,
43735- gigaset_set_line_ctrl,
43736- gigaset_m10x_send_skb,
43737- gigaset_m10x_input,
43738+ .write_cmd = gigaset_write_cmd,
43739+ .write_room = gigaset_write_room,
43740+ .chars_in_buffer = gigaset_chars_in_buffer,
43741+ .brkchars = gigaset_brkchars,
43742+ .init_bchannel = gigaset_init_bchannel,
43743+ .close_bchannel = gigaset_close_bchannel,
43744+ .initbcshw = gigaset_initbcshw,
43745+ .freebcshw = gigaset_freebcshw,
43746+ .reinitbcshw = gigaset_reinitbcshw,
43747+ .initcshw = gigaset_initcshw,
43748+ .freecshw = gigaset_freecshw,
43749+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43750+ .baud_rate = gigaset_baud_rate,
43751+ .set_line_ctrl = gigaset_set_line_ctrl,
43752+ .send_skb = gigaset_m10x_send_skb,
43753+ .handle_input = gigaset_m10x_input,
43754 };
43755
43756 /*
43757diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
43758index 4d9b195..455075c 100644
43759--- a/drivers/isdn/hardware/avm/b1.c
43760+++ b/drivers/isdn/hardware/avm/b1.c
43761@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
43762 }
43763 if (left) {
43764 if (t4file->user) {
43765- if (copy_from_user(buf, dp, left))
43766+ if (left > sizeof buf || copy_from_user(buf, dp, left))
43767 return -EFAULT;
43768 } else {
43769 memcpy(buf, dp, left);
43770@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
43771 }
43772 if (left) {
43773 if (config->user) {
43774- if (copy_from_user(buf, dp, left))
43775+ if (left > sizeof buf || copy_from_user(buf, dp, left))
43776 return -EFAULT;
43777 } else {
43778 memcpy(buf, dp, left);
43779diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
43780index 9bb12ba..d4262f7 100644
43781--- a/drivers/isdn/i4l/isdn_common.c
43782+++ b/drivers/isdn/i4l/isdn_common.c
43783@@ -1651,6 +1651,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
43784 } else
43785 return -EINVAL;
43786 case IIOCDBGVAR:
43787+ if (!capable(CAP_SYS_RAWIO))
43788+ return -EPERM;
43789 if (arg) {
43790 if (copy_to_user(argp, &dev, sizeof(ulong)))
43791 return -EFAULT;
43792diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
43793index 91d5730..336523e 100644
43794--- a/drivers/isdn/i4l/isdn_concap.c
43795+++ b/drivers/isdn/i4l/isdn_concap.c
43796@@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
43797 }
43798
43799 struct concap_device_ops isdn_concap_reliable_dl_dops = {
43800- &isdn_concap_dl_data_req,
43801- &isdn_concap_dl_connect_req,
43802- &isdn_concap_dl_disconn_req
43803+ .data_req = &isdn_concap_dl_data_req,
43804+ .connect_req = &isdn_concap_dl_connect_req,
43805+ .disconn_req = &isdn_concap_dl_disconn_req
43806 };
43807
43808 /* The following should better go into a dedicated source file such that
43809diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
43810index 3c5f249..5fac4d0 100644
43811--- a/drivers/isdn/i4l/isdn_tty.c
43812+++ b/drivers/isdn/i4l/isdn_tty.c
43813@@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
43814
43815 #ifdef ISDN_DEBUG_MODEM_OPEN
43816 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
43817- port->count);
43818+ atomic_read(&port->count));
43819 #endif
43820- port->count++;
43821+ atomic_inc(&port->count);
43822 port->tty = tty;
43823 /*
43824 * Start up serial port
43825@@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43826 #endif
43827 return;
43828 }
43829- if ((tty->count == 1) && (port->count != 1)) {
43830+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
43831 /*
43832 * Uh, oh. tty->count is 1, which means that the tty
43833 * structure will be freed. Info->count should always
43834@@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43835 * serial port won't be shutdown.
43836 */
43837 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
43838- "info->count is %d\n", port->count);
43839- port->count = 1;
43840+ "info->count is %d\n", atomic_read(&port->count));
43841+ atomic_set(&port->count, 1);
43842 }
43843- if (--port->count < 0) {
43844+ if (atomic_dec_return(&port->count) < 0) {
43845 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
43846- info->line, port->count);
43847- port->count = 0;
43848+ info->line, atomic_read(&port->count));
43849+ atomic_set(&port->count, 0);
43850 }
43851- if (port->count) {
43852+ if (atomic_read(&port->count)) {
43853 #ifdef ISDN_DEBUG_MODEM_OPEN
43854 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
43855 #endif
43856@@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
43857 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
43858 return;
43859 isdn_tty_shutdown(info);
43860- port->count = 0;
43861+ atomic_set(&port->count, 0);
43862 port->flags &= ~ASYNC_NORMAL_ACTIVE;
43863 port->tty = NULL;
43864 wake_up_interruptible(&port->open_wait);
43865@@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
43866 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
43867 modem_info *info = &dev->mdm.info[i];
43868
43869- if (info->port.count == 0)
43870+ if (atomic_read(&info->port.count) == 0)
43871 continue;
43872 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
43873 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
43874diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
43875index e2d4e58..40cd045 100644
43876--- a/drivers/isdn/i4l/isdn_x25iface.c
43877+++ b/drivers/isdn/i4l/isdn_x25iface.c
43878@@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
43879
43880
43881 static struct concap_proto_ops ix25_pops = {
43882- &isdn_x25iface_proto_new,
43883- &isdn_x25iface_proto_del,
43884- &isdn_x25iface_proto_restart,
43885- &isdn_x25iface_proto_close,
43886- &isdn_x25iface_xmit,
43887- &isdn_x25iface_receive,
43888- &isdn_x25iface_connect_ind,
43889- &isdn_x25iface_disconn_ind
43890+ .proto_new = &isdn_x25iface_proto_new,
43891+ .proto_del = &isdn_x25iface_proto_del,
43892+ .restart = &isdn_x25iface_proto_restart,
43893+ .close = &isdn_x25iface_proto_close,
43894+ .encap_and_xmit = &isdn_x25iface_xmit,
43895+ .data_ind = &isdn_x25iface_receive,
43896+ .connect_ind = &isdn_x25iface_connect_ind,
43897+ .disconn_ind = &isdn_x25iface_disconn_ind
43898 };
43899
43900 /* error message helper function */
43901diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
43902index 53d487f..cae33fe 100644
43903--- a/drivers/isdn/icn/icn.c
43904+++ b/drivers/isdn/icn/icn.c
43905@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
43906 if (count > len)
43907 count = len;
43908 if (user) {
43909- if (copy_from_user(msg, buf, count))
43910+ if (count > sizeof msg || copy_from_user(msg, buf, count))
43911 return -EFAULT;
43912 } else
43913 memcpy(msg, buf, count);
43914@@ -1155,7 +1155,7 @@ icn_command(isdn_ctrl *c, icn_card *card)
43915 ulong a;
43916 ulong flags;
43917 int i;
43918- char cbuf[60];
43919+ char cbuf[80];
43920 isdn_ctrl cmd;
43921 icn_cdef cdef;
43922 char __user *arg;
43923@@ -1309,7 +1309,6 @@ icn_command(isdn_ctrl *c, icn_card *card)
43924 break;
43925 if ((c->arg & 255) < ICN_BCH) {
43926 char *p;
43927- char dial[50];
43928 char dcode[4];
43929
43930 a = c->arg;
43931@@ -1321,10 +1320,10 @@ icn_command(isdn_ctrl *c, icn_card *card)
43932 } else
43933 /* Normal Dial */
43934 strcpy(dcode, "CAL");
43935- strcpy(dial, p);
43936- sprintf(cbuf, "%02d;D%s_R%s,%02d,%02d,%s\n", (int) (a + 1),
43937- dcode, dial, c->parm.setup.si1,
43938- c->parm.setup.si2, c->parm.setup.eazmsn);
43939+ snprintf(cbuf, sizeof(cbuf),
43940+ "%02d;D%s_R%s,%02d,%02d,%s\n", (int) (a + 1),
43941+ dcode, p, c->parm.setup.si1,
43942+ c->parm.setup.si2, c->parm.setup.eazmsn);
43943 i = icn_writecmd(cbuf, strlen(cbuf), 0, card);
43944 }
43945 break;
43946diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
43947index a4f05c5..1433bc5 100644
43948--- a/drivers/isdn/mISDN/dsp_cmx.c
43949+++ b/drivers/isdn/mISDN/dsp_cmx.c
43950@@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
43951 static u16 dsp_count; /* last sample count */
43952 static int dsp_count_valid; /* if we have last sample count */
43953
43954-void
43955+void __intentional_overflow(-1)
43956 dsp_cmx_send(void *arg)
43957 {
43958 struct dsp_conf *conf;
43959diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
43960index d93e245..e7ece6b 100644
43961--- a/drivers/leds/leds-clevo-mail.c
43962+++ b/drivers/leds/leds-clevo-mail.c
43963@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
43964 * detected as working, but in reality it is not) as low as
43965 * possible.
43966 */
43967-static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
43968+static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
43969 {
43970 .callback = clevo_mail_led_dmi_callback,
43971 .ident = "Clevo D410J",
43972diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
43973index 5b8f938..b73d657 100644
43974--- a/drivers/leds/leds-ss4200.c
43975+++ b/drivers/leds/leds-ss4200.c
43976@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
43977 * detected as working, but in reality it is not) as low as
43978 * possible.
43979 */
43980-static struct dmi_system_id nas_led_whitelist[] __initdata = {
43981+static struct dmi_system_id nas_led_whitelist[] __initconst = {
43982 {
43983 .callback = ss4200_led_dmi_callback,
43984 .ident = "Intel SS4200-E",
43985diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
43986index 0bf1e4e..b4bf44e 100644
43987--- a/drivers/lguest/core.c
43988+++ b/drivers/lguest/core.c
43989@@ -97,9 +97,17 @@ static __init int map_switcher(void)
43990 * The end address needs +1 because __get_vm_area allocates an
43991 * extra guard page, so we need space for that.
43992 */
43993+
43994+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
43995+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43996+ VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
43997+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43998+#else
43999 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
44000 VM_ALLOC, switcher_addr, switcher_addr
44001 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
44002+#endif
44003+
44004 if (!switcher_vma) {
44005 err = -ENOMEM;
44006 printk("lguest: could not map switcher pages high\n");
44007@@ -124,7 +132,7 @@ static __init int map_switcher(void)
44008 * Now the Switcher is mapped at the right address, we can't fail!
44009 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
44010 */
44011- memcpy(switcher_vma->addr, start_switcher_text,
44012+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
44013 end_switcher_text - start_switcher_text);
44014
44015 printk(KERN_INFO "lguest: mapped switcher at %p\n",
44016diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
44017index bfb39bb..08a603b 100644
44018--- a/drivers/lguest/page_tables.c
44019+++ b/drivers/lguest/page_tables.c
44020@@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
44021 /*:*/
44022
44023 #ifdef CONFIG_X86_PAE
44024-static void release_pmd(pmd_t *spmd)
44025+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
44026 {
44027 /* If the entry's not present, there's nothing to release. */
44028 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
44029diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
44030index 922a1ac..9dd0c2a 100644
44031--- a/drivers/lguest/x86/core.c
44032+++ b/drivers/lguest/x86/core.c
44033@@ -59,7 +59,7 @@ static struct {
44034 /* Offset from where switcher.S was compiled to where we've copied it */
44035 static unsigned long switcher_offset(void)
44036 {
44037- return switcher_addr - (unsigned long)start_switcher_text;
44038+ return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
44039 }
44040
44041 /* This cpu's struct lguest_pages (after the Switcher text page) */
44042@@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
44043 * These copies are pretty cheap, so we do them unconditionally: */
44044 /* Save the current Host top-level page directory.
44045 */
44046+
44047+#ifdef CONFIG_PAX_PER_CPU_PGD
44048+ pages->state.host_cr3 = read_cr3();
44049+#else
44050 pages->state.host_cr3 = __pa(current->mm->pgd);
44051+#endif
44052+
44053 /*
44054 * Set up the Guest's page tables to see this CPU's pages (and no
44055 * other CPU's pages).
44056@@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
44057 * compiled-in switcher code and the high-mapped copy we just made.
44058 */
44059 for (i = 0; i < IDT_ENTRIES; i++)
44060- default_idt_entries[i] += switcher_offset();
44061+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
44062
44063 /*
44064 * Set up the Switcher's per-cpu areas.
44065@@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
44066 * it will be undisturbed when we switch. To change %cs and jump we
44067 * need this structure to feed to Intel's "lcall" instruction.
44068 */
44069- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
44070+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
44071 lguest_entry.segment = LGUEST_CS;
44072
44073 /*
44074diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
44075index 40634b0..4f5855e 100644
44076--- a/drivers/lguest/x86/switcher_32.S
44077+++ b/drivers/lguest/x86/switcher_32.S
44078@@ -87,6 +87,7 @@
44079 #include <asm/page.h>
44080 #include <asm/segment.h>
44081 #include <asm/lguest.h>
44082+#include <asm/processor-flags.h>
44083
44084 // We mark the start of the code to copy
44085 // It's placed in .text tho it's never run here
44086@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
44087 // Changes type when we load it: damn Intel!
44088 // For after we switch over our page tables
44089 // That entry will be read-only: we'd crash.
44090+
44091+#ifdef CONFIG_PAX_KERNEXEC
44092+ mov %cr0, %edx
44093+ xor $X86_CR0_WP, %edx
44094+ mov %edx, %cr0
44095+#endif
44096+
44097 movl $(GDT_ENTRY_TSS*8), %edx
44098 ltr %dx
44099
44100@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
44101 // Let's clear it again for our return.
44102 // The GDT descriptor of the Host
44103 // Points to the table after two "size" bytes
44104- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
44105+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
44106 // Clear "used" from type field (byte 5, bit 2)
44107- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
44108+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
44109+
44110+#ifdef CONFIG_PAX_KERNEXEC
44111+ mov %cr0, %eax
44112+ xor $X86_CR0_WP, %eax
44113+ mov %eax, %cr0
44114+#endif
44115
44116 // Once our page table's switched, the Guest is live!
44117 // The Host fades as we run this final step.
44118@@ -295,13 +309,12 @@ deliver_to_host:
44119 // I consulted gcc, and it gave
44120 // These instructions, which I gladly credit:
44121 leal (%edx,%ebx,8), %eax
44122- movzwl (%eax),%edx
44123- movl 4(%eax), %eax
44124- xorw %ax, %ax
44125- orl %eax, %edx
44126+ movl 4(%eax), %edx
44127+ movw (%eax), %dx
44128 // Now the address of the handler's in %edx
44129 // We call it now: its "iret" drops us home.
44130- jmp *%edx
44131+ ljmp $__KERNEL_CS, $1f
44132+1: jmp *%edx
44133
44134 // Every interrupt can come to us here
44135 // But we must truly tell each apart.
44136diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
44137index 7ef7461..5a09dac 100644
44138--- a/drivers/md/bcache/closure.h
44139+++ b/drivers/md/bcache/closure.h
44140@@ -238,7 +238,7 @@ static inline void closure_set_stopped(struct closure *cl)
44141 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
44142 struct workqueue_struct *wq)
44143 {
44144- BUG_ON(object_is_on_stack(cl));
44145+ BUG_ON(object_starts_on_stack(cl));
44146 closure_set_ip(cl);
44147 cl->fn = fn;
44148 cl->wq = wq;
44149diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
44150index 4195a01..42527ac 100644
44151--- a/drivers/md/bitmap.c
44152+++ b/drivers/md/bitmap.c
44153@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
44154 chunk_kb ? "KB" : "B");
44155 if (bitmap->storage.file) {
44156 seq_printf(seq, ", file: ");
44157- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
44158+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
44159 }
44160
44161 seq_printf(seq, "\n");
44162diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
44163index 5152142..623d141 100644
44164--- a/drivers/md/dm-ioctl.c
44165+++ b/drivers/md/dm-ioctl.c
44166@@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
44167 cmd == DM_LIST_VERSIONS_CMD)
44168 return 0;
44169
44170- if ((cmd == DM_DEV_CREATE_CMD)) {
44171+ if (cmd == DM_DEV_CREATE_CMD) {
44172 if (!*param->name) {
44173 DMWARN("name not supplied when creating device");
44174 return -EINVAL;
44175diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
44176index 7dfdb5c..4caada6 100644
44177--- a/drivers/md/dm-raid1.c
44178+++ b/drivers/md/dm-raid1.c
44179@@ -40,7 +40,7 @@ enum dm_raid1_error {
44180
44181 struct mirror {
44182 struct mirror_set *ms;
44183- atomic_t error_count;
44184+ atomic_unchecked_t error_count;
44185 unsigned long error_type;
44186 struct dm_dev *dev;
44187 sector_t offset;
44188@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
44189 struct mirror *m;
44190
44191 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
44192- if (!atomic_read(&m->error_count))
44193+ if (!atomic_read_unchecked(&m->error_count))
44194 return m;
44195
44196 return NULL;
44197@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
44198 * simple way to tell if a device has encountered
44199 * errors.
44200 */
44201- atomic_inc(&m->error_count);
44202+ atomic_inc_unchecked(&m->error_count);
44203
44204 if (test_and_set_bit(error_type, &m->error_type))
44205 return;
44206@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
44207 struct mirror *m = get_default_mirror(ms);
44208
44209 do {
44210- if (likely(!atomic_read(&m->error_count)))
44211+ if (likely(!atomic_read_unchecked(&m->error_count)))
44212 return m;
44213
44214 if (m-- == ms->mirror)
44215@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
44216 {
44217 struct mirror *default_mirror = get_default_mirror(m->ms);
44218
44219- return !atomic_read(&default_mirror->error_count);
44220+ return !atomic_read_unchecked(&default_mirror->error_count);
44221 }
44222
44223 static int mirror_available(struct mirror_set *ms, struct bio *bio)
44224@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
44225 */
44226 if (likely(region_in_sync(ms, region, 1)))
44227 m = choose_mirror(ms, bio->bi_iter.bi_sector);
44228- else if (m && atomic_read(&m->error_count))
44229+ else if (m && atomic_read_unchecked(&m->error_count))
44230 m = NULL;
44231
44232 if (likely(m))
44233@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
44234 }
44235
44236 ms->mirror[mirror].ms = ms;
44237- atomic_set(&(ms->mirror[mirror].error_count), 0);
44238+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
44239 ms->mirror[mirror].error_type = 0;
44240 ms->mirror[mirror].offset = offset;
44241
44242@@ -1342,7 +1342,7 @@ static void mirror_resume(struct dm_target *ti)
44243 */
44244 static char device_status_char(struct mirror *m)
44245 {
44246- if (!atomic_read(&(m->error_count)))
44247+ if (!atomic_read_unchecked(&(m->error_count)))
44248 return 'A';
44249
44250 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
44251diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
44252index 28a9012..9c0f6a5 100644
44253--- a/drivers/md/dm-stats.c
44254+++ b/drivers/md/dm-stats.c
44255@@ -382,7 +382,7 @@ do_sync_free:
44256 synchronize_rcu_expedited();
44257 dm_stat_free(&s->rcu_head);
44258 } else {
44259- ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
44260+ ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
44261 call_rcu(&s->rcu_head, dm_stat_free);
44262 }
44263 return 0;
44264@@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
44265 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
44266 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
44267 ));
44268- ACCESS_ONCE(last->last_sector) = end_sector;
44269- ACCESS_ONCE(last->last_rw) = bi_rw;
44270+ ACCESS_ONCE_RW(last->last_sector) = end_sector;
44271+ ACCESS_ONCE_RW(last->last_rw) = bi_rw;
44272 }
44273
44274 rcu_read_lock();
44275diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
44276index d1600d2..4c3af3a 100644
44277--- a/drivers/md/dm-stripe.c
44278+++ b/drivers/md/dm-stripe.c
44279@@ -21,7 +21,7 @@ struct stripe {
44280 struct dm_dev *dev;
44281 sector_t physical_start;
44282
44283- atomic_t error_count;
44284+ atomic_unchecked_t error_count;
44285 };
44286
44287 struct stripe_c {
44288@@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
44289 kfree(sc);
44290 return r;
44291 }
44292- atomic_set(&(sc->stripe[i].error_count), 0);
44293+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
44294 }
44295
44296 ti->private = sc;
44297@@ -330,7 +330,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
44298 DMEMIT("%d ", sc->stripes);
44299 for (i = 0; i < sc->stripes; i++) {
44300 DMEMIT("%s ", sc->stripe[i].dev->name);
44301- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
44302+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
44303 'D' : 'A';
44304 }
44305 buffer[i] = '\0';
44306@@ -375,8 +375,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
44307 */
44308 for (i = 0; i < sc->stripes; i++)
44309 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
44310- atomic_inc(&(sc->stripe[i].error_count));
44311- if (atomic_read(&(sc->stripe[i].error_count)) <
44312+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
44313+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
44314 DM_IO_ERROR_THRESHOLD)
44315 schedule_work(&sc->trigger_event);
44316 }
44317diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
44318index 6a7f2b8..fea0bde 100644
44319--- a/drivers/md/dm-table.c
44320+++ b/drivers/md/dm-table.c
44321@@ -274,7 +274,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
44322 static int open_dev(struct dm_dev_internal *d, dev_t dev,
44323 struct mapped_device *md)
44324 {
44325- static char *_claim_ptr = "I belong to device-mapper";
44326+ static char _claim_ptr[] = "I belong to device-mapper";
44327 struct block_device *bdev;
44328
44329 int r;
44330@@ -342,7 +342,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
44331 if (!dev_size)
44332 return 0;
44333
44334- if ((start >= dev_size) || (start + len > dev_size)) {
44335+ if ((start >= dev_size) || (len > dev_size - start)) {
44336 DMWARN("%s: %s too small for target: "
44337 "start=%llu, len=%llu, dev_size=%llu",
44338 dm_device_name(ti->table->md), bdevname(bdev, b),
44339diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
44340index fb9efc8..81e8986 100644
44341--- a/drivers/md/dm-thin-metadata.c
44342+++ b/drivers/md/dm-thin-metadata.c
44343@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
44344 {
44345 pmd->info.tm = pmd->tm;
44346 pmd->info.levels = 2;
44347- pmd->info.value_type.context = pmd->data_sm;
44348+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
44349 pmd->info.value_type.size = sizeof(__le64);
44350 pmd->info.value_type.inc = data_block_inc;
44351 pmd->info.value_type.dec = data_block_dec;
44352@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
44353
44354 pmd->bl_info.tm = pmd->tm;
44355 pmd->bl_info.levels = 1;
44356- pmd->bl_info.value_type.context = pmd->data_sm;
44357+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
44358 pmd->bl_info.value_type.size = sizeof(__le64);
44359 pmd->bl_info.value_type.inc = data_block_inc;
44360 pmd->bl_info.value_type.dec = data_block_dec;
44361diff --git a/drivers/md/dm.c b/drivers/md/dm.c
44362index 8c53b09..f1fb2b0 100644
44363--- a/drivers/md/dm.c
44364+++ b/drivers/md/dm.c
44365@@ -185,9 +185,9 @@ struct mapped_device {
44366 /*
44367 * Event handling.
44368 */
44369- atomic_t event_nr;
44370+ atomic_unchecked_t event_nr;
44371 wait_queue_head_t eventq;
44372- atomic_t uevent_seq;
44373+ atomic_unchecked_t uevent_seq;
44374 struct list_head uevent_list;
44375 spinlock_t uevent_lock; /* Protect access to uevent_list */
44376
44377@@ -1888,8 +1888,8 @@ static struct mapped_device *alloc_dev(int minor)
44378 spin_lock_init(&md->deferred_lock);
44379 atomic_set(&md->holders, 1);
44380 atomic_set(&md->open_count, 0);
44381- atomic_set(&md->event_nr, 0);
44382- atomic_set(&md->uevent_seq, 0);
44383+ atomic_set_unchecked(&md->event_nr, 0);
44384+ atomic_set_unchecked(&md->uevent_seq, 0);
44385 INIT_LIST_HEAD(&md->uevent_list);
44386 spin_lock_init(&md->uevent_lock);
44387
44388@@ -2043,7 +2043,7 @@ static void event_callback(void *context)
44389
44390 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
44391
44392- atomic_inc(&md->event_nr);
44393+ atomic_inc_unchecked(&md->event_nr);
44394 wake_up(&md->eventq);
44395 }
44396
44397@@ -2736,18 +2736,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
44398
44399 uint32_t dm_next_uevent_seq(struct mapped_device *md)
44400 {
44401- return atomic_add_return(1, &md->uevent_seq);
44402+ return atomic_add_return_unchecked(1, &md->uevent_seq);
44403 }
44404
44405 uint32_t dm_get_event_nr(struct mapped_device *md)
44406 {
44407- return atomic_read(&md->event_nr);
44408+ return atomic_read_unchecked(&md->event_nr);
44409 }
44410
44411 int dm_wait_event(struct mapped_device *md, int event_nr)
44412 {
44413 return wait_event_interruptible(md->eventq,
44414- (event_nr != atomic_read(&md->event_nr)));
44415+ (event_nr != atomic_read_unchecked(&md->event_nr)));
44416 }
44417
44418 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
44419diff --git a/drivers/md/md.c b/drivers/md/md.c
44420index 4ad5cc4..0f19664 100644
44421--- a/drivers/md/md.c
44422+++ b/drivers/md/md.c
44423@@ -194,10 +194,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
44424 * start build, activate spare
44425 */
44426 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
44427-static atomic_t md_event_count;
44428+static atomic_unchecked_t md_event_count;
44429 void md_new_event(struct mddev *mddev)
44430 {
44431- atomic_inc(&md_event_count);
44432+ atomic_inc_unchecked(&md_event_count);
44433 wake_up(&md_event_waiters);
44434 }
44435 EXPORT_SYMBOL_GPL(md_new_event);
44436@@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
44437 */
44438 static void md_new_event_inintr(struct mddev *mddev)
44439 {
44440- atomic_inc(&md_event_count);
44441+ atomic_inc_unchecked(&md_event_count);
44442 wake_up(&md_event_waiters);
44443 }
44444
44445@@ -1462,7 +1462,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
44446 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
44447 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
44448 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
44449- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
44450+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
44451
44452 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
44453 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
44454@@ -1713,7 +1713,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
44455 else
44456 sb->resync_offset = cpu_to_le64(0);
44457
44458- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
44459+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
44460
44461 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
44462 sb->size = cpu_to_le64(mddev->dev_sectors);
44463@@ -2725,7 +2725,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
44464 static ssize_t
44465 errors_show(struct md_rdev *rdev, char *page)
44466 {
44467- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
44468+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
44469 }
44470
44471 static ssize_t
44472@@ -2734,7 +2734,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
44473 char *e;
44474 unsigned long n = simple_strtoul(buf, &e, 10);
44475 if (*buf && (*e == 0 || *e == '\n')) {
44476- atomic_set(&rdev->corrected_errors, n);
44477+ atomic_set_unchecked(&rdev->corrected_errors, n);
44478 return len;
44479 }
44480 return -EINVAL;
44481@@ -3183,8 +3183,8 @@ int md_rdev_init(struct md_rdev *rdev)
44482 rdev->sb_loaded = 0;
44483 rdev->bb_page = NULL;
44484 atomic_set(&rdev->nr_pending, 0);
44485- atomic_set(&rdev->read_errors, 0);
44486- atomic_set(&rdev->corrected_errors, 0);
44487+ atomic_set_unchecked(&rdev->read_errors, 0);
44488+ atomic_set_unchecked(&rdev->corrected_errors, 0);
44489
44490 INIT_LIST_HEAD(&rdev->same_set);
44491 init_waitqueue_head(&rdev->blocked_wait);
44492@@ -7075,7 +7075,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
44493
44494 spin_unlock(&pers_lock);
44495 seq_printf(seq, "\n");
44496- seq->poll_event = atomic_read(&md_event_count);
44497+ seq->poll_event = atomic_read_unchecked(&md_event_count);
44498 return 0;
44499 }
44500 if (v == (void*)2) {
44501@@ -7178,7 +7178,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
44502 return error;
44503
44504 seq = file->private_data;
44505- seq->poll_event = atomic_read(&md_event_count);
44506+ seq->poll_event = atomic_read_unchecked(&md_event_count);
44507 return error;
44508 }
44509
44510@@ -7192,7 +7192,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
44511 /* always allow read */
44512 mask = POLLIN | POLLRDNORM;
44513
44514- if (seq->poll_event != atomic_read(&md_event_count))
44515+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
44516 mask |= POLLERR | POLLPRI;
44517 return mask;
44518 }
44519@@ -7236,7 +7236,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
44520 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
44521 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
44522 (int)part_stat_read(&disk->part0, sectors[1]) -
44523- atomic_read(&disk->sync_io);
44524+ atomic_read_unchecked(&disk->sync_io);
44525 /* sync IO will cause sync_io to increase before the disk_stats
44526 * as sync_io is counted when a request starts, and
44527 * disk_stats is counted when it completes.
44528diff --git a/drivers/md/md.h b/drivers/md/md.h
44529index 07bba96..2d6788c 100644
44530--- a/drivers/md/md.h
44531+++ b/drivers/md/md.h
44532@@ -94,13 +94,13 @@ struct md_rdev {
44533 * only maintained for arrays that
44534 * support hot removal
44535 */
44536- atomic_t read_errors; /* number of consecutive read errors that
44537+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
44538 * we have tried to ignore.
44539 */
44540 struct timespec last_read_error; /* monotonic time since our
44541 * last read error
44542 */
44543- atomic_t corrected_errors; /* number of corrected read errors,
44544+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
44545 * for reporting to userspace and storing
44546 * in superblock.
44547 */
44548@@ -449,7 +449,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
44549
44550 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
44551 {
44552- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44553+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44554 }
44555
44556 struct md_personality
44557diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
44558index 786b689..ea8c956 100644
44559--- a/drivers/md/persistent-data/dm-space-map-metadata.c
44560+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
44561@@ -679,7 +679,7 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
44562 * Flick into a mode where all blocks get allocated in the new area.
44563 */
44564 smm->begin = old_len;
44565- memcpy(sm, &bootstrap_ops, sizeof(*sm));
44566+ memcpy((void *)sm, &bootstrap_ops, sizeof(*sm));
44567
44568 /*
44569 * Extend.
44570@@ -710,7 +710,7 @@ out:
44571 /*
44572 * Switch back to normal behaviour.
44573 */
44574- memcpy(sm, &ops, sizeof(*sm));
44575+ memcpy((void *)sm, &ops, sizeof(*sm));
44576 return r;
44577 }
44578
44579diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
44580index 3e6d115..ffecdeb 100644
44581--- a/drivers/md/persistent-data/dm-space-map.h
44582+++ b/drivers/md/persistent-data/dm-space-map.h
44583@@ -71,6 +71,7 @@ struct dm_space_map {
44584 dm_sm_threshold_fn fn,
44585 void *context);
44586 };
44587+typedef struct dm_space_map __no_const dm_space_map_no_const;
44588
44589 /*----------------------------------------------------------------*/
44590
44591diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
44592index 4a6ca1c..e952750 100644
44593--- a/drivers/md/raid1.c
44594+++ b/drivers/md/raid1.c
44595@@ -1922,7 +1922,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
44596 if (r1_sync_page_io(rdev, sect, s,
44597 bio->bi_io_vec[idx].bv_page,
44598 READ) != 0)
44599- atomic_add(s, &rdev->corrected_errors);
44600+ atomic_add_unchecked(s, &rdev->corrected_errors);
44601 }
44602 sectors -= s;
44603 sect += s;
44604@@ -2156,7 +2156,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
44605 test_bit(In_sync, &rdev->flags)) {
44606 if (r1_sync_page_io(rdev, sect, s,
44607 conf->tmppage, READ)) {
44608- atomic_add(s, &rdev->corrected_errors);
44609+ atomic_add_unchecked(s, &rdev->corrected_errors);
44610 printk(KERN_INFO
44611 "md/raid1:%s: read error corrected "
44612 "(%d sectors at %llu on %s)\n",
44613diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
44614index 33fc408..fc61709 100644
44615--- a/drivers/md/raid10.c
44616+++ b/drivers/md/raid10.c
44617@@ -1948,7 +1948,7 @@ static void end_sync_read(struct bio *bio, int error)
44618 /* The write handler will notice the lack of
44619 * R10BIO_Uptodate and record any errors etc
44620 */
44621- atomic_add(r10_bio->sectors,
44622+ atomic_add_unchecked(r10_bio->sectors,
44623 &conf->mirrors[d].rdev->corrected_errors);
44624
44625 /* for reconstruct, we always reschedule after a read.
44626@@ -2306,7 +2306,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44627 {
44628 struct timespec cur_time_mon;
44629 unsigned long hours_since_last;
44630- unsigned int read_errors = atomic_read(&rdev->read_errors);
44631+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
44632
44633 ktime_get_ts(&cur_time_mon);
44634
44635@@ -2328,9 +2328,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44636 * overflowing the shift of read_errors by hours_since_last.
44637 */
44638 if (hours_since_last >= 8 * sizeof(read_errors))
44639- atomic_set(&rdev->read_errors, 0);
44640+ atomic_set_unchecked(&rdev->read_errors, 0);
44641 else
44642- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
44643+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
44644 }
44645
44646 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
44647@@ -2384,8 +2384,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44648 return;
44649
44650 check_decay_read_errors(mddev, rdev);
44651- atomic_inc(&rdev->read_errors);
44652- if (atomic_read(&rdev->read_errors) > max_read_errors) {
44653+ atomic_inc_unchecked(&rdev->read_errors);
44654+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
44655 char b[BDEVNAME_SIZE];
44656 bdevname(rdev->bdev, b);
44657
44658@@ -2393,7 +2393,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44659 "md/raid10:%s: %s: Raid device exceeded "
44660 "read_error threshold [cur %d:max %d]\n",
44661 mdname(mddev), b,
44662- atomic_read(&rdev->read_errors), max_read_errors);
44663+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
44664 printk(KERN_NOTICE
44665 "md/raid10:%s: %s: Failing raid device\n",
44666 mdname(mddev), b);
44667@@ -2548,7 +2548,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44668 sect +
44669 choose_data_offset(r10_bio, rdev)),
44670 bdevname(rdev->bdev, b));
44671- atomic_add(s, &rdev->corrected_errors);
44672+ atomic_add_unchecked(s, &rdev->corrected_errors);
44673 }
44674
44675 rdev_dec_pending(rdev, mddev);
44676diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
44677index 16f5c21..4df20dc 100644
44678--- a/drivers/md/raid5.c
44679+++ b/drivers/md/raid5.c
44680@@ -1991,21 +1991,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
44681 mdname(conf->mddev), STRIPE_SECTORS,
44682 (unsigned long long)s,
44683 bdevname(rdev->bdev, b));
44684- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
44685+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
44686 clear_bit(R5_ReadError, &sh->dev[i].flags);
44687 clear_bit(R5_ReWrite, &sh->dev[i].flags);
44688 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
44689 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
44690
44691- if (atomic_read(&rdev->read_errors))
44692- atomic_set(&rdev->read_errors, 0);
44693+ if (atomic_read_unchecked(&rdev->read_errors))
44694+ atomic_set_unchecked(&rdev->read_errors, 0);
44695 } else {
44696 const char *bdn = bdevname(rdev->bdev, b);
44697 int retry = 0;
44698 int set_bad = 0;
44699
44700 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
44701- atomic_inc(&rdev->read_errors);
44702+ atomic_inc_unchecked(&rdev->read_errors);
44703 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
44704 printk_ratelimited(
44705 KERN_WARNING
44706@@ -2033,7 +2033,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
44707 mdname(conf->mddev),
44708 (unsigned long long)s,
44709 bdn);
44710- } else if (atomic_read(&rdev->read_errors)
44711+ } else if (atomic_read_unchecked(&rdev->read_errors)
44712 > conf->max_nr_stripes)
44713 printk(KERN_WARNING
44714 "md/raid:%s: Too many read errors, failing device %s.\n",
44715diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
44716index 983db75..ef9248c 100644
44717--- a/drivers/media/dvb-core/dvbdev.c
44718+++ b/drivers/media/dvb-core/dvbdev.c
44719@@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
44720 const struct dvb_device *template, void *priv, int type)
44721 {
44722 struct dvb_device *dvbdev;
44723- struct file_operations *dvbdevfops;
44724+ file_operations_no_const *dvbdevfops;
44725 struct device *clsdev;
44726 int minor;
44727 int id;
44728diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
44729index 9b6c3bb..baeb5c7 100644
44730--- a/drivers/media/dvb-frontends/dib3000.h
44731+++ b/drivers/media/dvb-frontends/dib3000.h
44732@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
44733 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
44734 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
44735 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
44736-};
44737+} __no_const;
44738
44739 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
44740 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
44741diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
44742index d5a7a13..703560f 100644
44743--- a/drivers/media/media-device.c
44744+++ b/drivers/media/media-device.c
44745@@ -93,6 +93,7 @@ static long media_device_enum_entities(struct media_device *mdev,
44746 struct media_entity *ent;
44747 struct media_entity_desc u_ent;
44748
44749+ memset(&u_ent, 0, sizeof(u_ent));
44750 if (copy_from_user(&u_ent.id, &uent->id, sizeof(u_ent.id)))
44751 return -EFAULT;
44752
44753diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
44754index ed8cb90..5ef7f79 100644
44755--- a/drivers/media/pci/cx88/cx88-video.c
44756+++ b/drivers/media/pci/cx88/cx88-video.c
44757@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
44758
44759 /* ------------------------------------------------------------------ */
44760
44761-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44762-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44763-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44764+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44765+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44766+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44767
44768 module_param_array(video_nr, int, NULL, 0444);
44769 module_param_array(vbi_nr, int, NULL, 0444);
44770diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
44771index 802642d..5534900 100644
44772--- a/drivers/media/pci/ivtv/ivtv-driver.c
44773+++ b/drivers/media/pci/ivtv/ivtv-driver.c
44774@@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
44775 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
44776
44777 /* ivtv instance counter */
44778-static atomic_t ivtv_instance = ATOMIC_INIT(0);
44779+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
44780
44781 /* Parameter declarations */
44782 static int cardtype[IVTV_MAX_CARDS];
44783diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
44784index dfd0a21..6bbb465 100644
44785--- a/drivers/media/platform/omap/omap_vout.c
44786+++ b/drivers/media/platform/omap/omap_vout.c
44787@@ -63,7 +63,6 @@ enum omap_vout_channels {
44788 OMAP_VIDEO2,
44789 };
44790
44791-static struct videobuf_queue_ops video_vbq_ops;
44792 /* Variables configurable through module params*/
44793 static u32 video1_numbuffers = 3;
44794 static u32 video2_numbuffers = 3;
44795@@ -1014,6 +1013,12 @@ static int omap_vout_open(struct file *file)
44796 {
44797 struct videobuf_queue *q;
44798 struct omap_vout_device *vout = NULL;
44799+ static struct videobuf_queue_ops video_vbq_ops = {
44800+ .buf_setup = omap_vout_buffer_setup,
44801+ .buf_prepare = omap_vout_buffer_prepare,
44802+ .buf_release = omap_vout_buffer_release,
44803+ .buf_queue = omap_vout_buffer_queue,
44804+ };
44805
44806 vout = video_drvdata(file);
44807 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
44808@@ -1031,10 +1036,6 @@ static int omap_vout_open(struct file *file)
44809 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
44810
44811 q = &vout->vbq;
44812- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
44813- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
44814- video_vbq_ops.buf_release = omap_vout_buffer_release;
44815- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
44816 spin_lock_init(&vout->vbq_lock);
44817
44818 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
44819diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
44820index fb2acc5..a2fcbdc4 100644
44821--- a/drivers/media/platform/s5p-tv/mixer.h
44822+++ b/drivers/media/platform/s5p-tv/mixer.h
44823@@ -156,7 +156,7 @@ struct mxr_layer {
44824 /** layer index (unique identifier) */
44825 int idx;
44826 /** callbacks for layer methods */
44827- struct mxr_layer_ops ops;
44828+ struct mxr_layer_ops *ops;
44829 /** format array */
44830 const struct mxr_format **fmt_array;
44831 /** size of format array */
44832diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44833index 74344c7..a39e70e 100644
44834--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44835+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44836@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
44837 {
44838 struct mxr_layer *layer;
44839 int ret;
44840- struct mxr_layer_ops ops = {
44841+ static struct mxr_layer_ops ops = {
44842 .release = mxr_graph_layer_release,
44843 .buffer_set = mxr_graph_buffer_set,
44844 .stream_set = mxr_graph_stream_set,
44845diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
44846index b713403..53cb5ad 100644
44847--- a/drivers/media/platform/s5p-tv/mixer_reg.c
44848+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
44849@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
44850 layer->update_buf = next;
44851 }
44852
44853- layer->ops.buffer_set(layer, layer->update_buf);
44854+ layer->ops->buffer_set(layer, layer->update_buf);
44855
44856 if (done && done != layer->shadow_buf)
44857 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
44858diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
44859index c5059ba..2649f28 100644
44860--- a/drivers/media/platform/s5p-tv/mixer_video.c
44861+++ b/drivers/media/platform/s5p-tv/mixer_video.c
44862@@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
44863 layer->geo.src.height = layer->geo.src.full_height;
44864
44865 mxr_geometry_dump(mdev, &layer->geo);
44866- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44867+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44868 mxr_geometry_dump(mdev, &layer->geo);
44869 }
44870
44871@@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
44872 layer->geo.dst.full_width = mbus_fmt.width;
44873 layer->geo.dst.full_height = mbus_fmt.height;
44874 layer->geo.dst.field = mbus_fmt.field;
44875- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44876+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44877
44878 mxr_geometry_dump(mdev, &layer->geo);
44879 }
44880@@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
44881 /* set source size to highest accepted value */
44882 geo->src.full_width = max(geo->dst.full_width, pix->width);
44883 geo->src.full_height = max(geo->dst.full_height, pix->height);
44884- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44885+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44886 mxr_geometry_dump(mdev, &layer->geo);
44887 /* set cropping to total visible screen */
44888 geo->src.width = pix->width;
44889@@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
44890 geo->src.x_offset = 0;
44891 geo->src.y_offset = 0;
44892 /* assure consistency of geometry */
44893- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44894+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44895 mxr_geometry_dump(mdev, &layer->geo);
44896 /* set full size to lowest possible value */
44897 geo->src.full_width = 0;
44898 geo->src.full_height = 0;
44899- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44900+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44901 mxr_geometry_dump(mdev, &layer->geo);
44902
44903 /* returning results */
44904@@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
44905 target->width = s->r.width;
44906 target->height = s->r.height;
44907
44908- layer->ops.fix_geometry(layer, stage, s->flags);
44909+ layer->ops->fix_geometry(layer, stage, s->flags);
44910
44911 /* retrieve update selection rectangle */
44912 res.left = target->x_offset;
44913@@ -955,13 +955,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
44914 mxr_output_get(mdev);
44915
44916 mxr_layer_update_output(layer);
44917- layer->ops.format_set(layer);
44918+ layer->ops->format_set(layer);
44919 /* enabling layer in hardware */
44920 spin_lock_irqsave(&layer->enq_slock, flags);
44921 layer->state = MXR_LAYER_STREAMING;
44922 spin_unlock_irqrestore(&layer->enq_slock, flags);
44923
44924- layer->ops.stream_set(layer, MXR_ENABLE);
44925+ layer->ops->stream_set(layer, MXR_ENABLE);
44926 mxr_streamer_get(mdev);
44927
44928 return 0;
44929@@ -1031,7 +1031,7 @@ static int stop_streaming(struct vb2_queue *vq)
44930 spin_unlock_irqrestore(&layer->enq_slock, flags);
44931
44932 /* disabling layer in hardware */
44933- layer->ops.stream_set(layer, MXR_DISABLE);
44934+ layer->ops->stream_set(layer, MXR_DISABLE);
44935 /* remove one streamer */
44936 mxr_streamer_put(mdev);
44937 /* allow changes in output configuration */
44938@@ -1070,8 +1070,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
44939
44940 void mxr_layer_release(struct mxr_layer *layer)
44941 {
44942- if (layer->ops.release)
44943- layer->ops.release(layer);
44944+ if (layer->ops->release)
44945+ layer->ops->release(layer);
44946 }
44947
44948 void mxr_base_layer_release(struct mxr_layer *layer)
44949@@ -1097,7 +1097,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
44950
44951 layer->mdev = mdev;
44952 layer->idx = idx;
44953- layer->ops = *ops;
44954+ layer->ops = ops;
44955
44956 spin_lock_init(&layer->enq_slock);
44957 INIT_LIST_HEAD(&layer->enq_list);
44958diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44959index c9388c4..ce71ece 100644
44960--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44961+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44962@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
44963 {
44964 struct mxr_layer *layer;
44965 int ret;
44966- struct mxr_layer_ops ops = {
44967+ static struct mxr_layer_ops ops = {
44968 .release = mxr_vp_layer_release,
44969 .buffer_set = mxr_vp_buffer_set,
44970 .stream_set = mxr_vp_stream_set,
44971diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
44972index 2d4e73b..8b4d5b6 100644
44973--- a/drivers/media/platform/vivi.c
44974+++ b/drivers/media/platform/vivi.c
44975@@ -58,8 +58,8 @@ MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
44976 MODULE_LICENSE("Dual BSD/GPL");
44977 MODULE_VERSION(VIVI_VERSION);
44978
44979-static unsigned video_nr = -1;
44980-module_param(video_nr, uint, 0644);
44981+static int video_nr = -1;
44982+module_param(video_nr, int, 0644);
44983 MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect");
44984
44985 static unsigned n_devs = 1;
44986diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
44987index 545c04c..a14bded 100644
44988--- a/drivers/media/radio/radio-cadet.c
44989+++ b/drivers/media/radio/radio-cadet.c
44990@@ -324,6 +324,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44991 unsigned char readbuf[RDS_BUFFER];
44992 int i = 0;
44993
44994+ if (count > RDS_BUFFER)
44995+ return -EFAULT;
44996 mutex_lock(&dev->lock);
44997 if (dev->rdsstat == 0)
44998 cadet_start_rds(dev);
44999@@ -339,7 +341,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
45000 while (i < count && dev->rdsin != dev->rdsout)
45001 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
45002
45003- if (i && copy_to_user(data, readbuf, i))
45004+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
45005 i = -EFAULT;
45006 unlock:
45007 mutex_unlock(&dev->lock);
45008diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
45009index 5236035..c622c74 100644
45010--- a/drivers/media/radio/radio-maxiradio.c
45011+++ b/drivers/media/radio/radio-maxiradio.c
45012@@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
45013 /* TEA5757 pin mappings */
45014 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
45015
45016-static atomic_t maxiradio_instance = ATOMIC_INIT(0);
45017+static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
45018
45019 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
45020 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
45021diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
45022index 050b3bb..79f62b9 100644
45023--- a/drivers/media/radio/radio-shark.c
45024+++ b/drivers/media/radio/radio-shark.c
45025@@ -79,7 +79,7 @@ struct shark_device {
45026 u32 last_val;
45027 };
45028
45029-static atomic_t shark_instance = ATOMIC_INIT(0);
45030+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
45031
45032 static void shark_write_val(struct snd_tea575x *tea, u32 val)
45033 {
45034diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
45035index 8654e0d..0608a64 100644
45036--- a/drivers/media/radio/radio-shark2.c
45037+++ b/drivers/media/radio/radio-shark2.c
45038@@ -74,7 +74,7 @@ struct shark_device {
45039 u8 *transfer_buffer;
45040 };
45041
45042-static atomic_t shark_instance = ATOMIC_INIT(0);
45043+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
45044
45045 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
45046 {
45047diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
45048index 2fd9009..278cc1e 100644
45049--- a/drivers/media/radio/radio-si476x.c
45050+++ b/drivers/media/radio/radio-si476x.c
45051@@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
45052 struct si476x_radio *radio;
45053 struct v4l2_ctrl *ctrl;
45054
45055- static atomic_t instance = ATOMIC_INIT(0);
45056+ static atomic_unchecked_t instance = ATOMIC_INIT(0);
45057
45058 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
45059 if (!radio)
45060diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
45061index a1c641e..3007da9 100644
45062--- a/drivers/media/usb/dvb-usb/cxusb.c
45063+++ b/drivers/media/usb/dvb-usb/cxusb.c
45064@@ -1112,7 +1112,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
45065
45066 struct dib0700_adapter_state {
45067 int (*set_param_save) (struct dvb_frontend *);
45068-};
45069+} __no_const;
45070
45071 static int dib7070_set_param_override(struct dvb_frontend *fe)
45072 {
45073diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
45074index ae0f56a..ec71784 100644
45075--- a/drivers/media/usb/dvb-usb/dw2102.c
45076+++ b/drivers/media/usb/dvb-usb/dw2102.c
45077@@ -118,7 +118,7 @@ struct su3000_state {
45078
45079 struct s6x0_state {
45080 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
45081-};
45082+} __no_const;
45083
45084 /* debug */
45085 static int dvb_usb_dw2102_debug;
45086diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
45087index b63a5e5..b16a062 100644
45088--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
45089+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
45090@@ -326,7 +326,7 @@ struct v4l2_buffer32 {
45091 __u32 reserved;
45092 };
45093
45094-static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
45095+static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
45096 enum v4l2_memory memory)
45097 {
45098 void __user *up_pln;
45099@@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
45100 return 0;
45101 }
45102
45103-static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
45104+static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
45105 enum v4l2_memory memory)
45106 {
45107 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
45108@@ -425,7 +425,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
45109 * by passing a very big num_planes value */
45110 uplane = compat_alloc_user_space(num_planes *
45111 sizeof(struct v4l2_plane));
45112- kp->m.planes = uplane;
45113+ kp->m.planes = (struct v4l2_plane __force_kernel *)uplane;
45114
45115 while (--num_planes >= 0) {
45116 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
45117@@ -496,7 +496,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
45118 if (num_planes == 0)
45119 return 0;
45120
45121- uplane = kp->m.planes;
45122+ uplane = (struct v4l2_plane __force_user *)kp->m.planes;
45123 if (get_user(p, &up->m.planes))
45124 return -EFAULT;
45125 uplane32 = compat_ptr(p);
45126@@ -550,7 +550,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
45127 get_user(kp->capability, &up->capability) ||
45128 get_user(kp->flags, &up->flags))
45129 return -EFAULT;
45130- kp->base = compat_ptr(tmp);
45131+ kp->base = (void __force_kernel *)compat_ptr(tmp);
45132 get_v4l2_pix_format(&kp->fmt, &up->fmt);
45133 return 0;
45134 }
45135@@ -656,7 +656,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
45136 n * sizeof(struct v4l2_ext_control32)))
45137 return -EFAULT;
45138 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
45139- kp->controls = kcontrols;
45140+ kp->controls = (struct v4l2_ext_control __force_kernel *)kcontrols;
45141 while (--n >= 0) {
45142 if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
45143 return -EFAULT;
45144@@ -678,7 +678,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
45145 static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
45146 {
45147 struct v4l2_ext_control32 __user *ucontrols;
45148- struct v4l2_ext_control __user *kcontrols = kp->controls;
45149+ struct v4l2_ext_control __user *kcontrols = (struct v4l2_ext_control __force_user *)kp->controls;
45150 int n = kp->count;
45151 compat_caddr_t p;
45152
45153@@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
45154 put_user(kp->start_block, &up->start_block) ||
45155 put_user(kp->blocks, &up->blocks) ||
45156 put_user(tmp, &up->edid) ||
45157- copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
45158+ copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
45159 return -EFAULT;
45160 return 0;
45161 }
45162diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
45163index 6ff002b..6b9316b 100644
45164--- a/drivers/media/v4l2-core/v4l2-ctrls.c
45165+++ b/drivers/media/v4l2-core/v4l2-ctrls.c
45166@@ -1401,8 +1401,8 @@ static int validate_new(const struct v4l2_ctrl *ctrl,
45167 return 0;
45168
45169 case V4L2_CTRL_TYPE_STRING:
45170- len = strlen(c->string);
45171- if (len < ctrl->minimum)
45172+ len = strlen_user(c->string);
45173+ if (!len || len < ctrl->minimum)
45174 return -ERANGE;
45175 if ((len - ctrl->minimum) % ctrl->step)
45176 return -ERANGE;
45177diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
45178index 02d1b63..5fd6b16 100644
45179--- a/drivers/media/v4l2-core/v4l2-device.c
45180+++ b/drivers/media/v4l2-core/v4l2-device.c
45181@@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
45182 EXPORT_SYMBOL_GPL(v4l2_device_put);
45183
45184 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
45185- atomic_t *instance)
45186+ atomic_unchecked_t *instance)
45187 {
45188- int num = atomic_inc_return(instance) - 1;
45189+ int num = atomic_inc_return_unchecked(instance) - 1;
45190 int len = strlen(basename);
45191
45192 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
45193diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
45194index 707aef7..93b8ac0 100644
45195--- a/drivers/media/v4l2-core/v4l2-ioctl.c
45196+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
45197@@ -1942,7 +1942,8 @@ struct v4l2_ioctl_info {
45198 struct file *file, void *fh, void *p);
45199 } u;
45200 void (*debug)(const void *arg, bool write_only);
45201-};
45202+} __do_const;
45203+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
45204
45205 /* This control needs a priority check */
45206 #define INFO_FL_PRIO (1 << 0)
45207@@ -2123,7 +2124,7 @@ static long __video_do_ioctl(struct file *file,
45208 struct video_device *vfd = video_devdata(file);
45209 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
45210 bool write_only = false;
45211- struct v4l2_ioctl_info default_info;
45212+ v4l2_ioctl_info_no_const default_info;
45213 const struct v4l2_ioctl_info *info;
45214 void *fh = file->private_data;
45215 struct v4l2_fh *vfh = NULL;
45216@@ -2197,7 +2198,7 @@ done:
45217 }
45218
45219 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
45220- void * __user *user_ptr, void ***kernel_ptr)
45221+ void __user **user_ptr, void ***kernel_ptr)
45222 {
45223 int ret = 0;
45224
45225@@ -2213,7 +2214,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
45226 ret = -EINVAL;
45227 break;
45228 }
45229- *user_ptr = (void __user *)buf->m.planes;
45230+ *user_ptr = (void __force_user *)buf->m.planes;
45231 *kernel_ptr = (void *)&buf->m.planes;
45232 *array_size = sizeof(struct v4l2_plane) * buf->length;
45233 ret = 1;
45234@@ -2248,7 +2249,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
45235 ret = -EINVAL;
45236 break;
45237 }
45238- *user_ptr = (void __user *)ctrls->controls;
45239+ *user_ptr = (void __force_user *)ctrls->controls;
45240 *kernel_ptr = (void *)&ctrls->controls;
45241 *array_size = sizeof(struct v4l2_ext_control)
45242 * ctrls->count;
45243@@ -2349,7 +2350,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
45244 }
45245
45246 if (has_array_args) {
45247- *kernel_ptr = user_ptr;
45248+ *kernel_ptr = (void __force_kernel *)user_ptr;
45249 if (copy_to_user(user_ptr, mbuf, array_size))
45250 err = -EFAULT;
45251 goto out_array_args;
45252diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
45253index 570b18a..f880314 100644
45254--- a/drivers/message/fusion/mptbase.c
45255+++ b/drivers/message/fusion/mptbase.c
45256@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
45257 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
45258 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
45259
45260+#ifdef CONFIG_GRKERNSEC_HIDESYM
45261+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
45262+#else
45263 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
45264 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
45265+#endif
45266+
45267 /*
45268 * Rounding UP to nearest 4-kB boundary here...
45269 */
45270@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
45271 ioc->facts.GlobalCredits);
45272
45273 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
45274+#ifdef CONFIG_GRKERNSEC_HIDESYM
45275+ NULL, NULL);
45276+#else
45277 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
45278+#endif
45279 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
45280 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
45281 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
45282diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
45283index 00d339c..2ea899d 100644
45284--- a/drivers/message/fusion/mptsas.c
45285+++ b/drivers/message/fusion/mptsas.c
45286@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
45287 return 0;
45288 }
45289
45290+static inline void
45291+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
45292+{
45293+ if (phy_info->port_details) {
45294+ phy_info->port_details->rphy = rphy;
45295+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
45296+ ioc->name, rphy));
45297+ }
45298+
45299+ if (rphy) {
45300+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
45301+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
45302+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
45303+ ioc->name, rphy, rphy->dev.release));
45304+ }
45305+}
45306+
45307 /* no mutex */
45308 static void
45309 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
45310@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
45311 return NULL;
45312 }
45313
45314-static inline void
45315-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
45316-{
45317- if (phy_info->port_details) {
45318- phy_info->port_details->rphy = rphy;
45319- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
45320- ioc->name, rphy));
45321- }
45322-
45323- if (rphy) {
45324- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
45325- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
45326- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
45327- ioc->name, rphy, rphy->dev.release));
45328- }
45329-}
45330-
45331 static inline struct sas_port *
45332 mptsas_get_port(struct mptsas_phyinfo *phy_info)
45333 {
45334diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
45335index 727819c..ad74694 100644
45336--- a/drivers/message/fusion/mptscsih.c
45337+++ b/drivers/message/fusion/mptscsih.c
45338@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
45339
45340 h = shost_priv(SChost);
45341
45342- if (h) {
45343- if (h->info_kbuf == NULL)
45344- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
45345- return h->info_kbuf;
45346- h->info_kbuf[0] = '\0';
45347+ if (!h)
45348+ return NULL;
45349
45350- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
45351- h->info_kbuf[size-1] = '\0';
45352- }
45353+ if (h->info_kbuf == NULL)
45354+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
45355+ return h->info_kbuf;
45356+ h->info_kbuf[0] = '\0';
45357+
45358+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
45359+ h->info_kbuf[size-1] = '\0';
45360
45361 return h->info_kbuf;
45362 }
45363diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
45364index b7d87cd..3fb36da 100644
45365--- a/drivers/message/i2o/i2o_proc.c
45366+++ b/drivers/message/i2o/i2o_proc.c
45367@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
45368 "Array Controller Device"
45369 };
45370
45371-static char *chtostr(char *tmp, u8 *chars, int n)
45372-{
45373- tmp[0] = 0;
45374- return strncat(tmp, (char *)chars, n);
45375-}
45376-
45377 static int i2o_report_query_status(struct seq_file *seq, int block_status,
45378 char *group)
45379 {
45380@@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
45381 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
45382 {
45383 struct i2o_controller *c = (struct i2o_controller *)seq->private;
45384- static u32 work32[5];
45385- static u8 *work8 = (u8 *) work32;
45386- static u16 *work16 = (u16 *) work32;
45387+ u32 work32[5];
45388+ u8 *work8 = (u8 *) work32;
45389+ u16 *work16 = (u16 *) work32;
45390 int token;
45391 u32 hwcap;
45392
45393@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
45394 } *result;
45395
45396 i2o_exec_execute_ddm_table ddm_table;
45397- char tmp[28 + 1];
45398
45399 result = kmalloc(sizeof(*result), GFP_KERNEL);
45400 if (!result)
45401@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
45402
45403 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
45404 seq_printf(seq, "%-#8x", ddm_table.module_id);
45405- seq_printf(seq, "%-29s",
45406- chtostr(tmp, ddm_table.module_name_version, 28));
45407+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
45408 seq_printf(seq, "%9d ", ddm_table.data_size);
45409 seq_printf(seq, "%8d", ddm_table.code_size);
45410
45411@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
45412
45413 i2o_driver_result_table *result;
45414 i2o_driver_store_table *dst;
45415- char tmp[28 + 1];
45416
45417 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
45418 if (result == NULL)
45419@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
45420
45421 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
45422 seq_printf(seq, "%-#8x", dst->module_id);
45423- seq_printf(seq, "%-29s",
45424- chtostr(tmp, dst->module_name_version, 28));
45425- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
45426+ seq_printf(seq, "%-.28s", dst->module_name_version);
45427+ seq_printf(seq, "%-.8s", dst->date);
45428 seq_printf(seq, "%8d ", dst->module_size);
45429 seq_printf(seq, "%8d ", dst->mpb_size);
45430 seq_printf(seq, "0x%04x", dst->module_flags);
45431@@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
45432 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
45433 {
45434 struct i2o_device *d = (struct i2o_device *)seq->private;
45435- static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
45436+ u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
45437 // == (allow) 512d bytes (max)
45438- static u16 *work16 = (u16 *) work32;
45439+ u16 *work16 = (u16 *) work32;
45440 int token;
45441- char tmp[16 + 1];
45442
45443 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
45444
45445@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
45446 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
45447 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
45448 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
45449- seq_printf(seq, "Vendor info : %s\n",
45450- chtostr(tmp, (u8 *) (work32 + 2), 16));
45451- seq_printf(seq, "Product info : %s\n",
45452- chtostr(tmp, (u8 *) (work32 + 6), 16));
45453- seq_printf(seq, "Description : %s\n",
45454- chtostr(tmp, (u8 *) (work32 + 10), 16));
45455- seq_printf(seq, "Product rev. : %s\n",
45456- chtostr(tmp, (u8 *) (work32 + 14), 8));
45457+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
45458+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
45459+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
45460+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
45461
45462 seq_printf(seq, "Serial number : ");
45463 print_serial_number(seq, (u8 *) (work32 + 16),
45464@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
45465 u8 pad[256]; // allow up to 256 byte (max) serial number
45466 } result;
45467
45468- char tmp[24 + 1];
45469-
45470 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
45471
45472 if (token < 0) {
45473@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
45474 }
45475
45476 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
45477- seq_printf(seq, "Module name : %s\n",
45478- chtostr(tmp, result.module_name, 24));
45479- seq_printf(seq, "Module revision : %s\n",
45480- chtostr(tmp, result.module_rev, 8));
45481+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
45482+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
45483
45484 seq_printf(seq, "Serial number : ");
45485 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
45486@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45487 u8 instance_number[4];
45488 } result;
45489
45490- char tmp[64 + 1];
45491-
45492 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
45493
45494 if (token < 0) {
45495@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45496 return 0;
45497 }
45498
45499- seq_printf(seq, "Device name : %s\n",
45500- chtostr(tmp, result.device_name, 64));
45501- seq_printf(seq, "Service name : %s\n",
45502- chtostr(tmp, result.service_name, 64));
45503- seq_printf(seq, "Physical name : %s\n",
45504- chtostr(tmp, result.physical_location, 64));
45505- seq_printf(seq, "Instance number : %s\n",
45506- chtostr(tmp, result.instance_number, 4));
45507+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
45508+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
45509+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
45510+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
45511
45512 return 0;
45513 }
45514@@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45515 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
45516 {
45517 struct i2o_device *d = (struct i2o_device *)seq->private;
45518- static u32 work32[12];
45519- static u16 *work16 = (u16 *) work32;
45520- static u8 *work8 = (u8 *) work32;
45521+ u32 work32[12];
45522+ u16 *work16 = (u16 *) work32;
45523+ u8 *work8 = (u8 *) work32;
45524 int token;
45525
45526 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
45527diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
45528index a8c08f3..155fe3d 100644
45529--- a/drivers/message/i2o/iop.c
45530+++ b/drivers/message/i2o/iop.c
45531@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
45532
45533 spin_lock_irqsave(&c->context_list_lock, flags);
45534
45535- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
45536- atomic_inc(&c->context_list_counter);
45537+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
45538+ atomic_inc_unchecked(&c->context_list_counter);
45539
45540- entry->context = atomic_read(&c->context_list_counter);
45541+ entry->context = atomic_read_unchecked(&c->context_list_counter);
45542
45543 list_add(&entry->list, &c->context_list);
45544
45545@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
45546
45547 #if BITS_PER_LONG == 64
45548 spin_lock_init(&c->context_list_lock);
45549- atomic_set(&c->context_list_counter, 0);
45550+ atomic_set_unchecked(&c->context_list_counter, 0);
45551 INIT_LIST_HEAD(&c->context_list);
45552 #endif
45553
45554diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
45555index d1a22aa..d0f7bf7 100644
45556--- a/drivers/mfd/ab8500-debugfs.c
45557+++ b/drivers/mfd/ab8500-debugfs.c
45558@@ -100,7 +100,7 @@ static int irq_last;
45559 static u32 *irq_count;
45560 static int num_irqs;
45561
45562-static struct device_attribute **dev_attr;
45563+static device_attribute_no_const **dev_attr;
45564 static char **event_name;
45565
45566 static u8 avg_sample = SAMPLE_16;
45567diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
45568index 81b7d88..95ae998 100644
45569--- a/drivers/mfd/janz-cmodio.c
45570+++ b/drivers/mfd/janz-cmodio.c
45571@@ -13,6 +13,7 @@
45572
45573 #include <linux/kernel.h>
45574 #include <linux/module.h>
45575+#include <linux/slab.h>
45576 #include <linux/init.h>
45577 #include <linux/pci.h>
45578 #include <linux/interrupt.h>
45579diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
45580index a83eed5..62a58a9 100644
45581--- a/drivers/mfd/max8925-i2c.c
45582+++ b/drivers/mfd/max8925-i2c.c
45583@@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
45584 const struct i2c_device_id *id)
45585 {
45586 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
45587- static struct max8925_chip *chip;
45588+ struct max8925_chip *chip;
45589 struct device_node *node = client->dev.of_node;
45590
45591 if (node && !pdata) {
45592diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
45593index d657331..0d9a80f 100644
45594--- a/drivers/mfd/tps65910.c
45595+++ b/drivers/mfd/tps65910.c
45596@@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
45597 struct tps65910_platform_data *pdata)
45598 {
45599 int ret = 0;
45600- static struct regmap_irq_chip *tps6591x_irqs_chip;
45601+ struct regmap_irq_chip *tps6591x_irqs_chip;
45602
45603 if (!irq) {
45604 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
45605diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
45606index 9aa6d1e..1631bfc 100644
45607--- a/drivers/mfd/twl4030-irq.c
45608+++ b/drivers/mfd/twl4030-irq.c
45609@@ -35,6 +35,7 @@
45610 #include <linux/of.h>
45611 #include <linux/irqdomain.h>
45612 #include <linux/i2c/twl.h>
45613+#include <asm/pgtable.h>
45614
45615 #include "twl-core.h"
45616
45617@@ -726,10 +727,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
45618 * Install an irq handler for each of the SIH modules;
45619 * clone dummy irq_chip since PIH can't *do* anything
45620 */
45621- twl4030_irq_chip = dummy_irq_chip;
45622- twl4030_irq_chip.name = "twl4030";
45623+ pax_open_kernel();
45624+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
45625+ *(const char **)&twl4030_irq_chip.name = "twl4030";
45626
45627- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45628+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45629+ pax_close_kernel();
45630
45631 for (i = irq_base; i < irq_end; i++) {
45632 irq_set_chip_and_handler(i, &twl4030_irq_chip,
45633diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
45634index 464419b..64bae8d 100644
45635--- a/drivers/misc/c2port/core.c
45636+++ b/drivers/misc/c2port/core.c
45637@@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
45638 goto error_idr_alloc;
45639 c2dev->id = ret;
45640
45641- bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45642+ pax_open_kernel();
45643+ *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45644+ pax_close_kernel();
45645
45646 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
45647 "c2port%d", c2dev->id);
45648diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
45649index 9c34e57..b981cda 100644
45650--- a/drivers/misc/eeprom/sunxi_sid.c
45651+++ b/drivers/misc/eeprom/sunxi_sid.c
45652@@ -127,7 +127,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
45653
45654 platform_set_drvdata(pdev, sid_data);
45655
45656- sid_bin_attr.size = sid_data->keysize;
45657+ pax_open_kernel();
45658+ *(size_t *)&sid_bin_attr.size = sid_data->keysize;
45659+ pax_close_kernel();
45660 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
45661 return -ENODEV;
45662
45663diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
45664index 36f5d52..32311c3 100644
45665--- a/drivers/misc/kgdbts.c
45666+++ b/drivers/misc/kgdbts.c
45667@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
45668 char before[BREAK_INSTR_SIZE];
45669 char after[BREAK_INSTR_SIZE];
45670
45671- probe_kernel_read(before, (char *)kgdbts_break_test,
45672+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
45673 BREAK_INSTR_SIZE);
45674 init_simple_test();
45675 ts.tst = plant_and_detach_test;
45676@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
45677 /* Activate test with initial breakpoint */
45678 if (!is_early)
45679 kgdb_breakpoint();
45680- probe_kernel_read(after, (char *)kgdbts_break_test,
45681+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
45682 BREAK_INSTR_SIZE);
45683 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
45684 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
45685diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
45686index 036effe..b3a6336 100644
45687--- a/drivers/misc/lis3lv02d/lis3lv02d.c
45688+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
45689@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
45690 * the lid is closed. This leads to interrupts as soon as a little move
45691 * is done.
45692 */
45693- atomic_inc(&lis3->count);
45694+ atomic_inc_unchecked(&lis3->count);
45695
45696 wake_up_interruptible(&lis3->misc_wait);
45697 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
45698@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
45699 if (lis3->pm_dev)
45700 pm_runtime_get_sync(lis3->pm_dev);
45701
45702- atomic_set(&lis3->count, 0);
45703+ atomic_set_unchecked(&lis3->count, 0);
45704 return 0;
45705 }
45706
45707@@ -616,7 +616,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
45708 add_wait_queue(&lis3->misc_wait, &wait);
45709 while (true) {
45710 set_current_state(TASK_INTERRUPTIBLE);
45711- data = atomic_xchg(&lis3->count, 0);
45712+ data = atomic_xchg_unchecked(&lis3->count, 0);
45713 if (data)
45714 break;
45715
45716@@ -657,7 +657,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
45717 struct lis3lv02d, miscdev);
45718
45719 poll_wait(file, &lis3->misc_wait, wait);
45720- if (atomic_read(&lis3->count))
45721+ if (atomic_read_unchecked(&lis3->count))
45722 return POLLIN | POLLRDNORM;
45723 return 0;
45724 }
45725diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
45726index c439c82..1f20f57 100644
45727--- a/drivers/misc/lis3lv02d/lis3lv02d.h
45728+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
45729@@ -297,7 +297,7 @@ struct lis3lv02d {
45730 struct input_polled_dev *idev; /* input device */
45731 struct platform_device *pdev; /* platform device */
45732 struct regulator_bulk_data regulators[2];
45733- atomic_t count; /* interrupt count after last read */
45734+ atomic_unchecked_t count; /* interrupt count after last read */
45735 union axis_conversion ac; /* hw -> logical axis */
45736 int mapped_btns[3];
45737
45738diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
45739index 2f30bad..c4c13d0 100644
45740--- a/drivers/misc/sgi-gru/gruhandles.c
45741+++ b/drivers/misc/sgi-gru/gruhandles.c
45742@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
45743 unsigned long nsec;
45744
45745 nsec = CLKS2NSEC(clks);
45746- atomic_long_inc(&mcs_op_statistics[op].count);
45747- atomic_long_add(nsec, &mcs_op_statistics[op].total);
45748+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
45749+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
45750 if (mcs_op_statistics[op].max < nsec)
45751 mcs_op_statistics[op].max = nsec;
45752 }
45753diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
45754index 4f76359..cdfcb2e 100644
45755--- a/drivers/misc/sgi-gru/gruprocfs.c
45756+++ b/drivers/misc/sgi-gru/gruprocfs.c
45757@@ -32,9 +32,9 @@
45758
45759 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
45760
45761-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
45762+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
45763 {
45764- unsigned long val = atomic_long_read(v);
45765+ unsigned long val = atomic_long_read_unchecked(v);
45766
45767 seq_printf(s, "%16lu %s\n", val, id);
45768 }
45769@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
45770
45771 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
45772 for (op = 0; op < mcsop_last; op++) {
45773- count = atomic_long_read(&mcs_op_statistics[op].count);
45774- total = atomic_long_read(&mcs_op_statistics[op].total);
45775+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
45776+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
45777 max = mcs_op_statistics[op].max;
45778 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
45779 count ? total / count : 0, max);
45780diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
45781index 5c3ce24..4915ccb 100644
45782--- a/drivers/misc/sgi-gru/grutables.h
45783+++ b/drivers/misc/sgi-gru/grutables.h
45784@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
45785 * GRU statistics.
45786 */
45787 struct gru_stats_s {
45788- atomic_long_t vdata_alloc;
45789- atomic_long_t vdata_free;
45790- atomic_long_t gts_alloc;
45791- atomic_long_t gts_free;
45792- atomic_long_t gms_alloc;
45793- atomic_long_t gms_free;
45794- atomic_long_t gts_double_allocate;
45795- atomic_long_t assign_context;
45796- atomic_long_t assign_context_failed;
45797- atomic_long_t free_context;
45798- atomic_long_t load_user_context;
45799- atomic_long_t load_kernel_context;
45800- atomic_long_t lock_kernel_context;
45801- atomic_long_t unlock_kernel_context;
45802- atomic_long_t steal_user_context;
45803- atomic_long_t steal_kernel_context;
45804- atomic_long_t steal_context_failed;
45805- atomic_long_t nopfn;
45806- atomic_long_t asid_new;
45807- atomic_long_t asid_next;
45808- atomic_long_t asid_wrap;
45809- atomic_long_t asid_reuse;
45810- atomic_long_t intr;
45811- atomic_long_t intr_cbr;
45812- atomic_long_t intr_tfh;
45813- atomic_long_t intr_spurious;
45814- atomic_long_t intr_mm_lock_failed;
45815- atomic_long_t call_os;
45816- atomic_long_t call_os_wait_queue;
45817- atomic_long_t user_flush_tlb;
45818- atomic_long_t user_unload_context;
45819- atomic_long_t user_exception;
45820- atomic_long_t set_context_option;
45821- atomic_long_t check_context_retarget_intr;
45822- atomic_long_t check_context_unload;
45823- atomic_long_t tlb_dropin;
45824- atomic_long_t tlb_preload_page;
45825- atomic_long_t tlb_dropin_fail_no_asid;
45826- atomic_long_t tlb_dropin_fail_upm;
45827- atomic_long_t tlb_dropin_fail_invalid;
45828- atomic_long_t tlb_dropin_fail_range_active;
45829- atomic_long_t tlb_dropin_fail_idle;
45830- atomic_long_t tlb_dropin_fail_fmm;
45831- atomic_long_t tlb_dropin_fail_no_exception;
45832- atomic_long_t tfh_stale_on_fault;
45833- atomic_long_t mmu_invalidate_range;
45834- atomic_long_t mmu_invalidate_page;
45835- atomic_long_t flush_tlb;
45836- atomic_long_t flush_tlb_gru;
45837- atomic_long_t flush_tlb_gru_tgh;
45838- atomic_long_t flush_tlb_gru_zero_asid;
45839+ atomic_long_unchecked_t vdata_alloc;
45840+ atomic_long_unchecked_t vdata_free;
45841+ atomic_long_unchecked_t gts_alloc;
45842+ atomic_long_unchecked_t gts_free;
45843+ atomic_long_unchecked_t gms_alloc;
45844+ atomic_long_unchecked_t gms_free;
45845+ atomic_long_unchecked_t gts_double_allocate;
45846+ atomic_long_unchecked_t assign_context;
45847+ atomic_long_unchecked_t assign_context_failed;
45848+ atomic_long_unchecked_t free_context;
45849+ atomic_long_unchecked_t load_user_context;
45850+ atomic_long_unchecked_t load_kernel_context;
45851+ atomic_long_unchecked_t lock_kernel_context;
45852+ atomic_long_unchecked_t unlock_kernel_context;
45853+ atomic_long_unchecked_t steal_user_context;
45854+ atomic_long_unchecked_t steal_kernel_context;
45855+ atomic_long_unchecked_t steal_context_failed;
45856+ atomic_long_unchecked_t nopfn;
45857+ atomic_long_unchecked_t asid_new;
45858+ atomic_long_unchecked_t asid_next;
45859+ atomic_long_unchecked_t asid_wrap;
45860+ atomic_long_unchecked_t asid_reuse;
45861+ atomic_long_unchecked_t intr;
45862+ atomic_long_unchecked_t intr_cbr;
45863+ atomic_long_unchecked_t intr_tfh;
45864+ atomic_long_unchecked_t intr_spurious;
45865+ atomic_long_unchecked_t intr_mm_lock_failed;
45866+ atomic_long_unchecked_t call_os;
45867+ atomic_long_unchecked_t call_os_wait_queue;
45868+ atomic_long_unchecked_t user_flush_tlb;
45869+ atomic_long_unchecked_t user_unload_context;
45870+ atomic_long_unchecked_t user_exception;
45871+ atomic_long_unchecked_t set_context_option;
45872+ atomic_long_unchecked_t check_context_retarget_intr;
45873+ atomic_long_unchecked_t check_context_unload;
45874+ atomic_long_unchecked_t tlb_dropin;
45875+ atomic_long_unchecked_t tlb_preload_page;
45876+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
45877+ atomic_long_unchecked_t tlb_dropin_fail_upm;
45878+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
45879+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
45880+ atomic_long_unchecked_t tlb_dropin_fail_idle;
45881+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
45882+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
45883+ atomic_long_unchecked_t tfh_stale_on_fault;
45884+ atomic_long_unchecked_t mmu_invalidate_range;
45885+ atomic_long_unchecked_t mmu_invalidate_page;
45886+ atomic_long_unchecked_t flush_tlb;
45887+ atomic_long_unchecked_t flush_tlb_gru;
45888+ atomic_long_unchecked_t flush_tlb_gru_tgh;
45889+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
45890
45891- atomic_long_t copy_gpa;
45892- atomic_long_t read_gpa;
45893+ atomic_long_unchecked_t copy_gpa;
45894+ atomic_long_unchecked_t read_gpa;
45895
45896- atomic_long_t mesq_receive;
45897- atomic_long_t mesq_receive_none;
45898- atomic_long_t mesq_send;
45899- atomic_long_t mesq_send_failed;
45900- atomic_long_t mesq_noop;
45901- atomic_long_t mesq_send_unexpected_error;
45902- atomic_long_t mesq_send_lb_overflow;
45903- atomic_long_t mesq_send_qlimit_reached;
45904- atomic_long_t mesq_send_amo_nacked;
45905- atomic_long_t mesq_send_put_nacked;
45906- atomic_long_t mesq_page_overflow;
45907- atomic_long_t mesq_qf_locked;
45908- atomic_long_t mesq_qf_noop_not_full;
45909- atomic_long_t mesq_qf_switch_head_failed;
45910- atomic_long_t mesq_qf_unexpected_error;
45911- atomic_long_t mesq_noop_unexpected_error;
45912- atomic_long_t mesq_noop_lb_overflow;
45913- atomic_long_t mesq_noop_qlimit_reached;
45914- atomic_long_t mesq_noop_amo_nacked;
45915- atomic_long_t mesq_noop_put_nacked;
45916- atomic_long_t mesq_noop_page_overflow;
45917+ atomic_long_unchecked_t mesq_receive;
45918+ atomic_long_unchecked_t mesq_receive_none;
45919+ atomic_long_unchecked_t mesq_send;
45920+ atomic_long_unchecked_t mesq_send_failed;
45921+ atomic_long_unchecked_t mesq_noop;
45922+ atomic_long_unchecked_t mesq_send_unexpected_error;
45923+ atomic_long_unchecked_t mesq_send_lb_overflow;
45924+ atomic_long_unchecked_t mesq_send_qlimit_reached;
45925+ atomic_long_unchecked_t mesq_send_amo_nacked;
45926+ atomic_long_unchecked_t mesq_send_put_nacked;
45927+ atomic_long_unchecked_t mesq_page_overflow;
45928+ atomic_long_unchecked_t mesq_qf_locked;
45929+ atomic_long_unchecked_t mesq_qf_noop_not_full;
45930+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
45931+ atomic_long_unchecked_t mesq_qf_unexpected_error;
45932+ atomic_long_unchecked_t mesq_noop_unexpected_error;
45933+ atomic_long_unchecked_t mesq_noop_lb_overflow;
45934+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
45935+ atomic_long_unchecked_t mesq_noop_amo_nacked;
45936+ atomic_long_unchecked_t mesq_noop_put_nacked;
45937+ atomic_long_unchecked_t mesq_noop_page_overflow;
45938
45939 };
45940
45941@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
45942 tghop_invalidate, mcsop_last};
45943
45944 struct mcs_op_statistic {
45945- atomic_long_t count;
45946- atomic_long_t total;
45947+ atomic_long_unchecked_t count;
45948+ atomic_long_unchecked_t total;
45949 unsigned long max;
45950 };
45951
45952@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
45953
45954 #define STAT(id) do { \
45955 if (gru_options & OPT_STATS) \
45956- atomic_long_inc(&gru_stats.id); \
45957+ atomic_long_inc_unchecked(&gru_stats.id); \
45958 } while (0)
45959
45960 #ifdef CONFIG_SGI_GRU_DEBUG
45961diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
45962index c862cd4..0d176fe 100644
45963--- a/drivers/misc/sgi-xp/xp.h
45964+++ b/drivers/misc/sgi-xp/xp.h
45965@@ -288,7 +288,7 @@ struct xpc_interface {
45966 xpc_notify_func, void *);
45967 void (*received) (short, int, void *);
45968 enum xp_retval (*partid_to_nasids) (short, void *);
45969-};
45970+} __no_const;
45971
45972 extern struct xpc_interface xpc_interface;
45973
45974diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
45975index 01be66d..e3a0c7e 100644
45976--- a/drivers/misc/sgi-xp/xp_main.c
45977+++ b/drivers/misc/sgi-xp/xp_main.c
45978@@ -78,13 +78,13 @@ xpc_notloaded(void)
45979 }
45980
45981 struct xpc_interface xpc_interface = {
45982- (void (*)(int))xpc_notloaded,
45983- (void (*)(int))xpc_notloaded,
45984- (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45985- (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45986+ .connect = (void (*)(int))xpc_notloaded,
45987+ .disconnect = (void (*)(int))xpc_notloaded,
45988+ .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45989+ .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45990 void *))xpc_notloaded,
45991- (void (*)(short, int, void *))xpc_notloaded,
45992- (enum xp_retval(*)(short, void *))xpc_notloaded
45993+ .received = (void (*)(short, int, void *))xpc_notloaded,
45994+ .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
45995 };
45996 EXPORT_SYMBOL_GPL(xpc_interface);
45997
45998diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
45999index b94d5f7..7f494c5 100644
46000--- a/drivers/misc/sgi-xp/xpc.h
46001+++ b/drivers/misc/sgi-xp/xpc.h
46002@@ -835,6 +835,7 @@ struct xpc_arch_operations {
46003 void (*received_payload) (struct xpc_channel *, void *);
46004 void (*notify_senders_of_disconnect) (struct xpc_channel *);
46005 };
46006+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
46007
46008 /* struct xpc_partition act_state values (for XPC HB) */
46009
46010@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
46011 /* found in xpc_main.c */
46012 extern struct device *xpc_part;
46013 extern struct device *xpc_chan;
46014-extern struct xpc_arch_operations xpc_arch_ops;
46015+extern xpc_arch_operations_no_const xpc_arch_ops;
46016 extern int xpc_disengage_timelimit;
46017 extern int xpc_disengage_timedout;
46018 extern int xpc_activate_IRQ_rcvd;
46019diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
46020index 82dc574..8539ab2 100644
46021--- a/drivers/misc/sgi-xp/xpc_main.c
46022+++ b/drivers/misc/sgi-xp/xpc_main.c
46023@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
46024 .notifier_call = xpc_system_die,
46025 };
46026
46027-struct xpc_arch_operations xpc_arch_ops;
46028+xpc_arch_operations_no_const xpc_arch_ops;
46029
46030 /*
46031 * Timer function to enforce the timelimit on the partition disengage.
46032@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
46033
46034 if (((die_args->trapnr == X86_TRAP_MF) ||
46035 (die_args->trapnr == X86_TRAP_XF)) &&
46036- !user_mode_vm(die_args->regs))
46037+ !user_mode(die_args->regs))
46038 xpc_die_deactivate();
46039
46040 break;
46041diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
46042index 7b5424f..ed1d6ac 100644
46043--- a/drivers/mmc/card/block.c
46044+++ b/drivers/mmc/card/block.c
46045@@ -575,7 +575,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
46046 if (idata->ic.postsleep_min_us)
46047 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
46048
46049- if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
46050+ if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
46051 err = -EFAULT;
46052 goto cmd_rel_host;
46053 }
46054diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
46055index e5b5eeb..7bf2212 100644
46056--- a/drivers/mmc/core/mmc_ops.c
46057+++ b/drivers/mmc/core/mmc_ops.c
46058@@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
46059 void *data_buf;
46060 int is_on_stack;
46061
46062- is_on_stack = object_is_on_stack(buf);
46063+ is_on_stack = object_starts_on_stack(buf);
46064 if (is_on_stack) {
46065 /*
46066 * dma onto stack is unsafe/nonportable, but callers to this
46067diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
46068index 6bf24ab..13d0293b 100644
46069--- a/drivers/mmc/host/dw_mmc.h
46070+++ b/drivers/mmc/host/dw_mmc.h
46071@@ -258,5 +258,5 @@ struct dw_mci_drv_data {
46072 int (*parse_dt)(struct dw_mci *host);
46073 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
46074 struct dw_mci_tuning_data *tuning_data);
46075-};
46076+} __do_const;
46077 #endif /* _DW_MMC_H_ */
46078diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
46079index b931226..df6a085 100644
46080--- a/drivers/mmc/host/mmci.c
46081+++ b/drivers/mmc/host/mmci.c
46082@@ -1504,7 +1504,9 @@ static int mmci_probe(struct amba_device *dev,
46083 }
46084
46085 if (variant->busy_detect) {
46086- mmci_ops.card_busy = mmci_card_busy;
46087+ pax_open_kernel();
46088+ *(void **)&mmci_ops.card_busy = mmci_card_busy;
46089+ pax_close_kernel();
46090 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
46091 }
46092
46093diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
46094index b841bb7..d82712f5 100644
46095--- a/drivers/mmc/host/sdhci-esdhc-imx.c
46096+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
46097@@ -1031,9 +1031,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
46098 host->mmc->caps |= MMC_CAP_1_8V_DDR;
46099 }
46100
46101- if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
46102- sdhci_esdhc_ops.platform_execute_tuning =
46103+ if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
46104+ pax_open_kernel();
46105+ *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
46106 esdhc_executing_tuning;
46107+ pax_close_kernel();
46108+ }
46109
46110 if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING)
46111 writel(readl(host->ioaddr + ESDHC_TUNING_CTRL) |
46112diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
46113index 6debda9..2ba7427 100644
46114--- a/drivers/mmc/host/sdhci-s3c.c
46115+++ b/drivers/mmc/host/sdhci-s3c.c
46116@@ -668,9 +668,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
46117 * we can use overriding functions instead of default.
46118 */
46119 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
46120- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
46121- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
46122- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
46123+ pax_open_kernel();
46124+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
46125+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
46126+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
46127+ pax_close_kernel();
46128 }
46129
46130 /* It supports additional host capabilities if needed */
46131diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
46132index 096993f..f02c23b 100644
46133--- a/drivers/mtd/chips/cfi_cmdset_0020.c
46134+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
46135@@ -669,7 +669,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
46136 size_t totlen = 0, thislen;
46137 int ret = 0;
46138 size_t buflen = 0;
46139- static char *buffer;
46140+ char *buffer;
46141
46142 if (!ECCBUF_SIZE) {
46143 /* We should fall back to a general writev implementation.
46144diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
46145index c07cd57..61c4fbd 100644
46146--- a/drivers/mtd/nand/denali.c
46147+++ b/drivers/mtd/nand/denali.c
46148@@ -24,6 +24,7 @@
46149 #include <linux/slab.h>
46150 #include <linux/mtd/mtd.h>
46151 #include <linux/module.h>
46152+#include <linux/slab.h>
46153
46154 #include "denali.h"
46155
46156diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
46157index ca6369f..0ce9fed 100644
46158--- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
46159+++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
46160@@ -369,7 +369,7 @@ void prepare_data_dma(struct gpmi_nand_data *this, enum dma_data_direction dr)
46161
46162 /* first try to map the upper buffer directly */
46163 if (virt_addr_valid(this->upper_buf) &&
46164- !object_is_on_stack(this->upper_buf)) {
46165+ !object_starts_on_stack(this->upper_buf)) {
46166 sg_init_one(sgl, this->upper_buf, this->upper_len);
46167 ret = dma_map_sg(this->dev, sgl, 1, dr);
46168 if (ret == 0)
46169diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
46170index 51b9d6a..52af9a7 100644
46171--- a/drivers/mtd/nftlmount.c
46172+++ b/drivers/mtd/nftlmount.c
46173@@ -24,6 +24,7 @@
46174 #include <asm/errno.h>
46175 #include <linux/delay.h>
46176 #include <linux/slab.h>
46177+#include <linux/sched.h>
46178 #include <linux/mtd/mtd.h>
46179 #include <linux/mtd/nand.h>
46180 #include <linux/mtd/nftl.h>
46181diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
46182index 4b8e895..6b3c498 100644
46183--- a/drivers/mtd/sm_ftl.c
46184+++ b/drivers/mtd/sm_ftl.c
46185@@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
46186 #define SM_CIS_VENDOR_OFFSET 0x59
46187 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
46188 {
46189- struct attribute_group *attr_group;
46190+ attribute_group_no_const *attr_group;
46191 struct attribute **attributes;
46192 struct sm_sysfs_attribute *vendor_attribute;
46193
46194diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
46195index e5628fc..ffe54d1 100644
46196--- a/drivers/net/bonding/bond_main.c
46197+++ b/drivers/net/bonding/bond_main.c
46198@@ -4551,6 +4551,7 @@ static void __exit bonding_exit(void)
46199
46200 bond_netlink_fini();
46201 unregister_pernet_subsys(&bond_net_ops);
46202+ rtnl_link_unregister(&bond_link_ops);
46203
46204 #ifdef CONFIG_NET_POLL_CONTROLLER
46205 /*
46206diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
46207index 70651f8..7eb1bdf 100644
46208--- a/drivers/net/bonding/bond_netlink.c
46209+++ b/drivers/net/bonding/bond_netlink.c
46210@@ -542,7 +542,7 @@ nla_put_failure:
46211 return -EMSGSIZE;
46212 }
46213
46214-struct rtnl_link_ops bond_link_ops __read_mostly = {
46215+struct rtnl_link_ops bond_link_ops = {
46216 .kind = "bond",
46217 .priv_size = sizeof(struct bonding),
46218 .setup = bond_setup,
46219diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
46220index 9e7d95d..d447b88 100644
46221--- a/drivers/net/can/Kconfig
46222+++ b/drivers/net/can/Kconfig
46223@@ -104,7 +104,7 @@ config CAN_JANZ_ICAN3
46224
46225 config CAN_FLEXCAN
46226 tristate "Support for Freescale FLEXCAN based chips"
46227- depends on ARM || PPC
46228+ depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
46229 ---help---
46230 Say Y here if you want to support for Freescale FlexCAN.
46231
46232diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
46233index 455d4c3..3353ee7 100644
46234--- a/drivers/net/ethernet/8390/ax88796.c
46235+++ b/drivers/net/ethernet/8390/ax88796.c
46236@@ -889,9 +889,11 @@ static int ax_probe(struct platform_device *pdev)
46237 if (ax->plat->reg_offsets)
46238 ei_local->reg_offset = ax->plat->reg_offsets;
46239 else {
46240+ resource_size_t _mem_size = mem_size;
46241+ do_div(_mem_size, 0x18);
46242 ei_local->reg_offset = ax->reg_offsets;
46243 for (ret = 0; ret < 0x18; ret++)
46244- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
46245+ ax->reg_offsets[ret] = _mem_size * ret;
46246 }
46247
46248 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
46249diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
46250index a89a40f..5a8a2ac 100644
46251--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
46252+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
46253@@ -1062,7 +1062,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
46254 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
46255 {
46256 /* RX_MODE controlling object */
46257- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
46258+ bnx2x_init_rx_mode_obj(bp);
46259
46260 /* multicast configuration controlling object */
46261 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
46262diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
46263index 0fb6ff2..78fd55c 100644
46264--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
46265+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
46266@@ -2329,15 +2329,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
46267 return rc;
46268 }
46269
46270-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
46271- struct bnx2x_rx_mode_obj *o)
46272+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
46273 {
46274 if (CHIP_IS_E1x(bp)) {
46275- o->wait_comp = bnx2x_empty_rx_mode_wait;
46276- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
46277+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
46278+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
46279 } else {
46280- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
46281- o->config_rx_mode = bnx2x_set_rx_mode_e2;
46282+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
46283+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
46284 }
46285 }
46286
46287diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
46288index 00d7f21..2cddec4 100644
46289--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
46290+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
46291@@ -1321,8 +1321,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
46292
46293 /********************* RX MODE ****************/
46294
46295-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
46296- struct bnx2x_rx_mode_obj *o);
46297+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
46298
46299 /**
46300 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
46301diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
46302index 04321e5..b51cdc4 100644
46303--- a/drivers/net/ethernet/broadcom/tg3.h
46304+++ b/drivers/net/ethernet/broadcom/tg3.h
46305@@ -150,6 +150,7 @@
46306 #define CHIPREV_ID_5750_A0 0x4000
46307 #define CHIPREV_ID_5750_A1 0x4001
46308 #define CHIPREV_ID_5750_A3 0x4003
46309+#define CHIPREV_ID_5750_C1 0x4201
46310 #define CHIPREV_ID_5750_C2 0x4202
46311 #define CHIPREV_ID_5752_A0_HW 0x5000
46312 #define CHIPREV_ID_5752_A0 0x6000
46313diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
46314index 13f9636..228040f 100644
46315--- a/drivers/net/ethernet/brocade/bna/bna_enet.c
46316+++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
46317@@ -1690,10 +1690,10 @@ bna_cb_ioceth_reset(void *arg)
46318 }
46319
46320 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
46321- bna_cb_ioceth_enable,
46322- bna_cb_ioceth_disable,
46323- bna_cb_ioceth_hbfail,
46324- bna_cb_ioceth_reset
46325+ .enable_cbfn = bna_cb_ioceth_enable,
46326+ .disable_cbfn = bna_cb_ioceth_disable,
46327+ .hbfail_cbfn = bna_cb_ioceth_hbfail,
46328+ .reset_cbfn = bna_cb_ioceth_reset
46329 };
46330
46331 static void bna_attr_init(struct bna_ioceth *ioceth)
46332diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
46333index 8cffcdf..aadf043 100644
46334--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
46335+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
46336@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
46337 */
46338 struct l2t_skb_cb {
46339 arp_failure_handler_func arp_failure_handler;
46340-};
46341+} __no_const;
46342
46343 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
46344
46345diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
46346index 34e2488..07e2079 100644
46347--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
46348+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
46349@@ -2120,7 +2120,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
46350
46351 int i;
46352 struct adapter *ap = netdev2adap(dev);
46353- static const unsigned int *reg_ranges;
46354+ const unsigned int *reg_ranges;
46355 int arr_size = 0, buf_size = 0;
46356
46357 if (is_t4(ap->params.chip)) {
46358diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
46359index c05b66d..ed69872 100644
46360--- a/drivers/net/ethernet/dec/tulip/de4x5.c
46361+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
46362@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
46363 for (i=0; i<ETH_ALEN; i++) {
46364 tmp.addr[i] = dev->dev_addr[i];
46365 }
46366- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
46367+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
46368 break;
46369
46370 case DE4X5_SET_HWADDR: /* Set the hardware address */
46371@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
46372 spin_lock_irqsave(&lp->lock, flags);
46373 memcpy(&statbuf, &lp->pktStats, ioc->len);
46374 spin_unlock_irqrestore(&lp->lock, flags);
46375- if (copy_to_user(ioc->data, &statbuf, ioc->len))
46376+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
46377 return -EFAULT;
46378 break;
46379 }
46380diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
46381index 36c8061..ca5e1e0 100644
46382--- a/drivers/net/ethernet/emulex/benet/be_main.c
46383+++ b/drivers/net/ethernet/emulex/benet/be_main.c
46384@@ -534,7 +534,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
46385
46386 if (wrapped)
46387 newacc += 65536;
46388- ACCESS_ONCE(*acc) = newacc;
46389+ ACCESS_ONCE_RW(*acc) = newacc;
46390 }
46391
46392 static void populate_erx_stats(struct be_adapter *adapter,
46393diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
46394index c11ecbc..13bb299 100644
46395--- a/drivers/net/ethernet/faraday/ftgmac100.c
46396+++ b/drivers/net/ethernet/faraday/ftgmac100.c
46397@@ -30,6 +30,8 @@
46398 #include <linux/netdevice.h>
46399 #include <linux/phy.h>
46400 #include <linux/platform_device.h>
46401+#include <linux/interrupt.h>
46402+#include <linux/irqreturn.h>
46403 #include <net/ip.h>
46404
46405 #include "ftgmac100.h"
46406diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
46407index 8be5b40..081bc1b 100644
46408--- a/drivers/net/ethernet/faraday/ftmac100.c
46409+++ b/drivers/net/ethernet/faraday/ftmac100.c
46410@@ -31,6 +31,8 @@
46411 #include <linux/module.h>
46412 #include <linux/netdevice.h>
46413 #include <linux/platform_device.h>
46414+#include <linux/interrupt.h>
46415+#include <linux/irqreturn.h>
46416
46417 #include "ftmac100.h"
46418
46419diff --git a/drivers/net/ethernet/intel/i40e/i40e_ptp.c b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
46420index e33ec6c..f54cfe7 100644
46421--- a/drivers/net/ethernet/intel/i40e/i40e_ptp.c
46422+++ b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
46423@@ -436,7 +436,7 @@ void i40e_ptp_set_increment(struct i40e_pf *pf)
46424 wr32(hw, I40E_PRTTSYN_INC_H, incval >> 32);
46425
46426 /* Update the base adjustement value. */
46427- ACCESS_ONCE(pf->ptp_base_adj) = incval;
46428+ ACCESS_ONCE_RW(pf->ptp_base_adj) = incval;
46429 smp_mb(); /* Force the above update. */
46430 }
46431
46432diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
46433index 5184e2a..acb28c3 100644
46434--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
46435+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
46436@@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
46437 }
46438
46439 /* update the base incval used to calculate frequency adjustment */
46440- ACCESS_ONCE(adapter->base_incval) = incval;
46441+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
46442 smp_mb();
46443
46444 /* need lock to prevent incorrect read while modifying cyclecounter */
46445diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
46446index 089b713..28d87ae 100644
46447--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
46448+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
46449@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
46450 struct __vxge_hw_fifo *fifo;
46451 struct vxge_hw_fifo_config *config;
46452 u32 txdl_size, txdl_per_memblock;
46453- struct vxge_hw_mempool_cbs fifo_mp_callback;
46454+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
46455+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
46456+ };
46457+
46458 struct __vxge_hw_virtualpath *vpath;
46459
46460 if ((vp == NULL) || (attr == NULL)) {
46461@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
46462 goto exit;
46463 }
46464
46465- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
46466-
46467 fifo->mempool =
46468 __vxge_hw_mempool_create(vpath->hldev,
46469 fifo->config->memblock_size,
46470diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
46471index 90a2dda..47e620e 100644
46472--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
46473+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
46474@@ -2088,7 +2088,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
46475 adapter->max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
46476 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
46477 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
46478- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
46479+ pax_open_kernel();
46480+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
46481+ pax_close_kernel();
46482 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46483 adapter->max_sds_rings = QLCNIC_MAX_SDS_RINGS;
46484 adapter->max_tx_rings = QLCNIC_MAX_TX_RINGS;
46485diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46486index be7d7a6..a8983f8 100644
46487--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46488+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46489@@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
46490 case QLCNIC_NON_PRIV_FUNC:
46491 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
46492 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46493- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
46494+ pax_open_kernel();
46495+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
46496+ pax_close_kernel();
46497 break;
46498 case QLCNIC_PRIV_FUNC:
46499 ahw->op_mode = QLCNIC_PRIV_FUNC;
46500 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
46501- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
46502+ pax_open_kernel();
46503+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
46504+ pax_close_kernel();
46505 break;
46506 case QLCNIC_MGMT_FUNC:
46507 ahw->op_mode = QLCNIC_MGMT_FUNC;
46508 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46509- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
46510+ pax_open_kernel();
46511+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
46512+ pax_close_kernel();
46513 break;
46514 default:
46515 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
46516diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46517index 7763962..c3499a7 100644
46518--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46519+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46520@@ -1108,7 +1108,7 @@ int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
46521 struct qlcnic_dump_entry *entry;
46522 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
46523 struct qlcnic_dump_template_hdr *tmpl_hdr = fw_dump->tmpl_hdr;
46524- static const struct qlcnic_dump_operations *fw_dump_ops;
46525+ const struct qlcnic_dump_operations *fw_dump_ops;
46526 struct device *dev = &adapter->pdev->dev;
46527 struct qlcnic_hardware_context *ahw;
46528 void *temp_buffer;
46529diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
46530index 3ff7bc3..366091b 100644
46531--- a/drivers/net/ethernet/realtek/r8169.c
46532+++ b/drivers/net/ethernet/realtek/r8169.c
46533@@ -758,22 +758,22 @@ struct rtl8169_private {
46534 struct mdio_ops {
46535 void (*write)(struct rtl8169_private *, int, int);
46536 int (*read)(struct rtl8169_private *, int);
46537- } mdio_ops;
46538+ } __no_const mdio_ops;
46539
46540 struct pll_power_ops {
46541 void (*down)(struct rtl8169_private *);
46542 void (*up)(struct rtl8169_private *);
46543- } pll_power_ops;
46544+ } __no_const pll_power_ops;
46545
46546 struct jumbo_ops {
46547 void (*enable)(struct rtl8169_private *);
46548 void (*disable)(struct rtl8169_private *);
46549- } jumbo_ops;
46550+ } __no_const jumbo_ops;
46551
46552 struct csi_ops {
46553 void (*write)(struct rtl8169_private *, int, int);
46554 u32 (*read)(struct rtl8169_private *, int);
46555- } csi_ops;
46556+ } __no_const csi_ops;
46557
46558 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
46559 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
46560diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
46561index d7a3682..9ce272a 100644
46562--- a/drivers/net/ethernet/sfc/ptp.c
46563+++ b/drivers/net/ethernet/sfc/ptp.c
46564@@ -825,7 +825,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
46565 ptp->start.dma_addr);
46566
46567 /* Clear flag that signals MC ready */
46568- ACCESS_ONCE(*start) = 0;
46569+ ACCESS_ONCE_RW(*start) = 0;
46570 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
46571 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
46572 EFX_BUG_ON_PARANOID(rc);
46573diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46574index 50617c5..b13724c 100644
46575--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46576+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46577@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
46578
46579 writel(value, ioaddr + MMC_CNTRL);
46580
46581- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46582- MMC_CNTRL, value);
46583+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46584+// MMC_CNTRL, value);
46585 }
46586
46587 /* To mask all all interrupts.*/
46588diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
46589index 7b594ce..1f6c5708 100644
46590--- a/drivers/net/hyperv/hyperv_net.h
46591+++ b/drivers/net/hyperv/hyperv_net.h
46592@@ -100,7 +100,7 @@ struct rndis_device {
46593
46594 enum rndis_device_state state;
46595 bool link_state;
46596- atomic_t new_req_id;
46597+ atomic_unchecked_t new_req_id;
46598
46599 spinlock_t request_lock;
46600 struct list_head req_list;
46601diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
46602index b54fd25..9bd2bae 100644
46603--- a/drivers/net/hyperv/rndis_filter.c
46604+++ b/drivers/net/hyperv/rndis_filter.c
46605@@ -103,7 +103,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
46606 * template
46607 */
46608 set = &rndis_msg->msg.set_req;
46609- set->req_id = atomic_inc_return(&dev->new_req_id);
46610+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46611
46612 /* Add to the request list */
46613 spin_lock_irqsave(&dev->request_lock, flags);
46614@@ -770,7 +770,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
46615
46616 /* Setup the rndis set */
46617 halt = &request->request_msg.msg.halt_req;
46618- halt->req_id = atomic_inc_return(&dev->new_req_id);
46619+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46620
46621 /* Ignore return since this msg is optional. */
46622 rndis_filter_send_request(dev, request);
46623diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
46624index bf0d55e..82bcfbd1 100644
46625--- a/drivers/net/ieee802154/fakehard.c
46626+++ b/drivers/net/ieee802154/fakehard.c
46627@@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
46628 phy->transmit_power = 0xbf;
46629
46630 dev->netdev_ops = &fake_ops;
46631- dev->ml_priv = &fake_mlme;
46632+ dev->ml_priv = (void *)&fake_mlme;
46633
46634 priv = netdev_priv(dev);
46635 priv->phy = phy;
46636diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
46637index 1831fb7..9c24bca 100644
46638--- a/drivers/net/macvlan.c
46639+++ b/drivers/net/macvlan.c
46640@@ -984,13 +984,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
46641 int macvlan_link_register(struct rtnl_link_ops *ops)
46642 {
46643 /* common fields */
46644- ops->priv_size = sizeof(struct macvlan_dev);
46645- ops->validate = macvlan_validate;
46646- ops->maxtype = IFLA_MACVLAN_MAX;
46647- ops->policy = macvlan_policy;
46648- ops->changelink = macvlan_changelink;
46649- ops->get_size = macvlan_get_size;
46650- ops->fill_info = macvlan_fill_info;
46651+ pax_open_kernel();
46652+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
46653+ *(void **)&ops->validate = macvlan_validate;
46654+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
46655+ *(const void **)&ops->policy = macvlan_policy;
46656+ *(void **)&ops->changelink = macvlan_changelink;
46657+ *(void **)&ops->get_size = macvlan_get_size;
46658+ *(void **)&ops->fill_info = macvlan_fill_info;
46659+ pax_close_kernel();
46660
46661 return rtnl_link_register(ops);
46662 };
46663@@ -1045,7 +1047,7 @@ static int macvlan_device_event(struct notifier_block *unused,
46664 return NOTIFY_DONE;
46665 }
46666
46667-static struct notifier_block macvlan_notifier_block __read_mostly = {
46668+static struct notifier_block macvlan_notifier_block = {
46669 .notifier_call = macvlan_device_event,
46670 };
46671
46672diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
46673index ff111a8..c4c3ac4 100644
46674--- a/drivers/net/macvtap.c
46675+++ b/drivers/net/macvtap.c
46676@@ -1011,7 +1011,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
46677 }
46678
46679 ret = 0;
46680- if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46681+ if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46682 put_user(q->flags, &ifr->ifr_flags))
46683 ret = -EFAULT;
46684 macvtap_put_vlan(vlan);
46685@@ -1181,7 +1181,7 @@ static int macvtap_device_event(struct notifier_block *unused,
46686 return NOTIFY_DONE;
46687 }
46688
46689-static struct notifier_block macvtap_notifier_block __read_mostly = {
46690+static struct notifier_block macvtap_notifier_block = {
46691 .notifier_call = macvtap_device_event,
46692 };
46693
46694diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
46695index daec9b0..6428fcb 100644
46696--- a/drivers/net/phy/mdio-bitbang.c
46697+++ b/drivers/net/phy/mdio-bitbang.c
46698@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
46699 struct mdiobb_ctrl *ctrl = bus->priv;
46700
46701 module_put(ctrl->ops->owner);
46702+ mdiobus_unregister(bus);
46703 mdiobus_free(bus);
46704 }
46705 EXPORT_SYMBOL(free_mdio_bitbang);
46706diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
46707index 72ff14b..11d442d 100644
46708--- a/drivers/net/ppp/ppp_generic.c
46709+++ b/drivers/net/ppp/ppp_generic.c
46710@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46711 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
46712 struct ppp_stats stats;
46713 struct ppp_comp_stats cstats;
46714- char *vers;
46715
46716 switch (cmd) {
46717 case SIOCGPPPSTATS:
46718@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46719 break;
46720
46721 case SIOCGPPPVER:
46722- vers = PPP_VERSION;
46723- if (copy_to_user(addr, vers, strlen(vers) + 1))
46724+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
46725 break;
46726 err = 0;
46727 break;
46728diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
46729index 1252d9c..80e660b 100644
46730--- a/drivers/net/slip/slhc.c
46731+++ b/drivers/net/slip/slhc.c
46732@@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
46733 register struct tcphdr *thp;
46734 register struct iphdr *ip;
46735 register struct cstate *cs;
46736- int len, hdrlen;
46737+ long len, hdrlen;
46738 unsigned char *cp = icp;
46739
46740 /* We've got a compressed packet; read the change byte */
46741diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
46742index c8624a8..f0a4f6a 100644
46743--- a/drivers/net/team/team.c
46744+++ b/drivers/net/team/team.c
46745@@ -2869,7 +2869,7 @@ static int team_device_event(struct notifier_block *unused,
46746 return NOTIFY_DONE;
46747 }
46748
46749-static struct notifier_block team_notifier_block __read_mostly = {
46750+static struct notifier_block team_notifier_block = {
46751 .notifier_call = team_device_event,
46752 };
46753
46754diff --git a/drivers/net/tun.c b/drivers/net/tun.c
46755index 26f8635..c237839 100644
46756--- a/drivers/net/tun.c
46757+++ b/drivers/net/tun.c
46758@@ -1876,7 +1876,7 @@ unlock:
46759 }
46760
46761 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46762- unsigned long arg, int ifreq_len)
46763+ unsigned long arg, size_t ifreq_len)
46764 {
46765 struct tun_file *tfile = file->private_data;
46766 struct tun_struct *tun;
46767@@ -1889,6 +1889,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46768 unsigned int ifindex;
46769 int ret;
46770
46771+ if (ifreq_len > sizeof ifr)
46772+ return -EFAULT;
46773+
46774 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
46775 if (copy_from_user(&ifr, argp, ifreq_len))
46776 return -EFAULT;
46777diff --git a/drivers/net/usb/cdc_ncm.c b/drivers/net/usb/cdc_ncm.c
46778index d350d27..75d7d9d 100644
46779--- a/drivers/net/usb/cdc_ncm.c
46780+++ b/drivers/net/usb/cdc_ncm.c
46781@@ -768,7 +768,7 @@ cdc_ncm_fill_tx_frame(struct usbnet *dev, struct sk_buff *skb, __le32 sign)
46782 skb_out->len > CDC_NCM_MIN_TX_PKT)
46783 memset(skb_put(skb_out, ctx->tx_max - skb_out->len), 0,
46784 ctx->tx_max - skb_out->len);
46785- else if ((skb_out->len % dev->maxpacket) == 0)
46786+ else if (skb_out->len < ctx->tx_max && (skb_out->len % dev->maxpacket) == 0)
46787 *skb_put(skb_out, 1) = 0; /* force short packet */
46788
46789 /* set final frame length */
46790diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
46791index 660bd5e..ac59452 100644
46792--- a/drivers/net/usb/hso.c
46793+++ b/drivers/net/usb/hso.c
46794@@ -71,7 +71,7 @@
46795 #include <asm/byteorder.h>
46796 #include <linux/serial_core.h>
46797 #include <linux/serial.h>
46798-
46799+#include <asm/local.h>
46800
46801 #define MOD_AUTHOR "Option Wireless"
46802 #define MOD_DESCRIPTION "USB High Speed Option driver"
46803@@ -1179,7 +1179,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
46804 struct urb *urb;
46805
46806 urb = serial->rx_urb[0];
46807- if (serial->port.count > 0) {
46808+ if (atomic_read(&serial->port.count) > 0) {
46809 count = put_rxbuf_data(urb, serial);
46810 if (count == -1)
46811 return;
46812@@ -1217,7 +1217,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
46813 DUMP1(urb->transfer_buffer, urb->actual_length);
46814
46815 /* Anyone listening? */
46816- if (serial->port.count == 0)
46817+ if (atomic_read(&serial->port.count) == 0)
46818 return;
46819
46820 if (serial->parent->port_spec & HSO_INFO_CRC_BUG)
46821@@ -1287,8 +1287,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46822 tty_port_tty_set(&serial->port, tty);
46823
46824 /* check for port already opened, if not set the termios */
46825- serial->port.count++;
46826- if (serial->port.count == 1) {
46827+ if (atomic_inc_return(&serial->port.count) == 1) {
46828 serial->rx_state = RX_IDLE;
46829 /* Force default termio settings */
46830 _hso_serial_set_termios(tty, NULL);
46831@@ -1300,7 +1299,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46832 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
46833 if (result) {
46834 hso_stop_serial_device(serial->parent);
46835- serial->port.count--;
46836+ atomic_dec(&serial->port.count);
46837 kref_put(&serial->parent->ref, hso_serial_ref_free);
46838 }
46839 } else {
46840@@ -1337,10 +1336,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
46841
46842 /* reset the rts and dtr */
46843 /* do the actual close */
46844- serial->port.count--;
46845+ atomic_dec(&serial->port.count);
46846
46847- if (serial->port.count <= 0) {
46848- serial->port.count = 0;
46849+ if (atomic_read(&serial->port.count) <= 0) {
46850+ atomic_set(&serial->port.count, 0);
46851 tty_port_tty_set(&serial->port, NULL);
46852 if (!usb_gone)
46853 hso_stop_serial_device(serial->parent);
46854@@ -1416,7 +1415,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
46855
46856 /* the actual setup */
46857 spin_lock_irqsave(&serial->serial_lock, flags);
46858- if (serial->port.count)
46859+ if (atomic_read(&serial->port.count))
46860 _hso_serial_set_termios(tty, old);
46861 else
46862 tty->termios = *old;
46863@@ -1885,7 +1884,7 @@ static void intr_callback(struct urb *urb)
46864 D1("Pending read interrupt on port %d\n", i);
46865 spin_lock(&serial->serial_lock);
46866 if (serial->rx_state == RX_IDLE &&
46867- serial->port.count > 0) {
46868+ atomic_read(&serial->port.count) > 0) {
46869 /* Setup and send a ctrl req read on
46870 * port i */
46871 if (!serial->rx_urb_filled[0]) {
46872@@ -3061,7 +3060,7 @@ static int hso_resume(struct usb_interface *iface)
46873 /* Start all serial ports */
46874 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
46875 if (serial_table[i] && (serial_table[i]->interface == iface)) {
46876- if (dev2ser(serial_table[i])->port.count) {
46877+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
46878 result =
46879 hso_start_serial_device(serial_table[i], GFP_NOIO);
46880 hso_kick_transmit(dev2ser(serial_table[i]));
46881diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
46882index adb12f3..48005ab 100644
46883--- a/drivers/net/usb/r8152.c
46884+++ b/drivers/net/usb/r8152.c
46885@@ -513,7 +513,7 @@ struct r8152 {
46886 void (*disable)(struct r8152 *);
46887 void (*down)(struct r8152 *);
46888 void (*unload)(struct r8152 *);
46889- } rtl_ops;
46890+ } __no_const rtl_ops;
46891
46892 int intr_interval;
46893 u32 msg_enable;
46894diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
46895index a2515887..6d13233 100644
46896--- a/drivers/net/usb/sierra_net.c
46897+++ b/drivers/net/usb/sierra_net.c
46898@@ -51,7 +51,7 @@ static const char driver_name[] = "sierra_net";
46899 /* atomic counter partially included in MAC address to make sure 2 devices
46900 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
46901 */
46902-static atomic_t iface_counter = ATOMIC_INIT(0);
46903+static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
46904
46905 /*
46906 * SYNC Timer Delay definition used to set the expiry time
46907@@ -697,7 +697,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
46908 dev->net->netdev_ops = &sierra_net_device_ops;
46909
46910 /* change MAC addr to include, ifacenum, and to be unique */
46911- dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
46912+ dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
46913 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
46914
46915 /* we will have to manufacture ethernet headers, prepare template */
46916diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
46917index d091e52..568bb179 100644
46918--- a/drivers/net/vxlan.c
46919+++ b/drivers/net/vxlan.c
46920@@ -2847,7 +2847,7 @@ nla_put_failure:
46921 return -EMSGSIZE;
46922 }
46923
46924-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
46925+static struct rtnl_link_ops vxlan_link_ops = {
46926 .kind = "vxlan",
46927 .maxtype = IFLA_VXLAN_MAX,
46928 .policy = vxlan_policy,
46929@@ -2894,7 +2894,7 @@ static int vxlan_lowerdev_event(struct notifier_block *unused,
46930 return NOTIFY_DONE;
46931 }
46932
46933-static struct notifier_block vxlan_notifier_block __read_mostly = {
46934+static struct notifier_block vxlan_notifier_block = {
46935 .notifier_call = vxlan_lowerdev_event,
46936 };
46937
46938diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
46939index 5920c99..ff2e4a5 100644
46940--- a/drivers/net/wan/lmc/lmc_media.c
46941+++ b/drivers/net/wan/lmc/lmc_media.c
46942@@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
46943 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
46944
46945 lmc_media_t lmc_ds3_media = {
46946- lmc_ds3_init, /* special media init stuff */
46947- lmc_ds3_default, /* reset to default state */
46948- lmc_ds3_set_status, /* reset status to state provided */
46949- lmc_dummy_set_1, /* set clock source */
46950- lmc_dummy_set2_1, /* set line speed */
46951- lmc_ds3_set_100ft, /* set cable length */
46952- lmc_ds3_set_scram, /* set scrambler */
46953- lmc_ds3_get_link_status, /* get link status */
46954- lmc_dummy_set_1, /* set link status */
46955- lmc_ds3_set_crc_length, /* set CRC length */
46956- lmc_dummy_set_1, /* set T1 or E1 circuit type */
46957- lmc_ds3_watchdog
46958+ .init = lmc_ds3_init, /* special media init stuff */
46959+ .defaults = lmc_ds3_default, /* reset to default state */
46960+ .set_status = lmc_ds3_set_status, /* reset status to state provided */
46961+ .set_clock_source = lmc_dummy_set_1, /* set clock source */
46962+ .set_speed = lmc_dummy_set2_1, /* set line speed */
46963+ .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
46964+ .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
46965+ .get_link_status = lmc_ds3_get_link_status, /* get link status */
46966+ .set_link_status = lmc_dummy_set_1, /* set link status */
46967+ .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
46968+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46969+ .watchdog = lmc_ds3_watchdog
46970 };
46971
46972 lmc_media_t lmc_hssi_media = {
46973- lmc_hssi_init, /* special media init stuff */
46974- lmc_hssi_default, /* reset to default state */
46975- lmc_hssi_set_status, /* reset status to state provided */
46976- lmc_hssi_set_clock, /* set clock source */
46977- lmc_dummy_set2_1, /* set line speed */
46978- lmc_dummy_set_1, /* set cable length */
46979- lmc_dummy_set_1, /* set scrambler */
46980- lmc_hssi_get_link_status, /* get link status */
46981- lmc_hssi_set_link_status, /* set link status */
46982- lmc_hssi_set_crc_length, /* set CRC length */
46983- lmc_dummy_set_1, /* set T1 or E1 circuit type */
46984- lmc_hssi_watchdog
46985+ .init = lmc_hssi_init, /* special media init stuff */
46986+ .defaults = lmc_hssi_default, /* reset to default state */
46987+ .set_status = lmc_hssi_set_status, /* reset status to state provided */
46988+ .set_clock_source = lmc_hssi_set_clock, /* set clock source */
46989+ .set_speed = lmc_dummy_set2_1, /* set line speed */
46990+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
46991+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46992+ .get_link_status = lmc_hssi_get_link_status, /* get link status */
46993+ .set_link_status = lmc_hssi_set_link_status, /* set link status */
46994+ .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
46995+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46996+ .watchdog = lmc_hssi_watchdog
46997 };
46998
46999-lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
47000- lmc_ssi_default, /* reset to default state */
47001- lmc_ssi_set_status, /* reset status to state provided */
47002- lmc_ssi_set_clock, /* set clock source */
47003- lmc_ssi_set_speed, /* set line speed */
47004- lmc_dummy_set_1, /* set cable length */
47005- lmc_dummy_set_1, /* set scrambler */
47006- lmc_ssi_get_link_status, /* get link status */
47007- lmc_ssi_set_link_status, /* set link status */
47008- lmc_ssi_set_crc_length, /* set CRC length */
47009- lmc_dummy_set_1, /* set T1 or E1 circuit type */
47010- lmc_ssi_watchdog
47011+lmc_media_t lmc_ssi_media = {
47012+ .init = lmc_ssi_init, /* special media init stuff */
47013+ .defaults = lmc_ssi_default, /* reset to default state */
47014+ .set_status = lmc_ssi_set_status, /* reset status to state provided */
47015+ .set_clock_source = lmc_ssi_set_clock, /* set clock source */
47016+ .set_speed = lmc_ssi_set_speed, /* set line speed */
47017+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
47018+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
47019+ .get_link_status = lmc_ssi_get_link_status, /* get link status */
47020+ .set_link_status = lmc_ssi_set_link_status, /* set link status */
47021+ .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
47022+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
47023+ .watchdog = lmc_ssi_watchdog
47024 };
47025
47026 lmc_media_t lmc_t1_media = {
47027- lmc_t1_init, /* special media init stuff */
47028- lmc_t1_default, /* reset to default state */
47029- lmc_t1_set_status, /* reset status to state provided */
47030- lmc_t1_set_clock, /* set clock source */
47031- lmc_dummy_set2_1, /* set line speed */
47032- lmc_dummy_set_1, /* set cable length */
47033- lmc_dummy_set_1, /* set scrambler */
47034- lmc_t1_get_link_status, /* get link status */
47035- lmc_dummy_set_1, /* set link status */
47036- lmc_t1_set_crc_length, /* set CRC length */
47037- lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
47038- lmc_t1_watchdog
47039+ .init = lmc_t1_init, /* special media init stuff */
47040+ .defaults = lmc_t1_default, /* reset to default state */
47041+ .set_status = lmc_t1_set_status, /* reset status to state provided */
47042+ .set_clock_source = lmc_t1_set_clock, /* set clock source */
47043+ .set_speed = lmc_dummy_set2_1, /* set line speed */
47044+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
47045+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
47046+ .get_link_status = lmc_t1_get_link_status, /* get link status */
47047+ .set_link_status = lmc_dummy_set_1, /* set link status */
47048+ .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
47049+ .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
47050+ .watchdog = lmc_t1_watchdog
47051 };
47052
47053 static void
47054diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
47055index feacc3b..5bac0de 100644
47056--- a/drivers/net/wan/z85230.c
47057+++ b/drivers/net/wan/z85230.c
47058@@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
47059
47060 struct z8530_irqhandler z8530_sync =
47061 {
47062- z8530_rx,
47063- z8530_tx,
47064- z8530_status
47065+ .rx = z8530_rx,
47066+ .tx = z8530_tx,
47067+ .status = z8530_status
47068 };
47069
47070 EXPORT_SYMBOL(z8530_sync);
47071@@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
47072 }
47073
47074 static struct z8530_irqhandler z8530_dma_sync = {
47075- z8530_dma_rx,
47076- z8530_dma_tx,
47077- z8530_dma_status
47078+ .rx = z8530_dma_rx,
47079+ .tx = z8530_dma_tx,
47080+ .status = z8530_dma_status
47081 };
47082
47083 static struct z8530_irqhandler z8530_txdma_sync = {
47084- z8530_rx,
47085- z8530_dma_tx,
47086- z8530_dma_status
47087+ .rx = z8530_rx,
47088+ .tx = z8530_dma_tx,
47089+ .status = z8530_dma_status
47090 };
47091
47092 /**
47093@@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
47094
47095 struct z8530_irqhandler z8530_nop=
47096 {
47097- z8530_rx_clear,
47098- z8530_tx_clear,
47099- z8530_status_clear
47100+ .rx = z8530_rx_clear,
47101+ .tx = z8530_tx_clear,
47102+ .status = z8530_status_clear
47103 };
47104
47105
47106diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
47107index 0b60295..b8bfa5b 100644
47108--- a/drivers/net/wimax/i2400m/rx.c
47109+++ b/drivers/net/wimax/i2400m/rx.c
47110@@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
47111 if (i2400m->rx_roq == NULL)
47112 goto error_roq_alloc;
47113
47114- rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
47115+ rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
47116 GFP_KERNEL);
47117 if (rd == NULL) {
47118 result = -ENOMEM;
47119diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
47120index edf4b57..68b51c0 100644
47121--- a/drivers/net/wireless/airo.c
47122+++ b/drivers/net/wireless/airo.c
47123@@ -7843,7 +7843,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
47124 struct airo_info *ai = dev->ml_priv;
47125 int ridcode;
47126 int enabled;
47127- static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
47128+ int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
47129 unsigned char *iobuf;
47130
47131 /* Only super-user can write RIDs */
47132diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
47133index 99b3bfa..9559372 100644
47134--- a/drivers/net/wireless/at76c50x-usb.c
47135+++ b/drivers/net/wireless/at76c50x-usb.c
47136@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
47137 }
47138
47139 /* Convert timeout from the DFU status to jiffies */
47140-static inline unsigned long at76_get_timeout(struct dfu_status *s)
47141+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
47142 {
47143 return msecs_to_jiffies((s->poll_timeout[2] << 16)
47144 | (s->poll_timeout[1] << 8)
47145diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
47146index edc57ab..ff49e0a 100644
47147--- a/drivers/net/wireless/ath/ath10k/htc.c
47148+++ b/drivers/net/wireless/ath/ath10k/htc.c
47149@@ -831,7 +831,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
47150 /* registered target arrival callback from the HIF layer */
47151 int ath10k_htc_init(struct ath10k *ar)
47152 {
47153- struct ath10k_hif_cb htc_callbacks;
47154+ static struct ath10k_hif_cb htc_callbacks = {
47155+ .rx_completion = ath10k_htc_rx_completion_handler,
47156+ .tx_completion = ath10k_htc_tx_completion_handler,
47157+ };
47158 struct ath10k_htc_ep *ep = NULL;
47159 struct ath10k_htc *htc = &ar->htc;
47160
47161@@ -841,8 +844,6 @@ int ath10k_htc_init(struct ath10k *ar)
47162 ath10k_htc_reset_endpoint_states(htc);
47163
47164 /* setup HIF layer callbacks */
47165- htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
47166- htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
47167 htc->ar = ar;
47168
47169 /* Get HIF default pipe for HTC message exchange */
47170diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
47171index 4716d33..a688310 100644
47172--- a/drivers/net/wireless/ath/ath10k/htc.h
47173+++ b/drivers/net/wireless/ath/ath10k/htc.h
47174@@ -271,13 +271,13 @@ enum ath10k_htc_ep_id {
47175
47176 struct ath10k_htc_ops {
47177 void (*target_send_suspend_complete)(struct ath10k *ar);
47178-};
47179+} __no_const;
47180
47181 struct ath10k_htc_ep_ops {
47182 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
47183 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
47184 void (*ep_tx_credits)(struct ath10k *);
47185-};
47186+} __no_const;
47187
47188 /* service connection information */
47189 struct ath10k_htc_svc_conn_req {
47190diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
47191index 741b38d..b7ae41b 100644
47192--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
47193+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
47194@@ -220,8 +220,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47195 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
47196 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
47197
47198- ACCESS_ONCE(ads->ds_link) = i->link;
47199- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
47200+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
47201+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
47202
47203 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
47204 ctl6 = SM(i->keytype, AR_EncrType);
47205@@ -235,26 +235,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47206
47207 if ((i->is_first || i->is_last) &&
47208 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
47209- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
47210+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
47211 | set11nTries(i->rates, 1)
47212 | set11nTries(i->rates, 2)
47213 | set11nTries(i->rates, 3)
47214 | (i->dur_update ? AR_DurUpdateEna : 0)
47215 | SM(0, AR_BurstDur);
47216
47217- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
47218+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
47219 | set11nRate(i->rates, 1)
47220 | set11nRate(i->rates, 2)
47221 | set11nRate(i->rates, 3);
47222 } else {
47223- ACCESS_ONCE(ads->ds_ctl2) = 0;
47224- ACCESS_ONCE(ads->ds_ctl3) = 0;
47225+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
47226+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
47227 }
47228
47229 if (!i->is_first) {
47230- ACCESS_ONCE(ads->ds_ctl0) = 0;
47231- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
47232- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
47233+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
47234+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
47235+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
47236 return;
47237 }
47238
47239@@ -279,7 +279,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47240 break;
47241 }
47242
47243- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
47244+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
47245 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
47246 | SM(i->txpower, AR_XmitPower)
47247 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
47248@@ -289,19 +289,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47249 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
47250 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
47251
47252- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
47253- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
47254+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
47255+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
47256
47257 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
47258 return;
47259
47260- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
47261+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
47262 | set11nPktDurRTSCTS(i->rates, 1);
47263
47264- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
47265+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
47266 | set11nPktDurRTSCTS(i->rates, 3);
47267
47268- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
47269+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
47270 | set11nRateFlags(i->rates, 1)
47271 | set11nRateFlags(i->rates, 2)
47272 | set11nRateFlags(i->rates, 3)
47273diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
47274index 729ffbf..49f50e3 100644
47275--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
47276+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
47277@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47278 (i->qcu << AR_TxQcuNum_S) | desc_len;
47279
47280 checksum += val;
47281- ACCESS_ONCE(ads->info) = val;
47282+ ACCESS_ONCE_RW(ads->info) = val;
47283
47284 checksum += i->link;
47285- ACCESS_ONCE(ads->link) = i->link;
47286+ ACCESS_ONCE_RW(ads->link) = i->link;
47287
47288 checksum += i->buf_addr[0];
47289- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
47290+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
47291 checksum += i->buf_addr[1];
47292- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
47293+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
47294 checksum += i->buf_addr[2];
47295- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
47296+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
47297 checksum += i->buf_addr[3];
47298- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
47299+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
47300
47301 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
47302- ACCESS_ONCE(ads->ctl3) = val;
47303+ ACCESS_ONCE_RW(ads->ctl3) = val;
47304 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
47305- ACCESS_ONCE(ads->ctl5) = val;
47306+ ACCESS_ONCE_RW(ads->ctl5) = val;
47307 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
47308- ACCESS_ONCE(ads->ctl7) = val;
47309+ ACCESS_ONCE_RW(ads->ctl7) = val;
47310 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
47311- ACCESS_ONCE(ads->ctl9) = val;
47312+ ACCESS_ONCE_RW(ads->ctl9) = val;
47313
47314 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
47315- ACCESS_ONCE(ads->ctl10) = checksum;
47316+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
47317
47318 if (i->is_first || i->is_last) {
47319- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
47320+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
47321 | set11nTries(i->rates, 1)
47322 | set11nTries(i->rates, 2)
47323 | set11nTries(i->rates, 3)
47324 | (i->dur_update ? AR_DurUpdateEna : 0)
47325 | SM(0, AR_BurstDur);
47326
47327- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
47328+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
47329 | set11nRate(i->rates, 1)
47330 | set11nRate(i->rates, 2)
47331 | set11nRate(i->rates, 3);
47332 } else {
47333- ACCESS_ONCE(ads->ctl13) = 0;
47334- ACCESS_ONCE(ads->ctl14) = 0;
47335+ ACCESS_ONCE_RW(ads->ctl13) = 0;
47336+ ACCESS_ONCE_RW(ads->ctl14) = 0;
47337 }
47338
47339 ads->ctl20 = 0;
47340@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47341
47342 ctl17 = SM(i->keytype, AR_EncrType);
47343 if (!i->is_first) {
47344- ACCESS_ONCE(ads->ctl11) = 0;
47345- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
47346- ACCESS_ONCE(ads->ctl15) = 0;
47347- ACCESS_ONCE(ads->ctl16) = 0;
47348- ACCESS_ONCE(ads->ctl17) = ctl17;
47349- ACCESS_ONCE(ads->ctl18) = 0;
47350- ACCESS_ONCE(ads->ctl19) = 0;
47351+ ACCESS_ONCE_RW(ads->ctl11) = 0;
47352+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
47353+ ACCESS_ONCE_RW(ads->ctl15) = 0;
47354+ ACCESS_ONCE_RW(ads->ctl16) = 0;
47355+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
47356+ ACCESS_ONCE_RW(ads->ctl18) = 0;
47357+ ACCESS_ONCE_RW(ads->ctl19) = 0;
47358 return;
47359 }
47360
47361- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
47362+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
47363 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
47364 | SM(i->txpower, AR_XmitPower)
47365 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
47366@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47367 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
47368 ctl12 |= SM(val, AR_PAPRDChainMask);
47369
47370- ACCESS_ONCE(ads->ctl12) = ctl12;
47371- ACCESS_ONCE(ads->ctl17) = ctl17;
47372+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
47373+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
47374
47375- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
47376+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
47377 | set11nPktDurRTSCTS(i->rates, 1);
47378
47379- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
47380+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
47381 | set11nPktDurRTSCTS(i->rates, 3);
47382
47383- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
47384+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
47385 | set11nRateFlags(i->rates, 1)
47386 | set11nRateFlags(i->rates, 2)
47387 | set11nRateFlags(i->rates, 3)
47388 | SM(i->rtscts_rate, AR_RTSCTSRate);
47389
47390- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
47391+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
47392 }
47393
47394 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
47395diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
47396index 0acd4b5..0591c91 100644
47397--- a/drivers/net/wireless/ath/ath9k/hw.h
47398+++ b/drivers/net/wireless/ath/ath9k/hw.h
47399@@ -629,7 +629,7 @@ struct ath_hw_private_ops {
47400
47401 /* ANI */
47402 void (*ani_cache_ini_regs)(struct ath_hw *ah);
47403-};
47404+} __no_const;
47405
47406 /**
47407 * struct ath_spec_scan - parameters for Atheros spectral scan
47408@@ -706,7 +706,7 @@ struct ath_hw_ops {
47409 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
47410 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
47411 #endif
47412-};
47413+} __no_const;
47414
47415 struct ath_nf_limits {
47416 s16 max;
47417diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
47418index 92190da..f3a4c4c 100644
47419--- a/drivers/net/wireless/b43/phy_lp.c
47420+++ b/drivers/net/wireless/b43/phy_lp.c
47421@@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
47422 {
47423 struct ssb_bus *bus = dev->dev->sdev->bus;
47424
47425- static const struct b206x_channel *chandata = NULL;
47426+ const struct b206x_channel *chandata = NULL;
47427 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
47428 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
47429 u16 old_comm15, scale;
47430diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
47431index 0487461..fd9e84a 100644
47432--- a/drivers/net/wireless/iwlegacy/3945-mac.c
47433+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
47434@@ -3638,7 +3638,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
47435 */
47436 if (il3945_mod_params.disable_hw_scan) {
47437 D_INFO("Disabling hw_scan\n");
47438- il3945_mac_ops.hw_scan = NULL;
47439+ pax_open_kernel();
47440+ *(void **)&il3945_mac_ops.hw_scan = NULL;
47441+ pax_close_kernel();
47442 }
47443
47444 D_INFO("*** LOAD DRIVER ***\n");
47445diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
47446index d2fe259..0c4c682 100644
47447--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
47448+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
47449@@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
47450 {
47451 struct iwl_priv *priv = file->private_data;
47452 char buf[64];
47453- int buf_size;
47454+ size_t buf_size;
47455 u32 offset, len;
47456
47457 memset(buf, 0, sizeof(buf));
47458@@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
47459 struct iwl_priv *priv = file->private_data;
47460
47461 char buf[8];
47462- int buf_size;
47463+ size_t buf_size;
47464 u32 reset_flag;
47465
47466 memset(buf, 0, sizeof(buf));
47467@@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
47468 {
47469 struct iwl_priv *priv = file->private_data;
47470 char buf[8];
47471- int buf_size;
47472+ size_t buf_size;
47473 int ht40;
47474
47475 memset(buf, 0, sizeof(buf));
47476@@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
47477 {
47478 struct iwl_priv *priv = file->private_data;
47479 char buf[8];
47480- int buf_size;
47481+ size_t buf_size;
47482 int value;
47483
47484 memset(buf, 0, sizeof(buf));
47485@@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
47486 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
47487 DEBUGFS_READ_FILE_OPS(current_sleep_command);
47488
47489-static const char *fmt_value = " %-30s %10u\n";
47490-static const char *fmt_hex = " %-30s 0x%02X\n";
47491-static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
47492-static const char *fmt_header =
47493+static const char fmt_value[] = " %-30s %10u\n";
47494+static const char fmt_hex[] = " %-30s 0x%02X\n";
47495+static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
47496+static const char fmt_header[] =
47497 "%-32s current cumulative delta max\n";
47498
47499 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
47500@@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
47501 {
47502 struct iwl_priv *priv = file->private_data;
47503 char buf[8];
47504- int buf_size;
47505+ size_t buf_size;
47506 int clear;
47507
47508 memset(buf, 0, sizeof(buf));
47509@@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
47510 {
47511 struct iwl_priv *priv = file->private_data;
47512 char buf[8];
47513- int buf_size;
47514+ size_t buf_size;
47515 int trace;
47516
47517 memset(buf, 0, sizeof(buf));
47518@@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
47519 {
47520 struct iwl_priv *priv = file->private_data;
47521 char buf[8];
47522- int buf_size;
47523+ size_t buf_size;
47524 int missed;
47525
47526 memset(buf, 0, sizeof(buf));
47527@@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
47528
47529 struct iwl_priv *priv = file->private_data;
47530 char buf[8];
47531- int buf_size;
47532+ size_t buf_size;
47533 int plcp;
47534
47535 memset(buf, 0, sizeof(buf));
47536@@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
47537
47538 struct iwl_priv *priv = file->private_data;
47539 char buf[8];
47540- int buf_size;
47541+ size_t buf_size;
47542 int flush;
47543
47544 memset(buf, 0, sizeof(buf));
47545@@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
47546
47547 struct iwl_priv *priv = file->private_data;
47548 char buf[8];
47549- int buf_size;
47550+ size_t buf_size;
47551 int rts;
47552
47553 if (!priv->cfg->ht_params)
47554@@ -2205,7 +2205,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
47555 {
47556 struct iwl_priv *priv = file->private_data;
47557 char buf[8];
47558- int buf_size;
47559+ size_t buf_size;
47560
47561 memset(buf, 0, sizeof(buf));
47562 buf_size = min(count, sizeof(buf) - 1);
47563@@ -2239,7 +2239,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
47564 struct iwl_priv *priv = file->private_data;
47565 u32 event_log_flag;
47566 char buf[8];
47567- int buf_size;
47568+ size_t buf_size;
47569
47570 /* check that the interface is up */
47571 if (!iwl_is_ready(priv))
47572@@ -2293,7 +2293,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
47573 struct iwl_priv *priv = file->private_data;
47574 char buf[8];
47575 u32 calib_disabled;
47576- int buf_size;
47577+ size_t buf_size;
47578
47579 memset(buf, 0, sizeof(buf));
47580 buf_size = min(count, sizeof(buf) - 1);
47581diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
47582index ba1b1ea..0ff7e98 100644
47583--- a/drivers/net/wireless/iwlwifi/dvm/main.c
47584+++ b/drivers/net/wireless/iwlwifi/dvm/main.c
47585@@ -1123,7 +1123,7 @@ static void iwl_option_config(struct iwl_priv *priv)
47586 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
47587 {
47588 struct iwl_nvm_data *data = priv->nvm_data;
47589- char *debug_msg;
47590+ static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
47591
47592 if (data->sku_cap_11n_enable &&
47593 !priv->cfg->ht_params) {
47594@@ -1137,7 +1137,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
47595 return -EINVAL;
47596 }
47597
47598- debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
47599 IWL_DEBUG_INFO(priv, debug_msg,
47600 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
47601 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
47602diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
47603index f950780..be9df93 100644
47604--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
47605+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
47606@@ -1365,7 +1365,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
47607 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
47608
47609 char buf[8];
47610- int buf_size;
47611+ size_t buf_size;
47612 u32 reset_flag;
47613
47614 memset(buf, 0, sizeof(buf));
47615@@ -1386,7 +1386,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
47616 {
47617 struct iwl_trans *trans = file->private_data;
47618 char buf[8];
47619- int buf_size;
47620+ size_t buf_size;
47621 int csr;
47622
47623 memset(buf, 0, sizeof(buf));
47624diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
47625index 69d4c31..bd0b316 100644
47626--- a/drivers/net/wireless/mac80211_hwsim.c
47627+++ b/drivers/net/wireless/mac80211_hwsim.c
47628@@ -2541,20 +2541,20 @@ static int __init init_mac80211_hwsim(void)
47629 if (channels < 1)
47630 return -EINVAL;
47631
47632- mac80211_hwsim_mchan_ops = mac80211_hwsim_ops;
47633- mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
47634- mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
47635- mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
47636- mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
47637- mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
47638- mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
47639- mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
47640- mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
47641- mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47642- mac80211_hwsim_mchan_ops.assign_vif_chanctx =
47643- mac80211_hwsim_assign_vif_chanctx;
47644- mac80211_hwsim_mchan_ops.unassign_vif_chanctx =
47645- mac80211_hwsim_unassign_vif_chanctx;
47646+ pax_open_kernel();
47647+ memcpy((void *)&mac80211_hwsim_mchan_ops, &mac80211_hwsim_ops, sizeof mac80211_hwsim_mchan_ops);
47648+ *(void **)&mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
47649+ *(void **)&mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
47650+ *(void **)&mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
47651+ *(void **)&mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
47652+ *(void **)&mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
47653+ *(void **)&mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
47654+ *(void **)&mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
47655+ *(void **)&mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
47656+ *(void **)&mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47657+ *(void **)&mac80211_hwsim_mchan_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
47658+ *(void **)&mac80211_hwsim_mchan_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
47659+ pax_close_kernel();
47660
47661 spin_lock_init(&hwsim_radio_lock);
47662 INIT_LIST_HEAD(&hwsim_radios);
47663diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
47664index 5028557..91cf394 100644
47665--- a/drivers/net/wireless/rndis_wlan.c
47666+++ b/drivers/net/wireless/rndis_wlan.c
47667@@ -1236,7 +1236,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
47668
47669 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
47670
47671- if (rts_threshold < 0 || rts_threshold > 2347)
47672+ if (rts_threshold > 2347)
47673 rts_threshold = 2347;
47674
47675 tmp = cpu_to_le32(rts_threshold);
47676diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
47677index e3b885d..7a7de2f 100644
47678--- a/drivers/net/wireless/rt2x00/rt2x00.h
47679+++ b/drivers/net/wireless/rt2x00/rt2x00.h
47680@@ -375,7 +375,7 @@ struct rt2x00_intf {
47681 * for hardware which doesn't support hardware
47682 * sequence counting.
47683 */
47684- atomic_t seqno;
47685+ atomic_unchecked_t seqno;
47686 };
47687
47688 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
47689diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
47690index 5642ccc..01f03eb 100644
47691--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
47692+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
47693@@ -250,9 +250,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
47694 * sequence counter given by mac80211.
47695 */
47696 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
47697- seqno = atomic_add_return(0x10, &intf->seqno);
47698+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
47699 else
47700- seqno = atomic_read(&intf->seqno);
47701+ seqno = atomic_read_unchecked(&intf->seqno);
47702
47703 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
47704 hdr->seq_ctrl |= cpu_to_le16(seqno);
47705diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
47706index e2b3d9c..67a5184 100644
47707--- a/drivers/net/wireless/ti/wl1251/sdio.c
47708+++ b/drivers/net/wireless/ti/wl1251/sdio.c
47709@@ -271,13 +271,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
47710
47711 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
47712
47713- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47714- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47715+ pax_open_kernel();
47716+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47717+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47718+ pax_close_kernel();
47719
47720 wl1251_info("using dedicated interrupt line");
47721 } else {
47722- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47723- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47724+ pax_open_kernel();
47725+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47726+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47727+ pax_close_kernel();
47728
47729 wl1251_info("using SDIO interrupt");
47730 }
47731diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
47732index be7129b..4161356 100644
47733--- a/drivers/net/wireless/ti/wl12xx/main.c
47734+++ b/drivers/net/wireless/ti/wl12xx/main.c
47735@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47736 sizeof(wl->conf.mem));
47737
47738 /* read data preparation is only needed by wl127x */
47739- wl->ops->prepare_read = wl127x_prepare_read;
47740+ pax_open_kernel();
47741+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47742+ pax_close_kernel();
47743
47744 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47745 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47746@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47747 sizeof(wl->conf.mem));
47748
47749 /* read data preparation is only needed by wl127x */
47750- wl->ops->prepare_read = wl127x_prepare_read;
47751+ pax_open_kernel();
47752+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47753+ pax_close_kernel();
47754
47755 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47756 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47757diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
47758index ec37b16..7e34d66 100644
47759--- a/drivers/net/wireless/ti/wl18xx/main.c
47760+++ b/drivers/net/wireless/ti/wl18xx/main.c
47761@@ -1823,8 +1823,10 @@ static int wl18xx_setup(struct wl1271 *wl)
47762 }
47763
47764 if (!checksum_param) {
47765- wl18xx_ops.set_rx_csum = NULL;
47766- wl18xx_ops.init_vif = NULL;
47767+ pax_open_kernel();
47768+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
47769+ *(void **)&wl18xx_ops.init_vif = NULL;
47770+ pax_close_kernel();
47771 }
47772
47773 /* Enable 11a Band only if we have 5G antennas */
47774diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
47775index a912dc0..a8225ba 100644
47776--- a/drivers/net/wireless/zd1211rw/zd_usb.c
47777+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
47778@@ -385,7 +385,7 @@ static inline void handle_regs_int(struct urb *urb)
47779 {
47780 struct zd_usb *usb = urb->context;
47781 struct zd_usb_interrupt *intr = &usb->intr;
47782- int len;
47783+ unsigned int len;
47784 u16 int_num;
47785
47786 ZD_ASSERT(in_interrupt());
47787diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
47788index 683671a..4519fc2 100644
47789--- a/drivers/nfc/nfcwilink.c
47790+++ b/drivers/nfc/nfcwilink.c
47791@@ -497,7 +497,7 @@ static struct nci_ops nfcwilink_ops = {
47792
47793 static int nfcwilink_probe(struct platform_device *pdev)
47794 {
47795- static struct nfcwilink *drv;
47796+ struct nfcwilink *drv;
47797 int rc;
47798 __u32 protocols;
47799
47800diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
47801index d93b2b6..ae50401 100644
47802--- a/drivers/oprofile/buffer_sync.c
47803+++ b/drivers/oprofile/buffer_sync.c
47804@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
47805 if (cookie == NO_COOKIE)
47806 offset = pc;
47807 if (cookie == INVALID_COOKIE) {
47808- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47809+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47810 offset = pc;
47811 }
47812 if (cookie != last_cookie) {
47813@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
47814 /* add userspace sample */
47815
47816 if (!mm) {
47817- atomic_inc(&oprofile_stats.sample_lost_no_mm);
47818+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
47819 return 0;
47820 }
47821
47822 cookie = lookup_dcookie(mm, s->eip, &offset);
47823
47824 if (cookie == INVALID_COOKIE) {
47825- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47826+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47827 return 0;
47828 }
47829
47830@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
47831 /* ignore backtraces if failed to add a sample */
47832 if (state == sb_bt_start) {
47833 state = sb_bt_ignore;
47834- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
47835+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
47836 }
47837 }
47838 release_mm(mm);
47839diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
47840index c0cc4e7..44d4e54 100644
47841--- a/drivers/oprofile/event_buffer.c
47842+++ b/drivers/oprofile/event_buffer.c
47843@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
47844 }
47845
47846 if (buffer_pos == buffer_size) {
47847- atomic_inc(&oprofile_stats.event_lost_overflow);
47848+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
47849 return;
47850 }
47851
47852diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
47853index ed2c3ec..deda85a 100644
47854--- a/drivers/oprofile/oprof.c
47855+++ b/drivers/oprofile/oprof.c
47856@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
47857 if (oprofile_ops.switch_events())
47858 return;
47859
47860- atomic_inc(&oprofile_stats.multiplex_counter);
47861+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
47862 start_switch_worker();
47863 }
47864
47865diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
47866index ee2cfce..7f8f699 100644
47867--- a/drivers/oprofile/oprofile_files.c
47868+++ b/drivers/oprofile/oprofile_files.c
47869@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
47870
47871 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
47872
47873-static ssize_t timeout_read(struct file *file, char __user *buf,
47874+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
47875 size_t count, loff_t *offset)
47876 {
47877 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
47878diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
47879index 59659ce..6c860a0 100644
47880--- a/drivers/oprofile/oprofile_stats.c
47881+++ b/drivers/oprofile/oprofile_stats.c
47882@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
47883 cpu_buf->sample_invalid_eip = 0;
47884 }
47885
47886- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
47887- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
47888- atomic_set(&oprofile_stats.event_lost_overflow, 0);
47889- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
47890- atomic_set(&oprofile_stats.multiplex_counter, 0);
47891+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
47892+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
47893+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
47894+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
47895+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
47896 }
47897
47898
47899diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
47900index 1fc622b..8c48fc3 100644
47901--- a/drivers/oprofile/oprofile_stats.h
47902+++ b/drivers/oprofile/oprofile_stats.h
47903@@ -13,11 +13,11 @@
47904 #include <linux/atomic.h>
47905
47906 struct oprofile_stat_struct {
47907- atomic_t sample_lost_no_mm;
47908- atomic_t sample_lost_no_mapping;
47909- atomic_t bt_lost_no_mapping;
47910- atomic_t event_lost_overflow;
47911- atomic_t multiplex_counter;
47912+ atomic_unchecked_t sample_lost_no_mm;
47913+ atomic_unchecked_t sample_lost_no_mapping;
47914+ atomic_unchecked_t bt_lost_no_mapping;
47915+ atomic_unchecked_t event_lost_overflow;
47916+ atomic_unchecked_t multiplex_counter;
47917 };
47918
47919 extern struct oprofile_stat_struct oprofile_stats;
47920diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
47921index 3f49345..c750d0b 100644
47922--- a/drivers/oprofile/oprofilefs.c
47923+++ b/drivers/oprofile/oprofilefs.c
47924@@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
47925
47926 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
47927 {
47928- atomic_t *val = file->private_data;
47929- return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
47930+ atomic_unchecked_t *val = file->private_data;
47931+ return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
47932 }
47933
47934
47935@@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
47936
47937
47938 int oprofilefs_create_ro_atomic(struct dentry *root,
47939- char const *name, atomic_t *val)
47940+ char const *name, atomic_unchecked_t *val)
47941 {
47942 return __oprofilefs_create_file(root, name,
47943 &atomic_ro_fops, 0444, val);
47944diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
47945index 61be1d9..dec05d7 100644
47946--- a/drivers/oprofile/timer_int.c
47947+++ b/drivers/oprofile/timer_int.c
47948@@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
47949 return NOTIFY_OK;
47950 }
47951
47952-static struct notifier_block __refdata oprofile_cpu_notifier = {
47953+static struct notifier_block oprofile_cpu_notifier = {
47954 .notifier_call = oprofile_cpu_notify,
47955 };
47956
47957diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
47958index 92ed045..62d39bd7 100644
47959--- a/drivers/parport/procfs.c
47960+++ b/drivers/parport/procfs.c
47961@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
47962
47963 *ppos += len;
47964
47965- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
47966+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
47967 }
47968
47969 #ifdef CONFIG_PARPORT_1284
47970@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
47971
47972 *ppos += len;
47973
47974- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
47975+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
47976 }
47977 #endif /* IEEE1284.3 support. */
47978
47979diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
47980index 8dcccff..35d701d 100644
47981--- a/drivers/pci/hotplug/acpiphp_ibm.c
47982+++ b/drivers/pci/hotplug/acpiphp_ibm.c
47983@@ -452,7 +452,9 @@ static int __init ibm_acpiphp_init(void)
47984 goto init_cleanup;
47985 }
47986
47987- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
47988+ pax_open_kernel();
47989+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
47990+ pax_close_kernel();
47991 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
47992
47993 return retval;
47994diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
47995index 7536eef..52dc8fa 100644
47996--- a/drivers/pci/hotplug/cpcihp_generic.c
47997+++ b/drivers/pci/hotplug/cpcihp_generic.c
47998@@ -73,7 +73,6 @@ static u16 port;
47999 static unsigned int enum_bit;
48000 static u8 enum_mask;
48001
48002-static struct cpci_hp_controller_ops generic_hpc_ops;
48003 static struct cpci_hp_controller generic_hpc;
48004
48005 static int __init validate_parameters(void)
48006@@ -139,6 +138,10 @@ static int query_enum(void)
48007 return ((value & enum_mask) == enum_mask);
48008 }
48009
48010+static struct cpci_hp_controller_ops generic_hpc_ops = {
48011+ .query_enum = query_enum,
48012+};
48013+
48014 static int __init cpcihp_generic_init(void)
48015 {
48016 int status;
48017@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
48018 pci_dev_put(dev);
48019
48020 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
48021- generic_hpc_ops.query_enum = query_enum;
48022 generic_hpc.ops = &generic_hpc_ops;
48023
48024 status = cpci_hp_register_controller(&generic_hpc);
48025diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
48026index e8c4a7c..7046f5c 100644
48027--- a/drivers/pci/hotplug/cpcihp_zt5550.c
48028+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
48029@@ -59,7 +59,6 @@
48030 /* local variables */
48031 static bool debug;
48032 static bool poll;
48033-static struct cpci_hp_controller_ops zt5550_hpc_ops;
48034 static struct cpci_hp_controller zt5550_hpc;
48035
48036 /* Primary cPCI bus bridge device */
48037@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
48038 return 0;
48039 }
48040
48041+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
48042+ .query_enum = zt5550_hc_query_enum,
48043+};
48044+
48045 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
48046 {
48047 int status;
48048@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
48049 dbg("returned from zt5550_hc_config");
48050
48051 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
48052- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
48053 zt5550_hpc.ops = &zt5550_hpc_ops;
48054 if(!poll) {
48055 zt5550_hpc.irq = hc_dev->irq;
48056 zt5550_hpc.irq_flags = IRQF_SHARED;
48057 zt5550_hpc.dev_id = hc_dev;
48058
48059- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
48060- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
48061- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
48062+ pax_open_kernel();
48063+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
48064+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
48065+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
48066+ pax_open_kernel();
48067 } else {
48068 info("using ENUM# polling mode");
48069 }
48070diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
48071index 76ba8a1..20ca857 100644
48072--- a/drivers/pci/hotplug/cpqphp_nvram.c
48073+++ b/drivers/pci/hotplug/cpqphp_nvram.c
48074@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
48075
48076 void compaq_nvram_init (void __iomem *rom_start)
48077 {
48078+
48079+#ifndef CONFIG_PAX_KERNEXEC
48080 if (rom_start) {
48081 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
48082 }
48083+#endif
48084+
48085 dbg("int15 entry = %p\n", compaq_int15_entry_point);
48086
48087 /* initialize our int15 lock */
48088diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
48089index cfa92a9..29539c5 100644
48090--- a/drivers/pci/hotplug/pci_hotplug_core.c
48091+++ b/drivers/pci/hotplug/pci_hotplug_core.c
48092@@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
48093 return -EINVAL;
48094 }
48095
48096- slot->ops->owner = owner;
48097- slot->ops->mod_name = mod_name;
48098+ pax_open_kernel();
48099+ *(struct module **)&slot->ops->owner = owner;
48100+ *(const char **)&slot->ops->mod_name = mod_name;
48101+ pax_close_kernel();
48102
48103 mutex_lock(&pci_hp_mutex);
48104 /*
48105diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
48106index 53b58de..4479896 100644
48107--- a/drivers/pci/hotplug/pciehp_core.c
48108+++ b/drivers/pci/hotplug/pciehp_core.c
48109@@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
48110 struct slot *slot = ctrl->slot;
48111 struct hotplug_slot *hotplug = NULL;
48112 struct hotplug_slot_info *info = NULL;
48113- struct hotplug_slot_ops *ops = NULL;
48114+ hotplug_slot_ops_no_const *ops = NULL;
48115 char name[SLOT_NAME_SIZE];
48116 int retval = -ENOMEM;
48117
48118diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
48119index 955ab79..d1df9c7 100644
48120--- a/drivers/pci/msi.c
48121+++ b/drivers/pci/msi.c
48122@@ -524,8 +524,8 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
48123 {
48124 struct attribute **msi_attrs;
48125 struct attribute *msi_attr;
48126- struct device_attribute *msi_dev_attr;
48127- struct attribute_group *msi_irq_group;
48128+ device_attribute_no_const *msi_dev_attr;
48129+ attribute_group_no_const *msi_irq_group;
48130 const struct attribute_group **msi_irq_groups;
48131 struct msi_desc *entry;
48132 int ret = -ENOMEM;
48133@@ -589,7 +589,7 @@ error_attrs:
48134 count = 0;
48135 msi_attr = msi_attrs[count];
48136 while (msi_attr) {
48137- msi_dev_attr = container_of(msi_attr, struct device_attribute, attr);
48138+ msi_dev_attr = container_of(msi_attr, device_attribute_no_const, attr);
48139 kfree(msi_attr->name);
48140 kfree(msi_dev_attr);
48141 ++count;
48142diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
48143index 276ef9c..1d33a36 100644
48144--- a/drivers/pci/pci-sysfs.c
48145+++ b/drivers/pci/pci-sysfs.c
48146@@ -1112,7 +1112,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
48147 {
48148 /* allocate attribute structure, piggyback attribute name */
48149 int name_len = write_combine ? 13 : 10;
48150- struct bin_attribute *res_attr;
48151+ bin_attribute_no_const *res_attr;
48152 int retval;
48153
48154 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
48155@@ -1297,7 +1297,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
48156 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
48157 {
48158 int retval;
48159- struct bin_attribute *attr;
48160+ bin_attribute_no_const *attr;
48161
48162 /* If the device has VPD, try to expose it in sysfs. */
48163 if (dev->vpd) {
48164@@ -1344,7 +1344,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
48165 {
48166 int retval;
48167 int rom_size = 0;
48168- struct bin_attribute *attr;
48169+ bin_attribute_no_const *attr;
48170
48171 if (!sysfs_initialized)
48172 return -EACCES;
48173diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
48174index 4df38df..b6bb7fe 100644
48175--- a/drivers/pci/pci.h
48176+++ b/drivers/pci/pci.h
48177@@ -93,7 +93,7 @@ struct pci_vpd_ops {
48178 struct pci_vpd {
48179 unsigned int len;
48180 const struct pci_vpd_ops *ops;
48181- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
48182+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
48183 };
48184
48185 int pci_vpd_pci22_init(struct pci_dev *dev);
48186diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
48187index e1e7026..d28dd33 100644
48188--- a/drivers/pci/pcie/aspm.c
48189+++ b/drivers/pci/pcie/aspm.c
48190@@ -27,9 +27,9 @@
48191 #define MODULE_PARAM_PREFIX "pcie_aspm."
48192
48193 /* Note: those are not register definitions */
48194-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
48195-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
48196-#define ASPM_STATE_L1 (4) /* L1 state */
48197+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
48198+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
48199+#define ASPM_STATE_L1 (4U) /* L1 state */
48200 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
48201 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
48202
48203diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
48204index 6e34498..9911975 100644
48205--- a/drivers/pci/probe.c
48206+++ b/drivers/pci/probe.c
48207@@ -175,7 +175,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
48208 struct pci_bus_region region, inverted_region;
48209 bool bar_too_big = false, bar_disabled = false;
48210
48211- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
48212+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
48213
48214 /* No printks while decoding is disabled! */
48215 if (!dev->mmio_always_on) {
48216diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
48217index 46d1378..30e452b 100644
48218--- a/drivers/pci/proc.c
48219+++ b/drivers/pci/proc.c
48220@@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
48221 static int __init pci_proc_init(void)
48222 {
48223 struct pci_dev *dev = NULL;
48224+
48225+#ifdef CONFIG_GRKERNSEC_PROC_ADD
48226+#ifdef CONFIG_GRKERNSEC_PROC_USER
48227+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
48228+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48229+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
48230+#endif
48231+#else
48232 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
48233+#endif
48234 proc_create("devices", 0, proc_bus_pci_dir,
48235 &proc_bus_pci_dev_operations);
48236 proc_initialized = 1;
48237diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
48238index 7f3aad0..7d604bb 100644
48239--- a/drivers/platform/chrome/chromeos_laptop.c
48240+++ b/drivers/platform/chrome/chromeos_laptop.c
48241@@ -406,7 +406,7 @@ static struct chromeos_laptop cr48 = {
48242 .callback = chromeos_laptop_dmi_matched, \
48243 .driver_data = (void *)&board_
48244
48245-static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
48246+static struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
48247 {
48248 .ident = "Samsung Series 5 550",
48249 .matches = {
48250diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
48251index c5e082f..d6307a0 100644
48252--- a/drivers/platform/x86/asus-wmi.c
48253+++ b/drivers/platform/x86/asus-wmi.c
48254@@ -1595,6 +1595,10 @@ static int show_dsts(struct seq_file *m, void *data)
48255 int err;
48256 u32 retval = -1;
48257
48258+#ifdef CONFIG_GRKERNSEC_KMEM
48259+ return -EPERM;
48260+#endif
48261+
48262 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
48263
48264 if (err < 0)
48265@@ -1611,6 +1615,10 @@ static int show_devs(struct seq_file *m, void *data)
48266 int err;
48267 u32 retval = -1;
48268
48269+#ifdef CONFIG_GRKERNSEC_KMEM
48270+ return -EPERM;
48271+#endif
48272+
48273 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
48274 &retval);
48275
48276@@ -1635,6 +1643,10 @@ static int show_call(struct seq_file *m, void *data)
48277 union acpi_object *obj;
48278 acpi_status status;
48279
48280+#ifdef CONFIG_GRKERNSEC_KMEM
48281+ return -EPERM;
48282+#endif
48283+
48284 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
48285 1, asus->debug.method_id,
48286 &input, &output);
48287diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
48288index 62f8030..c7f2a45 100644
48289--- a/drivers/platform/x86/msi-laptop.c
48290+++ b/drivers/platform/x86/msi-laptop.c
48291@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
48292
48293 if (!quirks->ec_read_only) {
48294 /* allow userland write sysfs file */
48295- dev_attr_bluetooth.store = store_bluetooth;
48296- dev_attr_wlan.store = store_wlan;
48297- dev_attr_threeg.store = store_threeg;
48298- dev_attr_bluetooth.attr.mode |= S_IWUSR;
48299- dev_attr_wlan.attr.mode |= S_IWUSR;
48300- dev_attr_threeg.attr.mode |= S_IWUSR;
48301+ pax_open_kernel();
48302+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
48303+ *(void **)&dev_attr_wlan.store = store_wlan;
48304+ *(void **)&dev_attr_threeg.store = store_threeg;
48305+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
48306+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
48307+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
48308+ pax_close_kernel();
48309 }
48310
48311 /* disable hardware control by fn key */
48312diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
48313index 70222f2..8c8ce66 100644
48314--- a/drivers/platform/x86/msi-wmi.c
48315+++ b/drivers/platform/x86/msi-wmi.c
48316@@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
48317 static void msi_wmi_notify(u32 value, void *context)
48318 {
48319 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
48320- static struct key_entry *key;
48321+ struct key_entry *key;
48322 union acpi_object *obj;
48323 acpi_status status;
48324
48325diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
48326index 8f8551a..3ace3ca 100644
48327--- a/drivers/platform/x86/sony-laptop.c
48328+++ b/drivers/platform/x86/sony-laptop.c
48329@@ -2451,7 +2451,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
48330 }
48331
48332 /* High speed charging function */
48333-static struct device_attribute *hsc_handle;
48334+static device_attribute_no_const *hsc_handle;
48335
48336 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
48337 struct device_attribute *attr,
48338diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
48339index defb6af..7a5d3d1 100644
48340--- a/drivers/platform/x86/thinkpad_acpi.c
48341+++ b/drivers/platform/x86/thinkpad_acpi.c
48342@@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
48343 return 0;
48344 }
48345
48346-void static hotkey_mask_warn_incomplete_mask(void)
48347+static void hotkey_mask_warn_incomplete_mask(void)
48348 {
48349 /* log only what the user can fix... */
48350 const u32 wantedmask = hotkey_driver_mask &
48351@@ -2321,11 +2321,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
48352 }
48353 }
48354
48355-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48356- struct tp_nvram_state *newn,
48357- const u32 event_mask)
48358-{
48359-
48360 #define TPACPI_COMPARE_KEY(__scancode, __member) \
48361 do { \
48362 if ((event_mask & (1 << __scancode)) && \
48363@@ -2339,36 +2334,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48364 tpacpi_hotkey_send_key(__scancode); \
48365 } while (0)
48366
48367- void issue_volchange(const unsigned int oldvol,
48368- const unsigned int newvol)
48369- {
48370- unsigned int i = oldvol;
48371+static void issue_volchange(const unsigned int oldvol,
48372+ const unsigned int newvol,
48373+ const u32 event_mask)
48374+{
48375+ unsigned int i = oldvol;
48376
48377- while (i > newvol) {
48378- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
48379- i--;
48380- }
48381- while (i < newvol) {
48382- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
48383- i++;
48384- }
48385+ while (i > newvol) {
48386+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
48387+ i--;
48388 }
48389+ while (i < newvol) {
48390+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
48391+ i++;
48392+ }
48393+}
48394
48395- void issue_brightnesschange(const unsigned int oldbrt,
48396- const unsigned int newbrt)
48397- {
48398- unsigned int i = oldbrt;
48399+static void issue_brightnesschange(const unsigned int oldbrt,
48400+ const unsigned int newbrt,
48401+ const u32 event_mask)
48402+{
48403+ unsigned int i = oldbrt;
48404
48405- while (i > newbrt) {
48406- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
48407- i--;
48408- }
48409- while (i < newbrt) {
48410- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
48411- i++;
48412- }
48413+ while (i > newbrt) {
48414+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
48415+ i--;
48416+ }
48417+ while (i < newbrt) {
48418+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
48419+ i++;
48420 }
48421+}
48422
48423+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48424+ struct tp_nvram_state *newn,
48425+ const u32 event_mask)
48426+{
48427 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
48428 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
48429 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
48430@@ -2402,7 +2403,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48431 oldn->volume_level != newn->volume_level) {
48432 /* recently muted, or repeated mute keypress, or
48433 * multiple presses ending in mute */
48434- issue_volchange(oldn->volume_level, newn->volume_level);
48435+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
48436 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
48437 }
48438 } else {
48439@@ -2412,7 +2413,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48440 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
48441 }
48442 if (oldn->volume_level != newn->volume_level) {
48443- issue_volchange(oldn->volume_level, newn->volume_level);
48444+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
48445 } else if (oldn->volume_toggle != newn->volume_toggle) {
48446 /* repeated vol up/down keypress at end of scale ? */
48447 if (newn->volume_level == 0)
48448@@ -2425,7 +2426,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48449 /* handle brightness */
48450 if (oldn->brightness_level != newn->brightness_level) {
48451 issue_brightnesschange(oldn->brightness_level,
48452- newn->brightness_level);
48453+ newn->brightness_level,
48454+ event_mask);
48455 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
48456 /* repeated key presses that didn't change state */
48457 if (newn->brightness_level == 0)
48458@@ -2434,10 +2436,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48459 && !tp_features.bright_unkfw)
48460 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
48461 }
48462+}
48463
48464 #undef TPACPI_COMPARE_KEY
48465 #undef TPACPI_MAY_SEND_KEY
48466-}
48467
48468 /*
48469 * Polling driver
48470diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
48471index 769d265..a3a05ca 100644
48472--- a/drivers/pnp/pnpbios/bioscalls.c
48473+++ b/drivers/pnp/pnpbios/bioscalls.c
48474@@ -58,7 +58,7 @@ do { \
48475 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
48476 } while(0)
48477
48478-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
48479+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
48480 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
48481
48482 /*
48483@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
48484
48485 cpu = get_cpu();
48486 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
48487+
48488+ pax_open_kernel();
48489 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
48490+ pax_close_kernel();
48491
48492 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
48493 spin_lock_irqsave(&pnp_bios_lock, flags);
48494@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
48495 :"memory");
48496 spin_unlock_irqrestore(&pnp_bios_lock, flags);
48497
48498+ pax_open_kernel();
48499 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
48500+ pax_close_kernel();
48501+
48502 put_cpu();
48503
48504 /* If we get here and this is set then the PnP BIOS faulted on us. */
48505@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
48506 return status;
48507 }
48508
48509-void pnpbios_calls_init(union pnp_bios_install_struct *header)
48510+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
48511 {
48512 int i;
48513
48514@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
48515 pnp_bios_callpoint.offset = header->fields.pm16offset;
48516 pnp_bios_callpoint.segment = PNP_CS16;
48517
48518+ pax_open_kernel();
48519+
48520 for_each_possible_cpu(i) {
48521 struct desc_struct *gdt = get_cpu_gdt_table(i);
48522 if (!gdt)
48523@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
48524 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
48525 (unsigned long)__va(header->fields.pm16dseg));
48526 }
48527+
48528+ pax_close_kernel();
48529 }
48530diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
48531index bacddd1..65ea100 100644
48532--- a/drivers/pnp/resource.c
48533+++ b/drivers/pnp/resource.c
48534@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
48535 return 1;
48536
48537 /* check if the resource is valid */
48538- if (*irq < 0 || *irq > 15)
48539+ if (*irq > 15)
48540 return 0;
48541
48542 /* check if the resource is reserved */
48543@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
48544 return 1;
48545
48546 /* check if the resource is valid */
48547- if (*dma < 0 || *dma == 4 || *dma > 7)
48548+ if (*dma == 4 || *dma > 7)
48549 return 0;
48550
48551 /* check if the resource is reserved */
48552diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
48553index 0c52e2a..3421ab7 100644
48554--- a/drivers/power/pda_power.c
48555+++ b/drivers/power/pda_power.c
48556@@ -37,7 +37,11 @@ static int polling;
48557
48558 #if IS_ENABLED(CONFIG_USB_PHY)
48559 static struct usb_phy *transceiver;
48560-static struct notifier_block otg_nb;
48561+static int otg_handle_notification(struct notifier_block *nb,
48562+ unsigned long event, void *unused);
48563+static struct notifier_block otg_nb = {
48564+ .notifier_call = otg_handle_notification
48565+};
48566 #endif
48567
48568 static struct regulator *ac_draw;
48569@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
48570
48571 #if IS_ENABLED(CONFIG_USB_PHY)
48572 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
48573- otg_nb.notifier_call = otg_handle_notification;
48574 ret = usb_register_notifier(transceiver, &otg_nb);
48575 if (ret) {
48576 dev_err(dev, "failure to register otg notifier\n");
48577diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
48578index cc439fd..8fa30df 100644
48579--- a/drivers/power/power_supply.h
48580+++ b/drivers/power/power_supply.h
48581@@ -16,12 +16,12 @@ struct power_supply;
48582
48583 #ifdef CONFIG_SYSFS
48584
48585-extern void power_supply_init_attrs(struct device_type *dev_type);
48586+extern void power_supply_init_attrs(void);
48587 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
48588
48589 #else
48590
48591-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
48592+static inline void power_supply_init_attrs(void) {}
48593 #define power_supply_uevent NULL
48594
48595 #endif /* CONFIG_SYSFS */
48596diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
48597index 2660664..75fcb04 100644
48598--- a/drivers/power/power_supply_core.c
48599+++ b/drivers/power/power_supply_core.c
48600@@ -28,7 +28,10 @@ EXPORT_SYMBOL_GPL(power_supply_class);
48601 ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
48602 EXPORT_SYMBOL_GPL(power_supply_notifier);
48603
48604-static struct device_type power_supply_dev_type;
48605+extern const struct attribute_group *power_supply_attr_groups[];
48606+static struct device_type power_supply_dev_type = {
48607+ .groups = power_supply_attr_groups,
48608+};
48609
48610 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
48611 struct power_supply *supply)
48612@@ -628,7 +631,7 @@ static int __init power_supply_class_init(void)
48613 return PTR_ERR(power_supply_class);
48614
48615 power_supply_class->dev_uevent = power_supply_uevent;
48616- power_supply_init_attrs(&power_supply_dev_type);
48617+ power_supply_init_attrs();
48618
48619 return 0;
48620 }
48621diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
48622index 44420d1..967126e 100644
48623--- a/drivers/power/power_supply_sysfs.c
48624+++ b/drivers/power/power_supply_sysfs.c
48625@@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
48626 .is_visible = power_supply_attr_is_visible,
48627 };
48628
48629-static const struct attribute_group *power_supply_attr_groups[] = {
48630+const struct attribute_group *power_supply_attr_groups[] = {
48631 &power_supply_attr_group,
48632 NULL,
48633 };
48634
48635-void power_supply_init_attrs(struct device_type *dev_type)
48636+void power_supply_init_attrs(void)
48637 {
48638 int i;
48639
48640- dev_type->groups = power_supply_attr_groups;
48641-
48642 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
48643 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
48644 }
48645diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
48646index 84419af..268ede8 100644
48647--- a/drivers/powercap/powercap_sys.c
48648+++ b/drivers/powercap/powercap_sys.c
48649@@ -154,8 +154,77 @@ struct powercap_constraint_attr {
48650 struct device_attribute name_attr;
48651 };
48652
48653+static ssize_t show_constraint_name(struct device *dev,
48654+ struct device_attribute *dev_attr,
48655+ char *buf);
48656+
48657 static struct powercap_constraint_attr
48658- constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
48659+ constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
48660+ [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
48661+ .power_limit_attr = {
48662+ .attr = {
48663+ .name = NULL,
48664+ .mode = S_IWUSR | S_IRUGO
48665+ },
48666+ .show = show_constraint_power_limit_uw,
48667+ .store = store_constraint_power_limit_uw
48668+ },
48669+
48670+ .time_window_attr = {
48671+ .attr = {
48672+ .name = NULL,
48673+ .mode = S_IWUSR | S_IRUGO
48674+ },
48675+ .show = show_constraint_time_window_us,
48676+ .store = store_constraint_time_window_us
48677+ },
48678+
48679+ .max_power_attr = {
48680+ .attr = {
48681+ .name = NULL,
48682+ .mode = S_IRUGO
48683+ },
48684+ .show = show_constraint_max_power_uw,
48685+ .store = NULL
48686+ },
48687+
48688+ .min_power_attr = {
48689+ .attr = {
48690+ .name = NULL,
48691+ .mode = S_IRUGO
48692+ },
48693+ .show = show_constraint_min_power_uw,
48694+ .store = NULL
48695+ },
48696+
48697+ .max_time_window_attr = {
48698+ .attr = {
48699+ .name = NULL,
48700+ .mode = S_IRUGO
48701+ },
48702+ .show = show_constraint_max_time_window_us,
48703+ .store = NULL
48704+ },
48705+
48706+ .min_time_window_attr = {
48707+ .attr = {
48708+ .name = NULL,
48709+ .mode = S_IRUGO
48710+ },
48711+ .show = show_constraint_min_time_window_us,
48712+ .store = NULL
48713+ },
48714+
48715+ .name_attr = {
48716+ .attr = {
48717+ .name = NULL,
48718+ .mode = S_IRUGO
48719+ },
48720+ .show = show_constraint_name,
48721+ .store = NULL
48722+ }
48723+ }
48724+};
48725
48726 /* A list of powercap control_types */
48727 static LIST_HEAD(powercap_cntrl_list);
48728@@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
48729 }
48730
48731 static int create_constraint_attribute(int id, const char *name,
48732- int mode,
48733- struct device_attribute *dev_attr,
48734- ssize_t (*show)(struct device *,
48735- struct device_attribute *, char *),
48736- ssize_t (*store)(struct device *,
48737- struct device_attribute *,
48738- const char *, size_t)
48739- )
48740+ struct device_attribute *dev_attr)
48741 {
48742+ name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
48743
48744- dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
48745- id, name);
48746- if (!dev_attr->attr.name)
48747+ if (!name)
48748 return -ENOMEM;
48749- dev_attr->attr.mode = mode;
48750- dev_attr->show = show;
48751- dev_attr->store = store;
48752+
48753+ pax_open_kernel();
48754+ *(const char **)&dev_attr->attr.name = name;
48755+ pax_close_kernel();
48756
48757 return 0;
48758 }
48759@@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
48760
48761 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
48762 ret = create_constraint_attribute(i, "power_limit_uw",
48763- S_IWUSR | S_IRUGO,
48764- &constraint_attrs[i].power_limit_attr,
48765- show_constraint_power_limit_uw,
48766- store_constraint_power_limit_uw);
48767+ &constraint_attrs[i].power_limit_attr);
48768 if (ret)
48769 goto err_alloc;
48770 ret = create_constraint_attribute(i, "time_window_us",
48771- S_IWUSR | S_IRUGO,
48772- &constraint_attrs[i].time_window_attr,
48773- show_constraint_time_window_us,
48774- store_constraint_time_window_us);
48775+ &constraint_attrs[i].time_window_attr);
48776 if (ret)
48777 goto err_alloc;
48778- ret = create_constraint_attribute(i, "name", S_IRUGO,
48779- &constraint_attrs[i].name_attr,
48780- show_constraint_name,
48781- NULL);
48782+ ret = create_constraint_attribute(i, "name",
48783+ &constraint_attrs[i].name_attr);
48784 if (ret)
48785 goto err_alloc;
48786- ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
48787- &constraint_attrs[i].max_power_attr,
48788- show_constraint_max_power_uw,
48789- NULL);
48790+ ret = create_constraint_attribute(i, "max_power_uw",
48791+ &constraint_attrs[i].max_power_attr);
48792 if (ret)
48793 goto err_alloc;
48794- ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
48795- &constraint_attrs[i].min_power_attr,
48796- show_constraint_min_power_uw,
48797- NULL);
48798+ ret = create_constraint_attribute(i, "min_power_uw",
48799+ &constraint_attrs[i].min_power_attr);
48800 if (ret)
48801 goto err_alloc;
48802 ret = create_constraint_attribute(i, "max_time_window_us",
48803- S_IRUGO,
48804- &constraint_attrs[i].max_time_window_attr,
48805- show_constraint_max_time_window_us,
48806- NULL);
48807+ &constraint_attrs[i].max_time_window_attr);
48808 if (ret)
48809 goto err_alloc;
48810 ret = create_constraint_attribute(i, "min_time_window_us",
48811- S_IRUGO,
48812- &constraint_attrs[i].min_time_window_attr,
48813- show_constraint_min_time_window_us,
48814- NULL);
48815+ &constraint_attrs[i].min_time_window_attr);
48816 if (ret)
48817 goto err_alloc;
48818
48819@@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
48820 power_zone->zone_dev_attrs[count++] =
48821 &dev_attr_max_energy_range_uj.attr;
48822 if (power_zone->ops->get_energy_uj) {
48823+ pax_open_kernel();
48824 if (power_zone->ops->reset_energy_uj)
48825- dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48826+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48827 else
48828- dev_attr_energy_uj.attr.mode = S_IRUGO;
48829+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
48830+ pax_close_kernel();
48831 power_zone->zone_dev_attrs[count++] =
48832 &dev_attr_energy_uj.attr;
48833 }
48834diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
48835index afca1bc..86840b8 100644
48836--- a/drivers/regulator/core.c
48837+++ b/drivers/regulator/core.c
48838@@ -3366,7 +3366,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48839 {
48840 const struct regulation_constraints *constraints = NULL;
48841 const struct regulator_init_data *init_data;
48842- static atomic_t regulator_no = ATOMIC_INIT(0);
48843+ static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
48844 struct regulator_dev *rdev;
48845 struct device *dev;
48846 int ret, i;
48847@@ -3436,7 +3436,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48848 rdev->dev.of_node = config->of_node;
48849 rdev->dev.parent = dev;
48850 dev_set_name(&rdev->dev, "regulator.%d",
48851- atomic_inc_return(&regulator_no) - 1);
48852+ atomic_inc_return_unchecked(&regulator_no) - 1);
48853 ret = device_register(&rdev->dev);
48854 if (ret != 0) {
48855 put_device(&rdev->dev);
48856diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
48857index 8d94d3d..653b623 100644
48858--- a/drivers/regulator/max8660.c
48859+++ b/drivers/regulator/max8660.c
48860@@ -420,8 +420,10 @@ static int max8660_probe(struct i2c_client *client,
48861 max8660->shadow_regs[MAX8660_OVER1] = 5;
48862 } else {
48863 /* Otherwise devices can be toggled via software */
48864- max8660_dcdc_ops.enable = max8660_dcdc_enable;
48865- max8660_dcdc_ops.disable = max8660_dcdc_disable;
48866+ pax_open_kernel();
48867+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
48868+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
48869+ pax_close_kernel();
48870 }
48871
48872 /*
48873diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
48874index 892aa1e..ebd1b9c 100644
48875--- a/drivers/regulator/max8973-regulator.c
48876+++ b/drivers/regulator/max8973-regulator.c
48877@@ -406,9 +406,11 @@ static int max8973_probe(struct i2c_client *client,
48878 if (!pdata || !pdata->enable_ext_control) {
48879 max->desc.enable_reg = MAX8973_VOUT;
48880 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
48881- max->ops.enable = regulator_enable_regmap;
48882- max->ops.disable = regulator_disable_regmap;
48883- max->ops.is_enabled = regulator_is_enabled_regmap;
48884+ pax_open_kernel();
48885+ *(void **)&max->ops.enable = regulator_enable_regmap;
48886+ *(void **)&max->ops.disable = regulator_disable_regmap;
48887+ *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
48888+ pax_close_kernel();
48889 }
48890
48891 if (pdata) {
48892diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
48893index f374fa5..26f0683 100644
48894--- a/drivers/regulator/mc13892-regulator.c
48895+++ b/drivers/regulator/mc13892-regulator.c
48896@@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
48897 }
48898 mc13xxx_unlock(mc13892);
48899
48900- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48901+ pax_open_kernel();
48902+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48903 = mc13892_vcam_set_mode;
48904- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48905+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48906 = mc13892_vcam_get_mode;
48907+ pax_close_kernel();
48908
48909 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
48910 ARRAY_SIZE(mc13892_regulators));
48911diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
48912index cae212f..58a3980 100644
48913--- a/drivers/rtc/rtc-cmos.c
48914+++ b/drivers/rtc/rtc-cmos.c
48915@@ -777,7 +777,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
48916 hpet_rtc_timer_init();
48917
48918 /* export at least the first block of NVRAM */
48919- nvram.size = address_space - NVRAM_OFFSET;
48920+ pax_open_kernel();
48921+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
48922+ pax_close_kernel();
48923 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
48924 if (retval < 0) {
48925 dev_dbg(dev, "can't create nvram file? %d\n", retval);
48926diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
48927index d049393..bb20be0 100644
48928--- a/drivers/rtc/rtc-dev.c
48929+++ b/drivers/rtc/rtc-dev.c
48930@@ -16,6 +16,7 @@
48931 #include <linux/module.h>
48932 #include <linux/rtc.h>
48933 #include <linux/sched.h>
48934+#include <linux/grsecurity.h>
48935 #include "rtc-core.h"
48936
48937 static dev_t rtc_devt;
48938@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
48939 if (copy_from_user(&tm, uarg, sizeof(tm)))
48940 return -EFAULT;
48941
48942+ gr_log_timechange();
48943+
48944 return rtc_set_time(rtc, &tm);
48945
48946 case RTC_PIE_ON:
48947diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
48948index 4e75345..09f8663 100644
48949--- a/drivers/rtc/rtc-ds1307.c
48950+++ b/drivers/rtc/rtc-ds1307.c
48951@@ -107,7 +107,7 @@ struct ds1307 {
48952 u8 offset; /* register's offset */
48953 u8 regs[11];
48954 u16 nvram_offset;
48955- struct bin_attribute *nvram;
48956+ bin_attribute_no_const *nvram;
48957 enum ds_type type;
48958 unsigned long flags;
48959 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
48960diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
48961index 11880c1..b823aa4 100644
48962--- a/drivers/rtc/rtc-m48t59.c
48963+++ b/drivers/rtc/rtc-m48t59.c
48964@@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
48965 if (IS_ERR(m48t59->rtc))
48966 return PTR_ERR(m48t59->rtc);
48967
48968- m48t59_nvram_attr.size = pdata->offset;
48969+ pax_open_kernel();
48970+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
48971+ pax_close_kernel();
48972
48973 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
48974 if (ret)
48975diff --git a/drivers/scsi/aic7xxx/aic79xx_pci.c b/drivers/scsi/aic7xxx/aic79xx_pci.c
48976index 14b5f8d..cc9bd26 100644
48977--- a/drivers/scsi/aic7xxx/aic79xx_pci.c
48978+++ b/drivers/scsi/aic7xxx/aic79xx_pci.c
48979@@ -827,7 +827,7 @@ ahd_pci_intr(struct ahd_softc *ahd)
48980 for (bit = 0; bit < 8; bit++) {
48981
48982 if ((pci_status[i] & (0x1 << bit)) != 0) {
48983- static const char *s;
48984+ const char *s;
48985
48986 s = pci_status_strings[bit];
48987 if (i == 7/*TARG*/ && bit == 3)
48988@@ -887,23 +887,15 @@ ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat)
48989
48990 for (bit = 0; bit < 8; bit++) {
48991
48992- if ((split_status[i] & (0x1 << bit)) != 0) {
48993- static const char *s;
48994-
48995- s = split_status_strings[bit];
48996- printk(s, ahd_name(ahd),
48997+ if ((split_status[i] & (0x1 << bit)) != 0)
48998+ printk(split_status_strings[bit], ahd_name(ahd),
48999 split_status_source[i]);
49000- }
49001
49002 if (i > 1)
49003 continue;
49004
49005- if ((sg_split_status[i] & (0x1 << bit)) != 0) {
49006- static const char *s;
49007-
49008- s = split_status_strings[bit];
49009- printk(s, ahd_name(ahd), "SG");
49010- }
49011+ if ((sg_split_status[i] & (0x1 << bit)) != 0)
49012+ printk(split_status_strings[bit], ahd_name(ahd), "SG");
49013 }
49014 }
49015 /*
49016diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
49017index e693af6..2e525b6 100644
49018--- a/drivers/scsi/bfa/bfa_fcpim.h
49019+++ b/drivers/scsi/bfa/bfa_fcpim.h
49020@@ -36,7 +36,7 @@ struct bfa_iotag_s {
49021
49022 struct bfa_itn_s {
49023 bfa_isr_func_t isr;
49024-};
49025+} __no_const;
49026
49027 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
49028 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
49029diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
49030index a3ab5cc..8143622 100644
49031--- a/drivers/scsi/bfa/bfa_fcs.c
49032+++ b/drivers/scsi/bfa/bfa_fcs.c
49033@@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
49034 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
49035
49036 static struct bfa_fcs_mod_s fcs_modules[] = {
49037- { bfa_fcs_port_attach, NULL, NULL },
49038- { bfa_fcs_uf_attach, NULL, NULL },
49039- { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
49040- bfa_fcs_fabric_modexit },
49041+ {
49042+ .attach = bfa_fcs_port_attach,
49043+ .modinit = NULL,
49044+ .modexit = NULL
49045+ },
49046+ {
49047+ .attach = bfa_fcs_uf_attach,
49048+ .modinit = NULL,
49049+ .modexit = NULL
49050+ },
49051+ {
49052+ .attach = bfa_fcs_fabric_attach,
49053+ .modinit = bfa_fcs_fabric_modinit,
49054+ .modexit = bfa_fcs_fabric_modexit
49055+ },
49056 };
49057
49058 /*
49059diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
49060index ff75ef8..2dfe00a 100644
49061--- a/drivers/scsi/bfa/bfa_fcs_lport.c
49062+++ b/drivers/scsi/bfa/bfa_fcs_lport.c
49063@@ -89,15 +89,26 @@ static struct {
49064 void (*offline) (struct bfa_fcs_lport_s *port);
49065 } __port_action[] = {
49066 {
49067- bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
49068- bfa_fcs_lport_unknown_offline}, {
49069- bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
49070- bfa_fcs_lport_fab_offline}, {
49071- bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
49072- bfa_fcs_lport_n2n_offline}, {
49073- bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
49074- bfa_fcs_lport_loop_offline},
49075- };
49076+ .init = bfa_fcs_lport_unknown_init,
49077+ .online = bfa_fcs_lport_unknown_online,
49078+ .offline = bfa_fcs_lport_unknown_offline
49079+ },
49080+ {
49081+ .init = bfa_fcs_lport_fab_init,
49082+ .online = bfa_fcs_lport_fab_online,
49083+ .offline = bfa_fcs_lport_fab_offline
49084+ },
49085+ {
49086+ .init = bfa_fcs_lport_n2n_init,
49087+ .online = bfa_fcs_lport_n2n_online,
49088+ .offline = bfa_fcs_lport_n2n_offline
49089+ },
49090+ {
49091+ .init = bfa_fcs_lport_loop_init,
49092+ .online = bfa_fcs_lport_loop_online,
49093+ .offline = bfa_fcs_lport_loop_offline
49094+ },
49095+};
49096
49097 /*
49098 * fcs_port_sm FCS logical port state machine
49099diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
49100index 2e28392..9d865b6 100644
49101--- a/drivers/scsi/bfa/bfa_ioc.h
49102+++ b/drivers/scsi/bfa/bfa_ioc.h
49103@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
49104 bfa_ioc_disable_cbfn_t disable_cbfn;
49105 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
49106 bfa_ioc_reset_cbfn_t reset_cbfn;
49107-};
49108+} __no_const;
49109
49110 /*
49111 * IOC event notification mechanism.
49112@@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
49113 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
49114 enum bfi_ioc_state fwstate);
49115 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
49116-};
49117+} __no_const;
49118
49119 /*
49120 * Queue element to wait for room in request queue. FIFO order is
49121diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
49122index a14c784..6de6790 100644
49123--- a/drivers/scsi/bfa/bfa_modules.h
49124+++ b/drivers/scsi/bfa/bfa_modules.h
49125@@ -78,12 +78,12 @@ enum {
49126 \
49127 extern struct bfa_module_s hal_mod_ ## __mod; \
49128 struct bfa_module_s hal_mod_ ## __mod = { \
49129- bfa_ ## __mod ## _meminfo, \
49130- bfa_ ## __mod ## _attach, \
49131- bfa_ ## __mod ## _detach, \
49132- bfa_ ## __mod ## _start, \
49133- bfa_ ## __mod ## _stop, \
49134- bfa_ ## __mod ## _iocdisable, \
49135+ .meminfo = bfa_ ## __mod ## _meminfo, \
49136+ .attach = bfa_ ## __mod ## _attach, \
49137+ .detach = bfa_ ## __mod ## _detach, \
49138+ .start = bfa_ ## __mod ## _start, \
49139+ .stop = bfa_ ## __mod ## _stop, \
49140+ .iocdisable = bfa_ ## __mod ## _iocdisable, \
49141 }
49142
49143 #define BFA_CACHELINE_SZ (256)
49144diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
49145index 045c4e1..13de803 100644
49146--- a/drivers/scsi/fcoe/fcoe_sysfs.c
49147+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
49148@@ -33,8 +33,8 @@
49149 */
49150 #include "libfcoe.h"
49151
49152-static atomic_t ctlr_num;
49153-static atomic_t fcf_num;
49154+static atomic_unchecked_t ctlr_num;
49155+static atomic_unchecked_t fcf_num;
49156
49157 /*
49158 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
49159@@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
49160 if (!ctlr)
49161 goto out;
49162
49163- ctlr->id = atomic_inc_return(&ctlr_num) - 1;
49164+ ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
49165 ctlr->f = f;
49166 ctlr->mode = FIP_CONN_TYPE_FABRIC;
49167 INIT_LIST_HEAD(&ctlr->fcfs);
49168@@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
49169 fcf->dev.parent = &ctlr->dev;
49170 fcf->dev.bus = &fcoe_bus_type;
49171 fcf->dev.type = &fcoe_fcf_device_type;
49172- fcf->id = atomic_inc_return(&fcf_num) - 1;
49173+ fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
49174 fcf->state = FCOE_FCF_STATE_UNKNOWN;
49175
49176 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
49177@@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
49178 {
49179 int error;
49180
49181- atomic_set(&ctlr_num, 0);
49182- atomic_set(&fcf_num, 0);
49183+ atomic_set_unchecked(&ctlr_num, 0);
49184+ atomic_set_unchecked(&fcf_num, 0);
49185
49186 error = bus_register(&fcoe_bus_type);
49187 if (error)
49188diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
49189index f28ea07..34b16d3 100644
49190--- a/drivers/scsi/hosts.c
49191+++ b/drivers/scsi/hosts.c
49192@@ -42,7 +42,7 @@
49193 #include "scsi_logging.h"
49194
49195
49196-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
49197+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
49198
49199
49200 static void scsi_host_cls_release(struct device *dev)
49201@@ -369,7 +369,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
49202 * subtract one because we increment first then return, but we need to
49203 * know what the next host number was before increment
49204 */
49205- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
49206+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
49207 shost->dma_channel = 0xff;
49208
49209 /* These three are default values which can be overridden */
49210diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
49211index 868318a..e07ef3b 100644
49212--- a/drivers/scsi/hpsa.c
49213+++ b/drivers/scsi/hpsa.c
49214@@ -571,7 +571,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
49215 unsigned long flags;
49216
49217 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
49218- return h->access.command_completed(h, q);
49219+ return h->access->command_completed(h, q);
49220
49221 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
49222 a = rq->head[rq->current_entry];
49223@@ -3474,7 +3474,7 @@ static void start_io(struct ctlr_info *h)
49224 while (!list_empty(&h->reqQ)) {
49225 c = list_entry(h->reqQ.next, struct CommandList, list);
49226 /* can't do anything if fifo is full */
49227- if ((h->access.fifo_full(h))) {
49228+ if ((h->access->fifo_full(h))) {
49229 h->fifo_recently_full = 1;
49230 dev_warn(&h->pdev->dev, "fifo full\n");
49231 break;
49232@@ -3498,7 +3498,7 @@ static void start_io(struct ctlr_info *h)
49233
49234 /* Tell the controller execute command */
49235 spin_unlock_irqrestore(&h->lock, flags);
49236- h->access.submit_command(h, c);
49237+ h->access->submit_command(h, c);
49238 spin_lock_irqsave(&h->lock, flags);
49239 }
49240 spin_unlock_irqrestore(&h->lock, flags);
49241@@ -3506,17 +3506,17 @@ static void start_io(struct ctlr_info *h)
49242
49243 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
49244 {
49245- return h->access.command_completed(h, q);
49246+ return h->access->command_completed(h, q);
49247 }
49248
49249 static inline bool interrupt_pending(struct ctlr_info *h)
49250 {
49251- return h->access.intr_pending(h);
49252+ return h->access->intr_pending(h);
49253 }
49254
49255 static inline long interrupt_not_for_us(struct ctlr_info *h)
49256 {
49257- return (h->access.intr_pending(h) == 0) ||
49258+ return (h->access->intr_pending(h) == 0) ||
49259 (h->interrupts_enabled == 0);
49260 }
49261
49262@@ -4442,7 +4442,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
49263 if (prod_index < 0)
49264 return -ENODEV;
49265 h->product_name = products[prod_index].product_name;
49266- h->access = *(products[prod_index].access);
49267+ h->access = products[prod_index].access;
49268
49269 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
49270 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
49271@@ -4712,7 +4712,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
49272 {
49273 unsigned long flags;
49274
49275- h->access.set_intr_mask(h, HPSA_INTR_OFF);
49276+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
49277 spin_lock_irqsave(&h->lock, flags);
49278 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
49279 spin_unlock_irqrestore(&h->lock, flags);
49280@@ -4843,7 +4843,7 @@ reinit_after_soft_reset:
49281 }
49282
49283 /* make sure the board interrupts are off */
49284- h->access.set_intr_mask(h, HPSA_INTR_OFF);
49285+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
49286
49287 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
49288 goto clean2;
49289@@ -4877,7 +4877,7 @@ reinit_after_soft_reset:
49290 * fake ones to scoop up any residual completions.
49291 */
49292 spin_lock_irqsave(&h->lock, flags);
49293- h->access.set_intr_mask(h, HPSA_INTR_OFF);
49294+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
49295 spin_unlock_irqrestore(&h->lock, flags);
49296 free_irqs(h);
49297 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
49298@@ -4896,9 +4896,9 @@ reinit_after_soft_reset:
49299 dev_info(&h->pdev->dev, "Board READY.\n");
49300 dev_info(&h->pdev->dev,
49301 "Waiting for stale completions to drain.\n");
49302- h->access.set_intr_mask(h, HPSA_INTR_ON);
49303+ h->access->set_intr_mask(h, HPSA_INTR_ON);
49304 msleep(10000);
49305- h->access.set_intr_mask(h, HPSA_INTR_OFF);
49306+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
49307
49308 rc = controller_reset_failed(h->cfgtable);
49309 if (rc)
49310@@ -4919,7 +4919,7 @@ reinit_after_soft_reset:
49311 }
49312
49313 /* Turn the interrupts on so we can service requests */
49314- h->access.set_intr_mask(h, HPSA_INTR_ON);
49315+ h->access->set_intr_mask(h, HPSA_INTR_ON);
49316
49317 hpsa_hba_inquiry(h);
49318 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
49319@@ -4988,7 +4988,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
49320 * To write all data in the battery backed cache to disks
49321 */
49322 hpsa_flush_cache(h);
49323- h->access.set_intr_mask(h, HPSA_INTR_OFF);
49324+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
49325 hpsa_free_irqs_and_disable_msix(h);
49326 }
49327
49328@@ -5162,7 +5162,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
49329 return;
49330 }
49331 /* Change the access methods to the performant access methods */
49332- h->access = SA5_performant_access;
49333+ h->access = &SA5_performant_access;
49334 h->transMethod = CFGTBL_Trans_Performant;
49335 }
49336
49337diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
49338index 01c3283..4655219 100644
49339--- a/drivers/scsi/hpsa.h
49340+++ b/drivers/scsi/hpsa.h
49341@@ -79,7 +79,7 @@ struct ctlr_info {
49342 unsigned int msix_vector;
49343 unsigned int msi_vector;
49344 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
49345- struct access_method access;
49346+ struct access_method *access;
49347
49348 /* queue and queue Info */
49349 struct list_head reqQ;
49350@@ -388,19 +388,19 @@ static bool SA5_performant_intr_pending(struct ctlr_info *h)
49351 }
49352
49353 static struct access_method SA5_access = {
49354- SA5_submit_command,
49355- SA5_intr_mask,
49356- SA5_fifo_full,
49357- SA5_intr_pending,
49358- SA5_completed,
49359+ .submit_command = SA5_submit_command,
49360+ .set_intr_mask = SA5_intr_mask,
49361+ .fifo_full = SA5_fifo_full,
49362+ .intr_pending = SA5_intr_pending,
49363+ .command_completed = SA5_completed,
49364 };
49365
49366 static struct access_method SA5_performant_access = {
49367- SA5_submit_command,
49368- SA5_performant_intr_mask,
49369- SA5_fifo_full,
49370- SA5_performant_intr_pending,
49371- SA5_performant_completed,
49372+ .submit_command = SA5_submit_command,
49373+ .set_intr_mask = SA5_performant_intr_mask,
49374+ .fifo_full = SA5_fifo_full,
49375+ .intr_pending = SA5_performant_intr_pending,
49376+ .command_completed = SA5_performant_completed,
49377 };
49378
49379 struct board_type {
49380diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
49381index 1b3a094..068e683 100644
49382--- a/drivers/scsi/libfc/fc_exch.c
49383+++ b/drivers/scsi/libfc/fc_exch.c
49384@@ -101,12 +101,12 @@ struct fc_exch_mgr {
49385 u16 pool_max_index;
49386
49387 struct {
49388- atomic_t no_free_exch;
49389- atomic_t no_free_exch_xid;
49390- atomic_t xid_not_found;
49391- atomic_t xid_busy;
49392- atomic_t seq_not_found;
49393- atomic_t non_bls_resp;
49394+ atomic_unchecked_t no_free_exch;
49395+ atomic_unchecked_t no_free_exch_xid;
49396+ atomic_unchecked_t xid_not_found;
49397+ atomic_unchecked_t xid_busy;
49398+ atomic_unchecked_t seq_not_found;
49399+ atomic_unchecked_t non_bls_resp;
49400 } stats;
49401 };
49402
49403@@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
49404 /* allocate memory for exchange */
49405 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
49406 if (!ep) {
49407- atomic_inc(&mp->stats.no_free_exch);
49408+ atomic_inc_unchecked(&mp->stats.no_free_exch);
49409 goto out;
49410 }
49411 memset(ep, 0, sizeof(*ep));
49412@@ -874,7 +874,7 @@ out:
49413 return ep;
49414 err:
49415 spin_unlock_bh(&pool->lock);
49416- atomic_inc(&mp->stats.no_free_exch_xid);
49417+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
49418 mempool_free(ep, mp->ep_pool);
49419 return NULL;
49420 }
49421@@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49422 xid = ntohs(fh->fh_ox_id); /* we originated exch */
49423 ep = fc_exch_find(mp, xid);
49424 if (!ep) {
49425- atomic_inc(&mp->stats.xid_not_found);
49426+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49427 reject = FC_RJT_OX_ID;
49428 goto out;
49429 }
49430@@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49431 ep = fc_exch_find(mp, xid);
49432 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
49433 if (ep) {
49434- atomic_inc(&mp->stats.xid_busy);
49435+ atomic_inc_unchecked(&mp->stats.xid_busy);
49436 reject = FC_RJT_RX_ID;
49437 goto rel;
49438 }
49439@@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49440 }
49441 xid = ep->xid; /* get our XID */
49442 } else if (!ep) {
49443- atomic_inc(&mp->stats.xid_not_found);
49444+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49445 reject = FC_RJT_RX_ID; /* XID not found */
49446 goto out;
49447 }
49448@@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49449 } else {
49450 sp = &ep->seq;
49451 if (sp->id != fh->fh_seq_id) {
49452- atomic_inc(&mp->stats.seq_not_found);
49453+ atomic_inc_unchecked(&mp->stats.seq_not_found);
49454 if (f_ctl & FC_FC_END_SEQ) {
49455 /*
49456 * Update sequence_id based on incoming last
49457@@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49458
49459 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
49460 if (!ep) {
49461- atomic_inc(&mp->stats.xid_not_found);
49462+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49463 goto out;
49464 }
49465 if (ep->esb_stat & ESB_ST_COMPLETE) {
49466- atomic_inc(&mp->stats.xid_not_found);
49467+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49468 goto rel;
49469 }
49470 if (ep->rxid == FC_XID_UNKNOWN)
49471 ep->rxid = ntohs(fh->fh_rx_id);
49472 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
49473- atomic_inc(&mp->stats.xid_not_found);
49474+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49475 goto rel;
49476 }
49477 if (ep->did != ntoh24(fh->fh_s_id) &&
49478 ep->did != FC_FID_FLOGI) {
49479- atomic_inc(&mp->stats.xid_not_found);
49480+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49481 goto rel;
49482 }
49483 sof = fr_sof(fp);
49484@@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49485 sp->ssb_stat |= SSB_ST_RESP;
49486 sp->id = fh->fh_seq_id;
49487 } else if (sp->id != fh->fh_seq_id) {
49488- atomic_inc(&mp->stats.seq_not_found);
49489+ atomic_inc_unchecked(&mp->stats.seq_not_found);
49490 goto rel;
49491 }
49492
49493@@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49494 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
49495
49496 if (!sp)
49497- atomic_inc(&mp->stats.xid_not_found);
49498+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49499 else
49500- atomic_inc(&mp->stats.non_bls_resp);
49501+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
49502
49503 fc_frame_free(fp);
49504 }
49505@@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
49506
49507 list_for_each_entry(ema, &lport->ema_list, ema_list) {
49508 mp = ema->mp;
49509- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
49510+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
49511 st->fc_no_free_exch_xid +=
49512- atomic_read(&mp->stats.no_free_exch_xid);
49513- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
49514- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
49515- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
49516- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
49517+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
49518+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
49519+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
49520+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
49521+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
49522 }
49523 }
49524 EXPORT_SYMBOL(fc_exch_update_stats);
49525diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
49526index d289583..b745eec 100644
49527--- a/drivers/scsi/libsas/sas_ata.c
49528+++ b/drivers/scsi/libsas/sas_ata.c
49529@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
49530 .postreset = ata_std_postreset,
49531 .error_handler = ata_std_error_handler,
49532 .post_internal_cmd = sas_ata_post_internal,
49533- .qc_defer = ata_std_qc_defer,
49534+ .qc_defer = ata_std_qc_defer,
49535 .qc_prep = ata_noop_qc_prep,
49536 .qc_issue = sas_ata_qc_issue,
49537 .qc_fill_rtf = sas_ata_qc_fill_rtf,
49538diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
49539index 4e1b75c..0bbdfa9 100644
49540--- a/drivers/scsi/lpfc/lpfc.h
49541+++ b/drivers/scsi/lpfc/lpfc.h
49542@@ -432,7 +432,7 @@ struct lpfc_vport {
49543 struct dentry *debug_nodelist;
49544 struct dentry *vport_debugfs_root;
49545 struct lpfc_debugfs_trc *disc_trc;
49546- atomic_t disc_trc_cnt;
49547+ atomic_unchecked_t disc_trc_cnt;
49548 #endif
49549 uint8_t stat_data_enabled;
49550 uint8_t stat_data_blocked;
49551@@ -865,8 +865,8 @@ struct lpfc_hba {
49552 struct timer_list fabric_block_timer;
49553 unsigned long bit_flags;
49554 #define FABRIC_COMANDS_BLOCKED 0
49555- atomic_t num_rsrc_err;
49556- atomic_t num_cmd_success;
49557+ atomic_unchecked_t num_rsrc_err;
49558+ atomic_unchecked_t num_cmd_success;
49559 unsigned long last_rsrc_error_time;
49560 unsigned long last_ramp_down_time;
49561 unsigned long last_ramp_up_time;
49562@@ -902,7 +902,7 @@ struct lpfc_hba {
49563
49564 struct dentry *debug_slow_ring_trc;
49565 struct lpfc_debugfs_trc *slow_ring_trc;
49566- atomic_t slow_ring_trc_cnt;
49567+ atomic_unchecked_t slow_ring_trc_cnt;
49568 /* iDiag debugfs sub-directory */
49569 struct dentry *idiag_root;
49570 struct dentry *idiag_pci_cfg;
49571diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
49572index b800cc9..16b6a91 100644
49573--- a/drivers/scsi/lpfc/lpfc_debugfs.c
49574+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
49575@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
49576
49577 #include <linux/debugfs.h>
49578
49579-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
49580+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
49581 static unsigned long lpfc_debugfs_start_time = 0L;
49582
49583 /* iDiag */
49584@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
49585 lpfc_debugfs_enable = 0;
49586
49587 len = 0;
49588- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
49589+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
49590 (lpfc_debugfs_max_disc_trc - 1);
49591 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
49592 dtp = vport->disc_trc + i;
49593@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
49594 lpfc_debugfs_enable = 0;
49595
49596 len = 0;
49597- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
49598+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
49599 (lpfc_debugfs_max_slow_ring_trc - 1);
49600 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
49601 dtp = phba->slow_ring_trc + i;
49602@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
49603 !vport || !vport->disc_trc)
49604 return;
49605
49606- index = atomic_inc_return(&vport->disc_trc_cnt) &
49607+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
49608 (lpfc_debugfs_max_disc_trc - 1);
49609 dtp = vport->disc_trc + index;
49610 dtp->fmt = fmt;
49611 dtp->data1 = data1;
49612 dtp->data2 = data2;
49613 dtp->data3 = data3;
49614- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
49615+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
49616 dtp->jif = jiffies;
49617 #endif
49618 return;
49619@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
49620 !phba || !phba->slow_ring_trc)
49621 return;
49622
49623- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
49624+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
49625 (lpfc_debugfs_max_slow_ring_trc - 1);
49626 dtp = phba->slow_ring_trc + index;
49627 dtp->fmt = fmt;
49628 dtp->data1 = data1;
49629 dtp->data2 = data2;
49630 dtp->data3 = data3;
49631- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
49632+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
49633 dtp->jif = jiffies;
49634 #endif
49635 return;
49636@@ -4168,7 +4168,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49637 "slow_ring buffer\n");
49638 goto debug_failed;
49639 }
49640- atomic_set(&phba->slow_ring_trc_cnt, 0);
49641+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
49642 memset(phba->slow_ring_trc, 0,
49643 (sizeof(struct lpfc_debugfs_trc) *
49644 lpfc_debugfs_max_slow_ring_trc));
49645@@ -4214,7 +4214,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49646 "buffer\n");
49647 goto debug_failed;
49648 }
49649- atomic_set(&vport->disc_trc_cnt, 0);
49650+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
49651
49652 snprintf(name, sizeof(name), "discovery_trace");
49653 vport->debug_disc_trc =
49654diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
49655index 68c94cc..8c27be5 100644
49656--- a/drivers/scsi/lpfc/lpfc_init.c
49657+++ b/drivers/scsi/lpfc/lpfc_init.c
49658@@ -10949,8 +10949,10 @@ lpfc_init(void)
49659 "misc_register returned with status %d", error);
49660
49661 if (lpfc_enable_npiv) {
49662- lpfc_transport_functions.vport_create = lpfc_vport_create;
49663- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49664+ pax_open_kernel();
49665+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
49666+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49667+ pax_close_kernel();
49668 }
49669 lpfc_transport_template =
49670 fc_attach_transport(&lpfc_transport_functions);
49671diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
49672index b2ede05..aaf482ca 100644
49673--- a/drivers/scsi/lpfc/lpfc_scsi.c
49674+++ b/drivers/scsi/lpfc/lpfc_scsi.c
49675@@ -353,7 +353,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
49676 uint32_t evt_posted;
49677
49678 spin_lock_irqsave(&phba->hbalock, flags);
49679- atomic_inc(&phba->num_rsrc_err);
49680+ atomic_inc_unchecked(&phba->num_rsrc_err);
49681 phba->last_rsrc_error_time = jiffies;
49682
49683 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
49684@@ -394,7 +394,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
49685 unsigned long flags;
49686 struct lpfc_hba *phba = vport->phba;
49687 uint32_t evt_posted;
49688- atomic_inc(&phba->num_cmd_success);
49689+ atomic_inc_unchecked(&phba->num_cmd_success);
49690
49691 if (vport->cfg_lun_queue_depth <= queue_depth)
49692 return;
49693@@ -438,8 +438,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49694 unsigned long num_rsrc_err, num_cmd_success;
49695 int i;
49696
49697- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
49698- num_cmd_success = atomic_read(&phba->num_cmd_success);
49699+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
49700+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
49701
49702 /*
49703 * The error and success command counters are global per
49704@@ -467,8 +467,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49705 }
49706 }
49707 lpfc_destroy_vport_work_array(phba, vports);
49708- atomic_set(&phba->num_rsrc_err, 0);
49709- atomic_set(&phba->num_cmd_success, 0);
49710+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
49711+ atomic_set_unchecked(&phba->num_cmd_success, 0);
49712 }
49713
49714 /**
49715@@ -502,8 +502,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
49716 }
49717 }
49718 lpfc_destroy_vport_work_array(phba, vports);
49719- atomic_set(&phba->num_rsrc_err, 0);
49720- atomic_set(&phba->num_cmd_success, 0);
49721+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
49722+ atomic_set_unchecked(&phba->num_cmd_success, 0);
49723 }
49724
49725 /**
49726diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49727index 7f0af4f..193ac3e 100644
49728--- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49729+++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49730@@ -1557,7 +1557,7 @@ _scsih_get_resync(struct device *dev)
49731 {
49732 struct scsi_device *sdev = to_scsi_device(dev);
49733 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49734- static struct _raid_device *raid_device;
49735+ struct _raid_device *raid_device;
49736 unsigned long flags;
49737 Mpi2RaidVolPage0_t vol_pg0;
49738 Mpi2ConfigReply_t mpi_reply;
49739@@ -1609,7 +1609,7 @@ _scsih_get_state(struct device *dev)
49740 {
49741 struct scsi_device *sdev = to_scsi_device(dev);
49742 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49743- static struct _raid_device *raid_device;
49744+ struct _raid_device *raid_device;
49745 unsigned long flags;
49746 Mpi2RaidVolPage0_t vol_pg0;
49747 Mpi2ConfigReply_t mpi_reply;
49748@@ -6637,7 +6637,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
49749 struct fw_event_work *fw_event)
49750 {
49751 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
49752- static struct _raid_device *raid_device;
49753+ struct _raid_device *raid_device;
49754 unsigned long flags;
49755 u16 handle;
49756
49757@@ -7108,7 +7108,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
49758 u64 sas_address;
49759 struct _sas_device *sas_device;
49760 struct _sas_node *expander_device;
49761- static struct _raid_device *raid_device;
49762+ struct _raid_device *raid_device;
49763 u8 retry_count;
49764 unsigned long flags;
49765
49766diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
49767index be8ce54..94ed33a 100644
49768--- a/drivers/scsi/pmcraid.c
49769+++ b/drivers/scsi/pmcraid.c
49770@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
49771 res->scsi_dev = scsi_dev;
49772 scsi_dev->hostdata = res;
49773 res->change_detected = 0;
49774- atomic_set(&res->read_failures, 0);
49775- atomic_set(&res->write_failures, 0);
49776+ atomic_set_unchecked(&res->read_failures, 0);
49777+ atomic_set_unchecked(&res->write_failures, 0);
49778 rc = 0;
49779 }
49780 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
49781@@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
49782
49783 /* If this was a SCSI read/write command keep count of errors */
49784 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
49785- atomic_inc(&res->read_failures);
49786+ atomic_inc_unchecked(&res->read_failures);
49787 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
49788- atomic_inc(&res->write_failures);
49789+ atomic_inc_unchecked(&res->write_failures);
49790
49791 if (!RES_IS_GSCSI(res->cfg_entry) &&
49792 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
49793@@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
49794 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49795 * hrrq_id assigned here in queuecommand
49796 */
49797- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49798+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49799 pinstance->num_hrrq;
49800 cmd->cmd_done = pmcraid_io_done;
49801
49802@@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
49803 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49804 * hrrq_id assigned here in queuecommand
49805 */
49806- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49807+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49808 pinstance->num_hrrq;
49809
49810 if (request_size) {
49811@@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
49812
49813 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
49814 /* add resources only after host is added into system */
49815- if (!atomic_read(&pinstance->expose_resources))
49816+ if (!atomic_read_unchecked(&pinstance->expose_resources))
49817 return;
49818
49819 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
49820@@ -5322,8 +5322,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
49821 init_waitqueue_head(&pinstance->reset_wait_q);
49822
49823 atomic_set(&pinstance->outstanding_cmds, 0);
49824- atomic_set(&pinstance->last_message_id, 0);
49825- atomic_set(&pinstance->expose_resources, 0);
49826+ atomic_set_unchecked(&pinstance->last_message_id, 0);
49827+ atomic_set_unchecked(&pinstance->expose_resources, 0);
49828
49829 INIT_LIST_HEAD(&pinstance->free_res_q);
49830 INIT_LIST_HEAD(&pinstance->used_res_q);
49831@@ -6036,7 +6036,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
49832 /* Schedule worker thread to handle CCN and take care of adding and
49833 * removing devices to OS
49834 */
49835- atomic_set(&pinstance->expose_resources, 1);
49836+ atomic_set_unchecked(&pinstance->expose_resources, 1);
49837 schedule_work(&pinstance->worker_q);
49838 return rc;
49839
49840diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
49841index e1d150f..6c6df44 100644
49842--- a/drivers/scsi/pmcraid.h
49843+++ b/drivers/scsi/pmcraid.h
49844@@ -748,7 +748,7 @@ struct pmcraid_instance {
49845 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
49846
49847 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
49848- atomic_t last_message_id;
49849+ atomic_unchecked_t last_message_id;
49850
49851 /* configuration table */
49852 struct pmcraid_config_table *cfg_table;
49853@@ -777,7 +777,7 @@ struct pmcraid_instance {
49854 atomic_t outstanding_cmds;
49855
49856 /* should add/delete resources to mid-layer now ?*/
49857- atomic_t expose_resources;
49858+ atomic_unchecked_t expose_resources;
49859
49860
49861
49862@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
49863 struct pmcraid_config_table_entry_ext cfg_entry_ext;
49864 };
49865 struct scsi_device *scsi_dev; /* Link scsi_device structure */
49866- atomic_t read_failures; /* count of failed READ commands */
49867- atomic_t write_failures; /* count of failed WRITE commands */
49868+ atomic_unchecked_t read_failures; /* count of failed READ commands */
49869+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
49870
49871 /* To indicate add/delete/modify during CCN */
49872 u8 change_detected;
49873diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
49874index 4a0d7c9..3d658d7 100644
49875--- a/drivers/scsi/qla2xxx/qla_attr.c
49876+++ b/drivers/scsi/qla2xxx/qla_attr.c
49877@@ -2038,7 +2038,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
49878 return 0;
49879 }
49880
49881-struct fc_function_template qla2xxx_transport_functions = {
49882+fc_function_template_no_const qla2xxx_transport_functions = {
49883
49884 .show_host_node_name = 1,
49885 .show_host_port_name = 1,
49886@@ -2086,7 +2086,7 @@ struct fc_function_template qla2xxx_transport_functions = {
49887 .bsg_timeout = qla24xx_bsg_timeout,
49888 };
49889
49890-struct fc_function_template qla2xxx_transport_vport_functions = {
49891+fc_function_template_no_const qla2xxx_transport_vport_functions = {
49892
49893 .show_host_node_name = 1,
49894 .show_host_port_name = 1,
49895diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
49896index 1f42662..bf9836c 100644
49897--- a/drivers/scsi/qla2xxx/qla_gbl.h
49898+++ b/drivers/scsi/qla2xxx/qla_gbl.h
49899@@ -546,8 +546,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
49900 struct device_attribute;
49901 extern struct device_attribute *qla2x00_host_attrs[];
49902 struct fc_function_template;
49903-extern struct fc_function_template qla2xxx_transport_functions;
49904-extern struct fc_function_template qla2xxx_transport_vport_functions;
49905+extern fc_function_template_no_const qla2xxx_transport_functions;
49906+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
49907 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
49908 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *, bool);
49909 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
49910diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
49911index 83cb612..9b7b08c 100644
49912--- a/drivers/scsi/qla2xxx/qla_os.c
49913+++ b/drivers/scsi/qla2xxx/qla_os.c
49914@@ -1491,8 +1491,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
49915 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
49916 /* Ok, a 64bit DMA mask is applicable. */
49917 ha->flags.enable_64bit_addressing = 1;
49918- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49919- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49920+ pax_open_kernel();
49921+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49922+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49923+ pax_close_kernel();
49924 return;
49925 }
49926 }
49927diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
49928index aa67bb9..06d0e2a 100644
49929--- a/drivers/scsi/qla4xxx/ql4_def.h
49930+++ b/drivers/scsi/qla4xxx/ql4_def.h
49931@@ -303,7 +303,7 @@ struct ddb_entry {
49932 * (4000 only) */
49933 atomic_t relogin_timer; /* Max Time to wait for
49934 * relogin to complete */
49935- atomic_t relogin_retry_count; /* Num of times relogin has been
49936+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
49937 * retried */
49938 uint32_t default_time2wait; /* Default Min time between
49939 * relogins (+aens) */
49940diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
49941index c21adc3..1b4155f 100644
49942--- a/drivers/scsi/qla4xxx/ql4_os.c
49943+++ b/drivers/scsi/qla4xxx/ql4_os.c
49944@@ -4463,12 +4463,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
49945 */
49946 if (!iscsi_is_session_online(cls_sess)) {
49947 /* Reset retry relogin timer */
49948- atomic_inc(&ddb_entry->relogin_retry_count);
49949+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
49950 DEBUG2(ql4_printk(KERN_INFO, ha,
49951 "%s: index[%d] relogin timed out-retrying"
49952 " relogin (%d), retry (%d)\n", __func__,
49953 ddb_entry->fw_ddb_index,
49954- atomic_read(&ddb_entry->relogin_retry_count),
49955+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
49956 ddb_entry->default_time2wait + 4));
49957 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
49958 atomic_set(&ddb_entry->retry_relogin_timer,
49959@@ -6552,7 +6552,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
49960
49961 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
49962 atomic_set(&ddb_entry->relogin_timer, 0);
49963- atomic_set(&ddb_entry->relogin_retry_count, 0);
49964+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
49965 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
49966 ddb_entry->default_relogin_timeout =
49967 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
49968diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
49969index d8afec8..3ec7152 100644
49970--- a/drivers/scsi/scsi.c
49971+++ b/drivers/scsi/scsi.c
49972@@ -658,7 +658,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
49973 struct Scsi_Host *host = cmd->device->host;
49974 int rtn = 0;
49975
49976- atomic_inc(&cmd->device->iorequest_cnt);
49977+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
49978
49979 /* check if the device is still usable */
49980 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
49981diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
49982index 62ec84b..93159d8 100644
49983--- a/drivers/scsi/scsi_lib.c
49984+++ b/drivers/scsi/scsi_lib.c
49985@@ -1474,7 +1474,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
49986 shost = sdev->host;
49987 scsi_init_cmd_errh(cmd);
49988 cmd->result = DID_NO_CONNECT << 16;
49989- atomic_inc(&cmd->device->iorequest_cnt);
49990+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
49991
49992 /*
49993 * SCSI request completion path will do scsi_device_unbusy(),
49994@@ -1500,9 +1500,9 @@ static void scsi_softirq_done(struct request *rq)
49995
49996 INIT_LIST_HEAD(&cmd->eh_entry);
49997
49998- atomic_inc(&cmd->device->iodone_cnt);
49999+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
50000 if (cmd->result)
50001- atomic_inc(&cmd->device->ioerr_cnt);
50002+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
50003
50004 disposition = scsi_decide_disposition(cmd);
50005 if (disposition != SUCCESS &&
50006diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
50007index 9117d0b..d289a7a 100644
50008--- a/drivers/scsi/scsi_sysfs.c
50009+++ b/drivers/scsi/scsi_sysfs.c
50010@@ -739,7 +739,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
50011 char *buf) \
50012 { \
50013 struct scsi_device *sdev = to_scsi_device(dev); \
50014- unsigned long long count = atomic_read(&sdev->field); \
50015+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
50016 return snprintf(buf, 20, "0x%llx\n", count); \
50017 } \
50018 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
50019diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
50020index 84a1fdf..693b0d6 100644
50021--- a/drivers/scsi/scsi_tgt_lib.c
50022+++ b/drivers/scsi/scsi_tgt_lib.c
50023@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
50024 int err;
50025
50026 dprintk("%lx %u\n", uaddr, len);
50027- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
50028+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
50029 if (err) {
50030 /*
50031 * TODO: need to fixup sg_tablesize, max_segment_size,
50032diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
50033index 4628fd5..a94a1c2 100644
50034--- a/drivers/scsi/scsi_transport_fc.c
50035+++ b/drivers/scsi/scsi_transport_fc.c
50036@@ -497,7 +497,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
50037 * Netlink Infrastructure
50038 */
50039
50040-static atomic_t fc_event_seq;
50041+static atomic_unchecked_t fc_event_seq;
50042
50043 /**
50044 * fc_get_event_number - Obtain the next sequential FC event number
50045@@ -510,7 +510,7 @@ static atomic_t fc_event_seq;
50046 u32
50047 fc_get_event_number(void)
50048 {
50049- return atomic_add_return(1, &fc_event_seq);
50050+ return atomic_add_return_unchecked(1, &fc_event_seq);
50051 }
50052 EXPORT_SYMBOL(fc_get_event_number);
50053
50054@@ -654,7 +654,7 @@ static __init int fc_transport_init(void)
50055 {
50056 int error;
50057
50058- atomic_set(&fc_event_seq, 0);
50059+ atomic_set_unchecked(&fc_event_seq, 0);
50060
50061 error = transport_class_register(&fc_host_class);
50062 if (error)
50063@@ -844,7 +844,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
50064 char *cp;
50065
50066 *val = simple_strtoul(buf, &cp, 0);
50067- if ((*cp && (*cp != '\n')) || (*val < 0))
50068+ if (*cp && (*cp != '\n'))
50069 return -EINVAL;
50070 /*
50071 * Check for overflow; dev_loss_tmo is u32
50072diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
50073index fd8ffe6..fd0bebf 100644
50074--- a/drivers/scsi/scsi_transport_iscsi.c
50075+++ b/drivers/scsi/scsi_transport_iscsi.c
50076@@ -79,7 +79,7 @@ struct iscsi_internal {
50077 struct transport_container session_cont;
50078 };
50079
50080-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
50081+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
50082 static struct workqueue_struct *iscsi_eh_timer_workq;
50083
50084 static DEFINE_IDA(iscsi_sess_ida);
50085@@ -2071,7 +2071,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
50086 int err;
50087
50088 ihost = shost->shost_data;
50089- session->sid = atomic_add_return(1, &iscsi_session_nr);
50090+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
50091
50092 if (target_id == ISCSI_MAX_TARGET) {
50093 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
50094@@ -4511,7 +4511,7 @@ static __init int iscsi_transport_init(void)
50095 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
50096 ISCSI_TRANSPORT_VERSION);
50097
50098- atomic_set(&iscsi_session_nr, 0);
50099+ atomic_set_unchecked(&iscsi_session_nr, 0);
50100
50101 err = class_register(&iscsi_transport_class);
50102 if (err)
50103diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
50104index d47ffc8..30f46a9 100644
50105--- a/drivers/scsi/scsi_transport_srp.c
50106+++ b/drivers/scsi/scsi_transport_srp.c
50107@@ -36,7 +36,7 @@
50108 #include "scsi_transport_srp_internal.h"
50109
50110 struct srp_host_attrs {
50111- atomic_t next_port_id;
50112+ atomic_unchecked_t next_port_id;
50113 };
50114 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
50115
50116@@ -101,7 +101,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
50117 struct Scsi_Host *shost = dev_to_shost(dev);
50118 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
50119
50120- atomic_set(&srp_host->next_port_id, 0);
50121+ atomic_set_unchecked(&srp_host->next_port_id, 0);
50122 return 0;
50123 }
50124
50125@@ -734,7 +734,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
50126 rport_fast_io_fail_timedout);
50127 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
50128
50129- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
50130+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
50131 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
50132
50133 transport_setup_device(&rport->dev);
50134diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
50135index 36d1a23..3f33303 100644
50136--- a/drivers/scsi/sd.c
50137+++ b/drivers/scsi/sd.c
50138@@ -2962,7 +2962,7 @@ static int sd_probe(struct device *dev)
50139 sdkp->disk = gd;
50140 sdkp->index = index;
50141 atomic_set(&sdkp->openers, 0);
50142- atomic_set(&sdkp->device->ioerr_cnt, 0);
50143+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
50144
50145 if (!sdp->request_queue->rq_timeout) {
50146 if (sdp->type != TYPE_MOD)
50147diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
50148index df5e961..df6b97f 100644
50149--- a/drivers/scsi/sg.c
50150+++ b/drivers/scsi/sg.c
50151@@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
50152 sdp->disk->disk_name,
50153 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
50154 NULL,
50155- (char *)arg);
50156+ (char __user *)arg);
50157 case BLKTRACESTART:
50158 return blk_trace_startstop(sdp->device->request_queue, 1);
50159 case BLKTRACESTOP:
50160diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
50161index d0b28bb..a263613 100644
50162--- a/drivers/spi/spi.c
50163+++ b/drivers/spi/spi.c
50164@@ -1971,7 +1971,7 @@ int spi_bus_unlock(struct spi_master *master)
50165 EXPORT_SYMBOL_GPL(spi_bus_unlock);
50166
50167 /* portable code must never pass more than 32 bytes */
50168-#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
50169+#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
50170
50171 static u8 *buf;
50172
50173diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
50174index 2c61783..4d49e4e 100644
50175--- a/drivers/staging/android/timed_output.c
50176+++ b/drivers/staging/android/timed_output.c
50177@@ -25,7 +25,7 @@
50178 #include "timed_output.h"
50179
50180 static struct class *timed_output_class;
50181-static atomic_t device_count;
50182+static atomic_unchecked_t device_count;
50183
50184 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
50185 char *buf)
50186@@ -63,7 +63,7 @@ static int create_timed_output_class(void)
50187 timed_output_class = class_create(THIS_MODULE, "timed_output");
50188 if (IS_ERR(timed_output_class))
50189 return PTR_ERR(timed_output_class);
50190- atomic_set(&device_count, 0);
50191+ atomic_set_unchecked(&device_count, 0);
50192 timed_output_class->dev_groups = timed_output_groups;
50193 }
50194
50195@@ -81,7 +81,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
50196 if (ret < 0)
50197 return ret;
50198
50199- tdev->index = atomic_inc_return(&device_count);
50200+ tdev->index = atomic_inc_return_unchecked(&device_count);
50201 tdev->dev = device_create(timed_output_class, NULL,
50202 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
50203 if (IS_ERR(tdev->dev))
50204diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
50205index fe47cd3..19a1bd1 100644
50206--- a/drivers/staging/gdm724x/gdm_tty.c
50207+++ b/drivers/staging/gdm724x/gdm_tty.c
50208@@ -44,7 +44,7 @@
50209 #define gdm_tty_send_control(n, r, v, d, l) (\
50210 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
50211
50212-#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
50213+#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
50214
50215 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
50216 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
50217diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
50218index 236ed66..dd9cd74 100644
50219--- a/drivers/staging/imx-drm/imx-drm-core.c
50220+++ b/drivers/staging/imx-drm/imx-drm-core.c
50221@@ -488,7 +488,7 @@ int imx_drm_add_crtc(struct drm_crtc *crtc,
50222 goto err_busy;
50223 }
50224
50225- if (imxdrm->drm->open_count) {
50226+ if (local_read(&imxdrm->drm->open_count)) {
50227 ret = -EBUSY;
50228 goto err_busy;
50229 }
50230@@ -576,7 +576,7 @@ int imx_drm_add_encoder(struct drm_encoder *encoder,
50231
50232 mutex_lock(&imxdrm->mutex);
50233
50234- if (imxdrm->drm->open_count) {
50235+ if (local_read(&imxdrm->drm->open_count)) {
50236 ret = -EBUSY;
50237 goto err_busy;
50238 }
50239@@ -715,7 +715,7 @@ int imx_drm_add_connector(struct drm_connector *connector,
50240
50241 mutex_lock(&imxdrm->mutex);
50242
50243- if (imxdrm->drm->open_count) {
50244+ if (local_read(&imxdrm->drm->open_count)) {
50245 ret = -EBUSY;
50246 goto err_busy;
50247 }
50248diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
50249index 3f8020c..649fded 100644
50250--- a/drivers/staging/lustre/lnet/selftest/brw_test.c
50251+++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
50252@@ -488,13 +488,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
50253 return 0;
50254 }
50255
50256-sfw_test_client_ops_t brw_test_client;
50257-void brw_init_test_client(void)
50258-{
50259- brw_test_client.tso_init = brw_client_init;
50260- brw_test_client.tso_fini = brw_client_fini;
50261- brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
50262- brw_test_client.tso_done_rpc = brw_client_done_rpc;
50263+sfw_test_client_ops_t brw_test_client = {
50264+ .tso_init = brw_client_init,
50265+ .tso_fini = brw_client_fini,
50266+ .tso_prep_rpc = brw_client_prep_rpc,
50267+ .tso_done_rpc = brw_client_done_rpc,
50268 };
50269
50270 srpc_service_t brw_test_service;
50271diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
50272index 050723a..fa6fdf1 100644
50273--- a/drivers/staging/lustre/lnet/selftest/framework.c
50274+++ b/drivers/staging/lustre/lnet/selftest/framework.c
50275@@ -1635,12 +1635,10 @@ static srpc_service_t sfw_services[] =
50276
50277 extern sfw_test_client_ops_t ping_test_client;
50278 extern srpc_service_t ping_test_service;
50279-extern void ping_init_test_client(void);
50280 extern void ping_init_test_service(void);
50281
50282 extern sfw_test_client_ops_t brw_test_client;
50283 extern srpc_service_t brw_test_service;
50284-extern void brw_init_test_client(void);
50285 extern void brw_init_test_service(void);
50286
50287
50288@@ -1684,12 +1682,10 @@ sfw_startup (void)
50289 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
50290 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
50291
50292- brw_init_test_client();
50293 brw_init_test_service();
50294 rc = sfw_register_test(&brw_test_service, &brw_test_client);
50295 LASSERT (rc == 0);
50296
50297- ping_init_test_client();
50298 ping_init_test_service();
50299 rc = sfw_register_test(&ping_test_service, &ping_test_client);
50300 LASSERT (rc == 0);
50301diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
50302index 750cac4..e4d751f 100644
50303--- a/drivers/staging/lustre/lnet/selftest/ping_test.c
50304+++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
50305@@ -211,14 +211,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
50306 return 0;
50307 }
50308
50309-sfw_test_client_ops_t ping_test_client;
50310-void ping_init_test_client(void)
50311-{
50312- ping_test_client.tso_init = ping_client_init;
50313- ping_test_client.tso_fini = ping_client_fini;
50314- ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
50315- ping_test_client.tso_done_rpc = ping_client_done_rpc;
50316-}
50317+sfw_test_client_ops_t ping_test_client = {
50318+ .tso_init = ping_client_init,
50319+ .tso_fini = ping_client_fini,
50320+ .tso_prep_rpc = ping_client_prep_rpc,
50321+ .tso_done_rpc = ping_client_done_rpc,
50322+};
50323
50324 srpc_service_t ping_test_service;
50325 void ping_init_test_service(void)
50326diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
50327index ec4bb5e..740c6dd 100644
50328--- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
50329+++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
50330@@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
50331 ldlm_completion_callback lcs_completion;
50332 ldlm_blocking_callback lcs_blocking;
50333 ldlm_glimpse_callback lcs_glimpse;
50334-};
50335+} __no_const;
50336
50337 /* ldlm_lockd.c */
50338 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
50339diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
50340index c3470ce..2bef527 100644
50341--- a/drivers/staging/lustre/lustre/include/obd.h
50342+++ b/drivers/staging/lustre/lustre/include/obd.h
50343@@ -1426,7 +1426,7 @@ struct md_ops {
50344 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
50345 * wrapper function in include/linux/obd_class.h.
50346 */
50347-};
50348+} __no_const;
50349
50350 struct lsm_operations {
50351 void (*lsm_free)(struct lov_stripe_md *);
50352diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
50353index c9aae13..60ea292 100644
50354--- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
50355+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
50356@@ -239,7 +239,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
50357 int added = (mode == LCK_NL);
50358 int overlaps = 0;
50359 int splitted = 0;
50360- const struct ldlm_callback_suite null_cbs = { NULL };
50361+ const struct ldlm_callback_suite null_cbs = { };
50362
50363 CDEBUG(D_DLMTRACE, "flags %#llx owner "LPU64" pid %u mode %u start "
50364 LPU64" end "LPU64"\n", *flags,
50365diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
50366index e947b91..f408990 100644
50367--- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
50368+++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
50369@@ -217,7 +217,7 @@ DECLARE_PROC_HANDLER(proc_debug_mb)
50370 int LL_PROC_PROTO(proc_console_max_delay_cs)
50371 {
50372 int rc, max_delay_cs;
50373- ctl_table_t dummy = *table;
50374+ ctl_table_no_const dummy = *table;
50375 cfs_duration_t d;
50376
50377 dummy.data = &max_delay_cs;
50378@@ -248,7 +248,7 @@ int LL_PROC_PROTO(proc_console_max_delay_cs)
50379 int LL_PROC_PROTO(proc_console_min_delay_cs)
50380 {
50381 int rc, min_delay_cs;
50382- ctl_table_t dummy = *table;
50383+ ctl_table_no_const dummy = *table;
50384 cfs_duration_t d;
50385
50386 dummy.data = &min_delay_cs;
50387@@ -279,7 +279,7 @@ int LL_PROC_PROTO(proc_console_min_delay_cs)
50388 int LL_PROC_PROTO(proc_console_backoff)
50389 {
50390 int rc, backoff;
50391- ctl_table_t dummy = *table;
50392+ ctl_table_no_const dummy = *table;
50393
50394 dummy.data = &backoff;
50395 dummy.proc_handler = &proc_dointvec;
50396diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
50397index 24ae26d..9d09cab 100644
50398--- a/drivers/staging/lustre/lustre/libcfs/module.c
50399+++ b/drivers/staging/lustre/lustre/libcfs/module.c
50400@@ -313,11 +313,11 @@ out:
50401
50402
50403 struct cfs_psdev_ops libcfs_psdev_ops = {
50404- libcfs_psdev_open,
50405- libcfs_psdev_release,
50406- NULL,
50407- NULL,
50408- libcfs_ioctl
50409+ .p_open = libcfs_psdev_open,
50410+ .p_close = libcfs_psdev_release,
50411+ .p_read = NULL,
50412+ .p_write = NULL,
50413+ .p_ioctl = libcfs_ioctl
50414 };
50415
50416 extern int insert_proc(void);
50417diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
50418index 52b7731..d604da0 100644
50419--- a/drivers/staging/lustre/lustre/llite/dir.c
50420+++ b/drivers/staging/lustre/lustre/llite/dir.c
50421@@ -660,7 +660,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
50422 int mode;
50423 int err;
50424
50425- mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
50426+ mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
50427 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
50428 strlen(filename), mode, LUSTRE_OPC_MKDIR,
50429 lump);
50430diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
50431index 480b7c4..6846324 100644
50432--- a/drivers/staging/media/solo6x10/solo6x10-core.c
50433+++ b/drivers/staging/media/solo6x10/solo6x10-core.c
50434@@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
50435
50436 static int solo_sysfs_init(struct solo_dev *solo_dev)
50437 {
50438- struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
50439+ bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
50440 struct device *dev = &solo_dev->dev;
50441 const char *driver;
50442 int i;
50443diff --git a/drivers/staging/media/solo6x10/solo6x10-g723.c b/drivers/staging/media/solo6x10/solo6x10-g723.c
50444index 1db18c7..35e6afc 100644
50445--- a/drivers/staging/media/solo6x10/solo6x10-g723.c
50446+++ b/drivers/staging/media/solo6x10/solo6x10-g723.c
50447@@ -355,7 +355,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
50448
50449 int solo_g723_init(struct solo_dev *solo_dev)
50450 {
50451- static struct snd_device_ops ops = { NULL };
50452+ static struct snd_device_ops ops = { };
50453 struct snd_card *card;
50454 struct snd_kcontrol_new kctl;
50455 char name[32];
50456diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
50457index 7f2f247..d999137 100644
50458--- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
50459+++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
50460@@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
50461
50462 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
50463 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
50464- p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
50465+ p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
50466 if (p2m_id < 0)
50467 p2m_id = -p2m_id;
50468 }
50469diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
50470index 8964f8b..36eb087 100644
50471--- a/drivers/staging/media/solo6x10/solo6x10.h
50472+++ b/drivers/staging/media/solo6x10/solo6x10.h
50473@@ -237,7 +237,7 @@ struct solo_dev {
50474
50475 /* P2M DMA Engine */
50476 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
50477- atomic_t p2m_count;
50478+ atomic_unchecked_t p2m_count;
50479 int p2m_jiffies;
50480 unsigned int p2m_timeouts;
50481
50482diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
50483index a0f4868..139f1fb 100644
50484--- a/drivers/staging/octeon/ethernet-rx.c
50485+++ b/drivers/staging/octeon/ethernet-rx.c
50486@@ -417,11 +417,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
50487 /* Increment RX stats for virtual ports */
50488 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
50489 #ifdef CONFIG_64BIT
50490- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
50491- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
50492+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
50493+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
50494 #else
50495- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
50496- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
50497+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
50498+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
50499 #endif
50500 }
50501 netif_receive_skb(skb);
50502@@ -432,9 +432,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
50503 dev->name);
50504 */
50505 #ifdef CONFIG_64BIT
50506- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
50507+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
50508 #else
50509- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
50510+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
50511 #endif
50512 dev_kfree_skb_irq(skb);
50513 }
50514diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
50515index 089dc4b..c9a687e 100644
50516--- a/drivers/staging/octeon/ethernet.c
50517+++ b/drivers/staging/octeon/ethernet.c
50518@@ -253,11 +253,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
50519 * since the RX tasklet also increments it.
50520 */
50521 #ifdef CONFIG_64BIT
50522- atomic64_add(rx_status.dropped_packets,
50523- (atomic64_t *)&priv->stats.rx_dropped);
50524+ atomic64_add_unchecked(rx_status.dropped_packets,
50525+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
50526 #else
50527- atomic_add(rx_status.dropped_packets,
50528- (atomic_t *)&priv->stats.rx_dropped);
50529+ atomic_add_unchecked(rx_status.dropped_packets,
50530+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
50531 #endif
50532 }
50533
50534diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
50535index c274b34..f84de76 100644
50536--- a/drivers/staging/rtl8188eu/include/hal_intf.h
50537+++ b/drivers/staging/rtl8188eu/include/hal_intf.h
50538@@ -271,7 +271,7 @@ struct hal_ops {
50539 s32 (*c2h_handler)(struct adapter *padapter,
50540 struct c2h_evt_hdr *c2h_evt);
50541 c2h_id_filter c2h_id_filter_ccx;
50542-};
50543+} __no_const;
50544
50545 enum rt_eeprom_type {
50546 EEPROM_93C46,
50547diff --git a/drivers/staging/rtl8188eu/include/rtw_io.h b/drivers/staging/rtl8188eu/include/rtw_io.h
50548index 3d1dfcc..ff5620a 100644
50549--- a/drivers/staging/rtl8188eu/include/rtw_io.h
50550+++ b/drivers/staging/rtl8188eu/include/rtw_io.h
50551@@ -126,7 +126,7 @@ struct _io_ops {
50552 u32 (*_write_scsi)(struct intf_hdl *pintfhdl, u32 cnt, u8 *pmem);
50553 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
50554 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
50555-};
50556+} __no_const;
50557
50558 struct io_req {
50559 struct list_head list;
50560diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
50561index dc23395..cf7e9b1 100644
50562--- a/drivers/staging/rtl8712/rtl871x_io.h
50563+++ b/drivers/staging/rtl8712/rtl871x_io.h
50564@@ -108,7 +108,7 @@ struct _io_ops {
50565 u8 *pmem);
50566 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
50567 u8 *pmem);
50568-};
50569+} __no_const;
50570
50571 struct io_req {
50572 struct list_head list;
50573diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
50574index 1f5088b..0e59820 100644
50575--- a/drivers/staging/sbe-2t3e3/netdev.c
50576+++ b/drivers/staging/sbe-2t3e3/netdev.c
50577@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
50578 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
50579
50580 if (rlen)
50581- if (copy_to_user(data, &resp, rlen))
50582+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
50583 return -EFAULT;
50584
50585 return 0;
50586diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
50587index a863a98..d272795 100644
50588--- a/drivers/staging/usbip/vhci.h
50589+++ b/drivers/staging/usbip/vhci.h
50590@@ -83,7 +83,7 @@ struct vhci_hcd {
50591 unsigned resuming:1;
50592 unsigned long re_timeout;
50593
50594- atomic_t seqnum;
50595+ atomic_unchecked_t seqnum;
50596
50597 /*
50598 * NOTE:
50599diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
50600index 72391ef..7c6717a 100644
50601--- a/drivers/staging/usbip/vhci_hcd.c
50602+++ b/drivers/staging/usbip/vhci_hcd.c
50603@@ -440,7 +440,7 @@ static void vhci_tx_urb(struct urb *urb)
50604
50605 spin_lock(&vdev->priv_lock);
50606
50607- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
50608+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
50609 if (priv->seqnum == 0xffff)
50610 dev_info(&urb->dev->dev, "seqnum max\n");
50611
50612@@ -686,7 +686,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
50613 return -ENOMEM;
50614 }
50615
50616- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
50617+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
50618 if (unlink->seqnum == 0xffff)
50619 pr_info("seqnum max\n");
50620
50621@@ -890,7 +890,7 @@ static int vhci_start(struct usb_hcd *hcd)
50622 vdev->rhport = rhport;
50623 }
50624
50625- atomic_set(&vhci->seqnum, 0);
50626+ atomic_set_unchecked(&vhci->seqnum, 0);
50627 spin_lock_init(&vhci->lock);
50628
50629 hcd->power_budget = 0; /* no limit */
50630diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
50631index d07fcb5..358e1e1 100644
50632--- a/drivers/staging/usbip/vhci_rx.c
50633+++ b/drivers/staging/usbip/vhci_rx.c
50634@@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
50635 if (!urb) {
50636 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
50637 pr_info("max seqnum %d\n",
50638- atomic_read(&the_controller->seqnum));
50639+ atomic_read_unchecked(&the_controller->seqnum));
50640 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
50641 return;
50642 }
50643diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
50644index 6eecd53..29317c6 100644
50645--- a/drivers/staging/vt6655/hostap.c
50646+++ b/drivers/staging/vt6655/hostap.c
50647@@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
50648 *
50649 */
50650
50651+static net_device_ops_no_const apdev_netdev_ops;
50652+
50653 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50654 {
50655 PSDevice apdev_priv;
50656 struct net_device *dev = pDevice->dev;
50657 int ret;
50658- const struct net_device_ops apdev_netdev_ops = {
50659- .ndo_start_xmit = pDevice->tx_80211,
50660- };
50661
50662 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50663
50664@@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50665 *apdev_priv = *pDevice;
50666 eth_hw_addr_inherit(pDevice->apdev, dev);
50667
50668+ /* only half broken now */
50669+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50670 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50671
50672 pDevice->apdev->type = ARPHRD_IEEE80211;
50673diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
50674index 67ba48b..24e602f 100644
50675--- a/drivers/staging/vt6656/hostap.c
50676+++ b/drivers/staging/vt6656/hostap.c
50677@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
50678 *
50679 */
50680
50681+static net_device_ops_no_const apdev_netdev_ops;
50682+
50683 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50684 {
50685 struct vnt_private *apdev_priv;
50686 struct net_device *dev = pDevice->dev;
50687 int ret;
50688- const struct net_device_ops apdev_netdev_ops = {
50689- .ndo_start_xmit = pDevice->tx_80211,
50690- };
50691
50692 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50693
50694@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50695 *apdev_priv = *pDevice;
50696 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
50697
50698+ /* only half broken now */
50699+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50700 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50701
50702 pDevice->apdev->type = ARPHRD_IEEE80211;
50703diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
50704index 24884ca..26c8220 100644
50705--- a/drivers/target/sbp/sbp_target.c
50706+++ b/drivers/target/sbp/sbp_target.c
50707@@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
50708
50709 #define SESSION_MAINTENANCE_INTERVAL HZ
50710
50711-static atomic_t login_id = ATOMIC_INIT(0);
50712+static atomic_unchecked_t login_id = ATOMIC_INIT(0);
50713
50714 static void session_maintenance_work(struct work_struct *);
50715 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
50716@@ -444,7 +444,7 @@ static void sbp_management_request_login(
50717 login->lun = se_lun;
50718 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
50719 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
50720- login->login_id = atomic_inc_return(&login_id);
50721+ login->login_id = atomic_inc_return_unchecked(&login_id);
50722
50723 login->tgt_agt = sbp_target_agent_register(login);
50724 if (IS_ERR(login->tgt_agt)) {
50725diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
50726index 65001e1..2ebfbb9 100644
50727--- a/drivers/target/target_core_device.c
50728+++ b/drivers/target/target_core_device.c
50729@@ -1520,7 +1520,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
50730 spin_lock_init(&dev->se_tmr_lock);
50731 spin_lock_init(&dev->qf_cmd_lock);
50732 sema_init(&dev->caw_sem, 1);
50733- atomic_set(&dev->dev_ordered_id, 0);
50734+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
50735 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
50736 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
50737 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
50738diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
50739index 2956250..b10f722 100644
50740--- a/drivers/target/target_core_transport.c
50741+++ b/drivers/target/target_core_transport.c
50742@@ -1136,7 +1136,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
50743 * Used to determine when ORDERED commands should go from
50744 * Dormant to Active status.
50745 */
50746- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
50747+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
50748 smp_mb__after_atomic_inc();
50749 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
50750 cmd->se_ordered_id, cmd->sam_task_attr,
50751diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
50752index 04b1be7..5eff86d 100644
50753--- a/drivers/thermal/of-thermal.c
50754+++ b/drivers/thermal/of-thermal.c
50755@@ -30,6 +30,7 @@
50756 #include <linux/err.h>
50757 #include <linux/export.h>
50758 #include <linux/string.h>
50759+#include <linux/mm.h>
50760
50761 #include "thermal_core.h"
50762
50763@@ -341,8 +342,10 @@ thermal_zone_of_add_sensor(struct device_node *zone,
50764 tz->get_trend = get_trend;
50765 tz->sensor_data = data;
50766
50767- tzd->ops->get_temp = of_thermal_get_temp;
50768- tzd->ops->get_trend = of_thermal_get_trend;
50769+ pax_open_kernel();
50770+ *(void **)&tzd->ops->get_temp = of_thermal_get_temp;
50771+ *(void **)&tzd->ops->get_trend = of_thermal_get_trend;
50772+ pax_close_kernel();
50773 mutex_unlock(&tzd->lock);
50774
50775 return tzd;
50776@@ -461,8 +464,10 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
50777 return;
50778
50779 mutex_lock(&tzd->lock);
50780- tzd->ops->get_temp = NULL;
50781- tzd->ops->get_trend = NULL;
50782+ pax_open_kernel();
50783+ *(void **)&tzd->ops->get_temp = NULL;
50784+ *(void **)&tzd->ops->get_trend = NULL;
50785+ pax_close_kernel();
50786
50787 tz->get_temp = NULL;
50788 tz->get_trend = NULL;
50789diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
50790index a57bb5a..1f727d33 100644
50791--- a/drivers/tty/cyclades.c
50792+++ b/drivers/tty/cyclades.c
50793@@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
50794 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
50795 info->port.count);
50796 #endif
50797- info->port.count++;
50798+ atomic_inc(&info->port.count);
50799 #ifdef CY_DEBUG_COUNT
50800 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
50801- current->pid, info->port.count);
50802+ current->pid, atomic_read(&info->port.count));
50803 #endif
50804
50805 /*
50806@@ -3974,7 +3974,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
50807 for (j = 0; j < cy_card[i].nports; j++) {
50808 info = &cy_card[i].ports[j];
50809
50810- if (info->port.count) {
50811+ if (atomic_read(&info->port.count)) {
50812 /* XXX is the ldisc num worth this? */
50813 struct tty_struct *tty;
50814 struct tty_ldisc *ld;
50815diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
50816index 94f9e3a..4c8afa8 100644
50817--- a/drivers/tty/hvc/hvc_console.c
50818+++ b/drivers/tty/hvc/hvc_console.c
50819@@ -342,7 +342,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
50820
50821 spin_lock_irqsave(&hp->port.lock, flags);
50822 /* Check and then increment for fast path open. */
50823- if (hp->port.count++ > 0) {
50824+ if (atomic_inc_return(&hp->port.count) > 1) {
50825 spin_unlock_irqrestore(&hp->port.lock, flags);
50826 hvc_kick();
50827 return 0;
50828@@ -397,7 +397,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50829
50830 spin_lock_irqsave(&hp->port.lock, flags);
50831
50832- if (--hp->port.count == 0) {
50833+ if (atomic_dec_return(&hp->port.count) == 0) {
50834 spin_unlock_irqrestore(&hp->port.lock, flags);
50835 /* We are done with the tty pointer now. */
50836 tty_port_tty_set(&hp->port, NULL);
50837@@ -419,9 +419,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50838 */
50839 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
50840 } else {
50841- if (hp->port.count < 0)
50842+ if (atomic_read(&hp->port.count) < 0)
50843 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
50844- hp->vtermno, hp->port.count);
50845+ hp->vtermno, atomic_read(&hp->port.count));
50846 spin_unlock_irqrestore(&hp->port.lock, flags);
50847 }
50848 }
50849@@ -451,12 +451,12 @@ static void hvc_hangup(struct tty_struct *tty)
50850 * open->hangup case this can be called after the final close so prevent
50851 * that from happening for now.
50852 */
50853- if (hp->port.count <= 0) {
50854+ if (atomic_read(&hp->port.count) <= 0) {
50855 spin_unlock_irqrestore(&hp->port.lock, flags);
50856 return;
50857 }
50858
50859- hp->port.count = 0;
50860+ atomic_set(&hp->port.count, 0);
50861 spin_unlock_irqrestore(&hp->port.lock, flags);
50862 tty_port_tty_set(&hp->port, NULL);
50863
50864@@ -504,7 +504,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
50865 return -EPIPE;
50866
50867 /* FIXME what's this (unprotected) check for? */
50868- if (hp->port.count <= 0)
50869+ if (atomic_read(&hp->port.count) <= 0)
50870 return -EIO;
50871
50872 spin_lock_irqsave(&hp->lock, flags);
50873diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
50874index 81e939e..95ead10 100644
50875--- a/drivers/tty/hvc/hvcs.c
50876+++ b/drivers/tty/hvc/hvcs.c
50877@@ -83,6 +83,7 @@
50878 #include <asm/hvcserver.h>
50879 #include <asm/uaccess.h>
50880 #include <asm/vio.h>
50881+#include <asm/local.h>
50882
50883 /*
50884 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
50885@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
50886
50887 spin_lock_irqsave(&hvcsd->lock, flags);
50888
50889- if (hvcsd->port.count > 0) {
50890+ if (atomic_read(&hvcsd->port.count) > 0) {
50891 spin_unlock_irqrestore(&hvcsd->lock, flags);
50892 printk(KERN_INFO "HVCS: vterm state unchanged. "
50893 "The hvcs device node is still in use.\n");
50894@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
50895 }
50896 }
50897
50898- hvcsd->port.count = 0;
50899+ atomic_set(&hvcsd->port.count, 0);
50900 hvcsd->port.tty = tty;
50901 tty->driver_data = hvcsd;
50902
50903@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
50904 unsigned long flags;
50905
50906 spin_lock_irqsave(&hvcsd->lock, flags);
50907- hvcsd->port.count++;
50908+ atomic_inc(&hvcsd->port.count);
50909 hvcsd->todo_mask |= HVCS_SCHED_READ;
50910 spin_unlock_irqrestore(&hvcsd->lock, flags);
50911
50912@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50913 hvcsd = tty->driver_data;
50914
50915 spin_lock_irqsave(&hvcsd->lock, flags);
50916- if (--hvcsd->port.count == 0) {
50917+ if (atomic_dec_and_test(&hvcsd->port.count)) {
50918
50919 vio_disable_interrupts(hvcsd->vdev);
50920
50921@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50922
50923 free_irq(irq, hvcsd);
50924 return;
50925- } else if (hvcsd->port.count < 0) {
50926+ } else if (atomic_read(&hvcsd->port.count) < 0) {
50927 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
50928 " is missmanaged.\n",
50929- hvcsd->vdev->unit_address, hvcsd->port.count);
50930+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
50931 }
50932
50933 spin_unlock_irqrestore(&hvcsd->lock, flags);
50934@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50935
50936 spin_lock_irqsave(&hvcsd->lock, flags);
50937 /* Preserve this so that we know how many kref refs to put */
50938- temp_open_count = hvcsd->port.count;
50939+ temp_open_count = atomic_read(&hvcsd->port.count);
50940
50941 /*
50942 * Don't kref put inside the spinlock because the destruction
50943@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50944 tty->driver_data = NULL;
50945 hvcsd->port.tty = NULL;
50946
50947- hvcsd->port.count = 0;
50948+ atomic_set(&hvcsd->port.count, 0);
50949
50950 /* This will drop any buffered data on the floor which is OK in a hangup
50951 * scenario. */
50952@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
50953 * the middle of a write operation? This is a crummy place to do this
50954 * but we want to keep it all in the spinlock.
50955 */
50956- if (hvcsd->port.count <= 0) {
50957+ if (atomic_read(&hvcsd->port.count) <= 0) {
50958 spin_unlock_irqrestore(&hvcsd->lock, flags);
50959 return -ENODEV;
50960 }
50961@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
50962 {
50963 struct hvcs_struct *hvcsd = tty->driver_data;
50964
50965- if (!hvcsd || hvcsd->port.count <= 0)
50966+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
50967 return 0;
50968
50969 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
50970diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
50971index 4190199..06d5bfa 100644
50972--- a/drivers/tty/hvc/hvsi.c
50973+++ b/drivers/tty/hvc/hvsi.c
50974@@ -85,7 +85,7 @@ struct hvsi_struct {
50975 int n_outbuf;
50976 uint32_t vtermno;
50977 uint32_t virq;
50978- atomic_t seqno; /* HVSI packet sequence number */
50979+ atomic_unchecked_t seqno; /* HVSI packet sequence number */
50980 uint16_t mctrl;
50981 uint8_t state; /* HVSI protocol state */
50982 uint8_t flags;
50983@@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
50984
50985 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
50986 packet.hdr.len = sizeof(struct hvsi_query_response);
50987- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50988+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50989 packet.verb = VSV_SEND_VERSION_NUMBER;
50990 packet.u.version = HVSI_VERSION;
50991 packet.query_seqno = query_seqno+1;
50992@@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
50993
50994 packet.hdr.type = VS_QUERY_PACKET_HEADER;
50995 packet.hdr.len = sizeof(struct hvsi_query);
50996- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50997+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50998 packet.verb = verb;
50999
51000 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
51001@@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
51002 int wrote;
51003
51004 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
51005- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
51006+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
51007 packet.hdr.len = sizeof(struct hvsi_control);
51008 packet.verb = VSV_SET_MODEM_CTL;
51009 packet.mask = HVSI_TSDTR;
51010@@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
51011 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
51012
51013 packet.hdr.type = VS_DATA_PACKET_HEADER;
51014- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
51015+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
51016 packet.hdr.len = count + sizeof(struct hvsi_header);
51017 memcpy(&packet.data, buf, count);
51018
51019@@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
51020 struct hvsi_control packet __ALIGNED__;
51021
51022 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
51023- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
51024+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
51025 packet.hdr.len = 6;
51026 packet.verb = VSV_CLOSE_PROTOCOL;
51027
51028@@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
51029
51030 tty_port_tty_set(&hp->port, tty);
51031 spin_lock_irqsave(&hp->lock, flags);
51032- hp->port.count++;
51033+ atomic_inc(&hp->port.count);
51034 atomic_set(&hp->seqno, 0);
51035 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
51036 spin_unlock_irqrestore(&hp->lock, flags);
51037@@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
51038
51039 spin_lock_irqsave(&hp->lock, flags);
51040
51041- if (--hp->port.count == 0) {
51042+ if (atomic_dec_return(&hp->port.count) == 0) {
51043 tty_port_tty_set(&hp->port, NULL);
51044 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
51045
51046@@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
51047
51048 spin_lock_irqsave(&hp->lock, flags);
51049 }
51050- } else if (hp->port.count < 0)
51051+ } else if (atomic_read(&hp->port.count) < 0)
51052 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
51053- hp - hvsi_ports, hp->port.count);
51054+ hp - hvsi_ports, atomic_read(&hp->port.count));
51055
51056 spin_unlock_irqrestore(&hp->lock, flags);
51057 }
51058@@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
51059 tty_port_tty_set(&hp->port, NULL);
51060
51061 spin_lock_irqsave(&hp->lock, flags);
51062- hp->port.count = 0;
51063+ atomic_set(&hp->port.count, 0);
51064 hp->n_outbuf = 0;
51065 spin_unlock_irqrestore(&hp->lock, flags);
51066 }
51067diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
51068index 7ae6c29..05c6dba 100644
51069--- a/drivers/tty/hvc/hvsi_lib.c
51070+++ b/drivers/tty/hvc/hvsi_lib.c
51071@@ -8,7 +8,7 @@
51072
51073 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
51074 {
51075- packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
51076+ packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
51077
51078 /* Assumes that always succeeds, works in practice */
51079 return pv->put_chars(pv->termno, (char *)packet, packet->len);
51080@@ -20,7 +20,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
51081
51082 /* Reset state */
51083 pv->established = 0;
51084- atomic_set(&pv->seqno, 0);
51085+ atomic_set_unchecked(&pv->seqno, 0);
51086
51087 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
51088
51089diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
51090index 17ee3bf..8d2520d 100644
51091--- a/drivers/tty/ipwireless/tty.c
51092+++ b/drivers/tty/ipwireless/tty.c
51093@@ -28,6 +28,7 @@
51094 #include <linux/tty_driver.h>
51095 #include <linux/tty_flip.h>
51096 #include <linux/uaccess.h>
51097+#include <asm/local.h>
51098
51099 #include "tty.h"
51100 #include "network.h"
51101@@ -98,10 +99,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
51102 mutex_unlock(&tty->ipw_tty_mutex);
51103 return -ENODEV;
51104 }
51105- if (tty->port.count == 0)
51106+ if (atomic_read(&tty->port.count) == 0)
51107 tty->tx_bytes_queued = 0;
51108
51109- tty->port.count++;
51110+ atomic_inc(&tty->port.count);
51111
51112 tty->port.tty = linux_tty;
51113 linux_tty->driver_data = tty;
51114@@ -117,9 +118,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
51115
51116 static void do_ipw_close(struct ipw_tty *tty)
51117 {
51118- tty->port.count--;
51119-
51120- if (tty->port.count == 0) {
51121+ if (atomic_dec_return(&tty->port.count) == 0) {
51122 struct tty_struct *linux_tty = tty->port.tty;
51123
51124 if (linux_tty != NULL) {
51125@@ -140,7 +139,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
51126 return;
51127
51128 mutex_lock(&tty->ipw_tty_mutex);
51129- if (tty->port.count == 0) {
51130+ if (atomic_read(&tty->port.count) == 0) {
51131 mutex_unlock(&tty->ipw_tty_mutex);
51132 return;
51133 }
51134@@ -163,7 +162,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
51135
51136 mutex_lock(&tty->ipw_tty_mutex);
51137
51138- if (!tty->port.count) {
51139+ if (!atomic_read(&tty->port.count)) {
51140 mutex_unlock(&tty->ipw_tty_mutex);
51141 return;
51142 }
51143@@ -202,7 +201,7 @@ static int ipw_write(struct tty_struct *linux_tty,
51144 return -ENODEV;
51145
51146 mutex_lock(&tty->ipw_tty_mutex);
51147- if (!tty->port.count) {
51148+ if (!atomic_read(&tty->port.count)) {
51149 mutex_unlock(&tty->ipw_tty_mutex);
51150 return -EINVAL;
51151 }
51152@@ -242,7 +241,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
51153 if (!tty)
51154 return -ENODEV;
51155
51156- if (!tty->port.count)
51157+ if (!atomic_read(&tty->port.count))
51158 return -EINVAL;
51159
51160 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
51161@@ -284,7 +283,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
51162 if (!tty)
51163 return 0;
51164
51165- if (!tty->port.count)
51166+ if (!atomic_read(&tty->port.count))
51167 return 0;
51168
51169 return tty->tx_bytes_queued;
51170@@ -365,7 +364,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
51171 if (!tty)
51172 return -ENODEV;
51173
51174- if (!tty->port.count)
51175+ if (!atomic_read(&tty->port.count))
51176 return -EINVAL;
51177
51178 return get_control_lines(tty);
51179@@ -381,7 +380,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
51180 if (!tty)
51181 return -ENODEV;
51182
51183- if (!tty->port.count)
51184+ if (!atomic_read(&tty->port.count))
51185 return -EINVAL;
51186
51187 return set_control_lines(tty, set, clear);
51188@@ -395,7 +394,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
51189 if (!tty)
51190 return -ENODEV;
51191
51192- if (!tty->port.count)
51193+ if (!atomic_read(&tty->port.count))
51194 return -EINVAL;
51195
51196 /* FIXME: Exactly how is the tty object locked here .. */
51197@@ -551,7 +550,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
51198 * are gone */
51199 mutex_lock(&ttyj->ipw_tty_mutex);
51200 }
51201- while (ttyj->port.count)
51202+ while (atomic_read(&ttyj->port.count))
51203 do_ipw_close(ttyj);
51204 ipwireless_disassociate_network_ttys(network,
51205 ttyj->channel_idx);
51206diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
51207index 1deaca4..c8582d4 100644
51208--- a/drivers/tty/moxa.c
51209+++ b/drivers/tty/moxa.c
51210@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
51211 }
51212
51213 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
51214- ch->port.count++;
51215+ atomic_inc(&ch->port.count);
51216 tty->driver_data = ch;
51217 tty_port_tty_set(&ch->port, tty);
51218 mutex_lock(&ch->port.mutex);
51219diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
51220index 2ebe47b..3205833 100644
51221--- a/drivers/tty/n_gsm.c
51222+++ b/drivers/tty/n_gsm.c
51223@@ -1644,7 +1644,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
51224 spin_lock_init(&dlci->lock);
51225 mutex_init(&dlci->mutex);
51226 dlci->fifo = &dlci->_fifo;
51227- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
51228+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
51229 kfree(dlci);
51230 return NULL;
51231 }
51232@@ -2954,7 +2954,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
51233 struct gsm_dlci *dlci = tty->driver_data;
51234 struct tty_port *port = &dlci->port;
51235
51236- port->count++;
51237+ atomic_inc(&port->count);
51238 tty_port_tty_set(port, tty);
51239
51240 dlci->modem_rx = 0;
51241diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
51242index d15624c..bd628c6 100644
51243--- a/drivers/tty/n_tty.c
51244+++ b/drivers/tty/n_tty.c
51245@@ -115,7 +115,7 @@ struct n_tty_data {
51246 int minimum_to_wake;
51247
51248 /* consumer-published */
51249- size_t read_tail;
51250+ size_t read_tail __intentional_overflow(-1);
51251 size_t line_start;
51252
51253 /* protected by output lock */
51254@@ -2356,10 +2356,18 @@ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file,
51255 if (tty->ops->flush_chars)
51256 tty->ops->flush_chars(tty);
51257 } else {
51258+ struct n_tty_data *ldata = tty->disc_data;
51259+ bool lock;
51260+
51261+ lock = L_ECHO(tty) || (ldata->icanon & L_ECHONL(tty));
51262+ if (lock)
51263+ mutex_lock(&ldata->output_lock);
51264 while (nr > 0) {
51265 c = tty->ops->write(tty, b, nr);
51266 if (c < 0) {
51267 retval = c;
51268+ if (lock)
51269+ mutex_unlock(&ldata->output_lock);
51270 goto break_out;
51271 }
51272 if (!c)
51273@@ -2367,6 +2375,8 @@ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file,
51274 b += c;
51275 nr -= c;
51276 }
51277+ if (lock)
51278+ mutex_unlock(&ldata->output_lock);
51279 }
51280 if (!nr)
51281 break;
51282@@ -2515,6 +2525,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
51283 {
51284 *ops = tty_ldisc_N_TTY;
51285 ops->owner = NULL;
51286- ops->refcount = ops->flags = 0;
51287+ atomic_set(&ops->refcount, 0);
51288+ ops->flags = 0;
51289 }
51290 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
51291diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
51292index 25c9bc7..24077b7 100644
51293--- a/drivers/tty/pty.c
51294+++ b/drivers/tty/pty.c
51295@@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
51296 panic("Couldn't register Unix98 pts driver");
51297
51298 /* Now create the /dev/ptmx special device */
51299+ pax_open_kernel();
51300 tty_default_fops(&ptmx_fops);
51301- ptmx_fops.open = ptmx_open;
51302+ *(void **)&ptmx_fops.open = ptmx_open;
51303+ pax_close_kernel();
51304
51305 cdev_init(&ptmx_cdev, &ptmx_fops);
51306 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
51307diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
51308index 383c4c7..d408e21 100644
51309--- a/drivers/tty/rocket.c
51310+++ b/drivers/tty/rocket.c
51311@@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
51312 tty->driver_data = info;
51313 tty_port_tty_set(port, tty);
51314
51315- if (port->count++ == 0) {
51316+ if (atomic_inc_return(&port->count) == 1) {
51317 atomic_inc(&rp_num_ports_open);
51318
51319 #ifdef ROCKET_DEBUG_OPEN
51320@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
51321 #endif
51322 }
51323 #ifdef ROCKET_DEBUG_OPEN
51324- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
51325+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
51326 #endif
51327
51328 /*
51329@@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
51330 spin_unlock_irqrestore(&info->port.lock, flags);
51331 return;
51332 }
51333- if (info->port.count)
51334+ if (atomic_read(&info->port.count))
51335 atomic_dec(&rp_num_ports_open);
51336 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
51337 spin_unlock_irqrestore(&info->port.lock, flags);
51338diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
51339index 1274499..f541382 100644
51340--- a/drivers/tty/serial/ioc4_serial.c
51341+++ b/drivers/tty/serial/ioc4_serial.c
51342@@ -437,7 +437,7 @@ struct ioc4_soft {
51343 } is_intr_info[MAX_IOC4_INTR_ENTS];
51344
51345 /* Number of entries active in the above array */
51346- atomic_t is_num_intrs;
51347+ atomic_unchecked_t is_num_intrs;
51348 } is_intr_type[IOC4_NUM_INTR_TYPES];
51349
51350 /* is_ir_lock must be held while
51351@@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
51352 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
51353 || (type == IOC4_OTHER_INTR_TYPE)));
51354
51355- i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
51356+ i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
51357 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
51358
51359 /* Save off the lower level interrupt handler */
51360@@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
51361
51362 soft = arg;
51363 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
51364- num_intrs = (int)atomic_read(
51365+ num_intrs = (int)atomic_read_unchecked(
51366 &soft->is_intr_type[intr_type].is_num_intrs);
51367
51368 this_mir = this_ir = pending_intrs(soft, intr_type);
51369diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
51370index a260cde..6b2b5ce 100644
51371--- a/drivers/tty/serial/kgdboc.c
51372+++ b/drivers/tty/serial/kgdboc.c
51373@@ -24,8 +24,9 @@
51374 #define MAX_CONFIG_LEN 40
51375
51376 static struct kgdb_io kgdboc_io_ops;
51377+static struct kgdb_io kgdboc_io_ops_console;
51378
51379-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
51380+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
51381 static int configured = -1;
51382
51383 static char config[MAX_CONFIG_LEN];
51384@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
51385 kgdboc_unregister_kbd();
51386 if (configured == 1)
51387 kgdb_unregister_io_module(&kgdboc_io_ops);
51388+ else if (configured == 2)
51389+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
51390 }
51391
51392 static int configure_kgdboc(void)
51393@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
51394 int err;
51395 char *cptr = config;
51396 struct console *cons;
51397+ int is_console = 0;
51398
51399 err = kgdboc_option_setup(config);
51400 if (err || !strlen(config) || isspace(config[0]))
51401 goto noconfig;
51402
51403 err = -ENODEV;
51404- kgdboc_io_ops.is_console = 0;
51405 kgdb_tty_driver = NULL;
51406
51407 kgdboc_use_kms = 0;
51408@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
51409 int idx;
51410 if (cons->device && cons->device(cons, &idx) == p &&
51411 idx == tty_line) {
51412- kgdboc_io_ops.is_console = 1;
51413+ is_console = 1;
51414 break;
51415 }
51416 cons = cons->next;
51417@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
51418 kgdb_tty_line = tty_line;
51419
51420 do_register:
51421- err = kgdb_register_io_module(&kgdboc_io_ops);
51422+ if (is_console) {
51423+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
51424+ configured = 2;
51425+ } else {
51426+ err = kgdb_register_io_module(&kgdboc_io_ops);
51427+ configured = 1;
51428+ }
51429 if (err)
51430 goto noconfig;
51431
51432@@ -205,8 +214,6 @@ do_register:
51433 if (err)
51434 goto nmi_con_failed;
51435
51436- configured = 1;
51437-
51438 return 0;
51439
51440 nmi_con_failed:
51441@@ -223,7 +230,7 @@ noconfig:
51442 static int __init init_kgdboc(void)
51443 {
51444 /* Already configured? */
51445- if (configured == 1)
51446+ if (configured >= 1)
51447 return 0;
51448
51449 return configure_kgdboc();
51450@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
51451 if (config[len - 1] == '\n')
51452 config[len - 1] = '\0';
51453
51454- if (configured == 1)
51455+ if (configured >= 1)
51456 cleanup_kgdboc();
51457
51458 /* Go and configure with the new params. */
51459@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
51460 .post_exception = kgdboc_post_exp_handler,
51461 };
51462
51463+static struct kgdb_io kgdboc_io_ops_console = {
51464+ .name = "kgdboc",
51465+ .read_char = kgdboc_get_char,
51466+ .write_char = kgdboc_put_char,
51467+ .pre_exception = kgdboc_pre_exp_handler,
51468+ .post_exception = kgdboc_post_exp_handler,
51469+ .is_console = 1
51470+};
51471+
51472 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
51473 /* This is only available if kgdboc is a built in for early debugging */
51474 static int __init kgdboc_early_init(char *opt)
51475diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
51476index b5d779c..3622cfe 100644
51477--- a/drivers/tty/serial/msm_serial.c
51478+++ b/drivers/tty/serial/msm_serial.c
51479@@ -897,7 +897,7 @@ static struct uart_driver msm_uart_driver = {
51480 .cons = MSM_CONSOLE,
51481 };
51482
51483-static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
51484+static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
51485
51486 static const struct of_device_id msm_uartdm_table[] = {
51487 { .compatible = "qcom,msm-uartdm" },
51488@@ -912,7 +912,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
51489 int irq;
51490
51491 if (pdev->id == -1)
51492- pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
51493+ pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
51494
51495 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
51496 return -ENXIO;
51497diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
51498index 9cd706d..6ff2de7 100644
51499--- a/drivers/tty/serial/samsung.c
51500+++ b/drivers/tty/serial/samsung.c
51501@@ -463,11 +463,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
51502 }
51503 }
51504
51505+static int s3c64xx_serial_startup(struct uart_port *port);
51506 static int s3c24xx_serial_startup(struct uart_port *port)
51507 {
51508 struct s3c24xx_uart_port *ourport = to_ourport(port);
51509 int ret;
51510
51511+ /* Startup sequence is different for s3c64xx and higher SoC's */
51512+ if (s3c24xx_serial_has_interrupt_mask(port))
51513+ return s3c64xx_serial_startup(port);
51514+
51515 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
51516 port->mapbase, port->membase);
51517
51518@@ -1141,10 +1146,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
51519 /* setup info for port */
51520 port->dev = &platdev->dev;
51521
51522- /* Startup sequence is different for s3c64xx and higher SoC's */
51523- if (s3c24xx_serial_has_interrupt_mask(port))
51524- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
51525-
51526 port->uartclk = 1;
51527
51528 if (cfg->uart_flags & UPF_CONS_FLOW) {
51529diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
51530index ece2049..fba2524 100644
51531--- a/drivers/tty/serial/serial_core.c
51532+++ b/drivers/tty/serial/serial_core.c
51533@@ -1448,7 +1448,7 @@ static void uart_hangup(struct tty_struct *tty)
51534 uart_flush_buffer(tty);
51535 uart_shutdown(tty, state);
51536 spin_lock_irqsave(&port->lock, flags);
51537- port->count = 0;
51538+ atomic_set(&port->count, 0);
51539 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
51540 spin_unlock_irqrestore(&port->lock, flags);
51541 tty_port_tty_set(port, NULL);
51542@@ -1544,7 +1544,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51543 goto end;
51544 }
51545
51546- port->count++;
51547+ atomic_inc(&port->count);
51548 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
51549 retval = -ENXIO;
51550 goto err_dec_count;
51551@@ -1572,7 +1572,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51552 /*
51553 * Make sure the device is in D0 state.
51554 */
51555- if (port->count == 1)
51556+ if (atomic_read(&port->count) == 1)
51557 uart_change_pm(state, UART_PM_STATE_ON);
51558
51559 /*
51560@@ -1590,7 +1590,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51561 end:
51562 return retval;
51563 err_dec_count:
51564- port->count--;
51565+ atomic_inc(&port->count);
51566 mutex_unlock(&port->mutex);
51567 goto end;
51568 }
51569diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
51570index 5ae14b4..2c1288f 100644
51571--- a/drivers/tty/synclink.c
51572+++ b/drivers/tty/synclink.c
51573@@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
51574
51575 if (debug_level >= DEBUG_LEVEL_INFO)
51576 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
51577- __FILE__,__LINE__, info->device_name, info->port.count);
51578+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51579
51580 if (tty_port_close_start(&info->port, tty, filp) == 0)
51581 goto cleanup;
51582@@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
51583 cleanup:
51584 if (debug_level >= DEBUG_LEVEL_INFO)
51585 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
51586- tty->driver->name, info->port.count);
51587+ tty->driver->name, atomic_read(&info->port.count));
51588
51589 } /* end of mgsl_close() */
51590
51591@@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
51592
51593 mgsl_flush_buffer(tty);
51594 shutdown(info);
51595-
51596- info->port.count = 0;
51597+
51598+ atomic_set(&info->port.count, 0);
51599 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51600 info->port.tty = NULL;
51601
51602@@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51603
51604 if (debug_level >= DEBUG_LEVEL_INFO)
51605 printk("%s(%d):block_til_ready before block on %s count=%d\n",
51606- __FILE__,__LINE__, tty->driver->name, port->count );
51607+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51608
51609 spin_lock_irqsave(&info->irq_spinlock, flags);
51610 if (!tty_hung_up_p(filp)) {
51611 extra_count = true;
51612- port->count--;
51613+ atomic_dec(&port->count);
51614 }
51615 spin_unlock_irqrestore(&info->irq_spinlock, flags);
51616 port->blocked_open++;
51617@@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51618
51619 if (debug_level >= DEBUG_LEVEL_INFO)
51620 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
51621- __FILE__,__LINE__, tty->driver->name, port->count );
51622+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51623
51624 tty_unlock(tty);
51625 schedule();
51626@@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51627
51628 /* FIXME: Racy on hangup during close wait */
51629 if (extra_count)
51630- port->count++;
51631+ atomic_inc(&port->count);
51632 port->blocked_open--;
51633
51634 if (debug_level >= DEBUG_LEVEL_INFO)
51635 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
51636- __FILE__,__LINE__, tty->driver->name, port->count );
51637+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51638
51639 if (!retval)
51640 port->flags |= ASYNC_NORMAL_ACTIVE;
51641@@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
51642
51643 if (debug_level >= DEBUG_LEVEL_INFO)
51644 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
51645- __FILE__,__LINE__,tty->driver->name, info->port.count);
51646+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51647
51648 /* If port is closing, signal caller to try again */
51649 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51650@@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
51651 spin_unlock_irqrestore(&info->netlock, flags);
51652 goto cleanup;
51653 }
51654- info->port.count++;
51655+ atomic_inc(&info->port.count);
51656 spin_unlock_irqrestore(&info->netlock, flags);
51657
51658- if (info->port.count == 1) {
51659+ if (atomic_read(&info->port.count) == 1) {
51660 /* 1st open on this device, init hardware */
51661 retval = startup(info);
51662 if (retval < 0)
51663@@ -3446,8 +3446,8 @@ cleanup:
51664 if (retval) {
51665 if (tty->count == 1)
51666 info->port.tty = NULL; /* tty layer will release tty struct */
51667- if(info->port.count)
51668- info->port.count--;
51669+ if (atomic_read(&info->port.count))
51670+ atomic_dec(&info->port.count);
51671 }
51672
51673 return retval;
51674@@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51675 unsigned short new_crctype;
51676
51677 /* return error if TTY interface open */
51678- if (info->port.count)
51679+ if (atomic_read(&info->port.count))
51680 return -EBUSY;
51681
51682 switch (encoding)
51683@@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
51684
51685 /* arbitrate between network and tty opens */
51686 spin_lock_irqsave(&info->netlock, flags);
51687- if (info->port.count != 0 || info->netcount != 0) {
51688+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51689 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51690 spin_unlock_irqrestore(&info->netlock, flags);
51691 return -EBUSY;
51692@@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51693 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51694
51695 /* return error if TTY interface open */
51696- if (info->port.count)
51697+ if (atomic_read(&info->port.count))
51698 return -EBUSY;
51699
51700 if (cmd != SIOCWANDEV)
51701diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
51702index c359a91..959fc26 100644
51703--- a/drivers/tty/synclink_gt.c
51704+++ b/drivers/tty/synclink_gt.c
51705@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51706 tty->driver_data = info;
51707 info->port.tty = tty;
51708
51709- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
51710+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
51711
51712 /* If port is closing, signal caller to try again */
51713 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51714@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51715 mutex_unlock(&info->port.mutex);
51716 goto cleanup;
51717 }
51718- info->port.count++;
51719+ atomic_inc(&info->port.count);
51720 spin_unlock_irqrestore(&info->netlock, flags);
51721
51722- if (info->port.count == 1) {
51723+ if (atomic_read(&info->port.count) == 1) {
51724 /* 1st open on this device, init hardware */
51725 retval = startup(info);
51726 if (retval < 0) {
51727@@ -715,8 +715,8 @@ cleanup:
51728 if (retval) {
51729 if (tty->count == 1)
51730 info->port.tty = NULL; /* tty layer will release tty struct */
51731- if(info->port.count)
51732- info->port.count--;
51733+ if(atomic_read(&info->port.count))
51734+ atomic_dec(&info->port.count);
51735 }
51736
51737 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
51738@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51739
51740 if (sanity_check(info, tty->name, "close"))
51741 return;
51742- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
51743+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
51744
51745 if (tty_port_close_start(&info->port, tty, filp) == 0)
51746 goto cleanup;
51747@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51748 tty_port_close_end(&info->port, tty);
51749 info->port.tty = NULL;
51750 cleanup:
51751- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
51752+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
51753 }
51754
51755 static void hangup(struct tty_struct *tty)
51756@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
51757 shutdown(info);
51758
51759 spin_lock_irqsave(&info->port.lock, flags);
51760- info->port.count = 0;
51761+ atomic_set(&info->port.count, 0);
51762 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51763 info->port.tty = NULL;
51764 spin_unlock_irqrestore(&info->port.lock, flags);
51765@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51766 unsigned short new_crctype;
51767
51768 /* return error if TTY interface open */
51769- if (info->port.count)
51770+ if (atomic_read(&info->port.count))
51771 return -EBUSY;
51772
51773 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
51774@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
51775
51776 /* arbitrate between network and tty opens */
51777 spin_lock_irqsave(&info->netlock, flags);
51778- if (info->port.count != 0 || info->netcount != 0) {
51779+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51780 DBGINFO(("%s hdlc_open busy\n", dev->name));
51781 spin_unlock_irqrestore(&info->netlock, flags);
51782 return -EBUSY;
51783@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51784 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
51785
51786 /* return error if TTY interface open */
51787- if (info->port.count)
51788+ if (atomic_read(&info->port.count))
51789 return -EBUSY;
51790
51791 if (cmd != SIOCWANDEV)
51792@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
51793 if (port == NULL)
51794 continue;
51795 spin_lock(&port->lock);
51796- if ((port->port.count || port->netcount) &&
51797+ if ((atomic_read(&port->port.count) || port->netcount) &&
51798 port->pending_bh && !port->bh_running &&
51799 !port->bh_requested) {
51800 DBGISR(("%s bh queued\n", port->device_name));
51801@@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51802 spin_lock_irqsave(&info->lock, flags);
51803 if (!tty_hung_up_p(filp)) {
51804 extra_count = true;
51805- port->count--;
51806+ atomic_dec(&port->count);
51807 }
51808 spin_unlock_irqrestore(&info->lock, flags);
51809 port->blocked_open++;
51810@@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51811 remove_wait_queue(&port->open_wait, &wait);
51812
51813 if (extra_count)
51814- port->count++;
51815+ atomic_inc(&port->count);
51816 port->blocked_open--;
51817
51818 if (!retval)
51819diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
51820index 144202e..4ccb07d 100644
51821--- a/drivers/tty/synclinkmp.c
51822+++ b/drivers/tty/synclinkmp.c
51823@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51824
51825 if (debug_level >= DEBUG_LEVEL_INFO)
51826 printk("%s(%d):%s open(), old ref count = %d\n",
51827- __FILE__,__LINE__,tty->driver->name, info->port.count);
51828+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51829
51830 /* If port is closing, signal caller to try again */
51831 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51832@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51833 spin_unlock_irqrestore(&info->netlock, flags);
51834 goto cleanup;
51835 }
51836- info->port.count++;
51837+ atomic_inc(&info->port.count);
51838 spin_unlock_irqrestore(&info->netlock, flags);
51839
51840- if (info->port.count == 1) {
51841+ if (atomic_read(&info->port.count) == 1) {
51842 /* 1st open on this device, init hardware */
51843 retval = startup(info);
51844 if (retval < 0)
51845@@ -796,8 +796,8 @@ cleanup:
51846 if (retval) {
51847 if (tty->count == 1)
51848 info->port.tty = NULL; /* tty layer will release tty struct */
51849- if(info->port.count)
51850- info->port.count--;
51851+ if(atomic_read(&info->port.count))
51852+ atomic_dec(&info->port.count);
51853 }
51854
51855 return retval;
51856@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51857
51858 if (debug_level >= DEBUG_LEVEL_INFO)
51859 printk("%s(%d):%s close() entry, count=%d\n",
51860- __FILE__,__LINE__, info->device_name, info->port.count);
51861+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51862
51863 if (tty_port_close_start(&info->port, tty, filp) == 0)
51864 goto cleanup;
51865@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51866 cleanup:
51867 if (debug_level >= DEBUG_LEVEL_INFO)
51868 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
51869- tty->driver->name, info->port.count);
51870+ tty->driver->name, atomic_read(&info->port.count));
51871 }
51872
51873 /* Called by tty_hangup() when a hangup is signaled.
51874@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
51875 shutdown(info);
51876
51877 spin_lock_irqsave(&info->port.lock, flags);
51878- info->port.count = 0;
51879+ atomic_set(&info->port.count, 0);
51880 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51881 info->port.tty = NULL;
51882 spin_unlock_irqrestore(&info->port.lock, flags);
51883@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51884 unsigned short new_crctype;
51885
51886 /* return error if TTY interface open */
51887- if (info->port.count)
51888+ if (atomic_read(&info->port.count))
51889 return -EBUSY;
51890
51891 switch (encoding)
51892@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
51893
51894 /* arbitrate between network and tty opens */
51895 spin_lock_irqsave(&info->netlock, flags);
51896- if (info->port.count != 0 || info->netcount != 0) {
51897+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51898 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51899 spin_unlock_irqrestore(&info->netlock, flags);
51900 return -EBUSY;
51901@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51902 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51903
51904 /* return error if TTY interface open */
51905- if (info->port.count)
51906+ if (atomic_read(&info->port.count))
51907 return -EBUSY;
51908
51909 if (cmd != SIOCWANDEV)
51910@@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
51911 * do not request bottom half processing if the
51912 * device is not open in a normal mode.
51913 */
51914- if ( port && (port->port.count || port->netcount) &&
51915+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
51916 port->pending_bh && !port->bh_running &&
51917 !port->bh_requested ) {
51918 if ( debug_level >= DEBUG_LEVEL_ISR )
51919@@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51920
51921 if (debug_level >= DEBUG_LEVEL_INFO)
51922 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
51923- __FILE__,__LINE__, tty->driver->name, port->count );
51924+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51925
51926 spin_lock_irqsave(&info->lock, flags);
51927 if (!tty_hung_up_p(filp)) {
51928 extra_count = true;
51929- port->count--;
51930+ atomic_dec(&port->count);
51931 }
51932 spin_unlock_irqrestore(&info->lock, flags);
51933 port->blocked_open++;
51934@@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51935
51936 if (debug_level >= DEBUG_LEVEL_INFO)
51937 printk("%s(%d):%s block_til_ready() count=%d\n",
51938- __FILE__,__LINE__, tty->driver->name, port->count );
51939+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51940
51941 tty_unlock(tty);
51942 schedule();
51943@@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51944 remove_wait_queue(&port->open_wait, &wait);
51945
51946 if (extra_count)
51947- port->count++;
51948+ atomic_inc(&port->count);
51949 port->blocked_open--;
51950
51951 if (debug_level >= DEBUG_LEVEL_INFO)
51952 printk("%s(%d):%s block_til_ready() after, count=%d\n",
51953- __FILE__,__LINE__, tty->driver->name, port->count );
51954+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51955
51956 if (!retval)
51957 port->flags |= ASYNC_NORMAL_ACTIVE;
51958diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
51959index ce396ec..04a37be 100644
51960--- a/drivers/tty/sysrq.c
51961+++ b/drivers/tty/sysrq.c
51962@@ -1075,7 +1075,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
51963 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
51964 size_t count, loff_t *ppos)
51965 {
51966- if (count) {
51967+ if (count && capable(CAP_SYS_ADMIN)) {
51968 char c;
51969
51970 if (get_user(c, buf))
51971diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
51972index d3448a9..28e8db0 100644
51973--- a/drivers/tty/tty_io.c
51974+++ b/drivers/tty/tty_io.c
51975@@ -3475,7 +3475,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
51976
51977 void tty_default_fops(struct file_operations *fops)
51978 {
51979- *fops = tty_fops;
51980+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
51981 }
51982
51983 /*
51984diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
51985index 2d822aa..a566234 100644
51986--- a/drivers/tty/tty_ldisc.c
51987+++ b/drivers/tty/tty_ldisc.c
51988@@ -71,7 +71,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
51989 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51990 tty_ldiscs[disc] = new_ldisc;
51991 new_ldisc->num = disc;
51992- new_ldisc->refcount = 0;
51993+ atomic_set(&new_ldisc->refcount, 0);
51994 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
51995
51996 return ret;
51997@@ -99,7 +99,7 @@ int tty_unregister_ldisc(int disc)
51998 return -EINVAL;
51999
52000 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
52001- if (tty_ldiscs[disc]->refcount)
52002+ if (atomic_read(&tty_ldiscs[disc]->refcount))
52003 ret = -EBUSY;
52004 else
52005 tty_ldiscs[disc] = NULL;
52006@@ -120,7 +120,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
52007 if (ldops) {
52008 ret = ERR_PTR(-EAGAIN);
52009 if (try_module_get(ldops->owner)) {
52010- ldops->refcount++;
52011+ atomic_inc(&ldops->refcount);
52012 ret = ldops;
52013 }
52014 }
52015@@ -133,7 +133,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
52016 unsigned long flags;
52017
52018 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
52019- ldops->refcount--;
52020+ atomic_dec(&ldops->refcount);
52021 module_put(ldops->owner);
52022 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
52023 }
52024diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
52025index 3f746c8..2f2fcaa 100644
52026--- a/drivers/tty/tty_port.c
52027+++ b/drivers/tty/tty_port.c
52028@@ -235,7 +235,7 @@ void tty_port_hangup(struct tty_port *port)
52029 unsigned long flags;
52030
52031 spin_lock_irqsave(&port->lock, flags);
52032- port->count = 0;
52033+ atomic_set(&port->count, 0);
52034 port->flags &= ~ASYNC_NORMAL_ACTIVE;
52035 tty = port->tty;
52036 if (tty)
52037@@ -393,7 +393,7 @@ int tty_port_block_til_ready(struct tty_port *port,
52038 /* The port lock protects the port counts */
52039 spin_lock_irqsave(&port->lock, flags);
52040 if (!tty_hung_up_p(filp))
52041- port->count--;
52042+ atomic_dec(&port->count);
52043 port->blocked_open++;
52044 spin_unlock_irqrestore(&port->lock, flags);
52045
52046@@ -435,7 +435,7 @@ int tty_port_block_til_ready(struct tty_port *port,
52047 we must not mess that up further */
52048 spin_lock_irqsave(&port->lock, flags);
52049 if (!tty_hung_up_p(filp))
52050- port->count++;
52051+ atomic_inc(&port->count);
52052 port->blocked_open--;
52053 if (retval == 0)
52054 port->flags |= ASYNC_NORMAL_ACTIVE;
52055@@ -469,19 +469,19 @@ int tty_port_close_start(struct tty_port *port,
52056 return 0;
52057 }
52058
52059- if (tty->count == 1 && port->count != 1) {
52060+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
52061 printk(KERN_WARNING
52062 "tty_port_close_start: tty->count = 1 port count = %d.\n",
52063- port->count);
52064- port->count = 1;
52065+ atomic_read(&port->count));
52066+ atomic_set(&port->count, 1);
52067 }
52068- if (--port->count < 0) {
52069+ if (atomic_dec_return(&port->count) < 0) {
52070 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
52071- port->count);
52072- port->count = 0;
52073+ atomic_read(&port->count));
52074+ atomic_set(&port->count, 0);
52075 }
52076
52077- if (port->count) {
52078+ if (atomic_read(&port->count)) {
52079 spin_unlock_irqrestore(&port->lock, flags);
52080 return 0;
52081 }
52082@@ -563,7 +563,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
52083 {
52084 spin_lock_irq(&port->lock);
52085 if (!tty_hung_up_p(filp))
52086- ++port->count;
52087+ atomic_inc(&port->count);
52088 spin_unlock_irq(&port->lock);
52089 tty_port_tty_set(port, tty);
52090
52091diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
52092index d0e3a44..5f8b754 100644
52093--- a/drivers/tty/vt/keyboard.c
52094+++ b/drivers/tty/vt/keyboard.c
52095@@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
52096 kbd->kbdmode == VC_OFF) &&
52097 value != KVAL(K_SAK))
52098 return; /* SAK is allowed even in raw mode */
52099+
52100+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
52101+ {
52102+ void *func = fn_handler[value];
52103+ if (func == fn_show_state || func == fn_show_ptregs ||
52104+ func == fn_show_mem)
52105+ return;
52106+ }
52107+#endif
52108+
52109 fn_handler[value](vc);
52110 }
52111
52112@@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
52113 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
52114 return -EFAULT;
52115
52116- if (!capable(CAP_SYS_TTY_CONFIG))
52117- perm = 0;
52118-
52119 switch (cmd) {
52120 case KDGKBENT:
52121 /* Ensure another thread doesn't free it under us */
52122@@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
52123 spin_unlock_irqrestore(&kbd_event_lock, flags);
52124 return put_user(val, &user_kbe->kb_value);
52125 case KDSKBENT:
52126+ if (!capable(CAP_SYS_TTY_CONFIG))
52127+ perm = 0;
52128+
52129 if (!perm)
52130 return -EPERM;
52131 if (!i && v == K_NOSUCHMAP) {
52132@@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
52133 int i, j, k;
52134 int ret;
52135
52136- if (!capable(CAP_SYS_TTY_CONFIG))
52137- perm = 0;
52138-
52139 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
52140 if (!kbs) {
52141 ret = -ENOMEM;
52142@@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
52143 kfree(kbs);
52144 return ((p && *p) ? -EOVERFLOW : 0);
52145 case KDSKBSENT:
52146+ if (!capable(CAP_SYS_TTY_CONFIG))
52147+ perm = 0;
52148+
52149 if (!perm) {
52150 ret = -EPERM;
52151 goto reterr;
52152diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
52153index a673e5b..36e5d32 100644
52154--- a/drivers/uio/uio.c
52155+++ b/drivers/uio/uio.c
52156@@ -25,6 +25,7 @@
52157 #include <linux/kobject.h>
52158 #include <linux/cdev.h>
52159 #include <linux/uio_driver.h>
52160+#include <asm/local.h>
52161
52162 #define UIO_MAX_DEVICES (1U << MINORBITS)
52163
52164@@ -32,7 +33,7 @@ struct uio_device {
52165 struct module *owner;
52166 struct device *dev;
52167 int minor;
52168- atomic_t event;
52169+ atomic_unchecked_t event;
52170 struct fasync_struct *async_queue;
52171 wait_queue_head_t wait;
52172 struct uio_info *info;
52173@@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
52174 struct device_attribute *attr, char *buf)
52175 {
52176 struct uio_device *idev = dev_get_drvdata(dev);
52177- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
52178+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
52179 }
52180 static DEVICE_ATTR_RO(event);
52181
52182@@ -405,7 +406,7 @@ void uio_event_notify(struct uio_info *info)
52183 {
52184 struct uio_device *idev = info->uio_dev;
52185
52186- atomic_inc(&idev->event);
52187+ atomic_inc_unchecked(&idev->event);
52188 wake_up_interruptible(&idev->wait);
52189 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
52190 }
52191@@ -458,7 +459,7 @@ static int uio_open(struct inode *inode, struct file *filep)
52192 }
52193
52194 listener->dev = idev;
52195- listener->event_count = atomic_read(&idev->event);
52196+ listener->event_count = atomic_read_unchecked(&idev->event);
52197 filep->private_data = listener;
52198
52199 if (idev->info->open) {
52200@@ -509,7 +510,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
52201 return -EIO;
52202
52203 poll_wait(filep, &idev->wait, wait);
52204- if (listener->event_count != atomic_read(&idev->event))
52205+ if (listener->event_count != atomic_read_unchecked(&idev->event))
52206 return POLLIN | POLLRDNORM;
52207 return 0;
52208 }
52209@@ -534,7 +535,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
52210 do {
52211 set_current_state(TASK_INTERRUPTIBLE);
52212
52213- event_count = atomic_read(&idev->event);
52214+ event_count = atomic_read_unchecked(&idev->event);
52215 if (event_count != listener->event_count) {
52216 if (copy_to_user(buf, &event_count, count))
52217 retval = -EFAULT;
52218@@ -591,9 +592,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
52219 static int uio_find_mem_index(struct vm_area_struct *vma)
52220 {
52221 struct uio_device *idev = vma->vm_private_data;
52222+ unsigned long size;
52223
52224 if (vma->vm_pgoff < MAX_UIO_MAPS) {
52225- if (idev->info->mem[vma->vm_pgoff].size == 0)
52226+ size = idev->info->mem[vma->vm_pgoff].size;
52227+ if (size == 0)
52228+ return -1;
52229+ if (vma->vm_end - vma->vm_start > size)
52230 return -1;
52231 return (int)vma->vm_pgoff;
52232 }
52233@@ -825,7 +830,7 @@ int __uio_register_device(struct module *owner,
52234 idev->owner = owner;
52235 idev->info = info;
52236 init_waitqueue_head(&idev->wait);
52237- atomic_set(&idev->event, 0);
52238+ atomic_set_unchecked(&idev->event, 0);
52239
52240 ret = uio_get_minor(idev);
52241 if (ret)
52242diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
52243index 813d4d3..a71934f 100644
52244--- a/drivers/usb/atm/cxacru.c
52245+++ b/drivers/usb/atm/cxacru.c
52246@@ -472,7 +472,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
52247 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
52248 if (ret < 2)
52249 return -EINVAL;
52250- if (index < 0 || index > 0x7f)
52251+ if (index > 0x7f)
52252 return -EINVAL;
52253 pos += tmp;
52254
52255diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
52256index dada014..1d0d517 100644
52257--- a/drivers/usb/atm/usbatm.c
52258+++ b/drivers/usb/atm/usbatm.c
52259@@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52260 if (printk_ratelimit())
52261 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
52262 __func__, vpi, vci);
52263- atomic_inc(&vcc->stats->rx_err);
52264+ atomic_inc_unchecked(&vcc->stats->rx_err);
52265 return;
52266 }
52267
52268@@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52269 if (length > ATM_MAX_AAL5_PDU) {
52270 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
52271 __func__, length, vcc);
52272- atomic_inc(&vcc->stats->rx_err);
52273+ atomic_inc_unchecked(&vcc->stats->rx_err);
52274 goto out;
52275 }
52276
52277@@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52278 if (sarb->len < pdu_length) {
52279 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
52280 __func__, pdu_length, sarb->len, vcc);
52281- atomic_inc(&vcc->stats->rx_err);
52282+ atomic_inc_unchecked(&vcc->stats->rx_err);
52283 goto out;
52284 }
52285
52286 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
52287 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
52288 __func__, vcc);
52289- atomic_inc(&vcc->stats->rx_err);
52290+ atomic_inc_unchecked(&vcc->stats->rx_err);
52291 goto out;
52292 }
52293
52294@@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52295 if (printk_ratelimit())
52296 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
52297 __func__, length);
52298- atomic_inc(&vcc->stats->rx_drop);
52299+ atomic_inc_unchecked(&vcc->stats->rx_drop);
52300 goto out;
52301 }
52302
52303@@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52304
52305 vcc->push(vcc, skb);
52306
52307- atomic_inc(&vcc->stats->rx);
52308+ atomic_inc_unchecked(&vcc->stats->rx);
52309 out:
52310 skb_trim(sarb, 0);
52311 }
52312@@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
52313 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
52314
52315 usbatm_pop(vcc, skb);
52316- atomic_inc(&vcc->stats->tx);
52317+ atomic_inc_unchecked(&vcc->stats->tx);
52318
52319 skb = skb_dequeue(&instance->sndqueue);
52320 }
52321@@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page
52322 if (!left--)
52323 return sprintf(page,
52324 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
52325- atomic_read(&atm_dev->stats.aal5.tx),
52326- atomic_read(&atm_dev->stats.aal5.tx_err),
52327- atomic_read(&atm_dev->stats.aal5.rx),
52328- atomic_read(&atm_dev->stats.aal5.rx_err),
52329- atomic_read(&atm_dev->stats.aal5.rx_drop));
52330+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
52331+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
52332+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
52333+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
52334+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
52335
52336 if (!left--) {
52337 if (instance->disconnected)
52338diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
52339index 2a3bbdf..91d72cf 100644
52340--- a/drivers/usb/core/devices.c
52341+++ b/drivers/usb/core/devices.c
52342@@ -126,7 +126,7 @@ static const char format_endpt[] =
52343 * time it gets called.
52344 */
52345 static struct device_connect_event {
52346- atomic_t count;
52347+ atomic_unchecked_t count;
52348 wait_queue_head_t wait;
52349 } device_event = {
52350 .count = ATOMIC_INIT(1),
52351@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
52352
52353 void usbfs_conn_disc_event(void)
52354 {
52355- atomic_add(2, &device_event.count);
52356+ atomic_add_unchecked(2, &device_event.count);
52357 wake_up(&device_event.wait);
52358 }
52359
52360@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
52361
52362 poll_wait(file, &device_event.wait, wait);
52363
52364- event_count = atomic_read(&device_event.count);
52365+ event_count = atomic_read_unchecked(&device_event.count);
52366 if (file->f_version != event_count) {
52367 file->f_version = event_count;
52368 return POLLIN | POLLRDNORM;
52369diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
52370index 90e18f6..5eeda46 100644
52371--- a/drivers/usb/core/devio.c
52372+++ b/drivers/usb/core/devio.c
52373@@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
52374 struct dev_state *ps = file->private_data;
52375 struct usb_device *dev = ps->dev;
52376 ssize_t ret = 0;
52377- unsigned len;
52378+ size_t len;
52379 loff_t pos;
52380 int i;
52381
52382@@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
52383 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
52384 struct usb_config_descriptor *config =
52385 (struct usb_config_descriptor *)dev->rawdescriptors[i];
52386- unsigned int length = le16_to_cpu(config->wTotalLength);
52387+ size_t length = le16_to_cpu(config->wTotalLength);
52388
52389 if (*ppos < pos + length) {
52390
52391 /* The descriptor may claim to be longer than it
52392 * really is. Here is the actual allocated length. */
52393- unsigned alloclen =
52394+ size_t alloclen =
52395 le16_to_cpu(dev->config[i].desc.wTotalLength);
52396
52397- len = length - (*ppos - pos);
52398+ len = length + pos - *ppos;
52399 if (len > nbytes)
52400 len = nbytes;
52401
52402 /* Simply don't write (skip over) unallocated parts */
52403 if (alloclen > (*ppos - pos)) {
52404- alloclen -= (*ppos - pos);
52405+ alloclen = alloclen + pos - *ppos;
52406 if (copy_to_user(buf,
52407 dev->rawdescriptors[i] + (*ppos - pos),
52408 min(len, alloclen))) {
52409diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
52410index 2518c32..1c201bb 100644
52411--- a/drivers/usb/core/hcd.c
52412+++ b/drivers/usb/core/hcd.c
52413@@ -1550,7 +1550,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
52414 */
52415 usb_get_urb(urb);
52416 atomic_inc(&urb->use_count);
52417- atomic_inc(&urb->dev->urbnum);
52418+ atomic_inc_unchecked(&urb->dev->urbnum);
52419 usbmon_urb_submit(&hcd->self, urb);
52420
52421 /* NOTE requirements on root-hub callers (usbfs and the hub
52422@@ -1577,7 +1577,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
52423 urb->hcpriv = NULL;
52424 INIT_LIST_HEAD(&urb->urb_list);
52425 atomic_dec(&urb->use_count);
52426- atomic_dec(&urb->dev->urbnum);
52427+ atomic_dec_unchecked(&urb->dev->urbnum);
52428 if (atomic_read(&urb->reject))
52429 wake_up(&usb_kill_urb_queue);
52430 usb_put_urb(urb);
52431diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
52432index d498d03..e26f959 100644
52433--- a/drivers/usb/core/hub.c
52434+++ b/drivers/usb/core/hub.c
52435@@ -27,6 +27,7 @@
52436 #include <linux/freezer.h>
52437 #include <linux/random.h>
52438 #include <linux/pm_qos.h>
52439+#include <linux/grsecurity.h>
52440
52441 #include <asm/uaccess.h>
52442 #include <asm/byteorder.h>
52443@@ -4472,6 +4473,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
52444 goto done;
52445 return;
52446 }
52447+
52448+ if (gr_handle_new_usb())
52449+ goto done;
52450+
52451 if (hub_is_superspeed(hub->hdev))
52452 unit_load = 150;
52453 else
52454diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
52455index f829a1a..e6c334a 100644
52456--- a/drivers/usb/core/message.c
52457+++ b/drivers/usb/core/message.c
52458@@ -128,7 +128,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
52459 * Return: If successful, the number of bytes transferred. Otherwise, a negative
52460 * error number.
52461 */
52462-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
52463+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
52464 __u8 requesttype, __u16 value, __u16 index, void *data,
52465 __u16 size, int timeout)
52466 {
52467@@ -180,7 +180,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
52468 * If successful, 0. Otherwise a negative error number. The number of actual
52469 * bytes transferred will be stored in the @actual_length paramater.
52470 */
52471-int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
52472+int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
52473 void *data, int len, int *actual_length, int timeout)
52474 {
52475 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
52476@@ -220,7 +220,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
52477 * bytes transferred will be stored in the @actual_length parameter.
52478 *
52479 */
52480-int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
52481+int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
52482 void *data, int len, int *actual_length, int timeout)
52483 {
52484 struct urb *urb;
52485diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
52486index 1236c60..d47a51c 100644
52487--- a/drivers/usb/core/sysfs.c
52488+++ b/drivers/usb/core/sysfs.c
52489@@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
52490 struct usb_device *udev;
52491
52492 udev = to_usb_device(dev);
52493- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
52494+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
52495 }
52496 static DEVICE_ATTR_RO(urbnum);
52497
52498diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
52499index 4d11449..f4ccabf 100644
52500--- a/drivers/usb/core/usb.c
52501+++ b/drivers/usb/core/usb.c
52502@@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
52503 set_dev_node(&dev->dev, dev_to_node(bus->controller));
52504 dev->state = USB_STATE_ATTACHED;
52505 dev->lpm_disable_count = 1;
52506- atomic_set(&dev->urbnum, 0);
52507+ atomic_set_unchecked(&dev->urbnum, 0);
52508
52509 INIT_LIST_HEAD(&dev->ep0.urb_list);
52510 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
52511diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
52512index 2da0a5a..4870e09 100644
52513--- a/drivers/usb/dwc3/gadget.c
52514+++ b/drivers/usb/dwc3/gadget.c
52515@@ -532,8 +532,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
52516 if (!usb_endpoint_xfer_isoc(desc))
52517 return 0;
52518
52519- memset(&trb_link, 0, sizeof(trb_link));
52520-
52521 /* Link TRB for ISOC. The HWO bit is never reset */
52522 trb_st_hw = &dep->trb_pool[0];
52523
52524diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
52525index 8cfc319..4868255 100644
52526--- a/drivers/usb/early/ehci-dbgp.c
52527+++ b/drivers/usb/early/ehci-dbgp.c
52528@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
52529
52530 #ifdef CONFIG_KGDB
52531 static struct kgdb_io kgdbdbgp_io_ops;
52532-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
52533+static struct kgdb_io kgdbdbgp_io_ops_console;
52534+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
52535 #else
52536 #define dbgp_kgdb_mode (0)
52537 #endif
52538@@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
52539 .write_char = kgdbdbgp_write_char,
52540 };
52541
52542+static struct kgdb_io kgdbdbgp_io_ops_console = {
52543+ .name = "kgdbdbgp",
52544+ .read_char = kgdbdbgp_read_char,
52545+ .write_char = kgdbdbgp_write_char,
52546+ .is_console = 1
52547+};
52548+
52549 static int kgdbdbgp_wait_time;
52550
52551 static int __init kgdbdbgp_parse_config(char *str)
52552@@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
52553 ptr++;
52554 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
52555 }
52556- kgdb_register_io_module(&kgdbdbgp_io_ops);
52557- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
52558+ if (early_dbgp_console.index != -1)
52559+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
52560+ else
52561+ kgdb_register_io_module(&kgdbdbgp_io_ops);
52562
52563 return 0;
52564 }
52565diff --git a/drivers/usb/gadget/f_uac1.c b/drivers/usb/gadget/f_uac1.c
52566index 2b4c82d..06a8ee6 100644
52567--- a/drivers/usb/gadget/f_uac1.c
52568+++ b/drivers/usb/gadget/f_uac1.c
52569@@ -13,6 +13,7 @@
52570 #include <linux/kernel.h>
52571 #include <linux/device.h>
52572 #include <linux/atomic.h>
52573+#include <linux/module.h>
52574
52575 #include "u_uac1.h"
52576
52577diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
52578index ad0aca8..8ff84865 100644
52579--- a/drivers/usb/gadget/u_serial.c
52580+++ b/drivers/usb/gadget/u_serial.c
52581@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
52582 spin_lock_irq(&port->port_lock);
52583
52584 /* already open? Great. */
52585- if (port->port.count) {
52586+ if (atomic_read(&port->port.count)) {
52587 status = 0;
52588- port->port.count++;
52589+ atomic_inc(&port->port.count);
52590
52591 /* currently opening/closing? wait ... */
52592 } else if (port->openclose) {
52593@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
52594 tty->driver_data = port;
52595 port->port.tty = tty;
52596
52597- port->port.count = 1;
52598+ atomic_set(&port->port.count, 1);
52599 port->openclose = false;
52600
52601 /* if connected, start the I/O stream */
52602@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
52603
52604 spin_lock_irq(&port->port_lock);
52605
52606- if (port->port.count != 1) {
52607- if (port->port.count == 0)
52608+ if (atomic_read(&port->port.count) != 1) {
52609+ if (atomic_read(&port->port.count) == 0)
52610 WARN_ON(1);
52611 else
52612- --port->port.count;
52613+ atomic_dec(&port->port.count);
52614 goto exit;
52615 }
52616
52617@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
52618 * and sleep if necessary
52619 */
52620 port->openclose = true;
52621- port->port.count = 0;
52622+ atomic_set(&port->port.count, 0);
52623
52624 gser = port->port_usb;
52625 if (gser && gser->disconnect)
52626@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
52627 int cond;
52628
52629 spin_lock_irq(&port->port_lock);
52630- cond = (port->port.count == 0) && !port->openclose;
52631+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
52632 spin_unlock_irq(&port->port_lock);
52633 return cond;
52634 }
52635@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
52636 /* if it's already open, start I/O ... and notify the serial
52637 * protocol about open/close status (connect/disconnect).
52638 */
52639- if (port->port.count) {
52640+ if (atomic_read(&port->port.count)) {
52641 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
52642 gs_start_io(port);
52643 if (gser->connect)
52644@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
52645
52646 port->port_usb = NULL;
52647 gser->ioport = NULL;
52648- if (port->port.count > 0 || port->openclose) {
52649+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
52650 wake_up_interruptible(&port->drain_wait);
52651 if (port->port.tty)
52652 tty_hangup(port->port.tty);
52653@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
52654
52655 /* finally, free any unused/unusable I/O buffers */
52656 spin_lock_irqsave(&port->port_lock, flags);
52657- if (port->port.count == 0 && !port->openclose)
52658+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
52659 gs_buf_free(&port->port_write_buf);
52660 gs_free_requests(gser->out, &port->read_pool, NULL);
52661 gs_free_requests(gser->out, &port->read_queue, NULL);
52662diff --git a/drivers/usb/gadget/u_uac1.c b/drivers/usb/gadget/u_uac1.c
52663index 7a55fea..cc0ed4f 100644
52664--- a/drivers/usb/gadget/u_uac1.c
52665+++ b/drivers/usb/gadget/u_uac1.c
52666@@ -16,6 +16,7 @@
52667 #include <linux/ctype.h>
52668 #include <linux/random.h>
52669 #include <linux/syscalls.h>
52670+#include <linux/module.h>
52671
52672 #include "u_uac1.h"
52673
52674diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
52675index 7ae0c4d..35521b7 100644
52676--- a/drivers/usb/host/ehci-hub.c
52677+++ b/drivers/usb/host/ehci-hub.c
52678@@ -780,7 +780,7 @@ static struct urb *request_single_step_set_feature_urb(
52679 urb->transfer_flags = URB_DIR_IN;
52680 usb_get_urb(urb);
52681 atomic_inc(&urb->use_count);
52682- atomic_inc(&urb->dev->urbnum);
52683+ atomic_inc_unchecked(&urb->dev->urbnum);
52684 urb->setup_dma = dma_map_single(
52685 hcd->self.controller,
52686 urb->setup_packet,
52687@@ -847,7 +847,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
52688 urb->status = -EINPROGRESS;
52689 usb_get_urb(urb);
52690 atomic_inc(&urb->use_count);
52691- atomic_inc(&urb->dev->urbnum);
52692+ atomic_inc_unchecked(&urb->dev->urbnum);
52693 retval = submit_single_step_set_feature(hcd, urb, 0);
52694 if (!retval && !wait_for_completion_timeout(&done,
52695 msecs_to_jiffies(2000))) {
52696diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
52697index ba6a5d6..f88f7f3 100644
52698--- a/drivers/usb/misc/appledisplay.c
52699+++ b/drivers/usb/misc/appledisplay.c
52700@@ -83,7 +83,7 @@ struct appledisplay {
52701 spinlock_t lock;
52702 };
52703
52704-static atomic_t count_displays = ATOMIC_INIT(0);
52705+static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
52706 static struct workqueue_struct *wq;
52707
52708 static void appledisplay_complete(struct urb *urb)
52709@@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
52710
52711 /* Register backlight device */
52712 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
52713- atomic_inc_return(&count_displays) - 1);
52714+ atomic_inc_return_unchecked(&count_displays) - 1);
52715 memset(&props, 0, sizeof(struct backlight_properties));
52716 props.type = BACKLIGHT_RAW;
52717 props.max_brightness = 0xff;
52718diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
52719index 8d7fc48..01c4986 100644
52720--- a/drivers/usb/serial/console.c
52721+++ b/drivers/usb/serial/console.c
52722@@ -123,7 +123,7 @@ static int usb_console_setup(struct console *co, char *options)
52723
52724 info->port = port;
52725
52726- ++port->port.count;
52727+ atomic_inc(&port->port.count);
52728 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
52729 if (serial->type->set_termios) {
52730 /*
52731@@ -167,7 +167,7 @@ static int usb_console_setup(struct console *co, char *options)
52732 }
52733 /* Now that any required fake tty operations are completed restore
52734 * the tty port count */
52735- --port->port.count;
52736+ atomic_dec(&port->port.count);
52737 /* The console is special in terms of closing the device so
52738 * indicate this port is now acting as a system console. */
52739 port->port.console = 1;
52740@@ -180,7 +180,7 @@ static int usb_console_setup(struct console *co, char *options)
52741 free_tty:
52742 kfree(tty);
52743 reset_open_count:
52744- port->port.count = 0;
52745+ atomic_set(&port->port.count, 0);
52746 usb_autopm_put_interface(serial->interface);
52747 error_get_interface:
52748 usb_serial_put(serial);
52749@@ -191,7 +191,7 @@ static int usb_console_setup(struct console *co, char *options)
52750 static void usb_console_write(struct console *co,
52751 const char *buf, unsigned count)
52752 {
52753- static struct usbcons_info *info = &usbcons_info;
52754+ struct usbcons_info *info = &usbcons_info;
52755 struct usb_serial_port *port = info->port;
52756 struct usb_serial *serial;
52757 int retval = -ENODEV;
52758diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
52759index 75f70f0..d467e1a 100644
52760--- a/drivers/usb/storage/usb.h
52761+++ b/drivers/usb/storage/usb.h
52762@@ -63,7 +63,7 @@ struct us_unusual_dev {
52763 __u8 useProtocol;
52764 __u8 useTransport;
52765 int (*initFunction)(struct us_data *);
52766-};
52767+} __do_const;
52768
52769
52770 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
52771diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
52772index a2ef84b..aa7c2b8 100644
52773--- a/drivers/usb/wusbcore/wa-hc.h
52774+++ b/drivers/usb/wusbcore/wa-hc.h
52775@@ -225,7 +225,7 @@ struct wahc {
52776 spinlock_t xfer_list_lock;
52777 struct work_struct xfer_enqueue_work;
52778 struct work_struct xfer_error_work;
52779- atomic_t xfer_id_count;
52780+ atomic_unchecked_t xfer_id_count;
52781
52782 kernel_ulong_t quirks;
52783 };
52784@@ -287,7 +287,7 @@ static inline void wa_init(struct wahc *wa)
52785 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
52786 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
52787 wa->dto_in_use = 0;
52788- atomic_set(&wa->xfer_id_count, 1);
52789+ atomic_set_unchecked(&wa->xfer_id_count, 1);
52790 }
52791
52792 /**
52793diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
52794index 3cd96e9..bd7c58d 100644
52795--- a/drivers/usb/wusbcore/wa-xfer.c
52796+++ b/drivers/usb/wusbcore/wa-xfer.c
52797@@ -312,7 +312,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
52798 */
52799 static void wa_xfer_id_init(struct wa_xfer *xfer)
52800 {
52801- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
52802+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
52803 }
52804
52805 /* Return the xfer's ID. */
52806diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
52807index 21271d8..45b55a0 100644
52808--- a/drivers/vfio/vfio.c
52809+++ b/drivers/vfio/vfio.c
52810@@ -487,7 +487,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
52811 return 0;
52812
52813 /* TODO Prevent device auto probing */
52814- WARN("Device %s added to live group %d!\n", dev_name(dev),
52815+ WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
52816 iommu_group_id(group->iommu_group));
52817
52818 return 0;
52819diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
52820index 5174eba..451e6bc 100644
52821--- a/drivers/vhost/vringh.c
52822+++ b/drivers/vhost/vringh.c
52823@@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
52824 /* Userspace access helpers: in this case, addresses are really userspace. */
52825 static inline int getu16_user(u16 *val, const u16 *p)
52826 {
52827- return get_user(*val, (__force u16 __user *)p);
52828+ return get_user(*val, (u16 __force_user *)p);
52829 }
52830
52831 static inline int putu16_user(u16 *p, u16 val)
52832 {
52833- return put_user(val, (__force u16 __user *)p);
52834+ return put_user(val, (u16 __force_user *)p);
52835 }
52836
52837 static inline int copydesc_user(void *dst, const void *src, size_t len)
52838 {
52839- return copy_from_user(dst, (__force void __user *)src, len) ?
52840+ return copy_from_user(dst, (void __force_user *)src, len) ?
52841 -EFAULT : 0;
52842 }
52843
52844@@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
52845 const struct vring_used_elem *src,
52846 unsigned int num)
52847 {
52848- return copy_to_user((__force void __user *)dst, src,
52849+ return copy_to_user((void __force_user *)dst, src,
52850 sizeof(*dst) * num) ? -EFAULT : 0;
52851 }
52852
52853 static inline int xfer_from_user(void *src, void *dst, size_t len)
52854 {
52855- return copy_from_user(dst, (__force void __user *)src, len) ?
52856+ return copy_from_user(dst, (void __force_user *)src, len) ?
52857 -EFAULT : 0;
52858 }
52859
52860 static inline int xfer_to_user(void *dst, void *src, size_t len)
52861 {
52862- return copy_to_user((__force void __user *)dst, src, len) ?
52863+ return copy_to_user((void __force_user *)dst, src, len) ?
52864 -EFAULT : 0;
52865 }
52866
52867@@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
52868 vrh->last_used_idx = 0;
52869 vrh->vring.num = num;
52870 /* vring expects kernel addresses, but only used via accessors. */
52871- vrh->vring.desc = (__force struct vring_desc *)desc;
52872- vrh->vring.avail = (__force struct vring_avail *)avail;
52873- vrh->vring.used = (__force struct vring_used *)used;
52874+ vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
52875+ vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
52876+ vrh->vring.used = (__force_kernel struct vring_used *)used;
52877 return 0;
52878 }
52879 EXPORT_SYMBOL(vringh_init_user);
52880@@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
52881
52882 static inline int putu16_kern(u16 *p, u16 val)
52883 {
52884- ACCESS_ONCE(*p) = val;
52885+ ACCESS_ONCE_RW(*p) = val;
52886 return 0;
52887 }
52888
52889diff --git a/drivers/video/arcfb.c b/drivers/video/arcfb.c
52890index 1b0b233..6f34c2c 100644
52891--- a/drivers/video/arcfb.c
52892+++ b/drivers/video/arcfb.c
52893@@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
52894 return -ENOSPC;
52895
52896 err = 0;
52897- if ((count + p) > fbmemlength) {
52898+ if (count > (fbmemlength - p)) {
52899 count = fbmemlength - p;
52900 err = -ENOSPC;
52901 }
52902diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
52903index 52108be..c7c110d 100644
52904--- a/drivers/video/aty/aty128fb.c
52905+++ b/drivers/video/aty/aty128fb.c
52906@@ -149,7 +149,7 @@ enum {
52907 };
52908
52909 /* Must match above enum */
52910-static char * const r128_family[] = {
52911+static const char * const r128_family[] = {
52912 "AGP",
52913 "PCI",
52914 "PRO AGP",
52915diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
52916index 28fafbf..ae91651 100644
52917--- a/drivers/video/aty/atyfb_base.c
52918+++ b/drivers/video/aty/atyfb_base.c
52919@@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
52920 par->accel_flags = var->accel_flags; /* hack */
52921
52922 if (var->accel_flags) {
52923- info->fbops->fb_sync = atyfb_sync;
52924+ pax_open_kernel();
52925+ *(void **)&info->fbops->fb_sync = atyfb_sync;
52926+ pax_close_kernel();
52927 info->flags &= ~FBINFO_HWACCEL_DISABLED;
52928 } else {
52929- info->fbops->fb_sync = NULL;
52930+ pax_open_kernel();
52931+ *(void **)&info->fbops->fb_sync = NULL;
52932+ pax_close_kernel();
52933 info->flags |= FBINFO_HWACCEL_DISABLED;
52934 }
52935
52936diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
52937index 95ec042..e6affdd 100644
52938--- a/drivers/video/aty/mach64_cursor.c
52939+++ b/drivers/video/aty/mach64_cursor.c
52940@@ -7,6 +7,7 @@
52941 #include <linux/string.h>
52942
52943 #include <asm/io.h>
52944+#include <asm/pgtable.h>
52945
52946 #ifdef __sparc__
52947 #include <asm/fbio.h>
52948@@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
52949 info->sprite.buf_align = 16; /* and 64 lines tall. */
52950 info->sprite.flags = FB_PIXMAP_IO;
52951
52952- info->fbops->fb_cursor = atyfb_cursor;
52953+ pax_open_kernel();
52954+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
52955+ pax_close_kernel();
52956
52957 return 0;
52958 }
52959diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
52960index 84a110a..96312c3 100644
52961--- a/drivers/video/backlight/kb3886_bl.c
52962+++ b/drivers/video/backlight/kb3886_bl.c
52963@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
52964 static unsigned long kb3886bl_flags;
52965 #define KB3886BL_SUSPENDED 0x01
52966
52967-static struct dmi_system_id kb3886bl_device_table[] __initdata = {
52968+static const struct dmi_system_id kb3886bl_device_table[] __initconst = {
52969 {
52970 .ident = "Sahara Touch-iT",
52971 .matches = {
52972diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
52973index 900aa4e..6d49418 100644
52974--- a/drivers/video/fb_defio.c
52975+++ b/drivers/video/fb_defio.c
52976@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
52977
52978 BUG_ON(!fbdefio);
52979 mutex_init(&fbdefio->lock);
52980- info->fbops->fb_mmap = fb_deferred_io_mmap;
52981+ pax_open_kernel();
52982+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
52983+ pax_close_kernel();
52984 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
52985 INIT_LIST_HEAD(&fbdefio->pagelist);
52986 if (fbdefio->delay == 0) /* set a default of 1 s */
52987@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
52988 page->mapping = NULL;
52989 }
52990
52991- info->fbops->fb_mmap = NULL;
52992+ *(void **)&info->fbops->fb_mmap = NULL;
52993 mutex_destroy(&fbdefio->lock);
52994 }
52995 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
52996diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
52997index 7309ac7..be3c49c 100644
52998--- a/drivers/video/fbmem.c
52999+++ b/drivers/video/fbmem.c
53000@@ -433,7 +433,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
53001 image->dx += image->width + 8;
53002 }
53003 } else if (rotate == FB_ROTATE_UD) {
53004- for (x = 0; x < num && image->dx >= 0; x++) {
53005+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
53006 info->fbops->fb_imageblit(info, image);
53007 image->dx -= image->width + 8;
53008 }
53009@@ -445,7 +445,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
53010 image->dy += image->height + 8;
53011 }
53012 } else if (rotate == FB_ROTATE_CCW) {
53013- for (x = 0; x < num && image->dy >= 0; x++) {
53014+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
53015 info->fbops->fb_imageblit(info, image);
53016 image->dy -= image->height + 8;
53017 }
53018@@ -1179,7 +1179,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
53019 return -EFAULT;
53020 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
53021 return -EINVAL;
53022- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
53023+ if (con2fb.framebuffer >= FB_MAX)
53024 return -EINVAL;
53025 if (!registered_fb[con2fb.framebuffer])
53026 request_module("fb%d", con2fb.framebuffer);
53027@@ -1300,7 +1300,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
53028 __u32 data;
53029 int err;
53030
53031- err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
53032+ err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
53033
53034 data = (__u32) (unsigned long) fix->smem_start;
53035 err |= put_user(data, &fix32->smem_start);
53036diff --git a/drivers/video/hyperv_fb.c b/drivers/video/hyperv_fb.c
53037index 130708f..cdac1a9 100644
53038--- a/drivers/video/hyperv_fb.c
53039+++ b/drivers/video/hyperv_fb.c
53040@@ -233,7 +233,7 @@ static uint screen_fb_size;
53041 static inline int synthvid_send(struct hv_device *hdev,
53042 struct synthvid_msg *msg)
53043 {
53044- static atomic64_t request_id = ATOMIC64_INIT(0);
53045+ static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
53046 int ret;
53047
53048 msg->pipe_hdr.type = PIPE_MSG_DATA;
53049@@ -241,7 +241,7 @@ static inline int synthvid_send(struct hv_device *hdev,
53050
53051 ret = vmbus_sendpacket(hdev->channel, msg,
53052 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
53053- atomic64_inc_return(&request_id),
53054+ atomic64_inc_return_unchecked(&request_id),
53055 VM_PKT_DATA_INBAND, 0);
53056
53057 if (ret)
53058diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
53059index 7672d2e..b56437f 100644
53060--- a/drivers/video/i810/i810_accel.c
53061+++ b/drivers/video/i810/i810_accel.c
53062@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
53063 }
53064 }
53065 printk("ringbuffer lockup!!!\n");
53066+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
53067 i810_report_error(mmio);
53068 par->dev_flags |= LOCKUP;
53069 info->pixmap.scan_align = 1;
53070diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
53071index 3c14e43..2630570 100644
53072--- a/drivers/video/logo/logo_linux_clut224.ppm
53073+++ b/drivers/video/logo/logo_linux_clut224.ppm
53074@@ -2,1603 +2,1123 @@ P3
53075 # Standard 224-color Linux logo
53076 80 80
53077 255
53078- 0 0 0 0 0 0 0 0 0 0 0 0
53079- 0 0 0 0 0 0 0 0 0 0 0 0
53080- 0 0 0 0 0 0 0 0 0 0 0 0
53081- 0 0 0 0 0 0 0 0 0 0 0 0
53082- 0 0 0 0 0 0 0 0 0 0 0 0
53083- 0 0 0 0 0 0 0 0 0 0 0 0
53084- 0 0 0 0 0 0 0 0 0 0 0 0
53085- 0 0 0 0 0 0 0 0 0 0 0 0
53086- 0 0 0 0 0 0 0 0 0 0 0 0
53087- 6 6 6 6 6 6 10 10 10 10 10 10
53088- 10 10 10 6 6 6 6 6 6 6 6 6
53089- 0 0 0 0 0 0 0 0 0 0 0 0
53090- 0 0 0 0 0 0 0 0 0 0 0 0
53091- 0 0 0 0 0 0 0 0 0 0 0 0
53092- 0 0 0 0 0 0 0 0 0 0 0 0
53093- 0 0 0 0 0 0 0 0 0 0 0 0
53094- 0 0 0 0 0 0 0 0 0 0 0 0
53095- 0 0 0 0 0 0 0 0 0 0 0 0
53096- 0 0 0 0 0 0 0 0 0 0 0 0
53097- 0 0 0 0 0 0 0 0 0 0 0 0
53098- 0 0 0 0 0 0 0 0 0 0 0 0
53099- 0 0 0 0 0 0 0 0 0 0 0 0
53100- 0 0 0 0 0 0 0 0 0 0 0 0
53101- 0 0 0 0 0 0 0 0 0 0 0 0
53102- 0 0 0 0 0 0 0 0 0 0 0 0
53103- 0 0 0 0 0 0 0 0 0 0 0 0
53104- 0 0 0 0 0 0 0 0 0 0 0 0
53105- 0 0 0 0 0 0 0 0 0 0 0 0
53106- 0 0 0 6 6 6 10 10 10 14 14 14
53107- 22 22 22 26 26 26 30 30 30 34 34 34
53108- 30 30 30 30 30 30 26 26 26 18 18 18
53109- 14 14 14 10 10 10 6 6 6 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 1 0 0 1 0 0 0
53120- 0 0 0 0 0 0 0 0 0 0 0 0
53121- 0 0 0 0 0 0 0 0 0 0 0 0
53122- 0 0 0 0 0 0 0 0 0 0 0 0
53123- 0 0 0 0 0 0 0 0 0 0 0 0
53124- 0 0 0 0 0 0 0 0 0 0 0 0
53125- 0 0 0 0 0 0 0 0 0 0 0 0
53126- 6 6 6 14 14 14 26 26 26 42 42 42
53127- 54 54 54 66 66 66 78 78 78 78 78 78
53128- 78 78 78 74 74 74 66 66 66 54 54 54
53129- 42 42 42 26 26 26 18 18 18 10 10 10
53130- 6 6 6 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 0 0 0 0 0 0 0 0 0 0
53135- 0 0 0 0 0 0 0 0 0 0 0 0
53136- 0 0 0 0 0 0 0 0 0 0 0 0
53137- 0 0 0 0 0 0 0 0 0 0 0 0
53138- 0 0 0 0 0 0 0 0 0 0 0 0
53139- 0 0 1 0 0 0 0 0 0 0 0 0
53140- 0 0 0 0 0 0 0 0 0 0 0 0
53141- 0 0 0 0 0 0 0 0 0 0 0 0
53142- 0 0 0 0 0 0 0 0 0 0 0 0
53143- 0 0 0 0 0 0 0 0 0 0 0 0
53144- 0 0 0 0 0 0 0 0 0 0 0 0
53145- 0 0 0 0 0 0 0 0 0 10 10 10
53146- 22 22 22 42 42 42 66 66 66 86 86 86
53147- 66 66 66 38 38 38 38 38 38 22 22 22
53148- 26 26 26 34 34 34 54 54 54 66 66 66
53149- 86 86 86 70 70 70 46 46 46 26 26 26
53150- 14 14 14 6 6 6 0 0 0 0 0 0
53151- 0 0 0 0 0 0 0 0 0 0 0 0
53152- 0 0 0 0 0 0 0 0 0 0 0 0
53153- 0 0 0 0 0 0 0 0 0 0 0 0
53154- 0 0 0 0 0 0 0 0 0 0 0 0
53155- 0 0 0 0 0 0 0 0 0 0 0 0
53156- 0 0 0 0 0 0 0 0 0 0 0 0
53157- 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 1 0 0 1 0 0 1 0 0 0
53160- 0 0 0 0 0 0 0 0 0 0 0 0
53161- 0 0 0 0 0 0 0 0 0 0 0 0
53162- 0 0 0 0 0 0 0 0 0 0 0 0
53163- 0 0 0 0 0 0 0 0 0 0 0 0
53164- 0 0 0 0 0 0 0 0 0 0 0 0
53165- 0 0 0 0 0 0 10 10 10 26 26 26
53166- 50 50 50 82 82 82 58 58 58 6 6 6
53167- 2 2 6 2 2 6 2 2 6 2 2 6
53168- 2 2 6 2 2 6 2 2 6 2 2 6
53169- 6 6 6 54 54 54 86 86 86 66 66 66
53170- 38 38 38 18 18 18 6 6 6 0 0 0
53171- 0 0 0 0 0 0 0 0 0 0 0 0
53172- 0 0 0 0 0 0 0 0 0 0 0 0
53173- 0 0 0 0 0 0 0 0 0 0 0 0
53174- 0 0 0 0 0 0 0 0 0 0 0 0
53175- 0 0 0 0 0 0 0 0 0 0 0 0
53176- 0 0 0 0 0 0 0 0 0 0 0 0
53177- 0 0 0 0 0 0 0 0 0 0 0 0
53178- 0 0 0 0 0 0 0 0 0 0 0 0
53179- 0 0 0 0 0 0 0 0 0 0 0 0
53180- 0 0 0 0 0 0 0 0 0 0 0 0
53181- 0 0 0 0 0 0 0 0 0 0 0 0
53182- 0 0 0 0 0 0 0 0 0 0 0 0
53183- 0 0 0 0 0 0 0 0 0 0 0 0
53184- 0 0 0 0 0 0 0 0 0 0 0 0
53185- 0 0 0 6 6 6 22 22 22 50 50 50
53186- 78 78 78 34 34 34 2 2 6 2 2 6
53187- 2 2 6 2 2 6 2 2 6 2 2 6
53188- 2 2 6 2 2 6 2 2 6 2 2 6
53189- 2 2 6 2 2 6 6 6 6 70 70 70
53190- 78 78 78 46 46 46 22 22 22 6 6 6
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 1 0 0 1 0 0 1 0 0 0
53200- 0 0 0 0 0 0 0 0 0 0 0 0
53201- 0 0 0 0 0 0 0 0 0 0 0 0
53202- 0 0 0 0 0 0 0 0 0 0 0 0
53203- 0 0 0 0 0 0 0 0 0 0 0 0
53204- 0 0 0 0 0 0 0 0 0 0 0 0
53205- 6 6 6 18 18 18 42 42 42 82 82 82
53206- 26 26 26 2 2 6 2 2 6 2 2 6
53207- 2 2 6 2 2 6 2 2 6 2 2 6
53208- 2 2 6 2 2 6 2 2 6 14 14 14
53209- 46 46 46 34 34 34 6 6 6 2 2 6
53210- 42 42 42 78 78 78 42 42 42 18 18 18
53211- 6 6 6 0 0 0 0 0 0 0 0 0
53212- 0 0 0 0 0 0 0 0 0 0 0 0
53213- 0 0 0 0 0 0 0 0 0 0 0 0
53214- 0 0 0 0 0 0 0 0 0 0 0 0
53215- 0 0 0 0 0 0 0 0 0 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 1 0 0 0 0 0 1 0 0 0
53220- 0 0 0 0 0 0 0 0 0 0 0 0
53221- 0 0 0 0 0 0 0 0 0 0 0 0
53222- 0 0 0 0 0 0 0 0 0 0 0 0
53223- 0 0 0 0 0 0 0 0 0 0 0 0
53224- 0 0 0 0 0 0 0 0 0 0 0 0
53225- 10 10 10 30 30 30 66 66 66 58 58 58
53226- 2 2 6 2 2 6 2 2 6 2 2 6
53227- 2 2 6 2 2 6 2 2 6 2 2 6
53228- 2 2 6 2 2 6 2 2 6 26 26 26
53229- 86 86 86 101 101 101 46 46 46 10 10 10
53230- 2 2 6 58 58 58 70 70 70 34 34 34
53231- 10 10 10 0 0 0 0 0 0 0 0 0
53232- 0 0 0 0 0 0 0 0 0 0 0 0
53233- 0 0 0 0 0 0 0 0 0 0 0 0
53234- 0 0 0 0 0 0 0 0 0 0 0 0
53235- 0 0 0 0 0 0 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 1 0 0 1 0 0 1 0 0 0
53240- 0 0 0 0 0 0 0 0 0 0 0 0
53241- 0 0 0 0 0 0 0 0 0 0 0 0
53242- 0 0 0 0 0 0 0 0 0 0 0 0
53243- 0 0 0 0 0 0 0 0 0 0 0 0
53244- 0 0 0 0 0 0 0 0 0 0 0 0
53245- 14 14 14 42 42 42 86 86 86 10 10 10
53246- 2 2 6 2 2 6 2 2 6 2 2 6
53247- 2 2 6 2 2 6 2 2 6 2 2 6
53248- 2 2 6 2 2 6 2 2 6 30 30 30
53249- 94 94 94 94 94 94 58 58 58 26 26 26
53250- 2 2 6 6 6 6 78 78 78 54 54 54
53251- 22 22 22 6 6 6 0 0 0 0 0 0
53252- 0 0 0 0 0 0 0 0 0 0 0 0
53253- 0 0 0 0 0 0 0 0 0 0 0 0
53254- 0 0 0 0 0 0 0 0 0 0 0 0
53255- 0 0 0 0 0 0 0 0 0 0 0 0
53256- 0 0 0 0 0 0 0 0 0 0 0 0
53257- 0 0 0 0 0 0 0 0 0 0 0 0
53258- 0 0 0 0 0 0 0 0 0 0 0 0
53259- 0 0 0 0 0 0 0 0 0 0 0 0
53260- 0 0 0 0 0 0 0 0 0 0 0 0
53261- 0 0 0 0 0 0 0 0 0 0 0 0
53262- 0 0 0 0 0 0 0 0 0 0 0 0
53263- 0 0 0 0 0 0 0 0 0 0 0 0
53264- 0 0 0 0 0 0 0 0 0 6 6 6
53265- 22 22 22 62 62 62 62 62 62 2 2 6
53266- 2 2 6 2 2 6 2 2 6 2 2 6
53267- 2 2 6 2 2 6 2 2 6 2 2 6
53268- 2 2 6 2 2 6 2 2 6 26 26 26
53269- 54 54 54 38 38 38 18 18 18 10 10 10
53270- 2 2 6 2 2 6 34 34 34 82 82 82
53271- 38 38 38 14 14 14 0 0 0 0 0 0
53272- 0 0 0 0 0 0 0 0 0 0 0 0
53273- 0 0 0 0 0 0 0 0 0 0 0 0
53274- 0 0 0 0 0 0 0 0 0 0 0 0
53275- 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 1 0 0 1 0 0 0
53280- 0 0 0 0 0 0 0 0 0 0 0 0
53281- 0 0 0 0 0 0 0 0 0 0 0 0
53282- 0 0 0 0 0 0 0 0 0 0 0 0
53283- 0 0 0 0 0 0 0 0 0 0 0 0
53284- 0 0 0 0 0 0 0 0 0 6 6 6
53285- 30 30 30 78 78 78 30 30 30 2 2 6
53286- 2 2 6 2 2 6 2 2 6 2 2 6
53287- 2 2 6 2 2 6 2 2 6 2 2 6
53288- 2 2 6 2 2 6 2 2 6 10 10 10
53289- 10 10 10 2 2 6 2 2 6 2 2 6
53290- 2 2 6 2 2 6 2 2 6 78 78 78
53291- 50 50 50 18 18 18 6 6 6 0 0 0
53292- 0 0 0 0 0 0 0 0 0 0 0 0
53293- 0 0 0 0 0 0 0 0 0 0 0 0
53294- 0 0 0 0 0 0 0 0 0 0 0 0
53295- 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 1 0 0 0 0 0 0 0 0 0
53300- 0 0 0 0 0 0 0 0 0 0 0 0
53301- 0 0 0 0 0 0 0 0 0 0 0 0
53302- 0 0 0 0 0 0 0 0 0 0 0 0
53303- 0 0 0 0 0 0 0 0 0 0 0 0
53304- 0 0 0 0 0 0 0 0 0 10 10 10
53305- 38 38 38 86 86 86 14 14 14 2 2 6
53306- 2 2 6 2 2 6 2 2 6 2 2 6
53307- 2 2 6 2 2 6 2 2 6 2 2 6
53308- 2 2 6 2 2 6 2 2 6 2 2 6
53309- 2 2 6 2 2 6 2 2 6 2 2 6
53310- 2 2 6 2 2 6 2 2 6 54 54 54
53311- 66 66 66 26 26 26 6 6 6 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 1 0 0 1 0 0 0
53320- 0 0 0 0 0 0 0 0 0 0 0 0
53321- 0 0 0 0 0 0 0 0 0 0 0 0
53322- 0 0 0 0 0 0 0 0 0 0 0 0
53323- 0 0 0 0 0 0 0 0 0 0 0 0
53324- 0 0 0 0 0 0 0 0 0 14 14 14
53325- 42 42 42 82 82 82 2 2 6 2 2 6
53326- 2 2 6 6 6 6 10 10 10 2 2 6
53327- 2 2 6 2 2 6 2 2 6 2 2 6
53328- 2 2 6 2 2 6 2 2 6 6 6 6
53329- 14 14 14 10 10 10 2 2 6 2 2 6
53330- 2 2 6 2 2 6 2 2 6 18 18 18
53331- 82 82 82 34 34 34 10 10 10 0 0 0
53332- 0 0 0 0 0 0 0 0 0 0 0 0
53333- 0 0 0 0 0 0 0 0 0 0 0 0
53334- 0 0 0 0 0 0 0 0 0 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 1 0 0 0 0 0 0 0 0 0
53340- 0 0 0 0 0 0 0 0 0 0 0 0
53341- 0 0 0 0 0 0 0 0 0 0 0 0
53342- 0 0 0 0 0 0 0 0 0 0 0 0
53343- 0 0 0 0 0 0 0 0 0 0 0 0
53344- 0 0 0 0 0 0 0 0 0 14 14 14
53345- 46 46 46 86 86 86 2 2 6 2 2 6
53346- 6 6 6 6 6 6 22 22 22 34 34 34
53347- 6 6 6 2 2 6 2 2 6 2 2 6
53348- 2 2 6 2 2 6 18 18 18 34 34 34
53349- 10 10 10 50 50 50 22 22 22 2 2 6
53350- 2 2 6 2 2 6 2 2 6 10 10 10
53351- 86 86 86 42 42 42 14 14 14 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 1 0 0 1 0 0 1 0 0 0
53360- 0 0 0 0 0 0 0 0 0 0 0 0
53361- 0 0 0 0 0 0 0 0 0 0 0 0
53362- 0 0 0 0 0 0 0 0 0 0 0 0
53363- 0 0 0 0 0 0 0 0 0 0 0 0
53364- 0 0 0 0 0 0 0 0 0 14 14 14
53365- 46 46 46 86 86 86 2 2 6 2 2 6
53366- 38 38 38 116 116 116 94 94 94 22 22 22
53367- 22 22 22 2 2 6 2 2 6 2 2 6
53368- 14 14 14 86 86 86 138 138 138 162 162 162
53369-154 154 154 38 38 38 26 26 26 6 6 6
53370- 2 2 6 2 2 6 2 2 6 2 2 6
53371- 86 86 86 46 46 46 14 14 14 0 0 0
53372- 0 0 0 0 0 0 0 0 0 0 0 0
53373- 0 0 0 0 0 0 0 0 0 0 0 0
53374- 0 0 0 0 0 0 0 0 0 0 0 0
53375- 0 0 0 0 0 0 0 0 0 0 0 0
53376- 0 0 0 0 0 0 0 0 0 0 0 0
53377- 0 0 0 0 0 0 0 0 0 0 0 0
53378- 0 0 0 0 0 0 0 0 0 0 0 0
53379- 0 0 0 0 0 0 0 0 0 0 0 0
53380- 0 0 0 0 0 0 0 0 0 0 0 0
53381- 0 0 0 0 0 0 0 0 0 0 0 0
53382- 0 0 0 0 0 0 0 0 0 0 0 0
53383- 0 0 0 0 0 0 0 0 0 0 0 0
53384- 0 0 0 0 0 0 0 0 0 14 14 14
53385- 46 46 46 86 86 86 2 2 6 14 14 14
53386-134 134 134 198 198 198 195 195 195 116 116 116
53387- 10 10 10 2 2 6 2 2 6 6 6 6
53388-101 98 89 187 187 187 210 210 210 218 218 218
53389-214 214 214 134 134 134 14 14 14 6 6 6
53390- 2 2 6 2 2 6 2 2 6 2 2 6
53391- 86 86 86 50 50 50 18 18 18 6 6 6
53392- 0 0 0 0 0 0 0 0 0 0 0 0
53393- 0 0 0 0 0 0 0 0 0 0 0 0
53394- 0 0 0 0 0 0 0 0 0 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 1 0 0 0
53399- 0 0 1 0 0 1 0 0 1 0 0 0
53400- 0 0 0 0 0 0 0 0 0 0 0 0
53401- 0 0 0 0 0 0 0 0 0 0 0 0
53402- 0 0 0 0 0 0 0 0 0 0 0 0
53403- 0 0 0 0 0 0 0 0 0 0 0 0
53404- 0 0 0 0 0 0 0 0 0 14 14 14
53405- 46 46 46 86 86 86 2 2 6 54 54 54
53406-218 218 218 195 195 195 226 226 226 246 246 246
53407- 58 58 58 2 2 6 2 2 6 30 30 30
53408-210 210 210 253 253 253 174 174 174 123 123 123
53409-221 221 221 234 234 234 74 74 74 2 2 6
53410- 2 2 6 2 2 6 2 2 6 2 2 6
53411- 70 70 70 58 58 58 22 22 22 6 6 6
53412- 0 0 0 0 0 0 0 0 0 0 0 0
53413- 0 0 0 0 0 0 0 0 0 0 0 0
53414- 0 0 0 0 0 0 0 0 0 0 0 0
53415- 0 0 0 0 0 0 0 0 0 0 0 0
53416- 0 0 0 0 0 0 0 0 0 0 0 0
53417- 0 0 0 0 0 0 0 0 0 0 0 0
53418- 0 0 0 0 0 0 0 0 0 0 0 0
53419- 0 0 0 0 0 0 0 0 0 0 0 0
53420- 0 0 0 0 0 0 0 0 0 0 0 0
53421- 0 0 0 0 0 0 0 0 0 0 0 0
53422- 0 0 0 0 0 0 0 0 0 0 0 0
53423- 0 0 0 0 0 0 0 0 0 0 0 0
53424- 0 0 0 0 0 0 0 0 0 14 14 14
53425- 46 46 46 82 82 82 2 2 6 106 106 106
53426-170 170 170 26 26 26 86 86 86 226 226 226
53427-123 123 123 10 10 10 14 14 14 46 46 46
53428-231 231 231 190 190 190 6 6 6 70 70 70
53429- 90 90 90 238 238 238 158 158 158 2 2 6
53430- 2 2 6 2 2 6 2 2 6 2 2 6
53431- 70 70 70 58 58 58 22 22 22 6 6 6
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 1 0 0 0
53439- 0 0 1 0 0 1 0 0 1 0 0 0
53440- 0 0 0 0 0 0 0 0 0 0 0 0
53441- 0 0 0 0 0 0 0 0 0 0 0 0
53442- 0 0 0 0 0 0 0 0 0 0 0 0
53443- 0 0 0 0 0 0 0 0 0 0 0 0
53444- 0 0 0 0 0 0 0 0 0 14 14 14
53445- 42 42 42 86 86 86 6 6 6 116 116 116
53446-106 106 106 6 6 6 70 70 70 149 149 149
53447-128 128 128 18 18 18 38 38 38 54 54 54
53448-221 221 221 106 106 106 2 2 6 14 14 14
53449- 46 46 46 190 190 190 198 198 198 2 2 6
53450- 2 2 6 2 2 6 2 2 6 2 2 6
53451- 74 74 74 62 62 62 22 22 22 6 6 6
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 1 0 0 0
53459- 0 0 1 0 0 0 0 0 1 0 0 0
53460- 0 0 0 0 0 0 0 0 0 0 0 0
53461- 0 0 0 0 0 0 0 0 0 0 0 0
53462- 0 0 0 0 0 0 0 0 0 0 0 0
53463- 0 0 0 0 0 0 0 0 0 0 0 0
53464- 0 0 0 0 0 0 0 0 0 14 14 14
53465- 42 42 42 94 94 94 14 14 14 101 101 101
53466-128 128 128 2 2 6 18 18 18 116 116 116
53467-118 98 46 121 92 8 121 92 8 98 78 10
53468-162 162 162 106 106 106 2 2 6 2 2 6
53469- 2 2 6 195 195 195 195 195 195 6 6 6
53470- 2 2 6 2 2 6 2 2 6 2 2 6
53471- 74 74 74 62 62 62 22 22 22 6 6 6
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 1 0 0 1
53479- 0 0 1 0 0 0 0 0 1 0 0 0
53480- 0 0 0 0 0 0 0 0 0 0 0 0
53481- 0 0 0 0 0 0 0 0 0 0 0 0
53482- 0 0 0 0 0 0 0 0 0 0 0 0
53483- 0 0 0 0 0 0 0 0 0 0 0 0
53484- 0 0 0 0 0 0 0 0 0 10 10 10
53485- 38 38 38 90 90 90 14 14 14 58 58 58
53486-210 210 210 26 26 26 54 38 6 154 114 10
53487-226 170 11 236 186 11 225 175 15 184 144 12
53488-215 174 15 175 146 61 37 26 9 2 2 6
53489- 70 70 70 246 246 246 138 138 138 2 2 6
53490- 2 2 6 2 2 6 2 2 6 2 2 6
53491- 70 70 70 66 66 66 26 26 26 6 6 6
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 0 0 0
53500- 0 0 0 0 0 0 0 0 0 0 0 0
53501- 0 0 0 0 0 0 0 0 0 0 0 0
53502- 0 0 0 0 0 0 0 0 0 0 0 0
53503- 0 0 0 0 0 0 0 0 0 0 0 0
53504- 0 0 0 0 0 0 0 0 0 10 10 10
53505- 38 38 38 86 86 86 14 14 14 10 10 10
53506-195 195 195 188 164 115 192 133 9 225 175 15
53507-239 182 13 234 190 10 232 195 16 232 200 30
53508-245 207 45 241 208 19 232 195 16 184 144 12
53509-218 194 134 211 206 186 42 42 42 2 2 6
53510- 2 2 6 2 2 6 2 2 6 2 2 6
53511- 50 50 50 74 74 74 30 30 30 6 6 6
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 0 0 0
53520- 0 0 0 0 0 0 0 0 0 0 0 0
53521- 0 0 0 0 0 0 0 0 0 0 0 0
53522- 0 0 0 0 0 0 0 0 0 0 0 0
53523- 0 0 0 0 0 0 0 0 0 0 0 0
53524- 0 0 0 0 0 0 0 0 0 10 10 10
53525- 34 34 34 86 86 86 14 14 14 2 2 6
53526-121 87 25 192 133 9 219 162 10 239 182 13
53527-236 186 11 232 195 16 241 208 19 244 214 54
53528-246 218 60 246 218 38 246 215 20 241 208 19
53529-241 208 19 226 184 13 121 87 25 2 2 6
53530- 2 2 6 2 2 6 2 2 6 2 2 6
53531- 50 50 50 82 82 82 34 34 34 10 10 10
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 0 0 0
53540- 0 0 0 0 0 0 0 0 0 0 0 0
53541- 0 0 0 0 0 0 0 0 0 0 0 0
53542- 0 0 0 0 0 0 0 0 0 0 0 0
53543- 0 0 0 0 0 0 0 0 0 0 0 0
53544- 0 0 0 0 0 0 0 0 0 10 10 10
53545- 34 34 34 82 82 82 30 30 30 61 42 6
53546-180 123 7 206 145 10 230 174 11 239 182 13
53547-234 190 10 238 202 15 241 208 19 246 218 74
53548-246 218 38 246 215 20 246 215 20 246 215 20
53549-226 184 13 215 174 15 184 144 12 6 6 6
53550- 2 2 6 2 2 6 2 2 6 2 2 6
53551- 26 26 26 94 94 94 42 42 42 14 14 14
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 0 0 0
53560- 0 0 0 0 0 0 0 0 0 0 0 0
53561- 0 0 0 0 0 0 0 0 0 0 0 0
53562- 0 0 0 0 0 0 0 0 0 0 0 0
53563- 0 0 0 0 0 0 0 0 0 0 0 0
53564- 0 0 0 0 0 0 0 0 0 10 10 10
53565- 30 30 30 78 78 78 50 50 50 104 69 6
53566-192 133 9 216 158 10 236 178 12 236 186 11
53567-232 195 16 241 208 19 244 214 54 245 215 43
53568-246 215 20 246 215 20 241 208 19 198 155 10
53569-200 144 11 216 158 10 156 118 10 2 2 6
53570- 2 2 6 2 2 6 2 2 6 2 2 6
53571- 6 6 6 90 90 90 54 54 54 18 18 18
53572- 6 6 6 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 0 0 0 0 0 0
53580- 0 0 0 0 0 0 0 0 0 0 0 0
53581- 0 0 0 0 0 0 0 0 0 0 0 0
53582- 0 0 0 0 0 0 0 0 0 0 0 0
53583- 0 0 0 0 0 0 0 0 0 0 0 0
53584- 0 0 0 0 0 0 0 0 0 10 10 10
53585- 30 30 30 78 78 78 46 46 46 22 22 22
53586-137 92 6 210 162 10 239 182 13 238 190 10
53587-238 202 15 241 208 19 246 215 20 246 215 20
53588-241 208 19 203 166 17 185 133 11 210 150 10
53589-216 158 10 210 150 10 102 78 10 2 2 6
53590- 6 6 6 54 54 54 14 14 14 2 2 6
53591- 2 2 6 62 62 62 74 74 74 30 30 30
53592- 10 10 10 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 0 0 0 0 0 0
53600- 0 0 0 0 0 0 0 0 0 0 0 0
53601- 0 0 0 0 0 0 0 0 0 0 0 0
53602- 0 0 0 0 0 0 0 0 0 0 0 0
53603- 0 0 0 0 0 0 0 0 0 0 0 0
53604- 0 0 0 0 0 0 0 0 0 10 10 10
53605- 34 34 34 78 78 78 50 50 50 6 6 6
53606- 94 70 30 139 102 15 190 146 13 226 184 13
53607-232 200 30 232 195 16 215 174 15 190 146 13
53608-168 122 10 192 133 9 210 150 10 213 154 11
53609-202 150 34 182 157 106 101 98 89 2 2 6
53610- 2 2 6 78 78 78 116 116 116 58 58 58
53611- 2 2 6 22 22 22 90 90 90 46 46 46
53612- 18 18 18 6 6 6 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 0 0 0 0 0 0 0 0 0
53620- 0 0 0 0 0 0 0 0 0 0 0 0
53621- 0 0 0 0 0 0 0 0 0 0 0 0
53622- 0 0 0 0 0 0 0 0 0 0 0 0
53623- 0 0 0 0 0 0 0 0 0 0 0 0
53624- 0 0 0 0 0 0 0 0 0 10 10 10
53625- 38 38 38 86 86 86 50 50 50 6 6 6
53626-128 128 128 174 154 114 156 107 11 168 122 10
53627-198 155 10 184 144 12 197 138 11 200 144 11
53628-206 145 10 206 145 10 197 138 11 188 164 115
53629-195 195 195 198 198 198 174 174 174 14 14 14
53630- 2 2 6 22 22 22 116 116 116 116 116 116
53631- 22 22 22 2 2 6 74 74 74 70 70 70
53632- 30 30 30 10 10 10 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- 0 0 0 0 0 0 0 0 0 0 0 0
53640- 0 0 0 0 0 0 0 0 0 0 0 0
53641- 0 0 0 0 0 0 0 0 0 0 0 0
53642- 0 0 0 0 0 0 0 0 0 0 0 0
53643- 0 0 0 0 0 0 0 0 0 0 0 0
53644- 0 0 0 0 0 0 6 6 6 18 18 18
53645- 50 50 50 101 101 101 26 26 26 10 10 10
53646-138 138 138 190 190 190 174 154 114 156 107 11
53647-197 138 11 200 144 11 197 138 11 192 133 9
53648-180 123 7 190 142 34 190 178 144 187 187 187
53649-202 202 202 221 221 221 214 214 214 66 66 66
53650- 2 2 6 2 2 6 50 50 50 62 62 62
53651- 6 6 6 2 2 6 10 10 10 90 90 90
53652- 50 50 50 18 18 18 6 6 6 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 0 0 0
53659- 0 0 0 0 0 0 0 0 0 0 0 0
53660- 0 0 0 0 0 0 0 0 0 0 0 0
53661- 0 0 0 0 0 0 0 0 0 0 0 0
53662- 0 0 0 0 0 0 0 0 0 0 0 0
53663- 0 0 0 0 0 0 0 0 0 0 0 0
53664- 0 0 0 0 0 0 10 10 10 34 34 34
53665- 74 74 74 74 74 74 2 2 6 6 6 6
53666-144 144 144 198 198 198 190 190 190 178 166 146
53667-154 121 60 156 107 11 156 107 11 168 124 44
53668-174 154 114 187 187 187 190 190 190 210 210 210
53669-246 246 246 253 253 253 253 253 253 182 182 182
53670- 6 6 6 2 2 6 2 2 6 2 2 6
53671- 2 2 6 2 2 6 2 2 6 62 62 62
53672- 74 74 74 34 34 34 14 14 14 0 0 0
53673- 0 0 0 0 0 0 0 0 0 0 0 0
53674- 0 0 0 0 0 0 0 0 0 0 0 0
53675- 0 0 0 0 0 0 0 0 0 0 0 0
53676- 0 0 0 0 0 0 0 0 0 0 0 0
53677- 0 0 0 0 0 0 0 0 0 0 0 0
53678- 0 0 0 0 0 0 0 0 0 0 0 0
53679- 0 0 0 0 0 0 0 0 0 0 0 0
53680- 0 0 0 0 0 0 0 0 0 0 0 0
53681- 0 0 0 0 0 0 0 0 0 0 0 0
53682- 0 0 0 0 0 0 0 0 0 0 0 0
53683- 0 0 0 0 0 0 0 0 0 0 0 0
53684- 0 0 0 10 10 10 22 22 22 54 54 54
53685- 94 94 94 18 18 18 2 2 6 46 46 46
53686-234 234 234 221 221 221 190 190 190 190 190 190
53687-190 190 190 187 187 187 187 187 187 190 190 190
53688-190 190 190 195 195 195 214 214 214 242 242 242
53689-253 253 253 253 253 253 253 253 253 253 253 253
53690- 82 82 82 2 2 6 2 2 6 2 2 6
53691- 2 2 6 2 2 6 2 2 6 14 14 14
53692- 86 86 86 54 54 54 22 22 22 6 6 6
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 0 0 0 0 0 0
53699- 0 0 0 0 0 0 0 0 0 0 0 0
53700- 0 0 0 0 0 0 0 0 0 0 0 0
53701- 0 0 0 0 0 0 0 0 0 0 0 0
53702- 0 0 0 0 0 0 0 0 0 0 0 0
53703- 0 0 0 0 0 0 0 0 0 0 0 0
53704- 6 6 6 18 18 18 46 46 46 90 90 90
53705- 46 46 46 18 18 18 6 6 6 182 182 182
53706-253 253 253 246 246 246 206 206 206 190 190 190
53707-190 190 190 190 190 190 190 190 190 190 190 190
53708-206 206 206 231 231 231 250 250 250 253 253 253
53709-253 253 253 253 253 253 253 253 253 253 253 253
53710-202 202 202 14 14 14 2 2 6 2 2 6
53711- 2 2 6 2 2 6 2 2 6 2 2 6
53712- 42 42 42 86 86 86 42 42 42 18 18 18
53713- 6 6 6 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 0 0 0 0 0 0 0 0 0
53719- 0 0 0 0 0 0 0 0 0 0 0 0
53720- 0 0 0 0 0 0 0 0 0 0 0 0
53721- 0 0 0 0 0 0 0 0 0 0 0 0
53722- 0 0 0 0 0 0 0 0 0 0 0 0
53723- 0 0 0 0 0 0 0 0 0 6 6 6
53724- 14 14 14 38 38 38 74 74 74 66 66 66
53725- 2 2 6 6 6 6 90 90 90 250 250 250
53726-253 253 253 253 253 253 238 238 238 198 198 198
53727-190 190 190 190 190 190 195 195 195 221 221 221
53728-246 246 246 253 253 253 253 253 253 253 253 253
53729-253 253 253 253 253 253 253 253 253 253 253 253
53730-253 253 253 82 82 82 2 2 6 2 2 6
53731- 2 2 6 2 2 6 2 2 6 2 2 6
53732- 2 2 6 78 78 78 70 70 70 34 34 34
53733- 14 14 14 6 6 6 0 0 0 0 0 0
53734- 0 0 0 0 0 0 0 0 0 0 0 0
53735- 0 0 0 0 0 0 0 0 0 0 0 0
53736- 0 0 0 0 0 0 0 0 0 0 0 0
53737- 0 0 0 0 0 0 0 0 0 0 0 0
53738- 0 0 0 0 0 0 0 0 0 0 0 0
53739- 0 0 0 0 0 0 0 0 0 0 0 0
53740- 0 0 0 0 0 0 0 0 0 0 0 0
53741- 0 0 0 0 0 0 0 0 0 0 0 0
53742- 0 0 0 0 0 0 0 0 0 0 0 0
53743- 0 0 0 0 0 0 0 0 0 14 14 14
53744- 34 34 34 66 66 66 78 78 78 6 6 6
53745- 2 2 6 18 18 18 218 218 218 253 253 253
53746-253 253 253 253 253 253 253 253 253 246 246 246
53747-226 226 226 231 231 231 246 246 246 253 253 253
53748-253 253 253 253 253 253 253 253 253 253 253 253
53749-253 253 253 253 253 253 253 253 253 253 253 253
53750-253 253 253 178 178 178 2 2 6 2 2 6
53751- 2 2 6 2 2 6 2 2 6 2 2 6
53752- 2 2 6 18 18 18 90 90 90 62 62 62
53753- 30 30 30 10 10 10 0 0 0 0 0 0
53754- 0 0 0 0 0 0 0 0 0 0 0 0
53755- 0 0 0 0 0 0 0 0 0 0 0 0
53756- 0 0 0 0 0 0 0 0 0 0 0 0
53757- 0 0 0 0 0 0 0 0 0 0 0 0
53758- 0 0 0 0 0 0 0 0 0 0 0 0
53759- 0 0 0 0 0 0 0 0 0 0 0 0
53760- 0 0 0 0 0 0 0 0 0 0 0 0
53761- 0 0 0 0 0 0 0 0 0 0 0 0
53762- 0 0 0 0 0 0 0 0 0 0 0 0
53763- 0 0 0 0 0 0 10 10 10 26 26 26
53764- 58 58 58 90 90 90 18 18 18 2 2 6
53765- 2 2 6 110 110 110 253 253 253 253 253 253
53766-253 253 253 253 253 253 253 253 253 253 253 253
53767-250 250 250 253 253 253 253 253 253 253 253 253
53768-253 253 253 253 253 253 253 253 253 253 253 253
53769-253 253 253 253 253 253 253 253 253 253 253 253
53770-253 253 253 231 231 231 18 18 18 2 2 6
53771- 2 2 6 2 2 6 2 2 6 2 2 6
53772- 2 2 6 2 2 6 18 18 18 94 94 94
53773- 54 54 54 26 26 26 10 10 10 0 0 0
53774- 0 0 0 0 0 0 0 0 0 0 0 0
53775- 0 0 0 0 0 0 0 0 0 0 0 0
53776- 0 0 0 0 0 0 0 0 0 0 0 0
53777- 0 0 0 0 0 0 0 0 0 0 0 0
53778- 0 0 0 0 0 0 0 0 0 0 0 0
53779- 0 0 0 0 0 0 0 0 0 0 0 0
53780- 0 0 0 0 0 0 0 0 0 0 0 0
53781- 0 0 0 0 0 0 0 0 0 0 0 0
53782- 0 0 0 0 0 0 0 0 0 0 0 0
53783- 0 0 0 6 6 6 22 22 22 50 50 50
53784- 90 90 90 26 26 26 2 2 6 2 2 6
53785- 14 14 14 195 195 195 250 250 250 253 253 253
53786-253 253 253 253 253 253 253 253 253 253 253 253
53787-253 253 253 253 253 253 253 253 253 253 253 253
53788-253 253 253 253 253 253 253 253 253 253 253 253
53789-253 253 253 253 253 253 253 253 253 253 253 253
53790-250 250 250 242 242 242 54 54 54 2 2 6
53791- 2 2 6 2 2 6 2 2 6 2 2 6
53792- 2 2 6 2 2 6 2 2 6 38 38 38
53793- 86 86 86 50 50 50 22 22 22 6 6 6
53794- 0 0 0 0 0 0 0 0 0 0 0 0
53795- 0 0 0 0 0 0 0 0 0 0 0 0
53796- 0 0 0 0 0 0 0 0 0 0 0 0
53797- 0 0 0 0 0 0 0 0 0 0 0 0
53798- 0 0 0 0 0 0 0 0 0 0 0 0
53799- 0 0 0 0 0 0 0 0 0 0 0 0
53800- 0 0 0 0 0 0 0 0 0 0 0 0
53801- 0 0 0 0 0 0 0 0 0 0 0 0
53802- 0 0 0 0 0 0 0 0 0 0 0 0
53803- 6 6 6 14 14 14 38 38 38 82 82 82
53804- 34 34 34 2 2 6 2 2 6 2 2 6
53805- 42 42 42 195 195 195 246 246 246 253 253 253
53806-253 253 253 253 253 253 253 253 253 250 250 250
53807-242 242 242 242 242 242 250 250 250 253 253 253
53808-253 253 253 253 253 253 253 253 253 253 253 253
53809-253 253 253 250 250 250 246 246 246 238 238 238
53810-226 226 226 231 231 231 101 101 101 6 6 6
53811- 2 2 6 2 2 6 2 2 6 2 2 6
53812- 2 2 6 2 2 6 2 2 6 2 2 6
53813- 38 38 38 82 82 82 42 42 42 14 14 14
53814- 6 6 6 0 0 0 0 0 0 0 0 0
53815- 0 0 0 0 0 0 0 0 0 0 0 0
53816- 0 0 0 0 0 0 0 0 0 0 0 0
53817- 0 0 0 0 0 0 0 0 0 0 0 0
53818- 0 0 0 0 0 0 0 0 0 0 0 0
53819- 0 0 0 0 0 0 0 0 0 0 0 0
53820- 0 0 0 0 0 0 0 0 0 0 0 0
53821- 0 0 0 0 0 0 0 0 0 0 0 0
53822- 0 0 0 0 0 0 0 0 0 0 0 0
53823- 10 10 10 26 26 26 62 62 62 66 66 66
53824- 2 2 6 2 2 6 2 2 6 6 6 6
53825- 70 70 70 170 170 170 206 206 206 234 234 234
53826-246 246 246 250 250 250 250 250 250 238 238 238
53827-226 226 226 231 231 231 238 238 238 250 250 250
53828-250 250 250 250 250 250 246 246 246 231 231 231
53829-214 214 214 206 206 206 202 202 202 202 202 202
53830-198 198 198 202 202 202 182 182 182 18 18 18
53831- 2 2 6 2 2 6 2 2 6 2 2 6
53832- 2 2 6 2 2 6 2 2 6 2 2 6
53833- 2 2 6 62 62 62 66 66 66 30 30 30
53834- 10 10 10 0 0 0 0 0 0 0 0 0
53835- 0 0 0 0 0 0 0 0 0 0 0 0
53836- 0 0 0 0 0 0 0 0 0 0 0 0
53837- 0 0 0 0 0 0 0 0 0 0 0 0
53838- 0 0 0 0 0 0 0 0 0 0 0 0
53839- 0 0 0 0 0 0 0 0 0 0 0 0
53840- 0 0 0 0 0 0 0 0 0 0 0 0
53841- 0 0 0 0 0 0 0 0 0 0 0 0
53842- 0 0 0 0 0 0 0 0 0 0 0 0
53843- 14 14 14 42 42 42 82 82 82 18 18 18
53844- 2 2 6 2 2 6 2 2 6 10 10 10
53845- 94 94 94 182 182 182 218 218 218 242 242 242
53846-250 250 250 253 253 253 253 253 253 250 250 250
53847-234 234 234 253 253 253 253 253 253 253 253 253
53848-253 253 253 253 253 253 253 253 253 246 246 246
53849-238 238 238 226 226 226 210 210 210 202 202 202
53850-195 195 195 195 195 195 210 210 210 158 158 158
53851- 6 6 6 14 14 14 50 50 50 14 14 14
53852- 2 2 6 2 2 6 2 2 6 2 2 6
53853- 2 2 6 6 6 6 86 86 86 46 46 46
53854- 18 18 18 6 6 6 0 0 0 0 0 0
53855- 0 0 0 0 0 0 0 0 0 0 0 0
53856- 0 0 0 0 0 0 0 0 0 0 0 0
53857- 0 0 0 0 0 0 0 0 0 0 0 0
53858- 0 0 0 0 0 0 0 0 0 0 0 0
53859- 0 0 0 0 0 0 0 0 0 0 0 0
53860- 0 0 0 0 0 0 0 0 0 0 0 0
53861- 0 0 0 0 0 0 0 0 0 0 0 0
53862- 0 0 0 0 0 0 0 0 0 6 6 6
53863- 22 22 22 54 54 54 70 70 70 2 2 6
53864- 2 2 6 10 10 10 2 2 6 22 22 22
53865-166 166 166 231 231 231 250 250 250 253 253 253
53866-253 253 253 253 253 253 253 253 253 250 250 250
53867-242 242 242 253 253 253 253 253 253 253 253 253
53868-253 253 253 253 253 253 253 253 253 253 253 253
53869-253 253 253 253 253 253 253 253 253 246 246 246
53870-231 231 231 206 206 206 198 198 198 226 226 226
53871- 94 94 94 2 2 6 6 6 6 38 38 38
53872- 30 30 30 2 2 6 2 2 6 2 2 6
53873- 2 2 6 2 2 6 62 62 62 66 66 66
53874- 26 26 26 10 10 10 0 0 0 0 0 0
53875- 0 0 0 0 0 0 0 0 0 0 0 0
53876- 0 0 0 0 0 0 0 0 0 0 0 0
53877- 0 0 0 0 0 0 0 0 0 0 0 0
53878- 0 0 0 0 0 0 0 0 0 0 0 0
53879- 0 0 0 0 0 0 0 0 0 0 0 0
53880- 0 0 0 0 0 0 0 0 0 0 0 0
53881- 0 0 0 0 0 0 0 0 0 0 0 0
53882- 0 0 0 0 0 0 0 0 0 10 10 10
53883- 30 30 30 74 74 74 50 50 50 2 2 6
53884- 26 26 26 26 26 26 2 2 6 106 106 106
53885-238 238 238 253 253 253 253 253 253 253 253 253
53886-253 253 253 253 253 253 253 253 253 253 253 253
53887-253 253 253 253 253 253 253 253 253 253 253 253
53888-253 253 253 253 253 253 253 253 253 253 253 253
53889-253 253 253 253 253 253 253 253 253 253 253 253
53890-253 253 253 246 246 246 218 218 218 202 202 202
53891-210 210 210 14 14 14 2 2 6 2 2 6
53892- 30 30 30 22 22 22 2 2 6 2 2 6
53893- 2 2 6 2 2 6 18 18 18 86 86 86
53894- 42 42 42 14 14 14 0 0 0 0 0 0
53895- 0 0 0 0 0 0 0 0 0 0 0 0
53896- 0 0 0 0 0 0 0 0 0 0 0 0
53897- 0 0 0 0 0 0 0 0 0 0 0 0
53898- 0 0 0 0 0 0 0 0 0 0 0 0
53899- 0 0 0 0 0 0 0 0 0 0 0 0
53900- 0 0 0 0 0 0 0 0 0 0 0 0
53901- 0 0 0 0 0 0 0 0 0 0 0 0
53902- 0 0 0 0 0 0 0 0 0 14 14 14
53903- 42 42 42 90 90 90 22 22 22 2 2 6
53904- 42 42 42 2 2 6 18 18 18 218 218 218
53905-253 253 253 253 253 253 253 253 253 253 253 253
53906-253 253 253 253 253 253 253 253 253 253 253 253
53907-253 253 253 253 253 253 253 253 253 253 253 253
53908-253 253 253 253 253 253 253 253 253 253 253 253
53909-253 253 253 253 253 253 253 253 253 253 253 253
53910-253 253 253 253 253 253 250 250 250 221 221 221
53911-218 218 218 101 101 101 2 2 6 14 14 14
53912- 18 18 18 38 38 38 10 10 10 2 2 6
53913- 2 2 6 2 2 6 2 2 6 78 78 78
53914- 58 58 58 22 22 22 6 6 6 0 0 0
53915- 0 0 0 0 0 0 0 0 0 0 0 0
53916- 0 0 0 0 0 0 0 0 0 0 0 0
53917- 0 0 0 0 0 0 0 0 0 0 0 0
53918- 0 0 0 0 0 0 0 0 0 0 0 0
53919- 0 0 0 0 0 0 0 0 0 0 0 0
53920- 0 0 0 0 0 0 0 0 0 0 0 0
53921- 0 0 0 0 0 0 0 0 0 0 0 0
53922- 0 0 0 0 0 0 6 6 6 18 18 18
53923- 54 54 54 82 82 82 2 2 6 26 26 26
53924- 22 22 22 2 2 6 123 123 123 253 253 253
53925-253 253 253 253 253 253 253 253 253 253 253 253
53926-253 253 253 253 253 253 253 253 253 253 253 253
53927-253 253 253 253 253 253 253 253 253 253 253 253
53928-253 253 253 253 253 253 253 253 253 253 253 253
53929-253 253 253 253 253 253 253 253 253 253 253 253
53930-253 253 253 253 253 253 253 253 253 250 250 250
53931-238 238 238 198 198 198 6 6 6 38 38 38
53932- 58 58 58 26 26 26 38 38 38 2 2 6
53933- 2 2 6 2 2 6 2 2 6 46 46 46
53934- 78 78 78 30 30 30 10 10 10 0 0 0
53935- 0 0 0 0 0 0 0 0 0 0 0 0
53936- 0 0 0 0 0 0 0 0 0 0 0 0
53937- 0 0 0 0 0 0 0 0 0 0 0 0
53938- 0 0 0 0 0 0 0 0 0 0 0 0
53939- 0 0 0 0 0 0 0 0 0 0 0 0
53940- 0 0 0 0 0 0 0 0 0 0 0 0
53941- 0 0 0 0 0 0 0 0 0 0 0 0
53942- 0 0 0 0 0 0 10 10 10 30 30 30
53943- 74 74 74 58 58 58 2 2 6 42 42 42
53944- 2 2 6 22 22 22 231 231 231 253 253 253
53945-253 253 253 253 253 253 253 253 253 253 253 253
53946-253 253 253 253 253 253 253 253 253 250 250 250
53947-253 253 253 253 253 253 253 253 253 253 253 253
53948-253 253 253 253 253 253 253 253 253 253 253 253
53949-253 253 253 253 253 253 253 253 253 253 253 253
53950-253 253 253 253 253 253 253 253 253 253 253 253
53951-253 253 253 246 246 246 46 46 46 38 38 38
53952- 42 42 42 14 14 14 38 38 38 14 14 14
53953- 2 2 6 2 2 6 2 2 6 6 6 6
53954- 86 86 86 46 46 46 14 14 14 0 0 0
53955- 0 0 0 0 0 0 0 0 0 0 0 0
53956- 0 0 0 0 0 0 0 0 0 0 0 0
53957- 0 0 0 0 0 0 0 0 0 0 0 0
53958- 0 0 0 0 0 0 0 0 0 0 0 0
53959- 0 0 0 0 0 0 0 0 0 0 0 0
53960- 0 0 0 0 0 0 0 0 0 0 0 0
53961- 0 0 0 0 0 0 0 0 0 0 0 0
53962- 0 0 0 6 6 6 14 14 14 42 42 42
53963- 90 90 90 18 18 18 18 18 18 26 26 26
53964- 2 2 6 116 116 116 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 250 250 250 238 238 238
53967-253 253 253 253 253 253 253 253 253 253 253 253
53968-253 253 253 253 253 253 253 253 253 253 253 253
53969-253 253 253 253 253 253 253 253 253 253 253 253
53970-253 253 253 253 253 253 253 253 253 253 253 253
53971-253 253 253 253 253 253 94 94 94 6 6 6
53972- 2 2 6 2 2 6 10 10 10 34 34 34
53973- 2 2 6 2 2 6 2 2 6 2 2 6
53974- 74 74 74 58 58 58 22 22 22 6 6 6
53975- 0 0 0 0 0 0 0 0 0 0 0 0
53976- 0 0 0 0 0 0 0 0 0 0 0 0
53977- 0 0 0 0 0 0 0 0 0 0 0 0
53978- 0 0 0 0 0 0 0 0 0 0 0 0
53979- 0 0 0 0 0 0 0 0 0 0 0 0
53980- 0 0 0 0 0 0 0 0 0 0 0 0
53981- 0 0 0 0 0 0 0 0 0 0 0 0
53982- 0 0 0 10 10 10 26 26 26 66 66 66
53983- 82 82 82 2 2 6 38 38 38 6 6 6
53984- 14 14 14 210 210 210 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 246 246 246 242 242 242
53987-253 253 253 253 253 253 253 253 253 253 253 253
53988-253 253 253 253 253 253 253 253 253 253 253 253
53989-253 253 253 253 253 253 253 253 253 253 253 253
53990-253 253 253 253 253 253 253 253 253 253 253 253
53991-253 253 253 253 253 253 144 144 144 2 2 6
53992- 2 2 6 2 2 6 2 2 6 46 46 46
53993- 2 2 6 2 2 6 2 2 6 2 2 6
53994- 42 42 42 74 74 74 30 30 30 10 10 10
53995- 0 0 0 0 0 0 0 0 0 0 0 0
53996- 0 0 0 0 0 0 0 0 0 0 0 0
53997- 0 0 0 0 0 0 0 0 0 0 0 0
53998- 0 0 0 0 0 0 0 0 0 0 0 0
53999- 0 0 0 0 0 0 0 0 0 0 0 0
54000- 0 0 0 0 0 0 0 0 0 0 0 0
54001- 0 0 0 0 0 0 0 0 0 0 0 0
54002- 6 6 6 14 14 14 42 42 42 90 90 90
54003- 26 26 26 6 6 6 42 42 42 2 2 6
54004- 74 74 74 250 250 250 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 242 242 242 242 242 242
54007-253 253 253 253 253 253 253 253 253 253 253 253
54008-253 253 253 253 253 253 253 253 253 253 253 253
54009-253 253 253 253 253 253 253 253 253 253 253 253
54010-253 253 253 253 253 253 253 253 253 253 253 253
54011-253 253 253 253 253 253 182 182 182 2 2 6
54012- 2 2 6 2 2 6 2 2 6 46 46 46
54013- 2 2 6 2 2 6 2 2 6 2 2 6
54014- 10 10 10 86 86 86 38 38 38 10 10 10
54015- 0 0 0 0 0 0 0 0 0 0 0 0
54016- 0 0 0 0 0 0 0 0 0 0 0 0
54017- 0 0 0 0 0 0 0 0 0 0 0 0
54018- 0 0 0 0 0 0 0 0 0 0 0 0
54019- 0 0 0 0 0 0 0 0 0 0 0 0
54020- 0 0 0 0 0 0 0 0 0 0 0 0
54021- 0 0 0 0 0 0 0 0 0 0 0 0
54022- 10 10 10 26 26 26 66 66 66 82 82 82
54023- 2 2 6 22 22 22 18 18 18 2 2 6
54024-149 149 149 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 242 242 242
54027-253 253 253 253 253 253 253 253 253 253 253 253
54028-253 253 253 253 253 253 253 253 253 253 253 253
54029-253 253 253 253 253 253 253 253 253 253 253 253
54030-253 253 253 253 253 253 253 253 253 253 253 253
54031-253 253 253 253 253 253 206 206 206 2 2 6
54032- 2 2 6 2 2 6 2 2 6 38 38 38
54033- 2 2 6 2 2 6 2 2 6 2 2 6
54034- 6 6 6 86 86 86 46 46 46 14 14 14
54035- 0 0 0 0 0 0 0 0 0 0 0 0
54036- 0 0 0 0 0 0 0 0 0 0 0 0
54037- 0 0 0 0 0 0 0 0 0 0 0 0
54038- 0 0 0 0 0 0 0 0 0 0 0 0
54039- 0 0 0 0 0 0 0 0 0 0 0 0
54040- 0 0 0 0 0 0 0 0 0 0 0 0
54041- 0 0 0 0 0 0 0 0 0 6 6 6
54042- 18 18 18 46 46 46 86 86 86 18 18 18
54043- 2 2 6 34 34 34 10 10 10 6 6 6
54044-210 210 210 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 242 242 242
54047-253 253 253 253 253 253 253 253 253 253 253 253
54048-253 253 253 253 253 253 253 253 253 253 253 253
54049-253 253 253 253 253 253 253 253 253 253 253 253
54050-253 253 253 253 253 253 253 253 253 253 253 253
54051-253 253 253 253 253 253 221 221 221 6 6 6
54052- 2 2 6 2 2 6 6 6 6 30 30 30
54053- 2 2 6 2 2 6 2 2 6 2 2 6
54054- 2 2 6 82 82 82 54 54 54 18 18 18
54055- 6 6 6 0 0 0 0 0 0 0 0 0
54056- 0 0 0 0 0 0 0 0 0 0 0 0
54057- 0 0 0 0 0 0 0 0 0 0 0 0
54058- 0 0 0 0 0 0 0 0 0 0 0 0
54059- 0 0 0 0 0 0 0 0 0 0 0 0
54060- 0 0 0 0 0 0 0 0 0 0 0 0
54061- 0 0 0 0 0 0 0 0 0 10 10 10
54062- 26 26 26 66 66 66 62 62 62 2 2 6
54063- 2 2 6 38 38 38 10 10 10 26 26 26
54064-238 238 238 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 231 231 231 238 238 238
54067-253 253 253 253 253 253 253 253 253 253 253 253
54068-253 253 253 253 253 253 253 253 253 253 253 253
54069-253 253 253 253 253 253 253 253 253 253 253 253
54070-253 253 253 253 253 253 253 253 253 253 253 253
54071-253 253 253 253 253 253 231 231 231 6 6 6
54072- 2 2 6 2 2 6 10 10 10 30 30 30
54073- 2 2 6 2 2 6 2 2 6 2 2 6
54074- 2 2 6 66 66 66 58 58 58 22 22 22
54075- 6 6 6 0 0 0 0 0 0 0 0 0
54076- 0 0 0 0 0 0 0 0 0 0 0 0
54077- 0 0 0 0 0 0 0 0 0 0 0 0
54078- 0 0 0 0 0 0 0 0 0 0 0 0
54079- 0 0 0 0 0 0 0 0 0 0 0 0
54080- 0 0 0 0 0 0 0 0 0 0 0 0
54081- 0 0 0 0 0 0 0 0 0 10 10 10
54082- 38 38 38 78 78 78 6 6 6 2 2 6
54083- 2 2 6 46 46 46 14 14 14 42 42 42
54084-246 246 246 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 231 231 231 242 242 242
54087-253 253 253 253 253 253 253 253 253 253 253 253
54088-253 253 253 253 253 253 253 253 253 253 253 253
54089-253 253 253 253 253 253 253 253 253 253 253 253
54090-253 253 253 253 253 253 253 253 253 253 253 253
54091-253 253 253 253 253 253 234 234 234 10 10 10
54092- 2 2 6 2 2 6 22 22 22 14 14 14
54093- 2 2 6 2 2 6 2 2 6 2 2 6
54094- 2 2 6 66 66 66 62 62 62 22 22 22
54095- 6 6 6 0 0 0 0 0 0 0 0 0
54096- 0 0 0 0 0 0 0 0 0 0 0 0
54097- 0 0 0 0 0 0 0 0 0 0 0 0
54098- 0 0 0 0 0 0 0 0 0 0 0 0
54099- 0 0 0 0 0 0 0 0 0 0 0 0
54100- 0 0 0 0 0 0 0 0 0 0 0 0
54101- 0 0 0 0 0 0 6 6 6 18 18 18
54102- 50 50 50 74 74 74 2 2 6 2 2 6
54103- 14 14 14 70 70 70 34 34 34 62 62 62
54104-250 250 250 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 231 231 231 246 246 246
54107-253 253 253 253 253 253 253 253 253 253 253 253
54108-253 253 253 253 253 253 253 253 253 253 253 253
54109-253 253 253 253 253 253 253 253 253 253 253 253
54110-253 253 253 253 253 253 253 253 253 253 253 253
54111-253 253 253 253 253 253 234 234 234 14 14 14
54112- 2 2 6 2 2 6 30 30 30 2 2 6
54113- 2 2 6 2 2 6 2 2 6 2 2 6
54114- 2 2 6 66 66 66 62 62 62 22 22 22
54115- 6 6 6 0 0 0 0 0 0 0 0 0
54116- 0 0 0 0 0 0 0 0 0 0 0 0
54117- 0 0 0 0 0 0 0 0 0 0 0 0
54118- 0 0 0 0 0 0 0 0 0 0 0 0
54119- 0 0 0 0 0 0 0 0 0 0 0 0
54120- 0 0 0 0 0 0 0 0 0 0 0 0
54121- 0 0 0 0 0 0 6 6 6 18 18 18
54122- 54 54 54 62 62 62 2 2 6 2 2 6
54123- 2 2 6 30 30 30 46 46 46 70 70 70
54124-250 250 250 253 253 253 253 253 253 253 253 253
54125-253 253 253 253 253 253 253 253 253 253 253 253
54126-253 253 253 253 253 253 231 231 231 246 246 246
54127-253 253 253 253 253 253 253 253 253 253 253 253
54128-253 253 253 253 253 253 253 253 253 253 253 253
54129-253 253 253 253 253 253 253 253 253 253 253 253
54130-253 253 253 253 253 253 253 253 253 253 253 253
54131-253 253 253 253 253 253 226 226 226 10 10 10
54132- 2 2 6 6 6 6 30 30 30 2 2 6
54133- 2 2 6 2 2 6 2 2 6 2 2 6
54134- 2 2 6 66 66 66 58 58 58 22 22 22
54135- 6 6 6 0 0 0 0 0 0 0 0 0
54136- 0 0 0 0 0 0 0 0 0 0 0 0
54137- 0 0 0 0 0 0 0 0 0 0 0 0
54138- 0 0 0 0 0 0 0 0 0 0 0 0
54139- 0 0 0 0 0 0 0 0 0 0 0 0
54140- 0 0 0 0 0 0 0 0 0 0 0 0
54141- 0 0 0 0 0 0 6 6 6 22 22 22
54142- 58 58 58 62 62 62 2 2 6 2 2 6
54143- 2 2 6 2 2 6 30 30 30 78 78 78
54144-250 250 250 253 253 253 253 253 253 253 253 253
54145-253 253 253 253 253 253 253 253 253 253 253 253
54146-253 253 253 253 253 253 231 231 231 246 246 246
54147-253 253 253 253 253 253 253 253 253 253 253 253
54148-253 253 253 253 253 253 253 253 253 253 253 253
54149-253 253 253 253 253 253 253 253 253 253 253 253
54150-253 253 253 253 253 253 253 253 253 253 253 253
54151-253 253 253 253 253 253 206 206 206 2 2 6
54152- 22 22 22 34 34 34 18 14 6 22 22 22
54153- 26 26 26 18 18 18 6 6 6 2 2 6
54154- 2 2 6 82 82 82 54 54 54 18 18 18
54155- 6 6 6 0 0 0 0 0 0 0 0 0
54156- 0 0 0 0 0 0 0 0 0 0 0 0
54157- 0 0 0 0 0 0 0 0 0 0 0 0
54158- 0 0 0 0 0 0 0 0 0 0 0 0
54159- 0 0 0 0 0 0 0 0 0 0 0 0
54160- 0 0 0 0 0 0 0 0 0 0 0 0
54161- 0 0 0 0 0 0 6 6 6 26 26 26
54162- 62 62 62 106 106 106 74 54 14 185 133 11
54163-210 162 10 121 92 8 6 6 6 62 62 62
54164-238 238 238 253 253 253 253 253 253 253 253 253
54165-253 253 253 253 253 253 253 253 253 253 253 253
54166-253 253 253 253 253 253 231 231 231 246 246 246
54167-253 253 253 253 253 253 253 253 253 253 253 253
54168-253 253 253 253 253 253 253 253 253 253 253 253
54169-253 253 253 253 253 253 253 253 253 253 253 253
54170-253 253 253 253 253 253 253 253 253 253 253 253
54171-253 253 253 253 253 253 158 158 158 18 18 18
54172- 14 14 14 2 2 6 2 2 6 2 2 6
54173- 6 6 6 18 18 18 66 66 66 38 38 38
54174- 6 6 6 94 94 94 50 50 50 18 18 18
54175- 6 6 6 0 0 0 0 0 0 0 0 0
54176- 0 0 0 0 0 0 0 0 0 0 0 0
54177- 0 0 0 0 0 0 0 0 0 0 0 0
54178- 0 0 0 0 0 0 0 0 0 0 0 0
54179- 0 0 0 0 0 0 0 0 0 0 0 0
54180- 0 0 0 0 0 0 0 0 0 6 6 6
54181- 10 10 10 10 10 10 18 18 18 38 38 38
54182- 78 78 78 142 134 106 216 158 10 242 186 14
54183-246 190 14 246 190 14 156 118 10 10 10 10
54184- 90 90 90 238 238 238 253 253 253 253 253 253
54185-253 253 253 253 253 253 253 253 253 253 253 253
54186-253 253 253 253 253 253 231 231 231 250 250 250
54187-253 253 253 253 253 253 253 253 253 253 253 253
54188-253 253 253 253 253 253 253 253 253 253 253 253
54189-253 253 253 253 253 253 253 253 253 253 253 253
54190-253 253 253 253 253 253 253 253 253 246 230 190
54191-238 204 91 238 204 91 181 142 44 37 26 9
54192- 2 2 6 2 2 6 2 2 6 2 2 6
54193- 2 2 6 2 2 6 38 38 38 46 46 46
54194- 26 26 26 106 106 106 54 54 54 18 18 18
54195- 6 6 6 0 0 0 0 0 0 0 0 0
54196- 0 0 0 0 0 0 0 0 0 0 0 0
54197- 0 0 0 0 0 0 0 0 0 0 0 0
54198- 0 0 0 0 0 0 0 0 0 0 0 0
54199- 0 0 0 0 0 0 0 0 0 0 0 0
54200- 0 0 0 6 6 6 14 14 14 22 22 22
54201- 30 30 30 38 38 38 50 50 50 70 70 70
54202-106 106 106 190 142 34 226 170 11 242 186 14
54203-246 190 14 246 190 14 246 190 14 154 114 10
54204- 6 6 6 74 74 74 226 226 226 253 253 253
54205-253 253 253 253 253 253 253 253 253 253 253 253
54206-253 253 253 253 253 253 231 231 231 250 250 250
54207-253 253 253 253 253 253 253 253 253 253 253 253
54208-253 253 253 253 253 253 253 253 253 253 253 253
54209-253 253 253 253 253 253 253 253 253 253 253 253
54210-253 253 253 253 253 253 253 253 253 228 184 62
54211-241 196 14 241 208 19 232 195 16 38 30 10
54212- 2 2 6 2 2 6 2 2 6 2 2 6
54213- 2 2 6 6 6 6 30 30 30 26 26 26
54214-203 166 17 154 142 90 66 66 66 26 26 26
54215- 6 6 6 0 0 0 0 0 0 0 0 0
54216- 0 0 0 0 0 0 0 0 0 0 0 0
54217- 0 0 0 0 0 0 0 0 0 0 0 0
54218- 0 0 0 0 0 0 0 0 0 0 0 0
54219- 0 0 0 0 0 0 0 0 0 0 0 0
54220- 6 6 6 18 18 18 38 38 38 58 58 58
54221- 78 78 78 86 86 86 101 101 101 123 123 123
54222-175 146 61 210 150 10 234 174 13 246 186 14
54223-246 190 14 246 190 14 246 190 14 238 190 10
54224-102 78 10 2 2 6 46 46 46 198 198 198
54225-253 253 253 253 253 253 253 253 253 253 253 253
54226-253 253 253 253 253 253 234 234 234 242 242 242
54227-253 253 253 253 253 253 253 253 253 253 253 253
54228-253 253 253 253 253 253 253 253 253 253 253 253
54229-253 253 253 253 253 253 253 253 253 253 253 253
54230-253 253 253 253 253 253 253 253 253 224 178 62
54231-242 186 14 241 196 14 210 166 10 22 18 6
54232- 2 2 6 2 2 6 2 2 6 2 2 6
54233- 2 2 6 2 2 6 6 6 6 121 92 8
54234-238 202 15 232 195 16 82 82 82 34 34 34
54235- 10 10 10 0 0 0 0 0 0 0 0 0
54236- 0 0 0 0 0 0 0 0 0 0 0 0
54237- 0 0 0 0 0 0 0 0 0 0 0 0
54238- 0 0 0 0 0 0 0 0 0 0 0 0
54239- 0 0 0 0 0 0 0 0 0 0 0 0
54240- 14 14 14 38 38 38 70 70 70 154 122 46
54241-190 142 34 200 144 11 197 138 11 197 138 11
54242-213 154 11 226 170 11 242 186 14 246 190 14
54243-246 190 14 246 190 14 246 190 14 246 190 14
54244-225 175 15 46 32 6 2 2 6 22 22 22
54245-158 158 158 250 250 250 253 253 253 253 253 253
54246-253 253 253 253 253 253 253 253 253 253 253 253
54247-253 253 253 253 253 253 253 253 253 253 253 253
54248-253 253 253 253 253 253 253 253 253 253 253 253
54249-253 253 253 253 253 253 253 253 253 253 253 253
54250-253 253 253 250 250 250 242 242 242 224 178 62
54251-239 182 13 236 186 11 213 154 11 46 32 6
54252- 2 2 6 2 2 6 2 2 6 2 2 6
54253- 2 2 6 2 2 6 61 42 6 225 175 15
54254-238 190 10 236 186 11 112 100 78 42 42 42
54255- 14 14 14 0 0 0 0 0 0 0 0 0
54256- 0 0 0 0 0 0 0 0 0 0 0 0
54257- 0 0 0 0 0 0 0 0 0 0 0 0
54258- 0 0 0 0 0 0 0 0 0 0 0 0
54259- 0 0 0 0 0 0 0 0 0 6 6 6
54260- 22 22 22 54 54 54 154 122 46 213 154 11
54261-226 170 11 230 174 11 226 170 11 226 170 11
54262-236 178 12 242 186 14 246 190 14 246 190 14
54263-246 190 14 246 190 14 246 190 14 246 190 14
54264-241 196 14 184 144 12 10 10 10 2 2 6
54265- 6 6 6 116 116 116 242 242 242 253 253 253
54266-253 253 253 253 253 253 253 253 253 253 253 253
54267-253 253 253 253 253 253 253 253 253 253 253 253
54268-253 253 253 253 253 253 253 253 253 253 253 253
54269-253 253 253 253 253 253 253 253 253 253 253 253
54270-253 253 253 231 231 231 198 198 198 214 170 54
54271-236 178 12 236 178 12 210 150 10 137 92 6
54272- 18 14 6 2 2 6 2 2 6 2 2 6
54273- 6 6 6 70 47 6 200 144 11 236 178 12
54274-239 182 13 239 182 13 124 112 88 58 58 58
54275- 22 22 22 6 6 6 0 0 0 0 0 0
54276- 0 0 0 0 0 0 0 0 0 0 0 0
54277- 0 0 0 0 0 0 0 0 0 0 0 0
54278- 0 0 0 0 0 0 0 0 0 0 0 0
54279- 0 0 0 0 0 0 0 0 0 10 10 10
54280- 30 30 30 70 70 70 180 133 36 226 170 11
54281-239 182 13 242 186 14 242 186 14 246 186 14
54282-246 190 14 246 190 14 246 190 14 246 190 14
54283-246 190 14 246 190 14 246 190 14 246 190 14
54284-246 190 14 232 195 16 98 70 6 2 2 6
54285- 2 2 6 2 2 6 66 66 66 221 221 221
54286-253 253 253 253 253 253 253 253 253 253 253 253
54287-253 253 253 253 253 253 253 253 253 253 253 253
54288-253 253 253 253 253 253 253 253 253 253 253 253
54289-253 253 253 253 253 253 253 253 253 253 253 253
54290-253 253 253 206 206 206 198 198 198 214 166 58
54291-230 174 11 230 174 11 216 158 10 192 133 9
54292-163 110 8 116 81 8 102 78 10 116 81 8
54293-167 114 7 197 138 11 226 170 11 239 182 13
54294-242 186 14 242 186 14 162 146 94 78 78 78
54295- 34 34 34 14 14 14 6 6 6 0 0 0
54296- 0 0 0 0 0 0 0 0 0 0 0 0
54297- 0 0 0 0 0 0 0 0 0 0 0 0
54298- 0 0 0 0 0 0 0 0 0 0 0 0
54299- 0 0 0 0 0 0 0 0 0 6 6 6
54300- 30 30 30 78 78 78 190 142 34 226 170 11
54301-239 182 13 246 190 14 246 190 14 246 190 14
54302-246 190 14 246 190 14 246 190 14 246 190 14
54303-246 190 14 246 190 14 246 190 14 246 190 14
54304-246 190 14 241 196 14 203 166 17 22 18 6
54305- 2 2 6 2 2 6 2 2 6 38 38 38
54306-218 218 218 253 253 253 253 253 253 253 253 253
54307-253 253 253 253 253 253 253 253 253 253 253 253
54308-253 253 253 253 253 253 253 253 253 253 253 253
54309-253 253 253 253 253 253 253 253 253 253 253 253
54310-250 250 250 206 206 206 198 198 198 202 162 69
54311-226 170 11 236 178 12 224 166 10 210 150 10
54312-200 144 11 197 138 11 192 133 9 197 138 11
54313-210 150 10 226 170 11 242 186 14 246 190 14
54314-246 190 14 246 186 14 225 175 15 124 112 88
54315- 62 62 62 30 30 30 14 14 14 6 6 6
54316- 0 0 0 0 0 0 0 0 0 0 0 0
54317- 0 0 0 0 0 0 0 0 0 0 0 0
54318- 0 0 0 0 0 0 0 0 0 0 0 0
54319- 0 0 0 0 0 0 0 0 0 10 10 10
54320- 30 30 30 78 78 78 174 135 50 224 166 10
54321-239 182 13 246 190 14 246 190 14 246 190 14
54322-246 190 14 246 190 14 246 190 14 246 190 14
54323-246 190 14 246 190 14 246 190 14 246 190 14
54324-246 190 14 246 190 14 241 196 14 139 102 15
54325- 2 2 6 2 2 6 2 2 6 2 2 6
54326- 78 78 78 250 250 250 253 253 253 253 253 253
54327-253 253 253 253 253 253 253 253 253 253 253 253
54328-253 253 253 253 253 253 253 253 253 253 253 253
54329-253 253 253 253 253 253 253 253 253 253 253 253
54330-250 250 250 214 214 214 198 198 198 190 150 46
54331-219 162 10 236 178 12 234 174 13 224 166 10
54332-216 158 10 213 154 11 213 154 11 216 158 10
54333-226 170 11 239 182 13 246 190 14 246 190 14
54334-246 190 14 246 190 14 242 186 14 206 162 42
54335-101 101 101 58 58 58 30 30 30 14 14 14
54336- 6 6 6 0 0 0 0 0 0 0 0 0
54337- 0 0 0 0 0 0 0 0 0 0 0 0
54338- 0 0 0 0 0 0 0 0 0 0 0 0
54339- 0 0 0 0 0 0 0 0 0 10 10 10
54340- 30 30 30 74 74 74 174 135 50 216 158 10
54341-236 178 12 246 190 14 246 190 14 246 190 14
54342-246 190 14 246 190 14 246 190 14 246 190 14
54343-246 190 14 246 190 14 246 190 14 246 190 14
54344-246 190 14 246 190 14 241 196 14 226 184 13
54345- 61 42 6 2 2 6 2 2 6 2 2 6
54346- 22 22 22 238 238 238 253 253 253 253 253 253
54347-253 253 253 253 253 253 253 253 253 253 253 253
54348-253 253 253 253 253 253 253 253 253 253 253 253
54349-253 253 253 253 253 253 253 253 253 253 253 253
54350-253 253 253 226 226 226 187 187 187 180 133 36
54351-216 158 10 236 178 12 239 182 13 236 178 12
54352-230 174 11 226 170 11 226 170 11 230 174 11
54353-236 178 12 242 186 14 246 190 14 246 190 14
54354-246 190 14 246 190 14 246 186 14 239 182 13
54355-206 162 42 106 106 106 66 66 66 34 34 34
54356- 14 14 14 6 6 6 0 0 0 0 0 0
54357- 0 0 0 0 0 0 0 0 0 0 0 0
54358- 0 0 0 0 0 0 0 0 0 0 0 0
54359- 0 0 0 0 0 0 0 0 0 6 6 6
54360- 26 26 26 70 70 70 163 133 67 213 154 11
54361-236 178 12 246 190 14 246 190 14 246 190 14
54362-246 190 14 246 190 14 246 190 14 246 190 14
54363-246 190 14 246 190 14 246 190 14 246 190 14
54364-246 190 14 246 190 14 246 190 14 241 196 14
54365-190 146 13 18 14 6 2 2 6 2 2 6
54366- 46 46 46 246 246 246 253 253 253 253 253 253
54367-253 253 253 253 253 253 253 253 253 253 253 253
54368-253 253 253 253 253 253 253 253 253 253 253 253
54369-253 253 253 253 253 253 253 253 253 253 253 253
54370-253 253 253 221 221 221 86 86 86 156 107 11
54371-216 158 10 236 178 12 242 186 14 246 186 14
54372-242 186 14 239 182 13 239 182 13 242 186 14
54373-242 186 14 246 186 14 246 190 14 246 190 14
54374-246 190 14 246 190 14 246 190 14 246 190 14
54375-242 186 14 225 175 15 142 122 72 66 66 66
54376- 30 30 30 10 10 10 0 0 0 0 0 0
54377- 0 0 0 0 0 0 0 0 0 0 0 0
54378- 0 0 0 0 0 0 0 0 0 0 0 0
54379- 0 0 0 0 0 0 0 0 0 6 6 6
54380- 26 26 26 70 70 70 163 133 67 210 150 10
54381-236 178 12 246 190 14 246 190 14 246 190 14
54382-246 190 14 246 190 14 246 190 14 246 190 14
54383-246 190 14 246 190 14 246 190 14 246 190 14
54384-246 190 14 246 190 14 246 190 14 246 190 14
54385-232 195 16 121 92 8 34 34 34 106 106 106
54386-221 221 221 253 253 253 253 253 253 253 253 253
54387-253 253 253 253 253 253 253 253 253 253 253 253
54388-253 253 253 253 253 253 253 253 253 253 253 253
54389-253 253 253 253 253 253 253 253 253 253 253 253
54390-242 242 242 82 82 82 18 14 6 163 110 8
54391-216 158 10 236 178 12 242 186 14 246 190 14
54392-246 190 14 246 190 14 246 190 14 246 190 14
54393-246 190 14 246 190 14 246 190 14 246 190 14
54394-246 190 14 246 190 14 246 190 14 246 190 14
54395-246 190 14 246 190 14 242 186 14 163 133 67
54396- 46 46 46 18 18 18 6 6 6 0 0 0
54397- 0 0 0 0 0 0 0 0 0 0 0 0
54398- 0 0 0 0 0 0 0 0 0 0 0 0
54399- 0 0 0 0 0 0 0 0 0 10 10 10
54400- 30 30 30 78 78 78 163 133 67 210 150 10
54401-236 178 12 246 186 14 246 190 14 246 190 14
54402-246 190 14 246 190 14 246 190 14 246 190 14
54403-246 190 14 246 190 14 246 190 14 246 190 14
54404-246 190 14 246 190 14 246 190 14 246 190 14
54405-241 196 14 215 174 15 190 178 144 253 253 253
54406-253 253 253 253 253 253 253 253 253 253 253 253
54407-253 253 253 253 253 253 253 253 253 253 253 253
54408-253 253 253 253 253 253 253 253 253 253 253 253
54409-253 253 253 253 253 253 253 253 253 218 218 218
54410- 58 58 58 2 2 6 22 18 6 167 114 7
54411-216 158 10 236 178 12 246 186 14 246 190 14
54412-246 190 14 246 190 14 246 190 14 246 190 14
54413-246 190 14 246 190 14 246 190 14 246 190 14
54414-246 190 14 246 190 14 246 190 14 246 190 14
54415-246 190 14 246 186 14 242 186 14 190 150 46
54416- 54 54 54 22 22 22 6 6 6 0 0 0
54417- 0 0 0 0 0 0 0 0 0 0 0 0
54418- 0 0 0 0 0 0 0 0 0 0 0 0
54419- 0 0 0 0 0 0 0 0 0 14 14 14
54420- 38 38 38 86 86 86 180 133 36 213 154 11
54421-236 178 12 246 186 14 246 190 14 246 190 14
54422-246 190 14 246 190 14 246 190 14 246 190 14
54423-246 190 14 246 190 14 246 190 14 246 190 14
54424-246 190 14 246 190 14 246 190 14 246 190 14
54425-246 190 14 232 195 16 190 146 13 214 214 214
54426-253 253 253 253 253 253 253 253 253 253 253 253
54427-253 253 253 253 253 253 253 253 253 253 253 253
54428-253 253 253 253 253 253 253 253 253 253 253 253
54429-253 253 253 250 250 250 170 170 170 26 26 26
54430- 2 2 6 2 2 6 37 26 9 163 110 8
54431-219 162 10 239 182 13 246 186 14 246 190 14
54432-246 190 14 246 190 14 246 190 14 246 190 14
54433-246 190 14 246 190 14 246 190 14 246 190 14
54434-246 190 14 246 190 14 246 190 14 246 190 14
54435-246 186 14 236 178 12 224 166 10 142 122 72
54436- 46 46 46 18 18 18 6 6 6 0 0 0
54437- 0 0 0 0 0 0 0 0 0 0 0 0
54438- 0 0 0 0 0 0 0 0 0 0 0 0
54439- 0 0 0 0 0 0 6 6 6 18 18 18
54440- 50 50 50 109 106 95 192 133 9 224 166 10
54441-242 186 14 246 190 14 246 190 14 246 190 14
54442-246 190 14 246 190 14 246 190 14 246 190 14
54443-246 190 14 246 190 14 246 190 14 246 190 14
54444-246 190 14 246 190 14 246 190 14 246 190 14
54445-242 186 14 226 184 13 210 162 10 142 110 46
54446-226 226 226 253 253 253 253 253 253 253 253 253
54447-253 253 253 253 253 253 253 253 253 253 253 253
54448-253 253 253 253 253 253 253 253 253 253 253 253
54449-198 198 198 66 66 66 2 2 6 2 2 6
54450- 2 2 6 2 2 6 50 34 6 156 107 11
54451-219 162 10 239 182 13 246 186 14 246 190 14
54452-246 190 14 246 190 14 246 190 14 246 190 14
54453-246 190 14 246 190 14 246 190 14 246 190 14
54454-246 190 14 246 190 14 246 190 14 242 186 14
54455-234 174 13 213 154 11 154 122 46 66 66 66
54456- 30 30 30 10 10 10 0 0 0 0 0 0
54457- 0 0 0 0 0 0 0 0 0 0 0 0
54458- 0 0 0 0 0 0 0 0 0 0 0 0
54459- 0 0 0 0 0 0 6 6 6 22 22 22
54460- 58 58 58 154 121 60 206 145 10 234 174 13
54461-242 186 14 246 186 14 246 190 14 246 190 14
54462-246 190 14 246 190 14 246 190 14 246 190 14
54463-246 190 14 246 190 14 246 190 14 246 190 14
54464-246 190 14 246 190 14 246 190 14 246 190 14
54465-246 186 14 236 178 12 210 162 10 163 110 8
54466- 61 42 6 138 138 138 218 218 218 250 250 250
54467-253 253 253 253 253 253 253 253 253 250 250 250
54468-242 242 242 210 210 210 144 144 144 66 66 66
54469- 6 6 6 2 2 6 2 2 6 2 2 6
54470- 2 2 6 2 2 6 61 42 6 163 110 8
54471-216 158 10 236 178 12 246 190 14 246 190 14
54472-246 190 14 246 190 14 246 190 14 246 190 14
54473-246 190 14 246 190 14 246 190 14 246 190 14
54474-246 190 14 239 182 13 230 174 11 216 158 10
54475-190 142 34 124 112 88 70 70 70 38 38 38
54476- 18 18 18 6 6 6 0 0 0 0 0 0
54477- 0 0 0 0 0 0 0 0 0 0 0 0
54478- 0 0 0 0 0 0 0 0 0 0 0 0
54479- 0 0 0 0 0 0 6 6 6 22 22 22
54480- 62 62 62 168 124 44 206 145 10 224 166 10
54481-236 178 12 239 182 13 242 186 14 242 186 14
54482-246 186 14 246 190 14 246 190 14 246 190 14
54483-246 190 14 246 190 14 246 190 14 246 190 14
54484-246 190 14 246 190 14 246 190 14 246 190 14
54485-246 190 14 236 178 12 216 158 10 175 118 6
54486- 80 54 7 2 2 6 6 6 6 30 30 30
54487- 54 54 54 62 62 62 50 50 50 38 38 38
54488- 14 14 14 2 2 6 2 2 6 2 2 6
54489- 2 2 6 2 2 6 2 2 6 2 2 6
54490- 2 2 6 6 6 6 80 54 7 167 114 7
54491-213 154 11 236 178 12 246 190 14 246 190 14
54492-246 190 14 246 190 14 246 190 14 246 190 14
54493-246 190 14 242 186 14 239 182 13 239 182 13
54494-230 174 11 210 150 10 174 135 50 124 112 88
54495- 82 82 82 54 54 54 34 34 34 18 18 18
54496- 6 6 6 0 0 0 0 0 0 0 0 0
54497- 0 0 0 0 0 0 0 0 0 0 0 0
54498- 0 0 0 0 0 0 0 0 0 0 0 0
54499- 0 0 0 0 0 0 6 6 6 18 18 18
54500- 50 50 50 158 118 36 192 133 9 200 144 11
54501-216 158 10 219 162 10 224 166 10 226 170 11
54502-230 174 11 236 178 12 239 182 13 239 182 13
54503-242 186 14 246 186 14 246 190 14 246 190 14
54504-246 190 14 246 190 14 246 190 14 246 190 14
54505-246 186 14 230 174 11 210 150 10 163 110 8
54506-104 69 6 10 10 10 2 2 6 2 2 6
54507- 2 2 6 2 2 6 2 2 6 2 2 6
54508- 2 2 6 2 2 6 2 2 6 2 2 6
54509- 2 2 6 2 2 6 2 2 6 2 2 6
54510- 2 2 6 6 6 6 91 60 6 167 114 7
54511-206 145 10 230 174 11 242 186 14 246 190 14
54512-246 190 14 246 190 14 246 186 14 242 186 14
54513-239 182 13 230 174 11 224 166 10 213 154 11
54514-180 133 36 124 112 88 86 86 86 58 58 58
54515- 38 38 38 22 22 22 10 10 10 6 6 6
54516- 0 0 0 0 0 0 0 0 0 0 0 0
54517- 0 0 0 0 0 0 0 0 0 0 0 0
54518- 0 0 0 0 0 0 0 0 0 0 0 0
54519- 0 0 0 0 0 0 0 0 0 14 14 14
54520- 34 34 34 70 70 70 138 110 50 158 118 36
54521-167 114 7 180 123 7 192 133 9 197 138 11
54522-200 144 11 206 145 10 213 154 11 219 162 10
54523-224 166 10 230 174 11 239 182 13 242 186 14
54524-246 186 14 246 186 14 246 186 14 246 186 14
54525-239 182 13 216 158 10 185 133 11 152 99 6
54526-104 69 6 18 14 6 2 2 6 2 2 6
54527- 2 2 6 2 2 6 2 2 6 2 2 6
54528- 2 2 6 2 2 6 2 2 6 2 2 6
54529- 2 2 6 2 2 6 2 2 6 2 2 6
54530- 2 2 6 6 6 6 80 54 7 152 99 6
54531-192 133 9 219 162 10 236 178 12 239 182 13
54532-246 186 14 242 186 14 239 182 13 236 178 12
54533-224 166 10 206 145 10 192 133 9 154 121 60
54534- 94 94 94 62 62 62 42 42 42 22 22 22
54535- 14 14 14 6 6 6 0 0 0 0 0 0
54536- 0 0 0 0 0 0 0 0 0 0 0 0
54537- 0 0 0 0 0 0 0 0 0 0 0 0
54538- 0 0 0 0 0 0 0 0 0 0 0 0
54539- 0 0 0 0 0 0 0 0 0 6 6 6
54540- 18 18 18 34 34 34 58 58 58 78 78 78
54541-101 98 89 124 112 88 142 110 46 156 107 11
54542-163 110 8 167 114 7 175 118 6 180 123 7
54543-185 133 11 197 138 11 210 150 10 219 162 10
54544-226 170 11 236 178 12 236 178 12 234 174 13
54545-219 162 10 197 138 11 163 110 8 130 83 6
54546- 91 60 6 10 10 10 2 2 6 2 2 6
54547- 18 18 18 38 38 38 38 38 38 38 38 38
54548- 38 38 38 38 38 38 38 38 38 38 38 38
54549- 38 38 38 38 38 38 26 26 26 2 2 6
54550- 2 2 6 6 6 6 70 47 6 137 92 6
54551-175 118 6 200 144 11 219 162 10 230 174 11
54552-234 174 13 230 174 11 219 162 10 210 150 10
54553-192 133 9 163 110 8 124 112 88 82 82 82
54554- 50 50 50 30 30 30 14 14 14 6 6 6
54555- 0 0 0 0 0 0 0 0 0 0 0 0
54556- 0 0 0 0 0 0 0 0 0 0 0 0
54557- 0 0 0 0 0 0 0 0 0 0 0 0
54558- 0 0 0 0 0 0 0 0 0 0 0 0
54559- 0 0 0 0 0 0 0 0 0 0 0 0
54560- 6 6 6 14 14 14 22 22 22 34 34 34
54561- 42 42 42 58 58 58 74 74 74 86 86 86
54562-101 98 89 122 102 70 130 98 46 121 87 25
54563-137 92 6 152 99 6 163 110 8 180 123 7
54564-185 133 11 197 138 11 206 145 10 200 144 11
54565-180 123 7 156 107 11 130 83 6 104 69 6
54566- 50 34 6 54 54 54 110 110 110 101 98 89
54567- 86 86 86 82 82 82 78 78 78 78 78 78
54568- 78 78 78 78 78 78 78 78 78 78 78 78
54569- 78 78 78 82 82 82 86 86 86 94 94 94
54570-106 106 106 101 101 101 86 66 34 124 80 6
54571-156 107 11 180 123 7 192 133 9 200 144 11
54572-206 145 10 200 144 11 192 133 9 175 118 6
54573-139 102 15 109 106 95 70 70 70 42 42 42
54574- 22 22 22 10 10 10 0 0 0 0 0 0
54575- 0 0 0 0 0 0 0 0 0 0 0 0
54576- 0 0 0 0 0 0 0 0 0 0 0 0
54577- 0 0 0 0 0 0 0 0 0 0 0 0
54578- 0 0 0 0 0 0 0 0 0 0 0 0
54579- 0 0 0 0 0 0 0 0 0 0 0 0
54580- 0 0 0 0 0 0 6 6 6 10 10 10
54581- 14 14 14 22 22 22 30 30 30 38 38 38
54582- 50 50 50 62 62 62 74 74 74 90 90 90
54583-101 98 89 112 100 78 121 87 25 124 80 6
54584-137 92 6 152 99 6 152 99 6 152 99 6
54585-138 86 6 124 80 6 98 70 6 86 66 30
54586-101 98 89 82 82 82 58 58 58 46 46 46
54587- 38 38 38 34 34 34 34 34 34 34 34 34
54588- 34 34 34 34 34 34 34 34 34 34 34 34
54589- 34 34 34 34 34 34 38 38 38 42 42 42
54590- 54 54 54 82 82 82 94 86 76 91 60 6
54591-134 86 6 156 107 11 167 114 7 175 118 6
54592-175 118 6 167 114 7 152 99 6 121 87 25
54593-101 98 89 62 62 62 34 34 34 18 18 18
54594- 6 6 6 0 0 0 0 0 0 0 0 0
54595- 0 0 0 0 0 0 0 0 0 0 0 0
54596- 0 0 0 0 0 0 0 0 0 0 0 0
54597- 0 0 0 0 0 0 0 0 0 0 0 0
54598- 0 0 0 0 0 0 0 0 0 0 0 0
54599- 0 0 0 0 0 0 0 0 0 0 0 0
54600- 0 0 0 0 0 0 0 0 0 0 0 0
54601- 0 0 0 6 6 6 6 6 6 10 10 10
54602- 18 18 18 22 22 22 30 30 30 42 42 42
54603- 50 50 50 66 66 66 86 86 86 101 98 89
54604-106 86 58 98 70 6 104 69 6 104 69 6
54605-104 69 6 91 60 6 82 62 34 90 90 90
54606- 62 62 62 38 38 38 22 22 22 14 14 14
54607- 10 10 10 10 10 10 10 10 10 10 10 10
54608- 10 10 10 10 10 10 6 6 6 10 10 10
54609- 10 10 10 10 10 10 10 10 10 14 14 14
54610- 22 22 22 42 42 42 70 70 70 89 81 66
54611- 80 54 7 104 69 6 124 80 6 137 92 6
54612-134 86 6 116 81 8 100 82 52 86 86 86
54613- 58 58 58 30 30 30 14 14 14 6 6 6
54614- 0 0 0 0 0 0 0 0 0 0 0 0
54615- 0 0 0 0 0 0 0 0 0 0 0 0
54616- 0 0 0 0 0 0 0 0 0 0 0 0
54617- 0 0 0 0 0 0 0 0 0 0 0 0
54618- 0 0 0 0 0 0 0 0 0 0 0 0
54619- 0 0 0 0 0 0 0 0 0 0 0 0
54620- 0 0 0 0 0 0 0 0 0 0 0 0
54621- 0 0 0 0 0 0 0 0 0 0 0 0
54622- 0 0 0 6 6 6 10 10 10 14 14 14
54623- 18 18 18 26 26 26 38 38 38 54 54 54
54624- 70 70 70 86 86 86 94 86 76 89 81 66
54625- 89 81 66 86 86 86 74 74 74 50 50 50
54626- 30 30 30 14 14 14 6 6 6 0 0 0
54627- 0 0 0 0 0 0 0 0 0 0 0 0
54628- 0 0 0 0 0 0 0 0 0 0 0 0
54629- 0 0 0 0 0 0 0 0 0 0 0 0
54630- 6 6 6 18 18 18 34 34 34 58 58 58
54631- 82 82 82 89 81 66 89 81 66 89 81 66
54632- 94 86 66 94 86 76 74 74 74 50 50 50
54633- 26 26 26 14 14 14 6 6 6 0 0 0
54634- 0 0 0 0 0 0 0 0 0 0 0 0
54635- 0 0 0 0 0 0 0 0 0 0 0 0
54636- 0 0 0 0 0 0 0 0 0 0 0 0
54637- 0 0 0 0 0 0 0 0 0 0 0 0
54638- 0 0 0 0 0 0 0 0 0 0 0 0
54639- 0 0 0 0 0 0 0 0 0 0 0 0
54640- 0 0 0 0 0 0 0 0 0 0 0 0
54641- 0 0 0 0 0 0 0 0 0 0 0 0
54642- 0 0 0 0 0 0 0 0 0 0 0 0
54643- 6 6 6 6 6 6 14 14 14 18 18 18
54644- 30 30 30 38 38 38 46 46 46 54 54 54
54645- 50 50 50 42 42 42 30 30 30 18 18 18
54646- 10 10 10 0 0 0 0 0 0 0 0 0
54647- 0 0 0 0 0 0 0 0 0 0 0 0
54648- 0 0 0 0 0 0 0 0 0 0 0 0
54649- 0 0 0 0 0 0 0 0 0 0 0 0
54650- 0 0 0 6 6 6 14 14 14 26 26 26
54651- 38 38 38 50 50 50 58 58 58 58 58 58
54652- 54 54 54 42 42 42 30 30 30 18 18 18
54653- 10 10 10 0 0 0 0 0 0 0 0 0
54654- 0 0 0 0 0 0 0 0 0 0 0 0
54655- 0 0 0 0 0 0 0 0 0 0 0 0
54656- 0 0 0 0 0 0 0 0 0 0 0 0
54657- 0 0 0 0 0 0 0 0 0 0 0 0
54658- 0 0 0 0 0 0 0 0 0 0 0 0
54659- 0 0 0 0 0 0 0 0 0 0 0 0
54660- 0 0 0 0 0 0 0 0 0 0 0 0
54661- 0 0 0 0 0 0 0 0 0 0 0 0
54662- 0 0 0 0 0 0 0 0 0 0 0 0
54663- 0 0 0 0 0 0 0 0 0 6 6 6
54664- 6 6 6 10 10 10 14 14 14 18 18 18
54665- 18 18 18 14 14 14 10 10 10 6 6 6
54666- 0 0 0 0 0 0 0 0 0 0 0 0
54667- 0 0 0 0 0 0 0 0 0 0 0 0
54668- 0 0 0 0 0 0 0 0 0 0 0 0
54669- 0 0 0 0 0 0 0 0 0 0 0 0
54670- 0 0 0 0 0 0 0 0 0 6 6 6
54671- 14 14 14 18 18 18 22 22 22 22 22 22
54672- 18 18 18 14 14 14 10 10 10 6 6 6
54673- 0 0 0 0 0 0 0 0 0 0 0 0
54674- 0 0 0 0 0 0 0 0 0 0 0 0
54675- 0 0 0 0 0 0 0 0 0 0 0 0
54676- 0 0 0 0 0 0 0 0 0 0 0 0
54677- 0 0 0 0 0 0 0 0 0 0 0 0
54678+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54679+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54680+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54681+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54682+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54683+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54684+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54685+4 4 4 4 4 4 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
54692+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54693+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54694+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54695+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54696+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54697+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54698+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54699+4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4
54702+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54703+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54704+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54705+4 4 4 4 4 4
54706+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54707+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54708+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54709+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54710+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54711+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54712+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54713+4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
54716+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54717+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54718+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54719+4 4 4 4 4 4
54720+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54721+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54722+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54723+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54724+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54725+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54726+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54727+4 4 4 4 4 4 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+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54730+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54731+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54732+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54733+4 4 4 4 4 4
54734+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54735+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54736+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54737+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54738+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54739+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54740+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54741+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54742+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54743+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54744+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54745+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54746+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54747+4 4 4 4 4 4
54748+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54749+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54750+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54751+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54752+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54753+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54754+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54755+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54756+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54757+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54758+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54759+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54760+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54761+4 4 4 4 4 4
54762+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54763+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54764+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54765+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54766+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
54767+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
54768+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54769+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54770+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54771+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
54772+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54773+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
54774+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54775+4 4 4 4 4 4
54776+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54777+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54778+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54779+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54780+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
54781+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
54782+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54783+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54784+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54785+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
54786+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
54787+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
54788+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54789+4 4 4 4 4 4
54790+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54791+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54792+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54793+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54794+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
54795+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
54796+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54797+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54798+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54799+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
54800+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
54801+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
54802+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
54803+4 4 4 4 4 4
54804+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54805+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54806+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54807+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
54808+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
54809+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
54810+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
54811+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54812+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
54813+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
54814+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
54815+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
54816+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
54817+4 4 4 4 4 4
54818+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54819+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54820+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54821+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
54822+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
54823+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
54824+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
54825+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54826+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
54827+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
54828+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
54829+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
54830+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
54831+4 4 4 4 4 4
54832+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54833+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54834+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
54835+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
54836+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
54837+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
54838+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
54839+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
54840+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
54841+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
54842+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
54843+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
54844+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
54845+4 4 4 4 4 4
54846+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54847+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54848+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
54849+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
54850+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
54851+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
54852+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
54853+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
54854+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
54855+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
54856+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
54857+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
54858+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
54859+4 4 4 4 4 4
54860+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54861+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54862+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
54863+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
54864+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
54865+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
54866+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
54867+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
54868+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
54869+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
54870+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
54871+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
54872+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
54873+4 4 4 4 4 4
54874+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54875+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54876+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
54877+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
54878+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
54879+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
54880+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
54881+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
54882+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
54883+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
54884+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
54885+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
54886+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54887+4 4 4 4 4 4
54888+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54889+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54890+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
54891+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
54892+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
54893+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
54894+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
54895+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
54896+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
54897+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
54898+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
54899+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
54900+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
54901+4 4 4 4 4 4
54902+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54903+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
54904+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
54905+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
54906+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
54907+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
54908+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
54909+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
54910+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
54911+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
54912+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
54913+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
54914+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
54915+4 4 4 4 4 4
54916+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54917+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
54918+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
54919+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
54920+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
54921+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
54922+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
54923+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
54924+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
54925+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
54926+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
54927+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
54928+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
54929+0 0 0 4 4 4
54930+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
54931+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
54932+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
54933+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
54934+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
54935+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
54936+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
54937+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
54938+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
54939+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
54940+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
54941+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
54942+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
54943+2 0 0 0 0 0
54944+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
54945+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
54946+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
54947+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
54948+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
54949+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
54950+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
54951+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
54952+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
54953+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
54954+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
54955+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
54956+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
54957+37 38 37 0 0 0
54958+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
54959+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
54960+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
54961+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
54962+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
54963+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
54964+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
54965+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
54966+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
54967+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
54968+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
54969+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
54970+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
54971+85 115 134 4 0 0
54972+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
54973+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
54974+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
54975+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
54976+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
54977+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
54978+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
54979+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
54980+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
54981+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
54982+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
54983+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
54984+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
54985+60 73 81 4 0 0
54986+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
54987+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
54988+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
54989+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
54990+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
54991+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
54992+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
54993+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
54994+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
54995+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
54996+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
54997+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
54998+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
54999+16 19 21 4 0 0
55000+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
55001+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
55002+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
55003+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
55004+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
55005+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
55006+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
55007+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
55008+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
55009+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
55010+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
55011+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
55012+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
55013+4 0 0 4 3 3
55014+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
55015+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
55016+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
55017+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
55018+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
55019+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
55020+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
55021+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
55022+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
55023+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
55024+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
55025+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
55026+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
55027+3 2 2 4 4 4
55028+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
55029+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
55030+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
55031+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
55032+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
55033+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
55034+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
55035+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
55036+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
55037+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
55038+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
55039+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
55040+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
55041+4 4 4 4 4 4
55042+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
55043+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
55044+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
55045+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
55046+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
55047+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
55048+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
55049+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
55050+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
55051+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
55052+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
55053+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
55054+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
55055+4 4 4 4 4 4
55056+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
55057+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
55058+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
55059+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
55060+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
55061+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
55062+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
55063+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
55064+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
55065+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
55066+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
55067+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
55068+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
55069+5 5 5 5 5 5
55070+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
55071+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
55072+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
55073+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
55074+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
55075+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55076+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
55077+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
55078+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
55079+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
55080+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
55081+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
55082+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
55083+5 5 5 4 4 4
55084+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
55085+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
55086+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
55087+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
55088+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
55089+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
55090+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
55091+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
55092+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
55093+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
55094+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
55095+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
55096+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55097+4 4 4 4 4 4
55098+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
55099+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
55100+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
55101+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
55102+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
55103+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55104+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55105+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
55106+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
55107+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
55108+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
55109+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
55110+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55111+4 4 4 4 4 4
55112+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
55113+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
55114+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
55115+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
55116+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
55117+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
55118+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
55119+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
55120+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
55121+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
55122+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
55123+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55124+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55125+4 4 4 4 4 4
55126+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
55127+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
55128+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
55129+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
55130+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55131+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55132+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55133+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
55134+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
55135+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
55136+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
55137+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55138+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55139+4 4 4 4 4 4
55140+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
55141+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
55142+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
55143+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
55144+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55145+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
55146+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
55147+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
55148+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
55149+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
55150+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55151+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55152+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55153+4 4 4 4 4 4
55154+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
55155+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
55156+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
55157+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
55158+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55159+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
55160+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
55161+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
55162+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
55163+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
55164+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
55165+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55166+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55167+4 4 4 4 4 4
55168+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
55169+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
55170+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
55171+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
55172+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
55173+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
55174+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
55175+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
55176+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
55177+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
55178+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
55179+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55180+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55181+4 4 4 4 4 4
55182+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
55183+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
55184+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
55185+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
55186+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
55187+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
55188+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
55189+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
55190+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
55191+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
55192+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55193+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55194+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55195+4 4 4 4 4 4
55196+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
55197+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
55198+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
55199+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
55200+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55201+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
55202+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
55203+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
55204+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
55205+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
55206+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55207+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55208+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55209+4 4 4 4 4 4
55210+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
55211+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
55212+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
55213+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
55214+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55215+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
55216+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
55217+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
55218+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
55219+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
55220+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55221+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55222+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55223+4 4 4 4 4 4
55224+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
55225+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
55226+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
55227+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
55228+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55229+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
55230+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
55231+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
55232+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
55233+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55234+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55235+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55236+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55237+4 4 4 4 4 4
55238+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
55239+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
55240+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
55241+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
55242+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
55243+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
55244+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
55245+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
55246+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55247+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55248+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55249+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55250+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55251+4 4 4 4 4 4
55252+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
55253+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
55254+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
55255+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
55256+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55257+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
55258+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
55259+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
55260+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
55261+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55262+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55263+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55264+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55265+4 4 4 4 4 4
55266+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
55267+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
55268+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
55269+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
55270+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
55271+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
55272+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
55273+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
55274+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55275+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55276+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55277+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55278+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55279+4 4 4 4 4 4
55280+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
55281+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
55282+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
55283+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
55284+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
55285+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
55286+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
55287+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
55288+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
55289+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55290+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55291+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55292+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55293+4 4 4 4 4 4
55294+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
55295+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
55296+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
55297+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
55298+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
55299+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
55300+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
55301+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
55302+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55303+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55304+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55305+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55306+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55307+4 4 4 4 4 4
55308+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
55309+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
55310+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
55311+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
55312+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
55313+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
55314+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
55315+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
55316+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
55317+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55318+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55319+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55320+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55321+4 4 4 4 4 4
55322+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
55323+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
55324+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
55325+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
55326+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
55327+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
55328+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
55329+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
55330+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55331+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55332+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55333+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55334+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55335+4 4 4 4 4 4
55336+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55337+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
55338+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
55339+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
55340+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
55341+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
55342+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
55343+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
55344+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
55345+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55346+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55347+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55348+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55349+4 4 4 4 4 4
55350+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
55351+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
55352+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
55353+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
55354+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
55355+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
55356+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55357+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
55358+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55359+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55360+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55361+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55362+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55363+4 4 4 4 4 4
55364+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55365+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
55366+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
55367+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
55368+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
55369+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
55370+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55371+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
55372+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
55373+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55374+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55375+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55376+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55377+4 4 4 4 4 4
55378+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
55379+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
55380+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
55381+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
55382+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
55383+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
55384+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
55385+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
55386+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
55387+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55388+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55389+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55390+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55391+4 4 4 4 4 4
55392+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55393+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
55394+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
55395+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
55396+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
55397+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
55398+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
55399+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
55400+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
55401+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55402+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55403+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55404+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55405+4 4 4 4 4 4
55406+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
55407+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
55408+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
55409+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
55410+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
55411+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
55412+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
55413+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
55414+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
55415+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55416+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55417+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55418+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55419+4 4 4 4 4 4
55420+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55421+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
55422+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
55423+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
55424+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
55425+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
55426+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
55427+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
55428+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
55429+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55430+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55431+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55432+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55433+4 4 4 4 4 4
55434+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
55435+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
55436+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
55437+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
55438+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
55439+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
55440+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
55441+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
55442+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
55443+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
55444+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55445+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55446+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55447+4 4 4 4 4 4
55448+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
55449+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
55450+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
55451+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
55452+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
55453+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
55454+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
55455+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
55456+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
55457+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
55458+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55459+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55460+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55461+4 4 4 4 4 4
55462+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
55463+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
55464+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
55465+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
55466+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
55467+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
55468+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55469+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
55470+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
55471+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
55472+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55473+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55474+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55475+4 4 4 4 4 4
55476+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
55477+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
55478+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
55479+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
55480+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
55481+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
55482+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
55483+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
55484+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
55485+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
55486+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55487+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55488+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55489+4 4 4 4 4 4
55490+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
55491+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
55492+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
55493+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
55494+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
55495+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
55496+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
55497+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
55498+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
55499+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
55500+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55501+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55502+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55503+4 4 4 4 4 4
55504+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55505+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
55506+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
55507+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
55508+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
55509+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
55510+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
55511+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
55512+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
55513+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
55514+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55515+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55516+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55517+4 4 4 4 4 4
55518+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
55519+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
55520+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
55521+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
55522+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
55523+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
55524+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
55525+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
55526+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
55527+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
55528+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55529+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55530+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55531+4 4 4 4 4 4
55532+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
55533+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
55534+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
55535+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
55536+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
55537+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
55538+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
55539+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
55540+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
55541+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55542+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55543+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55544+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55545+4 4 4 4 4 4
55546+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
55547+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55548+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
55549+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
55550+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
55551+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
55552+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
55553+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
55554+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
55555+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55556+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55557+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55558+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55559+4 4 4 4 4 4
55560+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
55561+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
55562+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
55563+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
55564+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
55565+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
55566+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
55567+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
55568+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
55569+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55570+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55571+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55572+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55573+4 4 4 4 4 4
55574+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
55575+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
55576+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
55577+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
55578+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
55579+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
55580+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
55581+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
55582+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55583+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55584+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55585+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55586+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55587+4 4 4 4 4 4
55588+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
55589+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
55590+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
55591+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
55592+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
55593+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
55594+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
55595+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
55596+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55597+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55598+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55599+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55600+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55601+4 4 4 4 4 4
55602+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
55603+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
55604+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
55605+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
55606+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
55607+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
55608+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
55609+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
55610+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55611+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55612+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55613+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55614+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55615+4 4 4 4 4 4
55616+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55617+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
55618+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55619+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
55620+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
55621+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
55622+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
55623+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
55624+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55625+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55626+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55627+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55628+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55629+4 4 4 4 4 4
55630+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55631+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
55632+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
55633+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
55634+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
55635+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
55636+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
55637+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
55638+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55639+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55640+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55641+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55642+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55643+4 4 4 4 4 4
55644+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55645+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
55646+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
55647+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
55648+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
55649+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
55650+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
55651+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55652+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55653+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55654+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55655+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55656+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55657+4 4 4 4 4 4
55658+4 4 4 4 4 4 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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
55661+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
55662+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
55663+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
55664+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
55665+4 3 3 5 5 5 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 4 4 4
55667+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55668+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55669+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55670+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55671+4 4 4 4 4 4
55672+4 4 4 4 4 4 4 4 4 4 4 4 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 5 5 5
55675+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55676+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
55677+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
55678+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55682+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55683+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55684+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55685+4 4 4 4 4 4
55686+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
55690+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
55691+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
55692+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55696+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55697+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55698+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55699+4 4 4 4 4 4
55700+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55701+4 4 4 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 5 5 5 4 3 3 5 5 5 6 6 6
55704+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55705+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
55706+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4
55710+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55711+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55712+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55713+4 4 4 4 4 4
55714+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55715+4 4 4 4 4 4 4 4 4 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 5 5 5 4 3 3 5 5 5
55718+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
55719+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
55720+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 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 4 4 4 4 4 4
55724+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55725+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55726+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55727+4 4 4 4 4 4
55728+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55729+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55730+4 4 4 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 5 5 5
55732+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
55733+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55734+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55735+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55736+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55737+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55738+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55739+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55740+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55741+4 4 4 4 4 4
55742+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55743+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55744+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55745+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55746+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
55747+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
55748+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
55749+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55750+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55751+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55752+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55753+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55754+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55755+4 4 4 4 4 4
55756+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55757+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55758+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55759+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55760+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
55761+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
55762+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55763+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55764+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55765+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55766+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55767+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55768+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55769+4 4 4 4 4 4
55770+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55771+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55772+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55773+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55774+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
55775+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
55776+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55777+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55778+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55779+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55780+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55781+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55782+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55783+4 4 4 4 4 4
55784+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55785+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55786+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55787+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55788+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
55789+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
55790+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55791+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55792+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55793+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55794+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55795+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55796+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55797+4 4 4 4 4 4
55798diff --git a/drivers/video/matrox/matroxfb_DAC1064.c b/drivers/video/matrox/matroxfb_DAC1064.c
55799index a01147f..5d896f8 100644
55800--- a/drivers/video/matrox/matroxfb_DAC1064.c
55801+++ b/drivers/video/matrox/matroxfb_DAC1064.c
55802@@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
55803
55804 #ifdef CONFIG_FB_MATROX_MYSTIQUE
55805 struct matrox_switch matrox_mystique = {
55806- MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
55807+ .preinit = MGA1064_preinit,
55808+ .reset = MGA1064_reset,
55809+ .init = MGA1064_init,
55810+ .restore = MGA1064_restore,
55811 };
55812 EXPORT_SYMBOL(matrox_mystique);
55813 #endif
55814
55815 #ifdef CONFIG_FB_MATROX_G
55816 struct matrox_switch matrox_G100 = {
55817- MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
55818+ .preinit = MGAG100_preinit,
55819+ .reset = MGAG100_reset,
55820+ .init = MGAG100_init,
55821+ .restore = MGAG100_restore,
55822 };
55823 EXPORT_SYMBOL(matrox_G100);
55824 #endif
55825diff --git a/drivers/video/matrox/matroxfb_Ti3026.c b/drivers/video/matrox/matroxfb_Ti3026.c
55826index 195ad7c..09743fc 100644
55827--- a/drivers/video/matrox/matroxfb_Ti3026.c
55828+++ b/drivers/video/matrox/matroxfb_Ti3026.c
55829@@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
55830 }
55831
55832 struct matrox_switch matrox_millennium = {
55833- Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
55834+ .preinit = Ti3026_preinit,
55835+ .reset = Ti3026_reset,
55836+ .init = Ti3026_init,
55837+ .restore = Ti3026_restore
55838 };
55839 EXPORT_SYMBOL(matrox_millennium);
55840 #endif
55841diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
55842index fe92eed..106e085 100644
55843--- a/drivers/video/mb862xx/mb862xxfb_accel.c
55844+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
55845@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
55846 struct mb862xxfb_par *par = info->par;
55847
55848 if (info->var.bits_per_pixel == 32) {
55849- info->fbops->fb_fillrect = cfb_fillrect;
55850- info->fbops->fb_copyarea = cfb_copyarea;
55851- info->fbops->fb_imageblit = cfb_imageblit;
55852+ pax_open_kernel();
55853+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55854+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55855+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55856+ pax_close_kernel();
55857 } else {
55858 outreg(disp, GC_L0EM, 3);
55859- info->fbops->fb_fillrect = mb86290fb_fillrect;
55860- info->fbops->fb_copyarea = mb86290fb_copyarea;
55861- info->fbops->fb_imageblit = mb86290fb_imageblit;
55862+ pax_open_kernel();
55863+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
55864+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
55865+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
55866+ pax_close_kernel();
55867 }
55868 outreg(draw, GDC_REG_DRAW_BASE, 0);
55869 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
55870diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
55871index def0412..fed6529 100644
55872--- a/drivers/video/nvidia/nvidia.c
55873+++ b/drivers/video/nvidia/nvidia.c
55874@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
55875 info->fix.line_length = (info->var.xres_virtual *
55876 info->var.bits_per_pixel) >> 3;
55877 if (info->var.accel_flags) {
55878- info->fbops->fb_imageblit = nvidiafb_imageblit;
55879- info->fbops->fb_fillrect = nvidiafb_fillrect;
55880- info->fbops->fb_copyarea = nvidiafb_copyarea;
55881- info->fbops->fb_sync = nvidiafb_sync;
55882+ pax_open_kernel();
55883+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
55884+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
55885+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
55886+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
55887+ pax_close_kernel();
55888 info->pixmap.scan_align = 4;
55889 info->flags &= ~FBINFO_HWACCEL_DISABLED;
55890 info->flags |= FBINFO_READS_FAST;
55891 NVResetGraphics(info);
55892 } else {
55893- info->fbops->fb_imageblit = cfb_imageblit;
55894- info->fbops->fb_fillrect = cfb_fillrect;
55895- info->fbops->fb_copyarea = cfb_copyarea;
55896- info->fbops->fb_sync = NULL;
55897+ pax_open_kernel();
55898+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55899+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55900+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55901+ *(void **)&info->fbops->fb_sync = NULL;
55902+ pax_close_kernel();
55903 info->pixmap.scan_align = 1;
55904 info->flags |= FBINFO_HWACCEL_DISABLED;
55905 info->flags &= ~FBINFO_READS_FAST;
55906@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
55907 info->pixmap.size = 8 * 1024;
55908 info->pixmap.flags = FB_PIXMAP_SYSTEM;
55909
55910- if (!hwcur)
55911- info->fbops->fb_cursor = NULL;
55912+ if (!hwcur) {
55913+ pax_open_kernel();
55914+ *(void **)&info->fbops->fb_cursor = NULL;
55915+ pax_close_kernel();
55916+ }
55917
55918 info->var.accel_flags = (!noaccel);
55919
55920diff --git a/drivers/video/omap2/dss/display.c b/drivers/video/omap2/dss/display.c
55921index 669a81f..e216d76 100644
55922--- a/drivers/video/omap2/dss/display.c
55923+++ b/drivers/video/omap2/dss/display.c
55924@@ -137,12 +137,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
55925 snprintf(dssdev->alias, sizeof(dssdev->alias),
55926 "display%d", disp_num_counter++);
55927
55928+ pax_open_kernel();
55929 if (drv && drv->get_resolution == NULL)
55930- drv->get_resolution = omapdss_default_get_resolution;
55931+ *(void **)&drv->get_resolution = omapdss_default_get_resolution;
55932 if (drv && drv->get_recommended_bpp == NULL)
55933- drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55934+ *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55935 if (drv && drv->get_timings == NULL)
55936- drv->get_timings = omapdss_default_get_timings;
55937+ *(void **)&drv->get_timings = omapdss_default_get_timings;
55938+ pax_close_kernel();
55939
55940 mutex_lock(&panel_list_mutex);
55941 list_add_tail(&dssdev->panel_list, &panel_list);
55942diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
55943index 83433cb..71e9b98 100644
55944--- a/drivers/video/s1d13xxxfb.c
55945+++ b/drivers/video/s1d13xxxfb.c
55946@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
55947
55948 switch(prod_id) {
55949 case S1D13506_PROD_ID: /* activate acceleration */
55950- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55951- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55952+ pax_open_kernel();
55953+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55954+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55955+ pax_close_kernel();
55956 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
55957 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
55958 break;
55959diff --git a/drivers/video/sh_mobile_lcdcfb.c b/drivers/video/sh_mobile_lcdcfb.c
55960index 2bcc84a..29dd1ea 100644
55961--- a/drivers/video/sh_mobile_lcdcfb.c
55962+++ b/drivers/video/sh_mobile_lcdcfb.c
55963@@ -439,9 +439,9 @@ static unsigned long lcdc_sys_read_data(void *handle)
55964 }
55965
55966 static struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
55967- lcdc_sys_write_index,
55968- lcdc_sys_write_data,
55969- lcdc_sys_read_data,
55970+ .write_index = lcdc_sys_write_index,
55971+ .write_data = lcdc_sys_write_data,
55972+ .read_data = lcdc_sys_read_data,
55973 };
55974
55975 static int sh_mobile_lcdc_sginit(struct fb_info *info,
55976diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
55977index d513ed6..90b0de9 100644
55978--- a/drivers/video/smscufx.c
55979+++ b/drivers/video/smscufx.c
55980@@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
55981 fb_deferred_io_cleanup(info);
55982 kfree(info->fbdefio);
55983 info->fbdefio = NULL;
55984- info->fbops->fb_mmap = ufx_ops_mmap;
55985+ pax_open_kernel();
55986+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
55987+ pax_close_kernel();
55988 }
55989
55990 pr_debug("released /dev/fb%d user=%d count=%d",
55991diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
55992index 77b890e..458e666 100644
55993--- a/drivers/video/udlfb.c
55994+++ b/drivers/video/udlfb.c
55995@@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
55996 dlfb_urb_completion(urb);
55997
55998 error:
55999- atomic_add(bytes_sent, &dev->bytes_sent);
56000- atomic_add(bytes_identical, &dev->bytes_identical);
56001- atomic_add(width*height*2, &dev->bytes_rendered);
56002+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
56003+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
56004+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
56005 end_cycles = get_cycles();
56006- atomic_add(((unsigned int) ((end_cycles - start_cycles)
56007+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
56008 >> 10)), /* Kcycles */
56009 &dev->cpu_kcycles_used);
56010
56011@@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
56012 dlfb_urb_completion(urb);
56013
56014 error:
56015- atomic_add(bytes_sent, &dev->bytes_sent);
56016- atomic_add(bytes_identical, &dev->bytes_identical);
56017- atomic_add(bytes_rendered, &dev->bytes_rendered);
56018+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
56019+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
56020+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
56021 end_cycles = get_cycles();
56022- atomic_add(((unsigned int) ((end_cycles - start_cycles)
56023+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
56024 >> 10)), /* Kcycles */
56025 &dev->cpu_kcycles_used);
56026 }
56027@@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
56028 fb_deferred_io_cleanup(info);
56029 kfree(info->fbdefio);
56030 info->fbdefio = NULL;
56031- info->fbops->fb_mmap = dlfb_ops_mmap;
56032+ pax_open_kernel();
56033+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
56034+ pax_close_kernel();
56035 }
56036
56037 pr_warn("released /dev/fb%d user=%d count=%d\n",
56038@@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
56039 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56040 struct dlfb_data *dev = fb_info->par;
56041 return snprintf(buf, PAGE_SIZE, "%u\n",
56042- atomic_read(&dev->bytes_rendered));
56043+ atomic_read_unchecked(&dev->bytes_rendered));
56044 }
56045
56046 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
56047@@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
56048 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56049 struct dlfb_data *dev = fb_info->par;
56050 return snprintf(buf, PAGE_SIZE, "%u\n",
56051- atomic_read(&dev->bytes_identical));
56052+ atomic_read_unchecked(&dev->bytes_identical));
56053 }
56054
56055 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
56056@@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
56057 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56058 struct dlfb_data *dev = fb_info->par;
56059 return snprintf(buf, PAGE_SIZE, "%u\n",
56060- atomic_read(&dev->bytes_sent));
56061+ atomic_read_unchecked(&dev->bytes_sent));
56062 }
56063
56064 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
56065@@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
56066 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56067 struct dlfb_data *dev = fb_info->par;
56068 return snprintf(buf, PAGE_SIZE, "%u\n",
56069- atomic_read(&dev->cpu_kcycles_used));
56070+ atomic_read_unchecked(&dev->cpu_kcycles_used));
56071 }
56072
56073 static ssize_t edid_show(
56074@@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
56075 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56076 struct dlfb_data *dev = fb_info->par;
56077
56078- atomic_set(&dev->bytes_rendered, 0);
56079- atomic_set(&dev->bytes_identical, 0);
56080- atomic_set(&dev->bytes_sent, 0);
56081- atomic_set(&dev->cpu_kcycles_used, 0);
56082+ atomic_set_unchecked(&dev->bytes_rendered, 0);
56083+ atomic_set_unchecked(&dev->bytes_identical, 0);
56084+ atomic_set_unchecked(&dev->bytes_sent, 0);
56085+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
56086
56087 return count;
56088 }
56089diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
56090index 256fba7..6e75516 100644
56091--- a/drivers/video/uvesafb.c
56092+++ b/drivers/video/uvesafb.c
56093@@ -19,6 +19,7 @@
56094 #include <linux/io.h>
56095 #include <linux/mutex.h>
56096 #include <linux/slab.h>
56097+#include <linux/moduleloader.h>
56098 #include <video/edid.h>
56099 #include <video/uvesafb.h>
56100 #ifdef CONFIG_X86
56101@@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
56102 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
56103 par->pmi_setpal = par->ypan = 0;
56104 } else {
56105+
56106+#ifdef CONFIG_PAX_KERNEXEC
56107+#ifdef CONFIG_MODULES
56108+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
56109+#endif
56110+ if (!par->pmi_code) {
56111+ par->pmi_setpal = par->ypan = 0;
56112+ return 0;
56113+ }
56114+#endif
56115+
56116 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
56117 + task->t.regs.edi);
56118+
56119+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56120+ pax_open_kernel();
56121+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
56122+ pax_close_kernel();
56123+
56124+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
56125+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
56126+#else
56127 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
56128 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
56129+#endif
56130+
56131 printk(KERN_INFO "uvesafb: protected mode interface info at "
56132 "%04x:%04x\n",
56133 (u16)task->t.regs.es, (u16)task->t.regs.edi);
56134@@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
56135 par->ypan = ypan;
56136
56137 if (par->pmi_setpal || par->ypan) {
56138+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
56139 if (__supported_pte_mask & _PAGE_NX) {
56140 par->pmi_setpal = par->ypan = 0;
56141 printk(KERN_WARNING "uvesafb: NX protection is active, "
56142 "better not use the PMI.\n");
56143- } else {
56144+ } else
56145+#endif
56146 uvesafb_vbe_getpmi(task, par);
56147- }
56148 }
56149 #else
56150 /* The protected mode interface is not available on non-x86. */
56151@@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
56152 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
56153
56154 /* Disable blanking if the user requested so. */
56155- if (!blank)
56156- info->fbops->fb_blank = NULL;
56157+ if (!blank) {
56158+ pax_open_kernel();
56159+ *(void **)&info->fbops->fb_blank = NULL;
56160+ pax_close_kernel();
56161+ }
56162
56163 /*
56164 * Find out how much IO memory is required for the mode with
56165@@ -1530,8 +1557,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
56166 info->flags = FBINFO_FLAG_DEFAULT |
56167 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
56168
56169- if (!par->ypan)
56170- info->fbops->fb_pan_display = NULL;
56171+ if (!par->ypan) {
56172+ pax_open_kernel();
56173+ *(void **)&info->fbops->fb_pan_display = NULL;
56174+ pax_close_kernel();
56175+ }
56176 }
56177
56178 static void uvesafb_init_mtrr(struct fb_info *info)
56179@@ -1792,6 +1822,11 @@ out_mode:
56180 out:
56181 kfree(par->vbe_modes);
56182
56183+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56184+ if (par->pmi_code)
56185+ module_free_exec(NULL, par->pmi_code);
56186+#endif
56187+
56188 framebuffer_release(info);
56189 return err;
56190 }
56191@@ -1816,6 +1851,12 @@ static int uvesafb_remove(struct platform_device *dev)
56192 kfree(par->vbe_modes);
56193 kfree(par->vbe_state_orig);
56194 kfree(par->vbe_state_saved);
56195+
56196+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56197+ if (par->pmi_code)
56198+ module_free_exec(NULL, par->pmi_code);
56199+#endif
56200+
56201 }
56202
56203 framebuffer_release(info);
56204diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
56205index 1c7da3b..56ea0bd 100644
56206--- a/drivers/video/vesafb.c
56207+++ b/drivers/video/vesafb.c
56208@@ -9,6 +9,7 @@
56209 */
56210
56211 #include <linux/module.h>
56212+#include <linux/moduleloader.h>
56213 #include <linux/kernel.h>
56214 #include <linux/errno.h>
56215 #include <linux/string.h>
56216@@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
56217 static int vram_total; /* Set total amount of memory */
56218 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
56219 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
56220-static void (*pmi_start)(void) __read_mostly;
56221-static void (*pmi_pal) (void) __read_mostly;
56222+static void (*pmi_start)(void) __read_only;
56223+static void (*pmi_pal) (void) __read_only;
56224 static int depth __read_mostly;
56225 static int vga_compat __read_mostly;
56226 /* --------------------------------------------------------------------- */
56227@@ -234,6 +235,7 @@ static int vesafb_probe(struct platform_device *dev)
56228 unsigned int size_remap;
56229 unsigned int size_total;
56230 char *option = NULL;
56231+ void *pmi_code = NULL;
56232
56233 /* ignore error return of fb_get_options */
56234 fb_get_options("vesafb", &option);
56235@@ -280,10 +282,6 @@ static int vesafb_probe(struct platform_device *dev)
56236 size_remap = size_total;
56237 vesafb_fix.smem_len = size_remap;
56238
56239-#ifndef __i386__
56240- screen_info.vesapm_seg = 0;
56241-#endif
56242-
56243 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
56244 printk(KERN_WARNING
56245 "vesafb: cannot reserve video memory at 0x%lx\n",
56246@@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
56247 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
56248 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
56249
56250+#ifdef __i386__
56251+
56252+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56253+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
56254+ if (!pmi_code)
56255+#elif !defined(CONFIG_PAX_KERNEXEC)
56256+ if (0)
56257+#endif
56258+
56259+#endif
56260+ screen_info.vesapm_seg = 0;
56261+
56262 if (screen_info.vesapm_seg) {
56263- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
56264- screen_info.vesapm_seg,screen_info.vesapm_off);
56265+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
56266+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
56267 }
56268
56269 if (screen_info.vesapm_seg < 0xc000)
56270@@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
56271
56272 if (ypan || pmi_setpal) {
56273 unsigned short *pmi_base;
56274+
56275 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
56276- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
56277- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
56278+
56279+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56280+ pax_open_kernel();
56281+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
56282+#else
56283+ pmi_code = pmi_base;
56284+#endif
56285+
56286+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
56287+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
56288+
56289+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56290+ pmi_start = ktva_ktla(pmi_start);
56291+ pmi_pal = ktva_ktla(pmi_pal);
56292+ pax_close_kernel();
56293+#endif
56294+
56295 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
56296 if (pmi_base[3]) {
56297 printk(KERN_INFO "vesafb: pmi: ports = ");
56298@@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
56299 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
56300 (ypan ? FBINFO_HWACCEL_YPAN : 0);
56301
56302- if (!ypan)
56303- info->fbops->fb_pan_display = NULL;
56304+ if (!ypan) {
56305+ pax_open_kernel();
56306+ *(void **)&info->fbops->fb_pan_display = NULL;
56307+ pax_close_kernel();
56308+ }
56309
56310 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
56311 err = -ENOMEM;
56312@@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
56313 fb_info(info, "%s frame buffer device\n", info->fix.id);
56314 return 0;
56315 err:
56316+
56317+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56318+ module_free_exec(NULL, pmi_code);
56319+#endif
56320+
56321 if (info->screen_base)
56322 iounmap(info->screen_base);
56323 framebuffer_release(info);
56324diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
56325index 88714ae..16c2e11 100644
56326--- a/drivers/video/via/via_clock.h
56327+++ b/drivers/video/via/via_clock.h
56328@@ -56,7 +56,7 @@ struct via_clock {
56329
56330 void (*set_engine_pll_state)(u8 state);
56331 void (*set_engine_pll)(struct via_pll_config config);
56332-};
56333+} __no_const;
56334
56335
56336 static inline u32 get_pll_internal_frequency(u32 ref_freq,
56337diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
56338index fef20db..d28b1ab 100644
56339--- a/drivers/xen/xenfs/xenstored.c
56340+++ b/drivers/xen/xenfs/xenstored.c
56341@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
56342 static int xsd_kva_open(struct inode *inode, struct file *file)
56343 {
56344 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
56345+#ifdef CONFIG_GRKERNSEC_HIDESYM
56346+ NULL);
56347+#else
56348 xen_store_interface);
56349+#endif
56350+
56351 if (!file->private_data)
56352 return -ENOMEM;
56353 return 0;
56354diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
56355index c71e886..61d3d44b 100644
56356--- a/fs/9p/vfs_addr.c
56357+++ b/fs/9p/vfs_addr.c
56358@@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
56359
56360 retval = v9fs_file_write_internal(inode,
56361 v9inode->writeback_fid,
56362- (__force const char __user *)buffer,
56363+ (const char __force_user *)buffer,
56364 len, &offset, 0);
56365 if (retval > 0)
56366 retval = 0;
56367diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
56368index bb7991c..481e21a 100644
56369--- a/fs/9p/vfs_inode.c
56370+++ b/fs/9p/vfs_inode.c
56371@@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
56372 void
56373 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
56374 {
56375- char *s = nd_get_link(nd);
56376+ const char *s = nd_get_link(nd);
56377
56378 p9_debug(P9_DEBUG_VFS, " %s %s\n",
56379 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
56380diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
56381index 370b24c..ff0be7b 100644
56382--- a/fs/Kconfig.binfmt
56383+++ b/fs/Kconfig.binfmt
56384@@ -103,7 +103,7 @@ config HAVE_AOUT
56385
56386 config BINFMT_AOUT
56387 tristate "Kernel support for a.out and ECOFF binaries"
56388- depends on HAVE_AOUT
56389+ depends on HAVE_AOUT && BROKEN
56390 ---help---
56391 A.out (Assembler.OUTput) is a set of formats for libraries and
56392 executables used in the earliest versions of UNIX. Linux used
56393diff --git a/fs/affs/super.c b/fs/affs/super.c
56394index d098731..9a5b19d 100644
56395--- a/fs/affs/super.c
56396+++ b/fs/affs/super.c
56397@@ -336,8 +336,6 @@ static int affs_fill_super(struct super_block *sb, void *data, int silent)
56398 &blocksize,&sbi->s_prefix,
56399 sbi->s_volume, &mount_flags)) {
56400 printk(KERN_ERR "AFFS: Error parsing options\n");
56401- kfree(sbi->s_prefix);
56402- kfree(sbi);
56403 return -EINVAL;
56404 }
56405 /* N.B. after this point s_prefix must be released */
56406diff --git a/fs/afs/inode.c b/fs/afs/inode.c
56407index ce25d75..dc09eeb 100644
56408--- a/fs/afs/inode.c
56409+++ b/fs/afs/inode.c
56410@@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
56411 struct afs_vnode *vnode;
56412 struct super_block *sb;
56413 struct inode *inode;
56414- static atomic_t afs_autocell_ino;
56415+ static atomic_unchecked_t afs_autocell_ino;
56416
56417 _enter("{%x:%u},%*.*s,",
56418 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
56419@@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
56420 data.fid.unique = 0;
56421 data.fid.vnode = 0;
56422
56423- inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
56424+ inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
56425 afs_iget5_autocell_test, afs_iget5_set,
56426 &data);
56427 if (!inode) {
56428diff --git a/fs/aio.c b/fs/aio.c
56429index 062a5f6..6ecefa2 100644
56430--- a/fs/aio.c
56431+++ b/fs/aio.c
56432@@ -374,7 +374,7 @@ static int aio_setup_ring(struct kioctx *ctx)
56433 size += sizeof(struct io_event) * nr_events;
56434
56435 nr_pages = PFN_UP(size);
56436- if (nr_pages < 0)
56437+ if (nr_pages <= 0)
56438 return -EINVAL;
56439
56440 file = aio_private_file(ctx, nr_pages);
56441@@ -1285,10 +1285,8 @@ rw_common:
56442 &iovec, compat)
56443 : aio_setup_single_vector(req, rw, buf, &nr_segs,
56444 iovec);
56445- if (ret)
56446- return ret;
56447-
56448- ret = rw_verify_area(rw, file, &req->ki_pos, req->ki_nbytes);
56449+ if (!ret)
56450+ ret = rw_verify_area(rw, file, &req->ki_pos, req->ki_nbytes);
56451 if (ret < 0) {
56452 if (iovec != &inline_vec)
56453 kfree(iovec);
56454diff --git a/fs/attr.c b/fs/attr.c
56455index 5d4e59d..fd02418 100644
56456--- a/fs/attr.c
56457+++ b/fs/attr.c
56458@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
56459 unsigned long limit;
56460
56461 limit = rlimit(RLIMIT_FSIZE);
56462+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
56463 if (limit != RLIM_INFINITY && offset > limit)
56464 goto out_sig;
56465 if (offset > inode->i_sb->s_maxbytes)
56466diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
56467index 116fd38..c04182da 100644
56468--- a/fs/autofs4/waitq.c
56469+++ b/fs/autofs4/waitq.c
56470@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
56471 {
56472 unsigned long sigpipe, flags;
56473 mm_segment_t fs;
56474- const char *data = (const char *)addr;
56475+ const char __user *data = (const char __force_user *)addr;
56476 ssize_t wr = 0;
56477
56478 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
56479@@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
56480 return 1;
56481 }
56482
56483+#ifdef CONFIG_GRKERNSEC_HIDESYM
56484+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
56485+#endif
56486+
56487 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
56488 enum autofs_notify notify)
56489 {
56490@@ -385,7 +389,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
56491
56492 /* If this is a direct mount request create a dummy name */
56493 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
56494+#ifdef CONFIG_GRKERNSEC_HIDESYM
56495+ /* this name does get written to userland via autofs4_write() */
56496+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
56497+#else
56498 qstr.len = sprintf(name, "%p", dentry);
56499+#endif
56500 else {
56501 qstr.len = autofs4_getpath(sbi, dentry, &name);
56502 if (!qstr.len) {
56503diff --git a/fs/befs/endian.h b/fs/befs/endian.h
56504index 2722387..56059b5 100644
56505--- a/fs/befs/endian.h
56506+++ b/fs/befs/endian.h
56507@@ -11,7 +11,7 @@
56508
56509 #include <asm/byteorder.h>
56510
56511-static inline u64
56512+static inline u64 __intentional_overflow(-1)
56513 fs64_to_cpu(const struct super_block *sb, fs64 n)
56514 {
56515 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56516@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
56517 return (__force fs64)cpu_to_be64(n);
56518 }
56519
56520-static inline u32
56521+static inline u32 __intentional_overflow(-1)
56522 fs32_to_cpu(const struct super_block *sb, fs32 n)
56523 {
56524 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56525@@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
56526 return (__force fs32)cpu_to_be32(n);
56527 }
56528
56529-static inline u16
56530+static inline u16 __intentional_overflow(-1)
56531 fs16_to_cpu(const struct super_block *sb, fs16 n)
56532 {
56533 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56534diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
56535index ca0ba15..0fa3257 100644
56536--- a/fs/binfmt_aout.c
56537+++ b/fs/binfmt_aout.c
56538@@ -16,6 +16,7 @@
56539 #include <linux/string.h>
56540 #include <linux/fs.h>
56541 #include <linux/file.h>
56542+#include <linux/security.h>
56543 #include <linux/stat.h>
56544 #include <linux/fcntl.h>
56545 #include <linux/ptrace.h>
56546@@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
56547 #endif
56548 # define START_STACK(u) ((void __user *)u.start_stack)
56549
56550+ memset(&dump, 0, sizeof(dump));
56551+
56552 fs = get_fs();
56553 set_fs(KERNEL_DS);
56554 has_dumped = 1;
56555@@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
56556
56557 /* If the size of the dump file exceeds the rlimit, then see what would happen
56558 if we wrote the stack, but not the data area. */
56559+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
56560 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
56561 dump.u_dsize = 0;
56562
56563 /* Make sure we have enough room to write the stack and data areas. */
56564+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
56565 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
56566 dump.u_ssize = 0;
56567
56568@@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
56569 rlim = rlimit(RLIMIT_DATA);
56570 if (rlim >= RLIM_INFINITY)
56571 rlim = ~0;
56572+
56573+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
56574 if (ex.a_data + ex.a_bss > rlim)
56575 return -ENOMEM;
56576
56577@@ -264,6 +271,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
56578
56579 install_exec_creds(bprm);
56580
56581+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56582+ current->mm->pax_flags = 0UL;
56583+#endif
56584+
56585+#ifdef CONFIG_PAX_PAGEEXEC
56586+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
56587+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
56588+
56589+#ifdef CONFIG_PAX_EMUTRAMP
56590+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
56591+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
56592+#endif
56593+
56594+#ifdef CONFIG_PAX_MPROTECT
56595+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
56596+ current->mm->pax_flags |= MF_PAX_MPROTECT;
56597+#endif
56598+
56599+ }
56600+#endif
56601+
56602 if (N_MAGIC(ex) == OMAGIC) {
56603 unsigned long text_addr, map_size;
56604 loff_t pos;
56605@@ -321,7 +349,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
56606 }
56607
56608 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
56609- PROT_READ | PROT_WRITE | PROT_EXEC,
56610+ PROT_READ | PROT_WRITE,
56611 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
56612 fd_offset + ex.a_text);
56613 if (error != N_DATADDR(ex)) {
56614diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
56615index 67be295..83e2f86 100644
56616--- a/fs/binfmt_elf.c
56617+++ b/fs/binfmt_elf.c
56618@@ -34,6 +34,7 @@
56619 #include <linux/utsname.h>
56620 #include <linux/coredump.h>
56621 #include <linux/sched.h>
56622+#include <linux/xattr.h>
56623 #include <asm/uaccess.h>
56624 #include <asm/param.h>
56625 #include <asm/page.h>
56626@@ -48,7 +49,7 @@
56627 static int load_elf_binary(struct linux_binprm *bprm);
56628 static int load_elf_library(struct file *);
56629 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
56630- int, int, unsigned long);
56631+ int, int, unsigned long) __intentional_overflow(-1);
56632
56633 /*
56634 * If we don't support core dumping, then supply a NULL so we
56635@@ -60,6 +61,14 @@ static int elf_core_dump(struct coredump_params *cprm);
56636 #define elf_core_dump NULL
56637 #endif
56638
56639+#ifdef CONFIG_PAX_MPROTECT
56640+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
56641+#endif
56642+
56643+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56644+static void elf_handle_mmap(struct file *file);
56645+#endif
56646+
56647 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
56648 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
56649 #else
56650@@ -79,6 +88,15 @@ static struct linux_binfmt elf_format = {
56651 .load_binary = load_elf_binary,
56652 .load_shlib = load_elf_library,
56653 .core_dump = elf_core_dump,
56654+
56655+#ifdef CONFIG_PAX_MPROTECT
56656+ .handle_mprotect= elf_handle_mprotect,
56657+#endif
56658+
56659+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56660+ .handle_mmap = elf_handle_mmap,
56661+#endif
56662+
56663 .min_coredump = ELF_EXEC_PAGESIZE,
56664 };
56665
56666@@ -86,6 +104,8 @@ static struct linux_binfmt elf_format = {
56667
56668 static int set_brk(unsigned long start, unsigned long end)
56669 {
56670+ unsigned long e = end;
56671+
56672 start = ELF_PAGEALIGN(start);
56673 end = ELF_PAGEALIGN(end);
56674 if (end > start) {
56675@@ -94,7 +114,7 @@ static int set_brk(unsigned long start, unsigned long end)
56676 if (BAD_ADDR(addr))
56677 return addr;
56678 }
56679- current->mm->start_brk = current->mm->brk = end;
56680+ current->mm->start_brk = current->mm->brk = e;
56681 return 0;
56682 }
56683
56684@@ -155,12 +175,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56685 elf_addr_t __user *u_rand_bytes;
56686 const char *k_platform = ELF_PLATFORM;
56687 const char *k_base_platform = ELF_BASE_PLATFORM;
56688- unsigned char k_rand_bytes[16];
56689+ u32 k_rand_bytes[4];
56690 int items;
56691 elf_addr_t *elf_info;
56692 int ei_index = 0;
56693 const struct cred *cred = current_cred();
56694 struct vm_area_struct *vma;
56695+ unsigned long saved_auxv[AT_VECTOR_SIZE];
56696
56697 /*
56698 * In some cases (e.g. Hyper-Threading), we want to avoid L1
56699@@ -202,8 +223,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56700 * Generate 16 random bytes for userspace PRNG seeding.
56701 */
56702 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
56703- u_rand_bytes = (elf_addr_t __user *)
56704- STACK_ALLOC(p, sizeof(k_rand_bytes));
56705+ prandom_seed(k_rand_bytes[0] ^ prandom_u32());
56706+ prandom_seed(k_rand_bytes[1] ^ prandom_u32());
56707+ prandom_seed(k_rand_bytes[2] ^ prandom_u32());
56708+ prandom_seed(k_rand_bytes[3] ^ prandom_u32());
56709+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
56710+ u_rand_bytes = (elf_addr_t __user *) p;
56711 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
56712 return -EFAULT;
56713
56714@@ -318,9 +343,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56715 return -EFAULT;
56716 current->mm->env_end = p;
56717
56718+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
56719+
56720 /* Put the elf_info on the stack in the right place. */
56721 sp = (elf_addr_t __user *)envp + 1;
56722- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
56723+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
56724 return -EFAULT;
56725 return 0;
56726 }
56727@@ -388,15 +415,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
56728 an ELF header */
56729
56730 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56731- struct file *interpreter, unsigned long *interp_map_addr,
56732- unsigned long no_base)
56733+ struct file *interpreter, unsigned long no_base)
56734 {
56735 struct elf_phdr *elf_phdata;
56736 struct elf_phdr *eppnt;
56737- unsigned long load_addr = 0;
56738+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
56739 int load_addr_set = 0;
56740 unsigned long last_bss = 0, elf_bss = 0;
56741- unsigned long error = ~0UL;
56742+ unsigned long error = -EINVAL;
56743 unsigned long total_size;
56744 int retval, i, size;
56745
56746@@ -442,6 +468,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56747 goto out_close;
56748 }
56749
56750+#ifdef CONFIG_PAX_SEGMEXEC
56751+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
56752+ pax_task_size = SEGMEXEC_TASK_SIZE;
56753+#endif
56754+
56755 eppnt = elf_phdata;
56756 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
56757 if (eppnt->p_type == PT_LOAD) {
56758@@ -465,8 +496,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56759 map_addr = elf_map(interpreter, load_addr + vaddr,
56760 eppnt, elf_prot, elf_type, total_size);
56761 total_size = 0;
56762- if (!*interp_map_addr)
56763- *interp_map_addr = map_addr;
56764 error = map_addr;
56765 if (BAD_ADDR(map_addr))
56766 goto out_close;
56767@@ -485,8 +514,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56768 k = load_addr + eppnt->p_vaddr;
56769 if (BAD_ADDR(k) ||
56770 eppnt->p_filesz > eppnt->p_memsz ||
56771- eppnt->p_memsz > TASK_SIZE ||
56772- TASK_SIZE - eppnt->p_memsz < k) {
56773+ eppnt->p_memsz > pax_task_size ||
56774+ pax_task_size - eppnt->p_memsz < k) {
56775 error = -ENOMEM;
56776 goto out_close;
56777 }
56778@@ -525,9 +554,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56779 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
56780
56781 /* Map the last of the bss segment */
56782- error = vm_brk(elf_bss, last_bss - elf_bss);
56783- if (BAD_ADDR(error))
56784- goto out_close;
56785+ if (last_bss > elf_bss) {
56786+ error = vm_brk(elf_bss, last_bss - elf_bss);
56787+ if (BAD_ADDR(error))
56788+ goto out_close;
56789+ }
56790 }
56791
56792 error = load_addr;
56793@@ -538,6 +569,336 @@ out:
56794 return error;
56795 }
56796
56797+#ifdef CONFIG_PAX_PT_PAX_FLAGS
56798+#ifdef CONFIG_PAX_SOFTMODE
56799+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
56800+{
56801+ unsigned long pax_flags = 0UL;
56802+
56803+#ifdef CONFIG_PAX_PAGEEXEC
56804+ if (elf_phdata->p_flags & PF_PAGEEXEC)
56805+ pax_flags |= MF_PAX_PAGEEXEC;
56806+#endif
56807+
56808+#ifdef CONFIG_PAX_SEGMEXEC
56809+ if (elf_phdata->p_flags & PF_SEGMEXEC)
56810+ pax_flags |= MF_PAX_SEGMEXEC;
56811+#endif
56812+
56813+#ifdef CONFIG_PAX_EMUTRAMP
56814+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56815+ pax_flags |= MF_PAX_EMUTRAMP;
56816+#endif
56817+
56818+#ifdef CONFIG_PAX_MPROTECT
56819+ if (elf_phdata->p_flags & PF_MPROTECT)
56820+ pax_flags |= MF_PAX_MPROTECT;
56821+#endif
56822+
56823+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56824+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
56825+ pax_flags |= MF_PAX_RANDMMAP;
56826+#endif
56827+
56828+ return pax_flags;
56829+}
56830+#endif
56831+
56832+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
56833+{
56834+ unsigned long pax_flags = 0UL;
56835+
56836+#ifdef CONFIG_PAX_PAGEEXEC
56837+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
56838+ pax_flags |= MF_PAX_PAGEEXEC;
56839+#endif
56840+
56841+#ifdef CONFIG_PAX_SEGMEXEC
56842+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
56843+ pax_flags |= MF_PAX_SEGMEXEC;
56844+#endif
56845+
56846+#ifdef CONFIG_PAX_EMUTRAMP
56847+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
56848+ pax_flags |= MF_PAX_EMUTRAMP;
56849+#endif
56850+
56851+#ifdef CONFIG_PAX_MPROTECT
56852+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
56853+ pax_flags |= MF_PAX_MPROTECT;
56854+#endif
56855+
56856+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56857+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
56858+ pax_flags |= MF_PAX_RANDMMAP;
56859+#endif
56860+
56861+ return pax_flags;
56862+}
56863+#endif
56864+
56865+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56866+#ifdef CONFIG_PAX_SOFTMODE
56867+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
56868+{
56869+ unsigned long pax_flags = 0UL;
56870+
56871+#ifdef CONFIG_PAX_PAGEEXEC
56872+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
56873+ pax_flags |= MF_PAX_PAGEEXEC;
56874+#endif
56875+
56876+#ifdef CONFIG_PAX_SEGMEXEC
56877+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
56878+ pax_flags |= MF_PAX_SEGMEXEC;
56879+#endif
56880+
56881+#ifdef CONFIG_PAX_EMUTRAMP
56882+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56883+ pax_flags |= MF_PAX_EMUTRAMP;
56884+#endif
56885+
56886+#ifdef CONFIG_PAX_MPROTECT
56887+ if (pax_flags_softmode & MF_PAX_MPROTECT)
56888+ pax_flags |= MF_PAX_MPROTECT;
56889+#endif
56890+
56891+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56892+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
56893+ pax_flags |= MF_PAX_RANDMMAP;
56894+#endif
56895+
56896+ return pax_flags;
56897+}
56898+#endif
56899+
56900+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
56901+{
56902+ unsigned long pax_flags = 0UL;
56903+
56904+#ifdef CONFIG_PAX_PAGEEXEC
56905+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
56906+ pax_flags |= MF_PAX_PAGEEXEC;
56907+#endif
56908+
56909+#ifdef CONFIG_PAX_SEGMEXEC
56910+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
56911+ pax_flags |= MF_PAX_SEGMEXEC;
56912+#endif
56913+
56914+#ifdef CONFIG_PAX_EMUTRAMP
56915+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
56916+ pax_flags |= MF_PAX_EMUTRAMP;
56917+#endif
56918+
56919+#ifdef CONFIG_PAX_MPROTECT
56920+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
56921+ pax_flags |= MF_PAX_MPROTECT;
56922+#endif
56923+
56924+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56925+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
56926+ pax_flags |= MF_PAX_RANDMMAP;
56927+#endif
56928+
56929+ return pax_flags;
56930+}
56931+#endif
56932+
56933+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56934+static unsigned long pax_parse_defaults(void)
56935+{
56936+ unsigned long pax_flags = 0UL;
56937+
56938+#ifdef CONFIG_PAX_SOFTMODE
56939+ if (pax_softmode)
56940+ return pax_flags;
56941+#endif
56942+
56943+#ifdef CONFIG_PAX_PAGEEXEC
56944+ pax_flags |= MF_PAX_PAGEEXEC;
56945+#endif
56946+
56947+#ifdef CONFIG_PAX_SEGMEXEC
56948+ pax_flags |= MF_PAX_SEGMEXEC;
56949+#endif
56950+
56951+#ifdef CONFIG_PAX_MPROTECT
56952+ pax_flags |= MF_PAX_MPROTECT;
56953+#endif
56954+
56955+#ifdef CONFIG_PAX_RANDMMAP
56956+ if (randomize_va_space)
56957+ pax_flags |= MF_PAX_RANDMMAP;
56958+#endif
56959+
56960+ return pax_flags;
56961+}
56962+
56963+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
56964+{
56965+ unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
56966+
56967+#ifdef CONFIG_PAX_EI_PAX
56968+
56969+#ifdef CONFIG_PAX_SOFTMODE
56970+ if (pax_softmode)
56971+ return pax_flags;
56972+#endif
56973+
56974+ pax_flags = 0UL;
56975+
56976+#ifdef CONFIG_PAX_PAGEEXEC
56977+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
56978+ pax_flags |= MF_PAX_PAGEEXEC;
56979+#endif
56980+
56981+#ifdef CONFIG_PAX_SEGMEXEC
56982+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
56983+ pax_flags |= MF_PAX_SEGMEXEC;
56984+#endif
56985+
56986+#ifdef CONFIG_PAX_EMUTRAMP
56987+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
56988+ pax_flags |= MF_PAX_EMUTRAMP;
56989+#endif
56990+
56991+#ifdef CONFIG_PAX_MPROTECT
56992+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
56993+ pax_flags |= MF_PAX_MPROTECT;
56994+#endif
56995+
56996+#ifdef CONFIG_PAX_ASLR
56997+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
56998+ pax_flags |= MF_PAX_RANDMMAP;
56999+#endif
57000+
57001+#endif
57002+
57003+ return pax_flags;
57004+
57005+}
57006+
57007+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
57008+{
57009+
57010+#ifdef CONFIG_PAX_PT_PAX_FLAGS
57011+ unsigned long i;
57012+
57013+ for (i = 0UL; i < elf_ex->e_phnum; i++)
57014+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
57015+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
57016+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
57017+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
57018+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
57019+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
57020+ return PAX_PARSE_FLAGS_FALLBACK;
57021+
57022+#ifdef CONFIG_PAX_SOFTMODE
57023+ if (pax_softmode)
57024+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
57025+ else
57026+#endif
57027+
57028+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
57029+ break;
57030+ }
57031+#endif
57032+
57033+ return PAX_PARSE_FLAGS_FALLBACK;
57034+}
57035+
57036+static unsigned long pax_parse_xattr_pax(struct file * const file)
57037+{
57038+
57039+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
57040+ ssize_t xattr_size, i;
57041+ unsigned char xattr_value[sizeof("pemrs") - 1];
57042+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
57043+
57044+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
57045+ if (xattr_size < 0 || xattr_size > sizeof xattr_value)
57046+ return PAX_PARSE_FLAGS_FALLBACK;
57047+
57048+ for (i = 0; i < xattr_size; i++)
57049+ switch (xattr_value[i]) {
57050+ default:
57051+ return PAX_PARSE_FLAGS_FALLBACK;
57052+
57053+#define parse_flag(option1, option2, flag) \
57054+ case option1: \
57055+ if (pax_flags_hardmode & MF_PAX_##flag) \
57056+ return PAX_PARSE_FLAGS_FALLBACK;\
57057+ pax_flags_hardmode |= MF_PAX_##flag; \
57058+ break; \
57059+ case option2: \
57060+ if (pax_flags_softmode & MF_PAX_##flag) \
57061+ return PAX_PARSE_FLAGS_FALLBACK;\
57062+ pax_flags_softmode |= MF_PAX_##flag; \
57063+ break;
57064+
57065+ parse_flag('p', 'P', PAGEEXEC);
57066+ parse_flag('e', 'E', EMUTRAMP);
57067+ parse_flag('m', 'M', MPROTECT);
57068+ parse_flag('r', 'R', RANDMMAP);
57069+ parse_flag('s', 'S', SEGMEXEC);
57070+
57071+#undef parse_flag
57072+ }
57073+
57074+ if (pax_flags_hardmode & pax_flags_softmode)
57075+ return PAX_PARSE_FLAGS_FALLBACK;
57076+
57077+#ifdef CONFIG_PAX_SOFTMODE
57078+ if (pax_softmode)
57079+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
57080+ else
57081+#endif
57082+
57083+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
57084+#else
57085+ return PAX_PARSE_FLAGS_FALLBACK;
57086+#endif
57087+
57088+}
57089+
57090+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
57091+{
57092+ unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
57093+
57094+ pax_flags = pax_parse_defaults();
57095+ ei_pax_flags = pax_parse_ei_pax(elf_ex);
57096+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
57097+ xattr_pax_flags = pax_parse_xattr_pax(file);
57098+
57099+ if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
57100+ xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
57101+ pt_pax_flags != xattr_pax_flags)
57102+ return -EINVAL;
57103+ if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
57104+ pax_flags = xattr_pax_flags;
57105+ else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
57106+ pax_flags = pt_pax_flags;
57107+ else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
57108+ pax_flags = ei_pax_flags;
57109+
57110+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
57111+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
57112+ if ((__supported_pte_mask & _PAGE_NX))
57113+ pax_flags &= ~MF_PAX_SEGMEXEC;
57114+ else
57115+ pax_flags &= ~MF_PAX_PAGEEXEC;
57116+ }
57117+#endif
57118+
57119+ if (0 > pax_check_flags(&pax_flags))
57120+ return -EINVAL;
57121+
57122+ current->mm->pax_flags = pax_flags;
57123+ return 0;
57124+}
57125+#endif
57126+
57127 /*
57128 * These are the functions used to load ELF style executables and shared
57129 * libraries. There is no binary dependent code anywhere else.
57130@@ -551,6 +912,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
57131 {
57132 unsigned int random_variable = 0;
57133
57134+#ifdef CONFIG_PAX_RANDUSTACK
57135+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
57136+ return stack_top - current->mm->delta_stack;
57137+#endif
57138+
57139 if ((current->flags & PF_RANDOMIZE) &&
57140 !(current->personality & ADDR_NO_RANDOMIZE)) {
57141 random_variable = get_random_int() & STACK_RND_MASK;
57142@@ -569,7 +935,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
57143 unsigned long load_addr = 0, load_bias = 0;
57144 int load_addr_set = 0;
57145 char * elf_interpreter = NULL;
57146- unsigned long error;
57147+ unsigned long error = 0;
57148 struct elf_phdr *elf_ppnt, *elf_phdata;
57149 unsigned long elf_bss, elf_brk;
57150 int retval, i;
57151@@ -579,12 +945,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
57152 unsigned long start_code, end_code, start_data, end_data;
57153 unsigned long reloc_func_desc __maybe_unused = 0;
57154 int executable_stack = EXSTACK_DEFAULT;
57155- unsigned long def_flags = 0;
57156 struct pt_regs *regs = current_pt_regs();
57157 struct {
57158 struct elfhdr elf_ex;
57159 struct elfhdr interp_elf_ex;
57160 } *loc;
57161+ unsigned long pax_task_size;
57162
57163 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
57164 if (!loc) {
57165@@ -720,11 +1086,82 @@ static int load_elf_binary(struct linux_binprm *bprm)
57166 goto out_free_dentry;
57167
57168 /* OK, This is the point of no return */
57169- current->mm->def_flags = def_flags;
57170+ current->mm->def_flags = 0;
57171
57172 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
57173 may depend on the personality. */
57174 SET_PERSONALITY(loc->elf_ex);
57175+
57176+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
57177+ current->mm->pax_flags = 0UL;
57178+#endif
57179+
57180+#ifdef CONFIG_PAX_DLRESOLVE
57181+ current->mm->call_dl_resolve = 0UL;
57182+#endif
57183+
57184+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
57185+ current->mm->call_syscall = 0UL;
57186+#endif
57187+
57188+#ifdef CONFIG_PAX_ASLR
57189+ current->mm->delta_mmap = 0UL;
57190+ current->mm->delta_stack = 0UL;
57191+#endif
57192+
57193+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
57194+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
57195+ send_sig(SIGKILL, current, 0);
57196+ goto out_free_dentry;
57197+ }
57198+#endif
57199+
57200+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57201+ pax_set_initial_flags(bprm);
57202+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
57203+ if (pax_set_initial_flags_func)
57204+ (pax_set_initial_flags_func)(bprm);
57205+#endif
57206+
57207+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
57208+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
57209+ current->mm->context.user_cs_limit = PAGE_SIZE;
57210+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
57211+ }
57212+#endif
57213+
57214+#ifdef CONFIG_PAX_SEGMEXEC
57215+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
57216+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
57217+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
57218+ pax_task_size = SEGMEXEC_TASK_SIZE;
57219+ current->mm->def_flags |= VM_NOHUGEPAGE;
57220+ } else
57221+#endif
57222+
57223+ pax_task_size = TASK_SIZE;
57224+
57225+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
57226+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
57227+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
57228+ put_cpu();
57229+ }
57230+#endif
57231+
57232+#ifdef CONFIG_PAX_ASLR
57233+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
57234+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
57235+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
57236+ }
57237+#endif
57238+
57239+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
57240+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
57241+ executable_stack = EXSTACK_DISABLE_X;
57242+ current->personality &= ~READ_IMPLIES_EXEC;
57243+ } else
57244+#endif
57245+
57246 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
57247 current->personality |= READ_IMPLIES_EXEC;
57248
57249@@ -814,6 +1251,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
57250 #else
57251 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
57252 #endif
57253+
57254+#ifdef CONFIG_PAX_RANDMMAP
57255+ /* PaX: randomize base address at the default exe base if requested */
57256+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
57257+#ifdef CONFIG_SPARC64
57258+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
57259+#else
57260+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
57261+#endif
57262+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
57263+ elf_flags |= MAP_FIXED;
57264+ }
57265+#endif
57266+
57267 }
57268
57269 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
57270@@ -846,9 +1297,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
57271 * allowed task size. Note that p_filesz must always be
57272 * <= p_memsz so it is only necessary to check p_memsz.
57273 */
57274- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
57275- elf_ppnt->p_memsz > TASK_SIZE ||
57276- TASK_SIZE - elf_ppnt->p_memsz < k) {
57277+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
57278+ elf_ppnt->p_memsz > pax_task_size ||
57279+ pax_task_size - elf_ppnt->p_memsz < k) {
57280 /* set_brk can never work. Avoid overflows. */
57281 send_sig(SIGKILL, current, 0);
57282 retval = -EINVAL;
57283@@ -887,17 +1338,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
57284 goto out_free_dentry;
57285 }
57286 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
57287- send_sig(SIGSEGV, current, 0);
57288- retval = -EFAULT; /* Nobody gets to see this, but.. */
57289- goto out_free_dentry;
57290+ /*
57291+ * This bss-zeroing can fail if the ELF
57292+ * file specifies odd protections. So
57293+ * we don't check the return value
57294+ */
57295 }
57296
57297+#ifdef CONFIG_PAX_RANDMMAP
57298+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
57299+ unsigned long start, size, flags;
57300+ vm_flags_t vm_flags;
57301+
57302+ start = ELF_PAGEALIGN(elf_brk);
57303+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
57304+ flags = MAP_FIXED | MAP_PRIVATE;
57305+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
57306+
57307+ down_write(&current->mm->mmap_sem);
57308+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
57309+ retval = -ENOMEM;
57310+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
57311+// if (current->personality & ADDR_NO_RANDOMIZE)
57312+// vm_flags |= VM_READ | VM_MAYREAD;
57313+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
57314+ retval = IS_ERR_VALUE(start) ? start : 0;
57315+ }
57316+ up_write(&current->mm->mmap_sem);
57317+ if (retval == 0)
57318+ retval = set_brk(start + size, start + size + PAGE_SIZE);
57319+ if (retval < 0) {
57320+ send_sig(SIGKILL, current, 0);
57321+ goto out_free_dentry;
57322+ }
57323+ }
57324+#endif
57325+
57326 if (elf_interpreter) {
57327- unsigned long interp_map_addr = 0;
57328-
57329 elf_entry = load_elf_interp(&loc->interp_elf_ex,
57330 interpreter,
57331- &interp_map_addr,
57332 load_bias);
57333 if (!IS_ERR((void *)elf_entry)) {
57334 /*
57335@@ -1119,7 +1598,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
57336 * Decide what to dump of a segment, part, all or none.
57337 */
57338 static unsigned long vma_dump_size(struct vm_area_struct *vma,
57339- unsigned long mm_flags)
57340+ unsigned long mm_flags, long signr)
57341 {
57342 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
57343
57344@@ -1157,7 +1636,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
57345 if (vma->vm_file == NULL)
57346 return 0;
57347
57348- if (FILTER(MAPPED_PRIVATE))
57349+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
57350 goto whole;
57351
57352 /*
57353@@ -1364,9 +1843,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
57354 {
57355 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
57356 int i = 0;
57357- do
57358+ do {
57359 i += 2;
57360- while (auxv[i - 2] != AT_NULL);
57361+ } while (auxv[i - 2] != AT_NULL);
57362 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
57363 }
57364
57365@@ -1375,7 +1854,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
57366 {
57367 mm_segment_t old_fs = get_fs();
57368 set_fs(KERNEL_DS);
57369- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
57370+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
57371 set_fs(old_fs);
57372 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
57373 }
57374@@ -1999,14 +2478,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
57375 }
57376
57377 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
57378- unsigned long mm_flags)
57379+ struct coredump_params *cprm)
57380 {
57381 struct vm_area_struct *vma;
57382 size_t size = 0;
57383
57384 for (vma = first_vma(current, gate_vma); vma != NULL;
57385 vma = next_vma(vma, gate_vma))
57386- size += vma_dump_size(vma, mm_flags);
57387+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
57388 return size;
57389 }
57390
57391@@ -2097,7 +2576,7 @@ static int elf_core_dump(struct coredump_params *cprm)
57392
57393 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
57394
57395- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
57396+ offset += elf_core_vma_data_size(gate_vma, cprm);
57397 offset += elf_core_extra_data_size();
57398 e_shoff = offset;
57399
57400@@ -2125,7 +2604,7 @@ static int elf_core_dump(struct coredump_params *cprm)
57401 phdr.p_offset = offset;
57402 phdr.p_vaddr = vma->vm_start;
57403 phdr.p_paddr = 0;
57404- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
57405+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
57406 phdr.p_memsz = vma->vm_end - vma->vm_start;
57407 offset += phdr.p_filesz;
57408 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
57409@@ -2158,7 +2637,7 @@ static int elf_core_dump(struct coredump_params *cprm)
57410 unsigned long addr;
57411 unsigned long end;
57412
57413- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
57414+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
57415
57416 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
57417 struct page *page;
57418@@ -2199,6 +2678,167 @@ out:
57419
57420 #endif /* CONFIG_ELF_CORE */
57421
57422+#ifdef CONFIG_PAX_MPROTECT
57423+/* PaX: non-PIC ELF libraries need relocations on their executable segments
57424+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
57425+ * we'll remove VM_MAYWRITE for good on RELRO segments.
57426+ *
57427+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
57428+ * basis because we want to allow the common case and not the special ones.
57429+ */
57430+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
57431+{
57432+ struct elfhdr elf_h;
57433+ struct elf_phdr elf_p;
57434+ unsigned long i;
57435+ unsigned long oldflags;
57436+ bool is_textrel_rw, is_textrel_rx, is_relro;
57437+
57438+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
57439+ return;
57440+
57441+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
57442+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
57443+
57444+#ifdef CONFIG_PAX_ELFRELOCS
57445+ /* possible TEXTREL */
57446+ is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
57447+ is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
57448+#else
57449+ is_textrel_rw = false;
57450+ is_textrel_rx = false;
57451+#endif
57452+
57453+ /* possible RELRO */
57454+ is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
57455+
57456+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
57457+ return;
57458+
57459+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
57460+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
57461+
57462+#ifdef CONFIG_PAX_ETEXECRELOCS
57463+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
57464+#else
57465+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
57466+#endif
57467+
57468+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
57469+ !elf_check_arch(&elf_h) ||
57470+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
57471+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
57472+ return;
57473+
57474+ for (i = 0UL; i < elf_h.e_phnum; i++) {
57475+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
57476+ return;
57477+ switch (elf_p.p_type) {
57478+ case PT_DYNAMIC:
57479+ if (!is_textrel_rw && !is_textrel_rx)
57480+ continue;
57481+ i = 0UL;
57482+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
57483+ elf_dyn dyn;
57484+
57485+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
57486+ break;
57487+ if (dyn.d_tag == DT_NULL)
57488+ break;
57489+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
57490+ gr_log_textrel(vma);
57491+ if (is_textrel_rw)
57492+ vma->vm_flags |= VM_MAYWRITE;
57493+ else
57494+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
57495+ vma->vm_flags &= ~VM_MAYWRITE;
57496+ break;
57497+ }
57498+ i++;
57499+ }
57500+ is_textrel_rw = false;
57501+ is_textrel_rx = false;
57502+ continue;
57503+
57504+ case PT_GNU_RELRO:
57505+ if (!is_relro)
57506+ continue;
57507+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
57508+ vma->vm_flags &= ~VM_MAYWRITE;
57509+ is_relro = false;
57510+ continue;
57511+
57512+#ifdef CONFIG_PAX_PT_PAX_FLAGS
57513+ case PT_PAX_FLAGS: {
57514+ const char *msg_mprotect = "", *msg_emutramp = "";
57515+ char *buffer_lib, *buffer_exe;
57516+
57517+ if (elf_p.p_flags & PF_NOMPROTECT)
57518+ msg_mprotect = "MPROTECT disabled";
57519+
57520+#ifdef CONFIG_PAX_EMUTRAMP
57521+ if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
57522+ msg_emutramp = "EMUTRAMP enabled";
57523+#endif
57524+
57525+ if (!msg_mprotect[0] && !msg_emutramp[0])
57526+ continue;
57527+
57528+ if (!printk_ratelimit())
57529+ continue;
57530+
57531+ buffer_lib = (char *)__get_free_page(GFP_KERNEL);
57532+ buffer_exe = (char *)__get_free_page(GFP_KERNEL);
57533+ if (buffer_lib && buffer_exe) {
57534+ char *path_lib, *path_exe;
57535+
57536+ path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
57537+ path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
57538+
57539+ pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
57540+ (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
57541+
57542+ }
57543+ free_page((unsigned long)buffer_exe);
57544+ free_page((unsigned long)buffer_lib);
57545+ continue;
57546+ }
57547+#endif
57548+
57549+ }
57550+ }
57551+}
57552+#endif
57553+
57554+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57555+
57556+extern int grsec_enable_log_rwxmaps;
57557+
57558+static void elf_handle_mmap(struct file *file)
57559+{
57560+ struct elfhdr elf_h;
57561+ struct elf_phdr elf_p;
57562+ unsigned long i;
57563+
57564+ if (!grsec_enable_log_rwxmaps)
57565+ return;
57566+
57567+ if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
57568+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
57569+ (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
57570+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
57571+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
57572+ return;
57573+
57574+ for (i = 0UL; i < elf_h.e_phnum; i++) {
57575+ if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
57576+ return;
57577+ if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
57578+ gr_log_ptgnustack(file);
57579+ }
57580+}
57581+#endif
57582+
57583 static int __init init_elf_binfmt(void)
57584 {
57585 register_binfmt(&elf_format);
57586diff --git a/fs/bio.c b/fs/bio.c
57587index 8754e7b..0669094 100644
57588--- a/fs/bio.c
57589+++ b/fs/bio.c
57590@@ -1145,7 +1145,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
57591 /*
57592 * Overflow, abort
57593 */
57594- if (end < start)
57595+ if (end < start || end - start > INT_MAX - nr_pages)
57596 return ERR_PTR(-EINVAL);
57597
57598 nr_pages += end - start;
57599@@ -1279,7 +1279,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
57600 /*
57601 * Overflow, abort
57602 */
57603- if (end < start)
57604+ if (end < start || end - start > INT_MAX - nr_pages)
57605 return ERR_PTR(-EINVAL);
57606
57607 nr_pages += end - start;
57608@@ -1541,7 +1541,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
57609 const int read = bio_data_dir(bio) == READ;
57610 struct bio_map_data *bmd = bio->bi_private;
57611 int i;
57612- char *p = bmd->sgvecs[0].iov_base;
57613+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
57614
57615 bio_for_each_segment_all(bvec, bio, i) {
57616 char *addr = page_address(bvec->bv_page);
57617diff --git a/fs/block_dev.c b/fs/block_dev.c
57618index 1e86823..8e34695 100644
57619--- a/fs/block_dev.c
57620+++ b/fs/block_dev.c
57621@@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
57622 else if (bdev->bd_contains == bdev)
57623 return true; /* is a whole device which isn't held */
57624
57625- else if (whole->bd_holder == bd_may_claim)
57626+ else if (whole->bd_holder == (void *)bd_may_claim)
57627 return true; /* is a partition of a device that is being partitioned */
57628 else if (whole->bd_holder != NULL)
57629 return false; /* is a partition of a held device */
57630diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
57631index cbd3a7d..c6a2881 100644
57632--- a/fs/btrfs/ctree.c
57633+++ b/fs/btrfs/ctree.c
57634@@ -1216,9 +1216,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
57635 free_extent_buffer(buf);
57636 add_root_to_dirty_list(root);
57637 } else {
57638- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
57639- parent_start = parent->start;
57640- else
57641+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
57642+ if (parent)
57643+ parent_start = parent->start;
57644+ else
57645+ parent_start = 0;
57646+ } else
57647 parent_start = 0;
57648
57649 WARN_ON(trans->transid != btrfs_header_generation(parent));
57650diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
57651index 451b00c..a2cccee 100644
57652--- a/fs/btrfs/delayed-inode.c
57653+++ b/fs/btrfs/delayed-inode.c
57654@@ -459,7 +459,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
57655
57656 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
57657 {
57658- int seq = atomic_inc_return(&delayed_root->items_seq);
57659+ int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
57660 if ((atomic_dec_return(&delayed_root->items) <
57661 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
57662 waitqueue_active(&delayed_root->wait))
57663@@ -1409,7 +1409,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
57664
57665 static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
57666 {
57667- int val = atomic_read(&delayed_root->items_seq);
57668+ int val = atomic_read_unchecked(&delayed_root->items_seq);
57669
57670 if (val < seq || val >= seq + BTRFS_DELAYED_BATCH)
57671 return 1;
57672@@ -1433,7 +1433,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
57673 int seq;
57674 int ret;
57675
57676- seq = atomic_read(&delayed_root->items_seq);
57677+ seq = atomic_read_unchecked(&delayed_root->items_seq);
57678
57679 ret = btrfs_wq_run_delayed_node(delayed_root, root, 0);
57680 if (ret)
57681diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
57682index f70119f..ab5894d 100644
57683--- a/fs/btrfs/delayed-inode.h
57684+++ b/fs/btrfs/delayed-inode.h
57685@@ -43,7 +43,7 @@ struct btrfs_delayed_root {
57686 */
57687 struct list_head prepare_list;
57688 atomic_t items; /* for delayed items */
57689- atomic_t items_seq; /* for delayed items */
57690+ atomic_unchecked_t items_seq; /* for delayed items */
57691 int nodes; /* for delayed nodes */
57692 wait_queue_head_t wait;
57693 };
57694@@ -90,7 +90,7 @@ static inline void btrfs_init_delayed_root(
57695 struct btrfs_delayed_root *delayed_root)
57696 {
57697 atomic_set(&delayed_root->items, 0);
57698- atomic_set(&delayed_root->items_seq, 0);
57699+ atomic_set_unchecked(&delayed_root->items_seq, 0);
57700 delayed_root->nodes = 0;
57701 spin_lock_init(&delayed_root->lock);
57702 init_waitqueue_head(&delayed_root->wait);
57703diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
57704index a6d8efa..2f062cf 100644
57705--- a/fs/btrfs/ioctl.c
57706+++ b/fs/btrfs/ioctl.c
57707@@ -3491,9 +3491,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57708 for (i = 0; i < num_types; i++) {
57709 struct btrfs_space_info *tmp;
57710
57711+ /* Don't copy in more than we allocated */
57712 if (!slot_count)
57713 break;
57714
57715+ slot_count--;
57716+
57717 info = NULL;
57718 rcu_read_lock();
57719 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
57720@@ -3515,10 +3518,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57721 memcpy(dest, &space, sizeof(space));
57722 dest++;
57723 space_args.total_spaces++;
57724- slot_count--;
57725 }
57726- if (!slot_count)
57727- break;
57728 }
57729 up_read(&info->groups_sem);
57730 }
57731diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
57732index d04db81..96e54f1 100644
57733--- a/fs/btrfs/super.c
57734+++ b/fs/btrfs/super.c
57735@@ -268,7 +268,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
57736 function, line, errstr);
57737 return;
57738 }
57739- ACCESS_ONCE(trans->transaction->aborted) = errno;
57740+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
57741 /* Wake up anybody who may be waiting on this transaction */
57742 wake_up(&root->fs_info->transaction_wait);
57743 wake_up(&root->fs_info->transaction_blocked_wait);
57744diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
57745index 865f4cf..f321e86 100644
57746--- a/fs/btrfs/sysfs.c
57747+++ b/fs/btrfs/sysfs.c
57748@@ -436,7 +436,7 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
57749 for (set = 0; set < FEAT_MAX; set++) {
57750 int i;
57751 struct attribute *attrs[2];
57752- struct attribute_group agroup = {
57753+ attribute_group_no_const agroup = {
57754 .name = "features",
57755 .attrs = attrs,
57756 };
57757diff --git a/fs/buffer.c b/fs/buffer.c
57758index 27265a8..289f488 100644
57759--- a/fs/buffer.c
57760+++ b/fs/buffer.c
57761@@ -3428,7 +3428,7 @@ void __init buffer_init(void)
57762 bh_cachep = kmem_cache_create("buffer_head",
57763 sizeof(struct buffer_head), 0,
57764 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
57765- SLAB_MEM_SPREAD),
57766+ SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
57767 NULL);
57768
57769 /*
57770diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
57771index 622f469..e8d2d55 100644
57772--- a/fs/cachefiles/bind.c
57773+++ b/fs/cachefiles/bind.c
57774@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
57775 args);
57776
57777 /* start by checking things over */
57778- ASSERT(cache->fstop_percent >= 0 &&
57779- cache->fstop_percent < cache->fcull_percent &&
57780+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
57781 cache->fcull_percent < cache->frun_percent &&
57782 cache->frun_percent < 100);
57783
57784- ASSERT(cache->bstop_percent >= 0 &&
57785- cache->bstop_percent < cache->bcull_percent &&
57786+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
57787 cache->bcull_percent < cache->brun_percent &&
57788 cache->brun_percent < 100);
57789
57790diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
57791index 0a1467b..6a53245 100644
57792--- a/fs/cachefiles/daemon.c
57793+++ b/fs/cachefiles/daemon.c
57794@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
57795 if (n > buflen)
57796 return -EMSGSIZE;
57797
57798- if (copy_to_user(_buffer, buffer, n) != 0)
57799+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
57800 return -EFAULT;
57801
57802 return n;
57803@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
57804 if (test_bit(CACHEFILES_DEAD, &cache->flags))
57805 return -EIO;
57806
57807- if (datalen < 0 || datalen > PAGE_SIZE - 1)
57808+ if (datalen > PAGE_SIZE - 1)
57809 return -EOPNOTSUPP;
57810
57811 /* drag the command string into the kernel so we can parse it */
57812@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
57813 if (args[0] != '%' || args[1] != '\0')
57814 return -EINVAL;
57815
57816- if (fstop < 0 || fstop >= cache->fcull_percent)
57817+ if (fstop >= cache->fcull_percent)
57818 return cachefiles_daemon_range_error(cache, args);
57819
57820 cache->fstop_percent = fstop;
57821@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
57822 if (args[0] != '%' || args[1] != '\0')
57823 return -EINVAL;
57824
57825- if (bstop < 0 || bstop >= cache->bcull_percent)
57826+ if (bstop >= cache->bcull_percent)
57827 return cachefiles_daemon_range_error(cache, args);
57828
57829 cache->bstop_percent = bstop;
57830diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
57831index 5349473..d6c0b93 100644
57832--- a/fs/cachefiles/internal.h
57833+++ b/fs/cachefiles/internal.h
57834@@ -59,7 +59,7 @@ struct cachefiles_cache {
57835 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
57836 struct rb_root active_nodes; /* active nodes (can't be culled) */
57837 rwlock_t active_lock; /* lock for active_nodes */
57838- atomic_t gravecounter; /* graveyard uniquifier */
57839+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
57840 unsigned frun_percent; /* when to stop culling (% files) */
57841 unsigned fcull_percent; /* when to start culling (% files) */
57842 unsigned fstop_percent; /* when to stop allocating (% files) */
57843@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
57844 * proc.c
57845 */
57846 #ifdef CONFIG_CACHEFILES_HISTOGRAM
57847-extern atomic_t cachefiles_lookup_histogram[HZ];
57848-extern atomic_t cachefiles_mkdir_histogram[HZ];
57849-extern atomic_t cachefiles_create_histogram[HZ];
57850+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57851+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57852+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
57853
57854 extern int __init cachefiles_proc_init(void);
57855 extern void cachefiles_proc_cleanup(void);
57856 static inline
57857-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
57858+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
57859 {
57860 unsigned long jif = jiffies - start_jif;
57861 if (jif >= HZ)
57862 jif = HZ - 1;
57863- atomic_inc(&histogram[jif]);
57864+ atomic_inc_unchecked(&histogram[jif]);
57865 }
57866
57867 #else
57868diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
57869index ca65f39..48921e3 100644
57870--- a/fs/cachefiles/namei.c
57871+++ b/fs/cachefiles/namei.c
57872@@ -317,7 +317,7 @@ try_again:
57873 /* first step is to make up a grave dentry in the graveyard */
57874 sprintf(nbuffer, "%08x%08x",
57875 (uint32_t) get_seconds(),
57876- (uint32_t) atomic_inc_return(&cache->gravecounter));
57877+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
57878
57879 /* do the multiway lock magic */
57880 trap = lock_rename(cache->graveyard, dir);
57881diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
57882index eccd339..4c1d995 100644
57883--- a/fs/cachefiles/proc.c
57884+++ b/fs/cachefiles/proc.c
57885@@ -14,9 +14,9 @@
57886 #include <linux/seq_file.h>
57887 #include "internal.h"
57888
57889-atomic_t cachefiles_lookup_histogram[HZ];
57890-atomic_t cachefiles_mkdir_histogram[HZ];
57891-atomic_t cachefiles_create_histogram[HZ];
57892+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57893+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57894+atomic_unchecked_t cachefiles_create_histogram[HZ];
57895
57896 /*
57897 * display the latency histogram
57898@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
57899 return 0;
57900 default:
57901 index = (unsigned long) v - 3;
57902- x = atomic_read(&cachefiles_lookup_histogram[index]);
57903- y = atomic_read(&cachefiles_mkdir_histogram[index]);
57904- z = atomic_read(&cachefiles_create_histogram[index]);
57905+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
57906+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
57907+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
57908 if (x == 0 && y == 0 && z == 0)
57909 return 0;
57910
57911diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
57912index ebaff36..7e3ea26 100644
57913--- a/fs/cachefiles/rdwr.c
57914+++ b/fs/cachefiles/rdwr.c
57915@@ -950,7 +950,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
57916 old_fs = get_fs();
57917 set_fs(KERNEL_DS);
57918 ret = file->f_op->write(
57919- file, (const void __user *) data, len, &pos);
57920+ file, (const void __force_user *) data, len, &pos);
57921 set_fs(old_fs);
57922 kunmap(page);
57923 file_end_write(file);
57924diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
57925index 45eda6d..9126f7f 100644
57926--- a/fs/ceph/dir.c
57927+++ b/fs/ceph/dir.c
57928@@ -248,7 +248,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
57929 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
57930 struct ceph_mds_client *mdsc = fsc->mdsc;
57931 unsigned frag = fpos_frag(ctx->pos);
57932- int off = fpos_off(ctx->pos);
57933+ unsigned int off = fpos_off(ctx->pos);
57934 int err;
57935 u32 ftype;
57936 struct ceph_mds_reply_info_parsed *rinfo;
57937diff --git a/fs/ceph/super.c b/fs/ceph/super.c
57938index 10a4ccb..92dbc5e 100644
57939--- a/fs/ceph/super.c
57940+++ b/fs/ceph/super.c
57941@@ -895,7 +895,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
57942 /*
57943 * construct our own bdi so we can control readahead, etc.
57944 */
57945-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
57946+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
57947
57948 static int ceph_register_bdi(struct super_block *sb,
57949 struct ceph_fs_client *fsc)
57950@@ -912,7 +912,7 @@ static int ceph_register_bdi(struct super_block *sb,
57951 default_backing_dev_info.ra_pages;
57952
57953 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
57954- atomic_long_inc_return(&bdi_seq));
57955+ atomic_long_inc_return_unchecked(&bdi_seq));
57956 if (!err)
57957 sb->s_bdi = &fsc->backing_dev_info;
57958 return err;
57959diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
57960index f3ac415..3d2420c 100644
57961--- a/fs/cifs/cifs_debug.c
57962+++ b/fs/cifs/cifs_debug.c
57963@@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57964
57965 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
57966 #ifdef CONFIG_CIFS_STATS2
57967- atomic_set(&totBufAllocCount, 0);
57968- atomic_set(&totSmBufAllocCount, 0);
57969+ atomic_set_unchecked(&totBufAllocCount, 0);
57970+ atomic_set_unchecked(&totSmBufAllocCount, 0);
57971 #endif /* CONFIG_CIFS_STATS2 */
57972 spin_lock(&cifs_tcp_ses_lock);
57973 list_for_each(tmp1, &cifs_tcp_ses_list) {
57974@@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57975 tcon = list_entry(tmp3,
57976 struct cifs_tcon,
57977 tcon_list);
57978- atomic_set(&tcon->num_smbs_sent, 0);
57979+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
57980 if (server->ops->clear_stats)
57981 server->ops->clear_stats(tcon);
57982 }
57983@@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57984 smBufAllocCount.counter, cifs_min_small);
57985 #ifdef CONFIG_CIFS_STATS2
57986 seq_printf(m, "Total Large %d Small %d Allocations\n",
57987- atomic_read(&totBufAllocCount),
57988- atomic_read(&totSmBufAllocCount));
57989+ atomic_read_unchecked(&totBufAllocCount),
57990+ atomic_read_unchecked(&totSmBufAllocCount));
57991 #endif /* CONFIG_CIFS_STATS2 */
57992
57993 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
57994@@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57995 if (tcon->need_reconnect)
57996 seq_puts(m, "\tDISCONNECTED ");
57997 seq_printf(m, "\nSMBs: %d",
57998- atomic_read(&tcon->num_smbs_sent));
57999+ atomic_read_unchecked(&tcon->num_smbs_sent));
58000 if (server->ops->print_stats)
58001 server->ops->print_stats(m, tcon);
58002 }
58003diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
58004index 849f613..eae6dec 100644
58005--- a/fs/cifs/cifsfs.c
58006+++ b/fs/cifs/cifsfs.c
58007@@ -1056,7 +1056,7 @@ cifs_init_request_bufs(void)
58008 */
58009 cifs_req_cachep = kmem_cache_create("cifs_request",
58010 CIFSMaxBufSize + max_hdr_size, 0,
58011- SLAB_HWCACHE_ALIGN, NULL);
58012+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
58013 if (cifs_req_cachep == NULL)
58014 return -ENOMEM;
58015
58016@@ -1083,7 +1083,7 @@ cifs_init_request_bufs(void)
58017 efficient to alloc 1 per page off the slab compared to 17K (5page)
58018 alloc of large cifs buffers even when page debugging is on */
58019 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
58020- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
58021+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
58022 NULL);
58023 if (cifs_sm_req_cachep == NULL) {
58024 mempool_destroy(cifs_req_poolp);
58025@@ -1168,8 +1168,8 @@ init_cifs(void)
58026 atomic_set(&bufAllocCount, 0);
58027 atomic_set(&smBufAllocCount, 0);
58028 #ifdef CONFIG_CIFS_STATS2
58029- atomic_set(&totBufAllocCount, 0);
58030- atomic_set(&totSmBufAllocCount, 0);
58031+ atomic_set_unchecked(&totBufAllocCount, 0);
58032+ atomic_set_unchecked(&totSmBufAllocCount, 0);
58033 #endif /* CONFIG_CIFS_STATS2 */
58034
58035 atomic_set(&midCount, 0);
58036diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
58037index c0f3718..6afed7d 100644
58038--- a/fs/cifs/cifsglob.h
58039+++ b/fs/cifs/cifsglob.h
58040@@ -804,35 +804,35 @@ struct cifs_tcon {
58041 __u16 Flags; /* optional support bits */
58042 enum statusEnum tidStatus;
58043 #ifdef CONFIG_CIFS_STATS
58044- atomic_t num_smbs_sent;
58045+ atomic_unchecked_t num_smbs_sent;
58046 union {
58047 struct {
58048- atomic_t num_writes;
58049- atomic_t num_reads;
58050- atomic_t num_flushes;
58051- atomic_t num_oplock_brks;
58052- atomic_t num_opens;
58053- atomic_t num_closes;
58054- atomic_t num_deletes;
58055- atomic_t num_mkdirs;
58056- atomic_t num_posixopens;
58057- atomic_t num_posixmkdirs;
58058- atomic_t num_rmdirs;
58059- atomic_t num_renames;
58060- atomic_t num_t2renames;
58061- atomic_t num_ffirst;
58062- atomic_t num_fnext;
58063- atomic_t num_fclose;
58064- atomic_t num_hardlinks;
58065- atomic_t num_symlinks;
58066- atomic_t num_locks;
58067- atomic_t num_acl_get;
58068- atomic_t num_acl_set;
58069+ atomic_unchecked_t num_writes;
58070+ atomic_unchecked_t num_reads;
58071+ atomic_unchecked_t num_flushes;
58072+ atomic_unchecked_t num_oplock_brks;
58073+ atomic_unchecked_t num_opens;
58074+ atomic_unchecked_t num_closes;
58075+ atomic_unchecked_t num_deletes;
58076+ atomic_unchecked_t num_mkdirs;
58077+ atomic_unchecked_t num_posixopens;
58078+ atomic_unchecked_t num_posixmkdirs;
58079+ atomic_unchecked_t num_rmdirs;
58080+ atomic_unchecked_t num_renames;
58081+ atomic_unchecked_t num_t2renames;
58082+ atomic_unchecked_t num_ffirst;
58083+ atomic_unchecked_t num_fnext;
58084+ atomic_unchecked_t num_fclose;
58085+ atomic_unchecked_t num_hardlinks;
58086+ atomic_unchecked_t num_symlinks;
58087+ atomic_unchecked_t num_locks;
58088+ atomic_unchecked_t num_acl_get;
58089+ atomic_unchecked_t num_acl_set;
58090 } cifs_stats;
58091 #ifdef CONFIG_CIFS_SMB2
58092 struct {
58093- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
58094- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
58095+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
58096+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
58097 } smb2_stats;
58098 #endif /* CONFIG_CIFS_SMB2 */
58099 } stats;
58100@@ -1162,7 +1162,7 @@ convert_delimiter(char *path, char delim)
58101 }
58102
58103 #ifdef CONFIG_CIFS_STATS
58104-#define cifs_stats_inc atomic_inc
58105+#define cifs_stats_inc atomic_inc_unchecked
58106
58107 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
58108 unsigned int bytes)
58109@@ -1528,8 +1528,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
58110 /* Various Debug counters */
58111 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
58112 #ifdef CONFIG_CIFS_STATS2
58113-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
58114-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
58115+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
58116+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
58117 #endif
58118 GLOBAL_EXTERN atomic_t smBufAllocCount;
58119 GLOBAL_EXTERN atomic_t midCount;
58120diff --git a/fs/cifs/file.c b/fs/cifs/file.c
58121index 834fce7..8a314b5 100644
58122--- a/fs/cifs/file.c
58123+++ b/fs/cifs/file.c
58124@@ -1900,10 +1900,14 @@ static int cifs_writepages(struct address_space *mapping,
58125 index = mapping->writeback_index; /* Start from prev offset */
58126 end = -1;
58127 } else {
58128- index = wbc->range_start >> PAGE_CACHE_SHIFT;
58129- end = wbc->range_end >> PAGE_CACHE_SHIFT;
58130- if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
58131+ if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
58132 range_whole = true;
58133+ index = 0;
58134+ end = ULONG_MAX;
58135+ } else {
58136+ index = wbc->range_start >> PAGE_CACHE_SHIFT;
58137+ end = wbc->range_end >> PAGE_CACHE_SHIFT;
58138+ }
58139 scanned = true;
58140 }
58141 retry:
58142diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
58143index 2f9f379..43f8025 100644
58144--- a/fs/cifs/misc.c
58145+++ b/fs/cifs/misc.c
58146@@ -170,7 +170,7 @@ cifs_buf_get(void)
58147 memset(ret_buf, 0, buf_size + 3);
58148 atomic_inc(&bufAllocCount);
58149 #ifdef CONFIG_CIFS_STATS2
58150- atomic_inc(&totBufAllocCount);
58151+ atomic_inc_unchecked(&totBufAllocCount);
58152 #endif /* CONFIG_CIFS_STATS2 */
58153 }
58154
58155@@ -205,7 +205,7 @@ cifs_small_buf_get(void)
58156 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
58157 atomic_inc(&smBufAllocCount);
58158 #ifdef CONFIG_CIFS_STATS2
58159- atomic_inc(&totSmBufAllocCount);
58160+ atomic_inc_unchecked(&totSmBufAllocCount);
58161 #endif /* CONFIG_CIFS_STATS2 */
58162
58163 }
58164diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
58165index 526fb89..ecdbf5a 100644
58166--- a/fs/cifs/smb1ops.c
58167+++ b/fs/cifs/smb1ops.c
58168@@ -616,27 +616,27 @@ static void
58169 cifs_clear_stats(struct cifs_tcon *tcon)
58170 {
58171 #ifdef CONFIG_CIFS_STATS
58172- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
58173- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
58174- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
58175- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
58176- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
58177- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
58178- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
58179- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
58180- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
58181- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
58182- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
58183- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
58184- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
58185- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
58186- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
58187- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
58188- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
58189- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
58190- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
58191- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
58192- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
58193+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
58194+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
58195+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
58196+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
58197+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
58198+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
58199+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
58200+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
58201+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
58202+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
58203+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
58204+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
58205+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
58206+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
58207+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
58208+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
58209+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
58210+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
58211+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
58212+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
58213+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
58214 #endif
58215 }
58216
58217@@ -645,36 +645,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
58218 {
58219 #ifdef CONFIG_CIFS_STATS
58220 seq_printf(m, " Oplocks breaks: %d",
58221- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
58222+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
58223 seq_printf(m, "\nReads: %d Bytes: %llu",
58224- atomic_read(&tcon->stats.cifs_stats.num_reads),
58225+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
58226 (long long)(tcon->bytes_read));
58227 seq_printf(m, "\nWrites: %d Bytes: %llu",
58228- atomic_read(&tcon->stats.cifs_stats.num_writes),
58229+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
58230 (long long)(tcon->bytes_written));
58231 seq_printf(m, "\nFlushes: %d",
58232- atomic_read(&tcon->stats.cifs_stats.num_flushes));
58233+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
58234 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
58235- atomic_read(&tcon->stats.cifs_stats.num_locks),
58236- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
58237- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
58238+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
58239+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
58240+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
58241 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
58242- atomic_read(&tcon->stats.cifs_stats.num_opens),
58243- atomic_read(&tcon->stats.cifs_stats.num_closes),
58244- atomic_read(&tcon->stats.cifs_stats.num_deletes));
58245+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
58246+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
58247+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
58248 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
58249- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
58250- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
58251+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
58252+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
58253 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
58254- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
58255- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
58256+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
58257+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
58258 seq_printf(m, "\nRenames: %d T2 Renames %d",
58259- atomic_read(&tcon->stats.cifs_stats.num_renames),
58260- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
58261+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
58262+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
58263 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
58264- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
58265- atomic_read(&tcon->stats.cifs_stats.num_fnext),
58266- atomic_read(&tcon->stats.cifs_stats.num_fclose));
58267+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
58268+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
58269+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
58270 #endif
58271 }
58272
58273diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
58274index 192f51a..539307e 100644
58275--- a/fs/cifs/smb2ops.c
58276+++ b/fs/cifs/smb2ops.c
58277@@ -364,8 +364,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
58278 #ifdef CONFIG_CIFS_STATS
58279 int i;
58280 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
58281- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
58282- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
58283+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
58284+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
58285 }
58286 #endif
58287 }
58288@@ -405,65 +405,65 @@ static void
58289 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
58290 {
58291 #ifdef CONFIG_CIFS_STATS
58292- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
58293- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
58294+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
58295+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
58296 seq_printf(m, "\nNegotiates: %d sent %d failed",
58297- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
58298- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
58299+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
58300+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
58301 seq_printf(m, "\nSessionSetups: %d sent %d failed",
58302- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
58303- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
58304+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
58305+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
58306 seq_printf(m, "\nLogoffs: %d sent %d failed",
58307- atomic_read(&sent[SMB2_LOGOFF_HE]),
58308- atomic_read(&failed[SMB2_LOGOFF_HE]));
58309+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
58310+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
58311 seq_printf(m, "\nTreeConnects: %d sent %d failed",
58312- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
58313- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
58314+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
58315+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
58316 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
58317- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
58318- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
58319+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
58320+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
58321 seq_printf(m, "\nCreates: %d sent %d failed",
58322- atomic_read(&sent[SMB2_CREATE_HE]),
58323- atomic_read(&failed[SMB2_CREATE_HE]));
58324+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
58325+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
58326 seq_printf(m, "\nCloses: %d sent %d failed",
58327- atomic_read(&sent[SMB2_CLOSE_HE]),
58328- atomic_read(&failed[SMB2_CLOSE_HE]));
58329+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
58330+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
58331 seq_printf(m, "\nFlushes: %d sent %d failed",
58332- atomic_read(&sent[SMB2_FLUSH_HE]),
58333- atomic_read(&failed[SMB2_FLUSH_HE]));
58334+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
58335+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
58336 seq_printf(m, "\nReads: %d sent %d failed",
58337- atomic_read(&sent[SMB2_READ_HE]),
58338- atomic_read(&failed[SMB2_READ_HE]));
58339+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
58340+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
58341 seq_printf(m, "\nWrites: %d sent %d failed",
58342- atomic_read(&sent[SMB2_WRITE_HE]),
58343- atomic_read(&failed[SMB2_WRITE_HE]));
58344+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
58345+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
58346 seq_printf(m, "\nLocks: %d sent %d failed",
58347- atomic_read(&sent[SMB2_LOCK_HE]),
58348- atomic_read(&failed[SMB2_LOCK_HE]));
58349+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
58350+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
58351 seq_printf(m, "\nIOCTLs: %d sent %d failed",
58352- atomic_read(&sent[SMB2_IOCTL_HE]),
58353- atomic_read(&failed[SMB2_IOCTL_HE]));
58354+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
58355+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
58356 seq_printf(m, "\nCancels: %d sent %d failed",
58357- atomic_read(&sent[SMB2_CANCEL_HE]),
58358- atomic_read(&failed[SMB2_CANCEL_HE]));
58359+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
58360+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
58361 seq_printf(m, "\nEchos: %d sent %d failed",
58362- atomic_read(&sent[SMB2_ECHO_HE]),
58363- atomic_read(&failed[SMB2_ECHO_HE]));
58364+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
58365+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
58366 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
58367- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
58368- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
58369+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
58370+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
58371 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
58372- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
58373- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
58374+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
58375+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
58376 seq_printf(m, "\nQueryInfos: %d sent %d failed",
58377- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
58378- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
58379+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
58380+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
58381 seq_printf(m, "\nSetInfos: %d sent %d failed",
58382- atomic_read(&sent[SMB2_SET_INFO_HE]),
58383- atomic_read(&failed[SMB2_SET_INFO_HE]));
58384+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
58385+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
58386 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
58387- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
58388- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
58389+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
58390+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
58391 #endif
58392 }
58393
58394diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
58395index 8603447..f9caeee 100644
58396--- a/fs/cifs/smb2pdu.c
58397+++ b/fs/cifs/smb2pdu.c
58398@@ -2094,8 +2094,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
58399 default:
58400 cifs_dbg(VFS, "info level %u isn't supported\n",
58401 srch_inf->info_level);
58402- rc = -EINVAL;
58403- goto qdir_exit;
58404+ return -EINVAL;
58405 }
58406
58407 req->FileIndex = cpu_to_le32(index);
58408diff --git a/fs/coda/cache.c b/fs/coda/cache.c
58409index 1da168c..8bc7ff6 100644
58410--- a/fs/coda/cache.c
58411+++ b/fs/coda/cache.c
58412@@ -24,7 +24,7 @@
58413 #include "coda_linux.h"
58414 #include "coda_cache.h"
58415
58416-static atomic_t permission_epoch = ATOMIC_INIT(0);
58417+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
58418
58419 /* replace or extend an acl cache hit */
58420 void coda_cache_enter(struct inode *inode, int mask)
58421@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
58422 struct coda_inode_info *cii = ITOC(inode);
58423
58424 spin_lock(&cii->c_lock);
58425- cii->c_cached_epoch = atomic_read(&permission_epoch);
58426+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
58427 if (!uid_eq(cii->c_uid, current_fsuid())) {
58428 cii->c_uid = current_fsuid();
58429 cii->c_cached_perm = mask;
58430@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
58431 {
58432 struct coda_inode_info *cii = ITOC(inode);
58433 spin_lock(&cii->c_lock);
58434- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
58435+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
58436 spin_unlock(&cii->c_lock);
58437 }
58438
58439 /* remove all acl caches */
58440 void coda_cache_clear_all(struct super_block *sb)
58441 {
58442- atomic_inc(&permission_epoch);
58443+ atomic_inc_unchecked(&permission_epoch);
58444 }
58445
58446
58447@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
58448 spin_lock(&cii->c_lock);
58449 hit = (mask & cii->c_cached_perm) == mask &&
58450 uid_eq(cii->c_uid, current_fsuid()) &&
58451- cii->c_cached_epoch == atomic_read(&permission_epoch);
58452+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
58453 spin_unlock(&cii->c_lock);
58454
58455 return hit;
58456diff --git a/fs/compat.c b/fs/compat.c
58457index 6af20de..fec3fbb 100644
58458--- a/fs/compat.c
58459+++ b/fs/compat.c
58460@@ -54,7 +54,7 @@
58461 #include <asm/ioctls.h>
58462 #include "internal.h"
58463
58464-int compat_log = 1;
58465+int compat_log = 0;
58466
58467 int compat_printk(const char *fmt, ...)
58468 {
58469@@ -488,7 +488,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
58470
58471 set_fs(KERNEL_DS);
58472 /* The __user pointer cast is valid because of the set_fs() */
58473- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
58474+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
58475 set_fs(oldfs);
58476 /* truncating is ok because it's a user address */
58477 if (!ret)
58478@@ -546,7 +546,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
58479 goto out;
58480
58481 ret = -EINVAL;
58482- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
58483+ if (nr_segs > UIO_MAXIOV)
58484 goto out;
58485 if (nr_segs > fast_segs) {
58486 ret = -ENOMEM;
58487@@ -834,6 +834,7 @@ struct compat_old_linux_dirent {
58488 struct compat_readdir_callback {
58489 struct dir_context ctx;
58490 struct compat_old_linux_dirent __user *dirent;
58491+ struct file * file;
58492 int result;
58493 };
58494
58495@@ -851,6 +852,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
58496 buf->result = -EOVERFLOW;
58497 return -EOVERFLOW;
58498 }
58499+
58500+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58501+ return 0;
58502+
58503 buf->result++;
58504 dirent = buf->dirent;
58505 if (!access_ok(VERIFY_WRITE, dirent,
58506@@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
58507 if (!f.file)
58508 return -EBADF;
58509
58510+ buf.file = f.file;
58511 error = iterate_dir(f.file, &buf.ctx);
58512 if (buf.result)
58513 error = buf.result;
58514@@ -901,6 +907,7 @@ struct compat_getdents_callback {
58515 struct dir_context ctx;
58516 struct compat_linux_dirent __user *current_dir;
58517 struct compat_linux_dirent __user *previous;
58518+ struct file * file;
58519 int count;
58520 int error;
58521 };
58522@@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
58523 buf->error = -EOVERFLOW;
58524 return -EOVERFLOW;
58525 }
58526+
58527+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58528+ return 0;
58529+
58530 dirent = buf->previous;
58531 if (dirent) {
58532 if (__put_user(offset, &dirent->d_off))
58533@@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
58534 if (!f.file)
58535 return -EBADF;
58536
58537+ buf.file = f.file;
58538 error = iterate_dir(f.file, &buf.ctx);
58539 if (error >= 0)
58540 error = buf.error;
58541@@ -987,6 +999,7 @@ struct compat_getdents_callback64 {
58542 struct dir_context ctx;
58543 struct linux_dirent64 __user *current_dir;
58544 struct linux_dirent64 __user *previous;
58545+ struct file * file;
58546 int count;
58547 int error;
58548 };
58549@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
58550 buf->error = -EINVAL; /* only used if we fail.. */
58551 if (reclen > buf->count)
58552 return -EINVAL;
58553+
58554+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58555+ return 0;
58556+
58557 dirent = buf->previous;
58558
58559 if (dirent) {
58560@@ -1052,6 +1069,7 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
58561 if (!f.file)
58562 return -EBADF;
58563
58564+ buf.file = f.file;
58565 error = iterate_dir(f.file, &buf.ctx);
58566 if (error >= 0)
58567 error = buf.error;
58568diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
58569index a81147e..20bf2b5 100644
58570--- a/fs/compat_binfmt_elf.c
58571+++ b/fs/compat_binfmt_elf.c
58572@@ -30,11 +30,13 @@
58573 #undef elf_phdr
58574 #undef elf_shdr
58575 #undef elf_note
58576+#undef elf_dyn
58577 #undef elf_addr_t
58578 #define elfhdr elf32_hdr
58579 #define elf_phdr elf32_phdr
58580 #define elf_shdr elf32_shdr
58581 #define elf_note elf32_note
58582+#define elf_dyn Elf32_Dyn
58583 #define elf_addr_t Elf32_Addr
58584
58585 /*
58586diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
58587index 3881610..ab3df0b 100644
58588--- a/fs/compat_ioctl.c
58589+++ b/fs/compat_ioctl.c
58590@@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
58591 return -EFAULT;
58592 if (__get_user(udata, &ss32->iomem_base))
58593 return -EFAULT;
58594- ss.iomem_base = compat_ptr(udata);
58595+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
58596 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
58597 __get_user(ss.port_high, &ss32->port_high))
58598 return -EFAULT;
58599@@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
58600 for (i = 0; i < nmsgs; i++) {
58601 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
58602 return -EFAULT;
58603- if (get_user(datap, &umsgs[i].buf) ||
58604- put_user(compat_ptr(datap), &tmsgs[i].buf))
58605+ if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
58606+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
58607 return -EFAULT;
58608 }
58609 return sys_ioctl(fd, cmd, (unsigned long)tdata);
58610@@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
58611 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
58612 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
58613 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
58614- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
58615+ copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
58616 return -EFAULT;
58617
58618 return ioctl_preallocate(file, p);
58619@@ -1617,8 +1617,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
58620 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
58621 {
58622 unsigned int a, b;
58623- a = *(unsigned int *)p;
58624- b = *(unsigned int *)q;
58625+ a = *(const unsigned int *)p;
58626+ b = *(const unsigned int *)q;
58627 if (a > b)
58628 return 1;
58629 if (a < b)
58630diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
58631index e081acb..911df21 100644
58632--- a/fs/configfs/dir.c
58633+++ b/fs/configfs/dir.c
58634@@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
58635 }
58636 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
58637 struct configfs_dirent *next;
58638- const char *name;
58639+ const unsigned char * name;
58640+ char d_name[sizeof(next->s_dentry->d_iname)];
58641 int len;
58642 struct inode *inode = NULL;
58643
58644@@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
58645 continue;
58646
58647 name = configfs_get_name(next);
58648- len = strlen(name);
58649+ if (next->s_dentry && name == next->s_dentry->d_iname) {
58650+ len = next->s_dentry->d_name.len;
58651+ memcpy(d_name, name, len);
58652+ name = d_name;
58653+ } else
58654+ len = strlen(name);
58655
58656 /*
58657 * We'll have a dentry and an inode for
58658diff --git a/fs/coredump.c b/fs/coredump.c
58659index e3ad709..836c55f 100644
58660--- a/fs/coredump.c
58661+++ b/fs/coredump.c
58662@@ -73,10 +73,15 @@ static int expand_corename(struct core_name *cn, int size)
58663 static int cn_vprintf(struct core_name *cn, const char *fmt, va_list arg)
58664 {
58665 int free, need;
58666+ va_list arg_copy;
58667
58668 again:
58669 free = cn->size - cn->used;
58670- need = vsnprintf(cn->corename + cn->used, free, fmt, arg);
58671+
58672+ va_copy(arg_copy, arg);
58673+ need = vsnprintf(cn->corename + cn->used, free, fmt, arg_copy);
58674+ va_end(arg_copy);
58675+
58676 if (need < free) {
58677 cn->used += need;
58678 return 0;
58679@@ -437,8 +442,8 @@ static void wait_for_dump_helpers(struct file *file)
58680 struct pipe_inode_info *pipe = file->private_data;
58681
58682 pipe_lock(pipe);
58683- pipe->readers++;
58684- pipe->writers--;
58685+ atomic_inc(&pipe->readers);
58686+ atomic_dec(&pipe->writers);
58687 wake_up_interruptible_sync(&pipe->wait);
58688 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
58689 pipe_unlock(pipe);
58690@@ -447,11 +452,11 @@ static void wait_for_dump_helpers(struct file *file)
58691 * We actually want wait_event_freezable() but then we need
58692 * to clear TIF_SIGPENDING and improve dump_interrupted().
58693 */
58694- wait_event_interruptible(pipe->wait, pipe->readers == 1);
58695+ wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
58696
58697 pipe_lock(pipe);
58698- pipe->readers--;
58699- pipe->writers++;
58700+ atomic_dec(&pipe->readers);
58701+ atomic_inc(&pipe->writers);
58702 pipe_unlock(pipe);
58703 }
58704
58705@@ -498,7 +503,9 @@ void do_coredump(const siginfo_t *siginfo)
58706 struct files_struct *displaced;
58707 bool need_nonrelative = false;
58708 bool core_dumped = false;
58709- static atomic_t core_dump_count = ATOMIC_INIT(0);
58710+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
58711+ long signr = siginfo->si_signo;
58712+ int dumpable;
58713 struct coredump_params cprm = {
58714 .siginfo = siginfo,
58715 .regs = signal_pt_regs(),
58716@@ -511,12 +518,17 @@ void do_coredump(const siginfo_t *siginfo)
58717 .mm_flags = mm->flags,
58718 };
58719
58720- audit_core_dumps(siginfo->si_signo);
58721+ audit_core_dumps(signr);
58722+
58723+ dumpable = __get_dumpable(cprm.mm_flags);
58724+
58725+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
58726+ gr_handle_brute_attach(dumpable);
58727
58728 binfmt = mm->binfmt;
58729 if (!binfmt || !binfmt->core_dump)
58730 goto fail;
58731- if (!__get_dumpable(cprm.mm_flags))
58732+ if (!dumpable)
58733 goto fail;
58734
58735 cred = prepare_creds();
58736@@ -535,7 +547,7 @@ void do_coredump(const siginfo_t *siginfo)
58737 need_nonrelative = true;
58738 }
58739
58740- retval = coredump_wait(siginfo->si_signo, &core_state);
58741+ retval = coredump_wait(signr, &core_state);
58742 if (retval < 0)
58743 goto fail_creds;
58744
58745@@ -578,7 +590,7 @@ void do_coredump(const siginfo_t *siginfo)
58746 }
58747 cprm.limit = RLIM_INFINITY;
58748
58749- dump_count = atomic_inc_return(&core_dump_count);
58750+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
58751 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
58752 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
58753 task_tgid_vnr(current), current->comm);
58754@@ -610,6 +622,8 @@ void do_coredump(const siginfo_t *siginfo)
58755 } else {
58756 struct inode *inode;
58757
58758+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
58759+
58760 if (cprm.limit < binfmt->min_coredump)
58761 goto fail_unlock;
58762
58763@@ -668,7 +682,7 @@ close_fail:
58764 filp_close(cprm.file, NULL);
58765 fail_dropcount:
58766 if (ispipe)
58767- atomic_dec(&core_dump_count);
58768+ atomic_dec_unchecked(&core_dump_count);
58769 fail_unlock:
58770 kfree(cn.corename);
58771 coredump_finish(mm, core_dumped);
58772@@ -689,6 +703,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
58773 struct file *file = cprm->file;
58774 loff_t pos = file->f_pos;
58775 ssize_t n;
58776+
58777+ gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
58778 if (cprm->written + nr > cprm->limit)
58779 return 0;
58780 while (nr) {
58781diff --git a/fs/dcache.c b/fs/dcache.c
58782index ca02c13..7e2b581 100644
58783--- a/fs/dcache.c
58784+++ b/fs/dcache.c
58785@@ -1495,7 +1495,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
58786 */
58787 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
58788 if (name->len > DNAME_INLINE_LEN-1) {
58789- dname = kmalloc(name->len + 1, GFP_KERNEL);
58790+ dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
58791 if (!dname) {
58792 kmem_cache_free(dentry_cache, dentry);
58793 return NULL;
58794@@ -3431,7 +3431,8 @@ void __init vfs_caches_init(unsigned long mempages)
58795 mempages -= reserve;
58796
58797 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
58798- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
58799+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
58800+ SLAB_NO_SANITIZE, NULL);
58801
58802 dcache_init();
58803 inode_init();
58804diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
58805index 9c0444c..628490c 100644
58806--- a/fs/debugfs/inode.c
58807+++ b/fs/debugfs/inode.c
58808@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
58809 */
58810 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
58811 {
58812+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
58813+ return __create_file(name, S_IFDIR | S_IRWXU,
58814+#else
58815 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
58816+#endif
58817 parent, NULL, NULL);
58818 }
58819 EXPORT_SYMBOL_GPL(debugfs_create_dir);
58820diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
58821index b167ca4..a224e19 100644
58822--- a/fs/ecryptfs/inode.c
58823+++ b/fs/ecryptfs/inode.c
58824@@ -673,7 +673,7 @@ static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
58825 old_fs = get_fs();
58826 set_fs(get_ds());
58827 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
58828- (char __user *)lower_buf,
58829+ (char __force_user *)lower_buf,
58830 PATH_MAX);
58831 set_fs(old_fs);
58832 if (rc < 0)
58833diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
58834index e4141f2..d8263e8 100644
58835--- a/fs/ecryptfs/miscdev.c
58836+++ b/fs/ecryptfs/miscdev.c
58837@@ -304,7 +304,7 @@ check_list:
58838 goto out_unlock_msg_ctx;
58839 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
58840 if (msg_ctx->msg) {
58841- if (copy_to_user(&buf[i], packet_length, packet_length_size))
58842+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
58843 goto out_unlock_msg_ctx;
58844 i += packet_length_size;
58845 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
58846diff --git a/fs/exec.c b/fs/exec.c
58847index 3d78fcc..460e2a0 100644
58848--- a/fs/exec.c
58849+++ b/fs/exec.c
58850@@ -55,8 +55,20 @@
58851 #include <linux/pipe_fs_i.h>
58852 #include <linux/oom.h>
58853 #include <linux/compat.h>
58854+#include <linux/random.h>
58855+#include <linux/seq_file.h>
58856+#include <linux/coredump.h>
58857+#include <linux/mman.h>
58858+
58859+#ifdef CONFIG_PAX_REFCOUNT
58860+#include <linux/kallsyms.h>
58861+#include <linux/kdebug.h>
58862+#endif
58863+
58864+#include <trace/events/fs.h>
58865
58866 #include <asm/uaccess.h>
58867+#include <asm/sections.h>
58868 #include <asm/mmu_context.h>
58869 #include <asm/tlb.h>
58870
58871@@ -65,19 +77,34 @@
58872
58873 #include <trace/events/sched.h>
58874
58875+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
58876+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
58877+{
58878+ 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");
58879+}
58880+#endif
58881+
58882+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
58883+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
58884+EXPORT_SYMBOL(pax_set_initial_flags_func);
58885+#endif
58886+
58887 int suid_dumpable = 0;
58888
58889 static LIST_HEAD(formats);
58890 static DEFINE_RWLOCK(binfmt_lock);
58891
58892+extern int gr_process_kernel_exec_ban(void);
58893+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
58894+
58895 void __register_binfmt(struct linux_binfmt * fmt, int insert)
58896 {
58897 BUG_ON(!fmt);
58898 if (WARN_ON(!fmt->load_binary))
58899 return;
58900 write_lock(&binfmt_lock);
58901- insert ? list_add(&fmt->lh, &formats) :
58902- list_add_tail(&fmt->lh, &formats);
58903+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
58904+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
58905 write_unlock(&binfmt_lock);
58906 }
58907
58908@@ -86,7 +113,7 @@ EXPORT_SYMBOL(__register_binfmt);
58909 void unregister_binfmt(struct linux_binfmt * fmt)
58910 {
58911 write_lock(&binfmt_lock);
58912- list_del(&fmt->lh);
58913+ pax_list_del((struct list_head *)&fmt->lh);
58914 write_unlock(&binfmt_lock);
58915 }
58916
58917@@ -180,18 +207,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58918 int write)
58919 {
58920 struct page *page;
58921- int ret;
58922
58923-#ifdef CONFIG_STACK_GROWSUP
58924- if (write) {
58925- ret = expand_downwards(bprm->vma, pos);
58926- if (ret < 0)
58927- return NULL;
58928- }
58929-#endif
58930- ret = get_user_pages(current, bprm->mm, pos,
58931- 1, write, 1, &page, NULL);
58932- if (ret <= 0)
58933+ if (0 > expand_downwards(bprm->vma, pos))
58934+ return NULL;
58935+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
58936 return NULL;
58937
58938 if (write) {
58939@@ -207,6 +226,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58940 if (size <= ARG_MAX)
58941 return page;
58942
58943+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58944+ // only allow 512KB for argv+env on suid/sgid binaries
58945+ // to prevent easy ASLR exhaustion
58946+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
58947+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
58948+ (size > (512 * 1024))) {
58949+ put_page(page);
58950+ return NULL;
58951+ }
58952+#endif
58953+
58954 /*
58955 * Limit to 1/4-th the stack size for the argv+env strings.
58956 * This ensures that:
58957@@ -266,6 +296,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58958 vma->vm_end = STACK_TOP_MAX;
58959 vma->vm_start = vma->vm_end - PAGE_SIZE;
58960 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
58961+
58962+#ifdef CONFIG_PAX_SEGMEXEC
58963+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
58964+#endif
58965+
58966 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
58967 INIT_LIST_HEAD(&vma->anon_vma_chain);
58968
58969@@ -276,6 +311,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58970 mm->stack_vm = mm->total_vm = 1;
58971 up_write(&mm->mmap_sem);
58972 bprm->p = vma->vm_end - sizeof(void *);
58973+
58974+#ifdef CONFIG_PAX_RANDUSTACK
58975+ if (randomize_va_space)
58976+ bprm->p ^= prandom_u32() & ~PAGE_MASK;
58977+#endif
58978+
58979 return 0;
58980 err:
58981 up_write(&mm->mmap_sem);
58982@@ -396,7 +437,7 @@ struct user_arg_ptr {
58983 } ptr;
58984 };
58985
58986-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58987+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58988 {
58989 const char __user *native;
58990
58991@@ -405,14 +446,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58992 compat_uptr_t compat;
58993
58994 if (get_user(compat, argv.ptr.compat + nr))
58995- return ERR_PTR(-EFAULT);
58996+ return (const char __force_user *)ERR_PTR(-EFAULT);
58997
58998 return compat_ptr(compat);
58999 }
59000 #endif
59001
59002 if (get_user(native, argv.ptr.native + nr))
59003- return ERR_PTR(-EFAULT);
59004+ return (const char __force_user *)ERR_PTR(-EFAULT);
59005
59006 return native;
59007 }
59008@@ -431,7 +472,7 @@ static int count(struct user_arg_ptr argv, int max)
59009 if (!p)
59010 break;
59011
59012- if (IS_ERR(p))
59013+ if (IS_ERR((const char __force_kernel *)p))
59014 return -EFAULT;
59015
59016 if (i >= max)
59017@@ -466,7 +507,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
59018
59019 ret = -EFAULT;
59020 str = get_user_arg_ptr(argv, argc);
59021- if (IS_ERR(str))
59022+ if (IS_ERR((const char __force_kernel *)str))
59023 goto out;
59024
59025 len = strnlen_user(str, MAX_ARG_STRLEN);
59026@@ -548,7 +589,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
59027 int r;
59028 mm_segment_t oldfs = get_fs();
59029 struct user_arg_ptr argv = {
59030- .ptr.native = (const char __user *const __user *)__argv,
59031+ .ptr.native = (const char __user * const __force_user *)__argv,
59032 };
59033
59034 set_fs(KERNEL_DS);
59035@@ -583,7 +624,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
59036 unsigned long new_end = old_end - shift;
59037 struct mmu_gather tlb;
59038
59039- BUG_ON(new_start > new_end);
59040+ if (new_start >= new_end || new_start < mmap_min_addr)
59041+ return -ENOMEM;
59042
59043 /*
59044 * ensure there are no vmas between where we want to go
59045@@ -592,6 +634,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
59046 if (vma != find_vma(mm, new_start))
59047 return -EFAULT;
59048
59049+#ifdef CONFIG_PAX_SEGMEXEC
59050+ BUG_ON(pax_find_mirror_vma(vma));
59051+#endif
59052+
59053 /*
59054 * cover the whole range: [new_start, old_end)
59055 */
59056@@ -672,10 +718,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
59057 stack_top = arch_align_stack(stack_top);
59058 stack_top = PAGE_ALIGN(stack_top);
59059
59060- if (unlikely(stack_top < mmap_min_addr) ||
59061- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
59062- return -ENOMEM;
59063-
59064 stack_shift = vma->vm_end - stack_top;
59065
59066 bprm->p -= stack_shift;
59067@@ -687,8 +729,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
59068 bprm->exec -= stack_shift;
59069
59070 down_write(&mm->mmap_sem);
59071+
59072+ /* Move stack pages down in memory. */
59073+ if (stack_shift) {
59074+ ret = shift_arg_pages(vma, stack_shift);
59075+ if (ret)
59076+ goto out_unlock;
59077+ }
59078+
59079 vm_flags = VM_STACK_FLAGS;
59080
59081+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
59082+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
59083+ vm_flags &= ~VM_EXEC;
59084+
59085+#ifdef CONFIG_PAX_MPROTECT
59086+ if (mm->pax_flags & MF_PAX_MPROTECT)
59087+ vm_flags &= ~VM_MAYEXEC;
59088+#endif
59089+
59090+ }
59091+#endif
59092+
59093 /*
59094 * Adjust stack execute permissions; explicitly enable for
59095 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
59096@@ -707,13 +769,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
59097 goto out_unlock;
59098 BUG_ON(prev != vma);
59099
59100- /* Move stack pages down in memory. */
59101- if (stack_shift) {
59102- ret = shift_arg_pages(vma, stack_shift);
59103- if (ret)
59104- goto out_unlock;
59105- }
59106-
59107 /* mprotect_fixup is overkill to remove the temporary stack flags */
59108 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
59109
59110@@ -737,6 +792,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
59111 #endif
59112 current->mm->start_stack = bprm->p;
59113 ret = expand_stack(vma, stack_base);
59114+
59115+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
59116+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
59117+ unsigned long size;
59118+ vm_flags_t vm_flags;
59119+
59120+ size = STACK_TOP - vma->vm_end;
59121+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
59122+
59123+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
59124+
59125+#ifdef CONFIG_X86
59126+ if (!ret) {
59127+ size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
59128+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
59129+ }
59130+#endif
59131+
59132+ }
59133+#endif
59134+
59135 if (ret)
59136 ret = -EFAULT;
59137
59138@@ -772,6 +848,8 @@ static struct file *do_open_exec(struct filename *name)
59139
59140 fsnotify_open(file);
59141
59142+ trace_open_exec(name->name);
59143+
59144 err = deny_write_access(file);
59145 if (err)
59146 goto exit;
59147@@ -801,7 +879,7 @@ int kernel_read(struct file *file, loff_t offset,
59148 old_fs = get_fs();
59149 set_fs(get_ds());
59150 /* The cast to a user pointer is valid due to the set_fs() */
59151- result = vfs_read(file, (void __user *)addr, count, &pos);
59152+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
59153 set_fs(old_fs);
59154 return result;
59155 }
59156@@ -1258,7 +1336,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
59157 }
59158 rcu_read_unlock();
59159
59160- if (p->fs->users > n_fs)
59161+ if (atomic_read(&p->fs->users) > n_fs)
59162 bprm->unsafe |= LSM_UNSAFE_SHARE;
59163 else
59164 p->fs->in_exec = 1;
59165@@ -1434,6 +1512,31 @@ static int exec_binprm(struct linux_binprm *bprm)
59166 return ret;
59167 }
59168
59169+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59170+static DEFINE_PER_CPU(u64, exec_counter);
59171+static int __init init_exec_counters(void)
59172+{
59173+ unsigned int cpu;
59174+
59175+ for_each_possible_cpu(cpu) {
59176+ per_cpu(exec_counter, cpu) = (u64)cpu;
59177+ }
59178+
59179+ return 0;
59180+}
59181+early_initcall(init_exec_counters);
59182+static inline void increment_exec_counter(void)
59183+{
59184+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
59185+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
59186+}
59187+#else
59188+static inline void increment_exec_counter(void) {}
59189+#endif
59190+
59191+extern void gr_handle_exec_args(struct linux_binprm *bprm,
59192+ struct user_arg_ptr argv);
59193+
59194 /*
59195 * sys_execve() executes a new program.
59196 */
59197@@ -1441,6 +1544,11 @@ static int do_execve_common(struct filename *filename,
59198 struct user_arg_ptr argv,
59199 struct user_arg_ptr envp)
59200 {
59201+#ifdef CONFIG_GRKERNSEC
59202+ struct file *old_exec_file;
59203+ struct acl_subject_label *old_acl;
59204+ struct rlimit old_rlim[RLIM_NLIMITS];
59205+#endif
59206 struct linux_binprm *bprm;
59207 struct file *file;
59208 struct files_struct *displaced;
59209@@ -1449,6 +1557,8 @@ static int do_execve_common(struct filename *filename,
59210 if (IS_ERR(filename))
59211 return PTR_ERR(filename);
59212
59213+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
59214+
59215 /*
59216 * We move the actual failure in case of RLIMIT_NPROC excess from
59217 * set*uid() to execve() because too many poorly written programs
59218@@ -1486,11 +1596,21 @@ static int do_execve_common(struct filename *filename,
59219 if (IS_ERR(file))
59220 goto out_unmark;
59221
59222+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
59223+ retval = -EPERM;
59224+ goto out_unmark;
59225+ }
59226+
59227 sched_exec();
59228
59229 bprm->file = file;
59230 bprm->filename = bprm->interp = filename->name;
59231
59232+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
59233+ retval = -EACCES;
59234+ goto out_unmark;
59235+ }
59236+
59237 retval = bprm_mm_init(bprm);
59238 if (retval)
59239 goto out_unmark;
59240@@ -1507,24 +1627,70 @@ static int do_execve_common(struct filename *filename,
59241 if (retval < 0)
59242 goto out;
59243
59244+#ifdef CONFIG_GRKERNSEC
59245+ old_acl = current->acl;
59246+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
59247+ old_exec_file = current->exec_file;
59248+ get_file(file);
59249+ current->exec_file = file;
59250+#endif
59251+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59252+ /* limit suid stack to 8MB
59253+ * we saved the old limits above and will restore them if this exec fails
59254+ */
59255+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
59256+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
59257+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
59258+#endif
59259+
59260+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
59261+ retval = -EPERM;
59262+ goto out_fail;
59263+ }
59264+
59265+ if (!gr_tpe_allow(file)) {
59266+ retval = -EACCES;
59267+ goto out_fail;
59268+ }
59269+
59270+ if (gr_check_crash_exec(file)) {
59271+ retval = -EACCES;
59272+ goto out_fail;
59273+ }
59274+
59275+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
59276+ bprm->unsafe);
59277+ if (retval < 0)
59278+ goto out_fail;
59279+
59280 retval = copy_strings_kernel(1, &bprm->filename, bprm);
59281 if (retval < 0)
59282- goto out;
59283+ goto out_fail;
59284
59285 bprm->exec = bprm->p;
59286 retval = copy_strings(bprm->envc, envp, bprm);
59287 if (retval < 0)
59288- goto out;
59289+ goto out_fail;
59290
59291 retval = copy_strings(bprm->argc, argv, bprm);
59292 if (retval < 0)
59293- goto out;
59294+ goto out_fail;
59295+
59296+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
59297+
59298+ gr_handle_exec_args(bprm, argv);
59299
59300 retval = exec_binprm(bprm);
59301 if (retval < 0)
59302- goto out;
59303+ goto out_fail;
59304+#ifdef CONFIG_GRKERNSEC
59305+ if (old_exec_file)
59306+ fput(old_exec_file);
59307+#endif
59308
59309 /* execve succeeded */
59310+
59311+ increment_exec_counter();
59312 current->fs->in_exec = 0;
59313 current->in_execve = 0;
59314 acct_update_integrals(current);
59315@@ -1535,6 +1701,14 @@ static int do_execve_common(struct filename *filename,
59316 put_files_struct(displaced);
59317 return retval;
59318
59319+out_fail:
59320+#ifdef CONFIG_GRKERNSEC
59321+ current->acl = old_acl;
59322+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
59323+ fput(current->exec_file);
59324+ current->exec_file = old_exec_file;
59325+#endif
59326+
59327 out:
59328 if (bprm->mm) {
59329 acct_arg_size(bprm, 0);
59330@@ -1626,3 +1800,296 @@ asmlinkage long compat_sys_execve(const char __user * filename,
59331 return compat_do_execve(getname(filename), argv, envp);
59332 }
59333 #endif
59334+
59335+int pax_check_flags(unsigned long *flags)
59336+{
59337+ int retval = 0;
59338+
59339+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
59340+ if (*flags & MF_PAX_SEGMEXEC)
59341+ {
59342+ *flags &= ~MF_PAX_SEGMEXEC;
59343+ retval = -EINVAL;
59344+ }
59345+#endif
59346+
59347+ if ((*flags & MF_PAX_PAGEEXEC)
59348+
59349+#ifdef CONFIG_PAX_PAGEEXEC
59350+ && (*flags & MF_PAX_SEGMEXEC)
59351+#endif
59352+
59353+ )
59354+ {
59355+ *flags &= ~MF_PAX_PAGEEXEC;
59356+ retval = -EINVAL;
59357+ }
59358+
59359+ if ((*flags & MF_PAX_MPROTECT)
59360+
59361+#ifdef CONFIG_PAX_MPROTECT
59362+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
59363+#endif
59364+
59365+ )
59366+ {
59367+ *flags &= ~MF_PAX_MPROTECT;
59368+ retval = -EINVAL;
59369+ }
59370+
59371+ if ((*flags & MF_PAX_EMUTRAMP)
59372+
59373+#ifdef CONFIG_PAX_EMUTRAMP
59374+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
59375+#endif
59376+
59377+ )
59378+ {
59379+ *flags &= ~MF_PAX_EMUTRAMP;
59380+ retval = -EINVAL;
59381+ }
59382+
59383+ return retval;
59384+}
59385+
59386+EXPORT_SYMBOL(pax_check_flags);
59387+
59388+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
59389+char *pax_get_path(const struct path *path, char *buf, int buflen)
59390+{
59391+ char *pathname = d_path(path, buf, buflen);
59392+
59393+ if (IS_ERR(pathname))
59394+ goto toolong;
59395+
59396+ pathname = mangle_path(buf, pathname, "\t\n\\");
59397+ if (!pathname)
59398+ goto toolong;
59399+
59400+ *pathname = 0;
59401+ return buf;
59402+
59403+toolong:
59404+ return "<path too long>";
59405+}
59406+EXPORT_SYMBOL(pax_get_path);
59407+
59408+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
59409+{
59410+ struct task_struct *tsk = current;
59411+ struct mm_struct *mm = current->mm;
59412+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
59413+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
59414+ char *path_exec = NULL;
59415+ char *path_fault = NULL;
59416+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
59417+ siginfo_t info = { };
59418+
59419+ if (buffer_exec && buffer_fault) {
59420+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
59421+
59422+ down_read(&mm->mmap_sem);
59423+ vma = mm->mmap;
59424+ while (vma && (!vma_exec || !vma_fault)) {
59425+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
59426+ vma_exec = vma;
59427+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
59428+ vma_fault = vma;
59429+ vma = vma->vm_next;
59430+ }
59431+ if (vma_exec)
59432+ path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
59433+ if (vma_fault) {
59434+ start = vma_fault->vm_start;
59435+ end = vma_fault->vm_end;
59436+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
59437+ if (vma_fault->vm_file)
59438+ path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
59439+ else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
59440+ path_fault = "<heap>";
59441+ else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
59442+ path_fault = "<stack>";
59443+ else
59444+ path_fault = "<anonymous mapping>";
59445+ }
59446+ up_read(&mm->mmap_sem);
59447+ }
59448+ if (tsk->signal->curr_ip)
59449+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
59450+ else
59451+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
59452+ 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),
59453+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
59454+ free_page((unsigned long)buffer_exec);
59455+ free_page((unsigned long)buffer_fault);
59456+ pax_report_insns(regs, pc, sp);
59457+ info.si_signo = SIGKILL;
59458+ info.si_errno = 0;
59459+ info.si_code = SI_KERNEL;
59460+ info.si_pid = 0;
59461+ info.si_uid = 0;
59462+ do_coredump(&info);
59463+}
59464+#endif
59465+
59466+#ifdef CONFIG_PAX_REFCOUNT
59467+void pax_report_refcount_overflow(struct pt_regs *regs)
59468+{
59469+ if (current->signal->curr_ip)
59470+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
59471+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
59472+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
59473+ else
59474+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
59475+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
59476+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
59477+ preempt_disable();
59478+ show_regs(regs);
59479+ preempt_enable();
59480+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
59481+}
59482+#endif
59483+
59484+#ifdef CONFIG_PAX_USERCOPY
59485+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
59486+static noinline int check_stack_object(const void *obj, unsigned long len)
59487+{
59488+ const void * const stack = task_stack_page(current);
59489+ const void * const stackend = stack + THREAD_SIZE;
59490+
59491+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
59492+ const void *frame = NULL;
59493+ const void *oldframe;
59494+#endif
59495+
59496+ if (obj + len < obj)
59497+ return -1;
59498+
59499+ if (obj + len <= stack || stackend <= obj)
59500+ return 0;
59501+
59502+ if (obj < stack || stackend < obj + len)
59503+ return -1;
59504+
59505+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
59506+ oldframe = __builtin_frame_address(1);
59507+ if (oldframe)
59508+ frame = __builtin_frame_address(2);
59509+ /*
59510+ low ----------------------------------------------> high
59511+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
59512+ ^----------------^
59513+ allow copies only within here
59514+ */
59515+ while (stack <= frame && frame < stackend) {
59516+ /* if obj + len extends past the last frame, this
59517+ check won't pass and the next frame will be 0,
59518+ causing us to bail out and correctly report
59519+ the copy as invalid
59520+ */
59521+ if (obj + len <= frame)
59522+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
59523+ oldframe = frame;
59524+ frame = *(const void * const *)frame;
59525+ }
59526+ return -1;
59527+#else
59528+ return 1;
59529+#endif
59530+}
59531+
59532+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
59533+{
59534+ if (current->signal->curr_ip)
59535+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
59536+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
59537+ else
59538+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
59539+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
59540+ dump_stack();
59541+ gr_handle_kernel_exploit();
59542+ do_group_exit(SIGKILL);
59543+}
59544+#endif
59545+
59546+#ifdef CONFIG_PAX_USERCOPY
59547+
59548+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
59549+{
59550+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
59551+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
59552+#ifdef CONFIG_MODULES
59553+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
59554+#else
59555+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
59556+#endif
59557+
59558+#else
59559+ unsigned long textlow = (unsigned long)_stext;
59560+ unsigned long texthigh = (unsigned long)_etext;
59561+
59562+#ifdef CONFIG_X86_64
59563+ /* check against linear mapping as well */
59564+ if (high > (unsigned long)__va(__pa(textlow)) &&
59565+ low < (unsigned long)__va(__pa(texthigh)))
59566+ return true;
59567+#endif
59568+
59569+#endif
59570+
59571+ if (high <= textlow || low >= texthigh)
59572+ return false;
59573+ else
59574+ return true;
59575+}
59576+#endif
59577+
59578+void __check_object_size(const void *ptr, unsigned long n, bool to_user)
59579+{
59580+
59581+#ifdef CONFIG_PAX_USERCOPY
59582+ const char *type;
59583+
59584+ if (!n)
59585+ return;
59586+
59587+ type = check_heap_object(ptr, n);
59588+ if (!type) {
59589+ int ret = check_stack_object(ptr, n);
59590+ if (ret == 1 || ret == 2)
59591+ return;
59592+ if (ret == 0) {
59593+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
59594+ type = "<kernel text>";
59595+ else
59596+ return;
59597+ } else
59598+ type = "<process stack>";
59599+ }
59600+
59601+ pax_report_usercopy(ptr, n, to_user, type);
59602+#endif
59603+
59604+}
59605+EXPORT_SYMBOL(__check_object_size);
59606+
59607+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
59608+void pax_track_stack(void)
59609+{
59610+ unsigned long sp = (unsigned long)&sp;
59611+ if (sp < current_thread_info()->lowest_stack &&
59612+ sp > (unsigned long)task_stack_page(current))
59613+ current_thread_info()->lowest_stack = sp;
59614+}
59615+EXPORT_SYMBOL(pax_track_stack);
59616+#endif
59617+
59618+#ifdef CONFIG_PAX_SIZE_OVERFLOW
59619+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
59620+{
59621+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
59622+ dump_stack();
59623+ do_group_exit(SIGKILL);
59624+}
59625+EXPORT_SYMBOL(report_size_overflow);
59626+#endif
59627diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
59628index 9f9992b..8b59411 100644
59629--- a/fs/ext2/balloc.c
59630+++ b/fs/ext2/balloc.c
59631@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
59632
59633 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
59634 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
59635- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
59636+ if (free_blocks < root_blocks + 1 &&
59637 !uid_eq(sbi->s_resuid, current_fsuid()) &&
59638 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
59639- !in_group_p (sbi->s_resgid))) {
59640+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
59641 return 0;
59642 }
59643 return 1;
59644diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
59645index 9142614..97484fa 100644
59646--- a/fs/ext2/xattr.c
59647+++ b/fs/ext2/xattr.c
59648@@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
59649 struct buffer_head *bh = NULL;
59650 struct ext2_xattr_entry *entry;
59651 char *end;
59652- size_t rest = buffer_size;
59653+ size_t rest = buffer_size, total_size = 0;
59654 int error;
59655
59656 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
59657@@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
59658 buffer += size;
59659 }
59660 rest -= size;
59661+ total_size += size;
59662 }
59663 }
59664- error = buffer_size - rest; /* total size */
59665+ error = total_size;
59666
59667 cleanup:
59668 brelse(bh);
59669diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
59670index 22548f5..41521d8 100644
59671--- a/fs/ext3/balloc.c
59672+++ b/fs/ext3/balloc.c
59673@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
59674
59675 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
59676 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
59677- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
59678+ if (free_blocks < root_blocks + 1 &&
59679 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
59680 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
59681- !in_group_p (sbi->s_resgid))) {
59682+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
59683 return 0;
59684 }
59685 return 1;
59686diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
59687index c6874be..f8a6ae8 100644
59688--- a/fs/ext3/xattr.c
59689+++ b/fs/ext3/xattr.c
59690@@ -330,7 +330,7 @@ static int
59691 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59692 char *buffer, size_t buffer_size)
59693 {
59694- size_t rest = buffer_size;
59695+ size_t rest = buffer_size, total_size = 0;
59696
59697 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
59698 const struct xattr_handler *handler =
59699@@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59700 buffer += size;
59701 }
59702 rest -= size;
59703+ total_size += size;
59704 }
59705 }
59706- return buffer_size - rest;
59707+ return total_size;
59708 }
59709
59710 static int
59711diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
59712index 6ea7b14..8fa16d9 100644
59713--- a/fs/ext4/balloc.c
59714+++ b/fs/ext4/balloc.c
59715@@ -534,8 +534,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
59716 /* Hm, nope. Are (enough) root reserved clusters available? */
59717 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
59718 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
59719- capable(CAP_SYS_RESOURCE) ||
59720- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
59721+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
59722+ capable_nolog(CAP_SYS_RESOURCE)) {
59723
59724 if (free_clusters >= (nclusters + dirty_clusters +
59725 resv_clusters))
59726diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
59727index 3a603a8..9b868ba 100644
59728--- a/fs/ext4/ext4.h
59729+++ b/fs/ext4/ext4.h
59730@@ -1269,19 +1269,19 @@ struct ext4_sb_info {
59731 unsigned long s_mb_last_start;
59732
59733 /* stats for buddy allocator */
59734- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
59735- atomic_t s_bal_success; /* we found long enough chunks */
59736- atomic_t s_bal_allocated; /* in blocks */
59737- atomic_t s_bal_ex_scanned; /* total extents scanned */
59738- atomic_t s_bal_goals; /* goal hits */
59739- atomic_t s_bal_breaks; /* too long searches */
59740- atomic_t s_bal_2orders; /* 2^order hits */
59741+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
59742+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
59743+ atomic_unchecked_t s_bal_allocated; /* in blocks */
59744+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
59745+ atomic_unchecked_t s_bal_goals; /* goal hits */
59746+ atomic_unchecked_t s_bal_breaks; /* too long searches */
59747+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
59748 spinlock_t s_bal_lock;
59749 unsigned long s_mb_buddies_generated;
59750 unsigned long long s_mb_generation_time;
59751- atomic_t s_mb_lost_chunks;
59752- atomic_t s_mb_preallocated;
59753- atomic_t s_mb_discarded;
59754+ atomic_unchecked_t s_mb_lost_chunks;
59755+ atomic_unchecked_t s_mb_preallocated;
59756+ atomic_unchecked_t s_mb_discarded;
59757 atomic_t s_lock_busy;
59758
59759 /* locality groups */
59760diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
59761index 04a5c75..09894fa 100644
59762--- a/fs/ext4/mballoc.c
59763+++ b/fs/ext4/mballoc.c
59764@@ -1880,7 +1880,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
59765 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
59766
59767 if (EXT4_SB(sb)->s_mb_stats)
59768- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
59769+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
59770
59771 break;
59772 }
59773@@ -2189,7 +2189,7 @@ repeat:
59774 ac->ac_status = AC_STATUS_CONTINUE;
59775 ac->ac_flags |= EXT4_MB_HINT_FIRST;
59776 cr = 3;
59777- atomic_inc(&sbi->s_mb_lost_chunks);
59778+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
59779 goto repeat;
59780 }
59781 }
59782@@ -2697,25 +2697,25 @@ int ext4_mb_release(struct super_block *sb)
59783 if (sbi->s_mb_stats) {
59784 ext4_msg(sb, KERN_INFO,
59785 "mballoc: %u blocks %u reqs (%u success)",
59786- atomic_read(&sbi->s_bal_allocated),
59787- atomic_read(&sbi->s_bal_reqs),
59788- atomic_read(&sbi->s_bal_success));
59789+ atomic_read_unchecked(&sbi->s_bal_allocated),
59790+ atomic_read_unchecked(&sbi->s_bal_reqs),
59791+ atomic_read_unchecked(&sbi->s_bal_success));
59792 ext4_msg(sb, KERN_INFO,
59793 "mballoc: %u extents scanned, %u goal hits, "
59794 "%u 2^N hits, %u breaks, %u lost",
59795- atomic_read(&sbi->s_bal_ex_scanned),
59796- atomic_read(&sbi->s_bal_goals),
59797- atomic_read(&sbi->s_bal_2orders),
59798- atomic_read(&sbi->s_bal_breaks),
59799- atomic_read(&sbi->s_mb_lost_chunks));
59800+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
59801+ atomic_read_unchecked(&sbi->s_bal_goals),
59802+ atomic_read_unchecked(&sbi->s_bal_2orders),
59803+ atomic_read_unchecked(&sbi->s_bal_breaks),
59804+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
59805 ext4_msg(sb, KERN_INFO,
59806 "mballoc: %lu generated and it took %Lu",
59807 sbi->s_mb_buddies_generated,
59808 sbi->s_mb_generation_time);
59809 ext4_msg(sb, KERN_INFO,
59810 "mballoc: %u preallocated, %u discarded",
59811- atomic_read(&sbi->s_mb_preallocated),
59812- atomic_read(&sbi->s_mb_discarded));
59813+ atomic_read_unchecked(&sbi->s_mb_preallocated),
59814+ atomic_read_unchecked(&sbi->s_mb_discarded));
59815 }
59816
59817 free_percpu(sbi->s_locality_groups);
59818@@ -3169,16 +3169,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
59819 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
59820
59821 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
59822- atomic_inc(&sbi->s_bal_reqs);
59823- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59824+ atomic_inc_unchecked(&sbi->s_bal_reqs);
59825+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59826 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
59827- atomic_inc(&sbi->s_bal_success);
59828- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
59829+ atomic_inc_unchecked(&sbi->s_bal_success);
59830+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
59831 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
59832 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
59833- atomic_inc(&sbi->s_bal_goals);
59834+ atomic_inc_unchecked(&sbi->s_bal_goals);
59835 if (ac->ac_found > sbi->s_mb_max_to_scan)
59836- atomic_inc(&sbi->s_bal_breaks);
59837+ atomic_inc_unchecked(&sbi->s_bal_breaks);
59838 }
59839
59840 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
59841@@ -3583,7 +3583,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
59842 trace_ext4_mb_new_inode_pa(ac, pa);
59843
59844 ext4_mb_use_inode_pa(ac, pa);
59845- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
59846+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
59847
59848 ei = EXT4_I(ac->ac_inode);
59849 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59850@@ -3643,7 +3643,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
59851 trace_ext4_mb_new_group_pa(ac, pa);
59852
59853 ext4_mb_use_group_pa(ac, pa);
59854- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59855+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59856
59857 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59858 lg = ac->ac_lg;
59859@@ -3732,7 +3732,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
59860 * from the bitmap and continue.
59861 */
59862 }
59863- atomic_add(free, &sbi->s_mb_discarded);
59864+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
59865
59866 return err;
59867 }
59868@@ -3750,7 +3750,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
59869 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
59870 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
59871 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
59872- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59873+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59874 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
59875
59876 return 0;
59877diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
59878index 04434ad..6404663 100644
59879--- a/fs/ext4/mmp.c
59880+++ b/fs/ext4/mmp.c
59881@@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
59882 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
59883 const char *function, unsigned int line, const char *msg)
59884 {
59885- __ext4_warning(sb, function, line, msg);
59886+ __ext4_warning(sb, function, line, "%s", msg);
59887 __ext4_warning(sb, function, line,
59888 "MMP failure info: last update time: %llu, last update "
59889 "node: %s, last update device: %s\n",
59890diff --git a/fs/ext4/super.c b/fs/ext4/super.c
59891index 710fed2..a82e4e8 100644
59892--- a/fs/ext4/super.c
59893+++ b/fs/ext4/super.c
59894@@ -1270,7 +1270,7 @@ static ext4_fsblk_t get_sb_block(void **data)
59895 }
59896
59897 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
59898-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59899+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59900 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
59901
59902 #ifdef CONFIG_QUOTA
59903@@ -2450,7 +2450,7 @@ struct ext4_attr {
59904 int offset;
59905 int deprecated_val;
59906 } u;
59907-};
59908+} __do_const;
59909
59910 static int parse_strtoull(const char *buf,
59911 unsigned long long max, unsigned long long *value)
59912diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
59913index 55e611c..cfad16d 100644
59914--- a/fs/ext4/xattr.c
59915+++ b/fs/ext4/xattr.c
59916@@ -381,7 +381,7 @@ static int
59917 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59918 char *buffer, size_t buffer_size)
59919 {
59920- size_t rest = buffer_size;
59921+ size_t rest = buffer_size, total_size = 0;
59922
59923 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
59924 const struct xattr_handler *handler =
59925@@ -398,9 +398,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59926 buffer += size;
59927 }
59928 rest -= size;
59929+ total_size += size;
59930 }
59931 }
59932- return buffer_size - rest;
59933+ return total_size;
59934 }
59935
59936 static int
59937diff --git a/fs/fcntl.c b/fs/fcntl.c
59938index ef68665..5deacdc 100644
59939--- a/fs/fcntl.c
59940+++ b/fs/fcntl.c
59941@@ -106,6 +106,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
59942 if (err)
59943 return err;
59944
59945+ if (gr_handle_chroot_fowner(pid, type))
59946+ return -ENOENT;
59947+ if (gr_check_protected_task_fowner(pid, type))
59948+ return -EACCES;
59949+
59950 f_modown(filp, pid, type, force);
59951 return 0;
59952 }
59953diff --git a/fs/fhandle.c b/fs/fhandle.c
59954index 999ff5c..41f4109 100644
59955--- a/fs/fhandle.c
59956+++ b/fs/fhandle.c
59957@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
59958 } else
59959 retval = 0;
59960 /* copy the mount id */
59961- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
59962- sizeof(*mnt_id)) ||
59963+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
59964 copy_to_user(ufh, handle,
59965 sizeof(struct file_handle) + handle_bytes))
59966 retval = -EFAULT;
59967diff --git a/fs/file.c b/fs/file.c
59968index eb56a13..ccee850 100644
59969--- a/fs/file.c
59970+++ b/fs/file.c
59971@@ -16,6 +16,7 @@
59972 #include <linux/slab.h>
59973 #include <linux/vmalloc.h>
59974 #include <linux/file.h>
59975+#include <linux/security.h>
59976 #include <linux/fdtable.h>
59977 #include <linux/bitops.h>
59978 #include <linux/interrupt.h>
59979@@ -141,7 +142,7 @@ out:
59980 * Return <0 error code on error; 1 on successful completion.
59981 * The files->file_lock should be held on entry, and will be held on exit.
59982 */
59983-static int expand_fdtable(struct files_struct *files, int nr)
59984+static int expand_fdtable(struct files_struct *files, unsigned int nr)
59985 __releases(files->file_lock)
59986 __acquires(files->file_lock)
59987 {
59988@@ -186,7 +187,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
59989 * expanded and execution may have blocked.
59990 * The files->file_lock should be held on entry, and will be held on exit.
59991 */
59992-static int expand_files(struct files_struct *files, int nr)
59993+static int expand_files(struct files_struct *files, unsigned int nr)
59994 {
59995 struct fdtable *fdt;
59996
59997@@ -807,6 +808,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
59998 if (!file)
59999 return __close_fd(files, fd);
60000
60001+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
60002 if (fd >= rlimit(RLIMIT_NOFILE))
60003 return -EBADF;
60004
60005@@ -833,6 +835,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
60006 if (unlikely(oldfd == newfd))
60007 return -EINVAL;
60008
60009+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
60010 if (newfd >= rlimit(RLIMIT_NOFILE))
60011 return -EBADF;
60012
60013@@ -888,6 +891,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
60014 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
60015 {
60016 int err;
60017+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
60018 if (from >= rlimit(RLIMIT_NOFILE))
60019 return -EINVAL;
60020 err = alloc_fd(from, flags);
60021diff --git a/fs/filesystems.c b/fs/filesystems.c
60022index 92567d9..fcd8cbf 100644
60023--- a/fs/filesystems.c
60024+++ b/fs/filesystems.c
60025@@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
60026 int len = dot ? dot - name : strlen(name);
60027
60028 fs = __get_fs_type(name, len);
60029+#ifdef CONFIG_GRKERNSEC_MODHARDEN
60030+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
60031+#else
60032 if (!fs && (request_module("fs-%.*s", len, name) == 0))
60033+#endif
60034 fs = __get_fs_type(name, len);
60035
60036 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
60037diff --git a/fs/fs_struct.c b/fs/fs_struct.c
60038index 7dca743..543d620 100644
60039--- a/fs/fs_struct.c
60040+++ b/fs/fs_struct.c
60041@@ -4,6 +4,7 @@
60042 #include <linux/path.h>
60043 #include <linux/slab.h>
60044 #include <linux/fs_struct.h>
60045+#include <linux/grsecurity.h>
60046 #include "internal.h"
60047
60048 /*
60049@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
60050 write_seqcount_begin(&fs->seq);
60051 old_root = fs->root;
60052 fs->root = *path;
60053+ gr_set_chroot_entries(current, path);
60054 write_seqcount_end(&fs->seq);
60055 spin_unlock(&fs->lock);
60056 if (old_root.dentry)
60057@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
60058 int hits = 0;
60059 spin_lock(&fs->lock);
60060 write_seqcount_begin(&fs->seq);
60061+ /* this root replacement is only done by pivot_root,
60062+ leave grsec's chroot tagging alone for this task
60063+ so that a pivoted root isn't treated as a chroot
60064+ */
60065 hits += replace_path(&fs->root, old_root, new_root);
60066 hits += replace_path(&fs->pwd, old_root, new_root);
60067 write_seqcount_end(&fs->seq);
60068@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
60069 task_lock(tsk);
60070 spin_lock(&fs->lock);
60071 tsk->fs = NULL;
60072- kill = !--fs->users;
60073+ gr_clear_chroot_entries(tsk);
60074+ kill = !atomic_dec_return(&fs->users);
60075 spin_unlock(&fs->lock);
60076 task_unlock(tsk);
60077 if (kill)
60078@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
60079 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
60080 /* We don't need to lock fs - think why ;-) */
60081 if (fs) {
60082- fs->users = 1;
60083+ atomic_set(&fs->users, 1);
60084 fs->in_exec = 0;
60085 spin_lock_init(&fs->lock);
60086 seqcount_init(&fs->seq);
60087@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
60088 spin_lock(&old->lock);
60089 fs->root = old->root;
60090 path_get(&fs->root);
60091+ /* instead of calling gr_set_chroot_entries here,
60092+ we call it from every caller of this function
60093+ */
60094 fs->pwd = old->pwd;
60095 path_get(&fs->pwd);
60096 spin_unlock(&old->lock);
60097@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
60098
60099 task_lock(current);
60100 spin_lock(&fs->lock);
60101- kill = !--fs->users;
60102+ kill = !atomic_dec_return(&fs->users);
60103 current->fs = new_fs;
60104+ gr_set_chroot_entries(current, &new_fs->root);
60105 spin_unlock(&fs->lock);
60106 task_unlock(current);
60107
60108@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
60109
60110 int current_umask(void)
60111 {
60112- return current->fs->umask;
60113+ return current->fs->umask | gr_acl_umask();
60114 }
60115 EXPORT_SYMBOL(current_umask);
60116
60117 /* to be mentioned only in INIT_TASK */
60118 struct fs_struct init_fs = {
60119- .users = 1,
60120+ .users = ATOMIC_INIT(1),
60121 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
60122 .seq = SEQCNT_ZERO(init_fs.seq),
60123 .umask = 0022,
60124diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
60125index 29d7feb..303644d 100644
60126--- a/fs/fscache/cookie.c
60127+++ b/fs/fscache/cookie.c
60128@@ -19,7 +19,7 @@
60129
60130 struct kmem_cache *fscache_cookie_jar;
60131
60132-static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
60133+static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
60134
60135 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
60136 static int fscache_alloc_object(struct fscache_cache *cache,
60137@@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
60138 parent ? (char *) parent->def->name : "<no-parent>",
60139 def->name, netfs_data, enable);
60140
60141- fscache_stat(&fscache_n_acquires);
60142+ fscache_stat_unchecked(&fscache_n_acquires);
60143
60144 /* if there's no parent cookie, then we don't create one here either */
60145 if (!parent) {
60146- fscache_stat(&fscache_n_acquires_null);
60147+ fscache_stat_unchecked(&fscache_n_acquires_null);
60148 _leave(" [no parent]");
60149 return NULL;
60150 }
60151@@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
60152 /* allocate and initialise a cookie */
60153 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
60154 if (!cookie) {
60155- fscache_stat(&fscache_n_acquires_oom);
60156+ fscache_stat_unchecked(&fscache_n_acquires_oom);
60157 _leave(" [ENOMEM]");
60158 return NULL;
60159 }
60160@@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
60161
60162 switch (cookie->def->type) {
60163 case FSCACHE_COOKIE_TYPE_INDEX:
60164- fscache_stat(&fscache_n_cookie_index);
60165+ fscache_stat_unchecked(&fscache_n_cookie_index);
60166 break;
60167 case FSCACHE_COOKIE_TYPE_DATAFILE:
60168- fscache_stat(&fscache_n_cookie_data);
60169+ fscache_stat_unchecked(&fscache_n_cookie_data);
60170 break;
60171 default:
60172- fscache_stat(&fscache_n_cookie_special);
60173+ fscache_stat_unchecked(&fscache_n_cookie_special);
60174 break;
60175 }
60176
60177@@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
60178 } else {
60179 atomic_dec(&parent->n_children);
60180 __fscache_cookie_put(cookie);
60181- fscache_stat(&fscache_n_acquires_nobufs);
60182+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
60183 _leave(" = NULL");
60184 return NULL;
60185 }
60186@@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
60187 }
60188 }
60189
60190- fscache_stat(&fscache_n_acquires_ok);
60191+ fscache_stat_unchecked(&fscache_n_acquires_ok);
60192 _leave(" = %p", cookie);
60193 return cookie;
60194 }
60195@@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
60196 cache = fscache_select_cache_for_object(cookie->parent);
60197 if (!cache) {
60198 up_read(&fscache_addremove_sem);
60199- fscache_stat(&fscache_n_acquires_no_cache);
60200+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
60201 _leave(" = -ENOMEDIUM [no cache]");
60202 return -ENOMEDIUM;
60203 }
60204@@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
60205 object = cache->ops->alloc_object(cache, cookie);
60206 fscache_stat_d(&fscache_n_cop_alloc_object);
60207 if (IS_ERR(object)) {
60208- fscache_stat(&fscache_n_object_no_alloc);
60209+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
60210 ret = PTR_ERR(object);
60211 goto error;
60212 }
60213
60214- fscache_stat(&fscache_n_object_alloc);
60215+ fscache_stat_unchecked(&fscache_n_object_alloc);
60216
60217- object->debug_id = atomic_inc_return(&fscache_object_debug_id);
60218+ object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
60219
60220 _debug("ALLOC OBJ%x: %s {%lx}",
60221 object->debug_id, cookie->def->name, object->events);
60222@@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
60223
60224 _enter("{%s}", cookie->def->name);
60225
60226- fscache_stat(&fscache_n_invalidates);
60227+ fscache_stat_unchecked(&fscache_n_invalidates);
60228
60229 /* Only permit invalidation of data files. Invalidating an index will
60230 * require the caller to release all its attachments to the tree rooted
60231@@ -477,10 +477,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
60232 {
60233 struct fscache_object *object;
60234
60235- fscache_stat(&fscache_n_updates);
60236+ fscache_stat_unchecked(&fscache_n_updates);
60237
60238 if (!cookie) {
60239- fscache_stat(&fscache_n_updates_null);
60240+ fscache_stat_unchecked(&fscache_n_updates_null);
60241 _leave(" [no cookie]");
60242 return;
60243 }
60244@@ -581,12 +581,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
60245 */
60246 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
60247 {
60248- fscache_stat(&fscache_n_relinquishes);
60249+ fscache_stat_unchecked(&fscache_n_relinquishes);
60250 if (retire)
60251- fscache_stat(&fscache_n_relinquishes_retire);
60252+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
60253
60254 if (!cookie) {
60255- fscache_stat(&fscache_n_relinquishes_null);
60256+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
60257 _leave(" [no cookie]");
60258 return;
60259 }
60260@@ -687,7 +687,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
60261 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
60262 goto inconsistent;
60263
60264- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
60265+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60266
60267 __fscache_use_cookie(cookie);
60268 if (fscache_submit_op(object, op) < 0)
60269diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
60270index 4226f66..0fb3f45 100644
60271--- a/fs/fscache/internal.h
60272+++ b/fs/fscache/internal.h
60273@@ -133,8 +133,8 @@ extern void fscache_operation_gc(struct work_struct *);
60274 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
60275 extern int fscache_wait_for_operation_activation(struct fscache_object *,
60276 struct fscache_operation *,
60277- atomic_t *,
60278- atomic_t *,
60279+ atomic_unchecked_t *,
60280+ atomic_unchecked_t *,
60281 void (*)(struct fscache_operation *));
60282 extern void fscache_invalidate_writes(struct fscache_cookie *);
60283
60284@@ -153,101 +153,101 @@ extern void fscache_proc_cleanup(void);
60285 * stats.c
60286 */
60287 #ifdef CONFIG_FSCACHE_STATS
60288-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
60289-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
60290+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
60291+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
60292
60293-extern atomic_t fscache_n_op_pend;
60294-extern atomic_t fscache_n_op_run;
60295-extern atomic_t fscache_n_op_enqueue;
60296-extern atomic_t fscache_n_op_deferred_release;
60297-extern atomic_t fscache_n_op_release;
60298-extern atomic_t fscache_n_op_gc;
60299-extern atomic_t fscache_n_op_cancelled;
60300-extern atomic_t fscache_n_op_rejected;
60301+extern atomic_unchecked_t fscache_n_op_pend;
60302+extern atomic_unchecked_t fscache_n_op_run;
60303+extern atomic_unchecked_t fscache_n_op_enqueue;
60304+extern atomic_unchecked_t fscache_n_op_deferred_release;
60305+extern atomic_unchecked_t fscache_n_op_release;
60306+extern atomic_unchecked_t fscache_n_op_gc;
60307+extern atomic_unchecked_t fscache_n_op_cancelled;
60308+extern atomic_unchecked_t fscache_n_op_rejected;
60309
60310-extern atomic_t fscache_n_attr_changed;
60311-extern atomic_t fscache_n_attr_changed_ok;
60312-extern atomic_t fscache_n_attr_changed_nobufs;
60313-extern atomic_t fscache_n_attr_changed_nomem;
60314-extern atomic_t fscache_n_attr_changed_calls;
60315+extern atomic_unchecked_t fscache_n_attr_changed;
60316+extern atomic_unchecked_t fscache_n_attr_changed_ok;
60317+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
60318+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
60319+extern atomic_unchecked_t fscache_n_attr_changed_calls;
60320
60321-extern atomic_t fscache_n_allocs;
60322-extern atomic_t fscache_n_allocs_ok;
60323-extern atomic_t fscache_n_allocs_wait;
60324-extern atomic_t fscache_n_allocs_nobufs;
60325-extern atomic_t fscache_n_allocs_intr;
60326-extern atomic_t fscache_n_allocs_object_dead;
60327-extern atomic_t fscache_n_alloc_ops;
60328-extern atomic_t fscache_n_alloc_op_waits;
60329+extern atomic_unchecked_t fscache_n_allocs;
60330+extern atomic_unchecked_t fscache_n_allocs_ok;
60331+extern atomic_unchecked_t fscache_n_allocs_wait;
60332+extern atomic_unchecked_t fscache_n_allocs_nobufs;
60333+extern atomic_unchecked_t fscache_n_allocs_intr;
60334+extern atomic_unchecked_t fscache_n_allocs_object_dead;
60335+extern atomic_unchecked_t fscache_n_alloc_ops;
60336+extern atomic_unchecked_t fscache_n_alloc_op_waits;
60337
60338-extern atomic_t fscache_n_retrievals;
60339-extern atomic_t fscache_n_retrievals_ok;
60340-extern atomic_t fscache_n_retrievals_wait;
60341-extern atomic_t fscache_n_retrievals_nodata;
60342-extern atomic_t fscache_n_retrievals_nobufs;
60343-extern atomic_t fscache_n_retrievals_intr;
60344-extern atomic_t fscache_n_retrievals_nomem;
60345-extern atomic_t fscache_n_retrievals_object_dead;
60346-extern atomic_t fscache_n_retrieval_ops;
60347-extern atomic_t fscache_n_retrieval_op_waits;
60348+extern atomic_unchecked_t fscache_n_retrievals;
60349+extern atomic_unchecked_t fscache_n_retrievals_ok;
60350+extern atomic_unchecked_t fscache_n_retrievals_wait;
60351+extern atomic_unchecked_t fscache_n_retrievals_nodata;
60352+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
60353+extern atomic_unchecked_t fscache_n_retrievals_intr;
60354+extern atomic_unchecked_t fscache_n_retrievals_nomem;
60355+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
60356+extern atomic_unchecked_t fscache_n_retrieval_ops;
60357+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
60358
60359-extern atomic_t fscache_n_stores;
60360-extern atomic_t fscache_n_stores_ok;
60361-extern atomic_t fscache_n_stores_again;
60362-extern atomic_t fscache_n_stores_nobufs;
60363-extern atomic_t fscache_n_stores_oom;
60364-extern atomic_t fscache_n_store_ops;
60365-extern atomic_t fscache_n_store_calls;
60366-extern atomic_t fscache_n_store_pages;
60367-extern atomic_t fscache_n_store_radix_deletes;
60368-extern atomic_t fscache_n_store_pages_over_limit;
60369+extern atomic_unchecked_t fscache_n_stores;
60370+extern atomic_unchecked_t fscache_n_stores_ok;
60371+extern atomic_unchecked_t fscache_n_stores_again;
60372+extern atomic_unchecked_t fscache_n_stores_nobufs;
60373+extern atomic_unchecked_t fscache_n_stores_oom;
60374+extern atomic_unchecked_t fscache_n_store_ops;
60375+extern atomic_unchecked_t fscache_n_store_calls;
60376+extern atomic_unchecked_t fscache_n_store_pages;
60377+extern atomic_unchecked_t fscache_n_store_radix_deletes;
60378+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
60379
60380-extern atomic_t fscache_n_store_vmscan_not_storing;
60381-extern atomic_t fscache_n_store_vmscan_gone;
60382-extern atomic_t fscache_n_store_vmscan_busy;
60383-extern atomic_t fscache_n_store_vmscan_cancelled;
60384-extern atomic_t fscache_n_store_vmscan_wait;
60385+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
60386+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
60387+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
60388+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
60389+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
60390
60391-extern atomic_t fscache_n_marks;
60392-extern atomic_t fscache_n_uncaches;
60393+extern atomic_unchecked_t fscache_n_marks;
60394+extern atomic_unchecked_t fscache_n_uncaches;
60395
60396-extern atomic_t fscache_n_acquires;
60397-extern atomic_t fscache_n_acquires_null;
60398-extern atomic_t fscache_n_acquires_no_cache;
60399-extern atomic_t fscache_n_acquires_ok;
60400-extern atomic_t fscache_n_acquires_nobufs;
60401-extern atomic_t fscache_n_acquires_oom;
60402+extern atomic_unchecked_t fscache_n_acquires;
60403+extern atomic_unchecked_t fscache_n_acquires_null;
60404+extern atomic_unchecked_t fscache_n_acquires_no_cache;
60405+extern atomic_unchecked_t fscache_n_acquires_ok;
60406+extern atomic_unchecked_t fscache_n_acquires_nobufs;
60407+extern atomic_unchecked_t fscache_n_acquires_oom;
60408
60409-extern atomic_t fscache_n_invalidates;
60410-extern atomic_t fscache_n_invalidates_run;
60411+extern atomic_unchecked_t fscache_n_invalidates;
60412+extern atomic_unchecked_t fscache_n_invalidates_run;
60413
60414-extern atomic_t fscache_n_updates;
60415-extern atomic_t fscache_n_updates_null;
60416-extern atomic_t fscache_n_updates_run;
60417+extern atomic_unchecked_t fscache_n_updates;
60418+extern atomic_unchecked_t fscache_n_updates_null;
60419+extern atomic_unchecked_t fscache_n_updates_run;
60420
60421-extern atomic_t fscache_n_relinquishes;
60422-extern atomic_t fscache_n_relinquishes_null;
60423-extern atomic_t fscache_n_relinquishes_waitcrt;
60424-extern atomic_t fscache_n_relinquishes_retire;
60425+extern atomic_unchecked_t fscache_n_relinquishes;
60426+extern atomic_unchecked_t fscache_n_relinquishes_null;
60427+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
60428+extern atomic_unchecked_t fscache_n_relinquishes_retire;
60429
60430-extern atomic_t fscache_n_cookie_index;
60431-extern atomic_t fscache_n_cookie_data;
60432-extern atomic_t fscache_n_cookie_special;
60433+extern atomic_unchecked_t fscache_n_cookie_index;
60434+extern atomic_unchecked_t fscache_n_cookie_data;
60435+extern atomic_unchecked_t fscache_n_cookie_special;
60436
60437-extern atomic_t fscache_n_object_alloc;
60438-extern atomic_t fscache_n_object_no_alloc;
60439-extern atomic_t fscache_n_object_lookups;
60440-extern atomic_t fscache_n_object_lookups_negative;
60441-extern atomic_t fscache_n_object_lookups_positive;
60442-extern atomic_t fscache_n_object_lookups_timed_out;
60443-extern atomic_t fscache_n_object_created;
60444-extern atomic_t fscache_n_object_avail;
60445-extern atomic_t fscache_n_object_dead;
60446+extern atomic_unchecked_t fscache_n_object_alloc;
60447+extern atomic_unchecked_t fscache_n_object_no_alloc;
60448+extern atomic_unchecked_t fscache_n_object_lookups;
60449+extern atomic_unchecked_t fscache_n_object_lookups_negative;
60450+extern atomic_unchecked_t fscache_n_object_lookups_positive;
60451+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
60452+extern atomic_unchecked_t fscache_n_object_created;
60453+extern atomic_unchecked_t fscache_n_object_avail;
60454+extern atomic_unchecked_t fscache_n_object_dead;
60455
60456-extern atomic_t fscache_n_checkaux_none;
60457-extern atomic_t fscache_n_checkaux_okay;
60458-extern atomic_t fscache_n_checkaux_update;
60459-extern atomic_t fscache_n_checkaux_obsolete;
60460+extern atomic_unchecked_t fscache_n_checkaux_none;
60461+extern atomic_unchecked_t fscache_n_checkaux_okay;
60462+extern atomic_unchecked_t fscache_n_checkaux_update;
60463+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
60464
60465 extern atomic_t fscache_n_cop_alloc_object;
60466 extern atomic_t fscache_n_cop_lookup_object;
60467@@ -272,6 +272,11 @@ static inline void fscache_stat(atomic_t *stat)
60468 atomic_inc(stat);
60469 }
60470
60471+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
60472+{
60473+ atomic_inc_unchecked(stat);
60474+}
60475+
60476 static inline void fscache_stat_d(atomic_t *stat)
60477 {
60478 atomic_dec(stat);
60479@@ -284,6 +289,7 @@ extern const struct file_operations fscache_stats_fops;
60480
60481 #define __fscache_stat(stat) (NULL)
60482 #define fscache_stat(stat) do {} while (0)
60483+#define fscache_stat_unchecked(stat) do {} while (0)
60484 #define fscache_stat_d(stat) do {} while (0)
60485 #endif
60486
60487diff --git a/fs/fscache/object.c b/fs/fscache/object.c
60488index d3b4539..ed0c659 100644
60489--- a/fs/fscache/object.c
60490+++ b/fs/fscache/object.c
60491@@ -454,7 +454,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
60492 _debug("LOOKUP \"%s\" in \"%s\"",
60493 cookie->def->name, object->cache->tag->name);
60494
60495- fscache_stat(&fscache_n_object_lookups);
60496+ fscache_stat_unchecked(&fscache_n_object_lookups);
60497 fscache_stat(&fscache_n_cop_lookup_object);
60498 ret = object->cache->ops->lookup_object(object);
60499 fscache_stat_d(&fscache_n_cop_lookup_object);
60500@@ -464,7 +464,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
60501 if (ret == -ETIMEDOUT) {
60502 /* probably stuck behind another object, so move this one to
60503 * the back of the queue */
60504- fscache_stat(&fscache_n_object_lookups_timed_out);
60505+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
60506 _leave(" [timeout]");
60507 return NO_TRANSIT;
60508 }
60509@@ -492,7 +492,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
60510 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
60511
60512 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
60513- fscache_stat(&fscache_n_object_lookups_negative);
60514+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
60515
60516 /* Allow write requests to begin stacking up and read requests to begin
60517 * returning ENODATA.
60518@@ -527,7 +527,7 @@ void fscache_obtained_object(struct fscache_object *object)
60519 /* if we were still looking up, then we must have a positive lookup
60520 * result, in which case there may be data available */
60521 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
60522- fscache_stat(&fscache_n_object_lookups_positive);
60523+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
60524
60525 /* We do (presumably) have data */
60526 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
60527@@ -539,7 +539,7 @@ void fscache_obtained_object(struct fscache_object *object)
60528 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
60529 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
60530 } else {
60531- fscache_stat(&fscache_n_object_created);
60532+ fscache_stat_unchecked(&fscache_n_object_created);
60533 }
60534
60535 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
60536@@ -575,7 +575,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
60537 fscache_stat_d(&fscache_n_cop_lookup_complete);
60538
60539 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
60540- fscache_stat(&fscache_n_object_avail);
60541+ fscache_stat_unchecked(&fscache_n_object_avail);
60542
60543 _leave("");
60544 return transit_to(JUMPSTART_DEPS);
60545@@ -722,7 +722,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
60546
60547 /* this just shifts the object release to the work processor */
60548 fscache_put_object(object);
60549- fscache_stat(&fscache_n_object_dead);
60550+ fscache_stat_unchecked(&fscache_n_object_dead);
60551
60552 _leave("");
60553 return transit_to(OBJECT_DEAD);
60554@@ -887,7 +887,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
60555 enum fscache_checkaux result;
60556
60557 if (!object->cookie->def->check_aux) {
60558- fscache_stat(&fscache_n_checkaux_none);
60559+ fscache_stat_unchecked(&fscache_n_checkaux_none);
60560 return FSCACHE_CHECKAUX_OKAY;
60561 }
60562
60563@@ -896,17 +896,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
60564 switch (result) {
60565 /* entry okay as is */
60566 case FSCACHE_CHECKAUX_OKAY:
60567- fscache_stat(&fscache_n_checkaux_okay);
60568+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
60569 break;
60570
60571 /* entry requires update */
60572 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
60573- fscache_stat(&fscache_n_checkaux_update);
60574+ fscache_stat_unchecked(&fscache_n_checkaux_update);
60575 break;
60576
60577 /* entry requires deletion */
60578 case FSCACHE_CHECKAUX_OBSOLETE:
60579- fscache_stat(&fscache_n_checkaux_obsolete);
60580+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
60581 break;
60582
60583 default:
60584@@ -992,7 +992,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
60585 {
60586 const struct fscache_state *s;
60587
60588- fscache_stat(&fscache_n_invalidates_run);
60589+ fscache_stat_unchecked(&fscache_n_invalidates_run);
60590 fscache_stat(&fscache_n_cop_invalidate_object);
60591 s = _fscache_invalidate_object(object, event);
60592 fscache_stat_d(&fscache_n_cop_invalidate_object);
60593@@ -1007,7 +1007,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
60594 {
60595 _enter("{OBJ%x},%d", object->debug_id, event);
60596
60597- fscache_stat(&fscache_n_updates_run);
60598+ fscache_stat_unchecked(&fscache_n_updates_run);
60599 fscache_stat(&fscache_n_cop_update_object);
60600 object->cache->ops->update_object(object);
60601 fscache_stat_d(&fscache_n_cop_update_object);
60602diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
60603index 318071a..379938b 100644
60604--- a/fs/fscache/operation.c
60605+++ b/fs/fscache/operation.c
60606@@ -17,7 +17,7 @@
60607 #include <linux/slab.h>
60608 #include "internal.h"
60609
60610-atomic_t fscache_op_debug_id;
60611+atomic_unchecked_t fscache_op_debug_id;
60612 EXPORT_SYMBOL(fscache_op_debug_id);
60613
60614 /**
60615@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
60616 ASSERTCMP(atomic_read(&op->usage), >, 0);
60617 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
60618
60619- fscache_stat(&fscache_n_op_enqueue);
60620+ fscache_stat_unchecked(&fscache_n_op_enqueue);
60621 switch (op->flags & FSCACHE_OP_TYPE) {
60622 case FSCACHE_OP_ASYNC:
60623 _debug("queue async");
60624@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
60625 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
60626 if (op->processor)
60627 fscache_enqueue_operation(op);
60628- fscache_stat(&fscache_n_op_run);
60629+ fscache_stat_unchecked(&fscache_n_op_run);
60630 }
60631
60632 /*
60633@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
60634 if (object->n_in_progress > 0) {
60635 atomic_inc(&op->usage);
60636 list_add_tail(&op->pend_link, &object->pending_ops);
60637- fscache_stat(&fscache_n_op_pend);
60638+ fscache_stat_unchecked(&fscache_n_op_pend);
60639 } else if (!list_empty(&object->pending_ops)) {
60640 atomic_inc(&op->usage);
60641 list_add_tail(&op->pend_link, &object->pending_ops);
60642- fscache_stat(&fscache_n_op_pend);
60643+ fscache_stat_unchecked(&fscache_n_op_pend);
60644 fscache_start_operations(object);
60645 } else {
60646 ASSERTCMP(object->n_in_progress, ==, 0);
60647@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
60648 object->n_exclusive++; /* reads and writes must wait */
60649 atomic_inc(&op->usage);
60650 list_add_tail(&op->pend_link, &object->pending_ops);
60651- fscache_stat(&fscache_n_op_pend);
60652+ fscache_stat_unchecked(&fscache_n_op_pend);
60653 ret = 0;
60654 } else {
60655 /* If we're in any other state, there must have been an I/O
60656@@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
60657 if (object->n_exclusive > 0) {
60658 atomic_inc(&op->usage);
60659 list_add_tail(&op->pend_link, &object->pending_ops);
60660- fscache_stat(&fscache_n_op_pend);
60661+ fscache_stat_unchecked(&fscache_n_op_pend);
60662 } else if (!list_empty(&object->pending_ops)) {
60663 atomic_inc(&op->usage);
60664 list_add_tail(&op->pend_link, &object->pending_ops);
60665- fscache_stat(&fscache_n_op_pend);
60666+ fscache_stat_unchecked(&fscache_n_op_pend);
60667 fscache_start_operations(object);
60668 } else {
60669 ASSERTCMP(object->n_exclusive, ==, 0);
60670@@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
60671 object->n_ops++;
60672 atomic_inc(&op->usage);
60673 list_add_tail(&op->pend_link, &object->pending_ops);
60674- fscache_stat(&fscache_n_op_pend);
60675+ fscache_stat_unchecked(&fscache_n_op_pend);
60676 ret = 0;
60677 } else if (fscache_object_is_dying(object)) {
60678- fscache_stat(&fscache_n_op_rejected);
60679+ fscache_stat_unchecked(&fscache_n_op_rejected);
60680 op->state = FSCACHE_OP_ST_CANCELLED;
60681 ret = -ENOBUFS;
60682 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
60683@@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
60684 ret = -EBUSY;
60685 if (op->state == FSCACHE_OP_ST_PENDING) {
60686 ASSERT(!list_empty(&op->pend_link));
60687- fscache_stat(&fscache_n_op_cancelled);
60688+ fscache_stat_unchecked(&fscache_n_op_cancelled);
60689 list_del_init(&op->pend_link);
60690 if (do_cancel)
60691 do_cancel(op);
60692@@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
60693 while (!list_empty(&object->pending_ops)) {
60694 op = list_entry(object->pending_ops.next,
60695 struct fscache_operation, pend_link);
60696- fscache_stat(&fscache_n_op_cancelled);
60697+ fscache_stat_unchecked(&fscache_n_op_cancelled);
60698 list_del_init(&op->pend_link);
60699
60700 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
60701@@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
60702 op->state, ==, FSCACHE_OP_ST_CANCELLED);
60703 op->state = FSCACHE_OP_ST_DEAD;
60704
60705- fscache_stat(&fscache_n_op_release);
60706+ fscache_stat_unchecked(&fscache_n_op_release);
60707
60708 if (op->release) {
60709 op->release(op);
60710@@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
60711 * lock, and defer it otherwise */
60712 if (!spin_trylock(&object->lock)) {
60713 _debug("defer put");
60714- fscache_stat(&fscache_n_op_deferred_release);
60715+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
60716
60717 cache = object->cache;
60718 spin_lock(&cache->op_gc_list_lock);
60719@@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
60720
60721 _debug("GC DEFERRED REL OBJ%x OP%x",
60722 object->debug_id, op->debug_id);
60723- fscache_stat(&fscache_n_op_gc);
60724+ fscache_stat_unchecked(&fscache_n_op_gc);
60725
60726 ASSERTCMP(atomic_read(&op->usage), ==, 0);
60727 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
60728diff --git a/fs/fscache/page.c b/fs/fscache/page.c
60729index 7f5c658..6c1e164 100644
60730--- a/fs/fscache/page.c
60731+++ b/fs/fscache/page.c
60732@@ -61,7 +61,7 @@ try_again:
60733 val = radix_tree_lookup(&cookie->stores, page->index);
60734 if (!val) {
60735 rcu_read_unlock();
60736- fscache_stat(&fscache_n_store_vmscan_not_storing);
60737+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
60738 __fscache_uncache_page(cookie, page);
60739 return true;
60740 }
60741@@ -91,11 +91,11 @@ try_again:
60742 spin_unlock(&cookie->stores_lock);
60743
60744 if (xpage) {
60745- fscache_stat(&fscache_n_store_vmscan_cancelled);
60746- fscache_stat(&fscache_n_store_radix_deletes);
60747+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
60748+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60749 ASSERTCMP(xpage, ==, page);
60750 } else {
60751- fscache_stat(&fscache_n_store_vmscan_gone);
60752+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
60753 }
60754
60755 wake_up_bit(&cookie->flags, 0);
60756@@ -110,11 +110,11 @@ page_busy:
60757 * sleeping on memory allocation, so we may need to impose a timeout
60758 * too. */
60759 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
60760- fscache_stat(&fscache_n_store_vmscan_busy);
60761+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
60762 return false;
60763 }
60764
60765- fscache_stat(&fscache_n_store_vmscan_wait);
60766+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
60767 __fscache_wait_on_page_write(cookie, page);
60768 gfp &= ~__GFP_WAIT;
60769 goto try_again;
60770@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
60771 FSCACHE_COOKIE_STORING_TAG);
60772 if (!radix_tree_tag_get(&cookie->stores, page->index,
60773 FSCACHE_COOKIE_PENDING_TAG)) {
60774- fscache_stat(&fscache_n_store_radix_deletes);
60775+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60776 xpage = radix_tree_delete(&cookie->stores, page->index);
60777 }
60778 spin_unlock(&cookie->stores_lock);
60779@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
60780
60781 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
60782
60783- fscache_stat(&fscache_n_attr_changed_calls);
60784+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
60785
60786 if (fscache_object_is_active(object)) {
60787 fscache_stat(&fscache_n_cop_attr_changed);
60788@@ -188,11 +188,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60789
60790 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60791
60792- fscache_stat(&fscache_n_attr_changed);
60793+ fscache_stat_unchecked(&fscache_n_attr_changed);
60794
60795 op = kzalloc(sizeof(*op), GFP_KERNEL);
60796 if (!op) {
60797- fscache_stat(&fscache_n_attr_changed_nomem);
60798+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
60799 _leave(" = -ENOMEM");
60800 return -ENOMEM;
60801 }
60802@@ -214,7 +214,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60803 if (fscache_submit_exclusive_op(object, op) < 0)
60804 goto nobufs;
60805 spin_unlock(&cookie->lock);
60806- fscache_stat(&fscache_n_attr_changed_ok);
60807+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
60808 fscache_put_operation(op);
60809 _leave(" = 0");
60810 return 0;
60811@@ -225,7 +225,7 @@ nobufs:
60812 kfree(op);
60813 if (wake_cookie)
60814 __fscache_wake_unused_cookie(cookie);
60815- fscache_stat(&fscache_n_attr_changed_nobufs);
60816+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
60817 _leave(" = %d", -ENOBUFS);
60818 return -ENOBUFS;
60819 }
60820@@ -264,7 +264,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
60821 /* allocate a retrieval operation and attempt to submit it */
60822 op = kzalloc(sizeof(*op), GFP_NOIO);
60823 if (!op) {
60824- fscache_stat(&fscache_n_retrievals_nomem);
60825+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60826 return NULL;
60827 }
60828
60829@@ -294,13 +294,13 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
60830 return 0;
60831 }
60832
60833- fscache_stat(&fscache_n_retrievals_wait);
60834+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
60835
60836 jif = jiffies;
60837 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
60838 fscache_wait_bit_interruptible,
60839 TASK_INTERRUPTIBLE) != 0) {
60840- fscache_stat(&fscache_n_retrievals_intr);
60841+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
60842 _leave(" = -ERESTARTSYS");
60843 return -ERESTARTSYS;
60844 }
60845@@ -329,8 +329,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
60846 */
60847 int fscache_wait_for_operation_activation(struct fscache_object *object,
60848 struct fscache_operation *op,
60849- atomic_t *stat_op_waits,
60850- atomic_t *stat_object_dead,
60851+ atomic_unchecked_t *stat_op_waits,
60852+ atomic_unchecked_t *stat_object_dead,
60853 void (*do_cancel)(struct fscache_operation *))
60854 {
60855 int ret;
60856@@ -340,7 +340,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60857
60858 _debug(">>> WT");
60859 if (stat_op_waits)
60860- fscache_stat(stat_op_waits);
60861+ fscache_stat_unchecked(stat_op_waits);
60862 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
60863 fscache_wait_bit_interruptible,
60864 TASK_INTERRUPTIBLE) != 0) {
60865@@ -358,7 +358,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60866 check_if_dead:
60867 if (op->state == FSCACHE_OP_ST_CANCELLED) {
60868 if (stat_object_dead)
60869- fscache_stat(stat_object_dead);
60870+ fscache_stat_unchecked(stat_object_dead);
60871 _leave(" = -ENOBUFS [cancelled]");
60872 return -ENOBUFS;
60873 }
60874@@ -366,7 +366,7 @@ check_if_dead:
60875 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
60876 fscache_cancel_op(op, do_cancel);
60877 if (stat_object_dead)
60878- fscache_stat(stat_object_dead);
60879+ fscache_stat_unchecked(stat_object_dead);
60880 return -ENOBUFS;
60881 }
60882 return 0;
60883@@ -394,7 +394,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60884
60885 _enter("%p,%p,,,", cookie, page);
60886
60887- fscache_stat(&fscache_n_retrievals);
60888+ fscache_stat_unchecked(&fscache_n_retrievals);
60889
60890 if (hlist_empty(&cookie->backing_objects))
60891 goto nobufs;
60892@@ -436,7 +436,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60893 goto nobufs_unlock_dec;
60894 spin_unlock(&cookie->lock);
60895
60896- fscache_stat(&fscache_n_retrieval_ops);
60897+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
60898
60899 /* pin the netfs read context in case we need to do the actual netfs
60900 * read because we've encountered a cache read failure */
60901@@ -467,15 +467,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60902
60903 error:
60904 if (ret == -ENOMEM)
60905- fscache_stat(&fscache_n_retrievals_nomem);
60906+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60907 else if (ret == -ERESTARTSYS)
60908- fscache_stat(&fscache_n_retrievals_intr);
60909+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
60910 else if (ret == -ENODATA)
60911- fscache_stat(&fscache_n_retrievals_nodata);
60912+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60913 else if (ret < 0)
60914- fscache_stat(&fscache_n_retrievals_nobufs);
60915+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60916 else
60917- fscache_stat(&fscache_n_retrievals_ok);
60918+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
60919
60920 fscache_put_retrieval(op);
60921 _leave(" = %d", ret);
60922@@ -490,7 +490,7 @@ nobufs_unlock:
60923 __fscache_wake_unused_cookie(cookie);
60924 kfree(op);
60925 nobufs:
60926- fscache_stat(&fscache_n_retrievals_nobufs);
60927+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60928 _leave(" = -ENOBUFS");
60929 return -ENOBUFS;
60930 }
60931@@ -529,7 +529,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60932
60933 _enter("%p,,%d,,,", cookie, *nr_pages);
60934
60935- fscache_stat(&fscache_n_retrievals);
60936+ fscache_stat_unchecked(&fscache_n_retrievals);
60937
60938 if (hlist_empty(&cookie->backing_objects))
60939 goto nobufs;
60940@@ -567,7 +567,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60941 goto nobufs_unlock_dec;
60942 spin_unlock(&cookie->lock);
60943
60944- fscache_stat(&fscache_n_retrieval_ops);
60945+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
60946
60947 /* pin the netfs read context in case we need to do the actual netfs
60948 * read because we've encountered a cache read failure */
60949@@ -598,15 +598,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60950
60951 error:
60952 if (ret == -ENOMEM)
60953- fscache_stat(&fscache_n_retrievals_nomem);
60954+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60955 else if (ret == -ERESTARTSYS)
60956- fscache_stat(&fscache_n_retrievals_intr);
60957+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
60958 else if (ret == -ENODATA)
60959- fscache_stat(&fscache_n_retrievals_nodata);
60960+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60961 else if (ret < 0)
60962- fscache_stat(&fscache_n_retrievals_nobufs);
60963+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60964 else
60965- fscache_stat(&fscache_n_retrievals_ok);
60966+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
60967
60968 fscache_put_retrieval(op);
60969 _leave(" = %d", ret);
60970@@ -621,7 +621,7 @@ nobufs_unlock:
60971 if (wake_cookie)
60972 __fscache_wake_unused_cookie(cookie);
60973 nobufs:
60974- fscache_stat(&fscache_n_retrievals_nobufs);
60975+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60976 _leave(" = -ENOBUFS");
60977 return -ENOBUFS;
60978 }
60979@@ -646,7 +646,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60980
60981 _enter("%p,%p,,,", cookie, page);
60982
60983- fscache_stat(&fscache_n_allocs);
60984+ fscache_stat_unchecked(&fscache_n_allocs);
60985
60986 if (hlist_empty(&cookie->backing_objects))
60987 goto nobufs;
60988@@ -680,7 +680,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60989 goto nobufs_unlock_dec;
60990 spin_unlock(&cookie->lock);
60991
60992- fscache_stat(&fscache_n_alloc_ops);
60993+ fscache_stat_unchecked(&fscache_n_alloc_ops);
60994
60995 ret = fscache_wait_for_operation_activation(
60996 object, &op->op,
60997@@ -697,11 +697,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60998
60999 error:
61000 if (ret == -ERESTARTSYS)
61001- fscache_stat(&fscache_n_allocs_intr);
61002+ fscache_stat_unchecked(&fscache_n_allocs_intr);
61003 else if (ret < 0)
61004- fscache_stat(&fscache_n_allocs_nobufs);
61005+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
61006 else
61007- fscache_stat(&fscache_n_allocs_ok);
61008+ fscache_stat_unchecked(&fscache_n_allocs_ok);
61009
61010 fscache_put_retrieval(op);
61011 _leave(" = %d", ret);
61012@@ -715,7 +715,7 @@ nobufs_unlock:
61013 if (wake_cookie)
61014 __fscache_wake_unused_cookie(cookie);
61015 nobufs:
61016- fscache_stat(&fscache_n_allocs_nobufs);
61017+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
61018 _leave(" = -ENOBUFS");
61019 return -ENOBUFS;
61020 }
61021@@ -791,7 +791,7 @@ static void fscache_write_op(struct fscache_operation *_op)
61022
61023 spin_lock(&cookie->stores_lock);
61024
61025- fscache_stat(&fscache_n_store_calls);
61026+ fscache_stat_unchecked(&fscache_n_store_calls);
61027
61028 /* find a page to store */
61029 page = NULL;
61030@@ -802,7 +802,7 @@ static void fscache_write_op(struct fscache_operation *_op)
61031 page = results[0];
61032 _debug("gang %d [%lx]", n, page->index);
61033 if (page->index > op->store_limit) {
61034- fscache_stat(&fscache_n_store_pages_over_limit);
61035+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
61036 goto superseded;
61037 }
61038
61039@@ -814,7 +814,7 @@ static void fscache_write_op(struct fscache_operation *_op)
61040 spin_unlock(&cookie->stores_lock);
61041 spin_unlock(&object->lock);
61042
61043- fscache_stat(&fscache_n_store_pages);
61044+ fscache_stat_unchecked(&fscache_n_store_pages);
61045 fscache_stat(&fscache_n_cop_write_page);
61046 ret = object->cache->ops->write_page(op, page);
61047 fscache_stat_d(&fscache_n_cop_write_page);
61048@@ -918,7 +918,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
61049 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
61050 ASSERT(PageFsCache(page));
61051
61052- fscache_stat(&fscache_n_stores);
61053+ fscache_stat_unchecked(&fscache_n_stores);
61054
61055 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
61056 _leave(" = -ENOBUFS [invalidating]");
61057@@ -977,7 +977,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
61058 spin_unlock(&cookie->stores_lock);
61059 spin_unlock(&object->lock);
61060
61061- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
61062+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
61063 op->store_limit = object->store_limit;
61064
61065 __fscache_use_cookie(cookie);
61066@@ -986,8 +986,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
61067
61068 spin_unlock(&cookie->lock);
61069 radix_tree_preload_end();
61070- fscache_stat(&fscache_n_store_ops);
61071- fscache_stat(&fscache_n_stores_ok);
61072+ fscache_stat_unchecked(&fscache_n_store_ops);
61073+ fscache_stat_unchecked(&fscache_n_stores_ok);
61074
61075 /* the work queue now carries its own ref on the object */
61076 fscache_put_operation(&op->op);
61077@@ -995,14 +995,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
61078 return 0;
61079
61080 already_queued:
61081- fscache_stat(&fscache_n_stores_again);
61082+ fscache_stat_unchecked(&fscache_n_stores_again);
61083 already_pending:
61084 spin_unlock(&cookie->stores_lock);
61085 spin_unlock(&object->lock);
61086 spin_unlock(&cookie->lock);
61087 radix_tree_preload_end();
61088 kfree(op);
61089- fscache_stat(&fscache_n_stores_ok);
61090+ fscache_stat_unchecked(&fscache_n_stores_ok);
61091 _leave(" = 0");
61092 return 0;
61093
61094@@ -1024,14 +1024,14 @@ nobufs:
61095 kfree(op);
61096 if (wake_cookie)
61097 __fscache_wake_unused_cookie(cookie);
61098- fscache_stat(&fscache_n_stores_nobufs);
61099+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
61100 _leave(" = -ENOBUFS");
61101 return -ENOBUFS;
61102
61103 nomem_free:
61104 kfree(op);
61105 nomem:
61106- fscache_stat(&fscache_n_stores_oom);
61107+ fscache_stat_unchecked(&fscache_n_stores_oom);
61108 _leave(" = -ENOMEM");
61109 return -ENOMEM;
61110 }
61111@@ -1049,7 +1049,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
61112 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
61113 ASSERTCMP(page, !=, NULL);
61114
61115- fscache_stat(&fscache_n_uncaches);
61116+ fscache_stat_unchecked(&fscache_n_uncaches);
61117
61118 /* cache withdrawal may beat us to it */
61119 if (!PageFsCache(page))
61120@@ -1100,7 +1100,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
61121 struct fscache_cookie *cookie = op->op.object->cookie;
61122
61123 #ifdef CONFIG_FSCACHE_STATS
61124- atomic_inc(&fscache_n_marks);
61125+ atomic_inc_unchecked(&fscache_n_marks);
61126 #endif
61127
61128 _debug("- mark %p{%lx}", page, page->index);
61129diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
61130index 40d13c7..ddf52b9 100644
61131--- a/fs/fscache/stats.c
61132+++ b/fs/fscache/stats.c
61133@@ -18,99 +18,99 @@
61134 /*
61135 * operation counters
61136 */
61137-atomic_t fscache_n_op_pend;
61138-atomic_t fscache_n_op_run;
61139-atomic_t fscache_n_op_enqueue;
61140-atomic_t fscache_n_op_requeue;
61141-atomic_t fscache_n_op_deferred_release;
61142-atomic_t fscache_n_op_release;
61143-atomic_t fscache_n_op_gc;
61144-atomic_t fscache_n_op_cancelled;
61145-atomic_t fscache_n_op_rejected;
61146+atomic_unchecked_t fscache_n_op_pend;
61147+atomic_unchecked_t fscache_n_op_run;
61148+atomic_unchecked_t fscache_n_op_enqueue;
61149+atomic_unchecked_t fscache_n_op_requeue;
61150+atomic_unchecked_t fscache_n_op_deferred_release;
61151+atomic_unchecked_t fscache_n_op_release;
61152+atomic_unchecked_t fscache_n_op_gc;
61153+atomic_unchecked_t fscache_n_op_cancelled;
61154+atomic_unchecked_t fscache_n_op_rejected;
61155
61156-atomic_t fscache_n_attr_changed;
61157-atomic_t fscache_n_attr_changed_ok;
61158-atomic_t fscache_n_attr_changed_nobufs;
61159-atomic_t fscache_n_attr_changed_nomem;
61160-atomic_t fscache_n_attr_changed_calls;
61161+atomic_unchecked_t fscache_n_attr_changed;
61162+atomic_unchecked_t fscache_n_attr_changed_ok;
61163+atomic_unchecked_t fscache_n_attr_changed_nobufs;
61164+atomic_unchecked_t fscache_n_attr_changed_nomem;
61165+atomic_unchecked_t fscache_n_attr_changed_calls;
61166
61167-atomic_t fscache_n_allocs;
61168-atomic_t fscache_n_allocs_ok;
61169-atomic_t fscache_n_allocs_wait;
61170-atomic_t fscache_n_allocs_nobufs;
61171-atomic_t fscache_n_allocs_intr;
61172-atomic_t fscache_n_allocs_object_dead;
61173-atomic_t fscache_n_alloc_ops;
61174-atomic_t fscache_n_alloc_op_waits;
61175+atomic_unchecked_t fscache_n_allocs;
61176+atomic_unchecked_t fscache_n_allocs_ok;
61177+atomic_unchecked_t fscache_n_allocs_wait;
61178+atomic_unchecked_t fscache_n_allocs_nobufs;
61179+atomic_unchecked_t fscache_n_allocs_intr;
61180+atomic_unchecked_t fscache_n_allocs_object_dead;
61181+atomic_unchecked_t fscache_n_alloc_ops;
61182+atomic_unchecked_t fscache_n_alloc_op_waits;
61183
61184-atomic_t fscache_n_retrievals;
61185-atomic_t fscache_n_retrievals_ok;
61186-atomic_t fscache_n_retrievals_wait;
61187-atomic_t fscache_n_retrievals_nodata;
61188-atomic_t fscache_n_retrievals_nobufs;
61189-atomic_t fscache_n_retrievals_intr;
61190-atomic_t fscache_n_retrievals_nomem;
61191-atomic_t fscache_n_retrievals_object_dead;
61192-atomic_t fscache_n_retrieval_ops;
61193-atomic_t fscache_n_retrieval_op_waits;
61194+atomic_unchecked_t fscache_n_retrievals;
61195+atomic_unchecked_t fscache_n_retrievals_ok;
61196+atomic_unchecked_t fscache_n_retrievals_wait;
61197+atomic_unchecked_t fscache_n_retrievals_nodata;
61198+atomic_unchecked_t fscache_n_retrievals_nobufs;
61199+atomic_unchecked_t fscache_n_retrievals_intr;
61200+atomic_unchecked_t fscache_n_retrievals_nomem;
61201+atomic_unchecked_t fscache_n_retrievals_object_dead;
61202+atomic_unchecked_t fscache_n_retrieval_ops;
61203+atomic_unchecked_t fscache_n_retrieval_op_waits;
61204
61205-atomic_t fscache_n_stores;
61206-atomic_t fscache_n_stores_ok;
61207-atomic_t fscache_n_stores_again;
61208-atomic_t fscache_n_stores_nobufs;
61209-atomic_t fscache_n_stores_oom;
61210-atomic_t fscache_n_store_ops;
61211-atomic_t fscache_n_store_calls;
61212-atomic_t fscache_n_store_pages;
61213-atomic_t fscache_n_store_radix_deletes;
61214-atomic_t fscache_n_store_pages_over_limit;
61215+atomic_unchecked_t fscache_n_stores;
61216+atomic_unchecked_t fscache_n_stores_ok;
61217+atomic_unchecked_t fscache_n_stores_again;
61218+atomic_unchecked_t fscache_n_stores_nobufs;
61219+atomic_unchecked_t fscache_n_stores_oom;
61220+atomic_unchecked_t fscache_n_store_ops;
61221+atomic_unchecked_t fscache_n_store_calls;
61222+atomic_unchecked_t fscache_n_store_pages;
61223+atomic_unchecked_t fscache_n_store_radix_deletes;
61224+atomic_unchecked_t fscache_n_store_pages_over_limit;
61225
61226-atomic_t fscache_n_store_vmscan_not_storing;
61227-atomic_t fscache_n_store_vmscan_gone;
61228-atomic_t fscache_n_store_vmscan_busy;
61229-atomic_t fscache_n_store_vmscan_cancelled;
61230-atomic_t fscache_n_store_vmscan_wait;
61231+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
61232+atomic_unchecked_t fscache_n_store_vmscan_gone;
61233+atomic_unchecked_t fscache_n_store_vmscan_busy;
61234+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
61235+atomic_unchecked_t fscache_n_store_vmscan_wait;
61236
61237-atomic_t fscache_n_marks;
61238-atomic_t fscache_n_uncaches;
61239+atomic_unchecked_t fscache_n_marks;
61240+atomic_unchecked_t fscache_n_uncaches;
61241
61242-atomic_t fscache_n_acquires;
61243-atomic_t fscache_n_acquires_null;
61244-atomic_t fscache_n_acquires_no_cache;
61245-atomic_t fscache_n_acquires_ok;
61246-atomic_t fscache_n_acquires_nobufs;
61247-atomic_t fscache_n_acquires_oom;
61248+atomic_unchecked_t fscache_n_acquires;
61249+atomic_unchecked_t fscache_n_acquires_null;
61250+atomic_unchecked_t fscache_n_acquires_no_cache;
61251+atomic_unchecked_t fscache_n_acquires_ok;
61252+atomic_unchecked_t fscache_n_acquires_nobufs;
61253+atomic_unchecked_t fscache_n_acquires_oom;
61254
61255-atomic_t fscache_n_invalidates;
61256-atomic_t fscache_n_invalidates_run;
61257+atomic_unchecked_t fscache_n_invalidates;
61258+atomic_unchecked_t fscache_n_invalidates_run;
61259
61260-atomic_t fscache_n_updates;
61261-atomic_t fscache_n_updates_null;
61262-atomic_t fscache_n_updates_run;
61263+atomic_unchecked_t fscache_n_updates;
61264+atomic_unchecked_t fscache_n_updates_null;
61265+atomic_unchecked_t fscache_n_updates_run;
61266
61267-atomic_t fscache_n_relinquishes;
61268-atomic_t fscache_n_relinquishes_null;
61269-atomic_t fscache_n_relinquishes_waitcrt;
61270-atomic_t fscache_n_relinquishes_retire;
61271+atomic_unchecked_t fscache_n_relinquishes;
61272+atomic_unchecked_t fscache_n_relinquishes_null;
61273+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
61274+atomic_unchecked_t fscache_n_relinquishes_retire;
61275
61276-atomic_t fscache_n_cookie_index;
61277-atomic_t fscache_n_cookie_data;
61278-atomic_t fscache_n_cookie_special;
61279+atomic_unchecked_t fscache_n_cookie_index;
61280+atomic_unchecked_t fscache_n_cookie_data;
61281+atomic_unchecked_t fscache_n_cookie_special;
61282
61283-atomic_t fscache_n_object_alloc;
61284-atomic_t fscache_n_object_no_alloc;
61285-atomic_t fscache_n_object_lookups;
61286-atomic_t fscache_n_object_lookups_negative;
61287-atomic_t fscache_n_object_lookups_positive;
61288-atomic_t fscache_n_object_lookups_timed_out;
61289-atomic_t fscache_n_object_created;
61290-atomic_t fscache_n_object_avail;
61291-atomic_t fscache_n_object_dead;
61292+atomic_unchecked_t fscache_n_object_alloc;
61293+atomic_unchecked_t fscache_n_object_no_alloc;
61294+atomic_unchecked_t fscache_n_object_lookups;
61295+atomic_unchecked_t fscache_n_object_lookups_negative;
61296+atomic_unchecked_t fscache_n_object_lookups_positive;
61297+atomic_unchecked_t fscache_n_object_lookups_timed_out;
61298+atomic_unchecked_t fscache_n_object_created;
61299+atomic_unchecked_t fscache_n_object_avail;
61300+atomic_unchecked_t fscache_n_object_dead;
61301
61302-atomic_t fscache_n_checkaux_none;
61303-atomic_t fscache_n_checkaux_okay;
61304-atomic_t fscache_n_checkaux_update;
61305-atomic_t fscache_n_checkaux_obsolete;
61306+atomic_unchecked_t fscache_n_checkaux_none;
61307+atomic_unchecked_t fscache_n_checkaux_okay;
61308+atomic_unchecked_t fscache_n_checkaux_update;
61309+atomic_unchecked_t fscache_n_checkaux_obsolete;
61310
61311 atomic_t fscache_n_cop_alloc_object;
61312 atomic_t fscache_n_cop_lookup_object;
61313@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
61314 seq_puts(m, "FS-Cache statistics\n");
61315
61316 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
61317- atomic_read(&fscache_n_cookie_index),
61318- atomic_read(&fscache_n_cookie_data),
61319- atomic_read(&fscache_n_cookie_special));
61320+ atomic_read_unchecked(&fscache_n_cookie_index),
61321+ atomic_read_unchecked(&fscache_n_cookie_data),
61322+ atomic_read_unchecked(&fscache_n_cookie_special));
61323
61324 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
61325- atomic_read(&fscache_n_object_alloc),
61326- atomic_read(&fscache_n_object_no_alloc),
61327- atomic_read(&fscache_n_object_avail),
61328- atomic_read(&fscache_n_object_dead));
61329+ atomic_read_unchecked(&fscache_n_object_alloc),
61330+ atomic_read_unchecked(&fscache_n_object_no_alloc),
61331+ atomic_read_unchecked(&fscache_n_object_avail),
61332+ atomic_read_unchecked(&fscache_n_object_dead));
61333 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
61334- atomic_read(&fscache_n_checkaux_none),
61335- atomic_read(&fscache_n_checkaux_okay),
61336- atomic_read(&fscache_n_checkaux_update),
61337- atomic_read(&fscache_n_checkaux_obsolete));
61338+ atomic_read_unchecked(&fscache_n_checkaux_none),
61339+ atomic_read_unchecked(&fscache_n_checkaux_okay),
61340+ atomic_read_unchecked(&fscache_n_checkaux_update),
61341+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
61342
61343 seq_printf(m, "Pages : mrk=%u unc=%u\n",
61344- atomic_read(&fscache_n_marks),
61345- atomic_read(&fscache_n_uncaches));
61346+ atomic_read_unchecked(&fscache_n_marks),
61347+ atomic_read_unchecked(&fscache_n_uncaches));
61348
61349 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
61350 " oom=%u\n",
61351- atomic_read(&fscache_n_acquires),
61352- atomic_read(&fscache_n_acquires_null),
61353- atomic_read(&fscache_n_acquires_no_cache),
61354- atomic_read(&fscache_n_acquires_ok),
61355- atomic_read(&fscache_n_acquires_nobufs),
61356- atomic_read(&fscache_n_acquires_oom));
61357+ atomic_read_unchecked(&fscache_n_acquires),
61358+ atomic_read_unchecked(&fscache_n_acquires_null),
61359+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
61360+ atomic_read_unchecked(&fscache_n_acquires_ok),
61361+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
61362+ atomic_read_unchecked(&fscache_n_acquires_oom));
61363
61364 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
61365- atomic_read(&fscache_n_object_lookups),
61366- atomic_read(&fscache_n_object_lookups_negative),
61367- atomic_read(&fscache_n_object_lookups_positive),
61368- atomic_read(&fscache_n_object_created),
61369- atomic_read(&fscache_n_object_lookups_timed_out));
61370+ atomic_read_unchecked(&fscache_n_object_lookups),
61371+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
61372+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
61373+ atomic_read_unchecked(&fscache_n_object_created),
61374+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
61375
61376 seq_printf(m, "Invals : n=%u run=%u\n",
61377- atomic_read(&fscache_n_invalidates),
61378- atomic_read(&fscache_n_invalidates_run));
61379+ atomic_read_unchecked(&fscache_n_invalidates),
61380+ atomic_read_unchecked(&fscache_n_invalidates_run));
61381
61382 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
61383- atomic_read(&fscache_n_updates),
61384- atomic_read(&fscache_n_updates_null),
61385- atomic_read(&fscache_n_updates_run));
61386+ atomic_read_unchecked(&fscache_n_updates),
61387+ atomic_read_unchecked(&fscache_n_updates_null),
61388+ atomic_read_unchecked(&fscache_n_updates_run));
61389
61390 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
61391- atomic_read(&fscache_n_relinquishes),
61392- atomic_read(&fscache_n_relinquishes_null),
61393- atomic_read(&fscache_n_relinquishes_waitcrt),
61394- atomic_read(&fscache_n_relinquishes_retire));
61395+ atomic_read_unchecked(&fscache_n_relinquishes),
61396+ atomic_read_unchecked(&fscache_n_relinquishes_null),
61397+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
61398+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
61399
61400 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
61401- atomic_read(&fscache_n_attr_changed),
61402- atomic_read(&fscache_n_attr_changed_ok),
61403- atomic_read(&fscache_n_attr_changed_nobufs),
61404- atomic_read(&fscache_n_attr_changed_nomem),
61405- atomic_read(&fscache_n_attr_changed_calls));
61406+ atomic_read_unchecked(&fscache_n_attr_changed),
61407+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
61408+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
61409+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
61410+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
61411
61412 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
61413- atomic_read(&fscache_n_allocs),
61414- atomic_read(&fscache_n_allocs_ok),
61415- atomic_read(&fscache_n_allocs_wait),
61416- atomic_read(&fscache_n_allocs_nobufs),
61417- atomic_read(&fscache_n_allocs_intr));
61418+ atomic_read_unchecked(&fscache_n_allocs),
61419+ atomic_read_unchecked(&fscache_n_allocs_ok),
61420+ atomic_read_unchecked(&fscache_n_allocs_wait),
61421+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
61422+ atomic_read_unchecked(&fscache_n_allocs_intr));
61423 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
61424- atomic_read(&fscache_n_alloc_ops),
61425- atomic_read(&fscache_n_alloc_op_waits),
61426- atomic_read(&fscache_n_allocs_object_dead));
61427+ atomic_read_unchecked(&fscache_n_alloc_ops),
61428+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
61429+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
61430
61431 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
61432 " int=%u oom=%u\n",
61433- atomic_read(&fscache_n_retrievals),
61434- atomic_read(&fscache_n_retrievals_ok),
61435- atomic_read(&fscache_n_retrievals_wait),
61436- atomic_read(&fscache_n_retrievals_nodata),
61437- atomic_read(&fscache_n_retrievals_nobufs),
61438- atomic_read(&fscache_n_retrievals_intr),
61439- atomic_read(&fscache_n_retrievals_nomem));
61440+ atomic_read_unchecked(&fscache_n_retrievals),
61441+ atomic_read_unchecked(&fscache_n_retrievals_ok),
61442+ atomic_read_unchecked(&fscache_n_retrievals_wait),
61443+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
61444+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
61445+ atomic_read_unchecked(&fscache_n_retrievals_intr),
61446+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
61447 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
61448- atomic_read(&fscache_n_retrieval_ops),
61449- atomic_read(&fscache_n_retrieval_op_waits),
61450- atomic_read(&fscache_n_retrievals_object_dead));
61451+ atomic_read_unchecked(&fscache_n_retrieval_ops),
61452+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
61453+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
61454
61455 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
61456- atomic_read(&fscache_n_stores),
61457- atomic_read(&fscache_n_stores_ok),
61458- atomic_read(&fscache_n_stores_again),
61459- atomic_read(&fscache_n_stores_nobufs),
61460- atomic_read(&fscache_n_stores_oom));
61461+ atomic_read_unchecked(&fscache_n_stores),
61462+ atomic_read_unchecked(&fscache_n_stores_ok),
61463+ atomic_read_unchecked(&fscache_n_stores_again),
61464+ atomic_read_unchecked(&fscache_n_stores_nobufs),
61465+ atomic_read_unchecked(&fscache_n_stores_oom));
61466 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
61467- atomic_read(&fscache_n_store_ops),
61468- atomic_read(&fscache_n_store_calls),
61469- atomic_read(&fscache_n_store_pages),
61470- atomic_read(&fscache_n_store_radix_deletes),
61471- atomic_read(&fscache_n_store_pages_over_limit));
61472+ atomic_read_unchecked(&fscache_n_store_ops),
61473+ atomic_read_unchecked(&fscache_n_store_calls),
61474+ atomic_read_unchecked(&fscache_n_store_pages),
61475+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
61476+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
61477
61478 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
61479- atomic_read(&fscache_n_store_vmscan_not_storing),
61480- atomic_read(&fscache_n_store_vmscan_gone),
61481- atomic_read(&fscache_n_store_vmscan_busy),
61482- atomic_read(&fscache_n_store_vmscan_cancelled),
61483- atomic_read(&fscache_n_store_vmscan_wait));
61484+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
61485+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
61486+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
61487+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
61488+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
61489
61490 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
61491- atomic_read(&fscache_n_op_pend),
61492- atomic_read(&fscache_n_op_run),
61493- atomic_read(&fscache_n_op_enqueue),
61494- atomic_read(&fscache_n_op_cancelled),
61495- atomic_read(&fscache_n_op_rejected));
61496+ atomic_read_unchecked(&fscache_n_op_pend),
61497+ atomic_read_unchecked(&fscache_n_op_run),
61498+ atomic_read_unchecked(&fscache_n_op_enqueue),
61499+ atomic_read_unchecked(&fscache_n_op_cancelled),
61500+ atomic_read_unchecked(&fscache_n_op_rejected));
61501 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
61502- atomic_read(&fscache_n_op_deferred_release),
61503- atomic_read(&fscache_n_op_release),
61504- atomic_read(&fscache_n_op_gc));
61505+ atomic_read_unchecked(&fscache_n_op_deferred_release),
61506+ atomic_read_unchecked(&fscache_n_op_release),
61507+ atomic_read_unchecked(&fscache_n_op_gc));
61508
61509 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
61510 atomic_read(&fscache_n_cop_alloc_object),
61511diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
61512index b96a49b..9bfdc47 100644
61513--- a/fs/fuse/cuse.c
61514+++ b/fs/fuse/cuse.c
61515@@ -606,10 +606,12 @@ static int __init cuse_init(void)
61516 INIT_LIST_HEAD(&cuse_conntbl[i]);
61517
61518 /* inherit and extend fuse_dev_operations */
61519- cuse_channel_fops = fuse_dev_operations;
61520- cuse_channel_fops.owner = THIS_MODULE;
61521- cuse_channel_fops.open = cuse_channel_open;
61522- cuse_channel_fops.release = cuse_channel_release;
61523+ pax_open_kernel();
61524+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
61525+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
61526+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
61527+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
61528+ pax_close_kernel();
61529
61530 cuse_class = class_create(THIS_MODULE, "cuse");
61531 if (IS_ERR(cuse_class))
61532diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
61533index 0a648bb..8d463f1 100644
61534--- a/fs/fuse/dev.c
61535+++ b/fs/fuse/dev.c
61536@@ -1323,7 +1323,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
61537 ret = 0;
61538 pipe_lock(pipe);
61539
61540- if (!pipe->readers) {
61541+ if (!atomic_read(&pipe->readers)) {
61542 send_sig(SIGPIPE, current, 0);
61543 if (!ret)
61544 ret = -EPIPE;
61545@@ -1352,7 +1352,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
61546 page_nr++;
61547 ret += buf->len;
61548
61549- if (pipe->files)
61550+ if (atomic_read(&pipe->files))
61551 do_wakeup = 1;
61552 }
61553
61554diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
61555index 1d1292c..bba17ea 100644
61556--- a/fs/fuse/dir.c
61557+++ b/fs/fuse/dir.c
61558@@ -1418,7 +1418,7 @@ static char *read_link(struct dentry *dentry)
61559 return link;
61560 }
61561
61562-static void free_link(char *link)
61563+static void free_link(const char *link)
61564 {
61565 if (!IS_ERR(link))
61566 free_page((unsigned long) link);
61567diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
61568index fe649d3..c679164 100644
61569--- a/fs/hostfs/hostfs_kern.c
61570+++ b/fs/hostfs/hostfs_kern.c
61571@@ -898,7 +898,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
61572
61573 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
61574 {
61575- char *s = nd_get_link(nd);
61576+ const char *s = nd_get_link(nd);
61577 if (!IS_ERR(s))
61578 __putname(s);
61579 }
61580diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
61581index d19b30a..ef89c36 100644
61582--- a/fs/hugetlbfs/inode.c
61583+++ b/fs/hugetlbfs/inode.c
61584@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
61585 struct mm_struct *mm = current->mm;
61586 struct vm_area_struct *vma;
61587 struct hstate *h = hstate_file(file);
61588+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
61589 struct vm_unmapped_area_info info;
61590
61591 if (len & ~huge_page_mask(h))
61592@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
61593 return addr;
61594 }
61595
61596+#ifdef CONFIG_PAX_RANDMMAP
61597+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
61598+#endif
61599+
61600 if (addr) {
61601 addr = ALIGN(addr, huge_page_size(h));
61602 vma = find_vma(mm, addr);
61603- if (TASK_SIZE - len >= addr &&
61604- (!vma || addr + len <= vma->vm_start))
61605+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
61606 return addr;
61607 }
61608
61609 info.flags = 0;
61610 info.length = len;
61611 info.low_limit = TASK_UNMAPPED_BASE;
61612+
61613+#ifdef CONFIG_PAX_RANDMMAP
61614+ if (mm->pax_flags & MF_PAX_RANDMMAP)
61615+ info.low_limit += mm->delta_mmap;
61616+#endif
61617+
61618 info.high_limit = TASK_SIZE;
61619 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
61620 info.align_offset = 0;
61621@@ -908,7 +918,7 @@ static struct file_system_type hugetlbfs_fs_type = {
61622 };
61623 MODULE_ALIAS_FS("hugetlbfs");
61624
61625-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
61626+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
61627
61628 static int can_do_hugetlb_shm(void)
61629 {
61630diff --git a/fs/inode.c b/fs/inode.c
61631index 4bcdad3..1883822 100644
61632--- a/fs/inode.c
61633+++ b/fs/inode.c
61634@@ -841,8 +841,8 @@ unsigned int get_next_ino(void)
61635
61636 #ifdef CONFIG_SMP
61637 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
61638- static atomic_t shared_last_ino;
61639- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
61640+ static atomic_unchecked_t shared_last_ino;
61641+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
61642
61643 res = next - LAST_INO_BATCH;
61644 }
61645diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
61646index 4a6cf28..d3a29d3 100644
61647--- a/fs/jffs2/erase.c
61648+++ b/fs/jffs2/erase.c
61649@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
61650 struct jffs2_unknown_node marker = {
61651 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
61652 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
61653- .totlen = cpu_to_je32(c->cleanmarker_size)
61654+ .totlen = cpu_to_je32(c->cleanmarker_size),
61655+ .hdr_crc = cpu_to_je32(0)
61656 };
61657
61658 jffs2_prealloc_raw_node_refs(c, jeb, 1);
61659diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
61660index a6597d6..41b30ec 100644
61661--- a/fs/jffs2/wbuf.c
61662+++ b/fs/jffs2/wbuf.c
61663@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
61664 {
61665 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
61666 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
61667- .totlen = constant_cpu_to_je32(8)
61668+ .totlen = constant_cpu_to_je32(8),
61669+ .hdr_crc = constant_cpu_to_je32(0)
61670 };
61671
61672 /*
61673diff --git a/fs/jfs/super.c b/fs/jfs/super.c
61674index e2b7483..855bca3 100644
61675--- a/fs/jfs/super.c
61676+++ b/fs/jfs/super.c
61677@@ -884,7 +884,7 @@ static int __init init_jfs_fs(void)
61678
61679 jfs_inode_cachep =
61680 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
61681- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
61682+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
61683 init_once);
61684 if (jfs_inode_cachep == NULL)
61685 return -ENOMEM;
61686diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
61687index 39c0143..d54fad4 100644
61688--- a/fs/kernfs/dir.c
61689+++ b/fs/kernfs/dir.c
61690@@ -28,7 +28,7 @@ DEFINE_MUTEX(kernfs_mutex);
61691 *
61692 * Returns 31 bit hash of ns + name (so it fits in an off_t )
61693 */
61694-static unsigned int kernfs_name_hash(const char *name, const void *ns)
61695+static unsigned int kernfs_name_hash(const unsigned char *name, const void *ns)
61696 {
61697 unsigned long hash = init_name_hash();
61698 unsigned int len = strlen(name);
61699diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
61700index dbf397b..d624b48 100644
61701--- a/fs/kernfs/file.c
61702+++ b/fs/kernfs/file.c
61703@@ -33,7 +33,7 @@ static DEFINE_MUTEX(kernfs_open_file_mutex);
61704
61705 struct kernfs_open_node {
61706 atomic_t refcnt;
61707- atomic_t event;
61708+ atomic_unchecked_t event;
61709 wait_queue_head_t poll;
61710 struct list_head files; /* goes through kernfs_open_file.list */
61711 };
61712@@ -149,7 +149,7 @@ static int kernfs_seq_show(struct seq_file *sf, void *v)
61713 {
61714 struct kernfs_open_file *of = sf->private;
61715
61716- of->event = atomic_read(&of->kn->attr.open->event);
61717+ of->event = atomic_read_unchecked(&of->kn->attr.open->event);
61718
61719 return of->kn->attr.ops->seq_show(sf, v);
61720 }
61721@@ -353,12 +353,12 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
61722 return ret;
61723 }
61724
61725-static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
61726- void *buf, int len, int write)
61727+static ssize_t kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
61728+ void *buf, size_t len, int write)
61729 {
61730 struct file *file = vma->vm_file;
61731 struct kernfs_open_file *of = kernfs_of(file);
61732- int ret;
61733+ ssize_t ret;
61734
61735 if (!of->vm_ops)
61736 return -EINVAL;
61737@@ -557,7 +557,7 @@ static int kernfs_get_open_node(struct kernfs_node *kn,
61738 return -ENOMEM;
61739
61740 atomic_set(&new_on->refcnt, 0);
61741- atomic_set(&new_on->event, 1);
61742+ atomic_set_unchecked(&new_on->event, 1);
61743 init_waitqueue_head(&new_on->poll);
61744 INIT_LIST_HEAD(&new_on->files);
61745 goto retry;
61746@@ -754,7 +754,7 @@ static unsigned int kernfs_fop_poll(struct file *filp, poll_table *wait)
61747
61748 kernfs_put_active(kn);
61749
61750- if (of->event != atomic_read(&on->event))
61751+ if (of->event != atomic_read_unchecked(&on->event))
61752 goto trigger;
61753
61754 return DEFAULT_POLLMASK;
61755@@ -779,7 +779,7 @@ void kernfs_notify(struct kernfs_node *kn)
61756 if (!WARN_ON(kernfs_type(kn) != KERNFS_FILE)) {
61757 on = kn->attr.open;
61758 if (on) {
61759- atomic_inc(&on->event);
61760+ atomic_inc_unchecked(&on->event);
61761 wake_up_interruptible(&on->poll);
61762 }
61763 }
61764diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c
61765index 4d45705..b35e0bd 100644
61766--- a/fs/kernfs/symlink.c
61767+++ b/fs/kernfs/symlink.c
61768@@ -132,7 +132,7 @@ static void *kernfs_iop_follow_link(struct dentry *dentry, struct nameidata *nd)
61769 static void kernfs_iop_put_link(struct dentry *dentry, struct nameidata *nd,
61770 void *cookie)
61771 {
61772- char *page = nd_get_link(nd);
61773+ const char *page = nd_get_link(nd);
61774 if (!IS_ERR(page))
61775 free_page((unsigned long)page);
61776 }
61777diff --git a/fs/libfs.c b/fs/libfs.c
61778index a184424..944ddce 100644
61779--- a/fs/libfs.c
61780+++ b/fs/libfs.c
61781@@ -159,6 +159,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61782
61783 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
61784 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
61785+ char d_name[sizeof(next->d_iname)];
61786+ const unsigned char *name;
61787+
61788 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
61789 if (!simple_positive(next)) {
61790 spin_unlock(&next->d_lock);
61791@@ -167,7 +170,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61792
61793 spin_unlock(&next->d_lock);
61794 spin_unlock(&dentry->d_lock);
61795- if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
61796+ name = next->d_name.name;
61797+ if (name == next->d_iname) {
61798+ memcpy(d_name, name, next->d_name.len);
61799+ name = d_name;
61800+ }
61801+ if (!dir_emit(ctx, name, next->d_name.len,
61802 next->d_inode->i_ino, dt_type(next->d_inode)))
61803 return 0;
61804 spin_lock(&dentry->d_lock);
61805@@ -999,7 +1007,7 @@ EXPORT_SYMBOL(noop_fsync);
61806 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
61807 void *cookie)
61808 {
61809- char *s = nd_get_link(nd);
61810+ const char *s = nd_get_link(nd);
61811 if (!IS_ERR(s))
61812 kfree(s);
61813 }
61814diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
61815index acd3947..1f896e2 100644
61816--- a/fs/lockd/clntproc.c
61817+++ b/fs/lockd/clntproc.c
61818@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
61819 /*
61820 * Cookie counter for NLM requests
61821 */
61822-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
61823+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
61824
61825 void nlmclnt_next_cookie(struct nlm_cookie *c)
61826 {
61827- u32 cookie = atomic_inc_return(&nlm_cookie);
61828+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
61829
61830 memcpy(c->data, &cookie, 4);
61831 c->len=4;
61832diff --git a/fs/locks.c b/fs/locks.c
61833index 92a0f0a..45a48f0 100644
61834--- a/fs/locks.c
61835+++ b/fs/locks.c
61836@@ -2219,16 +2219,16 @@ void locks_remove_flock(struct file *filp)
61837 return;
61838
61839 if (filp->f_op->flock) {
61840- struct file_lock fl = {
61841+ struct file_lock flock = {
61842 .fl_pid = current->tgid,
61843 .fl_file = filp,
61844 .fl_flags = FL_FLOCK,
61845 .fl_type = F_UNLCK,
61846 .fl_end = OFFSET_MAX,
61847 };
61848- filp->f_op->flock(filp, F_SETLKW, &fl);
61849- if (fl.fl_ops && fl.fl_ops->fl_release_private)
61850- fl.fl_ops->fl_release_private(&fl);
61851+ filp->f_op->flock(filp, F_SETLKW, &flock);
61852+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
61853+ flock.fl_ops->fl_release_private(&flock);
61854 }
61855
61856 spin_lock(&inode->i_lock);
61857diff --git a/fs/mount.h b/fs/mount.h
61858index b29e42f..5ea7fdf 100644
61859--- a/fs/mount.h
61860+++ b/fs/mount.h
61861@@ -11,7 +11,7 @@ struct mnt_namespace {
61862 u64 seq; /* Sequence number to prevent loops */
61863 wait_queue_head_t poll;
61864 int event;
61865-};
61866+} __randomize_layout;
61867
61868 struct mnt_pcp {
61869 int mnt_count;
61870@@ -57,7 +57,7 @@ struct mount {
61871 int mnt_expiry_mark; /* true if marked for expiry */
61872 int mnt_pinned;
61873 struct path mnt_ex_mountpoint;
61874-};
61875+} __randomize_layout;
61876
61877 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
61878
61879diff --git a/fs/namei.c b/fs/namei.c
61880index 4b491b4..a0166f9 100644
61881--- a/fs/namei.c
61882+++ b/fs/namei.c
61883@@ -330,16 +330,32 @@ int generic_permission(struct inode *inode, int mask)
61884 if (ret != -EACCES)
61885 return ret;
61886
61887+#ifdef CONFIG_GRKERNSEC
61888+ /* we'll block if we have to log due to a denied capability use */
61889+ if (mask & MAY_NOT_BLOCK)
61890+ return -ECHILD;
61891+#endif
61892+
61893 if (S_ISDIR(inode->i_mode)) {
61894 /* DACs are overridable for directories */
61895- if (inode_capable(inode, CAP_DAC_OVERRIDE))
61896- return 0;
61897 if (!(mask & MAY_WRITE))
61898- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
61899+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
61900+ inode_capable(inode, CAP_DAC_READ_SEARCH))
61901 return 0;
61902+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
61903+ return 0;
61904 return -EACCES;
61905 }
61906 /*
61907+ * Searching includes executable on directories, else just read.
61908+ */
61909+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61910+ if (mask == MAY_READ)
61911+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
61912+ inode_capable(inode, CAP_DAC_READ_SEARCH))
61913+ return 0;
61914+
61915+ /*
61916 * Read/write DACs are always overridable.
61917 * Executable DACs are overridable when there is
61918 * at least one exec bit set.
61919@@ -348,14 +364,6 @@ int generic_permission(struct inode *inode, int mask)
61920 if (inode_capable(inode, CAP_DAC_OVERRIDE))
61921 return 0;
61922
61923- /*
61924- * Searching includes executable on directories, else just read.
61925- */
61926- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61927- if (mask == MAY_READ)
61928- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
61929- return 0;
61930-
61931 return -EACCES;
61932 }
61933
61934@@ -821,7 +829,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61935 {
61936 struct dentry *dentry = link->dentry;
61937 int error;
61938- char *s;
61939+ const char *s;
61940
61941 BUG_ON(nd->flags & LOOKUP_RCU);
61942
61943@@ -842,6 +850,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61944 if (error)
61945 goto out_put_nd_path;
61946
61947+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
61948+ dentry->d_inode, dentry, nd->path.mnt)) {
61949+ error = -EACCES;
61950+ goto out_put_nd_path;
61951+ }
61952+
61953 nd->last_type = LAST_BIND;
61954 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
61955 error = PTR_ERR(*p);
61956@@ -1590,6 +1604,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
61957 if (res)
61958 break;
61959 res = walk_component(nd, path, LOOKUP_FOLLOW);
61960+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
61961+ res = -EACCES;
61962 put_link(nd, &link, cookie);
61963 } while (res > 0);
61964
61965@@ -1663,7 +1679,7 @@ EXPORT_SYMBOL(full_name_hash);
61966 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
61967 {
61968 unsigned long a, b, adata, bdata, mask, hash, len;
61969- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61970+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61971
61972 hash = a = 0;
61973 len = -sizeof(unsigned long);
61974@@ -1947,6 +1963,8 @@ static int path_lookupat(int dfd, const char *name,
61975 if (err)
61976 break;
61977 err = lookup_last(nd, &path);
61978+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
61979+ err = -EACCES;
61980 put_link(nd, &link, cookie);
61981 }
61982 }
61983@@ -1954,6 +1972,13 @@ static int path_lookupat(int dfd, const char *name,
61984 if (!err)
61985 err = complete_walk(nd);
61986
61987+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
61988+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
61989+ path_put(&nd->path);
61990+ err = -ENOENT;
61991+ }
61992+ }
61993+
61994 if (!err && nd->flags & LOOKUP_DIRECTORY) {
61995 if (!d_is_directory(nd->path.dentry)) {
61996 path_put(&nd->path);
61997@@ -1981,8 +2006,15 @@ static int filename_lookup(int dfd, struct filename *name,
61998 retval = path_lookupat(dfd, name->name,
61999 flags | LOOKUP_REVAL, nd);
62000
62001- if (likely(!retval))
62002+ if (likely(!retval)) {
62003 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
62004+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
62005+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
62006+ path_put(&nd->path);
62007+ return -ENOENT;
62008+ }
62009+ }
62010+ }
62011 return retval;
62012 }
62013
62014@@ -2556,6 +2588,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
62015 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
62016 return -EPERM;
62017
62018+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
62019+ return -EPERM;
62020+ if (gr_handle_rawio(inode))
62021+ return -EPERM;
62022+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
62023+ return -EACCES;
62024+
62025 return 0;
62026 }
62027
62028@@ -2787,7 +2826,7 @@ looked_up:
62029 * cleared otherwise prior to returning.
62030 */
62031 static int lookup_open(struct nameidata *nd, struct path *path,
62032- struct file *file,
62033+ struct path *link, struct file *file,
62034 const struct open_flags *op,
62035 bool got_write, int *opened)
62036 {
62037@@ -2822,6 +2861,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
62038 /* Negative dentry, just create the file */
62039 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
62040 umode_t mode = op->mode;
62041+
62042+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
62043+ error = -EACCES;
62044+ goto out_dput;
62045+ }
62046+
62047+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
62048+ error = -EACCES;
62049+ goto out_dput;
62050+ }
62051+
62052 if (!IS_POSIXACL(dir->d_inode))
62053 mode &= ~current_umask();
62054 /*
62055@@ -2843,6 +2893,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
62056 nd->flags & LOOKUP_EXCL);
62057 if (error)
62058 goto out_dput;
62059+ else
62060+ gr_handle_create(dentry, nd->path.mnt);
62061 }
62062 out_no_open:
62063 path->dentry = dentry;
62064@@ -2857,7 +2909,7 @@ out_dput:
62065 /*
62066 * Handle the last step of open()
62067 */
62068-static int do_last(struct nameidata *nd, struct path *path,
62069+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
62070 struct file *file, const struct open_flags *op,
62071 int *opened, struct filename *name)
62072 {
62073@@ -2907,6 +2959,15 @@ static int do_last(struct nameidata *nd, struct path *path,
62074 if (error)
62075 return error;
62076
62077+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
62078+ error = -ENOENT;
62079+ goto out;
62080+ }
62081+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
62082+ error = -EACCES;
62083+ goto out;
62084+ }
62085+
62086 audit_inode(name, dir, LOOKUP_PARENT);
62087 error = -EISDIR;
62088 /* trailing slashes? */
62089@@ -2926,7 +2987,7 @@ retry_lookup:
62090 */
62091 }
62092 mutex_lock(&dir->d_inode->i_mutex);
62093- error = lookup_open(nd, path, file, op, got_write, opened);
62094+ error = lookup_open(nd, path, link, file, op, got_write, opened);
62095 mutex_unlock(&dir->d_inode->i_mutex);
62096
62097 if (error <= 0) {
62098@@ -2950,11 +3011,28 @@ retry_lookup:
62099 goto finish_open_created;
62100 }
62101
62102+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
62103+ error = -ENOENT;
62104+ goto exit_dput;
62105+ }
62106+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
62107+ error = -EACCES;
62108+ goto exit_dput;
62109+ }
62110+
62111 /*
62112 * create/update audit record if it already exists.
62113 */
62114- if (d_is_positive(path->dentry))
62115+ if (d_is_positive(path->dentry)) {
62116+ /* only check if O_CREAT is specified, all other checks need to go
62117+ into may_open */
62118+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
62119+ error = -EACCES;
62120+ goto exit_dput;
62121+ }
62122+
62123 audit_inode(name, path->dentry, 0);
62124+ }
62125
62126 /*
62127 * If atomic_open() acquired write access it is dropped now due to
62128@@ -2995,6 +3073,11 @@ finish_lookup:
62129 }
62130 }
62131 BUG_ON(inode != path->dentry->d_inode);
62132+ /* if we're resolving a symlink to another symlink */
62133+ if (link && gr_handle_symlink_owner(link, inode)) {
62134+ error = -EACCES;
62135+ goto out;
62136+ }
62137 return 1;
62138 }
62139
62140@@ -3004,7 +3087,6 @@ finish_lookup:
62141 save_parent.dentry = nd->path.dentry;
62142 save_parent.mnt = mntget(path->mnt);
62143 nd->path.dentry = path->dentry;
62144-
62145 }
62146 nd->inode = inode;
62147 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
62148@@ -3014,7 +3096,18 @@ finish_open:
62149 path_put(&save_parent);
62150 return error;
62151 }
62152+
62153+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
62154+ error = -ENOENT;
62155+ goto out;
62156+ }
62157+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
62158+ error = -EACCES;
62159+ goto out;
62160+ }
62161+
62162 audit_inode(name, nd->path.dentry, 0);
62163+
62164 error = -EISDIR;
62165 if ((open_flag & O_CREAT) &&
62166 (d_is_directory(nd->path.dentry) || d_is_autodir(nd->path.dentry)))
62167@@ -3178,7 +3271,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
62168 if (unlikely(error))
62169 goto out;
62170
62171- error = do_last(nd, &path, file, op, &opened, pathname);
62172+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
62173 while (unlikely(error > 0)) { /* trailing symlink */
62174 struct path link = path;
62175 void *cookie;
62176@@ -3196,7 +3289,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
62177 error = follow_link(&link, nd, &cookie);
62178 if (unlikely(error))
62179 break;
62180- error = do_last(nd, &path, file, op, &opened, pathname);
62181+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
62182 put_link(nd, &link, cookie);
62183 }
62184 out:
62185@@ -3296,9 +3389,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
62186 goto unlock;
62187
62188 error = -EEXIST;
62189- if (d_is_positive(dentry))
62190+ if (d_is_positive(dentry)) {
62191+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
62192+ error = -ENOENT;
62193 goto fail;
62194-
62195+ }
62196 /*
62197 * Special case - lookup gave negative, but... we had foo/bar/
62198 * From the vfs_mknod() POV we just have a negative dentry -
62199@@ -3350,6 +3445,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
62200 }
62201 EXPORT_SYMBOL(user_path_create);
62202
62203+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
62204+{
62205+ struct filename *tmp = getname(pathname);
62206+ struct dentry *res;
62207+ if (IS_ERR(tmp))
62208+ return ERR_CAST(tmp);
62209+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
62210+ if (IS_ERR(res))
62211+ putname(tmp);
62212+ else
62213+ *to = tmp;
62214+ return res;
62215+}
62216+
62217 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
62218 {
62219 int error = may_create(dir, dentry);
62220@@ -3412,6 +3521,17 @@ retry:
62221
62222 if (!IS_POSIXACL(path.dentry->d_inode))
62223 mode &= ~current_umask();
62224+
62225+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
62226+ error = -EPERM;
62227+ goto out;
62228+ }
62229+
62230+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
62231+ error = -EACCES;
62232+ goto out;
62233+ }
62234+
62235 error = security_path_mknod(&path, dentry, mode, dev);
62236 if (error)
62237 goto out;
62238@@ -3428,6 +3548,8 @@ retry:
62239 break;
62240 }
62241 out:
62242+ if (!error)
62243+ gr_handle_create(dentry, path.mnt);
62244 done_path_create(&path, dentry);
62245 if (retry_estale(error, lookup_flags)) {
62246 lookup_flags |= LOOKUP_REVAL;
62247@@ -3480,9 +3602,16 @@ retry:
62248
62249 if (!IS_POSIXACL(path.dentry->d_inode))
62250 mode &= ~current_umask();
62251+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
62252+ error = -EACCES;
62253+ goto out;
62254+ }
62255 error = security_path_mkdir(&path, dentry, mode);
62256 if (!error)
62257 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
62258+ if (!error)
62259+ gr_handle_create(dentry, path.mnt);
62260+out:
62261 done_path_create(&path, dentry);
62262 if (retry_estale(error, lookup_flags)) {
62263 lookup_flags |= LOOKUP_REVAL;
62264@@ -3563,6 +3692,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
62265 struct filename *name;
62266 struct dentry *dentry;
62267 struct nameidata nd;
62268+ ino_t saved_ino = 0;
62269+ dev_t saved_dev = 0;
62270 unsigned int lookup_flags = 0;
62271 retry:
62272 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
62273@@ -3595,10 +3726,21 @@ retry:
62274 error = -ENOENT;
62275 goto exit3;
62276 }
62277+
62278+ saved_ino = dentry->d_inode->i_ino;
62279+ saved_dev = gr_get_dev_from_dentry(dentry);
62280+
62281+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
62282+ error = -EACCES;
62283+ goto exit3;
62284+ }
62285+
62286 error = security_path_rmdir(&nd.path, dentry);
62287 if (error)
62288 goto exit3;
62289 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
62290+ if (!error && (saved_dev || saved_ino))
62291+ gr_handle_delete(saved_ino, saved_dev);
62292 exit3:
62293 dput(dentry);
62294 exit2:
62295@@ -3688,6 +3830,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
62296 struct nameidata nd;
62297 struct inode *inode = NULL;
62298 struct inode *delegated_inode = NULL;
62299+ ino_t saved_ino = 0;
62300+ dev_t saved_dev = 0;
62301 unsigned int lookup_flags = 0;
62302 retry:
62303 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
62304@@ -3714,10 +3858,22 @@ retry_deleg:
62305 if (d_is_negative(dentry))
62306 goto slashes;
62307 ihold(inode);
62308+
62309+ if (inode->i_nlink <= 1) {
62310+ saved_ino = inode->i_ino;
62311+ saved_dev = gr_get_dev_from_dentry(dentry);
62312+ }
62313+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
62314+ error = -EACCES;
62315+ goto exit2;
62316+ }
62317+
62318 error = security_path_unlink(&nd.path, dentry);
62319 if (error)
62320 goto exit2;
62321 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
62322+ if (!error && (saved_ino || saved_dev))
62323+ gr_handle_delete(saved_ino, saved_dev);
62324 exit2:
62325 dput(dentry);
62326 }
62327@@ -3805,9 +3961,17 @@ retry:
62328 if (IS_ERR(dentry))
62329 goto out_putname;
62330
62331+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
62332+ error = -EACCES;
62333+ goto out;
62334+ }
62335+
62336 error = security_path_symlink(&path, dentry, from->name);
62337 if (!error)
62338 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
62339+ if (!error)
62340+ gr_handle_create(dentry, path.mnt);
62341+out:
62342 done_path_create(&path, dentry);
62343 if (retry_estale(error, lookup_flags)) {
62344 lookup_flags |= LOOKUP_REVAL;
62345@@ -3910,6 +4074,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
62346 struct dentry *new_dentry;
62347 struct path old_path, new_path;
62348 struct inode *delegated_inode = NULL;
62349+ struct filename *to = NULL;
62350 int how = 0;
62351 int error;
62352
62353@@ -3933,7 +4098,7 @@ retry:
62354 if (error)
62355 return error;
62356
62357- new_dentry = user_path_create(newdfd, newname, &new_path,
62358+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
62359 (how & LOOKUP_REVAL));
62360 error = PTR_ERR(new_dentry);
62361 if (IS_ERR(new_dentry))
62362@@ -3945,11 +4110,28 @@ retry:
62363 error = may_linkat(&old_path);
62364 if (unlikely(error))
62365 goto out_dput;
62366+
62367+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
62368+ old_path.dentry->d_inode,
62369+ old_path.dentry->d_inode->i_mode, to)) {
62370+ error = -EACCES;
62371+ goto out_dput;
62372+ }
62373+
62374+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
62375+ old_path.dentry, old_path.mnt, to)) {
62376+ error = -EACCES;
62377+ goto out_dput;
62378+ }
62379+
62380 error = security_path_link(old_path.dentry, &new_path, new_dentry);
62381 if (error)
62382 goto out_dput;
62383 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
62384+ if (!error)
62385+ gr_handle_create(new_dentry, new_path.mnt);
62386 out_dput:
62387+ putname(to);
62388 done_path_create(&new_path, new_dentry);
62389 if (delegated_inode) {
62390 error = break_deleg_wait(&delegated_inode);
62391@@ -4236,6 +4418,12 @@ retry_deleg:
62392 if (new_dentry == trap)
62393 goto exit5;
62394
62395+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
62396+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
62397+ to);
62398+ if (error)
62399+ goto exit5;
62400+
62401 error = security_path_rename(&oldnd.path, old_dentry,
62402 &newnd.path, new_dentry);
62403 if (error)
62404@@ -4243,6 +4431,9 @@ retry_deleg:
62405 error = vfs_rename(old_dir->d_inode, old_dentry,
62406 new_dir->d_inode, new_dentry,
62407 &delegated_inode);
62408+ if (!error)
62409+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
62410+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
62411 exit5:
62412 dput(new_dentry);
62413 exit4:
62414@@ -4279,6 +4470,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
62415
62416 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
62417 {
62418+ char tmpbuf[64];
62419+ const char *newlink;
62420 int len;
62421
62422 len = PTR_ERR(link);
62423@@ -4288,7 +4481,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
62424 len = strlen(link);
62425 if (len > (unsigned) buflen)
62426 len = buflen;
62427- if (copy_to_user(buffer, link, len))
62428+
62429+ if (len < sizeof(tmpbuf)) {
62430+ memcpy(tmpbuf, link, len);
62431+ newlink = tmpbuf;
62432+ } else
62433+ newlink = link;
62434+
62435+ if (copy_to_user(buffer, newlink, len))
62436 len = -EFAULT;
62437 out:
62438 return len;
62439diff --git a/fs/namespace.c b/fs/namespace.c
62440index 65233a5..82ac953 100644
62441--- a/fs/namespace.c
62442+++ b/fs/namespace.c
62443@@ -1339,6 +1339,9 @@ static int do_umount(struct mount *mnt, int flags)
62444 if (!(sb->s_flags & MS_RDONLY))
62445 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
62446 up_write(&sb->s_umount);
62447+
62448+ gr_log_remount(mnt->mnt_devname, retval);
62449+
62450 return retval;
62451 }
62452
62453@@ -1361,6 +1364,9 @@ static int do_umount(struct mount *mnt, int flags)
62454 }
62455 unlock_mount_hash();
62456 namespace_unlock();
62457+
62458+ gr_log_unmount(mnt->mnt_devname, retval);
62459+
62460 return retval;
62461 }
62462
62463@@ -1380,7 +1386,7 @@ static inline bool may_mount(void)
62464 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
62465 */
62466
62467-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
62468+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
62469 {
62470 struct path path;
62471 struct mount *mnt;
62472@@ -1422,7 +1428,7 @@ out:
62473 /*
62474 * The 2.0 compatible umount. No flags.
62475 */
62476-SYSCALL_DEFINE1(oldumount, char __user *, name)
62477+SYSCALL_DEFINE1(oldumount, const char __user *, name)
62478 {
62479 return sys_umount(name, 0);
62480 }
62481@@ -2431,6 +2437,16 @@ long do_mount(const char *dev_name, const char *dir_name,
62482 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
62483 MS_STRICTATIME);
62484
62485+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
62486+ retval = -EPERM;
62487+ goto dput_out;
62488+ }
62489+
62490+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
62491+ retval = -EPERM;
62492+ goto dput_out;
62493+ }
62494+
62495 if (flags & MS_REMOUNT)
62496 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
62497 data_page);
62498@@ -2445,6 +2461,9 @@ long do_mount(const char *dev_name, const char *dir_name,
62499 dev_name, data_page);
62500 dput_out:
62501 path_put(&path);
62502+
62503+ gr_log_mount(dev_name, dir_name, retval);
62504+
62505 return retval;
62506 }
62507
62508@@ -2462,7 +2481,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
62509 * number incrementing at 10Ghz will take 12,427 years to wrap which
62510 * is effectively never, so we can ignore the possibility.
62511 */
62512-static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
62513+static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
62514
62515 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62516 {
62517@@ -2477,7 +2496,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62518 kfree(new_ns);
62519 return ERR_PTR(ret);
62520 }
62521- new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
62522+ new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
62523 atomic_set(&new_ns->count, 1);
62524 new_ns->root = NULL;
62525 INIT_LIST_HEAD(&new_ns->list);
62526@@ -2487,7 +2506,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62527 return new_ns;
62528 }
62529
62530-struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
62531+__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
62532 struct user_namespace *user_ns, struct fs_struct *new_fs)
62533 {
62534 struct mnt_namespace *new_ns;
62535@@ -2608,8 +2627,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
62536 }
62537 EXPORT_SYMBOL(mount_subtree);
62538
62539-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
62540- char __user *, type, unsigned long, flags, void __user *, data)
62541+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
62542+ const char __user *, type, unsigned long, flags, void __user *, data)
62543 {
62544 int ret;
62545 char *kernel_type;
62546@@ -2722,6 +2741,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
62547 if (error)
62548 goto out2;
62549
62550+ if (gr_handle_chroot_pivot()) {
62551+ error = -EPERM;
62552+ goto out2;
62553+ }
62554+
62555 get_fs_root(current->fs, &root);
62556 old_mp = lock_mount(&old);
62557 error = PTR_ERR(old_mp);
62558@@ -2990,7 +3014,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
62559 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
62560 return -EPERM;
62561
62562- if (fs->users != 1)
62563+ if (atomic_read(&fs->users) != 1)
62564 return -EINVAL;
62565
62566 get_mnt_ns(mnt_ns);
62567diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
62568index f4ccfe6..a5cf064 100644
62569--- a/fs/nfs/callback_xdr.c
62570+++ b/fs/nfs/callback_xdr.c
62571@@ -51,7 +51,7 @@ struct callback_op {
62572 callback_decode_arg_t decode_args;
62573 callback_encode_res_t encode_res;
62574 long res_maxsize;
62575-};
62576+} __do_const;
62577
62578 static struct callback_op callback_ops[];
62579
62580diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
62581index 360114a..ac6e265 100644
62582--- a/fs/nfs/inode.c
62583+++ b/fs/nfs/inode.c
62584@@ -1189,16 +1189,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
62585 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
62586 }
62587
62588-static atomic_long_t nfs_attr_generation_counter;
62589+static atomic_long_unchecked_t nfs_attr_generation_counter;
62590
62591 static unsigned long nfs_read_attr_generation_counter(void)
62592 {
62593- return atomic_long_read(&nfs_attr_generation_counter);
62594+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
62595 }
62596
62597 unsigned long nfs_inc_attr_generation_counter(void)
62598 {
62599- return atomic_long_inc_return(&nfs_attr_generation_counter);
62600+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
62601 }
62602
62603 void nfs_fattr_init(struct nfs_fattr *fattr)
62604diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
62605index 9a914e8..e89c0ea 100644
62606--- a/fs/nfsd/nfs4proc.c
62607+++ b/fs/nfsd/nfs4proc.c
62608@@ -1178,7 +1178,7 @@ struct nfsd4_operation {
62609 nfsd4op_rsize op_rsize_bop;
62610 stateid_getter op_get_currentstateid;
62611 stateid_setter op_set_currentstateid;
62612-};
62613+} __do_const;
62614
62615 static struct nfsd4_operation nfsd4_ops[];
62616
62617diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
62618index 16e8fa7..b0803f6 100644
62619--- a/fs/nfsd/nfs4xdr.c
62620+++ b/fs/nfsd/nfs4xdr.c
62621@@ -1531,7 +1531,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
62622
62623 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
62624
62625-static nfsd4_dec nfsd4_dec_ops[] = {
62626+static const nfsd4_dec nfsd4_dec_ops[] = {
62627 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
62628 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
62629 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
62630diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
62631index f8f060f..c4ba09a 100644
62632--- a/fs/nfsd/nfscache.c
62633+++ b/fs/nfsd/nfscache.c
62634@@ -519,14 +519,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
62635 {
62636 struct svc_cacherep *rp = rqstp->rq_cacherep;
62637 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
62638- int len;
62639+ long len;
62640 size_t bufsize = 0;
62641
62642 if (!rp)
62643 return;
62644
62645- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
62646- len >>= 2;
62647+ if (statp) {
62648+ len = (char*)statp - (char*)resv->iov_base;
62649+ len = resv->iov_len - len;
62650+ len >>= 2;
62651+ }
62652
62653 /* Don't cache excessive amounts of data and XDR failures */
62654 if (!statp || len > (256 >> 2)) {
62655diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
62656index eea5ad1..5a84ac7 100644
62657--- a/fs/nfsd/vfs.c
62658+++ b/fs/nfsd/vfs.c
62659@@ -843,7 +843,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
62660 } else {
62661 oldfs = get_fs();
62662 set_fs(KERNEL_DS);
62663- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
62664+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
62665 set_fs(oldfs);
62666 }
62667
62668@@ -934,7 +934,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
62669
62670 /* Write the data. */
62671 oldfs = get_fs(); set_fs(KERNEL_DS);
62672- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
62673+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
62674 set_fs(oldfs);
62675 if (host_err < 0)
62676 goto out_nfserr;
62677@@ -1479,7 +1479,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
62678 */
62679
62680 oldfs = get_fs(); set_fs(KERNEL_DS);
62681- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
62682+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
62683 set_fs(oldfs);
62684
62685 if (host_err < 0)
62686diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
62687index 52ccd34..43a53b1 100644
62688--- a/fs/nls/nls_base.c
62689+++ b/fs/nls/nls_base.c
62690@@ -234,21 +234,25 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
62691
62692 int __register_nls(struct nls_table *nls, struct module *owner)
62693 {
62694- struct nls_table ** tmp = &tables;
62695+ struct nls_table *tmp = tables;
62696
62697 if (nls->next)
62698 return -EBUSY;
62699
62700- nls->owner = owner;
62701+ pax_open_kernel();
62702+ *(void **)&nls->owner = owner;
62703+ pax_close_kernel();
62704 spin_lock(&nls_lock);
62705- while (*tmp) {
62706- if (nls == *tmp) {
62707+ while (tmp) {
62708+ if (nls == tmp) {
62709 spin_unlock(&nls_lock);
62710 return -EBUSY;
62711 }
62712- tmp = &(*tmp)->next;
62713+ tmp = tmp->next;
62714 }
62715- nls->next = tables;
62716+ pax_open_kernel();
62717+ *(struct nls_table **)&nls->next = tables;
62718+ pax_close_kernel();
62719 tables = nls;
62720 spin_unlock(&nls_lock);
62721 return 0;
62722@@ -257,12 +261,14 @@ EXPORT_SYMBOL(__register_nls);
62723
62724 int unregister_nls(struct nls_table * nls)
62725 {
62726- struct nls_table ** tmp = &tables;
62727+ struct nls_table * const * tmp = &tables;
62728
62729 spin_lock(&nls_lock);
62730 while (*tmp) {
62731 if (nls == *tmp) {
62732- *tmp = nls->next;
62733+ pax_open_kernel();
62734+ *(struct nls_table **)tmp = nls->next;
62735+ pax_close_kernel();
62736 spin_unlock(&nls_lock);
62737 return 0;
62738 }
62739diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
62740index 162b3f1..6076a7c 100644
62741--- a/fs/nls/nls_euc-jp.c
62742+++ b/fs/nls/nls_euc-jp.c
62743@@ -560,8 +560,10 @@ static int __init init_nls_euc_jp(void)
62744 p_nls = load_nls("cp932");
62745
62746 if (p_nls) {
62747- table.charset2upper = p_nls->charset2upper;
62748- table.charset2lower = p_nls->charset2lower;
62749+ pax_open_kernel();
62750+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62751+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62752+ pax_close_kernel();
62753 return register_nls(&table);
62754 }
62755
62756diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
62757index a80a741..7b96e1b 100644
62758--- a/fs/nls/nls_koi8-ru.c
62759+++ b/fs/nls/nls_koi8-ru.c
62760@@ -62,8 +62,10 @@ static int __init init_nls_koi8_ru(void)
62761 p_nls = load_nls("koi8-u");
62762
62763 if (p_nls) {
62764- table.charset2upper = p_nls->charset2upper;
62765- table.charset2lower = p_nls->charset2lower;
62766+ pax_open_kernel();
62767+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62768+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62769+ pax_close_kernel();
62770 return register_nls(&table);
62771 }
62772
62773diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
62774index 287a22c..4e56e4e 100644
62775--- a/fs/notify/fanotify/fanotify_user.c
62776+++ b/fs/notify/fanotify/fanotify_user.c
62777@@ -251,8 +251,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
62778
62779 fd = fanotify_event_metadata.fd;
62780 ret = -EFAULT;
62781- if (copy_to_user(buf, &fanotify_event_metadata,
62782- fanotify_event_metadata.event_len))
62783+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
62784+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
62785 goto out_close_fd;
62786
62787 ret = prepare_for_access_response(group, event, fd);
62788@@ -742,6 +742,8 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags)
62789 oevent->path.mnt = NULL;
62790 oevent->path.dentry = NULL;
62791
62792+ if (force_o_largefile())
62793+ event_f_flags |= O_LARGEFILE;
62794 group->fanotify_data.f_flags = event_f_flags;
62795 #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
62796 oevent->response = 0;
62797diff --git a/fs/notify/notification.c b/fs/notify/notification.c
62798index 1e58402..bb2d6f4 100644
62799--- a/fs/notify/notification.c
62800+++ b/fs/notify/notification.c
62801@@ -48,7 +48,7 @@
62802 #include <linux/fsnotify_backend.h>
62803 #include "fsnotify.h"
62804
62805-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62806+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62807
62808 /**
62809 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
62810@@ -56,7 +56,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62811 */
62812 u32 fsnotify_get_cookie(void)
62813 {
62814- return atomic_inc_return(&fsnotify_sync_cookie);
62815+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
62816 }
62817 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
62818
62819diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
62820index 9e38daf..5727cae 100644
62821--- a/fs/ntfs/dir.c
62822+++ b/fs/ntfs/dir.c
62823@@ -1310,7 +1310,7 @@ find_next_index_buffer:
62824 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
62825 ~(s64)(ndir->itype.index.block_size - 1)));
62826 /* Bounds checks. */
62827- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62828+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62829 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
62830 "inode 0x%lx or driver bug.", vdir->i_ino);
62831 goto err_out;
62832diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
62833index db9bd8a..8338fb6 100644
62834--- a/fs/ntfs/file.c
62835+++ b/fs/ntfs/file.c
62836@@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
62837 char *addr;
62838 size_t total = 0;
62839 unsigned len;
62840- int left;
62841+ unsigned left;
62842
62843 do {
62844 len = PAGE_CACHE_SIZE - ofs;
62845diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
62846index 82650d5..db37dcf 100644
62847--- a/fs/ntfs/super.c
62848+++ b/fs/ntfs/super.c
62849@@ -685,7 +685,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62850 if (!silent)
62851 ntfs_error(sb, "Primary boot sector is invalid.");
62852 } else if (!silent)
62853- ntfs_error(sb, read_err_str, "primary");
62854+ ntfs_error(sb, read_err_str, "%s", "primary");
62855 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
62856 if (bh_primary)
62857 brelse(bh_primary);
62858@@ -701,7 +701,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62859 goto hotfix_primary_boot_sector;
62860 brelse(bh_backup);
62861 } else if (!silent)
62862- ntfs_error(sb, read_err_str, "backup");
62863+ ntfs_error(sb, read_err_str, "%s", "backup");
62864 /* Try to read NT3.51- backup boot sector. */
62865 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
62866 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
62867@@ -712,7 +712,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62868 "sector.");
62869 brelse(bh_backup);
62870 } else if (!silent)
62871- ntfs_error(sb, read_err_str, "backup");
62872+ ntfs_error(sb, read_err_str, "%s", "backup");
62873 /* We failed. Cleanup and return. */
62874 if (bh_primary)
62875 brelse(bh_primary);
62876diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
62877index 0440134..d52c93a 100644
62878--- a/fs/ocfs2/localalloc.c
62879+++ b/fs/ocfs2/localalloc.c
62880@@ -1320,7 +1320,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
62881 goto bail;
62882 }
62883
62884- atomic_inc(&osb->alloc_stats.moves);
62885+ atomic_inc_unchecked(&osb->alloc_stats.moves);
62886
62887 bail:
62888 if (handle)
62889diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
62890index 553f53c..aaf5133 100644
62891--- a/fs/ocfs2/ocfs2.h
62892+++ b/fs/ocfs2/ocfs2.h
62893@@ -235,11 +235,11 @@ enum ocfs2_vol_state
62894
62895 struct ocfs2_alloc_stats
62896 {
62897- atomic_t moves;
62898- atomic_t local_data;
62899- atomic_t bitmap_data;
62900- atomic_t bg_allocs;
62901- atomic_t bg_extends;
62902+ atomic_unchecked_t moves;
62903+ atomic_unchecked_t local_data;
62904+ atomic_unchecked_t bitmap_data;
62905+ atomic_unchecked_t bg_allocs;
62906+ atomic_unchecked_t bg_extends;
62907 };
62908
62909 enum ocfs2_local_alloc_state
62910diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
62911index 47ae266..6e8b793 100644
62912--- a/fs/ocfs2/suballoc.c
62913+++ b/fs/ocfs2/suballoc.c
62914@@ -866,7 +866,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
62915 mlog_errno(status);
62916 goto bail;
62917 }
62918- atomic_inc(&osb->alloc_stats.bg_extends);
62919+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
62920
62921 /* You should never ask for this much metadata */
62922 BUG_ON(bits_wanted >
62923@@ -1992,7 +1992,7 @@ int ocfs2_claim_metadata(handle_t *handle,
62924 mlog_errno(status);
62925 goto bail;
62926 }
62927- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62928+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62929
62930 *suballoc_loc = res.sr_bg_blkno;
62931 *suballoc_bit_start = res.sr_bit_offset;
62932@@ -2156,7 +2156,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
62933 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
62934 res->sr_bits);
62935
62936- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62937+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62938
62939 BUG_ON(res->sr_bits != 1);
62940
62941@@ -2198,7 +2198,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
62942 mlog_errno(status);
62943 goto bail;
62944 }
62945- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62946+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62947
62948 BUG_ON(res.sr_bits != 1);
62949
62950@@ -2302,7 +2302,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62951 cluster_start,
62952 num_clusters);
62953 if (!status)
62954- atomic_inc(&osb->alloc_stats.local_data);
62955+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
62956 } else {
62957 if (min_clusters > (osb->bitmap_cpg - 1)) {
62958 /* The only paths asking for contiguousness
62959@@ -2328,7 +2328,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62960 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
62961 res.sr_bg_blkno,
62962 res.sr_bit_offset);
62963- atomic_inc(&osb->alloc_stats.bitmap_data);
62964+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
62965 *num_clusters = res.sr_bits;
62966 }
62967 }
62968diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
62969index 49d84f8..4807e0b 100644
62970--- a/fs/ocfs2/super.c
62971+++ b/fs/ocfs2/super.c
62972@@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
62973 "%10s => GlobalAllocs: %d LocalAllocs: %d "
62974 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
62975 "Stats",
62976- atomic_read(&osb->alloc_stats.bitmap_data),
62977- atomic_read(&osb->alloc_stats.local_data),
62978- atomic_read(&osb->alloc_stats.bg_allocs),
62979- atomic_read(&osb->alloc_stats.moves),
62980- atomic_read(&osb->alloc_stats.bg_extends));
62981+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
62982+ atomic_read_unchecked(&osb->alloc_stats.local_data),
62983+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
62984+ atomic_read_unchecked(&osb->alloc_stats.moves),
62985+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
62986
62987 out += snprintf(buf + out, len - out,
62988 "%10s => State: %u Descriptor: %llu Size: %u bits "
62989@@ -2123,11 +2123,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
62990 spin_lock_init(&osb->osb_xattr_lock);
62991 ocfs2_init_steal_slots(osb);
62992
62993- atomic_set(&osb->alloc_stats.moves, 0);
62994- atomic_set(&osb->alloc_stats.local_data, 0);
62995- atomic_set(&osb->alloc_stats.bitmap_data, 0);
62996- atomic_set(&osb->alloc_stats.bg_allocs, 0);
62997- atomic_set(&osb->alloc_stats.bg_extends, 0);
62998+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
62999+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
63000+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
63001+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
63002+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
63003
63004 /* Copy the blockcheck stats from the superblock probe */
63005 osb->osb_ecc_stats = *stats;
63006diff --git a/fs/open.c b/fs/open.c
63007index b9ed8b2..0d5c7a0 100644
63008--- a/fs/open.c
63009+++ b/fs/open.c
63010@@ -32,6 +32,8 @@
63011 #include <linux/dnotify.h>
63012 #include <linux/compat.h>
63013
63014+#define CREATE_TRACE_POINTS
63015+#include <trace/events/fs.h>
63016 #include "internal.h"
63017
63018 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
63019@@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
63020 error = locks_verify_truncate(inode, NULL, length);
63021 if (!error)
63022 error = security_path_truncate(path);
63023+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
63024+ error = -EACCES;
63025 if (!error)
63026 error = do_truncate(path->dentry, length, 0, NULL);
63027
63028@@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
63029 error = locks_verify_truncate(inode, f.file, length);
63030 if (!error)
63031 error = security_path_truncate(&f.file->f_path);
63032+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
63033+ error = -EACCES;
63034 if (!error)
63035 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
63036 sb_end_write(inode->i_sb);
63037@@ -361,6 +367,9 @@ retry:
63038 if (__mnt_is_readonly(path.mnt))
63039 res = -EROFS;
63040
63041+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
63042+ res = -EACCES;
63043+
63044 out_path_release:
63045 path_put(&path);
63046 if (retry_estale(res, lookup_flags)) {
63047@@ -392,6 +401,8 @@ retry:
63048 if (error)
63049 goto dput_and_out;
63050
63051+ gr_log_chdir(path.dentry, path.mnt);
63052+
63053 set_fs_pwd(current->fs, &path);
63054
63055 dput_and_out:
63056@@ -421,6 +432,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
63057 goto out_putf;
63058
63059 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
63060+
63061+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
63062+ error = -EPERM;
63063+
63064+ if (!error)
63065+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
63066+
63067 if (!error)
63068 set_fs_pwd(current->fs, &f.file->f_path);
63069 out_putf:
63070@@ -450,7 +468,13 @@ retry:
63071 if (error)
63072 goto dput_and_out;
63073
63074+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
63075+ goto dput_and_out;
63076+
63077 set_fs_root(current->fs, &path);
63078+
63079+ gr_handle_chroot_chdir(&path);
63080+
63081 error = 0;
63082 dput_and_out:
63083 path_put(&path);
63084@@ -474,6 +498,16 @@ static int chmod_common(struct path *path, umode_t mode)
63085 return error;
63086 retry_deleg:
63087 mutex_lock(&inode->i_mutex);
63088+
63089+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
63090+ error = -EACCES;
63091+ goto out_unlock;
63092+ }
63093+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
63094+ error = -EACCES;
63095+ goto out_unlock;
63096+ }
63097+
63098 error = security_path_chmod(path, mode);
63099 if (error)
63100 goto out_unlock;
63101@@ -539,6 +573,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
63102 uid = make_kuid(current_user_ns(), user);
63103 gid = make_kgid(current_user_ns(), group);
63104
63105+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
63106+ return -EACCES;
63107+
63108 newattrs.ia_valid = ATTR_CTIME;
63109 if (user != (uid_t) -1) {
63110 if (!uid_valid(uid))
63111@@ -994,6 +1031,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
63112 } else {
63113 fsnotify_open(f);
63114 fd_install(fd, f);
63115+ trace_do_sys_open(tmp->name, flags, mode);
63116 }
63117 }
63118 putname(tmp);
63119diff --git a/fs/pipe.c b/fs/pipe.c
63120index 78fd0d0..f71fc09 100644
63121--- a/fs/pipe.c
63122+++ b/fs/pipe.c
63123@@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
63124
63125 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
63126 {
63127- if (pipe->files)
63128+ if (atomic_read(&pipe->files))
63129 mutex_lock_nested(&pipe->mutex, subclass);
63130 }
63131
63132@@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
63133
63134 void pipe_unlock(struct pipe_inode_info *pipe)
63135 {
63136- if (pipe->files)
63137+ if (atomic_read(&pipe->files))
63138 mutex_unlock(&pipe->mutex);
63139 }
63140 EXPORT_SYMBOL(pipe_unlock);
63141@@ -449,9 +449,9 @@ redo:
63142 }
63143 if (bufs) /* More to do? */
63144 continue;
63145- if (!pipe->writers)
63146+ if (!atomic_read(&pipe->writers))
63147 break;
63148- if (!pipe->waiting_writers) {
63149+ if (!atomic_read(&pipe->waiting_writers)) {
63150 /* syscall merging: Usually we must not sleep
63151 * if O_NONBLOCK is set, or if we got some data.
63152 * But if a writer sleeps in kernel space, then
63153@@ -513,7 +513,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
63154 ret = 0;
63155 __pipe_lock(pipe);
63156
63157- if (!pipe->readers) {
63158+ if (!atomic_read(&pipe->readers)) {
63159 send_sig(SIGPIPE, current, 0);
63160 ret = -EPIPE;
63161 goto out;
63162@@ -562,7 +562,7 @@ redo1:
63163 for (;;) {
63164 int bufs;
63165
63166- if (!pipe->readers) {
63167+ if (!atomic_read(&pipe->readers)) {
63168 send_sig(SIGPIPE, current, 0);
63169 if (!ret)
63170 ret = -EPIPE;
63171@@ -653,9 +653,9 @@ redo2:
63172 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
63173 do_wakeup = 0;
63174 }
63175- pipe->waiting_writers++;
63176+ atomic_inc(&pipe->waiting_writers);
63177 pipe_wait(pipe);
63178- pipe->waiting_writers--;
63179+ atomic_dec(&pipe->waiting_writers);
63180 }
63181 out:
63182 __pipe_unlock(pipe);
63183@@ -710,7 +710,7 @@ pipe_poll(struct file *filp, poll_table *wait)
63184 mask = 0;
63185 if (filp->f_mode & FMODE_READ) {
63186 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
63187- if (!pipe->writers && filp->f_version != pipe->w_counter)
63188+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
63189 mask |= POLLHUP;
63190 }
63191
63192@@ -720,7 +720,7 @@ pipe_poll(struct file *filp, poll_table *wait)
63193 * Most Unices do not set POLLERR for FIFOs but on Linux they
63194 * behave exactly like pipes for poll().
63195 */
63196- if (!pipe->readers)
63197+ if (!atomic_read(&pipe->readers))
63198 mask |= POLLERR;
63199 }
63200
63201@@ -732,7 +732,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
63202 int kill = 0;
63203
63204 spin_lock(&inode->i_lock);
63205- if (!--pipe->files) {
63206+ if (atomic_dec_and_test(&pipe->files)) {
63207 inode->i_pipe = NULL;
63208 kill = 1;
63209 }
63210@@ -749,11 +749,11 @@ pipe_release(struct inode *inode, struct file *file)
63211
63212 __pipe_lock(pipe);
63213 if (file->f_mode & FMODE_READ)
63214- pipe->readers--;
63215+ atomic_dec(&pipe->readers);
63216 if (file->f_mode & FMODE_WRITE)
63217- pipe->writers--;
63218+ atomic_dec(&pipe->writers);
63219
63220- if (pipe->readers || pipe->writers) {
63221+ if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
63222 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
63223 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
63224 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
63225@@ -818,7 +818,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
63226 kfree(pipe);
63227 }
63228
63229-static struct vfsmount *pipe_mnt __read_mostly;
63230+struct vfsmount *pipe_mnt __read_mostly;
63231
63232 /*
63233 * pipefs_dname() is called from d_path().
63234@@ -848,8 +848,9 @@ static struct inode * get_pipe_inode(void)
63235 goto fail_iput;
63236
63237 inode->i_pipe = pipe;
63238- pipe->files = 2;
63239- pipe->readers = pipe->writers = 1;
63240+ atomic_set(&pipe->files, 2);
63241+ atomic_set(&pipe->readers, 1);
63242+ atomic_set(&pipe->writers, 1);
63243 inode->i_fop = &pipefifo_fops;
63244
63245 /*
63246@@ -1028,17 +1029,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
63247 spin_lock(&inode->i_lock);
63248 if (inode->i_pipe) {
63249 pipe = inode->i_pipe;
63250- pipe->files++;
63251+ atomic_inc(&pipe->files);
63252 spin_unlock(&inode->i_lock);
63253 } else {
63254 spin_unlock(&inode->i_lock);
63255 pipe = alloc_pipe_info();
63256 if (!pipe)
63257 return -ENOMEM;
63258- pipe->files = 1;
63259+ atomic_set(&pipe->files, 1);
63260 spin_lock(&inode->i_lock);
63261 if (unlikely(inode->i_pipe)) {
63262- inode->i_pipe->files++;
63263+ atomic_inc(&inode->i_pipe->files);
63264 spin_unlock(&inode->i_lock);
63265 free_pipe_info(pipe);
63266 pipe = inode->i_pipe;
63267@@ -1063,10 +1064,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
63268 * opened, even when there is no process writing the FIFO.
63269 */
63270 pipe->r_counter++;
63271- if (pipe->readers++ == 0)
63272+ if (atomic_inc_return(&pipe->readers) == 1)
63273 wake_up_partner(pipe);
63274
63275- if (!is_pipe && !pipe->writers) {
63276+ if (!is_pipe && !atomic_read(&pipe->writers)) {
63277 if ((filp->f_flags & O_NONBLOCK)) {
63278 /* suppress POLLHUP until we have
63279 * seen a writer */
63280@@ -1085,14 +1086,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
63281 * errno=ENXIO when there is no process reading the FIFO.
63282 */
63283 ret = -ENXIO;
63284- if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
63285+ if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
63286 goto err;
63287
63288 pipe->w_counter++;
63289- if (!pipe->writers++)
63290+ if (atomic_inc_return(&pipe->writers) == 1)
63291 wake_up_partner(pipe);
63292
63293- if (!is_pipe && !pipe->readers) {
63294+ if (!is_pipe && !atomic_read(&pipe->readers)) {
63295 if (wait_for_partner(pipe, &pipe->r_counter))
63296 goto err_wr;
63297 }
63298@@ -1106,11 +1107,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
63299 * the process can at least talk to itself.
63300 */
63301
63302- pipe->readers++;
63303- pipe->writers++;
63304+ atomic_inc(&pipe->readers);
63305+ atomic_inc(&pipe->writers);
63306 pipe->r_counter++;
63307 pipe->w_counter++;
63308- if (pipe->readers == 1 || pipe->writers == 1)
63309+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
63310 wake_up_partner(pipe);
63311 break;
63312
63313@@ -1124,13 +1125,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
63314 return 0;
63315
63316 err_rd:
63317- if (!--pipe->readers)
63318+ if (atomic_dec_and_test(&pipe->readers))
63319 wake_up_interruptible(&pipe->wait);
63320 ret = -ERESTARTSYS;
63321 goto err;
63322
63323 err_wr:
63324- if (!--pipe->writers)
63325+ if (atomic_dec_and_test(&pipe->writers))
63326 wake_up_interruptible(&pipe->wait);
63327 ret = -ERESTARTSYS;
63328 goto err;
63329diff --git a/fs/posix_acl.c b/fs/posix_acl.c
63330index 9e363e4..d936d15 100644
63331--- a/fs/posix_acl.c
63332+++ b/fs/posix_acl.c
63333@@ -20,6 +20,7 @@
63334 #include <linux/xattr.h>
63335 #include <linux/export.h>
63336 #include <linux/user_namespace.h>
63337+#include <linux/grsecurity.h>
63338
63339 struct posix_acl **acl_by_type(struct inode *inode, int type)
63340 {
63341@@ -271,7 +272,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
63342 }
63343 }
63344 if (mode_p)
63345- *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
63346+ *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
63347 return not_equiv;
63348 }
63349 EXPORT_SYMBOL(posix_acl_equiv_mode);
63350@@ -421,7 +422,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
63351 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
63352 }
63353
63354- *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
63355+ *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
63356 return not_equiv;
63357 }
63358
63359@@ -479,6 +480,8 @@ __posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
63360 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
63361 int err = -ENOMEM;
63362 if (clone) {
63363+ *mode_p &= ~gr_acl_umask();
63364+
63365 err = posix_acl_create_masq(clone, mode_p);
63366 if (err < 0) {
63367 posix_acl_release(clone);
63368@@ -653,11 +656,12 @@ struct posix_acl *
63369 posix_acl_from_xattr(struct user_namespace *user_ns,
63370 const void *value, size_t size)
63371 {
63372- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
63373- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
63374+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
63375+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
63376 int count;
63377 struct posix_acl *acl;
63378 struct posix_acl_entry *acl_e;
63379+ umode_t umask = gr_acl_umask();
63380
63381 if (!value)
63382 return NULL;
63383@@ -683,12 +687,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
63384
63385 switch(acl_e->e_tag) {
63386 case ACL_USER_OBJ:
63387+ acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
63388+ break;
63389 case ACL_GROUP_OBJ:
63390 case ACL_MASK:
63391+ acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
63392+ break;
63393 case ACL_OTHER:
63394+ acl_e->e_perm &= ~(umask & S_IRWXO);
63395 break;
63396
63397 case ACL_USER:
63398+ acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
63399 acl_e->e_uid =
63400 make_kuid(user_ns,
63401 le32_to_cpu(entry->e_id));
63402@@ -696,6 +706,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
63403 goto fail;
63404 break;
63405 case ACL_GROUP:
63406+ acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
63407 acl_e->e_gid =
63408 make_kgid(user_ns,
63409 le32_to_cpu(entry->e_id));
63410diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
63411index 2183fcf..3c32a98 100644
63412--- a/fs/proc/Kconfig
63413+++ b/fs/proc/Kconfig
63414@@ -30,7 +30,7 @@ config PROC_FS
63415
63416 config PROC_KCORE
63417 bool "/proc/kcore support" if !ARM
63418- depends on PROC_FS && MMU
63419+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
63420 help
63421 Provides a virtual ELF core file of the live kernel. This can
63422 be read with gdb and other ELF tools. No modifications can be
63423@@ -38,8 +38,8 @@ config PROC_KCORE
63424
63425 config PROC_VMCORE
63426 bool "/proc/vmcore support"
63427- depends on PROC_FS && CRASH_DUMP
63428- default y
63429+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
63430+ default n
63431 help
63432 Exports the dump image of crashed kernel in ELF format.
63433
63434@@ -63,8 +63,8 @@ config PROC_SYSCTL
63435 limited in memory.
63436
63437 config PROC_PAGE_MONITOR
63438- default y
63439- depends on PROC_FS && MMU
63440+ default n
63441+ depends on PROC_FS && MMU && !GRKERNSEC
63442 bool "Enable /proc page monitoring" if EXPERT
63443 help
63444 Various /proc files exist to monitor process memory utilization:
63445diff --git a/fs/proc/array.c b/fs/proc/array.c
63446index 656e401..b5b86b9 100644
63447--- a/fs/proc/array.c
63448+++ b/fs/proc/array.c
63449@@ -60,6 +60,7 @@
63450 #include <linux/tty.h>
63451 #include <linux/string.h>
63452 #include <linux/mman.h>
63453+#include <linux/grsecurity.h>
63454 #include <linux/proc_fs.h>
63455 #include <linux/ioport.h>
63456 #include <linux/uaccess.h>
63457@@ -356,6 +357,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
63458 seq_putc(m, '\n');
63459 }
63460
63461+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63462+static inline void task_pax(struct seq_file *m, struct task_struct *p)
63463+{
63464+ if (p->mm)
63465+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
63466+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
63467+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
63468+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
63469+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
63470+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
63471+ else
63472+ seq_printf(m, "PaX:\t-----\n");
63473+}
63474+#endif
63475+
63476 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
63477 struct pid *pid, struct task_struct *task)
63478 {
63479@@ -374,9 +390,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
63480 task_cpus_allowed(m, task);
63481 cpuset_task_status_allowed(m, task);
63482 task_context_switch_counts(m, task);
63483+
63484+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63485+ task_pax(m, task);
63486+#endif
63487+
63488+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
63489+ task_grsec_rbac(m, task);
63490+#endif
63491+
63492 return 0;
63493 }
63494
63495+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63496+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63497+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
63498+ _mm->pax_flags & MF_PAX_SEGMEXEC))
63499+#endif
63500+
63501 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63502 struct pid *pid, struct task_struct *task, int whole)
63503 {
63504@@ -398,6 +429,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63505 char tcomm[sizeof(task->comm)];
63506 unsigned long flags;
63507
63508+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63509+ if (current->exec_id != m->exec_id) {
63510+ gr_log_badprocpid("stat");
63511+ return 0;
63512+ }
63513+#endif
63514+
63515 state = *get_task_state(task);
63516 vsize = eip = esp = 0;
63517 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
63518@@ -468,6 +506,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63519 gtime = task_gtime(task);
63520 }
63521
63522+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63523+ if (PAX_RAND_FLAGS(mm)) {
63524+ eip = 0;
63525+ esp = 0;
63526+ wchan = 0;
63527+ }
63528+#endif
63529+#ifdef CONFIG_GRKERNSEC_HIDESYM
63530+ wchan = 0;
63531+ eip =0;
63532+ esp =0;
63533+#endif
63534+
63535 /* scale priority and nice values from timeslices to -20..20 */
63536 /* to make it look like a "normal" Unix priority/nice value */
63537 priority = task_prio(task);
63538@@ -504,9 +555,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63539 seq_put_decimal_ull(m, ' ', vsize);
63540 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
63541 seq_put_decimal_ull(m, ' ', rsslim);
63542+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63543+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
63544+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
63545+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
63546+#else
63547 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
63548 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
63549 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
63550+#endif
63551 seq_put_decimal_ull(m, ' ', esp);
63552 seq_put_decimal_ull(m, ' ', eip);
63553 /* The signal information here is obsolete.
63554@@ -528,7 +585,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63555 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
63556 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
63557
63558- if (mm && permitted) {
63559+ if (mm && permitted
63560+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63561+ && !PAX_RAND_FLAGS(mm)
63562+#endif
63563+ ) {
63564 seq_put_decimal_ull(m, ' ', mm->start_data);
63565 seq_put_decimal_ull(m, ' ', mm->end_data);
63566 seq_put_decimal_ull(m, ' ', mm->start_brk);
63567@@ -566,8 +627,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
63568 struct pid *pid, struct task_struct *task)
63569 {
63570 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
63571- struct mm_struct *mm = get_task_mm(task);
63572+ struct mm_struct *mm;
63573
63574+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63575+ if (current->exec_id != m->exec_id) {
63576+ gr_log_badprocpid("statm");
63577+ return 0;
63578+ }
63579+#endif
63580+ mm = get_task_mm(task);
63581 if (mm) {
63582 size = task_statm(mm, &shared, &text, &data, &resident);
63583 mmput(mm);
63584@@ -590,6 +658,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
63585 return 0;
63586 }
63587
63588+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63589+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
63590+{
63591+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
63592+}
63593+#endif
63594+
63595 #ifdef CONFIG_CHECKPOINT_RESTORE
63596 static struct pid *
63597 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
63598diff --git a/fs/proc/base.c b/fs/proc/base.c
63599index b976062..584d0bc 100644
63600--- a/fs/proc/base.c
63601+++ b/fs/proc/base.c
63602@@ -113,6 +113,14 @@ struct pid_entry {
63603 union proc_op op;
63604 };
63605
63606+struct getdents_callback {
63607+ struct linux_dirent __user * current_dir;
63608+ struct linux_dirent __user * previous;
63609+ struct file * file;
63610+ int count;
63611+ int error;
63612+};
63613+
63614 #define NOD(NAME, MODE, IOP, FOP, OP) { \
63615 .name = (NAME), \
63616 .len = sizeof(NAME) - 1, \
63617@@ -210,6 +218,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
63618 if (!mm->arg_end)
63619 goto out_mm; /* Shh! No looking before we're done */
63620
63621+ if (gr_acl_handle_procpidmem(task))
63622+ goto out_mm;
63623+
63624 len = mm->arg_end - mm->arg_start;
63625
63626 if (len > PAGE_SIZE)
63627@@ -237,12 +248,28 @@ out:
63628 return res;
63629 }
63630
63631+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63632+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63633+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
63634+ _mm->pax_flags & MF_PAX_SEGMEXEC))
63635+#endif
63636+
63637 static int proc_pid_auxv(struct task_struct *task, char *buffer)
63638 {
63639 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
63640 int res = PTR_ERR(mm);
63641 if (mm && !IS_ERR(mm)) {
63642 unsigned int nwords = 0;
63643+
63644+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63645+ /* allow if we're currently ptracing this task */
63646+ if (PAX_RAND_FLAGS(mm) &&
63647+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
63648+ mmput(mm);
63649+ return 0;
63650+ }
63651+#endif
63652+
63653 do {
63654 nwords += 2;
63655 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
63656@@ -256,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
63657 }
63658
63659
63660-#ifdef CONFIG_KALLSYMS
63661+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63662 /*
63663 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
63664 * Returns the resolved symbol. If that fails, simply return the address.
63665@@ -295,7 +322,7 @@ static void unlock_trace(struct task_struct *task)
63666 mutex_unlock(&task->signal->cred_guard_mutex);
63667 }
63668
63669-#ifdef CONFIG_STACKTRACE
63670+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63671
63672 #define MAX_STACK_TRACE_DEPTH 64
63673
63674@@ -518,7 +545,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
63675 return count;
63676 }
63677
63678-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63679+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63680 static int proc_pid_syscall(struct task_struct *task, char *buffer)
63681 {
63682 long nr;
63683@@ -547,7 +574,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
63684 /************************************************************************/
63685
63686 /* permission checks */
63687-static int proc_fd_access_allowed(struct inode *inode)
63688+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
63689 {
63690 struct task_struct *task;
63691 int allowed = 0;
63692@@ -557,7 +584,10 @@ static int proc_fd_access_allowed(struct inode *inode)
63693 */
63694 task = get_proc_task(inode);
63695 if (task) {
63696- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
63697+ if (log)
63698+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
63699+ else
63700+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
63701 put_task_struct(task);
63702 }
63703 return allowed;
63704@@ -588,10 +618,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
63705 struct task_struct *task,
63706 int hide_pid_min)
63707 {
63708+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63709+ return false;
63710+
63711+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63712+ rcu_read_lock();
63713+ {
63714+ const struct cred *tmpcred = current_cred();
63715+ const struct cred *cred = __task_cred(task);
63716+
63717+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
63718+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63719+ || in_group_p(grsec_proc_gid)
63720+#endif
63721+ ) {
63722+ rcu_read_unlock();
63723+ return true;
63724+ }
63725+ }
63726+ rcu_read_unlock();
63727+
63728+ if (!pid->hide_pid)
63729+ return false;
63730+#endif
63731+
63732 if (pid->hide_pid < hide_pid_min)
63733 return true;
63734 if (in_group_p(pid->pid_gid))
63735 return true;
63736+
63737 return ptrace_may_access(task, PTRACE_MODE_READ);
63738 }
63739
63740@@ -609,7 +664,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
63741 put_task_struct(task);
63742
63743 if (!has_perms) {
63744+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63745+ {
63746+#else
63747 if (pid->hide_pid == 2) {
63748+#endif
63749 /*
63750 * Let's make getdents(), stat(), and open()
63751 * consistent with each other. If a process
63752@@ -707,6 +766,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
63753 if (!task)
63754 return -ESRCH;
63755
63756+ if (gr_acl_handle_procpidmem(task)) {
63757+ put_task_struct(task);
63758+ return -EPERM;
63759+ }
63760+
63761 mm = mm_access(task, mode);
63762 put_task_struct(task);
63763
63764@@ -722,6 +786,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
63765
63766 file->private_data = mm;
63767
63768+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63769+ file->f_version = current->exec_id;
63770+#endif
63771+
63772 return 0;
63773 }
63774
63775@@ -743,6 +811,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63776 ssize_t copied;
63777 char *page;
63778
63779+#ifdef CONFIG_GRKERNSEC
63780+ if (write)
63781+ return -EPERM;
63782+#endif
63783+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63784+ if (file->f_version != current->exec_id) {
63785+ gr_log_badprocpid("mem");
63786+ return 0;
63787+ }
63788+#endif
63789+
63790 if (!mm)
63791 return 0;
63792
63793@@ -755,7 +834,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63794 goto free;
63795
63796 while (count > 0) {
63797- int this_len = min_t(int, count, PAGE_SIZE);
63798+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
63799
63800 if (write && copy_from_user(page, buf, this_len)) {
63801 copied = -EFAULT;
63802@@ -847,6 +926,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63803 if (!mm)
63804 return 0;
63805
63806+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63807+ if (file->f_version != current->exec_id) {
63808+ gr_log_badprocpid("environ");
63809+ return 0;
63810+ }
63811+#endif
63812+
63813 page = (char *)__get_free_page(GFP_TEMPORARY);
63814 if (!page)
63815 return -ENOMEM;
63816@@ -856,7 +942,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63817 goto free;
63818 while (count > 0) {
63819 size_t this_len, max_len;
63820- int retval;
63821+ ssize_t retval;
63822
63823 if (src >= (mm->env_end - mm->env_start))
63824 break;
63825@@ -1467,7 +1553,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
63826 int error = -EACCES;
63827
63828 /* Are we allowed to snoop on the tasks file descriptors? */
63829- if (!proc_fd_access_allowed(inode))
63830+ if (!proc_fd_access_allowed(inode, 0))
63831 goto out;
63832
63833 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63834@@ -1511,8 +1597,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
63835 struct path path;
63836
63837 /* Are we allowed to snoop on the tasks file descriptors? */
63838- if (!proc_fd_access_allowed(inode))
63839- goto out;
63840+ /* logging this is needed for learning on chromium to work properly,
63841+ but we don't want to flood the logs from 'ps' which does a readlink
63842+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
63843+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
63844+ */
63845+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
63846+ if (!proc_fd_access_allowed(inode,0))
63847+ goto out;
63848+ } else {
63849+ if (!proc_fd_access_allowed(inode,1))
63850+ goto out;
63851+ }
63852
63853 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63854 if (error)
63855@@ -1562,7 +1658,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
63856 rcu_read_lock();
63857 cred = __task_cred(task);
63858 inode->i_uid = cred->euid;
63859+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63860+ inode->i_gid = grsec_proc_gid;
63861+#else
63862 inode->i_gid = cred->egid;
63863+#endif
63864 rcu_read_unlock();
63865 }
63866 security_task_to_inode(task, inode);
63867@@ -1598,10 +1698,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
63868 return -ENOENT;
63869 }
63870 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63871+#ifdef CONFIG_GRKERNSEC_PROC_USER
63872+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63873+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63874+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63875+#endif
63876 task_dumpable(task)) {
63877 cred = __task_cred(task);
63878 stat->uid = cred->euid;
63879+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63880+ stat->gid = grsec_proc_gid;
63881+#else
63882 stat->gid = cred->egid;
63883+#endif
63884 }
63885 }
63886 rcu_read_unlock();
63887@@ -1639,11 +1748,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
63888
63889 if (task) {
63890 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63891+#ifdef CONFIG_GRKERNSEC_PROC_USER
63892+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63893+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63894+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63895+#endif
63896 task_dumpable(task)) {
63897 rcu_read_lock();
63898 cred = __task_cred(task);
63899 inode->i_uid = cred->euid;
63900+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63901+ inode->i_gid = grsec_proc_gid;
63902+#else
63903 inode->i_gid = cred->egid;
63904+#endif
63905 rcu_read_unlock();
63906 } else {
63907 inode->i_uid = GLOBAL_ROOT_UID;
63908@@ -2178,6 +2296,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
63909 if (!task)
63910 goto out_no_task;
63911
63912+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63913+ goto out;
63914+
63915 /*
63916 * Yes, it does not scale. And it should not. Don't add
63917 * new entries into /proc/<tgid>/ without very good reasons.
63918@@ -2208,6 +2329,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
63919 if (!task)
63920 return -ENOENT;
63921
63922+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63923+ goto out;
63924+
63925 if (!dir_emit_dots(file, ctx))
63926 goto out;
63927
63928@@ -2597,7 +2721,7 @@ static const struct pid_entry tgid_base_stuff[] = {
63929 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
63930 #endif
63931 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63932-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63933+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63934 INF("syscall", S_IRUGO, proc_pid_syscall),
63935 #endif
63936 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63937@@ -2622,10 +2746,10 @@ static const struct pid_entry tgid_base_stuff[] = {
63938 #ifdef CONFIG_SECURITY
63939 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63940 #endif
63941-#ifdef CONFIG_KALLSYMS
63942+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63943 INF("wchan", S_IRUGO, proc_pid_wchan),
63944 #endif
63945-#ifdef CONFIG_STACKTRACE
63946+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63947 ONE("stack", S_IRUGO, proc_pid_stack),
63948 #endif
63949 #ifdef CONFIG_SCHEDSTATS
63950@@ -2659,6 +2783,9 @@ static const struct pid_entry tgid_base_stuff[] = {
63951 #ifdef CONFIG_HARDWALL
63952 INF("hardwall", S_IRUGO, proc_pid_hardwall),
63953 #endif
63954+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63955+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
63956+#endif
63957 #ifdef CONFIG_USER_NS
63958 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
63959 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
63960@@ -2789,7 +2916,14 @@ static int proc_pid_instantiate(struct inode *dir,
63961 if (!inode)
63962 goto out;
63963
63964+#ifdef CONFIG_GRKERNSEC_PROC_USER
63965+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
63966+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63967+ inode->i_gid = grsec_proc_gid;
63968+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
63969+#else
63970 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
63971+#endif
63972 inode->i_op = &proc_tgid_base_inode_operations;
63973 inode->i_fop = &proc_tgid_base_operations;
63974 inode->i_flags|=S_IMMUTABLE;
63975@@ -2827,7 +2961,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
63976 if (!task)
63977 goto out;
63978
63979+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63980+ goto out_put_task;
63981+
63982 result = proc_pid_instantiate(dir, dentry, task, NULL);
63983+out_put_task:
63984 put_task_struct(task);
63985 out:
63986 return ERR_PTR(result);
63987@@ -2933,7 +3071,7 @@ static const struct pid_entry tid_base_stuff[] = {
63988 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
63989 #endif
63990 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63991-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63992+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63993 INF("syscall", S_IRUGO, proc_pid_syscall),
63994 #endif
63995 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63996@@ -2960,10 +3098,10 @@ static const struct pid_entry tid_base_stuff[] = {
63997 #ifdef CONFIG_SECURITY
63998 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63999 #endif
64000-#ifdef CONFIG_KALLSYMS
64001+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
64002 INF("wchan", S_IRUGO, proc_pid_wchan),
64003 #endif
64004-#ifdef CONFIG_STACKTRACE
64005+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
64006 ONE("stack", S_IRUGO, proc_pid_stack),
64007 #endif
64008 #ifdef CONFIG_SCHEDSTATS
64009diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
64010index cbd82df..c0407d2 100644
64011--- a/fs/proc/cmdline.c
64012+++ b/fs/proc/cmdline.c
64013@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
64014
64015 static int __init proc_cmdline_init(void)
64016 {
64017+#ifdef CONFIG_GRKERNSEC_PROC_ADD
64018+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
64019+#else
64020 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
64021+#endif
64022 return 0;
64023 }
64024 fs_initcall(proc_cmdline_init);
64025diff --git a/fs/proc/devices.c b/fs/proc/devices.c
64026index 50493ed..248166b 100644
64027--- a/fs/proc/devices.c
64028+++ b/fs/proc/devices.c
64029@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
64030
64031 static int __init proc_devices_init(void)
64032 {
64033+#ifdef CONFIG_GRKERNSEC_PROC_ADD
64034+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
64035+#else
64036 proc_create("devices", 0, NULL, &proc_devinfo_operations);
64037+#endif
64038 return 0;
64039 }
64040 fs_initcall(proc_devices_init);
64041diff --git a/fs/proc/fd.c b/fs/proc/fd.c
64042index 985ea88..d118a0a 100644
64043--- a/fs/proc/fd.c
64044+++ b/fs/proc/fd.c
64045@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
64046 if (!task)
64047 return -ENOENT;
64048
64049- files = get_files_struct(task);
64050+ if (!gr_acl_handle_procpidmem(task))
64051+ files = get_files_struct(task);
64052 put_task_struct(task);
64053
64054 if (files) {
64055@@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
64056 */
64057 int proc_fd_permission(struct inode *inode, int mask)
64058 {
64059+ struct task_struct *task;
64060 int rv = generic_permission(inode, mask);
64061- if (rv == 0)
64062- return 0;
64063+
64064 if (task_tgid(current) == proc_pid(inode))
64065 rv = 0;
64066+
64067+ task = get_proc_task(inode);
64068+ if (task == NULL)
64069+ return rv;
64070+
64071+ if (gr_acl_handle_procpidmem(task))
64072+ rv = -EACCES;
64073+
64074+ put_task_struct(task);
64075+
64076 return rv;
64077 }
64078
64079diff --git a/fs/proc/generic.c b/fs/proc/generic.c
64080index b7f268e..3bea6b7 100644
64081--- a/fs/proc/generic.c
64082+++ b/fs/proc/generic.c
64083@@ -23,6 +23,7 @@
64084 #include <linux/bitops.h>
64085 #include <linux/spinlock.h>
64086 #include <linux/completion.h>
64087+#include <linux/grsecurity.h>
64088 #include <asm/uaccess.h>
64089
64090 #include "internal.h"
64091@@ -207,6 +208,15 @@ struct dentry *proc_lookup(struct inode *dir, struct dentry *dentry,
64092 return proc_lookup_de(PDE(dir), dir, dentry);
64093 }
64094
64095+struct dentry *proc_lookup_restrict(struct inode *dir, struct dentry *dentry,
64096+ unsigned int flags)
64097+{
64098+ if (gr_proc_is_restricted())
64099+ return ERR_PTR(-EACCES);
64100+
64101+ return proc_lookup_de(PDE(dir), dir, dentry);
64102+}
64103+
64104 /*
64105 * This returns non-zero if at EOF, so that the /proc
64106 * root directory can use this and check if it should
64107@@ -264,6 +274,16 @@ int proc_readdir(struct file *file, struct dir_context *ctx)
64108 return proc_readdir_de(PDE(inode), file, ctx);
64109 }
64110
64111+int proc_readdir_restrict(struct file *file, struct dir_context *ctx)
64112+{
64113+ struct inode *inode = file_inode(file);
64114+
64115+ if (gr_proc_is_restricted())
64116+ return -EACCES;
64117+
64118+ return proc_readdir_de(PDE(inode), file, ctx);
64119+}
64120+
64121 /*
64122 * These are the generic /proc directory operations. They
64123 * use the in-memory "struct proc_dir_entry" tree to parse
64124@@ -275,6 +295,12 @@ static const struct file_operations proc_dir_operations = {
64125 .iterate = proc_readdir,
64126 };
64127
64128+static const struct file_operations proc_dir_restricted_operations = {
64129+ .llseek = generic_file_llseek,
64130+ .read = generic_read_dir,
64131+ .iterate = proc_readdir_restrict,
64132+};
64133+
64134 /*
64135 * proc directories can do almost nothing..
64136 */
64137@@ -284,6 +310,12 @@ static const struct inode_operations proc_dir_inode_operations = {
64138 .setattr = proc_notify_change,
64139 };
64140
64141+static const struct inode_operations proc_dir_restricted_inode_operations = {
64142+ .lookup = proc_lookup_restrict,
64143+ .getattr = proc_getattr,
64144+ .setattr = proc_notify_change,
64145+};
64146+
64147 static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
64148 {
64149 struct proc_dir_entry *tmp;
64150@@ -294,8 +326,13 @@ static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
64151 return ret;
64152
64153 if (S_ISDIR(dp->mode)) {
64154- dp->proc_fops = &proc_dir_operations;
64155- dp->proc_iops = &proc_dir_inode_operations;
64156+ if (dp->restricted) {
64157+ dp->proc_fops = &proc_dir_restricted_operations;
64158+ dp->proc_iops = &proc_dir_restricted_inode_operations;
64159+ } else {
64160+ dp->proc_fops = &proc_dir_operations;
64161+ dp->proc_iops = &proc_dir_inode_operations;
64162+ }
64163 dir->nlink++;
64164 } else if (S_ISLNK(dp->mode)) {
64165 dp->proc_iops = &proc_link_inode_operations;
64166@@ -407,6 +444,27 @@ struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
64167 }
64168 EXPORT_SYMBOL_GPL(proc_mkdir_data);
64169
64170+struct proc_dir_entry *proc_mkdir_data_restrict(const char *name, umode_t mode,
64171+ struct proc_dir_entry *parent, void *data)
64172+{
64173+ struct proc_dir_entry *ent;
64174+
64175+ if (mode == 0)
64176+ mode = S_IRUGO | S_IXUGO;
64177+
64178+ ent = __proc_create(&parent, name, S_IFDIR | mode, 2);
64179+ if (ent) {
64180+ ent->data = data;
64181+ ent->restricted = 1;
64182+ if (proc_register(parent, ent) < 0) {
64183+ kfree(ent);
64184+ ent = NULL;
64185+ }
64186+ }
64187+ return ent;
64188+}
64189+EXPORT_SYMBOL_GPL(proc_mkdir_data_restrict);
64190+
64191 struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
64192 struct proc_dir_entry *parent)
64193 {
64194@@ -421,6 +479,13 @@ struct proc_dir_entry *proc_mkdir(const char *name,
64195 }
64196 EXPORT_SYMBOL(proc_mkdir);
64197
64198+struct proc_dir_entry *proc_mkdir_restrict(const char *name,
64199+ struct proc_dir_entry *parent)
64200+{
64201+ return proc_mkdir_data_restrict(name, 0, parent, NULL);
64202+}
64203+EXPORT_SYMBOL(proc_mkdir_restrict);
64204+
64205 struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
64206 struct proc_dir_entry *parent,
64207 const struct file_operations *proc_fops,
64208diff --git a/fs/proc/inode.c b/fs/proc/inode.c
64209index 124fc43..8afbb02 100644
64210--- a/fs/proc/inode.c
64211+++ b/fs/proc/inode.c
64212@@ -23,11 +23,17 @@
64213 #include <linux/slab.h>
64214 #include <linux/mount.h>
64215 #include <linux/magic.h>
64216+#include <linux/grsecurity.h>
64217
64218 #include <asm/uaccess.h>
64219
64220 #include "internal.h"
64221
64222+#ifdef CONFIG_PROC_SYSCTL
64223+extern const struct inode_operations proc_sys_inode_operations;
64224+extern const struct inode_operations proc_sys_dir_operations;
64225+#endif
64226+
64227 static void proc_evict_inode(struct inode *inode)
64228 {
64229 struct proc_dir_entry *de;
64230@@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
64231 ns = PROC_I(inode)->ns.ns;
64232 if (ns_ops && ns)
64233 ns_ops->put(ns);
64234+
64235+#ifdef CONFIG_PROC_SYSCTL
64236+ if (inode->i_op == &proc_sys_inode_operations ||
64237+ inode->i_op == &proc_sys_dir_operations)
64238+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
64239+#endif
64240+
64241 }
64242
64243 static struct kmem_cache * proc_inode_cachep;
64244@@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
64245 if (de->mode) {
64246 inode->i_mode = de->mode;
64247 inode->i_uid = de->uid;
64248+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64249+ inode->i_gid = grsec_proc_gid;
64250+#else
64251 inode->i_gid = de->gid;
64252+#endif
64253 }
64254 if (de->size)
64255 inode->i_size = de->size;
64256diff --git a/fs/proc/internal.h b/fs/proc/internal.h
64257index 651d09a..6a4b495 100644
64258--- a/fs/proc/internal.h
64259+++ b/fs/proc/internal.h
64260@@ -46,9 +46,10 @@ struct proc_dir_entry {
64261 struct completion *pde_unload_completion;
64262 struct list_head pde_openers; /* who did ->open, but not ->release */
64263 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
64264+ u8 restricted; /* a directory in /proc/net that should be restricted via GRKERNSEC_PROC */
64265 u8 namelen;
64266 char name[];
64267-};
64268+} __randomize_layout;
64269
64270 union proc_op {
64271 int (*proc_get_link)(struct dentry *, struct path *);
64272@@ -67,7 +68,7 @@ struct proc_inode {
64273 struct ctl_table *sysctl_entry;
64274 struct proc_ns ns;
64275 struct inode vfs_inode;
64276-};
64277+} __randomize_layout;
64278
64279 /*
64280 * General functions
64281@@ -155,6 +156,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
64282 struct pid *, struct task_struct *);
64283 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
64284 struct pid *, struct task_struct *);
64285+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
64286+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
64287+#endif
64288
64289 /*
64290 * base.c
64291@@ -181,9 +185,11 @@ extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, i
64292 extern spinlock_t proc_subdir_lock;
64293
64294 extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
64295+extern struct dentry *proc_lookup_restrict(struct inode *, struct dentry *, unsigned int);
64296 extern struct dentry *proc_lookup_de(struct proc_dir_entry *, struct inode *,
64297 struct dentry *);
64298 extern int proc_readdir(struct file *, struct dir_context *);
64299+extern int proc_readdir_restrict(struct file *, struct dir_context *);
64300 extern int proc_readdir_de(struct proc_dir_entry *, struct file *, struct dir_context *);
64301
64302 static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
64303diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
64304index a352d57..cb94a5c 100644
64305--- a/fs/proc/interrupts.c
64306+++ b/fs/proc/interrupts.c
64307@@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
64308
64309 static int __init proc_interrupts_init(void)
64310 {
64311+#ifdef CONFIG_GRKERNSEC_PROC_ADD
64312+ proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
64313+#else
64314 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
64315+#endif
64316 return 0;
64317 }
64318 fs_initcall(proc_interrupts_init);
64319diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
64320index 39e6ef3..2f9cb5e 100644
64321--- a/fs/proc/kcore.c
64322+++ b/fs/proc/kcore.c
64323@@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
64324 * the addresses in the elf_phdr on our list.
64325 */
64326 start = kc_offset_to_vaddr(*fpos - elf_buflen);
64327- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
64328+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
64329+ if (tsz > buflen)
64330 tsz = buflen;
64331-
64332+
64333 while (buflen) {
64334 struct kcore_list *m;
64335
64336@@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
64337 kfree(elf_buf);
64338 } else {
64339 if (kern_addr_valid(start)) {
64340- unsigned long n;
64341+ char *elf_buf;
64342+ mm_segment_t oldfs;
64343
64344- n = copy_to_user(buffer, (char *)start, tsz);
64345- /*
64346- * We cannot distinguish between fault on source
64347- * and fault on destination. When this happens
64348- * we clear too and hope it will trigger the
64349- * EFAULT again.
64350- */
64351- if (n) {
64352- if (clear_user(buffer + tsz - n,
64353- n))
64354+ elf_buf = kmalloc(tsz, GFP_KERNEL);
64355+ if (!elf_buf)
64356+ return -ENOMEM;
64357+ oldfs = get_fs();
64358+ set_fs(KERNEL_DS);
64359+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
64360+ set_fs(oldfs);
64361+ if (copy_to_user(buffer, elf_buf, tsz)) {
64362+ kfree(elf_buf);
64363 return -EFAULT;
64364+ }
64365 }
64366+ set_fs(oldfs);
64367+ kfree(elf_buf);
64368 } else {
64369 if (clear_user(buffer, tsz))
64370 return -EFAULT;
64371@@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
64372
64373 static int open_kcore(struct inode *inode, struct file *filp)
64374 {
64375+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
64376+ return -EPERM;
64377+#endif
64378 if (!capable(CAP_SYS_RAWIO))
64379 return -EPERM;
64380 if (kcore_need_update)
64381diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
64382index 136e548..1f88922 100644
64383--- a/fs/proc/meminfo.c
64384+++ b/fs/proc/meminfo.c
64385@@ -187,7 +187,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
64386 vmi.used >> 10,
64387 vmi.largest_chunk >> 10
64388 #ifdef CONFIG_MEMORY_FAILURE
64389- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
64390+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
64391 #endif
64392 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
64393 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
64394diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
64395index d4a3574..b421ce9 100644
64396--- a/fs/proc/nommu.c
64397+++ b/fs/proc/nommu.c
64398@@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
64399
64400 if (file) {
64401 seq_pad(m, ' ');
64402- seq_path(m, &file->f_path, "");
64403+ seq_path(m, &file->f_path, "\n\\");
64404 }
64405
64406 seq_putc(m, '\n');
64407diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
64408index 4677bb7..94067cd 100644
64409--- a/fs/proc/proc_net.c
64410+++ b/fs/proc/proc_net.c
64411@@ -23,6 +23,7 @@
64412 #include <linux/nsproxy.h>
64413 #include <net/net_namespace.h>
64414 #include <linux/seq_file.h>
64415+#include <linux/grsecurity.h>
64416
64417 #include "internal.h"
64418
64419@@ -36,6 +37,8 @@ static struct net *get_proc_net(const struct inode *inode)
64420 return maybe_get_net(PDE_NET(PDE(inode)));
64421 }
64422
64423+extern const struct seq_operations dev_seq_ops;
64424+
64425 int seq_open_net(struct inode *ino, struct file *f,
64426 const struct seq_operations *ops, int size)
64427 {
64428@@ -44,6 +47,10 @@ int seq_open_net(struct inode *ino, struct file *f,
64429
64430 BUG_ON(size < sizeof(*p));
64431
64432+ /* only permit access to /proc/net/dev */
64433+ if (ops != &dev_seq_ops && gr_proc_is_restricted())
64434+ return -EACCES;
64435+
64436 net = get_proc_net(ino);
64437 if (net == NULL)
64438 return -ENXIO;
64439@@ -66,6 +73,9 @@ int single_open_net(struct inode *inode, struct file *file,
64440 int err;
64441 struct net *net;
64442
64443+ if (gr_proc_is_restricted())
64444+ return -EACCES;
64445+
64446 err = -ENXIO;
64447 net = get_proc_net(inode);
64448 if (net == NULL)
64449diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
64450index 7129046..6914844 100644
64451--- a/fs/proc/proc_sysctl.c
64452+++ b/fs/proc/proc_sysctl.c
64453@@ -11,13 +11,21 @@
64454 #include <linux/namei.h>
64455 #include <linux/mm.h>
64456 #include <linux/module.h>
64457+#include <linux/nsproxy.h>
64458+#ifdef CONFIG_GRKERNSEC
64459+#include <net/net_namespace.h>
64460+#endif
64461 #include "internal.h"
64462
64463+extern int gr_handle_chroot_sysctl(const int op);
64464+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
64465+ const int op);
64466+
64467 static const struct dentry_operations proc_sys_dentry_operations;
64468 static const struct file_operations proc_sys_file_operations;
64469-static const struct inode_operations proc_sys_inode_operations;
64470+const struct inode_operations proc_sys_inode_operations;
64471 static const struct file_operations proc_sys_dir_file_operations;
64472-static const struct inode_operations proc_sys_dir_operations;
64473+const struct inode_operations proc_sys_dir_operations;
64474
64475 void proc_sys_poll_notify(struct ctl_table_poll *poll)
64476 {
64477@@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
64478
64479 err = NULL;
64480 d_set_d_op(dentry, &proc_sys_dentry_operations);
64481+
64482+ gr_handle_proc_create(dentry, inode);
64483+
64484 d_add(dentry, inode);
64485
64486 out:
64487@@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64488 struct inode *inode = file_inode(filp);
64489 struct ctl_table_header *head = grab_header(inode);
64490 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
64491+ int op = write ? MAY_WRITE : MAY_READ;
64492 ssize_t error;
64493 size_t res;
64494
64495@@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64496 * and won't be until we finish.
64497 */
64498 error = -EPERM;
64499- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
64500+ if (sysctl_perm(head, table, op))
64501 goto out;
64502
64503 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
64504@@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64505 if (!table->proc_handler)
64506 goto out;
64507
64508+#ifdef CONFIG_GRKERNSEC
64509+ error = -EPERM;
64510+ if (gr_handle_chroot_sysctl(op))
64511+ goto out;
64512+ dget(filp->f_path.dentry);
64513+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
64514+ dput(filp->f_path.dentry);
64515+ goto out;
64516+ }
64517+ dput(filp->f_path.dentry);
64518+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
64519+ goto out;
64520+ if (write) {
64521+ if (current->nsproxy->net_ns != table->extra2) {
64522+ if (!capable(CAP_SYS_ADMIN))
64523+ goto out;
64524+ } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
64525+ goto out;
64526+ }
64527+#endif
64528+
64529 /* careful: calling conventions are nasty here */
64530 res = count;
64531 error = table->proc_handler(table, write, buf, &res, ppos);
64532@@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
64533 return false;
64534 } else {
64535 d_set_d_op(child, &proc_sys_dentry_operations);
64536+
64537+ gr_handle_proc_create(child, inode);
64538+
64539 d_add(child, inode);
64540 }
64541 } else {
64542@@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
64543 if ((*pos)++ < ctx->pos)
64544 return true;
64545
64546+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
64547+ return 0;
64548+
64549 if (unlikely(S_ISLNK(table->mode)))
64550 res = proc_sys_link_fill_cache(file, ctx, head, table);
64551 else
64552@@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
64553 if (IS_ERR(head))
64554 return PTR_ERR(head);
64555
64556+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
64557+ return -ENOENT;
64558+
64559 generic_fillattr(inode, stat);
64560 if (table)
64561 stat->mode = (stat->mode & S_IFMT) | table->mode;
64562@@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
64563 .llseek = generic_file_llseek,
64564 };
64565
64566-static const struct inode_operations proc_sys_inode_operations = {
64567+const struct inode_operations proc_sys_inode_operations = {
64568 .permission = proc_sys_permission,
64569 .setattr = proc_sys_setattr,
64570 .getattr = proc_sys_getattr,
64571 };
64572
64573-static const struct inode_operations proc_sys_dir_operations = {
64574+const struct inode_operations proc_sys_dir_operations = {
64575 .lookup = proc_sys_lookup,
64576 .permission = proc_sys_permission,
64577 .setattr = proc_sys_setattr,
64578@@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
64579 static struct ctl_dir *new_dir(struct ctl_table_set *set,
64580 const char *name, int namelen)
64581 {
64582- struct ctl_table *table;
64583+ ctl_table_no_const *table;
64584 struct ctl_dir *new;
64585 struct ctl_node *node;
64586 char *new_name;
64587@@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
64588 return NULL;
64589
64590 node = (struct ctl_node *)(new + 1);
64591- table = (struct ctl_table *)(node + 1);
64592+ table = (ctl_table_no_const *)(node + 1);
64593 new_name = (char *)(table + 2);
64594 memcpy(new_name, name, namelen);
64595 new_name[namelen] = '\0';
64596@@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
64597 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
64598 struct ctl_table_root *link_root)
64599 {
64600- struct ctl_table *link_table, *entry, *link;
64601+ ctl_table_no_const *link_table, *link;
64602+ struct ctl_table *entry;
64603 struct ctl_table_header *links;
64604 struct ctl_node *node;
64605 char *link_name;
64606@@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
64607 return NULL;
64608
64609 node = (struct ctl_node *)(links + 1);
64610- link_table = (struct ctl_table *)(node + nr_entries);
64611+ link_table = (ctl_table_no_const *)(node + nr_entries);
64612 link_name = (char *)&link_table[nr_entries + 1];
64613
64614 for (link = link_table, entry = table; entry->procname; link++, entry++) {
64615@@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64616 struct ctl_table_header ***subheader, struct ctl_table_set *set,
64617 struct ctl_table *table)
64618 {
64619- struct ctl_table *ctl_table_arg = NULL;
64620- struct ctl_table *entry, *files;
64621+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
64622+ struct ctl_table *entry;
64623 int nr_files = 0;
64624 int nr_dirs = 0;
64625 int err = -ENOMEM;
64626@@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64627 nr_files++;
64628 }
64629
64630- files = table;
64631 /* If there are mixed files and directories we need a new table */
64632 if (nr_dirs && nr_files) {
64633- struct ctl_table *new;
64634+ ctl_table_no_const *new;
64635 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
64636 GFP_KERNEL);
64637 if (!files)
64638@@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64639 /* Register everything except a directory full of subdirectories */
64640 if (nr_files || !nr_dirs) {
64641 struct ctl_table_header *header;
64642- header = __register_sysctl_table(set, path, files);
64643+ header = __register_sysctl_table(set, path, files ? files : table);
64644 if (!header) {
64645 kfree(ctl_table_arg);
64646 goto out;
64647diff --git a/fs/proc/root.c b/fs/proc/root.c
64648index 87dbcbe..55e1b4d 100644
64649--- a/fs/proc/root.c
64650+++ b/fs/proc/root.c
64651@@ -186,7 +186,15 @@ void __init proc_root_init(void)
64652 #ifdef CONFIG_PROC_DEVICETREE
64653 proc_device_tree_init();
64654 #endif
64655+#ifdef CONFIG_GRKERNSEC_PROC_ADD
64656+#ifdef CONFIG_GRKERNSEC_PROC_USER
64657+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
64658+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64659+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
64660+#endif
64661+#else
64662 proc_mkdir("bus", NULL);
64663+#endif
64664 proc_sys_init();
64665 }
64666
64667diff --git a/fs/proc/stat.c b/fs/proc/stat.c
64668index 6f599c6..bd00271 100644
64669--- a/fs/proc/stat.c
64670+++ b/fs/proc/stat.c
64671@@ -11,6 +11,7 @@
64672 #include <linux/irqnr.h>
64673 #include <asm/cputime.h>
64674 #include <linux/tick.h>
64675+#include <linux/grsecurity.h>
64676
64677 #ifndef arch_irq_stat_cpu
64678 #define arch_irq_stat_cpu(cpu) 0
64679@@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
64680 u64 sum_softirq = 0;
64681 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
64682 struct timespec boottime;
64683+ int unrestricted = 1;
64684+
64685+#ifdef CONFIG_GRKERNSEC_PROC_ADD
64686+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64687+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
64688+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64689+ && !in_group_p(grsec_proc_gid)
64690+#endif
64691+ )
64692+ unrestricted = 0;
64693+#endif
64694+#endif
64695
64696 user = nice = system = idle = iowait =
64697 irq = softirq = steal = 0;
64698@@ -99,23 +112,25 @@ static int show_stat(struct seq_file *p, void *v)
64699 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
64700 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
64701 idle += get_idle_time(i);
64702- iowait += get_iowait_time(i);
64703- irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64704- softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64705- steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64706- guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64707- guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64708- sum += kstat_cpu_irqs_sum(i);
64709- sum += arch_irq_stat_cpu(i);
64710+ if (unrestricted) {
64711+ iowait += get_iowait_time(i);
64712+ irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64713+ softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64714+ steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64715+ guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64716+ guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64717+ sum += kstat_cpu_irqs_sum(i);
64718+ sum += arch_irq_stat_cpu(i);
64719+ for (j = 0; j < NR_SOFTIRQS; j++) {
64720+ unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
64721
64722- for (j = 0; j < NR_SOFTIRQS; j++) {
64723- unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
64724-
64725- per_softirq_sums[j] += softirq_stat;
64726- sum_softirq += softirq_stat;
64727+ per_softirq_sums[j] += softirq_stat;
64728+ sum_softirq += softirq_stat;
64729+ }
64730 }
64731 }
64732- sum += arch_irq_stat();
64733+ if (unrestricted)
64734+ sum += arch_irq_stat();
64735
64736 seq_puts(p, "cpu ");
64737 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
64738@@ -136,12 +151,14 @@ static int show_stat(struct seq_file *p, void *v)
64739 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
64740 system = kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
64741 idle = get_idle_time(i);
64742- iowait = get_iowait_time(i);
64743- irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64744- softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64745- steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64746- guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64747- guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64748+ if (unrestricted) {
64749+ iowait = get_iowait_time(i);
64750+ irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64751+ softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64752+ steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64753+ guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64754+ guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64755+ }
64756 seq_printf(p, "cpu%d", i);
64757 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
64758 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
64759@@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
64760
64761 /* sum again ? it could be updated? */
64762 for_each_irq_nr(j)
64763- seq_put_decimal_ull(p, ' ', kstat_irqs(j));
64764+ seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
64765
64766 seq_printf(p,
64767 "\nctxt %llu\n"
64768@@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
64769 "processes %lu\n"
64770 "procs_running %lu\n"
64771 "procs_blocked %lu\n",
64772- nr_context_switches(),
64773+ unrestricted ? nr_context_switches() : 0ULL,
64774 (unsigned long)jif,
64775- total_forks,
64776- nr_running(),
64777- nr_iowait());
64778+ unrestricted ? total_forks : 0UL,
64779+ unrestricted ? nr_running() : 0UL,
64780+ unrestricted ? nr_iowait() : 0UL);
64781
64782 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
64783
64784diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
64785index fb52b54..5fc7c14 100644
64786--- a/fs/proc/task_mmu.c
64787+++ b/fs/proc/task_mmu.c
64788@@ -12,12 +12,19 @@
64789 #include <linux/swap.h>
64790 #include <linux/swapops.h>
64791 #include <linux/mmu_notifier.h>
64792+#include <linux/grsecurity.h>
64793
64794 #include <asm/elf.h>
64795 #include <asm/uaccess.h>
64796 #include <asm/tlbflush.h>
64797 #include "internal.h"
64798
64799+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64800+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
64801+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
64802+ _mm->pax_flags & MF_PAX_SEGMEXEC))
64803+#endif
64804+
64805 void task_mem(struct seq_file *m, struct mm_struct *mm)
64806 {
64807 unsigned long data, text, lib, swap;
64808@@ -53,8 +60,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64809 "VmExe:\t%8lu kB\n"
64810 "VmLib:\t%8lu kB\n"
64811 "VmPTE:\t%8lu kB\n"
64812- "VmSwap:\t%8lu kB\n",
64813- hiwater_vm << (PAGE_SHIFT-10),
64814+ "VmSwap:\t%8lu kB\n"
64815+
64816+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
64817+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
64818+#endif
64819+
64820+ ,hiwater_vm << (PAGE_SHIFT-10),
64821 total_vm << (PAGE_SHIFT-10),
64822 mm->locked_vm << (PAGE_SHIFT-10),
64823 mm->pinned_vm << (PAGE_SHIFT-10),
64824@@ -64,7 +76,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64825 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
64826 (PTRS_PER_PTE * sizeof(pte_t) *
64827 atomic_long_read(&mm->nr_ptes)) >> 10,
64828- swap << (PAGE_SHIFT-10));
64829+ swap << (PAGE_SHIFT-10)
64830+
64831+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
64832+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64833+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
64834+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
64835+#else
64836+ , mm->context.user_cs_base
64837+ , mm->context.user_cs_limit
64838+#endif
64839+#endif
64840+
64841+ );
64842 }
64843
64844 unsigned long task_vsize(struct mm_struct *mm)
64845@@ -270,13 +294,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64846 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
64847 }
64848
64849- /* We don't show the stack guard page in /proc/maps */
64850+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64851+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
64852+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
64853+#else
64854 start = vma->vm_start;
64855- if (stack_guard_page_start(vma, start))
64856- start += PAGE_SIZE;
64857 end = vma->vm_end;
64858- if (stack_guard_page_end(vma, end))
64859- end -= PAGE_SIZE;
64860+#endif
64861
64862 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
64863 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
64864@@ -286,7 +310,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64865 flags & VM_WRITE ? 'w' : '-',
64866 flags & VM_EXEC ? 'x' : '-',
64867 flags & VM_MAYSHARE ? 's' : 'p',
64868+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64869+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
64870+#else
64871 pgoff,
64872+#endif
64873 MAJOR(dev), MINOR(dev), ino);
64874
64875 /*
64876@@ -295,7 +323,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64877 */
64878 if (file) {
64879 seq_pad(m, ' ');
64880- seq_path(m, &file->f_path, "\n");
64881+ seq_path(m, &file->f_path, "\n\\");
64882 goto done;
64883 }
64884
64885@@ -321,8 +349,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64886 * Thread stack in /proc/PID/task/TID/maps or
64887 * the main process stack.
64888 */
64889- if (!is_pid || (vma->vm_start <= mm->start_stack &&
64890- vma->vm_end >= mm->start_stack)) {
64891+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
64892+ (vma->vm_start <= mm->start_stack &&
64893+ vma->vm_end >= mm->start_stack)) {
64894 name = "[stack]";
64895 } else {
64896 /* Thread stack in /proc/PID/maps */
64897@@ -346,6 +375,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
64898 struct proc_maps_private *priv = m->private;
64899 struct task_struct *task = priv->task;
64900
64901+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64902+ if (current->exec_id != m->exec_id) {
64903+ gr_log_badprocpid("maps");
64904+ return 0;
64905+ }
64906+#endif
64907+
64908 show_map_vma(m, vma, is_pid);
64909
64910 if (m->count < m->size) /* vma is copied successfully */
64911@@ -586,12 +622,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
64912 .private = &mss,
64913 };
64914
64915+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64916+ if (current->exec_id != m->exec_id) {
64917+ gr_log_badprocpid("smaps");
64918+ return 0;
64919+ }
64920+#endif
64921 memset(&mss, 0, sizeof mss);
64922- mss.vma = vma;
64923- /* mmap_sem is held in m_start */
64924- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
64925- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
64926-
64927+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64928+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
64929+#endif
64930+ mss.vma = vma;
64931+ /* mmap_sem is held in m_start */
64932+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
64933+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
64934+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64935+ }
64936+#endif
64937 show_map_vma(m, vma, is_pid);
64938
64939 seq_printf(m,
64940@@ -609,7 +656,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
64941 "KernelPageSize: %8lu kB\n"
64942 "MMUPageSize: %8lu kB\n"
64943 "Locked: %8lu kB\n",
64944+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64945+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
64946+#else
64947 (vma->vm_end - vma->vm_start) >> 10,
64948+#endif
64949 mss.resident >> 10,
64950 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
64951 mss.shared_clean >> 10,
64952@@ -1387,6 +1438,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
64953 char buffer[64];
64954 int nid;
64955
64956+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64957+ if (current->exec_id != m->exec_id) {
64958+ gr_log_badprocpid("numa_maps");
64959+ return 0;
64960+ }
64961+#endif
64962+
64963 if (!mm)
64964 return 0;
64965
64966@@ -1404,11 +1462,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
64967 mpol_to_str(buffer, sizeof(buffer), pol);
64968 mpol_cond_put(pol);
64969
64970+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64971+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
64972+#else
64973 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
64974+#endif
64975
64976 if (file) {
64977 seq_printf(m, " file=");
64978- seq_path(m, &file->f_path, "\n\t= ");
64979+ seq_path(m, &file->f_path, "\n\t\\= ");
64980 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
64981 seq_printf(m, " heap");
64982 } else {
64983diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
64984index 678455d..ebd3245 100644
64985--- a/fs/proc/task_nommu.c
64986+++ b/fs/proc/task_nommu.c
64987@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64988 else
64989 bytes += kobjsize(mm);
64990
64991- if (current->fs && current->fs->users > 1)
64992+ if (current->fs && atomic_read(&current->fs->users) > 1)
64993 sbytes += kobjsize(current->fs);
64994 else
64995 bytes += kobjsize(current->fs);
64996@@ -161,7 +161,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
64997
64998 if (file) {
64999 seq_pad(m, ' ');
65000- seq_path(m, &file->f_path, "");
65001+ seq_path(m, &file->f_path, "\n\\");
65002 } else if (mm) {
65003 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
65004
65005diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
65006index 88d4585..c10bfeb 100644
65007--- a/fs/proc/vmcore.c
65008+++ b/fs/proc/vmcore.c
65009@@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
65010 nr_bytes = count;
65011
65012 /* If pfn is not ram, return zeros for sparse dump files */
65013- if (pfn_is_ram(pfn) == 0)
65014- memset(buf, 0, nr_bytes);
65015- else {
65016+ if (pfn_is_ram(pfn) == 0) {
65017+ if (userbuf) {
65018+ if (clear_user((char __force_user *)buf, nr_bytes))
65019+ return -EFAULT;
65020+ } else
65021+ memset(buf, 0, nr_bytes);
65022+ } else {
65023 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
65024 offset, userbuf);
65025 if (tmp < 0)
65026@@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
65027 static int copy_to(void *target, void *src, size_t size, int userbuf)
65028 {
65029 if (userbuf) {
65030- if (copy_to_user((char __user *) target, src, size))
65031+ if (copy_to_user((char __force_user *) target, src, size))
65032 return -EFAULT;
65033 } else {
65034 memcpy(target, src, size);
65035@@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
65036 if (*fpos < m->offset + m->size) {
65037 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
65038 start = m->paddr + *fpos - m->offset;
65039- tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
65040+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
65041 if (tmp < 0)
65042 return tmp;
65043 buflen -= tsz;
65044@@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
65045 static ssize_t read_vmcore(struct file *file, char __user *buffer,
65046 size_t buflen, loff_t *fpos)
65047 {
65048- return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
65049+ return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
65050 }
65051
65052 /*
65053diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
65054index b00fcc9..e0c6381 100644
65055--- a/fs/qnx6/qnx6.h
65056+++ b/fs/qnx6/qnx6.h
65057@@ -74,7 +74,7 @@ enum {
65058 BYTESEX_BE,
65059 };
65060
65061-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
65062+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
65063 {
65064 if (sbi->s_bytesex == BYTESEX_LE)
65065 return le64_to_cpu((__force __le64)n);
65066@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
65067 return (__force __fs64)cpu_to_be64(n);
65068 }
65069
65070-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
65071+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
65072 {
65073 if (sbi->s_bytesex == BYTESEX_LE)
65074 return le32_to_cpu((__force __le32)n);
65075diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
65076index 72d2917..c917c12 100644
65077--- a/fs/quota/netlink.c
65078+++ b/fs/quota/netlink.c
65079@@ -45,7 +45,7 @@ static struct genl_family quota_genl_family = {
65080 void quota_send_warning(struct kqid qid, dev_t dev,
65081 const char warntype)
65082 {
65083- static atomic_t seq;
65084+ static atomic_unchecked_t seq;
65085 struct sk_buff *skb;
65086 void *msg_head;
65087 int ret;
65088@@ -61,7 +61,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
65089 "VFS: Not enough memory to send quota warning.\n");
65090 return;
65091 }
65092- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
65093+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
65094 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
65095 if (!msg_head) {
65096 printk(KERN_ERR
65097diff --git a/fs/read_write.c b/fs/read_write.c
65098index 28cc9c8..208e4fb 100644
65099--- a/fs/read_write.c
65100+++ b/fs/read_write.c
65101@@ -450,7 +450,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
65102
65103 old_fs = get_fs();
65104 set_fs(get_ds());
65105- p = (__force const char __user *)buf;
65106+ p = (const char __force_user *)buf;
65107 if (count > MAX_RW_COUNT)
65108 count = MAX_RW_COUNT;
65109 if (file->f_op->write)
65110diff --git a/fs/readdir.c b/fs/readdir.c
65111index 5b53d99..a6c3049 100644
65112--- a/fs/readdir.c
65113+++ b/fs/readdir.c
65114@@ -17,6 +17,7 @@
65115 #include <linux/security.h>
65116 #include <linux/syscalls.h>
65117 #include <linux/unistd.h>
65118+#include <linux/namei.h>
65119
65120 #include <asm/uaccess.h>
65121
65122@@ -69,6 +70,7 @@ struct old_linux_dirent {
65123 struct readdir_callback {
65124 struct dir_context ctx;
65125 struct old_linux_dirent __user * dirent;
65126+ struct file * file;
65127 int result;
65128 };
65129
65130@@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
65131 buf->result = -EOVERFLOW;
65132 return -EOVERFLOW;
65133 }
65134+
65135+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
65136+ return 0;
65137+
65138 buf->result++;
65139 dirent = buf->dirent;
65140 if (!access_ok(VERIFY_WRITE, dirent,
65141@@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
65142 if (!f.file)
65143 return -EBADF;
65144
65145+ buf.file = f.file;
65146 error = iterate_dir(f.file, &buf.ctx);
65147 if (buf.result)
65148 error = buf.result;
65149@@ -142,6 +149,7 @@ struct getdents_callback {
65150 struct dir_context ctx;
65151 struct linux_dirent __user * current_dir;
65152 struct linux_dirent __user * previous;
65153+ struct file * file;
65154 int count;
65155 int error;
65156 };
65157@@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
65158 buf->error = -EOVERFLOW;
65159 return -EOVERFLOW;
65160 }
65161+
65162+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
65163+ return 0;
65164+
65165 dirent = buf->previous;
65166 if (dirent) {
65167 if (__put_user(offset, &dirent->d_off))
65168@@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
65169 if (!f.file)
65170 return -EBADF;
65171
65172+ buf.file = f.file;
65173 error = iterate_dir(f.file, &buf.ctx);
65174 if (error >= 0)
65175 error = buf.error;
65176@@ -226,6 +239,7 @@ struct getdents_callback64 {
65177 struct dir_context ctx;
65178 struct linux_dirent64 __user * current_dir;
65179 struct linux_dirent64 __user * previous;
65180+ struct file *file;
65181 int count;
65182 int error;
65183 };
65184@@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
65185 buf->error = -EINVAL; /* only used if we fail.. */
65186 if (reclen > buf->count)
65187 return -EINVAL;
65188+
65189+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
65190+ return 0;
65191+
65192 dirent = buf->previous;
65193 if (dirent) {
65194 if (__put_user(offset, &dirent->d_off))
65195@@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
65196 if (!f.file)
65197 return -EBADF;
65198
65199+ buf.file = f.file;
65200 error = iterate_dir(f.file, &buf.ctx);
65201 if (error >= 0)
65202 error = buf.error;
65203diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
65204index 9a3c68c..767933e 100644
65205--- a/fs/reiserfs/do_balan.c
65206+++ b/fs/reiserfs/do_balan.c
65207@@ -1546,7 +1546,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
65208 return;
65209 }
65210
65211- atomic_inc(&(fs_generation(tb->tb_sb)));
65212+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
65213 do_balance_starts(tb);
65214
65215 /* balance leaf returns 0 except if combining L R and S into
65216diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
65217index ee382ef..f4eb6eb5 100644
65218--- a/fs/reiserfs/item_ops.c
65219+++ b/fs/reiserfs/item_ops.c
65220@@ -725,18 +725,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
65221 }
65222
65223 static struct item_operations errcatch_ops = {
65224- errcatch_bytes_number,
65225- errcatch_decrement_key,
65226- errcatch_is_left_mergeable,
65227- errcatch_print_item,
65228- errcatch_check_item,
65229+ .bytes_number = errcatch_bytes_number,
65230+ .decrement_key = errcatch_decrement_key,
65231+ .is_left_mergeable = errcatch_is_left_mergeable,
65232+ .print_item = errcatch_print_item,
65233+ .check_item = errcatch_check_item,
65234
65235- errcatch_create_vi,
65236- errcatch_check_left,
65237- errcatch_check_right,
65238- errcatch_part_size,
65239- errcatch_unit_num,
65240- errcatch_print_vi
65241+ .create_vi = errcatch_create_vi,
65242+ .check_left = errcatch_check_left,
65243+ .check_right = errcatch_check_right,
65244+ .part_size = errcatch_part_size,
65245+ .unit_num = errcatch_unit_num,
65246+ .print_vi = errcatch_print_vi
65247 };
65248
65249 //////////////////////////////////////////////////////////////////////////////
65250diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
65251index 02b0b7d..c85018b 100644
65252--- a/fs/reiserfs/procfs.c
65253+++ b/fs/reiserfs/procfs.c
65254@@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
65255 "SMALL_TAILS " : "NO_TAILS ",
65256 replay_only(sb) ? "REPLAY_ONLY " : "",
65257 convert_reiserfs(sb) ? "CONV " : "",
65258- atomic_read(&r->s_generation_counter),
65259+ atomic_read_unchecked(&r->s_generation_counter),
65260 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
65261 SF(s_do_balance), SF(s_unneeded_left_neighbor),
65262 SF(s_good_search_by_key_reada), SF(s_bmaps),
65263diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
65264index 8d06adf..7e1c9f8 100644
65265--- a/fs/reiserfs/reiserfs.h
65266+++ b/fs/reiserfs/reiserfs.h
65267@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
65268 /* Comment? -Hans */
65269 wait_queue_head_t s_wait;
65270 /* To be obsoleted soon by per buffer seals.. -Hans */
65271- atomic_t s_generation_counter; // increased by one every time the
65272+ atomic_unchecked_t s_generation_counter; // increased by one every time the
65273 // tree gets re-balanced
65274 unsigned long s_properties; /* File system properties. Currently holds
65275 on-disk FS format */
65276@@ -1972,7 +1972,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
65277 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
65278
65279 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
65280-#define get_generation(s) atomic_read (&fs_generation(s))
65281+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
65282 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
65283 #define __fs_changed(gen,s) (gen != get_generation (s))
65284 #define fs_changed(gen,s) \
65285diff --git a/fs/select.c b/fs/select.c
65286index 467bb1c..cf9d65a 100644
65287--- a/fs/select.c
65288+++ b/fs/select.c
65289@@ -20,6 +20,7 @@
65290 #include <linux/export.h>
65291 #include <linux/slab.h>
65292 #include <linux/poll.h>
65293+#include <linux/security.h>
65294 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
65295 #include <linux/file.h>
65296 #include <linux/fdtable.h>
65297@@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
65298 struct poll_list *walk = head;
65299 unsigned long todo = nfds;
65300
65301+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
65302 if (nfds > rlimit(RLIMIT_NOFILE))
65303 return -EINVAL;
65304
65305diff --git a/fs/seq_file.c b/fs/seq_file.c
65306index 1d641bb..c2f4743 100644
65307--- a/fs/seq_file.c
65308+++ b/fs/seq_file.c
65309@@ -10,6 +10,8 @@
65310 #include <linux/seq_file.h>
65311 #include <linux/slab.h>
65312 #include <linux/cred.h>
65313+#include <linux/sched.h>
65314+#include <linux/grsecurity.h>
65315
65316 #include <asm/uaccess.h>
65317 #include <asm/page.h>
65318@@ -60,6 +62,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
65319 #ifdef CONFIG_USER_NS
65320 p->user_ns = file->f_cred->user_ns;
65321 #endif
65322+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65323+ p->exec_id = current->exec_id;
65324+#endif
65325
65326 /*
65327 * Wrappers around seq_open(e.g. swaps_open) need to be
65328@@ -82,6 +87,16 @@ int seq_open(struct file *file, const struct seq_operations *op)
65329 }
65330 EXPORT_SYMBOL(seq_open);
65331
65332+
65333+int seq_open_restrict(struct file *file, const struct seq_operations *op)
65334+{
65335+ if (gr_proc_is_restricted())
65336+ return -EACCES;
65337+
65338+ return seq_open(file, op);
65339+}
65340+EXPORT_SYMBOL(seq_open_restrict);
65341+
65342 static int traverse(struct seq_file *m, loff_t offset)
65343 {
65344 loff_t pos = 0, index;
65345@@ -96,7 +111,7 @@ static int traverse(struct seq_file *m, loff_t offset)
65346 return 0;
65347 }
65348 if (!m->buf) {
65349- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
65350+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
65351 if (!m->buf)
65352 return -ENOMEM;
65353 }
65354@@ -137,7 +152,7 @@ Eoverflow:
65355 m->op->stop(m, p);
65356 kfree(m->buf);
65357 m->count = 0;
65358- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
65359+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
65360 return !m->buf ? -ENOMEM : -EAGAIN;
65361 }
65362
65363@@ -153,7 +168,7 @@ Eoverflow:
65364 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
65365 {
65366 struct seq_file *m = file->private_data;
65367- size_t copied = 0;
65368+ ssize_t copied = 0;
65369 loff_t pos;
65370 size_t n;
65371 void *p;
65372@@ -192,7 +207,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
65373
65374 /* grab buffer if we didn't have one */
65375 if (!m->buf) {
65376- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
65377+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
65378 if (!m->buf)
65379 goto Enomem;
65380 }
65381@@ -234,7 +249,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
65382 m->op->stop(m, p);
65383 kfree(m->buf);
65384 m->count = 0;
65385- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
65386+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
65387 if (!m->buf)
65388 goto Enomem;
65389 m->version = 0;
65390@@ -584,7 +599,7 @@ static void single_stop(struct seq_file *p, void *v)
65391 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
65392 void *data)
65393 {
65394- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
65395+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
65396 int res = -ENOMEM;
65397
65398 if (op) {
65399@@ -620,6 +635,17 @@ int single_open_size(struct file *file, int (*show)(struct seq_file *, void *),
65400 }
65401 EXPORT_SYMBOL(single_open_size);
65402
65403+int single_open_restrict(struct file *file, int (*show)(struct seq_file *, void *),
65404+ void *data)
65405+{
65406+ if (gr_proc_is_restricted())
65407+ return -EACCES;
65408+
65409+ return single_open(file, show, data);
65410+}
65411+EXPORT_SYMBOL(single_open_restrict);
65412+
65413+
65414 int single_release(struct inode *inode, struct file *file)
65415 {
65416 const struct seq_operations *op = ((struct seq_file *)file->private_data)->op;
65417diff --git a/fs/splice.c b/fs/splice.c
65418index 12028fa..a6f2619 100644
65419--- a/fs/splice.c
65420+++ b/fs/splice.c
65421@@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65422 pipe_lock(pipe);
65423
65424 for (;;) {
65425- if (!pipe->readers) {
65426+ if (!atomic_read(&pipe->readers)) {
65427 send_sig(SIGPIPE, current, 0);
65428 if (!ret)
65429 ret = -EPIPE;
65430@@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65431 page_nr++;
65432 ret += buf->len;
65433
65434- if (pipe->files)
65435+ if (atomic_read(&pipe->files))
65436 do_wakeup = 1;
65437
65438 if (!--spd->nr_pages)
65439@@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65440 do_wakeup = 0;
65441 }
65442
65443- pipe->waiting_writers++;
65444+ atomic_inc(&pipe->waiting_writers);
65445 pipe_wait(pipe);
65446- pipe->waiting_writers--;
65447+ atomic_dec(&pipe->waiting_writers);
65448 }
65449
65450 pipe_unlock(pipe);
65451@@ -583,7 +583,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
65452 old_fs = get_fs();
65453 set_fs(get_ds());
65454 /* The cast to a user pointer is valid due to the set_fs() */
65455- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
65456+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
65457 set_fs(old_fs);
65458
65459 return res;
65460@@ -598,7 +598,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
65461 old_fs = get_fs();
65462 set_fs(get_ds());
65463 /* The cast to a user pointer is valid due to the set_fs() */
65464- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
65465+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
65466 set_fs(old_fs);
65467
65468 return res;
65469@@ -651,7 +651,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
65470 goto err;
65471
65472 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
65473- vec[i].iov_base = (void __user *) page_address(page);
65474+ vec[i].iov_base = (void __force_user *) page_address(page);
65475 vec[i].iov_len = this_len;
65476 spd.pages[i] = page;
65477 spd.nr_pages++;
65478@@ -847,7 +847,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
65479 ops->release(pipe, buf);
65480 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
65481 pipe->nrbufs--;
65482- if (pipe->files)
65483+ if (atomic_read(&pipe->files))
65484 sd->need_wakeup = true;
65485 }
65486
65487@@ -872,10 +872,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
65488 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
65489 {
65490 while (!pipe->nrbufs) {
65491- if (!pipe->writers)
65492+ if (!atomic_read(&pipe->writers))
65493 return 0;
65494
65495- if (!pipe->waiting_writers && sd->num_spliced)
65496+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
65497 return 0;
65498
65499 if (sd->flags & SPLICE_F_NONBLOCK)
65500@@ -1197,7 +1197,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
65501 * out of the pipe right after the splice_to_pipe(). So set
65502 * PIPE_READERS appropriately.
65503 */
65504- pipe->readers = 1;
65505+ atomic_set(&pipe->readers, 1);
65506
65507 current->splice_pipe = pipe;
65508 }
65509@@ -1493,6 +1493,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
65510
65511 partial[buffers].offset = off;
65512 partial[buffers].len = plen;
65513+ partial[buffers].private = 0;
65514
65515 off = 0;
65516 len -= plen;
65517@@ -1795,9 +1796,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65518 ret = -ERESTARTSYS;
65519 break;
65520 }
65521- if (!pipe->writers)
65522+ if (!atomic_read(&pipe->writers))
65523 break;
65524- if (!pipe->waiting_writers) {
65525+ if (!atomic_read(&pipe->waiting_writers)) {
65526 if (flags & SPLICE_F_NONBLOCK) {
65527 ret = -EAGAIN;
65528 break;
65529@@ -1829,7 +1830,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65530 pipe_lock(pipe);
65531
65532 while (pipe->nrbufs >= pipe->buffers) {
65533- if (!pipe->readers) {
65534+ if (!atomic_read(&pipe->readers)) {
65535 send_sig(SIGPIPE, current, 0);
65536 ret = -EPIPE;
65537 break;
65538@@ -1842,9 +1843,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65539 ret = -ERESTARTSYS;
65540 break;
65541 }
65542- pipe->waiting_writers++;
65543+ atomic_inc(&pipe->waiting_writers);
65544 pipe_wait(pipe);
65545- pipe->waiting_writers--;
65546+ atomic_dec(&pipe->waiting_writers);
65547 }
65548
65549 pipe_unlock(pipe);
65550@@ -1880,14 +1881,14 @@ retry:
65551 pipe_double_lock(ipipe, opipe);
65552
65553 do {
65554- if (!opipe->readers) {
65555+ if (!atomic_read(&opipe->readers)) {
65556 send_sig(SIGPIPE, current, 0);
65557 if (!ret)
65558 ret = -EPIPE;
65559 break;
65560 }
65561
65562- if (!ipipe->nrbufs && !ipipe->writers)
65563+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
65564 break;
65565
65566 /*
65567@@ -1984,7 +1985,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
65568 pipe_double_lock(ipipe, opipe);
65569
65570 do {
65571- if (!opipe->readers) {
65572+ if (!atomic_read(&opipe->readers)) {
65573 send_sig(SIGPIPE, current, 0);
65574 if (!ret)
65575 ret = -EPIPE;
65576@@ -2029,7 +2030,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
65577 * return EAGAIN if we have the potential of some data in the
65578 * future, otherwise just return 0
65579 */
65580- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
65581+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
65582 ret = -EAGAIN;
65583
65584 pipe_unlock(ipipe);
65585diff --git a/fs/stat.c b/fs/stat.c
65586index ae0c3ce..9ee641c 100644
65587--- a/fs/stat.c
65588+++ b/fs/stat.c
65589@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
65590 stat->gid = inode->i_gid;
65591 stat->rdev = inode->i_rdev;
65592 stat->size = i_size_read(inode);
65593- stat->atime = inode->i_atime;
65594- stat->mtime = inode->i_mtime;
65595+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
65596+ stat->atime = inode->i_ctime;
65597+ stat->mtime = inode->i_ctime;
65598+ } else {
65599+ stat->atime = inode->i_atime;
65600+ stat->mtime = inode->i_mtime;
65601+ }
65602 stat->ctime = inode->i_ctime;
65603 stat->blksize = (1 << inode->i_blkbits);
65604 stat->blocks = inode->i_blocks;
65605@@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
65606 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
65607 {
65608 struct inode *inode = path->dentry->d_inode;
65609+ int retval;
65610
65611- if (inode->i_op->getattr)
65612- return inode->i_op->getattr(path->mnt, path->dentry, stat);
65613+ if (inode->i_op->getattr) {
65614+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
65615+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
65616+ stat->atime = stat->ctime;
65617+ stat->mtime = stat->ctime;
65618+ }
65619+ return retval;
65620+ }
65621
65622 generic_fillattr(inode, stat);
65623 return 0;
65624diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
65625index ee0d761..b346c58 100644
65626--- a/fs/sysfs/dir.c
65627+++ b/fs/sysfs/dir.c
65628@@ -62,9 +62,16 @@ void sysfs_warn_dup(struct kernfs_node *parent, const char *name)
65629 int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
65630 {
65631 struct kernfs_node *parent, *kn;
65632+ const char *name;
65633+ umode_t mode = S_IRWXU | S_IRUGO | S_IXUGO;
65634+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
65635+ const char *parent_name;
65636+#endif
65637
65638 BUG_ON(!kobj);
65639
65640+ name = kobject_name(kobj);
65641+
65642 if (kobj->parent)
65643 parent = kobj->parent->sd;
65644 else
65645@@ -73,11 +80,22 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
65646 if (!parent)
65647 return -ENOENT;
65648
65649- kn = kernfs_create_dir_ns(parent, kobject_name(kobj),
65650- S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns);
65651+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
65652+ parent_name = parent->name;
65653+ mode = S_IRWXU;
65654+
65655+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
65656+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
65657+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
65658+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
65659+ mode = S_IRWXU | S_IRUGO | S_IXUGO;
65660+#endif
65661+
65662+ kn = kernfs_create_dir_ns(parent, name,
65663+ mode, kobj, ns);
65664 if (IS_ERR(kn)) {
65665 if (PTR_ERR(kn) == -EEXIST)
65666- sysfs_warn_dup(parent, kobject_name(kobj));
65667+ sysfs_warn_dup(parent, name);
65668 return PTR_ERR(kn);
65669 }
65670
65671diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
65672index 69d4889..a810bd4 100644
65673--- a/fs/sysv/sysv.h
65674+++ b/fs/sysv/sysv.h
65675@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
65676 #endif
65677 }
65678
65679-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
65680+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
65681 {
65682 if (sbi->s_bytesex == BYTESEX_PDP)
65683 return PDP_swab((__force __u32)n);
65684diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
65685index e18b988..f1d4ad0f 100644
65686--- a/fs/ubifs/io.c
65687+++ b/fs/ubifs/io.c
65688@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
65689 return err;
65690 }
65691
65692-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
65693+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
65694 {
65695 int err;
65696
65697diff --git a/fs/udf/misc.c b/fs/udf/misc.c
65698index c175b4d..8f36a16 100644
65699--- a/fs/udf/misc.c
65700+++ b/fs/udf/misc.c
65701@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
65702
65703 u8 udf_tag_checksum(const struct tag *t)
65704 {
65705- u8 *data = (u8 *)t;
65706+ const u8 *data = (const u8 *)t;
65707 u8 checksum = 0;
65708 int i;
65709 for (i = 0; i < sizeof(struct tag); ++i)
65710diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
65711index 8d974c4..b82f6ec 100644
65712--- a/fs/ufs/swab.h
65713+++ b/fs/ufs/swab.h
65714@@ -22,7 +22,7 @@ enum {
65715 BYTESEX_BE
65716 };
65717
65718-static inline u64
65719+static inline u64 __intentional_overflow(-1)
65720 fs64_to_cpu(struct super_block *sbp, __fs64 n)
65721 {
65722 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
65723@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
65724 return (__force __fs64)cpu_to_be64(n);
65725 }
65726
65727-static inline u32
65728+static inline u32 __intentional_overflow(-1)
65729 fs32_to_cpu(struct super_block *sbp, __fs32 n)
65730 {
65731 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
65732diff --git a/fs/utimes.c b/fs/utimes.c
65733index aa138d6..5f3a811 100644
65734--- a/fs/utimes.c
65735+++ b/fs/utimes.c
65736@@ -1,6 +1,7 @@
65737 #include <linux/compiler.h>
65738 #include <linux/file.h>
65739 #include <linux/fs.h>
65740+#include <linux/security.h>
65741 #include <linux/linkage.h>
65742 #include <linux/mount.h>
65743 #include <linux/namei.h>
65744@@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
65745 }
65746 }
65747 retry_deleg:
65748+
65749+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
65750+ error = -EACCES;
65751+ goto mnt_drop_write_and_out;
65752+ }
65753+
65754 mutex_lock(&inode->i_mutex);
65755 error = notify_change(path->dentry, &newattrs, &delegated_inode);
65756 mutex_unlock(&inode->i_mutex);
65757diff --git a/fs/xattr.c b/fs/xattr.c
65758index 3377dff..f394815 100644
65759--- a/fs/xattr.c
65760+++ b/fs/xattr.c
65761@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
65762 return rc;
65763 }
65764
65765+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
65766+ssize_t
65767+pax_getxattr(struct dentry *dentry, void *value, size_t size)
65768+{
65769+ struct inode *inode = dentry->d_inode;
65770+ ssize_t error;
65771+
65772+ error = inode_permission(inode, MAY_EXEC);
65773+ if (error)
65774+ return error;
65775+
65776+ if (inode->i_op->getxattr)
65777+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
65778+ else
65779+ error = -EOPNOTSUPP;
65780+
65781+ return error;
65782+}
65783+EXPORT_SYMBOL(pax_getxattr);
65784+#endif
65785+
65786 ssize_t
65787 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
65788 {
65789@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
65790 * Extended attribute SET operations
65791 */
65792 static long
65793-setxattr(struct dentry *d, const char __user *name, const void __user *value,
65794+setxattr(struct path *path, const char __user *name, const void __user *value,
65795 size_t size, int flags)
65796 {
65797 int error;
65798@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
65799 posix_acl_fix_xattr_from_user(kvalue, size);
65800 }
65801
65802- error = vfs_setxattr(d, kname, kvalue, size, flags);
65803+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
65804+ error = -EACCES;
65805+ goto out;
65806+ }
65807+
65808+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
65809 out:
65810 if (vvalue)
65811 vfree(vvalue);
65812@@ -377,7 +403,7 @@ retry:
65813 return error;
65814 error = mnt_want_write(path.mnt);
65815 if (!error) {
65816- error = setxattr(path.dentry, name, value, size, flags);
65817+ error = setxattr(&path, name, value, size, flags);
65818 mnt_drop_write(path.mnt);
65819 }
65820 path_put(&path);
65821@@ -401,7 +427,7 @@ retry:
65822 return error;
65823 error = mnt_want_write(path.mnt);
65824 if (!error) {
65825- error = setxattr(path.dentry, name, value, size, flags);
65826+ error = setxattr(&path, name, value, size, flags);
65827 mnt_drop_write(path.mnt);
65828 }
65829 path_put(&path);
65830@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
65831 const void __user *,value, size_t, size, int, flags)
65832 {
65833 struct fd f = fdget(fd);
65834- struct dentry *dentry;
65835 int error = -EBADF;
65836
65837 if (!f.file)
65838 return error;
65839- dentry = f.file->f_path.dentry;
65840- audit_inode(NULL, dentry, 0);
65841+ audit_inode(NULL, f.file->f_path.dentry, 0);
65842 error = mnt_want_write_file(f.file);
65843 if (!error) {
65844- error = setxattr(dentry, name, value, size, flags);
65845+ error = setxattr(&f.file->f_path, name, value, size, flags);
65846 mnt_drop_write_file(f.file);
65847 }
65848 fdput(f);
65849@@ -626,7 +650,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
65850 * Extended attribute REMOVE operations
65851 */
65852 static long
65853-removexattr(struct dentry *d, const char __user *name)
65854+removexattr(struct path *path, const char __user *name)
65855 {
65856 int error;
65857 char kname[XATTR_NAME_MAX + 1];
65858@@ -637,7 +661,10 @@ removexattr(struct dentry *d, const char __user *name)
65859 if (error < 0)
65860 return error;
65861
65862- return vfs_removexattr(d, kname);
65863+ if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
65864+ return -EACCES;
65865+
65866+ return vfs_removexattr(path->dentry, kname);
65867 }
65868
65869 SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
65870@@ -652,7 +679,7 @@ retry:
65871 return error;
65872 error = mnt_want_write(path.mnt);
65873 if (!error) {
65874- error = removexattr(path.dentry, name);
65875+ error = removexattr(&path, name);
65876 mnt_drop_write(path.mnt);
65877 }
65878 path_put(&path);
65879@@ -675,7 +702,7 @@ retry:
65880 return error;
65881 error = mnt_want_write(path.mnt);
65882 if (!error) {
65883- error = removexattr(path.dentry, name);
65884+ error = removexattr(&path, name);
65885 mnt_drop_write(path.mnt);
65886 }
65887 path_put(&path);
65888@@ -689,16 +716,16 @@ retry:
65889 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
65890 {
65891 struct fd f = fdget(fd);
65892- struct dentry *dentry;
65893+ struct path *path;
65894 int error = -EBADF;
65895
65896 if (!f.file)
65897 return error;
65898- dentry = f.file->f_path.dentry;
65899- audit_inode(NULL, dentry, 0);
65900+ path = &f.file->f_path;
65901+ audit_inode(NULL, path->dentry, 0);
65902 error = mnt_want_write_file(f.file);
65903 if (!error) {
65904- error = removexattr(dentry, name);
65905+ error = removexattr(path, name);
65906 mnt_drop_write_file(f.file);
65907 }
65908 fdput(f);
65909diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
65910index 152543c..d80c361 100644
65911--- a/fs/xfs/xfs_bmap.c
65912+++ b/fs/xfs/xfs_bmap.c
65913@@ -584,7 +584,7 @@ xfs_bmap_validate_ret(
65914
65915 #else
65916 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
65917-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
65918+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
65919 #endif /* DEBUG */
65920
65921 /*
65922diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
65923index aead369..0dfecfd 100644
65924--- a/fs/xfs/xfs_dir2_readdir.c
65925+++ b/fs/xfs/xfs_dir2_readdir.c
65926@@ -160,7 +160,12 @@ xfs_dir2_sf_getdents(
65927 ino = dp->d_ops->sf_get_ino(sfp, sfep);
65928 filetype = dp->d_ops->sf_get_ftype(sfep);
65929 ctx->pos = off & 0x7fffffff;
65930- if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
65931+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
65932+ char name[sfep->namelen];
65933+ memcpy(name, sfep->name, sfep->namelen);
65934+ if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(mp, filetype)))
65935+ return 0;
65936+ } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
65937 xfs_dir3_get_dtype(mp, filetype)))
65938 return 0;
65939 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
65940diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
65941index bcfe612..aa399c0 100644
65942--- a/fs/xfs/xfs_ioctl.c
65943+++ b/fs/xfs/xfs_ioctl.c
65944@@ -122,7 +122,7 @@ xfs_find_handle(
65945 }
65946
65947 error = -EFAULT;
65948- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
65949+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
65950 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
65951 goto out_put;
65952
65953diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
65954new file mode 100644
65955index 0000000..3abaf02
65956--- /dev/null
65957+++ b/grsecurity/Kconfig
65958@@ -0,0 +1,1161 @@
65959+#
65960+# grecurity configuration
65961+#
65962+menu "Memory Protections"
65963+depends on GRKERNSEC
65964+
65965+config GRKERNSEC_KMEM
65966+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
65967+ default y if GRKERNSEC_CONFIG_AUTO
65968+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
65969+ help
65970+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
65971+ be written to or read from to modify or leak the contents of the running
65972+ kernel. /dev/port will also not be allowed to be opened, writing to
65973+ /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
65974+ If you have module support disabled, enabling this will close up several
65975+ ways that are currently used to insert malicious code into the running
65976+ kernel.
65977+
65978+ Even with this feature enabled, we still highly recommend that
65979+ you use the RBAC system, as it is still possible for an attacker to
65980+ modify the running kernel through other more obscure methods.
65981+
65982+ It is highly recommended that you say Y here if you meet all the
65983+ conditions above.
65984+
65985+config GRKERNSEC_VM86
65986+ bool "Restrict VM86 mode"
65987+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65988+ depends on X86_32
65989+
65990+ help
65991+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
65992+ make use of a special execution mode on 32bit x86 processors called
65993+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
65994+ video cards and will still work with this option enabled. The purpose
65995+ of the option is to prevent exploitation of emulation errors in
65996+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
65997+ Nearly all users should be able to enable this option.
65998+
65999+config GRKERNSEC_IO
66000+ bool "Disable privileged I/O"
66001+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
66002+ depends on X86
66003+ select RTC_CLASS
66004+ select RTC_INTF_DEV
66005+ select RTC_DRV_CMOS
66006+
66007+ help
66008+ If you say Y here, all ioperm and iopl calls will return an error.
66009+ Ioperm and iopl can be used to modify the running kernel.
66010+ Unfortunately, some programs need this access to operate properly,
66011+ the most notable of which are XFree86 and hwclock. hwclock can be
66012+ remedied by having RTC support in the kernel, so real-time
66013+ clock support is enabled if this option is enabled, to ensure
66014+ that hwclock operates correctly. If hwclock still does not work,
66015+ either update udev or symlink /dev/rtc to /dev/rtc0.
66016+
66017+ If you're using XFree86 or a version of Xorg from 2012 or earlier,
66018+ you may not be able to boot into a graphical environment with this
66019+ option enabled. In this case, you should use the RBAC system instead.
66020+
66021+config GRKERNSEC_JIT_HARDEN
66022+ bool "Harden BPF JIT against spray attacks"
66023+ default y if GRKERNSEC_CONFIG_AUTO
66024+ depends on BPF_JIT && X86
66025+ help
66026+ If you say Y here, the native code generated by the kernel's Berkeley
66027+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
66028+ attacks that attempt to fit attacker-beneficial instructions in
66029+ 32bit immediate fields of JIT-generated native instructions. The
66030+ attacker will generally aim to cause an unintended instruction sequence
66031+ of JIT-generated native code to execute by jumping into the middle of
66032+ a generated instruction. This feature effectively randomizes the 32bit
66033+ immediate constants present in the generated code to thwart such attacks.
66034+
66035+ If you're using KERNEXEC, it's recommended that you enable this option
66036+ to supplement the hardening of the kernel.
66037+
66038+config GRKERNSEC_PERF_HARDEN
66039+ bool "Disable unprivileged PERF_EVENTS usage by default"
66040+ default y if GRKERNSEC_CONFIG_AUTO
66041+ depends on PERF_EVENTS
66042+ help
66043+ If you say Y here, the range of acceptable values for the
66044+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
66045+ default to a new value: 3. When the sysctl is set to this value, no
66046+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
66047+
66048+ Though PERF_EVENTS can be used legitimately for performance monitoring
66049+ and low-level application profiling, it is forced on regardless of
66050+ configuration, has been at fault for several vulnerabilities, and
66051+ creates new opportunities for side channels and other information leaks.
66052+
66053+ This feature puts PERF_EVENTS into a secure default state and permits
66054+ the administrator to change out of it temporarily if unprivileged
66055+ application profiling is needed.
66056+
66057+config GRKERNSEC_RAND_THREADSTACK
66058+ bool "Insert random gaps between thread stacks"
66059+ default y if GRKERNSEC_CONFIG_AUTO
66060+ depends on PAX_RANDMMAP && !PPC
66061+ help
66062+ If you say Y here, a random-sized gap will be enforced between allocated
66063+ thread stacks. Glibc's NPTL and other threading libraries that
66064+ pass MAP_STACK to the kernel for thread stack allocation are supported.
66065+ The implementation currently provides 8 bits of entropy for the gap.
66066+
66067+ Many distributions do not compile threaded remote services with the
66068+ -fstack-check argument to GCC, causing the variable-sized stack-based
66069+ allocator, alloca(), to not probe the stack on allocation. This
66070+ permits an unbounded alloca() to skip over any guard page and potentially
66071+ modify another thread's stack reliably. An enforced random gap
66072+ reduces the reliability of such an attack and increases the chance
66073+ that such a read/write to another thread's stack instead lands in
66074+ an unmapped area, causing a crash and triggering grsecurity's
66075+ anti-bruteforcing logic.
66076+
66077+config GRKERNSEC_PROC_MEMMAP
66078+ bool "Harden ASLR against information leaks and entropy reduction"
66079+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
66080+ depends on PAX_NOEXEC || PAX_ASLR
66081+ help
66082+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
66083+ give no information about the addresses of its mappings if
66084+ PaX features that rely on random addresses are enabled on the task.
66085+ In addition to sanitizing this information and disabling other
66086+ dangerous sources of information, this option causes reads of sensitive
66087+ /proc/<pid> entries where the file descriptor was opened in a different
66088+ task than the one performing the read. Such attempts are logged.
66089+ This option also limits argv/env strings for suid/sgid binaries
66090+ to 512KB to prevent a complete exhaustion of the stack entropy provided
66091+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
66092+ binaries to prevent alternative mmap layouts from being abused.
66093+
66094+ If you use PaX it is essential that you say Y here as it closes up
66095+ several holes that make full ASLR useless locally.
66096+
66097+config GRKERNSEC_BRUTE
66098+ bool "Deter exploit bruteforcing"
66099+ default y if GRKERNSEC_CONFIG_AUTO
66100+ help
66101+ If you say Y here, attempts to bruteforce exploits against forking
66102+ daemons such as apache or sshd, as well as against suid/sgid binaries
66103+ will be deterred. When a child of a forking daemon is killed by PaX
66104+ or crashes due to an illegal instruction or other suspicious signal,
66105+ the parent process will be delayed 30 seconds upon every subsequent
66106+ fork until the administrator is able to assess the situation and
66107+ restart the daemon.
66108+ In the suid/sgid case, the attempt is logged, the user has all their
66109+ existing instances of the suid/sgid binary terminated and will
66110+ be unable to execute any suid/sgid binaries for 15 minutes.
66111+
66112+ It is recommended that you also enable signal logging in the auditing
66113+ section so that logs are generated when a process triggers a suspicious
66114+ signal.
66115+ If the sysctl option is enabled, a sysctl option with name
66116+ "deter_bruteforce" is created.
66117+
66118+config GRKERNSEC_MODHARDEN
66119+ bool "Harden module auto-loading"
66120+ default y if GRKERNSEC_CONFIG_AUTO
66121+ depends on MODULES
66122+ help
66123+ If you say Y here, module auto-loading in response to use of some
66124+ feature implemented by an unloaded module will be restricted to
66125+ root users. Enabling this option helps defend against attacks
66126+ by unprivileged users who abuse the auto-loading behavior to
66127+ cause a vulnerable module to load that is then exploited.
66128+
66129+ If this option prevents a legitimate use of auto-loading for a
66130+ non-root user, the administrator can execute modprobe manually
66131+ with the exact name of the module mentioned in the alert log.
66132+ Alternatively, the administrator can add the module to the list
66133+ of modules loaded at boot by modifying init scripts.
66134+
66135+ Modification of init scripts will most likely be needed on
66136+ Ubuntu servers with encrypted home directory support enabled,
66137+ as the first non-root user logging in will cause the ecb(aes),
66138+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
66139+
66140+config GRKERNSEC_HIDESYM
66141+ bool "Hide kernel symbols"
66142+ default y if GRKERNSEC_CONFIG_AUTO
66143+ select PAX_USERCOPY_SLABS
66144+ help
66145+ If you say Y here, getting information on loaded modules, and
66146+ displaying all kernel symbols through a syscall will be restricted
66147+ to users with CAP_SYS_MODULE. For software compatibility reasons,
66148+ /proc/kallsyms will be restricted to the root user. The RBAC
66149+ system can hide that entry even from root.
66150+
66151+ This option also prevents leaking of kernel addresses through
66152+ several /proc entries.
66153+
66154+ Note that this option is only effective provided the following
66155+ conditions are met:
66156+ 1) The kernel using grsecurity is not precompiled by some distribution
66157+ 2) You have also enabled GRKERNSEC_DMESG
66158+ 3) You are using the RBAC system and hiding other files such as your
66159+ kernel image and System.map. Alternatively, enabling this option
66160+ causes the permissions on /boot, /lib/modules, and the kernel
66161+ source directory to change at compile time to prevent
66162+ reading by non-root users.
66163+ If the above conditions are met, this option will aid in providing a
66164+ useful protection against local kernel exploitation of overflows
66165+ and arbitrary read/write vulnerabilities.
66166+
66167+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
66168+ in addition to this feature.
66169+
66170+config GRKERNSEC_RANDSTRUCT
66171+ bool "Randomize layout of sensitive kernel structures"
66172+ default y if GRKERNSEC_CONFIG_AUTO
66173+ select GRKERNSEC_HIDESYM
66174+ select MODVERSIONS if MODULES
66175+ help
66176+ If you say Y here, the layouts of a number of sensitive kernel
66177+ structures (task, fs, cred, etc) and all structures composed entirely
66178+ of function pointers (aka "ops" structs) will be randomized at compile-time.
66179+ This can introduce the requirement of an additional infoleak
66180+ vulnerability for exploits targeting these structure types.
66181+
66182+ Enabling this feature will introduce some performance impact, slightly
66183+ increase memory usage, and prevent the use of forensic tools like
66184+ Volatility against the system (unless the kernel source tree isn't
66185+ cleaned after kernel installation).
66186+
66187+ The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
66188+ It remains after a make clean to allow for external modules to be compiled
66189+ with the existing seed and will be removed by a make mrproper or
66190+ make distclean.
66191+
66192+ Note that the implementation requires gcc 4.6.4. or newer. You may need
66193+ to install the supporting headers explicitly in addition to the normal
66194+ gcc package.
66195+
66196+config GRKERNSEC_RANDSTRUCT_PERFORMANCE
66197+ bool "Use cacheline-aware structure randomization"
66198+ depends on GRKERNSEC_RANDSTRUCT
66199+ default y if GRKERNSEC_CONFIG_PRIORITY_PERF
66200+ help
66201+ If you say Y here, the RANDSTRUCT randomization will make a best effort
66202+ at restricting randomization to cacheline-sized groups of elements. It
66203+ will further not randomize bitfields in structures. This reduces the
66204+ performance hit of RANDSTRUCT at the cost of weakened randomization.
66205+
66206+config GRKERNSEC_KERN_LOCKOUT
66207+ bool "Active kernel exploit response"
66208+ default y if GRKERNSEC_CONFIG_AUTO
66209+ depends on X86 || ARM || PPC || SPARC
66210+ help
66211+ If you say Y here, when a PaX alert is triggered due to suspicious
66212+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
66213+ or an OOPS occurs due to bad memory accesses, instead of just
66214+ terminating the offending process (and potentially allowing
66215+ a subsequent exploit from the same user), we will take one of two
66216+ actions:
66217+ If the user was root, we will panic the system
66218+ If the user was non-root, we will log the attempt, terminate
66219+ all processes owned by the user, then prevent them from creating
66220+ any new processes until the system is restarted
66221+ This deters repeated kernel exploitation/bruteforcing attempts
66222+ and is useful for later forensics.
66223+
66224+config GRKERNSEC_OLD_ARM_USERLAND
66225+ bool "Old ARM userland compatibility"
66226+ depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
66227+ help
66228+ If you say Y here, stubs of executable code to perform such operations
66229+ as "compare-exchange" will be placed at fixed locations in the ARM vector
66230+ table. This is unfortunately needed for old ARM userland meant to run
66231+ across a wide range of processors. Without this option enabled,
66232+ the get_tls and data memory barrier stubs will be emulated by the kernel,
66233+ which is enough for Linaro userlands or other userlands designed for v6
66234+ and newer ARM CPUs. It's recommended that you try without this option enabled
66235+ first, and only enable it if your userland does not boot (it will likely fail
66236+ at init time).
66237+
66238+endmenu
66239+menu "Role Based Access Control Options"
66240+depends on GRKERNSEC
66241+
66242+config GRKERNSEC_RBAC_DEBUG
66243+ bool
66244+
66245+config GRKERNSEC_NO_RBAC
66246+ bool "Disable RBAC system"
66247+ help
66248+ If you say Y here, the /dev/grsec device will be removed from the kernel,
66249+ preventing the RBAC system from being enabled. You should only say Y
66250+ here if you have no intention of using the RBAC system, so as to prevent
66251+ an attacker with root access from misusing the RBAC system to hide files
66252+ and processes when loadable module support and /dev/[k]mem have been
66253+ locked down.
66254+
66255+config GRKERNSEC_ACL_HIDEKERN
66256+ bool "Hide kernel processes"
66257+ help
66258+ If you say Y here, all kernel threads will be hidden to all
66259+ processes but those whose subject has the "view hidden processes"
66260+ flag.
66261+
66262+config GRKERNSEC_ACL_MAXTRIES
66263+ int "Maximum tries before password lockout"
66264+ default 3
66265+ help
66266+ This option enforces the maximum number of times a user can attempt
66267+ to authorize themselves with the grsecurity RBAC system before being
66268+ denied the ability to attempt authorization again for a specified time.
66269+ The lower the number, the harder it will be to brute-force a password.
66270+
66271+config GRKERNSEC_ACL_TIMEOUT
66272+ int "Time to wait after max password tries, in seconds"
66273+ default 30
66274+ help
66275+ This option specifies the time the user must wait after attempting to
66276+ authorize to the RBAC system with the maximum number of invalid
66277+ passwords. The higher the number, the harder it will be to brute-force
66278+ a password.
66279+
66280+endmenu
66281+menu "Filesystem Protections"
66282+depends on GRKERNSEC
66283+
66284+config GRKERNSEC_PROC
66285+ bool "Proc restrictions"
66286+ default y if GRKERNSEC_CONFIG_AUTO
66287+ help
66288+ If you say Y here, the permissions of the /proc filesystem
66289+ will be altered to enhance system security and privacy. You MUST
66290+ choose either a user only restriction or a user and group restriction.
66291+ Depending upon the option you choose, you can either restrict users to
66292+ see only the processes they themselves run, or choose a group that can
66293+ view all processes and files normally restricted to root if you choose
66294+ the "restrict to user only" option. NOTE: If you're running identd or
66295+ ntpd as a non-root user, you will have to run it as the group you
66296+ specify here.
66297+
66298+config GRKERNSEC_PROC_USER
66299+ bool "Restrict /proc to user only"
66300+ depends on GRKERNSEC_PROC
66301+ help
66302+ If you say Y here, non-root users will only be able to view their own
66303+ processes, and restricts them from viewing network-related information,
66304+ and viewing kernel symbol and module information.
66305+
66306+config GRKERNSEC_PROC_USERGROUP
66307+ bool "Allow special group"
66308+ default y if GRKERNSEC_CONFIG_AUTO
66309+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
66310+ help
66311+ If you say Y here, you will be able to select a group that will be
66312+ able to view all processes and network-related information. If you've
66313+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
66314+ remain hidden. This option is useful if you want to run identd as
66315+ a non-root user. The group you select may also be chosen at boot time
66316+ via "grsec_proc_gid=" on the kernel commandline.
66317+
66318+config GRKERNSEC_PROC_GID
66319+ int "GID for special group"
66320+ depends on GRKERNSEC_PROC_USERGROUP
66321+ default 1001
66322+
66323+config GRKERNSEC_PROC_ADD
66324+ bool "Additional restrictions"
66325+ default y if GRKERNSEC_CONFIG_AUTO
66326+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
66327+ help
66328+ If you say Y here, additional restrictions will be placed on
66329+ /proc that keep normal users from viewing device information and
66330+ slabinfo information that could be useful for exploits.
66331+
66332+config GRKERNSEC_LINK
66333+ bool "Linking restrictions"
66334+ default y if GRKERNSEC_CONFIG_AUTO
66335+ help
66336+ If you say Y here, /tmp race exploits will be prevented, since users
66337+ will no longer be able to follow symlinks owned by other users in
66338+ world-writable +t directories (e.g. /tmp), unless the owner of the
66339+ symlink is the owner of the directory. users will also not be
66340+ able to hardlink to files they do not own. If the sysctl option is
66341+ enabled, a sysctl option with name "linking_restrictions" is created.
66342+
66343+config GRKERNSEC_SYMLINKOWN
66344+ bool "Kernel-enforced SymlinksIfOwnerMatch"
66345+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
66346+ help
66347+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
66348+ that prevents it from being used as a security feature. As Apache
66349+ verifies the symlink by performing a stat() against the target of
66350+ the symlink before it is followed, an attacker can setup a symlink
66351+ to point to a same-owned file, then replace the symlink with one
66352+ that targets another user's file just after Apache "validates" the
66353+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
66354+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
66355+ will be in place for the group you specify. If the sysctl option
66356+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
66357+ created.
66358+
66359+config GRKERNSEC_SYMLINKOWN_GID
66360+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
66361+ depends on GRKERNSEC_SYMLINKOWN
66362+ default 1006
66363+ help
66364+ Setting this GID determines what group kernel-enforced
66365+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
66366+ is enabled, a sysctl option with name "symlinkown_gid" is created.
66367+
66368+config GRKERNSEC_FIFO
66369+ bool "FIFO restrictions"
66370+ default y if GRKERNSEC_CONFIG_AUTO
66371+ help
66372+ If you say Y here, users will not be able to write to FIFOs they don't
66373+ own in world-writable +t directories (e.g. /tmp), unless the owner of
66374+ the FIFO is the same owner of the directory it's held in. If the sysctl
66375+ option is enabled, a sysctl option with name "fifo_restrictions" is
66376+ created.
66377+
66378+config GRKERNSEC_SYSFS_RESTRICT
66379+ bool "Sysfs/debugfs restriction"
66380+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
66381+ depends on SYSFS
66382+ help
66383+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
66384+ any filesystem normally mounted under it (e.g. debugfs) will be
66385+ mostly accessible only by root. These filesystems generally provide access
66386+ to hardware and debug information that isn't appropriate for unprivileged
66387+ users of the system. Sysfs and debugfs have also become a large source
66388+ of new vulnerabilities, ranging from infoleaks to local compromise.
66389+ There has been very little oversight with an eye toward security involved
66390+ in adding new exporters of information to these filesystems, so their
66391+ use is discouraged.
66392+ For reasons of compatibility, a few directories have been whitelisted
66393+ for access by non-root users:
66394+ /sys/fs/selinux
66395+ /sys/fs/fuse
66396+ /sys/devices/system/cpu
66397+
66398+config GRKERNSEC_ROFS
66399+ bool "Runtime read-only mount protection"
66400+ depends on SYSCTL
66401+ help
66402+ If you say Y here, a sysctl option with name "romount_protect" will
66403+ be created. By setting this option to 1 at runtime, filesystems
66404+ will be protected in the following ways:
66405+ * No new writable mounts will be allowed
66406+ * Existing read-only mounts won't be able to be remounted read/write
66407+ * Write operations will be denied on all block devices
66408+ This option acts independently of grsec_lock: once it is set to 1,
66409+ it cannot be turned off. Therefore, please be mindful of the resulting
66410+ behavior if this option is enabled in an init script on a read-only
66411+ filesystem.
66412+ Also be aware that as with other root-focused features, GRKERNSEC_KMEM
66413+ and GRKERNSEC_IO should be enabled and module loading disabled via
66414+ config or at runtime.
66415+ This feature is mainly intended for secure embedded systems.
66416+
66417+
66418+config GRKERNSEC_DEVICE_SIDECHANNEL
66419+ bool "Eliminate stat/notify-based device sidechannels"
66420+ default y if GRKERNSEC_CONFIG_AUTO
66421+ help
66422+ If you say Y here, timing analyses on block or character
66423+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
66424+ will be thwarted for unprivileged users. If a process without
66425+ CAP_MKNOD stats such a device, the last access and last modify times
66426+ will match the device's create time. No access or modify events
66427+ will be triggered through inotify/dnotify/fanotify for such devices.
66428+ This feature will prevent attacks that may at a minimum
66429+ allow an attacker to determine the administrator's password length.
66430+
66431+config GRKERNSEC_CHROOT
66432+ bool "Chroot jail restrictions"
66433+ default y if GRKERNSEC_CONFIG_AUTO
66434+ help
66435+ If you say Y here, you will be able to choose several options that will
66436+ make breaking out of a chrooted jail much more difficult. If you
66437+ encounter no software incompatibilities with the following options, it
66438+ is recommended that you enable each one.
66439+
66440+ Note that the chroot restrictions are not intended to apply to "chroots"
66441+ to directories that are simple bind mounts of the global root filesystem.
66442+ For several other reasons, a user shouldn't expect any significant
66443+ security by performing such a chroot.
66444+
66445+config GRKERNSEC_CHROOT_MOUNT
66446+ bool "Deny mounts"
66447+ default y if GRKERNSEC_CONFIG_AUTO
66448+ depends on GRKERNSEC_CHROOT
66449+ help
66450+ If you say Y here, processes inside a chroot will not be able to
66451+ mount or remount filesystems. If the sysctl option is enabled, a
66452+ sysctl option with name "chroot_deny_mount" is created.
66453+
66454+config GRKERNSEC_CHROOT_DOUBLE
66455+ bool "Deny double-chroots"
66456+ default y if GRKERNSEC_CONFIG_AUTO
66457+ depends on GRKERNSEC_CHROOT
66458+ help
66459+ If you say Y here, processes inside a chroot will not be able to chroot
66460+ again outside the chroot. This is a widely used method of breaking
66461+ out of a chroot jail and should not be allowed. If the sysctl
66462+ option is enabled, a sysctl option with name
66463+ "chroot_deny_chroot" is created.
66464+
66465+config GRKERNSEC_CHROOT_PIVOT
66466+ bool "Deny pivot_root in chroot"
66467+ default y if GRKERNSEC_CONFIG_AUTO
66468+ depends on GRKERNSEC_CHROOT
66469+ help
66470+ If you say Y here, processes inside a chroot will not be able to use
66471+ a function called pivot_root() that was introduced in Linux 2.3.41. It
66472+ works similar to chroot in that it changes the root filesystem. This
66473+ function could be misused in a chrooted process to attempt to break out
66474+ of the chroot, and therefore should not be allowed. If the sysctl
66475+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
66476+ created.
66477+
66478+config GRKERNSEC_CHROOT_CHDIR
66479+ bool "Enforce chdir(\"/\") on all chroots"
66480+ default y if GRKERNSEC_CONFIG_AUTO
66481+ depends on GRKERNSEC_CHROOT
66482+ help
66483+ If you say Y here, the current working directory of all newly-chrooted
66484+ applications will be set to the the root directory of the chroot.
66485+ The man page on chroot(2) states:
66486+ Note that this call does not change the current working
66487+ directory, so that `.' can be outside the tree rooted at
66488+ `/'. In particular, the super-user can escape from a
66489+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
66490+
66491+ It is recommended that you say Y here, since it's not known to break
66492+ any software. If the sysctl option is enabled, a sysctl option with
66493+ name "chroot_enforce_chdir" is created.
66494+
66495+config GRKERNSEC_CHROOT_CHMOD
66496+ bool "Deny (f)chmod +s"
66497+ default y if GRKERNSEC_CONFIG_AUTO
66498+ depends on GRKERNSEC_CHROOT
66499+ help
66500+ If you say Y here, processes inside a chroot will not be able to chmod
66501+ or fchmod files to make them have suid or sgid bits. This protects
66502+ against another published method of breaking a chroot. If the sysctl
66503+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
66504+ created.
66505+
66506+config GRKERNSEC_CHROOT_FCHDIR
66507+ bool "Deny fchdir out of chroot"
66508+ default y if GRKERNSEC_CONFIG_AUTO
66509+ depends on GRKERNSEC_CHROOT
66510+ help
66511+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
66512+ to a file descriptor of the chrooting process that points to a directory
66513+ outside the filesystem will be stopped. If the sysctl option
66514+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
66515+
66516+config GRKERNSEC_CHROOT_MKNOD
66517+ bool "Deny mknod"
66518+ default y if GRKERNSEC_CONFIG_AUTO
66519+ depends on GRKERNSEC_CHROOT
66520+ help
66521+ If you say Y here, processes inside a chroot will not be allowed to
66522+ mknod. The problem with using mknod inside a chroot is that it
66523+ would allow an attacker to create a device entry that is the same
66524+ as one on the physical root of your system, which could range from
66525+ anything from the console device to a device for your harddrive (which
66526+ they could then use to wipe the drive or steal data). It is recommended
66527+ that you say Y here, unless you run into software incompatibilities.
66528+ If the sysctl option is enabled, a sysctl option with name
66529+ "chroot_deny_mknod" is created.
66530+
66531+config GRKERNSEC_CHROOT_SHMAT
66532+ bool "Deny shmat() out of chroot"
66533+ default y if GRKERNSEC_CONFIG_AUTO
66534+ depends on GRKERNSEC_CHROOT
66535+ help
66536+ If you say Y here, processes inside a chroot will not be able to attach
66537+ to shared memory segments that were created outside of the chroot jail.
66538+ It is recommended that you say Y here. If the sysctl option is enabled,
66539+ a sysctl option with name "chroot_deny_shmat" is created.
66540+
66541+config GRKERNSEC_CHROOT_UNIX
66542+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
66543+ default y if GRKERNSEC_CONFIG_AUTO
66544+ depends on GRKERNSEC_CHROOT
66545+ help
66546+ If you say Y here, processes inside a chroot will not be able to
66547+ connect to abstract (meaning not belonging to a filesystem) Unix
66548+ domain sockets that were bound outside of a chroot. It is recommended
66549+ that you say Y here. If the sysctl option is enabled, a sysctl option
66550+ with name "chroot_deny_unix" is created.
66551+
66552+config GRKERNSEC_CHROOT_FINDTASK
66553+ bool "Protect outside processes"
66554+ default y if GRKERNSEC_CONFIG_AUTO
66555+ depends on GRKERNSEC_CHROOT
66556+ help
66557+ If you say Y here, processes inside a chroot will not be able to
66558+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
66559+ getsid, or view any process outside of the chroot. If the sysctl
66560+ option is enabled, a sysctl option with name "chroot_findtask" is
66561+ created.
66562+
66563+config GRKERNSEC_CHROOT_NICE
66564+ bool "Restrict priority changes"
66565+ default y if GRKERNSEC_CONFIG_AUTO
66566+ depends on GRKERNSEC_CHROOT
66567+ help
66568+ If you say Y here, processes inside a chroot will not be able to raise
66569+ the priority of processes in the chroot, or alter the priority of
66570+ processes outside the chroot. This provides more security than simply
66571+ removing CAP_SYS_NICE from the process' capability set. If the
66572+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
66573+ is created.
66574+
66575+config GRKERNSEC_CHROOT_SYSCTL
66576+ bool "Deny sysctl writes"
66577+ default y if GRKERNSEC_CONFIG_AUTO
66578+ depends on GRKERNSEC_CHROOT
66579+ help
66580+ If you say Y here, an attacker in a chroot will not be able to
66581+ write to sysctl entries, either by sysctl(2) or through a /proc
66582+ interface. It is strongly recommended that you say Y here. If the
66583+ sysctl option is enabled, a sysctl option with name
66584+ "chroot_deny_sysctl" is created.
66585+
66586+config GRKERNSEC_CHROOT_CAPS
66587+ bool "Capability restrictions"
66588+ default y if GRKERNSEC_CONFIG_AUTO
66589+ depends on GRKERNSEC_CHROOT
66590+ help
66591+ If you say Y here, the capabilities on all processes within a
66592+ chroot jail will be lowered to stop module insertion, raw i/o,
66593+ system and net admin tasks, rebooting the system, modifying immutable
66594+ files, modifying IPC owned by another, and changing the system time.
66595+ This is left an option because it can break some apps. Disable this
66596+ if your chrooted apps are having problems performing those kinds of
66597+ tasks. If the sysctl option is enabled, a sysctl option with
66598+ name "chroot_caps" is created.
66599+
66600+config GRKERNSEC_CHROOT_INITRD
66601+ bool "Exempt initrd tasks from restrictions"
66602+ default y if GRKERNSEC_CONFIG_AUTO
66603+ depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
66604+ help
66605+ If you say Y here, tasks started prior to init will be exempted from
66606+ grsecurity's chroot restrictions. This option is mainly meant to
66607+ resolve Plymouth's performing privileged operations unnecessarily
66608+ in a chroot.
66609+
66610+endmenu
66611+menu "Kernel Auditing"
66612+depends on GRKERNSEC
66613+
66614+config GRKERNSEC_AUDIT_GROUP
66615+ bool "Single group for auditing"
66616+ help
66617+ If you say Y here, the exec and chdir logging features will only operate
66618+ on a group you specify. This option is recommended if you only want to
66619+ watch certain users instead of having a large amount of logs from the
66620+ entire system. If the sysctl option is enabled, a sysctl option with
66621+ name "audit_group" is created.
66622+
66623+config GRKERNSEC_AUDIT_GID
66624+ int "GID for auditing"
66625+ depends on GRKERNSEC_AUDIT_GROUP
66626+ default 1007
66627+
66628+config GRKERNSEC_EXECLOG
66629+ bool "Exec logging"
66630+ help
66631+ If you say Y here, all execve() calls will be logged (since the
66632+ other exec*() calls are frontends to execve(), all execution
66633+ will be logged). Useful for shell-servers that like to keep track
66634+ of their users. If the sysctl option is enabled, a sysctl option with
66635+ name "exec_logging" is created.
66636+ WARNING: This option when enabled will produce a LOT of logs, especially
66637+ on an active system.
66638+
66639+config GRKERNSEC_RESLOG
66640+ bool "Resource logging"
66641+ default y if GRKERNSEC_CONFIG_AUTO
66642+ help
66643+ If you say Y here, all attempts to overstep resource limits will
66644+ be logged with the resource name, the requested size, and the current
66645+ limit. It is highly recommended that you say Y here. If the sysctl
66646+ option is enabled, a sysctl option with name "resource_logging" is
66647+ created. If the RBAC system is enabled, the sysctl value is ignored.
66648+
66649+config GRKERNSEC_CHROOT_EXECLOG
66650+ bool "Log execs within chroot"
66651+ help
66652+ If you say Y here, all executions inside a chroot jail will be logged
66653+ to syslog. This can cause a large amount of logs if certain
66654+ applications (eg. djb's daemontools) are installed on the system, and
66655+ is therefore left as an option. If the sysctl option is enabled, a
66656+ sysctl option with name "chroot_execlog" is created.
66657+
66658+config GRKERNSEC_AUDIT_PTRACE
66659+ bool "Ptrace logging"
66660+ help
66661+ If you say Y here, all attempts to attach to a process via ptrace
66662+ will be logged. If the sysctl option is enabled, a sysctl option
66663+ with name "audit_ptrace" is created.
66664+
66665+config GRKERNSEC_AUDIT_CHDIR
66666+ bool "Chdir logging"
66667+ help
66668+ If you say Y here, all chdir() calls will be logged. If the sysctl
66669+ option is enabled, a sysctl option with name "audit_chdir" is created.
66670+
66671+config GRKERNSEC_AUDIT_MOUNT
66672+ bool "(Un)Mount logging"
66673+ help
66674+ If you say Y here, all mounts and unmounts will be logged. If the
66675+ sysctl option is enabled, a sysctl option with name "audit_mount" is
66676+ created.
66677+
66678+config GRKERNSEC_SIGNAL
66679+ bool "Signal logging"
66680+ default y if GRKERNSEC_CONFIG_AUTO
66681+ help
66682+ If you say Y here, certain important signals will be logged, such as
66683+ SIGSEGV, which will as a result inform you of when a error in a program
66684+ occurred, which in some cases could mean a possible exploit attempt.
66685+ If the sysctl option is enabled, a sysctl option with name
66686+ "signal_logging" is created.
66687+
66688+config GRKERNSEC_FORKFAIL
66689+ bool "Fork failure logging"
66690+ help
66691+ If you say Y here, all failed fork() attempts will be logged.
66692+ This could suggest a fork bomb, or someone attempting to overstep
66693+ their process limit. If the sysctl option is enabled, a sysctl option
66694+ with name "forkfail_logging" is created.
66695+
66696+config GRKERNSEC_TIME
66697+ bool "Time change logging"
66698+ default y if GRKERNSEC_CONFIG_AUTO
66699+ help
66700+ If you say Y here, any changes of the system clock will be logged.
66701+ If the sysctl option is enabled, a sysctl option with name
66702+ "timechange_logging" is created.
66703+
66704+config GRKERNSEC_PROC_IPADDR
66705+ bool "/proc/<pid>/ipaddr support"
66706+ default y if GRKERNSEC_CONFIG_AUTO
66707+ help
66708+ If you say Y here, a new entry will be added to each /proc/<pid>
66709+ directory that contains the IP address of the person using the task.
66710+ The IP is carried across local TCP and AF_UNIX stream sockets.
66711+ This information can be useful for IDS/IPSes to perform remote response
66712+ to a local attack. The entry is readable by only the owner of the
66713+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
66714+ the RBAC system), and thus does not create privacy concerns.
66715+
66716+config GRKERNSEC_RWXMAP_LOG
66717+ bool 'Denied RWX mmap/mprotect logging'
66718+ default y if GRKERNSEC_CONFIG_AUTO
66719+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
66720+ help
66721+ If you say Y here, calls to mmap() and mprotect() with explicit
66722+ usage of PROT_WRITE and PROT_EXEC together will be logged when
66723+ denied by the PAX_MPROTECT feature. This feature will also
66724+ log other problematic scenarios that can occur when PAX_MPROTECT
66725+ is enabled on a binary, like textrels and PT_GNU_STACK. If the
66726+ sysctl option is enabled, a sysctl option with name "rwxmap_logging"
66727+ is created.
66728+
66729+endmenu
66730+
66731+menu "Executable Protections"
66732+depends on GRKERNSEC
66733+
66734+config GRKERNSEC_DMESG
66735+ bool "Dmesg(8) restriction"
66736+ default y if GRKERNSEC_CONFIG_AUTO
66737+ help
66738+ If you say Y here, non-root users will not be able to use dmesg(8)
66739+ to view the contents of the kernel's circular log buffer.
66740+ The kernel's log buffer often contains kernel addresses and other
66741+ identifying information useful to an attacker in fingerprinting a
66742+ system for a targeted exploit.
66743+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
66744+ created.
66745+
66746+config GRKERNSEC_HARDEN_PTRACE
66747+ bool "Deter ptrace-based process snooping"
66748+ default y if GRKERNSEC_CONFIG_AUTO
66749+ help
66750+ If you say Y here, TTY sniffers and other malicious monitoring
66751+ programs implemented through ptrace will be defeated. If you
66752+ have been using the RBAC system, this option has already been
66753+ enabled for several years for all users, with the ability to make
66754+ fine-grained exceptions.
66755+
66756+ This option only affects the ability of non-root users to ptrace
66757+ processes that are not a descendent of the ptracing process.
66758+ This means that strace ./binary and gdb ./binary will still work,
66759+ but attaching to arbitrary processes will not. If the sysctl
66760+ option is enabled, a sysctl option with name "harden_ptrace" is
66761+ created.
66762+
66763+config GRKERNSEC_PTRACE_READEXEC
66764+ bool "Require read access to ptrace sensitive binaries"
66765+ default y if GRKERNSEC_CONFIG_AUTO
66766+ help
66767+ If you say Y here, unprivileged users will not be able to ptrace unreadable
66768+ binaries. This option is useful in environments that
66769+ remove the read bits (e.g. file mode 4711) from suid binaries to
66770+ prevent infoleaking of their contents. This option adds
66771+ consistency to the use of that file mode, as the binary could normally
66772+ be read out when run without privileges while ptracing.
66773+
66774+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
66775+ is created.
66776+
66777+config GRKERNSEC_SETXID
66778+ bool "Enforce consistent multithreaded privileges"
66779+ default y if GRKERNSEC_CONFIG_AUTO
66780+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
66781+ help
66782+ If you say Y here, a change from a root uid to a non-root uid
66783+ in a multithreaded application will cause the resulting uids,
66784+ gids, supplementary groups, and capabilities in that thread
66785+ to be propagated to the other threads of the process. In most
66786+ cases this is unnecessary, as glibc will emulate this behavior
66787+ on behalf of the application. Other libcs do not act in the
66788+ same way, allowing the other threads of the process to continue
66789+ running with root privileges. If the sysctl option is enabled,
66790+ a sysctl option with name "consistent_setxid" is created.
66791+
66792+config GRKERNSEC_HARDEN_IPC
66793+ bool "Disallow access to overly-permissive IPC objects"
66794+ default y if GRKERNSEC_CONFIG_AUTO
66795+ depends on SYSVIPC
66796+ help
66797+ If you say Y here, access to overly-permissive IPC objects (shared
66798+ memory, message queues, and semaphores) will be denied for processes
66799+ given the following criteria beyond normal permission checks:
66800+ 1) If the IPC object is world-accessible and the euid doesn't match
66801+ that of the creator or current uid for the IPC object
66802+ 2) If the IPC object is group-accessible and the egid doesn't
66803+ match that of the creator or current gid for the IPC object
66804+ It's a common error to grant too much permission to these objects,
66805+ with impact ranging from denial of service and information leaking to
66806+ privilege escalation. This feature was developed in response to
66807+ research by Tim Brown:
66808+ http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
66809+ who found hundreds of such insecure usages. Processes with
66810+ CAP_IPC_OWNER are still permitted to access these IPC objects.
66811+ If the sysctl option is enabled, a sysctl option with name
66812+ "harden_ipc" is created.
66813+
66814+config GRKERNSEC_TPE
66815+ bool "Trusted Path Execution (TPE)"
66816+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
66817+ help
66818+ If you say Y here, you will be able to choose a gid to add to the
66819+ supplementary groups of users you want to mark as "untrusted."
66820+ These users will not be able to execute any files that are not in
66821+ root-owned directories writable only by root. If the sysctl option
66822+ is enabled, a sysctl option with name "tpe" is created.
66823+
66824+config GRKERNSEC_TPE_ALL
66825+ bool "Partially restrict all non-root users"
66826+ depends on GRKERNSEC_TPE
66827+ help
66828+ If you say Y here, all non-root users will be covered under
66829+ a weaker TPE restriction. This is separate from, and in addition to,
66830+ the main TPE options that you have selected elsewhere. Thus, if a
66831+ "trusted" GID is chosen, this restriction applies to even that GID.
66832+ Under this restriction, all non-root users will only be allowed to
66833+ execute files in directories they own that are not group or
66834+ world-writable, or in directories owned by root and writable only by
66835+ root. If the sysctl option is enabled, a sysctl option with name
66836+ "tpe_restrict_all" is created.
66837+
66838+config GRKERNSEC_TPE_INVERT
66839+ bool "Invert GID option"
66840+ depends on GRKERNSEC_TPE
66841+ help
66842+ If you say Y here, the group you specify in the TPE configuration will
66843+ decide what group TPE restrictions will be *disabled* for. This
66844+ option is useful if you want TPE restrictions to be applied to most
66845+ users on the system. If the sysctl option is enabled, a sysctl option
66846+ with name "tpe_invert" is created. Unlike other sysctl options, this
66847+ entry will default to on for backward-compatibility.
66848+
66849+config GRKERNSEC_TPE_GID
66850+ int
66851+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
66852+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
66853+
66854+config GRKERNSEC_TPE_UNTRUSTED_GID
66855+ int "GID for TPE-untrusted users"
66856+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
66857+ default 1005
66858+ help
66859+ Setting this GID determines what group TPE restrictions will be
66860+ *enabled* for. If the sysctl option is enabled, a sysctl option
66861+ with name "tpe_gid" is created.
66862+
66863+config GRKERNSEC_TPE_TRUSTED_GID
66864+ int "GID for TPE-trusted users"
66865+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
66866+ default 1005
66867+ help
66868+ Setting this GID determines what group TPE restrictions will be
66869+ *disabled* for. If the sysctl option is enabled, a sysctl option
66870+ with name "tpe_gid" is created.
66871+
66872+endmenu
66873+menu "Network Protections"
66874+depends on GRKERNSEC
66875+
66876+config GRKERNSEC_RANDNET
66877+ bool "Larger entropy pools"
66878+ default y if GRKERNSEC_CONFIG_AUTO
66879+ help
66880+ If you say Y here, the entropy pools used for many features of Linux
66881+ and grsecurity will be doubled in size. Since several grsecurity
66882+ features use additional randomness, it is recommended that you say Y
66883+ here. Saying Y here has a similar effect as modifying
66884+ /proc/sys/kernel/random/poolsize.
66885+
66886+config GRKERNSEC_BLACKHOLE
66887+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
66888+ default y if GRKERNSEC_CONFIG_AUTO
66889+ depends on NET
66890+ help
66891+ If you say Y here, neither TCP resets nor ICMP
66892+ destination-unreachable packets will be sent in response to packets
66893+ sent to ports for which no associated listening process exists.
66894+ This feature supports both IPV4 and IPV6 and exempts the
66895+ loopback interface from blackholing. Enabling this feature
66896+ makes a host more resilient to DoS attacks and reduces network
66897+ visibility against scanners.
66898+
66899+ The blackhole feature as-implemented is equivalent to the FreeBSD
66900+ blackhole feature, as it prevents RST responses to all packets, not
66901+ just SYNs. Under most application behavior this causes no
66902+ problems, but applications (like haproxy) may not close certain
66903+ connections in a way that cleanly terminates them on the remote
66904+ end, leaving the remote host in LAST_ACK state. Because of this
66905+ side-effect and to prevent intentional LAST_ACK DoSes, this
66906+ feature also adds automatic mitigation against such attacks.
66907+ The mitigation drastically reduces the amount of time a socket
66908+ can spend in LAST_ACK state. If you're using haproxy and not
66909+ all servers it connects to have this option enabled, consider
66910+ disabling this feature on the haproxy host.
66911+
66912+ If the sysctl option is enabled, two sysctl options with names
66913+ "ip_blackhole" and "lastack_retries" will be created.
66914+ While "ip_blackhole" takes the standard zero/non-zero on/off
66915+ toggle, "lastack_retries" uses the same kinds of values as
66916+ "tcp_retries1" and "tcp_retries2". The default value of 4
66917+ prevents a socket from lasting more than 45 seconds in LAST_ACK
66918+ state.
66919+
66920+config GRKERNSEC_NO_SIMULT_CONNECT
66921+ bool "Disable TCP Simultaneous Connect"
66922+ default y if GRKERNSEC_CONFIG_AUTO
66923+ depends on NET
66924+ help
66925+ If you say Y here, a feature by Willy Tarreau will be enabled that
66926+ removes a weakness in Linux's strict implementation of TCP that
66927+ allows two clients to connect to each other without either entering
66928+ a listening state. The weakness allows an attacker to easily prevent
66929+ a client from connecting to a known server provided the source port
66930+ for the connection is guessed correctly.
66931+
66932+ As the weakness could be used to prevent an antivirus or IPS from
66933+ fetching updates, or prevent an SSL gateway from fetching a CRL,
66934+ it should be eliminated by enabling this option. Though Linux is
66935+ one of few operating systems supporting simultaneous connect, it
66936+ has no legitimate use in practice and is rarely supported by firewalls.
66937+
66938+config GRKERNSEC_SOCKET
66939+ bool "Socket restrictions"
66940+ depends on NET
66941+ help
66942+ If you say Y here, you will be able to choose from several options.
66943+ If you assign a GID on your system and add it to the supplementary
66944+ groups of users you want to restrict socket access to, this patch
66945+ will perform up to three things, based on the option(s) you choose.
66946+
66947+config GRKERNSEC_SOCKET_ALL
66948+ bool "Deny any sockets to group"
66949+ depends on GRKERNSEC_SOCKET
66950+ help
66951+ If you say Y here, you will be able to choose a GID of whose users will
66952+ be unable to connect to other hosts from your machine or run server
66953+ applications from your machine. If the sysctl option is enabled, a
66954+ sysctl option with name "socket_all" is created.
66955+
66956+config GRKERNSEC_SOCKET_ALL_GID
66957+ int "GID to deny all sockets for"
66958+ depends on GRKERNSEC_SOCKET_ALL
66959+ default 1004
66960+ help
66961+ Here you can choose the GID to disable socket access for. Remember to
66962+ add the users you want socket access disabled for to the GID
66963+ specified here. If the sysctl option is enabled, a sysctl option
66964+ with name "socket_all_gid" is created.
66965+
66966+config GRKERNSEC_SOCKET_CLIENT
66967+ bool "Deny client sockets to group"
66968+ depends on GRKERNSEC_SOCKET
66969+ help
66970+ If you say Y here, you will be able to choose a GID of whose users will
66971+ be unable to connect to other hosts from your machine, but will be
66972+ able to run servers. If this option is enabled, all users in the group
66973+ you specify will have to use passive mode when initiating ftp transfers
66974+ from the shell on your machine. If the sysctl option is enabled, a
66975+ sysctl option with name "socket_client" is created.
66976+
66977+config GRKERNSEC_SOCKET_CLIENT_GID
66978+ int "GID to deny client sockets for"
66979+ depends on GRKERNSEC_SOCKET_CLIENT
66980+ default 1003
66981+ help
66982+ Here you can choose the GID to disable client socket access for.
66983+ Remember to add the users you want client socket access disabled for to
66984+ the GID specified here. If the sysctl option is enabled, a sysctl
66985+ option with name "socket_client_gid" is created.
66986+
66987+config GRKERNSEC_SOCKET_SERVER
66988+ bool "Deny server sockets to group"
66989+ depends on GRKERNSEC_SOCKET
66990+ help
66991+ If you say Y here, you will be able to choose a GID of whose users will
66992+ be unable to run server applications from your machine. If the sysctl
66993+ option is enabled, a sysctl option with name "socket_server" is created.
66994+
66995+config GRKERNSEC_SOCKET_SERVER_GID
66996+ int "GID to deny server sockets for"
66997+ depends on GRKERNSEC_SOCKET_SERVER
66998+ default 1002
66999+ help
67000+ Here you can choose the GID to disable server socket access for.
67001+ Remember to add the users you want server socket access disabled for to
67002+ the GID specified here. If the sysctl option is enabled, a sysctl
67003+ option with name "socket_server_gid" is created.
67004+
67005+endmenu
67006+
67007+menu "Physical Protections"
67008+depends on GRKERNSEC
67009+
67010+config GRKERNSEC_DENYUSB
67011+ bool "Deny new USB connections after toggle"
67012+ default y if GRKERNSEC_CONFIG_AUTO
67013+ depends on SYSCTL && USB_SUPPORT
67014+ help
67015+ If you say Y here, a new sysctl option with name "deny_new_usb"
67016+ will be created. Setting its value to 1 will prevent any new
67017+ USB devices from being recognized by the OS. Any attempted USB
67018+ device insertion will be logged. This option is intended to be
67019+ used against custom USB devices designed to exploit vulnerabilities
67020+ in various USB device drivers.
67021+
67022+ For greatest effectiveness, this sysctl should be set after any
67023+ relevant init scripts. This option is safe to enable in distros
67024+ as each user can choose whether or not to toggle the sysctl.
67025+
67026+config GRKERNSEC_DENYUSB_FORCE
67027+ bool "Reject all USB devices not connected at boot"
67028+ select USB
67029+ depends on GRKERNSEC_DENYUSB
67030+ help
67031+ If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
67032+ that doesn't involve a sysctl entry. This option should only be
67033+ enabled if you're sure you want to deny all new USB connections
67034+ at runtime and don't want to modify init scripts. This should not
67035+ be enabled by distros. It forces the core USB code to be built
67036+ into the kernel image so that all devices connected at boot time
67037+ can be recognized and new USB device connections can be prevented
67038+ prior to init running.
67039+
67040+endmenu
67041+
67042+menu "Sysctl Support"
67043+depends on GRKERNSEC && SYSCTL
67044+
67045+config GRKERNSEC_SYSCTL
67046+ bool "Sysctl support"
67047+ default y if GRKERNSEC_CONFIG_AUTO
67048+ help
67049+ If you say Y here, you will be able to change the options that
67050+ grsecurity runs with at bootup, without having to recompile your
67051+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
67052+ to enable (1) or disable (0) various features. All the sysctl entries
67053+ are mutable until the "grsec_lock" entry is set to a non-zero value.
67054+ All features enabled in the kernel configuration are disabled at boot
67055+ if you do not say Y to the "Turn on features by default" option.
67056+ All options should be set at startup, and the grsec_lock entry should
67057+ be set to a non-zero value after all the options are set.
67058+ *THIS IS EXTREMELY IMPORTANT*
67059+
67060+config GRKERNSEC_SYSCTL_DISTRO
67061+ bool "Extra sysctl support for distro makers (READ HELP)"
67062+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
67063+ help
67064+ If you say Y here, additional sysctl options will be created
67065+ for features that affect processes running as root. Therefore,
67066+ it is critical when using this option that the grsec_lock entry be
67067+ enabled after boot. Only distros with prebuilt kernel packages
67068+ with this option enabled that can ensure grsec_lock is enabled
67069+ after boot should use this option.
67070+ *Failure to set grsec_lock after boot makes all grsec features
67071+ this option covers useless*
67072+
67073+ Currently this option creates the following sysctl entries:
67074+ "Disable Privileged I/O": "disable_priv_io"
67075+
67076+config GRKERNSEC_SYSCTL_ON
67077+ bool "Turn on features by default"
67078+ default y if GRKERNSEC_CONFIG_AUTO
67079+ depends on GRKERNSEC_SYSCTL
67080+ help
67081+ If you say Y here, instead of having all features enabled in the
67082+ kernel configuration disabled at boot time, the features will be
67083+ enabled at boot time. It is recommended you say Y here unless
67084+ there is some reason you would want all sysctl-tunable features to
67085+ be disabled by default. As mentioned elsewhere, it is important
67086+ to enable the grsec_lock entry once you have finished modifying
67087+ the sysctl entries.
67088+
67089+endmenu
67090+menu "Logging Options"
67091+depends on GRKERNSEC
67092+
67093+config GRKERNSEC_FLOODTIME
67094+ int "Seconds in between log messages (minimum)"
67095+ default 10
67096+ help
67097+ This option allows you to enforce the number of seconds between
67098+ grsecurity log messages. The default should be suitable for most
67099+ people, however, if you choose to change it, choose a value small enough
67100+ to allow informative logs to be produced, but large enough to
67101+ prevent flooding.
67102+
67103+ Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
67104+ any rate limiting on grsecurity log messages.
67105+
67106+config GRKERNSEC_FLOODBURST
67107+ int "Number of messages in a burst (maximum)"
67108+ default 6
67109+ help
67110+ This option allows you to choose the maximum number of messages allowed
67111+ within the flood time interval you chose in a separate option. The
67112+ default should be suitable for most people, however if you find that
67113+ many of your logs are being interpreted as flooding, you may want to
67114+ raise this value.
67115+
67116+ Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
67117+ any rate limiting on grsecurity log messages.
67118+
67119+endmenu
67120diff --git a/grsecurity/Makefile b/grsecurity/Makefile
67121new file mode 100644
67122index 0000000..30ababb
67123--- /dev/null
67124+++ b/grsecurity/Makefile
67125@@ -0,0 +1,54 @@
67126+# grsecurity – access control and security hardening for Linux
67127+# All code in this directory and various hooks located throughout the Linux kernel are
67128+# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
67129+# http://www.grsecurity.net spender@grsecurity.net
67130+#
67131+# This program is free software; you can redistribute it and/or
67132+# modify it under the terms of the GNU General Public License version 2
67133+# as published by the Free Software Foundation.
67134+#
67135+# This program is distributed in the hope that it will be useful,
67136+# but WITHOUT ANY WARRANTY; without even the implied warranty of
67137+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
67138+# GNU General Public License for more details.
67139+#
67140+# You should have received a copy of the GNU General Public License
67141+# along with this program; if not, write to the Free Software
67142+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
67143+
67144+KBUILD_CFLAGS += -Werror
67145+
67146+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
67147+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
67148+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
67149+ grsec_usb.o grsec_ipc.o grsec_proc.o
67150+
67151+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
67152+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
67153+ gracl_learn.o grsec_log.o gracl_policy.o
67154+ifdef CONFIG_COMPAT
67155+obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
67156+endif
67157+
67158+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
67159+
67160+ifdef CONFIG_NET
67161+obj-y += grsec_sock.o
67162+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
67163+endif
67164+
67165+ifndef CONFIG_GRKERNSEC
67166+obj-y += grsec_disabled.o
67167+endif
67168+
67169+ifdef CONFIG_GRKERNSEC_HIDESYM
67170+extra-y := grsec_hidesym.o
67171+$(obj)/grsec_hidesym.o:
67172+ @-chmod -f 500 /boot
67173+ @-chmod -f 500 /lib/modules
67174+ @-chmod -f 500 /lib64/modules
67175+ @-chmod -f 500 /lib32/modules
67176+ @-chmod -f 700 .
67177+ @-chmod -f 700 $(objtree)
67178+ @echo ' grsec: protected kernel image paths'
67179+endif
67180diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
67181new file mode 100644
67182index 0000000..e56396f
67183--- /dev/null
67184+++ b/grsecurity/gracl.c
67185@@ -0,0 +1,2679 @@
67186+#include <linux/kernel.h>
67187+#include <linux/module.h>
67188+#include <linux/sched.h>
67189+#include <linux/mm.h>
67190+#include <linux/file.h>
67191+#include <linux/fs.h>
67192+#include <linux/namei.h>
67193+#include <linux/mount.h>
67194+#include <linux/tty.h>
67195+#include <linux/proc_fs.h>
67196+#include <linux/lglock.h>
67197+#include <linux/slab.h>
67198+#include <linux/vmalloc.h>
67199+#include <linux/types.h>
67200+#include <linux/sysctl.h>
67201+#include <linux/netdevice.h>
67202+#include <linux/ptrace.h>
67203+#include <linux/gracl.h>
67204+#include <linux/gralloc.h>
67205+#include <linux/security.h>
67206+#include <linux/grinternal.h>
67207+#include <linux/pid_namespace.h>
67208+#include <linux/stop_machine.h>
67209+#include <linux/fdtable.h>
67210+#include <linux/percpu.h>
67211+#include <linux/lglock.h>
67212+#include <linux/hugetlb.h>
67213+#include <linux/posix-timers.h>
67214+#include <linux/prefetch.h>
67215+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
67216+#include <linux/magic.h>
67217+#include <linux/pagemap.h>
67218+#include "../fs/btrfs/async-thread.h"
67219+#include "../fs/btrfs/ctree.h"
67220+#include "../fs/btrfs/btrfs_inode.h"
67221+#endif
67222+#include "../fs/mount.h"
67223+
67224+#include <asm/uaccess.h>
67225+#include <asm/errno.h>
67226+#include <asm/mman.h>
67227+
67228+#define FOR_EACH_ROLE_START(role) \
67229+ role = running_polstate.role_list; \
67230+ while (role) {
67231+
67232+#define FOR_EACH_ROLE_END(role) \
67233+ role = role->prev; \
67234+ }
67235+
67236+extern struct path gr_real_root;
67237+
67238+static struct gr_policy_state running_polstate;
67239+struct gr_policy_state *polstate = &running_polstate;
67240+extern struct gr_alloc_state *current_alloc_state;
67241+
67242+extern char *gr_shared_page[4];
67243+DEFINE_RWLOCK(gr_inode_lock);
67244+
67245+static unsigned int gr_status __read_only = GR_STATUS_INIT;
67246+
67247+#ifdef CONFIG_NET
67248+extern struct vfsmount *sock_mnt;
67249+#endif
67250+
67251+extern struct vfsmount *pipe_mnt;
67252+extern struct vfsmount *shm_mnt;
67253+
67254+#ifdef CONFIG_HUGETLBFS
67255+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
67256+#endif
67257+
67258+extern u16 acl_sp_role_value;
67259+extern struct acl_object_label *fakefs_obj_rw;
67260+extern struct acl_object_label *fakefs_obj_rwx;
67261+
67262+int gr_acl_is_enabled(void)
67263+{
67264+ return (gr_status & GR_READY);
67265+}
67266+
67267+void gr_enable_rbac_system(void)
67268+{
67269+ pax_open_kernel();
67270+ gr_status |= GR_READY;
67271+ pax_close_kernel();
67272+}
67273+
67274+int gr_rbac_disable(void *unused)
67275+{
67276+ pax_open_kernel();
67277+ gr_status &= ~GR_READY;
67278+ pax_close_kernel();
67279+
67280+ return 0;
67281+}
67282+
67283+static inline dev_t __get_dev(const struct dentry *dentry)
67284+{
67285+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
67286+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
67287+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
67288+ else
67289+#endif
67290+ return dentry->d_sb->s_dev;
67291+}
67292+
67293+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
67294+{
67295+ return __get_dev(dentry);
67296+}
67297+
67298+static char gr_task_roletype_to_char(struct task_struct *task)
67299+{
67300+ switch (task->role->roletype &
67301+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
67302+ GR_ROLE_SPECIAL)) {
67303+ case GR_ROLE_DEFAULT:
67304+ return 'D';
67305+ case GR_ROLE_USER:
67306+ return 'U';
67307+ case GR_ROLE_GROUP:
67308+ return 'G';
67309+ case GR_ROLE_SPECIAL:
67310+ return 'S';
67311+ }
67312+
67313+ return 'X';
67314+}
67315+
67316+char gr_roletype_to_char(void)
67317+{
67318+ return gr_task_roletype_to_char(current);
67319+}
67320+
67321+__inline__ int
67322+gr_acl_tpe_check(void)
67323+{
67324+ if (unlikely(!(gr_status & GR_READY)))
67325+ return 0;
67326+ if (current->role->roletype & GR_ROLE_TPE)
67327+ return 1;
67328+ else
67329+ return 0;
67330+}
67331+
67332+int
67333+gr_handle_rawio(const struct inode *inode)
67334+{
67335+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
67336+ if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
67337+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
67338+ !capable(CAP_SYS_RAWIO))
67339+ return 1;
67340+#endif
67341+ return 0;
67342+}
67343+
67344+int
67345+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
67346+{
67347+ if (likely(lena != lenb))
67348+ return 0;
67349+
67350+ return !memcmp(a, b, lena);
67351+}
67352+
67353+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
67354+{
67355+ *buflen -= namelen;
67356+ if (*buflen < 0)
67357+ return -ENAMETOOLONG;
67358+ *buffer -= namelen;
67359+ memcpy(*buffer, str, namelen);
67360+ return 0;
67361+}
67362+
67363+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
67364+{
67365+ return prepend(buffer, buflen, name->name, name->len);
67366+}
67367+
67368+static int prepend_path(const struct path *path, struct path *root,
67369+ char **buffer, int *buflen)
67370+{
67371+ struct dentry *dentry = path->dentry;
67372+ struct vfsmount *vfsmnt = path->mnt;
67373+ struct mount *mnt = real_mount(vfsmnt);
67374+ bool slash = false;
67375+ int error = 0;
67376+
67377+ while (dentry != root->dentry || vfsmnt != root->mnt) {
67378+ struct dentry * parent;
67379+
67380+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
67381+ /* Global root? */
67382+ if (!mnt_has_parent(mnt)) {
67383+ goto out;
67384+ }
67385+ dentry = mnt->mnt_mountpoint;
67386+ mnt = mnt->mnt_parent;
67387+ vfsmnt = &mnt->mnt;
67388+ continue;
67389+ }
67390+ parent = dentry->d_parent;
67391+ prefetch(parent);
67392+ spin_lock(&dentry->d_lock);
67393+ error = prepend_name(buffer, buflen, &dentry->d_name);
67394+ spin_unlock(&dentry->d_lock);
67395+ if (!error)
67396+ error = prepend(buffer, buflen, "/", 1);
67397+ if (error)
67398+ break;
67399+
67400+ slash = true;
67401+ dentry = parent;
67402+ }
67403+
67404+out:
67405+ if (!error && !slash)
67406+ error = prepend(buffer, buflen, "/", 1);
67407+
67408+ return error;
67409+}
67410+
67411+/* this must be called with mount_lock and rename_lock held */
67412+
67413+static char *__our_d_path(const struct path *path, struct path *root,
67414+ char *buf, int buflen)
67415+{
67416+ char *res = buf + buflen;
67417+ int error;
67418+
67419+ prepend(&res, &buflen, "\0", 1);
67420+ error = prepend_path(path, root, &res, &buflen);
67421+ if (error)
67422+ return ERR_PTR(error);
67423+
67424+ return res;
67425+}
67426+
67427+static char *
67428+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
67429+{
67430+ char *retval;
67431+
67432+ retval = __our_d_path(path, root, buf, buflen);
67433+ if (unlikely(IS_ERR(retval)))
67434+ retval = strcpy(buf, "<path too long>");
67435+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
67436+ retval[1] = '\0';
67437+
67438+ return retval;
67439+}
67440+
67441+static char *
67442+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
67443+ char *buf, int buflen)
67444+{
67445+ struct path path;
67446+ char *res;
67447+
67448+ path.dentry = (struct dentry *)dentry;
67449+ path.mnt = (struct vfsmount *)vfsmnt;
67450+
67451+ /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
67452+ by the RBAC system */
67453+ res = gen_full_path(&path, &gr_real_root, buf, buflen);
67454+
67455+ return res;
67456+}
67457+
67458+static char *
67459+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
67460+ char *buf, int buflen)
67461+{
67462+ char *res;
67463+ struct path path;
67464+ struct path root;
67465+ struct task_struct *reaper = init_pid_ns.child_reaper;
67466+
67467+ path.dentry = (struct dentry *)dentry;
67468+ path.mnt = (struct vfsmount *)vfsmnt;
67469+
67470+ /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
67471+ get_fs_root(reaper->fs, &root);
67472+
67473+ read_seqlock_excl(&mount_lock);
67474+ write_seqlock(&rename_lock);
67475+ res = gen_full_path(&path, &root, buf, buflen);
67476+ write_sequnlock(&rename_lock);
67477+ read_sequnlock_excl(&mount_lock);
67478+
67479+ path_put(&root);
67480+ return res;
67481+}
67482+
67483+char *
67484+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
67485+{
67486+ char *ret;
67487+ read_seqlock_excl(&mount_lock);
67488+ write_seqlock(&rename_lock);
67489+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
67490+ PAGE_SIZE);
67491+ write_sequnlock(&rename_lock);
67492+ read_sequnlock_excl(&mount_lock);
67493+ return ret;
67494+}
67495+
67496+static char *
67497+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
67498+{
67499+ char *ret;
67500+ char *buf;
67501+ int buflen;
67502+
67503+ read_seqlock_excl(&mount_lock);
67504+ write_seqlock(&rename_lock);
67505+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
67506+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
67507+ buflen = (int)(ret - buf);
67508+ if (buflen >= 5)
67509+ prepend(&ret, &buflen, "/proc", 5);
67510+ else
67511+ ret = strcpy(buf, "<path too long>");
67512+ write_sequnlock(&rename_lock);
67513+ read_sequnlock_excl(&mount_lock);
67514+ return ret;
67515+}
67516+
67517+char *
67518+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
67519+{
67520+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
67521+ PAGE_SIZE);
67522+}
67523+
67524+char *
67525+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
67526+{
67527+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
67528+ PAGE_SIZE);
67529+}
67530+
67531+char *
67532+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
67533+{
67534+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
67535+ PAGE_SIZE);
67536+}
67537+
67538+char *
67539+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
67540+{
67541+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
67542+ PAGE_SIZE);
67543+}
67544+
67545+char *
67546+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
67547+{
67548+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
67549+ PAGE_SIZE);
67550+}
67551+
67552+__inline__ __u32
67553+to_gr_audit(const __u32 reqmode)
67554+{
67555+ /* masks off auditable permission flags, then shifts them to create
67556+ auditing flags, and adds the special case of append auditing if
67557+ we're requesting write */
67558+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
67559+}
67560+
67561+struct acl_role_label *
67562+__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
67563+ const gid_t gid)
67564+{
67565+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
67566+ struct acl_role_label *match;
67567+ struct role_allowed_ip *ipp;
67568+ unsigned int x;
67569+ u32 curr_ip = task->signal->saved_ip;
67570+
67571+ match = state->acl_role_set.r_hash[index];
67572+
67573+ while (match) {
67574+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
67575+ for (x = 0; x < match->domain_child_num; x++) {
67576+ if (match->domain_children[x] == uid)
67577+ goto found;
67578+ }
67579+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
67580+ break;
67581+ match = match->next;
67582+ }
67583+found:
67584+ if (match == NULL) {
67585+ try_group:
67586+ index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
67587+ match = state->acl_role_set.r_hash[index];
67588+
67589+ while (match) {
67590+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
67591+ for (x = 0; x < match->domain_child_num; x++) {
67592+ if (match->domain_children[x] == gid)
67593+ goto found2;
67594+ }
67595+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
67596+ break;
67597+ match = match->next;
67598+ }
67599+found2:
67600+ if (match == NULL)
67601+ match = state->default_role;
67602+ if (match->allowed_ips == NULL)
67603+ return match;
67604+ else {
67605+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
67606+ if (likely
67607+ ((ntohl(curr_ip) & ipp->netmask) ==
67608+ (ntohl(ipp->addr) & ipp->netmask)))
67609+ return match;
67610+ }
67611+ match = state->default_role;
67612+ }
67613+ } else if (match->allowed_ips == NULL) {
67614+ return match;
67615+ } else {
67616+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
67617+ if (likely
67618+ ((ntohl(curr_ip) & ipp->netmask) ==
67619+ (ntohl(ipp->addr) & ipp->netmask)))
67620+ return match;
67621+ }
67622+ goto try_group;
67623+ }
67624+
67625+ return match;
67626+}
67627+
67628+static struct acl_role_label *
67629+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
67630+ const gid_t gid)
67631+{
67632+ return __lookup_acl_role_label(&running_polstate, task, uid, gid);
67633+}
67634+
67635+struct acl_subject_label *
67636+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
67637+ const struct acl_role_label *role)
67638+{
67639+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
67640+ struct acl_subject_label *match;
67641+
67642+ match = role->subj_hash[index];
67643+
67644+ while (match && (match->inode != ino || match->device != dev ||
67645+ (match->mode & GR_DELETED))) {
67646+ match = match->next;
67647+ }
67648+
67649+ if (match && !(match->mode & GR_DELETED))
67650+ return match;
67651+ else
67652+ return NULL;
67653+}
67654+
67655+struct acl_subject_label *
67656+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
67657+ const struct acl_role_label *role)
67658+{
67659+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
67660+ struct acl_subject_label *match;
67661+
67662+ match = role->subj_hash[index];
67663+
67664+ while (match && (match->inode != ino || match->device != dev ||
67665+ !(match->mode & GR_DELETED))) {
67666+ match = match->next;
67667+ }
67668+
67669+ if (match && (match->mode & GR_DELETED))
67670+ return match;
67671+ else
67672+ return NULL;
67673+}
67674+
67675+static struct acl_object_label *
67676+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
67677+ const struct acl_subject_label *subj)
67678+{
67679+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
67680+ struct acl_object_label *match;
67681+
67682+ match = subj->obj_hash[index];
67683+
67684+ while (match && (match->inode != ino || match->device != dev ||
67685+ (match->mode & GR_DELETED))) {
67686+ match = match->next;
67687+ }
67688+
67689+ if (match && !(match->mode & GR_DELETED))
67690+ return match;
67691+ else
67692+ return NULL;
67693+}
67694+
67695+static struct acl_object_label *
67696+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
67697+ const struct acl_subject_label *subj)
67698+{
67699+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
67700+ struct acl_object_label *match;
67701+
67702+ match = subj->obj_hash[index];
67703+
67704+ while (match && (match->inode != ino || match->device != dev ||
67705+ !(match->mode & GR_DELETED))) {
67706+ match = match->next;
67707+ }
67708+
67709+ if (match && (match->mode & GR_DELETED))
67710+ return match;
67711+
67712+ match = subj->obj_hash[index];
67713+
67714+ while (match && (match->inode != ino || match->device != dev ||
67715+ (match->mode & GR_DELETED))) {
67716+ match = match->next;
67717+ }
67718+
67719+ if (match && !(match->mode & GR_DELETED))
67720+ return match;
67721+ else
67722+ return NULL;
67723+}
67724+
67725+struct name_entry *
67726+__lookup_name_entry(const struct gr_policy_state *state, const char *name)
67727+{
67728+ unsigned int len = strlen(name);
67729+ unsigned int key = full_name_hash(name, len);
67730+ unsigned int index = key % state->name_set.n_size;
67731+ struct name_entry *match;
67732+
67733+ match = state->name_set.n_hash[index];
67734+
67735+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
67736+ match = match->next;
67737+
67738+ return match;
67739+}
67740+
67741+static struct name_entry *
67742+lookup_name_entry(const char *name)
67743+{
67744+ return __lookup_name_entry(&running_polstate, name);
67745+}
67746+
67747+static struct name_entry *
67748+lookup_name_entry_create(const char *name)
67749+{
67750+ unsigned int len = strlen(name);
67751+ unsigned int key = full_name_hash(name, len);
67752+ unsigned int index = key % running_polstate.name_set.n_size;
67753+ struct name_entry *match;
67754+
67755+ match = running_polstate.name_set.n_hash[index];
67756+
67757+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
67758+ !match->deleted))
67759+ match = match->next;
67760+
67761+ if (match && match->deleted)
67762+ return match;
67763+
67764+ match = running_polstate.name_set.n_hash[index];
67765+
67766+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
67767+ match->deleted))
67768+ match = match->next;
67769+
67770+ if (match && !match->deleted)
67771+ return match;
67772+ else
67773+ return NULL;
67774+}
67775+
67776+static struct inodev_entry *
67777+lookup_inodev_entry(const ino_t ino, const dev_t dev)
67778+{
67779+ unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
67780+ struct inodev_entry *match;
67781+
67782+ match = running_polstate.inodev_set.i_hash[index];
67783+
67784+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
67785+ match = match->next;
67786+
67787+ return match;
67788+}
67789+
67790+void
67791+__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
67792+{
67793+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
67794+ state->inodev_set.i_size);
67795+ struct inodev_entry **curr;
67796+
67797+ entry->prev = NULL;
67798+
67799+ curr = &state->inodev_set.i_hash[index];
67800+ if (*curr != NULL)
67801+ (*curr)->prev = entry;
67802+
67803+ entry->next = *curr;
67804+ *curr = entry;
67805+
67806+ return;
67807+}
67808+
67809+static void
67810+insert_inodev_entry(struct inodev_entry *entry)
67811+{
67812+ __insert_inodev_entry(&running_polstate, entry);
67813+}
67814+
67815+void
67816+insert_acl_obj_label(struct acl_object_label *obj,
67817+ struct acl_subject_label *subj)
67818+{
67819+ unsigned int index =
67820+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
67821+ struct acl_object_label **curr;
67822+
67823+ obj->prev = NULL;
67824+
67825+ curr = &subj->obj_hash[index];
67826+ if (*curr != NULL)
67827+ (*curr)->prev = obj;
67828+
67829+ obj->next = *curr;
67830+ *curr = obj;
67831+
67832+ return;
67833+}
67834+
67835+void
67836+insert_acl_subj_label(struct acl_subject_label *obj,
67837+ struct acl_role_label *role)
67838+{
67839+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
67840+ struct acl_subject_label **curr;
67841+
67842+ obj->prev = NULL;
67843+
67844+ curr = &role->subj_hash[index];
67845+ if (*curr != NULL)
67846+ (*curr)->prev = obj;
67847+
67848+ obj->next = *curr;
67849+ *curr = obj;
67850+
67851+ return;
67852+}
67853+
67854+/* derived from glibc fnmatch() 0: match, 1: no match*/
67855+
67856+static int
67857+glob_match(const char *p, const char *n)
67858+{
67859+ char c;
67860+
67861+ while ((c = *p++) != '\0') {
67862+ switch (c) {
67863+ case '?':
67864+ if (*n == '\0')
67865+ return 1;
67866+ else if (*n == '/')
67867+ return 1;
67868+ break;
67869+ case '\\':
67870+ if (*n != c)
67871+ return 1;
67872+ break;
67873+ case '*':
67874+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
67875+ if (*n == '/')
67876+ return 1;
67877+ else if (c == '?') {
67878+ if (*n == '\0')
67879+ return 1;
67880+ else
67881+ ++n;
67882+ }
67883+ }
67884+ if (c == '\0') {
67885+ return 0;
67886+ } else {
67887+ const char *endp;
67888+
67889+ if ((endp = strchr(n, '/')) == NULL)
67890+ endp = n + strlen(n);
67891+
67892+ if (c == '[') {
67893+ for (--p; n < endp; ++n)
67894+ if (!glob_match(p, n))
67895+ return 0;
67896+ } else if (c == '/') {
67897+ while (*n != '\0' && *n != '/')
67898+ ++n;
67899+ if (*n == '/' && !glob_match(p, n + 1))
67900+ return 0;
67901+ } else {
67902+ for (--p; n < endp; ++n)
67903+ if (*n == c && !glob_match(p, n))
67904+ return 0;
67905+ }
67906+
67907+ return 1;
67908+ }
67909+ case '[':
67910+ {
67911+ int not;
67912+ char cold;
67913+
67914+ if (*n == '\0' || *n == '/')
67915+ return 1;
67916+
67917+ not = (*p == '!' || *p == '^');
67918+ if (not)
67919+ ++p;
67920+
67921+ c = *p++;
67922+ for (;;) {
67923+ unsigned char fn = (unsigned char)*n;
67924+
67925+ if (c == '\0')
67926+ return 1;
67927+ else {
67928+ if (c == fn)
67929+ goto matched;
67930+ cold = c;
67931+ c = *p++;
67932+
67933+ if (c == '-' && *p != ']') {
67934+ unsigned char cend = *p++;
67935+
67936+ if (cend == '\0')
67937+ return 1;
67938+
67939+ if (cold <= fn && fn <= cend)
67940+ goto matched;
67941+
67942+ c = *p++;
67943+ }
67944+ }
67945+
67946+ if (c == ']')
67947+ break;
67948+ }
67949+ if (!not)
67950+ return 1;
67951+ break;
67952+ matched:
67953+ while (c != ']') {
67954+ if (c == '\0')
67955+ return 1;
67956+
67957+ c = *p++;
67958+ }
67959+ if (not)
67960+ return 1;
67961+ }
67962+ break;
67963+ default:
67964+ if (c != *n)
67965+ return 1;
67966+ }
67967+
67968+ ++n;
67969+ }
67970+
67971+ if (*n == '\0')
67972+ return 0;
67973+
67974+ if (*n == '/')
67975+ return 0;
67976+
67977+ return 1;
67978+}
67979+
67980+static struct acl_object_label *
67981+chk_glob_label(struct acl_object_label *globbed,
67982+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
67983+{
67984+ struct acl_object_label *tmp;
67985+
67986+ if (*path == NULL)
67987+ *path = gr_to_filename_nolock(dentry, mnt);
67988+
67989+ tmp = globbed;
67990+
67991+ while (tmp) {
67992+ if (!glob_match(tmp->filename, *path))
67993+ return tmp;
67994+ tmp = tmp->next;
67995+ }
67996+
67997+ return NULL;
67998+}
67999+
68000+static struct acl_object_label *
68001+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
68002+ const ino_t curr_ino, const dev_t curr_dev,
68003+ const struct acl_subject_label *subj, char **path, const int checkglob)
68004+{
68005+ struct acl_subject_label *tmpsubj;
68006+ struct acl_object_label *retval;
68007+ struct acl_object_label *retval2;
68008+
68009+ tmpsubj = (struct acl_subject_label *) subj;
68010+ read_lock(&gr_inode_lock);
68011+ do {
68012+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
68013+ if (retval) {
68014+ if (checkglob && retval->globbed) {
68015+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
68016+ if (retval2)
68017+ retval = retval2;
68018+ }
68019+ break;
68020+ }
68021+ } while ((tmpsubj = tmpsubj->parent_subject));
68022+ read_unlock(&gr_inode_lock);
68023+
68024+ return retval;
68025+}
68026+
68027+static __inline__ struct acl_object_label *
68028+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
68029+ struct dentry *curr_dentry,
68030+ const struct acl_subject_label *subj, char **path, const int checkglob)
68031+{
68032+ int newglob = checkglob;
68033+ ino_t inode;
68034+ dev_t device;
68035+
68036+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
68037+ as we don't want a / * rule to match instead of the / object
68038+ don't do this for create lookups that call this function though, since they're looking up
68039+ on the parent and thus need globbing checks on all paths
68040+ */
68041+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
68042+ newglob = GR_NO_GLOB;
68043+
68044+ spin_lock(&curr_dentry->d_lock);
68045+ inode = curr_dentry->d_inode->i_ino;
68046+ device = __get_dev(curr_dentry);
68047+ spin_unlock(&curr_dentry->d_lock);
68048+
68049+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
68050+}
68051+
68052+#ifdef CONFIG_HUGETLBFS
68053+static inline bool
68054+is_hugetlbfs_mnt(const struct vfsmount *mnt)
68055+{
68056+ int i;
68057+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
68058+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
68059+ return true;
68060+ }
68061+
68062+ return false;
68063+}
68064+#endif
68065+
68066+static struct acl_object_label *
68067+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68068+ const struct acl_subject_label *subj, char *path, const int checkglob)
68069+{
68070+ struct dentry *dentry = (struct dentry *) l_dentry;
68071+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
68072+ struct mount *real_mnt = real_mount(mnt);
68073+ struct acl_object_label *retval;
68074+ struct dentry *parent;
68075+
68076+ read_seqlock_excl(&mount_lock);
68077+ write_seqlock(&rename_lock);
68078+
68079+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
68080+#ifdef CONFIG_NET
68081+ mnt == sock_mnt ||
68082+#endif
68083+#ifdef CONFIG_HUGETLBFS
68084+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
68085+#endif
68086+ /* ignore Eric Biederman */
68087+ IS_PRIVATE(l_dentry->d_inode))) {
68088+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
68089+ goto out;
68090+ }
68091+
68092+ for (;;) {
68093+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
68094+ break;
68095+
68096+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
68097+ if (!mnt_has_parent(real_mnt))
68098+ break;
68099+
68100+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
68101+ if (retval != NULL)
68102+ goto out;
68103+
68104+ dentry = real_mnt->mnt_mountpoint;
68105+ real_mnt = real_mnt->mnt_parent;
68106+ mnt = &real_mnt->mnt;
68107+ continue;
68108+ }
68109+
68110+ parent = dentry->d_parent;
68111+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
68112+ if (retval != NULL)
68113+ goto out;
68114+
68115+ dentry = parent;
68116+ }
68117+
68118+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
68119+
68120+ /* gr_real_root is pinned so we don't have to hold a reference */
68121+ if (retval == NULL)
68122+ retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
68123+out:
68124+ write_sequnlock(&rename_lock);
68125+ read_sequnlock_excl(&mount_lock);
68126+
68127+ BUG_ON(retval == NULL);
68128+
68129+ return retval;
68130+}
68131+
68132+static __inline__ struct acl_object_label *
68133+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68134+ const struct acl_subject_label *subj)
68135+{
68136+ char *path = NULL;
68137+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
68138+}
68139+
68140+static __inline__ struct acl_object_label *
68141+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68142+ const struct acl_subject_label *subj)
68143+{
68144+ char *path = NULL;
68145+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
68146+}
68147+
68148+static __inline__ struct acl_object_label *
68149+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68150+ const struct acl_subject_label *subj, char *path)
68151+{
68152+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
68153+}
68154+
68155+struct acl_subject_label *
68156+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68157+ const struct acl_role_label *role)
68158+{
68159+ struct dentry *dentry = (struct dentry *) l_dentry;
68160+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
68161+ struct mount *real_mnt = real_mount(mnt);
68162+ struct acl_subject_label *retval;
68163+ struct dentry *parent;
68164+
68165+ read_seqlock_excl(&mount_lock);
68166+ write_seqlock(&rename_lock);
68167+
68168+ for (;;) {
68169+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
68170+ break;
68171+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
68172+ if (!mnt_has_parent(real_mnt))
68173+ break;
68174+
68175+ spin_lock(&dentry->d_lock);
68176+ read_lock(&gr_inode_lock);
68177+ retval =
68178+ lookup_acl_subj_label(dentry->d_inode->i_ino,
68179+ __get_dev(dentry), role);
68180+ read_unlock(&gr_inode_lock);
68181+ spin_unlock(&dentry->d_lock);
68182+ if (retval != NULL)
68183+ goto out;
68184+
68185+ dentry = real_mnt->mnt_mountpoint;
68186+ real_mnt = real_mnt->mnt_parent;
68187+ mnt = &real_mnt->mnt;
68188+ continue;
68189+ }
68190+
68191+ spin_lock(&dentry->d_lock);
68192+ read_lock(&gr_inode_lock);
68193+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
68194+ __get_dev(dentry), role);
68195+ read_unlock(&gr_inode_lock);
68196+ parent = dentry->d_parent;
68197+ spin_unlock(&dentry->d_lock);
68198+
68199+ if (retval != NULL)
68200+ goto out;
68201+
68202+ dentry = parent;
68203+ }
68204+
68205+ spin_lock(&dentry->d_lock);
68206+ read_lock(&gr_inode_lock);
68207+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
68208+ __get_dev(dentry), role);
68209+ read_unlock(&gr_inode_lock);
68210+ spin_unlock(&dentry->d_lock);
68211+
68212+ if (unlikely(retval == NULL)) {
68213+ /* gr_real_root is pinned, we don't need to hold a reference */
68214+ read_lock(&gr_inode_lock);
68215+ retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
68216+ __get_dev(gr_real_root.dentry), role);
68217+ read_unlock(&gr_inode_lock);
68218+ }
68219+out:
68220+ write_sequnlock(&rename_lock);
68221+ read_sequnlock_excl(&mount_lock);
68222+
68223+ BUG_ON(retval == NULL);
68224+
68225+ return retval;
68226+}
68227+
68228+void
68229+assign_special_role(const char *rolename)
68230+{
68231+ struct acl_object_label *obj;
68232+ struct acl_role_label *r;
68233+ struct acl_role_label *assigned = NULL;
68234+ struct task_struct *tsk;
68235+ struct file *filp;
68236+
68237+ FOR_EACH_ROLE_START(r)
68238+ if (!strcmp(rolename, r->rolename) &&
68239+ (r->roletype & GR_ROLE_SPECIAL)) {
68240+ assigned = r;
68241+ break;
68242+ }
68243+ FOR_EACH_ROLE_END(r)
68244+
68245+ if (!assigned)
68246+ return;
68247+
68248+ read_lock(&tasklist_lock);
68249+ read_lock(&grsec_exec_file_lock);
68250+
68251+ tsk = current->real_parent;
68252+ if (tsk == NULL)
68253+ goto out_unlock;
68254+
68255+ filp = tsk->exec_file;
68256+ if (filp == NULL)
68257+ goto out_unlock;
68258+
68259+ tsk->is_writable = 0;
68260+ tsk->inherited = 0;
68261+
68262+ tsk->acl_sp_role = 1;
68263+ tsk->acl_role_id = ++acl_sp_role_value;
68264+ tsk->role = assigned;
68265+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
68266+
68267+ /* ignore additional mmap checks for processes that are writable
68268+ by the default ACL */
68269+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
68270+ if (unlikely(obj->mode & GR_WRITE))
68271+ tsk->is_writable = 1;
68272+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
68273+ if (unlikely(obj->mode & GR_WRITE))
68274+ tsk->is_writable = 1;
68275+
68276+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68277+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
68278+ tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
68279+#endif
68280+
68281+out_unlock:
68282+ read_unlock(&grsec_exec_file_lock);
68283+ read_unlock(&tasklist_lock);
68284+ return;
68285+}
68286+
68287+
68288+static void
68289+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
68290+{
68291+ struct task_struct *task = current;
68292+ const struct cred *cred = current_cred();
68293+
68294+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
68295+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
68296+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
68297+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
68298+
68299+ return;
68300+}
68301+
68302+static void
68303+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
68304+{
68305+ struct task_struct *task = current;
68306+ const struct cred *cred = current_cred();
68307+
68308+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
68309+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
68310+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
68311+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
68312+
68313+ return;
68314+}
68315+
68316+static void
68317+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
68318+{
68319+ struct task_struct *task = current;
68320+ const struct cred *cred = current_cred();
68321+
68322+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
68323+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
68324+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
68325+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
68326+
68327+ return;
68328+}
68329+
68330+static void
68331+gr_set_proc_res(struct task_struct *task)
68332+{
68333+ struct acl_subject_label *proc;
68334+ unsigned short i;
68335+
68336+ proc = task->acl;
68337+
68338+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
68339+ return;
68340+
68341+ for (i = 0; i < RLIM_NLIMITS; i++) {
68342+ if (!(proc->resmask & (1U << i)))
68343+ continue;
68344+
68345+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
68346+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
68347+
68348+ if (i == RLIMIT_CPU)
68349+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
68350+ }
68351+
68352+ return;
68353+}
68354+
68355+/* both of the below must be called with
68356+ rcu_read_lock();
68357+ read_lock(&tasklist_lock);
68358+ read_lock(&grsec_exec_file_lock);
68359+*/
68360+
68361+struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
68362+{
68363+ char *tmpname;
68364+ struct acl_subject_label *tmpsubj;
68365+ struct file *filp;
68366+ struct name_entry *nmatch;
68367+
68368+ filp = task->exec_file;
68369+ if (filp == NULL)
68370+ return NULL;
68371+
68372+ /* the following is to apply the correct subject
68373+ on binaries running when the RBAC system
68374+ is enabled, when the binaries have been
68375+ replaced or deleted since their execution
68376+ -----
68377+ when the RBAC system starts, the inode/dev
68378+ from exec_file will be one the RBAC system
68379+ is unaware of. It only knows the inode/dev
68380+ of the present file on disk, or the absence
68381+ of it.
68382+ */
68383+
68384+ if (filename)
68385+ nmatch = __lookup_name_entry(state, filename);
68386+ else {
68387+ preempt_disable();
68388+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
68389+
68390+ nmatch = __lookup_name_entry(state, tmpname);
68391+ preempt_enable();
68392+ }
68393+ tmpsubj = NULL;
68394+ if (nmatch) {
68395+ if (nmatch->deleted)
68396+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
68397+ else
68398+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
68399+ }
68400+ /* this also works for the reload case -- if we don't match a potentially inherited subject
68401+ then we fall back to a normal lookup based on the binary's ino/dev
68402+ */
68403+ if (tmpsubj == NULL)
68404+ tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
68405+
68406+ return tmpsubj;
68407+}
68408+
68409+static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
68410+{
68411+ return __gr_get_subject_for_task(&running_polstate, task, filename);
68412+}
68413+
68414+void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
68415+{
68416+ struct acl_object_label *obj;
68417+ struct file *filp;
68418+
68419+ filp = task->exec_file;
68420+
68421+ task->acl = subj;
68422+ task->is_writable = 0;
68423+ /* ignore additional mmap checks for processes that are writable
68424+ by the default ACL */
68425+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
68426+ if (unlikely(obj->mode & GR_WRITE))
68427+ task->is_writable = 1;
68428+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
68429+ if (unlikely(obj->mode & GR_WRITE))
68430+ task->is_writable = 1;
68431+
68432+ gr_set_proc_res(task);
68433+
68434+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68435+ 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);
68436+#endif
68437+}
68438+
68439+static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
68440+{
68441+ __gr_apply_subject_to_task(&running_polstate, task, subj);
68442+}
68443+
68444+__u32
68445+gr_search_file(const struct dentry * dentry, const __u32 mode,
68446+ const struct vfsmount * mnt)
68447+{
68448+ __u32 retval = mode;
68449+ struct acl_subject_label *curracl;
68450+ struct acl_object_label *currobj;
68451+
68452+ if (unlikely(!(gr_status & GR_READY)))
68453+ return (mode & ~GR_AUDITS);
68454+
68455+ curracl = current->acl;
68456+
68457+ currobj = chk_obj_label(dentry, mnt, curracl);
68458+ retval = currobj->mode & mode;
68459+
68460+ /* if we're opening a specified transfer file for writing
68461+ (e.g. /dev/initctl), then transfer our role to init
68462+ */
68463+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
68464+ current->role->roletype & GR_ROLE_PERSIST)) {
68465+ struct task_struct *task = init_pid_ns.child_reaper;
68466+
68467+ if (task->role != current->role) {
68468+ struct acl_subject_label *subj;
68469+
68470+ task->acl_sp_role = 0;
68471+ task->acl_role_id = current->acl_role_id;
68472+ task->role = current->role;
68473+ rcu_read_lock();
68474+ read_lock(&grsec_exec_file_lock);
68475+ subj = gr_get_subject_for_task(task, NULL);
68476+ gr_apply_subject_to_task(task, subj);
68477+ read_unlock(&grsec_exec_file_lock);
68478+ rcu_read_unlock();
68479+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
68480+ }
68481+ }
68482+
68483+ if (unlikely
68484+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
68485+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
68486+ __u32 new_mode = mode;
68487+
68488+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
68489+
68490+ retval = new_mode;
68491+
68492+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
68493+ new_mode |= GR_INHERIT;
68494+
68495+ if (!(mode & GR_NOLEARN))
68496+ gr_log_learn(dentry, mnt, new_mode);
68497+ }
68498+
68499+ return retval;
68500+}
68501+
68502+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
68503+ const struct dentry *parent,
68504+ const struct vfsmount *mnt)
68505+{
68506+ struct name_entry *match;
68507+ struct acl_object_label *matchpo;
68508+ struct acl_subject_label *curracl;
68509+ char *path;
68510+
68511+ if (unlikely(!(gr_status & GR_READY)))
68512+ return NULL;
68513+
68514+ preempt_disable();
68515+ path = gr_to_filename_rbac(new_dentry, mnt);
68516+ match = lookup_name_entry_create(path);
68517+
68518+ curracl = current->acl;
68519+
68520+ if (match) {
68521+ read_lock(&gr_inode_lock);
68522+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
68523+ read_unlock(&gr_inode_lock);
68524+
68525+ if (matchpo) {
68526+ preempt_enable();
68527+ return matchpo;
68528+ }
68529+ }
68530+
68531+ // lookup parent
68532+
68533+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
68534+
68535+ preempt_enable();
68536+ return matchpo;
68537+}
68538+
68539+__u32
68540+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
68541+ const struct vfsmount * mnt, const __u32 mode)
68542+{
68543+ struct acl_object_label *matchpo;
68544+ __u32 retval;
68545+
68546+ if (unlikely(!(gr_status & GR_READY)))
68547+ return (mode & ~GR_AUDITS);
68548+
68549+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
68550+
68551+ retval = matchpo->mode & mode;
68552+
68553+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
68554+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
68555+ __u32 new_mode = mode;
68556+
68557+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
68558+
68559+ gr_log_learn(new_dentry, mnt, new_mode);
68560+ return new_mode;
68561+ }
68562+
68563+ return retval;
68564+}
68565+
68566+__u32
68567+gr_check_link(const struct dentry * new_dentry,
68568+ const struct dentry * parent_dentry,
68569+ const struct vfsmount * parent_mnt,
68570+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
68571+{
68572+ struct acl_object_label *obj;
68573+ __u32 oldmode, newmode;
68574+ __u32 needmode;
68575+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
68576+ GR_DELETE | GR_INHERIT;
68577+
68578+ if (unlikely(!(gr_status & GR_READY)))
68579+ return (GR_CREATE | GR_LINK);
68580+
68581+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
68582+ oldmode = obj->mode;
68583+
68584+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
68585+ newmode = obj->mode;
68586+
68587+ needmode = newmode & checkmodes;
68588+
68589+ // old name for hardlink must have at least the permissions of the new name
68590+ if ((oldmode & needmode) != needmode)
68591+ goto bad;
68592+
68593+ // if old name had restrictions/auditing, make sure the new name does as well
68594+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
68595+
68596+ // don't allow hardlinking of suid/sgid/fcapped files without permission
68597+ if (is_privileged_binary(old_dentry))
68598+ needmode |= GR_SETID;
68599+
68600+ if ((newmode & needmode) != needmode)
68601+ goto bad;
68602+
68603+ // enforce minimum permissions
68604+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
68605+ return newmode;
68606+bad:
68607+ needmode = oldmode;
68608+ if (is_privileged_binary(old_dentry))
68609+ needmode |= GR_SETID;
68610+
68611+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
68612+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
68613+ return (GR_CREATE | GR_LINK);
68614+ } else if (newmode & GR_SUPPRESS)
68615+ return GR_SUPPRESS;
68616+ else
68617+ return 0;
68618+}
68619+
68620+int
68621+gr_check_hidden_task(const struct task_struct *task)
68622+{
68623+ if (unlikely(!(gr_status & GR_READY)))
68624+ return 0;
68625+
68626+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
68627+ return 1;
68628+
68629+ return 0;
68630+}
68631+
68632+int
68633+gr_check_protected_task(const struct task_struct *task)
68634+{
68635+ if (unlikely(!(gr_status & GR_READY) || !task))
68636+ return 0;
68637+
68638+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
68639+ task->acl != current->acl)
68640+ return 1;
68641+
68642+ return 0;
68643+}
68644+
68645+int
68646+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
68647+{
68648+ struct task_struct *p;
68649+ int ret = 0;
68650+
68651+ if (unlikely(!(gr_status & GR_READY) || !pid))
68652+ return ret;
68653+
68654+ read_lock(&tasklist_lock);
68655+ do_each_pid_task(pid, type, p) {
68656+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
68657+ p->acl != current->acl) {
68658+ ret = 1;
68659+ goto out;
68660+ }
68661+ } while_each_pid_task(pid, type, p);
68662+out:
68663+ read_unlock(&tasklist_lock);
68664+
68665+ return ret;
68666+}
68667+
68668+void
68669+gr_copy_label(struct task_struct *tsk)
68670+{
68671+ struct task_struct *p = current;
68672+
68673+ tsk->inherited = p->inherited;
68674+ tsk->acl_sp_role = 0;
68675+ tsk->acl_role_id = p->acl_role_id;
68676+ tsk->acl = p->acl;
68677+ tsk->role = p->role;
68678+ tsk->signal->used_accept = 0;
68679+ tsk->signal->curr_ip = p->signal->curr_ip;
68680+ tsk->signal->saved_ip = p->signal->saved_ip;
68681+ if (p->exec_file)
68682+ get_file(p->exec_file);
68683+ tsk->exec_file = p->exec_file;
68684+ tsk->is_writable = p->is_writable;
68685+ if (unlikely(p->signal->used_accept)) {
68686+ p->signal->curr_ip = 0;
68687+ p->signal->saved_ip = 0;
68688+ }
68689+
68690+ return;
68691+}
68692+
68693+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
68694+
68695+int
68696+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
68697+{
68698+ unsigned int i;
68699+ __u16 num;
68700+ uid_t *uidlist;
68701+ uid_t curuid;
68702+ int realok = 0;
68703+ int effectiveok = 0;
68704+ int fsok = 0;
68705+ uid_t globalreal, globaleffective, globalfs;
68706+
68707+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
68708+ struct user_struct *user;
68709+
68710+ if (!uid_valid(real))
68711+ goto skipit;
68712+
68713+ /* find user based on global namespace */
68714+
68715+ globalreal = GR_GLOBAL_UID(real);
68716+
68717+ user = find_user(make_kuid(&init_user_ns, globalreal));
68718+ if (user == NULL)
68719+ goto skipit;
68720+
68721+ if (gr_process_kernel_setuid_ban(user)) {
68722+ /* for find_user */
68723+ free_uid(user);
68724+ return 1;
68725+ }
68726+
68727+ /* for find_user */
68728+ free_uid(user);
68729+
68730+skipit:
68731+#endif
68732+
68733+ if (unlikely(!(gr_status & GR_READY)))
68734+ return 0;
68735+
68736+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68737+ gr_log_learn_uid_change(real, effective, fs);
68738+
68739+ num = current->acl->user_trans_num;
68740+ uidlist = current->acl->user_transitions;
68741+
68742+ if (uidlist == NULL)
68743+ return 0;
68744+
68745+ if (!uid_valid(real)) {
68746+ realok = 1;
68747+ globalreal = (uid_t)-1;
68748+ } else {
68749+ globalreal = GR_GLOBAL_UID(real);
68750+ }
68751+ if (!uid_valid(effective)) {
68752+ effectiveok = 1;
68753+ globaleffective = (uid_t)-1;
68754+ } else {
68755+ globaleffective = GR_GLOBAL_UID(effective);
68756+ }
68757+ if (!uid_valid(fs)) {
68758+ fsok = 1;
68759+ globalfs = (uid_t)-1;
68760+ } else {
68761+ globalfs = GR_GLOBAL_UID(fs);
68762+ }
68763+
68764+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
68765+ for (i = 0; i < num; i++) {
68766+ curuid = uidlist[i];
68767+ if (globalreal == curuid)
68768+ realok = 1;
68769+ if (globaleffective == curuid)
68770+ effectiveok = 1;
68771+ if (globalfs == curuid)
68772+ fsok = 1;
68773+ }
68774+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
68775+ for (i = 0; i < num; i++) {
68776+ curuid = uidlist[i];
68777+ if (globalreal == curuid)
68778+ break;
68779+ if (globaleffective == curuid)
68780+ break;
68781+ if (globalfs == curuid)
68782+ break;
68783+ }
68784+ /* not in deny list */
68785+ if (i == num) {
68786+ realok = 1;
68787+ effectiveok = 1;
68788+ fsok = 1;
68789+ }
68790+ }
68791+
68792+ if (realok && effectiveok && fsok)
68793+ return 0;
68794+ else {
68795+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
68796+ return 1;
68797+ }
68798+}
68799+
68800+int
68801+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
68802+{
68803+ unsigned int i;
68804+ __u16 num;
68805+ gid_t *gidlist;
68806+ gid_t curgid;
68807+ int realok = 0;
68808+ int effectiveok = 0;
68809+ int fsok = 0;
68810+ gid_t globalreal, globaleffective, globalfs;
68811+
68812+ if (unlikely(!(gr_status & GR_READY)))
68813+ return 0;
68814+
68815+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68816+ gr_log_learn_gid_change(real, effective, fs);
68817+
68818+ num = current->acl->group_trans_num;
68819+ gidlist = current->acl->group_transitions;
68820+
68821+ if (gidlist == NULL)
68822+ return 0;
68823+
68824+ if (!gid_valid(real)) {
68825+ realok = 1;
68826+ globalreal = (gid_t)-1;
68827+ } else {
68828+ globalreal = GR_GLOBAL_GID(real);
68829+ }
68830+ if (!gid_valid(effective)) {
68831+ effectiveok = 1;
68832+ globaleffective = (gid_t)-1;
68833+ } else {
68834+ globaleffective = GR_GLOBAL_GID(effective);
68835+ }
68836+ if (!gid_valid(fs)) {
68837+ fsok = 1;
68838+ globalfs = (gid_t)-1;
68839+ } else {
68840+ globalfs = GR_GLOBAL_GID(fs);
68841+ }
68842+
68843+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
68844+ for (i = 0; i < num; i++) {
68845+ curgid = gidlist[i];
68846+ if (globalreal == curgid)
68847+ realok = 1;
68848+ if (globaleffective == curgid)
68849+ effectiveok = 1;
68850+ if (globalfs == curgid)
68851+ fsok = 1;
68852+ }
68853+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
68854+ for (i = 0; i < num; i++) {
68855+ curgid = gidlist[i];
68856+ if (globalreal == curgid)
68857+ break;
68858+ if (globaleffective == curgid)
68859+ break;
68860+ if (globalfs == curgid)
68861+ break;
68862+ }
68863+ /* not in deny list */
68864+ if (i == num) {
68865+ realok = 1;
68866+ effectiveok = 1;
68867+ fsok = 1;
68868+ }
68869+ }
68870+
68871+ if (realok && effectiveok && fsok)
68872+ return 0;
68873+ else {
68874+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
68875+ return 1;
68876+ }
68877+}
68878+
68879+extern int gr_acl_is_capable(const int cap);
68880+
68881+void
68882+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
68883+{
68884+ struct acl_role_label *role = task->role;
68885+ struct acl_subject_label *subj = NULL;
68886+ struct acl_object_label *obj;
68887+ struct file *filp;
68888+ uid_t uid;
68889+ gid_t gid;
68890+
68891+ if (unlikely(!(gr_status & GR_READY)))
68892+ return;
68893+
68894+ uid = GR_GLOBAL_UID(kuid);
68895+ gid = GR_GLOBAL_GID(kgid);
68896+
68897+ filp = task->exec_file;
68898+
68899+ /* kernel process, we'll give them the kernel role */
68900+ if (unlikely(!filp)) {
68901+ task->role = running_polstate.kernel_role;
68902+ task->acl = running_polstate.kernel_role->root_label;
68903+ return;
68904+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
68905+ /* save the current ip at time of role lookup so that the proper
68906+ IP will be learned for role_allowed_ip */
68907+ task->signal->saved_ip = task->signal->curr_ip;
68908+ role = lookup_acl_role_label(task, uid, gid);
68909+ }
68910+
68911+ /* don't change the role if we're not a privileged process */
68912+ if (role && task->role != role &&
68913+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
68914+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
68915+ return;
68916+
68917+ /* perform subject lookup in possibly new role
68918+ we can use this result below in the case where role == task->role
68919+ */
68920+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
68921+
68922+ /* if we changed uid/gid, but result in the same role
68923+ and are using inheritance, don't lose the inherited subject
68924+ if current subject is other than what normal lookup
68925+ would result in, we arrived via inheritance, don't
68926+ lose subject
68927+ */
68928+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
68929+ (subj == task->acl)))
68930+ task->acl = subj;
68931+
68932+ /* leave task->inherited unaffected */
68933+
68934+ task->role = role;
68935+
68936+ task->is_writable = 0;
68937+
68938+ /* ignore additional mmap checks for processes that are writable
68939+ by the default ACL */
68940+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
68941+ if (unlikely(obj->mode & GR_WRITE))
68942+ task->is_writable = 1;
68943+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
68944+ if (unlikely(obj->mode & GR_WRITE))
68945+ task->is_writable = 1;
68946+
68947+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68948+ 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);
68949+#endif
68950+
68951+ gr_set_proc_res(task);
68952+
68953+ return;
68954+}
68955+
68956+int
68957+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
68958+ const int unsafe_flags)
68959+{
68960+ struct task_struct *task = current;
68961+ struct acl_subject_label *newacl;
68962+ struct acl_object_label *obj;
68963+ __u32 retmode;
68964+
68965+ if (unlikely(!(gr_status & GR_READY)))
68966+ return 0;
68967+
68968+ newacl = chk_subj_label(dentry, mnt, task->role);
68969+
68970+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
68971+ did an exec
68972+ */
68973+ rcu_read_lock();
68974+ read_lock(&tasklist_lock);
68975+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
68976+ (task->parent->acl->mode & GR_POVERRIDE))) {
68977+ read_unlock(&tasklist_lock);
68978+ rcu_read_unlock();
68979+ goto skip_check;
68980+ }
68981+ read_unlock(&tasklist_lock);
68982+ rcu_read_unlock();
68983+
68984+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
68985+ !(task->role->roletype & GR_ROLE_GOD) &&
68986+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
68987+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
68988+ if (unsafe_flags & LSM_UNSAFE_SHARE)
68989+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
68990+ else
68991+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
68992+ return -EACCES;
68993+ }
68994+
68995+skip_check:
68996+
68997+ obj = chk_obj_label(dentry, mnt, task->acl);
68998+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
68999+
69000+ if (!(task->acl->mode & GR_INHERITLEARN) &&
69001+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
69002+ if (obj->nested)
69003+ task->acl = obj->nested;
69004+ else
69005+ task->acl = newacl;
69006+ task->inherited = 0;
69007+ } else {
69008+ task->inherited = 1;
69009+ if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
69010+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
69011+ }
69012+
69013+ task->is_writable = 0;
69014+
69015+ /* ignore additional mmap checks for processes that are writable
69016+ by the default ACL */
69017+ obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
69018+ if (unlikely(obj->mode & GR_WRITE))
69019+ task->is_writable = 1;
69020+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
69021+ if (unlikely(obj->mode & GR_WRITE))
69022+ task->is_writable = 1;
69023+
69024+ gr_set_proc_res(task);
69025+
69026+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
69027+ 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);
69028+#endif
69029+ return 0;
69030+}
69031+
69032+/* always called with valid inodev ptr */
69033+static void
69034+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
69035+{
69036+ struct acl_object_label *matchpo;
69037+ struct acl_subject_label *matchps;
69038+ struct acl_subject_label *subj;
69039+ struct acl_role_label *role;
69040+ unsigned int x;
69041+
69042+ FOR_EACH_ROLE_START(role)
69043+ FOR_EACH_SUBJECT_START(role, subj, x)
69044+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
69045+ matchpo->mode |= GR_DELETED;
69046+ FOR_EACH_SUBJECT_END(subj,x)
69047+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
69048+ /* nested subjects aren't in the role's subj_hash table */
69049+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
69050+ matchpo->mode |= GR_DELETED;
69051+ FOR_EACH_NESTED_SUBJECT_END(subj)
69052+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
69053+ matchps->mode |= GR_DELETED;
69054+ FOR_EACH_ROLE_END(role)
69055+
69056+ inodev->nentry->deleted = 1;
69057+
69058+ return;
69059+}
69060+
69061+void
69062+gr_handle_delete(const ino_t ino, const dev_t dev)
69063+{
69064+ struct inodev_entry *inodev;
69065+
69066+ if (unlikely(!(gr_status & GR_READY)))
69067+ return;
69068+
69069+ write_lock(&gr_inode_lock);
69070+ inodev = lookup_inodev_entry(ino, dev);
69071+ if (inodev != NULL)
69072+ do_handle_delete(inodev, ino, dev);
69073+ write_unlock(&gr_inode_lock);
69074+
69075+ return;
69076+}
69077+
69078+static void
69079+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
69080+ const ino_t newinode, const dev_t newdevice,
69081+ struct acl_subject_label *subj)
69082+{
69083+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
69084+ struct acl_object_label *match;
69085+
69086+ match = subj->obj_hash[index];
69087+
69088+ while (match && (match->inode != oldinode ||
69089+ match->device != olddevice ||
69090+ !(match->mode & GR_DELETED)))
69091+ match = match->next;
69092+
69093+ if (match && (match->inode == oldinode)
69094+ && (match->device == olddevice)
69095+ && (match->mode & GR_DELETED)) {
69096+ if (match->prev == NULL) {
69097+ subj->obj_hash[index] = match->next;
69098+ if (match->next != NULL)
69099+ match->next->prev = NULL;
69100+ } else {
69101+ match->prev->next = match->next;
69102+ if (match->next != NULL)
69103+ match->next->prev = match->prev;
69104+ }
69105+ match->prev = NULL;
69106+ match->next = NULL;
69107+ match->inode = newinode;
69108+ match->device = newdevice;
69109+ match->mode &= ~GR_DELETED;
69110+
69111+ insert_acl_obj_label(match, subj);
69112+ }
69113+
69114+ return;
69115+}
69116+
69117+static void
69118+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
69119+ const ino_t newinode, const dev_t newdevice,
69120+ struct acl_role_label *role)
69121+{
69122+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
69123+ struct acl_subject_label *match;
69124+
69125+ match = role->subj_hash[index];
69126+
69127+ while (match && (match->inode != oldinode ||
69128+ match->device != olddevice ||
69129+ !(match->mode & GR_DELETED)))
69130+ match = match->next;
69131+
69132+ if (match && (match->inode == oldinode)
69133+ && (match->device == olddevice)
69134+ && (match->mode & GR_DELETED)) {
69135+ if (match->prev == NULL) {
69136+ role->subj_hash[index] = match->next;
69137+ if (match->next != NULL)
69138+ match->next->prev = NULL;
69139+ } else {
69140+ match->prev->next = match->next;
69141+ if (match->next != NULL)
69142+ match->next->prev = match->prev;
69143+ }
69144+ match->prev = NULL;
69145+ match->next = NULL;
69146+ match->inode = newinode;
69147+ match->device = newdevice;
69148+ match->mode &= ~GR_DELETED;
69149+
69150+ insert_acl_subj_label(match, role);
69151+ }
69152+
69153+ return;
69154+}
69155+
69156+static void
69157+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
69158+ const ino_t newinode, const dev_t newdevice)
69159+{
69160+ unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
69161+ struct inodev_entry *match;
69162+
69163+ match = running_polstate.inodev_set.i_hash[index];
69164+
69165+ while (match && (match->nentry->inode != oldinode ||
69166+ match->nentry->device != olddevice || !match->nentry->deleted))
69167+ match = match->next;
69168+
69169+ if (match && (match->nentry->inode == oldinode)
69170+ && (match->nentry->device == olddevice) &&
69171+ match->nentry->deleted) {
69172+ if (match->prev == NULL) {
69173+ running_polstate.inodev_set.i_hash[index] = match->next;
69174+ if (match->next != NULL)
69175+ match->next->prev = NULL;
69176+ } else {
69177+ match->prev->next = match->next;
69178+ if (match->next != NULL)
69179+ match->next->prev = match->prev;
69180+ }
69181+ match->prev = NULL;
69182+ match->next = NULL;
69183+ match->nentry->inode = newinode;
69184+ match->nentry->device = newdevice;
69185+ match->nentry->deleted = 0;
69186+
69187+ insert_inodev_entry(match);
69188+ }
69189+
69190+ return;
69191+}
69192+
69193+static void
69194+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
69195+{
69196+ struct acl_subject_label *subj;
69197+ struct acl_role_label *role;
69198+ unsigned int x;
69199+
69200+ FOR_EACH_ROLE_START(role)
69201+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
69202+
69203+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
69204+ if ((subj->inode == ino) && (subj->device == dev)) {
69205+ subj->inode = ino;
69206+ subj->device = dev;
69207+ }
69208+ /* nested subjects aren't in the role's subj_hash table */
69209+ update_acl_obj_label(matchn->inode, matchn->device,
69210+ ino, dev, subj);
69211+ FOR_EACH_NESTED_SUBJECT_END(subj)
69212+ FOR_EACH_SUBJECT_START(role, subj, x)
69213+ update_acl_obj_label(matchn->inode, matchn->device,
69214+ ino, dev, subj);
69215+ FOR_EACH_SUBJECT_END(subj,x)
69216+ FOR_EACH_ROLE_END(role)
69217+
69218+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
69219+
69220+ return;
69221+}
69222+
69223+static void
69224+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
69225+ const struct vfsmount *mnt)
69226+{
69227+ ino_t ino = dentry->d_inode->i_ino;
69228+ dev_t dev = __get_dev(dentry);
69229+
69230+ __do_handle_create(matchn, ino, dev);
69231+
69232+ return;
69233+}
69234+
69235+void
69236+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
69237+{
69238+ struct name_entry *matchn;
69239+
69240+ if (unlikely(!(gr_status & GR_READY)))
69241+ return;
69242+
69243+ preempt_disable();
69244+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
69245+
69246+ if (unlikely((unsigned long)matchn)) {
69247+ write_lock(&gr_inode_lock);
69248+ do_handle_create(matchn, dentry, mnt);
69249+ write_unlock(&gr_inode_lock);
69250+ }
69251+ preempt_enable();
69252+
69253+ return;
69254+}
69255+
69256+void
69257+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
69258+{
69259+ struct name_entry *matchn;
69260+
69261+ if (unlikely(!(gr_status & GR_READY)))
69262+ return;
69263+
69264+ preempt_disable();
69265+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
69266+
69267+ if (unlikely((unsigned long)matchn)) {
69268+ write_lock(&gr_inode_lock);
69269+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
69270+ write_unlock(&gr_inode_lock);
69271+ }
69272+ preempt_enable();
69273+
69274+ return;
69275+}
69276+
69277+void
69278+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
69279+ struct dentry *old_dentry,
69280+ struct dentry *new_dentry,
69281+ struct vfsmount *mnt, const __u8 replace)
69282+{
69283+ struct name_entry *matchn;
69284+ struct inodev_entry *inodev;
69285+ struct inode *inode = new_dentry->d_inode;
69286+ ino_t old_ino = old_dentry->d_inode->i_ino;
69287+ dev_t old_dev = __get_dev(old_dentry);
69288+
69289+ /* vfs_rename swaps the name and parent link for old_dentry and
69290+ new_dentry
69291+ at this point, old_dentry has the new name, parent link, and inode
69292+ for the renamed file
69293+ if a file is being replaced by a rename, new_dentry has the inode
69294+ and name for the replaced file
69295+ */
69296+
69297+ if (unlikely(!(gr_status & GR_READY)))
69298+ return;
69299+
69300+ preempt_disable();
69301+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
69302+
69303+ /* we wouldn't have to check d_inode if it weren't for
69304+ NFS silly-renaming
69305+ */
69306+
69307+ write_lock(&gr_inode_lock);
69308+ if (unlikely(replace && inode)) {
69309+ ino_t new_ino = inode->i_ino;
69310+ dev_t new_dev = __get_dev(new_dentry);
69311+
69312+ inodev = lookup_inodev_entry(new_ino, new_dev);
69313+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
69314+ do_handle_delete(inodev, new_ino, new_dev);
69315+ }
69316+
69317+ inodev = lookup_inodev_entry(old_ino, old_dev);
69318+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
69319+ do_handle_delete(inodev, old_ino, old_dev);
69320+
69321+ if (unlikely((unsigned long)matchn))
69322+ do_handle_create(matchn, old_dentry, mnt);
69323+
69324+ write_unlock(&gr_inode_lock);
69325+ preempt_enable();
69326+
69327+ return;
69328+}
69329+
69330+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
69331+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
69332+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
69333+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
69334+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
69335+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
69336+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
69337+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
69338+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
69339+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
69340+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
69341+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
69342+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
69343+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
69344+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
69345+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
69346+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
69347+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
69348+};
69349+
69350+void
69351+gr_learn_resource(const struct task_struct *task,
69352+ const int res, const unsigned long wanted, const int gt)
69353+{
69354+ struct acl_subject_label *acl;
69355+ const struct cred *cred;
69356+
69357+ if (unlikely((gr_status & GR_READY) &&
69358+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
69359+ goto skip_reslog;
69360+
69361+ gr_log_resource(task, res, wanted, gt);
69362+skip_reslog:
69363+
69364+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
69365+ return;
69366+
69367+ acl = task->acl;
69368+
69369+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
69370+ !(acl->resmask & (1U << (unsigned short) res))))
69371+ return;
69372+
69373+ if (wanted >= acl->res[res].rlim_cur) {
69374+ unsigned long res_add;
69375+
69376+ res_add = wanted + res_learn_bumps[res];
69377+
69378+ acl->res[res].rlim_cur = res_add;
69379+
69380+ if (wanted > acl->res[res].rlim_max)
69381+ acl->res[res].rlim_max = res_add;
69382+
69383+ /* only log the subject filename, since resource logging is supported for
69384+ single-subject learning only */
69385+ rcu_read_lock();
69386+ cred = __task_cred(task);
69387+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
69388+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
69389+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
69390+ "", (unsigned long) res, &task->signal->saved_ip);
69391+ rcu_read_unlock();
69392+ }
69393+
69394+ return;
69395+}
69396+EXPORT_SYMBOL_GPL(gr_learn_resource);
69397+#endif
69398+
69399+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
69400+void
69401+pax_set_initial_flags(struct linux_binprm *bprm)
69402+{
69403+ struct task_struct *task = current;
69404+ struct acl_subject_label *proc;
69405+ unsigned long flags;
69406+
69407+ if (unlikely(!(gr_status & GR_READY)))
69408+ return;
69409+
69410+ flags = pax_get_flags(task);
69411+
69412+ proc = task->acl;
69413+
69414+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
69415+ flags &= ~MF_PAX_PAGEEXEC;
69416+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
69417+ flags &= ~MF_PAX_SEGMEXEC;
69418+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
69419+ flags &= ~MF_PAX_RANDMMAP;
69420+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
69421+ flags &= ~MF_PAX_EMUTRAMP;
69422+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
69423+ flags &= ~MF_PAX_MPROTECT;
69424+
69425+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
69426+ flags |= MF_PAX_PAGEEXEC;
69427+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
69428+ flags |= MF_PAX_SEGMEXEC;
69429+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
69430+ flags |= MF_PAX_RANDMMAP;
69431+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
69432+ flags |= MF_PAX_EMUTRAMP;
69433+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
69434+ flags |= MF_PAX_MPROTECT;
69435+
69436+ pax_set_flags(task, flags);
69437+
69438+ return;
69439+}
69440+#endif
69441+
69442+int
69443+gr_handle_proc_ptrace(struct task_struct *task)
69444+{
69445+ struct file *filp;
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+
69455+ read_lock(&tasklist_lock);
69456+ read_lock(&grsec_exec_file_lock);
69457+ filp = task->exec_file;
69458+
69459+ while (task_pid_nr(tmp) > 0) {
69460+ if (tmp == curtemp)
69461+ break;
69462+ tmp = tmp->real_parent;
69463+ }
69464+
69465+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
69466+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
69467+ read_unlock(&grsec_exec_file_lock);
69468+ read_unlock(&tasklist_lock);
69469+ return 1;
69470+ }
69471+
69472+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69473+ if (!(gr_status & GR_READY)) {
69474+ read_unlock(&grsec_exec_file_lock);
69475+ read_unlock(&tasklist_lock);
69476+ return 0;
69477+ }
69478+#endif
69479+
69480+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
69481+ read_unlock(&grsec_exec_file_lock);
69482+ read_unlock(&tasklist_lock);
69483+
69484+ if (retmode & GR_NOPTRACE)
69485+ return 1;
69486+
69487+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
69488+ && (current->acl != task->acl || (current->acl != current->role->root_label
69489+ && task_pid_nr(current) != task_pid_nr(task))))
69490+ return 1;
69491+
69492+ return 0;
69493+}
69494+
69495+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
69496+{
69497+ if (unlikely(!(gr_status & GR_READY)))
69498+ return;
69499+
69500+ if (!(current->role->roletype & GR_ROLE_GOD))
69501+ return;
69502+
69503+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
69504+ p->role->rolename, gr_task_roletype_to_char(p),
69505+ p->acl->filename);
69506+}
69507+
69508+int
69509+gr_handle_ptrace(struct task_struct *task, const long request)
69510+{
69511+ struct task_struct *tmp = task;
69512+ struct task_struct *curtemp = current;
69513+ __u32 retmode;
69514+
69515+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
69516+ if (unlikely(!(gr_status & GR_READY)))
69517+ return 0;
69518+#endif
69519+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69520+ read_lock(&tasklist_lock);
69521+ while (task_pid_nr(tmp) > 0) {
69522+ if (tmp == curtemp)
69523+ break;
69524+ tmp = tmp->real_parent;
69525+ }
69526+
69527+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
69528+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
69529+ read_unlock(&tasklist_lock);
69530+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69531+ return 1;
69532+ }
69533+ read_unlock(&tasklist_lock);
69534+ }
69535+
69536+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69537+ if (!(gr_status & GR_READY))
69538+ return 0;
69539+#endif
69540+
69541+ read_lock(&grsec_exec_file_lock);
69542+ if (unlikely(!task->exec_file)) {
69543+ read_unlock(&grsec_exec_file_lock);
69544+ return 0;
69545+ }
69546+
69547+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
69548+ read_unlock(&grsec_exec_file_lock);
69549+
69550+ if (retmode & GR_NOPTRACE) {
69551+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69552+ return 1;
69553+ }
69554+
69555+ if (retmode & GR_PTRACERD) {
69556+ switch (request) {
69557+ case PTRACE_SEIZE:
69558+ case PTRACE_POKETEXT:
69559+ case PTRACE_POKEDATA:
69560+ case PTRACE_POKEUSR:
69561+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
69562+ case PTRACE_SETREGS:
69563+ case PTRACE_SETFPREGS:
69564+#endif
69565+#ifdef CONFIG_X86
69566+ case PTRACE_SETFPXREGS:
69567+#endif
69568+#ifdef CONFIG_ALTIVEC
69569+ case PTRACE_SETVRREGS:
69570+#endif
69571+ return 1;
69572+ default:
69573+ return 0;
69574+ }
69575+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
69576+ !(current->role->roletype & GR_ROLE_GOD) &&
69577+ (current->acl != task->acl)) {
69578+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69579+ return 1;
69580+ }
69581+
69582+ return 0;
69583+}
69584+
69585+static int is_writable_mmap(const struct file *filp)
69586+{
69587+ struct task_struct *task = current;
69588+ struct acl_object_label *obj, *obj2;
69589+
69590+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
69591+ !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))) {
69592+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
69593+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
69594+ task->role->root_label);
69595+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
69596+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
69597+ return 1;
69598+ }
69599+ }
69600+ return 0;
69601+}
69602+
69603+int
69604+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
69605+{
69606+ __u32 mode;
69607+
69608+ if (unlikely(!file || !(prot & PROT_EXEC)))
69609+ return 1;
69610+
69611+ if (is_writable_mmap(file))
69612+ return 0;
69613+
69614+ mode =
69615+ gr_search_file(file->f_path.dentry,
69616+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
69617+ file->f_path.mnt);
69618+
69619+ if (!gr_tpe_allow(file))
69620+ return 0;
69621+
69622+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
69623+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69624+ return 0;
69625+ } else if (unlikely(!(mode & GR_EXEC))) {
69626+ return 0;
69627+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
69628+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69629+ return 1;
69630+ }
69631+
69632+ return 1;
69633+}
69634+
69635+int
69636+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
69637+{
69638+ __u32 mode;
69639+
69640+ if (unlikely(!file || !(prot & PROT_EXEC)))
69641+ return 1;
69642+
69643+ if (is_writable_mmap(file))
69644+ return 0;
69645+
69646+ mode =
69647+ gr_search_file(file->f_path.dentry,
69648+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
69649+ file->f_path.mnt);
69650+
69651+ if (!gr_tpe_allow(file))
69652+ return 0;
69653+
69654+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
69655+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69656+ return 0;
69657+ } else if (unlikely(!(mode & GR_EXEC))) {
69658+ return 0;
69659+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
69660+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69661+ return 1;
69662+ }
69663+
69664+ return 1;
69665+}
69666+
69667+void
69668+gr_acl_handle_psacct(struct task_struct *task, const long code)
69669+{
69670+ unsigned long runtime, cputime;
69671+ cputime_t utime, stime;
69672+ unsigned int wday, cday;
69673+ __u8 whr, chr;
69674+ __u8 wmin, cmin;
69675+ __u8 wsec, csec;
69676+ struct timespec timeval;
69677+
69678+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
69679+ !(task->acl->mode & GR_PROCACCT)))
69680+ return;
69681+
69682+ do_posix_clock_monotonic_gettime(&timeval);
69683+ runtime = timeval.tv_sec - task->start_time.tv_sec;
69684+ wday = runtime / (60 * 60 * 24);
69685+ runtime -= wday * (60 * 60 * 24);
69686+ whr = runtime / (60 * 60);
69687+ runtime -= whr * (60 * 60);
69688+ wmin = runtime / 60;
69689+ runtime -= wmin * 60;
69690+ wsec = runtime;
69691+
69692+ task_cputime(task, &utime, &stime);
69693+ cputime = cputime_to_secs(utime + stime);
69694+ cday = cputime / (60 * 60 * 24);
69695+ cputime -= cday * (60 * 60 * 24);
69696+ chr = cputime / (60 * 60);
69697+ cputime -= chr * (60 * 60);
69698+ cmin = cputime / 60;
69699+ cputime -= cmin * 60;
69700+ csec = cputime;
69701+
69702+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
69703+
69704+ return;
69705+}
69706+
69707+#ifdef CONFIG_TASKSTATS
69708+int gr_is_taskstats_denied(int pid)
69709+{
69710+ struct task_struct *task;
69711+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69712+ const struct cred *cred;
69713+#endif
69714+ int ret = 0;
69715+
69716+ /* restrict taskstats viewing to un-chrooted root users
69717+ who have the 'view' subject flag if the RBAC system is enabled
69718+ */
69719+
69720+ rcu_read_lock();
69721+ read_lock(&tasklist_lock);
69722+ task = find_task_by_vpid(pid);
69723+ if (task) {
69724+#ifdef CONFIG_GRKERNSEC_CHROOT
69725+ if (proc_is_chrooted(task))
69726+ ret = -EACCES;
69727+#endif
69728+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69729+ cred = __task_cred(task);
69730+#ifdef CONFIG_GRKERNSEC_PROC_USER
69731+ if (gr_is_global_nonroot(cred->uid))
69732+ ret = -EACCES;
69733+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69734+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
69735+ ret = -EACCES;
69736+#endif
69737+#endif
69738+ if (gr_status & GR_READY) {
69739+ if (!(task->acl->mode & GR_VIEW))
69740+ ret = -EACCES;
69741+ }
69742+ } else
69743+ ret = -ENOENT;
69744+
69745+ read_unlock(&tasklist_lock);
69746+ rcu_read_unlock();
69747+
69748+ return ret;
69749+}
69750+#endif
69751+
69752+/* AUXV entries are filled via a descendant of search_binary_handler
69753+ after we've already applied the subject for the target
69754+*/
69755+int gr_acl_enable_at_secure(void)
69756+{
69757+ if (unlikely(!(gr_status & GR_READY)))
69758+ return 0;
69759+
69760+ if (current->acl->mode & GR_ATSECURE)
69761+ return 1;
69762+
69763+ return 0;
69764+}
69765+
69766+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
69767+{
69768+ struct task_struct *task = current;
69769+ struct dentry *dentry = file->f_path.dentry;
69770+ struct vfsmount *mnt = file->f_path.mnt;
69771+ struct acl_object_label *obj, *tmp;
69772+ struct acl_subject_label *subj;
69773+ unsigned int bufsize;
69774+ int is_not_root;
69775+ char *path;
69776+ dev_t dev = __get_dev(dentry);
69777+
69778+ if (unlikely(!(gr_status & GR_READY)))
69779+ return 1;
69780+
69781+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
69782+ return 1;
69783+
69784+ /* ignore Eric Biederman */
69785+ if (IS_PRIVATE(dentry->d_inode))
69786+ return 1;
69787+
69788+ subj = task->acl;
69789+ read_lock(&gr_inode_lock);
69790+ do {
69791+ obj = lookup_acl_obj_label(ino, dev, subj);
69792+ if (obj != NULL) {
69793+ read_unlock(&gr_inode_lock);
69794+ return (obj->mode & GR_FIND) ? 1 : 0;
69795+ }
69796+ } while ((subj = subj->parent_subject));
69797+ read_unlock(&gr_inode_lock);
69798+
69799+ /* this is purely an optimization since we're looking for an object
69800+ for the directory we're doing a readdir on
69801+ if it's possible for any globbed object to match the entry we're
69802+ filling into the directory, then the object we find here will be
69803+ an anchor point with attached globbed objects
69804+ */
69805+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
69806+ if (obj->globbed == NULL)
69807+ return (obj->mode & GR_FIND) ? 1 : 0;
69808+
69809+ is_not_root = ((obj->filename[0] == '/') &&
69810+ (obj->filename[1] == '\0')) ? 0 : 1;
69811+ bufsize = PAGE_SIZE - namelen - is_not_root;
69812+
69813+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
69814+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
69815+ return 1;
69816+
69817+ preempt_disable();
69818+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
69819+ bufsize);
69820+
69821+ bufsize = strlen(path);
69822+
69823+ /* if base is "/", don't append an additional slash */
69824+ if (is_not_root)
69825+ *(path + bufsize) = '/';
69826+ memcpy(path + bufsize + is_not_root, name, namelen);
69827+ *(path + bufsize + namelen + is_not_root) = '\0';
69828+
69829+ tmp = obj->globbed;
69830+ while (tmp) {
69831+ if (!glob_match(tmp->filename, path)) {
69832+ preempt_enable();
69833+ return (tmp->mode & GR_FIND) ? 1 : 0;
69834+ }
69835+ tmp = tmp->next;
69836+ }
69837+ preempt_enable();
69838+ return (obj->mode & GR_FIND) ? 1 : 0;
69839+}
69840+
69841+void gr_put_exec_file(struct task_struct *task)
69842+{
69843+ struct file *filp;
69844+
69845+ write_lock(&grsec_exec_file_lock);
69846+ filp = task->exec_file;
69847+ task->exec_file = NULL;
69848+ write_unlock(&grsec_exec_file_lock);
69849+
69850+ if (filp)
69851+ fput(filp);
69852+
69853+ return;
69854+}
69855+
69856+
69857+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
69858+EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
69859+#endif
69860+#ifdef CONFIG_SECURITY
69861+EXPORT_SYMBOL_GPL(gr_check_user_change);
69862+EXPORT_SYMBOL_GPL(gr_check_group_change);
69863+#endif
69864+
69865diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
69866new file mode 100644
69867index 0000000..18ffbbd
69868--- /dev/null
69869+++ b/grsecurity/gracl_alloc.c
69870@@ -0,0 +1,105 @@
69871+#include <linux/kernel.h>
69872+#include <linux/mm.h>
69873+#include <linux/slab.h>
69874+#include <linux/vmalloc.h>
69875+#include <linux/gracl.h>
69876+#include <linux/grsecurity.h>
69877+
69878+static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
69879+struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
69880+
69881+static __inline__ int
69882+alloc_pop(void)
69883+{
69884+ if (current_alloc_state->alloc_stack_next == 1)
69885+ return 0;
69886+
69887+ kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
69888+
69889+ current_alloc_state->alloc_stack_next--;
69890+
69891+ return 1;
69892+}
69893+
69894+static __inline__ int
69895+alloc_push(void *buf)
69896+{
69897+ if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
69898+ return 1;
69899+
69900+ current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
69901+
69902+ current_alloc_state->alloc_stack_next++;
69903+
69904+ return 0;
69905+}
69906+
69907+void *
69908+acl_alloc(unsigned long len)
69909+{
69910+ void *ret = NULL;
69911+
69912+ if (!len || len > PAGE_SIZE)
69913+ goto out;
69914+
69915+ ret = kmalloc(len, GFP_KERNEL);
69916+
69917+ if (ret) {
69918+ if (alloc_push(ret)) {
69919+ kfree(ret);
69920+ ret = NULL;
69921+ }
69922+ }
69923+
69924+out:
69925+ return ret;
69926+}
69927+
69928+void *
69929+acl_alloc_num(unsigned long num, unsigned long len)
69930+{
69931+ if (!len || (num > (PAGE_SIZE / len)))
69932+ return NULL;
69933+
69934+ return acl_alloc(num * len);
69935+}
69936+
69937+void
69938+acl_free_all(void)
69939+{
69940+ if (!current_alloc_state->alloc_stack)
69941+ return;
69942+
69943+ while (alloc_pop()) ;
69944+
69945+ if (current_alloc_state->alloc_stack) {
69946+ if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
69947+ kfree(current_alloc_state->alloc_stack);
69948+ else
69949+ vfree(current_alloc_state->alloc_stack);
69950+ }
69951+
69952+ current_alloc_state->alloc_stack = NULL;
69953+ current_alloc_state->alloc_stack_size = 1;
69954+ current_alloc_state->alloc_stack_next = 1;
69955+
69956+ return;
69957+}
69958+
69959+int
69960+acl_alloc_stack_init(unsigned long size)
69961+{
69962+ if ((size * sizeof (void *)) <= PAGE_SIZE)
69963+ current_alloc_state->alloc_stack =
69964+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
69965+ else
69966+ current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
69967+
69968+ current_alloc_state->alloc_stack_size = size;
69969+ current_alloc_state->alloc_stack_next = 1;
69970+
69971+ if (!current_alloc_state->alloc_stack)
69972+ return 0;
69973+ else
69974+ return 1;
69975+}
69976diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
69977new file mode 100644
69978index 0000000..bdd51ea
69979--- /dev/null
69980+++ b/grsecurity/gracl_cap.c
69981@@ -0,0 +1,110 @@
69982+#include <linux/kernel.h>
69983+#include <linux/module.h>
69984+#include <linux/sched.h>
69985+#include <linux/gracl.h>
69986+#include <linux/grsecurity.h>
69987+#include <linux/grinternal.h>
69988+
69989+extern const char *captab_log[];
69990+extern int captab_log_entries;
69991+
69992+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
69993+{
69994+ struct acl_subject_label *curracl;
69995+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
69996+ kernel_cap_t cap_audit = __cap_empty_set;
69997+
69998+ if (!gr_acl_is_enabled())
69999+ return 1;
70000+
70001+ curracl = task->acl;
70002+
70003+ cap_drop = curracl->cap_lower;
70004+ cap_mask = curracl->cap_mask;
70005+ cap_audit = curracl->cap_invert_audit;
70006+
70007+ while ((curracl = curracl->parent_subject)) {
70008+ /* if the cap isn't specified in the current computed mask but is specified in the
70009+ current level subject, and is lowered in the current level subject, then add
70010+ it to the set of dropped capabilities
70011+ otherwise, add the current level subject's mask to the current computed mask
70012+ */
70013+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
70014+ cap_raise(cap_mask, cap);
70015+ if (cap_raised(curracl->cap_lower, cap))
70016+ cap_raise(cap_drop, cap);
70017+ if (cap_raised(curracl->cap_invert_audit, cap))
70018+ cap_raise(cap_audit, cap);
70019+ }
70020+ }
70021+
70022+ if (!cap_raised(cap_drop, cap)) {
70023+ if (cap_raised(cap_audit, cap))
70024+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
70025+ return 1;
70026+ }
70027+
70028+ curracl = task->acl;
70029+
70030+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
70031+ && cap_raised(cred->cap_effective, cap)) {
70032+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
70033+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
70034+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
70035+ gr_to_filename(task->exec_file->f_path.dentry,
70036+ task->exec_file->f_path.mnt) : curracl->filename,
70037+ curracl->filename, 0UL,
70038+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
70039+ return 1;
70040+ }
70041+
70042+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
70043+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
70044+
70045+ return 0;
70046+}
70047+
70048+int
70049+gr_acl_is_capable(const int cap)
70050+{
70051+ return gr_task_acl_is_capable(current, current_cred(), cap);
70052+}
70053+
70054+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
70055+{
70056+ struct acl_subject_label *curracl;
70057+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
70058+
70059+ if (!gr_acl_is_enabled())
70060+ return 1;
70061+
70062+ curracl = task->acl;
70063+
70064+ cap_drop = curracl->cap_lower;
70065+ cap_mask = curracl->cap_mask;
70066+
70067+ while ((curracl = curracl->parent_subject)) {
70068+ /* if the cap isn't specified in the current computed mask but is specified in the
70069+ current level subject, and is lowered in the current level subject, then add
70070+ it to the set of dropped capabilities
70071+ otherwise, add the current level subject's mask to the current computed mask
70072+ */
70073+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
70074+ cap_raise(cap_mask, cap);
70075+ if (cap_raised(curracl->cap_lower, cap))
70076+ cap_raise(cap_drop, cap);
70077+ }
70078+ }
70079+
70080+ if (!cap_raised(cap_drop, cap))
70081+ return 1;
70082+
70083+ return 0;
70084+}
70085+
70086+int
70087+gr_acl_is_capable_nolog(const int cap)
70088+{
70089+ return gr_task_acl_is_capable_nolog(current, cap);
70090+}
70091+
70092diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
70093new file mode 100644
70094index 0000000..ca25605
70095--- /dev/null
70096+++ b/grsecurity/gracl_compat.c
70097@@ -0,0 +1,270 @@
70098+#include <linux/kernel.h>
70099+#include <linux/gracl.h>
70100+#include <linux/compat.h>
70101+#include <linux/gracl_compat.h>
70102+
70103+#include <asm/uaccess.h>
70104+
70105+int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
70106+{
70107+ struct gr_arg_wrapper_compat uwrapcompat;
70108+
70109+ if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
70110+ return -EFAULT;
70111+
70112+ if (((uwrapcompat.version != GRSECURITY_VERSION) &&
70113+ (uwrapcompat.version != 0x2901)) ||
70114+ (uwrapcompat.size != sizeof(struct gr_arg_compat)))
70115+ return -EINVAL;
70116+
70117+ uwrap->arg = compat_ptr(uwrapcompat.arg);
70118+ uwrap->version = uwrapcompat.version;
70119+ uwrap->size = sizeof(struct gr_arg);
70120+
70121+ return 0;
70122+}
70123+
70124+int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
70125+{
70126+ struct gr_arg_compat argcompat;
70127+
70128+ if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
70129+ return -EFAULT;
70130+
70131+ arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
70132+ arg->role_db.num_pointers = argcompat.role_db.num_pointers;
70133+ arg->role_db.num_roles = argcompat.role_db.num_roles;
70134+ arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
70135+ arg->role_db.num_subjects = argcompat.role_db.num_subjects;
70136+ arg->role_db.num_objects = argcompat.role_db.num_objects;
70137+
70138+ memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
70139+ memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
70140+ memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
70141+ memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
70142+ arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
70143+ arg->segv_device = argcompat.segv_device;
70144+ arg->segv_inode = argcompat.segv_inode;
70145+ arg->segv_uid = argcompat.segv_uid;
70146+ arg->num_sprole_pws = argcompat.num_sprole_pws;
70147+ arg->mode = argcompat.mode;
70148+
70149+ return 0;
70150+}
70151+
70152+int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
70153+{
70154+ struct acl_object_label_compat objcompat;
70155+
70156+ if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
70157+ return -EFAULT;
70158+
70159+ obj->filename = compat_ptr(objcompat.filename);
70160+ obj->inode = objcompat.inode;
70161+ obj->device = objcompat.device;
70162+ obj->mode = objcompat.mode;
70163+
70164+ obj->nested = compat_ptr(objcompat.nested);
70165+ obj->globbed = compat_ptr(objcompat.globbed);
70166+
70167+ obj->prev = compat_ptr(objcompat.prev);
70168+ obj->next = compat_ptr(objcompat.next);
70169+
70170+ return 0;
70171+}
70172+
70173+int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
70174+{
70175+ unsigned int i;
70176+ struct acl_subject_label_compat subjcompat;
70177+
70178+ if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
70179+ return -EFAULT;
70180+
70181+ subj->filename = compat_ptr(subjcompat.filename);
70182+ subj->inode = subjcompat.inode;
70183+ subj->device = subjcompat.device;
70184+ subj->mode = subjcompat.mode;
70185+ subj->cap_mask = subjcompat.cap_mask;
70186+ subj->cap_lower = subjcompat.cap_lower;
70187+ subj->cap_invert_audit = subjcompat.cap_invert_audit;
70188+
70189+ for (i = 0; i < GR_NLIMITS; i++) {
70190+ if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
70191+ subj->res[i].rlim_cur = RLIM_INFINITY;
70192+ else
70193+ subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
70194+ if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
70195+ subj->res[i].rlim_max = RLIM_INFINITY;
70196+ else
70197+ subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
70198+ }
70199+ subj->resmask = subjcompat.resmask;
70200+
70201+ subj->user_trans_type = subjcompat.user_trans_type;
70202+ subj->group_trans_type = subjcompat.group_trans_type;
70203+ subj->user_transitions = compat_ptr(subjcompat.user_transitions);
70204+ subj->group_transitions = compat_ptr(subjcompat.group_transitions);
70205+ subj->user_trans_num = subjcompat.user_trans_num;
70206+ subj->group_trans_num = subjcompat.group_trans_num;
70207+
70208+ memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
70209+ memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
70210+ subj->ip_type = subjcompat.ip_type;
70211+ subj->ips = compat_ptr(subjcompat.ips);
70212+ subj->ip_num = subjcompat.ip_num;
70213+ subj->inaddr_any_override = subjcompat.inaddr_any_override;
70214+
70215+ subj->crashes = subjcompat.crashes;
70216+ subj->expires = subjcompat.expires;
70217+
70218+ subj->parent_subject = compat_ptr(subjcompat.parent_subject);
70219+ subj->hash = compat_ptr(subjcompat.hash);
70220+ subj->prev = compat_ptr(subjcompat.prev);
70221+ subj->next = compat_ptr(subjcompat.next);
70222+
70223+ subj->obj_hash = compat_ptr(subjcompat.obj_hash);
70224+ subj->obj_hash_size = subjcompat.obj_hash_size;
70225+ subj->pax_flags = subjcompat.pax_flags;
70226+
70227+ return 0;
70228+}
70229+
70230+int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
70231+{
70232+ struct acl_role_label_compat rolecompat;
70233+
70234+ if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
70235+ return -EFAULT;
70236+
70237+ role->rolename = compat_ptr(rolecompat.rolename);
70238+ role->uidgid = rolecompat.uidgid;
70239+ role->roletype = rolecompat.roletype;
70240+
70241+ role->auth_attempts = rolecompat.auth_attempts;
70242+ role->expires = rolecompat.expires;
70243+
70244+ role->root_label = compat_ptr(rolecompat.root_label);
70245+ role->hash = compat_ptr(rolecompat.hash);
70246+
70247+ role->prev = compat_ptr(rolecompat.prev);
70248+ role->next = compat_ptr(rolecompat.next);
70249+
70250+ role->transitions = compat_ptr(rolecompat.transitions);
70251+ role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
70252+ role->domain_children = compat_ptr(rolecompat.domain_children);
70253+ role->domain_child_num = rolecompat.domain_child_num;
70254+
70255+ role->umask = rolecompat.umask;
70256+
70257+ role->subj_hash = compat_ptr(rolecompat.subj_hash);
70258+ role->subj_hash_size = rolecompat.subj_hash_size;
70259+
70260+ return 0;
70261+}
70262+
70263+int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
70264+{
70265+ struct role_allowed_ip_compat roleip_compat;
70266+
70267+ if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
70268+ return -EFAULT;
70269+
70270+ roleip->addr = roleip_compat.addr;
70271+ roleip->netmask = roleip_compat.netmask;
70272+
70273+ roleip->prev = compat_ptr(roleip_compat.prev);
70274+ roleip->next = compat_ptr(roleip_compat.next);
70275+
70276+ return 0;
70277+}
70278+
70279+int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
70280+{
70281+ struct role_transition_compat trans_compat;
70282+
70283+ if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
70284+ return -EFAULT;
70285+
70286+ trans->rolename = compat_ptr(trans_compat.rolename);
70287+
70288+ trans->prev = compat_ptr(trans_compat.prev);
70289+ trans->next = compat_ptr(trans_compat.next);
70290+
70291+ return 0;
70292+
70293+}
70294+
70295+int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
70296+{
70297+ struct gr_hash_struct_compat hash_compat;
70298+
70299+ if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
70300+ return -EFAULT;
70301+
70302+ hash->table = compat_ptr(hash_compat.table);
70303+ hash->nametable = compat_ptr(hash_compat.nametable);
70304+ hash->first = compat_ptr(hash_compat.first);
70305+
70306+ hash->table_size = hash_compat.table_size;
70307+ hash->used_size = hash_compat.used_size;
70308+
70309+ hash->type = hash_compat.type;
70310+
70311+ return 0;
70312+}
70313+
70314+int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
70315+{
70316+ compat_uptr_t ptrcompat;
70317+
70318+ if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
70319+ return -EFAULT;
70320+
70321+ *(void **)ptr = compat_ptr(ptrcompat);
70322+
70323+ return 0;
70324+}
70325+
70326+int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
70327+{
70328+ struct acl_ip_label_compat ip_compat;
70329+
70330+ if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
70331+ return -EFAULT;
70332+
70333+ ip->iface = compat_ptr(ip_compat.iface);
70334+ ip->addr = ip_compat.addr;
70335+ ip->netmask = ip_compat.netmask;
70336+ ip->low = ip_compat.low;
70337+ ip->high = ip_compat.high;
70338+ ip->mode = ip_compat.mode;
70339+ ip->type = ip_compat.type;
70340+
70341+ memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
70342+
70343+ ip->prev = compat_ptr(ip_compat.prev);
70344+ ip->next = compat_ptr(ip_compat.next);
70345+
70346+ return 0;
70347+}
70348+
70349+int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
70350+{
70351+ struct sprole_pw_compat pw_compat;
70352+
70353+ if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
70354+ return -EFAULT;
70355+
70356+ pw->rolename = compat_ptr(pw_compat.rolename);
70357+ memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
70358+ memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
70359+
70360+ return 0;
70361+}
70362+
70363+size_t get_gr_arg_wrapper_size_compat(void)
70364+{
70365+ return sizeof(struct gr_arg_wrapper_compat);
70366+}
70367+
70368diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
70369new file mode 100644
70370index 0000000..a89b1f4
70371--- /dev/null
70372+++ b/grsecurity/gracl_fs.c
70373@@ -0,0 +1,437 @@
70374+#include <linux/kernel.h>
70375+#include <linux/sched.h>
70376+#include <linux/types.h>
70377+#include <linux/fs.h>
70378+#include <linux/file.h>
70379+#include <linux/stat.h>
70380+#include <linux/grsecurity.h>
70381+#include <linux/grinternal.h>
70382+#include <linux/gracl.h>
70383+
70384+umode_t
70385+gr_acl_umask(void)
70386+{
70387+ if (unlikely(!gr_acl_is_enabled()))
70388+ return 0;
70389+
70390+ return current->role->umask;
70391+}
70392+
70393+__u32
70394+gr_acl_handle_hidden_file(const struct dentry * dentry,
70395+ const struct vfsmount * mnt)
70396+{
70397+ __u32 mode;
70398+
70399+ if (unlikely(d_is_negative(dentry)))
70400+ return GR_FIND;
70401+
70402+ mode =
70403+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
70404+
70405+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
70406+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
70407+ return mode;
70408+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
70409+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
70410+ return 0;
70411+ } else if (unlikely(!(mode & GR_FIND)))
70412+ return 0;
70413+
70414+ return GR_FIND;
70415+}
70416+
70417+__u32
70418+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
70419+ int acc_mode)
70420+{
70421+ __u32 reqmode = GR_FIND;
70422+ __u32 mode;
70423+
70424+ if (unlikely(d_is_negative(dentry)))
70425+ return reqmode;
70426+
70427+ if (acc_mode & MAY_APPEND)
70428+ reqmode |= GR_APPEND;
70429+ else if (acc_mode & MAY_WRITE)
70430+ reqmode |= GR_WRITE;
70431+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
70432+ reqmode |= GR_READ;
70433+
70434+ mode =
70435+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
70436+ mnt);
70437+
70438+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70439+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
70440+ reqmode & GR_READ ? " reading" : "",
70441+ reqmode & GR_WRITE ? " writing" : reqmode &
70442+ GR_APPEND ? " appending" : "");
70443+ return reqmode;
70444+ } else
70445+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70446+ {
70447+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
70448+ reqmode & GR_READ ? " reading" : "",
70449+ reqmode & GR_WRITE ? " writing" : reqmode &
70450+ GR_APPEND ? " appending" : "");
70451+ return 0;
70452+ } else if (unlikely((mode & reqmode) != reqmode))
70453+ return 0;
70454+
70455+ return reqmode;
70456+}
70457+
70458+__u32
70459+gr_acl_handle_creat(const struct dentry * dentry,
70460+ const struct dentry * p_dentry,
70461+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
70462+ const int imode)
70463+{
70464+ __u32 reqmode = GR_WRITE | GR_CREATE;
70465+ __u32 mode;
70466+
70467+ if (acc_mode & MAY_APPEND)
70468+ reqmode |= GR_APPEND;
70469+ // if a directory was required or the directory already exists, then
70470+ // don't count this open as a read
70471+ if ((acc_mode & MAY_READ) &&
70472+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
70473+ reqmode |= GR_READ;
70474+ if ((open_flags & O_CREAT) &&
70475+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
70476+ reqmode |= GR_SETID;
70477+
70478+ mode =
70479+ gr_check_create(dentry, p_dentry, p_mnt,
70480+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
70481+
70482+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70483+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
70484+ reqmode & GR_READ ? " reading" : "",
70485+ reqmode & GR_WRITE ? " writing" : reqmode &
70486+ GR_APPEND ? " appending" : "");
70487+ return reqmode;
70488+ } else
70489+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70490+ {
70491+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
70492+ reqmode & GR_READ ? " reading" : "",
70493+ reqmode & GR_WRITE ? " writing" : reqmode &
70494+ GR_APPEND ? " appending" : "");
70495+ return 0;
70496+ } else if (unlikely((mode & reqmode) != reqmode))
70497+ return 0;
70498+
70499+ return reqmode;
70500+}
70501+
70502+__u32
70503+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
70504+ const int fmode)
70505+{
70506+ __u32 mode, reqmode = GR_FIND;
70507+
70508+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
70509+ reqmode |= GR_EXEC;
70510+ if (fmode & S_IWOTH)
70511+ reqmode |= GR_WRITE;
70512+ if (fmode & S_IROTH)
70513+ reqmode |= GR_READ;
70514+
70515+ mode =
70516+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
70517+ mnt);
70518+
70519+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70520+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
70521+ reqmode & GR_READ ? " reading" : "",
70522+ reqmode & GR_WRITE ? " writing" : "",
70523+ reqmode & GR_EXEC ? " executing" : "");
70524+ return reqmode;
70525+ } else
70526+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70527+ {
70528+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
70529+ reqmode & GR_READ ? " reading" : "",
70530+ reqmode & GR_WRITE ? " writing" : "",
70531+ reqmode & GR_EXEC ? " executing" : "");
70532+ return 0;
70533+ } else if (unlikely((mode & reqmode) != reqmode))
70534+ return 0;
70535+
70536+ return reqmode;
70537+}
70538+
70539+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
70540+{
70541+ __u32 mode;
70542+
70543+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
70544+
70545+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
70546+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
70547+ return mode;
70548+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
70549+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
70550+ return 0;
70551+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
70552+ return 0;
70553+
70554+ return (reqmode);
70555+}
70556+
70557+__u32
70558+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
70559+{
70560+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
70561+}
70562+
70563+__u32
70564+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
70565+{
70566+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
70567+}
70568+
70569+__u32
70570+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
70571+{
70572+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
70573+}
70574+
70575+__u32
70576+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
70577+{
70578+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
70579+}
70580+
70581+__u32
70582+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
70583+ umode_t *modeptr)
70584+{
70585+ umode_t mode;
70586+
70587+ *modeptr &= ~gr_acl_umask();
70588+ mode = *modeptr;
70589+
70590+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
70591+ return 1;
70592+
70593+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
70594+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
70595+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
70596+ GR_CHMOD_ACL_MSG);
70597+ } else {
70598+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
70599+ }
70600+}
70601+
70602+__u32
70603+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
70604+{
70605+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
70606+}
70607+
70608+__u32
70609+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
70610+{
70611+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
70612+}
70613+
70614+__u32
70615+gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
70616+{
70617+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
70618+}
70619+
70620+__u32
70621+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
70622+{
70623+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
70624+}
70625+
70626+__u32
70627+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
70628+{
70629+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
70630+ GR_UNIXCONNECT_ACL_MSG);
70631+}
70632+
70633+/* hardlinks require at minimum create and link permission,
70634+ any additional privilege required is based on the
70635+ privilege of the file being linked to
70636+*/
70637+__u32
70638+gr_acl_handle_link(const struct dentry * new_dentry,
70639+ const struct dentry * parent_dentry,
70640+ const struct vfsmount * parent_mnt,
70641+ const struct dentry * old_dentry,
70642+ const struct vfsmount * old_mnt, const struct filename *to)
70643+{
70644+ __u32 mode;
70645+ __u32 needmode = GR_CREATE | GR_LINK;
70646+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
70647+
70648+ mode =
70649+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
70650+ old_mnt);
70651+
70652+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
70653+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
70654+ return mode;
70655+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
70656+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
70657+ return 0;
70658+ } else if (unlikely((mode & needmode) != needmode))
70659+ return 0;
70660+
70661+ return 1;
70662+}
70663+
70664+__u32
70665+gr_acl_handle_symlink(const struct dentry * new_dentry,
70666+ const struct dentry * parent_dentry,
70667+ const struct vfsmount * parent_mnt, const struct filename *from)
70668+{
70669+ __u32 needmode = GR_WRITE | GR_CREATE;
70670+ __u32 mode;
70671+
70672+ mode =
70673+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
70674+ GR_CREATE | GR_AUDIT_CREATE |
70675+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
70676+
70677+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
70678+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
70679+ return mode;
70680+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
70681+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
70682+ return 0;
70683+ } else if (unlikely((mode & needmode) != needmode))
70684+ return 0;
70685+
70686+ return (GR_WRITE | GR_CREATE);
70687+}
70688+
70689+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)
70690+{
70691+ __u32 mode;
70692+
70693+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
70694+
70695+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
70696+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
70697+ return mode;
70698+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
70699+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
70700+ return 0;
70701+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
70702+ return 0;
70703+
70704+ return (reqmode);
70705+}
70706+
70707+__u32
70708+gr_acl_handle_mknod(const struct dentry * new_dentry,
70709+ const struct dentry * parent_dentry,
70710+ const struct vfsmount * parent_mnt,
70711+ const int mode)
70712+{
70713+ __u32 reqmode = GR_WRITE | GR_CREATE;
70714+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
70715+ reqmode |= GR_SETID;
70716+
70717+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
70718+ reqmode, GR_MKNOD_ACL_MSG);
70719+}
70720+
70721+__u32
70722+gr_acl_handle_mkdir(const struct dentry *new_dentry,
70723+ const struct dentry *parent_dentry,
70724+ const struct vfsmount *parent_mnt)
70725+{
70726+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
70727+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
70728+}
70729+
70730+#define RENAME_CHECK_SUCCESS(old, new) \
70731+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
70732+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
70733+
70734+int
70735+gr_acl_handle_rename(struct dentry *new_dentry,
70736+ struct dentry *parent_dentry,
70737+ const struct vfsmount *parent_mnt,
70738+ struct dentry *old_dentry,
70739+ struct inode *old_parent_inode,
70740+ struct vfsmount *old_mnt, const struct filename *newname)
70741+{
70742+ __u32 comp1, comp2;
70743+ int error = 0;
70744+
70745+ if (unlikely(!gr_acl_is_enabled()))
70746+ return 0;
70747+
70748+ if (d_is_negative(new_dentry)) {
70749+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
70750+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
70751+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
70752+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
70753+ GR_DELETE | GR_AUDIT_DELETE |
70754+ GR_AUDIT_READ | GR_AUDIT_WRITE |
70755+ GR_SUPPRESS, old_mnt);
70756+ } else {
70757+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
70758+ GR_CREATE | GR_DELETE |
70759+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
70760+ GR_AUDIT_READ | GR_AUDIT_WRITE |
70761+ GR_SUPPRESS, parent_mnt);
70762+ comp2 =
70763+ gr_search_file(old_dentry,
70764+ GR_READ | GR_WRITE | GR_AUDIT_READ |
70765+ GR_DELETE | GR_AUDIT_DELETE |
70766+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
70767+ }
70768+
70769+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
70770+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
70771+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
70772+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
70773+ && !(comp2 & GR_SUPPRESS)) {
70774+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
70775+ error = -EACCES;
70776+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
70777+ error = -EACCES;
70778+
70779+ return error;
70780+}
70781+
70782+void
70783+gr_acl_handle_exit(void)
70784+{
70785+ u16 id;
70786+ char *rolename;
70787+
70788+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
70789+ !(current->role->roletype & GR_ROLE_PERSIST))) {
70790+ id = current->acl_role_id;
70791+ rolename = current->role->rolename;
70792+ gr_set_acls(1);
70793+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
70794+ }
70795+
70796+ gr_put_exec_file(current);
70797+ return;
70798+}
70799+
70800+int
70801+gr_acl_handle_procpidmem(const struct task_struct *task)
70802+{
70803+ if (unlikely(!gr_acl_is_enabled()))
70804+ return 0;
70805+
70806+ if (task != current && task->acl->mode & GR_PROTPROCFD)
70807+ return -EACCES;
70808+
70809+ return 0;
70810+}
70811diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
70812new file mode 100644
70813index 0000000..f056b81
70814--- /dev/null
70815+++ b/grsecurity/gracl_ip.c
70816@@ -0,0 +1,386 @@
70817+#include <linux/kernel.h>
70818+#include <asm/uaccess.h>
70819+#include <asm/errno.h>
70820+#include <net/sock.h>
70821+#include <linux/file.h>
70822+#include <linux/fs.h>
70823+#include <linux/net.h>
70824+#include <linux/in.h>
70825+#include <linux/skbuff.h>
70826+#include <linux/ip.h>
70827+#include <linux/udp.h>
70828+#include <linux/types.h>
70829+#include <linux/sched.h>
70830+#include <linux/netdevice.h>
70831+#include <linux/inetdevice.h>
70832+#include <linux/gracl.h>
70833+#include <linux/grsecurity.h>
70834+#include <linux/grinternal.h>
70835+
70836+#define GR_BIND 0x01
70837+#define GR_CONNECT 0x02
70838+#define GR_INVERT 0x04
70839+#define GR_BINDOVERRIDE 0x08
70840+#define GR_CONNECTOVERRIDE 0x10
70841+#define GR_SOCK_FAMILY 0x20
70842+
70843+static const char * gr_protocols[IPPROTO_MAX] = {
70844+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
70845+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
70846+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
70847+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
70848+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
70849+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
70850+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
70851+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
70852+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
70853+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
70854+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
70855+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
70856+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
70857+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
70858+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
70859+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
70860+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
70861+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
70862+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
70863+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
70864+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
70865+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
70866+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
70867+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
70868+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
70869+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
70870+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
70871+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
70872+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
70873+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
70874+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
70875+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
70876+ };
70877+
70878+static const char * gr_socktypes[SOCK_MAX] = {
70879+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
70880+ "unknown:7", "unknown:8", "unknown:9", "packet"
70881+ };
70882+
70883+static const char * gr_sockfamilies[AF_MAX+1] = {
70884+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
70885+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
70886+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
70887+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
70888+ };
70889+
70890+const char *
70891+gr_proto_to_name(unsigned char proto)
70892+{
70893+ return gr_protocols[proto];
70894+}
70895+
70896+const char *
70897+gr_socktype_to_name(unsigned char type)
70898+{
70899+ return gr_socktypes[type];
70900+}
70901+
70902+const char *
70903+gr_sockfamily_to_name(unsigned char family)
70904+{
70905+ return gr_sockfamilies[family];
70906+}
70907+
70908+extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
70909+
70910+int
70911+gr_search_socket(const int domain, const int type, const int protocol)
70912+{
70913+ struct acl_subject_label *curr;
70914+ const struct cred *cred = current_cred();
70915+
70916+ if (unlikely(!gr_acl_is_enabled()))
70917+ goto exit;
70918+
70919+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
70920+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
70921+ goto exit; // let the kernel handle it
70922+
70923+ curr = current->acl;
70924+
70925+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
70926+ /* the family is allowed, if this is PF_INET allow it only if
70927+ the extra sock type/protocol checks pass */
70928+ if (domain == PF_INET)
70929+ goto inet_check;
70930+ goto exit;
70931+ } else {
70932+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70933+ __u32 fakeip = 0;
70934+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70935+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
70936+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
70937+ gr_to_filename(current->exec_file->f_path.dentry,
70938+ current->exec_file->f_path.mnt) :
70939+ curr->filename, curr->filename,
70940+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
70941+ &current->signal->saved_ip);
70942+ goto exit;
70943+ }
70944+ goto exit_fail;
70945+ }
70946+
70947+inet_check:
70948+ /* the rest of this checking is for IPv4 only */
70949+ if (!curr->ips)
70950+ goto exit;
70951+
70952+ if ((curr->ip_type & (1U << type)) &&
70953+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
70954+ goto exit;
70955+
70956+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70957+ /* we don't place acls on raw sockets , and sometimes
70958+ dgram/ip sockets are opened for ioctl and not
70959+ bind/connect, so we'll fake a bind learn log */
70960+ if (type == SOCK_RAW || type == SOCK_PACKET) {
70961+ __u32 fakeip = 0;
70962+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70963+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
70964+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
70965+ gr_to_filename(current->exec_file->f_path.dentry,
70966+ current->exec_file->f_path.mnt) :
70967+ curr->filename, curr->filename,
70968+ &fakeip, 0, type,
70969+ protocol, GR_CONNECT, &current->signal->saved_ip);
70970+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
70971+ __u32 fakeip = 0;
70972+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70973+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
70974+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
70975+ gr_to_filename(current->exec_file->f_path.dentry,
70976+ current->exec_file->f_path.mnt) :
70977+ curr->filename, curr->filename,
70978+ &fakeip, 0, type,
70979+ protocol, GR_BIND, &current->signal->saved_ip);
70980+ }
70981+ /* we'll log when they use connect or bind */
70982+ goto exit;
70983+ }
70984+
70985+exit_fail:
70986+ if (domain == PF_INET)
70987+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
70988+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
70989+ else if (rcu_access_pointer(net_families[domain]) != NULL)
70990+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
70991+ gr_socktype_to_name(type), protocol);
70992+
70993+ return 0;
70994+exit:
70995+ return 1;
70996+}
70997+
70998+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)
70999+{
71000+ if ((ip->mode & mode) &&
71001+ (ip_port >= ip->low) &&
71002+ (ip_port <= ip->high) &&
71003+ ((ntohl(ip_addr) & our_netmask) ==
71004+ (ntohl(our_addr) & our_netmask))
71005+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
71006+ && (ip->type & (1U << type))) {
71007+ if (ip->mode & GR_INVERT)
71008+ return 2; // specifically denied
71009+ else
71010+ return 1; // allowed
71011+ }
71012+
71013+ return 0; // not specifically allowed, may continue parsing
71014+}
71015+
71016+static int
71017+gr_search_connectbind(const int full_mode, struct sock *sk,
71018+ struct sockaddr_in *addr, const int type)
71019+{
71020+ char iface[IFNAMSIZ] = {0};
71021+ struct acl_subject_label *curr;
71022+ struct acl_ip_label *ip;
71023+ struct inet_sock *isk;
71024+ struct net_device *dev;
71025+ struct in_device *idev;
71026+ unsigned long i;
71027+ int ret;
71028+ int mode = full_mode & (GR_BIND | GR_CONNECT);
71029+ __u32 ip_addr = 0;
71030+ __u32 our_addr;
71031+ __u32 our_netmask;
71032+ char *p;
71033+ __u16 ip_port = 0;
71034+ const struct cred *cred = current_cred();
71035+
71036+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
71037+ return 0;
71038+
71039+ curr = current->acl;
71040+ isk = inet_sk(sk);
71041+
71042+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
71043+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
71044+ addr->sin_addr.s_addr = curr->inaddr_any_override;
71045+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
71046+ struct sockaddr_in saddr;
71047+ int err;
71048+
71049+ saddr.sin_family = AF_INET;
71050+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
71051+ saddr.sin_port = isk->inet_sport;
71052+
71053+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
71054+ if (err)
71055+ return err;
71056+
71057+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
71058+ if (err)
71059+ return err;
71060+ }
71061+
71062+ if (!curr->ips)
71063+ return 0;
71064+
71065+ ip_addr = addr->sin_addr.s_addr;
71066+ ip_port = ntohs(addr->sin_port);
71067+
71068+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
71069+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
71070+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
71071+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
71072+ gr_to_filename(current->exec_file->f_path.dentry,
71073+ current->exec_file->f_path.mnt) :
71074+ curr->filename, curr->filename,
71075+ &ip_addr, ip_port, type,
71076+ sk->sk_protocol, mode, &current->signal->saved_ip);
71077+ return 0;
71078+ }
71079+
71080+ for (i = 0; i < curr->ip_num; i++) {
71081+ ip = *(curr->ips + i);
71082+ if (ip->iface != NULL) {
71083+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
71084+ p = strchr(iface, ':');
71085+ if (p != NULL)
71086+ *p = '\0';
71087+ dev = dev_get_by_name(sock_net(sk), iface);
71088+ if (dev == NULL)
71089+ continue;
71090+ idev = in_dev_get(dev);
71091+ if (idev == NULL) {
71092+ dev_put(dev);
71093+ continue;
71094+ }
71095+ rcu_read_lock();
71096+ for_ifa(idev) {
71097+ if (!strcmp(ip->iface, ifa->ifa_label)) {
71098+ our_addr = ifa->ifa_address;
71099+ our_netmask = 0xffffffff;
71100+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
71101+ if (ret == 1) {
71102+ rcu_read_unlock();
71103+ in_dev_put(idev);
71104+ dev_put(dev);
71105+ return 0;
71106+ } else if (ret == 2) {
71107+ rcu_read_unlock();
71108+ in_dev_put(idev);
71109+ dev_put(dev);
71110+ goto denied;
71111+ }
71112+ }
71113+ } endfor_ifa(idev);
71114+ rcu_read_unlock();
71115+ in_dev_put(idev);
71116+ dev_put(dev);
71117+ } else {
71118+ our_addr = ip->addr;
71119+ our_netmask = ip->netmask;
71120+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
71121+ if (ret == 1)
71122+ return 0;
71123+ else if (ret == 2)
71124+ goto denied;
71125+ }
71126+ }
71127+
71128+denied:
71129+ if (mode == GR_BIND)
71130+ 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));
71131+ else if (mode == GR_CONNECT)
71132+ 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));
71133+
71134+ return -EACCES;
71135+}
71136+
71137+int
71138+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
71139+{
71140+ /* always allow disconnection of dgram sockets with connect */
71141+ if (addr->sin_family == AF_UNSPEC)
71142+ return 0;
71143+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
71144+}
71145+
71146+int
71147+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
71148+{
71149+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
71150+}
71151+
71152+int gr_search_listen(struct socket *sock)
71153+{
71154+ struct sock *sk = sock->sk;
71155+ struct sockaddr_in addr;
71156+
71157+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
71158+ addr.sin_port = inet_sk(sk)->inet_sport;
71159+
71160+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
71161+}
71162+
71163+int gr_search_accept(struct socket *sock)
71164+{
71165+ struct sock *sk = sock->sk;
71166+ struct sockaddr_in addr;
71167+
71168+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
71169+ addr.sin_port = inet_sk(sk)->inet_sport;
71170+
71171+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
71172+}
71173+
71174+int
71175+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
71176+{
71177+ if (addr)
71178+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
71179+ else {
71180+ struct sockaddr_in sin;
71181+ const struct inet_sock *inet = inet_sk(sk);
71182+
71183+ sin.sin_addr.s_addr = inet->inet_daddr;
71184+ sin.sin_port = inet->inet_dport;
71185+
71186+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
71187+ }
71188+}
71189+
71190+int
71191+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
71192+{
71193+ struct sockaddr_in sin;
71194+
71195+ if (unlikely(skb->len < sizeof (struct udphdr)))
71196+ return 0; // skip this packet
71197+
71198+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
71199+ sin.sin_port = udp_hdr(skb)->source;
71200+
71201+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
71202+}
71203diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
71204new file mode 100644
71205index 0000000..25f54ef
71206--- /dev/null
71207+++ b/grsecurity/gracl_learn.c
71208@@ -0,0 +1,207 @@
71209+#include <linux/kernel.h>
71210+#include <linux/mm.h>
71211+#include <linux/sched.h>
71212+#include <linux/poll.h>
71213+#include <linux/string.h>
71214+#include <linux/file.h>
71215+#include <linux/types.h>
71216+#include <linux/vmalloc.h>
71217+#include <linux/grinternal.h>
71218+
71219+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
71220+ size_t count, loff_t *ppos);
71221+extern int gr_acl_is_enabled(void);
71222+
71223+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
71224+static int gr_learn_attached;
71225+
71226+/* use a 512k buffer */
71227+#define LEARN_BUFFER_SIZE (512 * 1024)
71228+
71229+static DEFINE_SPINLOCK(gr_learn_lock);
71230+static DEFINE_MUTEX(gr_learn_user_mutex);
71231+
71232+/* we need to maintain two buffers, so that the kernel context of grlearn
71233+ uses a semaphore around the userspace copying, and the other kernel contexts
71234+ use a spinlock when copying into the buffer, since they cannot sleep
71235+*/
71236+static char *learn_buffer;
71237+static char *learn_buffer_user;
71238+static int learn_buffer_len;
71239+static int learn_buffer_user_len;
71240+
71241+static ssize_t
71242+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
71243+{
71244+ DECLARE_WAITQUEUE(wait, current);
71245+ ssize_t retval = 0;
71246+
71247+ add_wait_queue(&learn_wait, &wait);
71248+ set_current_state(TASK_INTERRUPTIBLE);
71249+ do {
71250+ mutex_lock(&gr_learn_user_mutex);
71251+ spin_lock(&gr_learn_lock);
71252+ if (learn_buffer_len)
71253+ break;
71254+ spin_unlock(&gr_learn_lock);
71255+ mutex_unlock(&gr_learn_user_mutex);
71256+ if (file->f_flags & O_NONBLOCK) {
71257+ retval = -EAGAIN;
71258+ goto out;
71259+ }
71260+ if (signal_pending(current)) {
71261+ retval = -ERESTARTSYS;
71262+ goto out;
71263+ }
71264+
71265+ schedule();
71266+ } while (1);
71267+
71268+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
71269+ learn_buffer_user_len = learn_buffer_len;
71270+ retval = learn_buffer_len;
71271+ learn_buffer_len = 0;
71272+
71273+ spin_unlock(&gr_learn_lock);
71274+
71275+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
71276+ retval = -EFAULT;
71277+
71278+ mutex_unlock(&gr_learn_user_mutex);
71279+out:
71280+ set_current_state(TASK_RUNNING);
71281+ remove_wait_queue(&learn_wait, &wait);
71282+ return retval;
71283+}
71284+
71285+static unsigned int
71286+poll_learn(struct file * file, poll_table * wait)
71287+{
71288+ poll_wait(file, &learn_wait, wait);
71289+
71290+ if (learn_buffer_len)
71291+ return (POLLIN | POLLRDNORM);
71292+
71293+ return 0;
71294+}
71295+
71296+void
71297+gr_clear_learn_entries(void)
71298+{
71299+ char *tmp;
71300+
71301+ mutex_lock(&gr_learn_user_mutex);
71302+ spin_lock(&gr_learn_lock);
71303+ tmp = learn_buffer;
71304+ learn_buffer = NULL;
71305+ spin_unlock(&gr_learn_lock);
71306+ if (tmp)
71307+ vfree(tmp);
71308+ if (learn_buffer_user != NULL) {
71309+ vfree(learn_buffer_user);
71310+ learn_buffer_user = NULL;
71311+ }
71312+ learn_buffer_len = 0;
71313+ mutex_unlock(&gr_learn_user_mutex);
71314+
71315+ return;
71316+}
71317+
71318+void
71319+gr_add_learn_entry(const char *fmt, ...)
71320+{
71321+ va_list args;
71322+ unsigned int len;
71323+
71324+ if (!gr_learn_attached)
71325+ return;
71326+
71327+ spin_lock(&gr_learn_lock);
71328+
71329+ /* leave a gap at the end so we know when it's "full" but don't have to
71330+ compute the exact length of the string we're trying to append
71331+ */
71332+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
71333+ spin_unlock(&gr_learn_lock);
71334+ wake_up_interruptible(&learn_wait);
71335+ return;
71336+ }
71337+ if (learn_buffer == NULL) {
71338+ spin_unlock(&gr_learn_lock);
71339+ return;
71340+ }
71341+
71342+ va_start(args, fmt);
71343+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
71344+ va_end(args);
71345+
71346+ learn_buffer_len += len + 1;
71347+
71348+ spin_unlock(&gr_learn_lock);
71349+ wake_up_interruptible(&learn_wait);
71350+
71351+ return;
71352+}
71353+
71354+static int
71355+open_learn(struct inode *inode, struct file *file)
71356+{
71357+ if (file->f_mode & FMODE_READ && gr_learn_attached)
71358+ return -EBUSY;
71359+ if (file->f_mode & FMODE_READ) {
71360+ int retval = 0;
71361+ mutex_lock(&gr_learn_user_mutex);
71362+ if (learn_buffer == NULL)
71363+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
71364+ if (learn_buffer_user == NULL)
71365+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
71366+ if (learn_buffer == NULL) {
71367+ retval = -ENOMEM;
71368+ goto out_error;
71369+ }
71370+ if (learn_buffer_user == NULL) {
71371+ retval = -ENOMEM;
71372+ goto out_error;
71373+ }
71374+ learn_buffer_len = 0;
71375+ learn_buffer_user_len = 0;
71376+ gr_learn_attached = 1;
71377+out_error:
71378+ mutex_unlock(&gr_learn_user_mutex);
71379+ return retval;
71380+ }
71381+ return 0;
71382+}
71383+
71384+static int
71385+close_learn(struct inode *inode, struct file *file)
71386+{
71387+ if (file->f_mode & FMODE_READ) {
71388+ char *tmp = NULL;
71389+ mutex_lock(&gr_learn_user_mutex);
71390+ spin_lock(&gr_learn_lock);
71391+ tmp = learn_buffer;
71392+ learn_buffer = NULL;
71393+ spin_unlock(&gr_learn_lock);
71394+ if (tmp)
71395+ vfree(tmp);
71396+ if (learn_buffer_user != NULL) {
71397+ vfree(learn_buffer_user);
71398+ learn_buffer_user = NULL;
71399+ }
71400+ learn_buffer_len = 0;
71401+ learn_buffer_user_len = 0;
71402+ gr_learn_attached = 0;
71403+ mutex_unlock(&gr_learn_user_mutex);
71404+ }
71405+
71406+ return 0;
71407+}
71408+
71409+const struct file_operations grsec_fops = {
71410+ .read = read_learn,
71411+ .write = write_grsec_handler,
71412+ .open = open_learn,
71413+ .release = close_learn,
71414+ .poll = poll_learn,
71415+};
71416diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
71417new file mode 100644
71418index 0000000..361a099
71419--- /dev/null
71420+++ b/grsecurity/gracl_policy.c
71421@@ -0,0 +1,1782 @@
71422+#include <linux/kernel.h>
71423+#include <linux/module.h>
71424+#include <linux/sched.h>
71425+#include <linux/mm.h>
71426+#include <linux/file.h>
71427+#include <linux/fs.h>
71428+#include <linux/namei.h>
71429+#include <linux/mount.h>
71430+#include <linux/tty.h>
71431+#include <linux/proc_fs.h>
71432+#include <linux/lglock.h>
71433+#include <linux/slab.h>
71434+#include <linux/vmalloc.h>
71435+#include <linux/types.h>
71436+#include <linux/sysctl.h>
71437+#include <linux/netdevice.h>
71438+#include <linux/ptrace.h>
71439+#include <linux/gracl.h>
71440+#include <linux/gralloc.h>
71441+#include <linux/security.h>
71442+#include <linux/grinternal.h>
71443+#include <linux/pid_namespace.h>
71444+#include <linux/stop_machine.h>
71445+#include <linux/fdtable.h>
71446+#include <linux/percpu.h>
71447+#include <linux/lglock.h>
71448+#include <linux/hugetlb.h>
71449+#include <linux/posix-timers.h>
71450+#include "../fs/mount.h"
71451+
71452+#include <asm/uaccess.h>
71453+#include <asm/errno.h>
71454+#include <asm/mman.h>
71455+
71456+extern struct gr_policy_state *polstate;
71457+
71458+#define FOR_EACH_ROLE_START(role) \
71459+ role = polstate->role_list; \
71460+ while (role) {
71461+
71462+#define FOR_EACH_ROLE_END(role) \
71463+ role = role->prev; \
71464+ }
71465+
71466+struct path gr_real_root;
71467+
71468+extern struct gr_alloc_state *current_alloc_state;
71469+
71470+u16 acl_sp_role_value;
71471+
71472+static DEFINE_MUTEX(gr_dev_mutex);
71473+
71474+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
71475+extern void gr_clear_learn_entries(void);
71476+
71477+static struct gr_arg gr_usermode;
71478+static unsigned char gr_system_salt[GR_SALT_LEN];
71479+static unsigned char gr_system_sum[GR_SHA_LEN];
71480+
71481+static unsigned int gr_auth_attempts = 0;
71482+static unsigned long gr_auth_expires = 0UL;
71483+
71484+struct acl_object_label *fakefs_obj_rw;
71485+struct acl_object_label *fakefs_obj_rwx;
71486+
71487+extern int gr_init_uidset(void);
71488+extern void gr_free_uidset(void);
71489+extern void gr_remove_uid(uid_t uid);
71490+extern int gr_find_uid(uid_t uid);
71491+
71492+extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
71493+extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
71494+extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
71495+extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
71496+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);
71497+extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
71498+extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
71499+extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
71500+extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
71501+extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
71502+extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
71503+extern void assign_special_role(const char *rolename);
71504+extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
71505+extern int gr_rbac_disable(void *unused);
71506+extern void gr_enable_rbac_system(void);
71507+
71508+static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
71509+{
71510+ if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
71511+ return -EFAULT;
71512+
71513+ return 0;
71514+}
71515+
71516+static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
71517+{
71518+ if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
71519+ return -EFAULT;
71520+
71521+ return 0;
71522+}
71523+
71524+static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
71525+{
71526+ if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
71527+ return -EFAULT;
71528+
71529+ return 0;
71530+}
71531+
71532+static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
71533+{
71534+ if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
71535+ return -EFAULT;
71536+
71537+ return 0;
71538+}
71539+
71540+static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
71541+{
71542+ if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
71543+ return -EFAULT;
71544+
71545+ return 0;
71546+}
71547+
71548+static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
71549+{
71550+ if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
71551+ return -EFAULT;
71552+
71553+ return 0;
71554+}
71555+
71556+static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
71557+{
71558+ if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
71559+ return -EFAULT;
71560+
71561+ return 0;
71562+}
71563+
71564+static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
71565+{
71566+ if (copy_from_user(trans, userp, sizeof(struct role_transition)))
71567+ return -EFAULT;
71568+
71569+ return 0;
71570+}
71571+
71572+int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
71573+{
71574+ if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
71575+ return -EFAULT;
71576+
71577+ return 0;
71578+}
71579+
71580+static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
71581+{
71582+ if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
71583+ return -EFAULT;
71584+
71585+ if (((uwrap->version != GRSECURITY_VERSION) &&
71586+ (uwrap->version != 0x2901)) ||
71587+ (uwrap->size != sizeof(struct gr_arg)))
71588+ return -EINVAL;
71589+
71590+ return 0;
71591+}
71592+
71593+static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
71594+{
71595+ if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
71596+ return -EFAULT;
71597+
71598+ return 0;
71599+}
71600+
71601+static size_t get_gr_arg_wrapper_size_normal(void)
71602+{
71603+ return sizeof(struct gr_arg_wrapper);
71604+}
71605+
71606+#ifdef CONFIG_COMPAT
71607+extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
71608+extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
71609+extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
71610+extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
71611+extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
71612+extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
71613+extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
71614+extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
71615+extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
71616+extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
71617+extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
71618+extern size_t get_gr_arg_wrapper_size_compat(void);
71619+
71620+int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
71621+int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
71622+int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
71623+int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
71624+int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
71625+int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
71626+int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
71627+int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
71628+int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
71629+int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
71630+int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
71631+size_t (* get_gr_arg_wrapper_size)(void) __read_only;
71632+
71633+#else
71634+#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
71635+#define copy_gr_arg copy_gr_arg_normal
71636+#define copy_gr_hash_struct copy_gr_hash_struct_normal
71637+#define copy_acl_object_label copy_acl_object_label_normal
71638+#define copy_acl_subject_label copy_acl_subject_label_normal
71639+#define copy_acl_role_label copy_acl_role_label_normal
71640+#define copy_acl_ip_label copy_acl_ip_label_normal
71641+#define copy_pointer_from_array copy_pointer_from_array_normal
71642+#define copy_sprole_pw copy_sprole_pw_normal
71643+#define copy_role_transition copy_role_transition_normal
71644+#define copy_role_allowed_ip copy_role_allowed_ip_normal
71645+#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
71646+#endif
71647+
71648+static struct acl_subject_label *
71649+lookup_subject_map(const struct acl_subject_label *userp)
71650+{
71651+ unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
71652+ struct subject_map *match;
71653+
71654+ match = polstate->subj_map_set.s_hash[index];
71655+
71656+ while (match && match->user != userp)
71657+ match = match->next;
71658+
71659+ if (match != NULL)
71660+ return match->kernel;
71661+ else
71662+ return NULL;
71663+}
71664+
71665+static void
71666+insert_subj_map_entry(struct subject_map *subjmap)
71667+{
71668+ unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
71669+ struct subject_map **curr;
71670+
71671+ subjmap->prev = NULL;
71672+
71673+ curr = &polstate->subj_map_set.s_hash[index];
71674+ if (*curr != NULL)
71675+ (*curr)->prev = subjmap;
71676+
71677+ subjmap->next = *curr;
71678+ *curr = subjmap;
71679+
71680+ return;
71681+}
71682+
71683+static void
71684+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
71685+{
71686+ unsigned int index =
71687+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
71688+ struct acl_role_label **curr;
71689+ struct acl_role_label *tmp, *tmp2;
71690+
71691+ curr = &polstate->acl_role_set.r_hash[index];
71692+
71693+ /* simple case, slot is empty, just set it to our role */
71694+ if (*curr == NULL) {
71695+ *curr = role;
71696+ } else {
71697+ /* example:
71698+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
71699+ 2 -> 3
71700+ */
71701+ /* first check to see if we can already be reached via this slot */
71702+ tmp = *curr;
71703+ while (tmp && tmp != role)
71704+ tmp = tmp->next;
71705+ if (tmp == role) {
71706+ /* we don't need to add ourselves to this slot's chain */
71707+ return;
71708+ }
71709+ /* we need to add ourselves to this chain, two cases */
71710+ if (role->next == NULL) {
71711+ /* simple case, append the current chain to our role */
71712+ role->next = *curr;
71713+ *curr = role;
71714+ } else {
71715+ /* 1 -> 2 -> 3 -> 4
71716+ 2 -> 3 -> 4
71717+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
71718+ */
71719+ /* trickier case: walk our role's chain until we find
71720+ the role for the start of the current slot's chain */
71721+ tmp = role;
71722+ tmp2 = *curr;
71723+ while (tmp->next && tmp->next != tmp2)
71724+ tmp = tmp->next;
71725+ if (tmp->next == tmp2) {
71726+ /* from example above, we found 3, so just
71727+ replace this slot's chain with ours */
71728+ *curr = role;
71729+ } else {
71730+ /* we didn't find a subset of our role's chain
71731+ in the current slot's chain, so append their
71732+ chain to ours, and set us as the first role in
71733+ the slot's chain
71734+
71735+ we could fold this case with the case above,
71736+ but making it explicit for clarity
71737+ */
71738+ tmp->next = tmp2;
71739+ *curr = role;
71740+ }
71741+ }
71742+ }
71743+
71744+ return;
71745+}
71746+
71747+static void
71748+insert_acl_role_label(struct acl_role_label *role)
71749+{
71750+ int i;
71751+
71752+ if (polstate->role_list == NULL) {
71753+ polstate->role_list = role;
71754+ role->prev = NULL;
71755+ } else {
71756+ role->prev = polstate->role_list;
71757+ polstate->role_list = role;
71758+ }
71759+
71760+ /* used for hash chains */
71761+ role->next = NULL;
71762+
71763+ if (role->roletype & GR_ROLE_DOMAIN) {
71764+ for (i = 0; i < role->domain_child_num; i++)
71765+ __insert_acl_role_label(role, role->domain_children[i]);
71766+ } else
71767+ __insert_acl_role_label(role, role->uidgid);
71768+}
71769+
71770+static int
71771+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
71772+{
71773+ struct name_entry **curr, *nentry;
71774+ struct inodev_entry *ientry;
71775+ unsigned int len = strlen(name);
71776+ unsigned int key = full_name_hash(name, len);
71777+ unsigned int index = key % polstate->name_set.n_size;
71778+
71779+ curr = &polstate->name_set.n_hash[index];
71780+
71781+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
71782+ curr = &((*curr)->next);
71783+
71784+ if (*curr != NULL)
71785+ return 1;
71786+
71787+ nentry = acl_alloc(sizeof (struct name_entry));
71788+ if (nentry == NULL)
71789+ return 0;
71790+ ientry = acl_alloc(sizeof (struct inodev_entry));
71791+ if (ientry == NULL)
71792+ return 0;
71793+ ientry->nentry = nentry;
71794+
71795+ nentry->key = key;
71796+ nentry->name = name;
71797+ nentry->inode = inode;
71798+ nentry->device = device;
71799+ nentry->len = len;
71800+ nentry->deleted = deleted;
71801+
71802+ nentry->prev = NULL;
71803+ curr = &polstate->name_set.n_hash[index];
71804+ if (*curr != NULL)
71805+ (*curr)->prev = nentry;
71806+ nentry->next = *curr;
71807+ *curr = nentry;
71808+
71809+ /* insert us into the table searchable by inode/dev */
71810+ __insert_inodev_entry(polstate, ientry);
71811+
71812+ return 1;
71813+}
71814+
71815+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
71816+
71817+static void *
71818+create_table(__u32 * len, int elementsize)
71819+{
71820+ unsigned int table_sizes[] = {
71821+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
71822+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
71823+ 4194301, 8388593, 16777213, 33554393, 67108859
71824+ };
71825+ void *newtable = NULL;
71826+ unsigned int pwr = 0;
71827+
71828+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
71829+ table_sizes[pwr] <= *len)
71830+ pwr++;
71831+
71832+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
71833+ return newtable;
71834+
71835+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
71836+ newtable =
71837+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
71838+ else
71839+ newtable = vmalloc(table_sizes[pwr] * elementsize);
71840+
71841+ *len = table_sizes[pwr];
71842+
71843+ return newtable;
71844+}
71845+
71846+static int
71847+init_variables(const struct gr_arg *arg, bool reload)
71848+{
71849+ struct task_struct *reaper = init_pid_ns.child_reaper;
71850+ unsigned int stacksize;
71851+
71852+ polstate->subj_map_set.s_size = arg->role_db.num_subjects;
71853+ polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
71854+ polstate->name_set.n_size = arg->role_db.num_objects;
71855+ polstate->inodev_set.i_size = arg->role_db.num_objects;
71856+
71857+ if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
71858+ !polstate->name_set.n_size || !polstate->inodev_set.i_size)
71859+ return 1;
71860+
71861+ if (!reload) {
71862+ if (!gr_init_uidset())
71863+ return 1;
71864+ }
71865+
71866+ /* set up the stack that holds allocation info */
71867+
71868+ stacksize = arg->role_db.num_pointers + 5;
71869+
71870+ if (!acl_alloc_stack_init(stacksize))
71871+ return 1;
71872+
71873+ if (!reload) {
71874+ /* grab reference for the real root dentry and vfsmount */
71875+ get_fs_root(reaper->fs, &gr_real_root);
71876+
71877+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71878+ 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);
71879+#endif
71880+
71881+ fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
71882+ if (fakefs_obj_rw == NULL)
71883+ return 1;
71884+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
71885+
71886+ fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
71887+ if (fakefs_obj_rwx == NULL)
71888+ return 1;
71889+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
71890+ }
71891+
71892+ polstate->subj_map_set.s_hash =
71893+ (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
71894+ polstate->acl_role_set.r_hash =
71895+ (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
71896+ polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
71897+ polstate->inodev_set.i_hash =
71898+ (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
71899+
71900+ if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
71901+ !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
71902+ return 1;
71903+
71904+ memset(polstate->subj_map_set.s_hash, 0,
71905+ sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
71906+ memset(polstate->acl_role_set.r_hash, 0,
71907+ sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
71908+ memset(polstate->name_set.n_hash, 0,
71909+ sizeof (struct name_entry *) * polstate->name_set.n_size);
71910+ memset(polstate->inodev_set.i_hash, 0,
71911+ sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
71912+
71913+ return 0;
71914+}
71915+
71916+/* free information not needed after startup
71917+ currently contains user->kernel pointer mappings for subjects
71918+*/
71919+
71920+static void
71921+free_init_variables(void)
71922+{
71923+ __u32 i;
71924+
71925+ if (polstate->subj_map_set.s_hash) {
71926+ for (i = 0; i < polstate->subj_map_set.s_size; i++) {
71927+ if (polstate->subj_map_set.s_hash[i]) {
71928+ kfree(polstate->subj_map_set.s_hash[i]);
71929+ polstate->subj_map_set.s_hash[i] = NULL;
71930+ }
71931+ }
71932+
71933+ if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
71934+ PAGE_SIZE)
71935+ kfree(polstate->subj_map_set.s_hash);
71936+ else
71937+ vfree(polstate->subj_map_set.s_hash);
71938+ }
71939+
71940+ return;
71941+}
71942+
71943+static void
71944+free_variables(bool reload)
71945+{
71946+ struct acl_subject_label *s;
71947+ struct acl_role_label *r;
71948+ struct task_struct *task, *task2;
71949+ unsigned int x;
71950+
71951+ if (!reload) {
71952+ gr_clear_learn_entries();
71953+
71954+ read_lock(&tasklist_lock);
71955+ do_each_thread(task2, task) {
71956+ task->acl_sp_role = 0;
71957+ task->acl_role_id = 0;
71958+ task->inherited = 0;
71959+ task->acl = NULL;
71960+ task->role = NULL;
71961+ } while_each_thread(task2, task);
71962+ read_unlock(&tasklist_lock);
71963+
71964+ kfree(fakefs_obj_rw);
71965+ fakefs_obj_rw = NULL;
71966+ kfree(fakefs_obj_rwx);
71967+ fakefs_obj_rwx = NULL;
71968+
71969+ /* release the reference to the real root dentry and vfsmount */
71970+ path_put(&gr_real_root);
71971+ memset(&gr_real_root, 0, sizeof(gr_real_root));
71972+ }
71973+
71974+ /* free all object hash tables */
71975+
71976+ FOR_EACH_ROLE_START(r)
71977+ if (r->subj_hash == NULL)
71978+ goto next_role;
71979+ FOR_EACH_SUBJECT_START(r, s, x)
71980+ if (s->obj_hash == NULL)
71981+ break;
71982+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
71983+ kfree(s->obj_hash);
71984+ else
71985+ vfree(s->obj_hash);
71986+ FOR_EACH_SUBJECT_END(s, x)
71987+ FOR_EACH_NESTED_SUBJECT_START(r, s)
71988+ if (s->obj_hash == NULL)
71989+ break;
71990+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
71991+ kfree(s->obj_hash);
71992+ else
71993+ vfree(s->obj_hash);
71994+ FOR_EACH_NESTED_SUBJECT_END(s)
71995+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
71996+ kfree(r->subj_hash);
71997+ else
71998+ vfree(r->subj_hash);
71999+ r->subj_hash = NULL;
72000+next_role:
72001+ FOR_EACH_ROLE_END(r)
72002+
72003+ acl_free_all();
72004+
72005+ if (polstate->acl_role_set.r_hash) {
72006+ if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
72007+ PAGE_SIZE)
72008+ kfree(polstate->acl_role_set.r_hash);
72009+ else
72010+ vfree(polstate->acl_role_set.r_hash);
72011+ }
72012+ if (polstate->name_set.n_hash) {
72013+ if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
72014+ PAGE_SIZE)
72015+ kfree(polstate->name_set.n_hash);
72016+ else
72017+ vfree(polstate->name_set.n_hash);
72018+ }
72019+
72020+ if (polstate->inodev_set.i_hash) {
72021+ if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
72022+ PAGE_SIZE)
72023+ kfree(polstate->inodev_set.i_hash);
72024+ else
72025+ vfree(polstate->inodev_set.i_hash);
72026+ }
72027+
72028+ if (!reload)
72029+ gr_free_uidset();
72030+
72031+ memset(&polstate->name_set, 0, sizeof (struct name_db));
72032+ memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
72033+ memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
72034+ memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
72035+
72036+ polstate->default_role = NULL;
72037+ polstate->kernel_role = NULL;
72038+ polstate->role_list = NULL;
72039+
72040+ return;
72041+}
72042+
72043+static struct acl_subject_label *
72044+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
72045+
72046+static int alloc_and_copy_string(char **name, unsigned int maxlen)
72047+{
72048+ unsigned int len = strnlen_user(*name, maxlen);
72049+ char *tmp;
72050+
72051+ if (!len || len >= maxlen)
72052+ return -EINVAL;
72053+
72054+ if ((tmp = (char *) acl_alloc(len)) == NULL)
72055+ return -ENOMEM;
72056+
72057+ if (copy_from_user(tmp, *name, len))
72058+ return -EFAULT;
72059+
72060+ tmp[len-1] = '\0';
72061+ *name = tmp;
72062+
72063+ return 0;
72064+}
72065+
72066+static int
72067+copy_user_glob(struct acl_object_label *obj)
72068+{
72069+ struct acl_object_label *g_tmp, **guser;
72070+ int error;
72071+
72072+ if (obj->globbed == NULL)
72073+ return 0;
72074+
72075+ guser = &obj->globbed;
72076+ while (*guser) {
72077+ g_tmp = (struct acl_object_label *)
72078+ acl_alloc(sizeof (struct acl_object_label));
72079+ if (g_tmp == NULL)
72080+ return -ENOMEM;
72081+
72082+ if (copy_acl_object_label(g_tmp, *guser))
72083+ return -EFAULT;
72084+
72085+ error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
72086+ if (error)
72087+ return error;
72088+
72089+ *guser = g_tmp;
72090+ guser = &(g_tmp->next);
72091+ }
72092+
72093+ return 0;
72094+}
72095+
72096+static int
72097+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
72098+ struct acl_role_label *role)
72099+{
72100+ struct acl_object_label *o_tmp;
72101+ int ret;
72102+
72103+ while (userp) {
72104+ if ((o_tmp = (struct acl_object_label *)
72105+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
72106+ return -ENOMEM;
72107+
72108+ if (copy_acl_object_label(o_tmp, userp))
72109+ return -EFAULT;
72110+
72111+ userp = o_tmp->prev;
72112+
72113+ ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
72114+ if (ret)
72115+ return ret;
72116+
72117+ insert_acl_obj_label(o_tmp, subj);
72118+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
72119+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
72120+ return -ENOMEM;
72121+
72122+ ret = copy_user_glob(o_tmp);
72123+ if (ret)
72124+ return ret;
72125+
72126+ if (o_tmp->nested) {
72127+ int already_copied;
72128+
72129+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
72130+ if (IS_ERR(o_tmp->nested))
72131+ return PTR_ERR(o_tmp->nested);
72132+
72133+ /* insert into nested subject list if we haven't copied this one yet
72134+ to prevent duplicate entries */
72135+ if (!already_copied) {
72136+ o_tmp->nested->next = role->hash->first;
72137+ role->hash->first = o_tmp->nested;
72138+ }
72139+ }
72140+ }
72141+
72142+ return 0;
72143+}
72144+
72145+static __u32
72146+count_user_subjs(struct acl_subject_label *userp)
72147+{
72148+ struct acl_subject_label s_tmp;
72149+ __u32 num = 0;
72150+
72151+ while (userp) {
72152+ if (copy_acl_subject_label(&s_tmp, userp))
72153+ break;
72154+
72155+ userp = s_tmp.prev;
72156+ }
72157+
72158+ return num;
72159+}
72160+
72161+static int
72162+copy_user_allowedips(struct acl_role_label *rolep)
72163+{
72164+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
72165+
72166+ ruserip = rolep->allowed_ips;
72167+
72168+ while (ruserip) {
72169+ rlast = rtmp;
72170+
72171+ if ((rtmp = (struct role_allowed_ip *)
72172+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
72173+ return -ENOMEM;
72174+
72175+ if (copy_role_allowed_ip(rtmp, ruserip))
72176+ return -EFAULT;
72177+
72178+ ruserip = rtmp->prev;
72179+
72180+ if (!rlast) {
72181+ rtmp->prev = NULL;
72182+ rolep->allowed_ips = rtmp;
72183+ } else {
72184+ rlast->next = rtmp;
72185+ rtmp->prev = rlast;
72186+ }
72187+
72188+ if (!ruserip)
72189+ rtmp->next = NULL;
72190+ }
72191+
72192+ return 0;
72193+}
72194+
72195+static int
72196+copy_user_transitions(struct acl_role_label *rolep)
72197+{
72198+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
72199+ int error;
72200+
72201+ rusertp = rolep->transitions;
72202+
72203+ while (rusertp) {
72204+ rlast = rtmp;
72205+
72206+ if ((rtmp = (struct role_transition *)
72207+ acl_alloc(sizeof (struct role_transition))) == NULL)
72208+ return -ENOMEM;
72209+
72210+ if (copy_role_transition(rtmp, rusertp))
72211+ return -EFAULT;
72212+
72213+ rusertp = rtmp->prev;
72214+
72215+ error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
72216+ if (error)
72217+ return error;
72218+
72219+ if (!rlast) {
72220+ rtmp->prev = NULL;
72221+ rolep->transitions = rtmp;
72222+ } else {
72223+ rlast->next = rtmp;
72224+ rtmp->prev = rlast;
72225+ }
72226+
72227+ if (!rusertp)
72228+ rtmp->next = NULL;
72229+ }
72230+
72231+ return 0;
72232+}
72233+
72234+static __u32 count_user_objs(const struct acl_object_label __user *userp)
72235+{
72236+ struct acl_object_label o_tmp;
72237+ __u32 num = 0;
72238+
72239+ while (userp) {
72240+ if (copy_acl_object_label(&o_tmp, userp))
72241+ break;
72242+
72243+ userp = o_tmp.prev;
72244+ num++;
72245+ }
72246+
72247+ return num;
72248+}
72249+
72250+static struct acl_subject_label *
72251+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
72252+{
72253+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
72254+ __u32 num_objs;
72255+ struct acl_ip_label **i_tmp, *i_utmp2;
72256+ struct gr_hash_struct ghash;
72257+ struct subject_map *subjmap;
72258+ unsigned int i_num;
72259+ int err;
72260+
72261+ if (already_copied != NULL)
72262+ *already_copied = 0;
72263+
72264+ s_tmp = lookup_subject_map(userp);
72265+
72266+ /* we've already copied this subject into the kernel, just return
72267+ the reference to it, and don't copy it over again
72268+ */
72269+ if (s_tmp) {
72270+ if (already_copied != NULL)
72271+ *already_copied = 1;
72272+ return(s_tmp);
72273+ }
72274+
72275+ if ((s_tmp = (struct acl_subject_label *)
72276+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
72277+ return ERR_PTR(-ENOMEM);
72278+
72279+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
72280+ if (subjmap == NULL)
72281+ return ERR_PTR(-ENOMEM);
72282+
72283+ subjmap->user = userp;
72284+ subjmap->kernel = s_tmp;
72285+ insert_subj_map_entry(subjmap);
72286+
72287+ if (copy_acl_subject_label(s_tmp, userp))
72288+ return ERR_PTR(-EFAULT);
72289+
72290+ err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
72291+ if (err)
72292+ return ERR_PTR(err);
72293+
72294+ if (!strcmp(s_tmp->filename, "/"))
72295+ role->root_label = s_tmp;
72296+
72297+ if (copy_gr_hash_struct(&ghash, s_tmp->hash))
72298+ return ERR_PTR(-EFAULT);
72299+
72300+ /* copy user and group transition tables */
72301+
72302+ if (s_tmp->user_trans_num) {
72303+ uid_t *uidlist;
72304+
72305+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
72306+ if (uidlist == NULL)
72307+ return ERR_PTR(-ENOMEM);
72308+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
72309+ return ERR_PTR(-EFAULT);
72310+
72311+ s_tmp->user_transitions = uidlist;
72312+ }
72313+
72314+ if (s_tmp->group_trans_num) {
72315+ gid_t *gidlist;
72316+
72317+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
72318+ if (gidlist == NULL)
72319+ return ERR_PTR(-ENOMEM);
72320+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
72321+ return ERR_PTR(-EFAULT);
72322+
72323+ s_tmp->group_transitions = gidlist;
72324+ }
72325+
72326+ /* set up object hash table */
72327+ num_objs = count_user_objs(ghash.first);
72328+
72329+ s_tmp->obj_hash_size = num_objs;
72330+ s_tmp->obj_hash =
72331+ (struct acl_object_label **)
72332+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
72333+
72334+ if (!s_tmp->obj_hash)
72335+ return ERR_PTR(-ENOMEM);
72336+
72337+ memset(s_tmp->obj_hash, 0,
72338+ s_tmp->obj_hash_size *
72339+ sizeof (struct acl_object_label *));
72340+
72341+ /* add in objects */
72342+ err = copy_user_objs(ghash.first, s_tmp, role);
72343+
72344+ if (err)
72345+ return ERR_PTR(err);
72346+
72347+ /* set pointer for parent subject */
72348+ if (s_tmp->parent_subject) {
72349+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
72350+
72351+ if (IS_ERR(s_tmp2))
72352+ return s_tmp2;
72353+
72354+ s_tmp->parent_subject = s_tmp2;
72355+ }
72356+
72357+ /* add in ip acls */
72358+
72359+ if (!s_tmp->ip_num) {
72360+ s_tmp->ips = NULL;
72361+ goto insert;
72362+ }
72363+
72364+ i_tmp =
72365+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
72366+ sizeof (struct acl_ip_label *));
72367+
72368+ if (!i_tmp)
72369+ return ERR_PTR(-ENOMEM);
72370+
72371+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
72372+ *(i_tmp + i_num) =
72373+ (struct acl_ip_label *)
72374+ acl_alloc(sizeof (struct acl_ip_label));
72375+ if (!*(i_tmp + i_num))
72376+ return ERR_PTR(-ENOMEM);
72377+
72378+ if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
72379+ return ERR_PTR(-EFAULT);
72380+
72381+ if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
72382+ return ERR_PTR(-EFAULT);
72383+
72384+ if ((*(i_tmp + i_num))->iface == NULL)
72385+ continue;
72386+
72387+ err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
72388+ if (err)
72389+ return ERR_PTR(err);
72390+ }
72391+
72392+ s_tmp->ips = i_tmp;
72393+
72394+insert:
72395+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
72396+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
72397+ return ERR_PTR(-ENOMEM);
72398+
72399+ return s_tmp;
72400+}
72401+
72402+static int
72403+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
72404+{
72405+ struct acl_subject_label s_pre;
72406+ struct acl_subject_label * ret;
72407+ int err;
72408+
72409+ while (userp) {
72410+ if (copy_acl_subject_label(&s_pre, userp))
72411+ return -EFAULT;
72412+
72413+ ret = do_copy_user_subj(userp, role, NULL);
72414+
72415+ err = PTR_ERR(ret);
72416+ if (IS_ERR(ret))
72417+ return err;
72418+
72419+ insert_acl_subj_label(ret, role);
72420+
72421+ userp = s_pre.prev;
72422+ }
72423+
72424+ return 0;
72425+}
72426+
72427+static int
72428+copy_user_acl(struct gr_arg *arg)
72429+{
72430+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
72431+ struct acl_subject_label *subj_list;
72432+ struct sprole_pw *sptmp;
72433+ struct gr_hash_struct *ghash;
72434+ uid_t *domainlist;
72435+ unsigned int r_num;
72436+ int err = 0;
72437+ __u16 i;
72438+ __u32 num_subjs;
72439+
72440+ /* we need a default and kernel role */
72441+ if (arg->role_db.num_roles < 2)
72442+ return -EINVAL;
72443+
72444+ /* copy special role authentication info from userspace */
72445+
72446+ polstate->num_sprole_pws = arg->num_sprole_pws;
72447+ polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
72448+
72449+ if (!polstate->acl_special_roles && polstate->num_sprole_pws)
72450+ return -ENOMEM;
72451+
72452+ for (i = 0; i < polstate->num_sprole_pws; i++) {
72453+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
72454+ if (!sptmp)
72455+ return -ENOMEM;
72456+ if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
72457+ return -EFAULT;
72458+
72459+ err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
72460+ if (err)
72461+ return err;
72462+
72463+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
72464+ printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
72465+#endif
72466+
72467+ polstate->acl_special_roles[i] = sptmp;
72468+ }
72469+
72470+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
72471+
72472+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
72473+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
72474+
72475+ if (!r_tmp)
72476+ return -ENOMEM;
72477+
72478+ if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
72479+ return -EFAULT;
72480+
72481+ if (copy_acl_role_label(r_tmp, r_utmp2))
72482+ return -EFAULT;
72483+
72484+ err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
72485+ if (err)
72486+ return err;
72487+
72488+ if (!strcmp(r_tmp->rolename, "default")
72489+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
72490+ polstate->default_role = r_tmp;
72491+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
72492+ polstate->kernel_role = r_tmp;
72493+ }
72494+
72495+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
72496+ return -ENOMEM;
72497+
72498+ if (copy_gr_hash_struct(ghash, r_tmp->hash))
72499+ return -EFAULT;
72500+
72501+ r_tmp->hash = ghash;
72502+
72503+ num_subjs = count_user_subjs(r_tmp->hash->first);
72504+
72505+ r_tmp->subj_hash_size = num_subjs;
72506+ r_tmp->subj_hash =
72507+ (struct acl_subject_label **)
72508+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
72509+
72510+ if (!r_tmp->subj_hash)
72511+ return -ENOMEM;
72512+
72513+ err = copy_user_allowedips(r_tmp);
72514+ if (err)
72515+ return err;
72516+
72517+ /* copy domain info */
72518+ if (r_tmp->domain_children != NULL) {
72519+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
72520+ if (domainlist == NULL)
72521+ return -ENOMEM;
72522+
72523+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
72524+ return -EFAULT;
72525+
72526+ r_tmp->domain_children = domainlist;
72527+ }
72528+
72529+ err = copy_user_transitions(r_tmp);
72530+ if (err)
72531+ return err;
72532+
72533+ memset(r_tmp->subj_hash, 0,
72534+ r_tmp->subj_hash_size *
72535+ sizeof (struct acl_subject_label *));
72536+
72537+ /* acquire the list of subjects, then NULL out
72538+ the list prior to parsing the subjects for this role,
72539+ as during this parsing the list is replaced with a list
72540+ of *nested* subjects for the role
72541+ */
72542+ subj_list = r_tmp->hash->first;
72543+
72544+ /* set nested subject list to null */
72545+ r_tmp->hash->first = NULL;
72546+
72547+ err = copy_user_subjs(subj_list, r_tmp);
72548+
72549+ if (err)
72550+ return err;
72551+
72552+ insert_acl_role_label(r_tmp);
72553+ }
72554+
72555+ if (polstate->default_role == NULL || polstate->kernel_role == NULL)
72556+ return -EINVAL;
72557+
72558+ return err;
72559+}
72560+
72561+static int gracl_reload_apply_policies(void *reload)
72562+{
72563+ struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
72564+ struct task_struct *task, *task2;
72565+ struct acl_role_label *role, *rtmp;
72566+ struct acl_subject_label *subj;
72567+ const struct cred *cred;
72568+ int role_applied;
72569+ int ret = 0;
72570+
72571+ memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
72572+ memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
72573+
72574+ /* first make sure we'll be able to apply the new policy cleanly */
72575+ do_each_thread(task2, task) {
72576+ if (task->exec_file == NULL)
72577+ continue;
72578+ role_applied = 0;
72579+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
72580+ /* preserve special roles */
72581+ FOR_EACH_ROLE_START(role)
72582+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
72583+ rtmp = task->role;
72584+ task->role = role;
72585+ role_applied = 1;
72586+ break;
72587+ }
72588+ FOR_EACH_ROLE_END(role)
72589+ }
72590+ if (!role_applied) {
72591+ cred = __task_cred(task);
72592+ rtmp = task->role;
72593+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72594+ }
72595+ /* this handles non-nested inherited subjects, nested subjects will still
72596+ be dropped currently */
72597+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
72598+ task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
72599+ /* change the role back so that we've made no modifications to the policy */
72600+ task->role = rtmp;
72601+
72602+ if (subj == NULL || task->tmpacl == NULL) {
72603+ ret = -EINVAL;
72604+ goto out;
72605+ }
72606+ } while_each_thread(task2, task);
72607+
72608+ /* now actually apply the policy */
72609+
72610+ do_each_thread(task2, task) {
72611+ if (task->exec_file) {
72612+ role_applied = 0;
72613+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
72614+ /* preserve special roles */
72615+ FOR_EACH_ROLE_START(role)
72616+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
72617+ task->role = role;
72618+ role_applied = 1;
72619+ break;
72620+ }
72621+ FOR_EACH_ROLE_END(role)
72622+ }
72623+ if (!role_applied) {
72624+ cred = __task_cred(task);
72625+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72626+ }
72627+ /* this handles non-nested inherited subjects, nested subjects will still
72628+ be dropped currently */
72629+ if (!reload_state->oldmode && task->inherited)
72630+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
72631+ else {
72632+ /* looked up and tagged to the task previously */
72633+ subj = task->tmpacl;
72634+ }
72635+ /* subj will be non-null */
72636+ __gr_apply_subject_to_task(polstate, task, subj);
72637+ if (reload_state->oldmode) {
72638+ task->acl_role_id = 0;
72639+ task->acl_sp_role = 0;
72640+ task->inherited = 0;
72641+ }
72642+ } else {
72643+ // it's a kernel process
72644+ task->role = polstate->kernel_role;
72645+ task->acl = polstate->kernel_role->root_label;
72646+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
72647+ task->acl->mode &= ~GR_PROCFIND;
72648+#endif
72649+ }
72650+ } while_each_thread(task2, task);
72651+
72652+ memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
72653+ memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
72654+
72655+out:
72656+
72657+ return ret;
72658+}
72659+
72660+static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
72661+{
72662+ struct gr_reload_state new_reload_state = { };
72663+ int err;
72664+
72665+ new_reload_state.oldpolicy_ptr = polstate;
72666+ new_reload_state.oldalloc_ptr = current_alloc_state;
72667+ new_reload_state.oldmode = oldmode;
72668+
72669+ current_alloc_state = &new_reload_state.newalloc;
72670+ polstate = &new_reload_state.newpolicy;
72671+
72672+ /* everything relevant is now saved off, copy in the new policy */
72673+ if (init_variables(args, true)) {
72674+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
72675+ err = -ENOMEM;
72676+ goto error;
72677+ }
72678+
72679+ err = copy_user_acl(args);
72680+ free_init_variables();
72681+ if (err)
72682+ goto error;
72683+ /* the new policy is copied in, with the old policy available via saved_state
72684+ first go through applying roles, making sure to preserve special roles
72685+ then apply new subjects, making sure to preserve inherited and nested subjects,
72686+ though currently only inherited subjects will be preserved
72687+ */
72688+ err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
72689+ if (err)
72690+ goto error;
72691+
72692+ /* we've now applied the new policy, so restore the old policy state to free it */
72693+ polstate = &new_reload_state.oldpolicy;
72694+ current_alloc_state = &new_reload_state.oldalloc;
72695+ free_variables(true);
72696+
72697+ /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
72698+ to running_polstate/current_alloc_state inside stop_machine
72699+ */
72700+ err = 0;
72701+ goto out;
72702+error:
72703+ /* on error of loading the new policy, we'll just keep the previous
72704+ policy set around
72705+ */
72706+ free_variables(true);
72707+
72708+ /* doesn't affect runtime, but maintains consistent state */
72709+out:
72710+ polstate = new_reload_state.oldpolicy_ptr;
72711+ current_alloc_state = new_reload_state.oldalloc_ptr;
72712+
72713+ return err;
72714+}
72715+
72716+static int
72717+gracl_init(struct gr_arg *args)
72718+{
72719+ int error = 0;
72720+
72721+ memcpy(&gr_system_salt, args->salt, sizeof(gr_system_salt));
72722+ memcpy(&gr_system_sum, args->sum, sizeof(gr_system_sum));
72723+
72724+ if (init_variables(args, false)) {
72725+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
72726+ error = -ENOMEM;
72727+ goto out;
72728+ }
72729+
72730+ error = copy_user_acl(args);
72731+ free_init_variables();
72732+ if (error)
72733+ goto out;
72734+
72735+ error = gr_set_acls(0);
72736+ if (error)
72737+ goto out;
72738+
72739+ gr_enable_rbac_system();
72740+
72741+ return 0;
72742+
72743+out:
72744+ free_variables(false);
72745+ return error;
72746+}
72747+
72748+static int
72749+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
72750+ unsigned char **sum)
72751+{
72752+ struct acl_role_label *r;
72753+ struct role_allowed_ip *ipp;
72754+ struct role_transition *trans;
72755+ unsigned int i;
72756+ int found = 0;
72757+ u32 curr_ip = current->signal->curr_ip;
72758+
72759+ current->signal->saved_ip = curr_ip;
72760+
72761+ /* check transition table */
72762+
72763+ for (trans = current->role->transitions; trans; trans = trans->next) {
72764+ if (!strcmp(rolename, trans->rolename)) {
72765+ found = 1;
72766+ break;
72767+ }
72768+ }
72769+
72770+ if (!found)
72771+ return 0;
72772+
72773+ /* handle special roles that do not require authentication
72774+ and check ip */
72775+
72776+ FOR_EACH_ROLE_START(r)
72777+ if (!strcmp(rolename, r->rolename) &&
72778+ (r->roletype & GR_ROLE_SPECIAL)) {
72779+ found = 0;
72780+ if (r->allowed_ips != NULL) {
72781+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
72782+ if ((ntohl(curr_ip) & ipp->netmask) ==
72783+ (ntohl(ipp->addr) & ipp->netmask))
72784+ found = 1;
72785+ }
72786+ } else
72787+ found = 2;
72788+ if (!found)
72789+ return 0;
72790+
72791+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
72792+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
72793+ *salt = NULL;
72794+ *sum = NULL;
72795+ return 1;
72796+ }
72797+ }
72798+ FOR_EACH_ROLE_END(r)
72799+
72800+ for (i = 0; i < polstate->num_sprole_pws; i++) {
72801+ if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
72802+ *salt = polstate->acl_special_roles[i]->salt;
72803+ *sum = polstate->acl_special_roles[i]->sum;
72804+ return 1;
72805+ }
72806+ }
72807+
72808+ return 0;
72809+}
72810+
72811+int gr_check_secure_terminal(struct task_struct *task)
72812+{
72813+ struct task_struct *p, *p2, *p3;
72814+ struct files_struct *files;
72815+ struct fdtable *fdt;
72816+ struct file *our_file = NULL, *file;
72817+ int i;
72818+
72819+ if (task->signal->tty == NULL)
72820+ return 1;
72821+
72822+ files = get_files_struct(task);
72823+ if (files != NULL) {
72824+ rcu_read_lock();
72825+ fdt = files_fdtable(files);
72826+ for (i=0; i < fdt->max_fds; i++) {
72827+ file = fcheck_files(files, i);
72828+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
72829+ get_file(file);
72830+ our_file = file;
72831+ }
72832+ }
72833+ rcu_read_unlock();
72834+ put_files_struct(files);
72835+ }
72836+
72837+ if (our_file == NULL)
72838+ return 1;
72839+
72840+ read_lock(&tasklist_lock);
72841+ do_each_thread(p2, p) {
72842+ files = get_files_struct(p);
72843+ if (files == NULL ||
72844+ (p->signal && p->signal->tty == task->signal->tty)) {
72845+ if (files != NULL)
72846+ put_files_struct(files);
72847+ continue;
72848+ }
72849+ rcu_read_lock();
72850+ fdt = files_fdtable(files);
72851+ for (i=0; i < fdt->max_fds; i++) {
72852+ file = fcheck_files(files, i);
72853+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
72854+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
72855+ p3 = task;
72856+ while (task_pid_nr(p3) > 0) {
72857+ if (p3 == p)
72858+ break;
72859+ p3 = p3->real_parent;
72860+ }
72861+ if (p3 == p)
72862+ break;
72863+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
72864+ gr_handle_alertkill(p);
72865+ rcu_read_unlock();
72866+ put_files_struct(files);
72867+ read_unlock(&tasklist_lock);
72868+ fput(our_file);
72869+ return 0;
72870+ }
72871+ }
72872+ rcu_read_unlock();
72873+ put_files_struct(files);
72874+ } while_each_thread(p2, p);
72875+ read_unlock(&tasklist_lock);
72876+
72877+ fput(our_file);
72878+ return 1;
72879+}
72880+
72881+ssize_t
72882+write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
72883+{
72884+ struct gr_arg_wrapper uwrap;
72885+ unsigned char *sprole_salt = NULL;
72886+ unsigned char *sprole_sum = NULL;
72887+ int error = 0;
72888+ int error2 = 0;
72889+ size_t req_count = 0;
72890+ unsigned char oldmode = 0;
72891+
72892+ mutex_lock(&gr_dev_mutex);
72893+
72894+ if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
72895+ error = -EPERM;
72896+ goto out;
72897+ }
72898+
72899+#ifdef CONFIG_COMPAT
72900+ pax_open_kernel();
72901+ if (is_compat_task()) {
72902+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
72903+ copy_gr_arg = &copy_gr_arg_compat;
72904+ copy_acl_object_label = &copy_acl_object_label_compat;
72905+ copy_acl_subject_label = &copy_acl_subject_label_compat;
72906+ copy_acl_role_label = &copy_acl_role_label_compat;
72907+ copy_acl_ip_label = &copy_acl_ip_label_compat;
72908+ copy_role_allowed_ip = &copy_role_allowed_ip_compat;
72909+ copy_role_transition = &copy_role_transition_compat;
72910+ copy_sprole_pw = &copy_sprole_pw_compat;
72911+ copy_gr_hash_struct = &copy_gr_hash_struct_compat;
72912+ copy_pointer_from_array = &copy_pointer_from_array_compat;
72913+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
72914+ } else {
72915+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
72916+ copy_gr_arg = &copy_gr_arg_normal;
72917+ copy_acl_object_label = &copy_acl_object_label_normal;
72918+ copy_acl_subject_label = &copy_acl_subject_label_normal;
72919+ copy_acl_role_label = &copy_acl_role_label_normal;
72920+ copy_acl_ip_label = &copy_acl_ip_label_normal;
72921+ copy_role_allowed_ip = &copy_role_allowed_ip_normal;
72922+ copy_role_transition = &copy_role_transition_normal;
72923+ copy_sprole_pw = &copy_sprole_pw_normal;
72924+ copy_gr_hash_struct = &copy_gr_hash_struct_normal;
72925+ copy_pointer_from_array = &copy_pointer_from_array_normal;
72926+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
72927+ }
72928+ pax_close_kernel();
72929+#endif
72930+
72931+ req_count = get_gr_arg_wrapper_size();
72932+
72933+ if (count != req_count) {
72934+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
72935+ error = -EINVAL;
72936+ goto out;
72937+ }
72938+
72939+
72940+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
72941+ gr_auth_expires = 0;
72942+ gr_auth_attempts = 0;
72943+ }
72944+
72945+ error = copy_gr_arg_wrapper(buf, &uwrap);
72946+ if (error)
72947+ goto out;
72948+
72949+ error = copy_gr_arg(uwrap.arg, &gr_usermode);
72950+ if (error)
72951+ goto out;
72952+
72953+ if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_SPROLEPAM &&
72954+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
72955+ time_after(gr_auth_expires, get_seconds())) {
72956+ error = -EBUSY;
72957+ goto out;
72958+ }
72959+
72960+ /* if non-root trying to do anything other than use a special role,
72961+ do not attempt authentication, do not count towards authentication
72962+ locking
72963+ */
72964+
72965+ if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_STATUS &&
72966+ gr_usermode.mode != GR_UNSPROLE && gr_usermode.mode != GR_SPROLEPAM &&
72967+ gr_is_global_nonroot(current_uid())) {
72968+ error = -EPERM;
72969+ goto out;
72970+ }
72971+
72972+ /* ensure pw and special role name are null terminated */
72973+
72974+ gr_usermode.pw[GR_PW_LEN - 1] = '\0';
72975+ gr_usermode.sp_role[GR_SPROLE_LEN - 1] = '\0';
72976+
72977+ /* Okay.
72978+ * We have our enough of the argument structure..(we have yet
72979+ * to copy_from_user the tables themselves) . Copy the tables
72980+ * only if we need them, i.e. for loading operations. */
72981+
72982+ switch (gr_usermode.mode) {
72983+ case GR_STATUS:
72984+ if (gr_acl_is_enabled()) {
72985+ error = 1;
72986+ if (!gr_check_secure_terminal(current))
72987+ error = 3;
72988+ } else
72989+ error = 2;
72990+ goto out;
72991+ case GR_SHUTDOWN:
72992+ if (gr_acl_is_enabled() && !(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72993+ stop_machine(gr_rbac_disable, NULL, NULL);
72994+ free_variables(false);
72995+ memset(&gr_usermode, 0, sizeof(gr_usermode));
72996+ memset(&gr_system_salt, 0, sizeof(gr_system_salt));
72997+ memset(&gr_system_sum, 0, sizeof(gr_system_sum));
72998+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
72999+ } else if (gr_acl_is_enabled()) {
73000+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
73001+ error = -EPERM;
73002+ } else {
73003+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
73004+ error = -EAGAIN;
73005+ }
73006+ break;
73007+ case GR_ENABLE:
73008+ if (!gr_acl_is_enabled() && !(error2 = gracl_init(&gr_usermode)))
73009+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
73010+ else {
73011+ if (gr_acl_is_enabled())
73012+ error = -EAGAIN;
73013+ else
73014+ error = error2;
73015+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
73016+ }
73017+ break;
73018+ case GR_OLDRELOAD:
73019+ oldmode = 1;
73020+ case GR_RELOAD:
73021+ if (!gr_acl_is_enabled()) {
73022+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
73023+ error = -EAGAIN;
73024+ } else if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
73025+ error2 = gracl_reload(&gr_usermode, oldmode);
73026+ if (!error2)
73027+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
73028+ else {
73029+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
73030+ error = error2;
73031+ }
73032+ } else {
73033+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
73034+ error = -EPERM;
73035+ }
73036+ break;
73037+ case GR_SEGVMOD:
73038+ if (unlikely(!gr_acl_is_enabled())) {
73039+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
73040+ error = -EAGAIN;
73041+ break;
73042+ }
73043+
73044+ if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
73045+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
73046+ if (gr_usermode.segv_device && gr_usermode.segv_inode) {
73047+ struct acl_subject_label *segvacl;
73048+ segvacl =
73049+ lookup_acl_subj_label(gr_usermode.segv_inode,
73050+ gr_usermode.segv_device,
73051+ current->role);
73052+ if (segvacl) {
73053+ segvacl->crashes = 0;
73054+ segvacl->expires = 0;
73055+ }
73056+ } else if (gr_find_uid(gr_usermode.segv_uid) >= 0) {
73057+ gr_remove_uid(gr_usermode.segv_uid);
73058+ }
73059+ } else {
73060+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
73061+ error = -EPERM;
73062+ }
73063+ break;
73064+ case GR_SPROLE:
73065+ case GR_SPROLEPAM:
73066+ if (unlikely(!gr_acl_is_enabled())) {
73067+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
73068+ error = -EAGAIN;
73069+ break;
73070+ }
73071+
73072+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
73073+ current->role->expires = 0;
73074+ current->role->auth_attempts = 0;
73075+ }
73076+
73077+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
73078+ time_after(current->role->expires, get_seconds())) {
73079+ error = -EBUSY;
73080+ goto out;
73081+ }
73082+
73083+ if (lookup_special_role_auth
73084+ (gr_usermode.mode, gr_usermode.sp_role, &sprole_salt, &sprole_sum)
73085+ && ((!sprole_salt && !sprole_sum)
73086+ || !(chkpw(&gr_usermode, sprole_salt, sprole_sum)))) {
73087+ char *p = "";
73088+ assign_special_role(gr_usermode.sp_role);
73089+ read_lock(&tasklist_lock);
73090+ if (current->real_parent)
73091+ p = current->real_parent->role->rolename;
73092+ read_unlock(&tasklist_lock);
73093+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
73094+ p, acl_sp_role_value);
73095+ } else {
73096+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode.sp_role);
73097+ error = -EPERM;
73098+ if(!(current->role->auth_attempts++))
73099+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
73100+
73101+ goto out;
73102+ }
73103+ break;
73104+ case GR_UNSPROLE:
73105+ if (unlikely(!gr_acl_is_enabled())) {
73106+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
73107+ error = -EAGAIN;
73108+ break;
73109+ }
73110+
73111+ if (current->role->roletype & GR_ROLE_SPECIAL) {
73112+ char *p = "";
73113+ int i = 0;
73114+
73115+ read_lock(&tasklist_lock);
73116+ if (current->real_parent) {
73117+ p = current->real_parent->role->rolename;
73118+ i = current->real_parent->acl_role_id;
73119+ }
73120+ read_unlock(&tasklist_lock);
73121+
73122+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
73123+ gr_set_acls(1);
73124+ } else {
73125+ error = -EPERM;
73126+ goto out;
73127+ }
73128+ break;
73129+ default:
73130+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode.mode);
73131+ error = -EINVAL;
73132+ break;
73133+ }
73134+
73135+ if (error != -EPERM)
73136+ goto out;
73137+
73138+ if(!(gr_auth_attempts++))
73139+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
73140+
73141+ out:
73142+ mutex_unlock(&gr_dev_mutex);
73143+
73144+ if (!error)
73145+ error = req_count;
73146+
73147+ return error;
73148+}
73149+
73150+int
73151+gr_set_acls(const int type)
73152+{
73153+ struct task_struct *task, *task2;
73154+ struct acl_role_label *role = current->role;
73155+ struct acl_subject_label *subj;
73156+ __u16 acl_role_id = current->acl_role_id;
73157+ const struct cred *cred;
73158+ int ret;
73159+
73160+ rcu_read_lock();
73161+ read_lock(&tasklist_lock);
73162+ read_lock(&grsec_exec_file_lock);
73163+ do_each_thread(task2, task) {
73164+ /* check to see if we're called from the exit handler,
73165+ if so, only replace ACLs that have inherited the admin
73166+ ACL */
73167+
73168+ if (type && (task->role != role ||
73169+ task->acl_role_id != acl_role_id))
73170+ continue;
73171+
73172+ task->acl_role_id = 0;
73173+ task->acl_sp_role = 0;
73174+ task->inherited = 0;
73175+
73176+ if (task->exec_file) {
73177+ cred = __task_cred(task);
73178+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
73179+ subj = __gr_get_subject_for_task(polstate, task, NULL);
73180+ if (subj == NULL) {
73181+ ret = -EINVAL;
73182+ read_unlock(&grsec_exec_file_lock);
73183+ read_unlock(&tasklist_lock);
73184+ rcu_read_unlock();
73185+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
73186+ return ret;
73187+ }
73188+ __gr_apply_subject_to_task(polstate, task, subj);
73189+ } else {
73190+ // it's a kernel process
73191+ task->role = polstate->kernel_role;
73192+ task->acl = polstate->kernel_role->root_label;
73193+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
73194+ task->acl->mode &= ~GR_PROCFIND;
73195+#endif
73196+ }
73197+ } while_each_thread(task2, task);
73198+ read_unlock(&grsec_exec_file_lock);
73199+ read_unlock(&tasklist_lock);
73200+ rcu_read_unlock();
73201+
73202+ return 0;
73203+}
73204diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
73205new file mode 100644
73206index 0000000..39645c9
73207--- /dev/null
73208+++ b/grsecurity/gracl_res.c
73209@@ -0,0 +1,68 @@
73210+#include <linux/kernel.h>
73211+#include <linux/sched.h>
73212+#include <linux/gracl.h>
73213+#include <linux/grinternal.h>
73214+
73215+static const char *restab_log[] = {
73216+ [RLIMIT_CPU] = "RLIMIT_CPU",
73217+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
73218+ [RLIMIT_DATA] = "RLIMIT_DATA",
73219+ [RLIMIT_STACK] = "RLIMIT_STACK",
73220+ [RLIMIT_CORE] = "RLIMIT_CORE",
73221+ [RLIMIT_RSS] = "RLIMIT_RSS",
73222+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
73223+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
73224+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
73225+ [RLIMIT_AS] = "RLIMIT_AS",
73226+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
73227+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
73228+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
73229+ [RLIMIT_NICE] = "RLIMIT_NICE",
73230+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
73231+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
73232+ [GR_CRASH_RES] = "RLIMIT_CRASH"
73233+};
73234+
73235+void
73236+gr_log_resource(const struct task_struct *task,
73237+ const int res, const unsigned long wanted, const int gt)
73238+{
73239+ const struct cred *cred;
73240+ unsigned long rlim;
73241+
73242+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
73243+ return;
73244+
73245+ // not yet supported resource
73246+ if (unlikely(!restab_log[res]))
73247+ return;
73248+
73249+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
73250+ rlim = task_rlimit_max(task, res);
73251+ else
73252+ rlim = task_rlimit(task, res);
73253+
73254+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
73255+ return;
73256+
73257+ rcu_read_lock();
73258+ cred = __task_cred(task);
73259+
73260+ if (res == RLIMIT_NPROC &&
73261+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
73262+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
73263+ goto out_rcu_unlock;
73264+ else if (res == RLIMIT_MEMLOCK &&
73265+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
73266+ goto out_rcu_unlock;
73267+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
73268+ goto out_rcu_unlock;
73269+ rcu_read_unlock();
73270+
73271+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
73272+
73273+ return;
73274+out_rcu_unlock:
73275+ rcu_read_unlock();
73276+ return;
73277+}
73278diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
73279new file mode 100644
73280index 0000000..2040e61
73281--- /dev/null
73282+++ b/grsecurity/gracl_segv.c
73283@@ -0,0 +1,313 @@
73284+#include <linux/kernel.h>
73285+#include <linux/mm.h>
73286+#include <asm/uaccess.h>
73287+#include <asm/errno.h>
73288+#include <asm/mman.h>
73289+#include <net/sock.h>
73290+#include <linux/file.h>
73291+#include <linux/fs.h>
73292+#include <linux/net.h>
73293+#include <linux/in.h>
73294+#include <linux/slab.h>
73295+#include <linux/types.h>
73296+#include <linux/sched.h>
73297+#include <linux/timer.h>
73298+#include <linux/gracl.h>
73299+#include <linux/grsecurity.h>
73300+#include <linux/grinternal.h>
73301+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
73302+#include <linux/magic.h>
73303+#include <linux/pagemap.h>
73304+#include "../fs/btrfs/async-thread.h"
73305+#include "../fs/btrfs/ctree.h"
73306+#include "../fs/btrfs/btrfs_inode.h"
73307+#endif
73308+
73309+static struct crash_uid *uid_set;
73310+static unsigned short uid_used;
73311+static DEFINE_SPINLOCK(gr_uid_lock);
73312+extern rwlock_t gr_inode_lock;
73313+extern struct acl_subject_label *
73314+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
73315+ struct acl_role_label *role);
73316+
73317+static inline dev_t __get_dev(const struct dentry *dentry)
73318+{
73319+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
73320+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
73321+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
73322+ else
73323+#endif
73324+ return dentry->d_sb->s_dev;
73325+}
73326+
73327+int
73328+gr_init_uidset(void)
73329+{
73330+ uid_set =
73331+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
73332+ uid_used = 0;
73333+
73334+ return uid_set ? 1 : 0;
73335+}
73336+
73337+void
73338+gr_free_uidset(void)
73339+{
73340+ if (uid_set) {
73341+ struct crash_uid *tmpset;
73342+ spin_lock(&gr_uid_lock);
73343+ tmpset = uid_set;
73344+ uid_set = NULL;
73345+ uid_used = 0;
73346+ spin_unlock(&gr_uid_lock);
73347+ if (tmpset)
73348+ kfree(tmpset);
73349+ }
73350+
73351+ return;
73352+}
73353+
73354+int
73355+gr_find_uid(const uid_t uid)
73356+{
73357+ struct crash_uid *tmp = uid_set;
73358+ uid_t buid;
73359+ int low = 0, high = uid_used - 1, mid;
73360+
73361+ while (high >= low) {
73362+ mid = (low + high) >> 1;
73363+ buid = tmp[mid].uid;
73364+ if (buid == uid)
73365+ return mid;
73366+ if (buid > uid)
73367+ high = mid - 1;
73368+ if (buid < uid)
73369+ low = mid + 1;
73370+ }
73371+
73372+ return -1;
73373+}
73374+
73375+static __inline__ void
73376+gr_insertsort(void)
73377+{
73378+ unsigned short i, j;
73379+ struct crash_uid index;
73380+
73381+ for (i = 1; i < uid_used; i++) {
73382+ index = uid_set[i];
73383+ j = i;
73384+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
73385+ uid_set[j] = uid_set[j - 1];
73386+ j--;
73387+ }
73388+ uid_set[j] = index;
73389+ }
73390+
73391+ return;
73392+}
73393+
73394+static __inline__ void
73395+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
73396+{
73397+ int loc;
73398+ uid_t uid = GR_GLOBAL_UID(kuid);
73399+
73400+ if (uid_used == GR_UIDTABLE_MAX)
73401+ return;
73402+
73403+ loc = gr_find_uid(uid);
73404+
73405+ if (loc >= 0) {
73406+ uid_set[loc].expires = expires;
73407+ return;
73408+ }
73409+
73410+ uid_set[uid_used].uid = uid;
73411+ uid_set[uid_used].expires = expires;
73412+ uid_used++;
73413+
73414+ gr_insertsort();
73415+
73416+ return;
73417+}
73418+
73419+void
73420+gr_remove_uid(const unsigned short loc)
73421+{
73422+ unsigned short i;
73423+
73424+ for (i = loc + 1; i < uid_used; i++)
73425+ uid_set[i - 1] = uid_set[i];
73426+
73427+ uid_used--;
73428+
73429+ return;
73430+}
73431+
73432+int
73433+gr_check_crash_uid(const kuid_t kuid)
73434+{
73435+ int loc;
73436+ int ret = 0;
73437+ uid_t uid;
73438+
73439+ if (unlikely(!gr_acl_is_enabled()))
73440+ return 0;
73441+
73442+ uid = GR_GLOBAL_UID(kuid);
73443+
73444+ spin_lock(&gr_uid_lock);
73445+ loc = gr_find_uid(uid);
73446+
73447+ if (loc < 0)
73448+ goto out_unlock;
73449+
73450+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
73451+ gr_remove_uid(loc);
73452+ else
73453+ ret = 1;
73454+
73455+out_unlock:
73456+ spin_unlock(&gr_uid_lock);
73457+ return ret;
73458+}
73459+
73460+static __inline__ int
73461+proc_is_setxid(const struct cred *cred)
73462+{
73463+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
73464+ !uid_eq(cred->uid, cred->fsuid))
73465+ return 1;
73466+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
73467+ !gid_eq(cred->gid, cred->fsgid))
73468+ return 1;
73469+
73470+ return 0;
73471+}
73472+
73473+extern int gr_fake_force_sig(int sig, struct task_struct *t);
73474+
73475+void
73476+gr_handle_crash(struct task_struct *task, const int sig)
73477+{
73478+ struct acl_subject_label *curr;
73479+ struct task_struct *tsk, *tsk2;
73480+ const struct cred *cred;
73481+ const struct cred *cred2;
73482+
73483+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
73484+ return;
73485+
73486+ if (unlikely(!gr_acl_is_enabled()))
73487+ return;
73488+
73489+ curr = task->acl;
73490+
73491+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
73492+ return;
73493+
73494+ if (time_before_eq(curr->expires, get_seconds())) {
73495+ curr->expires = 0;
73496+ curr->crashes = 0;
73497+ }
73498+
73499+ curr->crashes++;
73500+
73501+ if (!curr->expires)
73502+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
73503+
73504+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
73505+ time_after(curr->expires, get_seconds())) {
73506+ rcu_read_lock();
73507+ cred = __task_cred(task);
73508+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
73509+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
73510+ spin_lock(&gr_uid_lock);
73511+ gr_insert_uid(cred->uid, curr->expires);
73512+ spin_unlock(&gr_uid_lock);
73513+ curr->expires = 0;
73514+ curr->crashes = 0;
73515+ read_lock(&tasklist_lock);
73516+ do_each_thread(tsk2, tsk) {
73517+ cred2 = __task_cred(tsk);
73518+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
73519+ gr_fake_force_sig(SIGKILL, tsk);
73520+ } while_each_thread(tsk2, tsk);
73521+ read_unlock(&tasklist_lock);
73522+ } else {
73523+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
73524+ read_lock(&tasklist_lock);
73525+ read_lock(&grsec_exec_file_lock);
73526+ do_each_thread(tsk2, tsk) {
73527+ if (likely(tsk != task)) {
73528+ // if this thread has the same subject as the one that triggered
73529+ // RES_CRASH and it's the same binary, kill it
73530+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
73531+ gr_fake_force_sig(SIGKILL, tsk);
73532+ }
73533+ } while_each_thread(tsk2, tsk);
73534+ read_unlock(&grsec_exec_file_lock);
73535+ read_unlock(&tasklist_lock);
73536+ }
73537+ rcu_read_unlock();
73538+ }
73539+
73540+ return;
73541+}
73542+
73543+int
73544+gr_check_crash_exec(const struct file *filp)
73545+{
73546+ struct acl_subject_label *curr;
73547+
73548+ if (unlikely(!gr_acl_is_enabled()))
73549+ return 0;
73550+
73551+ read_lock(&gr_inode_lock);
73552+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
73553+ __get_dev(filp->f_path.dentry),
73554+ current->role);
73555+ read_unlock(&gr_inode_lock);
73556+
73557+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
73558+ (!curr->crashes && !curr->expires))
73559+ return 0;
73560+
73561+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
73562+ time_after(curr->expires, get_seconds()))
73563+ return 1;
73564+ else if (time_before_eq(curr->expires, get_seconds())) {
73565+ curr->crashes = 0;
73566+ curr->expires = 0;
73567+ }
73568+
73569+ return 0;
73570+}
73571+
73572+void
73573+gr_handle_alertkill(struct task_struct *task)
73574+{
73575+ struct acl_subject_label *curracl;
73576+ __u32 curr_ip;
73577+ struct task_struct *p, *p2;
73578+
73579+ if (unlikely(!gr_acl_is_enabled()))
73580+ return;
73581+
73582+ curracl = task->acl;
73583+ curr_ip = task->signal->curr_ip;
73584+
73585+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
73586+ read_lock(&tasklist_lock);
73587+ do_each_thread(p2, p) {
73588+ if (p->signal->curr_ip == curr_ip)
73589+ gr_fake_force_sig(SIGKILL, p);
73590+ } while_each_thread(p2, p);
73591+ read_unlock(&tasklist_lock);
73592+ } else if (curracl->mode & GR_KILLPROC)
73593+ gr_fake_force_sig(SIGKILL, task);
73594+
73595+ return;
73596+}
73597diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
73598new file mode 100644
73599index 0000000..98011b0
73600--- /dev/null
73601+++ b/grsecurity/gracl_shm.c
73602@@ -0,0 +1,40 @@
73603+#include <linux/kernel.h>
73604+#include <linux/mm.h>
73605+#include <linux/sched.h>
73606+#include <linux/file.h>
73607+#include <linux/ipc.h>
73608+#include <linux/gracl.h>
73609+#include <linux/grsecurity.h>
73610+#include <linux/grinternal.h>
73611+
73612+int
73613+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73614+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
73615+{
73616+ struct task_struct *task;
73617+
73618+ if (!gr_acl_is_enabled())
73619+ return 1;
73620+
73621+ rcu_read_lock();
73622+ read_lock(&tasklist_lock);
73623+
73624+ task = find_task_by_vpid(shm_cprid);
73625+
73626+ if (unlikely(!task))
73627+ task = find_task_by_vpid(shm_lapid);
73628+
73629+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
73630+ (task_pid_nr(task) == shm_lapid)) &&
73631+ (task->acl->mode & GR_PROTSHM) &&
73632+ (task->acl != current->acl))) {
73633+ read_unlock(&tasklist_lock);
73634+ rcu_read_unlock();
73635+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
73636+ return 0;
73637+ }
73638+ read_unlock(&tasklist_lock);
73639+ rcu_read_unlock();
73640+
73641+ return 1;
73642+}
73643diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
73644new file mode 100644
73645index 0000000..bc0be01
73646--- /dev/null
73647+++ b/grsecurity/grsec_chdir.c
73648@@ -0,0 +1,19 @@
73649+#include <linux/kernel.h>
73650+#include <linux/sched.h>
73651+#include <linux/fs.h>
73652+#include <linux/file.h>
73653+#include <linux/grsecurity.h>
73654+#include <linux/grinternal.h>
73655+
73656+void
73657+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
73658+{
73659+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
73660+ if ((grsec_enable_chdir && grsec_enable_group &&
73661+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
73662+ !grsec_enable_group)) {
73663+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
73664+ }
73665+#endif
73666+ return;
73667+}
73668diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
73669new file mode 100644
73670index 0000000..651d6c2
73671--- /dev/null
73672+++ b/grsecurity/grsec_chroot.c
73673@@ -0,0 +1,370 @@
73674+#include <linux/kernel.h>
73675+#include <linux/module.h>
73676+#include <linux/sched.h>
73677+#include <linux/file.h>
73678+#include <linux/fs.h>
73679+#include <linux/mount.h>
73680+#include <linux/types.h>
73681+#include "../fs/mount.h"
73682+#include <linux/grsecurity.h>
73683+#include <linux/grinternal.h>
73684+
73685+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73686+int gr_init_ran;
73687+#endif
73688+
73689+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
73690+{
73691+#ifdef CONFIG_GRKERNSEC
73692+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
73693+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
73694+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73695+ && gr_init_ran
73696+#endif
73697+ )
73698+ task->gr_is_chrooted = 1;
73699+ else {
73700+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73701+ if (task_pid_nr(task) == 1 && !gr_init_ran)
73702+ gr_init_ran = 1;
73703+#endif
73704+ task->gr_is_chrooted = 0;
73705+ }
73706+
73707+ task->gr_chroot_dentry = path->dentry;
73708+#endif
73709+ return;
73710+}
73711+
73712+void gr_clear_chroot_entries(struct task_struct *task)
73713+{
73714+#ifdef CONFIG_GRKERNSEC
73715+ task->gr_is_chrooted = 0;
73716+ task->gr_chroot_dentry = NULL;
73717+#endif
73718+ return;
73719+}
73720+
73721+int
73722+gr_handle_chroot_unix(const pid_t pid)
73723+{
73724+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
73725+ struct task_struct *p;
73726+
73727+ if (unlikely(!grsec_enable_chroot_unix))
73728+ return 1;
73729+
73730+ if (likely(!proc_is_chrooted(current)))
73731+ return 1;
73732+
73733+ rcu_read_lock();
73734+ read_lock(&tasklist_lock);
73735+ p = find_task_by_vpid_unrestricted(pid);
73736+ if (unlikely(p && !have_same_root(current, p))) {
73737+ read_unlock(&tasklist_lock);
73738+ rcu_read_unlock();
73739+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
73740+ return 0;
73741+ }
73742+ read_unlock(&tasklist_lock);
73743+ rcu_read_unlock();
73744+#endif
73745+ return 1;
73746+}
73747+
73748+int
73749+gr_handle_chroot_nice(void)
73750+{
73751+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
73752+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
73753+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
73754+ return -EPERM;
73755+ }
73756+#endif
73757+ return 0;
73758+}
73759+
73760+int
73761+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
73762+{
73763+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
73764+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
73765+ && proc_is_chrooted(current)) {
73766+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
73767+ return -EACCES;
73768+ }
73769+#endif
73770+ return 0;
73771+}
73772+
73773+int
73774+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
73775+{
73776+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73777+ struct task_struct *p;
73778+ int ret = 0;
73779+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
73780+ return ret;
73781+
73782+ read_lock(&tasklist_lock);
73783+ do_each_pid_task(pid, type, p) {
73784+ if (!have_same_root(current, p)) {
73785+ ret = 1;
73786+ goto out;
73787+ }
73788+ } while_each_pid_task(pid, type, p);
73789+out:
73790+ read_unlock(&tasklist_lock);
73791+ return ret;
73792+#endif
73793+ return 0;
73794+}
73795+
73796+int
73797+gr_pid_is_chrooted(struct task_struct *p)
73798+{
73799+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73800+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
73801+ return 0;
73802+
73803+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
73804+ !have_same_root(current, p)) {
73805+ return 1;
73806+ }
73807+#endif
73808+ return 0;
73809+}
73810+
73811+EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
73812+
73813+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
73814+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
73815+{
73816+ struct path path, currentroot;
73817+ int ret = 0;
73818+
73819+ path.dentry = (struct dentry *)u_dentry;
73820+ path.mnt = (struct vfsmount *)u_mnt;
73821+ get_fs_root(current->fs, &currentroot);
73822+ if (path_is_under(&path, &currentroot))
73823+ ret = 1;
73824+ path_put(&currentroot);
73825+
73826+ return ret;
73827+}
73828+#endif
73829+
73830+int
73831+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
73832+{
73833+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
73834+ if (!grsec_enable_chroot_fchdir)
73835+ return 1;
73836+
73837+ if (!proc_is_chrooted(current))
73838+ return 1;
73839+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
73840+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
73841+ return 0;
73842+ }
73843+#endif
73844+ return 1;
73845+}
73846+
73847+int
73848+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73849+ const time_t shm_createtime)
73850+{
73851+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
73852+ struct task_struct *p;
73853+ time_t starttime;
73854+
73855+ if (unlikely(!grsec_enable_chroot_shmat))
73856+ return 1;
73857+
73858+ if (likely(!proc_is_chrooted(current)))
73859+ return 1;
73860+
73861+ rcu_read_lock();
73862+ read_lock(&tasklist_lock);
73863+
73864+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
73865+ starttime = p->start_time.tv_sec;
73866+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
73867+ if (have_same_root(current, p)) {
73868+ goto allow;
73869+ } else {
73870+ read_unlock(&tasklist_lock);
73871+ rcu_read_unlock();
73872+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
73873+ return 0;
73874+ }
73875+ }
73876+ /* creator exited, pid reuse, fall through to next check */
73877+ }
73878+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
73879+ if (unlikely(!have_same_root(current, p))) {
73880+ read_unlock(&tasklist_lock);
73881+ rcu_read_unlock();
73882+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
73883+ return 0;
73884+ }
73885+ }
73886+
73887+allow:
73888+ read_unlock(&tasklist_lock);
73889+ rcu_read_unlock();
73890+#endif
73891+ return 1;
73892+}
73893+
73894+void
73895+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
73896+{
73897+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
73898+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
73899+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
73900+#endif
73901+ return;
73902+}
73903+
73904+int
73905+gr_handle_chroot_mknod(const struct dentry *dentry,
73906+ const struct vfsmount *mnt, const int mode)
73907+{
73908+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
73909+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
73910+ proc_is_chrooted(current)) {
73911+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
73912+ return -EPERM;
73913+ }
73914+#endif
73915+ return 0;
73916+}
73917+
73918+int
73919+gr_handle_chroot_mount(const struct dentry *dentry,
73920+ const struct vfsmount *mnt, const char *dev_name)
73921+{
73922+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
73923+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
73924+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
73925+ return -EPERM;
73926+ }
73927+#endif
73928+ return 0;
73929+}
73930+
73931+int
73932+gr_handle_chroot_pivot(void)
73933+{
73934+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
73935+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
73936+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
73937+ return -EPERM;
73938+ }
73939+#endif
73940+ return 0;
73941+}
73942+
73943+int
73944+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
73945+{
73946+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
73947+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
73948+ !gr_is_outside_chroot(dentry, mnt)) {
73949+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
73950+ return -EPERM;
73951+ }
73952+#endif
73953+ return 0;
73954+}
73955+
73956+extern const char *captab_log[];
73957+extern int captab_log_entries;
73958+
73959+int
73960+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
73961+{
73962+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73963+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
73964+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
73965+ if (cap_raised(chroot_caps, cap)) {
73966+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
73967+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
73968+ }
73969+ return 0;
73970+ }
73971+ }
73972+#endif
73973+ return 1;
73974+}
73975+
73976+int
73977+gr_chroot_is_capable(const int cap)
73978+{
73979+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73980+ return gr_task_chroot_is_capable(current, current_cred(), cap);
73981+#endif
73982+ return 1;
73983+}
73984+
73985+int
73986+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
73987+{
73988+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73989+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
73990+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
73991+ if (cap_raised(chroot_caps, cap)) {
73992+ return 0;
73993+ }
73994+ }
73995+#endif
73996+ return 1;
73997+}
73998+
73999+int
74000+gr_chroot_is_capable_nolog(const int cap)
74001+{
74002+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74003+ return gr_task_chroot_is_capable_nolog(current, cap);
74004+#endif
74005+ return 1;
74006+}
74007+
74008+int
74009+gr_handle_chroot_sysctl(const int op)
74010+{
74011+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
74012+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
74013+ proc_is_chrooted(current))
74014+ return -EACCES;
74015+#endif
74016+ return 0;
74017+}
74018+
74019+void
74020+gr_handle_chroot_chdir(const struct path *path)
74021+{
74022+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
74023+ if (grsec_enable_chroot_chdir)
74024+ set_fs_pwd(current->fs, path);
74025+#endif
74026+ return;
74027+}
74028+
74029+int
74030+gr_handle_chroot_chmod(const struct dentry *dentry,
74031+ const struct vfsmount *mnt, const int mode)
74032+{
74033+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
74034+ /* allow chmod +s on directories, but not files */
74035+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
74036+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
74037+ proc_is_chrooted(current)) {
74038+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
74039+ return -EPERM;
74040+ }
74041+#endif
74042+ return 0;
74043+}
74044diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
74045new file mode 100644
74046index 0000000..4d6fce8
74047--- /dev/null
74048+++ b/grsecurity/grsec_disabled.c
74049@@ -0,0 +1,433 @@
74050+#include <linux/kernel.h>
74051+#include <linux/module.h>
74052+#include <linux/sched.h>
74053+#include <linux/file.h>
74054+#include <linux/fs.h>
74055+#include <linux/kdev_t.h>
74056+#include <linux/net.h>
74057+#include <linux/in.h>
74058+#include <linux/ip.h>
74059+#include <linux/skbuff.h>
74060+#include <linux/sysctl.h>
74061+
74062+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
74063+void
74064+pax_set_initial_flags(struct linux_binprm *bprm)
74065+{
74066+ return;
74067+}
74068+#endif
74069+
74070+#ifdef CONFIG_SYSCTL
74071+__u32
74072+gr_handle_sysctl(const struct ctl_table * table, const int op)
74073+{
74074+ return 0;
74075+}
74076+#endif
74077+
74078+#ifdef CONFIG_TASKSTATS
74079+int gr_is_taskstats_denied(int pid)
74080+{
74081+ return 0;
74082+}
74083+#endif
74084+
74085+int
74086+gr_acl_is_enabled(void)
74087+{
74088+ return 0;
74089+}
74090+
74091+void
74092+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
74093+{
74094+ return;
74095+}
74096+
74097+int
74098+gr_handle_rawio(const struct inode *inode)
74099+{
74100+ return 0;
74101+}
74102+
74103+void
74104+gr_acl_handle_psacct(struct task_struct *task, const long code)
74105+{
74106+ return;
74107+}
74108+
74109+int
74110+gr_handle_ptrace(struct task_struct *task, const long request)
74111+{
74112+ return 0;
74113+}
74114+
74115+int
74116+gr_handle_proc_ptrace(struct task_struct *task)
74117+{
74118+ return 0;
74119+}
74120+
74121+int
74122+gr_set_acls(const int type)
74123+{
74124+ return 0;
74125+}
74126+
74127+int
74128+gr_check_hidden_task(const struct task_struct *tsk)
74129+{
74130+ return 0;
74131+}
74132+
74133+int
74134+gr_check_protected_task(const struct task_struct *task)
74135+{
74136+ return 0;
74137+}
74138+
74139+int
74140+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
74141+{
74142+ return 0;
74143+}
74144+
74145+void
74146+gr_copy_label(struct task_struct *tsk)
74147+{
74148+ return;
74149+}
74150+
74151+void
74152+gr_set_pax_flags(struct task_struct *task)
74153+{
74154+ return;
74155+}
74156+
74157+int
74158+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
74159+ const int unsafe_share)
74160+{
74161+ return 0;
74162+}
74163+
74164+void
74165+gr_handle_delete(const ino_t ino, const dev_t dev)
74166+{
74167+ return;
74168+}
74169+
74170+void
74171+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
74172+{
74173+ return;
74174+}
74175+
74176+void
74177+gr_handle_crash(struct task_struct *task, const int sig)
74178+{
74179+ return;
74180+}
74181+
74182+int
74183+gr_check_crash_exec(const struct file *filp)
74184+{
74185+ return 0;
74186+}
74187+
74188+int
74189+gr_check_crash_uid(const kuid_t uid)
74190+{
74191+ return 0;
74192+}
74193+
74194+void
74195+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
74196+ struct dentry *old_dentry,
74197+ struct dentry *new_dentry,
74198+ struct vfsmount *mnt, const __u8 replace)
74199+{
74200+ return;
74201+}
74202+
74203+int
74204+gr_search_socket(const int family, const int type, const int protocol)
74205+{
74206+ return 1;
74207+}
74208+
74209+int
74210+gr_search_connectbind(const int mode, const struct socket *sock,
74211+ const struct sockaddr_in *addr)
74212+{
74213+ return 0;
74214+}
74215+
74216+void
74217+gr_handle_alertkill(struct task_struct *task)
74218+{
74219+ return;
74220+}
74221+
74222+__u32
74223+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
74224+{
74225+ return 1;
74226+}
74227+
74228+__u32
74229+gr_acl_handle_hidden_file(const struct dentry * dentry,
74230+ const struct vfsmount * mnt)
74231+{
74232+ return 1;
74233+}
74234+
74235+__u32
74236+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
74237+ int acc_mode)
74238+{
74239+ return 1;
74240+}
74241+
74242+__u32
74243+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
74244+{
74245+ return 1;
74246+}
74247+
74248+__u32
74249+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
74250+{
74251+ return 1;
74252+}
74253+
74254+int
74255+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
74256+ unsigned int *vm_flags)
74257+{
74258+ return 1;
74259+}
74260+
74261+__u32
74262+gr_acl_handle_truncate(const struct dentry * dentry,
74263+ const struct vfsmount * mnt)
74264+{
74265+ return 1;
74266+}
74267+
74268+__u32
74269+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
74270+{
74271+ return 1;
74272+}
74273+
74274+__u32
74275+gr_acl_handle_access(const struct dentry * dentry,
74276+ const struct vfsmount * mnt, const int fmode)
74277+{
74278+ return 1;
74279+}
74280+
74281+__u32
74282+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
74283+ umode_t *mode)
74284+{
74285+ return 1;
74286+}
74287+
74288+__u32
74289+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
74290+{
74291+ return 1;
74292+}
74293+
74294+__u32
74295+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
74296+{
74297+ return 1;
74298+}
74299+
74300+__u32
74301+gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
74302+{
74303+ return 1;
74304+}
74305+
74306+void
74307+grsecurity_init(void)
74308+{
74309+ return;
74310+}
74311+
74312+umode_t gr_acl_umask(void)
74313+{
74314+ return 0;
74315+}
74316+
74317+__u32
74318+gr_acl_handle_mknod(const struct dentry * new_dentry,
74319+ const struct dentry * parent_dentry,
74320+ const struct vfsmount * parent_mnt,
74321+ const int mode)
74322+{
74323+ return 1;
74324+}
74325+
74326+__u32
74327+gr_acl_handle_mkdir(const struct dentry * new_dentry,
74328+ const struct dentry * parent_dentry,
74329+ const struct vfsmount * parent_mnt)
74330+{
74331+ return 1;
74332+}
74333+
74334+__u32
74335+gr_acl_handle_symlink(const struct dentry * new_dentry,
74336+ const struct dentry * parent_dentry,
74337+ const struct vfsmount * parent_mnt, const struct filename *from)
74338+{
74339+ return 1;
74340+}
74341+
74342+__u32
74343+gr_acl_handle_link(const struct dentry * new_dentry,
74344+ const struct dentry * parent_dentry,
74345+ const struct vfsmount * parent_mnt,
74346+ const struct dentry * old_dentry,
74347+ const struct vfsmount * old_mnt, const struct filename *to)
74348+{
74349+ return 1;
74350+}
74351+
74352+int
74353+gr_acl_handle_rename(const struct dentry *new_dentry,
74354+ const struct dentry *parent_dentry,
74355+ const struct vfsmount *parent_mnt,
74356+ const struct dentry *old_dentry,
74357+ const struct inode *old_parent_inode,
74358+ const struct vfsmount *old_mnt, const struct filename *newname)
74359+{
74360+ return 0;
74361+}
74362+
74363+int
74364+gr_acl_handle_filldir(const struct file *file, const char *name,
74365+ const int namelen, const ino_t ino)
74366+{
74367+ return 1;
74368+}
74369+
74370+int
74371+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
74372+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
74373+{
74374+ return 1;
74375+}
74376+
74377+int
74378+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
74379+{
74380+ return 0;
74381+}
74382+
74383+int
74384+gr_search_accept(const struct socket *sock)
74385+{
74386+ return 0;
74387+}
74388+
74389+int
74390+gr_search_listen(const struct socket *sock)
74391+{
74392+ return 0;
74393+}
74394+
74395+int
74396+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
74397+{
74398+ return 0;
74399+}
74400+
74401+__u32
74402+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
74403+{
74404+ return 1;
74405+}
74406+
74407+__u32
74408+gr_acl_handle_creat(const struct dentry * dentry,
74409+ const struct dentry * p_dentry,
74410+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
74411+ const int imode)
74412+{
74413+ return 1;
74414+}
74415+
74416+void
74417+gr_acl_handle_exit(void)
74418+{
74419+ return;
74420+}
74421+
74422+int
74423+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
74424+{
74425+ return 1;
74426+}
74427+
74428+void
74429+gr_set_role_label(const kuid_t uid, const kgid_t gid)
74430+{
74431+ return;
74432+}
74433+
74434+int
74435+gr_acl_handle_procpidmem(const struct task_struct *task)
74436+{
74437+ return 0;
74438+}
74439+
74440+int
74441+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
74442+{
74443+ return 0;
74444+}
74445+
74446+int
74447+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
74448+{
74449+ return 0;
74450+}
74451+
74452+int
74453+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
74454+{
74455+ return 0;
74456+}
74457+
74458+int
74459+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
74460+{
74461+ return 0;
74462+}
74463+
74464+int gr_acl_enable_at_secure(void)
74465+{
74466+ return 0;
74467+}
74468+
74469+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
74470+{
74471+ return dentry->d_sb->s_dev;
74472+}
74473+
74474+void gr_put_exec_file(struct task_struct *task)
74475+{
74476+ return;
74477+}
74478+
74479+#ifdef CONFIG_SECURITY
74480+EXPORT_SYMBOL_GPL(gr_check_user_change);
74481+EXPORT_SYMBOL_GPL(gr_check_group_change);
74482+#endif
74483diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
74484new file mode 100644
74485index 0000000..f35f454
74486--- /dev/null
74487+++ b/grsecurity/grsec_exec.c
74488@@ -0,0 +1,187 @@
74489+#include <linux/kernel.h>
74490+#include <linux/sched.h>
74491+#include <linux/file.h>
74492+#include <linux/binfmts.h>
74493+#include <linux/fs.h>
74494+#include <linux/types.h>
74495+#include <linux/grdefs.h>
74496+#include <linux/grsecurity.h>
74497+#include <linux/grinternal.h>
74498+#include <linux/capability.h>
74499+#include <linux/module.h>
74500+#include <linux/compat.h>
74501+
74502+#include <asm/uaccess.h>
74503+
74504+#ifdef CONFIG_GRKERNSEC_EXECLOG
74505+static char gr_exec_arg_buf[132];
74506+static DEFINE_MUTEX(gr_exec_arg_mutex);
74507+#endif
74508+
74509+struct user_arg_ptr {
74510+#ifdef CONFIG_COMPAT
74511+ bool is_compat;
74512+#endif
74513+ union {
74514+ const char __user *const __user *native;
74515+#ifdef CONFIG_COMPAT
74516+ const compat_uptr_t __user *compat;
74517+#endif
74518+ } ptr;
74519+};
74520+
74521+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
74522+
74523+void
74524+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
74525+{
74526+#ifdef CONFIG_GRKERNSEC_EXECLOG
74527+ char *grarg = gr_exec_arg_buf;
74528+ unsigned int i, x, execlen = 0;
74529+ char c;
74530+
74531+ if (!((grsec_enable_execlog && grsec_enable_group &&
74532+ in_group_p(grsec_audit_gid))
74533+ || (grsec_enable_execlog && !grsec_enable_group)))
74534+ return;
74535+
74536+ mutex_lock(&gr_exec_arg_mutex);
74537+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
74538+
74539+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
74540+ const char __user *p;
74541+ unsigned int len;
74542+
74543+ p = get_user_arg_ptr(argv, i);
74544+ if (IS_ERR(p))
74545+ goto log;
74546+
74547+ len = strnlen_user(p, 128 - execlen);
74548+ if (len > 128 - execlen)
74549+ len = 128 - execlen;
74550+ else if (len > 0)
74551+ len--;
74552+ if (copy_from_user(grarg + execlen, p, len))
74553+ goto log;
74554+
74555+ /* rewrite unprintable characters */
74556+ for (x = 0; x < len; x++) {
74557+ c = *(grarg + execlen + x);
74558+ if (c < 32 || c > 126)
74559+ *(grarg + execlen + x) = ' ';
74560+ }
74561+
74562+ execlen += len;
74563+ *(grarg + execlen) = ' ';
74564+ *(grarg + execlen + 1) = '\0';
74565+ execlen++;
74566+ }
74567+
74568+ log:
74569+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
74570+ bprm->file->f_path.mnt, grarg);
74571+ mutex_unlock(&gr_exec_arg_mutex);
74572+#endif
74573+ return;
74574+}
74575+
74576+#ifdef CONFIG_GRKERNSEC
74577+extern int gr_acl_is_capable(const int cap);
74578+extern int gr_acl_is_capable_nolog(const int cap);
74579+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74580+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
74581+extern int gr_chroot_is_capable(const int cap);
74582+extern int gr_chroot_is_capable_nolog(const int cap);
74583+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74584+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
74585+#endif
74586+
74587+const char *captab_log[] = {
74588+ "CAP_CHOWN",
74589+ "CAP_DAC_OVERRIDE",
74590+ "CAP_DAC_READ_SEARCH",
74591+ "CAP_FOWNER",
74592+ "CAP_FSETID",
74593+ "CAP_KILL",
74594+ "CAP_SETGID",
74595+ "CAP_SETUID",
74596+ "CAP_SETPCAP",
74597+ "CAP_LINUX_IMMUTABLE",
74598+ "CAP_NET_BIND_SERVICE",
74599+ "CAP_NET_BROADCAST",
74600+ "CAP_NET_ADMIN",
74601+ "CAP_NET_RAW",
74602+ "CAP_IPC_LOCK",
74603+ "CAP_IPC_OWNER",
74604+ "CAP_SYS_MODULE",
74605+ "CAP_SYS_RAWIO",
74606+ "CAP_SYS_CHROOT",
74607+ "CAP_SYS_PTRACE",
74608+ "CAP_SYS_PACCT",
74609+ "CAP_SYS_ADMIN",
74610+ "CAP_SYS_BOOT",
74611+ "CAP_SYS_NICE",
74612+ "CAP_SYS_RESOURCE",
74613+ "CAP_SYS_TIME",
74614+ "CAP_SYS_TTY_CONFIG",
74615+ "CAP_MKNOD",
74616+ "CAP_LEASE",
74617+ "CAP_AUDIT_WRITE",
74618+ "CAP_AUDIT_CONTROL",
74619+ "CAP_SETFCAP",
74620+ "CAP_MAC_OVERRIDE",
74621+ "CAP_MAC_ADMIN",
74622+ "CAP_SYSLOG",
74623+ "CAP_WAKE_ALARM"
74624+};
74625+
74626+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
74627+
74628+int gr_is_capable(const int cap)
74629+{
74630+#ifdef CONFIG_GRKERNSEC
74631+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
74632+ return 1;
74633+ return 0;
74634+#else
74635+ return 1;
74636+#endif
74637+}
74638+
74639+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
74640+{
74641+#ifdef CONFIG_GRKERNSEC
74642+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
74643+ return 1;
74644+ return 0;
74645+#else
74646+ return 1;
74647+#endif
74648+}
74649+
74650+int gr_is_capable_nolog(const int cap)
74651+{
74652+#ifdef CONFIG_GRKERNSEC
74653+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
74654+ return 1;
74655+ return 0;
74656+#else
74657+ return 1;
74658+#endif
74659+}
74660+
74661+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
74662+{
74663+#ifdef CONFIG_GRKERNSEC
74664+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
74665+ return 1;
74666+ return 0;
74667+#else
74668+ return 1;
74669+#endif
74670+}
74671+
74672+EXPORT_SYMBOL_GPL(gr_is_capable);
74673+EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
74674+EXPORT_SYMBOL_GPL(gr_task_is_capable);
74675+EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
74676diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
74677new file mode 100644
74678index 0000000..06cc6ea
74679--- /dev/null
74680+++ b/grsecurity/grsec_fifo.c
74681@@ -0,0 +1,24 @@
74682+#include <linux/kernel.h>
74683+#include <linux/sched.h>
74684+#include <linux/fs.h>
74685+#include <linux/file.h>
74686+#include <linux/grinternal.h>
74687+
74688+int
74689+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
74690+ const struct dentry *dir, const int flag, const int acc_mode)
74691+{
74692+#ifdef CONFIG_GRKERNSEC_FIFO
74693+ const struct cred *cred = current_cred();
74694+
74695+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
74696+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
74697+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
74698+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
74699+ if (!inode_permission(dentry->d_inode, acc_mode))
74700+ 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));
74701+ return -EACCES;
74702+ }
74703+#endif
74704+ return 0;
74705+}
74706diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
74707new file mode 100644
74708index 0000000..8ca18bf
74709--- /dev/null
74710+++ b/grsecurity/grsec_fork.c
74711@@ -0,0 +1,23 @@
74712+#include <linux/kernel.h>
74713+#include <linux/sched.h>
74714+#include <linux/grsecurity.h>
74715+#include <linux/grinternal.h>
74716+#include <linux/errno.h>
74717+
74718+void
74719+gr_log_forkfail(const int retval)
74720+{
74721+#ifdef CONFIG_GRKERNSEC_FORKFAIL
74722+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
74723+ switch (retval) {
74724+ case -EAGAIN:
74725+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
74726+ break;
74727+ case -ENOMEM:
74728+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
74729+ break;
74730+ }
74731+ }
74732+#endif
74733+ return;
74734+}
74735diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
74736new file mode 100644
74737index 0000000..ae6c028
74738--- /dev/null
74739+++ b/grsecurity/grsec_init.c
74740@@ -0,0 +1,272 @@
74741+#include <linux/kernel.h>
74742+#include <linux/sched.h>
74743+#include <linux/mm.h>
74744+#include <linux/gracl.h>
74745+#include <linux/slab.h>
74746+#include <linux/vmalloc.h>
74747+#include <linux/percpu.h>
74748+#include <linux/module.h>
74749+
74750+int grsec_enable_ptrace_readexec;
74751+int grsec_enable_setxid;
74752+int grsec_enable_symlinkown;
74753+kgid_t grsec_symlinkown_gid;
74754+int grsec_enable_brute;
74755+int grsec_enable_link;
74756+int grsec_enable_dmesg;
74757+int grsec_enable_harden_ptrace;
74758+int grsec_enable_harden_ipc;
74759+int grsec_enable_fifo;
74760+int grsec_enable_execlog;
74761+int grsec_enable_signal;
74762+int grsec_enable_forkfail;
74763+int grsec_enable_audit_ptrace;
74764+int grsec_enable_time;
74765+int grsec_enable_group;
74766+kgid_t grsec_audit_gid;
74767+int grsec_enable_chdir;
74768+int grsec_enable_mount;
74769+int grsec_enable_rofs;
74770+int grsec_deny_new_usb;
74771+int grsec_enable_chroot_findtask;
74772+int grsec_enable_chroot_mount;
74773+int grsec_enable_chroot_shmat;
74774+int grsec_enable_chroot_fchdir;
74775+int grsec_enable_chroot_double;
74776+int grsec_enable_chroot_pivot;
74777+int grsec_enable_chroot_chdir;
74778+int grsec_enable_chroot_chmod;
74779+int grsec_enable_chroot_mknod;
74780+int grsec_enable_chroot_nice;
74781+int grsec_enable_chroot_execlog;
74782+int grsec_enable_chroot_caps;
74783+int grsec_enable_chroot_sysctl;
74784+int grsec_enable_chroot_unix;
74785+int grsec_enable_tpe;
74786+kgid_t grsec_tpe_gid;
74787+int grsec_enable_blackhole;
74788+#ifdef CONFIG_IPV6_MODULE
74789+EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
74790+#endif
74791+int grsec_lastack_retries;
74792+int grsec_enable_tpe_all;
74793+int grsec_enable_tpe_invert;
74794+int grsec_enable_socket_all;
74795+kgid_t grsec_socket_all_gid;
74796+int grsec_enable_socket_client;
74797+kgid_t grsec_socket_client_gid;
74798+int grsec_enable_socket_server;
74799+kgid_t grsec_socket_server_gid;
74800+int grsec_resource_logging;
74801+int grsec_disable_privio;
74802+int grsec_enable_log_rwxmaps;
74803+int grsec_lock;
74804+
74805+DEFINE_SPINLOCK(grsec_alert_lock);
74806+unsigned long grsec_alert_wtime = 0;
74807+unsigned long grsec_alert_fyet = 0;
74808+
74809+DEFINE_SPINLOCK(grsec_audit_lock);
74810+
74811+DEFINE_RWLOCK(grsec_exec_file_lock);
74812+
74813+char *gr_shared_page[4];
74814+
74815+char *gr_alert_log_fmt;
74816+char *gr_audit_log_fmt;
74817+char *gr_alert_log_buf;
74818+char *gr_audit_log_buf;
74819+
74820+void __init
74821+grsecurity_init(void)
74822+{
74823+ int j;
74824+ /* create the per-cpu shared pages */
74825+
74826+#ifdef CONFIG_X86
74827+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
74828+#endif
74829+
74830+ for (j = 0; j < 4; j++) {
74831+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
74832+ if (gr_shared_page[j] == NULL) {
74833+ panic("Unable to allocate grsecurity shared page");
74834+ return;
74835+ }
74836+ }
74837+
74838+ /* allocate log buffers */
74839+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
74840+ if (!gr_alert_log_fmt) {
74841+ panic("Unable to allocate grsecurity alert log format buffer");
74842+ return;
74843+ }
74844+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
74845+ if (!gr_audit_log_fmt) {
74846+ panic("Unable to allocate grsecurity audit log format buffer");
74847+ return;
74848+ }
74849+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
74850+ if (!gr_alert_log_buf) {
74851+ panic("Unable to allocate grsecurity alert log buffer");
74852+ return;
74853+ }
74854+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
74855+ if (!gr_audit_log_buf) {
74856+ panic("Unable to allocate grsecurity audit log buffer");
74857+ return;
74858+ }
74859+
74860+#ifdef CONFIG_GRKERNSEC_IO
74861+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
74862+ grsec_disable_privio = 1;
74863+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
74864+ grsec_disable_privio = 1;
74865+#else
74866+ grsec_disable_privio = 0;
74867+#endif
74868+#endif
74869+
74870+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
74871+ /* for backward compatibility, tpe_invert always defaults to on if
74872+ enabled in the kernel
74873+ */
74874+ grsec_enable_tpe_invert = 1;
74875+#endif
74876+
74877+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
74878+#ifndef CONFIG_GRKERNSEC_SYSCTL
74879+ grsec_lock = 1;
74880+#endif
74881+
74882+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74883+ grsec_enable_log_rwxmaps = 1;
74884+#endif
74885+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
74886+ grsec_enable_group = 1;
74887+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
74888+#endif
74889+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
74890+ grsec_enable_ptrace_readexec = 1;
74891+#endif
74892+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
74893+ grsec_enable_chdir = 1;
74894+#endif
74895+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
74896+ grsec_enable_harden_ptrace = 1;
74897+#endif
74898+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
74899+ grsec_enable_harden_ipc = 1;
74900+#endif
74901+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74902+ grsec_enable_mount = 1;
74903+#endif
74904+#ifdef CONFIG_GRKERNSEC_LINK
74905+ grsec_enable_link = 1;
74906+#endif
74907+#ifdef CONFIG_GRKERNSEC_BRUTE
74908+ grsec_enable_brute = 1;
74909+#endif
74910+#ifdef CONFIG_GRKERNSEC_DMESG
74911+ grsec_enable_dmesg = 1;
74912+#endif
74913+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74914+ grsec_enable_blackhole = 1;
74915+ grsec_lastack_retries = 4;
74916+#endif
74917+#ifdef CONFIG_GRKERNSEC_FIFO
74918+ grsec_enable_fifo = 1;
74919+#endif
74920+#ifdef CONFIG_GRKERNSEC_EXECLOG
74921+ grsec_enable_execlog = 1;
74922+#endif
74923+#ifdef CONFIG_GRKERNSEC_SETXID
74924+ grsec_enable_setxid = 1;
74925+#endif
74926+#ifdef CONFIG_GRKERNSEC_SIGNAL
74927+ grsec_enable_signal = 1;
74928+#endif
74929+#ifdef CONFIG_GRKERNSEC_FORKFAIL
74930+ grsec_enable_forkfail = 1;
74931+#endif
74932+#ifdef CONFIG_GRKERNSEC_TIME
74933+ grsec_enable_time = 1;
74934+#endif
74935+#ifdef CONFIG_GRKERNSEC_RESLOG
74936+ grsec_resource_logging = 1;
74937+#endif
74938+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
74939+ grsec_enable_chroot_findtask = 1;
74940+#endif
74941+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
74942+ grsec_enable_chroot_unix = 1;
74943+#endif
74944+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
74945+ grsec_enable_chroot_mount = 1;
74946+#endif
74947+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
74948+ grsec_enable_chroot_fchdir = 1;
74949+#endif
74950+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
74951+ grsec_enable_chroot_shmat = 1;
74952+#endif
74953+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
74954+ grsec_enable_audit_ptrace = 1;
74955+#endif
74956+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
74957+ grsec_enable_chroot_double = 1;
74958+#endif
74959+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
74960+ grsec_enable_chroot_pivot = 1;
74961+#endif
74962+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
74963+ grsec_enable_chroot_chdir = 1;
74964+#endif
74965+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
74966+ grsec_enable_chroot_chmod = 1;
74967+#endif
74968+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
74969+ grsec_enable_chroot_mknod = 1;
74970+#endif
74971+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
74972+ grsec_enable_chroot_nice = 1;
74973+#endif
74974+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
74975+ grsec_enable_chroot_execlog = 1;
74976+#endif
74977+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74978+ grsec_enable_chroot_caps = 1;
74979+#endif
74980+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
74981+ grsec_enable_chroot_sysctl = 1;
74982+#endif
74983+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
74984+ grsec_enable_symlinkown = 1;
74985+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
74986+#endif
74987+#ifdef CONFIG_GRKERNSEC_TPE
74988+ grsec_enable_tpe = 1;
74989+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
74990+#ifdef CONFIG_GRKERNSEC_TPE_ALL
74991+ grsec_enable_tpe_all = 1;
74992+#endif
74993+#endif
74994+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
74995+ grsec_enable_socket_all = 1;
74996+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
74997+#endif
74998+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
74999+ grsec_enable_socket_client = 1;
75000+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
75001+#endif
75002+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75003+ grsec_enable_socket_server = 1;
75004+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
75005+#endif
75006+#endif
75007+#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
75008+ grsec_deny_new_usb = 1;
75009+#endif
75010+
75011+ return;
75012+}
75013diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
75014new file mode 100644
75015index 0000000..1773300
75016--- /dev/null
75017+++ b/grsecurity/grsec_ipc.c
75018@@ -0,0 +1,48 @@
75019+#include <linux/kernel.h>
75020+#include <linux/mm.h>
75021+#include <linux/sched.h>
75022+#include <linux/file.h>
75023+#include <linux/ipc.h>
75024+#include <linux/ipc_namespace.h>
75025+#include <linux/grsecurity.h>
75026+#include <linux/grinternal.h>
75027+
75028+int
75029+gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
75030+{
75031+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
75032+ int write;
75033+ int orig_granted_mode;
75034+ kuid_t euid;
75035+ kgid_t egid;
75036+
75037+ if (!grsec_enable_harden_ipc)
75038+ return 1;
75039+
75040+ euid = current_euid();
75041+ egid = current_egid();
75042+
75043+ write = requested_mode & 00002;
75044+ orig_granted_mode = ipcp->mode;
75045+
75046+ if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
75047+ orig_granted_mode >>= 6;
75048+ else {
75049+ /* if likely wrong permissions, lock to user */
75050+ if (orig_granted_mode & 0007)
75051+ orig_granted_mode = 0;
75052+ /* otherwise do a egid-only check */
75053+ else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
75054+ orig_granted_mode >>= 3;
75055+ /* otherwise, no access */
75056+ else
75057+ orig_granted_mode = 0;
75058+ }
75059+ if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
75060+ !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
75061+ gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
75062+ return 0;
75063+ }
75064+#endif
75065+ return 1;
75066+}
75067diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
75068new file mode 100644
75069index 0000000..5e05e20
75070--- /dev/null
75071+++ b/grsecurity/grsec_link.c
75072@@ -0,0 +1,58 @@
75073+#include <linux/kernel.h>
75074+#include <linux/sched.h>
75075+#include <linux/fs.h>
75076+#include <linux/file.h>
75077+#include <linux/grinternal.h>
75078+
75079+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
75080+{
75081+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
75082+ const struct inode *link_inode = link->dentry->d_inode;
75083+
75084+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
75085+ /* ignore root-owned links, e.g. /proc/self */
75086+ gr_is_global_nonroot(link_inode->i_uid) && target &&
75087+ !uid_eq(link_inode->i_uid, target->i_uid)) {
75088+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
75089+ return 1;
75090+ }
75091+#endif
75092+ return 0;
75093+}
75094+
75095+int
75096+gr_handle_follow_link(const struct inode *parent,
75097+ const struct inode *inode,
75098+ const struct dentry *dentry, const struct vfsmount *mnt)
75099+{
75100+#ifdef CONFIG_GRKERNSEC_LINK
75101+ const struct cred *cred = current_cred();
75102+
75103+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
75104+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
75105+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
75106+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
75107+ return -EACCES;
75108+ }
75109+#endif
75110+ return 0;
75111+}
75112+
75113+int
75114+gr_handle_hardlink(const struct dentry *dentry,
75115+ const struct vfsmount *mnt,
75116+ struct inode *inode, const int mode, const struct filename *to)
75117+{
75118+#ifdef CONFIG_GRKERNSEC_LINK
75119+ const struct cred *cred = current_cred();
75120+
75121+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
75122+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
75123+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
75124+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
75125+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
75126+ return -EPERM;
75127+ }
75128+#endif
75129+ return 0;
75130+}
75131diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
75132new file mode 100644
75133index 0000000..dbe0a6b
75134--- /dev/null
75135+++ b/grsecurity/grsec_log.c
75136@@ -0,0 +1,341 @@
75137+#include <linux/kernel.h>
75138+#include <linux/sched.h>
75139+#include <linux/file.h>
75140+#include <linux/tty.h>
75141+#include <linux/fs.h>
75142+#include <linux/mm.h>
75143+#include <linux/grinternal.h>
75144+
75145+#ifdef CONFIG_TREE_PREEMPT_RCU
75146+#define DISABLE_PREEMPT() preempt_disable()
75147+#define ENABLE_PREEMPT() preempt_enable()
75148+#else
75149+#define DISABLE_PREEMPT()
75150+#define ENABLE_PREEMPT()
75151+#endif
75152+
75153+#define BEGIN_LOCKS(x) \
75154+ DISABLE_PREEMPT(); \
75155+ rcu_read_lock(); \
75156+ read_lock(&tasklist_lock); \
75157+ read_lock(&grsec_exec_file_lock); \
75158+ if (x != GR_DO_AUDIT) \
75159+ spin_lock(&grsec_alert_lock); \
75160+ else \
75161+ spin_lock(&grsec_audit_lock)
75162+
75163+#define END_LOCKS(x) \
75164+ if (x != GR_DO_AUDIT) \
75165+ spin_unlock(&grsec_alert_lock); \
75166+ else \
75167+ spin_unlock(&grsec_audit_lock); \
75168+ read_unlock(&grsec_exec_file_lock); \
75169+ read_unlock(&tasklist_lock); \
75170+ rcu_read_unlock(); \
75171+ ENABLE_PREEMPT(); \
75172+ if (x == GR_DONT_AUDIT) \
75173+ gr_handle_alertkill(current)
75174+
75175+enum {
75176+ FLOODING,
75177+ NO_FLOODING
75178+};
75179+
75180+extern char *gr_alert_log_fmt;
75181+extern char *gr_audit_log_fmt;
75182+extern char *gr_alert_log_buf;
75183+extern char *gr_audit_log_buf;
75184+
75185+static int gr_log_start(int audit)
75186+{
75187+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
75188+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
75189+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75190+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
75191+ unsigned long curr_secs = get_seconds();
75192+
75193+ if (audit == GR_DO_AUDIT)
75194+ goto set_fmt;
75195+
75196+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
75197+ grsec_alert_wtime = curr_secs;
75198+ grsec_alert_fyet = 0;
75199+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
75200+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
75201+ grsec_alert_fyet++;
75202+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
75203+ grsec_alert_wtime = curr_secs;
75204+ grsec_alert_fyet++;
75205+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
75206+ return FLOODING;
75207+ }
75208+ else return FLOODING;
75209+
75210+set_fmt:
75211+#endif
75212+ memset(buf, 0, PAGE_SIZE);
75213+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
75214+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
75215+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
75216+ } else if (current->signal->curr_ip) {
75217+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
75218+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
75219+ } else if (gr_acl_is_enabled()) {
75220+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
75221+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
75222+ } else {
75223+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
75224+ strcpy(buf, fmt);
75225+ }
75226+
75227+ return NO_FLOODING;
75228+}
75229+
75230+static void gr_log_middle(int audit, const char *msg, va_list ap)
75231+ __attribute__ ((format (printf, 2, 0)));
75232+
75233+static void gr_log_middle(int audit, const char *msg, va_list ap)
75234+{
75235+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75236+ unsigned int len = strlen(buf);
75237+
75238+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
75239+
75240+ return;
75241+}
75242+
75243+static void gr_log_middle_varargs(int audit, const char *msg, ...)
75244+ __attribute__ ((format (printf, 2, 3)));
75245+
75246+static void gr_log_middle_varargs(int audit, const char *msg, ...)
75247+{
75248+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75249+ unsigned int len = strlen(buf);
75250+ va_list ap;
75251+
75252+ va_start(ap, msg);
75253+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
75254+ va_end(ap);
75255+
75256+ return;
75257+}
75258+
75259+static void gr_log_end(int audit, int append_default)
75260+{
75261+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75262+ if (append_default) {
75263+ struct task_struct *task = current;
75264+ struct task_struct *parent = task->real_parent;
75265+ const struct cred *cred = __task_cred(task);
75266+ const struct cred *pcred = __task_cred(parent);
75267+ unsigned int len = strlen(buf);
75268+
75269+ 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));
75270+ }
75271+
75272+ printk("%s\n", buf);
75273+
75274+ return;
75275+}
75276+
75277+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
75278+{
75279+ int logtype;
75280+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
75281+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
75282+ void *voidptr = NULL;
75283+ int num1 = 0, num2 = 0;
75284+ unsigned long ulong1 = 0, ulong2 = 0;
75285+ struct dentry *dentry = NULL;
75286+ struct vfsmount *mnt = NULL;
75287+ struct file *file = NULL;
75288+ struct task_struct *task = NULL;
75289+ struct vm_area_struct *vma = NULL;
75290+ const struct cred *cred, *pcred;
75291+ va_list ap;
75292+
75293+ BEGIN_LOCKS(audit);
75294+ logtype = gr_log_start(audit);
75295+ if (logtype == FLOODING) {
75296+ END_LOCKS(audit);
75297+ return;
75298+ }
75299+ va_start(ap, argtypes);
75300+ switch (argtypes) {
75301+ case GR_TTYSNIFF:
75302+ task = va_arg(ap, struct task_struct *);
75303+ 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));
75304+ break;
75305+ case GR_SYSCTL_HIDDEN:
75306+ str1 = va_arg(ap, char *);
75307+ gr_log_middle_varargs(audit, msg, result, str1);
75308+ break;
75309+ case GR_RBAC:
75310+ dentry = va_arg(ap, struct dentry *);
75311+ mnt = va_arg(ap, struct vfsmount *);
75312+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
75313+ break;
75314+ case GR_RBAC_STR:
75315+ dentry = va_arg(ap, struct dentry *);
75316+ mnt = va_arg(ap, struct vfsmount *);
75317+ str1 = va_arg(ap, char *);
75318+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
75319+ break;
75320+ case GR_STR_RBAC:
75321+ str1 = va_arg(ap, char *);
75322+ dentry = va_arg(ap, struct dentry *);
75323+ mnt = va_arg(ap, struct vfsmount *);
75324+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
75325+ break;
75326+ case GR_RBAC_MODE2:
75327+ dentry = va_arg(ap, struct dentry *);
75328+ mnt = va_arg(ap, struct vfsmount *);
75329+ str1 = va_arg(ap, char *);
75330+ str2 = va_arg(ap, char *);
75331+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
75332+ break;
75333+ case GR_RBAC_MODE3:
75334+ dentry = va_arg(ap, struct dentry *);
75335+ mnt = va_arg(ap, struct vfsmount *);
75336+ str1 = va_arg(ap, char *);
75337+ str2 = va_arg(ap, char *);
75338+ str3 = va_arg(ap, char *);
75339+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
75340+ break;
75341+ case GR_FILENAME:
75342+ dentry = va_arg(ap, struct dentry *);
75343+ mnt = va_arg(ap, struct vfsmount *);
75344+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
75345+ break;
75346+ case GR_STR_FILENAME:
75347+ str1 = va_arg(ap, char *);
75348+ dentry = va_arg(ap, struct dentry *);
75349+ mnt = va_arg(ap, struct vfsmount *);
75350+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
75351+ break;
75352+ case GR_FILENAME_STR:
75353+ dentry = va_arg(ap, struct dentry *);
75354+ mnt = va_arg(ap, struct vfsmount *);
75355+ str1 = va_arg(ap, char *);
75356+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
75357+ break;
75358+ case GR_FILENAME_TWO_INT:
75359+ dentry = va_arg(ap, struct dentry *);
75360+ mnt = va_arg(ap, struct vfsmount *);
75361+ num1 = va_arg(ap, int);
75362+ num2 = va_arg(ap, int);
75363+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
75364+ break;
75365+ case GR_FILENAME_TWO_INT_STR:
75366+ dentry = va_arg(ap, struct dentry *);
75367+ mnt = va_arg(ap, struct vfsmount *);
75368+ num1 = va_arg(ap, int);
75369+ num2 = va_arg(ap, int);
75370+ str1 = va_arg(ap, char *);
75371+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
75372+ break;
75373+ case GR_TEXTREL:
75374+ file = va_arg(ap, struct file *);
75375+ ulong1 = va_arg(ap, unsigned long);
75376+ ulong2 = va_arg(ap, unsigned long);
75377+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
75378+ break;
75379+ case GR_PTRACE:
75380+ task = va_arg(ap, struct task_struct *);
75381+ 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));
75382+ break;
75383+ case GR_RESOURCE:
75384+ task = va_arg(ap, struct task_struct *);
75385+ cred = __task_cred(task);
75386+ pcred = __task_cred(task->real_parent);
75387+ ulong1 = va_arg(ap, unsigned long);
75388+ str1 = va_arg(ap, char *);
75389+ ulong2 = va_arg(ap, unsigned long);
75390+ 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));
75391+ break;
75392+ case GR_CAP:
75393+ task = va_arg(ap, struct task_struct *);
75394+ cred = __task_cred(task);
75395+ pcred = __task_cred(task->real_parent);
75396+ str1 = va_arg(ap, char *);
75397+ 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));
75398+ break;
75399+ case GR_SIG:
75400+ str1 = va_arg(ap, char *);
75401+ voidptr = va_arg(ap, void *);
75402+ gr_log_middle_varargs(audit, msg, str1, voidptr);
75403+ break;
75404+ case GR_SIG2:
75405+ task = va_arg(ap, struct task_struct *);
75406+ cred = __task_cred(task);
75407+ pcred = __task_cred(task->real_parent);
75408+ num1 = va_arg(ap, int);
75409+ 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));
75410+ break;
75411+ case GR_CRASH1:
75412+ task = va_arg(ap, struct task_struct *);
75413+ cred = __task_cred(task);
75414+ pcred = __task_cred(task->real_parent);
75415+ ulong1 = va_arg(ap, unsigned long);
75416+ 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);
75417+ break;
75418+ case GR_CRASH2:
75419+ task = va_arg(ap, struct task_struct *);
75420+ cred = __task_cred(task);
75421+ pcred = __task_cred(task->real_parent);
75422+ ulong1 = va_arg(ap, unsigned long);
75423+ 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);
75424+ break;
75425+ case GR_RWXMAP:
75426+ file = va_arg(ap, struct file *);
75427+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
75428+ break;
75429+ case GR_RWXMAPVMA:
75430+ vma = va_arg(ap, struct vm_area_struct *);
75431+ if (vma->vm_file)
75432+ str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
75433+ else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
75434+ str1 = "<stack>";
75435+ else if (vma->vm_start <= current->mm->brk &&
75436+ vma->vm_end >= current->mm->start_brk)
75437+ str1 = "<heap>";
75438+ else
75439+ str1 = "<anonymous mapping>";
75440+ gr_log_middle_varargs(audit, msg, str1);
75441+ break;
75442+ case GR_PSACCT:
75443+ {
75444+ unsigned int wday, cday;
75445+ __u8 whr, chr;
75446+ __u8 wmin, cmin;
75447+ __u8 wsec, csec;
75448+ char cur_tty[64] = { 0 };
75449+ char parent_tty[64] = { 0 };
75450+
75451+ task = va_arg(ap, struct task_struct *);
75452+ wday = va_arg(ap, unsigned int);
75453+ cday = va_arg(ap, unsigned int);
75454+ whr = va_arg(ap, int);
75455+ chr = va_arg(ap, int);
75456+ wmin = va_arg(ap, int);
75457+ cmin = va_arg(ap, int);
75458+ wsec = va_arg(ap, int);
75459+ csec = va_arg(ap, int);
75460+ ulong1 = va_arg(ap, unsigned long);
75461+ cred = __task_cred(task);
75462+ pcred = __task_cred(task->real_parent);
75463+
75464+ 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));
75465+ }
75466+ break;
75467+ default:
75468+ gr_log_middle(audit, msg, ap);
75469+ }
75470+ va_end(ap);
75471+ // these don't need DEFAULTSECARGS printed on the end
75472+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
75473+ gr_log_end(audit, 0);
75474+ else
75475+ gr_log_end(audit, 1);
75476+ END_LOCKS(audit);
75477+}
75478diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
75479new file mode 100644
75480index 0000000..0e39d8c
75481--- /dev/null
75482+++ b/grsecurity/grsec_mem.c
75483@@ -0,0 +1,48 @@
75484+#include <linux/kernel.h>
75485+#include <linux/sched.h>
75486+#include <linux/mm.h>
75487+#include <linux/mman.h>
75488+#include <linux/module.h>
75489+#include <linux/grinternal.h>
75490+
75491+void gr_handle_msr_write(void)
75492+{
75493+ gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
75494+ return;
75495+}
75496+EXPORT_SYMBOL_GPL(gr_handle_msr_write);
75497+
75498+void
75499+gr_handle_ioperm(void)
75500+{
75501+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
75502+ return;
75503+}
75504+
75505+void
75506+gr_handle_iopl(void)
75507+{
75508+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
75509+ return;
75510+}
75511+
75512+void
75513+gr_handle_mem_readwrite(u64 from, u64 to)
75514+{
75515+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
75516+ return;
75517+}
75518+
75519+void
75520+gr_handle_vm86(void)
75521+{
75522+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
75523+ return;
75524+}
75525+
75526+void
75527+gr_log_badprocpid(const char *entry)
75528+{
75529+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
75530+ return;
75531+}
75532diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
75533new file mode 100644
75534index 0000000..cd9e124
75535--- /dev/null
75536+++ b/grsecurity/grsec_mount.c
75537@@ -0,0 +1,65 @@
75538+#include <linux/kernel.h>
75539+#include <linux/sched.h>
75540+#include <linux/mount.h>
75541+#include <linux/major.h>
75542+#include <linux/grsecurity.h>
75543+#include <linux/grinternal.h>
75544+
75545+void
75546+gr_log_remount(const char *devname, const int retval)
75547+{
75548+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75549+ if (grsec_enable_mount && (retval >= 0))
75550+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
75551+#endif
75552+ return;
75553+}
75554+
75555+void
75556+gr_log_unmount(const char *devname, const int retval)
75557+{
75558+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75559+ if (grsec_enable_mount && (retval >= 0))
75560+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
75561+#endif
75562+ return;
75563+}
75564+
75565+void
75566+gr_log_mount(const char *from, const char *to, const int retval)
75567+{
75568+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75569+ if (grsec_enable_mount && (retval >= 0))
75570+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
75571+#endif
75572+ return;
75573+}
75574+
75575+int
75576+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
75577+{
75578+#ifdef CONFIG_GRKERNSEC_ROFS
75579+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
75580+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
75581+ return -EPERM;
75582+ } else
75583+ return 0;
75584+#endif
75585+ return 0;
75586+}
75587+
75588+int
75589+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
75590+{
75591+#ifdef CONFIG_GRKERNSEC_ROFS
75592+ struct inode *inode = dentry->d_inode;
75593+
75594+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
75595+ inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
75596+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
75597+ return -EPERM;
75598+ } else
75599+ return 0;
75600+#endif
75601+ return 0;
75602+}
75603diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
75604new file mode 100644
75605index 0000000..6ee9d50
75606--- /dev/null
75607+++ b/grsecurity/grsec_pax.c
75608@@ -0,0 +1,45 @@
75609+#include <linux/kernel.h>
75610+#include <linux/sched.h>
75611+#include <linux/mm.h>
75612+#include <linux/file.h>
75613+#include <linux/grinternal.h>
75614+#include <linux/grsecurity.h>
75615+
75616+void
75617+gr_log_textrel(struct vm_area_struct * vma)
75618+{
75619+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75620+ if (grsec_enable_log_rwxmaps)
75621+ gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
75622+#endif
75623+ return;
75624+}
75625+
75626+void gr_log_ptgnustack(struct file *file)
75627+{
75628+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75629+ if (grsec_enable_log_rwxmaps)
75630+ gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
75631+#endif
75632+ return;
75633+}
75634+
75635+void
75636+gr_log_rwxmmap(struct file *file)
75637+{
75638+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75639+ if (grsec_enable_log_rwxmaps)
75640+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
75641+#endif
75642+ return;
75643+}
75644+
75645+void
75646+gr_log_rwxmprotect(struct vm_area_struct *vma)
75647+{
75648+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75649+ if (grsec_enable_log_rwxmaps)
75650+ gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
75651+#endif
75652+ return;
75653+}
75654diff --git a/grsecurity/grsec_proc.c b/grsecurity/grsec_proc.c
75655new file mode 100644
75656index 0000000..2005a3a
75657--- /dev/null
75658+++ b/grsecurity/grsec_proc.c
75659@@ -0,0 +1,20 @@
75660+#include <linux/kernel.h>
75661+#include <linux/sched.h>
75662+#include <linux/grsecurity.h>
75663+#include <linux/grinternal.h>
75664+
75665+int gr_proc_is_restricted(void)
75666+{
75667+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75668+ const struct cred *cred = current_cred();
75669+#endif
75670+
75671+#ifdef CONFIG_GRKERNSEC_PROC_USER
75672+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
75673+ return -EACCES;
75674+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75675+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
75676+ return -EACCES;
75677+#endif
75678+ return 0;
75679+}
75680diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
75681new file mode 100644
75682index 0000000..f7f29aa
75683--- /dev/null
75684+++ b/grsecurity/grsec_ptrace.c
75685@@ -0,0 +1,30 @@
75686+#include <linux/kernel.h>
75687+#include <linux/sched.h>
75688+#include <linux/grinternal.h>
75689+#include <linux/security.h>
75690+
75691+void
75692+gr_audit_ptrace(struct task_struct *task)
75693+{
75694+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
75695+ if (grsec_enable_audit_ptrace)
75696+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
75697+#endif
75698+ return;
75699+}
75700+
75701+int
75702+gr_ptrace_readexec(struct file *file, int unsafe_flags)
75703+{
75704+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
75705+ const struct dentry *dentry = file->f_path.dentry;
75706+ const struct vfsmount *mnt = file->f_path.mnt;
75707+
75708+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
75709+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
75710+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
75711+ return -EACCES;
75712+ }
75713+#endif
75714+ return 0;
75715+}
75716diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
75717new file mode 100644
75718index 0000000..3860c7e
75719--- /dev/null
75720+++ b/grsecurity/grsec_sig.c
75721@@ -0,0 +1,236 @@
75722+#include <linux/kernel.h>
75723+#include <linux/sched.h>
75724+#include <linux/fs.h>
75725+#include <linux/delay.h>
75726+#include <linux/grsecurity.h>
75727+#include <linux/grinternal.h>
75728+#include <linux/hardirq.h>
75729+
75730+char *signames[] = {
75731+ [SIGSEGV] = "Segmentation fault",
75732+ [SIGILL] = "Illegal instruction",
75733+ [SIGABRT] = "Abort",
75734+ [SIGBUS] = "Invalid alignment/Bus error"
75735+};
75736+
75737+void
75738+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
75739+{
75740+#ifdef CONFIG_GRKERNSEC_SIGNAL
75741+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
75742+ (sig == SIGABRT) || (sig == SIGBUS))) {
75743+ if (task_pid_nr(t) == task_pid_nr(current)) {
75744+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
75745+ } else {
75746+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
75747+ }
75748+ }
75749+#endif
75750+ return;
75751+}
75752+
75753+int
75754+gr_handle_signal(const struct task_struct *p, const int sig)
75755+{
75756+#ifdef CONFIG_GRKERNSEC
75757+ /* ignore the 0 signal for protected task checks */
75758+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
75759+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
75760+ return -EPERM;
75761+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
75762+ return -EPERM;
75763+ }
75764+#endif
75765+ return 0;
75766+}
75767+
75768+#ifdef CONFIG_GRKERNSEC
75769+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
75770+
75771+int gr_fake_force_sig(int sig, struct task_struct *t)
75772+{
75773+ unsigned long int flags;
75774+ int ret, blocked, ignored;
75775+ struct k_sigaction *action;
75776+
75777+ spin_lock_irqsave(&t->sighand->siglock, flags);
75778+ action = &t->sighand->action[sig-1];
75779+ ignored = action->sa.sa_handler == SIG_IGN;
75780+ blocked = sigismember(&t->blocked, sig);
75781+ if (blocked || ignored) {
75782+ action->sa.sa_handler = SIG_DFL;
75783+ if (blocked) {
75784+ sigdelset(&t->blocked, sig);
75785+ recalc_sigpending_and_wake(t);
75786+ }
75787+ }
75788+ if (action->sa.sa_handler == SIG_DFL)
75789+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
75790+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
75791+
75792+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
75793+
75794+ return ret;
75795+}
75796+#endif
75797+
75798+#define GR_USER_BAN_TIME (15 * 60)
75799+#define GR_DAEMON_BRUTE_TIME (30 * 60)
75800+
75801+void gr_handle_brute_attach(int dumpable)
75802+{
75803+#ifdef CONFIG_GRKERNSEC_BRUTE
75804+ struct task_struct *p = current;
75805+ kuid_t uid = GLOBAL_ROOT_UID;
75806+ int daemon = 0;
75807+
75808+ if (!grsec_enable_brute)
75809+ return;
75810+
75811+ rcu_read_lock();
75812+ read_lock(&tasklist_lock);
75813+ read_lock(&grsec_exec_file_lock);
75814+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
75815+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
75816+ p->real_parent->brute = 1;
75817+ daemon = 1;
75818+ } else {
75819+ const struct cred *cred = __task_cred(p), *cred2;
75820+ struct task_struct *tsk, *tsk2;
75821+
75822+ if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
75823+ struct user_struct *user;
75824+
75825+ uid = cred->uid;
75826+
75827+ /* this is put upon execution past expiration */
75828+ user = find_user(uid);
75829+ if (user == NULL)
75830+ goto unlock;
75831+ user->suid_banned = 1;
75832+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
75833+ if (user->suid_ban_expires == ~0UL)
75834+ user->suid_ban_expires--;
75835+
75836+ /* only kill other threads of the same binary, from the same user */
75837+ do_each_thread(tsk2, tsk) {
75838+ cred2 = __task_cred(tsk);
75839+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
75840+ gr_fake_force_sig(SIGKILL, tsk);
75841+ } while_each_thread(tsk2, tsk);
75842+ }
75843+ }
75844+unlock:
75845+ read_unlock(&grsec_exec_file_lock);
75846+ read_unlock(&tasklist_lock);
75847+ rcu_read_unlock();
75848+
75849+ if (gr_is_global_nonroot(uid))
75850+ 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);
75851+ else if (daemon)
75852+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
75853+
75854+#endif
75855+ return;
75856+}
75857+
75858+void gr_handle_brute_check(void)
75859+{
75860+#ifdef CONFIG_GRKERNSEC_BRUTE
75861+ struct task_struct *p = current;
75862+
75863+ if (unlikely(p->brute)) {
75864+ if (!grsec_enable_brute)
75865+ p->brute = 0;
75866+ else if (time_before(get_seconds(), p->brute_expires))
75867+ msleep(30 * 1000);
75868+ }
75869+#endif
75870+ return;
75871+}
75872+
75873+void gr_handle_kernel_exploit(void)
75874+{
75875+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75876+ const struct cred *cred;
75877+ struct task_struct *tsk, *tsk2;
75878+ struct user_struct *user;
75879+ kuid_t uid;
75880+
75881+ if (in_irq() || in_serving_softirq() || in_nmi())
75882+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
75883+
75884+ uid = current_uid();
75885+
75886+ if (gr_is_global_root(uid))
75887+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
75888+ else {
75889+ /* kill all the processes of this user, hold a reference
75890+ to their creds struct, and prevent them from creating
75891+ another process until system reset
75892+ */
75893+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
75894+ GR_GLOBAL_UID(uid));
75895+ /* we intentionally leak this ref */
75896+ user = get_uid(current->cred->user);
75897+ if (user)
75898+ user->kernel_banned = 1;
75899+
75900+ /* kill all processes of this user */
75901+ read_lock(&tasklist_lock);
75902+ do_each_thread(tsk2, tsk) {
75903+ cred = __task_cred(tsk);
75904+ if (uid_eq(cred->uid, uid))
75905+ gr_fake_force_sig(SIGKILL, tsk);
75906+ } while_each_thread(tsk2, tsk);
75907+ read_unlock(&tasklist_lock);
75908+ }
75909+#endif
75910+}
75911+
75912+#ifdef CONFIG_GRKERNSEC_BRUTE
75913+static bool suid_ban_expired(struct user_struct *user)
75914+{
75915+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
75916+ user->suid_banned = 0;
75917+ user->suid_ban_expires = 0;
75918+ free_uid(user);
75919+ return true;
75920+ }
75921+
75922+ return false;
75923+}
75924+#endif
75925+
75926+int gr_process_kernel_exec_ban(void)
75927+{
75928+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75929+ if (unlikely(current->cred->user->kernel_banned))
75930+ return -EPERM;
75931+#endif
75932+ return 0;
75933+}
75934+
75935+int gr_process_kernel_setuid_ban(struct user_struct *user)
75936+{
75937+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75938+ if (unlikely(user->kernel_banned))
75939+ gr_fake_force_sig(SIGKILL, current);
75940+#endif
75941+ return 0;
75942+}
75943+
75944+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
75945+{
75946+#ifdef CONFIG_GRKERNSEC_BRUTE
75947+ struct user_struct *user = current->cred->user;
75948+ if (unlikely(user->suid_banned)) {
75949+ if (suid_ban_expired(user))
75950+ return 0;
75951+ /* disallow execution of suid binaries only */
75952+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
75953+ return -EPERM;
75954+ }
75955+#endif
75956+ return 0;
75957+}
75958diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
75959new file mode 100644
75960index 0000000..c0aef3a
75961--- /dev/null
75962+++ b/grsecurity/grsec_sock.c
75963@@ -0,0 +1,244 @@
75964+#include <linux/kernel.h>
75965+#include <linux/module.h>
75966+#include <linux/sched.h>
75967+#include <linux/file.h>
75968+#include <linux/net.h>
75969+#include <linux/in.h>
75970+#include <linux/ip.h>
75971+#include <net/sock.h>
75972+#include <net/inet_sock.h>
75973+#include <linux/grsecurity.h>
75974+#include <linux/grinternal.h>
75975+#include <linux/gracl.h>
75976+
75977+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
75978+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
75979+
75980+EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
75981+EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
75982+
75983+#ifdef CONFIG_UNIX_MODULE
75984+EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
75985+EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
75986+EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
75987+EXPORT_SYMBOL_GPL(gr_handle_create);
75988+#endif
75989+
75990+#ifdef CONFIG_GRKERNSEC
75991+#define gr_conn_table_size 32749
75992+struct conn_table_entry {
75993+ struct conn_table_entry *next;
75994+ struct signal_struct *sig;
75995+};
75996+
75997+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
75998+DEFINE_SPINLOCK(gr_conn_table_lock);
75999+
76000+extern const char * gr_socktype_to_name(unsigned char type);
76001+extern const char * gr_proto_to_name(unsigned char proto);
76002+extern const char * gr_sockfamily_to_name(unsigned char family);
76003+
76004+static __inline__ int
76005+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
76006+{
76007+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
76008+}
76009+
76010+static __inline__ int
76011+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
76012+ __u16 sport, __u16 dport)
76013+{
76014+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
76015+ sig->gr_sport == sport && sig->gr_dport == dport))
76016+ return 1;
76017+ else
76018+ return 0;
76019+}
76020+
76021+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
76022+{
76023+ struct conn_table_entry **match;
76024+ unsigned int index;
76025+
76026+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
76027+ sig->gr_sport, sig->gr_dport,
76028+ gr_conn_table_size);
76029+
76030+ newent->sig = sig;
76031+
76032+ match = &gr_conn_table[index];
76033+ newent->next = *match;
76034+ *match = newent;
76035+
76036+ return;
76037+}
76038+
76039+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
76040+{
76041+ struct conn_table_entry *match, *last = NULL;
76042+ unsigned int index;
76043+
76044+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
76045+ sig->gr_sport, sig->gr_dport,
76046+ gr_conn_table_size);
76047+
76048+ match = gr_conn_table[index];
76049+ while (match && !conn_match(match->sig,
76050+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
76051+ sig->gr_dport)) {
76052+ last = match;
76053+ match = match->next;
76054+ }
76055+
76056+ if (match) {
76057+ if (last)
76058+ last->next = match->next;
76059+ else
76060+ gr_conn_table[index] = NULL;
76061+ kfree(match);
76062+ }
76063+
76064+ return;
76065+}
76066+
76067+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
76068+ __u16 sport, __u16 dport)
76069+{
76070+ struct conn_table_entry *match;
76071+ unsigned int index;
76072+
76073+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
76074+
76075+ match = gr_conn_table[index];
76076+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
76077+ match = match->next;
76078+
76079+ if (match)
76080+ return match->sig;
76081+ else
76082+ return NULL;
76083+}
76084+
76085+#endif
76086+
76087+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
76088+{
76089+#ifdef CONFIG_GRKERNSEC
76090+ struct signal_struct *sig = task->signal;
76091+ struct conn_table_entry *newent;
76092+
76093+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
76094+ if (newent == NULL)
76095+ return;
76096+ /* no bh lock needed since we are called with bh disabled */
76097+ spin_lock(&gr_conn_table_lock);
76098+ gr_del_task_from_ip_table_nolock(sig);
76099+ sig->gr_saddr = inet->inet_rcv_saddr;
76100+ sig->gr_daddr = inet->inet_daddr;
76101+ sig->gr_sport = inet->inet_sport;
76102+ sig->gr_dport = inet->inet_dport;
76103+ gr_add_to_task_ip_table_nolock(sig, newent);
76104+ spin_unlock(&gr_conn_table_lock);
76105+#endif
76106+ return;
76107+}
76108+
76109+void gr_del_task_from_ip_table(struct task_struct *task)
76110+{
76111+#ifdef CONFIG_GRKERNSEC
76112+ spin_lock_bh(&gr_conn_table_lock);
76113+ gr_del_task_from_ip_table_nolock(task->signal);
76114+ spin_unlock_bh(&gr_conn_table_lock);
76115+#endif
76116+ return;
76117+}
76118+
76119+void
76120+gr_attach_curr_ip(const struct sock *sk)
76121+{
76122+#ifdef CONFIG_GRKERNSEC
76123+ struct signal_struct *p, *set;
76124+ const struct inet_sock *inet = inet_sk(sk);
76125+
76126+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
76127+ return;
76128+
76129+ set = current->signal;
76130+
76131+ spin_lock_bh(&gr_conn_table_lock);
76132+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
76133+ inet->inet_dport, inet->inet_sport);
76134+ if (unlikely(p != NULL)) {
76135+ set->curr_ip = p->curr_ip;
76136+ set->used_accept = 1;
76137+ gr_del_task_from_ip_table_nolock(p);
76138+ spin_unlock_bh(&gr_conn_table_lock);
76139+ return;
76140+ }
76141+ spin_unlock_bh(&gr_conn_table_lock);
76142+
76143+ set->curr_ip = inet->inet_daddr;
76144+ set->used_accept = 1;
76145+#endif
76146+ return;
76147+}
76148+
76149+int
76150+gr_handle_sock_all(const int family, const int type, const int protocol)
76151+{
76152+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
76153+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
76154+ (family != AF_UNIX)) {
76155+ if (family == AF_INET)
76156+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
76157+ else
76158+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
76159+ return -EACCES;
76160+ }
76161+#endif
76162+ return 0;
76163+}
76164+
76165+int
76166+gr_handle_sock_server(const struct sockaddr *sck)
76167+{
76168+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
76169+ if (grsec_enable_socket_server &&
76170+ in_group_p(grsec_socket_server_gid) &&
76171+ sck && (sck->sa_family != AF_UNIX) &&
76172+ (sck->sa_family != AF_LOCAL)) {
76173+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
76174+ return -EACCES;
76175+ }
76176+#endif
76177+ return 0;
76178+}
76179+
76180+int
76181+gr_handle_sock_server_other(const struct sock *sck)
76182+{
76183+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
76184+ if (grsec_enable_socket_server &&
76185+ in_group_p(grsec_socket_server_gid) &&
76186+ sck && (sck->sk_family != AF_UNIX) &&
76187+ (sck->sk_family != AF_LOCAL)) {
76188+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
76189+ return -EACCES;
76190+ }
76191+#endif
76192+ return 0;
76193+}
76194+
76195+int
76196+gr_handle_sock_client(const struct sockaddr *sck)
76197+{
76198+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
76199+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
76200+ sck && (sck->sa_family != AF_UNIX) &&
76201+ (sck->sa_family != AF_LOCAL)) {
76202+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
76203+ return -EACCES;
76204+ }
76205+#endif
76206+ return 0;
76207+}
76208diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
76209new file mode 100644
76210index 0000000..8159888
76211--- /dev/null
76212+++ b/grsecurity/grsec_sysctl.c
76213@@ -0,0 +1,479 @@
76214+#include <linux/kernel.h>
76215+#include <linux/sched.h>
76216+#include <linux/sysctl.h>
76217+#include <linux/grsecurity.h>
76218+#include <linux/grinternal.h>
76219+
76220+int
76221+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
76222+{
76223+#ifdef CONFIG_GRKERNSEC_SYSCTL
76224+ if (dirname == NULL || name == NULL)
76225+ return 0;
76226+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
76227+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
76228+ return -EACCES;
76229+ }
76230+#endif
76231+ return 0;
76232+}
76233+
76234+#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
76235+static int __maybe_unused __read_only one = 1;
76236+#endif
76237+
76238+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
76239+ defined(CONFIG_GRKERNSEC_DENYUSB)
76240+struct ctl_table grsecurity_table[] = {
76241+#ifdef CONFIG_GRKERNSEC_SYSCTL
76242+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
76243+#ifdef CONFIG_GRKERNSEC_IO
76244+ {
76245+ .procname = "disable_priv_io",
76246+ .data = &grsec_disable_privio,
76247+ .maxlen = sizeof(int),
76248+ .mode = 0600,
76249+ .proc_handler = &proc_dointvec,
76250+ },
76251+#endif
76252+#endif
76253+#ifdef CONFIG_GRKERNSEC_LINK
76254+ {
76255+ .procname = "linking_restrictions",
76256+ .data = &grsec_enable_link,
76257+ .maxlen = sizeof(int),
76258+ .mode = 0600,
76259+ .proc_handler = &proc_dointvec,
76260+ },
76261+#endif
76262+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
76263+ {
76264+ .procname = "enforce_symlinksifowner",
76265+ .data = &grsec_enable_symlinkown,
76266+ .maxlen = sizeof(int),
76267+ .mode = 0600,
76268+ .proc_handler = &proc_dointvec,
76269+ },
76270+ {
76271+ .procname = "symlinkown_gid",
76272+ .data = &grsec_symlinkown_gid,
76273+ .maxlen = sizeof(int),
76274+ .mode = 0600,
76275+ .proc_handler = &proc_dointvec,
76276+ },
76277+#endif
76278+#ifdef CONFIG_GRKERNSEC_BRUTE
76279+ {
76280+ .procname = "deter_bruteforce",
76281+ .data = &grsec_enable_brute,
76282+ .maxlen = sizeof(int),
76283+ .mode = 0600,
76284+ .proc_handler = &proc_dointvec,
76285+ },
76286+#endif
76287+#ifdef CONFIG_GRKERNSEC_FIFO
76288+ {
76289+ .procname = "fifo_restrictions",
76290+ .data = &grsec_enable_fifo,
76291+ .maxlen = sizeof(int),
76292+ .mode = 0600,
76293+ .proc_handler = &proc_dointvec,
76294+ },
76295+#endif
76296+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
76297+ {
76298+ .procname = "ptrace_readexec",
76299+ .data = &grsec_enable_ptrace_readexec,
76300+ .maxlen = sizeof(int),
76301+ .mode = 0600,
76302+ .proc_handler = &proc_dointvec,
76303+ },
76304+#endif
76305+#ifdef CONFIG_GRKERNSEC_SETXID
76306+ {
76307+ .procname = "consistent_setxid",
76308+ .data = &grsec_enable_setxid,
76309+ .maxlen = sizeof(int),
76310+ .mode = 0600,
76311+ .proc_handler = &proc_dointvec,
76312+ },
76313+#endif
76314+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76315+ {
76316+ .procname = "ip_blackhole",
76317+ .data = &grsec_enable_blackhole,
76318+ .maxlen = sizeof(int),
76319+ .mode = 0600,
76320+ .proc_handler = &proc_dointvec,
76321+ },
76322+ {
76323+ .procname = "lastack_retries",
76324+ .data = &grsec_lastack_retries,
76325+ .maxlen = sizeof(int),
76326+ .mode = 0600,
76327+ .proc_handler = &proc_dointvec,
76328+ },
76329+#endif
76330+#ifdef CONFIG_GRKERNSEC_EXECLOG
76331+ {
76332+ .procname = "exec_logging",
76333+ .data = &grsec_enable_execlog,
76334+ .maxlen = sizeof(int),
76335+ .mode = 0600,
76336+ .proc_handler = &proc_dointvec,
76337+ },
76338+#endif
76339+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
76340+ {
76341+ .procname = "rwxmap_logging",
76342+ .data = &grsec_enable_log_rwxmaps,
76343+ .maxlen = sizeof(int),
76344+ .mode = 0600,
76345+ .proc_handler = &proc_dointvec,
76346+ },
76347+#endif
76348+#ifdef CONFIG_GRKERNSEC_SIGNAL
76349+ {
76350+ .procname = "signal_logging",
76351+ .data = &grsec_enable_signal,
76352+ .maxlen = sizeof(int),
76353+ .mode = 0600,
76354+ .proc_handler = &proc_dointvec,
76355+ },
76356+#endif
76357+#ifdef CONFIG_GRKERNSEC_FORKFAIL
76358+ {
76359+ .procname = "forkfail_logging",
76360+ .data = &grsec_enable_forkfail,
76361+ .maxlen = sizeof(int),
76362+ .mode = 0600,
76363+ .proc_handler = &proc_dointvec,
76364+ },
76365+#endif
76366+#ifdef CONFIG_GRKERNSEC_TIME
76367+ {
76368+ .procname = "timechange_logging",
76369+ .data = &grsec_enable_time,
76370+ .maxlen = sizeof(int),
76371+ .mode = 0600,
76372+ .proc_handler = &proc_dointvec,
76373+ },
76374+#endif
76375+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
76376+ {
76377+ .procname = "chroot_deny_shmat",
76378+ .data = &grsec_enable_chroot_shmat,
76379+ .maxlen = sizeof(int),
76380+ .mode = 0600,
76381+ .proc_handler = &proc_dointvec,
76382+ },
76383+#endif
76384+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
76385+ {
76386+ .procname = "chroot_deny_unix",
76387+ .data = &grsec_enable_chroot_unix,
76388+ .maxlen = sizeof(int),
76389+ .mode = 0600,
76390+ .proc_handler = &proc_dointvec,
76391+ },
76392+#endif
76393+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
76394+ {
76395+ .procname = "chroot_deny_mount",
76396+ .data = &grsec_enable_chroot_mount,
76397+ .maxlen = sizeof(int),
76398+ .mode = 0600,
76399+ .proc_handler = &proc_dointvec,
76400+ },
76401+#endif
76402+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
76403+ {
76404+ .procname = "chroot_deny_fchdir",
76405+ .data = &grsec_enable_chroot_fchdir,
76406+ .maxlen = sizeof(int),
76407+ .mode = 0600,
76408+ .proc_handler = &proc_dointvec,
76409+ },
76410+#endif
76411+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
76412+ {
76413+ .procname = "chroot_deny_chroot",
76414+ .data = &grsec_enable_chroot_double,
76415+ .maxlen = sizeof(int),
76416+ .mode = 0600,
76417+ .proc_handler = &proc_dointvec,
76418+ },
76419+#endif
76420+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
76421+ {
76422+ .procname = "chroot_deny_pivot",
76423+ .data = &grsec_enable_chroot_pivot,
76424+ .maxlen = sizeof(int),
76425+ .mode = 0600,
76426+ .proc_handler = &proc_dointvec,
76427+ },
76428+#endif
76429+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
76430+ {
76431+ .procname = "chroot_enforce_chdir",
76432+ .data = &grsec_enable_chroot_chdir,
76433+ .maxlen = sizeof(int),
76434+ .mode = 0600,
76435+ .proc_handler = &proc_dointvec,
76436+ },
76437+#endif
76438+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
76439+ {
76440+ .procname = "chroot_deny_chmod",
76441+ .data = &grsec_enable_chroot_chmod,
76442+ .maxlen = sizeof(int),
76443+ .mode = 0600,
76444+ .proc_handler = &proc_dointvec,
76445+ },
76446+#endif
76447+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
76448+ {
76449+ .procname = "chroot_deny_mknod",
76450+ .data = &grsec_enable_chroot_mknod,
76451+ .maxlen = sizeof(int),
76452+ .mode = 0600,
76453+ .proc_handler = &proc_dointvec,
76454+ },
76455+#endif
76456+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
76457+ {
76458+ .procname = "chroot_restrict_nice",
76459+ .data = &grsec_enable_chroot_nice,
76460+ .maxlen = sizeof(int),
76461+ .mode = 0600,
76462+ .proc_handler = &proc_dointvec,
76463+ },
76464+#endif
76465+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
76466+ {
76467+ .procname = "chroot_execlog",
76468+ .data = &grsec_enable_chroot_execlog,
76469+ .maxlen = sizeof(int),
76470+ .mode = 0600,
76471+ .proc_handler = &proc_dointvec,
76472+ },
76473+#endif
76474+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76475+ {
76476+ .procname = "chroot_caps",
76477+ .data = &grsec_enable_chroot_caps,
76478+ .maxlen = sizeof(int),
76479+ .mode = 0600,
76480+ .proc_handler = &proc_dointvec,
76481+ },
76482+#endif
76483+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
76484+ {
76485+ .procname = "chroot_deny_sysctl",
76486+ .data = &grsec_enable_chroot_sysctl,
76487+ .maxlen = sizeof(int),
76488+ .mode = 0600,
76489+ .proc_handler = &proc_dointvec,
76490+ },
76491+#endif
76492+#ifdef CONFIG_GRKERNSEC_TPE
76493+ {
76494+ .procname = "tpe",
76495+ .data = &grsec_enable_tpe,
76496+ .maxlen = sizeof(int),
76497+ .mode = 0600,
76498+ .proc_handler = &proc_dointvec,
76499+ },
76500+ {
76501+ .procname = "tpe_gid",
76502+ .data = &grsec_tpe_gid,
76503+ .maxlen = sizeof(int),
76504+ .mode = 0600,
76505+ .proc_handler = &proc_dointvec,
76506+ },
76507+#endif
76508+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
76509+ {
76510+ .procname = "tpe_invert",
76511+ .data = &grsec_enable_tpe_invert,
76512+ .maxlen = sizeof(int),
76513+ .mode = 0600,
76514+ .proc_handler = &proc_dointvec,
76515+ },
76516+#endif
76517+#ifdef CONFIG_GRKERNSEC_TPE_ALL
76518+ {
76519+ .procname = "tpe_restrict_all",
76520+ .data = &grsec_enable_tpe_all,
76521+ .maxlen = sizeof(int),
76522+ .mode = 0600,
76523+ .proc_handler = &proc_dointvec,
76524+ },
76525+#endif
76526+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
76527+ {
76528+ .procname = "socket_all",
76529+ .data = &grsec_enable_socket_all,
76530+ .maxlen = sizeof(int),
76531+ .mode = 0600,
76532+ .proc_handler = &proc_dointvec,
76533+ },
76534+ {
76535+ .procname = "socket_all_gid",
76536+ .data = &grsec_socket_all_gid,
76537+ .maxlen = sizeof(int),
76538+ .mode = 0600,
76539+ .proc_handler = &proc_dointvec,
76540+ },
76541+#endif
76542+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
76543+ {
76544+ .procname = "socket_client",
76545+ .data = &grsec_enable_socket_client,
76546+ .maxlen = sizeof(int),
76547+ .mode = 0600,
76548+ .proc_handler = &proc_dointvec,
76549+ },
76550+ {
76551+ .procname = "socket_client_gid",
76552+ .data = &grsec_socket_client_gid,
76553+ .maxlen = sizeof(int),
76554+ .mode = 0600,
76555+ .proc_handler = &proc_dointvec,
76556+ },
76557+#endif
76558+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
76559+ {
76560+ .procname = "socket_server",
76561+ .data = &grsec_enable_socket_server,
76562+ .maxlen = sizeof(int),
76563+ .mode = 0600,
76564+ .proc_handler = &proc_dointvec,
76565+ },
76566+ {
76567+ .procname = "socket_server_gid",
76568+ .data = &grsec_socket_server_gid,
76569+ .maxlen = sizeof(int),
76570+ .mode = 0600,
76571+ .proc_handler = &proc_dointvec,
76572+ },
76573+#endif
76574+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
76575+ {
76576+ .procname = "audit_group",
76577+ .data = &grsec_enable_group,
76578+ .maxlen = sizeof(int),
76579+ .mode = 0600,
76580+ .proc_handler = &proc_dointvec,
76581+ },
76582+ {
76583+ .procname = "audit_gid",
76584+ .data = &grsec_audit_gid,
76585+ .maxlen = sizeof(int),
76586+ .mode = 0600,
76587+ .proc_handler = &proc_dointvec,
76588+ },
76589+#endif
76590+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
76591+ {
76592+ .procname = "audit_chdir",
76593+ .data = &grsec_enable_chdir,
76594+ .maxlen = sizeof(int),
76595+ .mode = 0600,
76596+ .proc_handler = &proc_dointvec,
76597+ },
76598+#endif
76599+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
76600+ {
76601+ .procname = "audit_mount",
76602+ .data = &grsec_enable_mount,
76603+ .maxlen = sizeof(int),
76604+ .mode = 0600,
76605+ .proc_handler = &proc_dointvec,
76606+ },
76607+#endif
76608+#ifdef CONFIG_GRKERNSEC_DMESG
76609+ {
76610+ .procname = "dmesg",
76611+ .data = &grsec_enable_dmesg,
76612+ .maxlen = sizeof(int),
76613+ .mode = 0600,
76614+ .proc_handler = &proc_dointvec,
76615+ },
76616+#endif
76617+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76618+ {
76619+ .procname = "chroot_findtask",
76620+ .data = &grsec_enable_chroot_findtask,
76621+ .maxlen = sizeof(int),
76622+ .mode = 0600,
76623+ .proc_handler = &proc_dointvec,
76624+ },
76625+#endif
76626+#ifdef CONFIG_GRKERNSEC_RESLOG
76627+ {
76628+ .procname = "resource_logging",
76629+ .data = &grsec_resource_logging,
76630+ .maxlen = sizeof(int),
76631+ .mode = 0600,
76632+ .proc_handler = &proc_dointvec,
76633+ },
76634+#endif
76635+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
76636+ {
76637+ .procname = "audit_ptrace",
76638+ .data = &grsec_enable_audit_ptrace,
76639+ .maxlen = sizeof(int),
76640+ .mode = 0600,
76641+ .proc_handler = &proc_dointvec,
76642+ },
76643+#endif
76644+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
76645+ {
76646+ .procname = "harden_ptrace",
76647+ .data = &grsec_enable_harden_ptrace,
76648+ .maxlen = sizeof(int),
76649+ .mode = 0600,
76650+ .proc_handler = &proc_dointvec,
76651+ },
76652+#endif
76653+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
76654+ {
76655+ .procname = "harden_ipc",
76656+ .data = &grsec_enable_harden_ipc,
76657+ .maxlen = sizeof(int),
76658+ .mode = 0600,
76659+ .proc_handler = &proc_dointvec,
76660+ },
76661+#endif
76662+ {
76663+ .procname = "grsec_lock",
76664+ .data = &grsec_lock,
76665+ .maxlen = sizeof(int),
76666+ .mode = 0600,
76667+ .proc_handler = &proc_dointvec,
76668+ },
76669+#endif
76670+#ifdef CONFIG_GRKERNSEC_ROFS
76671+ {
76672+ .procname = "romount_protect",
76673+ .data = &grsec_enable_rofs,
76674+ .maxlen = sizeof(int),
76675+ .mode = 0600,
76676+ .proc_handler = &proc_dointvec_minmax,
76677+ .extra1 = &one,
76678+ .extra2 = &one,
76679+ },
76680+#endif
76681+#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
76682+ {
76683+ .procname = "deny_new_usb",
76684+ .data = &grsec_deny_new_usb,
76685+ .maxlen = sizeof(int),
76686+ .mode = 0600,
76687+ .proc_handler = &proc_dointvec,
76688+ },
76689+#endif
76690+ { }
76691+};
76692+#endif
76693diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
76694new file mode 100644
76695index 0000000..61b514e
76696--- /dev/null
76697+++ b/grsecurity/grsec_time.c
76698@@ -0,0 +1,16 @@
76699+#include <linux/kernel.h>
76700+#include <linux/sched.h>
76701+#include <linux/grinternal.h>
76702+#include <linux/module.h>
76703+
76704+void
76705+gr_log_timechange(void)
76706+{
76707+#ifdef CONFIG_GRKERNSEC_TIME
76708+ if (grsec_enable_time)
76709+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
76710+#endif
76711+ return;
76712+}
76713+
76714+EXPORT_SYMBOL_GPL(gr_log_timechange);
76715diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
76716new file mode 100644
76717index 0000000..ee57dcf
76718--- /dev/null
76719+++ b/grsecurity/grsec_tpe.c
76720@@ -0,0 +1,73 @@
76721+#include <linux/kernel.h>
76722+#include <linux/sched.h>
76723+#include <linux/file.h>
76724+#include <linux/fs.h>
76725+#include <linux/grinternal.h>
76726+
76727+extern int gr_acl_tpe_check(void);
76728+
76729+int
76730+gr_tpe_allow(const struct file *file)
76731+{
76732+#ifdef CONFIG_GRKERNSEC
76733+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
76734+ const struct cred *cred = current_cred();
76735+ char *msg = NULL;
76736+ char *msg2 = NULL;
76737+
76738+ // never restrict root
76739+ if (gr_is_global_root(cred->uid))
76740+ return 1;
76741+
76742+ if (grsec_enable_tpe) {
76743+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
76744+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
76745+ msg = "not being in trusted group";
76746+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
76747+ msg = "being in untrusted group";
76748+#else
76749+ if (in_group_p(grsec_tpe_gid))
76750+ msg = "being in untrusted group";
76751+#endif
76752+ }
76753+ if (!msg && gr_acl_tpe_check())
76754+ msg = "being in untrusted role";
76755+
76756+ // not in any affected group/role
76757+ if (!msg)
76758+ goto next_check;
76759+
76760+ if (gr_is_global_nonroot(inode->i_uid))
76761+ msg2 = "file in non-root-owned directory";
76762+ else if (inode->i_mode & S_IWOTH)
76763+ msg2 = "file in world-writable directory";
76764+ else if (inode->i_mode & S_IWGRP)
76765+ msg2 = "file in group-writable directory";
76766+
76767+ if (msg && msg2) {
76768+ char fullmsg[70] = {0};
76769+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
76770+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
76771+ return 0;
76772+ }
76773+ msg = NULL;
76774+next_check:
76775+#ifdef CONFIG_GRKERNSEC_TPE_ALL
76776+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
76777+ return 1;
76778+
76779+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
76780+ msg = "directory not owned by user";
76781+ else if (inode->i_mode & S_IWOTH)
76782+ msg = "file in world-writable directory";
76783+ else if (inode->i_mode & S_IWGRP)
76784+ msg = "file in group-writable directory";
76785+
76786+ if (msg) {
76787+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
76788+ return 0;
76789+ }
76790+#endif
76791+#endif
76792+ return 1;
76793+}
76794diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
76795new file mode 100644
76796index 0000000..ae02d8e
76797--- /dev/null
76798+++ b/grsecurity/grsec_usb.c
76799@@ -0,0 +1,15 @@
76800+#include <linux/kernel.h>
76801+#include <linux/grinternal.h>
76802+#include <linux/module.h>
76803+
76804+int gr_handle_new_usb(void)
76805+{
76806+#ifdef CONFIG_GRKERNSEC_DENYUSB
76807+ if (grsec_deny_new_usb) {
76808+ printk(KERN_ALERT "grsec: denied insert of new USB device\n");
76809+ return 1;
76810+ }
76811+#endif
76812+ return 0;
76813+}
76814+EXPORT_SYMBOL_GPL(gr_handle_new_usb);
76815diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
76816new file mode 100644
76817index 0000000..9f7b1ac
76818--- /dev/null
76819+++ b/grsecurity/grsum.c
76820@@ -0,0 +1,61 @@
76821+#include <linux/err.h>
76822+#include <linux/kernel.h>
76823+#include <linux/sched.h>
76824+#include <linux/mm.h>
76825+#include <linux/scatterlist.h>
76826+#include <linux/crypto.h>
76827+#include <linux/gracl.h>
76828+
76829+
76830+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
76831+#error "crypto and sha256 must be built into the kernel"
76832+#endif
76833+
76834+int
76835+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
76836+{
76837+ char *p;
76838+ struct crypto_hash *tfm;
76839+ struct hash_desc desc;
76840+ struct scatterlist sg;
76841+ unsigned char temp_sum[GR_SHA_LEN];
76842+ volatile int retval = 0;
76843+ volatile int dummy = 0;
76844+ unsigned int i;
76845+
76846+ sg_init_table(&sg, 1);
76847+
76848+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
76849+ if (IS_ERR(tfm)) {
76850+ /* should never happen, since sha256 should be built in */
76851+ return 1;
76852+ }
76853+
76854+ desc.tfm = tfm;
76855+ desc.flags = 0;
76856+
76857+ crypto_hash_init(&desc);
76858+
76859+ p = salt;
76860+ sg_set_buf(&sg, p, GR_SALT_LEN);
76861+ crypto_hash_update(&desc, &sg, sg.length);
76862+
76863+ p = entry->pw;
76864+ sg_set_buf(&sg, p, strlen(p));
76865+
76866+ crypto_hash_update(&desc, &sg, sg.length);
76867+
76868+ crypto_hash_final(&desc, temp_sum);
76869+
76870+ memset(entry->pw, 0, GR_PW_LEN);
76871+
76872+ for (i = 0; i < GR_SHA_LEN; i++)
76873+ if (sum[i] != temp_sum[i])
76874+ retval = 1;
76875+ else
76876+ dummy = 1; // waste a cycle
76877+
76878+ crypto_free_hash(tfm);
76879+
76880+ return retval;
76881+}
76882diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
76883index 77ff547..181834f 100644
76884--- a/include/asm-generic/4level-fixup.h
76885+++ b/include/asm-generic/4level-fixup.h
76886@@ -13,8 +13,10 @@
76887 #define pmd_alloc(mm, pud, address) \
76888 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
76889 NULL: pmd_offset(pud, address))
76890+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
76891
76892 #define pud_alloc(mm, pgd, address) (pgd)
76893+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
76894 #define pud_offset(pgd, start) (pgd)
76895 #define pud_none(pud) 0
76896 #define pud_bad(pud) 0
76897diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
76898index b7babf0..97f4c4f 100644
76899--- a/include/asm-generic/atomic-long.h
76900+++ b/include/asm-generic/atomic-long.h
76901@@ -22,6 +22,12 @@
76902
76903 typedef atomic64_t atomic_long_t;
76904
76905+#ifdef CONFIG_PAX_REFCOUNT
76906+typedef atomic64_unchecked_t atomic_long_unchecked_t;
76907+#else
76908+typedef atomic64_t atomic_long_unchecked_t;
76909+#endif
76910+
76911 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
76912
76913 static inline long atomic_long_read(atomic_long_t *l)
76914@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
76915 return (long)atomic64_read(v);
76916 }
76917
76918+#ifdef CONFIG_PAX_REFCOUNT
76919+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
76920+{
76921+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76922+
76923+ return (long)atomic64_read_unchecked(v);
76924+}
76925+#endif
76926+
76927 static inline void atomic_long_set(atomic_long_t *l, long i)
76928 {
76929 atomic64_t *v = (atomic64_t *)l;
76930@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
76931 atomic64_set(v, i);
76932 }
76933
76934+#ifdef CONFIG_PAX_REFCOUNT
76935+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
76936+{
76937+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76938+
76939+ atomic64_set_unchecked(v, i);
76940+}
76941+#endif
76942+
76943 static inline void atomic_long_inc(atomic_long_t *l)
76944 {
76945 atomic64_t *v = (atomic64_t *)l;
76946@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
76947 atomic64_inc(v);
76948 }
76949
76950+#ifdef CONFIG_PAX_REFCOUNT
76951+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
76952+{
76953+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76954+
76955+ atomic64_inc_unchecked(v);
76956+}
76957+#endif
76958+
76959 static inline void atomic_long_dec(atomic_long_t *l)
76960 {
76961 atomic64_t *v = (atomic64_t *)l;
76962@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
76963 atomic64_dec(v);
76964 }
76965
76966+#ifdef CONFIG_PAX_REFCOUNT
76967+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
76968+{
76969+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76970+
76971+ atomic64_dec_unchecked(v);
76972+}
76973+#endif
76974+
76975 static inline void atomic_long_add(long i, atomic_long_t *l)
76976 {
76977 atomic64_t *v = (atomic64_t *)l;
76978@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
76979 atomic64_add(i, v);
76980 }
76981
76982+#ifdef CONFIG_PAX_REFCOUNT
76983+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
76984+{
76985+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76986+
76987+ atomic64_add_unchecked(i, v);
76988+}
76989+#endif
76990+
76991 static inline void atomic_long_sub(long i, atomic_long_t *l)
76992 {
76993 atomic64_t *v = (atomic64_t *)l;
76994@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
76995 atomic64_sub(i, v);
76996 }
76997
76998+#ifdef CONFIG_PAX_REFCOUNT
76999+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
77000+{
77001+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77002+
77003+ atomic64_sub_unchecked(i, v);
77004+}
77005+#endif
77006+
77007 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
77008 {
77009 atomic64_t *v = (atomic64_t *)l;
77010@@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
77011 return atomic64_add_negative(i, v);
77012 }
77013
77014-static inline long atomic_long_add_return(long i, atomic_long_t *l)
77015+static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
77016 {
77017 atomic64_t *v = (atomic64_t *)l;
77018
77019 return (long)atomic64_add_return(i, v);
77020 }
77021
77022+#ifdef CONFIG_PAX_REFCOUNT
77023+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
77024+{
77025+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77026+
77027+ return (long)atomic64_add_return_unchecked(i, v);
77028+}
77029+#endif
77030+
77031 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
77032 {
77033 atomic64_t *v = (atomic64_t *)l;
77034@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
77035 return (long)atomic64_inc_return(v);
77036 }
77037
77038+#ifdef CONFIG_PAX_REFCOUNT
77039+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
77040+{
77041+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77042+
77043+ return (long)atomic64_inc_return_unchecked(v);
77044+}
77045+#endif
77046+
77047 static inline long atomic_long_dec_return(atomic_long_t *l)
77048 {
77049 atomic64_t *v = (atomic64_t *)l;
77050@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
77051
77052 typedef atomic_t atomic_long_t;
77053
77054+#ifdef CONFIG_PAX_REFCOUNT
77055+typedef atomic_unchecked_t atomic_long_unchecked_t;
77056+#else
77057+typedef atomic_t atomic_long_unchecked_t;
77058+#endif
77059+
77060 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
77061 static inline long atomic_long_read(atomic_long_t *l)
77062 {
77063@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
77064 return (long)atomic_read(v);
77065 }
77066
77067+#ifdef CONFIG_PAX_REFCOUNT
77068+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
77069+{
77070+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77071+
77072+ return (long)atomic_read_unchecked(v);
77073+}
77074+#endif
77075+
77076 static inline void atomic_long_set(atomic_long_t *l, long i)
77077 {
77078 atomic_t *v = (atomic_t *)l;
77079@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
77080 atomic_set(v, i);
77081 }
77082
77083+#ifdef CONFIG_PAX_REFCOUNT
77084+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
77085+{
77086+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77087+
77088+ atomic_set_unchecked(v, i);
77089+}
77090+#endif
77091+
77092 static inline void atomic_long_inc(atomic_long_t *l)
77093 {
77094 atomic_t *v = (atomic_t *)l;
77095@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
77096 atomic_inc(v);
77097 }
77098
77099+#ifdef CONFIG_PAX_REFCOUNT
77100+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
77101+{
77102+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77103+
77104+ atomic_inc_unchecked(v);
77105+}
77106+#endif
77107+
77108 static inline void atomic_long_dec(atomic_long_t *l)
77109 {
77110 atomic_t *v = (atomic_t *)l;
77111@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
77112 atomic_dec(v);
77113 }
77114
77115+#ifdef CONFIG_PAX_REFCOUNT
77116+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
77117+{
77118+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77119+
77120+ atomic_dec_unchecked(v);
77121+}
77122+#endif
77123+
77124 static inline void atomic_long_add(long i, atomic_long_t *l)
77125 {
77126 atomic_t *v = (atomic_t *)l;
77127@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
77128 atomic_add(i, v);
77129 }
77130
77131+#ifdef CONFIG_PAX_REFCOUNT
77132+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
77133+{
77134+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77135+
77136+ atomic_add_unchecked(i, v);
77137+}
77138+#endif
77139+
77140 static inline void atomic_long_sub(long i, atomic_long_t *l)
77141 {
77142 atomic_t *v = (atomic_t *)l;
77143@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
77144 atomic_sub(i, v);
77145 }
77146
77147+#ifdef CONFIG_PAX_REFCOUNT
77148+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
77149+{
77150+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77151+
77152+ atomic_sub_unchecked(i, v);
77153+}
77154+#endif
77155+
77156 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
77157 {
77158 atomic_t *v = (atomic_t *)l;
77159@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
77160 return (long)atomic_add_return(i, v);
77161 }
77162
77163+#ifdef CONFIG_PAX_REFCOUNT
77164+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
77165+{
77166+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77167+
77168+ return (long)atomic_add_return_unchecked(i, v);
77169+}
77170+
77171+#endif
77172+
77173 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
77174 {
77175 atomic_t *v = (atomic_t *)l;
77176@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
77177 return (long)atomic_inc_return(v);
77178 }
77179
77180+#ifdef CONFIG_PAX_REFCOUNT
77181+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
77182+{
77183+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77184+
77185+ return (long)atomic_inc_return_unchecked(v);
77186+}
77187+#endif
77188+
77189 static inline long atomic_long_dec_return(atomic_long_t *l)
77190 {
77191 atomic_t *v = (atomic_t *)l;
77192@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
77193
77194 #endif /* BITS_PER_LONG == 64 */
77195
77196+#ifdef CONFIG_PAX_REFCOUNT
77197+static inline void pax_refcount_needs_these_functions(void)
77198+{
77199+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
77200+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
77201+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
77202+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
77203+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
77204+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
77205+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
77206+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
77207+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
77208+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
77209+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
77210+#ifdef CONFIG_X86
77211+ atomic_clear_mask_unchecked(0, NULL);
77212+ atomic_set_mask_unchecked(0, NULL);
77213+#endif
77214+
77215+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
77216+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
77217+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
77218+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
77219+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
77220+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
77221+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
77222+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
77223+}
77224+#else
77225+#define atomic_read_unchecked(v) atomic_read(v)
77226+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
77227+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
77228+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
77229+#define atomic_inc_unchecked(v) atomic_inc(v)
77230+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
77231+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
77232+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
77233+#define atomic_dec_unchecked(v) atomic_dec(v)
77234+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
77235+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
77236+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
77237+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
77238+
77239+#define atomic_long_read_unchecked(v) atomic_long_read(v)
77240+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
77241+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
77242+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
77243+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
77244+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
77245+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
77246+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
77247+#endif
77248+
77249 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
77250diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
77251index 33bd2de..f31bff97 100644
77252--- a/include/asm-generic/atomic.h
77253+++ b/include/asm-generic/atomic.h
77254@@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
77255 * Atomically clears the bits set in @mask from @v
77256 */
77257 #ifndef atomic_clear_mask
77258-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
77259+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
77260 {
77261 unsigned long flags;
77262
77263diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
77264index b18ce4f..2ee2843 100644
77265--- a/include/asm-generic/atomic64.h
77266+++ b/include/asm-generic/atomic64.h
77267@@ -16,6 +16,8 @@ typedef struct {
77268 long long counter;
77269 } atomic64_t;
77270
77271+typedef atomic64_t atomic64_unchecked_t;
77272+
77273 #define ATOMIC64_INIT(i) { (i) }
77274
77275 extern long long atomic64_read(const atomic64_t *v);
77276@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
77277 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
77278 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
77279
77280+#define atomic64_read_unchecked(v) atomic64_read(v)
77281+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
77282+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
77283+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
77284+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
77285+#define atomic64_inc_unchecked(v) atomic64_inc(v)
77286+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
77287+#define atomic64_dec_unchecked(v) atomic64_dec(v)
77288+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
77289+
77290 #endif /* _ASM_GENERIC_ATOMIC64_H */
77291diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
77292index a60a7cc..0fe12f2 100644
77293--- a/include/asm-generic/bitops/__fls.h
77294+++ b/include/asm-generic/bitops/__fls.h
77295@@ -9,7 +9,7 @@
77296 *
77297 * Undefined if no set bit exists, so code should check against 0 first.
77298 */
77299-static __always_inline unsigned long __fls(unsigned long word)
77300+static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
77301 {
77302 int num = BITS_PER_LONG - 1;
77303
77304diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
77305index 0576d1f..dad6c71 100644
77306--- a/include/asm-generic/bitops/fls.h
77307+++ b/include/asm-generic/bitops/fls.h
77308@@ -9,7 +9,7 @@
77309 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
77310 */
77311
77312-static __always_inline int fls(int x)
77313+static __always_inline int __intentional_overflow(-1) fls(int x)
77314 {
77315 int r = 32;
77316
77317diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
77318index b097cf8..3d40e14 100644
77319--- a/include/asm-generic/bitops/fls64.h
77320+++ b/include/asm-generic/bitops/fls64.h
77321@@ -15,7 +15,7 @@
77322 * at position 64.
77323 */
77324 #if BITS_PER_LONG == 32
77325-static __always_inline int fls64(__u64 x)
77326+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
77327 {
77328 __u32 h = x >> 32;
77329 if (h)
77330@@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
77331 return fls(x);
77332 }
77333 #elif BITS_PER_LONG == 64
77334-static __always_inline int fls64(__u64 x)
77335+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
77336 {
77337 if (x == 0)
77338 return 0;
77339diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
77340index 1bfcfe5..e04c5c9 100644
77341--- a/include/asm-generic/cache.h
77342+++ b/include/asm-generic/cache.h
77343@@ -6,7 +6,7 @@
77344 * cache lines need to provide their own cache.h.
77345 */
77346
77347-#define L1_CACHE_SHIFT 5
77348-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
77349+#define L1_CACHE_SHIFT 5UL
77350+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
77351
77352 #endif /* __ASM_GENERIC_CACHE_H */
77353diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
77354index 0d68a1e..b74a761 100644
77355--- a/include/asm-generic/emergency-restart.h
77356+++ b/include/asm-generic/emergency-restart.h
77357@@ -1,7 +1,7 @@
77358 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
77359 #define _ASM_GENERIC_EMERGENCY_RESTART_H
77360
77361-static inline void machine_emergency_restart(void)
77362+static inline __noreturn void machine_emergency_restart(void)
77363 {
77364 machine_restart(NULL);
77365 }
77366diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
77367index 90f99c7..00ce236 100644
77368--- a/include/asm-generic/kmap_types.h
77369+++ b/include/asm-generic/kmap_types.h
77370@@ -2,9 +2,9 @@
77371 #define _ASM_GENERIC_KMAP_TYPES_H
77372
77373 #ifdef __WITH_KM_FENCE
77374-# define KM_TYPE_NR 41
77375+# define KM_TYPE_NR 42
77376 #else
77377-# define KM_TYPE_NR 20
77378+# define KM_TYPE_NR 21
77379 #endif
77380
77381 #endif
77382diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
77383index 9ceb03b..62b0b8f 100644
77384--- a/include/asm-generic/local.h
77385+++ b/include/asm-generic/local.h
77386@@ -23,24 +23,37 @@ typedef struct
77387 atomic_long_t a;
77388 } local_t;
77389
77390+typedef struct {
77391+ atomic_long_unchecked_t a;
77392+} local_unchecked_t;
77393+
77394 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
77395
77396 #define local_read(l) atomic_long_read(&(l)->a)
77397+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
77398 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
77399+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
77400 #define local_inc(l) atomic_long_inc(&(l)->a)
77401+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
77402 #define local_dec(l) atomic_long_dec(&(l)->a)
77403+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
77404 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
77405+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
77406 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
77407+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
77408
77409 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
77410 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
77411 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
77412 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
77413 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
77414+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
77415 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
77416 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
77417+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
77418
77419 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
77420+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
77421 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
77422 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
77423 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
77424diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
77425index 725612b..9cc513a 100644
77426--- a/include/asm-generic/pgtable-nopmd.h
77427+++ b/include/asm-generic/pgtable-nopmd.h
77428@@ -1,14 +1,19 @@
77429 #ifndef _PGTABLE_NOPMD_H
77430 #define _PGTABLE_NOPMD_H
77431
77432-#ifndef __ASSEMBLY__
77433-
77434 #include <asm-generic/pgtable-nopud.h>
77435
77436-struct mm_struct;
77437-
77438 #define __PAGETABLE_PMD_FOLDED
77439
77440+#define PMD_SHIFT PUD_SHIFT
77441+#define PTRS_PER_PMD 1
77442+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
77443+#define PMD_MASK (~(PMD_SIZE-1))
77444+
77445+#ifndef __ASSEMBLY__
77446+
77447+struct mm_struct;
77448+
77449 /*
77450 * Having the pmd type consist of a pud gets the size right, and allows
77451 * us to conceptually access the pud entry that this pmd is folded into
77452@@ -16,11 +21,6 @@ struct mm_struct;
77453 */
77454 typedef struct { pud_t pud; } pmd_t;
77455
77456-#define PMD_SHIFT PUD_SHIFT
77457-#define PTRS_PER_PMD 1
77458-#define PMD_SIZE (1UL << PMD_SHIFT)
77459-#define PMD_MASK (~(PMD_SIZE-1))
77460-
77461 /*
77462 * The "pud_xxx()" functions here are trivial for a folded two-level
77463 * setup: the pmd is never bad, and a pmd always exists (as it's folded
77464diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
77465index 810431d..0ec4804f 100644
77466--- a/include/asm-generic/pgtable-nopud.h
77467+++ b/include/asm-generic/pgtable-nopud.h
77468@@ -1,10 +1,15 @@
77469 #ifndef _PGTABLE_NOPUD_H
77470 #define _PGTABLE_NOPUD_H
77471
77472-#ifndef __ASSEMBLY__
77473-
77474 #define __PAGETABLE_PUD_FOLDED
77475
77476+#define PUD_SHIFT PGDIR_SHIFT
77477+#define PTRS_PER_PUD 1
77478+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
77479+#define PUD_MASK (~(PUD_SIZE-1))
77480+
77481+#ifndef __ASSEMBLY__
77482+
77483 /*
77484 * Having the pud type consist of a pgd gets the size right, and allows
77485 * us to conceptually access the pgd entry that this pud is folded into
77486@@ -12,11 +17,6 @@
77487 */
77488 typedef struct { pgd_t pgd; } pud_t;
77489
77490-#define PUD_SHIFT PGDIR_SHIFT
77491-#define PTRS_PER_PUD 1
77492-#define PUD_SIZE (1UL << PUD_SHIFT)
77493-#define PUD_MASK (~(PUD_SIZE-1))
77494-
77495 /*
77496 * The "pgd_xxx()" functions here are trivial for a folded two-level
77497 * setup: the pud is never bad, and a pud always exists (as it's folded
77498@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
77499 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
77500
77501 #define pgd_populate(mm, pgd, pud) do { } while (0)
77502+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
77503 /*
77504 * (puds are folded into pgds so this doesn't get actually called,
77505 * but the define is needed for a generic inline function.)
77506diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
77507index 34c7bdc..38d4f3b 100644
77508--- a/include/asm-generic/pgtable.h
77509+++ b/include/asm-generic/pgtable.h
77510@@ -787,6 +787,22 @@ static inline void pmdp_set_numa(struct mm_struct *mm, unsigned long addr,
77511 }
77512 #endif /* CONFIG_NUMA_BALANCING */
77513
77514+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
77515+#ifdef CONFIG_PAX_KERNEXEC
77516+#error KERNEXEC requires pax_open_kernel
77517+#else
77518+static inline unsigned long pax_open_kernel(void) { return 0; }
77519+#endif
77520+#endif
77521+
77522+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
77523+#ifdef CONFIG_PAX_KERNEXEC
77524+#error KERNEXEC requires pax_close_kernel
77525+#else
77526+static inline unsigned long pax_close_kernel(void) { return 0; }
77527+#endif
77528+#endif
77529+
77530 #endif /* CONFIG_MMU */
77531
77532 #endif /* !__ASSEMBLY__ */
77533diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
77534index 72d8803..cb9749c 100644
77535--- a/include/asm-generic/uaccess.h
77536+++ b/include/asm-generic/uaccess.h
77537@@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
77538 return __clear_user(to, n);
77539 }
77540
77541+#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
77542+#ifdef CONFIG_PAX_MEMORY_UDEREF
77543+#error UDEREF requires pax_open_userland
77544+#else
77545+static inline unsigned long pax_open_userland(void) { return 0; }
77546+#endif
77547+#endif
77548+
77549+#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
77550+#ifdef CONFIG_PAX_MEMORY_UDEREF
77551+#error UDEREF requires pax_close_userland
77552+#else
77553+static inline unsigned long pax_close_userland(void) { return 0; }
77554+#endif
77555+#endif
77556+
77557 #endif /* __ASM_GENERIC_UACCESS_H */
77558diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
77559index bc2121f..2f41f9a 100644
77560--- a/include/asm-generic/vmlinux.lds.h
77561+++ b/include/asm-generic/vmlinux.lds.h
77562@@ -232,6 +232,7 @@
77563 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
77564 VMLINUX_SYMBOL(__start_rodata) = .; \
77565 *(.rodata) *(.rodata.*) \
77566+ *(.data..read_only) \
77567 *(__vermagic) /* Kernel version magic */ \
77568 . = ALIGN(8); \
77569 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
77570@@ -716,17 +717,18 @@
77571 * section in the linker script will go there too. @phdr should have
77572 * a leading colon.
77573 *
77574- * Note that this macros defines __per_cpu_load as an absolute symbol.
77575+ * Note that this macros defines per_cpu_load as an absolute symbol.
77576 * If there is no need to put the percpu section at a predetermined
77577 * address, use PERCPU_SECTION.
77578 */
77579 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
77580- VMLINUX_SYMBOL(__per_cpu_load) = .; \
77581- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
77582+ per_cpu_load = .; \
77583+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
77584 - LOAD_OFFSET) { \
77585+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
77586 PERCPU_INPUT(cacheline) \
77587 } phdr \
77588- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
77589+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
77590
77591 /**
77592 * PERCPU_SECTION - define output section for percpu area, simple version
77593diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
77594index e73c19e..5b89e00 100644
77595--- a/include/crypto/algapi.h
77596+++ b/include/crypto/algapi.h
77597@@ -34,7 +34,7 @@ struct crypto_type {
77598 unsigned int maskclear;
77599 unsigned int maskset;
77600 unsigned int tfmsize;
77601-};
77602+} __do_const;
77603
77604 struct crypto_instance {
77605 struct crypto_alg alg;
77606diff --git a/include/drm/drmP.h b/include/drm/drmP.h
77607index 04a7f31..668d424 100644
77608--- a/include/drm/drmP.h
77609+++ b/include/drm/drmP.h
77610@@ -67,6 +67,7 @@
77611 #include <linux/workqueue.h>
77612 #include <linux/poll.h>
77613 #include <asm/pgalloc.h>
77614+#include <asm/local.h>
77615 #include <drm/drm.h>
77616 #include <drm/drm_sarea.h>
77617 #include <drm/drm_vma_manager.h>
77618@@ -297,10 +298,12 @@ do { \
77619 * \param cmd command.
77620 * \param arg argument.
77621 */
77622-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
77623+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
77624+ struct drm_file *file_priv);
77625+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
77626 struct drm_file *file_priv);
77627
77628-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
77629+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
77630 unsigned long arg);
77631
77632 #define DRM_IOCTL_NR(n) _IOC_NR(n)
77633@@ -316,10 +319,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
77634 struct drm_ioctl_desc {
77635 unsigned int cmd;
77636 int flags;
77637- drm_ioctl_t *func;
77638+ drm_ioctl_t func;
77639 unsigned int cmd_drv;
77640 const char *name;
77641-};
77642+} __do_const;
77643
77644 /**
77645 * Creates a driver or general drm_ioctl_desc array entry for the given
77646@@ -1022,7 +1025,8 @@ struct drm_info_list {
77647 int (*show)(struct seq_file*, void*); /** show callback */
77648 u32 driver_features; /**< Required driver features for this entry */
77649 void *data;
77650-};
77651+} __do_const;
77652+typedef struct drm_info_list __no_const drm_info_list_no_const;
77653
77654 /**
77655 * debugfs node structure. This structure represents a debugfs file.
77656@@ -1106,7 +1110,7 @@ struct drm_device {
77657
77658 /** \name Usage Counters */
77659 /*@{ */
77660- int open_count; /**< Outstanding files open */
77661+ local_t open_count; /**< Outstanding files open */
77662 int buf_use; /**< Buffers in use -- cannot alloc */
77663 atomic_t buf_alloc; /**< Buffer allocation in progress */
77664 /*@} */
77665diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
77666index b1388b5..e1d1163 100644
77667--- a/include/drm/drm_crtc_helper.h
77668+++ b/include/drm/drm_crtc_helper.h
77669@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
77670 struct drm_connector *connector);
77671 /* disable encoder when not in use - more explicit than dpms off */
77672 void (*disable)(struct drm_encoder *encoder);
77673-};
77674+} __no_const;
77675
77676 /**
77677 * drm_connector_helper_funcs - helper operations for connectors
77678diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
77679index 940ece4..8cb727f 100644
77680--- a/include/drm/i915_pciids.h
77681+++ b/include/drm/i915_pciids.h
77682@@ -37,7 +37,7 @@
77683 */
77684 #define INTEL_VGA_DEVICE(id, info) { \
77685 0x8086, id, \
77686- ~0, ~0, \
77687+ PCI_ANY_ID, PCI_ANY_ID, \
77688 0x030000, 0xff0000, \
77689 (unsigned long) info }
77690
77691diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
77692index 72dcbe8..8db58d7 100644
77693--- a/include/drm/ttm/ttm_memory.h
77694+++ b/include/drm/ttm/ttm_memory.h
77695@@ -48,7 +48,7 @@
77696
77697 struct ttm_mem_shrink {
77698 int (*do_shrink) (struct ttm_mem_shrink *);
77699-};
77700+} __no_const;
77701
77702 /**
77703 * struct ttm_mem_global - Global memory accounting structure.
77704diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
77705index 49a8284..9643967 100644
77706--- a/include/drm/ttm/ttm_page_alloc.h
77707+++ b/include/drm/ttm/ttm_page_alloc.h
77708@@ -80,6 +80,7 @@ void ttm_dma_page_alloc_fini(void);
77709 */
77710 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
77711
77712+struct device;
77713 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
77714 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
77715
77716diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
77717index 4b840e8..155d235 100644
77718--- a/include/keys/asymmetric-subtype.h
77719+++ b/include/keys/asymmetric-subtype.h
77720@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
77721 /* Verify the signature on a key of this subtype (optional) */
77722 int (*verify_signature)(const struct key *key,
77723 const struct public_key_signature *sig);
77724-};
77725+} __do_const;
77726
77727 /**
77728 * asymmetric_key_subtype - Get the subtype from an asymmetric key
77729diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
77730index c1da539..1dcec55 100644
77731--- a/include/linux/atmdev.h
77732+++ b/include/linux/atmdev.h
77733@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
77734 #endif
77735
77736 struct k_atm_aal_stats {
77737-#define __HANDLE_ITEM(i) atomic_t i
77738+#define __HANDLE_ITEM(i) atomic_unchecked_t i
77739 __AAL_STAT_ITEMS
77740 #undef __HANDLE_ITEM
77741 };
77742@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
77743 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
77744 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
77745 struct module *owner;
77746-};
77747+} __do_const ;
77748
77749 struct atmphy_ops {
77750 int (*start)(struct atm_dev *dev);
77751diff --git a/include/linux/audit.h b/include/linux/audit.h
77752index ec1464d..833274b 100644
77753--- a/include/linux/audit.h
77754+++ b/include/linux/audit.h
77755@@ -196,7 +196,7 @@ static inline void audit_ptrace(struct task_struct *t)
77756 extern unsigned int audit_serial(void);
77757 extern int auditsc_get_stamp(struct audit_context *ctx,
77758 struct timespec *t, unsigned int *serial);
77759-extern int audit_set_loginuid(kuid_t loginuid);
77760+extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
77761
77762 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
77763 {
77764diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
77765index b4a745d..e3c0942 100644
77766--- a/include/linux/binfmts.h
77767+++ b/include/linux/binfmts.h
77768@@ -45,7 +45,7 @@ struct linux_binprm {
77769 unsigned interp_data;
77770 unsigned long loader, exec;
77771 char tcomm[TASK_COMM_LEN];
77772-};
77773+} __randomize_layout;
77774
77775 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
77776 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
77777@@ -74,8 +74,10 @@ struct linux_binfmt {
77778 int (*load_binary)(struct linux_binprm *);
77779 int (*load_shlib)(struct file *);
77780 int (*core_dump)(struct coredump_params *cprm);
77781+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
77782+ void (*handle_mmap)(struct file *);
77783 unsigned long min_coredump; /* minimal dump size */
77784-};
77785+} __do_const __randomize_layout;
77786
77787 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
77788
77789diff --git a/include/linux/bitops.h b/include/linux/bitops.h
77790index be5fd38..d71192a 100644
77791--- a/include/linux/bitops.h
77792+++ b/include/linux/bitops.h
77793@@ -102,7 +102,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
77794 * @word: value to rotate
77795 * @shift: bits to roll
77796 */
77797-static inline __u32 rol32(__u32 word, unsigned int shift)
77798+static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
77799 {
77800 return (word << shift) | (word >> (32 - shift));
77801 }
77802@@ -112,7 +112,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
77803 * @word: value to rotate
77804 * @shift: bits to roll
77805 */
77806-static inline __u32 ror32(__u32 word, unsigned int shift)
77807+static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
77808 {
77809 return (word >> shift) | (word << (32 - shift));
77810 }
77811@@ -168,7 +168,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
77812 return (__s32)(value << shift) >> shift;
77813 }
77814
77815-static inline unsigned fls_long(unsigned long l)
77816+static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
77817 {
77818 if (sizeof(l) == 4)
77819 return fls(l);
77820diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
77821index 4afa4f8..1ed7824 100644
77822--- a/include/linux/blkdev.h
77823+++ b/include/linux/blkdev.h
77824@@ -1572,7 +1572,7 @@ struct block_device_operations {
77825 /* this callback is with swap_lock and sometimes page table lock held */
77826 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
77827 struct module *owner;
77828-};
77829+} __do_const;
77830
77831 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
77832 unsigned long);
77833diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
77834index afc1343..9735539 100644
77835--- a/include/linux/blktrace_api.h
77836+++ b/include/linux/blktrace_api.h
77837@@ -25,7 +25,7 @@ struct blk_trace {
77838 struct dentry *dropped_file;
77839 struct dentry *msg_file;
77840 struct list_head running_list;
77841- atomic_t dropped;
77842+ atomic_unchecked_t dropped;
77843 };
77844
77845 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
77846diff --git a/include/linux/cache.h b/include/linux/cache.h
77847index 17e7e82..1d7da26 100644
77848--- a/include/linux/cache.h
77849+++ b/include/linux/cache.h
77850@@ -16,6 +16,14 @@
77851 #define __read_mostly
77852 #endif
77853
77854+#ifndef __read_only
77855+#ifdef CONFIG_PAX_KERNEXEC
77856+#error KERNEXEC requires __read_only
77857+#else
77858+#define __read_only __read_mostly
77859+#endif
77860+#endif
77861+
77862 #ifndef ____cacheline_aligned
77863 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
77864 #endif
77865diff --git a/include/linux/capability.h b/include/linux/capability.h
77866index a6ee1f9..e1ca49d 100644
77867--- a/include/linux/capability.h
77868+++ b/include/linux/capability.h
77869@@ -212,8 +212,13 @@ extern bool capable(int cap);
77870 extern bool ns_capable(struct user_namespace *ns, int cap);
77871 extern bool inode_capable(const struct inode *inode, int cap);
77872 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
77873+extern bool capable_nolog(int cap);
77874+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
77875+extern bool inode_capable_nolog(const struct inode *inode, int cap);
77876
77877 /* audit system wants to get cap info from files as well */
77878 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
77879
77880+extern int is_privileged_binary(const struct dentry *dentry);
77881+
77882 #endif /* !_LINUX_CAPABILITY_H */
77883diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
77884index 8609d57..86e4d79 100644
77885--- a/include/linux/cdrom.h
77886+++ b/include/linux/cdrom.h
77887@@ -87,7 +87,6 @@ struct cdrom_device_ops {
77888
77889 /* driver specifications */
77890 const int capability; /* capability flags */
77891- int n_minors; /* number of active minor devices */
77892 /* handle uniform packets for scsi type devices (scsi,atapi) */
77893 int (*generic_packet) (struct cdrom_device_info *,
77894 struct packet_command *);
77895diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
77896index 4ce9056..86caac6 100644
77897--- a/include/linux/cleancache.h
77898+++ b/include/linux/cleancache.h
77899@@ -31,7 +31,7 @@ struct cleancache_ops {
77900 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
77901 void (*invalidate_inode)(int, struct cleancache_filekey);
77902 void (*invalidate_fs)(int);
77903-};
77904+} __no_const;
77905
77906 extern struct cleancache_ops *
77907 cleancache_register_ops(struct cleancache_ops *ops);
77908diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
77909index 939533d..cf0a57c 100644
77910--- a/include/linux/clk-provider.h
77911+++ b/include/linux/clk-provider.h
77912@@ -166,6 +166,7 @@ struct clk_ops {
77913 unsigned long parent_accuracy);
77914 void (*init)(struct clk_hw *hw);
77915 };
77916+typedef struct clk_ops __no_const clk_ops_no_const;
77917
77918 /**
77919 * struct clk_init_data - holds init data that's common to all clocks and is
77920diff --git a/include/linux/compat.h b/include/linux/compat.h
77921index 3f448c6..df3ce1d 100644
77922--- a/include/linux/compat.h
77923+++ b/include/linux/compat.h
77924@@ -313,7 +313,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
77925 compat_size_t __user *len_ptr);
77926
77927 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
77928-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
77929+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
77930 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
77931 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
77932 compat_ssize_t msgsz, int msgflg);
77933@@ -420,7 +420,7 @@ extern int compat_ptrace_request(struct task_struct *child,
77934 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
77935 compat_ulong_t addr, compat_ulong_t data);
77936 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
77937- compat_long_t addr, compat_long_t data);
77938+ compat_ulong_t addr, compat_ulong_t data);
77939
77940 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
77941 /*
77942diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
77943index 2507fd2..55203f8 100644
77944--- a/include/linux/compiler-gcc4.h
77945+++ b/include/linux/compiler-gcc4.h
77946@@ -39,9 +39,34 @@
77947 # define __compiletime_warning(message) __attribute__((warning(message)))
77948 # define __compiletime_error(message) __attribute__((error(message)))
77949 #endif /* __CHECKER__ */
77950+
77951+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
77952+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
77953+#define __bos0(ptr) __bos((ptr), 0)
77954+#define __bos1(ptr) __bos((ptr), 1)
77955 #endif /* GCC_VERSION >= 40300 */
77956
77957 #if GCC_VERSION >= 40500
77958+
77959+#ifdef RANDSTRUCT_PLUGIN
77960+#define __randomize_layout __attribute__((randomize_layout))
77961+#define __no_randomize_layout __attribute__((no_randomize_layout))
77962+#endif
77963+
77964+#ifdef CONSTIFY_PLUGIN
77965+#define __no_const __attribute__((no_const))
77966+#define __do_const __attribute__((do_const))
77967+#endif
77968+
77969+#ifdef SIZE_OVERFLOW_PLUGIN
77970+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
77971+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
77972+#endif
77973+
77974+#ifdef LATENT_ENTROPY_PLUGIN
77975+#define __latent_entropy __attribute__((latent_entropy))
77976+#endif
77977+
77978 /*
77979 * Mark a position in code as unreachable. This can be used to
77980 * suppress control flow warnings after asm blocks that transfer
77981diff --git a/include/linux/compiler.h b/include/linux/compiler.h
77982index 2472740..4857634 100644
77983--- a/include/linux/compiler.h
77984+++ b/include/linux/compiler.h
77985@@ -5,11 +5,14 @@
77986
77987 #ifdef __CHECKER__
77988 # define __user __attribute__((noderef, address_space(1)))
77989+# define __force_user __force __user
77990 # define __kernel __attribute__((address_space(0)))
77991+# define __force_kernel __force __kernel
77992 # define __safe __attribute__((safe))
77993 # define __force __attribute__((force))
77994 # define __nocast __attribute__((nocast))
77995 # define __iomem __attribute__((noderef, address_space(2)))
77996+# define __force_iomem __force __iomem
77997 # define __must_hold(x) __attribute__((context(x,1,1)))
77998 # define __acquires(x) __attribute__((context(x,0,1)))
77999 # define __releases(x) __attribute__((context(x,1,0)))
78000@@ -17,20 +20,37 @@
78001 # define __release(x) __context__(x,-1)
78002 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
78003 # define __percpu __attribute__((noderef, address_space(3)))
78004+# define __force_percpu __force __percpu
78005 #ifdef CONFIG_SPARSE_RCU_POINTER
78006 # define __rcu __attribute__((noderef, address_space(4)))
78007+# define __force_rcu __force __rcu
78008 #else
78009 # define __rcu
78010+# define __force_rcu
78011 #endif
78012 extern void __chk_user_ptr(const volatile void __user *);
78013 extern void __chk_io_ptr(const volatile void __iomem *);
78014 #else
78015-# define __user
78016-# define __kernel
78017+# ifdef CHECKER_PLUGIN
78018+//# define __user
78019+//# define __force_user
78020+//# define __kernel
78021+//# define __force_kernel
78022+# else
78023+# ifdef STRUCTLEAK_PLUGIN
78024+# define __user __attribute__((user))
78025+# else
78026+# define __user
78027+# endif
78028+# define __force_user
78029+# define __kernel
78030+# define __force_kernel
78031+# endif
78032 # define __safe
78033 # define __force
78034 # define __nocast
78035 # define __iomem
78036+# define __force_iomem
78037 # define __chk_user_ptr(x) (void)0
78038 # define __chk_io_ptr(x) (void)0
78039 # define __builtin_warning(x, y...) (1)
78040@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
78041 # define __release(x) (void)0
78042 # define __cond_lock(x,c) (c)
78043 # define __percpu
78044+# define __force_percpu
78045 # define __rcu
78046+# define __force_rcu
78047 #endif
78048
78049 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
78050@@ -279,6 +301,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
78051 # define __attribute_const__ /* unimplemented */
78052 #endif
78053
78054+#ifndef __randomize_layout
78055+# define __randomize_layout
78056+#endif
78057+
78058+#ifndef __no_randomize_layout
78059+# define __no_randomize_layout
78060+#endif
78061+
78062+#ifndef __no_const
78063+# define __no_const
78064+#endif
78065+
78066+#ifndef __do_const
78067+# define __do_const
78068+#endif
78069+
78070+#ifndef __size_overflow
78071+# define __size_overflow(...)
78072+#endif
78073+
78074+#ifndef __intentional_overflow
78075+# define __intentional_overflow(...)
78076+#endif
78077+
78078+#ifndef __latent_entropy
78079+# define __latent_entropy
78080+#endif
78081+
78082 /*
78083 * Tell gcc if a function is cold. The compiler will assume any path
78084 * directly leading to the call is unlikely.
78085@@ -288,6 +338,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
78086 #define __cold
78087 #endif
78088
78089+#ifndef __alloc_size
78090+#define __alloc_size(...)
78091+#endif
78092+
78093+#ifndef __bos
78094+#define __bos(ptr, arg)
78095+#endif
78096+
78097+#ifndef __bos0
78098+#define __bos0(ptr)
78099+#endif
78100+
78101+#ifndef __bos1
78102+#define __bos1(ptr)
78103+#endif
78104+
78105 /* Simple shorthand for a section definition */
78106 #ifndef __section
78107 # define __section(S) __attribute__ ((__section__(#S)))
78108@@ -362,7 +428,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
78109 * use is to mediate communication between process-level code and irq/NMI
78110 * handlers, all running on the same CPU.
78111 */
78112-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
78113+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
78114+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
78115
78116 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
78117 #ifdef CONFIG_KPROBES
78118diff --git a/include/linux/completion.h b/include/linux/completion.h
78119index 5d5aaae..0ea9b84 100644
78120--- a/include/linux/completion.h
78121+++ b/include/linux/completion.h
78122@@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
78123
78124 extern void wait_for_completion(struct completion *);
78125 extern void wait_for_completion_io(struct completion *);
78126-extern int wait_for_completion_interruptible(struct completion *x);
78127-extern int wait_for_completion_killable(struct completion *x);
78128+extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
78129+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
78130 extern unsigned long wait_for_completion_timeout(struct completion *x,
78131- unsigned long timeout);
78132+ unsigned long timeout) __intentional_overflow(-1);
78133 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
78134- unsigned long timeout);
78135+ unsigned long timeout) __intentional_overflow(-1);
78136 extern long wait_for_completion_interruptible_timeout(
78137- struct completion *x, unsigned long timeout);
78138+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
78139 extern long wait_for_completion_killable_timeout(
78140- struct completion *x, unsigned long timeout);
78141+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
78142 extern bool try_wait_for_completion(struct completion *x);
78143 extern bool completion_done(struct completion *x);
78144
78145diff --git a/include/linux/configfs.h b/include/linux/configfs.h
78146index 34025df..d94bbbc 100644
78147--- a/include/linux/configfs.h
78148+++ b/include/linux/configfs.h
78149@@ -125,7 +125,7 @@ struct configfs_attribute {
78150 const char *ca_name;
78151 struct module *ca_owner;
78152 umode_t ca_mode;
78153-};
78154+} __do_const;
78155
78156 /*
78157 * Users often need to create attribute structures for their configurable
78158diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
78159index 4d89e0e..5281847 100644
78160--- a/include/linux/cpufreq.h
78161+++ b/include/linux/cpufreq.h
78162@@ -191,6 +191,7 @@ struct global_attr {
78163 ssize_t (*store)(struct kobject *a, struct attribute *b,
78164 const char *c, size_t count);
78165 };
78166+typedef struct global_attr __no_const global_attr_no_const;
78167
78168 #define define_one_global_ro(_name) \
78169 static struct global_attr _name = \
78170@@ -232,7 +233,7 @@ struct cpufreq_driver {
78171 bool boost_supported;
78172 bool boost_enabled;
78173 int (*set_boost) (int state);
78174-};
78175+} __do_const;
78176
78177 /* flags */
78178 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
78179diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
78180index 50fcbb0..9d2dbd9 100644
78181--- a/include/linux/cpuidle.h
78182+++ b/include/linux/cpuidle.h
78183@@ -50,7 +50,8 @@ struct cpuidle_state {
78184 int index);
78185
78186 int (*enter_dead) (struct cpuidle_device *dev, int index);
78187-};
78188+} __do_const;
78189+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
78190
78191 /* Idle State Flags */
78192 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
78193@@ -192,7 +193,7 @@ struct cpuidle_governor {
78194 void (*reflect) (struct cpuidle_device *dev, int index);
78195
78196 struct module *owner;
78197-};
78198+} __do_const;
78199
78200 #ifdef CONFIG_CPU_IDLE
78201 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
78202diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
78203index d08e4d2..95fad61 100644
78204--- a/include/linux/cpumask.h
78205+++ b/include/linux/cpumask.h
78206@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
78207 }
78208
78209 /* Valid inputs for n are -1 and 0. */
78210-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
78211+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
78212 {
78213 return n+1;
78214 }
78215
78216-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
78217+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
78218 {
78219 return n+1;
78220 }
78221
78222-static inline unsigned int cpumask_next_and(int n,
78223+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
78224 const struct cpumask *srcp,
78225 const struct cpumask *andp)
78226 {
78227@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
78228 *
78229 * Returns >= nr_cpu_ids if no further cpus set.
78230 */
78231-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
78232+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
78233 {
78234 /* -1 is a legal arg here. */
78235 if (n != -1)
78236@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
78237 *
78238 * Returns >= nr_cpu_ids if no further cpus unset.
78239 */
78240-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
78241+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
78242 {
78243 /* -1 is a legal arg here. */
78244 if (n != -1)
78245@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
78246 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
78247 }
78248
78249-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
78250+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
78251 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
78252
78253 /**
78254diff --git a/include/linux/cred.h b/include/linux/cred.h
78255index 04421e8..117e17a 100644
78256--- a/include/linux/cred.h
78257+++ b/include/linux/cred.h
78258@@ -35,7 +35,7 @@ struct group_info {
78259 int nblocks;
78260 kgid_t small_block[NGROUPS_SMALL];
78261 kgid_t *blocks[0];
78262-};
78263+} __randomize_layout;
78264
78265 /**
78266 * get_group_info - Get a reference to a group info structure
78267@@ -136,7 +136,7 @@ struct cred {
78268 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
78269 struct group_info *group_info; /* supplementary groups for euid/fsgid */
78270 struct rcu_head rcu; /* RCU deletion hook */
78271-};
78272+} __randomize_layout;
78273
78274 extern void __put_cred(struct cred *);
78275 extern void exit_creds(struct task_struct *);
78276@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
78277 static inline void validate_process_creds(void)
78278 {
78279 }
78280+static inline void validate_task_creds(struct task_struct *task)
78281+{
78282+}
78283 #endif
78284
78285 /**
78286diff --git a/include/linux/crypto.h b/include/linux/crypto.h
78287index b92eadf..b4ecdc1 100644
78288--- a/include/linux/crypto.h
78289+++ b/include/linux/crypto.h
78290@@ -373,7 +373,7 @@ struct cipher_tfm {
78291 const u8 *key, unsigned int keylen);
78292 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
78293 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
78294-};
78295+} __no_const;
78296
78297 struct hash_tfm {
78298 int (*init)(struct hash_desc *desc);
78299@@ -394,13 +394,13 @@ struct compress_tfm {
78300 int (*cot_decompress)(struct crypto_tfm *tfm,
78301 const u8 *src, unsigned int slen,
78302 u8 *dst, unsigned int *dlen);
78303-};
78304+} __no_const;
78305
78306 struct rng_tfm {
78307 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
78308 unsigned int dlen);
78309 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
78310-};
78311+} __no_const;
78312
78313 #define crt_ablkcipher crt_u.ablkcipher
78314 #define crt_aead crt_u.aead
78315diff --git a/include/linux/ctype.h b/include/linux/ctype.h
78316index 653589e..4ef254a 100644
78317--- a/include/linux/ctype.h
78318+++ b/include/linux/ctype.h
78319@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
78320 * Fast implementation of tolower() for internal usage. Do not use in your
78321 * code.
78322 */
78323-static inline char _tolower(const char c)
78324+static inline unsigned char _tolower(const unsigned char c)
78325 {
78326 return c | 0x20;
78327 }
78328diff --git a/include/linux/dcache.h b/include/linux/dcache.h
78329index bf72e9a..4ca7927 100644
78330--- a/include/linux/dcache.h
78331+++ b/include/linux/dcache.h
78332@@ -133,7 +133,7 @@ struct dentry {
78333 } d_u;
78334 struct list_head d_subdirs; /* our children */
78335 struct hlist_node d_alias; /* inode alias list */
78336-};
78337+} __randomize_layout;
78338
78339 /*
78340 * dentry->d_lock spinlock nesting subclasses:
78341diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
78342index 7925bf0..d5143d2 100644
78343--- a/include/linux/decompress/mm.h
78344+++ b/include/linux/decompress/mm.h
78345@@ -77,7 +77,7 @@ static void free(void *where)
78346 * warnings when not needed (indeed large_malloc / large_free are not
78347 * needed by inflate */
78348
78349-#define malloc(a) kmalloc(a, GFP_KERNEL)
78350+#define malloc(a) kmalloc((a), GFP_KERNEL)
78351 #define free(a) kfree(a)
78352
78353 #define large_malloc(a) vmalloc(a)
78354diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
78355index d48dc00..211ee54 100644
78356--- a/include/linux/devfreq.h
78357+++ b/include/linux/devfreq.h
78358@@ -114,7 +114,7 @@ struct devfreq_governor {
78359 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
78360 int (*event_handler)(struct devfreq *devfreq,
78361 unsigned int event, void *data);
78362-};
78363+} __do_const;
78364
78365 /**
78366 * struct devfreq - Device devfreq structure
78367diff --git a/include/linux/device.h b/include/linux/device.h
78368index 952b010..d5b7691 100644
78369--- a/include/linux/device.h
78370+++ b/include/linux/device.h
78371@@ -310,7 +310,7 @@ struct subsys_interface {
78372 struct list_head node;
78373 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
78374 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
78375-};
78376+} __do_const;
78377
78378 int subsys_interface_register(struct subsys_interface *sif);
78379 void subsys_interface_unregister(struct subsys_interface *sif);
78380@@ -506,7 +506,7 @@ struct device_type {
78381 void (*release)(struct device *dev);
78382
78383 const struct dev_pm_ops *pm;
78384-};
78385+} __do_const;
78386
78387 /* interface for exporting device attributes */
78388 struct device_attribute {
78389@@ -516,11 +516,12 @@ struct device_attribute {
78390 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
78391 const char *buf, size_t count);
78392 };
78393+typedef struct device_attribute __no_const device_attribute_no_const;
78394
78395 struct dev_ext_attribute {
78396 struct device_attribute attr;
78397 void *var;
78398-};
78399+} __do_const;
78400
78401 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
78402 char *buf);
78403diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
78404index fd4aee2..1f28db9 100644
78405--- a/include/linux/dma-mapping.h
78406+++ b/include/linux/dma-mapping.h
78407@@ -54,7 +54,7 @@ struct dma_map_ops {
78408 u64 (*get_required_mask)(struct device *dev);
78409 #endif
78410 int is_phys;
78411-};
78412+} __do_const;
78413
78414 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
78415
78416diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
78417index c5c92d5..6a5c2b2 100644
78418--- a/include/linux/dmaengine.h
78419+++ b/include/linux/dmaengine.h
78420@@ -1150,9 +1150,9 @@ struct dma_pinned_list {
78421 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
78422 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
78423
78424-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
78425+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
78426 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
78427-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
78428+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
78429 struct dma_pinned_list *pinned_list, struct page *page,
78430 unsigned int offset, size_t len);
78431
78432diff --git a/include/linux/efi.h b/include/linux/efi.h
78433index 0a819e7..8ed47f1 100644
78434--- a/include/linux/efi.h
78435+++ b/include/linux/efi.h
78436@@ -768,6 +768,7 @@ struct efivar_operations {
78437 efi_set_variable_t *set_variable;
78438 efi_query_variable_store_t *query_variable_store;
78439 };
78440+typedef struct efivar_operations __no_const efivar_operations_no_const;
78441
78442 struct efivars {
78443 /*
78444diff --git a/include/linux/elf.h b/include/linux/elf.h
78445index 67a5fa7..b817372 100644
78446--- a/include/linux/elf.h
78447+++ b/include/linux/elf.h
78448@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
78449 #define elf_note elf32_note
78450 #define elf_addr_t Elf32_Off
78451 #define Elf_Half Elf32_Half
78452+#define elf_dyn Elf32_Dyn
78453
78454 #else
78455
78456@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
78457 #define elf_note elf64_note
78458 #define elf_addr_t Elf64_Off
78459 #define Elf_Half Elf64_Half
78460+#define elf_dyn Elf64_Dyn
78461
78462 #endif
78463
78464diff --git a/include/linux/err.h b/include/linux/err.h
78465index 15f92e0..e825a8e 100644
78466--- a/include/linux/err.h
78467+++ b/include/linux/err.h
78468@@ -19,12 +19,12 @@
78469
78470 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
78471
78472-static inline void * __must_check ERR_PTR(long error)
78473+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
78474 {
78475 return (void *) error;
78476 }
78477
78478-static inline long __must_check PTR_ERR(__force const void *ptr)
78479+static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
78480 {
78481 return (long) ptr;
78482 }
78483diff --git a/include/linux/extcon.h b/include/linux/extcon.h
78484index 21c59af..6057a03 100644
78485--- a/include/linux/extcon.h
78486+++ b/include/linux/extcon.h
78487@@ -135,7 +135,7 @@ struct extcon_dev {
78488 /* /sys/class/extcon/.../mutually_exclusive/... */
78489 struct attribute_group attr_g_muex;
78490 struct attribute **attrs_muex;
78491- struct device_attribute *d_attrs_muex;
78492+ device_attribute_no_const *d_attrs_muex;
78493 };
78494
78495 /**
78496diff --git a/include/linux/fb.h b/include/linux/fb.h
78497index fe6ac95..898d41d 100644
78498--- a/include/linux/fb.h
78499+++ b/include/linux/fb.h
78500@@ -304,7 +304,7 @@ struct fb_ops {
78501 /* called at KDB enter and leave time to prepare the console */
78502 int (*fb_debug_enter)(struct fb_info *info);
78503 int (*fb_debug_leave)(struct fb_info *info);
78504-};
78505+} __do_const;
78506
78507 #ifdef CONFIG_FB_TILEBLITTING
78508 #define FB_TILE_CURSOR_NONE 0
78509diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
78510index 70e8e21..1939916 100644
78511--- a/include/linux/fdtable.h
78512+++ b/include/linux/fdtable.h
78513@@ -102,7 +102,7 @@ struct files_struct *get_files_struct(struct task_struct *);
78514 void put_files_struct(struct files_struct *fs);
78515 void reset_files_struct(struct files_struct *);
78516 int unshare_files(struct files_struct **);
78517-struct files_struct *dup_fd(struct files_struct *, int *);
78518+struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
78519 void do_close_on_exec(struct files_struct *);
78520 int iterate_fd(struct files_struct *, unsigned,
78521 int (*)(const void *, struct file *, unsigned),
78522diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
78523index 8293262..2b3b8bd 100644
78524--- a/include/linux/frontswap.h
78525+++ b/include/linux/frontswap.h
78526@@ -11,7 +11,7 @@ struct frontswap_ops {
78527 int (*load)(unsigned, pgoff_t, struct page *);
78528 void (*invalidate_page)(unsigned, pgoff_t);
78529 void (*invalidate_area)(unsigned);
78530-};
78531+} __no_const;
78532
78533 extern bool frontswap_enabled;
78534 extern struct frontswap_ops *
78535diff --git a/include/linux/fs.h b/include/linux/fs.h
78536index 23b2a35..8764ab7 100644
78537--- a/include/linux/fs.h
78538+++ b/include/linux/fs.h
78539@@ -426,7 +426,7 @@ struct address_space {
78540 spinlock_t private_lock; /* for use by the address_space */
78541 struct list_head private_list; /* ditto */
78542 void *private_data; /* ditto */
78543-} __attribute__((aligned(sizeof(long))));
78544+} __attribute__((aligned(sizeof(long)))) __randomize_layout;
78545 /*
78546 * On most architectures that alignment is already the case; but
78547 * must be enforced here for CRIS, to let the least significant bit
78548@@ -469,7 +469,7 @@ struct block_device {
78549 int bd_fsfreeze_count;
78550 /* Mutex for freeze */
78551 struct mutex bd_fsfreeze_mutex;
78552-};
78553+} __randomize_layout;
78554
78555 /*
78556 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
78557@@ -613,7 +613,7 @@ struct inode {
78558 atomic_t i_readcount; /* struct files open RO */
78559 #endif
78560 void *i_private; /* fs or device private pointer */
78561-};
78562+} __randomize_layout;
78563
78564 static inline int inode_unhashed(struct inode *inode)
78565 {
78566@@ -812,7 +812,7 @@ struct file {
78567 #ifdef CONFIG_DEBUG_WRITECOUNT
78568 unsigned long f_mnt_write_state;
78569 #endif
78570-} __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
78571+} __attribute__((aligned(4))) __randomize_layout; /* lest something weird decides that 2 is OK */
78572
78573 struct file_handle {
78574 __u32 handle_bytes;
78575@@ -982,7 +982,7 @@ struct file_lock {
78576 int state; /* state of grant or error if -ve */
78577 } afs;
78578 } fl_u;
78579-};
78580+} __randomize_layout;
78581
78582 /* The following constant reflects the upper bound of the file/locking space */
78583 #ifndef OFFSET_MAX
78584@@ -1329,7 +1329,7 @@ struct super_block {
78585 struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
78586 struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
78587 struct rcu_head rcu;
78588-};
78589+} __randomize_layout;
78590
78591 extern struct timespec current_fs_time(struct super_block *sb);
78592
78593@@ -1551,7 +1551,8 @@ struct file_operations {
78594 long (*fallocate)(struct file *file, int mode, loff_t offset,
78595 loff_t len);
78596 int (*show_fdinfo)(struct seq_file *m, struct file *f);
78597-};
78598+} __do_const __randomize_layout;
78599+typedef struct file_operations __no_const file_operations_no_const;
78600
78601 struct inode_operations {
78602 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
78603@@ -2820,4 +2821,14 @@ static inline bool dir_relax(struct inode *inode)
78604 return !IS_DEADDIR(inode);
78605 }
78606
78607+static inline bool is_sidechannel_device(const struct inode *inode)
78608+{
78609+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
78610+ umode_t mode = inode->i_mode;
78611+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
78612+#else
78613+ return false;
78614+#endif
78615+}
78616+
78617 #endif /* _LINUX_FS_H */
78618diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
78619index 0efc3e6..fd23610 100644
78620--- a/include/linux/fs_struct.h
78621+++ b/include/linux/fs_struct.h
78622@@ -6,13 +6,13 @@
78623 #include <linux/seqlock.h>
78624
78625 struct fs_struct {
78626- int users;
78627+ atomic_t users;
78628 spinlock_t lock;
78629 seqcount_t seq;
78630 int umask;
78631 int in_exec;
78632 struct path root, pwd;
78633-};
78634+} __randomize_layout;
78635
78636 extern struct kmem_cache *fs_cachep;
78637
78638diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
78639index 7714849..a4a5c7a 100644
78640--- a/include/linux/fscache-cache.h
78641+++ b/include/linux/fscache-cache.h
78642@@ -113,7 +113,7 @@ struct fscache_operation {
78643 fscache_operation_release_t release;
78644 };
78645
78646-extern atomic_t fscache_op_debug_id;
78647+extern atomic_unchecked_t fscache_op_debug_id;
78648 extern void fscache_op_work_func(struct work_struct *work);
78649
78650 extern void fscache_enqueue_operation(struct fscache_operation *);
78651@@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
78652 INIT_WORK(&op->work, fscache_op_work_func);
78653 atomic_set(&op->usage, 1);
78654 op->state = FSCACHE_OP_ST_INITIALISED;
78655- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
78656+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
78657 op->processor = processor;
78658 op->release = release;
78659 INIT_LIST_HEAD(&op->pend_link);
78660diff --git a/include/linux/fscache.h b/include/linux/fscache.h
78661index 115bb81..e7b812b 100644
78662--- a/include/linux/fscache.h
78663+++ b/include/linux/fscache.h
78664@@ -152,7 +152,7 @@ struct fscache_cookie_def {
78665 * - this is mandatory for any object that may have data
78666 */
78667 void (*now_uncached)(void *cookie_netfs_data);
78668-};
78669+} __do_const;
78670
78671 /*
78672 * fscache cached network filesystem type
78673diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
78674index 1c804b0..1432c2b 100644
78675--- a/include/linux/fsnotify.h
78676+++ b/include/linux/fsnotify.h
78677@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
78678 struct inode *inode = file_inode(file);
78679 __u32 mask = FS_ACCESS;
78680
78681+ if (is_sidechannel_device(inode))
78682+ return;
78683+
78684 if (S_ISDIR(inode->i_mode))
78685 mask |= FS_ISDIR;
78686
78687@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
78688 struct inode *inode = file_inode(file);
78689 __u32 mask = FS_MODIFY;
78690
78691+ if (is_sidechannel_device(inode))
78692+ return;
78693+
78694 if (S_ISDIR(inode->i_mode))
78695 mask |= FS_ISDIR;
78696
78697@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
78698 */
78699 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
78700 {
78701- return kstrdup(name, GFP_KERNEL);
78702+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
78703 }
78704
78705 /*
78706diff --git a/include/linux/genhd.h b/include/linux/genhd.h
78707index 9f3c275..8bdff5d 100644
78708--- a/include/linux/genhd.h
78709+++ b/include/linux/genhd.h
78710@@ -194,7 +194,7 @@ struct gendisk {
78711 struct kobject *slave_dir;
78712
78713 struct timer_rand_state *random;
78714- atomic_t sync_io; /* RAID */
78715+ atomic_unchecked_t sync_io; /* RAID */
78716 struct disk_events *ev;
78717 #ifdef CONFIG_BLK_DEV_INTEGRITY
78718 struct blk_integrity *integrity;
78719@@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
78720 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
78721
78722 /* drivers/char/random.c */
78723-extern void add_disk_randomness(struct gendisk *disk);
78724+extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
78725 extern void rand_initialize_disk(struct gendisk *disk);
78726
78727 static inline sector_t get_start_sect(struct block_device *bdev)
78728diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
78729index c0894dd..2fbf10c 100644
78730--- a/include/linux/genl_magic_func.h
78731+++ b/include/linux/genl_magic_func.h
78732@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
78733 },
78734
78735 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
78736-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
78737+static struct genl_ops ZZZ_genl_ops[] = {
78738 #include GENL_MAGIC_INCLUDE_FILE
78739 };
78740
78741diff --git a/include/linux/gfp.h b/include/linux/gfp.h
78742index 39b81dc..819dc51 100644
78743--- a/include/linux/gfp.h
78744+++ b/include/linux/gfp.h
78745@@ -36,6 +36,13 @@ struct vm_area_struct;
78746 #define ___GFP_NO_KSWAPD 0x400000u
78747 #define ___GFP_OTHER_NODE 0x800000u
78748 #define ___GFP_WRITE 0x1000000u
78749+
78750+#ifdef CONFIG_PAX_USERCOPY_SLABS
78751+#define ___GFP_USERCOPY 0x2000000u
78752+#else
78753+#define ___GFP_USERCOPY 0
78754+#endif
78755+
78756 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
78757
78758 /*
78759@@ -93,6 +100,7 @@ struct vm_area_struct;
78760 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
78761 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
78762 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
78763+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
78764
78765 /*
78766 * This may seem redundant, but it's a way of annotating false positives vs.
78767@@ -100,7 +108,7 @@ struct vm_area_struct;
78768 */
78769 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
78770
78771-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
78772+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
78773 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
78774
78775 /* This equals 0, but use constants in case they ever change */
78776@@ -158,6 +166,8 @@ struct vm_area_struct;
78777 /* 4GB DMA on some platforms */
78778 #define GFP_DMA32 __GFP_DMA32
78779
78780+#define GFP_USERCOPY __GFP_USERCOPY
78781+
78782 /* Convert GFP flags to their corresponding migrate type */
78783 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
78784 {
78785diff --git a/include/linux/gracl.h b/include/linux/gracl.h
78786new file mode 100644
78787index 0000000..edb2cb6
78788--- /dev/null
78789+++ b/include/linux/gracl.h
78790@@ -0,0 +1,340 @@
78791+#ifndef GR_ACL_H
78792+#define GR_ACL_H
78793+
78794+#include <linux/grdefs.h>
78795+#include <linux/resource.h>
78796+#include <linux/capability.h>
78797+#include <linux/dcache.h>
78798+#include <asm/resource.h>
78799+
78800+/* Major status information */
78801+
78802+#define GR_VERSION "grsecurity 3.0"
78803+#define GRSECURITY_VERSION 0x3000
78804+
78805+enum {
78806+ GR_SHUTDOWN = 0,
78807+ GR_ENABLE = 1,
78808+ GR_SPROLE = 2,
78809+ GR_OLDRELOAD = 3,
78810+ GR_SEGVMOD = 4,
78811+ GR_STATUS = 5,
78812+ GR_UNSPROLE = 6,
78813+ GR_PASSSET = 7,
78814+ GR_SPROLEPAM = 8,
78815+ GR_RELOAD = 9,
78816+};
78817+
78818+/* Password setup definitions
78819+ * kernel/grhash.c */
78820+enum {
78821+ GR_PW_LEN = 128,
78822+ GR_SALT_LEN = 16,
78823+ GR_SHA_LEN = 32,
78824+};
78825+
78826+enum {
78827+ GR_SPROLE_LEN = 64,
78828+};
78829+
78830+enum {
78831+ GR_NO_GLOB = 0,
78832+ GR_REG_GLOB,
78833+ GR_CREATE_GLOB
78834+};
78835+
78836+#define GR_NLIMITS 32
78837+
78838+/* Begin Data Structures */
78839+
78840+struct sprole_pw {
78841+ unsigned char *rolename;
78842+ unsigned char salt[GR_SALT_LEN];
78843+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
78844+};
78845+
78846+struct name_entry {
78847+ __u32 key;
78848+ ino_t inode;
78849+ dev_t device;
78850+ char *name;
78851+ __u16 len;
78852+ __u8 deleted;
78853+ struct name_entry *prev;
78854+ struct name_entry *next;
78855+};
78856+
78857+struct inodev_entry {
78858+ struct name_entry *nentry;
78859+ struct inodev_entry *prev;
78860+ struct inodev_entry *next;
78861+};
78862+
78863+struct acl_role_db {
78864+ struct acl_role_label **r_hash;
78865+ __u32 r_size;
78866+};
78867+
78868+struct inodev_db {
78869+ struct inodev_entry **i_hash;
78870+ __u32 i_size;
78871+};
78872+
78873+struct name_db {
78874+ struct name_entry **n_hash;
78875+ __u32 n_size;
78876+};
78877+
78878+struct crash_uid {
78879+ uid_t uid;
78880+ unsigned long expires;
78881+};
78882+
78883+struct gr_hash_struct {
78884+ void **table;
78885+ void **nametable;
78886+ void *first;
78887+ __u32 table_size;
78888+ __u32 used_size;
78889+ int type;
78890+};
78891+
78892+/* Userspace Grsecurity ACL data structures */
78893+
78894+struct acl_subject_label {
78895+ char *filename;
78896+ ino_t inode;
78897+ dev_t device;
78898+ __u32 mode;
78899+ kernel_cap_t cap_mask;
78900+ kernel_cap_t cap_lower;
78901+ kernel_cap_t cap_invert_audit;
78902+
78903+ struct rlimit res[GR_NLIMITS];
78904+ __u32 resmask;
78905+
78906+ __u8 user_trans_type;
78907+ __u8 group_trans_type;
78908+ uid_t *user_transitions;
78909+ gid_t *group_transitions;
78910+ __u16 user_trans_num;
78911+ __u16 group_trans_num;
78912+
78913+ __u32 sock_families[2];
78914+ __u32 ip_proto[8];
78915+ __u32 ip_type;
78916+ struct acl_ip_label **ips;
78917+ __u32 ip_num;
78918+ __u32 inaddr_any_override;
78919+
78920+ __u32 crashes;
78921+ unsigned long expires;
78922+
78923+ struct acl_subject_label *parent_subject;
78924+ struct gr_hash_struct *hash;
78925+ struct acl_subject_label *prev;
78926+ struct acl_subject_label *next;
78927+
78928+ struct acl_object_label **obj_hash;
78929+ __u32 obj_hash_size;
78930+ __u16 pax_flags;
78931+};
78932+
78933+struct role_allowed_ip {
78934+ __u32 addr;
78935+ __u32 netmask;
78936+
78937+ struct role_allowed_ip *prev;
78938+ struct role_allowed_ip *next;
78939+};
78940+
78941+struct role_transition {
78942+ char *rolename;
78943+
78944+ struct role_transition *prev;
78945+ struct role_transition *next;
78946+};
78947+
78948+struct acl_role_label {
78949+ char *rolename;
78950+ uid_t uidgid;
78951+ __u16 roletype;
78952+
78953+ __u16 auth_attempts;
78954+ unsigned long expires;
78955+
78956+ struct acl_subject_label *root_label;
78957+ struct gr_hash_struct *hash;
78958+
78959+ struct acl_role_label *prev;
78960+ struct acl_role_label *next;
78961+
78962+ struct role_transition *transitions;
78963+ struct role_allowed_ip *allowed_ips;
78964+ uid_t *domain_children;
78965+ __u16 domain_child_num;
78966+
78967+ umode_t umask;
78968+
78969+ struct acl_subject_label **subj_hash;
78970+ __u32 subj_hash_size;
78971+};
78972+
78973+struct user_acl_role_db {
78974+ struct acl_role_label **r_table;
78975+ __u32 num_pointers; /* Number of allocations to track */
78976+ __u32 num_roles; /* Number of roles */
78977+ __u32 num_domain_children; /* Number of domain children */
78978+ __u32 num_subjects; /* Number of subjects */
78979+ __u32 num_objects; /* Number of objects */
78980+};
78981+
78982+struct acl_object_label {
78983+ char *filename;
78984+ ino_t inode;
78985+ dev_t device;
78986+ __u32 mode;
78987+
78988+ struct acl_subject_label *nested;
78989+ struct acl_object_label *globbed;
78990+
78991+ /* next two structures not used */
78992+
78993+ struct acl_object_label *prev;
78994+ struct acl_object_label *next;
78995+};
78996+
78997+struct acl_ip_label {
78998+ char *iface;
78999+ __u32 addr;
79000+ __u32 netmask;
79001+ __u16 low, high;
79002+ __u8 mode;
79003+ __u32 type;
79004+ __u32 proto[8];
79005+
79006+ /* next two structures not used */
79007+
79008+ struct acl_ip_label *prev;
79009+ struct acl_ip_label *next;
79010+};
79011+
79012+struct gr_arg {
79013+ struct user_acl_role_db role_db;
79014+ unsigned char pw[GR_PW_LEN];
79015+ unsigned char salt[GR_SALT_LEN];
79016+ unsigned char sum[GR_SHA_LEN];
79017+ unsigned char sp_role[GR_SPROLE_LEN];
79018+ struct sprole_pw *sprole_pws;
79019+ dev_t segv_device;
79020+ ino_t segv_inode;
79021+ uid_t segv_uid;
79022+ __u16 num_sprole_pws;
79023+ __u16 mode;
79024+};
79025+
79026+struct gr_arg_wrapper {
79027+ struct gr_arg *arg;
79028+ __u32 version;
79029+ __u32 size;
79030+};
79031+
79032+struct subject_map {
79033+ struct acl_subject_label *user;
79034+ struct acl_subject_label *kernel;
79035+ struct subject_map *prev;
79036+ struct subject_map *next;
79037+};
79038+
79039+struct acl_subj_map_db {
79040+ struct subject_map **s_hash;
79041+ __u32 s_size;
79042+};
79043+
79044+struct gr_policy_state {
79045+ struct sprole_pw **acl_special_roles;
79046+ __u16 num_sprole_pws;
79047+ struct acl_role_label *kernel_role;
79048+ struct acl_role_label *role_list;
79049+ struct acl_role_label *default_role;
79050+ struct acl_role_db acl_role_set;
79051+ struct acl_subj_map_db subj_map_set;
79052+ struct name_db name_set;
79053+ struct inodev_db inodev_set;
79054+};
79055+
79056+struct gr_alloc_state {
79057+ unsigned long alloc_stack_next;
79058+ unsigned long alloc_stack_size;
79059+ void **alloc_stack;
79060+};
79061+
79062+struct gr_reload_state {
79063+ struct gr_policy_state oldpolicy;
79064+ struct gr_alloc_state oldalloc;
79065+ struct gr_policy_state newpolicy;
79066+ struct gr_alloc_state newalloc;
79067+ struct gr_policy_state *oldpolicy_ptr;
79068+ struct gr_alloc_state *oldalloc_ptr;
79069+ unsigned char oldmode;
79070+};
79071+
79072+/* End Data Structures Section */
79073+
79074+/* Hash functions generated by empirical testing by Brad Spengler
79075+ Makes good use of the low bits of the inode. Generally 0-1 times
79076+ in loop for successful match. 0-3 for unsuccessful match.
79077+ Shift/add algorithm with modulus of table size and an XOR*/
79078+
79079+static __inline__ unsigned int
79080+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
79081+{
79082+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
79083+}
79084+
79085+ static __inline__ unsigned int
79086+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
79087+{
79088+ return ((const unsigned long)userp % sz);
79089+}
79090+
79091+static __inline__ unsigned int
79092+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
79093+{
79094+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
79095+}
79096+
79097+static __inline__ unsigned int
79098+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
79099+{
79100+ return full_name_hash((const unsigned char *)name, len) % sz;
79101+}
79102+
79103+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
79104+ subj = NULL; \
79105+ iter = 0; \
79106+ while (iter < role->subj_hash_size) { \
79107+ if (subj == NULL) \
79108+ subj = role->subj_hash[iter]; \
79109+ if (subj == NULL) { \
79110+ iter++; \
79111+ continue; \
79112+ }
79113+
79114+#define FOR_EACH_SUBJECT_END(subj,iter) \
79115+ subj = subj->next; \
79116+ if (subj == NULL) \
79117+ iter++; \
79118+ }
79119+
79120+
79121+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
79122+ subj = role->hash->first; \
79123+ while (subj != NULL) {
79124+
79125+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
79126+ subj = subj->next; \
79127+ }
79128+
79129+#endif
79130+
79131diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
79132new file mode 100644
79133index 0000000..33ebd1f
79134--- /dev/null
79135+++ b/include/linux/gracl_compat.h
79136@@ -0,0 +1,156 @@
79137+#ifndef GR_ACL_COMPAT_H
79138+#define GR_ACL_COMPAT_H
79139+
79140+#include <linux/resource.h>
79141+#include <asm/resource.h>
79142+
79143+struct sprole_pw_compat {
79144+ compat_uptr_t rolename;
79145+ unsigned char salt[GR_SALT_LEN];
79146+ unsigned char sum[GR_SHA_LEN];
79147+};
79148+
79149+struct gr_hash_struct_compat {
79150+ compat_uptr_t table;
79151+ compat_uptr_t nametable;
79152+ compat_uptr_t first;
79153+ __u32 table_size;
79154+ __u32 used_size;
79155+ int type;
79156+};
79157+
79158+struct acl_subject_label_compat {
79159+ compat_uptr_t filename;
79160+ compat_ino_t inode;
79161+ __u32 device;
79162+ __u32 mode;
79163+ kernel_cap_t cap_mask;
79164+ kernel_cap_t cap_lower;
79165+ kernel_cap_t cap_invert_audit;
79166+
79167+ struct compat_rlimit res[GR_NLIMITS];
79168+ __u32 resmask;
79169+
79170+ __u8 user_trans_type;
79171+ __u8 group_trans_type;
79172+ compat_uptr_t user_transitions;
79173+ compat_uptr_t group_transitions;
79174+ __u16 user_trans_num;
79175+ __u16 group_trans_num;
79176+
79177+ __u32 sock_families[2];
79178+ __u32 ip_proto[8];
79179+ __u32 ip_type;
79180+ compat_uptr_t ips;
79181+ __u32 ip_num;
79182+ __u32 inaddr_any_override;
79183+
79184+ __u32 crashes;
79185+ compat_ulong_t expires;
79186+
79187+ compat_uptr_t parent_subject;
79188+ compat_uptr_t hash;
79189+ compat_uptr_t prev;
79190+ compat_uptr_t next;
79191+
79192+ compat_uptr_t obj_hash;
79193+ __u32 obj_hash_size;
79194+ __u16 pax_flags;
79195+};
79196+
79197+struct role_allowed_ip_compat {
79198+ __u32 addr;
79199+ __u32 netmask;
79200+
79201+ compat_uptr_t prev;
79202+ compat_uptr_t next;
79203+};
79204+
79205+struct role_transition_compat {
79206+ compat_uptr_t rolename;
79207+
79208+ compat_uptr_t prev;
79209+ compat_uptr_t next;
79210+};
79211+
79212+struct acl_role_label_compat {
79213+ compat_uptr_t rolename;
79214+ uid_t uidgid;
79215+ __u16 roletype;
79216+
79217+ __u16 auth_attempts;
79218+ compat_ulong_t expires;
79219+
79220+ compat_uptr_t root_label;
79221+ compat_uptr_t hash;
79222+
79223+ compat_uptr_t prev;
79224+ compat_uptr_t next;
79225+
79226+ compat_uptr_t transitions;
79227+ compat_uptr_t allowed_ips;
79228+ compat_uptr_t domain_children;
79229+ __u16 domain_child_num;
79230+
79231+ umode_t umask;
79232+
79233+ compat_uptr_t subj_hash;
79234+ __u32 subj_hash_size;
79235+};
79236+
79237+struct user_acl_role_db_compat {
79238+ compat_uptr_t r_table;
79239+ __u32 num_pointers;
79240+ __u32 num_roles;
79241+ __u32 num_domain_children;
79242+ __u32 num_subjects;
79243+ __u32 num_objects;
79244+};
79245+
79246+struct acl_object_label_compat {
79247+ compat_uptr_t filename;
79248+ compat_ino_t inode;
79249+ __u32 device;
79250+ __u32 mode;
79251+
79252+ compat_uptr_t nested;
79253+ compat_uptr_t globbed;
79254+
79255+ compat_uptr_t prev;
79256+ compat_uptr_t next;
79257+};
79258+
79259+struct acl_ip_label_compat {
79260+ compat_uptr_t iface;
79261+ __u32 addr;
79262+ __u32 netmask;
79263+ __u16 low, high;
79264+ __u8 mode;
79265+ __u32 type;
79266+ __u32 proto[8];
79267+
79268+ compat_uptr_t prev;
79269+ compat_uptr_t next;
79270+};
79271+
79272+struct gr_arg_compat {
79273+ struct user_acl_role_db_compat role_db;
79274+ unsigned char pw[GR_PW_LEN];
79275+ unsigned char salt[GR_SALT_LEN];
79276+ unsigned char sum[GR_SHA_LEN];
79277+ unsigned char sp_role[GR_SPROLE_LEN];
79278+ compat_uptr_t sprole_pws;
79279+ __u32 segv_device;
79280+ compat_ino_t segv_inode;
79281+ uid_t segv_uid;
79282+ __u16 num_sprole_pws;
79283+ __u16 mode;
79284+};
79285+
79286+struct gr_arg_wrapper_compat {
79287+ compat_uptr_t arg;
79288+ __u32 version;
79289+ __u32 size;
79290+};
79291+
79292+#endif
79293diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
79294new file mode 100644
79295index 0000000..323ecf2
79296--- /dev/null
79297+++ b/include/linux/gralloc.h
79298@@ -0,0 +1,9 @@
79299+#ifndef __GRALLOC_H
79300+#define __GRALLOC_H
79301+
79302+void acl_free_all(void);
79303+int acl_alloc_stack_init(unsigned long size);
79304+void *acl_alloc(unsigned long len);
79305+void *acl_alloc_num(unsigned long num, unsigned long len);
79306+
79307+#endif
79308diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
79309new file mode 100644
79310index 0000000..be66033
79311--- /dev/null
79312+++ b/include/linux/grdefs.h
79313@@ -0,0 +1,140 @@
79314+#ifndef GRDEFS_H
79315+#define GRDEFS_H
79316+
79317+/* Begin grsecurity status declarations */
79318+
79319+enum {
79320+ GR_READY = 0x01,
79321+ GR_STATUS_INIT = 0x00 // disabled state
79322+};
79323+
79324+/* Begin ACL declarations */
79325+
79326+/* Role flags */
79327+
79328+enum {
79329+ GR_ROLE_USER = 0x0001,
79330+ GR_ROLE_GROUP = 0x0002,
79331+ GR_ROLE_DEFAULT = 0x0004,
79332+ GR_ROLE_SPECIAL = 0x0008,
79333+ GR_ROLE_AUTH = 0x0010,
79334+ GR_ROLE_NOPW = 0x0020,
79335+ GR_ROLE_GOD = 0x0040,
79336+ GR_ROLE_LEARN = 0x0080,
79337+ GR_ROLE_TPE = 0x0100,
79338+ GR_ROLE_DOMAIN = 0x0200,
79339+ GR_ROLE_PAM = 0x0400,
79340+ GR_ROLE_PERSIST = 0x0800
79341+};
79342+
79343+/* ACL Subject and Object mode flags */
79344+enum {
79345+ GR_DELETED = 0x80000000
79346+};
79347+
79348+/* ACL Object-only mode flags */
79349+enum {
79350+ GR_READ = 0x00000001,
79351+ GR_APPEND = 0x00000002,
79352+ GR_WRITE = 0x00000004,
79353+ GR_EXEC = 0x00000008,
79354+ GR_FIND = 0x00000010,
79355+ GR_INHERIT = 0x00000020,
79356+ GR_SETID = 0x00000040,
79357+ GR_CREATE = 0x00000080,
79358+ GR_DELETE = 0x00000100,
79359+ GR_LINK = 0x00000200,
79360+ GR_AUDIT_READ = 0x00000400,
79361+ GR_AUDIT_APPEND = 0x00000800,
79362+ GR_AUDIT_WRITE = 0x00001000,
79363+ GR_AUDIT_EXEC = 0x00002000,
79364+ GR_AUDIT_FIND = 0x00004000,
79365+ GR_AUDIT_INHERIT= 0x00008000,
79366+ GR_AUDIT_SETID = 0x00010000,
79367+ GR_AUDIT_CREATE = 0x00020000,
79368+ GR_AUDIT_DELETE = 0x00040000,
79369+ GR_AUDIT_LINK = 0x00080000,
79370+ GR_PTRACERD = 0x00100000,
79371+ GR_NOPTRACE = 0x00200000,
79372+ GR_SUPPRESS = 0x00400000,
79373+ GR_NOLEARN = 0x00800000,
79374+ GR_INIT_TRANSFER= 0x01000000
79375+};
79376+
79377+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
79378+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
79379+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
79380+
79381+/* ACL subject-only mode flags */
79382+enum {
79383+ GR_KILL = 0x00000001,
79384+ GR_VIEW = 0x00000002,
79385+ GR_PROTECTED = 0x00000004,
79386+ GR_LEARN = 0x00000008,
79387+ GR_OVERRIDE = 0x00000010,
79388+ /* just a placeholder, this mode is only used in userspace */
79389+ GR_DUMMY = 0x00000020,
79390+ GR_PROTSHM = 0x00000040,
79391+ GR_KILLPROC = 0x00000080,
79392+ GR_KILLIPPROC = 0x00000100,
79393+ /* just a placeholder, this mode is only used in userspace */
79394+ GR_NOTROJAN = 0x00000200,
79395+ GR_PROTPROCFD = 0x00000400,
79396+ GR_PROCACCT = 0x00000800,
79397+ GR_RELAXPTRACE = 0x00001000,
79398+ //GR_NESTED = 0x00002000,
79399+ GR_INHERITLEARN = 0x00004000,
79400+ GR_PROCFIND = 0x00008000,
79401+ GR_POVERRIDE = 0x00010000,
79402+ GR_KERNELAUTH = 0x00020000,
79403+ GR_ATSECURE = 0x00040000,
79404+ GR_SHMEXEC = 0x00080000
79405+};
79406+
79407+enum {
79408+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
79409+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
79410+ GR_PAX_ENABLE_MPROTECT = 0x0004,
79411+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
79412+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
79413+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
79414+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
79415+ GR_PAX_DISABLE_MPROTECT = 0x0400,
79416+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
79417+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
79418+};
79419+
79420+enum {
79421+ GR_ID_USER = 0x01,
79422+ GR_ID_GROUP = 0x02,
79423+};
79424+
79425+enum {
79426+ GR_ID_ALLOW = 0x01,
79427+ GR_ID_DENY = 0x02,
79428+};
79429+
79430+#define GR_CRASH_RES 31
79431+#define GR_UIDTABLE_MAX 500
79432+
79433+/* begin resource learning section */
79434+enum {
79435+ GR_RLIM_CPU_BUMP = 60,
79436+ GR_RLIM_FSIZE_BUMP = 50000,
79437+ GR_RLIM_DATA_BUMP = 10000,
79438+ GR_RLIM_STACK_BUMP = 1000,
79439+ GR_RLIM_CORE_BUMP = 10000,
79440+ GR_RLIM_RSS_BUMP = 500000,
79441+ GR_RLIM_NPROC_BUMP = 1,
79442+ GR_RLIM_NOFILE_BUMP = 5,
79443+ GR_RLIM_MEMLOCK_BUMP = 50000,
79444+ GR_RLIM_AS_BUMP = 500000,
79445+ GR_RLIM_LOCKS_BUMP = 2,
79446+ GR_RLIM_SIGPENDING_BUMP = 5,
79447+ GR_RLIM_MSGQUEUE_BUMP = 10000,
79448+ GR_RLIM_NICE_BUMP = 1,
79449+ GR_RLIM_RTPRIO_BUMP = 1,
79450+ GR_RLIM_RTTIME_BUMP = 1000000
79451+};
79452+
79453+#endif
79454diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
79455new file mode 100644
79456index 0000000..d25522e
79457--- /dev/null
79458+++ b/include/linux/grinternal.h
79459@@ -0,0 +1,229 @@
79460+#ifndef __GRINTERNAL_H
79461+#define __GRINTERNAL_H
79462+
79463+#ifdef CONFIG_GRKERNSEC
79464+
79465+#include <linux/fs.h>
79466+#include <linux/mnt_namespace.h>
79467+#include <linux/nsproxy.h>
79468+#include <linux/gracl.h>
79469+#include <linux/grdefs.h>
79470+#include <linux/grmsg.h>
79471+
79472+void gr_add_learn_entry(const char *fmt, ...)
79473+ __attribute__ ((format (printf, 1, 2)));
79474+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
79475+ const struct vfsmount *mnt);
79476+__u32 gr_check_create(const struct dentry *new_dentry,
79477+ const struct dentry *parent,
79478+ const struct vfsmount *mnt, const __u32 mode);
79479+int gr_check_protected_task(const struct task_struct *task);
79480+__u32 to_gr_audit(const __u32 reqmode);
79481+int gr_set_acls(const int type);
79482+int gr_acl_is_enabled(void);
79483+char gr_roletype_to_char(void);
79484+
79485+void gr_handle_alertkill(struct task_struct *task);
79486+char *gr_to_filename(const struct dentry *dentry,
79487+ const struct vfsmount *mnt);
79488+char *gr_to_filename1(const struct dentry *dentry,
79489+ const struct vfsmount *mnt);
79490+char *gr_to_filename2(const struct dentry *dentry,
79491+ const struct vfsmount *mnt);
79492+char *gr_to_filename3(const struct dentry *dentry,
79493+ const struct vfsmount *mnt);
79494+
79495+extern int grsec_enable_ptrace_readexec;
79496+extern int grsec_enable_harden_ptrace;
79497+extern int grsec_enable_link;
79498+extern int grsec_enable_fifo;
79499+extern int grsec_enable_execve;
79500+extern int grsec_enable_shm;
79501+extern int grsec_enable_execlog;
79502+extern int grsec_enable_signal;
79503+extern int grsec_enable_audit_ptrace;
79504+extern int grsec_enable_forkfail;
79505+extern int grsec_enable_time;
79506+extern int grsec_enable_rofs;
79507+extern int grsec_deny_new_usb;
79508+extern int grsec_enable_chroot_shmat;
79509+extern int grsec_enable_chroot_mount;
79510+extern int grsec_enable_chroot_double;
79511+extern int grsec_enable_chroot_pivot;
79512+extern int grsec_enable_chroot_chdir;
79513+extern int grsec_enable_chroot_chmod;
79514+extern int grsec_enable_chroot_mknod;
79515+extern int grsec_enable_chroot_fchdir;
79516+extern int grsec_enable_chroot_nice;
79517+extern int grsec_enable_chroot_execlog;
79518+extern int grsec_enable_chroot_caps;
79519+extern int grsec_enable_chroot_sysctl;
79520+extern int grsec_enable_chroot_unix;
79521+extern int grsec_enable_symlinkown;
79522+extern kgid_t grsec_symlinkown_gid;
79523+extern int grsec_enable_tpe;
79524+extern kgid_t grsec_tpe_gid;
79525+extern int grsec_enable_tpe_all;
79526+extern int grsec_enable_tpe_invert;
79527+extern int grsec_enable_socket_all;
79528+extern kgid_t grsec_socket_all_gid;
79529+extern int grsec_enable_socket_client;
79530+extern kgid_t grsec_socket_client_gid;
79531+extern int grsec_enable_socket_server;
79532+extern kgid_t grsec_socket_server_gid;
79533+extern kgid_t grsec_audit_gid;
79534+extern int grsec_enable_group;
79535+extern int grsec_enable_log_rwxmaps;
79536+extern int grsec_enable_mount;
79537+extern int grsec_enable_chdir;
79538+extern int grsec_resource_logging;
79539+extern int grsec_enable_blackhole;
79540+extern int grsec_lastack_retries;
79541+extern int grsec_enable_brute;
79542+extern int grsec_enable_harden_ipc;
79543+extern int grsec_lock;
79544+
79545+extern spinlock_t grsec_alert_lock;
79546+extern unsigned long grsec_alert_wtime;
79547+extern unsigned long grsec_alert_fyet;
79548+
79549+extern spinlock_t grsec_audit_lock;
79550+
79551+extern rwlock_t grsec_exec_file_lock;
79552+
79553+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
79554+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
79555+ (tsk)->exec_file->f_path.mnt) : "/")
79556+
79557+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
79558+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
79559+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
79560+
79561+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
79562+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
79563+ (tsk)->exec_file->f_path.mnt) : "/")
79564+
79565+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
79566+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
79567+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
79568+
79569+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
79570+
79571+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
79572+
79573+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
79574+{
79575+ if (file1 && file2) {
79576+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
79577+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
79578+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
79579+ return true;
79580+ }
79581+
79582+ return false;
79583+}
79584+
79585+#define GR_CHROOT_CAPS {{ \
79586+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
79587+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
79588+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
79589+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
79590+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
79591+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
79592+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
79593+
79594+#define security_learn(normal_msg,args...) \
79595+({ \
79596+ read_lock(&grsec_exec_file_lock); \
79597+ gr_add_learn_entry(normal_msg "\n", ## args); \
79598+ read_unlock(&grsec_exec_file_lock); \
79599+})
79600+
79601+enum {
79602+ GR_DO_AUDIT,
79603+ GR_DONT_AUDIT,
79604+ /* used for non-audit messages that we shouldn't kill the task on */
79605+ GR_DONT_AUDIT_GOOD
79606+};
79607+
79608+enum {
79609+ GR_TTYSNIFF,
79610+ GR_RBAC,
79611+ GR_RBAC_STR,
79612+ GR_STR_RBAC,
79613+ GR_RBAC_MODE2,
79614+ GR_RBAC_MODE3,
79615+ GR_FILENAME,
79616+ GR_SYSCTL_HIDDEN,
79617+ GR_NOARGS,
79618+ GR_ONE_INT,
79619+ GR_ONE_INT_TWO_STR,
79620+ GR_ONE_STR,
79621+ GR_STR_INT,
79622+ GR_TWO_STR_INT,
79623+ GR_TWO_INT,
79624+ GR_TWO_U64,
79625+ GR_THREE_INT,
79626+ GR_FIVE_INT_TWO_STR,
79627+ GR_TWO_STR,
79628+ GR_THREE_STR,
79629+ GR_FOUR_STR,
79630+ GR_STR_FILENAME,
79631+ GR_FILENAME_STR,
79632+ GR_FILENAME_TWO_INT,
79633+ GR_FILENAME_TWO_INT_STR,
79634+ GR_TEXTREL,
79635+ GR_PTRACE,
79636+ GR_RESOURCE,
79637+ GR_CAP,
79638+ GR_SIG,
79639+ GR_SIG2,
79640+ GR_CRASH1,
79641+ GR_CRASH2,
79642+ GR_PSACCT,
79643+ GR_RWXMAP,
79644+ GR_RWXMAPVMA
79645+};
79646+
79647+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
79648+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
79649+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
79650+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
79651+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
79652+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
79653+#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)
79654+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
79655+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
79656+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
79657+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
79658+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
79659+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
79660+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
79661+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
79662+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
79663+#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)
79664+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
79665+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
79666+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
79667+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
79668+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
79669+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
79670+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
79671+#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)
79672+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
79673+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
79674+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
79675+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
79676+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
79677+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
79678+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
79679+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
79680+#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)
79681+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
79682+#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
79683+
79684+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
79685+
79686+#endif
79687+
79688+#endif
79689diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
79690new file mode 100644
79691index 0000000..ba93581
79692--- /dev/null
79693+++ b/include/linux/grmsg.h
79694@@ -0,0 +1,116 @@
79695+#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"
79696+#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"
79697+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
79698+#define GR_STOPMOD_MSG "denied modification of module state by "
79699+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
79700+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
79701+#define GR_IOPERM_MSG "denied use of ioperm() by "
79702+#define GR_IOPL_MSG "denied use of iopl() by "
79703+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
79704+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
79705+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
79706+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
79707+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
79708+#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"
79709+#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"
79710+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
79711+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
79712+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
79713+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
79714+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
79715+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
79716+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
79717+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
79718+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
79719+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
79720+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
79721+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
79722+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
79723+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
79724+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
79725+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
79726+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
79727+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
79728+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
79729+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
79730+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
79731+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
79732+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
79733+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
79734+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
79735+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
79736+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
79737+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
79738+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
79739+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
79740+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
79741+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
79742+#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
79743+#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
79744+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
79745+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
79746+#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"
79747+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
79748+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
79749+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
79750+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
79751+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
79752+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
79753+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
79754+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
79755+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
79756+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
79757+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
79758+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
79759+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
79760+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
79761+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
79762+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
79763+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
79764+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
79765+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
79766+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
79767+#define GR_FAILFORK_MSG "failed fork with errno %s by "
79768+#define GR_NICE_CHROOT_MSG "denied priority change by "
79769+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
79770+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
79771+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
79772+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
79773+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
79774+#define GR_TIME_MSG "time set by "
79775+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
79776+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
79777+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
79778+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
79779+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
79780+#define GR_BIND_MSG "denied bind() by "
79781+#define GR_CONNECT_MSG "denied connect() by "
79782+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
79783+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
79784+#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"
79785+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
79786+#define GR_CAP_ACL_MSG "use of %s denied for "
79787+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
79788+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
79789+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
79790+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
79791+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
79792+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
79793+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
79794+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
79795+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
79796+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
79797+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
79798+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
79799+#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
79800+#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
79801+#define GR_VM86_MSG "denied use of vm86 by "
79802+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
79803+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
79804+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
79805+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
79806+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
79807+#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 "
79808+#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 "
79809+#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
79810+#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
79811diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
79812new file mode 100644
79813index 0000000..f2d8c6c
79814--- /dev/null
79815+++ b/include/linux/grsecurity.h
79816@@ -0,0 +1,248 @@
79817+#ifndef GR_SECURITY_H
79818+#define GR_SECURITY_H
79819+#include <linux/fs.h>
79820+#include <linux/fs_struct.h>
79821+#include <linux/binfmts.h>
79822+#include <linux/gracl.h>
79823+
79824+/* notify of brain-dead configs */
79825+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
79826+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
79827+#endif
79828+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
79829+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
79830+#endif
79831+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
79832+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
79833+#endif
79834+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
79835+#error "CONFIG_PAX enabled, but no PaX options are enabled."
79836+#endif
79837+
79838+int gr_handle_new_usb(void);
79839+
79840+void gr_handle_brute_attach(int dumpable);
79841+void gr_handle_brute_check(void);
79842+void gr_handle_kernel_exploit(void);
79843+
79844+char gr_roletype_to_char(void);
79845+
79846+int gr_proc_is_restricted(void);
79847+
79848+int gr_acl_enable_at_secure(void);
79849+
79850+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
79851+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
79852+
79853+void gr_del_task_from_ip_table(struct task_struct *p);
79854+
79855+int gr_pid_is_chrooted(struct task_struct *p);
79856+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
79857+int gr_handle_chroot_nice(void);
79858+int gr_handle_chroot_sysctl(const int op);
79859+int gr_handle_chroot_setpriority(struct task_struct *p,
79860+ const int niceval);
79861+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
79862+int gr_handle_chroot_chroot(const struct dentry *dentry,
79863+ const struct vfsmount *mnt);
79864+void gr_handle_chroot_chdir(const struct path *path);
79865+int gr_handle_chroot_chmod(const struct dentry *dentry,
79866+ const struct vfsmount *mnt, const int mode);
79867+int gr_handle_chroot_mknod(const struct dentry *dentry,
79868+ const struct vfsmount *mnt, const int mode);
79869+int gr_handle_chroot_mount(const struct dentry *dentry,
79870+ const struct vfsmount *mnt,
79871+ const char *dev_name);
79872+int gr_handle_chroot_pivot(void);
79873+int gr_handle_chroot_unix(const pid_t pid);
79874+
79875+int gr_handle_rawio(const struct inode *inode);
79876+
79877+void gr_handle_ioperm(void);
79878+void gr_handle_iopl(void);
79879+void gr_handle_msr_write(void);
79880+
79881+umode_t gr_acl_umask(void);
79882+
79883+int gr_tpe_allow(const struct file *file);
79884+
79885+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
79886+void gr_clear_chroot_entries(struct task_struct *task);
79887+
79888+void gr_log_forkfail(const int retval);
79889+void gr_log_timechange(void);
79890+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
79891+void gr_log_chdir(const struct dentry *dentry,
79892+ const struct vfsmount *mnt);
79893+void gr_log_chroot_exec(const struct dentry *dentry,
79894+ const struct vfsmount *mnt);
79895+void gr_log_remount(const char *devname, const int retval);
79896+void gr_log_unmount(const char *devname, const int retval);
79897+void gr_log_mount(const char *from, const char *to, const int retval);
79898+void gr_log_textrel(struct vm_area_struct *vma);
79899+void gr_log_ptgnustack(struct file *file);
79900+void gr_log_rwxmmap(struct file *file);
79901+void gr_log_rwxmprotect(struct vm_area_struct *vma);
79902+
79903+int gr_handle_follow_link(const struct inode *parent,
79904+ const struct inode *inode,
79905+ const struct dentry *dentry,
79906+ const struct vfsmount *mnt);
79907+int gr_handle_fifo(const struct dentry *dentry,
79908+ const struct vfsmount *mnt,
79909+ const struct dentry *dir, const int flag,
79910+ const int acc_mode);
79911+int gr_handle_hardlink(const struct dentry *dentry,
79912+ const struct vfsmount *mnt,
79913+ struct inode *inode,
79914+ const int mode, const struct filename *to);
79915+
79916+int gr_is_capable(const int cap);
79917+int gr_is_capable_nolog(const int cap);
79918+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
79919+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
79920+
79921+void gr_copy_label(struct task_struct *tsk);
79922+void gr_handle_crash(struct task_struct *task, const int sig);
79923+int gr_handle_signal(const struct task_struct *p, const int sig);
79924+int gr_check_crash_uid(const kuid_t uid);
79925+int gr_check_protected_task(const struct task_struct *task);
79926+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
79927+int gr_acl_handle_mmap(const struct file *file,
79928+ const unsigned long prot);
79929+int gr_acl_handle_mprotect(const struct file *file,
79930+ const unsigned long prot);
79931+int gr_check_hidden_task(const struct task_struct *tsk);
79932+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
79933+ const struct vfsmount *mnt);
79934+__u32 gr_acl_handle_utime(const struct dentry *dentry,
79935+ const struct vfsmount *mnt);
79936+__u32 gr_acl_handle_access(const struct dentry *dentry,
79937+ const struct vfsmount *mnt, const int fmode);
79938+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
79939+ const struct vfsmount *mnt, umode_t *mode);
79940+__u32 gr_acl_handle_chown(const struct dentry *dentry,
79941+ const struct vfsmount *mnt);
79942+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
79943+ const struct vfsmount *mnt);
79944+__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
79945+ const struct vfsmount *mnt);
79946+int gr_handle_ptrace(struct task_struct *task, const long request);
79947+int gr_handle_proc_ptrace(struct task_struct *task);
79948+__u32 gr_acl_handle_execve(const struct dentry *dentry,
79949+ const struct vfsmount *mnt);
79950+int gr_check_crash_exec(const struct file *filp);
79951+int gr_acl_is_enabled(void);
79952+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
79953+ const kgid_t gid);
79954+int gr_set_proc_label(const struct dentry *dentry,
79955+ const struct vfsmount *mnt,
79956+ const int unsafe_flags);
79957+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
79958+ const struct vfsmount *mnt);
79959+__u32 gr_acl_handle_open(const struct dentry *dentry,
79960+ const struct vfsmount *mnt, int acc_mode);
79961+__u32 gr_acl_handle_creat(const struct dentry *dentry,
79962+ const struct dentry *p_dentry,
79963+ const struct vfsmount *p_mnt,
79964+ int open_flags, int acc_mode, const int imode);
79965+void gr_handle_create(const struct dentry *dentry,
79966+ const struct vfsmount *mnt);
79967+void gr_handle_proc_create(const struct dentry *dentry,
79968+ const struct inode *inode);
79969+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
79970+ const struct dentry *parent_dentry,
79971+ const struct vfsmount *parent_mnt,
79972+ const int mode);
79973+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
79974+ const struct dentry *parent_dentry,
79975+ const struct vfsmount *parent_mnt);
79976+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
79977+ const struct vfsmount *mnt);
79978+void gr_handle_delete(const ino_t ino, const dev_t dev);
79979+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
79980+ const struct vfsmount *mnt);
79981+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
79982+ const struct dentry *parent_dentry,
79983+ const struct vfsmount *parent_mnt,
79984+ const struct filename *from);
79985+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
79986+ const struct dentry *parent_dentry,
79987+ const struct vfsmount *parent_mnt,
79988+ const struct dentry *old_dentry,
79989+ const struct vfsmount *old_mnt, const struct filename *to);
79990+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
79991+int gr_acl_handle_rename(struct dentry *new_dentry,
79992+ struct dentry *parent_dentry,
79993+ const struct vfsmount *parent_mnt,
79994+ struct dentry *old_dentry,
79995+ struct inode *old_parent_inode,
79996+ struct vfsmount *old_mnt, const struct filename *newname);
79997+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
79998+ struct dentry *old_dentry,
79999+ struct dentry *new_dentry,
80000+ struct vfsmount *mnt, const __u8 replace);
80001+__u32 gr_check_link(const struct dentry *new_dentry,
80002+ const struct dentry *parent_dentry,
80003+ const struct vfsmount *parent_mnt,
80004+ const struct dentry *old_dentry,
80005+ const struct vfsmount *old_mnt);
80006+int gr_acl_handle_filldir(const struct file *file, const char *name,
80007+ const unsigned int namelen, const ino_t ino);
80008+
80009+__u32 gr_acl_handle_unix(const struct dentry *dentry,
80010+ const struct vfsmount *mnt);
80011+void gr_acl_handle_exit(void);
80012+void gr_acl_handle_psacct(struct task_struct *task, const long code);
80013+int gr_acl_handle_procpidmem(const struct task_struct *task);
80014+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
80015+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
80016+void gr_audit_ptrace(struct task_struct *task);
80017+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
80018+void gr_put_exec_file(struct task_struct *task);
80019+
80020+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
80021+
80022+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
80023+extern void gr_learn_resource(const struct task_struct *task, const int res,
80024+ const unsigned long wanted, const int gt);
80025+#else
80026+static inline void gr_learn_resource(const struct task_struct *task, const int res,
80027+ const unsigned long wanted, const int gt)
80028+{
80029+}
80030+#endif
80031+
80032+#ifdef CONFIG_GRKERNSEC_RESLOG
80033+extern void gr_log_resource(const struct task_struct *task, const int res,
80034+ const unsigned long wanted, const int gt);
80035+#else
80036+static inline void gr_log_resource(const struct task_struct *task, const int res,
80037+ const unsigned long wanted, const int gt)
80038+{
80039+}
80040+#endif
80041+
80042+#ifdef CONFIG_GRKERNSEC
80043+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
80044+void gr_handle_vm86(void);
80045+void gr_handle_mem_readwrite(u64 from, u64 to);
80046+
80047+void gr_log_badprocpid(const char *entry);
80048+
80049+extern int grsec_enable_dmesg;
80050+extern int grsec_disable_privio;
80051+
80052+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
80053+extern kgid_t grsec_proc_gid;
80054+#endif
80055+
80056+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
80057+extern int grsec_enable_chroot_findtask;
80058+#endif
80059+#ifdef CONFIG_GRKERNSEC_SETXID
80060+extern int grsec_enable_setxid;
80061+#endif
80062+#endif
80063+
80064+#endif
80065diff --git a/include/linux/grsock.h b/include/linux/grsock.h
80066new file mode 100644
80067index 0000000..e7ffaaf
80068--- /dev/null
80069+++ b/include/linux/grsock.h
80070@@ -0,0 +1,19 @@
80071+#ifndef __GRSOCK_H
80072+#define __GRSOCK_H
80073+
80074+extern void gr_attach_curr_ip(const struct sock *sk);
80075+extern int gr_handle_sock_all(const int family, const int type,
80076+ const int protocol);
80077+extern int gr_handle_sock_server(const struct sockaddr *sck);
80078+extern int gr_handle_sock_server_other(const struct sock *sck);
80079+extern int gr_handle_sock_client(const struct sockaddr *sck);
80080+extern int gr_search_connect(struct socket * sock,
80081+ struct sockaddr_in * addr);
80082+extern int gr_search_bind(struct socket * sock,
80083+ struct sockaddr_in * addr);
80084+extern int gr_search_listen(struct socket * sock);
80085+extern int gr_search_accept(struct socket * sock);
80086+extern int gr_search_socket(const int domain, const int type,
80087+ const int protocol);
80088+
80089+#endif
80090diff --git a/include/linux/hash.h b/include/linux/hash.h
80091index bd1754c..8240892 100644
80092--- a/include/linux/hash.h
80093+++ b/include/linux/hash.h
80094@@ -83,7 +83,7 @@ static inline u32 hash32_ptr(const void *ptr)
80095 struct fast_hash_ops {
80096 u32 (*hash)(const void *data, u32 len, u32 seed);
80097 u32 (*hash2)(const u32 *data, u32 len, u32 seed);
80098-};
80099+} __no_const;
80100
80101 /**
80102 * arch_fast_hash - Caclulates a hash over a given buffer that can have
80103diff --git a/include/linux/highmem.h b/include/linux/highmem.h
80104index 7fb31da..08b5114 100644
80105--- a/include/linux/highmem.h
80106+++ b/include/linux/highmem.h
80107@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
80108 kunmap_atomic(kaddr);
80109 }
80110
80111+static inline void sanitize_highpage(struct page *page)
80112+{
80113+ void *kaddr;
80114+ unsigned long flags;
80115+
80116+ local_irq_save(flags);
80117+ kaddr = kmap_atomic(page);
80118+ clear_page(kaddr);
80119+ kunmap_atomic(kaddr);
80120+ local_irq_restore(flags);
80121+}
80122+
80123 static inline void zero_user_segments(struct page *page,
80124 unsigned start1, unsigned end1,
80125 unsigned start2, unsigned end2)
80126diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
80127index 1c7b89a..7dda400 100644
80128--- a/include/linux/hwmon-sysfs.h
80129+++ b/include/linux/hwmon-sysfs.h
80130@@ -25,7 +25,8 @@
80131 struct sensor_device_attribute{
80132 struct device_attribute dev_attr;
80133 int index;
80134-};
80135+} __do_const;
80136+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
80137 #define to_sensor_dev_attr(_dev_attr) \
80138 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
80139
80140@@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
80141 struct device_attribute dev_attr;
80142 u8 index;
80143 u8 nr;
80144-};
80145+} __do_const;
80146+typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
80147 #define to_sensor_dev_attr_2(_dev_attr) \
80148 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
80149
80150diff --git a/include/linux/i2c.h b/include/linux/i2c.h
80151index deddeb8..bcaf62d 100644
80152--- a/include/linux/i2c.h
80153+++ b/include/linux/i2c.h
80154@@ -378,6 +378,7 @@ struct i2c_algorithm {
80155 /* To determine what the adapter supports */
80156 u32 (*functionality) (struct i2c_adapter *);
80157 };
80158+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
80159
80160 /**
80161 * struct i2c_bus_recovery_info - I2C bus recovery information
80162diff --git a/include/linux/i2o.h b/include/linux/i2o.h
80163index d23c3c2..eb63c81 100644
80164--- a/include/linux/i2o.h
80165+++ b/include/linux/i2o.h
80166@@ -565,7 +565,7 @@ struct i2o_controller {
80167 struct i2o_device *exec; /* Executive */
80168 #if BITS_PER_LONG == 64
80169 spinlock_t context_list_lock; /* lock for context_list */
80170- atomic_t context_list_counter; /* needed for unique contexts */
80171+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
80172 struct list_head context_list; /* list of context id's
80173 and pointers */
80174 #endif
80175diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
80176index aff7ad8..3942bbd 100644
80177--- a/include/linux/if_pppox.h
80178+++ b/include/linux/if_pppox.h
80179@@ -76,7 +76,7 @@ struct pppox_proto {
80180 int (*ioctl)(struct socket *sock, unsigned int cmd,
80181 unsigned long arg);
80182 struct module *owner;
80183-};
80184+} __do_const;
80185
80186 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
80187 extern void unregister_pppox_proto(int proto_num);
80188diff --git a/include/linux/init.h b/include/linux/init.h
80189index e168880..d9b489d 100644
80190--- a/include/linux/init.h
80191+++ b/include/linux/init.h
80192@@ -37,9 +37,17 @@
80193 * section.
80194 */
80195
80196+#define add_init_latent_entropy __latent_entropy
80197+
80198+#ifdef CONFIG_MEMORY_HOTPLUG
80199+#define add_meminit_latent_entropy
80200+#else
80201+#define add_meminit_latent_entropy __latent_entropy
80202+#endif
80203+
80204 /* These are for everybody (although not all archs will actually
80205 discard it in modules) */
80206-#define __init __section(.init.text) __cold notrace
80207+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
80208 #define __initdata __section(.init.data)
80209 #define __initconst __constsection(.init.rodata)
80210 #define __exitdata __section(.exit.data)
80211@@ -100,7 +108,7 @@
80212 #define __cpuexitconst
80213
80214 /* Used for MEMORY_HOTPLUG */
80215-#define __meminit __section(.meminit.text) __cold notrace
80216+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
80217 #define __meminitdata __section(.meminit.data)
80218 #define __meminitconst __constsection(.meminit.rodata)
80219 #define __memexit __section(.memexit.text) __exitused __cold notrace
80220diff --git a/include/linux/init_task.h b/include/linux/init_task.h
80221index 6df7f9f..d0bf699 100644
80222--- a/include/linux/init_task.h
80223+++ b/include/linux/init_task.h
80224@@ -156,6 +156,12 @@ extern struct task_group root_task_group;
80225
80226 #define INIT_TASK_COMM "swapper"
80227
80228+#ifdef CONFIG_X86
80229+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
80230+#else
80231+#define INIT_TASK_THREAD_INFO
80232+#endif
80233+
80234 #ifdef CONFIG_RT_MUTEXES
80235 # define INIT_RT_MUTEXES(tsk) \
80236 .pi_waiters = RB_ROOT, \
80237@@ -203,6 +209,7 @@ extern struct task_group root_task_group;
80238 RCU_POINTER_INITIALIZER(cred, &init_cred), \
80239 .comm = INIT_TASK_COMM, \
80240 .thread = INIT_THREAD, \
80241+ INIT_TASK_THREAD_INFO \
80242 .fs = &init_fs, \
80243 .files = &init_files, \
80244 .signal = &init_signals, \
80245diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
80246index a2678d3..e411b1b 100644
80247--- a/include/linux/interrupt.h
80248+++ b/include/linux/interrupt.h
80249@@ -373,8 +373,8 @@ extern const char * const softirq_to_name[NR_SOFTIRQS];
80250
80251 struct softirq_action
80252 {
80253- void (*action)(struct softirq_action *);
80254-};
80255+ void (*action)(void);
80256+} __no_const;
80257
80258 asmlinkage void do_softirq(void);
80259 asmlinkage void __do_softirq(void);
80260@@ -388,7 +388,7 @@ static inline void do_softirq_own_stack(void)
80261 }
80262 #endif
80263
80264-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
80265+extern void open_softirq(int nr, void (*action)(void));
80266 extern void softirq_init(void);
80267 extern void __raise_softirq_irqoff(unsigned int nr);
80268
80269diff --git a/include/linux/iommu.h b/include/linux/iommu.h
80270index b96a5b2..2732d1c 100644
80271--- a/include/linux/iommu.h
80272+++ b/include/linux/iommu.h
80273@@ -131,7 +131,7 @@ struct iommu_ops {
80274 u32 (*domain_get_windows)(struct iommu_domain *domain);
80275
80276 unsigned long pgsize_bitmap;
80277-};
80278+} __do_const;
80279
80280 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
80281 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
80282diff --git a/include/linux/ioport.h b/include/linux/ioport.h
80283index 89b7c24..382af74 100644
80284--- a/include/linux/ioport.h
80285+++ b/include/linux/ioport.h
80286@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
80287 int adjust_resource(struct resource *res, resource_size_t start,
80288 resource_size_t size);
80289 resource_size_t resource_alignment(struct resource *res);
80290-static inline resource_size_t resource_size(const struct resource *res)
80291+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
80292 {
80293 return res->end - res->start + 1;
80294 }
80295diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
80296index 35e7eca..6afb7ad 100644
80297--- a/include/linux/ipc_namespace.h
80298+++ b/include/linux/ipc_namespace.h
80299@@ -69,7 +69,7 @@ struct ipc_namespace {
80300 struct user_namespace *user_ns;
80301
80302 unsigned int proc_inum;
80303-};
80304+} __randomize_layout;
80305
80306 extern struct ipc_namespace init_ipc_ns;
80307 extern atomic_t nr_ipc_ns;
80308diff --git a/include/linux/irq.h b/include/linux/irq.h
80309index 7dc1003..407327b 100644
80310--- a/include/linux/irq.h
80311+++ b/include/linux/irq.h
80312@@ -338,7 +338,8 @@ struct irq_chip {
80313 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
80314
80315 unsigned long flags;
80316-};
80317+} __do_const;
80318+typedef struct irq_chip __no_const irq_chip_no_const;
80319
80320 /*
80321 * irq_chip specific flags
80322diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
80323index 0ceb389..eed3fb8 100644
80324--- a/include/linux/irqchip/arm-gic.h
80325+++ b/include/linux/irqchip/arm-gic.h
80326@@ -73,9 +73,11 @@
80327
80328 #ifndef __ASSEMBLY__
80329
80330+#include <linux/irq.h>
80331+
80332 struct device_node;
80333
80334-extern struct irq_chip gic_arch_extn;
80335+extern irq_chip_no_const gic_arch_extn;
80336
80337 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
80338 u32 offset, struct device_node *);
80339diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
80340index 1f44466..b481806 100644
80341--- a/include/linux/jiffies.h
80342+++ b/include/linux/jiffies.h
80343@@ -292,20 +292,20 @@ extern unsigned long preset_lpj;
80344 /*
80345 * Convert various time units to each other:
80346 */
80347-extern unsigned int jiffies_to_msecs(const unsigned long j);
80348-extern unsigned int jiffies_to_usecs(const unsigned long j);
80349+extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
80350+extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
80351
80352-static inline u64 jiffies_to_nsecs(const unsigned long j)
80353+static inline u64 __intentional_overflow(-1) jiffies_to_nsecs(const unsigned long j)
80354 {
80355 return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC;
80356 }
80357
80358-extern unsigned long msecs_to_jiffies(const unsigned int m);
80359-extern unsigned long usecs_to_jiffies(const unsigned int u);
80360+extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
80361+extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
80362 extern unsigned long timespec_to_jiffies(const struct timespec *value);
80363 extern void jiffies_to_timespec(const unsigned long jiffies,
80364- struct timespec *value);
80365-extern unsigned long timeval_to_jiffies(const struct timeval *value);
80366+ struct timespec *value) __intentional_overflow(-1);
80367+extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
80368 extern void jiffies_to_timeval(const unsigned long jiffies,
80369 struct timeval *value);
80370
80371diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
80372index 6883e19..e854fcb 100644
80373--- a/include/linux/kallsyms.h
80374+++ b/include/linux/kallsyms.h
80375@@ -15,7 +15,8 @@
80376
80377 struct module;
80378
80379-#ifdef CONFIG_KALLSYMS
80380+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
80381+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
80382 /* Lookup the address for a symbol. Returns 0 if not found. */
80383 unsigned long kallsyms_lookup_name(const char *name);
80384
80385@@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
80386 /* Stupid that this does nothing, but I didn't create this mess. */
80387 #define __print_symbol(fmt, addr)
80388 #endif /*CONFIG_KALLSYMS*/
80389+#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
80390+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
80391+extern unsigned long kallsyms_lookup_name(const char *name);
80392+extern void __print_symbol(const char *fmt, unsigned long address);
80393+extern int sprint_backtrace(char *buffer, unsigned long address);
80394+extern int sprint_symbol(char *buffer, unsigned long address);
80395+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
80396+const char *kallsyms_lookup(unsigned long addr,
80397+ unsigned long *symbolsize,
80398+ unsigned long *offset,
80399+ char **modname, char *namebuf);
80400+extern int kallsyms_lookup_size_offset(unsigned long addr,
80401+ unsigned long *symbolsize,
80402+ unsigned long *offset);
80403+#endif
80404
80405 /* This macro allows us to keep printk typechecking */
80406 static __printf(1, 2)
80407diff --git a/include/linux/key-type.h b/include/linux/key-type.h
80408index a74c3a8..28d3f21 100644
80409--- a/include/linux/key-type.h
80410+++ b/include/linux/key-type.h
80411@@ -131,7 +131,7 @@ struct key_type {
80412 /* internal fields */
80413 struct list_head link; /* link in types list */
80414 struct lock_class_key lock_class; /* key->sem lock class */
80415-};
80416+} __do_const;
80417
80418 extern struct key_type key_type_keyring;
80419
80420diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
80421index 6b06d37..c134867 100644
80422--- a/include/linux/kgdb.h
80423+++ b/include/linux/kgdb.h
80424@@ -52,7 +52,7 @@ extern int kgdb_connected;
80425 extern int kgdb_io_module_registered;
80426
80427 extern atomic_t kgdb_setting_breakpoint;
80428-extern atomic_t kgdb_cpu_doing_single_step;
80429+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
80430
80431 extern struct task_struct *kgdb_usethread;
80432 extern struct task_struct *kgdb_contthread;
80433@@ -254,7 +254,7 @@ struct kgdb_arch {
80434 void (*correct_hw_break)(void);
80435
80436 void (*enable_nmi)(bool on);
80437-};
80438+} __do_const;
80439
80440 /**
80441 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
80442@@ -279,7 +279,7 @@ struct kgdb_io {
80443 void (*pre_exception) (void);
80444 void (*post_exception) (void);
80445 int is_console;
80446-};
80447+} __do_const;
80448
80449 extern struct kgdb_arch arch_kgdb_ops;
80450
80451diff --git a/include/linux/kmod.h b/include/linux/kmod.h
80452index 0555cc6..40116ce 100644
80453--- a/include/linux/kmod.h
80454+++ b/include/linux/kmod.h
80455@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
80456 * usually useless though. */
80457 extern __printf(2, 3)
80458 int __request_module(bool wait, const char *name, ...);
80459+extern __printf(3, 4)
80460+int ___request_module(bool wait, char *param_name, const char *name, ...);
80461 #define request_module(mod...) __request_module(true, mod)
80462 #define request_module_nowait(mod...) __request_module(false, mod)
80463 #define try_then_request_module(x, mod...) \
80464@@ -57,6 +59,9 @@ struct subprocess_info {
80465 struct work_struct work;
80466 struct completion *complete;
80467 char *path;
80468+#ifdef CONFIG_GRKERNSEC
80469+ char *origpath;
80470+#endif
80471 char **argv;
80472 char **envp;
80473 int wait;
80474diff --git a/include/linux/kobject.h b/include/linux/kobject.h
80475index 926afb6..58dd6e5 100644
80476--- a/include/linux/kobject.h
80477+++ b/include/linux/kobject.h
80478@@ -116,7 +116,7 @@ struct kobj_type {
80479 struct attribute **default_attrs;
80480 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
80481 const void *(*namespace)(struct kobject *kobj);
80482-};
80483+} __do_const;
80484
80485 struct kobj_uevent_env {
80486 char *envp[UEVENT_NUM_ENVP];
80487@@ -139,6 +139,7 @@ struct kobj_attribute {
80488 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
80489 const char *buf, size_t count);
80490 };
80491+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
80492
80493 extern const struct sysfs_ops kobj_sysfs_ops;
80494
80495@@ -166,7 +167,7 @@ struct kset {
80496 spinlock_t list_lock;
80497 struct kobject kobj;
80498 const struct kset_uevent_ops *uevent_ops;
80499-};
80500+} __randomize_layout;
80501
80502 extern void kset_init(struct kset *kset);
80503 extern int __must_check kset_register(struct kset *kset);
80504diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
80505index df32d25..fb52e27 100644
80506--- a/include/linux/kobject_ns.h
80507+++ b/include/linux/kobject_ns.h
80508@@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
80509 const void *(*netlink_ns)(struct sock *sk);
80510 const void *(*initial_ns)(void);
80511 void (*drop_ns)(void *);
80512-};
80513+} __do_const;
80514
80515 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
80516 int kobj_ns_type_registered(enum kobj_ns_type type);
80517diff --git a/include/linux/kref.h b/include/linux/kref.h
80518index 484604d..0f6c5b6 100644
80519--- a/include/linux/kref.h
80520+++ b/include/linux/kref.h
80521@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
80522 static inline int kref_sub(struct kref *kref, unsigned int count,
80523 void (*release)(struct kref *kref))
80524 {
80525- WARN_ON(release == NULL);
80526+ BUG_ON(release == NULL);
80527
80528 if (atomic_sub_and_test((int) count, &kref->refcount)) {
80529 release(kref);
80530diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
80531index b8e9a43..632678d 100644
80532--- a/include/linux/kvm_host.h
80533+++ b/include/linux/kvm_host.h
80534@@ -455,7 +455,7 @@ static inline void kvm_irqfd_exit(void)
80535 {
80536 }
80537 #endif
80538-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
80539+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
80540 struct module *module);
80541 void kvm_exit(void);
80542
80543@@ -621,7 +621,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
80544 struct kvm_guest_debug *dbg);
80545 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
80546
80547-int kvm_arch_init(void *opaque);
80548+int kvm_arch_init(const void *opaque);
80549 void kvm_arch_exit(void);
80550
80551 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
80552diff --git a/include/linux/libata.h b/include/linux/libata.h
80553index bec6dbe..2873d64 100644
80554--- a/include/linux/libata.h
80555+++ b/include/linux/libata.h
80556@@ -975,7 +975,7 @@ struct ata_port_operations {
80557 * fields must be pointers.
80558 */
80559 const struct ata_port_operations *inherits;
80560-};
80561+} __do_const;
80562
80563 struct ata_port_info {
80564 unsigned long flags;
80565diff --git a/include/linux/linkage.h b/include/linux/linkage.h
80566index a6a42dd..6c5ebce 100644
80567--- a/include/linux/linkage.h
80568+++ b/include/linux/linkage.h
80569@@ -36,6 +36,7 @@
80570 #endif
80571
80572 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
80573+#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
80574 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
80575
80576 /*
80577diff --git a/include/linux/list.h b/include/linux/list.h
80578index ef95941..82db65a 100644
80579--- a/include/linux/list.h
80580+++ b/include/linux/list.h
80581@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
80582 extern void list_del(struct list_head *entry);
80583 #endif
80584
80585+extern void __pax_list_add(struct list_head *new,
80586+ struct list_head *prev,
80587+ struct list_head *next);
80588+static inline void pax_list_add(struct list_head *new, struct list_head *head)
80589+{
80590+ __pax_list_add(new, head, head->next);
80591+}
80592+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
80593+{
80594+ __pax_list_add(new, head->prev, head);
80595+}
80596+extern void pax_list_del(struct list_head *entry);
80597+
80598 /**
80599 * list_replace - replace old entry by new one
80600 * @old : the element to be replaced
80601@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
80602 INIT_LIST_HEAD(entry);
80603 }
80604
80605+extern void pax_list_del_init(struct list_head *entry);
80606+
80607 /**
80608 * list_move - delete from one list and add as another's head
80609 * @list: the entry to move
80610diff --git a/include/linux/math64.h b/include/linux/math64.h
80611index c45c089..298841c 100644
80612--- a/include/linux/math64.h
80613+++ b/include/linux/math64.h
80614@@ -15,7 +15,7 @@
80615 * This is commonly provided by 32bit archs to provide an optimized 64bit
80616 * divide.
80617 */
80618-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80619+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80620 {
80621 *remainder = dividend % divisor;
80622 return dividend / divisor;
80623@@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
80624 /**
80625 * div64_u64 - unsigned 64bit divide with 64bit divisor
80626 */
80627-static inline u64 div64_u64(u64 dividend, u64 divisor)
80628+static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
80629 {
80630 return dividend / divisor;
80631 }
80632@@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
80633 #define div64_ul(x, y) div_u64((x), (y))
80634
80635 #ifndef div_u64_rem
80636-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80637+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80638 {
80639 *remainder = do_div(dividend, divisor);
80640 return dividend;
80641@@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
80642 #endif
80643
80644 #ifndef div64_u64
80645-extern u64 div64_u64(u64 dividend, u64 divisor);
80646+extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
80647 #endif
80648
80649 #ifndef div64_s64
80650@@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
80651 * divide.
80652 */
80653 #ifndef div_u64
80654-static inline u64 div_u64(u64 dividend, u32 divisor)
80655+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
80656 {
80657 u32 remainder;
80658 return div_u64_rem(dividend, divisor, &remainder);
80659diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
80660index 5f1ea75..5125ac5 100644
80661--- a/include/linux/mempolicy.h
80662+++ b/include/linux/mempolicy.h
80663@@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
80664 }
80665
80666 #define vma_policy(vma) ((vma)->vm_policy)
80667+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
80668+{
80669+ vma->vm_policy = pol;
80670+}
80671
80672 static inline void mpol_get(struct mempolicy *pol)
80673 {
80674@@ -223,6 +227,9 @@ static inline void mpol_free_shared_policy(struct shared_policy *p)
80675 }
80676
80677 #define vma_policy(vma) NULL
80678+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
80679+{
80680+}
80681
80682 static inline int
80683 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
80684diff --git a/include/linux/mm.h b/include/linux/mm.h
80685index c1b7414..5ea2ad8 100644
80686--- a/include/linux/mm.h
80687+++ b/include/linux/mm.h
80688@@ -127,6 +127,11 @@ extern unsigned int kobjsize(const void *objp);
80689 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
80690 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
80691 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
80692+
80693+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
80694+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
80695+#endif
80696+
80697 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
80698
80699 #ifdef CONFIG_MEM_SOFT_DIRTY
80700@@ -229,8 +234,8 @@ struct vm_operations_struct {
80701 /* called by access_process_vm when get_user_pages() fails, typically
80702 * for use by special VMAs that can switch between memory and hardware
80703 */
80704- int (*access)(struct vm_area_struct *vma, unsigned long addr,
80705- void *buf, int len, int write);
80706+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
80707+ void *buf, size_t len, int write);
80708 #ifdef CONFIG_NUMA
80709 /*
80710 * set_policy() op must add a reference to any non-NULL @new mempolicy
80711@@ -260,6 +265,7 @@ struct vm_operations_struct {
80712 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
80713 unsigned long size, pgoff_t pgoff);
80714 };
80715+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
80716
80717 struct mmu_gather;
80718 struct inode;
80719@@ -1112,8 +1118,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
80720 unsigned long *pfn);
80721 int follow_phys(struct vm_area_struct *vma, unsigned long address,
80722 unsigned int flags, unsigned long *prot, resource_size_t *phys);
80723-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
80724- void *buf, int len, int write);
80725+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
80726+ void *buf, size_t len, int write);
80727
80728 static inline void unmap_shared_mapping_range(struct address_space *mapping,
80729 loff_t const holebegin, loff_t const holelen)
80730@@ -1152,9 +1158,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
80731 }
80732 #endif
80733
80734-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
80735-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
80736- void *buf, int len, int write);
80737+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
80738+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
80739+ void *buf, size_t len, int write);
80740
80741 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
80742 unsigned long start, unsigned long nr_pages,
80743@@ -1186,34 +1192,6 @@ int set_page_dirty(struct page *page);
80744 int set_page_dirty_lock(struct page *page);
80745 int clear_page_dirty_for_io(struct page *page);
80746
80747-/* Is the vma a continuation of the stack vma above it? */
80748-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
80749-{
80750- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
80751-}
80752-
80753-static inline int stack_guard_page_start(struct vm_area_struct *vma,
80754- unsigned long addr)
80755-{
80756- return (vma->vm_flags & VM_GROWSDOWN) &&
80757- (vma->vm_start == addr) &&
80758- !vma_growsdown(vma->vm_prev, addr);
80759-}
80760-
80761-/* Is the vma a continuation of the stack vma below it? */
80762-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
80763-{
80764- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
80765-}
80766-
80767-static inline int stack_guard_page_end(struct vm_area_struct *vma,
80768- unsigned long addr)
80769-{
80770- return (vma->vm_flags & VM_GROWSUP) &&
80771- (vma->vm_end == addr) &&
80772- !vma_growsup(vma->vm_next, addr);
80773-}
80774-
80775 extern pid_t
80776 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
80777
80778@@ -1313,6 +1291,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
80779 }
80780 #endif
80781
80782+#ifdef CONFIG_MMU
80783+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
80784+#else
80785+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
80786+{
80787+ return __pgprot(0);
80788+}
80789+#endif
80790+
80791 int vma_wants_writenotify(struct vm_area_struct *vma);
80792
80793 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
80794@@ -1331,8 +1318,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
80795 {
80796 return 0;
80797 }
80798+
80799+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
80800+ unsigned long address)
80801+{
80802+ return 0;
80803+}
80804 #else
80805 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
80806+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
80807 #endif
80808
80809 #ifdef __PAGETABLE_PMD_FOLDED
80810@@ -1341,8 +1335,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
80811 {
80812 return 0;
80813 }
80814+
80815+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
80816+ unsigned long address)
80817+{
80818+ return 0;
80819+}
80820 #else
80821 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
80822+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
80823 #endif
80824
80825 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
80826@@ -1360,11 +1361,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
80827 NULL: pud_offset(pgd, address);
80828 }
80829
80830+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
80831+{
80832+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
80833+ NULL: pud_offset(pgd, address);
80834+}
80835+
80836 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
80837 {
80838 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
80839 NULL: pmd_offset(pud, address);
80840 }
80841+
80842+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
80843+{
80844+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
80845+ NULL: pmd_offset(pud, address);
80846+}
80847 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
80848
80849 #if USE_SPLIT_PTE_PTLOCKS
80850@@ -1754,7 +1767,7 @@ extern int install_special_mapping(struct mm_struct *mm,
80851 unsigned long addr, unsigned long len,
80852 unsigned long flags, struct page **pages);
80853
80854-extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
80855+extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
80856
80857 extern unsigned long mmap_region(struct file *file, unsigned long addr,
80858 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
80859@@ -1762,6 +1775,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
80860 unsigned long len, unsigned long prot, unsigned long flags,
80861 unsigned long pgoff, unsigned long *populate);
80862 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
80863+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
80864
80865 #ifdef CONFIG_MMU
80866 extern int __mm_populate(unsigned long addr, unsigned long len,
80867@@ -1790,10 +1804,11 @@ struct vm_unmapped_area_info {
80868 unsigned long high_limit;
80869 unsigned long align_mask;
80870 unsigned long align_offset;
80871+ unsigned long threadstack_offset;
80872 };
80873
80874-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
80875-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
80876+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
80877+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
80878
80879 /*
80880 * Search for an unmapped address range.
80881@@ -1805,7 +1820,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
80882 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
80883 */
80884 static inline unsigned long
80885-vm_unmapped_area(struct vm_unmapped_area_info *info)
80886+vm_unmapped_area(const struct vm_unmapped_area_info *info)
80887 {
80888 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
80889 return unmapped_area(info);
80890@@ -1868,6 +1883,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
80891 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
80892 struct vm_area_struct **pprev);
80893
80894+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
80895+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
80896+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
80897+
80898 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
80899 NULL if none. Assume start_addr < end_addr. */
80900 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
80901@@ -1896,15 +1915,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
80902 return vma;
80903 }
80904
80905-#ifdef CONFIG_MMU
80906-pgprot_t vm_get_page_prot(unsigned long vm_flags);
80907-#else
80908-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
80909-{
80910- return __pgprot(0);
80911-}
80912-#endif
80913-
80914 #ifdef CONFIG_NUMA_BALANCING
80915 unsigned long change_prot_numa(struct vm_area_struct *vma,
80916 unsigned long start, unsigned long end);
80917@@ -1956,6 +1966,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
80918 static inline void vm_stat_account(struct mm_struct *mm,
80919 unsigned long flags, struct file *file, long pages)
80920 {
80921+
80922+#ifdef CONFIG_PAX_RANDMMAP
80923+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
80924+#endif
80925+
80926 mm->total_vm += pages;
80927 }
80928 #endif /* CONFIG_PROC_FS */
80929@@ -2037,7 +2052,7 @@ extern int unpoison_memory(unsigned long pfn);
80930 extern int sysctl_memory_failure_early_kill;
80931 extern int sysctl_memory_failure_recovery;
80932 extern void shake_page(struct page *p, int access);
80933-extern atomic_long_t num_poisoned_pages;
80934+extern atomic_long_unchecked_t num_poisoned_pages;
80935 extern int soft_offline_page(struct page *page, int flags);
80936
80937 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
80938@@ -2072,5 +2087,11 @@ void __init setup_nr_node_ids(void);
80939 static inline void setup_nr_node_ids(void) {}
80940 #endif
80941
80942+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
80943+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
80944+#else
80945+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
80946+#endif
80947+
80948 #endif /* __KERNEL__ */
80949 #endif /* _LINUX_MM_H */
80950diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
80951index 290901a..e99b01c 100644
80952--- a/include/linux/mm_types.h
80953+++ b/include/linux/mm_types.h
80954@@ -307,7 +307,9 @@ struct vm_area_struct {
80955 #ifdef CONFIG_NUMA
80956 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
80957 #endif
80958-};
80959+
80960+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
80961+} __randomize_layout;
80962
80963 struct core_thread {
80964 struct task_struct *task;
80965@@ -453,7 +455,25 @@ struct mm_struct {
80966 bool tlb_flush_pending;
80967 #endif
80968 struct uprobes_state uprobes_state;
80969-};
80970+
80971+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
80972+ unsigned long pax_flags;
80973+#endif
80974+
80975+#ifdef CONFIG_PAX_DLRESOLVE
80976+ unsigned long call_dl_resolve;
80977+#endif
80978+
80979+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
80980+ unsigned long call_syscall;
80981+#endif
80982+
80983+#ifdef CONFIG_PAX_ASLR
80984+ unsigned long delta_mmap; /* randomized offset */
80985+ unsigned long delta_stack; /* randomized offset */
80986+#endif
80987+
80988+} __randomize_layout;
80989
80990 static inline void mm_init_cpumask(struct mm_struct *mm)
80991 {
80992diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
80993index c5d5278..f0b68c8 100644
80994--- a/include/linux/mmiotrace.h
80995+++ b/include/linux/mmiotrace.h
80996@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
80997 /* Called from ioremap.c */
80998 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
80999 void __iomem *addr);
81000-extern void mmiotrace_iounmap(volatile void __iomem *addr);
81001+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
81002
81003 /* For anyone to insert markers. Remember trailing newline. */
81004 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
81005@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
81006 {
81007 }
81008
81009-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
81010+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
81011 {
81012 }
81013
81014diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
81015index 9b61b9b..52147d6b 100644
81016--- a/include/linux/mmzone.h
81017+++ b/include/linux/mmzone.h
81018@@ -396,7 +396,7 @@ struct zone {
81019 unsigned long flags; /* zone flags, see below */
81020
81021 /* Zone statistics */
81022- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
81023+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
81024
81025 /*
81026 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
81027diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
81028index 45e9214..a7227d6 100644
81029--- a/include/linux/mod_devicetable.h
81030+++ b/include/linux/mod_devicetable.h
81031@@ -13,7 +13,7 @@
81032 typedef unsigned long kernel_ulong_t;
81033 #endif
81034
81035-#define PCI_ANY_ID (~0)
81036+#define PCI_ANY_ID ((__u16)~0)
81037
81038 struct pci_device_id {
81039 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
81040@@ -139,7 +139,7 @@ struct usb_device_id {
81041 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
81042 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
81043
81044-#define HID_ANY_ID (~0)
81045+#define HID_ANY_ID (~0U)
81046 #define HID_BUS_ANY 0xffff
81047 #define HID_GROUP_ANY 0x0000
81048
81049@@ -467,7 +467,7 @@ struct dmi_system_id {
81050 const char *ident;
81051 struct dmi_strmatch matches[4];
81052 void *driver_data;
81053-};
81054+} __do_const;
81055 /*
81056 * struct dmi_device_id appears during expansion of
81057 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
81058diff --git a/include/linux/module.h b/include/linux/module.h
81059index eaf60ff..641979a 100644
81060--- a/include/linux/module.h
81061+++ b/include/linux/module.h
81062@@ -17,9 +17,11 @@
81063 #include <linux/moduleparam.h>
81064 #include <linux/tracepoint.h>
81065 #include <linux/export.h>
81066+#include <linux/fs.h>
81067
81068 #include <linux/percpu.h>
81069 #include <asm/module.h>
81070+#include <asm/pgtable.h>
81071
81072 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
81073 #define MODULE_SIG_STRING "~Module signature appended~\n"
81074@@ -42,7 +44,7 @@ struct module_kobject {
81075 struct kobject *drivers_dir;
81076 struct module_param_attrs *mp;
81077 struct completion *kobj_completion;
81078-};
81079+} __randomize_layout;
81080
81081 struct module_attribute {
81082 struct attribute attr;
81083@@ -54,12 +56,13 @@ struct module_attribute {
81084 int (*test)(struct module *);
81085 void (*free)(struct module *);
81086 };
81087+typedef struct module_attribute __no_const module_attribute_no_const;
81088
81089 struct module_version_attribute {
81090 struct module_attribute mattr;
81091 const char *module_name;
81092 const char *version;
81093-} __attribute__ ((__aligned__(sizeof(void *))));
81094+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
81095
81096 extern ssize_t __modver_version_show(struct module_attribute *,
81097 struct module_kobject *, char *);
81098@@ -238,7 +241,7 @@ struct module {
81099
81100 /* Sysfs stuff. */
81101 struct module_kobject mkobj;
81102- struct module_attribute *modinfo_attrs;
81103+ module_attribute_no_const *modinfo_attrs;
81104 const char *version;
81105 const char *srcversion;
81106 struct kobject *holders_dir;
81107@@ -287,19 +290,16 @@ struct module {
81108 int (*init)(void);
81109
81110 /* If this is non-NULL, vfree after init() returns */
81111- void *module_init;
81112+ void *module_init_rx, *module_init_rw;
81113
81114 /* Here is the actual code + data, vfree'd on unload. */
81115- void *module_core;
81116+ void *module_core_rx, *module_core_rw;
81117
81118 /* Here are the sizes of the init and core sections */
81119- unsigned int init_size, core_size;
81120+ unsigned int init_size_rw, core_size_rw;
81121
81122 /* The size of the executable code in each section. */
81123- unsigned int init_text_size, core_text_size;
81124-
81125- /* Size of RO sections of the module (text+rodata) */
81126- unsigned int init_ro_size, core_ro_size;
81127+ unsigned int init_size_rx, core_size_rx;
81128
81129 /* Arch-specific module values */
81130 struct mod_arch_specific arch;
81131@@ -355,6 +355,10 @@ struct module {
81132 #ifdef CONFIG_EVENT_TRACING
81133 struct ftrace_event_call **trace_events;
81134 unsigned int num_trace_events;
81135+ struct file_operations trace_id;
81136+ struct file_operations trace_enable;
81137+ struct file_operations trace_format;
81138+ struct file_operations trace_filter;
81139 #endif
81140 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
81141 unsigned int num_ftrace_callsites;
81142@@ -378,7 +382,7 @@ struct module {
81143 ctor_fn_t *ctors;
81144 unsigned int num_ctors;
81145 #endif
81146-};
81147+} __randomize_layout;
81148 #ifndef MODULE_ARCH_INIT
81149 #define MODULE_ARCH_INIT {}
81150 #endif
81151@@ -399,16 +403,46 @@ bool is_module_address(unsigned long addr);
81152 bool is_module_percpu_address(unsigned long addr);
81153 bool is_module_text_address(unsigned long addr);
81154
81155+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
81156+{
81157+
81158+#ifdef CONFIG_PAX_KERNEXEC
81159+ if (ktla_ktva(addr) >= (unsigned long)start &&
81160+ ktla_ktva(addr) < (unsigned long)start + size)
81161+ return 1;
81162+#endif
81163+
81164+ return ((void *)addr >= start && (void *)addr < start + size);
81165+}
81166+
81167+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
81168+{
81169+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
81170+}
81171+
81172+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
81173+{
81174+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
81175+}
81176+
81177+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
81178+{
81179+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
81180+}
81181+
81182+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
81183+{
81184+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
81185+}
81186+
81187 static inline int within_module_core(unsigned long addr, const struct module *mod)
81188 {
81189- return (unsigned long)mod->module_core <= addr &&
81190- addr < (unsigned long)mod->module_core + mod->core_size;
81191+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
81192 }
81193
81194 static inline int within_module_init(unsigned long addr, const struct module *mod)
81195 {
81196- return (unsigned long)mod->module_init <= addr &&
81197- addr < (unsigned long)mod->module_init + mod->init_size;
81198+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
81199 }
81200
81201 /* Search for module by name: must hold module_mutex. */
81202diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
81203index 560ca53..ef621ef 100644
81204--- a/include/linux/moduleloader.h
81205+++ b/include/linux/moduleloader.h
81206@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
81207 sections. Returns NULL on failure. */
81208 void *module_alloc(unsigned long size);
81209
81210+#ifdef CONFIG_PAX_KERNEXEC
81211+void *module_alloc_exec(unsigned long size);
81212+#else
81213+#define module_alloc_exec(x) module_alloc(x)
81214+#endif
81215+
81216 /* Free memory returned from module_alloc. */
81217 void module_free(struct module *mod, void *module_region);
81218
81219+#ifdef CONFIG_PAX_KERNEXEC
81220+void module_free_exec(struct module *mod, void *module_region);
81221+#else
81222+#define module_free_exec(x, y) module_free((x), (y))
81223+#endif
81224+
81225 /*
81226 * Apply the given relocation to the (simplified) ELF. Return -error
81227 * or 0.
81228@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
81229 unsigned int relsec,
81230 struct module *me)
81231 {
81232+#ifdef CONFIG_MODULES
81233 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
81234+#endif
81235 return -ENOEXEC;
81236 }
81237 #endif
81238@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
81239 unsigned int relsec,
81240 struct module *me)
81241 {
81242+#ifdef CONFIG_MODULES
81243 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
81244+#endif
81245 return -ENOEXEC;
81246 }
81247 #endif
81248diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
81249index c3eb102..073c4a6 100644
81250--- a/include/linux/moduleparam.h
81251+++ b/include/linux/moduleparam.h
81252@@ -295,7 +295,7 @@ static inline void __kernel_param_unlock(void)
81253 * @len is usually just sizeof(string).
81254 */
81255 #define module_param_string(name, string, len, perm) \
81256- static const struct kparam_string __param_string_##name \
81257+ static const struct kparam_string __param_string_##name __used \
81258 = { len, string }; \
81259 __module_param_call(MODULE_PARAM_PREFIX, name, \
81260 &param_ops_string, \
81261@@ -434,7 +434,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
81262 */
81263 #define module_param_array_named(name, array, type, nump, perm) \
81264 param_check_##type(name, &(array)[0]); \
81265- static const struct kparam_array __param_arr_##name \
81266+ static const struct kparam_array __param_arr_##name __used \
81267 = { .max = ARRAY_SIZE(array), .num = nump, \
81268 .ops = &param_ops_##type, \
81269 .elemsize = sizeof(array[0]), .elem = array }; \
81270diff --git a/include/linux/mount.h b/include/linux/mount.h
81271index 839bac2..a96b37c 100644
81272--- a/include/linux/mount.h
81273+++ b/include/linux/mount.h
81274@@ -59,7 +59,7 @@ struct vfsmount {
81275 struct dentry *mnt_root; /* root of the mounted tree */
81276 struct super_block *mnt_sb; /* pointer to superblock */
81277 int mnt_flags;
81278-};
81279+} __randomize_layout;
81280
81281 struct file; /* forward dec */
81282
81283diff --git a/include/linux/namei.h b/include/linux/namei.h
81284index 492de72..1bddcd4 100644
81285--- a/include/linux/namei.h
81286+++ b/include/linux/namei.h
81287@@ -19,7 +19,7 @@ struct nameidata {
81288 unsigned seq, m_seq;
81289 int last_type;
81290 unsigned depth;
81291- char *saved_names[MAX_NESTED_LINKS + 1];
81292+ const char *saved_names[MAX_NESTED_LINKS + 1];
81293 };
81294
81295 /*
81296@@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
81297
81298 extern void nd_jump_link(struct nameidata *nd, struct path *path);
81299
81300-static inline void nd_set_link(struct nameidata *nd, char *path)
81301+static inline void nd_set_link(struct nameidata *nd, const char *path)
81302 {
81303 nd->saved_names[nd->depth] = path;
81304 }
81305
81306-static inline char *nd_get_link(struct nameidata *nd)
81307+static inline const char *nd_get_link(const struct nameidata *nd)
81308 {
81309 return nd->saved_names[nd->depth];
81310 }
81311diff --git a/include/linux/net.h b/include/linux/net.h
81312index 94734a6..d8d6931 100644
81313--- a/include/linux/net.h
81314+++ b/include/linux/net.h
81315@@ -192,7 +192,7 @@ struct net_proto_family {
81316 int (*create)(struct net *net, struct socket *sock,
81317 int protocol, int kern);
81318 struct module *owner;
81319-};
81320+} __do_const;
81321
81322 struct iovec;
81323 struct kvec;
81324diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
81325index daafd95..74c5d1e 100644
81326--- a/include/linux/netdevice.h
81327+++ b/include/linux/netdevice.h
81328@@ -1146,6 +1146,7 @@ struct net_device_ops {
81329 struct net_device *dev,
81330 void *priv);
81331 };
81332+typedef struct net_device_ops __no_const net_device_ops_no_const;
81333
81334 /*
81335 * The DEVICE structure.
81336@@ -1228,7 +1229,7 @@ struct net_device {
81337 int iflink;
81338
81339 struct net_device_stats stats;
81340- atomic_long_t rx_dropped; /* dropped packets by core network
81341+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
81342 * Do not use this in drivers.
81343 */
81344
81345diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
81346index 2077489..a15e561 100644
81347--- a/include/linux/netfilter.h
81348+++ b/include/linux/netfilter.h
81349@@ -84,7 +84,7 @@ struct nf_sockopt_ops {
81350 #endif
81351 /* Use the module struct to lock set/get code in place */
81352 struct module *owner;
81353-};
81354+} __do_const;
81355
81356 /* Function to register/unregister hook points. */
81357 int nf_register_hook(struct nf_hook_ops *reg);
81358diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
81359index 28c7436..2d6156a 100644
81360--- a/include/linux/netfilter/nfnetlink.h
81361+++ b/include/linux/netfilter/nfnetlink.h
81362@@ -19,7 +19,7 @@ struct nfnl_callback {
81363 const struct nlattr * const cda[]);
81364 const struct nla_policy *policy; /* netlink attribute policy */
81365 const u_int16_t attr_count; /* number of nlattr's */
81366-};
81367+} __do_const;
81368
81369 struct nfnetlink_subsystem {
81370 const char *name;
81371diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
81372new file mode 100644
81373index 0000000..33f4af8
81374--- /dev/null
81375+++ b/include/linux/netfilter/xt_gradm.h
81376@@ -0,0 +1,9 @@
81377+#ifndef _LINUX_NETFILTER_XT_GRADM_H
81378+#define _LINUX_NETFILTER_XT_GRADM_H 1
81379+
81380+struct xt_gradm_mtinfo {
81381+ __u16 flags;
81382+ __u16 invflags;
81383+};
81384+
81385+#endif
81386diff --git a/include/linux/nls.h b/include/linux/nls.h
81387index 520681b..1d67ed2 100644
81388--- a/include/linux/nls.h
81389+++ b/include/linux/nls.h
81390@@ -31,7 +31,7 @@ struct nls_table {
81391 const unsigned char *charset2upper;
81392 struct module *owner;
81393 struct nls_table *next;
81394-};
81395+} __do_const;
81396
81397 /* this value hold the maximum octet of charset */
81398 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
81399diff --git a/include/linux/notifier.h b/include/linux/notifier.h
81400index d14a4c3..a078786 100644
81401--- a/include/linux/notifier.h
81402+++ b/include/linux/notifier.h
81403@@ -54,7 +54,8 @@ struct notifier_block {
81404 notifier_fn_t notifier_call;
81405 struct notifier_block __rcu *next;
81406 int priority;
81407-};
81408+} __do_const;
81409+typedef struct notifier_block __no_const notifier_block_no_const;
81410
81411 struct atomic_notifier_head {
81412 spinlock_t lock;
81413diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
81414index b2a0f15..4d7da32 100644
81415--- a/include/linux/oprofile.h
81416+++ b/include/linux/oprofile.h
81417@@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
81418 int oprofilefs_create_ro_ulong(struct dentry * root,
81419 char const * name, ulong * val);
81420
81421-/** Create a file for read-only access to an atomic_t. */
81422+/** Create a file for read-only access to an atomic_unchecked_t. */
81423 int oprofilefs_create_ro_atomic(struct dentry * root,
81424- char const * name, atomic_t * val);
81425+ char const * name, atomic_unchecked_t * val);
81426
81427 /** create a directory */
81428 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
81429diff --git a/include/linux/padata.h b/include/linux/padata.h
81430index 4386946..f50c615 100644
81431--- a/include/linux/padata.h
81432+++ b/include/linux/padata.h
81433@@ -129,7 +129,7 @@ struct parallel_data {
81434 struct padata_serial_queue __percpu *squeue;
81435 atomic_t reorder_objects;
81436 atomic_t refcnt;
81437- atomic_t seq_nr;
81438+ atomic_unchecked_t seq_nr;
81439 struct padata_cpumask cpumask;
81440 spinlock_t lock ____cacheline_aligned;
81441 unsigned int processed;
81442diff --git a/include/linux/path.h b/include/linux/path.h
81443index d137218..be0c176 100644
81444--- a/include/linux/path.h
81445+++ b/include/linux/path.h
81446@@ -1,13 +1,15 @@
81447 #ifndef _LINUX_PATH_H
81448 #define _LINUX_PATH_H
81449
81450+#include <linux/compiler.h>
81451+
81452 struct dentry;
81453 struct vfsmount;
81454
81455 struct path {
81456 struct vfsmount *mnt;
81457 struct dentry *dentry;
81458-};
81459+} __randomize_layout;
81460
81461 extern void path_get(const struct path *);
81462 extern void path_put(const struct path *);
81463diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
81464index 5f2e559..7d59314 100644
81465--- a/include/linux/pci_hotplug.h
81466+++ b/include/linux/pci_hotplug.h
81467@@ -71,7 +71,8 @@ struct hotplug_slot_ops {
81468 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
81469 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
81470 int (*reset_slot) (struct hotplug_slot *slot, int probe);
81471-};
81472+} __do_const;
81473+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
81474
81475 /**
81476 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
81477diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
81478index e56b07f..aef789b 100644
81479--- a/include/linux/perf_event.h
81480+++ b/include/linux/perf_event.h
81481@@ -328,8 +328,8 @@ struct perf_event {
81482
81483 enum perf_event_active_state state;
81484 unsigned int attach_state;
81485- local64_t count;
81486- atomic64_t child_count;
81487+ local64_t count; /* PaX: fix it one day */
81488+ atomic64_unchecked_t child_count;
81489
81490 /*
81491 * These are the total time in nanoseconds that the event
81492@@ -380,8 +380,8 @@ struct perf_event {
81493 * These accumulate total time (in nanoseconds) that children
81494 * events have been enabled and running, respectively.
81495 */
81496- atomic64_t child_total_time_enabled;
81497- atomic64_t child_total_time_running;
81498+ atomic64_unchecked_t child_total_time_enabled;
81499+ atomic64_unchecked_t child_total_time_running;
81500
81501 /*
81502 * Protect attach/detach and child_list:
81503@@ -708,7 +708,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
81504 entry->ip[entry->nr++] = ip;
81505 }
81506
81507-extern int sysctl_perf_event_paranoid;
81508+extern int sysctl_perf_event_legitimately_concerned;
81509 extern int sysctl_perf_event_mlock;
81510 extern int sysctl_perf_event_sample_rate;
81511 extern int sysctl_perf_cpu_time_max_percent;
81512@@ -723,19 +723,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
81513 loff_t *ppos);
81514
81515
81516+static inline bool perf_paranoid_any(void)
81517+{
81518+ return sysctl_perf_event_legitimately_concerned > 2;
81519+}
81520+
81521 static inline bool perf_paranoid_tracepoint_raw(void)
81522 {
81523- return sysctl_perf_event_paranoid > -1;
81524+ return sysctl_perf_event_legitimately_concerned > -1;
81525 }
81526
81527 static inline bool perf_paranoid_cpu(void)
81528 {
81529- return sysctl_perf_event_paranoid > 0;
81530+ return sysctl_perf_event_legitimately_concerned > 0;
81531 }
81532
81533 static inline bool perf_paranoid_kernel(void)
81534 {
81535- return sysctl_perf_event_paranoid > 1;
81536+ return sysctl_perf_event_legitimately_concerned > 1;
81537 }
81538
81539 extern void perf_event_init(void);
81540@@ -851,7 +856,7 @@ struct perf_pmu_events_attr {
81541 struct device_attribute attr;
81542 u64 id;
81543 const char *event_str;
81544-};
81545+} __do_const;
81546
81547 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
81548 static struct perf_pmu_events_attr _var = { \
81549diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
81550index 7246ef3..1539ea4 100644
81551--- a/include/linux/pid_namespace.h
81552+++ b/include/linux/pid_namespace.h
81553@@ -43,7 +43,7 @@ struct pid_namespace {
81554 int hide_pid;
81555 int reboot; /* group exit code if this pidns was rebooted */
81556 unsigned int proc_inum;
81557-};
81558+} __randomize_layout;
81559
81560 extern struct pid_namespace init_pid_ns;
81561
81562diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
81563index ab57526..94598804 100644
81564--- a/include/linux/pipe_fs_i.h
81565+++ b/include/linux/pipe_fs_i.h
81566@@ -47,10 +47,10 @@ struct pipe_inode_info {
81567 struct mutex mutex;
81568 wait_queue_head_t wait;
81569 unsigned int nrbufs, curbuf, buffers;
81570- unsigned int readers;
81571- unsigned int writers;
81572- unsigned int files;
81573- unsigned int waiting_writers;
81574+ atomic_t readers;
81575+ atomic_t writers;
81576+ atomic_t files;
81577+ atomic_t waiting_writers;
81578 unsigned int r_counter;
81579 unsigned int w_counter;
81580 struct page *tmp_page;
81581diff --git a/include/linux/pm.h b/include/linux/pm.h
81582index 8c6583a..febb84c 100644
81583--- a/include/linux/pm.h
81584+++ b/include/linux/pm.h
81585@@ -597,6 +597,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
81586 struct dev_pm_domain {
81587 struct dev_pm_ops ops;
81588 };
81589+typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
81590
81591 /*
81592 * The PM_EVENT_ messages are also used by drivers implementing the legacy
81593diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
81594index 7c1d252..0e7061d 100644
81595--- a/include/linux/pm_domain.h
81596+++ b/include/linux/pm_domain.h
81597@@ -44,11 +44,11 @@ struct gpd_dev_ops {
81598 int (*thaw_early)(struct device *dev);
81599 int (*thaw)(struct device *dev);
81600 bool (*active_wakeup)(struct device *dev);
81601-};
81602+} __no_const;
81603
81604 struct gpd_cpu_data {
81605 unsigned int saved_exit_latency;
81606- struct cpuidle_state *idle_state;
81607+ cpuidle_state_no_const *idle_state;
81608 };
81609
81610 struct generic_pm_domain {
81611diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
81612index 16c9a62..f9f0838 100644
81613--- a/include/linux/pm_runtime.h
81614+++ b/include/linux/pm_runtime.h
81615@@ -109,7 +109,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
81616
81617 static inline void pm_runtime_mark_last_busy(struct device *dev)
81618 {
81619- ACCESS_ONCE(dev->power.last_busy) = jiffies;
81620+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
81621 }
81622
81623 #else /* !CONFIG_PM_RUNTIME */
81624diff --git a/include/linux/pnp.h b/include/linux/pnp.h
81625index 195aafc..49a7bc2 100644
81626--- a/include/linux/pnp.h
81627+++ b/include/linux/pnp.h
81628@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
81629 struct pnp_fixup {
81630 char id[7];
81631 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
81632-};
81633+} __do_const;
81634
81635 /* config parameters */
81636 #define PNP_CONFIG_NORMAL 0x0001
81637diff --git a/include/linux/poison.h b/include/linux/poison.h
81638index 2110a81..13a11bb 100644
81639--- a/include/linux/poison.h
81640+++ b/include/linux/poison.h
81641@@ -19,8 +19,8 @@
81642 * under normal circumstances, used to verify that nobody uses
81643 * non-initialized list entries.
81644 */
81645-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
81646-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
81647+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
81648+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
81649
81650 /********** include/linux/timer.h **********/
81651 /*
81652diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
81653index d8b187c3..9a9257a 100644
81654--- a/include/linux/power/smartreflex.h
81655+++ b/include/linux/power/smartreflex.h
81656@@ -238,7 +238,7 @@ struct omap_sr_class_data {
81657 int (*notify)(struct omap_sr *sr, u32 status);
81658 u8 notify_flags;
81659 u8 class_type;
81660-};
81661+} __do_const;
81662
81663 /**
81664 * struct omap_sr_nvalue_table - Smartreflex n-target value info
81665diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
81666index 4ea1d37..80f4b33 100644
81667--- a/include/linux/ppp-comp.h
81668+++ b/include/linux/ppp-comp.h
81669@@ -84,7 +84,7 @@ struct compressor {
81670 struct module *owner;
81671 /* Extra skb space needed by the compressor algorithm */
81672 unsigned int comp_extra;
81673-};
81674+} __do_const;
81675
81676 /*
81677 * The return value from decompress routine is the length of the
81678diff --git a/include/linux/preempt.h b/include/linux/preempt.h
81679index de83b4e..c4b997d 100644
81680--- a/include/linux/preempt.h
81681+++ b/include/linux/preempt.h
81682@@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
81683 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
81684 #endif
81685
81686+#define raw_preempt_count_add(val) __preempt_count_add(val)
81687+#define raw_preempt_count_sub(val) __preempt_count_sub(val)
81688+
81689 #define __preempt_count_inc() __preempt_count_add(1)
81690 #define __preempt_count_dec() __preempt_count_sub(1)
81691
81692 #define preempt_count_inc() preempt_count_add(1)
81693+#define raw_preempt_count_inc() raw_preempt_count_add(1)
81694 #define preempt_count_dec() preempt_count_sub(1)
81695+#define raw_preempt_count_dec() raw_preempt_count_sub(1)
81696
81697 #ifdef CONFIG_PREEMPT_COUNT
81698
81699@@ -41,6 +46,12 @@ do { \
81700 barrier(); \
81701 } while (0)
81702
81703+#define raw_preempt_disable() \
81704+do { \
81705+ raw_preempt_count_inc(); \
81706+ barrier(); \
81707+} while (0)
81708+
81709 #define sched_preempt_enable_no_resched() \
81710 do { \
81711 barrier(); \
81712@@ -49,6 +60,12 @@ do { \
81713
81714 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
81715
81716+#define raw_preempt_enable_no_resched() \
81717+do { \
81718+ barrier(); \
81719+ raw_preempt_count_dec(); \
81720+} while (0)
81721+
81722 #ifdef CONFIG_PREEMPT
81723 #define preempt_enable() \
81724 do { \
81725@@ -113,8 +130,10 @@ do { \
81726 * region.
81727 */
81728 #define preempt_disable() barrier()
81729+#define raw_preempt_disable() barrier()
81730 #define sched_preempt_enable_no_resched() barrier()
81731 #define preempt_enable_no_resched() barrier()
81732+#define raw_preempt_enable_no_resched() barrier()
81733 #define preempt_enable() barrier()
81734 #define preempt_check_resched() do { } while (0)
81735
81736@@ -128,11 +147,13 @@ do { \
81737 /*
81738 * Modules have no business playing preemption tricks.
81739 */
81740+#ifndef CONFIG_PAX_KERNEXEC
81741 #undef sched_preempt_enable_no_resched
81742 #undef preempt_enable_no_resched
81743 #undef preempt_enable_no_resched_notrace
81744 #undef preempt_check_resched
81745 #endif
81746+#endif
81747
81748 #define preempt_set_need_resched() \
81749 do { \
81750diff --git a/include/linux/printk.h b/include/linux/printk.h
81751index fa47e27..c08e034 100644
81752--- a/include/linux/printk.h
81753+++ b/include/linux/printk.h
81754@@ -114,6 +114,8 @@ static inline __printf(1, 2) __cold
81755 void early_printk(const char *s, ...) { }
81756 #endif
81757
81758+extern int kptr_restrict;
81759+
81760 #ifdef CONFIG_PRINTK
81761 asmlinkage __printf(5, 0)
81762 int vprintk_emit(int facility, int level,
81763@@ -148,7 +150,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
81764
81765 extern int printk_delay_msec;
81766 extern int dmesg_restrict;
81767-extern int kptr_restrict;
81768
81769 extern void wake_up_klogd(void);
81770
81771diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
81772index 608e60a..bbcb1a0 100644
81773--- a/include/linux/proc_fs.h
81774+++ b/include/linux/proc_fs.h
81775@@ -17,8 +17,11 @@ extern void proc_flush_task(struct task_struct *);
81776 extern struct proc_dir_entry *proc_symlink(const char *,
81777 struct proc_dir_entry *, const char *);
81778 extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
81779+extern struct proc_dir_entry *proc_mkdir_restrict(const char *, struct proc_dir_entry *);
81780 extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
81781 struct proc_dir_entry *, void *);
81782+extern struct proc_dir_entry *proc_mkdir_data_restrict(const char *, umode_t,
81783+ struct proc_dir_entry *, void *);
81784 extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
81785 struct proc_dir_entry *);
81786
81787@@ -34,6 +37,19 @@ static inline struct proc_dir_entry *proc_create(
81788 return proc_create_data(name, mode, parent, proc_fops, NULL);
81789 }
81790
81791+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
81792+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
81793+{
81794+#ifdef CONFIG_GRKERNSEC_PROC_USER
81795+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
81796+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
81797+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
81798+#else
81799+ return proc_create_data(name, mode, parent, proc_fops, NULL);
81800+#endif
81801+}
81802+
81803+
81804 extern void proc_set_size(struct proc_dir_entry *, loff_t);
81805 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
81806 extern void *PDE_DATA(const struct inode *);
81807@@ -73,7 +89,7 @@ static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *p
81808 static inline struct proc_dir_entry *proc_net_mkdir(
81809 struct net *net, const char *name, struct proc_dir_entry *parent)
81810 {
81811- return proc_mkdir_data(name, 0, parent, net);
81812+ return proc_mkdir_data_restrict(name, 0, parent, net);
81813 }
81814
81815 #endif /* _LINUX_PROC_FS_H */
81816diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
81817index 34a1e10..70f6bde 100644
81818--- a/include/linux/proc_ns.h
81819+++ b/include/linux/proc_ns.h
81820@@ -14,7 +14,7 @@ struct proc_ns_operations {
81821 void (*put)(void *ns);
81822 int (*install)(struct nsproxy *nsproxy, void *ns);
81823 unsigned int (*inum)(void *ns);
81824-};
81825+} __do_const __randomize_layout;
81826
81827 struct proc_ns {
81828 void *ns;
81829diff --git a/include/linux/quota.h b/include/linux/quota.h
81830index cc7494a..1e27036 100644
81831--- a/include/linux/quota.h
81832+++ b/include/linux/quota.h
81833@@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
81834
81835 extern bool qid_eq(struct kqid left, struct kqid right);
81836 extern bool qid_lt(struct kqid left, struct kqid right);
81837-extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
81838+extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
81839 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
81840 extern bool qid_valid(struct kqid qid);
81841
81842diff --git a/include/linux/random.h b/include/linux/random.h
81843index 1cfce0e..b0b9235 100644
81844--- a/include/linux/random.h
81845+++ b/include/linux/random.h
81846@@ -9,9 +9,19 @@
81847 #include <uapi/linux/random.h>
81848
81849 extern void add_device_randomness(const void *, unsigned int);
81850+
81851+static inline void add_latent_entropy(void)
81852+{
81853+
81854+#ifdef LATENT_ENTROPY_PLUGIN
81855+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
81856+#endif
81857+
81858+}
81859+
81860 extern void add_input_randomness(unsigned int type, unsigned int code,
81861- unsigned int value);
81862-extern void add_interrupt_randomness(int irq, int irq_flags);
81863+ unsigned int value) __latent_entropy;
81864+extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
81865
81866 extern void get_random_bytes(void *buf, int nbytes);
81867 extern void get_random_bytes_arch(void *buf, int nbytes);
81868@@ -22,10 +32,10 @@ extern int random_int_secret_init(void);
81869 extern const struct file_operations random_fops, urandom_fops;
81870 #endif
81871
81872-unsigned int get_random_int(void);
81873+unsigned int __intentional_overflow(-1) get_random_int(void);
81874 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
81875
81876-u32 prandom_u32(void);
81877+u32 prandom_u32(void) __intentional_overflow(-1);
81878 void prandom_bytes(void *buf, int nbytes);
81879 void prandom_seed(u32 seed);
81880 void prandom_reseed_late(void);
81881@@ -37,6 +47,11 @@ struct rnd_state {
81882 u32 prandom_u32_state(struct rnd_state *state);
81883 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
81884
81885+static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
81886+{
81887+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
81888+}
81889+
81890 /**
81891 * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro)
81892 * @ep_ro: right open interval endpoint
81893diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
81894index fea49b5..2ac22bb 100644
81895--- a/include/linux/rbtree_augmented.h
81896+++ b/include/linux/rbtree_augmented.h
81897@@ -80,7 +80,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
81898 old->rbaugmented = rbcompute(old); \
81899 } \
81900 rbstatic const struct rb_augment_callbacks rbname = { \
81901- rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
81902+ .propagate = rbname ## _propagate, \
81903+ .copy = rbname ## _copy, \
81904+ .rotate = rbname ## _rotate \
81905 };
81906
81907
81908diff --git a/include/linux/rculist.h b/include/linux/rculist.h
81909index dbaf990..52e07b8 100644
81910--- a/include/linux/rculist.h
81911+++ b/include/linux/rculist.h
81912@@ -29,8 +29,8 @@
81913 */
81914 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
81915 {
81916- ACCESS_ONCE(list->next) = list;
81917- ACCESS_ONCE(list->prev) = list;
81918+ ACCESS_ONCE_RW(list->next) = list;
81919+ ACCESS_ONCE_RW(list->prev) = list;
81920 }
81921
81922 /*
81923@@ -59,6 +59,9 @@ void __list_add_rcu(struct list_head *new,
81924 struct list_head *prev, struct list_head *next);
81925 #endif
81926
81927+void __pax_list_add_rcu(struct list_head *new,
81928+ struct list_head *prev, struct list_head *next);
81929+
81930 /**
81931 * list_add_rcu - add a new entry to rcu-protected list
81932 * @new: new entry to be added
81933@@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
81934 __list_add_rcu(new, head, head->next);
81935 }
81936
81937+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
81938+{
81939+ __pax_list_add_rcu(new, head, head->next);
81940+}
81941+
81942 /**
81943 * list_add_tail_rcu - add a new entry to rcu-protected list
81944 * @new: new entry to be added
81945@@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
81946 __list_add_rcu(new, head->prev, head);
81947 }
81948
81949+static inline void pax_list_add_tail_rcu(struct list_head *new,
81950+ struct list_head *head)
81951+{
81952+ __pax_list_add_rcu(new, head->prev, head);
81953+}
81954+
81955 /**
81956 * list_del_rcu - deletes entry from list without re-initialization
81957 * @entry: the element to delete from the list.
81958@@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
81959 entry->prev = LIST_POISON2;
81960 }
81961
81962+extern void pax_list_del_rcu(struct list_head *entry);
81963+
81964 /**
81965 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
81966 * @n: the element to delete from the hash list.
81967diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
81968index 72bf3a0..853347f 100644
81969--- a/include/linux/rcupdate.h
81970+++ b/include/linux/rcupdate.h
81971@@ -588,7 +588,7 @@ static inline void rcu_preempt_sleep_check(void)
81972 #define rcu_assign_pointer(p, v) \
81973 do { \
81974 smp_wmb(); \
81975- ACCESS_ONCE(p) = RCU_INITIALIZER(v); \
81976+ ACCESS_ONCE_RW(p) = RCU_INITIALIZER(v); \
81977 } while (0)
81978
81979
81980diff --git a/include/linux/reboot.h b/include/linux/reboot.h
81981index 9e7db9e..7d4fd72 100644
81982--- a/include/linux/reboot.h
81983+++ b/include/linux/reboot.h
81984@@ -44,9 +44,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
81985 */
81986
81987 extern void migrate_to_reboot_cpu(void);
81988-extern void machine_restart(char *cmd);
81989-extern void machine_halt(void);
81990-extern void machine_power_off(void);
81991+extern void machine_restart(char *cmd) __noreturn;
81992+extern void machine_halt(void) __noreturn;
81993+extern void machine_power_off(void) __noreturn;
81994
81995 extern void machine_shutdown(void);
81996 struct pt_regs;
81997@@ -57,9 +57,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
81998 */
81999
82000 extern void kernel_restart_prepare(char *cmd);
82001-extern void kernel_restart(char *cmd);
82002-extern void kernel_halt(void);
82003-extern void kernel_power_off(void);
82004+extern void kernel_restart(char *cmd) __noreturn;
82005+extern void kernel_halt(void) __noreturn;
82006+extern void kernel_power_off(void) __noreturn;
82007
82008 extern int C_A_D; /* for sysctl */
82009 void ctrl_alt_del(void);
82010@@ -73,7 +73,7 @@ extern int orderly_poweroff(bool force);
82011 * Emergency restart, callable from an interrupt handler.
82012 */
82013
82014-extern void emergency_restart(void);
82015+extern void emergency_restart(void) __noreturn;
82016 #include <asm/emergency-restart.h>
82017
82018 #endif /* _LINUX_REBOOT_H */
82019diff --git a/include/linux/regset.h b/include/linux/regset.h
82020index 8e0c9fe..ac4d221 100644
82021--- a/include/linux/regset.h
82022+++ b/include/linux/regset.h
82023@@ -161,7 +161,8 @@ struct user_regset {
82024 unsigned int align;
82025 unsigned int bias;
82026 unsigned int core_note_type;
82027-};
82028+} __do_const;
82029+typedef struct user_regset __no_const user_regset_no_const;
82030
82031 /**
82032 * struct user_regset_view - available regsets
82033diff --git a/include/linux/relay.h b/include/linux/relay.h
82034index d7c8359..818daf5 100644
82035--- a/include/linux/relay.h
82036+++ b/include/linux/relay.h
82037@@ -157,7 +157,7 @@ struct rchan_callbacks
82038 * The callback should return 0 if successful, negative if not.
82039 */
82040 int (*remove_buf_file)(struct dentry *dentry);
82041-};
82042+} __no_const;
82043
82044 /*
82045 * CONFIG_RELAY kernel API, kernel/relay.c
82046diff --git a/include/linux/rio.h b/include/linux/rio.h
82047index b71d573..2f940bd 100644
82048--- a/include/linux/rio.h
82049+++ b/include/linux/rio.h
82050@@ -355,7 +355,7 @@ struct rio_ops {
82051 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
82052 u64 rstart, u32 size, u32 flags);
82053 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
82054-};
82055+} __no_const;
82056
82057 #define RIO_RESOURCE_MEM 0x00000100
82058 #define RIO_RESOURCE_DOORBELL 0x00000200
82059diff --git a/include/linux/rmap.h b/include/linux/rmap.h
82060index b66c211..13d2915 100644
82061--- a/include/linux/rmap.h
82062+++ b/include/linux/rmap.h
82063@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
82064 void anon_vma_init(void); /* create anon_vma_cachep */
82065 int anon_vma_prepare(struct vm_area_struct *);
82066 void unlink_anon_vmas(struct vm_area_struct *);
82067-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
82068-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
82069+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
82070+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
82071
82072 static inline void anon_vma_merge(struct vm_area_struct *vma,
82073 struct vm_area_struct *next)
82074diff --git a/include/linux/sched.h b/include/linux/sched.h
82075index a781dec..be1d2a3 100644
82076--- a/include/linux/sched.h
82077+++ b/include/linux/sched.h
82078@@ -129,6 +129,7 @@ struct fs_struct;
82079 struct perf_event_context;
82080 struct blk_plug;
82081 struct filename;
82082+struct linux_binprm;
82083
82084 /*
82085 * List of flags we want to share for kernel threads,
82086@@ -369,7 +370,7 @@ extern char __sched_text_start[], __sched_text_end[];
82087 extern int in_sched_functions(unsigned long addr);
82088
82089 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
82090-extern signed long schedule_timeout(signed long timeout);
82091+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
82092 extern signed long schedule_timeout_interruptible(signed long timeout);
82093 extern signed long schedule_timeout_killable(signed long timeout);
82094 extern signed long schedule_timeout_uninterruptible(signed long timeout);
82095@@ -380,6 +381,19 @@ struct nsproxy;
82096 struct user_namespace;
82097
82098 #ifdef CONFIG_MMU
82099+
82100+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
82101+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
82102+#else
82103+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
82104+{
82105+ return 0;
82106+}
82107+#endif
82108+
82109+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
82110+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
82111+
82112 extern void arch_pick_mmap_layout(struct mm_struct *mm);
82113 extern unsigned long
82114 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
82115@@ -677,6 +691,17 @@ struct signal_struct {
82116 #ifdef CONFIG_TASKSTATS
82117 struct taskstats *stats;
82118 #endif
82119+
82120+#ifdef CONFIG_GRKERNSEC
82121+ u32 curr_ip;
82122+ u32 saved_ip;
82123+ u32 gr_saddr;
82124+ u32 gr_daddr;
82125+ u16 gr_sport;
82126+ u16 gr_dport;
82127+ u8 used_accept:1;
82128+#endif
82129+
82130 #ifdef CONFIG_AUDIT
82131 unsigned audit_tty;
82132 unsigned audit_tty_log_passwd;
82133@@ -703,7 +728,7 @@ struct signal_struct {
82134 struct mutex cred_guard_mutex; /* guard against foreign influences on
82135 * credential calculations
82136 * (notably. ptrace) */
82137-};
82138+} __randomize_layout;
82139
82140 /*
82141 * Bits in flags field of signal_struct.
82142@@ -757,6 +782,14 @@ struct user_struct {
82143 struct key *session_keyring; /* UID's default session keyring */
82144 #endif
82145
82146+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
82147+ unsigned char kernel_banned;
82148+#endif
82149+#ifdef CONFIG_GRKERNSEC_BRUTE
82150+ unsigned char suid_banned;
82151+ unsigned long suid_ban_expires;
82152+#endif
82153+
82154 /* Hash table maintenance information */
82155 struct hlist_node uidhash_node;
82156 kuid_t uid;
82157@@ -764,7 +797,7 @@ struct user_struct {
82158 #ifdef CONFIG_PERF_EVENTS
82159 atomic_long_t locked_vm;
82160 #endif
82161-};
82162+} __randomize_layout;
82163
82164 extern int uids_sysfs_init(void);
82165
82166@@ -1286,8 +1319,8 @@ struct task_struct {
82167 struct list_head thread_node;
82168
82169 struct completion *vfork_done; /* for vfork() */
82170- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
82171- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
82172+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
82173+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
82174
82175 cputime_t utime, stime, utimescaled, stimescaled;
82176 cputime_t gtime;
82177@@ -1312,11 +1345,6 @@ struct task_struct {
82178 struct task_cputime cputime_expires;
82179 struct list_head cpu_timers[3];
82180
82181-/* process credentials */
82182- const struct cred __rcu *real_cred; /* objective and real subjective task
82183- * credentials (COW) */
82184- const struct cred __rcu *cred; /* effective (overridable) subjective task
82185- * credentials (COW) */
82186 char comm[TASK_COMM_LEN]; /* executable name excluding path
82187 - access with [gs]et_task_comm (which lock
82188 it with task_lock())
82189@@ -1333,6 +1361,10 @@ struct task_struct {
82190 #endif
82191 /* CPU-specific state of this task */
82192 struct thread_struct thread;
82193+/* thread_info moved to task_struct */
82194+#ifdef CONFIG_X86
82195+ struct thread_info tinfo;
82196+#endif
82197 /* filesystem information */
82198 struct fs_struct *fs;
82199 /* open file information */
82200@@ -1409,6 +1441,10 @@ struct task_struct {
82201 gfp_t lockdep_reclaim_gfp;
82202 #endif
82203
82204+/* process credentials */
82205+ const struct cred __rcu *real_cred; /* objective and real subjective task
82206+ * credentials (COW) */
82207+
82208 /* journalling filesystem info */
82209 void *journal_info;
82210
82211@@ -1447,6 +1483,10 @@ struct task_struct {
82212 /* cg_list protected by css_set_lock and tsk->alloc_lock */
82213 struct list_head cg_list;
82214 #endif
82215+
82216+ const struct cred __rcu *cred; /* effective (overridable) subjective task
82217+ * credentials (COW) */
82218+
82219 #ifdef CONFIG_FUTEX
82220 struct robust_list_head __user *robust_list;
82221 #ifdef CONFIG_COMPAT
82222@@ -1581,7 +1621,78 @@ struct task_struct {
82223 unsigned int sequential_io;
82224 unsigned int sequential_io_avg;
82225 #endif
82226-};
82227+
82228+#ifdef CONFIG_GRKERNSEC
82229+ /* grsecurity */
82230+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
82231+ u64 exec_id;
82232+#endif
82233+#ifdef CONFIG_GRKERNSEC_SETXID
82234+ const struct cred *delayed_cred;
82235+#endif
82236+ struct dentry *gr_chroot_dentry;
82237+ struct acl_subject_label *acl;
82238+ struct acl_subject_label *tmpacl;
82239+ struct acl_role_label *role;
82240+ struct file *exec_file;
82241+ unsigned long brute_expires;
82242+ u16 acl_role_id;
82243+ u8 inherited;
82244+ /* is this the task that authenticated to the special role */
82245+ u8 acl_sp_role;
82246+ u8 is_writable;
82247+ u8 brute;
82248+ u8 gr_is_chrooted;
82249+#endif
82250+
82251+} __randomize_layout;
82252+
82253+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
82254+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
82255+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
82256+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
82257+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
82258+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
82259+
82260+#ifdef CONFIG_PAX_SOFTMODE
82261+extern int pax_softmode;
82262+#endif
82263+
82264+extern int pax_check_flags(unsigned long *);
82265+#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
82266+
82267+/* if tsk != current then task_lock must be held on it */
82268+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
82269+static inline unsigned long pax_get_flags(struct task_struct *tsk)
82270+{
82271+ if (likely(tsk->mm))
82272+ return tsk->mm->pax_flags;
82273+ else
82274+ return 0UL;
82275+}
82276+
82277+/* if tsk != current then task_lock must be held on it */
82278+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
82279+{
82280+ if (likely(tsk->mm)) {
82281+ tsk->mm->pax_flags = flags;
82282+ return 0;
82283+ }
82284+ return -EINVAL;
82285+}
82286+#endif
82287+
82288+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
82289+extern void pax_set_initial_flags(struct linux_binprm *bprm);
82290+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
82291+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
82292+#endif
82293+
82294+struct path;
82295+extern char *pax_get_path(const struct path *path, char *buf, int buflen);
82296+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
82297+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
82298+extern void pax_report_refcount_overflow(struct pt_regs *regs);
82299
82300 /* Future-safe accessor for struct task_struct's cpus_allowed. */
82301 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
82302@@ -1658,7 +1769,7 @@ struct pid_namespace;
82303 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
82304 struct pid_namespace *ns);
82305
82306-static inline pid_t task_pid_nr(struct task_struct *tsk)
82307+static inline pid_t task_pid_nr(const struct task_struct *tsk)
82308 {
82309 return tsk->pid;
82310 }
82311@@ -2112,7 +2223,9 @@ void yield(void);
82312 extern struct exec_domain default_exec_domain;
82313
82314 union thread_union {
82315+#ifndef CONFIG_X86
82316 struct thread_info thread_info;
82317+#endif
82318 unsigned long stack[THREAD_SIZE/sizeof(long)];
82319 };
82320
82321@@ -2145,6 +2258,7 @@ extern struct pid_namespace init_pid_ns;
82322 */
82323
82324 extern struct task_struct *find_task_by_vpid(pid_t nr);
82325+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
82326 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
82327 struct pid_namespace *ns);
82328
82329@@ -2307,7 +2421,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
82330 extern void exit_itimers(struct signal_struct *);
82331 extern void flush_itimer_signals(void);
82332
82333-extern void do_group_exit(int);
82334+extern __noreturn void do_group_exit(int);
82335
82336 extern int allow_signal(int);
82337 extern int disallow_signal(int);
82338@@ -2508,9 +2622,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
82339
82340 #endif
82341
82342-static inline int object_is_on_stack(void *obj)
82343+static inline int object_starts_on_stack(void *obj)
82344 {
82345- void *stack = task_stack_page(current);
82346+ const void *stack = task_stack_page(current);
82347
82348 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
82349 }
82350diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
82351index 8045a55..c959cd5 100644
82352--- a/include/linux/sched/sysctl.h
82353+++ b/include/linux/sched/sysctl.h
82354@@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
82355 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
82356
82357 extern int sysctl_max_map_count;
82358+extern unsigned long sysctl_heap_stack_gap;
82359
82360 extern unsigned int sysctl_sched_latency;
82361 extern unsigned int sysctl_sched_min_granularity;
82362diff --git a/include/linux/security.h b/include/linux/security.h
82363index 2fc42d1..4d802f2 100644
82364--- a/include/linux/security.h
82365+++ b/include/linux/security.h
82366@@ -27,6 +27,7 @@
82367 #include <linux/slab.h>
82368 #include <linux/err.h>
82369 #include <linux/string.h>
82370+#include <linux/grsecurity.h>
82371
82372 struct linux_binprm;
82373 struct cred;
82374@@ -116,8 +117,6 @@ struct seq_file;
82375
82376 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
82377
82378-void reset_security_ops(void);
82379-
82380 #ifdef CONFIG_MMU
82381 extern unsigned long mmap_min_addr;
82382 extern unsigned long dac_mmap_min_addr;
82383@@ -1719,7 +1718,7 @@ struct security_operations {
82384 struct audit_context *actx);
82385 void (*audit_rule_free) (void *lsmrule);
82386 #endif /* CONFIG_AUDIT */
82387-};
82388+} __randomize_layout;
82389
82390 /* prototypes */
82391 extern int security_init(void);
82392diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
82393index dc368b8..e895209 100644
82394--- a/include/linux/semaphore.h
82395+++ b/include/linux/semaphore.h
82396@@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
82397 }
82398
82399 extern void down(struct semaphore *sem);
82400-extern int __must_check down_interruptible(struct semaphore *sem);
82401+extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
82402 extern int __must_check down_killable(struct semaphore *sem);
82403 extern int __must_check down_trylock(struct semaphore *sem);
82404 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
82405diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
82406index 52e0097..383f21d 100644
82407--- a/include/linux/seq_file.h
82408+++ b/include/linux/seq_file.h
82409@@ -27,6 +27,9 @@ struct seq_file {
82410 struct mutex lock;
82411 const struct seq_operations *op;
82412 int poll_event;
82413+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
82414+ u64 exec_id;
82415+#endif
82416 #ifdef CONFIG_USER_NS
82417 struct user_namespace *user_ns;
82418 #endif
82419@@ -39,6 +42,7 @@ struct seq_operations {
82420 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
82421 int (*show) (struct seq_file *m, void *v);
82422 };
82423+typedef struct seq_operations __no_const seq_operations_no_const;
82424
82425 #define SEQ_SKIP 1
82426
82427@@ -96,6 +100,7 @@ void seq_pad(struct seq_file *m, char c);
82428
82429 char *mangle_path(char *s, const char *p, const char *esc);
82430 int seq_open(struct file *, const struct seq_operations *);
82431+int seq_open_restrict(struct file *, const struct seq_operations *);
82432 ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
82433 loff_t seq_lseek(struct file *, loff_t, int);
82434 int seq_release(struct inode *, struct file *);
82435@@ -138,6 +143,7 @@ static inline int seq_nodemask_list(struct seq_file *m, nodemask_t *mask)
82436 }
82437
82438 int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
82439+int single_open_restrict(struct file *, int (*)(struct seq_file *, void *), void *);
82440 int single_open_size(struct file *, int (*)(struct seq_file *, void *), void *, size_t);
82441 int single_release(struct inode *, struct file *);
82442 void *__seq_open_private(struct file *, const struct seq_operations *, int);
82443diff --git a/include/linux/shm.h b/include/linux/shm.h
82444index 1e2cd2e..0288750 100644
82445--- a/include/linux/shm.h
82446+++ b/include/linux/shm.h
82447@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
82448
82449 /* The task created the shm object. NULL if the task is dead. */
82450 struct task_struct *shm_creator;
82451+#ifdef CONFIG_GRKERNSEC
82452+ time_t shm_createtime;
82453+ pid_t shm_lapid;
82454+#endif
82455 };
82456
82457 /* shm_mode upper byte flags */
82458diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
82459index 15ede6a..80161c3 100644
82460--- a/include/linux/skbuff.h
82461+++ b/include/linux/skbuff.h
82462@@ -662,7 +662,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
82463 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
82464 int node);
82465 struct sk_buff *build_skb(void *data, unsigned int frag_size);
82466-static inline struct sk_buff *alloc_skb(unsigned int size,
82467+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
82468 gfp_t priority)
82469 {
82470 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
82471@@ -1768,7 +1768,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
82472 return skb->inner_transport_header - skb->inner_network_header;
82473 }
82474
82475-static inline int skb_network_offset(const struct sk_buff *skb)
82476+static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
82477 {
82478 return skb_network_header(skb) - skb->data;
82479 }
82480@@ -1828,7 +1828,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
82481 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
82482 */
82483 #ifndef NET_SKB_PAD
82484-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
82485+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
82486 #endif
82487
82488 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
82489@@ -2427,7 +2427,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
82490 int *err);
82491 unsigned int datagram_poll(struct file *file, struct socket *sock,
82492 struct poll_table_struct *wait);
82493-int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
82494+int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
82495 struct iovec *to, int size);
82496 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
82497 struct iovec *iov);
82498@@ -2721,6 +2721,9 @@ static inline void nf_reset(struct sk_buff *skb)
82499 nf_bridge_put(skb->nf_bridge);
82500 skb->nf_bridge = NULL;
82501 #endif
82502+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
82503+ skb->nf_trace = 0;
82504+#endif
82505 }
82506
82507 static inline void nf_reset_trace(struct sk_buff *skb)
82508diff --git a/include/linux/slab.h b/include/linux/slab.h
82509index b5b2df6..69f5734 100644
82510--- a/include/linux/slab.h
82511+++ b/include/linux/slab.h
82512@@ -14,15 +14,29 @@
82513 #include <linux/gfp.h>
82514 #include <linux/types.h>
82515 #include <linux/workqueue.h>
82516-
82517+#include <linux/err.h>
82518
82519 /*
82520 * Flags to pass to kmem_cache_create().
82521 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
82522 */
82523 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
82524+
82525+#ifdef CONFIG_PAX_USERCOPY_SLABS
82526+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
82527+#else
82528+#define SLAB_USERCOPY 0x00000000UL
82529+#endif
82530+
82531 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
82532 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
82533+
82534+#ifdef CONFIG_PAX_MEMORY_SANITIZE
82535+#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
82536+#else
82537+#define SLAB_NO_SANITIZE 0x00000000UL
82538+#endif
82539+
82540 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
82541 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
82542 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
82543@@ -98,10 +112,13 @@
82544 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
82545 * Both make kfree a no-op.
82546 */
82547-#define ZERO_SIZE_PTR ((void *)16)
82548+#define ZERO_SIZE_PTR \
82549+({ \
82550+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
82551+ (void *)(-MAX_ERRNO-1L); \
82552+})
82553
82554-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
82555- (unsigned long)ZERO_SIZE_PTR)
82556+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
82557
82558 #include <linux/kmemleak.h>
82559
82560@@ -142,6 +159,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
82561 void kfree(const void *);
82562 void kzfree(const void *);
82563 size_t ksize(const void *);
82564+const char *check_heap_object(const void *ptr, unsigned long n);
82565+bool is_usercopy_object(const void *ptr);
82566
82567 /*
82568 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
82569@@ -174,7 +193,7 @@ struct kmem_cache {
82570 unsigned int align; /* Alignment as calculated */
82571 unsigned long flags; /* Active flags on the slab */
82572 const char *name; /* Slab name for sysfs */
82573- int refcount; /* Use counter */
82574+ atomic_t refcount; /* Use counter */
82575 void (*ctor)(void *); /* Called on object slot creation */
82576 struct list_head list; /* List of all slab caches on the system */
82577 };
82578@@ -248,6 +267,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
82579 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
82580 #endif
82581
82582+#ifdef CONFIG_PAX_USERCOPY_SLABS
82583+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
82584+#endif
82585+
82586 /*
82587 * Figure out which kmalloc slab an allocation of a certain size
82588 * belongs to.
82589@@ -256,7 +279,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
82590 * 2 = 120 .. 192 bytes
82591 * n = 2^(n-1) .. 2^n -1
82592 */
82593-static __always_inline int kmalloc_index(size_t size)
82594+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
82595 {
82596 if (!size)
82597 return 0;
82598@@ -299,11 +322,11 @@ static __always_inline int kmalloc_index(size_t size)
82599 }
82600 #endif /* !CONFIG_SLOB */
82601
82602-void *__kmalloc(size_t size, gfp_t flags);
82603+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
82604 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
82605
82606 #ifdef CONFIG_NUMA
82607-void *__kmalloc_node(size_t size, gfp_t flags, int node);
82608+void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
82609 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
82610 #else
82611 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
82612diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
82613index 8235dfb..47ce586 100644
82614--- a/include/linux/slab_def.h
82615+++ b/include/linux/slab_def.h
82616@@ -38,7 +38,7 @@ struct kmem_cache {
82617 /* 4) cache creation/removal */
82618 const char *name;
82619 struct list_head list;
82620- int refcount;
82621+ atomic_t refcount;
82622 int object_size;
82623 int align;
82624
82625@@ -54,10 +54,14 @@ struct kmem_cache {
82626 unsigned long node_allocs;
82627 unsigned long node_frees;
82628 unsigned long node_overflow;
82629- atomic_t allochit;
82630- atomic_t allocmiss;
82631- atomic_t freehit;
82632- atomic_t freemiss;
82633+ atomic_unchecked_t allochit;
82634+ atomic_unchecked_t allocmiss;
82635+ atomic_unchecked_t freehit;
82636+ atomic_unchecked_t freemiss;
82637+#ifdef CONFIG_PAX_MEMORY_SANITIZE
82638+ atomic_unchecked_t sanitized;
82639+ atomic_unchecked_t not_sanitized;
82640+#endif
82641
82642 /*
82643 * If debugging is enabled, then the allocator can add additional
82644diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
82645index f56bfa9..8378a26 100644
82646--- a/include/linux/slub_def.h
82647+++ b/include/linux/slub_def.h
82648@@ -74,7 +74,7 @@ struct kmem_cache {
82649 struct kmem_cache_order_objects max;
82650 struct kmem_cache_order_objects min;
82651 gfp_t allocflags; /* gfp flags to use on each alloc */
82652- int refcount; /* Refcount for slab cache destroy */
82653+ atomic_t refcount; /* Refcount for slab cache destroy */
82654 void (*ctor)(void *);
82655 int inuse; /* Offset to metadata */
82656 int align; /* Alignment */
82657diff --git a/include/linux/smp.h b/include/linux/smp.h
82658index 6ae004e..2743532 100644
82659--- a/include/linux/smp.h
82660+++ b/include/linux/smp.h
82661@@ -180,7 +180,9 @@ static inline void kick_all_cpus_sync(void) { }
82662 #endif
82663
82664 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
82665+#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
82666 #define put_cpu() preempt_enable()
82667+#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
82668
82669 /*
82670 * Callback to arch code if there's nosmp or maxcpus=0 on the
82671diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
82672index 54f91d3..be2c379 100644
82673--- a/include/linux/sock_diag.h
82674+++ b/include/linux/sock_diag.h
82675@@ -11,7 +11,7 @@ struct sock;
82676 struct sock_diag_handler {
82677 __u8 family;
82678 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
82679-};
82680+} __do_const;
82681
82682 int sock_diag_register(const struct sock_diag_handler *h);
82683 void sock_diag_unregister(const struct sock_diag_handler *h);
82684diff --git a/include/linux/sonet.h b/include/linux/sonet.h
82685index 680f9a3..f13aeb0 100644
82686--- a/include/linux/sonet.h
82687+++ b/include/linux/sonet.h
82688@@ -7,7 +7,7 @@
82689 #include <uapi/linux/sonet.h>
82690
82691 struct k_sonet_stats {
82692-#define __HANDLE_ITEM(i) atomic_t i
82693+#define __HANDLE_ITEM(i) atomic_unchecked_t i
82694 __SONET_ITEMS
82695 #undef __HANDLE_ITEM
82696 };
82697diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
82698index 07d8e53..dc934c9 100644
82699--- a/include/linux/sunrpc/addr.h
82700+++ b/include/linux/sunrpc/addr.h
82701@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
82702 {
82703 switch (sap->sa_family) {
82704 case AF_INET:
82705- return ntohs(((struct sockaddr_in *)sap)->sin_port);
82706+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
82707 case AF_INET6:
82708- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
82709+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
82710 }
82711 return 0;
82712 }
82713@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
82714 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
82715 const struct sockaddr *src)
82716 {
82717- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
82718+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
82719 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
82720
82721 dsin->sin_family = ssin->sin_family;
82722@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
82723 if (sa->sa_family != AF_INET6)
82724 return 0;
82725
82726- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
82727+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
82728 }
82729
82730 #endif /* _LINUX_SUNRPC_ADDR_H */
82731diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
82732index 8af2804..c7414ef 100644
82733--- a/include/linux/sunrpc/clnt.h
82734+++ b/include/linux/sunrpc/clnt.h
82735@@ -97,7 +97,7 @@ struct rpc_procinfo {
82736 unsigned int p_timer; /* Which RTT timer to use */
82737 u32 p_statidx; /* Which procedure to account */
82738 const char * p_name; /* name of procedure */
82739-};
82740+} __do_const;
82741
82742 #ifdef __KERNEL__
82743
82744diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
82745index 04e7632..2e2a8a3 100644
82746--- a/include/linux/sunrpc/svc.h
82747+++ b/include/linux/sunrpc/svc.h
82748@@ -412,7 +412,7 @@ struct svc_procedure {
82749 unsigned int pc_count; /* call count */
82750 unsigned int pc_cachetype; /* cache info (NFS) */
82751 unsigned int pc_xdrressize; /* maximum size of XDR reply */
82752-};
82753+} __do_const;
82754
82755 /*
82756 * Function prototypes.
82757diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
82758index 0b8e3e6..33e0a01 100644
82759--- a/include/linux/sunrpc/svc_rdma.h
82760+++ b/include/linux/sunrpc/svc_rdma.h
82761@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
82762 extern unsigned int svcrdma_max_requests;
82763 extern unsigned int svcrdma_max_req_size;
82764
82765-extern atomic_t rdma_stat_recv;
82766-extern atomic_t rdma_stat_read;
82767-extern atomic_t rdma_stat_write;
82768-extern atomic_t rdma_stat_sq_starve;
82769-extern atomic_t rdma_stat_rq_starve;
82770-extern atomic_t rdma_stat_rq_poll;
82771-extern atomic_t rdma_stat_rq_prod;
82772-extern atomic_t rdma_stat_sq_poll;
82773-extern atomic_t rdma_stat_sq_prod;
82774+extern atomic_unchecked_t rdma_stat_recv;
82775+extern atomic_unchecked_t rdma_stat_read;
82776+extern atomic_unchecked_t rdma_stat_write;
82777+extern atomic_unchecked_t rdma_stat_sq_starve;
82778+extern atomic_unchecked_t rdma_stat_rq_starve;
82779+extern atomic_unchecked_t rdma_stat_rq_poll;
82780+extern atomic_unchecked_t rdma_stat_rq_prod;
82781+extern atomic_unchecked_t rdma_stat_sq_poll;
82782+extern atomic_unchecked_t rdma_stat_sq_prod;
82783
82784 #define RPCRDMA_VERSION 1
82785
82786diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
82787index 8d71d65..f79586e 100644
82788--- a/include/linux/sunrpc/svcauth.h
82789+++ b/include/linux/sunrpc/svcauth.h
82790@@ -120,7 +120,7 @@ struct auth_ops {
82791 int (*release)(struct svc_rqst *rq);
82792 void (*domain_release)(struct auth_domain *);
82793 int (*set_client)(struct svc_rqst *rq);
82794-};
82795+} __do_const;
82796
82797 #define SVC_GARBAGE 1
82798 #define SVC_SYSERR 2
82799diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
82800index a5ffd32..0935dea 100644
82801--- a/include/linux/swiotlb.h
82802+++ b/include/linux/swiotlb.h
82803@@ -60,7 +60,8 @@ extern void
82804
82805 extern void
82806 swiotlb_free_coherent(struct device *hwdev, size_t size,
82807- void *vaddr, dma_addr_t dma_handle);
82808+ void *vaddr, dma_addr_t dma_handle,
82809+ struct dma_attrs *attrs);
82810
82811 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
82812 unsigned long offset, size_t size,
82813diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
82814index a747a77..9e14df7 100644
82815--- a/include/linux/syscalls.h
82816+++ b/include/linux/syscalls.h
82817@@ -98,8 +98,14 @@ struct sigaltstack;
82818 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
82819
82820 #define __SC_DECL(t, a) t a
82821+#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))
82822 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
82823-#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
82824+#define __SC_LONG(t, a) __typeof( \
82825+ __builtin_choose_expr( \
82826+ sizeof(t) > sizeof(int), \
82827+ (t) 0, \
82828+ __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
82829+ )) a
82830 #define __SC_CAST(t, a) (t) a
82831 #define __SC_ARGS(t, a) a
82832 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
82833@@ -371,11 +377,11 @@ asmlinkage long sys_sync(void);
82834 asmlinkage long sys_fsync(unsigned int fd);
82835 asmlinkage long sys_fdatasync(unsigned int fd);
82836 asmlinkage long sys_bdflush(int func, long data);
82837-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
82838- char __user *type, unsigned long flags,
82839+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
82840+ const char __user *type, unsigned long flags,
82841 void __user *data);
82842-asmlinkage long sys_umount(char __user *name, int flags);
82843-asmlinkage long sys_oldumount(char __user *name);
82844+asmlinkage long sys_umount(const char __user *name, int flags);
82845+asmlinkage long sys_oldumount(const char __user *name);
82846 asmlinkage long sys_truncate(const char __user *path, long length);
82847 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
82848 asmlinkage long sys_stat(const char __user *filename,
82849@@ -587,7 +593,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
82850 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
82851 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
82852 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
82853- struct sockaddr __user *, int);
82854+ struct sockaddr __user *, int) __intentional_overflow(0);
82855 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
82856 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
82857 unsigned int vlen, unsigned flags);
82858diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
82859index 27b3b0b..e093dd9 100644
82860--- a/include/linux/syscore_ops.h
82861+++ b/include/linux/syscore_ops.h
82862@@ -16,7 +16,7 @@ struct syscore_ops {
82863 int (*suspend)(void);
82864 void (*resume)(void);
82865 void (*shutdown)(void);
82866-};
82867+} __do_const;
82868
82869 extern void register_syscore_ops(struct syscore_ops *ops);
82870 extern void unregister_syscore_ops(struct syscore_ops *ops);
82871diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
82872index 14a8ff2..fa95f3a 100644
82873--- a/include/linux/sysctl.h
82874+++ b/include/linux/sysctl.h
82875@@ -34,13 +34,13 @@ struct ctl_table_root;
82876 struct ctl_table_header;
82877 struct ctl_dir;
82878
82879-typedef struct ctl_table ctl_table;
82880-
82881 typedef int proc_handler (struct ctl_table *ctl, int write,
82882 void __user *buffer, size_t *lenp, loff_t *ppos);
82883
82884 extern int proc_dostring(struct ctl_table *, int,
82885 void __user *, size_t *, loff_t *);
82886+extern int proc_dostring_modpriv(struct ctl_table *, int,
82887+ void __user *, size_t *, loff_t *);
82888 extern int proc_dointvec(struct ctl_table *, int,
82889 void __user *, size_t *, loff_t *);
82890 extern int proc_dointvec_minmax(struct ctl_table *, int,
82891@@ -115,7 +115,9 @@ struct ctl_table
82892 struct ctl_table_poll *poll;
82893 void *extra1;
82894 void *extra2;
82895-};
82896+} __do_const __randomize_layout;
82897+typedef struct ctl_table __no_const ctl_table_no_const;
82898+typedef struct ctl_table ctl_table;
82899
82900 struct ctl_node {
82901 struct rb_node node;
82902diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
82903index 30b2ebe..37412ef 100644
82904--- a/include/linux/sysfs.h
82905+++ b/include/linux/sysfs.h
82906@@ -34,7 +34,8 @@ struct attribute {
82907 struct lock_class_key *key;
82908 struct lock_class_key skey;
82909 #endif
82910-};
82911+} __do_const;
82912+typedef struct attribute __no_const attribute_no_const;
82913
82914 /**
82915 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
82916@@ -63,7 +64,8 @@ struct attribute_group {
82917 struct attribute *, int);
82918 struct attribute **attrs;
82919 struct bin_attribute **bin_attrs;
82920-};
82921+} __do_const;
82922+typedef struct attribute_group __no_const attribute_group_no_const;
82923
82924 /**
82925 * Use these macros to make defining attributes easier. See include/linux/device.h
82926@@ -127,7 +129,8 @@ struct bin_attribute {
82927 char *, loff_t, size_t);
82928 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
82929 struct vm_area_struct *vma);
82930-};
82931+} __do_const;
82932+typedef struct bin_attribute __no_const bin_attribute_no_const;
82933
82934 /**
82935 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
82936diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
82937index 387fa7d..3fcde6b 100644
82938--- a/include/linux/sysrq.h
82939+++ b/include/linux/sysrq.h
82940@@ -16,6 +16,7 @@
82941
82942 #include <linux/errno.h>
82943 #include <linux/types.h>
82944+#include <linux/compiler.h>
82945
82946 /* Possible values of bitmask for enabling sysrq functions */
82947 /* 0x0001 is reserved for enable everything */
82948@@ -33,7 +34,7 @@ struct sysrq_key_op {
82949 char *help_msg;
82950 char *action_msg;
82951 int enable_mask;
82952-};
82953+} __do_const;
82954
82955 #ifdef CONFIG_MAGIC_SYSRQ
82956
82957diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
82958index fddbe20..e4cce53 100644
82959--- a/include/linux/thread_info.h
82960+++ b/include/linux/thread_info.h
82961@@ -161,6 +161,25 @@ static inline bool test_and_clear_restore_sigmask(void)
82962 #error "no set_restore_sigmask() provided and default one won't work"
82963 #endif
82964
82965+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
82966+
82967+#if defined(CONFIG_X86) && defined(CONFIG_PAX_USERCOPY)
82968+extern void pax_check_alloca(unsigned long size);
82969+#endif
82970+
82971+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
82972+{
82973+#if defined(CONFIG_X86) && defined(CONFIG_PAX_USERCOPY)
82974+ /* always check if we've overflowed the stack in a copy*user */
82975+ pax_check_alloca(sizeof(unsigned long));
82976+#endif
82977+
82978+#ifndef CONFIG_PAX_USERCOPY_DEBUG
82979+ if (!__builtin_constant_p(n))
82980+#endif
82981+ __check_object_size(ptr, n, to_user);
82982+}
82983+
82984 #endif /* __KERNEL__ */
82985
82986 #endif /* _LINUX_THREAD_INFO_H */
82987diff --git a/include/linux/tty.h b/include/linux/tty.h
82988index b90b5c2..e23a512 100644
82989--- a/include/linux/tty.h
82990+++ b/include/linux/tty.h
82991@@ -202,7 +202,7 @@ struct tty_port {
82992 const struct tty_port_operations *ops; /* Port operations */
82993 spinlock_t lock; /* Lock protecting tty field */
82994 int blocked_open; /* Waiting to open */
82995- int count; /* Usage count */
82996+ atomic_t count; /* Usage count */
82997 wait_queue_head_t open_wait; /* Open waiters */
82998 wait_queue_head_t close_wait; /* Close waiters */
82999 wait_queue_head_t delta_msr_wait; /* Modem status change */
83000@@ -284,7 +284,7 @@ struct tty_struct {
83001 /* If the tty has a pending do_SAK, queue it here - akpm */
83002 struct work_struct SAK_work;
83003 struct tty_port *port;
83004-};
83005+} __randomize_layout;
83006
83007 /* Each of a tty's open files has private_data pointing to tty_file_private */
83008 struct tty_file_private {
83009@@ -550,7 +550,7 @@ extern int tty_port_open(struct tty_port *port,
83010 struct tty_struct *tty, struct file *filp);
83011 static inline int tty_port_users(struct tty_port *port)
83012 {
83013- return port->count + port->blocked_open;
83014+ return atomic_read(&port->count) + port->blocked_open;
83015 }
83016
83017 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
83018diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
83019index 756a609..89db85e 100644
83020--- a/include/linux/tty_driver.h
83021+++ b/include/linux/tty_driver.h
83022@@ -285,7 +285,7 @@ struct tty_operations {
83023 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
83024 #endif
83025 const struct file_operations *proc_fops;
83026-};
83027+} __do_const __randomize_layout;
83028
83029 struct tty_driver {
83030 int magic; /* magic number for this structure */
83031@@ -319,7 +319,7 @@ struct tty_driver {
83032
83033 const struct tty_operations *ops;
83034 struct list_head tty_drivers;
83035-};
83036+} __randomize_layout;
83037
83038 extern struct list_head tty_drivers;
83039
83040diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
83041index b8347c2..85d8b0f 100644
83042--- a/include/linux/tty_ldisc.h
83043+++ b/include/linux/tty_ldisc.h
83044@@ -213,7 +213,7 @@ struct tty_ldisc_ops {
83045
83046 struct module *owner;
83047
83048- int refcount;
83049+ atomic_t refcount;
83050 };
83051
83052 struct tty_ldisc {
83053diff --git a/include/linux/types.h b/include/linux/types.h
83054index 4d118ba..c3ee9bf 100644
83055--- a/include/linux/types.h
83056+++ b/include/linux/types.h
83057@@ -176,10 +176,26 @@ typedef struct {
83058 int counter;
83059 } atomic_t;
83060
83061+#ifdef CONFIG_PAX_REFCOUNT
83062+typedef struct {
83063+ int counter;
83064+} atomic_unchecked_t;
83065+#else
83066+typedef atomic_t atomic_unchecked_t;
83067+#endif
83068+
83069 #ifdef CONFIG_64BIT
83070 typedef struct {
83071 long counter;
83072 } atomic64_t;
83073+
83074+#ifdef CONFIG_PAX_REFCOUNT
83075+typedef struct {
83076+ long counter;
83077+} atomic64_unchecked_t;
83078+#else
83079+typedef atomic64_t atomic64_unchecked_t;
83080+#endif
83081 #endif
83082
83083 struct list_head {
83084diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
83085index ecd3319..8a36ded 100644
83086--- a/include/linux/uaccess.h
83087+++ b/include/linux/uaccess.h
83088@@ -75,11 +75,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
83089 long ret; \
83090 mm_segment_t old_fs = get_fs(); \
83091 \
83092- set_fs(KERNEL_DS); \
83093 pagefault_disable(); \
83094- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
83095- pagefault_enable(); \
83096+ set_fs(KERNEL_DS); \
83097+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
83098 set_fs(old_fs); \
83099+ pagefault_enable(); \
83100 ret; \
83101 })
83102
83103diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
83104index 2d1f9b6..d7a9fce 100644
83105--- a/include/linux/uidgid.h
83106+++ b/include/linux/uidgid.h
83107@@ -175,4 +175,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
83108
83109 #endif /* CONFIG_USER_NS */
83110
83111+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
83112+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
83113+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
83114+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
83115+
83116 #endif /* _LINUX_UIDGID_H */
83117diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
83118index 99c1b4d..562e6f3 100644
83119--- a/include/linux/unaligned/access_ok.h
83120+++ b/include/linux/unaligned/access_ok.h
83121@@ -4,34 +4,34 @@
83122 #include <linux/kernel.h>
83123 #include <asm/byteorder.h>
83124
83125-static inline u16 get_unaligned_le16(const void *p)
83126+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
83127 {
83128- return le16_to_cpup((__le16 *)p);
83129+ return le16_to_cpup((const __le16 *)p);
83130 }
83131
83132-static inline u32 get_unaligned_le32(const void *p)
83133+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
83134 {
83135- return le32_to_cpup((__le32 *)p);
83136+ return le32_to_cpup((const __le32 *)p);
83137 }
83138
83139-static inline u64 get_unaligned_le64(const void *p)
83140+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
83141 {
83142- return le64_to_cpup((__le64 *)p);
83143+ return le64_to_cpup((const __le64 *)p);
83144 }
83145
83146-static inline u16 get_unaligned_be16(const void *p)
83147+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
83148 {
83149- return be16_to_cpup((__be16 *)p);
83150+ return be16_to_cpup((const __be16 *)p);
83151 }
83152
83153-static inline u32 get_unaligned_be32(const void *p)
83154+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
83155 {
83156- return be32_to_cpup((__be32 *)p);
83157+ return be32_to_cpup((const __be32 *)p);
83158 }
83159
83160-static inline u64 get_unaligned_be64(const void *p)
83161+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
83162 {
83163- return be64_to_cpup((__be64 *)p);
83164+ return be64_to_cpup((const __be64 *)p);
83165 }
83166
83167 static inline void put_unaligned_le16(u16 val, void *p)
83168diff --git a/include/linux/usb.h b/include/linux/usb.h
83169index 7f6eb85..656e806 100644
83170--- a/include/linux/usb.h
83171+++ b/include/linux/usb.h
83172@@ -563,7 +563,7 @@ struct usb_device {
83173 int maxchild;
83174
83175 u32 quirks;
83176- atomic_t urbnum;
83177+ atomic_unchecked_t urbnum;
83178
83179 unsigned long active_duration;
83180
83181@@ -1642,7 +1642,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
83182
83183 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
83184 __u8 request, __u8 requesttype, __u16 value, __u16 index,
83185- void *data, __u16 size, int timeout);
83186+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
83187 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
83188 void *data, int len, int *actual_length, int timeout);
83189 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
83190diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
83191index e452ba6..78f8e80 100644
83192--- a/include/linux/usb/renesas_usbhs.h
83193+++ b/include/linux/usb/renesas_usbhs.h
83194@@ -39,7 +39,7 @@ enum {
83195 */
83196 struct renesas_usbhs_driver_callback {
83197 int (*notify_hotplug)(struct platform_device *pdev);
83198-};
83199+} __no_const;
83200
83201 /*
83202 * callback functions for platform
83203diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
83204index 4836ba3..603f6ee 100644
83205--- a/include/linux/user_namespace.h
83206+++ b/include/linux/user_namespace.h
83207@@ -33,7 +33,7 @@ struct user_namespace {
83208 struct key *persistent_keyring_register;
83209 struct rw_semaphore persistent_keyring_register_sem;
83210 #endif
83211-};
83212+} __randomize_layout;
83213
83214 extern struct user_namespace init_user_ns;
83215
83216diff --git a/include/linux/utsname.h b/include/linux/utsname.h
83217index 239e277..22a5cf5 100644
83218--- a/include/linux/utsname.h
83219+++ b/include/linux/utsname.h
83220@@ -24,7 +24,7 @@ struct uts_namespace {
83221 struct new_utsname name;
83222 struct user_namespace *user_ns;
83223 unsigned int proc_inum;
83224-};
83225+} __randomize_layout;
83226 extern struct uts_namespace init_uts_ns;
83227
83228 #ifdef CONFIG_UTS_NS
83229diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
83230index 6f8fbcf..4efc177 100644
83231--- a/include/linux/vermagic.h
83232+++ b/include/linux/vermagic.h
83233@@ -25,9 +25,42 @@
83234 #define MODULE_ARCH_VERMAGIC ""
83235 #endif
83236
83237+#ifdef CONFIG_PAX_REFCOUNT
83238+#define MODULE_PAX_REFCOUNT "REFCOUNT "
83239+#else
83240+#define MODULE_PAX_REFCOUNT ""
83241+#endif
83242+
83243+#ifdef CONSTIFY_PLUGIN
83244+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
83245+#else
83246+#define MODULE_CONSTIFY_PLUGIN ""
83247+#endif
83248+
83249+#ifdef STACKLEAK_PLUGIN
83250+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
83251+#else
83252+#define MODULE_STACKLEAK_PLUGIN ""
83253+#endif
83254+
83255+#ifdef RANDSTRUCT_PLUGIN
83256+#include <generated/randomize_layout_hash.h>
83257+#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
83258+#else
83259+#define MODULE_RANDSTRUCT_PLUGIN
83260+#endif
83261+
83262+#ifdef CONFIG_GRKERNSEC
83263+#define MODULE_GRSEC "GRSEC "
83264+#else
83265+#define MODULE_GRSEC ""
83266+#endif
83267+
83268 #define VERMAGIC_STRING \
83269 UTS_RELEASE " " \
83270 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
83271 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
83272- MODULE_ARCH_VERMAGIC
83273+ MODULE_ARCH_VERMAGIC \
83274+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
83275+ MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
83276
83277diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
83278index 502073a..a7de024 100644
83279--- a/include/linux/vga_switcheroo.h
83280+++ b/include/linux/vga_switcheroo.h
83281@@ -63,8 +63,8 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
83282
83283 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
83284
83285-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
83286-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
83287+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
83288+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
83289 #else
83290
83291 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
83292@@ -81,8 +81,8 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
83293
83294 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
83295
83296-static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
83297-static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
83298+static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
83299+static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
83300
83301 #endif
83302 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
83303diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
83304index 4b8a891..cb8df6e 100644
83305--- a/include/linux/vmalloc.h
83306+++ b/include/linux/vmalloc.h
83307@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
83308 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
83309 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
83310 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
83311+
83312+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
83313+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
83314+#endif
83315+
83316 /* bits [20..32] reserved for arch specific ioremap internals */
83317
83318 /*
83319@@ -142,7 +147,7 @@ extern void free_vm_area(struct vm_struct *area);
83320
83321 /* for /dev/kmem */
83322 extern long vread(char *buf, char *addr, unsigned long count);
83323-extern long vwrite(char *buf, char *addr, unsigned long count);
83324+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
83325
83326 /*
83327 * Internals. Dont't use..
83328diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
83329index 67ce70c..d540954 100644
83330--- a/include/linux/vmstat.h
83331+++ b/include/linux/vmstat.h
83332@@ -98,18 +98,18 @@ static inline void vm_events_fold_cpu(int cpu)
83333 /*
83334 * Zone based page accounting with per cpu differentials.
83335 */
83336-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83337+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83338
83339 static inline void zone_page_state_add(long x, struct zone *zone,
83340 enum zone_stat_item item)
83341 {
83342- atomic_long_add(x, &zone->vm_stat[item]);
83343- atomic_long_add(x, &vm_stat[item]);
83344+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
83345+ atomic_long_add_unchecked(x, &vm_stat[item]);
83346 }
83347
83348-static inline unsigned long global_page_state(enum zone_stat_item item)
83349+static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
83350 {
83351- long x = atomic_long_read(&vm_stat[item]);
83352+ long x = atomic_long_read_unchecked(&vm_stat[item]);
83353 #ifdef CONFIG_SMP
83354 if (x < 0)
83355 x = 0;
83356@@ -117,10 +117,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
83357 return x;
83358 }
83359
83360-static inline unsigned long zone_page_state(struct zone *zone,
83361+static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
83362 enum zone_stat_item item)
83363 {
83364- long x = atomic_long_read(&zone->vm_stat[item]);
83365+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
83366 #ifdef CONFIG_SMP
83367 if (x < 0)
83368 x = 0;
83369@@ -137,7 +137,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
83370 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
83371 enum zone_stat_item item)
83372 {
83373- long x = atomic_long_read(&zone->vm_stat[item]);
83374+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
83375
83376 #ifdef CONFIG_SMP
83377 int cpu;
83378@@ -226,8 +226,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
83379
83380 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
83381 {
83382- atomic_long_inc(&zone->vm_stat[item]);
83383- atomic_long_inc(&vm_stat[item]);
83384+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
83385+ atomic_long_inc_unchecked(&vm_stat[item]);
83386 }
83387
83388 static inline void __inc_zone_page_state(struct page *page,
83389@@ -238,8 +238,8 @@ static inline void __inc_zone_page_state(struct page *page,
83390
83391 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
83392 {
83393- atomic_long_dec(&zone->vm_stat[item]);
83394- atomic_long_dec(&vm_stat[item]);
83395+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
83396+ atomic_long_dec_unchecked(&vm_stat[item]);
83397 }
83398
83399 static inline void __dec_zone_page_state(struct page *page,
83400diff --git a/include/linux/xattr.h b/include/linux/xattr.h
83401index 91b0a68..0e9adf6 100644
83402--- a/include/linux/xattr.h
83403+++ b/include/linux/xattr.h
83404@@ -28,7 +28,7 @@ struct xattr_handler {
83405 size_t size, int handler_flags);
83406 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
83407 size_t size, int flags, int handler_flags);
83408-};
83409+} __do_const;
83410
83411 struct xattr {
83412 const char *name;
83413@@ -37,6 +37,9 @@ struct xattr {
83414 };
83415
83416 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
83417+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
83418+ssize_t pax_getxattr(struct dentry *, void *, size_t);
83419+#endif
83420 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
83421 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
83422 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
83423diff --git a/include/linux/zlib.h b/include/linux/zlib.h
83424index 9c5a6b4..09c9438 100644
83425--- a/include/linux/zlib.h
83426+++ b/include/linux/zlib.h
83427@@ -31,6 +31,7 @@
83428 #define _ZLIB_H
83429
83430 #include <linux/zconf.h>
83431+#include <linux/compiler.h>
83432
83433 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
83434 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
83435@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
83436
83437 /* basic functions */
83438
83439-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
83440+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
83441 /*
83442 Returns the number of bytes that needs to be allocated for a per-
83443 stream workspace with the specified parameters. A pointer to this
83444diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
83445index c768c9f..bdcaa5a 100644
83446--- a/include/media/v4l2-dev.h
83447+++ b/include/media/v4l2-dev.h
83448@@ -76,7 +76,7 @@ struct v4l2_file_operations {
83449 int (*mmap) (struct file *, struct vm_area_struct *);
83450 int (*open) (struct file *);
83451 int (*release) (struct file *);
83452-};
83453+} __do_const;
83454
83455 /*
83456 * Newer version of video_device, handled by videodev2.c
83457diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
83458index c9b1593..a572459 100644
83459--- a/include/media/v4l2-device.h
83460+++ b/include/media/v4l2-device.h
83461@@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
83462 this function returns 0. If the name ends with a digit (e.g. cx18),
83463 then the name will be set to cx18-0 since cx180 looks really odd. */
83464 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
83465- atomic_t *instance);
83466+ atomic_unchecked_t *instance);
83467
83468 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
83469 Since the parent disappears this ensures that v4l2_dev doesn't have an
83470diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
83471index 9a36d92..0aafe2a 100644
83472--- a/include/net/9p/transport.h
83473+++ b/include/net/9p/transport.h
83474@@ -60,7 +60,7 @@ struct p9_trans_module {
83475 int (*cancel) (struct p9_client *, struct p9_req_t *req);
83476 int (*zc_request)(struct p9_client *, struct p9_req_t *,
83477 char *, char *, int , int, int, int);
83478-};
83479+} __do_const;
83480
83481 void v9fs_register_trans(struct p9_trans_module *m);
83482 void v9fs_unregister_trans(struct p9_trans_module *m);
83483diff --git a/include/net/af_unix.h b/include/net/af_unix.h
83484index a175ba4..196eb82 100644
83485--- a/include/net/af_unix.h
83486+++ b/include/net/af_unix.h
83487@@ -36,7 +36,7 @@ struct unix_skb_parms {
83488 u32 secid; /* Security ID */
83489 #endif
83490 u32 consumed;
83491-};
83492+} __randomize_layout;
83493
83494 #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
83495 #define UNIXSID(skb) (&UNIXCB((skb)).secid)
83496diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
83497index dbc4a89..4a59b5d 100644
83498--- a/include/net/bluetooth/l2cap.h
83499+++ b/include/net/bluetooth/l2cap.h
83500@@ -600,7 +600,7 @@ struct l2cap_ops {
83501 long (*get_sndtimeo) (struct l2cap_chan *chan);
83502 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
83503 unsigned long len, int nb);
83504-};
83505+} __do_const;
83506
83507 struct l2cap_conn {
83508 struct hci_conn *hcon;
83509diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
83510index f2ae33d..c457cf0 100644
83511--- a/include/net/caif/cfctrl.h
83512+++ b/include/net/caif/cfctrl.h
83513@@ -52,7 +52,7 @@ struct cfctrl_rsp {
83514 void (*radioset_rsp)(void);
83515 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
83516 struct cflayer *client_layer);
83517-};
83518+} __no_const;
83519
83520 /* Link Setup Parameters for CAIF-Links. */
83521 struct cfctrl_link_param {
83522@@ -101,8 +101,8 @@ struct cfctrl_request_info {
83523 struct cfctrl {
83524 struct cfsrvl serv;
83525 struct cfctrl_rsp res;
83526- atomic_t req_seq_no;
83527- atomic_t rsp_seq_no;
83528+ atomic_unchecked_t req_seq_no;
83529+ atomic_unchecked_t rsp_seq_no;
83530 struct list_head list;
83531 /* Protects from simultaneous access to first_req list */
83532 spinlock_t info_list_lock;
83533diff --git a/include/net/flow.h b/include/net/flow.h
83534index d23e7fa..e188307 100644
83535--- a/include/net/flow.h
83536+++ b/include/net/flow.h
83537@@ -221,6 +221,6 @@ struct flow_cache_object *flow_cache_lookup(struct net *net,
83538
83539 void flow_cache_flush(void);
83540 void flow_cache_flush_deferred(void);
83541-extern atomic_t flow_cache_genid;
83542+extern atomic_unchecked_t flow_cache_genid;
83543
83544 #endif
83545diff --git a/include/net/genetlink.h b/include/net/genetlink.h
83546index 93695f0..766d71c 100644
83547--- a/include/net/genetlink.h
83548+++ b/include/net/genetlink.h
83549@@ -120,7 +120,7 @@ struct genl_ops {
83550 u8 cmd;
83551 u8 internal_flags;
83552 u8 flags;
83553-};
83554+} __do_const;
83555
83556 int __genl_register_family(struct genl_family *family);
83557
83558diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
83559index 734d9b5..48a9a4b 100644
83560--- a/include/net/gro_cells.h
83561+++ b/include/net/gro_cells.h
83562@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
83563 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
83564
83565 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
83566- atomic_long_inc(&dev->rx_dropped);
83567+ atomic_long_inc_unchecked(&dev->rx_dropped);
83568 kfree_skb(skb);
83569 return;
83570 }
83571diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
83572index c55aeed..b3393f4 100644
83573--- a/include/net/inet_connection_sock.h
83574+++ b/include/net/inet_connection_sock.h
83575@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
83576 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
83577 int (*bind_conflict)(const struct sock *sk,
83578 const struct inet_bind_bucket *tb, bool relax);
83579-};
83580+} __do_const;
83581
83582 /** inet_connection_sock - INET connection oriented sock
83583 *
83584diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
83585index 6efe73c..fa94270 100644
83586--- a/include/net/inetpeer.h
83587+++ b/include/net/inetpeer.h
83588@@ -47,8 +47,8 @@ struct inet_peer {
83589 */
83590 union {
83591 struct {
83592- atomic_t rid; /* Frag reception counter */
83593- atomic_t ip_id_count; /* IP ID for the next packet */
83594+ atomic_unchecked_t rid; /* Frag reception counter */
83595+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
83596 };
83597 struct rcu_head rcu;
83598 struct inet_peer *gc_next;
83599@@ -177,16 +177,13 @@ static inline void inet_peer_refcheck(const struct inet_peer *p)
83600 /* can be called with or without local BH being disabled */
83601 static inline int inet_getid(struct inet_peer *p, int more)
83602 {
83603- int old, new;
83604+ int id;
83605 more++;
83606 inet_peer_refcheck(p);
83607- do {
83608- old = atomic_read(&p->ip_id_count);
83609- new = old + more;
83610- if (!new)
83611- new = 1;
83612- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
83613- return new;
83614+ id = atomic_add_return_unchecked(more, &p->ip_id_count);
83615+ if (!id)
83616+ id = atomic_inc_return_unchecked(&p->ip_id_count);
83617+ return id;
83618 }
83619
83620 #endif /* _NET_INETPEER_H */
83621diff --git a/include/net/ip.h b/include/net/ip.h
83622index 23be0fd..0cb3e2c 100644
83623--- a/include/net/ip.h
83624+++ b/include/net/ip.h
83625@@ -214,7 +214,7 @@ static inline void snmp_mib_free(void __percpu *ptr[SNMP_ARRAY_SZ])
83626
83627 void inet_get_local_port_range(struct net *net, int *low, int *high);
83628
83629-extern unsigned long *sysctl_local_reserved_ports;
83630+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
83631 static inline int inet_is_reserved_local_port(int port)
83632 {
83633 return test_bit(port, sysctl_local_reserved_ports);
83634diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
83635index 9922093..a1755d6 100644
83636--- a/include/net/ip_fib.h
83637+++ b/include/net/ip_fib.h
83638@@ -169,7 +169,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
83639
83640 #define FIB_RES_SADDR(net, res) \
83641 ((FIB_RES_NH(res).nh_saddr_genid == \
83642- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
83643+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
83644 FIB_RES_NH(res).nh_saddr : \
83645 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
83646 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
83647diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
83648index 5679d92..2e7a690 100644
83649--- a/include/net/ip_vs.h
83650+++ b/include/net/ip_vs.h
83651@@ -558,7 +558,7 @@ struct ip_vs_conn {
83652 struct ip_vs_conn *control; /* Master control connection */
83653 atomic_t n_control; /* Number of controlled ones */
83654 struct ip_vs_dest *dest; /* real server */
83655- atomic_t in_pkts; /* incoming packet counter */
83656+ atomic_unchecked_t in_pkts; /* incoming packet counter */
83657
83658 /* packet transmitter for different forwarding methods. If it
83659 mangles the packet, it must return NF_DROP or better NF_STOLEN,
83660@@ -705,7 +705,7 @@ struct ip_vs_dest {
83661 __be16 port; /* port number of the server */
83662 union nf_inet_addr addr; /* IP address of the server */
83663 volatile unsigned int flags; /* dest status flags */
83664- atomic_t conn_flags; /* flags to copy to conn */
83665+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
83666 atomic_t weight; /* server weight */
83667
83668 atomic_t refcnt; /* reference counter */
83669@@ -960,11 +960,11 @@ struct netns_ipvs {
83670 /* ip_vs_lblc */
83671 int sysctl_lblc_expiration;
83672 struct ctl_table_header *lblc_ctl_header;
83673- struct ctl_table *lblc_ctl_table;
83674+ ctl_table_no_const *lblc_ctl_table;
83675 /* ip_vs_lblcr */
83676 int sysctl_lblcr_expiration;
83677 struct ctl_table_header *lblcr_ctl_header;
83678- struct ctl_table *lblcr_ctl_table;
83679+ ctl_table_no_const *lblcr_ctl_table;
83680 /* ip_vs_est */
83681 struct list_head est_list; /* estimator list */
83682 spinlock_t est_lock;
83683diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
83684index 8d4f588..2e37ad2 100644
83685--- a/include/net/irda/ircomm_tty.h
83686+++ b/include/net/irda/ircomm_tty.h
83687@@ -33,6 +33,7 @@
83688 #include <linux/termios.h>
83689 #include <linux/timer.h>
83690 #include <linux/tty.h> /* struct tty_struct */
83691+#include <asm/local.h>
83692
83693 #include <net/irda/irias_object.h>
83694 #include <net/irda/ircomm_core.h>
83695diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
83696index 714cc9a..ea05f3e 100644
83697--- a/include/net/iucv/af_iucv.h
83698+++ b/include/net/iucv/af_iucv.h
83699@@ -149,7 +149,7 @@ struct iucv_skb_cb {
83700 struct iucv_sock_list {
83701 struct hlist_head head;
83702 rwlock_t lock;
83703- atomic_t autobind_name;
83704+ atomic_unchecked_t autobind_name;
83705 };
83706
83707 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
83708diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
83709index f3be818..bf46196 100644
83710--- a/include/net/llc_c_ac.h
83711+++ b/include/net/llc_c_ac.h
83712@@ -87,7 +87,7 @@
83713 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
83714 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
83715
83716-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
83717+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
83718
83719 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
83720 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
83721diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
83722index 3948cf1..83b28c4 100644
83723--- a/include/net/llc_c_ev.h
83724+++ b/include/net/llc_c_ev.h
83725@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
83726 return (struct llc_conn_state_ev *)skb->cb;
83727 }
83728
83729-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
83730-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
83731+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
83732+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
83733
83734 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
83735 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
83736diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
83737index 0e79cfb..f46db31 100644
83738--- a/include/net/llc_c_st.h
83739+++ b/include/net/llc_c_st.h
83740@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
83741 u8 next_state;
83742 llc_conn_ev_qfyr_t *ev_qualifiers;
83743 llc_conn_action_t *ev_actions;
83744-};
83745+} __do_const;
83746
83747 struct llc_conn_state {
83748 u8 current_state;
83749diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
83750index a61b98c..aade1eb 100644
83751--- a/include/net/llc_s_ac.h
83752+++ b/include/net/llc_s_ac.h
83753@@ -23,7 +23,7 @@
83754 #define SAP_ACT_TEST_IND 9
83755
83756 /* All action functions must look like this */
83757-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
83758+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
83759
83760 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
83761 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
83762diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
83763index 567c681..cd73ac0 100644
83764--- a/include/net/llc_s_st.h
83765+++ b/include/net/llc_s_st.h
83766@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
83767 llc_sap_ev_t ev;
83768 u8 next_state;
83769 llc_sap_action_t *ev_actions;
83770-};
83771+} __do_const;
83772
83773 struct llc_sap_state {
83774 u8 curr_state;
83775diff --git a/include/net/mac80211.h b/include/net/mac80211.h
83776index f4ab2fb..71a85ba 100644
83777--- a/include/net/mac80211.h
83778+++ b/include/net/mac80211.h
83779@@ -4476,7 +4476,7 @@ struct rate_control_ops {
83780 void (*add_sta_debugfs)(void *priv, void *priv_sta,
83781 struct dentry *dir);
83782 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
83783-};
83784+} __do_const;
83785
83786 static inline int rate_supported(struct ieee80211_sta *sta,
83787 enum ieee80211_band band,
83788diff --git a/include/net/neighbour.h b/include/net/neighbour.h
83789index 7277caf..fd095bc 100644
83790--- a/include/net/neighbour.h
83791+++ b/include/net/neighbour.h
83792@@ -163,7 +163,7 @@ struct neigh_ops {
83793 void (*error_report)(struct neighbour *, struct sk_buff *);
83794 int (*output)(struct neighbour *, struct sk_buff *);
83795 int (*connected_output)(struct neighbour *, struct sk_buff *);
83796-};
83797+} __do_const;
83798
83799 struct pneigh_entry {
83800 struct pneigh_entry *next;
83801@@ -203,7 +203,6 @@ struct neigh_table {
83802 void (*proxy_redo)(struct sk_buff *skb);
83803 char *id;
83804 struct neigh_parms parms;
83805- /* HACK. gc_* should follow parms without a gap! */
83806 int gc_interval;
83807 int gc_thresh1;
83808 int gc_thresh2;
83809@@ -218,7 +217,7 @@ struct neigh_table {
83810 struct neigh_statistics __percpu *stats;
83811 struct neigh_hash_table __rcu *nht;
83812 struct pneigh_entry **phash_buckets;
83813-};
83814+} __randomize_layout;
83815
83816 static inline int neigh_parms_family(struct neigh_parms *p)
83817 {
83818diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
83819index 991dcd9..ab58d00 100644
83820--- a/include/net/net_namespace.h
83821+++ b/include/net/net_namespace.h
83822@@ -124,8 +124,8 @@ struct net {
83823 struct netns_ipvs *ipvs;
83824 #endif
83825 struct sock *diag_nlsk;
83826- atomic_t fnhe_genid;
83827-};
83828+ atomic_unchecked_t fnhe_genid;
83829+} __randomize_layout;
83830
83831 /*
83832 * ifindex generation is per-net namespace, and loopback is
83833@@ -289,7 +289,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
83834 #define __net_init __init
83835 #define __net_exit __exit_refok
83836 #define __net_initdata __initdata
83837+#ifdef CONSTIFY_PLUGIN
83838 #define __net_initconst __initconst
83839+#else
83840+#define __net_initconst __initdata
83841+#endif
83842 #endif
83843
83844 struct pernet_operations {
83845@@ -299,7 +303,7 @@ struct pernet_operations {
83846 void (*exit_batch)(struct list_head *net_exit_list);
83847 int *id;
83848 size_t size;
83849-};
83850+} __do_const;
83851
83852 /*
83853 * Use these carefully. If you implement a network device and it
83854@@ -347,23 +351,23 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
83855
83856 static inline int rt_genid_ipv4(struct net *net)
83857 {
83858- return atomic_read(&net->ipv4.rt_genid);
83859+ return atomic_read_unchecked(&net->ipv4.rt_genid);
83860 }
83861
83862 static inline void rt_genid_bump_ipv4(struct net *net)
83863 {
83864- atomic_inc(&net->ipv4.rt_genid);
83865+ atomic_inc_unchecked(&net->ipv4.rt_genid);
83866 }
83867
83868 #if IS_ENABLED(CONFIG_IPV6)
83869 static inline int rt_genid_ipv6(struct net *net)
83870 {
83871- return atomic_read(&net->ipv6.rt_genid);
83872+ return atomic_read_unchecked(&net->ipv6.rt_genid);
83873 }
83874
83875 static inline void rt_genid_bump_ipv6(struct net *net)
83876 {
83877- atomic_inc(&net->ipv6.rt_genid);
83878+ atomic_inc_unchecked(&net->ipv6.rt_genid);
83879 }
83880 #else
83881 static inline int rt_genid_ipv6(struct net *net)
83882@@ -385,12 +389,12 @@ static inline void rt_genid_bump_all(struct net *net)
83883
83884 static inline int fnhe_genid(struct net *net)
83885 {
83886- return atomic_read(&net->fnhe_genid);
83887+ return atomic_read_unchecked(&net->fnhe_genid);
83888 }
83889
83890 static inline void fnhe_genid_bump(struct net *net)
83891 {
83892- atomic_inc(&net->fnhe_genid);
83893+ atomic_inc_unchecked(&net->fnhe_genid);
83894 }
83895
83896 #endif /* __NET_NET_NAMESPACE_H */
83897diff --git a/include/net/netdma.h b/include/net/netdma.h
83898index 8ba8ce2..99b7fff 100644
83899--- a/include/net/netdma.h
83900+++ b/include/net/netdma.h
83901@@ -24,7 +24,7 @@
83902 #include <linux/dmaengine.h>
83903 #include <linux/skbuff.h>
83904
83905-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
83906+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
83907 struct sk_buff *skb, int offset, struct iovec *to,
83908 size_t len, struct dma_pinned_list *pinned_list);
83909
83910diff --git a/include/net/netfilter/nf_conntrack_extend.h b/include/net/netfilter/nf_conntrack_extend.h
83911index 956b175..55d1504 100644
83912--- a/include/net/netfilter/nf_conntrack_extend.h
83913+++ b/include/net/netfilter/nf_conntrack_extend.h
83914@@ -47,8 +47,8 @@ enum nf_ct_ext_id {
83915 /* Extensions: optional stuff which isn't permanently in struct. */
83916 struct nf_ct_ext {
83917 struct rcu_head rcu;
83918- u8 offset[NF_CT_EXT_NUM];
83919- u8 len;
83920+ u16 offset[NF_CT_EXT_NUM];
83921+ u16 len;
83922 char data[0];
83923 };
83924
83925diff --git a/include/net/netlink.h b/include/net/netlink.h
83926index 2b47eaa..6d5bcc2 100644
83927--- a/include/net/netlink.h
83928+++ b/include/net/netlink.h
83929@@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
83930 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
83931 {
83932 if (mark)
83933- skb_trim(skb, (unsigned char *) mark - skb->data);
83934+ skb_trim(skb, (const unsigned char *) mark - skb->data);
83935 }
83936
83937 /**
83938diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
83939index fbcc7fa..03c7e51 100644
83940--- a/include/net/netns/conntrack.h
83941+++ b/include/net/netns/conntrack.h
83942@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
83943 struct nf_proto_net {
83944 #ifdef CONFIG_SYSCTL
83945 struct ctl_table_header *ctl_table_header;
83946- struct ctl_table *ctl_table;
83947+ ctl_table_no_const *ctl_table;
83948 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
83949 struct ctl_table_header *ctl_compat_header;
83950- struct ctl_table *ctl_compat_table;
83951+ ctl_table_no_const *ctl_compat_table;
83952 #endif
83953 #endif
83954 unsigned int users;
83955@@ -58,7 +58,7 @@ struct nf_ip_net {
83956 struct nf_icmp_net icmpv6;
83957 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
83958 struct ctl_table_header *ctl_table_header;
83959- struct ctl_table *ctl_table;
83960+ ctl_table_no_const *ctl_table;
83961 #endif
83962 };
83963
83964diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
83965index 80f500a..f0c23c2 100644
83966--- a/include/net/netns/ipv4.h
83967+++ b/include/net/netns/ipv4.h
83968@@ -74,7 +74,7 @@ struct netns_ipv4 {
83969
83970 kgid_t sysctl_ping_group_range[2];
83971
83972- atomic_t dev_addr_genid;
83973+ atomic_unchecked_t dev_addr_genid;
83974
83975 #ifdef CONFIG_IP_MROUTE
83976 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
83977@@ -84,6 +84,6 @@ struct netns_ipv4 {
83978 struct fib_rules_ops *mr_rules_ops;
83979 #endif
83980 #endif
83981- atomic_t rt_genid;
83982+ atomic_unchecked_t rt_genid;
83983 };
83984 #endif
83985diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
83986index 21edaf1..4c5faae 100644
83987--- a/include/net/netns/ipv6.h
83988+++ b/include/net/netns/ipv6.h
83989@@ -73,8 +73,8 @@ struct netns_ipv6 {
83990 struct fib_rules_ops *mr6_rules_ops;
83991 #endif
83992 #endif
83993- atomic_t dev_addr_genid;
83994- atomic_t rt_genid;
83995+ atomic_unchecked_t dev_addr_genid;
83996+ atomic_unchecked_t rt_genid;
83997 };
83998
83999 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
84000diff --git a/include/net/ping.h b/include/net/ping.h
84001index 026479b..d9b2829 100644
84002--- a/include/net/ping.h
84003+++ b/include/net/ping.h
84004@@ -54,7 +54,7 @@ struct ping_iter_state {
84005
84006 extern struct proto ping_prot;
84007 #if IS_ENABLED(CONFIG_IPV6)
84008-extern struct pingv6_ops pingv6_ops;
84009+extern struct pingv6_ops *pingv6_ops;
84010 #endif
84011
84012 struct pingfakehdr {
84013diff --git a/include/net/protocol.h b/include/net/protocol.h
84014index a7e986b..dc67bce 100644
84015--- a/include/net/protocol.h
84016+++ b/include/net/protocol.h
84017@@ -49,7 +49,7 @@ struct net_protocol {
84018 * socket lookup?
84019 */
84020 icmp_strict_tag_validation:1;
84021-};
84022+} __do_const;
84023
84024 #if IS_ENABLED(CONFIG_IPV6)
84025 struct inet6_protocol {
84026@@ -62,7 +62,7 @@ struct inet6_protocol {
84027 u8 type, u8 code, int offset,
84028 __be32 info);
84029 unsigned int flags; /* INET6_PROTO_xxx */
84030-};
84031+} __do_const;
84032
84033 #define INET6_PROTO_NOPOLICY 0x1
84034 #define INET6_PROTO_FINAL 0x2
84035diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
84036index 661e45d..54c39df 100644
84037--- a/include/net/rtnetlink.h
84038+++ b/include/net/rtnetlink.h
84039@@ -93,7 +93,7 @@ struct rtnl_link_ops {
84040 int (*fill_slave_info)(struct sk_buff *skb,
84041 const struct net_device *dev,
84042 const struct net_device *slave_dev);
84043-};
84044+} __do_const;
84045
84046 int __rtnl_link_register(struct rtnl_link_ops *ops);
84047 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
84048diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
84049index 4a5b9a3..ca27d73 100644
84050--- a/include/net/sctp/checksum.h
84051+++ b/include/net/sctp/checksum.h
84052@@ -61,8 +61,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
84053 unsigned int offset)
84054 {
84055 struct sctphdr *sh = sctp_hdr(skb);
84056- __le32 ret, old = sh->checksum;
84057- const struct skb_checksum_ops ops = {
84058+ __le32 ret, old = sh->checksum;
84059+ static const struct skb_checksum_ops ops = {
84060 .update = sctp_csum_update,
84061 .combine = sctp_csum_combine,
84062 };
84063diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
84064index 7f4eeb3..37e8fe1 100644
84065--- a/include/net/sctp/sm.h
84066+++ b/include/net/sctp/sm.h
84067@@ -80,7 +80,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
84068 typedef struct {
84069 sctp_state_fn_t *fn;
84070 const char *name;
84071-} sctp_sm_table_entry_t;
84072+} __do_const sctp_sm_table_entry_t;
84073
84074 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
84075 * currently in use.
84076@@ -292,7 +292,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
84077 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
84078
84079 /* Extern declarations for major data structures. */
84080-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
84081+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
84082
84083
84084 /* Get the size of a DATA chunk payload. */
84085diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
84086index 6ee76c8..45f2609 100644
84087--- a/include/net/sctp/structs.h
84088+++ b/include/net/sctp/structs.h
84089@@ -507,7 +507,7 @@ struct sctp_pf {
84090 struct sctp_association *asoc);
84091 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
84092 struct sctp_af *af;
84093-};
84094+} __do_const;
84095
84096
84097 /* Structure to track chunk fragments that have been acked, but peer
84098diff --git a/include/net/sock.h b/include/net/sock.h
84099index b9586a1..b2948c0 100644
84100--- a/include/net/sock.h
84101+++ b/include/net/sock.h
84102@@ -348,7 +348,7 @@ struct sock {
84103 unsigned int sk_napi_id;
84104 unsigned int sk_ll_usec;
84105 #endif
84106- atomic_t sk_drops;
84107+ atomic_unchecked_t sk_drops;
84108 int sk_rcvbuf;
84109
84110 struct sk_filter __rcu *sk_filter;
84111@@ -1036,7 +1036,7 @@ struct proto {
84112 void (*destroy_cgroup)(struct mem_cgroup *memcg);
84113 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
84114 #endif
84115-};
84116+} __randomize_layout;
84117
84118 /*
84119 * Bits in struct cg_proto.flags
84120@@ -1223,7 +1223,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
84121 return ret >> PAGE_SHIFT;
84122 }
84123
84124-static inline long
84125+static inline long __intentional_overflow(-1)
84126 sk_memory_allocated(const struct sock *sk)
84127 {
84128 struct proto *prot = sk->sk_prot;
84129@@ -1368,7 +1368,7 @@ struct sock_iocb {
84130 struct scm_cookie *scm;
84131 struct msghdr *msg, async_msg;
84132 struct kiocb *kiocb;
84133-};
84134+} __randomize_layout;
84135
84136 static inline struct sock_iocb *kiocb_to_siocb(struct kiocb *iocb)
84137 {
84138@@ -1830,7 +1830,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
84139 }
84140
84141 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
84142- char __user *from, char *to,
84143+ char __user *from, unsigned char *to,
84144 int copy, int offset)
84145 {
84146 if (skb->ip_summed == CHECKSUM_NONE) {
84147@@ -2092,7 +2092,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
84148 }
84149 }
84150
84151-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
84152+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
84153
84154 /**
84155 * sk_page_frag - return an appropriate page_frag
84156diff --git a/include/net/tcp.h b/include/net/tcp.h
84157index 743acce..44a58b0 100644
84158--- a/include/net/tcp.h
84159+++ b/include/net/tcp.h
84160@@ -541,7 +541,7 @@ void tcp_retransmit_timer(struct sock *sk);
84161 void tcp_xmit_retransmit_queue(struct sock *);
84162 void tcp_simple_retransmit(struct sock *);
84163 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
84164-int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
84165+int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
84166
84167 void tcp_send_probe0(struct sock *);
84168 void tcp_send_partial(struct sock *);
84169@@ -710,8 +710,8 @@ struct tcp_skb_cb {
84170 struct inet6_skb_parm h6;
84171 #endif
84172 } header; /* For incoming frames */
84173- __u32 seq; /* Starting sequence number */
84174- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
84175+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
84176+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
84177 __u32 when; /* used to compute rtt's */
84178 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
84179
84180@@ -725,7 +725,7 @@ struct tcp_skb_cb {
84181
84182 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
84183 /* 1 byte hole */
84184- __u32 ack_seq; /* Sequence number ACK'd */
84185+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
84186 };
84187
84188 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
84189diff --git a/include/net/xfrm.h b/include/net/xfrm.h
84190index fb5654a..4457522 100644
84191--- a/include/net/xfrm.h
84192+++ b/include/net/xfrm.h
84193@@ -286,7 +286,6 @@ struct xfrm_dst;
84194 struct xfrm_policy_afinfo {
84195 unsigned short family;
84196 struct dst_ops *dst_ops;
84197- void (*garbage_collect)(struct net *net);
84198 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
84199 const xfrm_address_t *saddr,
84200 const xfrm_address_t *daddr);
84201@@ -304,7 +303,7 @@ struct xfrm_policy_afinfo {
84202 struct net_device *dev,
84203 const struct flowi *fl);
84204 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
84205-};
84206+} __do_const;
84207
84208 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
84209 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
84210@@ -343,7 +342,7 @@ struct xfrm_state_afinfo {
84211 int (*transport_finish)(struct sk_buff *skb,
84212 int async);
84213 void (*local_error)(struct sk_buff *skb, u32 mtu);
84214-};
84215+} __do_const;
84216
84217 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
84218 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
84219@@ -428,7 +427,7 @@ struct xfrm_mode {
84220 struct module *owner;
84221 unsigned int encap;
84222 int flags;
84223-};
84224+} __do_const;
84225
84226 /* Flags for xfrm_mode. */
84227 enum {
84228@@ -525,7 +524,7 @@ struct xfrm_policy {
84229 struct timer_list timer;
84230
84231 struct flow_cache_object flo;
84232- atomic_t genid;
84233+ atomic_unchecked_t genid;
84234 u32 priority;
84235 u32 index;
84236 struct xfrm_mark mark;
84237@@ -1165,6 +1164,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
84238 }
84239
84240 void xfrm_garbage_collect(struct net *net);
84241+void xfrm_garbage_collect_deferred(struct net *net);
84242
84243 #else
84244
84245@@ -1203,6 +1203,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
84246 static inline void xfrm_garbage_collect(struct net *net)
84247 {
84248 }
84249+static inline void xfrm_garbage_collect_deferred(struct net *net)
84250+{
84251+}
84252 #endif
84253
84254 static __inline__
84255diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
84256index 1017e0b..227aa4d 100644
84257--- a/include/rdma/iw_cm.h
84258+++ b/include/rdma/iw_cm.h
84259@@ -122,7 +122,7 @@ struct iw_cm_verbs {
84260 int backlog);
84261
84262 int (*destroy_listen)(struct iw_cm_id *cm_id);
84263-};
84264+} __no_const;
84265
84266 /**
84267 * iw_create_cm_id - Create an IW CM identifier.
84268diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
84269index 52beadf..598734c 100644
84270--- a/include/scsi/libfc.h
84271+++ b/include/scsi/libfc.h
84272@@ -771,6 +771,7 @@ struct libfc_function_template {
84273 */
84274 void (*disc_stop_final) (struct fc_lport *);
84275 };
84276+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
84277
84278 /**
84279 * struct fc_disc - Discovery context
84280@@ -875,7 +876,7 @@ struct fc_lport {
84281 struct fc_vport *vport;
84282
84283 /* Operational Information */
84284- struct libfc_function_template tt;
84285+ libfc_function_template_no_const tt;
84286 u8 link_up;
84287 u8 qfull;
84288 enum fc_lport_state state;
84289diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
84290index d65fbec..f80fef2 100644
84291--- a/include/scsi/scsi_device.h
84292+++ b/include/scsi/scsi_device.h
84293@@ -180,9 +180,9 @@ struct scsi_device {
84294 unsigned int max_device_blocked; /* what device_blocked counts down from */
84295 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
84296
84297- atomic_t iorequest_cnt;
84298- atomic_t iodone_cnt;
84299- atomic_t ioerr_cnt;
84300+ atomic_unchecked_t iorequest_cnt;
84301+ atomic_unchecked_t iodone_cnt;
84302+ atomic_unchecked_t ioerr_cnt;
84303
84304 struct device sdev_gendev,
84305 sdev_dev;
84306diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
84307index b797e8f..8e2c3aa 100644
84308--- a/include/scsi/scsi_transport_fc.h
84309+++ b/include/scsi/scsi_transport_fc.h
84310@@ -751,7 +751,8 @@ struct fc_function_template {
84311 unsigned long show_host_system_hostname:1;
84312
84313 unsigned long disable_target_scan:1;
84314-};
84315+} __do_const;
84316+typedef struct fc_function_template __no_const fc_function_template_no_const;
84317
84318
84319 /**
84320diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
84321index ae6c3b8..fd748ac 100644
84322--- a/include/sound/compress_driver.h
84323+++ b/include/sound/compress_driver.h
84324@@ -128,7 +128,7 @@ struct snd_compr_ops {
84325 struct snd_compr_caps *caps);
84326 int (*get_codec_caps) (struct snd_compr_stream *stream,
84327 struct snd_compr_codec_caps *codec);
84328-};
84329+} __no_const;
84330
84331 /**
84332 * struct snd_compr: Compressed device
84333diff --git a/include/sound/soc.h b/include/sound/soc.h
84334index 9a00147..d814573 100644
84335--- a/include/sound/soc.h
84336+++ b/include/sound/soc.h
84337@@ -770,7 +770,7 @@ struct snd_soc_codec_driver {
84338 /* probe ordering - for components with runtime dependencies */
84339 int probe_order;
84340 int remove_order;
84341-};
84342+} __do_const;
84343
84344 /* SoC platform interface */
84345 struct snd_soc_platform_driver {
84346@@ -816,7 +816,7 @@ struct snd_soc_platform_driver {
84347 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
84348 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
84349 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
84350-};
84351+} __do_const;
84352
84353 struct snd_soc_platform {
84354 const char *name;
84355diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
84356index 1772fad..282e3e2 100644
84357--- a/include/target/target_core_base.h
84358+++ b/include/target/target_core_base.h
84359@@ -754,7 +754,7 @@ struct se_device {
84360 atomic_long_t write_bytes;
84361 /* Active commands on this virtual SE device */
84362 atomic_t simple_cmds;
84363- atomic_t dev_ordered_id;
84364+ atomic_unchecked_t dev_ordered_id;
84365 atomic_t dev_ordered_sync;
84366 atomic_t dev_qf_count;
84367 int export_count;
84368diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
84369new file mode 100644
84370index 0000000..fb634b7
84371--- /dev/null
84372+++ b/include/trace/events/fs.h
84373@@ -0,0 +1,53 @@
84374+#undef TRACE_SYSTEM
84375+#define TRACE_SYSTEM fs
84376+
84377+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
84378+#define _TRACE_FS_H
84379+
84380+#include <linux/fs.h>
84381+#include <linux/tracepoint.h>
84382+
84383+TRACE_EVENT(do_sys_open,
84384+
84385+ TP_PROTO(const char *filename, int flags, int mode),
84386+
84387+ TP_ARGS(filename, flags, mode),
84388+
84389+ TP_STRUCT__entry(
84390+ __string( filename, filename )
84391+ __field( int, flags )
84392+ __field( int, mode )
84393+ ),
84394+
84395+ TP_fast_assign(
84396+ __assign_str(filename, filename);
84397+ __entry->flags = flags;
84398+ __entry->mode = mode;
84399+ ),
84400+
84401+ TP_printk("\"%s\" %x %o",
84402+ __get_str(filename), __entry->flags, __entry->mode)
84403+);
84404+
84405+TRACE_EVENT(open_exec,
84406+
84407+ TP_PROTO(const char *filename),
84408+
84409+ TP_ARGS(filename),
84410+
84411+ TP_STRUCT__entry(
84412+ __string( filename, filename )
84413+ ),
84414+
84415+ TP_fast_assign(
84416+ __assign_str(filename, filename);
84417+ ),
84418+
84419+ TP_printk("\"%s\"",
84420+ __get_str(filename))
84421+);
84422+
84423+#endif /* _TRACE_FS_H */
84424+
84425+/* This part must be outside protection */
84426+#include <trace/define_trace.h>
84427diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
84428index 1c09820..7f5ec79 100644
84429--- a/include/trace/events/irq.h
84430+++ b/include/trace/events/irq.h
84431@@ -36,7 +36,7 @@ struct softirq_action;
84432 */
84433 TRACE_EVENT(irq_handler_entry,
84434
84435- TP_PROTO(int irq, struct irqaction *action),
84436+ TP_PROTO(int irq, const struct irqaction *action),
84437
84438 TP_ARGS(irq, action),
84439
84440@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
84441 */
84442 TRACE_EVENT(irq_handler_exit,
84443
84444- TP_PROTO(int irq, struct irqaction *action, int ret),
84445+ TP_PROTO(int irq, const struct irqaction *action, int ret),
84446
84447 TP_ARGS(irq, action, ret),
84448
84449diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
84450index 7caf44c..23c6f27 100644
84451--- a/include/uapi/linux/a.out.h
84452+++ b/include/uapi/linux/a.out.h
84453@@ -39,6 +39,14 @@ enum machine_type {
84454 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
84455 };
84456
84457+/* Constants for the N_FLAGS field */
84458+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
84459+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
84460+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
84461+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
84462+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
84463+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
84464+
84465 #if !defined (N_MAGIC)
84466 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
84467 #endif
84468diff --git a/include/uapi/linux/bcache.h b/include/uapi/linux/bcache.h
84469index 22b6ad3..aeba37e 100644
84470--- a/include/uapi/linux/bcache.h
84471+++ b/include/uapi/linux/bcache.h
84472@@ -5,6 +5,7 @@
84473 * Bcache on disk data structures
84474 */
84475
84476+#include <linux/compiler.h>
84477 #include <asm/types.h>
84478
84479 #define BITMASK(name, type, field, offset, size) \
84480@@ -20,8 +21,8 @@ static inline void SET_##name(type *k, __u64 v) \
84481 /* Btree keys - all units are in sectors */
84482
84483 struct bkey {
84484- __u64 high;
84485- __u64 low;
84486+ __u64 high __intentional_overflow(-1);
84487+ __u64 low __intentional_overflow(-1);
84488 __u64 ptr[];
84489 };
84490
84491diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
84492index d876736..ccce5c0 100644
84493--- a/include/uapi/linux/byteorder/little_endian.h
84494+++ b/include/uapi/linux/byteorder/little_endian.h
84495@@ -42,51 +42,51 @@
84496
84497 static inline __le64 __cpu_to_le64p(const __u64 *p)
84498 {
84499- return (__force __le64)*p;
84500+ return (__force const __le64)*p;
84501 }
84502-static inline __u64 __le64_to_cpup(const __le64 *p)
84503+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
84504 {
84505- return (__force __u64)*p;
84506+ return (__force const __u64)*p;
84507 }
84508 static inline __le32 __cpu_to_le32p(const __u32 *p)
84509 {
84510- return (__force __le32)*p;
84511+ return (__force const __le32)*p;
84512 }
84513 static inline __u32 __le32_to_cpup(const __le32 *p)
84514 {
84515- return (__force __u32)*p;
84516+ return (__force const __u32)*p;
84517 }
84518 static inline __le16 __cpu_to_le16p(const __u16 *p)
84519 {
84520- return (__force __le16)*p;
84521+ return (__force const __le16)*p;
84522 }
84523 static inline __u16 __le16_to_cpup(const __le16 *p)
84524 {
84525- return (__force __u16)*p;
84526+ return (__force const __u16)*p;
84527 }
84528 static inline __be64 __cpu_to_be64p(const __u64 *p)
84529 {
84530- return (__force __be64)__swab64p(p);
84531+ return (__force const __be64)__swab64p(p);
84532 }
84533 static inline __u64 __be64_to_cpup(const __be64 *p)
84534 {
84535- return __swab64p((__u64 *)p);
84536+ return __swab64p((const __u64 *)p);
84537 }
84538 static inline __be32 __cpu_to_be32p(const __u32 *p)
84539 {
84540- return (__force __be32)__swab32p(p);
84541+ return (__force const __be32)__swab32p(p);
84542 }
84543-static inline __u32 __be32_to_cpup(const __be32 *p)
84544+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
84545 {
84546- return __swab32p((__u32 *)p);
84547+ return __swab32p((const __u32 *)p);
84548 }
84549 static inline __be16 __cpu_to_be16p(const __u16 *p)
84550 {
84551- return (__force __be16)__swab16p(p);
84552+ return (__force const __be16)__swab16p(p);
84553 }
84554 static inline __u16 __be16_to_cpup(const __be16 *p)
84555 {
84556- return __swab16p((__u16 *)p);
84557+ return __swab16p((const __u16 *)p);
84558 }
84559 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
84560 #define __le64_to_cpus(x) do { (void)(x); } while (0)
84561diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
84562index ef6103b..d4e65dd 100644
84563--- a/include/uapi/linux/elf.h
84564+++ b/include/uapi/linux/elf.h
84565@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
84566 #define PT_GNU_EH_FRAME 0x6474e550
84567
84568 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
84569+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
84570+
84571+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
84572+
84573+/* Constants for the e_flags field */
84574+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
84575+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
84576+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
84577+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
84578+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
84579+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
84580
84581 /*
84582 * Extended Numbering
84583@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
84584 #define DT_DEBUG 21
84585 #define DT_TEXTREL 22
84586 #define DT_JMPREL 23
84587+#define DT_FLAGS 30
84588+ #define DF_TEXTREL 0x00000004
84589 #define DT_ENCODING 32
84590 #define OLD_DT_LOOS 0x60000000
84591 #define DT_LOOS 0x6000000d
84592@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
84593 #define PF_W 0x2
84594 #define PF_X 0x1
84595
84596+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
84597+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
84598+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
84599+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
84600+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
84601+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
84602+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
84603+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
84604+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
84605+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
84606+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
84607+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
84608+
84609 typedef struct elf32_phdr{
84610 Elf32_Word p_type;
84611 Elf32_Off p_offset;
84612@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
84613 #define EI_OSABI 7
84614 #define EI_PAD 8
84615
84616+#define EI_PAX 14
84617+
84618 #define ELFMAG0 0x7f /* EI_MAG */
84619 #define ELFMAG1 'E'
84620 #define ELFMAG2 'L'
84621diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
84622index aa169c4..6a2771d 100644
84623--- a/include/uapi/linux/personality.h
84624+++ b/include/uapi/linux/personality.h
84625@@ -30,6 +30,7 @@ enum {
84626 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
84627 ADDR_NO_RANDOMIZE | \
84628 ADDR_COMPAT_LAYOUT | \
84629+ ADDR_LIMIT_3GB | \
84630 MMAP_PAGE_ZERO)
84631
84632 /*
84633diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
84634index 7530e74..e714828 100644
84635--- a/include/uapi/linux/screen_info.h
84636+++ b/include/uapi/linux/screen_info.h
84637@@ -43,7 +43,8 @@ struct screen_info {
84638 __u16 pages; /* 0x32 */
84639 __u16 vesa_attributes; /* 0x34 */
84640 __u32 capabilities; /* 0x36 */
84641- __u8 _reserved[6]; /* 0x3a */
84642+ __u16 vesapm_size; /* 0x3a */
84643+ __u8 _reserved[4]; /* 0x3c */
84644 } __attribute__((packed));
84645
84646 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
84647diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
84648index 0e011eb..82681b1 100644
84649--- a/include/uapi/linux/swab.h
84650+++ b/include/uapi/linux/swab.h
84651@@ -43,7 +43,7 @@
84652 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
84653 */
84654
84655-static inline __attribute_const__ __u16 __fswab16(__u16 val)
84656+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
84657 {
84658 #ifdef __HAVE_BUILTIN_BSWAP16__
84659 return __builtin_bswap16(val);
84660@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
84661 #endif
84662 }
84663
84664-static inline __attribute_const__ __u32 __fswab32(__u32 val)
84665+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
84666 {
84667 #ifdef __HAVE_BUILTIN_BSWAP32__
84668 return __builtin_bswap32(val);
84669@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
84670 #endif
84671 }
84672
84673-static inline __attribute_const__ __u64 __fswab64(__u64 val)
84674+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
84675 {
84676 #ifdef __HAVE_BUILTIN_BSWAP64__
84677 return __builtin_bswap64(val);
84678diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
84679index 6d67213..552fdd9 100644
84680--- a/include/uapi/linux/sysctl.h
84681+++ b/include/uapi/linux/sysctl.h
84682@@ -155,8 +155,6 @@ enum
84683 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
84684 };
84685
84686-
84687-
84688 /* CTL_VM names: */
84689 enum
84690 {
84691diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
84692index fe94bb9..c9e51c2 100644
84693--- a/include/uapi/linux/videodev2.h
84694+++ b/include/uapi/linux/videodev2.h
84695@@ -1227,7 +1227,7 @@ struct v4l2_ext_control {
84696 union {
84697 __s32 value;
84698 __s64 value64;
84699- char *string;
84700+ char __user *string;
84701 };
84702 } __attribute__ ((packed));
84703
84704diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
84705index c38355c..17a57bc 100644
84706--- a/include/uapi/linux/xattr.h
84707+++ b/include/uapi/linux/xattr.h
84708@@ -73,5 +73,9 @@
84709 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
84710 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
84711
84712+/* User namespace */
84713+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
84714+#define XATTR_PAX_FLAGS_SUFFIX "flags"
84715+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
84716
84717 #endif /* _UAPI_LINUX_XATTR_H */
84718diff --git a/include/video/udlfb.h b/include/video/udlfb.h
84719index f9466fa..f4e2b81 100644
84720--- a/include/video/udlfb.h
84721+++ b/include/video/udlfb.h
84722@@ -53,10 +53,10 @@ struct dlfb_data {
84723 u32 pseudo_palette[256];
84724 int blank_mode; /*one of FB_BLANK_ */
84725 /* blit-only rendering path metrics, exposed through sysfs */
84726- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
84727- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
84728- atomic_t bytes_sent; /* to usb, after compression including overhead */
84729- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
84730+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
84731+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
84732+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
84733+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
84734 };
84735
84736 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
84737diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
84738index 30f5362..8ed8ac9 100644
84739--- a/include/video/uvesafb.h
84740+++ b/include/video/uvesafb.h
84741@@ -122,6 +122,7 @@ struct uvesafb_par {
84742 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
84743 u8 pmi_setpal; /* PMI for palette changes */
84744 u16 *pmi_base; /* protected mode interface location */
84745+ u8 *pmi_code; /* protected mode code location */
84746 void *pmi_start;
84747 void *pmi_pal;
84748 u8 *vbe_state_orig; /*
84749diff --git a/init/Kconfig b/init/Kconfig
84750index d56cb03..7e6d5dc 100644
84751--- a/init/Kconfig
84752+++ b/init/Kconfig
84753@@ -1079,6 +1079,7 @@ endif # CGROUPS
84754
84755 config CHECKPOINT_RESTORE
84756 bool "Checkpoint/restore support" if EXPERT
84757+ depends on !GRKERNSEC
84758 default n
84759 help
84760 Enables additional kernel features in a sake of checkpoint/restore.
84761@@ -1545,7 +1546,7 @@ config SLUB_DEBUG
84762
84763 config COMPAT_BRK
84764 bool "Disable heap randomization"
84765- default y
84766+ default n
84767 help
84768 Randomizing heap placement makes heap exploits harder, but it
84769 also breaks ancient binaries (including anything libc5 based).
84770@@ -1833,7 +1834,7 @@ config INIT_ALL_POSSIBLE
84771 config STOP_MACHINE
84772 bool
84773 default y
84774- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
84775+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
84776 help
84777 Need stop_machine() primitive.
84778
84779diff --git a/init/Makefile b/init/Makefile
84780index 7bc47ee..6da2dc7 100644
84781--- a/init/Makefile
84782+++ b/init/Makefile
84783@@ -2,6 +2,9 @@
84784 # Makefile for the linux kernel.
84785 #
84786
84787+ccflags-y := $(GCC_PLUGINS_CFLAGS)
84788+asflags-y := $(GCC_PLUGINS_AFLAGS)
84789+
84790 obj-y := main.o version.o mounts.o
84791 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
84792 obj-y += noinitramfs.o
84793diff --git a/init/do_mounts.c b/init/do_mounts.c
84794index 8e5addc..c96ea61 100644
84795--- a/init/do_mounts.c
84796+++ b/init/do_mounts.c
84797@@ -359,11 +359,11 @@ static void __init get_fs_names(char *page)
84798 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
84799 {
84800 struct super_block *s;
84801- int err = sys_mount(name, "/root", fs, flags, data);
84802+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
84803 if (err)
84804 return err;
84805
84806- sys_chdir("/root");
84807+ sys_chdir((const char __force_user *)"/root");
84808 s = current->fs->pwd.dentry->d_sb;
84809 ROOT_DEV = s->s_dev;
84810 printk(KERN_INFO
84811@@ -484,18 +484,18 @@ void __init change_floppy(char *fmt, ...)
84812 va_start(args, fmt);
84813 vsprintf(buf, fmt, args);
84814 va_end(args);
84815- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
84816+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
84817 if (fd >= 0) {
84818 sys_ioctl(fd, FDEJECT, 0);
84819 sys_close(fd);
84820 }
84821 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
84822- fd = sys_open("/dev/console", O_RDWR, 0);
84823+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
84824 if (fd >= 0) {
84825 sys_ioctl(fd, TCGETS, (long)&termios);
84826 termios.c_lflag &= ~ICANON;
84827 sys_ioctl(fd, TCSETSF, (long)&termios);
84828- sys_read(fd, &c, 1);
84829+ sys_read(fd, (char __user *)&c, 1);
84830 termios.c_lflag |= ICANON;
84831 sys_ioctl(fd, TCSETSF, (long)&termios);
84832 sys_close(fd);
84833@@ -589,8 +589,8 @@ void __init prepare_namespace(void)
84834 mount_root();
84835 out:
84836 devtmpfs_mount("dev");
84837- sys_mount(".", "/", NULL, MS_MOVE, NULL);
84838- sys_chroot(".");
84839+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
84840+ sys_chroot((const char __force_user *)".");
84841 }
84842
84843 static bool is_tmpfs;
84844diff --git a/init/do_mounts.h b/init/do_mounts.h
84845index f5b978a..69dbfe8 100644
84846--- a/init/do_mounts.h
84847+++ b/init/do_mounts.h
84848@@ -15,15 +15,15 @@ extern int root_mountflags;
84849
84850 static inline int create_dev(char *name, dev_t dev)
84851 {
84852- sys_unlink(name);
84853- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
84854+ sys_unlink((char __force_user *)name);
84855+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
84856 }
84857
84858 #if BITS_PER_LONG == 32
84859 static inline u32 bstat(char *name)
84860 {
84861 struct stat64 stat;
84862- if (sys_stat64(name, &stat) != 0)
84863+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
84864 return 0;
84865 if (!S_ISBLK(stat.st_mode))
84866 return 0;
84867@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
84868 static inline u32 bstat(char *name)
84869 {
84870 struct stat stat;
84871- if (sys_newstat(name, &stat) != 0)
84872+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
84873 return 0;
84874 if (!S_ISBLK(stat.st_mode))
84875 return 0;
84876diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
84877index 3e0878e..8a9d7a0 100644
84878--- a/init/do_mounts_initrd.c
84879+++ b/init/do_mounts_initrd.c
84880@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
84881 {
84882 sys_unshare(CLONE_FS | CLONE_FILES);
84883 /* stdin/stdout/stderr for /linuxrc */
84884- sys_open("/dev/console", O_RDWR, 0);
84885+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
84886 sys_dup(0);
84887 sys_dup(0);
84888 /* move initrd over / and chdir/chroot in initrd root */
84889- sys_chdir("/root");
84890- sys_mount(".", "/", NULL, MS_MOVE, NULL);
84891- sys_chroot(".");
84892+ sys_chdir((const char __force_user *)"/root");
84893+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
84894+ sys_chroot((const char __force_user *)".");
84895 sys_setsid();
84896 return 0;
84897 }
84898@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
84899 create_dev("/dev/root.old", Root_RAM0);
84900 /* mount initrd on rootfs' /root */
84901 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
84902- sys_mkdir("/old", 0700);
84903- sys_chdir("/old");
84904+ sys_mkdir((const char __force_user *)"/old", 0700);
84905+ sys_chdir((const char __force_user *)"/old");
84906
84907 /* try loading default modules from initrd */
84908 load_default_modules();
84909@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
84910 current->flags &= ~PF_FREEZER_SKIP;
84911
84912 /* move initrd to rootfs' /old */
84913- sys_mount("..", ".", NULL, MS_MOVE, NULL);
84914+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
84915 /* switch root and cwd back to / of rootfs */
84916- sys_chroot("..");
84917+ sys_chroot((const char __force_user *)"..");
84918
84919 if (new_decode_dev(real_root_dev) == Root_RAM0) {
84920- sys_chdir("/old");
84921+ sys_chdir((const char __force_user *)"/old");
84922 return;
84923 }
84924
84925- sys_chdir("/");
84926+ sys_chdir((const char __force_user *)"/");
84927 ROOT_DEV = new_decode_dev(real_root_dev);
84928 mount_root();
84929
84930 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
84931- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
84932+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
84933 if (!error)
84934 printk("okay\n");
84935 else {
84936- int fd = sys_open("/dev/root.old", O_RDWR, 0);
84937+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
84938 if (error == -ENOENT)
84939 printk("/initrd does not exist. Ignored.\n");
84940 else
84941 printk("failed\n");
84942 printk(KERN_NOTICE "Unmounting old root\n");
84943- sys_umount("/old", MNT_DETACH);
84944+ sys_umount((char __force_user *)"/old", MNT_DETACH);
84945 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
84946 if (fd < 0) {
84947 error = fd;
84948@@ -127,11 +127,11 @@ int __init initrd_load(void)
84949 * mounted in the normal path.
84950 */
84951 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
84952- sys_unlink("/initrd.image");
84953+ sys_unlink((const char __force_user *)"/initrd.image");
84954 handle_initrd();
84955 return 1;
84956 }
84957 }
84958- sys_unlink("/initrd.image");
84959+ sys_unlink((const char __force_user *)"/initrd.image");
84960 return 0;
84961 }
84962diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
84963index 8cb6db5..d729f50 100644
84964--- a/init/do_mounts_md.c
84965+++ b/init/do_mounts_md.c
84966@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
84967 partitioned ? "_d" : "", minor,
84968 md_setup_args[ent].device_names);
84969
84970- fd = sys_open(name, 0, 0);
84971+ fd = sys_open((char __force_user *)name, 0, 0);
84972 if (fd < 0) {
84973 printk(KERN_ERR "md: open failed - cannot start "
84974 "array %s\n", name);
84975@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
84976 * array without it
84977 */
84978 sys_close(fd);
84979- fd = sys_open(name, 0, 0);
84980+ fd = sys_open((char __force_user *)name, 0, 0);
84981 sys_ioctl(fd, BLKRRPART, 0);
84982 }
84983 sys_close(fd);
84984@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
84985
84986 wait_for_device_probe();
84987
84988- fd = sys_open("/dev/md0", 0, 0);
84989+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
84990 if (fd >= 0) {
84991 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
84992 sys_close(fd);
84993diff --git a/init/init_task.c b/init/init_task.c
84994index ba0a7f36..2bcf1d5 100644
84995--- a/init/init_task.c
84996+++ b/init/init_task.c
84997@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
84998 * Initial thread structure. Alignment of this is handled by a special
84999 * linker map entry.
85000 */
85001+#ifdef CONFIG_X86
85002+union thread_union init_thread_union __init_task_data;
85003+#else
85004 union thread_union init_thread_union __init_task_data =
85005 { INIT_THREAD_INFO(init_task) };
85006+#endif
85007diff --git a/init/initramfs.c b/init/initramfs.c
85008index 93b6139..8d628b7 100644
85009--- a/init/initramfs.c
85010+++ b/init/initramfs.c
85011@@ -84,7 +84,7 @@ static void __init free_hash(void)
85012 }
85013 }
85014
85015-static long __init do_utime(char *filename, time_t mtime)
85016+static long __init do_utime(char __force_user *filename, time_t mtime)
85017 {
85018 struct timespec t[2];
85019
85020@@ -119,7 +119,7 @@ static void __init dir_utime(void)
85021 struct dir_entry *de, *tmp;
85022 list_for_each_entry_safe(de, tmp, &dir_list, list) {
85023 list_del(&de->list);
85024- do_utime(de->name, de->mtime);
85025+ do_utime((char __force_user *)de->name, de->mtime);
85026 kfree(de->name);
85027 kfree(de);
85028 }
85029@@ -281,7 +281,7 @@ static int __init maybe_link(void)
85030 if (nlink >= 2) {
85031 char *old = find_link(major, minor, ino, mode, collected);
85032 if (old)
85033- return (sys_link(old, collected) < 0) ? -1 : 1;
85034+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
85035 }
85036 return 0;
85037 }
85038@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
85039 {
85040 struct stat st;
85041
85042- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
85043+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
85044 if (S_ISDIR(st.st_mode))
85045- sys_rmdir(path);
85046+ sys_rmdir((char __force_user *)path);
85047 else
85048- sys_unlink(path);
85049+ sys_unlink((char __force_user *)path);
85050 }
85051 }
85052
85053@@ -315,7 +315,7 @@ static int __init do_name(void)
85054 int openflags = O_WRONLY|O_CREAT;
85055 if (ml != 1)
85056 openflags |= O_TRUNC;
85057- wfd = sys_open(collected, openflags, mode);
85058+ wfd = sys_open((char __force_user *)collected, openflags, mode);
85059
85060 if (wfd >= 0) {
85061 sys_fchown(wfd, uid, gid);
85062@@ -327,17 +327,17 @@ static int __init do_name(void)
85063 }
85064 }
85065 } else if (S_ISDIR(mode)) {
85066- sys_mkdir(collected, mode);
85067- sys_chown(collected, uid, gid);
85068- sys_chmod(collected, mode);
85069+ sys_mkdir((char __force_user *)collected, mode);
85070+ sys_chown((char __force_user *)collected, uid, gid);
85071+ sys_chmod((char __force_user *)collected, mode);
85072 dir_add(collected, mtime);
85073 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
85074 S_ISFIFO(mode) || S_ISSOCK(mode)) {
85075 if (maybe_link() == 0) {
85076- sys_mknod(collected, mode, rdev);
85077- sys_chown(collected, uid, gid);
85078- sys_chmod(collected, mode);
85079- do_utime(collected, mtime);
85080+ sys_mknod((char __force_user *)collected, mode, rdev);
85081+ sys_chown((char __force_user *)collected, uid, gid);
85082+ sys_chmod((char __force_user *)collected, mode);
85083+ do_utime((char __force_user *)collected, mtime);
85084 }
85085 }
85086 return 0;
85087@@ -346,15 +346,15 @@ static int __init do_name(void)
85088 static int __init do_copy(void)
85089 {
85090 if (count >= body_len) {
85091- sys_write(wfd, victim, body_len);
85092+ sys_write(wfd, (char __force_user *)victim, body_len);
85093 sys_close(wfd);
85094- do_utime(vcollected, mtime);
85095+ do_utime((char __force_user *)vcollected, mtime);
85096 kfree(vcollected);
85097 eat(body_len);
85098 state = SkipIt;
85099 return 0;
85100 } else {
85101- sys_write(wfd, victim, count);
85102+ sys_write(wfd, (char __force_user *)victim, count);
85103 body_len -= count;
85104 eat(count);
85105 return 1;
85106@@ -365,9 +365,9 @@ static int __init do_symlink(void)
85107 {
85108 collected[N_ALIGN(name_len) + body_len] = '\0';
85109 clean_path(collected, 0);
85110- sys_symlink(collected + N_ALIGN(name_len), collected);
85111- sys_lchown(collected, uid, gid);
85112- do_utime(collected, mtime);
85113+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
85114+ sys_lchown((char __force_user *)collected, uid, gid);
85115+ do_utime((char __force_user *)collected, mtime);
85116 state = SkipIt;
85117 next_state = Reset;
85118 return 0;
85119diff --git a/init/main.c b/init/main.c
85120index 9c7fd4c..650b4f1 100644
85121--- a/init/main.c
85122+++ b/init/main.c
85123@@ -97,6 +97,8 @@ extern void radix_tree_init(void);
85124 static inline void mark_rodata_ro(void) { }
85125 #endif
85126
85127+extern void grsecurity_init(void);
85128+
85129 /*
85130 * Debug helper: via this flag we know that we are in 'early bootup code'
85131 * where only the boot processor is running with IRQ disabled. This means
85132@@ -158,6 +160,75 @@ static int __init set_reset_devices(char *str)
85133
85134 __setup("reset_devices", set_reset_devices);
85135
85136+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
85137+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
85138+static int __init setup_grsec_proc_gid(char *str)
85139+{
85140+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
85141+ return 1;
85142+}
85143+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
85144+#endif
85145+
85146+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
85147+unsigned long pax_user_shadow_base __read_only;
85148+EXPORT_SYMBOL(pax_user_shadow_base);
85149+extern char pax_enter_kernel_user[];
85150+extern char pax_exit_kernel_user[];
85151+#endif
85152+
85153+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
85154+static int __init setup_pax_nouderef(char *str)
85155+{
85156+#ifdef CONFIG_X86_32
85157+ unsigned int cpu;
85158+ struct desc_struct *gdt;
85159+
85160+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
85161+ gdt = get_cpu_gdt_table(cpu);
85162+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
85163+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
85164+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
85165+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
85166+ }
85167+ loadsegment(ds, __KERNEL_DS);
85168+ loadsegment(es, __KERNEL_DS);
85169+ loadsegment(ss, __KERNEL_DS);
85170+#else
85171+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
85172+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
85173+ clone_pgd_mask = ~(pgdval_t)0UL;
85174+ pax_user_shadow_base = 0UL;
85175+ setup_clear_cpu_cap(X86_FEATURE_PCID);
85176+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
85177+#endif
85178+
85179+ return 0;
85180+}
85181+early_param("pax_nouderef", setup_pax_nouderef);
85182+
85183+#ifdef CONFIG_X86_64
85184+static int __init setup_pax_weakuderef(char *str)
85185+{
85186+ if (clone_pgd_mask != ~(pgdval_t)0UL)
85187+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
85188+ return 1;
85189+}
85190+__setup("pax_weakuderef", setup_pax_weakuderef);
85191+#endif
85192+#endif
85193+
85194+#ifdef CONFIG_PAX_SOFTMODE
85195+int pax_softmode;
85196+
85197+static int __init setup_pax_softmode(char *str)
85198+{
85199+ get_option(&str, &pax_softmode);
85200+ return 1;
85201+}
85202+__setup("pax_softmode=", setup_pax_softmode);
85203+#endif
85204+
85205 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
85206 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
85207 static const char *panic_later, *panic_param;
85208@@ -688,25 +759,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
85209 {
85210 int count = preempt_count();
85211 int ret;
85212- char msgbuf[64];
85213+ const char *msg1 = "", *msg2 = "";
85214
85215 if (initcall_debug)
85216 ret = do_one_initcall_debug(fn);
85217 else
85218 ret = fn();
85219
85220- msgbuf[0] = 0;
85221-
85222 if (preempt_count() != count) {
85223- sprintf(msgbuf, "preemption imbalance ");
85224+ msg1 = " preemption imbalance";
85225 preempt_count_set(count);
85226 }
85227 if (irqs_disabled()) {
85228- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
85229+ msg2 = " disabled interrupts";
85230 local_irq_enable();
85231 }
85232- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
85233+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
85234
85235+ add_latent_entropy();
85236 return ret;
85237 }
85238
85239@@ -813,8 +883,8 @@ static int run_init_process(const char *init_filename)
85240 {
85241 argv_init[0] = init_filename;
85242 return do_execve(getname_kernel(init_filename),
85243- (const char __user *const __user *)argv_init,
85244- (const char __user *const __user *)envp_init);
85245+ (const char __user *const __force_user *)argv_init,
85246+ (const char __user *const __force_user *)envp_init);
85247 }
85248
85249 static int try_to_run_init_process(const char *init_filename)
85250@@ -831,6 +901,10 @@ static int try_to_run_init_process(const char *init_filename)
85251 return ret;
85252 }
85253
85254+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
85255+extern int gr_init_ran;
85256+#endif
85257+
85258 static noinline void __init kernel_init_freeable(void);
85259
85260 static int __ref kernel_init(void *unused)
85261@@ -855,6 +929,11 @@ static int __ref kernel_init(void *unused)
85262 ramdisk_execute_command, ret);
85263 }
85264
85265+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
85266+ /* if no initrd was used, be extra sure we enforce chroot restrictions */
85267+ gr_init_ran = 1;
85268+#endif
85269+
85270 /*
85271 * We try each of these until one succeeds.
85272 *
85273@@ -910,7 +989,7 @@ static noinline void __init kernel_init_freeable(void)
85274 do_basic_setup();
85275
85276 /* Open the /dev/console on the rootfs, this should never fail */
85277- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
85278+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
85279 pr_err("Warning: unable to open an initial console.\n");
85280
85281 (void) sys_dup(0);
85282@@ -923,11 +1002,13 @@ static noinline void __init kernel_init_freeable(void)
85283 if (!ramdisk_execute_command)
85284 ramdisk_execute_command = "/init";
85285
85286- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
85287+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
85288 ramdisk_execute_command = NULL;
85289 prepare_namespace();
85290 }
85291
85292+ grsecurity_init();
85293+
85294 /*
85295 * Ok, we have completed the initial bootup, and
85296 * we're essentially up and running. Get rid of the
85297diff --git a/ipc/compat.c b/ipc/compat.c
85298index f486b00..442867f 100644
85299--- a/ipc/compat.c
85300+++ b/ipc/compat.c
85301@@ -399,7 +399,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
85302 COMPAT_SHMLBA);
85303 if (err < 0)
85304 return err;
85305- return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
85306+ return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
85307 }
85308 case SHMDT:
85309 return sys_shmdt(compat_ptr(ptr));
85310diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
85311index 1702864..797fa84 100644
85312--- a/ipc/ipc_sysctl.c
85313+++ b/ipc/ipc_sysctl.c
85314@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
85315 static int proc_ipc_dointvec(ctl_table *table, int write,
85316 void __user *buffer, size_t *lenp, loff_t *ppos)
85317 {
85318- struct ctl_table ipc_table;
85319+ ctl_table_no_const ipc_table;
85320
85321 memcpy(&ipc_table, table, sizeof(ipc_table));
85322 ipc_table.data = get_ipc(table);
85323@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
85324 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
85325 void __user *buffer, size_t *lenp, loff_t *ppos)
85326 {
85327- struct ctl_table ipc_table;
85328+ ctl_table_no_const ipc_table;
85329
85330 memcpy(&ipc_table, table, sizeof(ipc_table));
85331 ipc_table.data = get_ipc(table);
85332@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
85333 static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
85334 void __user *buffer, size_t *lenp, loff_t *ppos)
85335 {
85336- struct ctl_table ipc_table;
85337+ ctl_table_no_const ipc_table;
85338 size_t lenp_bef = *lenp;
85339 int rc;
85340
85341@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
85342 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
85343 void __user *buffer, size_t *lenp, loff_t *ppos)
85344 {
85345- struct ctl_table ipc_table;
85346+ ctl_table_no_const ipc_table;
85347 memcpy(&ipc_table, table, sizeof(ipc_table));
85348 ipc_table.data = get_ipc(table);
85349
85350@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
85351 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
85352 void __user *buffer, size_t *lenp, loff_t *ppos)
85353 {
85354- struct ctl_table ipc_table;
85355+ ctl_table_no_const ipc_table;
85356 size_t lenp_bef = *lenp;
85357 int oldval;
85358 int rc;
85359diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
85360index 5bb8bfe..a38ec05 100644
85361--- a/ipc/mq_sysctl.c
85362+++ b/ipc/mq_sysctl.c
85363@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
85364 static int proc_mq_dointvec(ctl_table *table, int write,
85365 void __user *buffer, size_t *lenp, loff_t *ppos)
85366 {
85367- struct ctl_table mq_table;
85368+ ctl_table_no_const mq_table;
85369 memcpy(&mq_table, table, sizeof(mq_table));
85370 mq_table.data = get_mq(table);
85371
85372@@ -35,7 +35,7 @@ static int proc_mq_dointvec(ctl_table *table, int write,
85373 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
85374 void __user *buffer, size_t *lenp, loff_t *ppos)
85375 {
85376- struct ctl_table mq_table;
85377+ ctl_table_no_const mq_table;
85378 memcpy(&mq_table, table, sizeof(mq_table));
85379 mq_table.data = get_mq(table);
85380
85381diff --git a/ipc/mqueue.c b/ipc/mqueue.c
85382index c3b3117..1efa933 100644
85383--- a/ipc/mqueue.c
85384+++ b/ipc/mqueue.c
85385@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
85386 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
85387 info->attr.mq_msgsize);
85388
85389+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
85390 spin_lock(&mq_lock);
85391 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
85392 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
85393diff --git a/ipc/msg.c b/ipc/msg.c
85394index 6498531..b0ff3c8 100644
85395--- a/ipc/msg.c
85396+++ b/ipc/msg.c
85397@@ -303,18 +303,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
85398 return security_msg_queue_associate(msq, msgflg);
85399 }
85400
85401+static struct ipc_ops msg_ops = {
85402+ .getnew = newque,
85403+ .associate = msg_security,
85404+ .more_checks = NULL
85405+};
85406+
85407 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
85408 {
85409 struct ipc_namespace *ns;
85410- struct ipc_ops msg_ops;
85411 struct ipc_params msg_params;
85412
85413 ns = current->nsproxy->ipc_ns;
85414
85415- msg_ops.getnew = newque;
85416- msg_ops.associate = msg_security;
85417- msg_ops.more_checks = NULL;
85418-
85419 msg_params.key = key;
85420 msg_params.flg = msgflg;
85421
85422diff --git a/ipc/sem.c b/ipc/sem.c
85423index bee5554..e9af81dd 100644
85424--- a/ipc/sem.c
85425+++ b/ipc/sem.c
85426@@ -561,10 +561,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
85427 return 0;
85428 }
85429
85430+static struct ipc_ops sem_ops = {
85431+ .getnew = newary,
85432+ .associate = sem_security,
85433+ .more_checks = sem_more_checks
85434+};
85435+
85436 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
85437 {
85438 struct ipc_namespace *ns;
85439- struct ipc_ops sem_ops;
85440 struct ipc_params sem_params;
85441
85442 ns = current->nsproxy->ipc_ns;
85443@@ -572,10 +577,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
85444 if (nsems < 0 || nsems > ns->sc_semmsl)
85445 return -EINVAL;
85446
85447- sem_ops.getnew = newary;
85448- sem_ops.associate = sem_security;
85449- sem_ops.more_checks = sem_more_checks;
85450-
85451 sem_params.key = key;
85452 sem_params.flg = semflg;
85453 sem_params.u.nsems = nsems;
85454diff --git a/ipc/shm.c b/ipc/shm.c
85455index 7645961..afc7f02 100644
85456--- a/ipc/shm.c
85457+++ b/ipc/shm.c
85458@@ -72,6 +72,14 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
85459 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
85460 #endif
85461
85462+#ifdef CONFIG_GRKERNSEC
85463+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
85464+ const time_t shm_createtime, const kuid_t cuid,
85465+ const int shmid);
85466+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
85467+ const time_t shm_createtime);
85468+#endif
85469+
85470 void shm_init_ns(struct ipc_namespace *ns)
85471 {
85472 ns->shm_ctlmax = SHMMAX;
85473@@ -553,6 +561,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
85474 shp->shm_lprid = 0;
85475 shp->shm_atim = shp->shm_dtim = 0;
85476 shp->shm_ctim = get_seconds();
85477+#ifdef CONFIG_GRKERNSEC
85478+ {
85479+ struct timespec timeval;
85480+ do_posix_clock_monotonic_gettime(&timeval);
85481+
85482+ shp->shm_createtime = timeval.tv_sec;
85483+ }
85484+#endif
85485 shp->shm_segsz = size;
85486 shp->shm_nattch = 0;
85487 shp->shm_file = file;
85488@@ -606,18 +622,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
85489 return 0;
85490 }
85491
85492+static struct ipc_ops shm_ops = {
85493+ .getnew = newseg,
85494+ .associate = shm_security,
85495+ .more_checks = shm_more_checks
85496+};
85497+
85498 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
85499 {
85500 struct ipc_namespace *ns;
85501- struct ipc_ops shm_ops;
85502 struct ipc_params shm_params;
85503
85504 ns = current->nsproxy->ipc_ns;
85505
85506- shm_ops.getnew = newseg;
85507- shm_ops.associate = shm_security;
85508- shm_ops.more_checks = shm_more_checks;
85509-
85510 shm_params.key = key;
85511 shm_params.flg = shmflg;
85512 shm_params.u.size = size;
85513@@ -1088,6 +1105,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85514 f_mode = FMODE_READ | FMODE_WRITE;
85515 }
85516 if (shmflg & SHM_EXEC) {
85517+
85518+#ifdef CONFIG_PAX_MPROTECT
85519+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
85520+ goto out;
85521+#endif
85522+
85523 prot |= PROT_EXEC;
85524 acc_mode |= S_IXUGO;
85525 }
85526@@ -1112,6 +1135,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85527 if (err)
85528 goto out_unlock;
85529
85530+#ifdef CONFIG_GRKERNSEC
85531+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
85532+ shp->shm_perm.cuid, shmid) ||
85533+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
85534+ err = -EACCES;
85535+ goto out_unlock;
85536+ }
85537+#endif
85538+
85539 ipc_lock_object(&shp->shm_perm);
85540
85541 /* check if shm_destroy() is tearing down shp */
85542@@ -1124,6 +1156,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85543 path = shp->shm_file->f_path;
85544 path_get(&path);
85545 shp->shm_nattch++;
85546+#ifdef CONFIG_GRKERNSEC
85547+ shp->shm_lapid = current->pid;
85548+#endif
85549 size = i_size_read(path.dentry->d_inode);
85550 ipc_unlock_object(&shp->shm_perm);
85551 rcu_read_unlock();
85552diff --git a/ipc/util.c b/ipc/util.c
85553index e1b4c6d..8174204 100644
85554--- a/ipc/util.c
85555+++ b/ipc/util.c
85556@@ -71,6 +71,8 @@ struct ipc_proc_iface {
85557 int (*show)(struct seq_file *, void *);
85558 };
85559
85560+extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
85561+
85562 static void ipc_memory_notifier(struct work_struct *work)
85563 {
85564 ipcns_notify(IPCNS_MEMCHANGED);
85565@@ -537,6 +539,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
85566 granted_mode >>= 6;
85567 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
85568 granted_mode >>= 3;
85569+
85570+ if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
85571+ return -1;
85572+
85573 /* is there some bit set in requested_mode but not in granted_mode? */
85574 if ((requested_mode & ~granted_mode & 0007) &&
85575 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
85576diff --git a/kernel/acct.c b/kernel/acct.c
85577index 8d6e145..33e0b1e 100644
85578--- a/kernel/acct.c
85579+++ b/kernel/acct.c
85580@@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
85581 */
85582 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
85583 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
85584- file->f_op->write(file, (char *)&ac,
85585+ file->f_op->write(file, (char __force_user *)&ac,
85586 sizeof(acct_t), &file->f_pos);
85587 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
85588 set_fs(fs);
85589diff --git a/kernel/audit.c b/kernel/audit.c
85590index 95a20f3..e1cb300 100644
85591--- a/kernel/audit.c
85592+++ b/kernel/audit.c
85593@@ -122,7 +122,7 @@ u32 audit_sig_sid = 0;
85594 3) suppressed due to audit_rate_limit
85595 4) suppressed due to audit_backlog_limit
85596 */
85597-static atomic_t audit_lost = ATOMIC_INIT(0);
85598+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
85599
85600 /* The netlink socket. */
85601 static struct sock *audit_sock;
85602@@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
85603 unsigned long now;
85604 int print;
85605
85606- atomic_inc(&audit_lost);
85607+ atomic_inc_unchecked(&audit_lost);
85608
85609 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
85610
85611@@ -273,7 +273,7 @@ void audit_log_lost(const char *message)
85612 if (print) {
85613 if (printk_ratelimit())
85614 pr_warn("audit_lost=%u audit_rate_limit=%u audit_backlog_limit=%u\n",
85615- atomic_read(&audit_lost),
85616+ atomic_read_unchecked(&audit_lost),
85617 audit_rate_limit,
85618 audit_backlog_limit);
85619 audit_panic(message);
85620@@ -803,7 +803,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
85621 s.pid = audit_pid;
85622 s.rate_limit = audit_rate_limit;
85623 s.backlog_limit = audit_backlog_limit;
85624- s.lost = atomic_read(&audit_lost);
85625+ s.lost = atomic_read_unchecked(&audit_lost);
85626 s.backlog = skb_queue_len(&audit_skb_queue);
85627 s.version = AUDIT_VERSION_LATEST;
85628 s.backlog_wait_time = audit_backlog_wait_time;
85629diff --git a/kernel/auditsc.c b/kernel/auditsc.c
85630index 7aef2f4..db6ced2 100644
85631--- a/kernel/auditsc.c
85632+++ b/kernel/auditsc.c
85633@@ -1945,7 +1945,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
85634 }
85635
85636 /* global counter which is incremented every time something logs in */
85637-static atomic_t session_id = ATOMIC_INIT(0);
85638+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
85639
85640 static int audit_set_loginuid_perm(kuid_t loginuid)
85641 {
85642@@ -2014,7 +2014,7 @@ int audit_set_loginuid(kuid_t loginuid)
85643
85644 /* are we setting or clearing? */
85645 if (uid_valid(loginuid))
85646- sessionid = (unsigned int)atomic_inc_return(&session_id);
85647+ sessionid = (unsigned int)atomic_inc_return_unchecked(&session_id);
85648
85649 task->sessionid = sessionid;
85650 task->loginuid = loginuid;
85651diff --git a/kernel/capability.c b/kernel/capability.c
85652index 34019c5..363f279 100644
85653--- a/kernel/capability.c
85654+++ b/kernel/capability.c
85655@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
85656 * before modification is attempted and the application
85657 * fails.
85658 */
85659+ if (tocopy > ARRAY_SIZE(kdata))
85660+ return -EFAULT;
85661+
85662 if (copy_to_user(dataptr, kdata, tocopy
85663 * sizeof(struct __user_cap_data_struct))) {
85664 return -EFAULT;
85665@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
85666 int ret;
85667
85668 rcu_read_lock();
85669- ret = security_capable(__task_cred(t), ns, cap);
85670+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
85671+ gr_task_is_capable(t, __task_cred(t), cap);
85672 rcu_read_unlock();
85673
85674- return (ret == 0);
85675+ return ret;
85676 }
85677
85678 /**
85679@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
85680 int ret;
85681
85682 rcu_read_lock();
85683- ret = security_capable_noaudit(__task_cred(t), ns, cap);
85684+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
85685 rcu_read_unlock();
85686
85687- return (ret == 0);
85688+ return ret;
85689 }
85690
85691 /**
85692@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
85693 BUG();
85694 }
85695
85696- if (security_capable(current_cred(), ns, cap) == 0) {
85697+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
85698 current->flags |= PF_SUPERPRIV;
85699 return true;
85700 }
85701@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
85702 }
85703 EXPORT_SYMBOL(ns_capable);
85704
85705+bool ns_capable_nolog(struct user_namespace *ns, int cap)
85706+{
85707+ if (unlikely(!cap_valid(cap))) {
85708+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
85709+ BUG();
85710+ }
85711+
85712+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
85713+ current->flags |= PF_SUPERPRIV;
85714+ return true;
85715+ }
85716+ return false;
85717+}
85718+EXPORT_SYMBOL(ns_capable_nolog);
85719+
85720 /**
85721 * file_ns_capable - Determine if the file's opener had a capability in effect
85722 * @file: The file we want to check
85723@@ -432,6 +451,12 @@ bool capable(int cap)
85724 }
85725 EXPORT_SYMBOL(capable);
85726
85727+bool capable_nolog(int cap)
85728+{
85729+ return ns_capable_nolog(&init_user_ns, cap);
85730+}
85731+EXPORT_SYMBOL(capable_nolog);
85732+
85733 /**
85734 * inode_capable - Check superior capability over inode
85735 * @inode: The inode in question
85736@@ -453,3 +478,11 @@ bool inode_capable(const struct inode *inode, int cap)
85737 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
85738 }
85739 EXPORT_SYMBOL(inode_capable);
85740+
85741+bool inode_capable_nolog(const struct inode *inode, int cap)
85742+{
85743+ struct user_namespace *ns = current_user_ns();
85744+
85745+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
85746+}
85747+EXPORT_SYMBOL(inode_capable_nolog);
85748diff --git a/kernel/cgroup.c b/kernel/cgroup.c
85749index 0c753dd..dd7d3d6 100644
85750--- a/kernel/cgroup.c
85751+++ b/kernel/cgroup.c
85752@@ -5372,7 +5372,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)
85753 struct css_set *cset = link->cset;
85754 struct task_struct *task;
85755 int count = 0;
85756- seq_printf(seq, "css_set %p\n", cset);
85757+ seq_printf(seq, "css_set %pK\n", cset);
85758 list_for_each_entry(task, &cset->tasks, cg_list) {
85759 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
85760 seq_puts(seq, " ...\n");
85761diff --git a/kernel/compat.c b/kernel/compat.c
85762index 0a09e48..b46b3d78 100644
85763--- a/kernel/compat.c
85764+++ b/kernel/compat.c
85765@@ -13,6 +13,7 @@
85766
85767 #include <linux/linkage.h>
85768 #include <linux/compat.h>
85769+#include <linux/module.h>
85770 #include <linux/errno.h>
85771 #include <linux/time.h>
85772 #include <linux/signal.h>
85773@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
85774 mm_segment_t oldfs;
85775 long ret;
85776
85777- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
85778+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
85779 oldfs = get_fs();
85780 set_fs(KERNEL_DS);
85781 ret = hrtimer_nanosleep_restart(restart);
85782@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
85783 oldfs = get_fs();
85784 set_fs(KERNEL_DS);
85785 ret = hrtimer_nanosleep(&tu,
85786- rmtp ? (struct timespec __user *)&rmt : NULL,
85787+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
85788 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
85789 set_fs(oldfs);
85790
85791@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
85792 mm_segment_t old_fs = get_fs();
85793
85794 set_fs(KERNEL_DS);
85795- ret = sys_sigpending((old_sigset_t __user *) &s);
85796+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
85797 set_fs(old_fs);
85798 if (ret == 0)
85799 ret = put_user(s, set);
85800@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
85801 mm_segment_t old_fs = get_fs();
85802
85803 set_fs(KERNEL_DS);
85804- ret = sys_old_getrlimit(resource, &r);
85805+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
85806 set_fs(old_fs);
85807
85808 if (!ret) {
85809@@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
85810 set_fs (KERNEL_DS);
85811 ret = sys_wait4(pid,
85812 (stat_addr ?
85813- (unsigned int __user *) &status : NULL),
85814- options, (struct rusage __user *) &r);
85815+ (unsigned int __force_user *) &status : NULL),
85816+ options, (struct rusage __force_user *) &r);
85817 set_fs (old_fs);
85818
85819 if (ret > 0) {
85820@@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
85821 memset(&info, 0, sizeof(info));
85822
85823 set_fs(KERNEL_DS);
85824- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
85825- uru ? (struct rusage __user *)&ru : NULL);
85826+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
85827+ uru ? (struct rusage __force_user *)&ru : NULL);
85828 set_fs(old_fs);
85829
85830 if ((ret < 0) || (info.si_signo == 0))
85831@@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
85832 oldfs = get_fs();
85833 set_fs(KERNEL_DS);
85834 err = sys_timer_settime(timer_id, flags,
85835- (struct itimerspec __user *) &newts,
85836- (struct itimerspec __user *) &oldts);
85837+ (struct itimerspec __force_user *) &newts,
85838+ (struct itimerspec __force_user *) &oldts);
85839 set_fs(oldfs);
85840 if (!err && old && put_compat_itimerspec(old, &oldts))
85841 return -EFAULT;
85842@@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
85843 oldfs = get_fs();
85844 set_fs(KERNEL_DS);
85845 err = sys_timer_gettime(timer_id,
85846- (struct itimerspec __user *) &ts);
85847+ (struct itimerspec __force_user *) &ts);
85848 set_fs(oldfs);
85849 if (!err && put_compat_itimerspec(setting, &ts))
85850 return -EFAULT;
85851@@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
85852 oldfs = get_fs();
85853 set_fs(KERNEL_DS);
85854 err = sys_clock_settime(which_clock,
85855- (struct timespec __user *) &ts);
85856+ (struct timespec __force_user *) &ts);
85857 set_fs(oldfs);
85858 return err;
85859 }
85860@@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
85861 oldfs = get_fs();
85862 set_fs(KERNEL_DS);
85863 err = sys_clock_gettime(which_clock,
85864- (struct timespec __user *) &ts);
85865+ (struct timespec __force_user *) &ts);
85866 set_fs(oldfs);
85867 if (!err && put_compat_timespec(&ts, tp))
85868 return -EFAULT;
85869@@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
85870
85871 oldfs = get_fs();
85872 set_fs(KERNEL_DS);
85873- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
85874+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
85875 set_fs(oldfs);
85876
85877 err = compat_put_timex(utp, &txc);
85878@@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
85879 oldfs = get_fs();
85880 set_fs(KERNEL_DS);
85881 err = sys_clock_getres(which_clock,
85882- (struct timespec __user *) &ts);
85883+ (struct timespec __force_user *) &ts);
85884 set_fs(oldfs);
85885 if (!err && tp && put_compat_timespec(&ts, tp))
85886 return -EFAULT;
85887@@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
85888 long err;
85889 mm_segment_t oldfs;
85890 struct timespec tu;
85891- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
85892+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
85893
85894- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
85895+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
85896 oldfs = get_fs();
85897 set_fs(KERNEL_DS);
85898 err = clock_nanosleep_restart(restart);
85899@@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
85900 oldfs = get_fs();
85901 set_fs(KERNEL_DS);
85902 err = sys_clock_nanosleep(which_clock, flags,
85903- (struct timespec __user *) &in,
85904- (struct timespec __user *) &out);
85905+ (struct timespec __force_user *) &in,
85906+ (struct timespec __force_user *) &out);
85907 set_fs(oldfs);
85908
85909 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
85910@@ -1128,7 +1129,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
85911 mm_segment_t old_fs = get_fs();
85912
85913 set_fs(KERNEL_DS);
85914- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
85915+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
85916 set_fs(old_fs);
85917 if (put_compat_timespec(&t, interval))
85918 return -EFAULT;
85919diff --git a/kernel/configs.c b/kernel/configs.c
85920index c18b1f1..b9a0132 100644
85921--- a/kernel/configs.c
85922+++ b/kernel/configs.c
85923@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
85924 struct proc_dir_entry *entry;
85925
85926 /* create the current config file */
85927+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
85928+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
85929+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
85930+ &ikconfig_file_ops);
85931+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
85932+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
85933+ &ikconfig_file_ops);
85934+#endif
85935+#else
85936 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
85937 &ikconfig_file_ops);
85938+#endif
85939+
85940 if (!entry)
85941 return -ENOMEM;
85942
85943diff --git a/kernel/cred.c b/kernel/cred.c
85944index e0573a4..3874e41 100644
85945--- a/kernel/cred.c
85946+++ b/kernel/cred.c
85947@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
85948 validate_creds(cred);
85949 alter_cred_subscribers(cred, -1);
85950 put_cred(cred);
85951+
85952+#ifdef CONFIG_GRKERNSEC_SETXID
85953+ cred = (struct cred *) tsk->delayed_cred;
85954+ if (cred != NULL) {
85955+ tsk->delayed_cred = NULL;
85956+ validate_creds(cred);
85957+ alter_cred_subscribers(cred, -1);
85958+ put_cred(cred);
85959+ }
85960+#endif
85961 }
85962
85963 /**
85964@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
85965 * Always returns 0 thus allowing this function to be tail-called at the end
85966 * of, say, sys_setgid().
85967 */
85968-int commit_creds(struct cred *new)
85969+static int __commit_creds(struct cred *new)
85970 {
85971 struct task_struct *task = current;
85972 const struct cred *old = task->real_cred;
85973@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
85974
85975 get_cred(new); /* we will require a ref for the subj creds too */
85976
85977+ gr_set_role_label(task, new->uid, new->gid);
85978+
85979 /* dumpability changes */
85980 if (!uid_eq(old->euid, new->euid) ||
85981 !gid_eq(old->egid, new->egid) ||
85982@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
85983 put_cred(old);
85984 return 0;
85985 }
85986+#ifdef CONFIG_GRKERNSEC_SETXID
85987+extern int set_user(struct cred *new);
85988+
85989+void gr_delayed_cred_worker(void)
85990+{
85991+ const struct cred *new = current->delayed_cred;
85992+ struct cred *ncred;
85993+
85994+ current->delayed_cred = NULL;
85995+
85996+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
85997+ // from doing get_cred on it when queueing this
85998+ put_cred(new);
85999+ return;
86000+ } else if (new == NULL)
86001+ return;
86002+
86003+ ncred = prepare_creds();
86004+ if (!ncred)
86005+ goto die;
86006+ // uids
86007+ ncred->uid = new->uid;
86008+ ncred->euid = new->euid;
86009+ ncred->suid = new->suid;
86010+ ncred->fsuid = new->fsuid;
86011+ // gids
86012+ ncred->gid = new->gid;
86013+ ncred->egid = new->egid;
86014+ ncred->sgid = new->sgid;
86015+ ncred->fsgid = new->fsgid;
86016+ // groups
86017+ if (set_groups(ncred, new->group_info) < 0) {
86018+ abort_creds(ncred);
86019+ goto die;
86020+ }
86021+ // caps
86022+ ncred->securebits = new->securebits;
86023+ ncred->cap_inheritable = new->cap_inheritable;
86024+ ncred->cap_permitted = new->cap_permitted;
86025+ ncred->cap_effective = new->cap_effective;
86026+ ncred->cap_bset = new->cap_bset;
86027+
86028+ if (set_user(ncred)) {
86029+ abort_creds(ncred);
86030+ goto die;
86031+ }
86032+
86033+ // from doing get_cred on it when queueing this
86034+ put_cred(new);
86035+
86036+ __commit_creds(ncred);
86037+ return;
86038+die:
86039+ // from doing get_cred on it when queueing this
86040+ put_cred(new);
86041+ do_group_exit(SIGKILL);
86042+}
86043+#endif
86044+
86045+int commit_creds(struct cred *new)
86046+{
86047+#ifdef CONFIG_GRKERNSEC_SETXID
86048+ int ret;
86049+ int schedule_it = 0;
86050+ struct task_struct *t;
86051+
86052+ /* we won't get called with tasklist_lock held for writing
86053+ and interrupts disabled as the cred struct in that case is
86054+ init_cred
86055+ */
86056+ if (grsec_enable_setxid && !current_is_single_threaded() &&
86057+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
86058+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
86059+ schedule_it = 1;
86060+ }
86061+ ret = __commit_creds(new);
86062+ if (schedule_it) {
86063+ rcu_read_lock();
86064+ read_lock(&tasklist_lock);
86065+ for (t = next_thread(current); t != current;
86066+ t = next_thread(t)) {
86067+ if (t->delayed_cred == NULL) {
86068+ t->delayed_cred = get_cred(new);
86069+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
86070+ set_tsk_need_resched(t);
86071+ }
86072+ }
86073+ read_unlock(&tasklist_lock);
86074+ rcu_read_unlock();
86075+ }
86076+ return ret;
86077+#else
86078+ return __commit_creds(new);
86079+#endif
86080+}
86081+
86082 EXPORT_SYMBOL(commit_creds);
86083
86084 /**
86085diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
86086index 334b398..9145fb1 100644
86087--- a/kernel/debug/debug_core.c
86088+++ b/kernel/debug/debug_core.c
86089@@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
86090 */
86091 static atomic_t masters_in_kgdb;
86092 static atomic_t slaves_in_kgdb;
86093-static atomic_t kgdb_break_tasklet_var;
86094+static atomic_unchecked_t kgdb_break_tasklet_var;
86095 atomic_t kgdb_setting_breakpoint;
86096
86097 struct task_struct *kgdb_usethread;
86098@@ -133,7 +133,7 @@ int kgdb_single_step;
86099 static pid_t kgdb_sstep_pid;
86100
86101 /* to keep track of the CPU which is doing the single stepping*/
86102-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
86103+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
86104
86105 /*
86106 * If you are debugging a problem where roundup (the collection of
86107@@ -541,7 +541,7 @@ return_normal:
86108 * kernel will only try for the value of sstep_tries before
86109 * giving up and continuing on.
86110 */
86111- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
86112+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
86113 (kgdb_info[cpu].task &&
86114 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
86115 atomic_set(&kgdb_active, -1);
86116@@ -639,8 +639,8 @@ cpu_master_loop:
86117 }
86118
86119 kgdb_restore:
86120- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
86121- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
86122+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
86123+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
86124 if (kgdb_info[sstep_cpu].task)
86125 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
86126 else
86127@@ -917,18 +917,18 @@ static void kgdb_unregister_callbacks(void)
86128 static void kgdb_tasklet_bpt(unsigned long ing)
86129 {
86130 kgdb_breakpoint();
86131- atomic_set(&kgdb_break_tasklet_var, 0);
86132+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
86133 }
86134
86135 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
86136
86137 void kgdb_schedule_breakpoint(void)
86138 {
86139- if (atomic_read(&kgdb_break_tasklet_var) ||
86140+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
86141 atomic_read(&kgdb_active) != -1 ||
86142 atomic_read(&kgdb_setting_breakpoint))
86143 return;
86144- atomic_inc(&kgdb_break_tasklet_var);
86145+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
86146 tasklet_schedule(&kgdb_tasklet_breakpoint);
86147 }
86148 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
86149diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
86150index 0b097c8..11dd5c5 100644
86151--- a/kernel/debug/kdb/kdb_main.c
86152+++ b/kernel/debug/kdb/kdb_main.c
86153@@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
86154 continue;
86155
86156 kdb_printf("%-20s%8u 0x%p ", mod->name,
86157- mod->core_size, (void *)mod);
86158+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
86159 #ifdef CONFIG_MODULE_UNLOAD
86160 kdb_printf("%4ld ", module_refcount(mod));
86161 #endif
86162@@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
86163 kdb_printf(" (Loading)");
86164 else
86165 kdb_printf(" (Live)");
86166- kdb_printf(" 0x%p", mod->module_core);
86167+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
86168
86169 #ifdef CONFIG_MODULE_UNLOAD
86170 {
86171diff --git a/kernel/events/core.c b/kernel/events/core.c
86172index fa0b2d4..67a1c7a 100644
86173--- a/kernel/events/core.c
86174+++ b/kernel/events/core.c
86175@@ -158,8 +158,15 @@ static struct srcu_struct pmus_srcu;
86176 * 0 - disallow raw tracepoint access for unpriv
86177 * 1 - disallow cpu events for unpriv
86178 * 2 - disallow kernel profiling for unpriv
86179+ * 3 - disallow all unpriv perf event use
86180 */
86181-int sysctl_perf_event_paranoid __read_mostly = 1;
86182+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
86183+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
86184+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
86185+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
86186+#else
86187+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
86188+#endif
86189
86190 /* Minimum for 512 kiB + 1 user control page */
86191 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
86192@@ -185,7 +192,7 @@ void update_perf_cpu_limits(void)
86193
86194 tmp *= sysctl_perf_cpu_time_max_percent;
86195 do_div(tmp, 100);
86196- ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
86197+ ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
86198 }
86199
86200 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
86201@@ -272,7 +279,7 @@ void perf_sample_event_took(u64 sample_len_ns)
86202 update_perf_cpu_limits();
86203 }
86204
86205-static atomic64_t perf_event_id;
86206+static atomic64_unchecked_t perf_event_id;
86207
86208 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
86209 enum event_type_t event_type);
86210@@ -2986,7 +2993,7 @@ static void __perf_event_read(void *info)
86211
86212 static inline u64 perf_event_count(struct perf_event *event)
86213 {
86214- return local64_read(&event->count) + atomic64_read(&event->child_count);
86215+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
86216 }
86217
86218 static u64 perf_event_read(struct perf_event *event)
86219@@ -3354,9 +3361,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
86220 mutex_lock(&event->child_mutex);
86221 total += perf_event_read(event);
86222 *enabled += event->total_time_enabled +
86223- atomic64_read(&event->child_total_time_enabled);
86224+ atomic64_read_unchecked(&event->child_total_time_enabled);
86225 *running += event->total_time_running +
86226- atomic64_read(&event->child_total_time_running);
86227+ atomic64_read_unchecked(&event->child_total_time_running);
86228
86229 list_for_each_entry(child, &event->child_list, child_list) {
86230 total += perf_event_read(child);
86231@@ -3785,10 +3792,10 @@ void perf_event_update_userpage(struct perf_event *event)
86232 userpg->offset -= local64_read(&event->hw.prev_count);
86233
86234 userpg->time_enabled = enabled +
86235- atomic64_read(&event->child_total_time_enabled);
86236+ atomic64_read_unchecked(&event->child_total_time_enabled);
86237
86238 userpg->time_running = running +
86239- atomic64_read(&event->child_total_time_running);
86240+ atomic64_read_unchecked(&event->child_total_time_running);
86241
86242 arch_perf_update_userpage(userpg, now);
86243
86244@@ -4339,7 +4346,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
86245
86246 /* Data. */
86247 sp = perf_user_stack_pointer(regs);
86248- rem = __output_copy_user(handle, (void *) sp, dump_size);
86249+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
86250 dyn_size = dump_size - rem;
86251
86252 perf_output_skip(handle, rem);
86253@@ -4430,11 +4437,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
86254 values[n++] = perf_event_count(event);
86255 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
86256 values[n++] = enabled +
86257- atomic64_read(&event->child_total_time_enabled);
86258+ atomic64_read_unchecked(&event->child_total_time_enabled);
86259 }
86260 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
86261 values[n++] = running +
86262- atomic64_read(&event->child_total_time_running);
86263+ atomic64_read_unchecked(&event->child_total_time_running);
86264 }
86265 if (read_format & PERF_FORMAT_ID)
86266 values[n++] = primary_event_id(event);
86267@@ -6704,7 +6711,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
86268 event->parent = parent_event;
86269
86270 event->ns = get_pid_ns(task_active_pid_ns(current));
86271- event->id = atomic64_inc_return(&perf_event_id);
86272+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
86273
86274 event->state = PERF_EVENT_STATE_INACTIVE;
86275
86276@@ -7004,6 +7011,11 @@ SYSCALL_DEFINE5(perf_event_open,
86277 if (flags & ~PERF_FLAG_ALL)
86278 return -EINVAL;
86279
86280+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
86281+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
86282+ return -EACCES;
86283+#endif
86284+
86285 err = perf_copy_attr(attr_uptr, &attr);
86286 if (err)
86287 return err;
86288@@ -7339,10 +7351,10 @@ static void sync_child_event(struct perf_event *child_event,
86289 /*
86290 * Add back the child's count to the parent's count:
86291 */
86292- atomic64_add(child_val, &parent_event->child_count);
86293- atomic64_add(child_event->total_time_enabled,
86294+ atomic64_add_unchecked(child_val, &parent_event->child_count);
86295+ atomic64_add_unchecked(child_event->total_time_enabled,
86296 &parent_event->child_total_time_enabled);
86297- atomic64_add(child_event->total_time_running,
86298+ atomic64_add_unchecked(child_event->total_time_running,
86299 &parent_event->child_total_time_running);
86300
86301 /*
86302diff --git a/kernel/events/internal.h b/kernel/events/internal.h
86303index 569b2187..19940d9 100644
86304--- a/kernel/events/internal.h
86305+++ b/kernel/events/internal.h
86306@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
86307 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
86308 }
86309
86310-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
86311+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
86312 static inline unsigned long \
86313 func_name(struct perf_output_handle *handle, \
86314- const void *buf, unsigned long len) \
86315+ const void user *buf, unsigned long len) \
86316 { \
86317 unsigned long size, written; \
86318 \
86319@@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
86320 return 0;
86321 }
86322
86323-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
86324+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
86325
86326 static inline unsigned long
86327 memcpy_skip(void *dst, const void *src, unsigned long n)
86328@@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
86329 return 0;
86330 }
86331
86332-DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
86333+DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
86334
86335 #ifndef arch_perf_out_copy_user
86336 #define arch_perf_out_copy_user arch_perf_out_copy_user
86337@@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
86338 }
86339 #endif
86340
86341-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
86342+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
86343
86344 /* Callchain handling */
86345 extern struct perf_callchain_entry *
86346diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
86347index 307d87c..6466cbe 100644
86348--- a/kernel/events/uprobes.c
86349+++ b/kernel/events/uprobes.c
86350@@ -1666,7 +1666,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
86351 {
86352 struct page *page;
86353 uprobe_opcode_t opcode;
86354- int result;
86355+ long result;
86356
86357 pagefault_disable();
86358 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
86359diff --git a/kernel/exit.c b/kernel/exit.c
86360index 81b3d67..ef189a4 100644
86361--- a/kernel/exit.c
86362+++ b/kernel/exit.c
86363@@ -173,6 +173,10 @@ void release_task(struct task_struct * p)
86364 struct task_struct *leader;
86365 int zap_leader;
86366 repeat:
86367+#ifdef CONFIG_NET
86368+ gr_del_task_from_ip_table(p);
86369+#endif
86370+
86371 /* don't need to get the RCU readlock here - the process is dead and
86372 * can't be modifying its own credentials. But shut RCU-lockdep up */
86373 rcu_read_lock();
86374@@ -330,7 +334,7 @@ int allow_signal(int sig)
86375 * know it'll be handled, so that they don't get converted to
86376 * SIGKILL or just silently dropped.
86377 */
86378- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
86379+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
86380 recalc_sigpending();
86381 spin_unlock_irq(&current->sighand->siglock);
86382 return 0;
86383@@ -706,6 +710,8 @@ void do_exit(long code)
86384 struct task_struct *tsk = current;
86385 int group_dead;
86386
86387+ set_fs(USER_DS);
86388+
86389 profile_task_exit(tsk);
86390
86391 WARN_ON(blk_needs_flush_plug(tsk));
86392@@ -722,7 +728,6 @@ void do_exit(long code)
86393 * mm_release()->clear_child_tid() from writing to a user-controlled
86394 * kernel address.
86395 */
86396- set_fs(USER_DS);
86397
86398 ptrace_event(PTRACE_EVENT_EXIT, code);
86399
86400@@ -781,6 +786,9 @@ void do_exit(long code)
86401 tsk->exit_code = code;
86402 taskstats_exit(tsk, group_dead);
86403
86404+ gr_acl_handle_psacct(tsk, code);
86405+ gr_acl_handle_exit();
86406+
86407 exit_mm(tsk);
86408
86409 if (group_dead)
86410@@ -900,7 +908,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
86411 * Take down every thread in the group. This is called by fatal signals
86412 * as well as by sys_exit_group (below).
86413 */
86414-void
86415+__noreturn void
86416 do_group_exit(int exit_code)
86417 {
86418 struct signal_struct *sig = current->signal;
86419diff --git a/kernel/fork.c b/kernel/fork.c
86420index a17621c..b77fef8 100644
86421--- a/kernel/fork.c
86422+++ b/kernel/fork.c
86423@@ -319,7 +319,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86424 *stackend = STACK_END_MAGIC; /* for overflow detection */
86425
86426 #ifdef CONFIG_CC_STACKPROTECTOR
86427- tsk->stack_canary = get_random_int();
86428+ tsk->stack_canary = pax_get_random_long();
86429 #endif
86430
86431 /*
86432@@ -345,12 +345,80 @@ free_tsk:
86433 }
86434
86435 #ifdef CONFIG_MMU
86436-static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86437+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
86438+{
86439+ struct vm_area_struct *tmp;
86440+ unsigned long charge;
86441+ struct file *file;
86442+ int retval;
86443+
86444+ charge = 0;
86445+ if (mpnt->vm_flags & VM_ACCOUNT) {
86446+ unsigned long len = vma_pages(mpnt);
86447+
86448+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
86449+ goto fail_nomem;
86450+ charge = len;
86451+ }
86452+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
86453+ if (!tmp)
86454+ goto fail_nomem;
86455+ *tmp = *mpnt;
86456+ tmp->vm_mm = mm;
86457+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
86458+ retval = vma_dup_policy(mpnt, tmp);
86459+ if (retval)
86460+ goto fail_nomem_policy;
86461+ if (anon_vma_fork(tmp, mpnt))
86462+ goto fail_nomem_anon_vma_fork;
86463+ tmp->vm_flags &= ~VM_LOCKED;
86464+ tmp->vm_next = tmp->vm_prev = NULL;
86465+ tmp->vm_mirror = NULL;
86466+ file = tmp->vm_file;
86467+ if (file) {
86468+ struct inode *inode = file_inode(file);
86469+ struct address_space *mapping = file->f_mapping;
86470+
86471+ get_file(file);
86472+ if (tmp->vm_flags & VM_DENYWRITE)
86473+ atomic_dec(&inode->i_writecount);
86474+ mutex_lock(&mapping->i_mmap_mutex);
86475+ if (tmp->vm_flags & VM_SHARED)
86476+ mapping->i_mmap_writable++;
86477+ flush_dcache_mmap_lock(mapping);
86478+ /* insert tmp into the share list, just after mpnt */
86479+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
86480+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
86481+ else
86482+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
86483+ flush_dcache_mmap_unlock(mapping);
86484+ mutex_unlock(&mapping->i_mmap_mutex);
86485+ }
86486+
86487+ /*
86488+ * Clear hugetlb-related page reserves for children. This only
86489+ * affects MAP_PRIVATE mappings. Faults generated by the child
86490+ * are not guaranteed to succeed, even if read-only
86491+ */
86492+ if (is_vm_hugetlb_page(tmp))
86493+ reset_vma_resv_huge_pages(tmp);
86494+
86495+ return tmp;
86496+
86497+fail_nomem_anon_vma_fork:
86498+ mpol_put(vma_policy(tmp));
86499+fail_nomem_policy:
86500+ kmem_cache_free(vm_area_cachep, tmp);
86501+fail_nomem:
86502+ vm_unacct_memory(charge);
86503+ return NULL;
86504+}
86505+
86506+static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86507 {
86508 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
86509 struct rb_node **rb_link, *rb_parent;
86510 int retval;
86511- unsigned long charge;
86512
86513 uprobe_start_dup_mmap();
86514 down_write(&oldmm->mmap_sem);
86515@@ -379,55 +447,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86516
86517 prev = NULL;
86518 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
86519- struct file *file;
86520-
86521 if (mpnt->vm_flags & VM_DONTCOPY) {
86522 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
86523 -vma_pages(mpnt));
86524 continue;
86525 }
86526- charge = 0;
86527- if (mpnt->vm_flags & VM_ACCOUNT) {
86528- unsigned long len = vma_pages(mpnt);
86529-
86530- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
86531- goto fail_nomem;
86532- charge = len;
86533- }
86534- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
86535- if (!tmp)
86536- goto fail_nomem;
86537- *tmp = *mpnt;
86538- INIT_LIST_HEAD(&tmp->anon_vma_chain);
86539- retval = vma_dup_policy(mpnt, tmp);
86540- if (retval)
86541- goto fail_nomem_policy;
86542- tmp->vm_mm = mm;
86543- if (anon_vma_fork(tmp, mpnt))
86544- goto fail_nomem_anon_vma_fork;
86545- tmp->vm_flags &= ~VM_LOCKED;
86546- tmp->vm_next = tmp->vm_prev = NULL;
86547- file = tmp->vm_file;
86548- if (file) {
86549- struct inode *inode = file_inode(file);
86550- struct address_space *mapping = file->f_mapping;
86551-
86552- get_file(file);
86553- if (tmp->vm_flags & VM_DENYWRITE)
86554- atomic_dec(&inode->i_writecount);
86555- mutex_lock(&mapping->i_mmap_mutex);
86556- if (tmp->vm_flags & VM_SHARED)
86557- mapping->i_mmap_writable++;
86558- flush_dcache_mmap_lock(mapping);
86559- /* insert tmp into the share list, just after mpnt */
86560- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
86561- vma_nonlinear_insert(tmp,
86562- &mapping->i_mmap_nonlinear);
86563- else
86564- vma_interval_tree_insert_after(tmp, mpnt,
86565- &mapping->i_mmap);
86566- flush_dcache_mmap_unlock(mapping);
86567- mutex_unlock(&mapping->i_mmap_mutex);
86568+ tmp = dup_vma(mm, oldmm, mpnt);
86569+ if (!tmp) {
86570+ retval = -ENOMEM;
86571+ goto out;
86572 }
86573
86574 /*
86575@@ -459,6 +487,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86576 if (retval)
86577 goto out;
86578 }
86579+
86580+#ifdef CONFIG_PAX_SEGMEXEC
86581+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
86582+ struct vm_area_struct *mpnt_m;
86583+
86584+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
86585+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
86586+
86587+ if (!mpnt->vm_mirror)
86588+ continue;
86589+
86590+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
86591+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
86592+ mpnt->vm_mirror = mpnt_m;
86593+ } else {
86594+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
86595+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
86596+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
86597+ mpnt->vm_mirror->vm_mirror = mpnt;
86598+ }
86599+ }
86600+ BUG_ON(mpnt_m);
86601+ }
86602+#endif
86603+
86604 /* a new mm has just been created */
86605 arch_dup_mmap(oldmm, mm);
86606 retval = 0;
86607@@ -468,14 +521,6 @@ out:
86608 up_write(&oldmm->mmap_sem);
86609 uprobe_end_dup_mmap();
86610 return retval;
86611-fail_nomem_anon_vma_fork:
86612- mpol_put(vma_policy(tmp));
86613-fail_nomem_policy:
86614- kmem_cache_free(vm_area_cachep, tmp);
86615-fail_nomem:
86616- retval = -ENOMEM;
86617- vm_unacct_memory(charge);
86618- goto out;
86619 }
86620
86621 static inline int mm_alloc_pgd(struct mm_struct *mm)
86622@@ -689,8 +734,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
86623 return ERR_PTR(err);
86624
86625 mm = get_task_mm(task);
86626- if (mm && mm != current->mm &&
86627- !ptrace_may_access(task, mode)) {
86628+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
86629+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
86630 mmput(mm);
86631 mm = ERR_PTR(-EACCES);
86632 }
86633@@ -906,13 +951,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
86634 spin_unlock(&fs->lock);
86635 return -EAGAIN;
86636 }
86637- fs->users++;
86638+ atomic_inc(&fs->users);
86639 spin_unlock(&fs->lock);
86640 return 0;
86641 }
86642 tsk->fs = copy_fs_struct(fs);
86643 if (!tsk->fs)
86644 return -ENOMEM;
86645+ /* Carry through gr_chroot_dentry and is_chrooted instead
86646+ of recomputing it here. Already copied when the task struct
86647+ is duplicated. This allows pivot_root to not be treated as
86648+ a chroot
86649+ */
86650+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
86651+
86652 return 0;
86653 }
86654
86655@@ -1130,7 +1182,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
86656 * parts of the process environment (as per the clone
86657 * flags). The actual kick-off is left to the caller.
86658 */
86659-static struct task_struct *copy_process(unsigned long clone_flags,
86660+static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
86661 unsigned long stack_start,
86662 unsigned long stack_size,
86663 int __user *child_tidptr,
86664@@ -1202,6 +1254,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
86665 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
86666 #endif
86667 retval = -EAGAIN;
86668+
86669+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
86670+
86671 if (atomic_read(&p->real_cred->user->processes) >=
86672 task_rlimit(p, RLIMIT_NPROC)) {
86673 if (p->real_cred->user != INIT_USER &&
86674@@ -1449,6 +1504,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
86675 goto bad_fork_free_pid;
86676 }
86677
86678+ /* synchronizes with gr_set_acls()
86679+ we need to call this past the point of no return for fork()
86680+ */
86681+ gr_copy_label(p);
86682+
86683 if (likely(p->pid)) {
86684 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
86685
86686@@ -1537,6 +1597,8 @@ bad_fork_cleanup_count:
86687 bad_fork_free:
86688 free_task(p);
86689 fork_out:
86690+ gr_log_forkfail(retval);
86691+
86692 return ERR_PTR(retval);
86693 }
86694
86695@@ -1598,6 +1660,7 @@ long do_fork(unsigned long clone_flags,
86696
86697 p = copy_process(clone_flags, stack_start, stack_size,
86698 child_tidptr, NULL, trace);
86699+ add_latent_entropy();
86700 /*
86701 * Do this prior waking up the new thread - the thread pointer
86702 * might get invalid after that point, if the thread exits quickly.
86703@@ -1612,6 +1675,8 @@ long do_fork(unsigned long clone_flags,
86704 if (clone_flags & CLONE_PARENT_SETTID)
86705 put_user(nr, parent_tidptr);
86706
86707+ gr_handle_brute_check();
86708+
86709 if (clone_flags & CLONE_VFORK) {
86710 p->vfork_done = &vfork;
86711 init_completion(&vfork);
86712@@ -1728,7 +1793,7 @@ void __init proc_caches_init(void)
86713 mm_cachep = kmem_cache_create("mm_struct",
86714 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
86715 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
86716- vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
86717+ vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
86718 mmap_init();
86719 nsproxy_cache_init();
86720 }
86721@@ -1768,7 +1833,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
86722 return 0;
86723
86724 /* don't need lock here; in the worst case we'll do useless copy */
86725- if (fs->users == 1)
86726+ if (atomic_read(&fs->users) == 1)
86727 return 0;
86728
86729 *new_fsp = copy_fs_struct(fs);
86730@@ -1875,7 +1940,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
86731 fs = current->fs;
86732 spin_lock(&fs->lock);
86733 current->fs = new_fs;
86734- if (--fs->users)
86735+ gr_set_chroot_entries(current, &current->fs->root);
86736+ if (atomic_dec_return(&fs->users))
86737 new_fs = NULL;
86738 else
86739 new_fs = fs;
86740diff --git a/kernel/futex.c b/kernel/futex.c
86741index 6801b37..bb6becca 100644
86742--- a/kernel/futex.c
86743+++ b/kernel/futex.c
86744@@ -54,6 +54,7 @@
86745 #include <linux/mount.h>
86746 #include <linux/pagemap.h>
86747 #include <linux/syscalls.h>
86748+#include <linux/ptrace.h>
86749 #include <linux/signal.h>
86750 #include <linux/export.h>
86751 #include <linux/magic.h>
86752@@ -380,6 +381,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
86753 struct page *page, *page_head;
86754 int err, ro = 0;
86755
86756+#ifdef CONFIG_PAX_SEGMEXEC
86757+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
86758+ return -EFAULT;
86759+#endif
86760+
86761 /*
86762 * The futex address must be "naturally" aligned.
86763 */
86764@@ -579,7 +585,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
86765
86766 static int get_futex_value_locked(u32 *dest, u32 __user *from)
86767 {
86768- int ret;
86769+ unsigned long ret;
86770
86771 pagefault_disable();
86772 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
86773@@ -2886,6 +2892,7 @@ static void __init futex_detect_cmpxchg(void)
86774 {
86775 #ifndef CONFIG_HAVE_FUTEX_CMPXCHG
86776 u32 curval;
86777+ mm_segment_t oldfs;
86778
86779 /*
86780 * This will fail and we want it. Some arch implementations do
86781@@ -2897,8 +2904,11 @@ static void __init futex_detect_cmpxchg(void)
86782 * implementation, the non-functional ones will return
86783 * -ENOSYS.
86784 */
86785+ oldfs = get_fs();
86786+ set_fs(USER_DS);
86787 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
86788 futex_cmpxchg_enabled = 1;
86789+ set_fs(oldfs);
86790 #endif
86791 }
86792
86793diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
86794index f9f44fd..29885e4 100644
86795--- a/kernel/futex_compat.c
86796+++ b/kernel/futex_compat.c
86797@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
86798 return 0;
86799 }
86800
86801-static void __user *futex_uaddr(struct robust_list __user *entry,
86802+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
86803 compat_long_t futex_offset)
86804 {
86805 compat_uptr_t base = ptr_to_compat(entry);
86806diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
86807index f45b75b..bfac6d5 100644
86808--- a/kernel/gcov/base.c
86809+++ b/kernel/gcov/base.c
86810@@ -108,11 +108,6 @@ void gcov_enable_events(void)
86811 }
86812
86813 #ifdef CONFIG_MODULES
86814-static inline int within(void *addr, void *start, unsigned long size)
86815-{
86816- return ((addr >= start) && (addr < start + size));
86817-}
86818-
86819 /* Update list and generate events when modules are unloaded. */
86820 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
86821 void *data)
86822@@ -127,7 +122,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
86823
86824 /* Remove entries located in module from linked list. */
86825 while ((info = gcov_info_next(info))) {
86826- if (within(info, mod->module_core, mod->core_size)) {
86827+ if (within_module_core_rw((unsigned long)info, mod)) {
86828 gcov_info_unlink(prev, info);
86829 if (gcov_events_enabled)
86830 gcov_event(GCOV_REMOVE, info);
86831diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
86832index 0909436..6037d22 100644
86833--- a/kernel/hrtimer.c
86834+++ b/kernel/hrtimer.c
86835@@ -1439,7 +1439,7 @@ void hrtimer_peek_ahead_timers(void)
86836 local_irq_restore(flags);
86837 }
86838
86839-static void run_hrtimer_softirq(struct softirq_action *h)
86840+static __latent_entropy void run_hrtimer_softirq(void)
86841 {
86842 hrtimer_peek_ahead_timers();
86843 }
86844diff --git a/kernel/irq_work.c b/kernel/irq_work.c
86845index 55fcce6..0e4cf34 100644
86846--- a/kernel/irq_work.c
86847+++ b/kernel/irq_work.c
86848@@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
86849 return NOTIFY_OK;
86850 }
86851
86852-static struct notifier_block cpu_notify;
86853+static struct notifier_block cpu_notify = {
86854+ .notifier_call = irq_work_cpu_notify,
86855+ .priority = 0,
86856+};
86857
86858 static __init int irq_work_init_cpu_notifier(void)
86859 {
86860- cpu_notify.notifier_call = irq_work_cpu_notify;
86861- cpu_notify.priority = 0;
86862 register_cpu_notifier(&cpu_notify);
86863 return 0;
86864 }
86865diff --git a/kernel/jump_label.c b/kernel/jump_label.c
86866index 9019f15..9a3c42e 100644
86867--- a/kernel/jump_label.c
86868+++ b/kernel/jump_label.c
86869@@ -14,6 +14,7 @@
86870 #include <linux/err.h>
86871 #include <linux/static_key.h>
86872 #include <linux/jump_label_ratelimit.h>
86873+#include <linux/mm.h>
86874
86875 #ifdef HAVE_JUMP_LABEL
86876
86877@@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
86878
86879 size = (((unsigned long)stop - (unsigned long)start)
86880 / sizeof(struct jump_entry));
86881+ pax_open_kernel();
86882 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
86883+ pax_close_kernel();
86884 }
86885
86886 static void jump_label_update(struct static_key *key, int enable);
86887@@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
86888 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
86889 struct jump_entry *iter;
86890
86891+ pax_open_kernel();
86892 for (iter = iter_start; iter < iter_stop; iter++) {
86893 if (within_module_init(iter->code, mod))
86894 iter->code = 0;
86895 }
86896+ pax_close_kernel();
86897 }
86898
86899 static int
86900diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
86901index 3127ad5..159d880 100644
86902--- a/kernel/kallsyms.c
86903+++ b/kernel/kallsyms.c
86904@@ -11,6 +11,9 @@
86905 * Changed the compression method from stem compression to "table lookup"
86906 * compression (see scripts/kallsyms.c for a more complete description)
86907 */
86908+#ifdef CONFIG_GRKERNSEC_HIDESYM
86909+#define __INCLUDED_BY_HIDESYM 1
86910+#endif
86911 #include <linux/kallsyms.h>
86912 #include <linux/module.h>
86913 #include <linux/init.h>
86914@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
86915
86916 static inline int is_kernel_inittext(unsigned long addr)
86917 {
86918+ if (system_state != SYSTEM_BOOTING)
86919+ return 0;
86920+
86921 if (addr >= (unsigned long)_sinittext
86922 && addr <= (unsigned long)_einittext)
86923 return 1;
86924 return 0;
86925 }
86926
86927+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86928+#ifdef CONFIG_MODULES
86929+static inline int is_module_text(unsigned long addr)
86930+{
86931+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
86932+ return 1;
86933+
86934+ addr = ktla_ktva(addr);
86935+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
86936+}
86937+#else
86938+static inline int is_module_text(unsigned long addr)
86939+{
86940+ return 0;
86941+}
86942+#endif
86943+#endif
86944+
86945 static inline int is_kernel_text(unsigned long addr)
86946 {
86947 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
86948@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
86949
86950 static inline int is_kernel(unsigned long addr)
86951 {
86952+
86953+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86954+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
86955+ return 1;
86956+
86957+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
86958+#else
86959 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
86960+#endif
86961+
86962 return 1;
86963 return in_gate_area_no_mm(addr);
86964 }
86965
86966 static int is_ksym_addr(unsigned long addr)
86967 {
86968+
86969+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86970+ if (is_module_text(addr))
86971+ return 0;
86972+#endif
86973+
86974 if (all_var)
86975 return is_kernel(addr);
86976
86977@@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
86978
86979 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
86980 {
86981- iter->name[0] = '\0';
86982 iter->nameoff = get_symbol_offset(new_pos);
86983 iter->pos = new_pos;
86984 }
86985@@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
86986 {
86987 struct kallsym_iter *iter = m->private;
86988
86989+#ifdef CONFIG_GRKERNSEC_HIDESYM
86990+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
86991+ return 0;
86992+#endif
86993+
86994 /* Some debugging symbols have no name. Ignore them. */
86995 if (!iter->name[0])
86996 return 0;
86997@@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
86998 */
86999 type = iter->exported ? toupper(iter->type) :
87000 tolower(iter->type);
87001+
87002 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
87003 type, iter->name, iter->module_name);
87004 } else
87005@@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
87006 struct kallsym_iter *iter;
87007 int ret;
87008
87009- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
87010+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
87011 if (!iter)
87012 return -ENOMEM;
87013 reset_iter(iter, 0);
87014diff --git a/kernel/kcmp.c b/kernel/kcmp.c
87015index e30ac0f..3528cac 100644
87016--- a/kernel/kcmp.c
87017+++ b/kernel/kcmp.c
87018@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
87019 struct task_struct *task1, *task2;
87020 int ret;
87021
87022+#ifdef CONFIG_GRKERNSEC
87023+ return -ENOSYS;
87024+#endif
87025+
87026 rcu_read_lock();
87027
87028 /*
87029diff --git a/kernel/kexec.c b/kernel/kexec.c
87030index 60bafbe..a120f4f 100644
87031--- a/kernel/kexec.c
87032+++ b/kernel/kexec.c
87033@@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
87034 unsigned long flags)
87035 {
87036 struct compat_kexec_segment in;
87037- struct kexec_segment out, __user *ksegments;
87038+ struct kexec_segment out;
87039+ struct kexec_segment __user *ksegments;
87040 unsigned long i, result;
87041
87042 /* Don't allow clients that don't understand the native
87043diff --git a/kernel/kmod.c b/kernel/kmod.c
87044index 6b375af..eaff670 100644
87045--- a/kernel/kmod.c
87046+++ b/kernel/kmod.c
87047@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
87048 kfree(info->argv);
87049 }
87050
87051-static int call_modprobe(char *module_name, int wait)
87052+static int call_modprobe(char *module_name, char *module_param, int wait)
87053 {
87054 struct subprocess_info *info;
87055 static char *envp[] = {
87056@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
87057 NULL
87058 };
87059
87060- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
87061+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
87062 if (!argv)
87063 goto out;
87064
87065@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
87066 argv[1] = "-q";
87067 argv[2] = "--";
87068 argv[3] = module_name; /* check free_modprobe_argv() */
87069- argv[4] = NULL;
87070+ argv[4] = module_param;
87071+ argv[5] = NULL;
87072
87073 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
87074 NULL, free_modprobe_argv, NULL);
87075@@ -129,9 +130,8 @@ out:
87076 * If module auto-loading support is disabled then this function
87077 * becomes a no-operation.
87078 */
87079-int __request_module(bool wait, const char *fmt, ...)
87080+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
87081 {
87082- va_list args;
87083 char module_name[MODULE_NAME_LEN];
87084 unsigned int max_modprobes;
87085 int ret;
87086@@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
87087 if (!modprobe_path[0])
87088 return 0;
87089
87090- va_start(args, fmt);
87091- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
87092- va_end(args);
87093+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
87094 if (ret >= MODULE_NAME_LEN)
87095 return -ENAMETOOLONG;
87096
87097@@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
87098 if (ret)
87099 return ret;
87100
87101+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87102+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
87103+ /* hack to workaround consolekit/udisks stupidity */
87104+ read_lock(&tasklist_lock);
87105+ if (!strcmp(current->comm, "mount") &&
87106+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
87107+ read_unlock(&tasklist_lock);
87108+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
87109+ return -EPERM;
87110+ }
87111+ read_unlock(&tasklist_lock);
87112+ }
87113+#endif
87114+
87115 /* If modprobe needs a service that is in a module, we get a recursive
87116 * loop. Limit the number of running kmod threads to max_threads/2 or
87117 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
87118@@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
87119
87120 trace_module_request(module_name, wait, _RET_IP_);
87121
87122- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
87123+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
87124
87125 atomic_dec(&kmod_concurrent);
87126 return ret;
87127 }
87128+
87129+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
87130+{
87131+ va_list args;
87132+ int ret;
87133+
87134+ va_start(args, fmt);
87135+ ret = ____request_module(wait, module_param, fmt, args);
87136+ va_end(args);
87137+
87138+ return ret;
87139+}
87140+
87141+int __request_module(bool wait, const char *fmt, ...)
87142+{
87143+ va_list args;
87144+ int ret;
87145+
87146+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87147+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
87148+ char module_param[MODULE_NAME_LEN];
87149+
87150+ memset(module_param, 0, sizeof(module_param));
87151+
87152+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
87153+
87154+ va_start(args, fmt);
87155+ ret = ____request_module(wait, module_param, fmt, args);
87156+ va_end(args);
87157+
87158+ return ret;
87159+ }
87160+#endif
87161+
87162+ va_start(args, fmt);
87163+ ret = ____request_module(wait, NULL, fmt, args);
87164+ va_end(args);
87165+
87166+ return ret;
87167+}
87168+
87169 EXPORT_SYMBOL(__request_module);
87170 #endif /* CONFIG_MODULES */
87171
87172@@ -218,6 +271,20 @@ static int ____call_usermodehelper(void *data)
87173 */
87174 set_user_nice(current, 0);
87175
87176+#ifdef CONFIG_GRKERNSEC
87177+ /* this is race-free as far as userland is concerned as we copied
87178+ out the path to be used prior to this point and are now operating
87179+ on that copy
87180+ */
87181+ if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
87182+ strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
87183+ strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
87184+ printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
87185+ retval = -EPERM;
87186+ goto fail;
87187+ }
87188+#endif
87189+
87190 retval = -ENOMEM;
87191 new = prepare_kernel_cred(current);
87192 if (!new)
87193@@ -240,8 +307,8 @@ static int ____call_usermodehelper(void *data)
87194 commit_creds(new);
87195
87196 retval = do_execve(getname_kernel(sub_info->path),
87197- (const char __user *const __user *)sub_info->argv,
87198- (const char __user *const __user *)sub_info->envp);
87199+ (const char __user *const __force_user *)sub_info->argv,
87200+ (const char __user *const __force_user *)sub_info->envp);
87201 if (!retval)
87202 return 0;
87203
87204@@ -260,6 +327,10 @@ static int call_helper(void *data)
87205
87206 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
87207 {
87208+#ifdef CONFIG_GRKERNSEC
87209+ kfree(info->path);
87210+ info->path = info->origpath;
87211+#endif
87212 if (info->cleanup)
87213 (*info->cleanup)(info);
87214 kfree(info);
87215@@ -303,7 +374,7 @@ static int wait_for_helper(void *data)
87216 *
87217 * Thus the __user pointer cast is valid here.
87218 */
87219- sys_wait4(pid, (int __user *)&ret, 0, NULL);
87220+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
87221
87222 /*
87223 * If ret is 0, either ____call_usermodehelper failed and the
87224@@ -542,7 +613,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
87225 goto out;
87226
87227 INIT_WORK(&sub_info->work, __call_usermodehelper);
87228+#ifdef CONFIG_GRKERNSEC
87229+ sub_info->origpath = path;
87230+ sub_info->path = kstrdup(path, gfp_mask);
87231+#else
87232 sub_info->path = path;
87233+#endif
87234 sub_info->argv = argv;
87235 sub_info->envp = envp;
87236
87237@@ -650,7 +726,7 @@ EXPORT_SYMBOL(call_usermodehelper);
87238 static int proc_cap_handler(struct ctl_table *table, int write,
87239 void __user *buffer, size_t *lenp, loff_t *ppos)
87240 {
87241- struct ctl_table t;
87242+ ctl_table_no_const t;
87243 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
87244 kernel_cap_t new_cap;
87245 int err, i;
87246diff --git a/kernel/kprobes.c b/kernel/kprobes.c
87247index ceeadfc..11c18b6 100644
87248--- a/kernel/kprobes.c
87249+++ b/kernel/kprobes.c
87250@@ -31,6 +31,9 @@
87251 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
87252 * <prasanna@in.ibm.com> added function-return probes.
87253 */
87254+#ifdef CONFIG_GRKERNSEC_HIDESYM
87255+#define __INCLUDED_BY_HIDESYM 1
87256+#endif
87257 #include <linux/kprobes.h>
87258 #include <linux/hash.h>
87259 #include <linux/init.h>
87260@@ -135,12 +138,12 @@ enum kprobe_slot_state {
87261
87262 static void *alloc_insn_page(void)
87263 {
87264- return module_alloc(PAGE_SIZE);
87265+ return module_alloc_exec(PAGE_SIZE);
87266 }
87267
87268 static void free_insn_page(void *page)
87269 {
87270- module_free(NULL, page);
87271+ module_free_exec(NULL, page);
87272 }
87273
87274 struct kprobe_insn_cache kprobe_insn_slots = {
87275@@ -2151,11 +2154,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
87276 kprobe_type = "k";
87277
87278 if (sym)
87279- seq_printf(pi, "%p %s %s+0x%x %s ",
87280+ seq_printf(pi, "%pK %s %s+0x%x %s ",
87281 p->addr, kprobe_type, sym, offset,
87282 (modname ? modname : " "));
87283 else
87284- seq_printf(pi, "%p %s %p ",
87285+ seq_printf(pi, "%pK %s %pK ",
87286 p->addr, kprobe_type, p->addr);
87287
87288 if (!pp)
87289diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
87290index d945a94..0b7f45f 100644
87291--- a/kernel/ksysfs.c
87292+++ b/kernel/ksysfs.c
87293@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
87294 {
87295 if (count+1 > UEVENT_HELPER_PATH_LEN)
87296 return -ENOENT;
87297+ if (!capable(CAP_SYS_ADMIN))
87298+ return -EPERM;
87299 memcpy(uevent_helper, buf, count);
87300 uevent_helper[count] = '\0';
87301 if (count && uevent_helper[count-1] == '\n')
87302@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
87303 return count;
87304 }
87305
87306-static struct bin_attribute notes_attr = {
87307+static bin_attribute_no_const notes_attr __read_only = {
87308 .attr = {
87309 .name = "notes",
87310 .mode = S_IRUGO,
87311diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
87312index eb8a547..321d8e1 100644
87313--- a/kernel/locking/lockdep.c
87314+++ b/kernel/locking/lockdep.c
87315@@ -597,6 +597,10 @@ static int static_obj(void *obj)
87316 end = (unsigned long) &_end,
87317 addr = (unsigned long) obj;
87318
87319+#ifdef CONFIG_PAX_KERNEXEC
87320+ start = ktla_ktva(start);
87321+#endif
87322+
87323 /*
87324 * static variable?
87325 */
87326@@ -738,6 +742,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
87327 if (!static_obj(lock->key)) {
87328 debug_locks_off();
87329 printk("INFO: trying to register non-static key.\n");
87330+ printk("lock:%pS key:%pS.\n", lock, lock->key);
87331 printk("the code is fine but needs lockdep annotation.\n");
87332 printk("turning off the locking correctness validator.\n");
87333 dump_stack();
87334@@ -3082,7 +3087,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
87335 if (!class)
87336 return 0;
87337 }
87338- atomic_inc((atomic_t *)&class->ops);
87339+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
87340 if (very_verbose(class)) {
87341 printk("\nacquire class [%p] %s", class->key, class->name);
87342 if (class->name_version > 1)
87343diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
87344index ef43ac4..2720dfa 100644
87345--- a/kernel/locking/lockdep_proc.c
87346+++ b/kernel/locking/lockdep_proc.c
87347@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
87348 return 0;
87349 }
87350
87351- seq_printf(m, "%p", class->key);
87352+ seq_printf(m, "%pK", class->key);
87353 #ifdef CONFIG_DEBUG_LOCKDEP
87354 seq_printf(m, " OPS:%8ld", class->ops);
87355 #endif
87356@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
87357
87358 list_for_each_entry(entry, &class->locks_after, entry) {
87359 if (entry->distance == 1) {
87360- seq_printf(m, " -> [%p] ", entry->class->key);
87361+ seq_printf(m, " -> [%pK] ", entry->class->key);
87362 print_name(m, entry->class);
87363 seq_puts(m, "\n");
87364 }
87365@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
87366 if (!class->key)
87367 continue;
87368
87369- seq_printf(m, "[%p] ", class->key);
87370+ seq_printf(m, "[%pK] ", class->key);
87371 print_name(m, class);
87372 seq_puts(m, "\n");
87373 }
87374@@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
87375 if (!i)
87376 seq_line(m, '-', 40-namelen, namelen);
87377
87378- snprintf(ip, sizeof(ip), "[<%p>]",
87379+ snprintf(ip, sizeof(ip), "[<%pK>]",
87380 (void *)class->contention_point[i]);
87381 seq_printf(m, "%40s %14lu %29s %pS\n",
87382 name, stats->contention_point[i],
87383@@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
87384 if (!i)
87385 seq_line(m, '-', 40-namelen, namelen);
87386
87387- snprintf(ip, sizeof(ip), "[<%p>]",
87388+ snprintf(ip, sizeof(ip), "[<%pK>]",
87389 (void *)class->contending_point[i]);
87390 seq_printf(m, "%40s %14lu %29s %pS\n",
87391 name, stats->contending_point[i],
87392diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
87393index faf6f5b..dc9070a 100644
87394--- a/kernel/locking/mutex-debug.c
87395+++ b/kernel/locking/mutex-debug.c
87396@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
87397 }
87398
87399 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
87400- struct thread_info *ti)
87401+ struct task_struct *task)
87402 {
87403 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
87404
87405 /* Mark the current thread as blocked on the lock: */
87406- ti->task->blocked_on = waiter;
87407+ task->blocked_on = waiter;
87408 }
87409
87410 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
87411- struct thread_info *ti)
87412+ struct task_struct *task)
87413 {
87414 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
87415- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
87416- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
87417- ti->task->blocked_on = NULL;
87418+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
87419+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
87420+ task->blocked_on = NULL;
87421
87422 list_del_init(&waiter->list);
87423 waiter->task = NULL;
87424diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
87425index 0799fd3..d06ae3b 100644
87426--- a/kernel/locking/mutex-debug.h
87427+++ b/kernel/locking/mutex-debug.h
87428@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
87429 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
87430 extern void debug_mutex_add_waiter(struct mutex *lock,
87431 struct mutex_waiter *waiter,
87432- struct thread_info *ti);
87433+ struct task_struct *task);
87434 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
87435- struct thread_info *ti);
87436+ struct task_struct *task);
87437 extern void debug_mutex_unlock(struct mutex *lock);
87438 extern void debug_mutex_init(struct mutex *lock, const char *name,
87439 struct lock_class_key *key);
87440diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
87441index 4dd6e4c..df52693 100644
87442--- a/kernel/locking/mutex.c
87443+++ b/kernel/locking/mutex.c
87444@@ -135,7 +135,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
87445 node->locked = 1;
87446 return;
87447 }
87448- ACCESS_ONCE(prev->next) = node;
87449+ ACCESS_ONCE_RW(prev->next) = node;
87450 smp_wmb();
87451 /* Wait until the lock holder passes the lock down */
87452 while (!ACCESS_ONCE(node->locked))
87453@@ -156,7 +156,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
87454 while (!(next = ACCESS_ONCE(node->next)))
87455 arch_mutex_cpu_relax();
87456 }
87457- ACCESS_ONCE(next->locked) = 1;
87458+ ACCESS_ONCE_RW(next->locked) = 1;
87459 smp_wmb();
87460 }
87461
87462@@ -520,7 +520,7 @@ slowpath:
87463 goto skip_wait;
87464
87465 debug_mutex_lock_common(lock, &waiter);
87466- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
87467+ debug_mutex_add_waiter(lock, &waiter, task);
87468
87469 /* add waiting tasks to the end of the waitqueue (FIFO): */
87470 list_add_tail(&waiter.list, &lock->wait_list);
87471@@ -564,7 +564,7 @@ slowpath:
87472 schedule_preempt_disabled();
87473 spin_lock_mutex(&lock->wait_lock, flags);
87474 }
87475- mutex_remove_waiter(lock, &waiter, current_thread_info());
87476+ mutex_remove_waiter(lock, &waiter, task);
87477 /* set it to 0 if there are no waiters left: */
87478 if (likely(list_empty(&lock->wait_list)))
87479 atomic_set(&lock->count, 0);
87480@@ -601,7 +601,7 @@ skip_wait:
87481 return 0;
87482
87483 err:
87484- mutex_remove_waiter(lock, &waiter, task_thread_info(task));
87485+ mutex_remove_waiter(lock, &waiter, task);
87486 spin_unlock_mutex(&lock->wait_lock, flags);
87487 debug_mutex_free_waiter(&waiter);
87488 mutex_release(&lock->dep_map, 1, ip);
87489diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
87490index 1d96dd0..994ff19 100644
87491--- a/kernel/locking/rtmutex-tester.c
87492+++ b/kernel/locking/rtmutex-tester.c
87493@@ -22,7 +22,7 @@
87494 #define MAX_RT_TEST_MUTEXES 8
87495
87496 static spinlock_t rttest_lock;
87497-static atomic_t rttest_event;
87498+static atomic_unchecked_t rttest_event;
87499
87500 struct test_thread_data {
87501 int opcode;
87502@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87503
87504 case RTTEST_LOCKCONT:
87505 td->mutexes[td->opdata] = 1;
87506- td->event = atomic_add_return(1, &rttest_event);
87507+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87508 return 0;
87509
87510 case RTTEST_RESET:
87511@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87512 return 0;
87513
87514 case RTTEST_RESETEVENT:
87515- atomic_set(&rttest_event, 0);
87516+ atomic_set_unchecked(&rttest_event, 0);
87517 return 0;
87518
87519 default:
87520@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87521 return ret;
87522
87523 td->mutexes[id] = 1;
87524- td->event = atomic_add_return(1, &rttest_event);
87525+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87526 rt_mutex_lock(&mutexes[id]);
87527- td->event = atomic_add_return(1, &rttest_event);
87528+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87529 td->mutexes[id] = 4;
87530 return 0;
87531
87532@@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87533 return ret;
87534
87535 td->mutexes[id] = 1;
87536- td->event = atomic_add_return(1, &rttest_event);
87537+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87538 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
87539- td->event = atomic_add_return(1, &rttest_event);
87540+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87541 td->mutexes[id] = ret ? 0 : 4;
87542 return ret ? -EINTR : 0;
87543
87544@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87545 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
87546 return ret;
87547
87548- td->event = atomic_add_return(1, &rttest_event);
87549+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87550 rt_mutex_unlock(&mutexes[id]);
87551- td->event = atomic_add_return(1, &rttest_event);
87552+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87553 td->mutexes[id] = 0;
87554 return 0;
87555
87556@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87557 break;
87558
87559 td->mutexes[dat] = 2;
87560- td->event = atomic_add_return(1, &rttest_event);
87561+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87562 break;
87563
87564 default:
87565@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87566 return;
87567
87568 td->mutexes[dat] = 3;
87569- td->event = atomic_add_return(1, &rttest_event);
87570+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87571 break;
87572
87573 case RTTEST_LOCKNOWAIT:
87574@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87575 return;
87576
87577 td->mutexes[dat] = 1;
87578- td->event = atomic_add_return(1, &rttest_event);
87579+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87580 return;
87581
87582 default:
87583diff --git a/kernel/module.c b/kernel/module.c
87584index d24fcf2..2af3fd9 100644
87585--- a/kernel/module.c
87586+++ b/kernel/module.c
87587@@ -61,6 +61,7 @@
87588 #include <linux/pfn.h>
87589 #include <linux/bsearch.h>
87590 #include <linux/fips.h>
87591+#include <linux/grsecurity.h>
87592 #include <uapi/linux/module.h>
87593 #include "module-internal.h"
87594
87595@@ -157,7 +158,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
87596
87597 /* Bounds of module allocation, for speeding __module_address.
87598 * Protected by module_mutex. */
87599-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
87600+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
87601+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
87602
87603 int register_module_notifier(struct notifier_block * nb)
87604 {
87605@@ -324,7 +326,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
87606 return true;
87607
87608 list_for_each_entry_rcu(mod, &modules, list) {
87609- struct symsearch arr[] = {
87610+ struct symsearch modarr[] = {
87611 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
87612 NOT_GPL_ONLY, false },
87613 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
87614@@ -349,7 +351,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
87615 if (mod->state == MODULE_STATE_UNFORMED)
87616 continue;
87617
87618- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
87619+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
87620 return true;
87621 }
87622 return false;
87623@@ -489,7 +491,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
87624 if (!pcpusec->sh_size)
87625 return 0;
87626
87627- if (align > PAGE_SIZE) {
87628+ if (align-1 >= PAGE_SIZE) {
87629 pr_warn("%s: per-cpu alignment %li > %li\n",
87630 mod->name, align, PAGE_SIZE);
87631 align = PAGE_SIZE;
87632@@ -1062,7 +1064,7 @@ struct module_attribute module_uevent =
87633 static ssize_t show_coresize(struct module_attribute *mattr,
87634 struct module_kobject *mk, char *buffer)
87635 {
87636- return sprintf(buffer, "%u\n", mk->mod->core_size);
87637+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
87638 }
87639
87640 static struct module_attribute modinfo_coresize =
87641@@ -1071,7 +1073,7 @@ static struct module_attribute modinfo_coresize =
87642 static ssize_t show_initsize(struct module_attribute *mattr,
87643 struct module_kobject *mk, char *buffer)
87644 {
87645- return sprintf(buffer, "%u\n", mk->mod->init_size);
87646+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
87647 }
87648
87649 static struct module_attribute modinfo_initsize =
87650@@ -1163,12 +1165,29 @@ static int check_version(Elf_Shdr *sechdrs,
87651 goto bad_version;
87652 }
87653
87654+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
87655+ /*
87656+ * avoid potentially printing jibberish on attempted load
87657+ * of a module randomized with a different seed
87658+ */
87659+ pr_warn("no symbol version for %s\n", symname);
87660+#else
87661 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
87662+#endif
87663 return 0;
87664
87665 bad_version:
87666+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
87667+ /*
87668+ * avoid potentially printing jibberish on attempted load
87669+ * of a module randomized with a different seed
87670+ */
87671+ printk("attempted module disagrees about version of symbol %s\n",
87672+ symname);
87673+#else
87674 printk("%s: disagrees about version of symbol %s\n",
87675 mod->name, symname);
87676+#endif
87677 return 0;
87678 }
87679
87680@@ -1284,7 +1303,7 @@ resolve_symbol_wait(struct module *mod,
87681 */
87682 #ifdef CONFIG_SYSFS
87683
87684-#ifdef CONFIG_KALLSYMS
87685+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
87686 static inline bool sect_empty(const Elf_Shdr *sect)
87687 {
87688 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
87689@@ -1424,7 +1443,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
87690 {
87691 unsigned int notes, loaded, i;
87692 struct module_notes_attrs *notes_attrs;
87693- struct bin_attribute *nattr;
87694+ bin_attribute_no_const *nattr;
87695
87696 /* failed to create section attributes, so can't create notes */
87697 if (!mod->sect_attrs)
87698@@ -1536,7 +1555,7 @@ static void del_usage_links(struct module *mod)
87699 static int module_add_modinfo_attrs(struct module *mod)
87700 {
87701 struct module_attribute *attr;
87702- struct module_attribute *temp_attr;
87703+ module_attribute_no_const *temp_attr;
87704 int error = 0;
87705 int i;
87706
87707@@ -1757,21 +1776,21 @@ static void set_section_ro_nx(void *base,
87708
87709 static void unset_module_core_ro_nx(struct module *mod)
87710 {
87711- set_page_attributes(mod->module_core + mod->core_text_size,
87712- mod->module_core + mod->core_size,
87713+ set_page_attributes(mod->module_core_rw,
87714+ mod->module_core_rw + mod->core_size_rw,
87715 set_memory_x);
87716- set_page_attributes(mod->module_core,
87717- mod->module_core + mod->core_ro_size,
87718+ set_page_attributes(mod->module_core_rx,
87719+ mod->module_core_rx + mod->core_size_rx,
87720 set_memory_rw);
87721 }
87722
87723 static void unset_module_init_ro_nx(struct module *mod)
87724 {
87725- set_page_attributes(mod->module_init + mod->init_text_size,
87726- mod->module_init + mod->init_size,
87727+ set_page_attributes(mod->module_init_rw,
87728+ mod->module_init_rw + mod->init_size_rw,
87729 set_memory_x);
87730- set_page_attributes(mod->module_init,
87731- mod->module_init + mod->init_ro_size,
87732+ set_page_attributes(mod->module_init_rx,
87733+ mod->module_init_rx + mod->init_size_rx,
87734 set_memory_rw);
87735 }
87736
87737@@ -1784,14 +1803,14 @@ void set_all_modules_text_rw(void)
87738 list_for_each_entry_rcu(mod, &modules, list) {
87739 if (mod->state == MODULE_STATE_UNFORMED)
87740 continue;
87741- if ((mod->module_core) && (mod->core_text_size)) {
87742- set_page_attributes(mod->module_core,
87743- mod->module_core + mod->core_text_size,
87744+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
87745+ set_page_attributes(mod->module_core_rx,
87746+ mod->module_core_rx + mod->core_size_rx,
87747 set_memory_rw);
87748 }
87749- if ((mod->module_init) && (mod->init_text_size)) {
87750- set_page_attributes(mod->module_init,
87751- mod->module_init + mod->init_text_size,
87752+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
87753+ set_page_attributes(mod->module_init_rx,
87754+ mod->module_init_rx + mod->init_size_rx,
87755 set_memory_rw);
87756 }
87757 }
87758@@ -1807,14 +1826,14 @@ void set_all_modules_text_ro(void)
87759 list_for_each_entry_rcu(mod, &modules, list) {
87760 if (mod->state == MODULE_STATE_UNFORMED)
87761 continue;
87762- if ((mod->module_core) && (mod->core_text_size)) {
87763- set_page_attributes(mod->module_core,
87764- mod->module_core + mod->core_text_size,
87765+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
87766+ set_page_attributes(mod->module_core_rx,
87767+ mod->module_core_rx + mod->core_size_rx,
87768 set_memory_ro);
87769 }
87770- if ((mod->module_init) && (mod->init_text_size)) {
87771- set_page_attributes(mod->module_init,
87772- mod->module_init + mod->init_text_size,
87773+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
87774+ set_page_attributes(mod->module_init_rx,
87775+ mod->module_init_rx + mod->init_size_rx,
87776 set_memory_ro);
87777 }
87778 }
87779@@ -1865,16 +1884,19 @@ static void free_module(struct module *mod)
87780
87781 /* This may be NULL, but that's OK */
87782 unset_module_init_ro_nx(mod);
87783- module_free(mod, mod->module_init);
87784+ module_free(mod, mod->module_init_rw);
87785+ module_free_exec(mod, mod->module_init_rx);
87786 kfree(mod->args);
87787 percpu_modfree(mod);
87788
87789 /* Free lock-classes: */
87790- lockdep_free_key_range(mod->module_core, mod->core_size);
87791+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
87792+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
87793
87794 /* Finally, free the core (containing the module structure) */
87795 unset_module_core_ro_nx(mod);
87796- module_free(mod, mod->module_core);
87797+ module_free_exec(mod, mod->module_core_rx);
87798+ module_free(mod, mod->module_core_rw);
87799
87800 #ifdef CONFIG_MPU
87801 update_protections(current->mm);
87802@@ -1943,9 +1965,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
87803 int ret = 0;
87804 const struct kernel_symbol *ksym;
87805
87806+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87807+ int is_fs_load = 0;
87808+ int register_filesystem_found = 0;
87809+ char *p;
87810+
87811+ p = strstr(mod->args, "grsec_modharden_fs");
87812+ if (p) {
87813+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
87814+ /* copy \0 as well */
87815+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
87816+ is_fs_load = 1;
87817+ }
87818+#endif
87819+
87820 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
87821 const char *name = info->strtab + sym[i].st_name;
87822
87823+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87824+ /* it's a real shame this will never get ripped and copied
87825+ upstream! ;(
87826+ */
87827+ if (is_fs_load && !strcmp(name, "register_filesystem"))
87828+ register_filesystem_found = 1;
87829+#endif
87830+
87831 switch (sym[i].st_shndx) {
87832 case SHN_COMMON:
87833 /* We compiled with -fno-common. These are not
87834@@ -1966,7 +2010,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
87835 ksym = resolve_symbol_wait(mod, info, name);
87836 /* Ok if resolved. */
87837 if (ksym && !IS_ERR(ksym)) {
87838+ pax_open_kernel();
87839 sym[i].st_value = ksym->value;
87840+ pax_close_kernel();
87841 break;
87842 }
87843
87844@@ -1985,11 +2031,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
87845 secbase = (unsigned long)mod_percpu(mod);
87846 else
87847 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
87848+ pax_open_kernel();
87849 sym[i].st_value += secbase;
87850+ pax_close_kernel();
87851 break;
87852 }
87853 }
87854
87855+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87856+ if (is_fs_load && !register_filesystem_found) {
87857+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
87858+ ret = -EPERM;
87859+ }
87860+#endif
87861+
87862 return ret;
87863 }
87864
87865@@ -2073,22 +2128,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
87866 || s->sh_entsize != ~0UL
87867 || strstarts(sname, ".init"))
87868 continue;
87869- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
87870+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
87871+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
87872+ else
87873+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
87874 pr_debug("\t%s\n", sname);
87875 }
87876- switch (m) {
87877- case 0: /* executable */
87878- mod->core_size = debug_align(mod->core_size);
87879- mod->core_text_size = mod->core_size;
87880- break;
87881- case 1: /* RO: text and ro-data */
87882- mod->core_size = debug_align(mod->core_size);
87883- mod->core_ro_size = mod->core_size;
87884- break;
87885- case 3: /* whole core */
87886- mod->core_size = debug_align(mod->core_size);
87887- break;
87888- }
87889 }
87890
87891 pr_debug("Init section allocation order:\n");
87892@@ -2102,23 +2147,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
87893 || s->sh_entsize != ~0UL
87894 || !strstarts(sname, ".init"))
87895 continue;
87896- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
87897- | INIT_OFFSET_MASK);
87898+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
87899+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
87900+ else
87901+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
87902+ s->sh_entsize |= INIT_OFFSET_MASK;
87903 pr_debug("\t%s\n", sname);
87904 }
87905- switch (m) {
87906- case 0: /* executable */
87907- mod->init_size = debug_align(mod->init_size);
87908- mod->init_text_size = mod->init_size;
87909- break;
87910- case 1: /* RO: text and ro-data */
87911- mod->init_size = debug_align(mod->init_size);
87912- mod->init_ro_size = mod->init_size;
87913- break;
87914- case 3: /* whole init */
87915- mod->init_size = debug_align(mod->init_size);
87916- break;
87917- }
87918 }
87919 }
87920
87921@@ -2291,7 +2326,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
87922
87923 /* Put symbol section at end of init part of module. */
87924 symsect->sh_flags |= SHF_ALLOC;
87925- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
87926+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
87927 info->index.sym) | INIT_OFFSET_MASK;
87928 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
87929
87930@@ -2308,13 +2343,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
87931 }
87932
87933 /* Append room for core symbols at end of core part. */
87934- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
87935- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
87936- mod->core_size += strtab_size;
87937+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
87938+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
87939+ mod->core_size_rx += strtab_size;
87940
87941 /* Put string table section at end of init part of module. */
87942 strsect->sh_flags |= SHF_ALLOC;
87943- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
87944+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
87945 info->index.str) | INIT_OFFSET_MASK;
87946 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
87947 }
87948@@ -2332,12 +2367,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
87949 /* Make sure we get permanent strtab: don't use info->strtab. */
87950 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
87951
87952+ pax_open_kernel();
87953+
87954 /* Set types up while we still have access to sections. */
87955 for (i = 0; i < mod->num_symtab; i++)
87956 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
87957
87958- mod->core_symtab = dst = mod->module_core + info->symoffs;
87959- mod->core_strtab = s = mod->module_core + info->stroffs;
87960+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
87961+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
87962 src = mod->symtab;
87963 for (ndst = i = 0; i < mod->num_symtab; i++) {
87964 if (i == 0 ||
87965@@ -2349,6 +2386,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
87966 }
87967 }
87968 mod->core_num_syms = ndst;
87969+
87970+ pax_close_kernel();
87971 }
87972 #else
87973 static inline void layout_symtab(struct module *mod, struct load_info *info)
87974@@ -2382,17 +2421,33 @@ void * __weak module_alloc(unsigned long size)
87975 return vmalloc_exec(size);
87976 }
87977
87978-static void *module_alloc_update_bounds(unsigned long size)
87979+static void *module_alloc_update_bounds_rw(unsigned long size)
87980 {
87981 void *ret = module_alloc(size);
87982
87983 if (ret) {
87984 mutex_lock(&module_mutex);
87985 /* Update module bounds. */
87986- if ((unsigned long)ret < module_addr_min)
87987- module_addr_min = (unsigned long)ret;
87988- if ((unsigned long)ret + size > module_addr_max)
87989- module_addr_max = (unsigned long)ret + size;
87990+ if ((unsigned long)ret < module_addr_min_rw)
87991+ module_addr_min_rw = (unsigned long)ret;
87992+ if ((unsigned long)ret + size > module_addr_max_rw)
87993+ module_addr_max_rw = (unsigned long)ret + size;
87994+ mutex_unlock(&module_mutex);
87995+ }
87996+ return ret;
87997+}
87998+
87999+static void *module_alloc_update_bounds_rx(unsigned long size)
88000+{
88001+ void *ret = module_alloc_exec(size);
88002+
88003+ if (ret) {
88004+ mutex_lock(&module_mutex);
88005+ /* Update module bounds. */
88006+ if ((unsigned long)ret < module_addr_min_rx)
88007+ module_addr_min_rx = (unsigned long)ret;
88008+ if ((unsigned long)ret + size > module_addr_max_rx)
88009+ module_addr_max_rx = (unsigned long)ret + size;
88010 mutex_unlock(&module_mutex);
88011 }
88012 return ret;
88013@@ -2649,7 +2704,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
88014 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
88015
88016 if (info->index.sym == 0) {
88017+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
88018+ /*
88019+ * avoid potentially printing jibberish on attempted load
88020+ * of a module randomized with a different seed
88021+ */
88022+ pr_warn("module has no symbols (stripped?)\n");
88023+#else
88024 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
88025+#endif
88026 return ERR_PTR(-ENOEXEC);
88027 }
88028
88029@@ -2665,8 +2728,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
88030 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
88031 {
88032 const char *modmagic = get_modinfo(info, "vermagic");
88033+ const char *license = get_modinfo(info, "license");
88034 int err;
88035
88036+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
88037+ if (!license || !license_is_gpl_compatible(license))
88038+ return -ENOEXEC;
88039+#endif
88040+
88041 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
88042 modmagic = NULL;
88043
88044@@ -2691,7 +2760,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
88045 }
88046
88047 /* Set up license info based on the info section */
88048- set_license(mod, get_modinfo(info, "license"));
88049+ set_license(mod, license);
88050
88051 return 0;
88052 }
88053@@ -2785,7 +2854,7 @@ static int move_module(struct module *mod, struct load_info *info)
88054 void *ptr;
88055
88056 /* Do the allocs. */
88057- ptr = module_alloc_update_bounds(mod->core_size);
88058+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
88059 /*
88060 * The pointer to this block is stored in the module structure
88061 * which is inside the block. Just mark it as not being a
88062@@ -2795,11 +2864,11 @@ static int move_module(struct module *mod, struct load_info *info)
88063 if (!ptr)
88064 return -ENOMEM;
88065
88066- memset(ptr, 0, mod->core_size);
88067- mod->module_core = ptr;
88068+ memset(ptr, 0, mod->core_size_rw);
88069+ mod->module_core_rw = ptr;
88070
88071- if (mod->init_size) {
88072- ptr = module_alloc_update_bounds(mod->init_size);
88073+ if (mod->init_size_rw) {
88074+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
88075 /*
88076 * The pointer to this block is stored in the module structure
88077 * which is inside the block. This block doesn't need to be
88078@@ -2808,13 +2877,45 @@ static int move_module(struct module *mod, struct load_info *info)
88079 */
88080 kmemleak_ignore(ptr);
88081 if (!ptr) {
88082- module_free(mod, mod->module_core);
88083+ module_free(mod, mod->module_core_rw);
88084 return -ENOMEM;
88085 }
88086- memset(ptr, 0, mod->init_size);
88087- mod->module_init = ptr;
88088+ memset(ptr, 0, mod->init_size_rw);
88089+ mod->module_init_rw = ptr;
88090 } else
88091- mod->module_init = NULL;
88092+ mod->module_init_rw = NULL;
88093+
88094+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
88095+ kmemleak_not_leak(ptr);
88096+ if (!ptr) {
88097+ if (mod->module_init_rw)
88098+ module_free(mod, mod->module_init_rw);
88099+ module_free(mod, mod->module_core_rw);
88100+ return -ENOMEM;
88101+ }
88102+
88103+ pax_open_kernel();
88104+ memset(ptr, 0, mod->core_size_rx);
88105+ pax_close_kernel();
88106+ mod->module_core_rx = ptr;
88107+
88108+ if (mod->init_size_rx) {
88109+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
88110+ kmemleak_ignore(ptr);
88111+ if (!ptr && mod->init_size_rx) {
88112+ module_free_exec(mod, mod->module_core_rx);
88113+ if (mod->module_init_rw)
88114+ module_free(mod, mod->module_init_rw);
88115+ module_free(mod, mod->module_core_rw);
88116+ return -ENOMEM;
88117+ }
88118+
88119+ pax_open_kernel();
88120+ memset(ptr, 0, mod->init_size_rx);
88121+ pax_close_kernel();
88122+ mod->module_init_rx = ptr;
88123+ } else
88124+ mod->module_init_rx = NULL;
88125
88126 /* Transfer each section which specifies SHF_ALLOC */
88127 pr_debug("final section addresses:\n");
88128@@ -2825,16 +2926,45 @@ static int move_module(struct module *mod, struct load_info *info)
88129 if (!(shdr->sh_flags & SHF_ALLOC))
88130 continue;
88131
88132- if (shdr->sh_entsize & INIT_OFFSET_MASK)
88133- dest = mod->module_init
88134- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
88135- else
88136- dest = mod->module_core + shdr->sh_entsize;
88137+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
88138+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
88139+ dest = mod->module_init_rw
88140+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
88141+ else
88142+ dest = mod->module_init_rx
88143+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
88144+ } else {
88145+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
88146+ dest = mod->module_core_rw + shdr->sh_entsize;
88147+ else
88148+ dest = mod->module_core_rx + shdr->sh_entsize;
88149+ }
88150+
88151+ if (shdr->sh_type != SHT_NOBITS) {
88152+
88153+#ifdef CONFIG_PAX_KERNEXEC
88154+#ifdef CONFIG_X86_64
88155+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
88156+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
88157+#endif
88158+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
88159+ pax_open_kernel();
88160+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
88161+ pax_close_kernel();
88162+ } else
88163+#endif
88164
88165- if (shdr->sh_type != SHT_NOBITS)
88166 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
88167+ }
88168 /* Update sh_addr to point to copy in image. */
88169- shdr->sh_addr = (unsigned long)dest;
88170+
88171+#ifdef CONFIG_PAX_KERNEXEC
88172+ if (shdr->sh_flags & SHF_EXECINSTR)
88173+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
88174+ else
88175+#endif
88176+
88177+ shdr->sh_addr = (unsigned long)dest;
88178 pr_debug("\t0x%lx %s\n",
88179 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
88180 }
88181@@ -2891,12 +3021,12 @@ static void flush_module_icache(const struct module *mod)
88182 * Do it before processing of module parameters, so the module
88183 * can provide parameter accessor functions of its own.
88184 */
88185- if (mod->module_init)
88186- flush_icache_range((unsigned long)mod->module_init,
88187- (unsigned long)mod->module_init
88188- + mod->init_size);
88189- flush_icache_range((unsigned long)mod->module_core,
88190- (unsigned long)mod->module_core + mod->core_size);
88191+ if (mod->module_init_rx)
88192+ flush_icache_range((unsigned long)mod->module_init_rx,
88193+ (unsigned long)mod->module_init_rx
88194+ + mod->init_size_rx);
88195+ flush_icache_range((unsigned long)mod->module_core_rx,
88196+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
88197
88198 set_fs(old_fs);
88199 }
88200@@ -2953,8 +3083,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
88201 static void module_deallocate(struct module *mod, struct load_info *info)
88202 {
88203 percpu_modfree(mod);
88204- module_free(mod, mod->module_init);
88205- module_free(mod, mod->module_core);
88206+ module_free_exec(mod, mod->module_init_rx);
88207+ module_free_exec(mod, mod->module_core_rx);
88208+ module_free(mod, mod->module_init_rw);
88209+ module_free(mod, mod->module_core_rw);
88210 }
88211
88212 int __weak module_finalize(const Elf_Ehdr *hdr,
88213@@ -2967,7 +3099,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
88214 static int post_relocation(struct module *mod, const struct load_info *info)
88215 {
88216 /* Sort exception table now relocations are done. */
88217+ pax_open_kernel();
88218 sort_extable(mod->extable, mod->extable + mod->num_exentries);
88219+ pax_close_kernel();
88220
88221 /* Copy relocated percpu area over. */
88222 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
88223@@ -3021,16 +3155,16 @@ static int do_init_module(struct module *mod)
88224 MODULE_STATE_COMING, mod);
88225
88226 /* Set RO and NX regions for core */
88227- set_section_ro_nx(mod->module_core,
88228- mod->core_text_size,
88229- mod->core_ro_size,
88230- mod->core_size);
88231+ set_section_ro_nx(mod->module_core_rx,
88232+ mod->core_size_rx,
88233+ mod->core_size_rx,
88234+ mod->core_size_rx);
88235
88236 /* Set RO and NX regions for init */
88237- set_section_ro_nx(mod->module_init,
88238- mod->init_text_size,
88239- mod->init_ro_size,
88240- mod->init_size);
88241+ set_section_ro_nx(mod->module_init_rx,
88242+ mod->init_size_rx,
88243+ mod->init_size_rx,
88244+ mod->init_size_rx);
88245
88246 do_mod_ctors(mod);
88247 /* Start the module */
88248@@ -3091,11 +3225,12 @@ static int do_init_module(struct module *mod)
88249 mod->strtab = mod->core_strtab;
88250 #endif
88251 unset_module_init_ro_nx(mod);
88252- module_free(mod, mod->module_init);
88253- mod->module_init = NULL;
88254- mod->init_size = 0;
88255- mod->init_ro_size = 0;
88256- mod->init_text_size = 0;
88257+ module_free(mod, mod->module_init_rw);
88258+ module_free_exec(mod, mod->module_init_rx);
88259+ mod->module_init_rw = NULL;
88260+ mod->module_init_rx = NULL;
88261+ mod->init_size_rw = 0;
88262+ mod->init_size_rx = 0;
88263 mutex_unlock(&module_mutex);
88264 wake_up_all(&module_wq);
88265
88266@@ -3238,9 +3373,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
88267 if (err)
88268 goto free_unload;
88269
88270+ /* Now copy in args */
88271+ mod->args = strndup_user(uargs, ~0UL >> 1);
88272+ if (IS_ERR(mod->args)) {
88273+ err = PTR_ERR(mod->args);
88274+ goto free_unload;
88275+ }
88276+
88277 /* Set up MODINFO_ATTR fields */
88278 setup_modinfo(mod, info);
88279
88280+#ifdef CONFIG_GRKERNSEC_MODHARDEN
88281+ {
88282+ char *p, *p2;
88283+
88284+ if (strstr(mod->args, "grsec_modharden_netdev")) {
88285+ 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);
88286+ err = -EPERM;
88287+ goto free_modinfo;
88288+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
88289+ p += sizeof("grsec_modharden_normal") - 1;
88290+ p2 = strstr(p, "_");
88291+ if (p2) {
88292+ *p2 = '\0';
88293+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
88294+ *p2 = '_';
88295+ }
88296+ err = -EPERM;
88297+ goto free_modinfo;
88298+ }
88299+ }
88300+#endif
88301+
88302 /* Fix up syms, so that st_value is a pointer to location. */
88303 err = simplify_symbols(mod, info);
88304 if (err < 0)
88305@@ -3256,13 +3420,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
88306
88307 flush_module_icache(mod);
88308
88309- /* Now copy in args */
88310- mod->args = strndup_user(uargs, ~0UL >> 1);
88311- if (IS_ERR(mod->args)) {
88312- err = PTR_ERR(mod->args);
88313- goto free_arch_cleanup;
88314- }
88315-
88316 dynamic_debug_setup(info->debug, info->num_debug);
88317
88318 /* Finally it's fully formed, ready to start executing. */
88319@@ -3297,11 +3454,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
88320 ddebug_cleanup:
88321 dynamic_debug_remove(info->debug);
88322 synchronize_sched();
88323- kfree(mod->args);
88324- free_arch_cleanup:
88325 module_arch_cleanup(mod);
88326 free_modinfo:
88327 free_modinfo(mod);
88328+ kfree(mod->args);
88329 free_unload:
88330 module_unload_free(mod);
88331 unlink_mod:
88332@@ -3384,10 +3540,16 @@ static const char *get_ksymbol(struct module *mod,
88333 unsigned long nextval;
88334
88335 /* At worse, next value is at end of module */
88336- if (within_module_init(addr, mod))
88337- nextval = (unsigned long)mod->module_init+mod->init_text_size;
88338+ if (within_module_init_rx(addr, mod))
88339+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
88340+ else if (within_module_init_rw(addr, mod))
88341+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
88342+ else if (within_module_core_rx(addr, mod))
88343+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
88344+ else if (within_module_core_rw(addr, mod))
88345+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
88346 else
88347- nextval = (unsigned long)mod->module_core+mod->core_text_size;
88348+ return NULL;
88349
88350 /* Scan for closest preceding symbol, and next symbol. (ELF
88351 starts real symbols at 1). */
88352@@ -3638,7 +3800,7 @@ static int m_show(struct seq_file *m, void *p)
88353 return 0;
88354
88355 seq_printf(m, "%s %u",
88356- mod->name, mod->init_size + mod->core_size);
88357+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
88358 print_unload_info(m, mod);
88359
88360 /* Informative for users. */
88361@@ -3647,7 +3809,7 @@ static int m_show(struct seq_file *m, void *p)
88362 mod->state == MODULE_STATE_COMING ? "Loading":
88363 "Live");
88364 /* Used by oprofile and other similar tools. */
88365- seq_printf(m, " 0x%pK", mod->module_core);
88366+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
88367
88368 /* Taints info */
88369 if (mod->taints)
88370@@ -3683,7 +3845,17 @@ static const struct file_operations proc_modules_operations = {
88371
88372 static int __init proc_modules_init(void)
88373 {
88374+#ifndef CONFIG_GRKERNSEC_HIDESYM
88375+#ifdef CONFIG_GRKERNSEC_PROC_USER
88376+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
88377+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
88378+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
88379+#else
88380 proc_create("modules", 0, NULL, &proc_modules_operations);
88381+#endif
88382+#else
88383+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
88384+#endif
88385 return 0;
88386 }
88387 module_init(proc_modules_init);
88388@@ -3744,14 +3916,14 @@ struct module *__module_address(unsigned long addr)
88389 {
88390 struct module *mod;
88391
88392- if (addr < module_addr_min || addr > module_addr_max)
88393+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
88394+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
88395 return NULL;
88396
88397 list_for_each_entry_rcu(mod, &modules, list) {
88398 if (mod->state == MODULE_STATE_UNFORMED)
88399 continue;
88400- if (within_module_core(addr, mod)
88401- || within_module_init(addr, mod))
88402+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
88403 return mod;
88404 }
88405 return NULL;
88406@@ -3786,11 +3958,20 @@ bool is_module_text_address(unsigned long addr)
88407 */
88408 struct module *__module_text_address(unsigned long addr)
88409 {
88410- struct module *mod = __module_address(addr);
88411+ struct module *mod;
88412+
88413+#ifdef CONFIG_X86_32
88414+ addr = ktla_ktva(addr);
88415+#endif
88416+
88417+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
88418+ return NULL;
88419+
88420+ mod = __module_address(addr);
88421+
88422 if (mod) {
88423 /* Make sure it's within the text section. */
88424- if (!within(addr, mod->module_init, mod->init_text_size)
88425- && !within(addr, mod->module_core, mod->core_text_size))
88426+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
88427 mod = NULL;
88428 }
88429 return mod;
88430diff --git a/kernel/notifier.c b/kernel/notifier.c
88431index 2d5cc4c..d9ea600 100644
88432--- a/kernel/notifier.c
88433+++ b/kernel/notifier.c
88434@@ -5,6 +5,7 @@
88435 #include <linux/rcupdate.h>
88436 #include <linux/vmalloc.h>
88437 #include <linux/reboot.h>
88438+#include <linux/mm.h>
88439
88440 /*
88441 * Notifier list for kernel code which wants to be called
88442@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
88443 while ((*nl) != NULL) {
88444 if (n->priority > (*nl)->priority)
88445 break;
88446- nl = &((*nl)->next);
88447+ nl = (struct notifier_block **)&((*nl)->next);
88448 }
88449- n->next = *nl;
88450+ pax_open_kernel();
88451+ *(const void **)&n->next = *nl;
88452 rcu_assign_pointer(*nl, n);
88453+ pax_close_kernel();
88454 return 0;
88455 }
88456
88457@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
88458 return 0;
88459 if (n->priority > (*nl)->priority)
88460 break;
88461- nl = &((*nl)->next);
88462+ nl = (struct notifier_block **)&((*nl)->next);
88463 }
88464- n->next = *nl;
88465+ pax_open_kernel();
88466+ *(const void **)&n->next = *nl;
88467 rcu_assign_pointer(*nl, n);
88468+ pax_close_kernel();
88469 return 0;
88470 }
88471
88472@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
88473 {
88474 while ((*nl) != NULL) {
88475 if ((*nl) == n) {
88476+ pax_open_kernel();
88477 rcu_assign_pointer(*nl, n->next);
88478+ pax_close_kernel();
88479 return 0;
88480 }
88481- nl = &((*nl)->next);
88482+ nl = (struct notifier_block **)&((*nl)->next);
88483 }
88484 return -ENOENT;
88485 }
88486diff --git a/kernel/padata.c b/kernel/padata.c
88487index 161402f..598814c 100644
88488--- a/kernel/padata.c
88489+++ b/kernel/padata.c
88490@@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
88491 * seq_nr mod. number of cpus in use.
88492 */
88493
88494- seq_nr = atomic_inc_return(&pd->seq_nr);
88495+ seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
88496 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
88497
88498 return padata_index_to_cpu(pd, cpu_index);
88499@@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
88500 padata_init_pqueues(pd);
88501 padata_init_squeues(pd);
88502 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
88503- atomic_set(&pd->seq_nr, -1);
88504+ atomic_set_unchecked(&pd->seq_nr, -1);
88505 atomic_set(&pd->reorder_objects, 0);
88506 atomic_set(&pd->refcnt, 0);
88507 pd->pinst = pinst;
88508diff --git a/kernel/panic.c b/kernel/panic.c
88509index 6d63003..486a109 100644
88510--- a/kernel/panic.c
88511+++ b/kernel/panic.c
88512@@ -52,7 +52,7 @@ EXPORT_SYMBOL(panic_blink);
88513 /*
88514 * Stop ourself in panic -- architecture code may override this
88515 */
88516-void __weak panic_smp_self_stop(void)
88517+void __weak __noreturn panic_smp_self_stop(void)
88518 {
88519 while (1)
88520 cpu_relax();
88521@@ -407,7 +407,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
88522 disable_trace_on_warning();
88523
88524 pr_warn("------------[ cut here ]------------\n");
88525- pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
88526+ pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
88527 raw_smp_processor_id(), current->pid, file, line, caller);
88528
88529 if (args)
88530@@ -461,7 +461,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
88531 */
88532 void __stack_chk_fail(void)
88533 {
88534- panic("stack-protector: Kernel stack is corrupted in: %p\n",
88535+ dump_stack();
88536+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
88537 __builtin_return_address(0));
88538 }
88539 EXPORT_SYMBOL(__stack_chk_fail);
88540diff --git a/kernel/pid.c b/kernel/pid.c
88541index 9b9a266..c20ef80 100644
88542--- a/kernel/pid.c
88543+++ b/kernel/pid.c
88544@@ -33,6 +33,7 @@
88545 #include <linux/rculist.h>
88546 #include <linux/bootmem.h>
88547 #include <linux/hash.h>
88548+#include <linux/security.h>
88549 #include <linux/pid_namespace.h>
88550 #include <linux/init_task.h>
88551 #include <linux/syscalls.h>
88552@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
88553
88554 int pid_max = PID_MAX_DEFAULT;
88555
88556-#define RESERVED_PIDS 300
88557+#define RESERVED_PIDS 500
88558
88559 int pid_max_min = RESERVED_PIDS + 1;
88560 int pid_max_max = PID_MAX_LIMIT;
88561@@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
88562 */
88563 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
88564 {
88565+ struct task_struct *task;
88566+
88567 rcu_lockdep_assert(rcu_read_lock_held(),
88568 "find_task_by_pid_ns() needs rcu_read_lock()"
88569 " protection");
88570- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
88571+
88572+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
88573+
88574+ if (gr_pid_is_chrooted(task))
88575+ return NULL;
88576+
88577+ return task;
88578 }
88579
88580 struct task_struct *find_task_by_vpid(pid_t vnr)
88581@@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
88582 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
88583 }
88584
88585+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
88586+{
88587+ rcu_lockdep_assert(rcu_read_lock_held(),
88588+ "find_task_by_pid_ns() needs rcu_read_lock()"
88589+ " protection");
88590+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
88591+}
88592+
88593 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
88594 {
88595 struct pid *pid;
88596diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
88597index db95d8e..a0ca23f 100644
88598--- a/kernel/pid_namespace.c
88599+++ b/kernel/pid_namespace.c
88600@@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
88601 void __user *buffer, size_t *lenp, loff_t *ppos)
88602 {
88603 struct pid_namespace *pid_ns = task_active_pid_ns(current);
88604- struct ctl_table tmp = *table;
88605+ ctl_table_no_const tmp = *table;
88606
88607 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
88608 return -EPERM;
88609diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
88610index 3b89464..5e38379 100644
88611--- a/kernel/posix-cpu-timers.c
88612+++ b/kernel/posix-cpu-timers.c
88613@@ -1464,14 +1464,14 @@ struct k_clock clock_posix_cpu = {
88614
88615 static __init int init_posix_cpu_timers(void)
88616 {
88617- struct k_clock process = {
88618+ static struct k_clock process = {
88619 .clock_getres = process_cpu_clock_getres,
88620 .clock_get = process_cpu_clock_get,
88621 .timer_create = process_cpu_timer_create,
88622 .nsleep = process_cpu_nsleep,
88623 .nsleep_restart = process_cpu_nsleep_restart,
88624 };
88625- struct k_clock thread = {
88626+ static struct k_clock thread = {
88627 .clock_getres = thread_cpu_clock_getres,
88628 .clock_get = thread_cpu_clock_get,
88629 .timer_create = thread_cpu_timer_create,
88630diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
88631index 424c2d4..679242f 100644
88632--- a/kernel/posix-timers.c
88633+++ b/kernel/posix-timers.c
88634@@ -43,6 +43,7 @@
88635 #include <linux/hash.h>
88636 #include <linux/posix-clock.h>
88637 #include <linux/posix-timers.h>
88638+#include <linux/grsecurity.h>
88639 #include <linux/syscalls.h>
88640 #include <linux/wait.h>
88641 #include <linux/workqueue.h>
88642@@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
88643 * which we beg off on and pass to do_sys_settimeofday().
88644 */
88645
88646-static struct k_clock posix_clocks[MAX_CLOCKS];
88647+static struct k_clock *posix_clocks[MAX_CLOCKS];
88648
88649 /*
88650 * These ones are defined below.
88651@@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
88652 */
88653 static __init int init_posix_timers(void)
88654 {
88655- struct k_clock clock_realtime = {
88656+ static struct k_clock clock_realtime = {
88657 .clock_getres = hrtimer_get_res,
88658 .clock_get = posix_clock_realtime_get,
88659 .clock_set = posix_clock_realtime_set,
88660@@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
88661 .timer_get = common_timer_get,
88662 .timer_del = common_timer_del,
88663 };
88664- struct k_clock clock_monotonic = {
88665+ static struct k_clock clock_monotonic = {
88666 .clock_getres = hrtimer_get_res,
88667 .clock_get = posix_ktime_get_ts,
88668 .nsleep = common_nsleep,
88669@@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
88670 .timer_get = common_timer_get,
88671 .timer_del = common_timer_del,
88672 };
88673- struct k_clock clock_monotonic_raw = {
88674+ static struct k_clock clock_monotonic_raw = {
88675 .clock_getres = hrtimer_get_res,
88676 .clock_get = posix_get_monotonic_raw,
88677 };
88678- struct k_clock clock_realtime_coarse = {
88679+ static struct k_clock clock_realtime_coarse = {
88680 .clock_getres = posix_get_coarse_res,
88681 .clock_get = posix_get_realtime_coarse,
88682 };
88683- struct k_clock clock_monotonic_coarse = {
88684+ static struct k_clock clock_monotonic_coarse = {
88685 .clock_getres = posix_get_coarse_res,
88686 .clock_get = posix_get_monotonic_coarse,
88687 };
88688- struct k_clock clock_tai = {
88689+ static struct k_clock clock_tai = {
88690 .clock_getres = hrtimer_get_res,
88691 .clock_get = posix_get_tai,
88692 .nsleep = common_nsleep,
88693@@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
88694 .timer_get = common_timer_get,
88695 .timer_del = common_timer_del,
88696 };
88697- struct k_clock clock_boottime = {
88698+ static struct k_clock clock_boottime = {
88699 .clock_getres = hrtimer_get_res,
88700 .clock_get = posix_get_boottime,
88701 .nsleep = common_nsleep,
88702@@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
88703 return;
88704 }
88705
88706- posix_clocks[clock_id] = *new_clock;
88707+ posix_clocks[clock_id] = new_clock;
88708 }
88709 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
88710
88711@@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
88712 return (id & CLOCKFD_MASK) == CLOCKFD ?
88713 &clock_posix_dynamic : &clock_posix_cpu;
88714
88715- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
88716+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
88717 return NULL;
88718- return &posix_clocks[id];
88719+ return posix_clocks[id];
88720 }
88721
88722 static int common_timer_create(struct k_itimer *new_timer)
88723@@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
88724 struct k_clock *kc = clockid_to_kclock(which_clock);
88725 struct k_itimer *new_timer;
88726 int error, new_timer_id;
88727- sigevent_t event;
88728+ sigevent_t event = { };
88729 int it_id_set = IT_ID_NOT_SET;
88730
88731 if (!kc)
88732@@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
88733 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
88734 return -EFAULT;
88735
88736+ /* only the CLOCK_REALTIME clock can be set, all other clocks
88737+ have their clock_set fptr set to a nosettime dummy function
88738+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
88739+ call common_clock_set, which calls do_sys_settimeofday, which
88740+ we hook
88741+ */
88742+
88743 return kc->clock_set(which_clock, &new_tp);
88744 }
88745
88746diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
88747index 2fac9cc..56fef29 100644
88748--- a/kernel/power/Kconfig
88749+++ b/kernel/power/Kconfig
88750@@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
88751 config HIBERNATION
88752 bool "Hibernation (aka 'suspend to disk')"
88753 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
88754+ depends on !GRKERNSEC_KMEM
88755+ depends on !PAX_MEMORY_SANITIZE
88756 select HIBERNATE_CALLBACKS
88757 select LZO_COMPRESS
88758 select LZO_DECOMPRESS
88759diff --git a/kernel/power/process.c b/kernel/power/process.c
88760index 06ec886..9dba35e 100644
88761--- a/kernel/power/process.c
88762+++ b/kernel/power/process.c
88763@@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
88764 unsigned int elapsed_msecs;
88765 bool wakeup = false;
88766 int sleep_usecs = USEC_PER_MSEC;
88767+ bool timedout = false;
88768
88769 do_gettimeofday(&start);
88770
88771@@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
88772
88773 while (true) {
88774 todo = 0;
88775+ if (time_after(jiffies, end_time))
88776+ timedout = true;
88777 read_lock(&tasklist_lock);
88778 do_each_thread(g, p) {
88779 if (p == current || !freeze_task(p))
88780 continue;
88781
88782- if (!freezer_should_skip(p))
88783+ if (!freezer_should_skip(p)) {
88784 todo++;
88785+ if (timedout) {
88786+ printk(KERN_ERR "Task refusing to freeze:\n");
88787+ sched_show_task(p);
88788+ }
88789+ }
88790 } while_each_thread(g, p);
88791 read_unlock(&tasklist_lock);
88792
88793@@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
88794 todo += wq_busy;
88795 }
88796
88797- if (!todo || time_after(jiffies, end_time))
88798+ if (!todo || timedout)
88799 break;
88800
88801 if (pm_wakeup_pending()) {
88802diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
88803index 4dae9cb..039ffbb 100644
88804--- a/kernel/printk/printk.c
88805+++ b/kernel/printk/printk.c
88806@@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
88807 if (from_file && type != SYSLOG_ACTION_OPEN)
88808 return 0;
88809
88810+#ifdef CONFIG_GRKERNSEC_DMESG
88811+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
88812+ return -EPERM;
88813+#endif
88814+
88815 if (syslog_action_restricted(type)) {
88816 if (capable(CAP_SYSLOG))
88817 return 0;
88818diff --git a/kernel/profile.c b/kernel/profile.c
88819index ebdd9c1..612ee05 100644
88820--- a/kernel/profile.c
88821+++ b/kernel/profile.c
88822@@ -37,7 +37,7 @@ struct profile_hit {
88823 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
88824 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
88825
88826-static atomic_t *prof_buffer;
88827+static atomic_unchecked_t *prof_buffer;
88828 static unsigned long prof_len, prof_shift;
88829
88830 int prof_on __read_mostly;
88831@@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
88832 hits[i].pc = 0;
88833 continue;
88834 }
88835- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
88836+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
88837 hits[i].hits = hits[i].pc = 0;
88838 }
88839 }
88840@@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
88841 * Add the current hit(s) and flush the write-queue out
88842 * to the global buffer:
88843 */
88844- atomic_add(nr_hits, &prof_buffer[pc]);
88845+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
88846 for (i = 0; i < NR_PROFILE_HIT; ++i) {
88847- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
88848+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
88849 hits[i].pc = hits[i].hits = 0;
88850 }
88851 out:
88852@@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
88853 {
88854 unsigned long pc;
88855 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
88856- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
88857+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
88858 }
88859 #endif /* !CONFIG_SMP */
88860
88861@@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
88862 return -EFAULT;
88863 buf++; p++; count--; read++;
88864 }
88865- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
88866+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
88867 if (copy_to_user(buf, (void *)pnt, count))
88868 return -EFAULT;
88869 read += count;
88870@@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
88871 }
88872 #endif
88873 profile_discard_flip_buffers();
88874- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
88875+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
88876 return count;
88877 }
88878
88879diff --git a/kernel/ptrace.c b/kernel/ptrace.c
88880index 1f4bcb3..99cf7ab 100644
88881--- a/kernel/ptrace.c
88882+++ b/kernel/ptrace.c
88883@@ -327,7 +327,7 @@ static int ptrace_attach(struct task_struct *task, long request,
88884 if (seize)
88885 flags |= PT_SEIZED;
88886 rcu_read_lock();
88887- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
88888+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
88889 flags |= PT_PTRACE_CAP;
88890 rcu_read_unlock();
88891 task->ptrace = flags;
88892@@ -538,7 +538,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
88893 break;
88894 return -EIO;
88895 }
88896- if (copy_to_user(dst, buf, retval))
88897+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
88898 return -EFAULT;
88899 copied += retval;
88900 src += retval;
88901@@ -806,7 +806,7 @@ int ptrace_request(struct task_struct *child, long request,
88902 bool seized = child->ptrace & PT_SEIZED;
88903 int ret = -EIO;
88904 siginfo_t siginfo, *si;
88905- void __user *datavp = (void __user *) data;
88906+ void __user *datavp = (__force void __user *) data;
88907 unsigned long __user *datalp = datavp;
88908 unsigned long flags;
88909
88910@@ -1052,14 +1052,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
88911 goto out;
88912 }
88913
88914+ if (gr_handle_ptrace(child, request)) {
88915+ ret = -EPERM;
88916+ goto out_put_task_struct;
88917+ }
88918+
88919 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
88920 ret = ptrace_attach(child, request, addr, data);
88921 /*
88922 * Some architectures need to do book-keeping after
88923 * a ptrace attach.
88924 */
88925- if (!ret)
88926+ if (!ret) {
88927 arch_ptrace_attach(child);
88928+ gr_audit_ptrace(child);
88929+ }
88930 goto out_put_task_struct;
88931 }
88932
88933@@ -1087,7 +1094,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
88934 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
88935 if (copied != sizeof(tmp))
88936 return -EIO;
88937- return put_user(tmp, (unsigned long __user *)data);
88938+ return put_user(tmp, (__force unsigned long __user *)data);
88939 }
88940
88941 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
88942@@ -1181,7 +1188,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
88943 }
88944
88945 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
88946- compat_long_t addr, compat_long_t data)
88947+ compat_ulong_t addr, compat_ulong_t data)
88948 {
88949 struct task_struct *child;
88950 long ret;
88951@@ -1197,14 +1204,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
88952 goto out;
88953 }
88954
88955+ if (gr_handle_ptrace(child, request)) {
88956+ ret = -EPERM;
88957+ goto out_put_task_struct;
88958+ }
88959+
88960 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
88961 ret = ptrace_attach(child, request, addr, data);
88962 /*
88963 * Some architectures need to do book-keeping after
88964 * a ptrace attach.
88965 */
88966- if (!ret)
88967+ if (!ret) {
88968 arch_ptrace_attach(child);
88969+ gr_audit_ptrace(child);
88970+ }
88971 goto out_put_task_struct;
88972 }
88973
88974diff --git a/kernel/rcu/srcu.c b/kernel/rcu/srcu.c
88975index 3318d82..1a5b2d1 100644
88976--- a/kernel/rcu/srcu.c
88977+++ b/kernel/rcu/srcu.c
88978@@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
88979
88980 idx = ACCESS_ONCE(sp->completed) & 0x1;
88981 preempt_disable();
88982- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
88983+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
88984 smp_mb(); /* B */ /* Avoid leaking the critical section. */
88985- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
88986+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
88987 preempt_enable();
88988 return idx;
88989 }
88990diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
88991index 1254f31..16258dc 100644
88992--- a/kernel/rcu/tiny.c
88993+++ b/kernel/rcu/tiny.c
88994@@ -46,7 +46,7 @@
88995 /* Forward declarations for tiny_plugin.h. */
88996 struct rcu_ctrlblk;
88997 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
88998-static void rcu_process_callbacks(struct softirq_action *unused);
88999+static void rcu_process_callbacks(void);
89000 static void __call_rcu(struct rcu_head *head,
89001 void (*func)(struct rcu_head *rcu),
89002 struct rcu_ctrlblk *rcp);
89003@@ -312,7 +312,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
89004 false));
89005 }
89006
89007-static void rcu_process_callbacks(struct softirq_action *unused)
89008+static __latent_entropy void rcu_process_callbacks(void)
89009 {
89010 __rcu_process_callbacks(&rcu_sched_ctrlblk);
89011 __rcu_process_callbacks(&rcu_bh_ctrlblk);
89012diff --git a/kernel/rcu/torture.c b/kernel/rcu/torture.c
89013index 732f8ae..42c1919 100644
89014--- a/kernel/rcu/torture.c
89015+++ b/kernel/rcu/torture.c
89016@@ -174,12 +174,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
89017 { 0 };
89018 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
89019 { 0 };
89020-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
89021-static atomic_t n_rcu_torture_alloc;
89022-static atomic_t n_rcu_torture_alloc_fail;
89023-static atomic_t n_rcu_torture_free;
89024-static atomic_t n_rcu_torture_mberror;
89025-static atomic_t n_rcu_torture_error;
89026+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
89027+static atomic_unchecked_t n_rcu_torture_alloc;
89028+static atomic_unchecked_t n_rcu_torture_alloc_fail;
89029+static atomic_unchecked_t n_rcu_torture_free;
89030+static atomic_unchecked_t n_rcu_torture_mberror;
89031+static atomic_unchecked_t n_rcu_torture_error;
89032 static long n_rcu_torture_barrier_error;
89033 static long n_rcu_torture_boost_ktrerror;
89034 static long n_rcu_torture_boost_rterror;
89035@@ -297,11 +297,11 @@ rcu_torture_alloc(void)
89036
89037 spin_lock_bh(&rcu_torture_lock);
89038 if (list_empty(&rcu_torture_freelist)) {
89039- atomic_inc(&n_rcu_torture_alloc_fail);
89040+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
89041 spin_unlock_bh(&rcu_torture_lock);
89042 return NULL;
89043 }
89044- atomic_inc(&n_rcu_torture_alloc);
89045+ atomic_inc_unchecked(&n_rcu_torture_alloc);
89046 p = rcu_torture_freelist.next;
89047 list_del_init(p);
89048 spin_unlock_bh(&rcu_torture_lock);
89049@@ -314,7 +314,7 @@ rcu_torture_alloc(void)
89050 static void
89051 rcu_torture_free(struct rcu_torture *p)
89052 {
89053- atomic_inc(&n_rcu_torture_free);
89054+ atomic_inc_unchecked(&n_rcu_torture_free);
89055 spin_lock_bh(&rcu_torture_lock);
89056 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
89057 spin_unlock_bh(&rcu_torture_lock);
89058@@ -435,7 +435,7 @@ rcu_torture_cb(struct rcu_head *p)
89059 i = rp->rtort_pipe_count;
89060 if (i > RCU_TORTURE_PIPE_LEN)
89061 i = RCU_TORTURE_PIPE_LEN;
89062- atomic_inc(&rcu_torture_wcount[i]);
89063+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
89064 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
89065 rp->rtort_mbtest = 0;
89066 rcu_torture_free(rp);
89067@@ -823,7 +823,7 @@ rcu_torture_writer(void *arg)
89068 i = old_rp->rtort_pipe_count;
89069 if (i > RCU_TORTURE_PIPE_LEN)
89070 i = RCU_TORTURE_PIPE_LEN;
89071- atomic_inc(&rcu_torture_wcount[i]);
89072+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
89073 old_rp->rtort_pipe_count++;
89074 if (gp_normal == gp_exp)
89075 exp = !!(rcu_random(&rand) & 0x80);
89076@@ -841,7 +841,7 @@ rcu_torture_writer(void *arg)
89077 i = rp->rtort_pipe_count;
89078 if (i > RCU_TORTURE_PIPE_LEN)
89079 i = RCU_TORTURE_PIPE_LEN;
89080- atomic_inc(&rcu_torture_wcount[i]);
89081+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
89082 if (++rp->rtort_pipe_count >=
89083 RCU_TORTURE_PIPE_LEN) {
89084 rp->rtort_mbtest = 0;
89085@@ -940,7 +940,7 @@ static void rcu_torture_timer(unsigned long unused)
89086 return;
89087 }
89088 if (p->rtort_mbtest == 0)
89089- atomic_inc(&n_rcu_torture_mberror);
89090+ atomic_inc_unchecked(&n_rcu_torture_mberror);
89091 spin_lock(&rand_lock);
89092 cur_ops->read_delay(&rand);
89093 n_rcu_torture_timers++;
89094@@ -1010,7 +1010,7 @@ rcu_torture_reader(void *arg)
89095 continue;
89096 }
89097 if (p->rtort_mbtest == 0)
89098- atomic_inc(&n_rcu_torture_mberror);
89099+ atomic_inc_unchecked(&n_rcu_torture_mberror);
89100 cur_ops->read_delay(&rand);
89101 preempt_disable();
89102 pipe_count = p->rtort_pipe_count;
89103@@ -1068,15 +1068,15 @@ rcu_torture_printk(char *page)
89104 }
89105 page += sprintf(page, "%s%s ", torture_type, TORTURE_FLAG);
89106 page += sprintf(page,
89107- "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
89108+ "rtc: %pP ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
89109 rcu_torture_current,
89110 rcu_torture_current_version,
89111 list_empty(&rcu_torture_freelist),
89112- atomic_read(&n_rcu_torture_alloc),
89113- atomic_read(&n_rcu_torture_alloc_fail),
89114- atomic_read(&n_rcu_torture_free));
89115+ atomic_read_unchecked(&n_rcu_torture_alloc),
89116+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
89117+ atomic_read_unchecked(&n_rcu_torture_free));
89118 page += sprintf(page, "rtmbe: %d rtbke: %ld rtbre: %ld ",
89119- atomic_read(&n_rcu_torture_mberror),
89120+ atomic_read_unchecked(&n_rcu_torture_mberror),
89121 n_rcu_torture_boost_ktrerror,
89122 n_rcu_torture_boost_rterror);
89123 page += sprintf(page, "rtbf: %ld rtb: %ld nt: %ld ",
89124@@ -1095,14 +1095,14 @@ rcu_torture_printk(char *page)
89125 n_barrier_attempts,
89126 n_rcu_torture_barrier_error);
89127 page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG);
89128- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
89129+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
89130 n_rcu_torture_barrier_error != 0 ||
89131 n_rcu_torture_boost_ktrerror != 0 ||
89132 n_rcu_torture_boost_rterror != 0 ||
89133 n_rcu_torture_boost_failure != 0 ||
89134 i > 1) {
89135 page += sprintf(page, "!!! ");
89136- atomic_inc(&n_rcu_torture_error);
89137+ atomic_inc_unchecked(&n_rcu_torture_error);
89138 WARN_ON_ONCE(1);
89139 }
89140 page += sprintf(page, "Reader Pipe: ");
89141@@ -1116,7 +1116,7 @@ rcu_torture_printk(char *page)
89142 page += sprintf(page, "Free-Block Circulation: ");
89143 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
89144 page += sprintf(page, " %d",
89145- atomic_read(&rcu_torture_wcount[i]));
89146+ atomic_read_unchecked(&rcu_torture_wcount[i]));
89147 }
89148 page += sprintf(page, "\n");
89149 if (cur_ops->stats)
89150@@ -1839,7 +1839,7 @@ rcu_torture_cleanup(void)
89151
89152 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
89153
89154- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
89155+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
89156 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
89157 else if (n_online_successes != n_online_attempts ||
89158 n_offline_successes != n_offline_attempts)
89159@@ -1961,18 +1961,18 @@ rcu_torture_init(void)
89160
89161 rcu_torture_current = NULL;
89162 rcu_torture_current_version = 0;
89163- atomic_set(&n_rcu_torture_alloc, 0);
89164- atomic_set(&n_rcu_torture_alloc_fail, 0);
89165- atomic_set(&n_rcu_torture_free, 0);
89166- atomic_set(&n_rcu_torture_mberror, 0);
89167- atomic_set(&n_rcu_torture_error, 0);
89168+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
89169+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
89170+ atomic_set_unchecked(&n_rcu_torture_free, 0);
89171+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
89172+ atomic_set_unchecked(&n_rcu_torture_error, 0);
89173 n_rcu_torture_barrier_error = 0;
89174 n_rcu_torture_boost_ktrerror = 0;
89175 n_rcu_torture_boost_rterror = 0;
89176 n_rcu_torture_boost_failure = 0;
89177 n_rcu_torture_boosts = 0;
89178 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
89179- atomic_set(&rcu_torture_wcount[i], 0);
89180+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
89181 for_each_possible_cpu(cpu) {
89182 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
89183 per_cpu(rcu_torture_count, cpu)[i] = 0;
89184diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
89185index b3d116c..ebf6598 100644
89186--- a/kernel/rcu/tree.c
89187+++ b/kernel/rcu/tree.c
89188@@ -390,9 +390,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
89189 rcu_prepare_for_idle(smp_processor_id());
89190 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
89191 smp_mb__before_atomic_inc(); /* See above. */
89192- atomic_inc(&rdtp->dynticks);
89193+ atomic_inc_unchecked(&rdtp->dynticks);
89194 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
89195- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
89196+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
89197
89198 /*
89199 * It is illegal to enter an extended quiescent state while
89200@@ -510,10 +510,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
89201 int user)
89202 {
89203 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
89204- atomic_inc(&rdtp->dynticks);
89205+ atomic_inc_unchecked(&rdtp->dynticks);
89206 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
89207 smp_mb__after_atomic_inc(); /* See above. */
89208- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
89209+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
89210 rcu_cleanup_after_idle(smp_processor_id());
89211 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
89212 if (!user && !is_idle_task(current)) {
89213@@ -634,14 +634,14 @@ void rcu_nmi_enter(void)
89214 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
89215
89216 if (rdtp->dynticks_nmi_nesting == 0 &&
89217- (atomic_read(&rdtp->dynticks) & 0x1))
89218+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
89219 return;
89220 rdtp->dynticks_nmi_nesting++;
89221 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
89222- atomic_inc(&rdtp->dynticks);
89223+ atomic_inc_unchecked(&rdtp->dynticks);
89224 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
89225 smp_mb__after_atomic_inc(); /* See above. */
89226- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
89227+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
89228 }
89229
89230 /**
89231@@ -660,9 +660,9 @@ void rcu_nmi_exit(void)
89232 return;
89233 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
89234 smp_mb__before_atomic_inc(); /* See above. */
89235- atomic_inc(&rdtp->dynticks);
89236+ atomic_inc_unchecked(&rdtp->dynticks);
89237 smp_mb__after_atomic_inc(); /* Force delay to next write. */
89238- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
89239+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
89240 }
89241
89242 /**
89243@@ -675,7 +675,7 @@ void rcu_nmi_exit(void)
89244 */
89245 bool notrace __rcu_is_watching(void)
89246 {
89247- return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
89248+ return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
89249 }
89250
89251 /**
89252@@ -758,7 +758,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
89253 static int dyntick_save_progress_counter(struct rcu_data *rdp,
89254 bool *isidle, unsigned long *maxj)
89255 {
89256- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
89257+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
89258 rcu_sysidle_check_cpu(rdp, isidle, maxj);
89259 return (rdp->dynticks_snap & 0x1) == 0;
89260 }
89261@@ -781,7 +781,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
89262 unsigned int curr;
89263 unsigned int snap;
89264
89265- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
89266+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
89267 snap = (unsigned int)rdp->dynticks_snap;
89268
89269 /*
89270@@ -1450,9 +1450,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
89271 rdp = this_cpu_ptr(rsp->rda);
89272 rcu_preempt_check_blocked_tasks(rnp);
89273 rnp->qsmask = rnp->qsmaskinit;
89274- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
89275+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
89276 WARN_ON_ONCE(rnp->completed != rsp->completed);
89277- ACCESS_ONCE(rnp->completed) = rsp->completed;
89278+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
89279 if (rnp == rdp->mynode)
89280 __note_gp_changes(rsp, rnp, rdp);
89281 rcu_preempt_boost_start_gp(rnp);
89282@@ -1546,7 +1546,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
89283 rcu_for_each_node_breadth_first(rsp, rnp) {
89284 raw_spin_lock_irq(&rnp->lock);
89285 smp_mb__after_unlock_lock();
89286- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
89287+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
89288 rdp = this_cpu_ptr(rsp->rda);
89289 if (rnp == rdp->mynode)
89290 __note_gp_changes(rsp, rnp, rdp);
89291@@ -1912,7 +1912,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
89292 rsp->qlen += rdp->qlen;
89293 rdp->n_cbs_orphaned += rdp->qlen;
89294 rdp->qlen_lazy = 0;
89295- ACCESS_ONCE(rdp->qlen) = 0;
89296+ ACCESS_ONCE_RW(rdp->qlen) = 0;
89297 }
89298
89299 /*
89300@@ -2159,7 +2159,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
89301 }
89302 smp_mb(); /* List handling before counting for rcu_barrier(). */
89303 rdp->qlen_lazy -= count_lazy;
89304- ACCESS_ONCE(rdp->qlen) -= count;
89305+ ACCESS_ONCE_RW(rdp->qlen) -= count;
89306 rdp->n_cbs_invoked += count;
89307
89308 /* Reinstate batch limit if we have worked down the excess. */
89309@@ -2362,7 +2362,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
89310 /*
89311 * Do RCU core processing for the current CPU.
89312 */
89313-static void rcu_process_callbacks(struct softirq_action *unused)
89314+static void rcu_process_callbacks(void)
89315 {
89316 struct rcu_state *rsp;
89317
89318@@ -2470,7 +2470,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
89319 WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
89320 if (debug_rcu_head_queue(head)) {
89321 /* Probable double call_rcu(), so leak the callback. */
89322- ACCESS_ONCE(head->func) = rcu_leak_callback;
89323+ ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
89324 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
89325 return;
89326 }
89327@@ -2498,7 +2498,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
89328 local_irq_restore(flags);
89329 return;
89330 }
89331- ACCESS_ONCE(rdp->qlen)++;
89332+ ACCESS_ONCE_RW(rdp->qlen)++;
89333 if (lazy)
89334 rdp->qlen_lazy++;
89335 else
89336@@ -2707,11 +2707,11 @@ void synchronize_sched_expedited(void)
89337 * counter wrap on a 32-bit system. Quite a few more CPUs would of
89338 * course be required on a 64-bit system.
89339 */
89340- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
89341+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
89342 (ulong)atomic_long_read(&rsp->expedited_done) +
89343 ULONG_MAX / 8)) {
89344 synchronize_sched();
89345- atomic_long_inc(&rsp->expedited_wrap);
89346+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
89347 return;
89348 }
89349
89350@@ -2719,7 +2719,7 @@ void synchronize_sched_expedited(void)
89351 * Take a ticket. Note that atomic_inc_return() implies a
89352 * full memory barrier.
89353 */
89354- snap = atomic_long_inc_return(&rsp->expedited_start);
89355+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
89356 firstsnap = snap;
89357 get_online_cpus();
89358 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
89359@@ -2732,14 +2732,14 @@ void synchronize_sched_expedited(void)
89360 synchronize_sched_expedited_cpu_stop,
89361 NULL) == -EAGAIN) {
89362 put_online_cpus();
89363- atomic_long_inc(&rsp->expedited_tryfail);
89364+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
89365
89366 /* Check to see if someone else did our work for us. */
89367 s = atomic_long_read(&rsp->expedited_done);
89368 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
89369 /* ensure test happens before caller kfree */
89370 smp_mb__before_atomic_inc(); /* ^^^ */
89371- atomic_long_inc(&rsp->expedited_workdone1);
89372+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
89373 return;
89374 }
89375
89376@@ -2748,7 +2748,7 @@ void synchronize_sched_expedited(void)
89377 udelay(trycount * num_online_cpus());
89378 } else {
89379 wait_rcu_gp(call_rcu_sched);
89380- atomic_long_inc(&rsp->expedited_normal);
89381+ atomic_long_inc_unchecked(&rsp->expedited_normal);
89382 return;
89383 }
89384
89385@@ -2757,7 +2757,7 @@ void synchronize_sched_expedited(void)
89386 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
89387 /* ensure test happens before caller kfree */
89388 smp_mb__before_atomic_inc(); /* ^^^ */
89389- atomic_long_inc(&rsp->expedited_workdone2);
89390+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
89391 return;
89392 }
89393
89394@@ -2769,10 +2769,10 @@ void synchronize_sched_expedited(void)
89395 * period works for us.
89396 */
89397 get_online_cpus();
89398- snap = atomic_long_read(&rsp->expedited_start);
89399+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
89400 smp_mb(); /* ensure read is before try_stop_cpus(). */
89401 }
89402- atomic_long_inc(&rsp->expedited_stoppedcpus);
89403+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
89404
89405 /*
89406 * Everyone up to our most recent fetch is covered by our grace
89407@@ -2781,16 +2781,16 @@ void synchronize_sched_expedited(void)
89408 * than we did already did their update.
89409 */
89410 do {
89411- atomic_long_inc(&rsp->expedited_done_tries);
89412+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
89413 s = atomic_long_read(&rsp->expedited_done);
89414 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
89415 /* ensure test happens before caller kfree */
89416 smp_mb__before_atomic_inc(); /* ^^^ */
89417- atomic_long_inc(&rsp->expedited_done_lost);
89418+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
89419 break;
89420 }
89421 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
89422- atomic_long_inc(&rsp->expedited_done_exit);
89423+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
89424
89425 put_online_cpus();
89426 }
89427@@ -2996,7 +2996,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
89428 * ACCESS_ONCE() to prevent the compiler from speculating
89429 * the increment to precede the early-exit check.
89430 */
89431- ACCESS_ONCE(rsp->n_barrier_done)++;
89432+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
89433 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
89434 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
89435 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
89436@@ -3046,7 +3046,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
89437
89438 /* Increment ->n_barrier_done to prevent duplicate work. */
89439 smp_mb(); /* Keep increment after above mechanism. */
89440- ACCESS_ONCE(rsp->n_barrier_done)++;
89441+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
89442 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
89443 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
89444 smp_mb(); /* Keep increment before caller's subsequent code. */
89445@@ -3091,10 +3091,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
89446 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
89447 init_callback_list(rdp);
89448 rdp->qlen_lazy = 0;
89449- ACCESS_ONCE(rdp->qlen) = 0;
89450+ ACCESS_ONCE_RW(rdp->qlen) = 0;
89451 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
89452 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
89453- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
89454+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
89455 rdp->cpu = cpu;
89456 rdp->rsp = rsp;
89457 rcu_boot_init_nocb_percpu_data(rdp);
89458@@ -3128,8 +3128,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
89459 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
89460 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
89461 rcu_sysidle_init_percpu_data(rdp->dynticks);
89462- atomic_set(&rdp->dynticks->dynticks,
89463- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
89464+ atomic_set_unchecked(&rdp->dynticks->dynticks,
89465+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
89466 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
89467
89468 /* Add CPU to rcu_node bitmasks. */
89469diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
89470index 8c19873..bf83c57 100644
89471--- a/kernel/rcu/tree.h
89472+++ b/kernel/rcu/tree.h
89473@@ -87,11 +87,11 @@ struct rcu_dynticks {
89474 long long dynticks_nesting; /* Track irq/process nesting level. */
89475 /* Process level is worth LLONG_MAX/2. */
89476 int dynticks_nmi_nesting; /* Track NMI nesting level. */
89477- atomic_t dynticks; /* Even value for idle, else odd. */
89478+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
89479 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
89480 long long dynticks_idle_nesting;
89481 /* irq/process nesting level from idle. */
89482- atomic_t dynticks_idle; /* Even value for idle, else odd. */
89483+ atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
89484 /* "Idle" excludes userspace execution. */
89485 unsigned long dynticks_idle_jiffies;
89486 /* End of last non-NMI non-idle period. */
89487@@ -431,17 +431,17 @@ struct rcu_state {
89488 /* _rcu_barrier(). */
89489 /* End of fields guarded by barrier_mutex. */
89490
89491- atomic_long_t expedited_start; /* Starting ticket. */
89492- atomic_long_t expedited_done; /* Done ticket. */
89493- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
89494- atomic_long_t expedited_tryfail; /* # acquisition failures. */
89495- atomic_long_t expedited_workdone1; /* # done by others #1. */
89496- atomic_long_t expedited_workdone2; /* # done by others #2. */
89497- atomic_long_t expedited_normal; /* # fallbacks to normal. */
89498- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
89499- atomic_long_t expedited_done_tries; /* # tries to update _done. */
89500- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
89501- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
89502+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
89503+ atomic_long_t expedited_done; /* Done ticket. */
89504+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
89505+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
89506+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
89507+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
89508+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
89509+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
89510+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
89511+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
89512+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
89513
89514 unsigned long jiffies_force_qs; /* Time at which to invoke */
89515 /* force_quiescent_state(). */
89516diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
89517index 6e2ef4b..c15df94 100644
89518--- a/kernel/rcu/tree_plugin.h
89519+++ b/kernel/rcu/tree_plugin.h
89520@@ -758,7 +758,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
89521 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
89522 {
89523 return !rcu_preempted_readers_exp(rnp) &&
89524- ACCESS_ONCE(rnp->expmask) == 0;
89525+ ACCESS_ONCE_RW(rnp->expmask) == 0;
89526 }
89527
89528 /*
89529@@ -920,7 +920,7 @@ void synchronize_rcu_expedited(void)
89530
89531 /* Clean up and exit. */
89532 smp_mb(); /* ensure expedited GP seen before counter increment. */
89533- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
89534+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
89535 unlock_mb_ret:
89536 mutex_unlock(&sync_rcu_preempt_exp_mutex);
89537 mb_ret:
89538@@ -1496,7 +1496,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
89539 free_cpumask_var(cm);
89540 }
89541
89542-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
89543+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
89544 .store = &rcu_cpu_kthread_task,
89545 .thread_should_run = rcu_cpu_kthread_should_run,
89546 .thread_fn = rcu_cpu_kthread,
89547@@ -1965,7 +1965,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
89548 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
89549 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
89550 cpu, ticks_value, ticks_title,
89551- atomic_read(&rdtp->dynticks) & 0xfff,
89552+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
89553 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
89554 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
89555 fast_no_hz);
89556@@ -2129,7 +2129,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
89557
89558 /* Enqueue the callback on the nocb list and update counts. */
89559 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
89560- ACCESS_ONCE(*old_rhpp) = rhp;
89561+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
89562 atomic_long_add(rhcount, &rdp->nocb_q_count);
89563 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
89564
89565@@ -2302,12 +2302,12 @@ static int rcu_nocb_kthread(void *arg)
89566 * Extract queued callbacks, update counts, and wait
89567 * for a grace period to elapse.
89568 */
89569- ACCESS_ONCE(rdp->nocb_head) = NULL;
89570+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
89571 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
89572 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
89573 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
89574- ACCESS_ONCE(rdp->nocb_p_count) += c;
89575- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
89576+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
89577+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
89578 rcu_nocb_wait_gp(rdp);
89579
89580 /* Each pass through the following loop invokes a callback. */
89581@@ -2333,8 +2333,8 @@ static int rcu_nocb_kthread(void *arg)
89582 list = next;
89583 }
89584 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
89585- ACCESS_ONCE(rdp->nocb_p_count) -= c;
89586- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
89587+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
89588+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
89589 rdp->n_nocbs_invoked += c;
89590 }
89591 return 0;
89592@@ -2351,7 +2351,7 @@ static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
89593 {
89594 if (!rcu_nocb_need_deferred_wakeup(rdp))
89595 return;
89596- ACCESS_ONCE(rdp->nocb_defer_wakeup) = false;
89597+ ACCESS_ONCE_RW(rdp->nocb_defer_wakeup) = false;
89598 wake_up(&rdp->nocb_wq);
89599 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWakeEmpty"));
89600 }
89601@@ -2377,7 +2377,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
89602 t = kthread_run(rcu_nocb_kthread, rdp,
89603 "rcuo%c/%d", rsp->abbr, cpu);
89604 BUG_ON(IS_ERR(t));
89605- ACCESS_ONCE(rdp->nocb_kthread) = t;
89606+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
89607 }
89608 }
89609
89610@@ -2513,11 +2513,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
89611
89612 /* Record start of fully idle period. */
89613 j = jiffies;
89614- ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
89615+ ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
89616 smp_mb__before_atomic_inc();
89617- atomic_inc(&rdtp->dynticks_idle);
89618+ atomic_inc_unchecked(&rdtp->dynticks_idle);
89619 smp_mb__after_atomic_inc();
89620- WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
89621+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
89622 }
89623
89624 /*
89625@@ -2582,9 +2582,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
89626
89627 /* Record end of idle period. */
89628 smp_mb__before_atomic_inc();
89629- atomic_inc(&rdtp->dynticks_idle);
89630+ atomic_inc_unchecked(&rdtp->dynticks_idle);
89631 smp_mb__after_atomic_inc();
89632- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
89633+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
89634
89635 /*
89636 * If we are the timekeeping CPU, we are permitted to be non-idle
89637@@ -2625,7 +2625,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
89638 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
89639
89640 /* Pick up current idle and NMI-nesting counter and check. */
89641- cur = atomic_read(&rdtp->dynticks_idle);
89642+ cur = atomic_read_unchecked(&rdtp->dynticks_idle);
89643 if (cur & 0x1) {
89644 *isidle = false; /* We are not idle! */
89645 return;
89646@@ -2688,7 +2688,7 @@ static void rcu_sysidle(unsigned long j)
89647 case RCU_SYSIDLE_NOT:
89648
89649 /* First time all are idle, so note a short idle period. */
89650- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
89651+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
89652 break;
89653
89654 case RCU_SYSIDLE_SHORT:
89655@@ -2725,7 +2725,7 @@ static void rcu_sysidle(unsigned long j)
89656 static void rcu_sysidle_cancel(void)
89657 {
89658 smp_mb();
89659- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
89660+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
89661 }
89662
89663 /*
89664@@ -2773,7 +2773,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
89665 smp_mb(); /* grace period precedes setting inuse. */
89666
89667 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
89668- ACCESS_ONCE(rshp->inuse) = 0;
89669+ ACCESS_ONCE_RW(rshp->inuse) = 0;
89670 }
89671
89672 /*
89673diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
89674index 4def475..8ffddde 100644
89675--- a/kernel/rcu/tree_trace.c
89676+++ b/kernel/rcu/tree_trace.c
89677@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
89678 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
89679 rdp->passed_quiesce, rdp->qs_pending);
89680 seq_printf(m, " dt=%d/%llx/%d df=%lu",
89681- atomic_read(&rdp->dynticks->dynticks),
89682+ atomic_read_unchecked(&rdp->dynticks->dynticks),
89683 rdp->dynticks->dynticks_nesting,
89684 rdp->dynticks->dynticks_nmi_nesting,
89685 rdp->dynticks_fqs);
89686@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
89687 struct rcu_state *rsp = (struct rcu_state *)m->private;
89688
89689 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",
89690- atomic_long_read(&rsp->expedited_start),
89691+ atomic_long_read_unchecked(&rsp->expedited_start),
89692 atomic_long_read(&rsp->expedited_done),
89693- atomic_long_read(&rsp->expedited_wrap),
89694- atomic_long_read(&rsp->expedited_tryfail),
89695- atomic_long_read(&rsp->expedited_workdone1),
89696- atomic_long_read(&rsp->expedited_workdone2),
89697- atomic_long_read(&rsp->expedited_normal),
89698- atomic_long_read(&rsp->expedited_stoppedcpus),
89699- atomic_long_read(&rsp->expedited_done_tries),
89700- atomic_long_read(&rsp->expedited_done_lost),
89701- atomic_long_read(&rsp->expedited_done_exit));
89702+ atomic_long_read_unchecked(&rsp->expedited_wrap),
89703+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
89704+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
89705+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
89706+ atomic_long_read_unchecked(&rsp->expedited_normal),
89707+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
89708+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
89709+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
89710+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
89711 return 0;
89712 }
89713
89714diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
89715index c54609f..2e8829c 100644
89716--- a/kernel/rcu/update.c
89717+++ b/kernel/rcu/update.c
89718@@ -312,10 +312,10 @@ int rcu_jiffies_till_stall_check(void)
89719 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
89720 */
89721 if (till_stall_check < 3) {
89722- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
89723+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
89724 till_stall_check = 3;
89725 } else if (till_stall_check > 300) {
89726- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
89727+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
89728 till_stall_check = 300;
89729 }
89730 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
89731diff --git a/kernel/resource.c b/kernel/resource.c
89732index 3f285dc..5755f62 100644
89733--- a/kernel/resource.c
89734+++ b/kernel/resource.c
89735@@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
89736
89737 static int __init ioresources_init(void)
89738 {
89739+#ifdef CONFIG_GRKERNSEC_PROC_ADD
89740+#ifdef CONFIG_GRKERNSEC_PROC_USER
89741+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
89742+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
89743+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
89744+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
89745+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
89746+#endif
89747+#else
89748 proc_create("ioports", 0, NULL, &proc_ioports_operations);
89749 proc_create("iomem", 0, NULL, &proc_iomem_operations);
89750+#endif
89751 return 0;
89752 }
89753 __initcall(ioresources_init);
89754diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
89755index 4a07353..66b5291 100644
89756--- a/kernel/sched/auto_group.c
89757+++ b/kernel/sched/auto_group.c
89758@@ -11,7 +11,7 @@
89759
89760 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
89761 static struct autogroup autogroup_default;
89762-static atomic_t autogroup_seq_nr;
89763+static atomic_unchecked_t autogroup_seq_nr;
89764
89765 void __init autogroup_init(struct task_struct *init_task)
89766 {
89767@@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
89768
89769 kref_init(&ag->kref);
89770 init_rwsem(&ag->lock);
89771- ag->id = atomic_inc_return(&autogroup_seq_nr);
89772+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
89773 ag->tg = tg;
89774 #ifdef CONFIG_RT_GROUP_SCHED
89775 /*
89776diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
89777index a63f4dc..349bbb0 100644
89778--- a/kernel/sched/completion.c
89779+++ b/kernel/sched/completion.c
89780@@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
89781 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
89782 * or number of jiffies left till timeout) if completed.
89783 */
89784-long __sched
89785+long __sched __intentional_overflow(-1)
89786 wait_for_completion_interruptible_timeout(struct completion *x,
89787 unsigned long timeout)
89788 {
89789@@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
89790 *
89791 * Return: -ERESTARTSYS if interrupted, 0 if completed.
89792 */
89793-int __sched wait_for_completion_killable(struct completion *x)
89794+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
89795 {
89796 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
89797 if (t == -ERESTARTSYS)
89798@@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
89799 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
89800 * or number of jiffies left till timeout) if completed.
89801 */
89802-long __sched
89803+long __sched __intentional_overflow(-1)
89804 wait_for_completion_killable_timeout(struct completion *x,
89805 unsigned long timeout)
89806 {
89807diff --git a/kernel/sched/core.c b/kernel/sched/core.c
89808index f5c6635..ab9f223 100644
89809--- a/kernel/sched/core.c
89810+++ b/kernel/sched/core.c
89811@@ -1775,7 +1775,7 @@ void set_numabalancing_state(bool enabled)
89812 int sysctl_numa_balancing(struct ctl_table *table, int write,
89813 void __user *buffer, size_t *lenp, loff_t *ppos)
89814 {
89815- struct ctl_table t;
89816+ ctl_table_no_const t;
89817 int err;
89818 int state = numabalancing_enabled;
89819
89820@@ -3049,6 +3049,8 @@ int can_nice(const struct task_struct *p, const int nice)
89821 /* convert nice value [19,-20] to rlimit style value [1,40] */
89822 int nice_rlim = 20 - nice;
89823
89824+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
89825+
89826 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
89827 capable(CAP_SYS_NICE));
89828 }
89829@@ -3082,7 +3084,8 @@ SYSCALL_DEFINE1(nice, int, increment)
89830 if (nice > 19)
89831 nice = 19;
89832
89833- if (increment < 0 && !can_nice(current, nice))
89834+ if (increment < 0 && (!can_nice(current, nice) ||
89835+ gr_handle_chroot_nice()))
89836 return -EPERM;
89837
89838 retval = security_task_setnice(current, nice);
89839@@ -3332,6 +3335,7 @@ recheck:
89840 if (policy != p->policy && !rlim_rtprio)
89841 return -EPERM;
89842
89843+ gr_learn_resource(p, RLIMIT_RTPRIO, attr->sched_priority, 1);
89844 /* can't increase priority */
89845 if (attr->sched_priority > p->rt_priority &&
89846 attr->sched_priority > rlim_rtprio)
89847@@ -4781,7 +4785,7 @@ static void migrate_tasks(unsigned int dead_cpu)
89848
89849 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
89850
89851-static struct ctl_table sd_ctl_dir[] = {
89852+static ctl_table_no_const sd_ctl_dir[] __read_only = {
89853 {
89854 .procname = "sched_domain",
89855 .mode = 0555,
89856@@ -4798,17 +4802,17 @@ static struct ctl_table sd_ctl_root[] = {
89857 {}
89858 };
89859
89860-static struct ctl_table *sd_alloc_ctl_entry(int n)
89861+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
89862 {
89863- struct ctl_table *entry =
89864+ ctl_table_no_const *entry =
89865 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
89866
89867 return entry;
89868 }
89869
89870-static void sd_free_ctl_entry(struct ctl_table **tablep)
89871+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
89872 {
89873- struct ctl_table *entry;
89874+ ctl_table_no_const *entry;
89875
89876 /*
89877 * In the intermediate directories, both the child directory and
89878@@ -4816,22 +4820,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
89879 * will always be set. In the lowest directory the names are
89880 * static strings and all have proc handlers.
89881 */
89882- for (entry = *tablep; entry->mode; entry++) {
89883- if (entry->child)
89884- sd_free_ctl_entry(&entry->child);
89885+ for (entry = tablep; entry->mode; entry++) {
89886+ if (entry->child) {
89887+ sd_free_ctl_entry(entry->child);
89888+ pax_open_kernel();
89889+ entry->child = NULL;
89890+ pax_close_kernel();
89891+ }
89892 if (entry->proc_handler == NULL)
89893 kfree(entry->procname);
89894 }
89895
89896- kfree(*tablep);
89897- *tablep = NULL;
89898+ kfree(tablep);
89899 }
89900
89901 static int min_load_idx = 0;
89902 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
89903
89904 static void
89905-set_table_entry(struct ctl_table *entry,
89906+set_table_entry(ctl_table_no_const *entry,
89907 const char *procname, void *data, int maxlen,
89908 umode_t mode, proc_handler *proc_handler,
89909 bool load_idx)
89910@@ -4851,7 +4858,7 @@ set_table_entry(struct ctl_table *entry,
89911 static struct ctl_table *
89912 sd_alloc_ctl_domain_table(struct sched_domain *sd)
89913 {
89914- struct ctl_table *table = sd_alloc_ctl_entry(13);
89915+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
89916
89917 if (table == NULL)
89918 return NULL;
89919@@ -4886,9 +4893,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
89920 return table;
89921 }
89922
89923-static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
89924+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
89925 {
89926- struct ctl_table *entry, *table;
89927+ ctl_table_no_const *entry, *table;
89928 struct sched_domain *sd;
89929 int domain_num = 0, i;
89930 char buf[32];
89931@@ -4915,11 +4922,13 @@ static struct ctl_table_header *sd_sysctl_header;
89932 static void register_sched_domain_sysctl(void)
89933 {
89934 int i, cpu_num = num_possible_cpus();
89935- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
89936+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
89937 char buf[32];
89938
89939 WARN_ON(sd_ctl_dir[0].child);
89940+ pax_open_kernel();
89941 sd_ctl_dir[0].child = entry;
89942+ pax_close_kernel();
89943
89944 if (entry == NULL)
89945 return;
89946@@ -4942,8 +4951,12 @@ static void unregister_sched_domain_sysctl(void)
89947 if (sd_sysctl_header)
89948 unregister_sysctl_table(sd_sysctl_header);
89949 sd_sysctl_header = NULL;
89950- if (sd_ctl_dir[0].child)
89951- sd_free_ctl_entry(&sd_ctl_dir[0].child);
89952+ if (sd_ctl_dir[0].child) {
89953+ sd_free_ctl_entry(sd_ctl_dir[0].child);
89954+ pax_open_kernel();
89955+ sd_ctl_dir[0].child = NULL;
89956+ pax_close_kernel();
89957+ }
89958 }
89959 #else
89960 static void register_sched_domain_sysctl(void)
89961diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
89962index 9b4c4f3..665489b 100644
89963--- a/kernel/sched/fair.c
89964+++ b/kernel/sched/fair.c
89965@@ -1647,7 +1647,7 @@ void task_numa_fault(int last_cpupid, int node, int pages, int flags)
89966
89967 static void reset_ptenuma_scan(struct task_struct *p)
89968 {
89969- ACCESS_ONCE(p->mm->numa_scan_seq)++;
89970+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
89971 p->mm->numa_scan_offset = 0;
89972 }
89973
89974@@ -6851,7 +6851,7 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) { }
89975 * run_rebalance_domains is triggered when needed from the scheduler tick.
89976 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
89977 */
89978-static void run_rebalance_domains(struct softirq_action *h)
89979+static __latent_entropy void run_rebalance_domains(void)
89980 {
89981 struct rq *this_rq = this_rq();
89982 enum cpu_idle_type idle = this_rq->idle_balance ?
89983diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
89984index f964add..dcd823d 100644
89985--- a/kernel/sched/sched.h
89986+++ b/kernel/sched/sched.h
89987@@ -1157,7 +1157,7 @@ struct sched_class {
89988 #ifdef CONFIG_FAIR_GROUP_SCHED
89989 void (*task_move_group) (struct task_struct *p, int on_rq);
89990 #endif
89991-};
89992+} __do_const;
89993
89994 #define sched_class_highest (&stop_sched_class)
89995 #define for_each_class(class) \
89996diff --git a/kernel/signal.c b/kernel/signal.c
89997index 52f881d..1e9f941 100644
89998--- a/kernel/signal.c
89999+++ b/kernel/signal.c
90000@@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
90001
90002 int print_fatal_signals __read_mostly;
90003
90004-static void __user *sig_handler(struct task_struct *t, int sig)
90005+static __sighandler_t sig_handler(struct task_struct *t, int sig)
90006 {
90007 return t->sighand->action[sig - 1].sa.sa_handler;
90008 }
90009
90010-static int sig_handler_ignored(void __user *handler, int sig)
90011+static int sig_handler_ignored(__sighandler_t handler, int sig)
90012 {
90013 /* Is it explicitly or implicitly ignored? */
90014 return handler == SIG_IGN ||
90015@@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
90016
90017 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
90018 {
90019- void __user *handler;
90020+ __sighandler_t handler;
90021
90022 handler = sig_handler(t, sig);
90023
90024@@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
90025 atomic_inc(&user->sigpending);
90026 rcu_read_unlock();
90027
90028+ if (!override_rlimit)
90029+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
90030+
90031 if (override_rlimit ||
90032 atomic_read(&user->sigpending) <=
90033 task_rlimit(t, RLIMIT_SIGPENDING)) {
90034@@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
90035
90036 int unhandled_signal(struct task_struct *tsk, int sig)
90037 {
90038- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
90039+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
90040 if (is_global_init(tsk))
90041 return 1;
90042 if (handler != SIG_IGN && handler != SIG_DFL)
90043@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
90044 }
90045 }
90046
90047+ /* allow glibc communication via tgkill to other threads in our
90048+ thread group */
90049+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
90050+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
90051+ && gr_handle_signal(t, sig))
90052+ return -EPERM;
90053+
90054 return security_task_kill(t, info, sig, 0);
90055 }
90056
90057@@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
90058 return send_signal(sig, info, p, 1);
90059 }
90060
90061-static int
90062+int
90063 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
90064 {
90065 return send_signal(sig, info, t, 0);
90066@@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
90067 unsigned long int flags;
90068 int ret, blocked, ignored;
90069 struct k_sigaction *action;
90070+ int is_unhandled = 0;
90071
90072 spin_lock_irqsave(&t->sighand->siglock, flags);
90073 action = &t->sighand->action[sig-1];
90074@@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
90075 }
90076 if (action->sa.sa_handler == SIG_DFL)
90077 t->signal->flags &= ~SIGNAL_UNKILLABLE;
90078+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
90079+ is_unhandled = 1;
90080 ret = specific_send_sig_info(sig, info, t);
90081 spin_unlock_irqrestore(&t->sighand->siglock, flags);
90082
90083+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
90084+ normal operation */
90085+ if (is_unhandled) {
90086+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
90087+ gr_handle_crash(t, sig);
90088+ }
90089+
90090 return ret;
90091 }
90092
90093@@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
90094 ret = check_kill_permission(sig, info, p);
90095 rcu_read_unlock();
90096
90097- if (!ret && sig)
90098+ if (!ret && sig) {
90099 ret = do_send_sig_info(sig, info, p, true);
90100+ if (!ret)
90101+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
90102+ }
90103
90104 return ret;
90105 }
90106@@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
90107 int error = -ESRCH;
90108
90109 rcu_read_lock();
90110- p = find_task_by_vpid(pid);
90111+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
90112+ /* allow glibc communication via tgkill to other threads in our
90113+ thread group */
90114+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
90115+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
90116+ p = find_task_by_vpid_unrestricted(pid);
90117+ else
90118+#endif
90119+ p = find_task_by_vpid(pid);
90120 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
90121 error = check_kill_permission(sig, info, p);
90122 /*
90123@@ -3239,8 +3270,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
90124 }
90125 seg = get_fs();
90126 set_fs(KERNEL_DS);
90127- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
90128- (stack_t __force __user *) &uoss,
90129+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
90130+ (stack_t __force_user *) &uoss,
90131 compat_user_stack_pointer());
90132 set_fs(seg);
90133 if (ret >= 0 && uoss_ptr) {
90134diff --git a/kernel/smpboot.c b/kernel/smpboot.c
90135index eb89e18..a4e6792 100644
90136--- a/kernel/smpboot.c
90137+++ b/kernel/smpboot.c
90138@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
90139 }
90140 smpboot_unpark_thread(plug_thread, cpu);
90141 }
90142- list_add(&plug_thread->list, &hotplug_threads);
90143+ pax_list_add(&plug_thread->list, &hotplug_threads);
90144 out:
90145 mutex_unlock(&smpboot_threads_lock);
90146 return ret;
90147@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
90148 {
90149 get_online_cpus();
90150 mutex_lock(&smpboot_threads_lock);
90151- list_del(&plug_thread->list);
90152+ pax_list_del(&plug_thread->list);
90153 smpboot_destroy_threads(plug_thread);
90154 mutex_unlock(&smpboot_threads_lock);
90155 put_online_cpus();
90156diff --git a/kernel/softirq.c b/kernel/softirq.c
90157index 490fcbb..1e502c6 100644
90158--- a/kernel/softirq.c
90159+++ b/kernel/softirq.c
90160@@ -52,7 +52,7 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
90161 EXPORT_SYMBOL(irq_stat);
90162 #endif
90163
90164-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
90165+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
90166
90167 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
90168
90169@@ -267,7 +267,7 @@ restart:
90170 kstat_incr_softirqs_this_cpu(vec_nr);
90171
90172 trace_softirq_entry(vec_nr);
90173- h->action(h);
90174+ h->action();
90175 trace_softirq_exit(vec_nr);
90176 if (unlikely(prev_count != preempt_count())) {
90177 pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
90178@@ -427,7 +427,7 @@ void __raise_softirq_irqoff(unsigned int nr)
90179 or_softirq_pending(1UL << nr);
90180 }
90181
90182-void open_softirq(int nr, void (*action)(struct softirq_action *))
90183+void __init open_softirq(int nr, void (*action)(void))
90184 {
90185 softirq_vec[nr].action = action;
90186 }
90187@@ -479,7 +479,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
90188 }
90189 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
90190
90191-static void tasklet_action(struct softirq_action *a)
90192+static void tasklet_action(void)
90193 {
90194 struct tasklet_struct *list;
90195
90196@@ -515,7 +515,7 @@ static void tasklet_action(struct softirq_action *a)
90197 }
90198 }
90199
90200-static void tasklet_hi_action(struct softirq_action *a)
90201+static __latent_entropy void tasklet_hi_action(void)
90202 {
90203 struct tasklet_struct *list;
90204
90205@@ -742,7 +742,7 @@ static struct notifier_block cpu_nfb = {
90206 .notifier_call = cpu_callback
90207 };
90208
90209-static struct smp_hotplug_thread softirq_threads = {
90210+static struct smp_hotplug_thread softirq_threads __read_only = {
90211 .store = &ksoftirqd,
90212 .thread_should_run = ksoftirqd_should_run,
90213 .thread_fn = run_ksoftirqd,
90214diff --git a/kernel/sys.c b/kernel/sys.c
90215index c0a58be..784c618 100644
90216--- a/kernel/sys.c
90217+++ b/kernel/sys.c
90218@@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
90219 error = -EACCES;
90220 goto out;
90221 }
90222+
90223+ if (gr_handle_chroot_setpriority(p, niceval)) {
90224+ error = -EACCES;
90225+ goto out;
90226+ }
90227+
90228 no_nice = security_task_setnice(p, niceval);
90229 if (no_nice) {
90230 error = no_nice;
90231@@ -351,6 +357,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
90232 goto error;
90233 }
90234
90235+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
90236+ goto error;
90237+
90238 if (rgid != (gid_t) -1 ||
90239 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
90240 new->sgid = new->egid;
90241@@ -386,6 +395,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
90242 old = current_cred();
90243
90244 retval = -EPERM;
90245+
90246+ if (gr_check_group_change(kgid, kgid, kgid))
90247+ goto error;
90248+
90249 if (ns_capable(old->user_ns, CAP_SETGID))
90250 new->gid = new->egid = new->sgid = new->fsgid = kgid;
90251 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
90252@@ -403,7 +416,7 @@ error:
90253 /*
90254 * change the user struct in a credentials set to match the new UID
90255 */
90256-static int set_user(struct cred *new)
90257+int set_user(struct cred *new)
90258 {
90259 struct user_struct *new_user;
90260
90261@@ -483,6 +496,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
90262 goto error;
90263 }
90264
90265+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
90266+ goto error;
90267+
90268 if (!uid_eq(new->uid, old->uid)) {
90269 retval = set_user(new);
90270 if (retval < 0)
90271@@ -533,6 +549,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
90272 old = current_cred();
90273
90274 retval = -EPERM;
90275+
90276+ if (gr_check_crash_uid(kuid))
90277+ goto error;
90278+ if (gr_check_user_change(kuid, kuid, kuid))
90279+ goto error;
90280+
90281 if (ns_capable(old->user_ns, CAP_SETUID)) {
90282 new->suid = new->uid = kuid;
90283 if (!uid_eq(kuid, old->uid)) {
90284@@ -602,6 +624,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
90285 goto error;
90286 }
90287
90288+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
90289+ goto error;
90290+
90291 if (ruid != (uid_t) -1) {
90292 new->uid = kruid;
90293 if (!uid_eq(kruid, old->uid)) {
90294@@ -684,6 +709,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
90295 goto error;
90296 }
90297
90298+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
90299+ goto error;
90300+
90301 if (rgid != (gid_t) -1)
90302 new->gid = krgid;
90303 if (egid != (gid_t) -1)
90304@@ -745,12 +773,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
90305 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
90306 ns_capable(old->user_ns, CAP_SETUID)) {
90307 if (!uid_eq(kuid, old->fsuid)) {
90308+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
90309+ goto error;
90310+
90311 new->fsuid = kuid;
90312 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
90313 goto change_okay;
90314 }
90315 }
90316
90317+error:
90318 abort_creds(new);
90319 return old_fsuid;
90320
90321@@ -783,12 +815,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
90322 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
90323 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
90324 ns_capable(old->user_ns, CAP_SETGID)) {
90325+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
90326+ goto error;
90327+
90328 if (!gid_eq(kgid, old->fsgid)) {
90329 new->fsgid = kgid;
90330 goto change_okay;
90331 }
90332 }
90333
90334+error:
90335 abort_creds(new);
90336 return old_fsgid;
90337
90338@@ -1167,19 +1203,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
90339 return -EFAULT;
90340
90341 down_read(&uts_sem);
90342- error = __copy_to_user(&name->sysname, &utsname()->sysname,
90343+ error = __copy_to_user(name->sysname, &utsname()->sysname,
90344 __OLD_UTS_LEN);
90345 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
90346- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
90347+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
90348 __OLD_UTS_LEN);
90349 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
90350- error |= __copy_to_user(&name->release, &utsname()->release,
90351+ error |= __copy_to_user(name->release, &utsname()->release,
90352 __OLD_UTS_LEN);
90353 error |= __put_user(0, name->release + __OLD_UTS_LEN);
90354- error |= __copy_to_user(&name->version, &utsname()->version,
90355+ error |= __copy_to_user(name->version, &utsname()->version,
90356 __OLD_UTS_LEN);
90357 error |= __put_user(0, name->version + __OLD_UTS_LEN);
90358- error |= __copy_to_user(&name->machine, &utsname()->machine,
90359+ error |= __copy_to_user(name->machine, &utsname()->machine,
90360 __OLD_UTS_LEN);
90361 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
90362 up_read(&uts_sem);
90363@@ -1381,6 +1417,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
90364 */
90365 new_rlim->rlim_cur = 1;
90366 }
90367+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
90368+ is changed to a lower value. Since tasks can be created by the same
90369+ user in between this limit change and an execve by this task, force
90370+ a recheck only for this task by setting PF_NPROC_EXCEEDED
90371+ */
90372+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
90373+ tsk->flags |= PF_NPROC_EXCEEDED;
90374 }
90375 if (!retval) {
90376 if (old_rlim)
90377diff --git a/kernel/sysctl.c b/kernel/sysctl.c
90378index aae21e8..58d8c9a 100644
90379--- a/kernel/sysctl.c
90380+++ b/kernel/sysctl.c
90381@@ -94,7 +94,6 @@
90382
90383
90384 #if defined(CONFIG_SYSCTL)
90385-
90386 /* External variables not in a header file. */
90387 extern int max_threads;
90388 extern int suid_dumpable;
90389@@ -118,19 +117,18 @@ extern int blk_iopoll_enabled;
90390
90391 /* Constants used for minimum and maximum */
90392 #ifdef CONFIG_LOCKUP_DETECTOR
90393-static int sixty = 60;
90394+static int sixty __read_only = 60;
90395 #endif
90396
90397-static int __maybe_unused neg_one = -1;
90398-
90399-static int zero;
90400-static int __maybe_unused one = 1;
90401-static int __maybe_unused two = 2;
90402-static int __maybe_unused three = 3;
90403-static unsigned long one_ul = 1;
90404-static int one_hundred = 100;
90405+static int __maybe_unused neg_one __read_only = -1;
90406+static int zero __read_only = 0;
90407+static int __maybe_unused one __read_only = 1;
90408+static int __maybe_unused two __read_only = 2;
90409+static int __maybe_unused three __read_only = 3;
90410+static unsigned long one_ul __read_only = 1;
90411+static int one_hundred __read_only = 100;
90412 #ifdef CONFIG_PRINTK
90413-static int ten_thousand = 10000;
90414+static int ten_thousand __read_only = 10000;
90415 #endif
90416
90417 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
90418@@ -182,10 +180,8 @@ static int proc_taint(struct ctl_table *table, int write,
90419 void __user *buffer, size_t *lenp, loff_t *ppos);
90420 #endif
90421
90422-#ifdef CONFIG_PRINTK
90423 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
90424 void __user *buffer, size_t *lenp, loff_t *ppos);
90425-#endif
90426
90427 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
90428 void __user *buffer, size_t *lenp, loff_t *ppos);
90429@@ -216,6 +212,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
90430
90431 #endif
90432
90433+extern struct ctl_table grsecurity_table[];
90434+
90435 static struct ctl_table kern_table[];
90436 static struct ctl_table vm_table[];
90437 static struct ctl_table fs_table[];
90438@@ -230,6 +228,20 @@ extern struct ctl_table epoll_table[];
90439 int sysctl_legacy_va_layout;
90440 #endif
90441
90442+#ifdef CONFIG_PAX_SOFTMODE
90443+static ctl_table pax_table[] = {
90444+ {
90445+ .procname = "softmode",
90446+ .data = &pax_softmode,
90447+ .maxlen = sizeof(unsigned int),
90448+ .mode = 0600,
90449+ .proc_handler = &proc_dointvec,
90450+ },
90451+
90452+ { }
90453+};
90454+#endif
90455+
90456 /* The default sysctl tables: */
90457
90458 static struct ctl_table sysctl_base_table[] = {
90459@@ -278,6 +290,22 @@ static int max_extfrag_threshold = 1000;
90460 #endif
90461
90462 static struct ctl_table kern_table[] = {
90463+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
90464+ {
90465+ .procname = "grsecurity",
90466+ .mode = 0500,
90467+ .child = grsecurity_table,
90468+ },
90469+#endif
90470+
90471+#ifdef CONFIG_PAX_SOFTMODE
90472+ {
90473+ .procname = "pax",
90474+ .mode = 0500,
90475+ .child = pax_table,
90476+ },
90477+#endif
90478+
90479 {
90480 .procname = "sched_child_runs_first",
90481 .data = &sysctl_sched_child_runs_first,
90482@@ -640,7 +668,7 @@ static struct ctl_table kern_table[] = {
90483 .data = &modprobe_path,
90484 .maxlen = KMOD_PATH_LEN,
90485 .mode = 0644,
90486- .proc_handler = proc_dostring,
90487+ .proc_handler = proc_dostring_modpriv,
90488 },
90489 {
90490 .procname = "modules_disabled",
90491@@ -807,16 +835,20 @@ static struct ctl_table kern_table[] = {
90492 .extra1 = &zero,
90493 .extra2 = &one,
90494 },
90495+#endif
90496 {
90497 .procname = "kptr_restrict",
90498 .data = &kptr_restrict,
90499 .maxlen = sizeof(int),
90500 .mode = 0644,
90501 .proc_handler = proc_dointvec_minmax_sysadmin,
90502+#ifdef CONFIG_GRKERNSEC_HIDESYM
90503+ .extra1 = &two,
90504+#else
90505 .extra1 = &zero,
90506+#endif
90507 .extra2 = &two,
90508 },
90509-#endif
90510 {
90511 .procname = "ngroups_max",
90512 .data = &ngroups_max,
90513@@ -1061,10 +1093,17 @@ static struct ctl_table kern_table[] = {
90514 */
90515 {
90516 .procname = "perf_event_paranoid",
90517- .data = &sysctl_perf_event_paranoid,
90518- .maxlen = sizeof(sysctl_perf_event_paranoid),
90519+ .data = &sysctl_perf_event_legitimately_concerned,
90520+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
90521 .mode = 0644,
90522- .proc_handler = proc_dointvec,
90523+ /* go ahead, be a hero */
90524+ .proc_handler = proc_dointvec_minmax_sysadmin,
90525+ .extra1 = &neg_one,
90526+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
90527+ .extra2 = &three,
90528+#else
90529+ .extra2 = &two,
90530+#endif
90531 },
90532 {
90533 .procname = "perf_event_mlock_kb",
90534@@ -1335,6 +1374,13 @@ static struct ctl_table vm_table[] = {
90535 .proc_handler = proc_dointvec_minmax,
90536 .extra1 = &zero,
90537 },
90538+ {
90539+ .procname = "heap_stack_gap",
90540+ .data = &sysctl_heap_stack_gap,
90541+ .maxlen = sizeof(sysctl_heap_stack_gap),
90542+ .mode = 0644,
90543+ .proc_handler = proc_doulongvec_minmax,
90544+ },
90545 #else
90546 {
90547 .procname = "nr_trim_pages",
90548@@ -1799,6 +1845,16 @@ int proc_dostring(struct ctl_table *table, int write,
90549 buffer, lenp, ppos);
90550 }
90551
90552+int proc_dostring_modpriv(struct ctl_table *table, int write,
90553+ void __user *buffer, size_t *lenp, loff_t *ppos)
90554+{
90555+ if (write && !capable(CAP_SYS_MODULE))
90556+ return -EPERM;
90557+
90558+ return _proc_do_string(table->data, table->maxlen, write,
90559+ buffer, lenp, ppos);
90560+}
90561+
90562 static size_t proc_skip_spaces(char **buf)
90563 {
90564 size_t ret;
90565@@ -1904,6 +1960,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
90566 len = strlen(tmp);
90567 if (len > *size)
90568 len = *size;
90569+ if (len > sizeof(tmp))
90570+ len = sizeof(tmp);
90571 if (copy_to_user(*buf, tmp, len))
90572 return -EFAULT;
90573 *size -= len;
90574@@ -2068,7 +2126,7 @@ int proc_dointvec(struct ctl_table *table, int write,
90575 static int proc_taint(struct ctl_table *table, int write,
90576 void __user *buffer, size_t *lenp, loff_t *ppos)
90577 {
90578- struct ctl_table t;
90579+ ctl_table_no_const t;
90580 unsigned long tmptaint = get_taint();
90581 int err;
90582
90583@@ -2096,7 +2154,6 @@ static int proc_taint(struct ctl_table *table, int write,
90584 return err;
90585 }
90586
90587-#ifdef CONFIG_PRINTK
90588 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
90589 void __user *buffer, size_t *lenp, loff_t *ppos)
90590 {
90591@@ -2105,7 +2162,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
90592
90593 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
90594 }
90595-#endif
90596
90597 struct do_proc_dointvec_minmax_conv_param {
90598 int *min;
90599@@ -2652,6 +2708,12 @@ int proc_dostring(struct ctl_table *table, int write,
90600 return -ENOSYS;
90601 }
90602
90603+int proc_dostring_modpriv(struct ctl_table *table, int write,
90604+ void __user *buffer, size_t *lenp, loff_t *ppos)
90605+{
90606+ return -ENOSYS;
90607+}
90608+
90609 int proc_dointvec(struct ctl_table *table, int write,
90610 void __user *buffer, size_t *lenp, loff_t *ppos)
90611 {
90612@@ -2708,5 +2770,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
90613 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
90614 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
90615 EXPORT_SYMBOL(proc_dostring);
90616+EXPORT_SYMBOL(proc_dostring_modpriv);
90617 EXPORT_SYMBOL(proc_doulongvec_minmax);
90618 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
90619diff --git a/kernel/taskstats.c b/kernel/taskstats.c
90620index 13d2f7c..c93d0b0 100644
90621--- a/kernel/taskstats.c
90622+++ b/kernel/taskstats.c
90623@@ -28,9 +28,12 @@
90624 #include <linux/fs.h>
90625 #include <linux/file.h>
90626 #include <linux/pid_namespace.h>
90627+#include <linux/grsecurity.h>
90628 #include <net/genetlink.h>
90629 #include <linux/atomic.h>
90630
90631+extern int gr_is_taskstats_denied(int pid);
90632+
90633 /*
90634 * Maximum length of a cpumask that can be specified in
90635 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
90636@@ -576,6 +579,9 @@ err:
90637
90638 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
90639 {
90640+ if (gr_is_taskstats_denied(current->pid))
90641+ return -EACCES;
90642+
90643 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
90644 return cmd_attr_register_cpumask(info);
90645 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
90646diff --git a/kernel/time.c b/kernel/time.c
90647index 7c7964c..2a0d412 100644
90648--- a/kernel/time.c
90649+++ b/kernel/time.c
90650@@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
90651 return error;
90652
90653 if (tz) {
90654+ /* we log in do_settimeofday called below, so don't log twice
90655+ */
90656+ if (!tv)
90657+ gr_log_timechange();
90658+
90659 sys_tz = *tz;
90660 update_vsyscall_tz();
90661 if (firsttime) {
90662diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
90663index 88c9c65..7497ebc 100644
90664--- a/kernel/time/alarmtimer.c
90665+++ b/kernel/time/alarmtimer.c
90666@@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
90667 struct platform_device *pdev;
90668 int error = 0;
90669 int i;
90670- struct k_clock alarm_clock = {
90671+ static struct k_clock alarm_clock = {
90672 .clock_getres = alarm_clock_getres,
90673 .clock_get = alarm_clock_get,
90674 .timer_create = alarm_timer_create,
90675diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
90676index 5b40279..81e58db 100644
90677--- a/kernel/time/timekeeping.c
90678+++ b/kernel/time/timekeeping.c
90679@@ -15,6 +15,7 @@
90680 #include <linux/init.h>
90681 #include <linux/mm.h>
90682 #include <linux/sched.h>
90683+#include <linux/grsecurity.h>
90684 #include <linux/syscore_ops.h>
90685 #include <linux/clocksource.h>
90686 #include <linux/jiffies.h>
90687@@ -501,6 +502,8 @@ int do_settimeofday(const struct timespec *tv)
90688 if (!timespec_valid_strict(tv))
90689 return -EINVAL;
90690
90691+ gr_log_timechange();
90692+
90693 raw_spin_lock_irqsave(&timekeeper_lock, flags);
90694 write_seqcount_begin(&timekeeper_seq);
90695
90696diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
90697index 61ed862..3b52c65 100644
90698--- a/kernel/time/timer_list.c
90699+++ b/kernel/time/timer_list.c
90700@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
90701
90702 static void print_name_offset(struct seq_file *m, void *sym)
90703 {
90704+#ifdef CONFIG_GRKERNSEC_HIDESYM
90705+ SEQ_printf(m, "<%p>", NULL);
90706+#else
90707 char symname[KSYM_NAME_LEN];
90708
90709 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
90710 SEQ_printf(m, "<%pK>", sym);
90711 else
90712 SEQ_printf(m, "%s", symname);
90713+#endif
90714 }
90715
90716 static void
90717@@ -119,7 +123,11 @@ next_one:
90718 static void
90719 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
90720 {
90721+#ifdef CONFIG_GRKERNSEC_HIDESYM
90722+ SEQ_printf(m, " .base: %p\n", NULL);
90723+#else
90724 SEQ_printf(m, " .base: %pK\n", base);
90725+#endif
90726 SEQ_printf(m, " .index: %d\n",
90727 base->index);
90728 SEQ_printf(m, " .resolution: %Lu nsecs\n",
90729@@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
90730 {
90731 struct proc_dir_entry *pe;
90732
90733+#ifdef CONFIG_GRKERNSEC_PROC_ADD
90734+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
90735+#else
90736 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
90737+#endif
90738 if (!pe)
90739 return -ENOMEM;
90740 return 0;
90741diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
90742index 1fb08f2..ca4bb1e 100644
90743--- a/kernel/time/timer_stats.c
90744+++ b/kernel/time/timer_stats.c
90745@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
90746 static unsigned long nr_entries;
90747 static struct entry entries[MAX_ENTRIES];
90748
90749-static atomic_t overflow_count;
90750+static atomic_unchecked_t overflow_count;
90751
90752 /*
90753 * The entries are in a hash-table, for fast lookup:
90754@@ -140,7 +140,7 @@ static void reset_entries(void)
90755 nr_entries = 0;
90756 memset(entries, 0, sizeof(entries));
90757 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
90758- atomic_set(&overflow_count, 0);
90759+ atomic_set_unchecked(&overflow_count, 0);
90760 }
90761
90762 static struct entry *alloc_entry(void)
90763@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
90764 if (likely(entry))
90765 entry->count++;
90766 else
90767- atomic_inc(&overflow_count);
90768+ atomic_inc_unchecked(&overflow_count);
90769
90770 out_unlock:
90771 raw_spin_unlock_irqrestore(lock, flags);
90772@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
90773
90774 static void print_name_offset(struct seq_file *m, unsigned long addr)
90775 {
90776+#ifdef CONFIG_GRKERNSEC_HIDESYM
90777+ seq_printf(m, "<%p>", NULL);
90778+#else
90779 char symname[KSYM_NAME_LEN];
90780
90781 if (lookup_symbol_name(addr, symname) < 0)
90782- seq_printf(m, "<%p>", (void *)addr);
90783+ seq_printf(m, "<%pK>", (void *)addr);
90784 else
90785 seq_printf(m, "%s", symname);
90786+#endif
90787 }
90788
90789 static int tstats_show(struct seq_file *m, void *v)
90790@@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
90791
90792 seq_puts(m, "Timer Stats Version: v0.3\n");
90793 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
90794- if (atomic_read(&overflow_count))
90795- seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
90796+ if (atomic_read_unchecked(&overflow_count))
90797+ seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
90798 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
90799
90800 for (i = 0; i < nr_entries; i++) {
90801@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
90802 {
90803 struct proc_dir_entry *pe;
90804
90805+#ifdef CONFIG_GRKERNSEC_PROC_ADD
90806+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
90807+#else
90808 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
90809+#endif
90810 if (!pe)
90811 return -ENOMEM;
90812 return 0;
90813diff --git a/kernel/timer.c b/kernel/timer.c
90814index accfd24..e00f0c0 100644
90815--- a/kernel/timer.c
90816+++ b/kernel/timer.c
90817@@ -1366,7 +1366,7 @@ void update_process_times(int user_tick)
90818 /*
90819 * This function runs timers and the timer-tq in bottom half context.
90820 */
90821-static void run_timer_softirq(struct softirq_action *h)
90822+static __latent_entropy void run_timer_softirq(void)
90823 {
90824 struct tvec_base *base = __this_cpu_read(tvec_bases);
90825
90826@@ -1429,7 +1429,7 @@ static void process_timeout(unsigned long __data)
90827 *
90828 * In all cases the return value is guaranteed to be non-negative.
90829 */
90830-signed long __sched schedule_timeout(signed long timeout)
90831+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
90832 {
90833 struct timer_list timer;
90834 unsigned long expire;
90835diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
90836index b418cb0..f879a3d 100644
90837--- a/kernel/trace/blktrace.c
90838+++ b/kernel/trace/blktrace.c
90839@@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
90840 struct blk_trace *bt = filp->private_data;
90841 char buf[16];
90842
90843- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
90844+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
90845
90846 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
90847 }
90848@@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
90849 return 1;
90850
90851 bt = buf->chan->private_data;
90852- atomic_inc(&bt->dropped);
90853+ atomic_inc_unchecked(&bt->dropped);
90854 return 0;
90855 }
90856
90857@@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
90858
90859 bt->dir = dir;
90860 bt->dev = dev;
90861- atomic_set(&bt->dropped, 0);
90862+ atomic_set_unchecked(&bt->dropped, 0);
90863 INIT_LIST_HEAD(&bt->running_list);
90864
90865 ret = -EIO;
90866diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
90867index cd7f76d..553c805 100644
90868--- a/kernel/trace/ftrace.c
90869+++ b/kernel/trace/ftrace.c
90870@@ -1965,12 +1965,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
90871 if (unlikely(ftrace_disabled))
90872 return 0;
90873
90874+ ret = ftrace_arch_code_modify_prepare();
90875+ FTRACE_WARN_ON(ret);
90876+ if (ret)
90877+ return 0;
90878+
90879 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
90880+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
90881 if (ret) {
90882 ftrace_bug(ret, ip);
90883- return 0;
90884 }
90885- return 1;
90886+ return ret ? 0 : 1;
90887 }
90888
90889 /*
90890@@ -4177,8 +4182,10 @@ static int ftrace_process_locs(struct module *mod,
90891 if (!count)
90892 return 0;
90893
90894+ pax_open_kernel();
90895 sort(start, count, sizeof(*start),
90896 ftrace_cmp_ips, ftrace_swap_ips);
90897+ pax_close_kernel();
90898
90899 start_pg = ftrace_allocate_pages(count);
90900 if (!start_pg)
90901@@ -4909,8 +4916,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
90902 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
90903
90904 static int ftrace_graph_active;
90905-static struct notifier_block ftrace_suspend_notifier;
90906-
90907 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
90908 {
90909 return 0;
90910@@ -5086,6 +5091,10 @@ static void update_function_graph_func(void)
90911 ftrace_graph_entry = ftrace_graph_entry_test;
90912 }
90913
90914+static struct notifier_block ftrace_suspend_notifier = {
90915+ .notifier_call = ftrace_suspend_notifier_call
90916+};
90917+
90918 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
90919 trace_func_graph_ent_t entryfunc)
90920 {
90921@@ -5099,7 +5108,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
90922 goto out;
90923 }
90924
90925- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
90926 register_pm_notifier(&ftrace_suspend_notifier);
90927
90928 ftrace_graph_active++;
90929diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
90930index fc4da2d..f3e800b 100644
90931--- a/kernel/trace/ring_buffer.c
90932+++ b/kernel/trace/ring_buffer.c
90933@@ -352,9 +352,9 @@ struct buffer_data_page {
90934 */
90935 struct buffer_page {
90936 struct list_head list; /* list of buffer pages */
90937- local_t write; /* index for next write */
90938+ local_unchecked_t write; /* index for next write */
90939 unsigned read; /* index for next read */
90940- local_t entries; /* entries on this page */
90941+ local_unchecked_t entries; /* entries on this page */
90942 unsigned long real_end; /* real end of data */
90943 struct buffer_data_page *page; /* Actual data page */
90944 };
90945@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
90946 unsigned long last_overrun;
90947 local_t entries_bytes;
90948 local_t entries;
90949- local_t overrun;
90950- local_t commit_overrun;
90951+ local_unchecked_t overrun;
90952+ local_unchecked_t commit_overrun;
90953 local_t dropped_events;
90954 local_t committing;
90955 local_t commits;
90956@@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
90957 *
90958 * We add a counter to the write field to denote this.
90959 */
90960- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
90961- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
90962+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
90963+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
90964
90965 /*
90966 * Just make sure we have seen our old_write and synchronize
90967@@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
90968 * cmpxchg to only update if an interrupt did not already
90969 * do it for us. If the cmpxchg fails, we don't care.
90970 */
90971- (void)local_cmpxchg(&next_page->write, old_write, val);
90972- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
90973+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
90974+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
90975
90976 /*
90977 * No need to worry about races with clearing out the commit.
90978@@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
90979
90980 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
90981 {
90982- return local_read(&bpage->entries) & RB_WRITE_MASK;
90983+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
90984 }
90985
90986 static inline unsigned long rb_page_write(struct buffer_page *bpage)
90987 {
90988- return local_read(&bpage->write) & RB_WRITE_MASK;
90989+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
90990 }
90991
90992 static int
90993@@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
90994 * bytes consumed in ring buffer from here.
90995 * Increment overrun to account for the lost events.
90996 */
90997- local_add(page_entries, &cpu_buffer->overrun);
90998+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
90999 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
91000 }
91001
91002@@ -2064,7 +2064,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
91003 * it is our responsibility to update
91004 * the counters.
91005 */
91006- local_add(entries, &cpu_buffer->overrun);
91007+ local_add_unchecked(entries, &cpu_buffer->overrun);
91008 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
91009
91010 /*
91011@@ -2214,7 +2214,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
91012 if (tail == BUF_PAGE_SIZE)
91013 tail_page->real_end = 0;
91014
91015- local_sub(length, &tail_page->write);
91016+ local_sub_unchecked(length, &tail_page->write);
91017 return;
91018 }
91019
91020@@ -2249,7 +2249,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
91021 rb_event_set_padding(event);
91022
91023 /* Set the write back to the previous setting */
91024- local_sub(length, &tail_page->write);
91025+ local_sub_unchecked(length, &tail_page->write);
91026 return;
91027 }
91028
91029@@ -2261,7 +2261,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
91030
91031 /* Set write to end of buffer */
91032 length = (tail + length) - BUF_PAGE_SIZE;
91033- local_sub(length, &tail_page->write);
91034+ local_sub_unchecked(length, &tail_page->write);
91035 }
91036
91037 /*
91038@@ -2287,7 +2287,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
91039 * about it.
91040 */
91041 if (unlikely(next_page == commit_page)) {
91042- local_inc(&cpu_buffer->commit_overrun);
91043+ local_inc_unchecked(&cpu_buffer->commit_overrun);
91044 goto out_reset;
91045 }
91046
91047@@ -2343,7 +2343,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
91048 cpu_buffer->tail_page) &&
91049 (cpu_buffer->commit_page ==
91050 cpu_buffer->reader_page))) {
91051- local_inc(&cpu_buffer->commit_overrun);
91052+ local_inc_unchecked(&cpu_buffer->commit_overrun);
91053 goto out_reset;
91054 }
91055 }
91056@@ -2391,7 +2391,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
91057 length += RB_LEN_TIME_EXTEND;
91058
91059 tail_page = cpu_buffer->tail_page;
91060- write = local_add_return(length, &tail_page->write);
91061+ write = local_add_return_unchecked(length, &tail_page->write);
91062
91063 /* set write to only the index of the write */
91064 write &= RB_WRITE_MASK;
91065@@ -2415,7 +2415,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
91066 kmemcheck_annotate_bitfield(event, bitfield);
91067 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
91068
91069- local_inc(&tail_page->entries);
91070+ local_inc_unchecked(&tail_page->entries);
91071
91072 /*
91073 * If this is the first commit on the page, then update
91074@@ -2448,7 +2448,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
91075
91076 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
91077 unsigned long write_mask =
91078- local_read(&bpage->write) & ~RB_WRITE_MASK;
91079+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
91080 unsigned long event_length = rb_event_length(event);
91081 /*
91082 * This is on the tail page. It is possible that
91083@@ -2458,7 +2458,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
91084 */
91085 old_index += write_mask;
91086 new_index += write_mask;
91087- index = local_cmpxchg(&bpage->write, old_index, new_index);
91088+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
91089 if (index == old_index) {
91090 /* update counters */
91091 local_sub(event_length, &cpu_buffer->entries_bytes);
91092@@ -2850,7 +2850,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
91093
91094 /* Do the likely case first */
91095 if (likely(bpage->page == (void *)addr)) {
91096- local_dec(&bpage->entries);
91097+ local_dec_unchecked(&bpage->entries);
91098 return;
91099 }
91100
91101@@ -2862,7 +2862,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
91102 start = bpage;
91103 do {
91104 if (bpage->page == (void *)addr) {
91105- local_dec(&bpage->entries);
91106+ local_dec_unchecked(&bpage->entries);
91107 return;
91108 }
91109 rb_inc_page(cpu_buffer, &bpage);
91110@@ -3146,7 +3146,7 @@ static inline unsigned long
91111 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
91112 {
91113 return local_read(&cpu_buffer->entries) -
91114- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
91115+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
91116 }
91117
91118 /**
91119@@ -3235,7 +3235,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
91120 return 0;
91121
91122 cpu_buffer = buffer->buffers[cpu];
91123- ret = local_read(&cpu_buffer->overrun);
91124+ ret = local_read_unchecked(&cpu_buffer->overrun);
91125
91126 return ret;
91127 }
91128@@ -3258,7 +3258,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
91129 return 0;
91130
91131 cpu_buffer = buffer->buffers[cpu];
91132- ret = local_read(&cpu_buffer->commit_overrun);
91133+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
91134
91135 return ret;
91136 }
91137@@ -3343,7 +3343,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
91138 /* if you care about this being correct, lock the buffer */
91139 for_each_buffer_cpu(buffer, cpu) {
91140 cpu_buffer = buffer->buffers[cpu];
91141- overruns += local_read(&cpu_buffer->overrun);
91142+ overruns += local_read_unchecked(&cpu_buffer->overrun);
91143 }
91144
91145 return overruns;
91146@@ -3519,8 +3519,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
91147 /*
91148 * Reset the reader page to size zero.
91149 */
91150- local_set(&cpu_buffer->reader_page->write, 0);
91151- local_set(&cpu_buffer->reader_page->entries, 0);
91152+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
91153+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
91154 local_set(&cpu_buffer->reader_page->page->commit, 0);
91155 cpu_buffer->reader_page->real_end = 0;
91156
91157@@ -3554,7 +3554,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
91158 * want to compare with the last_overrun.
91159 */
91160 smp_mb();
91161- overwrite = local_read(&(cpu_buffer->overrun));
91162+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
91163
91164 /*
91165 * Here's the tricky part.
91166@@ -4124,8 +4124,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
91167
91168 cpu_buffer->head_page
91169 = list_entry(cpu_buffer->pages, struct buffer_page, list);
91170- local_set(&cpu_buffer->head_page->write, 0);
91171- local_set(&cpu_buffer->head_page->entries, 0);
91172+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
91173+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
91174 local_set(&cpu_buffer->head_page->page->commit, 0);
91175
91176 cpu_buffer->head_page->read = 0;
91177@@ -4135,14 +4135,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
91178
91179 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
91180 INIT_LIST_HEAD(&cpu_buffer->new_pages);
91181- local_set(&cpu_buffer->reader_page->write, 0);
91182- local_set(&cpu_buffer->reader_page->entries, 0);
91183+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
91184+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
91185 local_set(&cpu_buffer->reader_page->page->commit, 0);
91186 cpu_buffer->reader_page->read = 0;
91187
91188 local_set(&cpu_buffer->entries_bytes, 0);
91189- local_set(&cpu_buffer->overrun, 0);
91190- local_set(&cpu_buffer->commit_overrun, 0);
91191+ local_set_unchecked(&cpu_buffer->overrun, 0);
91192+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
91193 local_set(&cpu_buffer->dropped_events, 0);
91194 local_set(&cpu_buffer->entries, 0);
91195 local_set(&cpu_buffer->committing, 0);
91196@@ -4547,8 +4547,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
91197 rb_init_page(bpage);
91198 bpage = reader->page;
91199 reader->page = *data_page;
91200- local_set(&reader->write, 0);
91201- local_set(&reader->entries, 0);
91202+ local_set_unchecked(&reader->write, 0);
91203+ local_set_unchecked(&reader->entries, 0);
91204 reader->read = 0;
91205 *data_page = bpage;
91206
91207diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
91208index 24c1f23..781fd73f 100644
91209--- a/kernel/trace/trace.c
91210+++ b/kernel/trace/trace.c
91211@@ -3399,7 +3399,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
91212 return 0;
91213 }
91214
91215-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
91216+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
91217 {
91218 /* do nothing if flag is already set */
91219 if (!!(trace_flags & mask) == !!enabled)
91220diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
91221index 02b592f..f971546 100644
91222--- a/kernel/trace/trace.h
91223+++ b/kernel/trace/trace.h
91224@@ -1233,7 +1233,7 @@ extern const char *__stop___tracepoint_str[];
91225 void trace_printk_init_buffers(void);
91226 void trace_printk_start_comm(void);
91227 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
91228-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
91229+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
91230
91231 /*
91232 * Normal trace_printk() and friends allocates special buffers
91233diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
91234index 26dc348..8708ca7 100644
91235--- a/kernel/trace/trace_clock.c
91236+++ b/kernel/trace/trace_clock.c
91237@@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
91238 return now;
91239 }
91240
91241-static atomic64_t trace_counter;
91242+static atomic64_unchecked_t trace_counter;
91243
91244 /*
91245 * trace_clock_counter(): simply an atomic counter.
91246@@ -132,5 +132,5 @@ static atomic64_t trace_counter;
91247 */
91248 u64 notrace trace_clock_counter(void)
91249 {
91250- return atomic64_add_return(1, &trace_counter);
91251+ return atomic64_inc_return_unchecked(&trace_counter);
91252 }
91253diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
91254index 7b16d40..1b2875d 100644
91255--- a/kernel/trace/trace_events.c
91256+++ b/kernel/trace/trace_events.c
91257@@ -1681,7 +1681,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
91258 return 0;
91259 }
91260
91261-struct ftrace_module_file_ops;
91262 static void __add_event_to_tracers(struct ftrace_event_call *call);
91263
91264 /* Add an additional event_call dynamically */
91265diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
91266index 0abd9b8..6a663a2 100644
91267--- a/kernel/trace/trace_mmiotrace.c
91268+++ b/kernel/trace/trace_mmiotrace.c
91269@@ -24,7 +24,7 @@ struct header_iter {
91270 static struct trace_array *mmio_trace_array;
91271 static bool overrun_detected;
91272 static unsigned long prev_overruns;
91273-static atomic_t dropped_count;
91274+static atomic_unchecked_t dropped_count;
91275
91276 static void mmio_reset_data(struct trace_array *tr)
91277 {
91278@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
91279
91280 static unsigned long count_overruns(struct trace_iterator *iter)
91281 {
91282- unsigned long cnt = atomic_xchg(&dropped_count, 0);
91283+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
91284 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
91285
91286 if (over > prev_overruns)
91287@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
91288 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
91289 sizeof(*entry), 0, pc);
91290 if (!event) {
91291- atomic_inc(&dropped_count);
91292+ atomic_inc_unchecked(&dropped_count);
91293 return;
91294 }
91295 entry = ring_buffer_event_data(event);
91296@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
91297 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
91298 sizeof(*entry), 0, pc);
91299 if (!event) {
91300- atomic_inc(&dropped_count);
91301+ atomic_inc_unchecked(&dropped_count);
91302 return;
91303 }
91304 entry = ring_buffer_event_data(event);
91305diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
91306index ed32284..884d6c3 100644
91307--- a/kernel/trace/trace_output.c
91308+++ b/kernel/trace/trace_output.c
91309@@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
91310
91311 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
91312 if (!IS_ERR(p)) {
91313- p = mangle_path(s->buffer + s->len, p, "\n");
91314+ p = mangle_path(s->buffer + s->len, p, "\n\\");
91315 if (p) {
91316 s->len = p - s->buffer;
91317 return 1;
91318@@ -908,14 +908,16 @@ int register_ftrace_event(struct trace_event *event)
91319 goto out;
91320 }
91321
91322+ pax_open_kernel();
91323 if (event->funcs->trace == NULL)
91324- event->funcs->trace = trace_nop_print;
91325+ *(void **)&event->funcs->trace = trace_nop_print;
91326 if (event->funcs->raw == NULL)
91327- event->funcs->raw = trace_nop_print;
91328+ *(void **)&event->funcs->raw = trace_nop_print;
91329 if (event->funcs->hex == NULL)
91330- event->funcs->hex = trace_nop_print;
91331+ *(void **)&event->funcs->hex = trace_nop_print;
91332 if (event->funcs->binary == NULL)
91333- event->funcs->binary = trace_nop_print;
91334+ *(void **)&event->funcs->binary = trace_nop_print;
91335+ pax_close_kernel();
91336
91337 key = event->type & (EVENT_HASHSIZE - 1);
91338
91339diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
91340index e6be585..d73ae5e 100644
91341--- a/kernel/trace/trace_stack.c
91342+++ b/kernel/trace/trace_stack.c
91343@@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
91344 return;
91345
91346 /* we do not handle interrupt stacks yet */
91347- if (!object_is_on_stack(stack))
91348+ if (!object_starts_on_stack(stack))
91349 return;
91350
91351 local_irq_save(flags);
91352diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
91353index 80a57af..7f5a7ff 100644
91354--- a/kernel/user_namespace.c
91355+++ b/kernel/user_namespace.c
91356@@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
91357 !kgid_has_mapping(parent_ns, group))
91358 return -EPERM;
91359
91360+#ifdef CONFIG_GRKERNSEC
91361+ /*
91362+ * This doesn't really inspire confidence:
91363+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
91364+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
91365+ * Increases kernel attack surface in areas developers
91366+ * previously cared little about ("low importance due
91367+ * to requiring "root" capability")
91368+ * To be removed when this code receives *proper* review
91369+ */
91370+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
91371+ !capable(CAP_SETGID))
91372+ return -EPERM;
91373+#endif
91374+
91375 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
91376 if (!ns)
91377 return -ENOMEM;
91378@@ -865,7 +880,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
91379 if (atomic_read(&current->mm->mm_users) > 1)
91380 return -EINVAL;
91381
91382- if (current->fs->users != 1)
91383+ if (atomic_read(&current->fs->users) != 1)
91384 return -EINVAL;
91385
91386 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
91387diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
91388index 4f69f9a..7c6f8f8 100644
91389--- a/kernel/utsname_sysctl.c
91390+++ b/kernel/utsname_sysctl.c
91391@@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
91392 static int proc_do_uts_string(ctl_table *table, int write,
91393 void __user *buffer, size_t *lenp, loff_t *ppos)
91394 {
91395- struct ctl_table uts_table;
91396+ ctl_table_no_const uts_table;
91397 int r;
91398 memcpy(&uts_table, table, sizeof(uts_table));
91399 uts_table.data = get_uts(table, write);
91400diff --git a/kernel/watchdog.c b/kernel/watchdog.c
91401index 4431610..4265616 100644
91402--- a/kernel/watchdog.c
91403+++ b/kernel/watchdog.c
91404@@ -475,7 +475,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
91405 static void watchdog_nmi_disable(unsigned int cpu) { return; }
91406 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
91407
91408-static struct smp_hotplug_thread watchdog_threads = {
91409+static struct smp_hotplug_thread watchdog_threads __read_only = {
91410 .store = &softlockup_watchdog,
91411 .thread_should_run = watchdog_should_run,
91412 .thread_fn = watchdog,
91413diff --git a/kernel/workqueue.c b/kernel/workqueue.c
91414index 193e977..26dd63f 100644
91415--- a/kernel/workqueue.c
91416+++ b/kernel/workqueue.c
91417@@ -4678,7 +4678,7 @@ static void rebind_workers(struct worker_pool *pool)
91418 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
91419 worker_flags |= WORKER_REBOUND;
91420 worker_flags &= ~WORKER_UNBOUND;
91421- ACCESS_ONCE(worker->flags) = worker_flags;
91422+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
91423 }
91424
91425 spin_unlock_irq(&pool->lock);
91426diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
91427index a48abea..e108def 100644
91428--- a/lib/Kconfig.debug
91429+++ b/lib/Kconfig.debug
91430@@ -854,7 +854,7 @@ config DEBUG_MUTEXES
91431
91432 config DEBUG_WW_MUTEX_SLOWPATH
91433 bool "Wait/wound mutex debugging: Slowpath testing"
91434- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91435+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91436 select DEBUG_LOCK_ALLOC
91437 select DEBUG_SPINLOCK
91438 select DEBUG_MUTEXES
91439@@ -867,7 +867,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
91440
91441 config DEBUG_LOCK_ALLOC
91442 bool "Lock debugging: detect incorrect freeing of live locks"
91443- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91444+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91445 select DEBUG_SPINLOCK
91446 select DEBUG_MUTEXES
91447 select LOCKDEP
91448@@ -881,7 +881,7 @@ config DEBUG_LOCK_ALLOC
91449
91450 config PROVE_LOCKING
91451 bool "Lock debugging: prove locking correctness"
91452- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91453+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91454 select LOCKDEP
91455 select DEBUG_SPINLOCK
91456 select DEBUG_MUTEXES
91457@@ -932,7 +932,7 @@ config LOCKDEP
91458
91459 config LOCK_STAT
91460 bool "Lock usage statistics"
91461- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91462+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91463 select LOCKDEP
91464 select DEBUG_SPINLOCK
91465 select DEBUG_MUTEXES
91466@@ -1394,6 +1394,7 @@ config LATENCYTOP
91467 depends on DEBUG_KERNEL
91468 depends on STACKTRACE_SUPPORT
91469 depends on PROC_FS
91470+ depends on !GRKERNSEC_HIDESYM
91471 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
91472 select KALLSYMS
91473 select KALLSYMS_ALL
91474@@ -1410,7 +1411,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
91475 config DEBUG_STRICT_USER_COPY_CHECKS
91476 bool "Strict user copy size checks"
91477 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
91478- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
91479+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
91480 help
91481 Enabling this option turns a certain set of sanity checks for user
91482 copy operations into compile time failures.
91483@@ -1529,7 +1530,7 @@ endmenu # runtime tests
91484
91485 config PROVIDE_OHCI1394_DMA_INIT
91486 bool "Remote debugging over FireWire early on boot"
91487- depends on PCI && X86
91488+ depends on PCI && X86 && !GRKERNSEC
91489 help
91490 If you want to debug problems which hang or crash the kernel early
91491 on boot and the crashing machine has a FireWire port, you can use
91492diff --git a/lib/Makefile b/lib/Makefile
91493index 48140e3..de854e5 100644
91494--- a/lib/Makefile
91495+++ b/lib/Makefile
91496@@ -52,7 +52,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
91497 obj-$(CONFIG_BTREE) += btree.o
91498 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
91499 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
91500-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
91501+obj-y += list_debug.o
91502 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
91503
91504 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
91505diff --git a/lib/average.c b/lib/average.c
91506index 114d1be..ab0350c 100644
91507--- a/lib/average.c
91508+++ b/lib/average.c
91509@@ -55,7 +55,7 @@ struct ewma *ewma_add(struct ewma *avg, unsigned long val)
91510 {
91511 unsigned long internal = ACCESS_ONCE(avg->internal);
91512
91513- ACCESS_ONCE(avg->internal) = internal ?
91514+ ACCESS_ONCE_RW(avg->internal) = internal ?
91515 (((internal << avg->weight) - internal) +
91516 (val << avg->factor)) >> avg->weight :
91517 (val << avg->factor);
91518diff --git a/lib/bitmap.c b/lib/bitmap.c
91519index 06f7e4f..f3cf2b0 100644
91520--- a/lib/bitmap.c
91521+++ b/lib/bitmap.c
91522@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
91523 {
91524 int c, old_c, totaldigits, ndigits, nchunks, nbits;
91525 u32 chunk;
91526- const char __user __force *ubuf = (const char __user __force *)buf;
91527+ const char __user *ubuf = (const char __force_user *)buf;
91528
91529 bitmap_zero(maskp, nmaskbits);
91530
91531@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
91532 {
91533 if (!access_ok(VERIFY_READ, ubuf, ulen))
91534 return -EFAULT;
91535- return __bitmap_parse((const char __force *)ubuf,
91536+ return __bitmap_parse((const char __force_kernel *)ubuf,
91537 ulen, 1, maskp, nmaskbits);
91538
91539 }
91540@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
91541 {
91542 unsigned a, b;
91543 int c, old_c, totaldigits;
91544- const char __user __force *ubuf = (const char __user __force *)buf;
91545+ const char __user *ubuf = (const char __force_user *)buf;
91546 int exp_digit, in_range;
91547
91548 totaldigits = c = 0;
91549@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
91550 {
91551 if (!access_ok(VERIFY_READ, ubuf, ulen))
91552 return -EFAULT;
91553- return __bitmap_parselist((const char __force *)ubuf,
91554+ return __bitmap_parselist((const char __force_kernel *)ubuf,
91555 ulen, 1, maskp, nmaskbits);
91556 }
91557 EXPORT_SYMBOL(bitmap_parselist_user);
91558diff --git a/lib/bug.c b/lib/bug.c
91559index 1686034..a9c00c8 100644
91560--- a/lib/bug.c
91561+++ b/lib/bug.c
91562@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
91563 return BUG_TRAP_TYPE_NONE;
91564
91565 bug = find_bug(bugaddr);
91566+ if (!bug)
91567+ return BUG_TRAP_TYPE_NONE;
91568
91569 file = NULL;
91570 line = 0;
91571diff --git a/lib/debugobjects.c b/lib/debugobjects.c
91572index e0731c3..ad66444 100644
91573--- a/lib/debugobjects.c
91574+++ b/lib/debugobjects.c
91575@@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
91576 if (limit > 4)
91577 return;
91578
91579- is_on_stack = object_is_on_stack(addr);
91580+ is_on_stack = object_starts_on_stack(addr);
91581 if (is_on_stack == onstack)
91582 return;
91583
91584diff --git a/lib/devres.c b/lib/devres.c
91585index 8235331..5881053 100644
91586--- a/lib/devres.c
91587+++ b/lib/devres.c
91588@@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
91589 void devm_iounmap(struct device *dev, void __iomem *addr)
91590 {
91591 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
91592- (void *)addr));
91593+ (void __force *)addr));
91594 iounmap(addr);
91595 }
91596 EXPORT_SYMBOL(devm_iounmap);
91597@@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
91598 {
91599 ioport_unmap(addr);
91600 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
91601- devm_ioport_map_match, (void *)addr));
91602+ devm_ioport_map_match, (void __force *)addr));
91603 }
91604 EXPORT_SYMBOL(devm_ioport_unmap);
91605 #endif /* CONFIG_HAS_IOPORT */
91606diff --git a/lib/div64.c b/lib/div64.c
91607index 4382ad7..08aa558 100644
91608--- a/lib/div64.c
91609+++ b/lib/div64.c
91610@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
91611 EXPORT_SYMBOL(__div64_32);
91612
91613 #ifndef div_s64_rem
91614-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
91615+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
91616 {
91617 u64 quotient;
91618
91619@@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
91620 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
91621 */
91622 #ifndef div64_u64
91623-u64 div64_u64(u64 dividend, u64 divisor)
91624+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
91625 {
91626 u32 high = divisor >> 32;
91627 u64 quot;
91628diff --git a/lib/dma-debug.c b/lib/dma-debug.c
91629index 98f2d7e..899da5c 100644
91630--- a/lib/dma-debug.c
91631+++ b/lib/dma-debug.c
91632@@ -971,7 +971,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
91633
91634 void dma_debug_add_bus(struct bus_type *bus)
91635 {
91636- struct notifier_block *nb;
91637+ notifier_block_no_const *nb;
91638
91639 if (global_disable)
91640 return;
91641@@ -1148,7 +1148,7 @@ static void check_unmap(struct dma_debug_entry *ref)
91642
91643 static void check_for_stack(struct device *dev, void *addr)
91644 {
91645- if (object_is_on_stack(addr))
91646+ if (object_starts_on_stack(addr))
91647 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
91648 "stack [addr=%p]\n", addr);
91649 }
91650diff --git a/lib/hash.c b/lib/hash.c
91651index fea973f..386626f 100644
91652--- a/lib/hash.c
91653+++ b/lib/hash.c
91654@@ -14,7 +14,7 @@
91655 #include <linux/hash.h>
91656 #include <linux/cache.h>
91657
91658-static struct fast_hash_ops arch_hash_ops __read_mostly = {
91659+static struct fast_hash_ops arch_hash_ops __read_only = {
91660 .hash = jhash,
91661 .hash2 = jhash2,
91662 };
91663diff --git a/lib/inflate.c b/lib/inflate.c
91664index 013a761..c28f3fc 100644
91665--- a/lib/inflate.c
91666+++ b/lib/inflate.c
91667@@ -269,7 +269,7 @@ static void free(void *where)
91668 malloc_ptr = free_mem_ptr;
91669 }
91670 #else
91671-#define malloc(a) kmalloc(a, GFP_KERNEL)
91672+#define malloc(a) kmalloc((a), GFP_KERNEL)
91673 #define free(a) kfree(a)
91674 #endif
91675
91676diff --git a/lib/ioremap.c b/lib/ioremap.c
91677index 0c9216c..863bd89 100644
91678--- a/lib/ioremap.c
91679+++ b/lib/ioremap.c
91680@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
91681 unsigned long next;
91682
91683 phys_addr -= addr;
91684- pmd = pmd_alloc(&init_mm, pud, addr);
91685+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
91686 if (!pmd)
91687 return -ENOMEM;
91688 do {
91689@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
91690 unsigned long next;
91691
91692 phys_addr -= addr;
91693- pud = pud_alloc(&init_mm, pgd, addr);
91694+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
91695 if (!pud)
91696 return -ENOMEM;
91697 do {
91698diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
91699index bd2bea9..6b3c95e 100644
91700--- a/lib/is_single_threaded.c
91701+++ b/lib/is_single_threaded.c
91702@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
91703 struct task_struct *p, *t;
91704 bool ret;
91705
91706+ if (!mm)
91707+ return true;
91708+
91709 if (atomic_read(&task->signal->live) != 1)
91710 return false;
91711
91712diff --git a/lib/kobject.c b/lib/kobject.c
91713index cb14aea..8c53cdb 100644
91714--- a/lib/kobject.c
91715+++ b/lib/kobject.c
91716@@ -931,9 +931,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
91717
91718
91719 static DEFINE_SPINLOCK(kobj_ns_type_lock);
91720-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
91721+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
91722
91723-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
91724+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
91725 {
91726 enum kobj_ns_type type = ops->type;
91727 int error;
91728diff --git a/lib/list_debug.c b/lib/list_debug.c
91729index c24c2f7..f0296f4 100644
91730--- a/lib/list_debug.c
91731+++ b/lib/list_debug.c
91732@@ -11,7 +11,9 @@
91733 #include <linux/bug.h>
91734 #include <linux/kernel.h>
91735 #include <linux/rculist.h>
91736+#include <linux/mm.h>
91737
91738+#ifdef CONFIG_DEBUG_LIST
91739 /*
91740 * Insert a new entry between two known consecutive entries.
91741 *
91742@@ -19,21 +21,40 @@
91743 * the prev/next entries already!
91744 */
91745
91746+static bool __list_add_debug(struct list_head *new,
91747+ struct list_head *prev,
91748+ struct list_head *next)
91749+{
91750+ if (unlikely(next->prev != prev)) {
91751+ printk(KERN_ERR "list_add corruption. next->prev should be "
91752+ "prev (%p), but was %p. (next=%p).\n",
91753+ prev, next->prev, next);
91754+ BUG();
91755+ return false;
91756+ }
91757+ if (unlikely(prev->next != next)) {
91758+ printk(KERN_ERR "list_add corruption. prev->next should be "
91759+ "next (%p), but was %p. (prev=%p).\n",
91760+ next, prev->next, prev);
91761+ BUG();
91762+ return false;
91763+ }
91764+ if (unlikely(new == prev || new == next)) {
91765+ printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
91766+ new, prev, next);
91767+ BUG();
91768+ return false;
91769+ }
91770+ return true;
91771+}
91772+
91773 void __list_add(struct list_head *new,
91774- struct list_head *prev,
91775- struct list_head *next)
91776+ struct list_head *prev,
91777+ struct list_head *next)
91778 {
91779- WARN(next->prev != prev,
91780- "list_add corruption. next->prev should be "
91781- "prev (%p), but was %p. (next=%p).\n",
91782- prev, next->prev, next);
91783- WARN(prev->next != next,
91784- "list_add corruption. prev->next should be "
91785- "next (%p), but was %p. (prev=%p).\n",
91786- next, prev->next, prev);
91787- WARN(new == prev || new == next,
91788- "list_add double add: new=%p, prev=%p, next=%p.\n",
91789- new, prev, next);
91790+ if (!__list_add_debug(new, prev, next))
91791+ return;
91792+
91793 next->prev = new;
91794 new->next = next;
91795 new->prev = prev;
91796@@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
91797 }
91798 EXPORT_SYMBOL(__list_add);
91799
91800-void __list_del_entry(struct list_head *entry)
91801+static bool __list_del_entry_debug(struct list_head *entry)
91802 {
91803 struct list_head *prev, *next;
91804
91805 prev = entry->prev;
91806 next = entry->next;
91807
91808- if (WARN(next == LIST_POISON1,
91809- "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
91810- entry, LIST_POISON1) ||
91811- WARN(prev == LIST_POISON2,
91812- "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
91813- entry, LIST_POISON2) ||
91814- WARN(prev->next != entry,
91815- "list_del corruption. prev->next should be %p, "
91816- "but was %p\n", entry, prev->next) ||
91817- WARN(next->prev != entry,
91818- "list_del corruption. next->prev should be %p, "
91819- "but was %p\n", entry, next->prev))
91820+ if (unlikely(next == LIST_POISON1)) {
91821+ printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
91822+ entry, LIST_POISON1);
91823+ BUG();
91824+ return false;
91825+ }
91826+ if (unlikely(prev == LIST_POISON2)) {
91827+ printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
91828+ entry, LIST_POISON2);
91829+ BUG();
91830+ return false;
91831+ }
91832+ if (unlikely(entry->prev->next != entry)) {
91833+ printk(KERN_ERR "list_del corruption. prev->next should be %p, "
91834+ "but was %p\n", entry, prev->next);
91835+ BUG();
91836+ return false;
91837+ }
91838+ if (unlikely(entry->next->prev != entry)) {
91839+ printk(KERN_ERR "list_del corruption. next->prev should be %p, "
91840+ "but was %p\n", entry, next->prev);
91841+ BUG();
91842+ return false;
91843+ }
91844+ return true;
91845+}
91846+
91847+void __list_del_entry(struct list_head *entry)
91848+{
91849+ if (!__list_del_entry_debug(entry))
91850 return;
91851
91852- __list_del(prev, next);
91853+ __list_del(entry->prev, entry->next);
91854 }
91855 EXPORT_SYMBOL(__list_del_entry);
91856
91857@@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
91858 void __list_add_rcu(struct list_head *new,
91859 struct list_head *prev, struct list_head *next)
91860 {
91861- WARN(next->prev != prev,
91862- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
91863- prev, next->prev, next);
91864- WARN(prev->next != next,
91865- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
91866- next, prev->next, prev);
91867+ if (!__list_add_debug(new, prev, next))
91868+ return;
91869+
91870 new->next = next;
91871 new->prev = prev;
91872 rcu_assign_pointer(list_next_rcu(prev), new);
91873 next->prev = new;
91874 }
91875 EXPORT_SYMBOL(__list_add_rcu);
91876+#endif
91877+
91878+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
91879+{
91880+#ifdef CONFIG_DEBUG_LIST
91881+ if (!__list_add_debug(new, prev, next))
91882+ return;
91883+#endif
91884+
91885+ pax_open_kernel();
91886+ next->prev = new;
91887+ new->next = next;
91888+ new->prev = prev;
91889+ prev->next = new;
91890+ pax_close_kernel();
91891+}
91892+EXPORT_SYMBOL(__pax_list_add);
91893+
91894+void pax_list_del(struct list_head *entry)
91895+{
91896+#ifdef CONFIG_DEBUG_LIST
91897+ if (!__list_del_entry_debug(entry))
91898+ return;
91899+#endif
91900+
91901+ pax_open_kernel();
91902+ __list_del(entry->prev, entry->next);
91903+ entry->next = LIST_POISON1;
91904+ entry->prev = LIST_POISON2;
91905+ pax_close_kernel();
91906+}
91907+EXPORT_SYMBOL(pax_list_del);
91908+
91909+void pax_list_del_init(struct list_head *entry)
91910+{
91911+ pax_open_kernel();
91912+ __list_del(entry->prev, entry->next);
91913+ INIT_LIST_HEAD(entry);
91914+ pax_close_kernel();
91915+}
91916+EXPORT_SYMBOL(pax_list_del_init);
91917+
91918+void __pax_list_add_rcu(struct list_head *new,
91919+ struct list_head *prev, struct list_head *next)
91920+{
91921+#ifdef CONFIG_DEBUG_LIST
91922+ if (!__list_add_debug(new, prev, next))
91923+ return;
91924+#endif
91925+
91926+ pax_open_kernel();
91927+ new->next = next;
91928+ new->prev = prev;
91929+ rcu_assign_pointer(list_next_rcu(prev), new);
91930+ next->prev = new;
91931+ pax_close_kernel();
91932+}
91933+EXPORT_SYMBOL(__pax_list_add_rcu);
91934+
91935+void pax_list_del_rcu(struct list_head *entry)
91936+{
91937+#ifdef CONFIG_DEBUG_LIST
91938+ if (!__list_del_entry_debug(entry))
91939+ return;
91940+#endif
91941+
91942+ pax_open_kernel();
91943+ __list_del(entry->prev, entry->next);
91944+ entry->next = LIST_POISON1;
91945+ entry->prev = LIST_POISON2;
91946+ pax_close_kernel();
91947+}
91948+EXPORT_SYMBOL(pax_list_del_rcu);
91949diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
91950index 963b703..438bc51 100644
91951--- a/lib/percpu-refcount.c
91952+++ b/lib/percpu-refcount.c
91953@@ -29,7 +29,7 @@
91954 * can't hit 0 before we've added up all the percpu refs.
91955 */
91956
91957-#define PCPU_COUNT_BIAS (1U << 31)
91958+#define PCPU_COUNT_BIAS (1U << 30)
91959
91960 /**
91961 * percpu_ref_init - initialize a percpu refcount
91962diff --git a/lib/radix-tree.c b/lib/radix-tree.c
91963index bd4a8df..9e4804f 100644
91964--- a/lib/radix-tree.c
91965+++ b/lib/radix-tree.c
91966@@ -93,7 +93,7 @@ struct radix_tree_preload {
91967 int nr;
91968 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
91969 };
91970-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
91971+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
91972
91973 static inline void *ptr_to_indirect(void *ptr)
91974 {
91975diff --git a/lib/random32.c b/lib/random32.c
91976index 6148967..009bfe8 100644
91977--- a/lib/random32.c
91978+++ b/lib/random32.c
91979@@ -44,7 +44,7 @@
91980 static void __init prandom_state_selftest(void);
91981 #endif
91982
91983-static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
91984+static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
91985
91986 /**
91987 * prandom_u32_state - seeded pseudo-random number generator.
91988diff --git a/lib/rbtree.c b/lib/rbtree.c
91989index 65f4eff..2cfa167 100644
91990--- a/lib/rbtree.c
91991+++ b/lib/rbtree.c
91992@@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
91993 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
91994
91995 static const struct rb_augment_callbacks dummy_callbacks = {
91996- dummy_propagate, dummy_copy, dummy_rotate
91997+ .propagate = dummy_propagate,
91998+ .copy = dummy_copy,
91999+ .rotate = dummy_rotate
92000 };
92001
92002 void rb_insert_color(struct rb_node *node, struct rb_root *root)
92003diff --git a/lib/show_mem.c b/lib/show_mem.c
92004index 0922579..9d7adb9 100644
92005--- a/lib/show_mem.c
92006+++ b/lib/show_mem.c
92007@@ -44,6 +44,6 @@ void show_mem(unsigned int filter)
92008 quicklist_total_size());
92009 #endif
92010 #ifdef CONFIG_MEMORY_FAILURE
92011- printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages));
92012+ printk("%lu pages hwpoisoned\n", atomic_long_read_unchecked(&num_poisoned_pages));
92013 #endif
92014 }
92015diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
92016index bb2b201..46abaf9 100644
92017--- a/lib/strncpy_from_user.c
92018+++ b/lib/strncpy_from_user.c
92019@@ -21,7 +21,7 @@
92020 */
92021 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
92022 {
92023- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92024+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92025 long res = 0;
92026
92027 /*
92028diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
92029index a28df52..3d55877 100644
92030--- a/lib/strnlen_user.c
92031+++ b/lib/strnlen_user.c
92032@@ -26,7 +26,7 @@
92033 */
92034 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
92035 {
92036- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92037+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92038 long align, res = 0;
92039 unsigned long c;
92040
92041diff --git a/lib/swiotlb.c b/lib/swiotlb.c
92042index b604b83..c0547f6 100644
92043--- a/lib/swiotlb.c
92044+++ b/lib/swiotlb.c
92045@@ -674,7 +674,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
92046
92047 void
92048 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
92049- dma_addr_t dev_addr)
92050+ dma_addr_t dev_addr, struct dma_attrs *attrs)
92051 {
92052 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
92053
92054diff --git a/lib/usercopy.c b/lib/usercopy.c
92055index 4f5b1dd..7cab418 100644
92056--- a/lib/usercopy.c
92057+++ b/lib/usercopy.c
92058@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
92059 WARN(1, "Buffer overflow detected!\n");
92060 }
92061 EXPORT_SYMBOL(copy_from_user_overflow);
92062+
92063+void copy_to_user_overflow(void)
92064+{
92065+ WARN(1, "Buffer overflow detected!\n");
92066+}
92067+EXPORT_SYMBOL(copy_to_user_overflow);
92068diff --git a/lib/vsprintf.c b/lib/vsprintf.c
92069index 185b6d3..823c48c 100644
92070--- a/lib/vsprintf.c
92071+++ b/lib/vsprintf.c
92072@@ -16,6 +16,9 @@
92073 * - scnprintf and vscnprintf
92074 */
92075
92076+#ifdef CONFIG_GRKERNSEC_HIDESYM
92077+#define __INCLUDED_BY_HIDESYM 1
92078+#endif
92079 #include <stdarg.h>
92080 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
92081 #include <linux/types.h>
92082@@ -1179,7 +1182,11 @@ char *address_val(char *buf, char *end, const void *addr,
92083 return number(buf, end, num, spec);
92084 }
92085
92086+#ifdef CONFIG_GRKERNSEC_HIDESYM
92087+int kptr_restrict __read_mostly = 2;
92088+#else
92089 int kptr_restrict __read_mostly;
92090+#endif
92091
92092 /*
92093 * Show a '%p' thing. A kernel extension is that the '%p' is followed
92094@@ -1192,6 +1199,7 @@ int kptr_restrict __read_mostly;
92095 * - 'f' For simple symbolic function names without offset
92096 * - 'S' For symbolic direct pointers with offset
92097 * - 's' For symbolic direct pointers without offset
92098+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
92099 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
92100 * - 'B' For backtraced symbolic direct pointers with offset
92101 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
92102@@ -1259,12 +1267,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92103
92104 if (!ptr && *fmt != 'K') {
92105 /*
92106- * Print (null) with the same width as a pointer so it makes
92107+ * Print (nil) with the same width as a pointer so it makes
92108 * tabular output look nice.
92109 */
92110 if (spec.field_width == -1)
92111 spec.field_width = default_width;
92112- return string(buf, end, "(null)", spec);
92113+ return string(buf, end, "(nil)", spec);
92114 }
92115
92116 switch (*fmt) {
92117@@ -1274,6 +1282,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92118 /* Fallthrough */
92119 case 'S':
92120 case 's':
92121+#ifdef CONFIG_GRKERNSEC_HIDESYM
92122+ break;
92123+#else
92124+ return symbol_string(buf, end, ptr, spec, fmt);
92125+#endif
92126+ case 'A':
92127 case 'B':
92128 return symbol_string(buf, end, ptr, spec, fmt);
92129 case 'R':
92130@@ -1329,6 +1343,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92131 va_end(va);
92132 return buf;
92133 }
92134+ case 'P':
92135+ break;
92136 case 'K':
92137 /*
92138 * %pK cannot be used in IRQ context because its test
92139@@ -1386,6 +1402,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92140 ((const struct file *)ptr)->f_path.dentry,
92141 spec, fmt);
92142 }
92143+
92144+#ifdef CONFIG_GRKERNSEC_HIDESYM
92145+ /* 'P' = approved pointers to copy to userland,
92146+ as in the /proc/kallsyms case, as we make it display nothing
92147+ for non-root users, and the real contents for root users
92148+ Also ignore 'K' pointers, since we force their NULLing for non-root users
92149+ above
92150+ */
92151+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
92152+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
92153+ dump_stack();
92154+ ptr = NULL;
92155+ }
92156+#endif
92157+
92158 spec.flags |= SMALL;
92159 if (spec.field_width == -1) {
92160 spec.field_width = default_width;
92161@@ -2107,11 +2138,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
92162 typeof(type) value; \
92163 if (sizeof(type) == 8) { \
92164 args = PTR_ALIGN(args, sizeof(u32)); \
92165- *(u32 *)&value = *(u32 *)args; \
92166- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
92167+ *(u32 *)&value = *(const u32 *)args; \
92168+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
92169 } else { \
92170 args = PTR_ALIGN(args, sizeof(type)); \
92171- value = *(typeof(type) *)args; \
92172+ value = *(const typeof(type) *)args; \
92173 } \
92174 args += sizeof(type); \
92175 value; \
92176@@ -2174,7 +2205,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
92177 case FORMAT_TYPE_STR: {
92178 const char *str_arg = args;
92179 args += strlen(str_arg) + 1;
92180- str = string(str, end, (char *)str_arg, spec);
92181+ str = string(str, end, str_arg, spec);
92182 break;
92183 }
92184
92185diff --git a/localversion-grsec b/localversion-grsec
92186new file mode 100644
92187index 0000000..7cd6065
92188--- /dev/null
92189+++ b/localversion-grsec
92190@@ -0,0 +1 @@
92191+-grsec
92192diff --git a/mm/Kconfig b/mm/Kconfig
92193index 2888024..c15a810 100644
92194--- a/mm/Kconfig
92195+++ b/mm/Kconfig
92196@@ -326,10 +326,11 @@ config KSM
92197 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
92198
92199 config DEFAULT_MMAP_MIN_ADDR
92200- int "Low address space to protect from user allocation"
92201+ int "Low address space to protect from user allocation"
92202 depends on MMU
92203- default 4096
92204- help
92205+ default 32768 if ALPHA || ARM || PARISC || SPARC32
92206+ default 65536
92207+ help
92208 This is the portion of low virtual memory which should be protected
92209 from userspace allocation. Keeping a user from writing to low pages
92210 can help reduce the impact of kernel NULL pointer bugs.
92211@@ -360,7 +361,7 @@ config MEMORY_FAILURE
92212
92213 config HWPOISON_INJECT
92214 tristate "HWPoison pages injector"
92215- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
92216+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
92217 select PROC_PAGE_MONITOR
92218
92219 config NOMMU_INITIAL_TRIM_EXCESS
92220diff --git a/mm/backing-dev.c b/mm/backing-dev.c
92221index 09d9591..165bb75 100644
92222--- a/mm/backing-dev.c
92223+++ b/mm/backing-dev.c
92224@@ -12,7 +12,7 @@
92225 #include <linux/device.h>
92226 #include <trace/events/writeback.h>
92227
92228-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
92229+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
92230
92231 struct backing_dev_info default_backing_dev_info = {
92232 .name = "default",
92233@@ -533,7 +533,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
92234 return err;
92235
92236 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
92237- atomic_long_inc_return(&bdi_seq));
92238+ atomic_long_inc_return_unchecked(&bdi_seq));
92239 if (err) {
92240 bdi_destroy(bdi);
92241 return err;
92242diff --git a/mm/filemap.c b/mm/filemap.c
92243index 7a13f6a..e52e841 100644
92244--- a/mm/filemap.c
92245+++ b/mm/filemap.c
92246@@ -1766,7 +1766,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
92247 struct address_space *mapping = file->f_mapping;
92248
92249 if (!mapping->a_ops->readpage)
92250- return -ENOEXEC;
92251+ return -ENODEV;
92252 file_accessed(file);
92253 vma->vm_ops = &generic_file_vm_ops;
92254 return 0;
92255@@ -1948,7 +1948,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
92256
92257 while (bytes) {
92258 char __user *buf = iov->iov_base + base;
92259- int copy = min(bytes, iov->iov_len - base);
92260+ size_t copy = min(bytes, iov->iov_len - base);
92261
92262 base = 0;
92263 left = __copy_from_user_inatomic(vaddr, buf, copy);
92264@@ -1977,7 +1977,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
92265 BUG_ON(!in_atomic());
92266 kaddr = kmap_atomic(page);
92267 if (likely(i->nr_segs == 1)) {
92268- int left;
92269+ size_t left;
92270 char __user *buf = i->iov->iov_base + i->iov_offset;
92271 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
92272 copied = bytes - left;
92273@@ -2005,7 +2005,7 @@ size_t iov_iter_copy_from_user(struct page *page,
92274
92275 kaddr = kmap(page);
92276 if (likely(i->nr_segs == 1)) {
92277- int left;
92278+ size_t left;
92279 char __user *buf = i->iov->iov_base + i->iov_offset;
92280 left = __copy_from_user(kaddr + offset, buf, bytes);
92281 copied = bytes - left;
92282@@ -2035,7 +2035,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
92283 * zero-length segments (without overruning the iovec).
92284 */
92285 while (bytes || unlikely(i->count && !iov->iov_len)) {
92286- int copy;
92287+ size_t copy;
92288
92289 copy = min(bytes, iov->iov_len - base);
92290 BUG_ON(!i->count || i->count < copy);
92291@@ -2106,6 +2106,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
92292 *pos = i_size_read(inode);
92293
92294 if (limit != RLIM_INFINITY) {
92295+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
92296 if (*pos >= limit) {
92297 send_sig(SIGXFSZ, current, 0);
92298 return -EFBIG;
92299diff --git a/mm/fremap.c b/mm/fremap.c
92300index 34feba6..315fe78 100644
92301--- a/mm/fremap.c
92302+++ b/mm/fremap.c
92303@@ -179,6 +179,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
92304 retry:
92305 vma = find_vma(mm, start);
92306
92307+#ifdef CONFIG_PAX_SEGMEXEC
92308+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
92309+ goto out;
92310+#endif
92311+
92312 /*
92313 * Make sure the vma is shared, that it supports prefaulting,
92314 * and that the remapped range is valid and fully within
92315diff --git a/mm/highmem.c b/mm/highmem.c
92316index b32b70c..e512eb0 100644
92317--- a/mm/highmem.c
92318+++ b/mm/highmem.c
92319@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
92320 * So no dangers, even with speculative execution.
92321 */
92322 page = pte_page(pkmap_page_table[i]);
92323+ pax_open_kernel();
92324 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
92325-
92326+ pax_close_kernel();
92327 set_page_address(page, NULL);
92328 need_flush = 1;
92329 }
92330@@ -198,9 +199,11 @@ start:
92331 }
92332 }
92333 vaddr = PKMAP_ADDR(last_pkmap_nr);
92334+
92335+ pax_open_kernel();
92336 set_pte_at(&init_mm, vaddr,
92337 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
92338-
92339+ pax_close_kernel();
92340 pkmap_count[last_pkmap_nr] = 1;
92341 set_page_address(page, (void *)vaddr);
92342
92343diff --git a/mm/hugetlb.c b/mm/hugetlb.c
92344index 2de3c84..4ecaf1b 100644
92345--- a/mm/hugetlb.c
92346+++ b/mm/hugetlb.c
92347@@ -2069,15 +2069,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
92348 struct hstate *h = &default_hstate;
92349 unsigned long tmp;
92350 int ret;
92351+ ctl_table_no_const hugetlb_table;
92352
92353 tmp = h->max_huge_pages;
92354
92355 if (write && h->order >= MAX_ORDER)
92356 return -EINVAL;
92357
92358- table->data = &tmp;
92359- table->maxlen = sizeof(unsigned long);
92360- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
92361+ hugetlb_table = *table;
92362+ hugetlb_table.data = &tmp;
92363+ hugetlb_table.maxlen = sizeof(unsigned long);
92364+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
92365 if (ret)
92366 goto out;
92367
92368@@ -2122,15 +2124,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
92369 struct hstate *h = &default_hstate;
92370 unsigned long tmp;
92371 int ret;
92372+ ctl_table_no_const hugetlb_table;
92373
92374 tmp = h->nr_overcommit_huge_pages;
92375
92376 if (write && h->order >= MAX_ORDER)
92377 return -EINVAL;
92378
92379- table->data = &tmp;
92380- table->maxlen = sizeof(unsigned long);
92381- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
92382+ hugetlb_table = *table;
92383+ hugetlb_table.data = &tmp;
92384+ hugetlb_table.maxlen = sizeof(unsigned long);
92385+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
92386 if (ret)
92387 goto out;
92388
92389@@ -2599,6 +2603,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
92390 return 1;
92391 }
92392
92393+#ifdef CONFIG_PAX_SEGMEXEC
92394+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
92395+{
92396+ struct mm_struct *mm = vma->vm_mm;
92397+ struct vm_area_struct *vma_m;
92398+ unsigned long address_m;
92399+ pte_t *ptep_m;
92400+
92401+ vma_m = pax_find_mirror_vma(vma);
92402+ if (!vma_m)
92403+ return;
92404+
92405+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92406+ address_m = address + SEGMEXEC_TASK_SIZE;
92407+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
92408+ get_page(page_m);
92409+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
92410+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
92411+}
92412+#endif
92413+
92414 /*
92415 * Hugetlb_cow() should be called with page lock of the original hugepage held.
92416 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
92417@@ -2715,6 +2740,11 @@ retry_avoidcopy:
92418 make_huge_pte(vma, new_page, 1));
92419 page_remove_rmap(old_page);
92420 hugepage_add_new_anon_rmap(new_page, vma, address);
92421+
92422+#ifdef CONFIG_PAX_SEGMEXEC
92423+ pax_mirror_huge_pte(vma, address, new_page);
92424+#endif
92425+
92426 /* Make the old page be freed below */
92427 new_page = old_page;
92428 }
92429@@ -2879,6 +2909,10 @@ retry:
92430 && (vma->vm_flags & VM_SHARED)));
92431 set_huge_pte_at(mm, address, ptep, new_pte);
92432
92433+#ifdef CONFIG_PAX_SEGMEXEC
92434+ pax_mirror_huge_pte(vma, address, page);
92435+#endif
92436+
92437 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
92438 /* Optimization, do the COW without a second fault */
92439 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
92440@@ -2909,6 +2943,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92441 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
92442 struct hstate *h = hstate_vma(vma);
92443
92444+#ifdef CONFIG_PAX_SEGMEXEC
92445+ struct vm_area_struct *vma_m;
92446+#endif
92447+
92448 address &= huge_page_mask(h);
92449
92450 ptep = huge_pte_offset(mm, address);
92451@@ -2922,6 +2960,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92452 VM_FAULT_SET_HINDEX(hstate_index(h));
92453 }
92454
92455+#ifdef CONFIG_PAX_SEGMEXEC
92456+ vma_m = pax_find_mirror_vma(vma);
92457+ if (vma_m) {
92458+ unsigned long address_m;
92459+
92460+ if (vma->vm_start > vma_m->vm_start) {
92461+ address_m = address;
92462+ address -= SEGMEXEC_TASK_SIZE;
92463+ vma = vma_m;
92464+ h = hstate_vma(vma);
92465+ } else
92466+ address_m = address + SEGMEXEC_TASK_SIZE;
92467+
92468+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
92469+ return VM_FAULT_OOM;
92470+ address_m &= HPAGE_MASK;
92471+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
92472+ }
92473+#endif
92474+
92475 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
92476 if (!ptep)
92477 return VM_FAULT_OOM;
92478diff --git a/mm/internal.h b/mm/internal.h
92479index 3e91000..4741a60 100644
92480--- a/mm/internal.h
92481+++ b/mm/internal.h
92482@@ -94,6 +94,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
92483 * in mm/page_alloc.c
92484 */
92485 extern void __free_pages_bootmem(struct page *page, unsigned int order);
92486+extern void free_compound_page(struct page *page);
92487 extern void prep_compound_page(struct page *page, unsigned long order);
92488 #ifdef CONFIG_MEMORY_FAILURE
92489 extern bool is_free_buddy_page(struct page *page);
92490@@ -352,7 +353,7 @@ extern u32 hwpoison_filter_enable;
92491
92492 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
92493 unsigned long, unsigned long,
92494- unsigned long, unsigned long);
92495+ unsigned long, unsigned long) __intentional_overflow(-1);
92496
92497 extern void set_pageblock_order(void);
92498 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
92499diff --git a/mm/kmemleak.c b/mm/kmemleak.c
92500index 31f01c5..7015178 100644
92501--- a/mm/kmemleak.c
92502+++ b/mm/kmemleak.c
92503@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
92504
92505 for (i = 0; i < object->trace_len; i++) {
92506 void *ptr = (void *)object->trace[i];
92507- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
92508+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
92509 }
92510 }
92511
92512@@ -1853,7 +1853,7 @@ static int __init kmemleak_late_init(void)
92513 return -ENOMEM;
92514 }
92515
92516- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
92517+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
92518 &kmemleak_fops);
92519 if (!dentry)
92520 pr_warning("Failed to create the debugfs kmemleak file\n");
92521diff --git a/mm/maccess.c b/mm/maccess.c
92522index d53adf9..03a24bf 100644
92523--- a/mm/maccess.c
92524+++ b/mm/maccess.c
92525@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
92526 set_fs(KERNEL_DS);
92527 pagefault_disable();
92528 ret = __copy_from_user_inatomic(dst,
92529- (__force const void __user *)src, size);
92530+ (const void __force_user *)src, size);
92531 pagefault_enable();
92532 set_fs(old_fs);
92533
92534@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
92535
92536 set_fs(KERNEL_DS);
92537 pagefault_disable();
92538- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
92539+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
92540 pagefault_enable();
92541 set_fs(old_fs);
92542
92543diff --git a/mm/madvise.c b/mm/madvise.c
92544index 539eeb9..e24a987 100644
92545--- a/mm/madvise.c
92546+++ b/mm/madvise.c
92547@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
92548 pgoff_t pgoff;
92549 unsigned long new_flags = vma->vm_flags;
92550
92551+#ifdef CONFIG_PAX_SEGMEXEC
92552+ struct vm_area_struct *vma_m;
92553+#endif
92554+
92555 switch (behavior) {
92556 case MADV_NORMAL:
92557 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
92558@@ -126,6 +130,13 @@ success:
92559 /*
92560 * vm_flags is protected by the mmap_sem held in write mode.
92561 */
92562+
92563+#ifdef CONFIG_PAX_SEGMEXEC
92564+ vma_m = pax_find_mirror_vma(vma);
92565+ if (vma_m)
92566+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
92567+#endif
92568+
92569 vma->vm_flags = new_flags;
92570
92571 out:
92572@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
92573 struct vm_area_struct **prev,
92574 unsigned long start, unsigned long end)
92575 {
92576+
92577+#ifdef CONFIG_PAX_SEGMEXEC
92578+ struct vm_area_struct *vma_m;
92579+#endif
92580+
92581 *prev = vma;
92582 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
92583 return -EINVAL;
92584@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
92585 zap_page_range(vma, start, end - start, &details);
92586 } else
92587 zap_page_range(vma, start, end - start, NULL);
92588+
92589+#ifdef CONFIG_PAX_SEGMEXEC
92590+ vma_m = pax_find_mirror_vma(vma);
92591+ if (vma_m) {
92592+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
92593+ struct zap_details details = {
92594+ .nonlinear_vma = vma_m,
92595+ .last_index = ULONG_MAX,
92596+ };
92597+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
92598+ } else
92599+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
92600+ }
92601+#endif
92602+
92603 return 0;
92604 }
92605
92606@@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
92607 if (end < start)
92608 return error;
92609
92610+#ifdef CONFIG_PAX_SEGMEXEC
92611+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
92612+ if (end > SEGMEXEC_TASK_SIZE)
92613+ return error;
92614+ } else
92615+#endif
92616+
92617+ if (end > TASK_SIZE)
92618+ return error;
92619+
92620 error = 0;
92621 if (end == start)
92622 return error;
92623diff --git a/mm/memory-failure.c b/mm/memory-failure.c
92624index 90002ea..db1452d 100644
92625--- a/mm/memory-failure.c
92626+++ b/mm/memory-failure.c
92627@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
92628
92629 int sysctl_memory_failure_recovery __read_mostly = 1;
92630
92631-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
92632+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
92633
92634 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
92635
92636@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
92637 pfn, t->comm, t->pid);
92638 si.si_signo = SIGBUS;
92639 si.si_errno = 0;
92640- si.si_addr = (void *)addr;
92641+ si.si_addr = (void __user *)addr;
92642 #ifdef __ARCH_SI_TRAPNO
92643 si.si_trapno = trapno;
92644 #endif
92645@@ -762,7 +762,7 @@ static struct page_state {
92646 unsigned long res;
92647 char *msg;
92648 int (*action)(struct page *p, unsigned long pfn);
92649-} error_states[] = {
92650+} __do_const error_states[] = {
92651 { reserved, reserved, "reserved kernel", me_kernel },
92652 /*
92653 * free pages are specially detected outside this table:
92654@@ -1062,7 +1062,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
92655 nr_pages = 1 << compound_order(hpage);
92656 else /* normal page or thp */
92657 nr_pages = 1;
92658- atomic_long_add(nr_pages, &num_poisoned_pages);
92659+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
92660
92661 /*
92662 * We need/can do nothing about count=0 pages.
92663@@ -1092,7 +1092,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
92664 if (!PageHWPoison(hpage)
92665 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
92666 || (p != hpage && TestSetPageHWPoison(hpage))) {
92667- atomic_long_sub(nr_pages, &num_poisoned_pages);
92668+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92669 return 0;
92670 }
92671 set_page_hwpoison_huge_page(hpage);
92672@@ -1161,7 +1161,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
92673 }
92674 if (hwpoison_filter(p)) {
92675 if (TestClearPageHWPoison(p))
92676- atomic_long_sub(nr_pages, &num_poisoned_pages);
92677+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92678 unlock_page(hpage);
92679 put_page(hpage);
92680 return 0;
92681@@ -1383,7 +1383,7 @@ int unpoison_memory(unsigned long pfn)
92682 return 0;
92683 }
92684 if (TestClearPageHWPoison(p))
92685- atomic_long_dec(&num_poisoned_pages);
92686+ atomic_long_dec_unchecked(&num_poisoned_pages);
92687 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
92688 return 0;
92689 }
92690@@ -1397,7 +1397,7 @@ int unpoison_memory(unsigned long pfn)
92691 */
92692 if (TestClearPageHWPoison(page)) {
92693 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
92694- atomic_long_sub(nr_pages, &num_poisoned_pages);
92695+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92696 freeit = 1;
92697 if (PageHuge(page))
92698 clear_page_hwpoison_huge_page(page);
92699@@ -1522,11 +1522,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
92700 if (PageHuge(page)) {
92701 set_page_hwpoison_huge_page(hpage);
92702 dequeue_hwpoisoned_huge_page(hpage);
92703- atomic_long_add(1 << compound_order(hpage),
92704+ atomic_long_add_unchecked(1 << compound_order(hpage),
92705 &num_poisoned_pages);
92706 } else {
92707 SetPageHWPoison(page);
92708- atomic_long_inc(&num_poisoned_pages);
92709+ atomic_long_inc_unchecked(&num_poisoned_pages);
92710 }
92711 }
92712 return ret;
92713@@ -1565,7 +1565,7 @@ static int __soft_offline_page(struct page *page, int flags)
92714 put_page(page);
92715 pr_info("soft_offline: %#lx: invalidated\n", pfn);
92716 SetPageHWPoison(page);
92717- atomic_long_inc(&num_poisoned_pages);
92718+ atomic_long_inc_unchecked(&num_poisoned_pages);
92719 return 0;
92720 }
92721
92722@@ -1616,7 +1616,7 @@ static int __soft_offline_page(struct page *page, int flags)
92723 if (!is_free_buddy_page(page))
92724 pr_info("soft offline: %#lx: page leaked\n",
92725 pfn);
92726- atomic_long_inc(&num_poisoned_pages);
92727+ atomic_long_inc_unchecked(&num_poisoned_pages);
92728 }
92729 } else {
92730 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
92731@@ -1690,11 +1690,11 @@ int soft_offline_page(struct page *page, int flags)
92732 if (PageHuge(page)) {
92733 set_page_hwpoison_huge_page(hpage);
92734 dequeue_hwpoisoned_huge_page(hpage);
92735- atomic_long_add(1 << compound_order(hpage),
92736+ atomic_long_add_unchecked(1 << compound_order(hpage),
92737 &num_poisoned_pages);
92738 } else {
92739 SetPageHWPoison(page);
92740- atomic_long_inc(&num_poisoned_pages);
92741+ atomic_long_inc_unchecked(&num_poisoned_pages);
92742 }
92743 }
92744 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
92745diff --git a/mm/memory.c b/mm/memory.c
92746index 22dfa61..90d7ec5 100644
92747--- a/mm/memory.c
92748+++ b/mm/memory.c
92749@@ -403,6 +403,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
92750 free_pte_range(tlb, pmd, addr);
92751 } while (pmd++, addr = next, addr != end);
92752
92753+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
92754 start &= PUD_MASK;
92755 if (start < floor)
92756 return;
92757@@ -417,6 +418,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
92758 pmd = pmd_offset(pud, start);
92759 pud_clear(pud);
92760 pmd_free_tlb(tlb, pmd, start);
92761+#endif
92762+
92763 }
92764
92765 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
92766@@ -436,6 +439,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
92767 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
92768 } while (pud++, addr = next, addr != end);
92769
92770+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
92771 start &= PGDIR_MASK;
92772 if (start < floor)
92773 return;
92774@@ -450,6 +454,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
92775 pud = pud_offset(pgd, start);
92776 pgd_clear(pgd);
92777 pud_free_tlb(tlb, pud, start);
92778+#endif
92779+
92780 }
92781
92782 /*
92783@@ -1636,12 +1642,6 @@ no_page_table:
92784 return page;
92785 }
92786
92787-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
92788-{
92789- return stack_guard_page_start(vma, addr) ||
92790- stack_guard_page_end(vma, addr+PAGE_SIZE);
92791-}
92792-
92793 /**
92794 * __get_user_pages() - pin user pages in memory
92795 * @tsk: task_struct of target task
92796@@ -1728,10 +1728,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
92797
92798 i = 0;
92799
92800- do {
92801+ while (nr_pages) {
92802 struct vm_area_struct *vma;
92803
92804- vma = find_extend_vma(mm, start);
92805+ vma = find_vma(mm, start);
92806 if (!vma && in_gate_area(mm, start)) {
92807 unsigned long pg = start & PAGE_MASK;
92808 pgd_t *pgd;
92809@@ -1780,7 +1780,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
92810 goto next_page;
92811 }
92812
92813- if (!vma ||
92814+ if (!vma || start < vma->vm_start ||
92815 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
92816 !(vm_flags & vma->vm_flags))
92817 return i ? : -EFAULT;
92818@@ -1809,11 +1809,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
92819 int ret;
92820 unsigned int fault_flags = 0;
92821
92822- /* For mlock, just skip the stack guard page. */
92823- if (foll_flags & FOLL_MLOCK) {
92824- if (stack_guard_page(vma, start))
92825- goto next_page;
92826- }
92827 if (foll_flags & FOLL_WRITE)
92828 fault_flags |= FAULT_FLAG_WRITE;
92829 if (nonblocking)
92830@@ -1893,7 +1888,7 @@ next_page:
92831 start += page_increm * PAGE_SIZE;
92832 nr_pages -= page_increm;
92833 } while (nr_pages && start < vma->vm_end);
92834- } while (nr_pages);
92835+ }
92836 return i;
92837 }
92838 EXPORT_SYMBOL(__get_user_pages);
92839@@ -1929,12 +1924,17 @@ int fixup_user_fault(struct task_struct *tsk, struct mm_struct *mm,
92840 unsigned long address, unsigned int fault_flags)
92841 {
92842 struct vm_area_struct *vma;
92843+ vm_flags_t vm_flags;
92844 int ret;
92845
92846 vma = find_extend_vma(mm, address);
92847 if (!vma || address < vma->vm_start)
92848 return -EFAULT;
92849
92850+ vm_flags = (fault_flags & FAULT_FLAG_WRITE) ? VM_WRITE : VM_READ;
92851+ if (!(vm_flags & vma->vm_flags))
92852+ return -EFAULT;
92853+
92854 ret = handle_mm_fault(mm, vma, address, fault_flags);
92855 if (ret & VM_FAULT_ERROR) {
92856 if (ret & VM_FAULT_OOM)
92857@@ -2100,6 +2100,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
92858 page_add_file_rmap(page);
92859 set_pte_at(mm, addr, pte, mk_pte(page, prot));
92860
92861+#ifdef CONFIG_PAX_SEGMEXEC
92862+ pax_mirror_file_pte(vma, addr, page, ptl);
92863+#endif
92864+
92865 retval = 0;
92866 pte_unmap_unlock(pte, ptl);
92867 return retval;
92868@@ -2144,9 +2148,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
92869 if (!page_count(page))
92870 return -EINVAL;
92871 if (!(vma->vm_flags & VM_MIXEDMAP)) {
92872+
92873+#ifdef CONFIG_PAX_SEGMEXEC
92874+ struct vm_area_struct *vma_m;
92875+#endif
92876+
92877 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
92878 BUG_ON(vma->vm_flags & VM_PFNMAP);
92879 vma->vm_flags |= VM_MIXEDMAP;
92880+
92881+#ifdef CONFIG_PAX_SEGMEXEC
92882+ vma_m = pax_find_mirror_vma(vma);
92883+ if (vma_m)
92884+ vma_m->vm_flags |= VM_MIXEDMAP;
92885+#endif
92886+
92887 }
92888 return insert_page(vma, addr, page, vma->vm_page_prot);
92889 }
92890@@ -2229,6 +2245,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
92891 unsigned long pfn)
92892 {
92893 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
92894+ BUG_ON(vma->vm_mirror);
92895
92896 if (addr < vma->vm_start || addr >= vma->vm_end)
92897 return -EFAULT;
92898@@ -2476,7 +2493,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
92899
92900 BUG_ON(pud_huge(*pud));
92901
92902- pmd = pmd_alloc(mm, pud, addr);
92903+ pmd = (mm == &init_mm) ?
92904+ pmd_alloc_kernel(mm, pud, addr) :
92905+ pmd_alloc(mm, pud, addr);
92906 if (!pmd)
92907 return -ENOMEM;
92908 do {
92909@@ -2496,7 +2515,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
92910 unsigned long next;
92911 int err;
92912
92913- pud = pud_alloc(mm, pgd, addr);
92914+ pud = (mm == &init_mm) ?
92915+ pud_alloc_kernel(mm, pgd, addr) :
92916+ pud_alloc(mm, pgd, addr);
92917 if (!pud)
92918 return -ENOMEM;
92919 do {
92920@@ -2586,6 +2607,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
92921 copy_user_highpage(dst, src, va, vma);
92922 }
92923
92924+#ifdef CONFIG_PAX_SEGMEXEC
92925+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
92926+{
92927+ struct mm_struct *mm = vma->vm_mm;
92928+ spinlock_t *ptl;
92929+ pte_t *pte, entry;
92930+
92931+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
92932+ entry = *pte;
92933+ if (!pte_present(entry)) {
92934+ if (!pte_none(entry)) {
92935+ BUG_ON(pte_file(entry));
92936+ free_swap_and_cache(pte_to_swp_entry(entry));
92937+ pte_clear_not_present_full(mm, address, pte, 0);
92938+ }
92939+ } else {
92940+ struct page *page;
92941+
92942+ flush_cache_page(vma, address, pte_pfn(entry));
92943+ entry = ptep_clear_flush(vma, address, pte);
92944+ BUG_ON(pte_dirty(entry));
92945+ page = vm_normal_page(vma, address, entry);
92946+ if (page) {
92947+ update_hiwater_rss(mm);
92948+ if (PageAnon(page))
92949+ dec_mm_counter_fast(mm, MM_ANONPAGES);
92950+ else
92951+ dec_mm_counter_fast(mm, MM_FILEPAGES);
92952+ page_remove_rmap(page);
92953+ page_cache_release(page);
92954+ }
92955+ }
92956+ pte_unmap_unlock(pte, ptl);
92957+}
92958+
92959+/* PaX: if vma is mirrored, synchronize the mirror's PTE
92960+ *
92961+ * the ptl of the lower mapped page is held on entry and is not released on exit
92962+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
92963+ */
92964+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
92965+{
92966+ struct mm_struct *mm = vma->vm_mm;
92967+ unsigned long address_m;
92968+ spinlock_t *ptl_m;
92969+ struct vm_area_struct *vma_m;
92970+ pmd_t *pmd_m;
92971+ pte_t *pte_m, entry_m;
92972+
92973+ BUG_ON(!page_m || !PageAnon(page_m));
92974+
92975+ vma_m = pax_find_mirror_vma(vma);
92976+ if (!vma_m)
92977+ return;
92978+
92979+ BUG_ON(!PageLocked(page_m));
92980+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92981+ address_m = address + SEGMEXEC_TASK_SIZE;
92982+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
92983+ pte_m = pte_offset_map(pmd_m, address_m);
92984+ ptl_m = pte_lockptr(mm, pmd_m);
92985+ if (ptl != ptl_m) {
92986+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
92987+ if (!pte_none(*pte_m))
92988+ goto out;
92989+ }
92990+
92991+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
92992+ page_cache_get(page_m);
92993+ page_add_anon_rmap(page_m, vma_m, address_m);
92994+ inc_mm_counter_fast(mm, MM_ANONPAGES);
92995+ set_pte_at(mm, address_m, pte_m, entry_m);
92996+ update_mmu_cache(vma_m, address_m, pte_m);
92997+out:
92998+ if (ptl != ptl_m)
92999+ spin_unlock(ptl_m);
93000+ pte_unmap(pte_m);
93001+ unlock_page(page_m);
93002+}
93003+
93004+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
93005+{
93006+ struct mm_struct *mm = vma->vm_mm;
93007+ unsigned long address_m;
93008+ spinlock_t *ptl_m;
93009+ struct vm_area_struct *vma_m;
93010+ pmd_t *pmd_m;
93011+ pte_t *pte_m, entry_m;
93012+
93013+ BUG_ON(!page_m || PageAnon(page_m));
93014+
93015+ vma_m = pax_find_mirror_vma(vma);
93016+ if (!vma_m)
93017+ return;
93018+
93019+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
93020+ address_m = address + SEGMEXEC_TASK_SIZE;
93021+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
93022+ pte_m = pte_offset_map(pmd_m, address_m);
93023+ ptl_m = pte_lockptr(mm, pmd_m);
93024+ if (ptl != ptl_m) {
93025+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
93026+ if (!pte_none(*pte_m))
93027+ goto out;
93028+ }
93029+
93030+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
93031+ page_cache_get(page_m);
93032+ page_add_file_rmap(page_m);
93033+ inc_mm_counter_fast(mm, MM_FILEPAGES);
93034+ set_pte_at(mm, address_m, pte_m, entry_m);
93035+ update_mmu_cache(vma_m, address_m, pte_m);
93036+out:
93037+ if (ptl != ptl_m)
93038+ spin_unlock(ptl_m);
93039+ pte_unmap(pte_m);
93040+}
93041+
93042+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
93043+{
93044+ struct mm_struct *mm = vma->vm_mm;
93045+ unsigned long address_m;
93046+ spinlock_t *ptl_m;
93047+ struct vm_area_struct *vma_m;
93048+ pmd_t *pmd_m;
93049+ pte_t *pte_m, entry_m;
93050+
93051+ vma_m = pax_find_mirror_vma(vma);
93052+ if (!vma_m)
93053+ return;
93054+
93055+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
93056+ address_m = address + SEGMEXEC_TASK_SIZE;
93057+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
93058+ pte_m = pte_offset_map(pmd_m, address_m);
93059+ ptl_m = pte_lockptr(mm, pmd_m);
93060+ if (ptl != ptl_m) {
93061+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
93062+ if (!pte_none(*pte_m))
93063+ goto out;
93064+ }
93065+
93066+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
93067+ set_pte_at(mm, address_m, pte_m, entry_m);
93068+out:
93069+ if (ptl != ptl_m)
93070+ spin_unlock(ptl_m);
93071+ pte_unmap(pte_m);
93072+}
93073+
93074+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
93075+{
93076+ struct page *page_m;
93077+ pte_t entry;
93078+
93079+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
93080+ goto out;
93081+
93082+ entry = *pte;
93083+ page_m = vm_normal_page(vma, address, entry);
93084+ if (!page_m)
93085+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
93086+ else if (PageAnon(page_m)) {
93087+ if (pax_find_mirror_vma(vma)) {
93088+ pte_unmap_unlock(pte, ptl);
93089+ lock_page(page_m);
93090+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
93091+ if (pte_same(entry, *pte))
93092+ pax_mirror_anon_pte(vma, address, page_m, ptl);
93093+ else
93094+ unlock_page(page_m);
93095+ }
93096+ } else
93097+ pax_mirror_file_pte(vma, address, page_m, ptl);
93098+
93099+out:
93100+ pte_unmap_unlock(pte, ptl);
93101+}
93102+#endif
93103+
93104 /*
93105 * This routine handles present pages, when users try to write
93106 * to a shared page. It is done by copying the page to a new address
93107@@ -2810,6 +3011,12 @@ gotten:
93108 */
93109 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
93110 if (likely(pte_same(*page_table, orig_pte))) {
93111+
93112+#ifdef CONFIG_PAX_SEGMEXEC
93113+ if (pax_find_mirror_vma(vma))
93114+ BUG_ON(!trylock_page(new_page));
93115+#endif
93116+
93117 if (old_page) {
93118 if (!PageAnon(old_page)) {
93119 dec_mm_counter_fast(mm, MM_FILEPAGES);
93120@@ -2861,6 +3068,10 @@ gotten:
93121 page_remove_rmap(old_page);
93122 }
93123
93124+#ifdef CONFIG_PAX_SEGMEXEC
93125+ pax_mirror_anon_pte(vma, address, new_page, ptl);
93126+#endif
93127+
93128 /* Free the old page.. */
93129 new_page = old_page;
93130 ret |= VM_FAULT_WRITE;
93131@@ -3138,6 +3349,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
93132 swap_free(entry);
93133 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
93134 try_to_free_swap(page);
93135+
93136+#ifdef CONFIG_PAX_SEGMEXEC
93137+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
93138+#endif
93139+
93140 unlock_page(page);
93141 if (page != swapcache) {
93142 /*
93143@@ -3161,6 +3377,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
93144
93145 /* No need to invalidate - it was non-present before */
93146 update_mmu_cache(vma, address, page_table);
93147+
93148+#ifdef CONFIG_PAX_SEGMEXEC
93149+ pax_mirror_anon_pte(vma, address, page, ptl);
93150+#endif
93151+
93152 unlock:
93153 pte_unmap_unlock(page_table, ptl);
93154 out:
93155@@ -3180,40 +3401,6 @@ out_release:
93156 }
93157
93158 /*
93159- * This is like a special single-page "expand_{down|up}wards()",
93160- * except we must first make sure that 'address{-|+}PAGE_SIZE'
93161- * doesn't hit another vma.
93162- */
93163-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
93164-{
93165- address &= PAGE_MASK;
93166- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
93167- struct vm_area_struct *prev = vma->vm_prev;
93168-
93169- /*
93170- * Is there a mapping abutting this one below?
93171- *
93172- * That's only ok if it's the same stack mapping
93173- * that has gotten split..
93174- */
93175- if (prev && prev->vm_end == address)
93176- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
93177-
93178- expand_downwards(vma, address - PAGE_SIZE);
93179- }
93180- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
93181- struct vm_area_struct *next = vma->vm_next;
93182-
93183- /* As VM_GROWSDOWN but s/below/above/ */
93184- if (next && next->vm_start == address + PAGE_SIZE)
93185- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
93186-
93187- expand_upwards(vma, address + PAGE_SIZE);
93188- }
93189- return 0;
93190-}
93191-
93192-/*
93193 * We enter with non-exclusive mmap_sem (to exclude vma changes,
93194 * but allow concurrent faults), and pte mapped but not yet locked.
93195 * We return with mmap_sem still held, but pte unmapped and unlocked.
93196@@ -3222,27 +3409,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
93197 unsigned long address, pte_t *page_table, pmd_t *pmd,
93198 unsigned int flags)
93199 {
93200- struct page *page;
93201+ struct page *page = NULL;
93202 spinlock_t *ptl;
93203 pte_t entry;
93204
93205- pte_unmap(page_table);
93206-
93207- /* Check if we need to add a guard page to the stack */
93208- if (check_stack_guard_page(vma, address) < 0)
93209- return VM_FAULT_SIGBUS;
93210-
93211- /* Use the zero-page for reads */
93212 if (!(flags & FAULT_FLAG_WRITE)) {
93213 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
93214 vma->vm_page_prot));
93215- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
93216+ ptl = pte_lockptr(mm, pmd);
93217+ spin_lock(ptl);
93218 if (!pte_none(*page_table))
93219 goto unlock;
93220 goto setpte;
93221 }
93222
93223 /* Allocate our own private page. */
93224+ pte_unmap(page_table);
93225+
93226 if (unlikely(anon_vma_prepare(vma)))
93227 goto oom;
93228 page = alloc_zeroed_user_highpage_movable(vma, address);
93229@@ -3266,6 +3449,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
93230 if (!pte_none(*page_table))
93231 goto release;
93232
93233+#ifdef CONFIG_PAX_SEGMEXEC
93234+ if (pax_find_mirror_vma(vma))
93235+ BUG_ON(!trylock_page(page));
93236+#endif
93237+
93238 inc_mm_counter_fast(mm, MM_ANONPAGES);
93239 page_add_new_anon_rmap(page, vma, address);
93240 setpte:
93241@@ -3273,6 +3461,12 @@ setpte:
93242
93243 /* No need to invalidate - it was non-present before */
93244 update_mmu_cache(vma, address, page_table);
93245+
93246+#ifdef CONFIG_PAX_SEGMEXEC
93247+ if (page)
93248+ pax_mirror_anon_pte(vma, address, page, ptl);
93249+#endif
93250+
93251 unlock:
93252 pte_unmap_unlock(page_table, ptl);
93253 return 0;
93254@@ -3417,6 +3611,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93255 */
93256 /* Only go through if we didn't race with anybody else... */
93257 if (likely(pte_same(*page_table, orig_pte))) {
93258+
93259+#ifdef CONFIG_PAX_SEGMEXEC
93260+ if (anon && pax_find_mirror_vma(vma))
93261+ BUG_ON(!trylock_page(page));
93262+#endif
93263+
93264 flush_icache_page(vma, page);
93265 entry = mk_pte(page, vma->vm_page_prot);
93266 if (flags & FAULT_FLAG_WRITE)
93267@@ -3438,6 +3638,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93268
93269 /* no need to invalidate: a not-present page won't be cached */
93270 update_mmu_cache(vma, address, page_table);
93271+
93272+#ifdef CONFIG_PAX_SEGMEXEC
93273+ if (anon)
93274+ pax_mirror_anon_pte(vma, address, page, ptl);
93275+ else
93276+ pax_mirror_file_pte(vma, address, page, ptl);
93277+#endif
93278+
93279 } else {
93280 if (cow_page)
93281 mem_cgroup_uncharge_page(cow_page);
93282@@ -3685,6 +3893,12 @@ static int handle_pte_fault(struct mm_struct *mm,
93283 if (flags & FAULT_FLAG_WRITE)
93284 flush_tlb_fix_spurious_fault(vma, address);
93285 }
93286+
93287+#ifdef CONFIG_PAX_SEGMEXEC
93288+ pax_mirror_pte(vma, address, pte, pmd, ptl);
93289+ return 0;
93290+#endif
93291+
93292 unlock:
93293 pte_unmap_unlock(pte, ptl);
93294 return 0;
93295@@ -3701,9 +3915,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93296 pmd_t *pmd;
93297 pte_t *pte;
93298
93299+#ifdef CONFIG_PAX_SEGMEXEC
93300+ struct vm_area_struct *vma_m;
93301+#endif
93302+
93303 if (unlikely(is_vm_hugetlb_page(vma)))
93304 return hugetlb_fault(mm, vma, address, flags);
93305
93306+#ifdef CONFIG_PAX_SEGMEXEC
93307+ vma_m = pax_find_mirror_vma(vma);
93308+ if (vma_m) {
93309+ unsigned long address_m;
93310+ pgd_t *pgd_m;
93311+ pud_t *pud_m;
93312+ pmd_t *pmd_m;
93313+
93314+ if (vma->vm_start > vma_m->vm_start) {
93315+ address_m = address;
93316+ address -= SEGMEXEC_TASK_SIZE;
93317+ vma = vma_m;
93318+ } else
93319+ address_m = address + SEGMEXEC_TASK_SIZE;
93320+
93321+ pgd_m = pgd_offset(mm, address_m);
93322+ pud_m = pud_alloc(mm, pgd_m, address_m);
93323+ if (!pud_m)
93324+ return VM_FAULT_OOM;
93325+ pmd_m = pmd_alloc(mm, pud_m, address_m);
93326+ if (!pmd_m)
93327+ return VM_FAULT_OOM;
93328+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
93329+ return VM_FAULT_OOM;
93330+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
93331+ }
93332+#endif
93333+
93334 pgd = pgd_offset(mm, address);
93335 pud = pud_alloc(mm, pgd, address);
93336 if (!pud)
93337@@ -3834,6 +4080,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
93338 spin_unlock(&mm->page_table_lock);
93339 return 0;
93340 }
93341+
93342+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
93343+{
93344+ pud_t *new = pud_alloc_one(mm, address);
93345+ if (!new)
93346+ return -ENOMEM;
93347+
93348+ smp_wmb(); /* See comment in __pte_alloc */
93349+
93350+ spin_lock(&mm->page_table_lock);
93351+ if (pgd_present(*pgd)) /* Another has populated it */
93352+ pud_free(mm, new);
93353+ else
93354+ pgd_populate_kernel(mm, pgd, new);
93355+ spin_unlock(&mm->page_table_lock);
93356+ return 0;
93357+}
93358 #endif /* __PAGETABLE_PUD_FOLDED */
93359
93360 #ifndef __PAGETABLE_PMD_FOLDED
93361@@ -3864,6 +4127,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
93362 spin_unlock(&mm->page_table_lock);
93363 return 0;
93364 }
93365+
93366+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
93367+{
93368+ pmd_t *new = pmd_alloc_one(mm, address);
93369+ if (!new)
93370+ return -ENOMEM;
93371+
93372+ smp_wmb(); /* See comment in __pte_alloc */
93373+
93374+ spin_lock(&mm->page_table_lock);
93375+#ifndef __ARCH_HAS_4LEVEL_HACK
93376+ if (pud_present(*pud)) /* Another has populated it */
93377+ pmd_free(mm, new);
93378+ else
93379+ pud_populate_kernel(mm, pud, new);
93380+#else
93381+ if (pgd_present(*pud)) /* Another has populated it */
93382+ pmd_free(mm, new);
93383+ else
93384+ pgd_populate_kernel(mm, pud, new);
93385+#endif /* __ARCH_HAS_4LEVEL_HACK */
93386+ spin_unlock(&mm->page_table_lock);
93387+ return 0;
93388+}
93389 #endif /* __PAGETABLE_PMD_FOLDED */
93390
93391 #if !defined(__HAVE_ARCH_GATE_AREA)
93392@@ -3877,7 +4164,7 @@ static int __init gate_vma_init(void)
93393 gate_vma.vm_start = FIXADDR_USER_START;
93394 gate_vma.vm_end = FIXADDR_USER_END;
93395 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
93396- gate_vma.vm_page_prot = __P101;
93397+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
93398
93399 return 0;
93400 }
93401@@ -4011,8 +4298,8 @@ out:
93402 return ret;
93403 }
93404
93405-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
93406- void *buf, int len, int write)
93407+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
93408+ void *buf, size_t len, int write)
93409 {
93410 resource_size_t phys_addr;
93411 unsigned long prot = 0;
93412@@ -4038,8 +4325,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
93413 * Access another process' address space as given in mm. If non-NULL, use the
93414 * given task for page fault accounting.
93415 */
93416-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93417- unsigned long addr, void *buf, int len, int write)
93418+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93419+ unsigned long addr, void *buf, size_t len, int write)
93420 {
93421 struct vm_area_struct *vma;
93422 void *old_buf = buf;
93423@@ -4047,7 +4334,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93424 down_read(&mm->mmap_sem);
93425 /* ignore errors, just check how much was successfully transferred */
93426 while (len) {
93427- int bytes, ret, offset;
93428+ ssize_t bytes, ret, offset;
93429 void *maddr;
93430 struct page *page = NULL;
93431
93432@@ -4106,8 +4393,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93433 *
93434 * The caller must hold a reference on @mm.
93435 */
93436-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
93437- void *buf, int len, int write)
93438+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
93439+ void *buf, size_t len, int write)
93440 {
93441 return __access_remote_vm(NULL, mm, addr, buf, len, write);
93442 }
93443@@ -4117,11 +4404,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
93444 * Source/target buffer must be kernel space,
93445 * Do not walk the page table directly, use get_user_pages
93446 */
93447-int access_process_vm(struct task_struct *tsk, unsigned long addr,
93448- void *buf, int len, int write)
93449+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
93450+ void *buf, size_t len, int write)
93451 {
93452 struct mm_struct *mm;
93453- int ret;
93454+ ssize_t ret;
93455
93456 mm = get_task_mm(tsk);
93457 if (!mm)
93458diff --git a/mm/mempolicy.c b/mm/mempolicy.c
93459index ae3c8f3..fa4ee8e 100644
93460--- a/mm/mempolicy.c
93461+++ b/mm/mempolicy.c
93462@@ -746,6 +746,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
93463 unsigned long vmstart;
93464 unsigned long vmend;
93465
93466+#ifdef CONFIG_PAX_SEGMEXEC
93467+ struct vm_area_struct *vma_m;
93468+#endif
93469+
93470 vma = find_vma(mm, start);
93471 if (!vma || vma->vm_start > start)
93472 return -EFAULT;
93473@@ -789,6 +793,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
93474 err = vma_replace_policy(vma, new_pol);
93475 if (err)
93476 goto out;
93477+
93478+#ifdef CONFIG_PAX_SEGMEXEC
93479+ vma_m = pax_find_mirror_vma(vma);
93480+ if (vma_m) {
93481+ err = vma_replace_policy(vma_m, new_pol);
93482+ if (err)
93483+ goto out;
93484+ }
93485+#endif
93486+
93487 }
93488
93489 out:
93490@@ -1252,6 +1266,17 @@ static long do_mbind(unsigned long start, unsigned long len,
93491
93492 if (end < start)
93493 return -EINVAL;
93494+
93495+#ifdef CONFIG_PAX_SEGMEXEC
93496+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
93497+ if (end > SEGMEXEC_TASK_SIZE)
93498+ return -EINVAL;
93499+ } else
93500+#endif
93501+
93502+ if (end > TASK_SIZE)
93503+ return -EINVAL;
93504+
93505 if (end == start)
93506 return 0;
93507
93508@@ -1480,8 +1505,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
93509 */
93510 tcred = __task_cred(task);
93511 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
93512- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
93513- !capable(CAP_SYS_NICE)) {
93514+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
93515 rcu_read_unlock();
93516 err = -EPERM;
93517 goto out_put;
93518@@ -1512,6 +1536,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
93519 goto out;
93520 }
93521
93522+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
93523+ if (mm != current->mm &&
93524+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
93525+ mmput(mm);
93526+ err = -EPERM;
93527+ goto out;
93528+ }
93529+#endif
93530+
93531 err = do_migrate_pages(mm, old, new,
93532 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
93533
93534diff --git a/mm/migrate.c b/mm/migrate.c
93535index bed4880..a493f67 100644
93536--- a/mm/migrate.c
93537+++ b/mm/migrate.c
93538@@ -1485,8 +1485,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
93539 */
93540 tcred = __task_cred(task);
93541 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
93542- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
93543- !capable(CAP_SYS_NICE)) {
93544+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
93545 rcu_read_unlock();
93546 err = -EPERM;
93547 goto out;
93548diff --git a/mm/mlock.c b/mm/mlock.c
93549index b1eb536..091d154 100644
93550--- a/mm/mlock.c
93551+++ b/mm/mlock.c
93552@@ -14,6 +14,7 @@
93553 #include <linux/pagevec.h>
93554 #include <linux/mempolicy.h>
93555 #include <linux/syscalls.h>
93556+#include <linux/security.h>
93557 #include <linux/sched.h>
93558 #include <linux/export.h>
93559 #include <linux/rmap.h>
93560@@ -606,7 +607,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
93561 {
93562 unsigned long nstart, end, tmp;
93563 struct vm_area_struct * vma, * prev;
93564- int error;
93565+ int error = 0;
93566
93567 VM_BUG_ON(start & ~PAGE_MASK);
93568 VM_BUG_ON(len != PAGE_ALIGN(len));
93569@@ -615,6 +616,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
93570 return -EINVAL;
93571 if (end == start)
93572 return 0;
93573+ if (end > TASK_SIZE)
93574+ return -EINVAL;
93575+
93576 vma = find_vma(current->mm, start);
93577 if (!vma || vma->vm_start > start)
93578 return -ENOMEM;
93579@@ -626,6 +630,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
93580 for (nstart = start ; ; ) {
93581 vm_flags_t newflags;
93582
93583+#ifdef CONFIG_PAX_SEGMEXEC
93584+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
93585+ break;
93586+#endif
93587+
93588 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
93589
93590 newflags = vma->vm_flags & ~VM_LOCKED;
93591@@ -739,6 +748,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
93592 locked += current->mm->locked_vm;
93593
93594 /* check against resource limits */
93595+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
93596 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
93597 error = do_mlock(start, len, 1);
93598
93599@@ -776,6 +786,11 @@ static int do_mlockall(int flags)
93600 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
93601 vm_flags_t newflags;
93602
93603+#ifdef CONFIG_PAX_SEGMEXEC
93604+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
93605+ break;
93606+#endif
93607+
93608 newflags = vma->vm_flags & ~VM_LOCKED;
93609 if (flags & MCL_CURRENT)
93610 newflags |= VM_LOCKED;
93611@@ -807,8 +822,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
93612 lock_limit >>= PAGE_SHIFT;
93613
93614 ret = -ENOMEM;
93615+
93616+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
93617+
93618 down_write(&current->mm->mmap_sem);
93619-
93620 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
93621 capable(CAP_IPC_LOCK))
93622 ret = do_mlockall(flags);
93623diff --git a/mm/mmap.c b/mm/mmap.c
93624index 20ff0c3..a9eda98 100644
93625--- a/mm/mmap.c
93626+++ b/mm/mmap.c
93627@@ -36,6 +36,7 @@
93628 #include <linux/sched/sysctl.h>
93629 #include <linux/notifier.h>
93630 #include <linux/memory.h>
93631+#include <linux/random.h>
93632
93633 #include <asm/uaccess.h>
93634 #include <asm/cacheflush.h>
93635@@ -52,6 +53,16 @@
93636 #define arch_rebalance_pgtables(addr, len) (addr)
93637 #endif
93638
93639+static inline void verify_mm_writelocked(struct mm_struct *mm)
93640+{
93641+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
93642+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
93643+ up_read(&mm->mmap_sem);
93644+ BUG();
93645+ }
93646+#endif
93647+}
93648+
93649 static void unmap_region(struct mm_struct *mm,
93650 struct vm_area_struct *vma, struct vm_area_struct *prev,
93651 unsigned long start, unsigned long end);
93652@@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
93653 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
93654 *
93655 */
93656-pgprot_t protection_map[16] = {
93657+pgprot_t protection_map[16] __read_only = {
93658 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
93659 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
93660 };
93661
93662-pgprot_t vm_get_page_prot(unsigned long vm_flags)
93663+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
93664 {
93665- return __pgprot(pgprot_val(protection_map[vm_flags &
93666+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
93667 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
93668 pgprot_val(arch_vm_get_page_prot(vm_flags)));
93669+
93670+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
93671+ if (!(__supported_pte_mask & _PAGE_NX) &&
93672+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
93673+ (vm_flags & (VM_READ | VM_WRITE)))
93674+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
93675+#endif
93676+
93677+ return prot;
93678 }
93679 EXPORT_SYMBOL(vm_get_page_prot);
93680
93681@@ -90,6 +110,7 @@ unsigned long sysctl_overcommit_kbytes __read_mostly;
93682 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
93683 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
93684 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
93685+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
93686 /*
93687 * Make sure vm_committed_as in one cacheline and not cacheline shared with
93688 * other variables. It can be updated by several CPUs frequently.
93689@@ -246,6 +267,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
93690 struct vm_area_struct *next = vma->vm_next;
93691
93692 might_sleep();
93693+ BUG_ON(vma->vm_mirror);
93694 if (vma->vm_ops && vma->vm_ops->close)
93695 vma->vm_ops->close(vma);
93696 if (vma->vm_file)
93697@@ -290,6 +312,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
93698 * not page aligned -Ram Gupta
93699 */
93700 rlim = rlimit(RLIMIT_DATA);
93701+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
93702 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
93703 (mm->end_data - mm->start_data) > rlim)
93704 goto out;
93705@@ -940,6 +963,12 @@ static int
93706 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
93707 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
93708 {
93709+
93710+#ifdef CONFIG_PAX_SEGMEXEC
93711+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
93712+ return 0;
93713+#endif
93714+
93715 if (is_mergeable_vma(vma, file, vm_flags) &&
93716 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
93717 if (vma->vm_pgoff == vm_pgoff)
93718@@ -959,6 +988,12 @@ static int
93719 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
93720 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
93721 {
93722+
93723+#ifdef CONFIG_PAX_SEGMEXEC
93724+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
93725+ return 0;
93726+#endif
93727+
93728 if (is_mergeable_vma(vma, file, vm_flags) &&
93729 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
93730 pgoff_t vm_pglen;
93731@@ -1001,13 +1036,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
93732 struct vm_area_struct *vma_merge(struct mm_struct *mm,
93733 struct vm_area_struct *prev, unsigned long addr,
93734 unsigned long end, unsigned long vm_flags,
93735- struct anon_vma *anon_vma, struct file *file,
93736+ struct anon_vma *anon_vma, struct file *file,
93737 pgoff_t pgoff, struct mempolicy *policy)
93738 {
93739 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
93740 struct vm_area_struct *area, *next;
93741 int err;
93742
93743+#ifdef CONFIG_PAX_SEGMEXEC
93744+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
93745+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
93746+
93747+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
93748+#endif
93749+
93750 /*
93751 * We later require that vma->vm_flags == vm_flags,
93752 * so this tests vma->vm_flags & VM_SPECIAL, too.
93753@@ -1023,6 +1065,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
93754 if (next && next->vm_end == end) /* cases 6, 7, 8 */
93755 next = next->vm_next;
93756
93757+#ifdef CONFIG_PAX_SEGMEXEC
93758+ if (prev)
93759+ prev_m = pax_find_mirror_vma(prev);
93760+ if (area)
93761+ area_m = pax_find_mirror_vma(area);
93762+ if (next)
93763+ next_m = pax_find_mirror_vma(next);
93764+#endif
93765+
93766 /*
93767 * Can it merge with the predecessor?
93768 */
93769@@ -1042,9 +1093,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
93770 /* cases 1, 6 */
93771 err = vma_adjust(prev, prev->vm_start,
93772 next->vm_end, prev->vm_pgoff, NULL);
93773- } else /* cases 2, 5, 7 */
93774+
93775+#ifdef CONFIG_PAX_SEGMEXEC
93776+ if (!err && prev_m)
93777+ err = vma_adjust(prev_m, prev_m->vm_start,
93778+ next_m->vm_end, prev_m->vm_pgoff, NULL);
93779+#endif
93780+
93781+ } else { /* cases 2, 5, 7 */
93782 err = vma_adjust(prev, prev->vm_start,
93783 end, prev->vm_pgoff, NULL);
93784+
93785+#ifdef CONFIG_PAX_SEGMEXEC
93786+ if (!err && prev_m)
93787+ err = vma_adjust(prev_m, prev_m->vm_start,
93788+ end_m, prev_m->vm_pgoff, NULL);
93789+#endif
93790+
93791+ }
93792 if (err)
93793 return NULL;
93794 khugepaged_enter_vma_merge(prev);
93795@@ -1058,12 +1124,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
93796 mpol_equal(policy, vma_policy(next)) &&
93797 can_vma_merge_before(next, vm_flags,
93798 anon_vma, file, pgoff+pglen)) {
93799- if (prev && addr < prev->vm_end) /* case 4 */
93800+ if (prev && addr < prev->vm_end) { /* case 4 */
93801 err = vma_adjust(prev, prev->vm_start,
93802 addr, prev->vm_pgoff, NULL);
93803- else /* cases 3, 8 */
93804+
93805+#ifdef CONFIG_PAX_SEGMEXEC
93806+ if (!err && prev_m)
93807+ err = vma_adjust(prev_m, prev_m->vm_start,
93808+ addr_m, prev_m->vm_pgoff, NULL);
93809+#endif
93810+
93811+ } else { /* cases 3, 8 */
93812 err = vma_adjust(area, addr, next->vm_end,
93813 next->vm_pgoff - pglen, NULL);
93814+
93815+#ifdef CONFIG_PAX_SEGMEXEC
93816+ if (!err && area_m)
93817+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
93818+ next_m->vm_pgoff - pglen, NULL);
93819+#endif
93820+
93821+ }
93822 if (err)
93823 return NULL;
93824 khugepaged_enter_vma_merge(area);
93825@@ -1172,8 +1253,10 @@ none:
93826 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
93827 struct file *file, long pages)
93828 {
93829- const unsigned long stack_flags
93830- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
93831+
93832+#ifdef CONFIG_PAX_RANDMMAP
93833+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
93834+#endif
93835
93836 mm->total_vm += pages;
93837
93838@@ -1181,7 +1264,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
93839 mm->shared_vm += pages;
93840 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
93841 mm->exec_vm += pages;
93842- } else if (flags & stack_flags)
93843+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
93844 mm->stack_vm += pages;
93845 }
93846 #endif /* CONFIG_PROC_FS */
93847@@ -1211,6 +1294,7 @@ static inline int mlock_future_check(struct mm_struct *mm,
93848 locked += mm->locked_vm;
93849 lock_limit = rlimit(RLIMIT_MEMLOCK);
93850 lock_limit >>= PAGE_SHIFT;
93851+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
93852 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
93853 return -EAGAIN;
93854 }
93855@@ -1237,7 +1321,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93856 * (the exception is when the underlying filesystem is noexec
93857 * mounted, in which case we dont add PROT_EXEC.)
93858 */
93859- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
93860+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
93861 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
93862 prot |= PROT_EXEC;
93863
93864@@ -1263,7 +1347,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93865 /* Obtain the address to map to. we verify (or select) it and ensure
93866 * that it represents a valid section of the address space.
93867 */
93868- addr = get_unmapped_area(file, addr, len, pgoff, flags);
93869+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
93870 if (addr & ~PAGE_MASK)
93871 return addr;
93872
93873@@ -1274,6 +1358,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93874 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
93875 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
93876
93877+#ifdef CONFIG_PAX_MPROTECT
93878+ if (mm->pax_flags & MF_PAX_MPROTECT) {
93879+
93880+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
93881+ if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
93882+ mm->binfmt->handle_mmap)
93883+ mm->binfmt->handle_mmap(file);
93884+#endif
93885+
93886+#ifndef CONFIG_PAX_MPROTECT_COMPAT
93887+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
93888+ gr_log_rwxmmap(file);
93889+
93890+#ifdef CONFIG_PAX_EMUPLT
93891+ vm_flags &= ~VM_EXEC;
93892+#else
93893+ return -EPERM;
93894+#endif
93895+
93896+ }
93897+
93898+ if (!(vm_flags & VM_EXEC))
93899+ vm_flags &= ~VM_MAYEXEC;
93900+#else
93901+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
93902+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
93903+#endif
93904+ else
93905+ vm_flags &= ~VM_MAYWRITE;
93906+ }
93907+#endif
93908+
93909+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
93910+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
93911+ vm_flags &= ~VM_PAGEEXEC;
93912+#endif
93913+
93914 if (flags & MAP_LOCKED)
93915 if (!can_do_mlock())
93916 return -EPERM;
93917@@ -1361,6 +1482,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93918 vm_flags |= VM_NORESERVE;
93919 }
93920
93921+ if (!gr_acl_handle_mmap(file, prot))
93922+ return -EACCES;
93923+
93924 addr = mmap_region(file, addr, len, vm_flags, pgoff);
93925 if (!IS_ERR_VALUE(addr) &&
93926 ((vm_flags & VM_LOCKED) ||
93927@@ -1454,7 +1578,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
93928 vm_flags_t vm_flags = vma->vm_flags;
93929
93930 /* If it was private or non-writable, the write bit is already clear */
93931- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
93932+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
93933 return 0;
93934
93935 /* The backer wishes to know when pages are first written to? */
93936@@ -1500,7 +1624,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
93937 struct rb_node **rb_link, *rb_parent;
93938 unsigned long charged = 0;
93939
93940+#ifdef CONFIG_PAX_SEGMEXEC
93941+ struct vm_area_struct *vma_m = NULL;
93942+#endif
93943+
93944+ /*
93945+ * mm->mmap_sem is required to protect against another thread
93946+ * changing the mappings in case we sleep.
93947+ */
93948+ verify_mm_writelocked(mm);
93949+
93950 /* Check against address space limit. */
93951+
93952+#ifdef CONFIG_PAX_RANDMMAP
93953+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
93954+#endif
93955+
93956 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
93957 unsigned long nr_pages;
93958
93959@@ -1519,11 +1658,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
93960
93961 /* Clear old maps */
93962 error = -ENOMEM;
93963-munmap_back:
93964 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
93965 if (do_munmap(mm, addr, len))
93966 return -ENOMEM;
93967- goto munmap_back;
93968+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
93969 }
93970
93971 /*
93972@@ -1554,6 +1692,16 @@ munmap_back:
93973 goto unacct_error;
93974 }
93975
93976+#ifdef CONFIG_PAX_SEGMEXEC
93977+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
93978+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
93979+ if (!vma_m) {
93980+ error = -ENOMEM;
93981+ goto free_vma;
93982+ }
93983+ }
93984+#endif
93985+
93986 vma->vm_mm = mm;
93987 vma->vm_start = addr;
93988 vma->vm_end = addr + len;
93989@@ -1573,6 +1721,13 @@ munmap_back:
93990 if (error)
93991 goto unmap_and_free_vma;
93992
93993+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
93994+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
93995+ vma->vm_flags |= VM_PAGEEXEC;
93996+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
93997+ }
93998+#endif
93999+
94000 /* Can addr have changed??
94001 *
94002 * Answer: Yes, several device drivers can do it in their
94003@@ -1606,6 +1761,12 @@ munmap_back:
94004 }
94005
94006 vma_link(mm, vma, prev, rb_link, rb_parent);
94007+
94008+#ifdef CONFIG_PAX_SEGMEXEC
94009+ if (vma_m)
94010+ BUG_ON(pax_mirror_vma(vma_m, vma));
94011+#endif
94012+
94013 /* Once vma denies write, undo our temporary denial count */
94014 if (vm_flags & VM_DENYWRITE)
94015 allow_write_access(file);
94016@@ -1614,6 +1775,7 @@ out:
94017 perf_event_mmap(vma);
94018
94019 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
94020+ track_exec_limit(mm, addr, addr + len, vm_flags);
94021 if (vm_flags & VM_LOCKED) {
94022 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
94023 vma == get_gate_vma(current->mm)))
94024@@ -1646,6 +1808,12 @@ unmap_and_free_vma:
94025 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
94026 charged = 0;
94027 free_vma:
94028+
94029+#ifdef CONFIG_PAX_SEGMEXEC
94030+ if (vma_m)
94031+ kmem_cache_free(vm_area_cachep, vma_m);
94032+#endif
94033+
94034 kmem_cache_free(vm_area_cachep, vma);
94035 unacct_error:
94036 if (charged)
94037@@ -1653,7 +1821,63 @@ unacct_error:
94038 return error;
94039 }
94040
94041-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
94042+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
94043+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
94044+{
94045+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
94046+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
94047+
94048+ return 0;
94049+}
94050+#endif
94051+
94052+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
94053+{
94054+ if (!vma) {
94055+#ifdef CONFIG_STACK_GROWSUP
94056+ if (addr > sysctl_heap_stack_gap)
94057+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
94058+ else
94059+ vma = find_vma(current->mm, 0);
94060+ if (vma && (vma->vm_flags & VM_GROWSUP))
94061+ return false;
94062+#endif
94063+ return true;
94064+ }
94065+
94066+ if (addr + len > vma->vm_start)
94067+ return false;
94068+
94069+ if (vma->vm_flags & VM_GROWSDOWN)
94070+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
94071+#ifdef CONFIG_STACK_GROWSUP
94072+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
94073+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
94074+#endif
94075+ else if (offset)
94076+ return offset <= vma->vm_start - addr - len;
94077+
94078+ return true;
94079+}
94080+
94081+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
94082+{
94083+ if (vma->vm_start < len)
94084+ return -ENOMEM;
94085+
94086+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
94087+ if (offset <= vma->vm_start - len)
94088+ return vma->vm_start - len - offset;
94089+ else
94090+ return -ENOMEM;
94091+ }
94092+
94093+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
94094+ return vma->vm_start - len - sysctl_heap_stack_gap;
94095+ return -ENOMEM;
94096+}
94097+
94098+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
94099 {
94100 /*
94101 * We implement the search by looking for an rbtree node that
94102@@ -1701,11 +1925,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
94103 }
94104 }
94105
94106- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
94107+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
94108 check_current:
94109 /* Check if current node has a suitable gap */
94110 if (gap_start > high_limit)
94111 return -ENOMEM;
94112+
94113+ if (gap_end - gap_start > info->threadstack_offset)
94114+ gap_start += info->threadstack_offset;
94115+ else
94116+ gap_start = gap_end;
94117+
94118+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
94119+ if (gap_end - gap_start > sysctl_heap_stack_gap)
94120+ gap_start += sysctl_heap_stack_gap;
94121+ else
94122+ gap_start = gap_end;
94123+ }
94124+ if (vma->vm_flags & VM_GROWSDOWN) {
94125+ if (gap_end - gap_start > sysctl_heap_stack_gap)
94126+ gap_end -= sysctl_heap_stack_gap;
94127+ else
94128+ gap_end = gap_start;
94129+ }
94130 if (gap_end >= low_limit && gap_end - gap_start >= length)
94131 goto found;
94132
94133@@ -1755,7 +1997,7 @@ found:
94134 return gap_start;
94135 }
94136
94137-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
94138+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
94139 {
94140 struct mm_struct *mm = current->mm;
94141 struct vm_area_struct *vma;
94142@@ -1809,6 +2051,24 @@ check_current:
94143 gap_end = vma->vm_start;
94144 if (gap_end < low_limit)
94145 return -ENOMEM;
94146+
94147+ if (gap_end - gap_start > info->threadstack_offset)
94148+ gap_end -= info->threadstack_offset;
94149+ else
94150+ gap_end = gap_start;
94151+
94152+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
94153+ if (gap_end - gap_start > sysctl_heap_stack_gap)
94154+ gap_start += sysctl_heap_stack_gap;
94155+ else
94156+ gap_start = gap_end;
94157+ }
94158+ if (vma->vm_flags & VM_GROWSDOWN) {
94159+ if (gap_end - gap_start > sysctl_heap_stack_gap)
94160+ gap_end -= sysctl_heap_stack_gap;
94161+ else
94162+ gap_end = gap_start;
94163+ }
94164 if (gap_start <= high_limit && gap_end - gap_start >= length)
94165 goto found;
94166
94167@@ -1872,6 +2132,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94168 struct mm_struct *mm = current->mm;
94169 struct vm_area_struct *vma;
94170 struct vm_unmapped_area_info info;
94171+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
94172
94173 if (len > TASK_SIZE - mmap_min_addr)
94174 return -ENOMEM;
94175@@ -1879,11 +2140,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94176 if (flags & MAP_FIXED)
94177 return addr;
94178
94179+#ifdef CONFIG_PAX_RANDMMAP
94180+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
94181+#endif
94182+
94183 if (addr) {
94184 addr = PAGE_ALIGN(addr);
94185 vma = find_vma(mm, addr);
94186 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
94187- (!vma || addr + len <= vma->vm_start))
94188+ check_heap_stack_gap(vma, addr, len, offset))
94189 return addr;
94190 }
94191
94192@@ -1892,6 +2157,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94193 info.low_limit = mm->mmap_base;
94194 info.high_limit = TASK_SIZE;
94195 info.align_mask = 0;
94196+ info.threadstack_offset = offset;
94197 return vm_unmapped_area(&info);
94198 }
94199 #endif
94200@@ -1910,6 +2176,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94201 struct mm_struct *mm = current->mm;
94202 unsigned long addr = addr0;
94203 struct vm_unmapped_area_info info;
94204+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
94205
94206 /* requested length too big for entire address space */
94207 if (len > TASK_SIZE - mmap_min_addr)
94208@@ -1918,12 +2185,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94209 if (flags & MAP_FIXED)
94210 return addr;
94211
94212+#ifdef CONFIG_PAX_RANDMMAP
94213+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
94214+#endif
94215+
94216 /* requesting a specific address */
94217 if (addr) {
94218 addr = PAGE_ALIGN(addr);
94219 vma = find_vma(mm, addr);
94220 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
94221- (!vma || addr + len <= vma->vm_start))
94222+ check_heap_stack_gap(vma, addr, len, offset))
94223 return addr;
94224 }
94225
94226@@ -1932,6 +2203,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94227 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
94228 info.high_limit = mm->mmap_base;
94229 info.align_mask = 0;
94230+ info.threadstack_offset = offset;
94231 addr = vm_unmapped_area(&info);
94232
94233 /*
94234@@ -1944,6 +2216,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94235 VM_BUG_ON(addr != -ENOMEM);
94236 info.flags = 0;
94237 info.low_limit = TASK_UNMAPPED_BASE;
94238+
94239+#ifdef CONFIG_PAX_RANDMMAP
94240+ if (mm->pax_flags & MF_PAX_RANDMMAP)
94241+ info.low_limit += mm->delta_mmap;
94242+#endif
94243+
94244 info.high_limit = TASK_SIZE;
94245 addr = vm_unmapped_area(&info);
94246 }
94247@@ -2045,6 +2323,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
94248 return vma;
94249 }
94250
94251+#ifdef CONFIG_PAX_SEGMEXEC
94252+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
94253+{
94254+ struct vm_area_struct *vma_m;
94255+
94256+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
94257+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
94258+ BUG_ON(vma->vm_mirror);
94259+ return NULL;
94260+ }
94261+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
94262+ vma_m = vma->vm_mirror;
94263+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
94264+ BUG_ON(vma->vm_file != vma_m->vm_file);
94265+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
94266+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
94267+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
94268+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
94269+ return vma_m;
94270+}
94271+#endif
94272+
94273 /*
94274 * Verify that the stack growth is acceptable and
94275 * update accounting. This is shared with both the
94276@@ -2061,6 +2361,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
94277 return -ENOMEM;
94278
94279 /* Stack limit test */
94280+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
94281 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
94282 return -ENOMEM;
94283
94284@@ -2071,6 +2372,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
94285 locked = mm->locked_vm + grow;
94286 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
94287 limit >>= PAGE_SHIFT;
94288+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
94289 if (locked > limit && !capable(CAP_IPC_LOCK))
94290 return -ENOMEM;
94291 }
94292@@ -2100,37 +2402,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
94293 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
94294 * vma is the last one with address > vma->vm_end. Have to extend vma.
94295 */
94296+#ifndef CONFIG_IA64
94297+static
94298+#endif
94299 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
94300 {
94301 int error;
94302+ bool locknext;
94303
94304 if (!(vma->vm_flags & VM_GROWSUP))
94305 return -EFAULT;
94306
94307+ /* Also guard against wrapping around to address 0. */
94308+ if (address < PAGE_ALIGN(address+1))
94309+ address = PAGE_ALIGN(address+1);
94310+ else
94311+ return -ENOMEM;
94312+
94313 /*
94314 * We must make sure the anon_vma is allocated
94315 * so that the anon_vma locking is not a noop.
94316 */
94317 if (unlikely(anon_vma_prepare(vma)))
94318 return -ENOMEM;
94319+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
94320+ if (locknext && anon_vma_prepare(vma->vm_next))
94321+ return -ENOMEM;
94322 vma_lock_anon_vma(vma);
94323+ if (locknext)
94324+ vma_lock_anon_vma(vma->vm_next);
94325
94326 /*
94327 * vma->vm_start/vm_end cannot change under us because the caller
94328 * is required to hold the mmap_sem in read mode. We need the
94329- * anon_vma lock to serialize against concurrent expand_stacks.
94330- * Also guard against wrapping around to address 0.
94331+ * anon_vma locks to serialize against concurrent expand_stacks
94332+ * and expand_upwards.
94333 */
94334- if (address < PAGE_ALIGN(address+4))
94335- address = PAGE_ALIGN(address+4);
94336- else {
94337- vma_unlock_anon_vma(vma);
94338- return -ENOMEM;
94339- }
94340 error = 0;
94341
94342 /* Somebody else might have raced and expanded it already */
94343- if (address > vma->vm_end) {
94344+ 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)
94345+ error = -ENOMEM;
94346+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
94347 unsigned long size, grow;
94348
94349 size = address - vma->vm_start;
94350@@ -2165,6 +2478,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
94351 }
94352 }
94353 }
94354+ if (locknext)
94355+ vma_unlock_anon_vma(vma->vm_next);
94356 vma_unlock_anon_vma(vma);
94357 khugepaged_enter_vma_merge(vma);
94358 validate_mm(vma->vm_mm);
94359@@ -2179,6 +2494,8 @@ int expand_downwards(struct vm_area_struct *vma,
94360 unsigned long address)
94361 {
94362 int error;
94363+ bool lockprev = false;
94364+ struct vm_area_struct *prev;
94365
94366 /*
94367 * We must make sure the anon_vma is allocated
94368@@ -2192,6 +2509,15 @@ int expand_downwards(struct vm_area_struct *vma,
94369 if (error)
94370 return error;
94371
94372+ prev = vma->vm_prev;
94373+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
94374+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
94375+#endif
94376+ if (lockprev && anon_vma_prepare(prev))
94377+ return -ENOMEM;
94378+ if (lockprev)
94379+ vma_lock_anon_vma(prev);
94380+
94381 vma_lock_anon_vma(vma);
94382
94383 /*
94384@@ -2201,9 +2527,17 @@ int expand_downwards(struct vm_area_struct *vma,
94385 */
94386
94387 /* Somebody else might have raced and expanded it already */
94388- if (address < vma->vm_start) {
94389+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
94390+ error = -ENOMEM;
94391+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
94392 unsigned long size, grow;
94393
94394+#ifdef CONFIG_PAX_SEGMEXEC
94395+ struct vm_area_struct *vma_m;
94396+
94397+ vma_m = pax_find_mirror_vma(vma);
94398+#endif
94399+
94400 size = vma->vm_end - address;
94401 grow = (vma->vm_start - address) >> PAGE_SHIFT;
94402
94403@@ -2228,13 +2562,27 @@ int expand_downwards(struct vm_area_struct *vma,
94404 vma->vm_pgoff -= grow;
94405 anon_vma_interval_tree_post_update_vma(vma);
94406 vma_gap_update(vma);
94407+
94408+#ifdef CONFIG_PAX_SEGMEXEC
94409+ if (vma_m) {
94410+ anon_vma_interval_tree_pre_update_vma(vma_m);
94411+ vma_m->vm_start -= grow << PAGE_SHIFT;
94412+ vma_m->vm_pgoff -= grow;
94413+ anon_vma_interval_tree_post_update_vma(vma_m);
94414+ vma_gap_update(vma_m);
94415+ }
94416+#endif
94417+
94418 spin_unlock(&vma->vm_mm->page_table_lock);
94419
94420+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
94421 perf_event_mmap(vma);
94422 }
94423 }
94424 }
94425 vma_unlock_anon_vma(vma);
94426+ if (lockprev)
94427+ vma_unlock_anon_vma(prev);
94428 khugepaged_enter_vma_merge(vma);
94429 validate_mm(vma->vm_mm);
94430 return error;
94431@@ -2332,6 +2680,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
94432 do {
94433 long nrpages = vma_pages(vma);
94434
94435+#ifdef CONFIG_PAX_SEGMEXEC
94436+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
94437+ vma = remove_vma(vma);
94438+ continue;
94439+ }
94440+#endif
94441+
94442 if (vma->vm_flags & VM_ACCOUNT)
94443 nr_accounted += nrpages;
94444 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
94445@@ -2376,6 +2731,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
94446 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
94447 vma->vm_prev = NULL;
94448 do {
94449+
94450+#ifdef CONFIG_PAX_SEGMEXEC
94451+ if (vma->vm_mirror) {
94452+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
94453+ vma->vm_mirror->vm_mirror = NULL;
94454+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
94455+ vma->vm_mirror = NULL;
94456+ }
94457+#endif
94458+
94459 vma_rb_erase(vma, &mm->mm_rb);
94460 mm->map_count--;
94461 tail_vma = vma;
94462@@ -2401,14 +2766,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94463 struct vm_area_struct *new;
94464 int err = -ENOMEM;
94465
94466+#ifdef CONFIG_PAX_SEGMEXEC
94467+ struct vm_area_struct *vma_m, *new_m = NULL;
94468+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
94469+#endif
94470+
94471 if (is_vm_hugetlb_page(vma) && (addr &
94472 ~(huge_page_mask(hstate_vma(vma)))))
94473 return -EINVAL;
94474
94475+#ifdef CONFIG_PAX_SEGMEXEC
94476+ vma_m = pax_find_mirror_vma(vma);
94477+#endif
94478+
94479 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
94480 if (!new)
94481 goto out_err;
94482
94483+#ifdef CONFIG_PAX_SEGMEXEC
94484+ if (vma_m) {
94485+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
94486+ if (!new_m) {
94487+ kmem_cache_free(vm_area_cachep, new);
94488+ goto out_err;
94489+ }
94490+ }
94491+#endif
94492+
94493 /* most fields are the same, copy all, and then fixup */
94494 *new = *vma;
94495
94496@@ -2421,6 +2805,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94497 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
94498 }
94499
94500+#ifdef CONFIG_PAX_SEGMEXEC
94501+ if (vma_m) {
94502+ *new_m = *vma_m;
94503+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
94504+ new_m->vm_mirror = new;
94505+ new->vm_mirror = new_m;
94506+
94507+ if (new_below)
94508+ new_m->vm_end = addr_m;
94509+ else {
94510+ new_m->vm_start = addr_m;
94511+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
94512+ }
94513+ }
94514+#endif
94515+
94516 err = vma_dup_policy(vma, new);
94517 if (err)
94518 goto out_free_vma;
94519@@ -2440,6 +2840,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94520 else
94521 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
94522
94523+#ifdef CONFIG_PAX_SEGMEXEC
94524+ if (!err && vma_m) {
94525+ struct mempolicy *pol = vma_policy(new);
94526+
94527+ if (anon_vma_clone(new_m, vma_m))
94528+ goto out_free_mpol;
94529+
94530+ mpol_get(pol);
94531+ set_vma_policy(new_m, pol);
94532+
94533+ if (new_m->vm_file)
94534+ get_file(new_m->vm_file);
94535+
94536+ if (new_m->vm_ops && new_m->vm_ops->open)
94537+ new_m->vm_ops->open(new_m);
94538+
94539+ if (new_below)
94540+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
94541+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
94542+ else
94543+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
94544+
94545+ if (err) {
94546+ if (new_m->vm_ops && new_m->vm_ops->close)
94547+ new_m->vm_ops->close(new_m);
94548+ if (new_m->vm_file)
94549+ fput(new_m->vm_file);
94550+ mpol_put(pol);
94551+ }
94552+ }
94553+#endif
94554+
94555 /* Success. */
94556 if (!err)
94557 return 0;
94558@@ -2449,10 +2881,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94559 new->vm_ops->close(new);
94560 if (new->vm_file)
94561 fput(new->vm_file);
94562- unlink_anon_vmas(new);
94563 out_free_mpol:
94564 mpol_put(vma_policy(new));
94565 out_free_vma:
94566+
94567+#ifdef CONFIG_PAX_SEGMEXEC
94568+ if (new_m) {
94569+ unlink_anon_vmas(new_m);
94570+ kmem_cache_free(vm_area_cachep, new_m);
94571+ }
94572+#endif
94573+
94574+ unlink_anon_vmas(new);
94575 kmem_cache_free(vm_area_cachep, new);
94576 out_err:
94577 return err;
94578@@ -2465,6 +2905,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94579 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
94580 unsigned long addr, int new_below)
94581 {
94582+
94583+#ifdef CONFIG_PAX_SEGMEXEC
94584+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
94585+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
94586+ if (mm->map_count >= sysctl_max_map_count-1)
94587+ return -ENOMEM;
94588+ } else
94589+#endif
94590+
94591 if (mm->map_count >= sysctl_max_map_count)
94592 return -ENOMEM;
94593
94594@@ -2476,11 +2925,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
94595 * work. This now handles partial unmappings.
94596 * Jeremy Fitzhardinge <jeremy@goop.org>
94597 */
94598+#ifdef CONFIG_PAX_SEGMEXEC
94599 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94600 {
94601+ int ret = __do_munmap(mm, start, len);
94602+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
94603+ return ret;
94604+
94605+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
94606+}
94607+
94608+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94609+#else
94610+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94611+#endif
94612+{
94613 unsigned long end;
94614 struct vm_area_struct *vma, *prev, *last;
94615
94616+ /*
94617+ * mm->mmap_sem is required to protect against another thread
94618+ * changing the mappings in case we sleep.
94619+ */
94620+ verify_mm_writelocked(mm);
94621+
94622 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
94623 return -EINVAL;
94624
94625@@ -2555,6 +3023,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94626 /* Fix up all other VM information */
94627 remove_vma_list(mm, vma);
94628
94629+ track_exec_limit(mm, start, end, 0UL);
94630+
94631 return 0;
94632 }
94633
94634@@ -2563,6 +3033,13 @@ int vm_munmap(unsigned long start, size_t len)
94635 int ret;
94636 struct mm_struct *mm = current->mm;
94637
94638+
94639+#ifdef CONFIG_PAX_SEGMEXEC
94640+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
94641+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
94642+ return -EINVAL;
94643+#endif
94644+
94645 down_write(&mm->mmap_sem);
94646 ret = do_munmap(mm, start, len);
94647 up_write(&mm->mmap_sem);
94648@@ -2576,16 +3053,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
94649 return vm_munmap(addr, len);
94650 }
94651
94652-static inline void verify_mm_writelocked(struct mm_struct *mm)
94653-{
94654-#ifdef CONFIG_DEBUG_VM
94655- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
94656- WARN_ON(1);
94657- up_read(&mm->mmap_sem);
94658- }
94659-#endif
94660-}
94661-
94662 /*
94663 * this is really a simplified "do_mmap". it only handles
94664 * anonymous maps. eventually we may be able to do some
94665@@ -2599,6 +3066,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94666 struct rb_node ** rb_link, * rb_parent;
94667 pgoff_t pgoff = addr >> PAGE_SHIFT;
94668 int error;
94669+ unsigned long charged;
94670
94671 len = PAGE_ALIGN(len);
94672 if (!len)
94673@@ -2606,10 +3074,24 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94674
94675 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
94676
94677+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
94678+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
94679+ flags &= ~VM_EXEC;
94680+
94681+#ifdef CONFIG_PAX_MPROTECT
94682+ if (mm->pax_flags & MF_PAX_MPROTECT)
94683+ flags &= ~VM_MAYEXEC;
94684+#endif
94685+
94686+ }
94687+#endif
94688+
94689 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
94690 if (error & ~PAGE_MASK)
94691 return error;
94692
94693+ charged = len >> PAGE_SHIFT;
94694+
94695 error = mlock_future_check(mm, mm->def_flags, len);
94696 if (error)
94697 return error;
94698@@ -2623,21 +3105,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94699 /*
94700 * Clear old maps. this also does some error checking for us
94701 */
94702- munmap_back:
94703 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
94704 if (do_munmap(mm, addr, len))
94705 return -ENOMEM;
94706- goto munmap_back;
94707+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
94708 }
94709
94710 /* Check against address space limits *after* clearing old maps... */
94711- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
94712+ if (!may_expand_vm(mm, charged))
94713 return -ENOMEM;
94714
94715 if (mm->map_count > sysctl_max_map_count)
94716 return -ENOMEM;
94717
94718- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
94719+ if (security_vm_enough_memory_mm(mm, charged))
94720 return -ENOMEM;
94721
94722 /* Can we just expand an old private anonymous mapping? */
94723@@ -2651,7 +3132,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94724 */
94725 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94726 if (!vma) {
94727- vm_unacct_memory(len >> PAGE_SHIFT);
94728+ vm_unacct_memory(charged);
94729 return -ENOMEM;
94730 }
94731
94732@@ -2665,10 +3146,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94733 vma_link(mm, vma, prev, rb_link, rb_parent);
94734 out:
94735 perf_event_mmap(vma);
94736- mm->total_vm += len >> PAGE_SHIFT;
94737+ mm->total_vm += charged;
94738 if (flags & VM_LOCKED)
94739- mm->locked_vm += (len >> PAGE_SHIFT);
94740+ mm->locked_vm += charged;
94741 vma->vm_flags |= VM_SOFTDIRTY;
94742+ track_exec_limit(mm, addr, addr + len, flags);
94743 return addr;
94744 }
94745
94746@@ -2730,6 +3212,7 @@ void exit_mmap(struct mm_struct *mm)
94747 while (vma) {
94748 if (vma->vm_flags & VM_ACCOUNT)
94749 nr_accounted += vma_pages(vma);
94750+ vma->vm_mirror = NULL;
94751 vma = remove_vma(vma);
94752 }
94753 vm_unacct_memory(nr_accounted);
94754@@ -2747,6 +3230,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
94755 struct vm_area_struct *prev;
94756 struct rb_node **rb_link, *rb_parent;
94757
94758+#ifdef CONFIG_PAX_SEGMEXEC
94759+ struct vm_area_struct *vma_m = NULL;
94760+#endif
94761+
94762+ if (security_mmap_addr(vma->vm_start))
94763+ return -EPERM;
94764+
94765 /*
94766 * The vm_pgoff of a purely anonymous vma should be irrelevant
94767 * until its first write fault, when page's anon_vma and index
94768@@ -2770,7 +3260,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
94769 security_vm_enough_memory_mm(mm, vma_pages(vma)))
94770 return -ENOMEM;
94771
94772+#ifdef CONFIG_PAX_SEGMEXEC
94773+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
94774+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94775+ if (!vma_m)
94776+ return -ENOMEM;
94777+ }
94778+#endif
94779+
94780 vma_link(mm, vma, prev, rb_link, rb_parent);
94781+
94782+#ifdef CONFIG_PAX_SEGMEXEC
94783+ if (vma_m)
94784+ BUG_ON(pax_mirror_vma(vma_m, vma));
94785+#endif
94786+
94787 return 0;
94788 }
94789
94790@@ -2789,6 +3293,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
94791 struct rb_node **rb_link, *rb_parent;
94792 bool faulted_in_anon_vma = true;
94793
94794+ BUG_ON(vma->vm_mirror);
94795+
94796 /*
94797 * If anonymous vma has not yet been faulted, update new pgoff
94798 * to match new location, to increase its chance of merging.
94799@@ -2853,6 +3359,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
94800 return NULL;
94801 }
94802
94803+#ifdef CONFIG_PAX_SEGMEXEC
94804+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
94805+{
94806+ struct vm_area_struct *prev_m;
94807+ struct rb_node **rb_link_m, *rb_parent_m;
94808+ struct mempolicy *pol_m;
94809+
94810+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
94811+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
94812+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
94813+ *vma_m = *vma;
94814+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
94815+ if (anon_vma_clone(vma_m, vma))
94816+ return -ENOMEM;
94817+ pol_m = vma_policy(vma_m);
94818+ mpol_get(pol_m);
94819+ set_vma_policy(vma_m, pol_m);
94820+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
94821+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
94822+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
94823+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
94824+ if (vma_m->vm_file)
94825+ get_file(vma_m->vm_file);
94826+ if (vma_m->vm_ops && vma_m->vm_ops->open)
94827+ vma_m->vm_ops->open(vma_m);
94828+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
94829+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
94830+ vma_m->vm_mirror = vma;
94831+ vma->vm_mirror = vma_m;
94832+ return 0;
94833+}
94834+#endif
94835+
94836 /*
94837 * Return true if the calling process may expand its vm space by the passed
94838 * number of pages
94839@@ -2864,6 +3403,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
94840
94841 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
94842
94843+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
94844 if (cur + npages > lim)
94845 return 0;
94846 return 1;
94847@@ -2934,6 +3474,22 @@ int install_special_mapping(struct mm_struct *mm,
94848 vma->vm_start = addr;
94849 vma->vm_end = addr + len;
94850
94851+#ifdef CONFIG_PAX_MPROTECT
94852+ if (mm->pax_flags & MF_PAX_MPROTECT) {
94853+#ifndef CONFIG_PAX_MPROTECT_COMPAT
94854+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
94855+ return -EPERM;
94856+ if (!(vm_flags & VM_EXEC))
94857+ vm_flags &= ~VM_MAYEXEC;
94858+#else
94859+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
94860+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
94861+#endif
94862+ else
94863+ vm_flags &= ~VM_MAYWRITE;
94864+ }
94865+#endif
94866+
94867 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
94868 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
94869
94870diff --git a/mm/mprotect.c b/mm/mprotect.c
94871index 769a67a..414d24f 100644
94872--- a/mm/mprotect.c
94873+++ b/mm/mprotect.c
94874@@ -24,10 +24,18 @@
94875 #include <linux/migrate.h>
94876 #include <linux/perf_event.h>
94877 #include <linux/ksm.h>
94878+#include <linux/sched/sysctl.h>
94879+
94880+#ifdef CONFIG_PAX_MPROTECT
94881+#include <linux/elf.h>
94882+#include <linux/binfmts.h>
94883+#endif
94884+
94885 #include <asm/uaccess.h>
94886 #include <asm/pgtable.h>
94887 #include <asm/cacheflush.h>
94888 #include <asm/tlbflush.h>
94889+#include <asm/mmu_context.h>
94890
94891 #ifndef pgprot_modify
94892 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
94893@@ -214,6 +222,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
94894 return pages;
94895 }
94896
94897+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
94898+/* called while holding the mmap semaphor for writing except stack expansion */
94899+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
94900+{
94901+ unsigned long oldlimit, newlimit = 0UL;
94902+
94903+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
94904+ return;
94905+
94906+ spin_lock(&mm->page_table_lock);
94907+ oldlimit = mm->context.user_cs_limit;
94908+ if ((prot & VM_EXEC) && oldlimit < end)
94909+ /* USER_CS limit moved up */
94910+ newlimit = end;
94911+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
94912+ /* USER_CS limit moved down */
94913+ newlimit = start;
94914+
94915+ if (newlimit) {
94916+ mm->context.user_cs_limit = newlimit;
94917+
94918+#ifdef CONFIG_SMP
94919+ wmb();
94920+ cpus_clear(mm->context.cpu_user_cs_mask);
94921+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
94922+#endif
94923+
94924+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
94925+ }
94926+ spin_unlock(&mm->page_table_lock);
94927+ if (newlimit == end) {
94928+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
94929+
94930+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
94931+ if (is_vm_hugetlb_page(vma))
94932+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
94933+ else
94934+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
94935+ }
94936+}
94937+#endif
94938+
94939 int
94940 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
94941 unsigned long start, unsigned long end, unsigned long newflags)
94942@@ -226,11 +276,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
94943 int error;
94944 int dirty_accountable = 0;
94945
94946+#ifdef CONFIG_PAX_SEGMEXEC
94947+ struct vm_area_struct *vma_m = NULL;
94948+ unsigned long start_m, end_m;
94949+
94950+ start_m = start + SEGMEXEC_TASK_SIZE;
94951+ end_m = end + SEGMEXEC_TASK_SIZE;
94952+#endif
94953+
94954 if (newflags == oldflags) {
94955 *pprev = vma;
94956 return 0;
94957 }
94958
94959+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
94960+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
94961+
94962+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
94963+ return -ENOMEM;
94964+
94965+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
94966+ return -ENOMEM;
94967+ }
94968+
94969 /*
94970 * If we make a private mapping writable we increase our commit;
94971 * but (without finer accounting) cannot reduce our commit if we
94972@@ -247,6 +315,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
94973 }
94974 }
94975
94976+#ifdef CONFIG_PAX_SEGMEXEC
94977+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
94978+ if (start != vma->vm_start) {
94979+ error = split_vma(mm, vma, start, 1);
94980+ if (error)
94981+ goto fail;
94982+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
94983+ *pprev = (*pprev)->vm_next;
94984+ }
94985+
94986+ if (end != vma->vm_end) {
94987+ error = split_vma(mm, vma, end, 0);
94988+ if (error)
94989+ goto fail;
94990+ }
94991+
94992+ if (pax_find_mirror_vma(vma)) {
94993+ error = __do_munmap(mm, start_m, end_m - start_m);
94994+ if (error)
94995+ goto fail;
94996+ } else {
94997+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94998+ if (!vma_m) {
94999+ error = -ENOMEM;
95000+ goto fail;
95001+ }
95002+ vma->vm_flags = newflags;
95003+ error = pax_mirror_vma(vma_m, vma);
95004+ if (error) {
95005+ vma->vm_flags = oldflags;
95006+ goto fail;
95007+ }
95008+ }
95009+ }
95010+#endif
95011+
95012 /*
95013 * First try to merge with previous and/or next vma.
95014 */
95015@@ -277,9 +381,21 @@ success:
95016 * vm_flags and vm_page_prot are protected by the mmap_sem
95017 * held in write mode.
95018 */
95019+
95020+#ifdef CONFIG_PAX_SEGMEXEC
95021+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
95022+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
95023+#endif
95024+
95025 vma->vm_flags = newflags;
95026+
95027+#ifdef CONFIG_PAX_MPROTECT
95028+ if (mm->binfmt && mm->binfmt->handle_mprotect)
95029+ mm->binfmt->handle_mprotect(vma, newflags);
95030+#endif
95031+
95032 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
95033- vm_get_page_prot(newflags));
95034+ vm_get_page_prot(vma->vm_flags));
95035
95036 if (vma_wants_writenotify(vma)) {
95037 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
95038@@ -318,6 +434,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95039 end = start + len;
95040 if (end <= start)
95041 return -ENOMEM;
95042+
95043+#ifdef CONFIG_PAX_SEGMEXEC
95044+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
95045+ if (end > SEGMEXEC_TASK_SIZE)
95046+ return -EINVAL;
95047+ } else
95048+#endif
95049+
95050+ if (end > TASK_SIZE)
95051+ return -EINVAL;
95052+
95053 if (!arch_validate_prot(prot))
95054 return -EINVAL;
95055
95056@@ -325,7 +452,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95057 /*
95058 * Does the application expect PROT_READ to imply PROT_EXEC:
95059 */
95060- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
95061+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
95062 prot |= PROT_EXEC;
95063
95064 vm_flags = calc_vm_prot_bits(prot);
95065@@ -357,6 +484,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95066 if (start > vma->vm_start)
95067 prev = vma;
95068
95069+#ifdef CONFIG_PAX_MPROTECT
95070+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
95071+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
95072+#endif
95073+
95074 for (nstart = start ; ; ) {
95075 unsigned long newflags;
95076
95077@@ -367,6 +499,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95078
95079 /* newflags >> 4 shift VM_MAY% in place of VM_% */
95080 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
95081+ if (prot & (PROT_WRITE | PROT_EXEC))
95082+ gr_log_rwxmprotect(vma);
95083+
95084+ error = -EACCES;
95085+ goto out;
95086+ }
95087+
95088+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
95089 error = -EACCES;
95090 goto out;
95091 }
95092@@ -381,6 +521,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95093 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
95094 if (error)
95095 goto out;
95096+
95097+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
95098+
95099 nstart = tmp;
95100
95101 if (nstart < prev->vm_end)
95102diff --git a/mm/mremap.c b/mm/mremap.c
95103index 0843feb..c3cde48 100644
95104--- a/mm/mremap.c
95105+++ b/mm/mremap.c
95106@@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
95107 continue;
95108 pte = ptep_get_and_clear(mm, old_addr, old_pte);
95109 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
95110+
95111+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
95112+ if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
95113+ pte = pte_exprotect(pte);
95114+#endif
95115+
95116 pte = move_soft_dirty_pte(pte);
95117 set_pte_at(mm, new_addr, new_pte, pte);
95118 }
95119@@ -194,10 +200,17 @@ unsigned long move_page_tables(struct vm_area_struct *vma,
95120 break;
95121 if (pmd_trans_huge(*old_pmd)) {
95122 int err = 0;
95123- if (extent == HPAGE_PMD_SIZE)
95124+ if (extent == HPAGE_PMD_SIZE) {
95125+ VM_BUG_ON(vma->vm_file || !vma->anon_vma);
95126+ /* See comment in move_ptes() */
95127+ if (need_rmap_locks)
95128+ anon_vma_lock_write(vma->anon_vma);
95129 err = move_huge_pmd(vma, new_vma, old_addr,
95130 new_addr, old_end,
95131 old_pmd, new_pmd);
95132+ if (need_rmap_locks)
95133+ anon_vma_unlock_write(vma->anon_vma);
95134+ }
95135 if (err > 0) {
95136 need_flush = true;
95137 continue;
95138@@ -337,6 +350,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
95139 if (is_vm_hugetlb_page(vma))
95140 goto Einval;
95141
95142+#ifdef CONFIG_PAX_SEGMEXEC
95143+ if (pax_find_mirror_vma(vma))
95144+ goto Einval;
95145+#endif
95146+
95147 /* We can't remap across vm area boundaries */
95148 if (old_len > vma->vm_end - addr)
95149 goto Efault;
95150@@ -392,20 +410,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
95151 unsigned long ret = -EINVAL;
95152 unsigned long charged = 0;
95153 unsigned long map_flags;
95154+ unsigned long pax_task_size = TASK_SIZE;
95155
95156 if (new_addr & ~PAGE_MASK)
95157 goto out;
95158
95159- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
95160+#ifdef CONFIG_PAX_SEGMEXEC
95161+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
95162+ pax_task_size = SEGMEXEC_TASK_SIZE;
95163+#endif
95164+
95165+ pax_task_size -= PAGE_SIZE;
95166+
95167+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
95168 goto out;
95169
95170 /* Check if the location we're moving into overlaps the
95171 * old location at all, and fail if it does.
95172 */
95173- if ((new_addr <= addr) && (new_addr+new_len) > addr)
95174- goto out;
95175-
95176- if ((addr <= new_addr) && (addr+old_len) > new_addr)
95177+ if (addr + old_len > new_addr && new_addr + new_len > addr)
95178 goto out;
95179
95180 ret = do_munmap(mm, new_addr, new_len);
95181@@ -474,6 +497,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95182 unsigned long ret = -EINVAL;
95183 unsigned long charged = 0;
95184 bool locked = false;
95185+ unsigned long pax_task_size = TASK_SIZE;
95186
95187 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
95188 return ret;
95189@@ -495,6 +519,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95190 if (!new_len)
95191 return ret;
95192
95193+#ifdef CONFIG_PAX_SEGMEXEC
95194+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
95195+ pax_task_size = SEGMEXEC_TASK_SIZE;
95196+#endif
95197+
95198+ pax_task_size -= PAGE_SIZE;
95199+
95200+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
95201+ old_len > pax_task_size || addr > pax_task_size-old_len)
95202+ return ret;
95203+
95204 down_write(&current->mm->mmap_sem);
95205
95206 if (flags & MREMAP_FIXED) {
95207@@ -545,6 +580,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95208 new_addr = addr;
95209 }
95210 ret = addr;
95211+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
95212 goto out;
95213 }
95214 }
95215@@ -568,7 +604,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95216 goto out;
95217 }
95218
95219+ map_flags = vma->vm_flags;
95220 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
95221+ if (!(ret & ~PAGE_MASK)) {
95222+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
95223+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
95224+ }
95225 }
95226 out:
95227 if (ret & ~PAGE_MASK)
95228diff --git a/mm/nommu.c b/mm/nommu.c
95229index 8740213..f87e25b 100644
95230--- a/mm/nommu.c
95231+++ b/mm/nommu.c
95232@@ -65,7 +65,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
95233 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
95234 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
95235 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
95236-int heap_stack_gap = 0;
95237
95238 atomic_long_t mmap_pages_allocated;
95239
95240@@ -845,15 +844,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
95241 EXPORT_SYMBOL(find_vma);
95242
95243 /*
95244- * find a VMA
95245- * - we don't extend stack VMAs under NOMMU conditions
95246- */
95247-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
95248-{
95249- return find_vma(mm, addr);
95250-}
95251-
95252-/*
95253 * expand a stack to a given address
95254 * - not supported under NOMMU conditions
95255 */
95256@@ -1564,6 +1554,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
95257
95258 /* most fields are the same, copy all, and then fixup */
95259 *new = *vma;
95260+ INIT_LIST_HEAD(&new->anon_vma_chain);
95261 *region = *vma->vm_region;
95262 new->vm_region = region;
95263
95264@@ -1993,8 +1984,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
95265 }
95266 EXPORT_SYMBOL(generic_file_remap_pages);
95267
95268-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95269- unsigned long addr, void *buf, int len, int write)
95270+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95271+ unsigned long addr, void *buf, size_t len, int write)
95272 {
95273 struct vm_area_struct *vma;
95274
95275@@ -2035,8 +2026,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95276 *
95277 * The caller must hold a reference on @mm.
95278 */
95279-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
95280- void *buf, int len, int write)
95281+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
95282+ void *buf, size_t len, int write)
95283 {
95284 return __access_remote_vm(NULL, mm, addr, buf, len, write);
95285 }
95286@@ -2045,7 +2036,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
95287 * Access another process' address space.
95288 * - source/target buffer must be kernel space
95289 */
95290-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
95291+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
95292 {
95293 struct mm_struct *mm;
95294
95295diff --git a/mm/page-writeback.c b/mm/page-writeback.c
95296index 7106cb1..0805f48 100644
95297--- a/mm/page-writeback.c
95298+++ b/mm/page-writeback.c
95299@@ -685,7 +685,7 @@ static inline long long pos_ratio_polynom(unsigned long setpoint,
95300 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
95301 * - the bdi dirty thresh drops quickly due to change of JBOD workload
95302 */
95303-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
95304+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
95305 unsigned long thresh,
95306 unsigned long bg_thresh,
95307 unsigned long dirty,
95308diff --git a/mm/page_alloc.c b/mm/page_alloc.c
95309index 7387a67..67105e4 100644
95310--- a/mm/page_alloc.c
95311+++ b/mm/page_alloc.c
95312@@ -61,6 +61,7 @@
95313 #include <linux/page-debug-flags.h>
95314 #include <linux/hugetlb.h>
95315 #include <linux/sched/rt.h>
95316+#include <linux/random.h>
95317
95318 #include <asm/sections.h>
95319 #include <asm/tlbflush.h>
95320@@ -354,7 +355,7 @@ out:
95321 * This usage means that zero-order pages may not be compound.
95322 */
95323
95324-static void free_compound_page(struct page *page)
95325+void free_compound_page(struct page *page)
95326 {
95327 __free_pages_ok(page, compound_order(page));
95328 }
95329@@ -728,6 +729,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
95330 int i;
95331 int bad = 0;
95332
95333+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95334+ unsigned long index = 1UL << order;
95335+#endif
95336+
95337 trace_mm_page_free(page, order);
95338 kmemcheck_free_shadow(page, order);
95339
95340@@ -744,6 +749,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
95341 debug_check_no_obj_freed(page_address(page),
95342 PAGE_SIZE << order);
95343 }
95344+
95345+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95346+ for (; index; --index)
95347+ sanitize_highpage(page + index - 1);
95348+#endif
95349+
95350 arch_free_page(page, order);
95351 kernel_map_pages(page, 1 << order, 0);
95352
95353@@ -766,6 +777,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
95354 local_irq_restore(flags);
95355 }
95356
95357+#ifdef CONFIG_PAX_LATENT_ENTROPY
95358+bool __meminitdata extra_latent_entropy;
95359+
95360+static int __init setup_pax_extra_latent_entropy(char *str)
95361+{
95362+ extra_latent_entropy = true;
95363+ return 0;
95364+}
95365+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
95366+
95367+volatile u64 latent_entropy __latent_entropy;
95368+EXPORT_SYMBOL(latent_entropy);
95369+#endif
95370+
95371 void __init __free_pages_bootmem(struct page *page, unsigned int order)
95372 {
95373 unsigned int nr_pages = 1 << order;
95374@@ -781,6 +806,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
95375 __ClearPageReserved(p);
95376 set_page_count(p, 0);
95377
95378+#ifdef CONFIG_PAX_LATENT_ENTROPY
95379+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
95380+ u64 hash = 0;
95381+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
95382+ const u64 *data = lowmem_page_address(page);
95383+
95384+ for (index = 0; index < end; index++)
95385+ hash ^= hash + data[index];
95386+ latent_entropy ^= hash;
95387+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
95388+ }
95389+#endif
95390+
95391 page_zone(page)->managed_pages += nr_pages;
95392 set_page_refcounted(page);
95393 __free_pages(page, order);
95394@@ -897,8 +935,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
95395 arch_alloc_page(page, order);
95396 kernel_map_pages(page, 1 << order, 1);
95397
95398+#ifndef CONFIG_PAX_MEMORY_SANITIZE
95399 if (gfp_flags & __GFP_ZERO)
95400 prep_zero_page(page, order, gfp_flags);
95401+#endif
95402
95403 if (order && (gfp_flags & __GFP_COMP))
95404 prep_compound_page(page, order);
95405@@ -2401,7 +2441,7 @@ static void reset_alloc_batches(struct zonelist *zonelist,
95406 continue;
95407 mod_zone_page_state(zone, NR_ALLOC_BATCH,
95408 high_wmark_pages(zone) - low_wmark_pages(zone) -
95409- atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
95410+ atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
95411 }
95412 }
95413
95414@@ -6565,4 +6605,4 @@ void dump_page(struct page *page, char *reason)
95415 {
95416 dump_page_badflags(page, reason, 0);
95417 }
95418-EXPORT_SYMBOL_GPL(dump_page);
95419+EXPORT_SYMBOL(dump_page);
95420diff --git a/mm/page_io.c b/mm/page_io.c
95421index 7c59ef6..1358905 100644
95422--- a/mm/page_io.c
95423+++ b/mm/page_io.c
95424@@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
95425 struct file *swap_file = sis->swap_file;
95426 struct address_space *mapping = swap_file->f_mapping;
95427 struct iovec iov = {
95428- .iov_base = kmap(page),
95429+ .iov_base = (void __force_user *)kmap(page),
95430 .iov_len = PAGE_SIZE,
95431 };
95432
95433diff --git a/mm/percpu.c b/mm/percpu.c
95434index 036cfe0..980d0fa 100644
95435--- a/mm/percpu.c
95436+++ b/mm/percpu.c
95437@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
95438 static unsigned int pcpu_high_unit_cpu __read_mostly;
95439
95440 /* the address of the first chunk which starts with the kernel static area */
95441-void *pcpu_base_addr __read_mostly;
95442+void *pcpu_base_addr __read_only;
95443 EXPORT_SYMBOL_GPL(pcpu_base_addr);
95444
95445 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
95446diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
95447index fd26d04..0cea1b0 100644
95448--- a/mm/process_vm_access.c
95449+++ b/mm/process_vm_access.c
95450@@ -13,6 +13,7 @@
95451 #include <linux/uio.h>
95452 #include <linux/sched.h>
95453 #include <linux/highmem.h>
95454+#include <linux/security.h>
95455 #include <linux/ptrace.h>
95456 #include <linux/slab.h>
95457 #include <linux/syscalls.h>
95458@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
95459 size_t iov_l_curr_offset = 0;
95460 ssize_t iov_len;
95461
95462+ return -ENOSYS; // PaX: until properly audited
95463+
95464 /*
95465 * Work out how many pages of struct pages we're going to need
95466 * when eventually calling get_user_pages
95467 */
95468 for (i = 0; i < riovcnt; i++) {
95469 iov_len = rvec[i].iov_len;
95470- if (iov_len > 0) {
95471- nr_pages_iov = ((unsigned long)rvec[i].iov_base
95472- + iov_len)
95473- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
95474- / PAGE_SIZE + 1;
95475- nr_pages = max(nr_pages, nr_pages_iov);
95476- }
95477+ if (iov_len <= 0)
95478+ continue;
95479+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
95480+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
95481+ nr_pages = max(nr_pages, nr_pages_iov);
95482 }
95483
95484 if (nr_pages == 0)
95485@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
95486 goto free_proc_pages;
95487 }
95488
95489+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
95490+ rc = -EPERM;
95491+ goto put_task_struct;
95492+ }
95493+
95494 mm = mm_access(task, PTRACE_MODE_ATTACH);
95495 if (!mm || IS_ERR(mm)) {
95496 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
95497diff --git a/mm/rmap.c b/mm/rmap.c
95498index d3cbac5..0788da4 100644
95499--- a/mm/rmap.c
95500+++ b/mm/rmap.c
95501@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95502 struct anon_vma *anon_vma = vma->anon_vma;
95503 struct anon_vma_chain *avc;
95504
95505+#ifdef CONFIG_PAX_SEGMEXEC
95506+ struct anon_vma_chain *avc_m = NULL;
95507+#endif
95508+
95509 might_sleep();
95510 if (unlikely(!anon_vma)) {
95511 struct mm_struct *mm = vma->vm_mm;
95512@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95513 if (!avc)
95514 goto out_enomem;
95515
95516+#ifdef CONFIG_PAX_SEGMEXEC
95517+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
95518+ if (!avc_m)
95519+ goto out_enomem_free_avc;
95520+#endif
95521+
95522 anon_vma = find_mergeable_anon_vma(vma);
95523 allocated = NULL;
95524 if (!anon_vma) {
95525@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95526 /* page_table_lock to protect against threads */
95527 spin_lock(&mm->page_table_lock);
95528 if (likely(!vma->anon_vma)) {
95529+
95530+#ifdef CONFIG_PAX_SEGMEXEC
95531+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
95532+
95533+ if (vma_m) {
95534+ BUG_ON(vma_m->anon_vma);
95535+ vma_m->anon_vma = anon_vma;
95536+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
95537+ avc_m = NULL;
95538+ }
95539+#endif
95540+
95541 vma->anon_vma = anon_vma;
95542 anon_vma_chain_link(vma, avc, anon_vma);
95543 allocated = NULL;
95544@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95545
95546 if (unlikely(allocated))
95547 put_anon_vma(allocated);
95548+
95549+#ifdef CONFIG_PAX_SEGMEXEC
95550+ if (unlikely(avc_m))
95551+ anon_vma_chain_free(avc_m);
95552+#endif
95553+
95554 if (unlikely(avc))
95555 anon_vma_chain_free(avc);
95556 }
95557 return 0;
95558
95559 out_enomem_free_avc:
95560+
95561+#ifdef CONFIG_PAX_SEGMEXEC
95562+ if (avc_m)
95563+ anon_vma_chain_free(avc_m);
95564+#endif
95565+
95566 anon_vma_chain_free(avc);
95567 out_enomem:
95568 return -ENOMEM;
95569@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
95570 * Attach the anon_vmas from src to dst.
95571 * Returns 0 on success, -ENOMEM on failure.
95572 */
95573-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
95574+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
95575 {
95576 struct anon_vma_chain *avc, *pavc;
95577 struct anon_vma *root = NULL;
95578@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
95579 * the corresponding VMA in the parent process is attached to.
95580 * Returns 0 on success, non-zero on failure.
95581 */
95582-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
95583+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
95584 {
95585 struct anon_vma_chain *avc;
95586 struct anon_vma *anon_vma;
95587@@ -373,8 +407,10 @@ static void anon_vma_ctor(void *data)
95588 void __init anon_vma_init(void)
95589 {
95590 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
95591- 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
95592- anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
95593+ 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
95594+ anon_vma_ctor);
95595+ anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
95596+ SLAB_PANIC|SLAB_NO_SANITIZE);
95597 }
95598
95599 /*
95600diff --git a/mm/shmem.c b/mm/shmem.c
95601index 1f18c9d..3e03d33 100644
95602--- a/mm/shmem.c
95603+++ b/mm/shmem.c
95604@@ -33,7 +33,7 @@
95605 #include <linux/swap.h>
95606 #include <linux/aio.h>
95607
95608-static struct vfsmount *shm_mnt;
95609+struct vfsmount *shm_mnt;
95610
95611 #ifdef CONFIG_SHMEM
95612 /*
95613@@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
95614 #define BOGO_DIRENT_SIZE 20
95615
95616 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
95617-#define SHORT_SYMLINK_LEN 128
95618+#define SHORT_SYMLINK_LEN 64
95619
95620 /*
95621 * shmem_fallocate and shmem_writepage communicate via inode->i_private
95622@@ -2218,6 +2218,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
95623 static int shmem_xattr_validate(const char *name)
95624 {
95625 struct { const char *prefix; size_t len; } arr[] = {
95626+
95627+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
95628+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
95629+#endif
95630+
95631 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
95632 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
95633 };
95634@@ -2273,6 +2278,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
95635 if (err)
95636 return err;
95637
95638+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
95639+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
95640+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
95641+ return -EOPNOTSUPP;
95642+ if (size > 8)
95643+ return -EINVAL;
95644+ }
95645+#endif
95646+
95647 return simple_xattr_set(&info->xattrs, name, value, size, flags);
95648 }
95649
95650@@ -2585,8 +2599,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
95651 int err = -ENOMEM;
95652
95653 /* Round up to L1_CACHE_BYTES to resist false sharing */
95654- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
95655- L1_CACHE_BYTES), GFP_KERNEL);
95656+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
95657 if (!sbinfo)
95658 return -ENOMEM;
95659
95660diff --git a/mm/slab.c b/mm/slab.c
95661index b264214..83872cd 100644
95662--- a/mm/slab.c
95663+++ b/mm/slab.c
95664@@ -300,10 +300,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
95665 if ((x)->max_freeable < i) \
95666 (x)->max_freeable = i; \
95667 } while (0)
95668-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
95669-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
95670-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
95671-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
95672+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
95673+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
95674+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
95675+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
95676+#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
95677+#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
95678 #else
95679 #define STATS_INC_ACTIVE(x) do { } while (0)
95680 #define STATS_DEC_ACTIVE(x) do { } while (0)
95681@@ -320,6 +322,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
95682 #define STATS_INC_ALLOCMISS(x) do { } while (0)
95683 #define STATS_INC_FREEHIT(x) do { } while (0)
95684 #define STATS_INC_FREEMISS(x) do { } while (0)
95685+#define STATS_INC_SANITIZED(x) do { } while (0)
95686+#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
95687 #endif
95688
95689 #if DEBUG
95690@@ -403,7 +407,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
95691 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
95692 */
95693 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
95694- const struct page *page, void *obj)
95695+ const struct page *page, const void *obj)
95696 {
95697 u32 offset = (obj - page->s_mem);
95698 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
95699@@ -1489,12 +1493,12 @@ void __init kmem_cache_init(void)
95700 */
95701
95702 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
95703- kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
95704+ kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
95705
95706 if (INDEX_AC != INDEX_NODE)
95707 kmalloc_caches[INDEX_NODE] =
95708 create_kmalloc_cache("kmalloc-node",
95709- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
95710+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
95711
95712 slab_early_init = 0;
95713
95714@@ -3428,6 +3432,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
95715 struct array_cache *ac = cpu_cache_get(cachep);
95716
95717 check_irq_off();
95718+
95719+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95720+ if (pax_sanitize_slab) {
95721+ if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
95722+ memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
95723+
95724+ if (cachep->ctor)
95725+ cachep->ctor(objp);
95726+
95727+ STATS_INC_SANITIZED(cachep);
95728+ } else
95729+ STATS_INC_NOT_SANITIZED(cachep);
95730+ }
95731+#endif
95732+
95733 kmemleak_free_recursive(objp, cachep->flags);
95734 objp = cache_free_debugcheck(cachep, objp, caller);
95735
95736@@ -3656,6 +3675,7 @@ void kfree(const void *objp)
95737
95738 if (unlikely(ZERO_OR_NULL_PTR(objp)))
95739 return;
95740+ VM_BUG_ON(!virt_addr_valid(objp));
95741 local_irq_save(flags);
95742 kfree_debugcheck(objp);
95743 c = virt_to_cache(objp);
95744@@ -4097,14 +4117,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
95745 }
95746 /* cpu stats */
95747 {
95748- unsigned long allochit = atomic_read(&cachep->allochit);
95749- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
95750- unsigned long freehit = atomic_read(&cachep->freehit);
95751- unsigned long freemiss = atomic_read(&cachep->freemiss);
95752+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
95753+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
95754+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
95755+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
95756
95757 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
95758 allochit, allocmiss, freehit, freemiss);
95759 }
95760+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95761+ {
95762+ unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
95763+ unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
95764+
95765+ seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
95766+ }
95767+#endif
95768 #endif
95769 }
95770
95771@@ -4334,13 +4362,69 @@ static const struct file_operations proc_slabstats_operations = {
95772 static int __init slab_proc_init(void)
95773 {
95774 #ifdef CONFIG_DEBUG_SLAB_LEAK
95775- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
95776+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
95777 #endif
95778 return 0;
95779 }
95780 module_init(slab_proc_init);
95781 #endif
95782
95783+bool is_usercopy_object(const void *ptr)
95784+{
95785+ struct page *page;
95786+ struct kmem_cache *cachep;
95787+
95788+ if (ZERO_OR_NULL_PTR(ptr))
95789+ return false;
95790+
95791+ if (!slab_is_available())
95792+ return false;
95793+
95794+ if (!virt_addr_valid(ptr))
95795+ return false;
95796+
95797+ page = virt_to_head_page(ptr);
95798+
95799+ if (!PageSlab(page))
95800+ return false;
95801+
95802+ cachep = page->slab_cache;
95803+ return cachep->flags & SLAB_USERCOPY;
95804+}
95805+
95806+#ifdef CONFIG_PAX_USERCOPY
95807+const char *check_heap_object(const void *ptr, unsigned long n)
95808+{
95809+ struct page *page;
95810+ struct kmem_cache *cachep;
95811+ unsigned int objnr;
95812+ unsigned long offset;
95813+
95814+ if (ZERO_OR_NULL_PTR(ptr))
95815+ return "<null>";
95816+
95817+ if (!virt_addr_valid(ptr))
95818+ return NULL;
95819+
95820+ page = virt_to_head_page(ptr);
95821+
95822+ if (!PageSlab(page))
95823+ return NULL;
95824+
95825+ cachep = page->slab_cache;
95826+ if (!(cachep->flags & SLAB_USERCOPY))
95827+ return cachep->name;
95828+
95829+ objnr = obj_to_index(cachep, page, ptr);
95830+ BUG_ON(objnr >= cachep->num);
95831+ offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
95832+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
95833+ return NULL;
95834+
95835+ return cachep->name;
95836+}
95837+#endif
95838+
95839 /**
95840 * ksize - get the actual amount of memory allocated for a given object
95841 * @objp: Pointer to the object
95842diff --git a/mm/slab.h b/mm/slab.h
95843index 8184a7c..ab27737 100644
95844--- a/mm/slab.h
95845+++ b/mm/slab.h
95846@@ -32,6 +32,15 @@ extern struct list_head slab_caches;
95847 /* The slab cache that manages slab cache information */
95848 extern struct kmem_cache *kmem_cache;
95849
95850+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95851+#ifdef CONFIG_X86_64
95852+#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
95853+#else
95854+#define PAX_MEMORY_SANITIZE_VALUE '\xff'
95855+#endif
95856+extern bool pax_sanitize_slab;
95857+#endif
95858+
95859 unsigned long calculate_alignment(unsigned long flags,
95860 unsigned long align, unsigned long size);
95861
95862@@ -67,7 +76,8 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
95863
95864 /* Legal flag mask for kmem_cache_create(), for various configurations */
95865 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
95866- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
95867+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
95868+ SLAB_USERCOPY | SLAB_NO_SANITIZE)
95869
95870 #if defined(CONFIG_DEBUG_SLAB)
95871 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
95872@@ -257,6 +267,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
95873 return s;
95874
95875 page = virt_to_head_page(x);
95876+
95877+ BUG_ON(!PageSlab(page));
95878+
95879 cachep = page->slab_cache;
95880 if (slab_equal_or_root(cachep, s))
95881 return cachep;
95882diff --git a/mm/slab_common.c b/mm/slab_common.c
95883index 1ec3c61..2067c11 100644
95884--- a/mm/slab_common.c
95885+++ b/mm/slab_common.c
95886@@ -23,11 +23,22 @@
95887
95888 #include "slab.h"
95889
95890-enum slab_state slab_state;
95891+enum slab_state slab_state __read_only;
95892 LIST_HEAD(slab_caches);
95893 DEFINE_MUTEX(slab_mutex);
95894 struct kmem_cache *kmem_cache;
95895
95896+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95897+bool pax_sanitize_slab __read_only = true;
95898+static int __init pax_sanitize_slab_setup(char *str)
95899+{
95900+ pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
95901+ printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
95902+ return 1;
95903+}
95904+__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
95905+#endif
95906+
95907 #ifdef CONFIG_DEBUG_VM
95908 static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
95909 size_t size)
95910@@ -225,7 +236,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
95911 if (err)
95912 goto out_free_cache;
95913
95914- s->refcount = 1;
95915+ atomic_set(&s->refcount, 1);
95916 list_add(&s->list, &slab_caches);
95917 memcg_register_cache(s);
95918
95919@@ -278,8 +289,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
95920
95921 get_online_cpus();
95922 mutex_lock(&slab_mutex);
95923- s->refcount--;
95924- if (!s->refcount) {
95925+ if (atomic_dec_and_test(&s->refcount)) {
95926 list_del(&s->list);
95927
95928 if (!__kmem_cache_shutdown(s)) {
95929@@ -326,7 +336,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
95930 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
95931 name, size, err);
95932
95933- s->refcount = -1; /* Exempt from merging for now */
95934+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
95935 }
95936
95937 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
95938@@ -339,7 +349,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
95939
95940 create_boot_cache(s, name, size, flags);
95941 list_add(&s->list, &slab_caches);
95942- s->refcount = 1;
95943+ atomic_set(&s->refcount, 1);
95944 return s;
95945 }
95946
95947@@ -351,6 +361,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
95948 EXPORT_SYMBOL(kmalloc_dma_caches);
95949 #endif
95950
95951+#ifdef CONFIG_PAX_USERCOPY_SLABS
95952+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
95953+EXPORT_SYMBOL(kmalloc_usercopy_caches);
95954+#endif
95955+
95956 /*
95957 * Conversion table for small slabs sizes / 8 to the index in the
95958 * kmalloc array. This is necessary for slabs < 192 since we have non power
95959@@ -415,6 +430,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
95960 return kmalloc_dma_caches[index];
95961
95962 #endif
95963+
95964+#ifdef CONFIG_PAX_USERCOPY_SLABS
95965+ if (unlikely((flags & GFP_USERCOPY)))
95966+ return kmalloc_usercopy_caches[index];
95967+
95968+#endif
95969+
95970 return kmalloc_caches[index];
95971 }
95972
95973@@ -471,7 +493,7 @@ void __init create_kmalloc_caches(unsigned long flags)
95974 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
95975 if (!kmalloc_caches[i]) {
95976 kmalloc_caches[i] = create_kmalloc_cache(NULL,
95977- 1 << i, flags);
95978+ 1 << i, SLAB_USERCOPY | flags);
95979 }
95980
95981 /*
95982@@ -480,10 +502,10 @@ void __init create_kmalloc_caches(unsigned long flags)
95983 * earlier power of two caches
95984 */
95985 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
95986- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
95987+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
95988
95989 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
95990- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
95991+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
95992 }
95993
95994 /* Kmalloc array is now usable */
95995@@ -516,6 +538,23 @@ void __init create_kmalloc_caches(unsigned long flags)
95996 }
95997 }
95998 #endif
95999+
96000+#ifdef CONFIG_PAX_USERCOPY_SLABS
96001+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
96002+ struct kmem_cache *s = kmalloc_caches[i];
96003+
96004+ if (s) {
96005+ int size = kmalloc_size(i);
96006+ char *n = kasprintf(GFP_NOWAIT,
96007+ "usercopy-kmalloc-%d", size);
96008+
96009+ BUG_ON(!n);
96010+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
96011+ size, SLAB_USERCOPY | flags);
96012+ }
96013+ }
96014+#endif
96015+
96016 }
96017 #endif /* !CONFIG_SLOB */
96018
96019@@ -556,6 +595,9 @@ void print_slabinfo_header(struct seq_file *m)
96020 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
96021 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
96022 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
96023+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96024+ seq_puts(m, " : pax <sanitized> <not_sanitized>");
96025+#endif
96026 #endif
96027 seq_putc(m, '\n');
96028 }
96029diff --git a/mm/slob.c b/mm/slob.c
96030index 4bf8809..98a6914 100644
96031--- a/mm/slob.c
96032+++ b/mm/slob.c
96033@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
96034 /*
96035 * Return the size of a slob block.
96036 */
96037-static slobidx_t slob_units(slob_t *s)
96038+static slobidx_t slob_units(const slob_t *s)
96039 {
96040 if (s->units > 0)
96041 return s->units;
96042@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
96043 /*
96044 * Return the next free slob block pointer after this one.
96045 */
96046-static slob_t *slob_next(slob_t *s)
96047+static slob_t *slob_next(const slob_t *s)
96048 {
96049 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
96050 slobidx_t next;
96051@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
96052 /*
96053 * Returns true if s is the last free block in its page.
96054 */
96055-static int slob_last(slob_t *s)
96056+static int slob_last(const slob_t *s)
96057 {
96058 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
96059 }
96060
96061-static void *slob_new_pages(gfp_t gfp, int order, int node)
96062+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
96063 {
96064- void *page;
96065+ struct page *page;
96066
96067 #ifdef CONFIG_NUMA
96068 if (node != NUMA_NO_NODE)
96069@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
96070 if (!page)
96071 return NULL;
96072
96073- return page_address(page);
96074+ __SetPageSlab(page);
96075+ return page;
96076 }
96077
96078-static void slob_free_pages(void *b, int order)
96079+static void slob_free_pages(struct page *sp, int order)
96080 {
96081 if (current->reclaim_state)
96082 current->reclaim_state->reclaimed_slab += 1 << order;
96083- free_pages((unsigned long)b, order);
96084+ __ClearPageSlab(sp);
96085+ page_mapcount_reset(sp);
96086+ sp->private = 0;
96087+ __free_pages(sp, order);
96088 }
96089
96090 /*
96091@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
96092
96093 /* Not enough space: must allocate a new page */
96094 if (!b) {
96095- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
96096- if (!b)
96097+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
96098+ if (!sp)
96099 return NULL;
96100- sp = virt_to_page(b);
96101- __SetPageSlab(sp);
96102+ b = page_address(sp);
96103
96104 spin_lock_irqsave(&slob_lock, flags);
96105 sp->units = SLOB_UNITS(PAGE_SIZE);
96106 sp->freelist = b;
96107+ sp->private = 0;
96108 INIT_LIST_HEAD(&sp->list);
96109 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
96110 set_slob_page_free(sp, slob_list);
96111@@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
96112 if (slob_page_free(sp))
96113 clear_slob_page_free(sp);
96114 spin_unlock_irqrestore(&slob_lock, flags);
96115- __ClearPageSlab(sp);
96116- page_mapcount_reset(sp);
96117- slob_free_pages(b, 0);
96118+ slob_free_pages(sp, 0);
96119 return;
96120 }
96121
96122+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96123+ if (pax_sanitize_slab)
96124+ memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
96125+#endif
96126+
96127 if (!slob_page_free(sp)) {
96128 /* This slob page is about to become partially free. Easy! */
96129 sp->units = units;
96130@@ -424,11 +431,10 @@ out:
96131 */
96132
96133 static __always_inline void *
96134-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96135+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
96136 {
96137- unsigned int *m;
96138- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96139- void *ret;
96140+ slob_t *m;
96141+ void *ret = NULL;
96142
96143 gfp &= gfp_allowed_mask;
96144
96145@@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96146
96147 if (!m)
96148 return NULL;
96149- *m = size;
96150+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
96151+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
96152+ m[0].units = size;
96153+ m[1].units = align;
96154 ret = (void *)m + align;
96155
96156 trace_kmalloc_node(caller, ret,
96157 size, size + align, gfp, node);
96158 } else {
96159 unsigned int order = get_order(size);
96160+ struct page *page;
96161
96162 if (likely(order))
96163 gfp |= __GFP_COMP;
96164- ret = slob_new_pages(gfp, order, node);
96165+ page = slob_new_pages(gfp, order, node);
96166+ if (page) {
96167+ ret = page_address(page);
96168+ page->private = size;
96169+ }
96170
96171 trace_kmalloc_node(caller, ret,
96172 size, PAGE_SIZE << order, gfp, node);
96173 }
96174
96175- kmemleak_alloc(ret, size, 1, gfp);
96176+ return ret;
96177+}
96178+
96179+static __always_inline void *
96180+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96181+{
96182+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96183+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
96184+
96185+ if (!ZERO_OR_NULL_PTR(ret))
96186+ kmemleak_alloc(ret, size, 1, gfp);
96187 return ret;
96188 }
96189
96190@@ -493,34 +517,112 @@ void kfree(const void *block)
96191 return;
96192 kmemleak_free(block);
96193
96194+ VM_BUG_ON(!virt_addr_valid(block));
96195 sp = virt_to_page(block);
96196- if (PageSlab(sp)) {
96197+ VM_BUG_ON(!PageSlab(sp));
96198+ if (!sp->private) {
96199 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96200- unsigned int *m = (unsigned int *)(block - align);
96201- slob_free(m, *m + align);
96202- } else
96203+ slob_t *m = (slob_t *)(block - align);
96204+ slob_free(m, m[0].units + align);
96205+ } else {
96206+ __ClearPageSlab(sp);
96207+ page_mapcount_reset(sp);
96208+ sp->private = 0;
96209 __free_pages(sp, compound_order(sp));
96210+ }
96211 }
96212 EXPORT_SYMBOL(kfree);
96213
96214+bool is_usercopy_object(const void *ptr)
96215+{
96216+ if (!slab_is_available())
96217+ return false;
96218+
96219+ // PAX: TODO
96220+
96221+ return false;
96222+}
96223+
96224+#ifdef CONFIG_PAX_USERCOPY
96225+const char *check_heap_object(const void *ptr, unsigned long n)
96226+{
96227+ struct page *page;
96228+ const slob_t *free;
96229+ const void *base;
96230+ unsigned long flags;
96231+
96232+ if (ZERO_OR_NULL_PTR(ptr))
96233+ return "<null>";
96234+
96235+ if (!virt_addr_valid(ptr))
96236+ return NULL;
96237+
96238+ page = virt_to_head_page(ptr);
96239+ if (!PageSlab(page))
96240+ return NULL;
96241+
96242+ if (page->private) {
96243+ base = page;
96244+ if (base <= ptr && n <= page->private - (ptr - base))
96245+ return NULL;
96246+ return "<slob>";
96247+ }
96248+
96249+ /* some tricky double walking to find the chunk */
96250+ spin_lock_irqsave(&slob_lock, flags);
96251+ base = (void *)((unsigned long)ptr & PAGE_MASK);
96252+ free = page->freelist;
96253+
96254+ while (!slob_last(free) && (void *)free <= ptr) {
96255+ base = free + slob_units(free);
96256+ free = slob_next(free);
96257+ }
96258+
96259+ while (base < (void *)free) {
96260+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
96261+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
96262+ int offset;
96263+
96264+ if (ptr < base + align)
96265+ break;
96266+
96267+ offset = ptr - base - align;
96268+ if (offset >= m) {
96269+ base += size;
96270+ continue;
96271+ }
96272+
96273+ if (n > m - offset)
96274+ break;
96275+
96276+ spin_unlock_irqrestore(&slob_lock, flags);
96277+ return NULL;
96278+ }
96279+
96280+ spin_unlock_irqrestore(&slob_lock, flags);
96281+ return "<slob>";
96282+}
96283+#endif
96284+
96285 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
96286 size_t ksize(const void *block)
96287 {
96288 struct page *sp;
96289 int align;
96290- unsigned int *m;
96291+ slob_t *m;
96292
96293 BUG_ON(!block);
96294 if (unlikely(block == ZERO_SIZE_PTR))
96295 return 0;
96296
96297 sp = virt_to_page(block);
96298- if (unlikely(!PageSlab(sp)))
96299- return PAGE_SIZE << compound_order(sp);
96300+ VM_BUG_ON(!PageSlab(sp));
96301+ if (sp->private)
96302+ return sp->private;
96303
96304 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96305- m = (unsigned int *)(block - align);
96306- return SLOB_UNITS(*m) * SLOB_UNIT;
96307+ m = (slob_t *)(block - align);
96308+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
96309 }
96310 EXPORT_SYMBOL(ksize);
96311
96312@@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
96313
96314 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
96315 {
96316- void *b;
96317+ void *b = NULL;
96318
96319 flags &= gfp_allowed_mask;
96320
96321 lockdep_trace_alloc(flags);
96322
96323+#ifdef CONFIG_PAX_USERCOPY_SLABS
96324+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
96325+#else
96326 if (c->size < PAGE_SIZE) {
96327 b = slob_alloc(c->size, flags, c->align, node);
96328 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
96329 SLOB_UNITS(c->size) * SLOB_UNIT,
96330 flags, node);
96331 } else {
96332- b = slob_new_pages(flags, get_order(c->size), node);
96333+ struct page *sp;
96334+
96335+ sp = slob_new_pages(flags, get_order(c->size), node);
96336+ if (sp) {
96337+ b = page_address(sp);
96338+ sp->private = c->size;
96339+ }
96340 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
96341 PAGE_SIZE << get_order(c->size),
96342 flags, node);
96343 }
96344+#endif
96345
96346 if (b && c->ctor)
96347 c->ctor(b);
96348@@ -584,10 +696,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
96349
96350 static void __kmem_cache_free(void *b, int size)
96351 {
96352- if (size < PAGE_SIZE)
96353+ struct page *sp;
96354+
96355+ sp = virt_to_page(b);
96356+ BUG_ON(!PageSlab(sp));
96357+ if (!sp->private)
96358 slob_free(b, size);
96359 else
96360- slob_free_pages(b, get_order(size));
96361+ slob_free_pages(sp, get_order(size));
96362 }
96363
96364 static void kmem_rcu_free(struct rcu_head *head)
96365@@ -600,17 +716,31 @@ static void kmem_rcu_free(struct rcu_head *head)
96366
96367 void kmem_cache_free(struct kmem_cache *c, void *b)
96368 {
96369+ int size = c->size;
96370+
96371+#ifdef CONFIG_PAX_USERCOPY_SLABS
96372+ if (size + c->align < PAGE_SIZE) {
96373+ size += c->align;
96374+ b -= c->align;
96375+ }
96376+#endif
96377+
96378 kmemleak_free_recursive(b, c->flags);
96379 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
96380 struct slob_rcu *slob_rcu;
96381- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
96382- slob_rcu->size = c->size;
96383+ slob_rcu = b + (size - sizeof(struct slob_rcu));
96384+ slob_rcu->size = size;
96385 call_rcu(&slob_rcu->head, kmem_rcu_free);
96386 } else {
96387- __kmem_cache_free(b, c->size);
96388+ __kmem_cache_free(b, size);
96389 }
96390
96391+#ifdef CONFIG_PAX_USERCOPY_SLABS
96392+ trace_kfree(_RET_IP_, b);
96393+#else
96394 trace_kmem_cache_free(_RET_IP_, b);
96395+#endif
96396+
96397 }
96398 EXPORT_SYMBOL(kmem_cache_free);
96399
96400diff --git a/mm/slub.c b/mm/slub.c
96401index 25f14ad..ff4d0b7 100644
96402--- a/mm/slub.c
96403+++ b/mm/slub.c
96404@@ -207,7 +207,7 @@ struct track {
96405
96406 enum track_item { TRACK_ALLOC, TRACK_FREE };
96407
96408-#ifdef CONFIG_SYSFS
96409+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96410 static int sysfs_slab_add(struct kmem_cache *);
96411 static int sysfs_slab_alias(struct kmem_cache *, const char *);
96412 static void sysfs_slab_remove(struct kmem_cache *);
96413@@ -545,7 +545,7 @@ static void print_track(const char *s, struct track *t)
96414 if (!t->addr)
96415 return;
96416
96417- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
96418+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
96419 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
96420 #ifdef CONFIG_STACKTRACE
96421 {
96422@@ -2666,6 +2666,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
96423
96424 slab_free_hook(s, x);
96425
96426+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96427+ if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
96428+ memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
96429+ if (s->ctor)
96430+ s->ctor(x);
96431+ }
96432+#endif
96433+
96434 redo:
96435 /*
96436 * Determine the currently cpus per cpu slab.
96437@@ -2733,7 +2741,7 @@ static int slub_min_objects;
96438 * Merge control. If this is set then no merging of slab caches will occur.
96439 * (Could be removed. This was introduced to pacify the merge skeptics.)
96440 */
96441-static int slub_nomerge;
96442+static int slub_nomerge = 1;
96443
96444 /*
96445 * Calculate the order of allocation given an slab object size.
96446@@ -3014,6 +3022,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
96447 s->inuse = size;
96448
96449 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
96450+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96451+ (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
96452+#endif
96453 s->ctor)) {
96454 /*
96455 * Relocate free pointer after the object if it is not
96456@@ -3359,6 +3370,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
96457 EXPORT_SYMBOL(__kmalloc_node);
96458 #endif
96459
96460+bool is_usercopy_object(const void *ptr)
96461+{
96462+ struct page *page;
96463+ struct kmem_cache *s;
96464+
96465+ if (ZERO_OR_NULL_PTR(ptr))
96466+ return false;
96467+
96468+ if (!slab_is_available())
96469+ return false;
96470+
96471+ if (!virt_addr_valid(ptr))
96472+ return false;
96473+
96474+ page = virt_to_head_page(ptr);
96475+
96476+ if (!PageSlab(page))
96477+ return false;
96478+
96479+ s = page->slab_cache;
96480+ return s->flags & SLAB_USERCOPY;
96481+}
96482+
96483+#ifdef CONFIG_PAX_USERCOPY
96484+const char *check_heap_object(const void *ptr, unsigned long n)
96485+{
96486+ struct page *page;
96487+ struct kmem_cache *s;
96488+ unsigned long offset;
96489+
96490+ if (ZERO_OR_NULL_PTR(ptr))
96491+ return "<null>";
96492+
96493+ if (!virt_addr_valid(ptr))
96494+ return NULL;
96495+
96496+ page = virt_to_head_page(ptr);
96497+
96498+ if (!PageSlab(page))
96499+ return NULL;
96500+
96501+ s = page->slab_cache;
96502+ if (!(s->flags & SLAB_USERCOPY))
96503+ return s->name;
96504+
96505+ offset = (ptr - page_address(page)) % s->size;
96506+ if (offset <= s->object_size && n <= s->object_size - offset)
96507+ return NULL;
96508+
96509+ return s->name;
96510+}
96511+#endif
96512+
96513 size_t ksize(const void *object)
96514 {
96515 struct page *page;
96516@@ -3387,6 +3451,7 @@ void kfree(const void *x)
96517 if (unlikely(ZERO_OR_NULL_PTR(x)))
96518 return;
96519
96520+ VM_BUG_ON(!virt_addr_valid(x));
96521 page = virt_to_head_page(x);
96522 if (unlikely(!PageSlab(page))) {
96523 BUG_ON(!PageCompound(page));
96524@@ -3692,7 +3757,7 @@ static int slab_unmergeable(struct kmem_cache *s)
96525 /*
96526 * We may have set a slab to be unmergeable during bootstrap.
96527 */
96528- if (s->refcount < 0)
96529+ if (atomic_read(&s->refcount) < 0)
96530 return 1;
96531
96532 return 0;
96533@@ -3750,7 +3815,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
96534
96535 s = find_mergeable(memcg, size, align, flags, name, ctor);
96536 if (s) {
96537- s->refcount++;
96538+ atomic_inc(&s->refcount);
96539 /*
96540 * Adjust the object sizes so that we clear
96541 * the complete object on kzalloc.
96542@@ -3759,7 +3824,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
96543 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
96544
96545 if (sysfs_slab_alias(s, name)) {
96546- s->refcount--;
96547+ atomic_dec(&s->refcount);
96548 s = NULL;
96549 }
96550 }
96551@@ -3879,7 +3944,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
96552 }
96553 #endif
96554
96555-#ifdef CONFIG_SYSFS
96556+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96557 static int count_inuse(struct page *page)
96558 {
96559 return page->inuse;
96560@@ -4268,12 +4333,12 @@ static void resiliency_test(void)
96561 validate_slab_cache(kmalloc_caches[9]);
96562 }
96563 #else
96564-#ifdef CONFIG_SYSFS
96565+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96566 static void resiliency_test(void) {};
96567 #endif
96568 #endif
96569
96570-#ifdef CONFIG_SYSFS
96571+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96572 enum slab_stat_type {
96573 SL_ALL, /* All slabs */
96574 SL_PARTIAL, /* Only partially allocated slabs */
96575@@ -4519,7 +4584,7 @@ SLAB_ATTR_RO(ctor);
96576
96577 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
96578 {
96579- return sprintf(buf, "%d\n", s->refcount - 1);
96580+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
96581 }
96582 SLAB_ATTR_RO(aliases);
96583
96584@@ -4607,6 +4672,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
96585 SLAB_ATTR_RO(cache_dma);
96586 #endif
96587
96588+#ifdef CONFIG_PAX_USERCOPY_SLABS
96589+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
96590+{
96591+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
96592+}
96593+SLAB_ATTR_RO(usercopy);
96594+#endif
96595+
96596 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
96597 {
96598 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
96599@@ -4941,6 +5014,9 @@ static struct attribute *slab_attrs[] = {
96600 #ifdef CONFIG_ZONE_DMA
96601 &cache_dma_attr.attr,
96602 #endif
96603+#ifdef CONFIG_PAX_USERCOPY_SLABS
96604+ &usercopy_attr.attr,
96605+#endif
96606 #ifdef CONFIG_NUMA
96607 &remote_node_defrag_ratio_attr.attr,
96608 #endif
96609@@ -5173,6 +5249,7 @@ static char *create_unique_id(struct kmem_cache *s)
96610 return name;
96611 }
96612
96613+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96614 static int sysfs_slab_add(struct kmem_cache *s)
96615 {
96616 int err;
96617@@ -5230,6 +5307,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
96618 kobject_del(&s->kobj);
96619 kobject_put(&s->kobj);
96620 }
96621+#endif
96622
96623 /*
96624 * Need to buffer aliases during bootup until sysfs becomes
96625@@ -5243,6 +5321,7 @@ struct saved_alias {
96626
96627 static struct saved_alias *alias_list;
96628
96629+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96630 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
96631 {
96632 struct saved_alias *al;
96633@@ -5265,6 +5344,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
96634 alias_list = al;
96635 return 0;
96636 }
96637+#endif
96638
96639 static int __init slab_sysfs_init(void)
96640 {
96641diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
96642index 4cba9c2..b4f9fcc 100644
96643--- a/mm/sparse-vmemmap.c
96644+++ b/mm/sparse-vmemmap.c
96645@@ -131,7 +131,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
96646 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
96647 if (!p)
96648 return NULL;
96649- pud_populate(&init_mm, pud, p);
96650+ pud_populate_kernel(&init_mm, pud, p);
96651 }
96652 return pud;
96653 }
96654@@ -143,7 +143,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
96655 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
96656 if (!p)
96657 return NULL;
96658- pgd_populate(&init_mm, pgd, p);
96659+ pgd_populate_kernel(&init_mm, pgd, p);
96660 }
96661 return pgd;
96662 }
96663diff --git a/mm/sparse.c b/mm/sparse.c
96664index 63c3ea5..95c0858 100644
96665--- a/mm/sparse.c
96666+++ b/mm/sparse.c
96667@@ -748,7 +748,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
96668
96669 for (i = 0; i < PAGES_PER_SECTION; i++) {
96670 if (PageHWPoison(&memmap[i])) {
96671- atomic_long_sub(1, &num_poisoned_pages);
96672+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
96673 ClearPageHWPoison(&memmap[i]);
96674 }
96675 }
96676diff --git a/mm/swap.c b/mm/swap.c
96677index 0092097..33361ff 100644
96678--- a/mm/swap.c
96679+++ b/mm/swap.c
96680@@ -31,6 +31,7 @@
96681 #include <linux/memcontrol.h>
96682 #include <linux/gfp.h>
96683 #include <linux/uio.h>
96684+#include <linux/hugetlb.h>
96685
96686 #include "internal.h"
96687
96688@@ -76,6 +77,8 @@ static void __put_compound_page(struct page *page)
96689
96690 __page_cache_release(page);
96691 dtor = get_compound_page_dtor(page);
96692+ if (!PageHuge(page))
96693+ BUG_ON(dtor != free_compound_page);
96694 (*dtor)(page);
96695 }
96696
96697diff --git a/mm/swapfile.c b/mm/swapfile.c
96698index 4a7f7e6..22cddf5 100644
96699--- a/mm/swapfile.c
96700+++ b/mm/swapfile.c
96701@@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
96702
96703 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
96704 /* Activity counter to indicate that a swapon or swapoff has occurred */
96705-static atomic_t proc_poll_event = ATOMIC_INIT(0);
96706+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
96707
96708 static inline unsigned char swap_count(unsigned char ent)
96709 {
96710@@ -1959,7 +1959,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
96711 spin_unlock(&swap_lock);
96712
96713 err = 0;
96714- atomic_inc(&proc_poll_event);
96715+ atomic_inc_unchecked(&proc_poll_event);
96716 wake_up_interruptible(&proc_poll_wait);
96717
96718 out_dput:
96719@@ -1976,8 +1976,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
96720
96721 poll_wait(file, &proc_poll_wait, wait);
96722
96723- if (seq->poll_event != atomic_read(&proc_poll_event)) {
96724- seq->poll_event = atomic_read(&proc_poll_event);
96725+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
96726+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
96727 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
96728 }
96729
96730@@ -2075,7 +2075,7 @@ static int swaps_open(struct inode *inode, struct file *file)
96731 return ret;
96732
96733 seq = file->private_data;
96734- seq->poll_event = atomic_read(&proc_poll_event);
96735+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
96736 return 0;
96737 }
96738
96739@@ -2534,7 +2534,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
96740 (frontswap_map) ? "FS" : "");
96741
96742 mutex_unlock(&swapon_mutex);
96743- atomic_inc(&proc_poll_event);
96744+ atomic_inc_unchecked(&proc_poll_event);
96745 wake_up_interruptible(&proc_poll_wait);
96746
96747 if (S_ISREG(inode->i_mode))
96748diff --git a/mm/util.c b/mm/util.c
96749index a24aa22..a0d41ae 100644
96750--- a/mm/util.c
96751+++ b/mm/util.c
96752@@ -297,6 +297,12 @@ done:
96753 void arch_pick_mmap_layout(struct mm_struct *mm)
96754 {
96755 mm->mmap_base = TASK_UNMAPPED_BASE;
96756+
96757+#ifdef CONFIG_PAX_RANDMMAP
96758+ if (mm->pax_flags & MF_PAX_RANDMMAP)
96759+ mm->mmap_base += mm->delta_mmap;
96760+#endif
96761+
96762 mm->get_unmapped_area = arch_get_unmapped_area;
96763 }
96764 #endif
96765diff --git a/mm/vmalloc.c b/mm/vmalloc.c
96766index 0fdf968..d6686e8 100644
96767--- a/mm/vmalloc.c
96768+++ b/mm/vmalloc.c
96769@@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
96770
96771 pte = pte_offset_kernel(pmd, addr);
96772 do {
96773- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
96774- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
96775+
96776+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
96777+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
96778+ BUG_ON(!pte_exec(*pte));
96779+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
96780+ continue;
96781+ }
96782+#endif
96783+
96784+ {
96785+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
96786+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
96787+ }
96788 } while (pte++, addr += PAGE_SIZE, addr != end);
96789 }
96790
96791@@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
96792 pte = pte_alloc_kernel(pmd, addr);
96793 if (!pte)
96794 return -ENOMEM;
96795+
96796+ pax_open_kernel();
96797 do {
96798 struct page *page = pages[*nr];
96799
96800- if (WARN_ON(!pte_none(*pte)))
96801+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
96802+ if (pgprot_val(prot) & _PAGE_NX)
96803+#endif
96804+
96805+ if (!pte_none(*pte)) {
96806+ pax_close_kernel();
96807+ WARN_ON(1);
96808 return -EBUSY;
96809- if (WARN_ON(!page))
96810+ }
96811+ if (!page) {
96812+ pax_close_kernel();
96813+ WARN_ON(1);
96814 return -ENOMEM;
96815+ }
96816 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
96817 (*nr)++;
96818 } while (pte++, addr += PAGE_SIZE, addr != end);
96819+ pax_close_kernel();
96820 return 0;
96821 }
96822
96823@@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
96824 pmd_t *pmd;
96825 unsigned long next;
96826
96827- pmd = pmd_alloc(&init_mm, pud, addr);
96828+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
96829 if (!pmd)
96830 return -ENOMEM;
96831 do {
96832@@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
96833 pud_t *pud;
96834 unsigned long next;
96835
96836- pud = pud_alloc(&init_mm, pgd, addr);
96837+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
96838 if (!pud)
96839 return -ENOMEM;
96840 do {
96841@@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
96842 if (addr >= MODULES_VADDR && addr < MODULES_END)
96843 return 1;
96844 #endif
96845+
96846+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
96847+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
96848+ return 1;
96849+#endif
96850+
96851 return is_vmalloc_addr(x);
96852 }
96853
96854@@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
96855
96856 if (!pgd_none(*pgd)) {
96857 pud_t *pud = pud_offset(pgd, addr);
96858+#ifdef CONFIG_X86
96859+ if (!pud_large(*pud))
96860+#endif
96861 if (!pud_none(*pud)) {
96862 pmd_t *pmd = pmd_offset(pud, addr);
96863+#ifdef CONFIG_X86
96864+ if (!pmd_large(*pmd))
96865+#endif
96866 if (!pmd_none(*pmd)) {
96867 pte_t *ptep, pte;
96868
96869@@ -1309,6 +1345,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
96870 struct vm_struct *area;
96871
96872 BUG_ON(in_interrupt());
96873+
96874+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
96875+ if (flags & VM_KERNEXEC) {
96876+ if (start != VMALLOC_START || end != VMALLOC_END)
96877+ return NULL;
96878+ start = (unsigned long)MODULES_EXEC_VADDR;
96879+ end = (unsigned long)MODULES_EXEC_END;
96880+ }
96881+#endif
96882+
96883 if (flags & VM_IOREMAP)
96884 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
96885
96886@@ -1534,6 +1580,11 @@ void *vmap(struct page **pages, unsigned int count,
96887 if (count > totalram_pages)
96888 return NULL;
96889
96890+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
96891+ if (!(pgprot_val(prot) & _PAGE_NX))
96892+ flags |= VM_KERNEXEC;
96893+#endif
96894+
96895 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
96896 __builtin_return_address(0));
96897 if (!area)
96898@@ -1634,6 +1685,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
96899 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
96900 goto fail;
96901
96902+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
96903+ if (!(pgprot_val(prot) & _PAGE_NX))
96904+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
96905+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
96906+ else
96907+#endif
96908+
96909 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
96910 start, end, node, gfp_mask, caller);
96911 if (!area)
96912@@ -1810,10 +1868,9 @@ EXPORT_SYMBOL(vzalloc_node);
96913 * For tight control over page level allocator and protection flags
96914 * use __vmalloc() instead.
96915 */
96916-
96917 void *vmalloc_exec(unsigned long size)
96918 {
96919- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
96920+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
96921 NUMA_NO_NODE, __builtin_return_address(0));
96922 }
96923
96924@@ -2120,6 +2177,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
96925 {
96926 struct vm_struct *area;
96927
96928+ BUG_ON(vma->vm_mirror);
96929+
96930 size = PAGE_ALIGN(size);
96931
96932 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
96933@@ -2602,7 +2661,11 @@ static int s_show(struct seq_file *m, void *p)
96934 v->addr, v->addr + v->size, v->size);
96935
96936 if (v->caller)
96937+#ifdef CONFIG_GRKERNSEC_HIDESYM
96938+ seq_printf(m, " %pK", v->caller);
96939+#else
96940 seq_printf(m, " %pS", v->caller);
96941+#endif
96942
96943 if (v->nr_pages)
96944 seq_printf(m, " pages=%d", v->nr_pages);
96945diff --git a/mm/vmstat.c b/mm/vmstat.c
96946index def5dd2..4ce55cec 100644
96947--- a/mm/vmstat.c
96948+++ b/mm/vmstat.c
96949@@ -20,6 +20,7 @@
96950 #include <linux/writeback.h>
96951 #include <linux/compaction.h>
96952 #include <linux/mm_inline.h>
96953+#include <linux/grsecurity.h>
96954
96955 #include "internal.h"
96956
96957@@ -79,7 +80,7 @@ void vm_events_fold_cpu(int cpu)
96958 *
96959 * vm_stat contains the global counters
96960 */
96961-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
96962+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
96963 EXPORT_SYMBOL(vm_stat);
96964
96965 #ifdef CONFIG_SMP
96966@@ -423,7 +424,7 @@ static inline void fold_diff(int *diff)
96967
96968 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
96969 if (diff[i])
96970- atomic_long_add(diff[i], &vm_stat[i]);
96971+ atomic_long_add_unchecked(diff[i], &vm_stat[i]);
96972 }
96973
96974 /*
96975@@ -455,7 +456,7 @@ static void refresh_cpu_vm_stats(void)
96976 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
96977 if (v) {
96978
96979- atomic_long_add(v, &zone->vm_stat[i]);
96980+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
96981 global_diff[i] += v;
96982 #ifdef CONFIG_NUMA
96983 /* 3 seconds idle till flush */
96984@@ -517,7 +518,7 @@ void cpu_vm_stats_fold(int cpu)
96985
96986 v = p->vm_stat_diff[i];
96987 p->vm_stat_diff[i] = 0;
96988- atomic_long_add(v, &zone->vm_stat[i]);
96989+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
96990 global_diff[i] += v;
96991 }
96992 }
96993@@ -537,8 +538,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
96994 if (pset->vm_stat_diff[i]) {
96995 int v = pset->vm_stat_diff[i];
96996 pset->vm_stat_diff[i] = 0;
96997- atomic_long_add(v, &zone->vm_stat[i]);
96998- atomic_long_add(v, &vm_stat[i]);
96999+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
97000+ atomic_long_add_unchecked(v, &vm_stat[i]);
97001 }
97002 }
97003 #endif
97004@@ -1150,10 +1151,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
97005 stat_items_size += sizeof(struct vm_event_state);
97006 #endif
97007
97008- v = kmalloc(stat_items_size, GFP_KERNEL);
97009+ v = kzalloc(stat_items_size, GFP_KERNEL);
97010 m->private = v;
97011 if (!v)
97012 return ERR_PTR(-ENOMEM);
97013+
97014+#ifdef CONFIG_GRKERNSEC_PROC_ADD
97015+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
97016+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
97017+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
97018+ && !in_group_p(grsec_proc_gid)
97019+#endif
97020+ )
97021+ return (unsigned long *)m->private + *pos;
97022+#endif
97023+#endif
97024+
97025 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
97026 v[i] = global_page_state(i);
97027 v += NR_VM_ZONE_STAT_ITEMS;
97028@@ -1302,10 +1315,16 @@ static int __init setup_vmstat(void)
97029 put_online_cpus();
97030 #endif
97031 #ifdef CONFIG_PROC_FS
97032- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
97033- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
97034- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
97035- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
97036+ {
97037+ mode_t gr_mode = S_IRUGO;
97038+#ifdef CONFIG_GRKERNSEC_PROC_ADD
97039+ gr_mode = S_IRUSR;
97040+#endif
97041+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
97042+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
97043+ proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
97044+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
97045+ }
97046 #endif
97047 return 0;
97048 }
97049diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
97050index 175273f..1c63e05 100644
97051--- a/net/8021q/vlan.c
97052+++ b/net/8021q/vlan.c
97053@@ -474,7 +474,7 @@ out:
97054 return NOTIFY_DONE;
97055 }
97056
97057-static struct notifier_block vlan_notifier_block __read_mostly = {
97058+static struct notifier_block vlan_notifier_block = {
97059 .notifier_call = vlan_device_event,
97060 };
97061
97062@@ -549,8 +549,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
97063 err = -EPERM;
97064 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
97065 break;
97066- if ((args.u.name_type >= 0) &&
97067- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
97068+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
97069 struct vlan_net *vn;
97070
97071 vn = net_generic(net, vlan_net_id);
97072diff --git a/net/9p/client.c b/net/9p/client.c
97073index 9186550..e604a2f 100644
97074--- a/net/9p/client.c
97075+++ b/net/9p/client.c
97076@@ -588,7 +588,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
97077 len - inline_len);
97078 } else {
97079 err = copy_from_user(ename + inline_len,
97080- uidata, len - inline_len);
97081+ (char __force_user *)uidata, len - inline_len);
97082 if (err) {
97083 err = -EFAULT;
97084 goto out_err;
97085@@ -1560,7 +1560,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
97086 kernel_buf = 1;
97087 indata = data;
97088 } else
97089- indata = (__force char *)udata;
97090+ indata = (__force_kernel char *)udata;
97091 /*
97092 * response header len is 11
97093 * PDU Header(7) + IO Size (4)
97094@@ -1635,7 +1635,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
97095 kernel_buf = 1;
97096 odata = data;
97097 } else
97098- odata = (char *)udata;
97099+ odata = (char __force_kernel *)udata;
97100 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
97101 P9_ZC_HDR_SZ, kernel_buf, "dqd",
97102 fid->fid, offset, rsize);
97103diff --git a/net/9p/mod.c b/net/9p/mod.c
97104index 6ab36ae..6f1841b 100644
97105--- a/net/9p/mod.c
97106+++ b/net/9p/mod.c
97107@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
97108 void v9fs_register_trans(struct p9_trans_module *m)
97109 {
97110 spin_lock(&v9fs_trans_lock);
97111- list_add_tail(&m->list, &v9fs_trans_list);
97112+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
97113 spin_unlock(&v9fs_trans_lock);
97114 }
97115 EXPORT_SYMBOL(v9fs_register_trans);
97116@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
97117 void v9fs_unregister_trans(struct p9_trans_module *m)
97118 {
97119 spin_lock(&v9fs_trans_lock);
97120- list_del_init(&m->list);
97121+ pax_list_del_init((struct list_head *)&m->list);
97122 spin_unlock(&v9fs_trans_lock);
97123 }
97124 EXPORT_SYMBOL(v9fs_unregister_trans);
97125diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
97126index b7bd7f2..2498bf7 100644
97127--- a/net/9p/trans_fd.c
97128+++ b/net/9p/trans_fd.c
97129@@ -432,7 +432,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
97130 oldfs = get_fs();
97131 set_fs(get_ds());
97132 /* The cast to a user pointer is valid due to the set_fs() */
97133- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
97134+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
97135 set_fs(oldfs);
97136
97137 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
97138diff --git a/net/appletalk/atalk_proc.c b/net/appletalk/atalk_proc.c
97139index af46bc4..f9adfcd 100644
97140--- a/net/appletalk/atalk_proc.c
97141+++ b/net/appletalk/atalk_proc.c
97142@@ -256,7 +256,7 @@ int __init atalk_proc_init(void)
97143 struct proc_dir_entry *p;
97144 int rc = -ENOMEM;
97145
97146- atalk_proc_dir = proc_mkdir("atalk", init_net.proc_net);
97147+ atalk_proc_dir = proc_mkdir_restrict("atalk", init_net.proc_net);
97148 if (!atalk_proc_dir)
97149 goto out;
97150
97151diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
97152index 876fbe8..8bbea9f 100644
97153--- a/net/atm/atm_misc.c
97154+++ b/net/atm/atm_misc.c
97155@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
97156 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
97157 return 1;
97158 atm_return(vcc, truesize);
97159- atomic_inc(&vcc->stats->rx_drop);
97160+ atomic_inc_unchecked(&vcc->stats->rx_drop);
97161 return 0;
97162 }
97163 EXPORT_SYMBOL(atm_charge);
97164@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
97165 }
97166 }
97167 atm_return(vcc, guess);
97168- atomic_inc(&vcc->stats->rx_drop);
97169+ atomic_inc_unchecked(&vcc->stats->rx_drop);
97170 return NULL;
97171 }
97172 EXPORT_SYMBOL(atm_alloc_charge);
97173@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
97174
97175 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
97176 {
97177-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
97178+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
97179 __SONET_ITEMS
97180 #undef __HANDLE_ITEM
97181 }
97182@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
97183
97184 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
97185 {
97186-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
97187+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
97188 __SONET_ITEMS
97189 #undef __HANDLE_ITEM
97190 }
97191diff --git a/net/atm/lec.c b/net/atm/lec.c
97192index 5a2f602..9396143 100644
97193--- a/net/atm/lec.c
97194+++ b/net/atm/lec.c
97195@@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
97196 }
97197
97198 static struct lane2_ops lane2_ops = {
97199- lane2_resolve, /* resolve, spec 3.1.3 */
97200- lane2_associate_req, /* associate_req, spec 3.1.4 */
97201- NULL /* associate indicator, spec 3.1.5 */
97202+ .resolve = lane2_resolve,
97203+ .associate_req = lane2_associate_req,
97204+ .associate_indicator = NULL
97205 };
97206
97207 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
97208diff --git a/net/atm/lec.h b/net/atm/lec.h
97209index 4149db1..f2ab682 100644
97210--- a/net/atm/lec.h
97211+++ b/net/atm/lec.h
97212@@ -48,7 +48,7 @@ struct lane2_ops {
97213 const u8 *tlvs, u32 sizeoftlvs);
97214 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
97215 const u8 *tlvs, u32 sizeoftlvs);
97216-};
97217+} __no_const;
97218
97219 /*
97220 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
97221diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
97222index d1b2d9a..d549f7f 100644
97223--- a/net/atm/mpoa_caches.c
97224+++ b/net/atm/mpoa_caches.c
97225@@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
97226
97227
97228 static struct in_cache_ops ingress_ops = {
97229- in_cache_add_entry, /* add_entry */
97230- in_cache_get, /* get */
97231- in_cache_get_with_mask, /* get_with_mask */
97232- in_cache_get_by_vcc, /* get_by_vcc */
97233- in_cache_put, /* put */
97234- in_cache_remove_entry, /* remove_entry */
97235- cache_hit, /* cache_hit */
97236- clear_count_and_expired, /* clear_count */
97237- check_resolving_entries, /* check_resolving */
97238- refresh_entries, /* refresh */
97239- in_destroy_cache /* destroy_cache */
97240+ .add_entry = in_cache_add_entry,
97241+ .get = in_cache_get,
97242+ .get_with_mask = in_cache_get_with_mask,
97243+ .get_by_vcc = in_cache_get_by_vcc,
97244+ .put = in_cache_put,
97245+ .remove_entry = in_cache_remove_entry,
97246+ .cache_hit = cache_hit,
97247+ .clear_count = clear_count_and_expired,
97248+ .check_resolving = check_resolving_entries,
97249+ .refresh = refresh_entries,
97250+ .destroy_cache = in_destroy_cache
97251 };
97252
97253 static struct eg_cache_ops egress_ops = {
97254- eg_cache_add_entry, /* add_entry */
97255- eg_cache_get_by_cache_id, /* get_by_cache_id */
97256- eg_cache_get_by_tag, /* get_by_tag */
97257- eg_cache_get_by_vcc, /* get_by_vcc */
97258- eg_cache_get_by_src_ip, /* get_by_src_ip */
97259- eg_cache_put, /* put */
97260- eg_cache_remove_entry, /* remove_entry */
97261- update_eg_cache_entry, /* update */
97262- clear_expired, /* clear_expired */
97263- eg_destroy_cache /* destroy_cache */
97264+ .add_entry = eg_cache_add_entry,
97265+ .get_by_cache_id = eg_cache_get_by_cache_id,
97266+ .get_by_tag = eg_cache_get_by_tag,
97267+ .get_by_vcc = eg_cache_get_by_vcc,
97268+ .get_by_src_ip = eg_cache_get_by_src_ip,
97269+ .put = eg_cache_put,
97270+ .remove_entry = eg_cache_remove_entry,
97271+ .update = update_eg_cache_entry,
97272+ .clear_expired = clear_expired,
97273+ .destroy_cache = eg_destroy_cache
97274 };
97275
97276
97277diff --git a/net/atm/proc.c b/net/atm/proc.c
97278index bbb6461..cf04016 100644
97279--- a/net/atm/proc.c
97280+++ b/net/atm/proc.c
97281@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
97282 const struct k_atm_aal_stats *stats)
97283 {
97284 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
97285- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
97286- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
97287- atomic_read(&stats->rx_drop));
97288+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
97289+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
97290+ atomic_read_unchecked(&stats->rx_drop));
97291 }
97292
97293 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
97294diff --git a/net/atm/resources.c b/net/atm/resources.c
97295index 0447d5d..3cf4728 100644
97296--- a/net/atm/resources.c
97297+++ b/net/atm/resources.c
97298@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
97299 static void copy_aal_stats(struct k_atm_aal_stats *from,
97300 struct atm_aal_stats *to)
97301 {
97302-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
97303+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
97304 __AAL_STAT_ITEMS
97305 #undef __HANDLE_ITEM
97306 }
97307@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
97308 static void subtract_aal_stats(struct k_atm_aal_stats *from,
97309 struct atm_aal_stats *to)
97310 {
97311-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
97312+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
97313 __AAL_STAT_ITEMS
97314 #undef __HANDLE_ITEM
97315 }
97316diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
97317index 919a5ce..cc6b444 100644
97318--- a/net/ax25/sysctl_net_ax25.c
97319+++ b/net/ax25/sysctl_net_ax25.c
97320@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
97321 {
97322 char path[sizeof("net/ax25/") + IFNAMSIZ];
97323 int k;
97324- struct ctl_table *table;
97325+ ctl_table_no_const *table;
97326
97327 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
97328 if (!table)
97329diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
97330index 8323bce..a03130d 100644
97331--- a/net/batman-adv/bat_iv_ogm.c
97332+++ b/net/batman-adv/bat_iv_ogm.c
97333@@ -312,7 +312,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
97334
97335 /* randomize initial seqno to avoid collision */
97336 get_random_bytes(&random_seqno, sizeof(random_seqno));
97337- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
97338+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
97339
97340 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
97341 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
97342@@ -917,9 +917,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
97343 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
97344
97345 /* change sequence number to network order */
97346- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
97347+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
97348 batadv_ogm_packet->seqno = htonl(seqno);
97349- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
97350+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
97351
97352 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
97353
97354@@ -1594,7 +1594,7 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
97355 return;
97356
97357 /* could be changed by schedule_own_packet() */
97358- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
97359+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
97360
97361 if (ogm_packet->flags & BATADV_DIRECTLINK)
97362 has_directlink_flag = true;
97363diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
97364index 88df9b1..69cf7c0 100644
97365--- a/net/batman-adv/fragmentation.c
97366+++ b/net/batman-adv/fragmentation.c
97367@@ -445,7 +445,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
97368 frag_header.packet_type = BATADV_UNICAST_FRAG;
97369 frag_header.version = BATADV_COMPAT_VERSION;
97370 frag_header.ttl = BATADV_TTL;
97371- frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
97372+ frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
97373 frag_header.reserved = 0;
97374 frag_header.no = 0;
97375 frag_header.total_size = htons(skb->len);
97376diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
97377index f82c267..0e56d32 100644
97378--- a/net/batman-adv/soft-interface.c
97379+++ b/net/batman-adv/soft-interface.c
97380@@ -283,7 +283,7 @@ send:
97381 primary_if->net_dev->dev_addr, ETH_ALEN);
97382
97383 /* set broadcast sequence number */
97384- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
97385+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
97386 bcast_packet->seqno = htonl(seqno);
97387
97388 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
97389@@ -707,7 +707,7 @@ static int batadv_softif_init_late(struct net_device *dev)
97390 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
97391
97392 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
97393- atomic_set(&bat_priv->bcast_seqno, 1);
97394+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
97395 atomic_set(&bat_priv->tt.vn, 0);
97396 atomic_set(&bat_priv->tt.local_changes, 0);
97397 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
97398@@ -721,7 +721,7 @@ static int batadv_softif_init_late(struct net_device *dev)
97399
97400 /* randomize initial seqno to avoid collision */
97401 get_random_bytes(&random_seqno, sizeof(random_seqno));
97402- atomic_set(&bat_priv->frag_seqno, random_seqno);
97403+ atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
97404
97405 bat_priv->primary_if = NULL;
97406 bat_priv->num_ifaces = 0;
97407diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
97408index 78370ab..1cb3614 100644
97409--- a/net/batman-adv/types.h
97410+++ b/net/batman-adv/types.h
97411@@ -66,7 +66,7 @@ enum batadv_dhcp_recipient {
97412 struct batadv_hard_iface_bat_iv {
97413 unsigned char *ogm_buff;
97414 int ogm_buff_len;
97415- atomic_t ogm_seqno;
97416+ atomic_unchecked_t ogm_seqno;
97417 };
97418
97419 /**
97420@@ -714,7 +714,7 @@ struct batadv_priv {
97421 atomic_t bonding;
97422 atomic_t fragmentation;
97423 atomic_t packet_size_max;
97424- atomic_t frag_seqno;
97425+ atomic_unchecked_t frag_seqno;
97426 #ifdef CONFIG_BATMAN_ADV_BLA
97427 atomic_t bridge_loop_avoidance;
97428 #endif
97429@@ -730,7 +730,7 @@ struct batadv_priv {
97430 #endif
97431 uint32_t isolation_mark;
97432 uint32_t isolation_mark_mask;
97433- atomic_t bcast_seqno;
97434+ atomic_unchecked_t bcast_seqno;
97435 atomic_t bcast_queue_left;
97436 atomic_t batman_queue_left;
97437 char num_ifaces;
97438diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
97439index 7552f9e..074ce29 100644
97440--- a/net/bluetooth/hci_sock.c
97441+++ b/net/bluetooth/hci_sock.c
97442@@ -1052,7 +1052,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
97443 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
97444 }
97445
97446- len = min_t(unsigned int, len, sizeof(uf));
97447+ len = min((size_t)len, sizeof(uf));
97448 if (copy_from_user(&uf, optval, len)) {
97449 err = -EFAULT;
97450 break;
97451diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
97452index b0ad2c7..96f6a5e 100644
97453--- a/net/bluetooth/l2cap_core.c
97454+++ b/net/bluetooth/l2cap_core.c
97455@@ -3740,8 +3740,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
97456 break;
97457
97458 case L2CAP_CONF_RFC:
97459- if (olen == sizeof(rfc))
97460- memcpy(&rfc, (void *)val, olen);
97461+ if (olen != sizeof(rfc))
97462+ break;
97463+
97464+ memcpy(&rfc, (void *)val, olen);
97465
97466 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
97467 rfc.mode != chan->mode)
97468diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
97469index d58f76b..b69600a 100644
97470--- a/net/bluetooth/l2cap_sock.c
97471+++ b/net/bluetooth/l2cap_sock.c
97472@@ -625,7 +625,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
97473 struct sock *sk = sock->sk;
97474 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
97475 struct l2cap_options opts;
97476- int len, err = 0;
97477+ int err = 0;
97478+ size_t len = optlen;
97479 u32 opt;
97480
97481 BT_DBG("sk %p", sk);
97482@@ -652,7 +653,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
97483 opts.max_tx = chan->max_tx;
97484 opts.txwin_size = chan->tx_win;
97485
97486- len = min_t(unsigned int, sizeof(opts), optlen);
97487+ len = min(sizeof(opts), len);
97488 if (copy_from_user((char *) &opts, optval, len)) {
97489 err = -EFAULT;
97490 break;
97491@@ -734,7 +735,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
97492 struct bt_security sec;
97493 struct bt_power pwr;
97494 struct l2cap_conn *conn;
97495- int len, err = 0;
97496+ int err = 0;
97497+ size_t len = optlen;
97498 u32 opt;
97499
97500 BT_DBG("sk %p", sk);
97501@@ -757,7 +759,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
97502
97503 sec.level = BT_SECURITY_LOW;
97504
97505- len = min_t(unsigned int, sizeof(sec), optlen);
97506+ len = min(sizeof(sec), len);
97507 if (copy_from_user((char *) &sec, optval, len)) {
97508 err = -EFAULT;
97509 break;
97510@@ -857,7 +859,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
97511
97512 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
97513
97514- len = min_t(unsigned int, sizeof(pwr), optlen);
97515+ len = min(sizeof(pwr), len);
97516 if (copy_from_user((char *) &pwr, optval, len)) {
97517 err = -EFAULT;
97518 break;
97519diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
97520index 3c2d3e4..884855a 100644
97521--- a/net/bluetooth/rfcomm/sock.c
97522+++ b/net/bluetooth/rfcomm/sock.c
97523@@ -672,7 +672,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
97524 struct sock *sk = sock->sk;
97525 struct bt_security sec;
97526 int err = 0;
97527- size_t len;
97528+ size_t len = optlen;
97529 u32 opt;
97530
97531 BT_DBG("sk %p", sk);
97532@@ -694,7 +694,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
97533
97534 sec.level = BT_SECURITY_LOW;
97535
97536- len = min_t(unsigned int, sizeof(sec), optlen);
97537+ len = min(sizeof(sec), len);
97538 if (copy_from_user((char *) &sec, optval, len)) {
97539 err = -EFAULT;
97540 break;
97541diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
97542index f9c0980a..fcbbfeb 100644
97543--- a/net/bluetooth/rfcomm/tty.c
97544+++ b/net/bluetooth/rfcomm/tty.c
97545@@ -717,7 +717,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
97546 BT_DBG("tty %p id %d", tty, tty->index);
97547
97548 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
97549- dev->channel, dev->port.count);
97550+ dev->channel, atomic_read(&dev->port.count));
97551
97552 err = tty_port_open(&dev->port, tty, filp);
97553 if (err)
97554@@ -740,7 +740,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
97555 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
97556
97557 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
97558- dev->port.count);
97559+ atomic_read(&dev->port.count));
97560
97561 tty_port_close(&dev->port, tty, filp);
97562 }
97563diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
97564index 0e474b1..fb7109c 100644
97565--- a/net/bridge/netfilter/ebtables.c
97566+++ b/net/bridge/netfilter/ebtables.c
97567@@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
97568 tmp.valid_hooks = t->table->valid_hooks;
97569 }
97570 mutex_unlock(&ebt_mutex);
97571- if (copy_to_user(user, &tmp, *len) != 0) {
97572+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
97573 BUGPRINT("c2u Didn't work\n");
97574 ret = -EFAULT;
97575 break;
97576@@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
97577 goto out;
97578 tmp.valid_hooks = t->valid_hooks;
97579
97580- if (copy_to_user(user, &tmp, *len) != 0) {
97581+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
97582 ret = -EFAULT;
97583 break;
97584 }
97585@@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
97586 tmp.entries_size = t->table->entries_size;
97587 tmp.valid_hooks = t->table->valid_hooks;
97588
97589- if (copy_to_user(user, &tmp, *len) != 0) {
97590+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
97591 ret = -EFAULT;
97592 break;
97593 }
97594diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
97595index 0f45522..dab651f 100644
97596--- a/net/caif/cfctrl.c
97597+++ b/net/caif/cfctrl.c
97598@@ -10,6 +10,7 @@
97599 #include <linux/spinlock.h>
97600 #include <linux/slab.h>
97601 #include <linux/pkt_sched.h>
97602+#include <linux/sched.h>
97603 #include <net/caif/caif_layer.h>
97604 #include <net/caif/cfpkt.h>
97605 #include <net/caif/cfctrl.h>
97606@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
97607 memset(&dev_info, 0, sizeof(dev_info));
97608 dev_info.id = 0xff;
97609 cfsrvl_init(&this->serv, 0, &dev_info, false);
97610- atomic_set(&this->req_seq_no, 1);
97611- atomic_set(&this->rsp_seq_no, 1);
97612+ atomic_set_unchecked(&this->req_seq_no, 1);
97613+ atomic_set_unchecked(&this->rsp_seq_no, 1);
97614 this->serv.layer.receive = cfctrl_recv;
97615 sprintf(this->serv.layer.name, "ctrl");
97616 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
97617@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
97618 struct cfctrl_request_info *req)
97619 {
97620 spin_lock_bh(&ctrl->info_list_lock);
97621- atomic_inc(&ctrl->req_seq_no);
97622- req->sequence_no = atomic_read(&ctrl->req_seq_no);
97623+ atomic_inc_unchecked(&ctrl->req_seq_no);
97624+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
97625 list_add_tail(&req->list, &ctrl->list);
97626 spin_unlock_bh(&ctrl->info_list_lock);
97627 }
97628@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
97629 if (p != first)
97630 pr_warn("Requests are not received in order\n");
97631
97632- atomic_set(&ctrl->rsp_seq_no,
97633+ atomic_set_unchecked(&ctrl->rsp_seq_no,
97634 p->sequence_no);
97635 list_del(&p->list);
97636 goto out;
97637diff --git a/net/can/af_can.c b/net/can/af_can.c
97638index a27f8aa..67174a3 100644
97639--- a/net/can/af_can.c
97640+++ b/net/can/af_can.c
97641@@ -863,7 +863,7 @@ static const struct net_proto_family can_family_ops = {
97642 };
97643
97644 /* notifier block for netdevice event */
97645-static struct notifier_block can_netdev_notifier __read_mostly = {
97646+static struct notifier_block can_netdev_notifier = {
97647 .notifier_call = can_notifier,
97648 };
97649
97650diff --git a/net/can/bcm.c b/net/can/bcm.c
97651index dcb75c0..24b1b43 100644
97652--- a/net/can/bcm.c
97653+++ b/net/can/bcm.c
97654@@ -1624,7 +1624,7 @@ static int __init bcm_module_init(void)
97655 }
97656
97657 /* create /proc/net/can-bcm directory */
97658- proc_dir = proc_mkdir("can-bcm", init_net.proc_net);
97659+ proc_dir = proc_mkdir_restrict("can-bcm", init_net.proc_net);
97660 return 0;
97661 }
97662
97663diff --git a/net/can/gw.c b/net/can/gw.c
97664index ac31891..4799c17 100644
97665--- a/net/can/gw.c
97666+++ b/net/can/gw.c
97667@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
97668 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
97669
97670 static HLIST_HEAD(cgw_list);
97671-static struct notifier_block notifier;
97672
97673 static struct kmem_cache *cgw_cache __read_mostly;
97674
97675@@ -947,6 +946,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
97676 return err;
97677 }
97678
97679+static struct notifier_block notifier = {
97680+ .notifier_call = cgw_notifier
97681+};
97682+
97683 static __init int cgw_module_init(void)
97684 {
97685 /* sanitize given module parameter */
97686@@ -962,7 +965,6 @@ static __init int cgw_module_init(void)
97687 return -ENOMEM;
97688
97689 /* set notifier */
97690- notifier.notifier_call = cgw_notifier;
97691 register_netdevice_notifier(&notifier);
97692
97693 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
97694diff --git a/net/can/proc.c b/net/can/proc.c
97695index b543470..d2ddae2 100644
97696--- a/net/can/proc.c
97697+++ b/net/can/proc.c
97698@@ -468,7 +468,7 @@ static void can_remove_proc_readentry(const char *name)
97699 void can_init_proc(void)
97700 {
97701 /* create /proc/net/can directory */
97702- can_dir = proc_mkdir("can", init_net.proc_net);
97703+ can_dir = proc_mkdir_restrict("can", init_net.proc_net);
97704
97705 if (!can_dir) {
97706 printk(KERN_INFO "can: failed to create /proc/net/can . "
97707diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
97708index 30efc5c..cfa1bbc 100644
97709--- a/net/ceph/messenger.c
97710+++ b/net/ceph/messenger.c
97711@@ -187,7 +187,7 @@ static void con_fault(struct ceph_connection *con);
97712 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
97713
97714 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
97715-static atomic_t addr_str_seq = ATOMIC_INIT(0);
97716+static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
97717
97718 static struct page *zero_page; /* used in certain error cases */
97719
97720@@ -198,7 +198,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
97721 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
97722 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
97723
97724- i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
97725+ i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
97726 s = addr_str[i];
97727
97728 switch (ss->ss_family) {
97729diff --git a/net/compat.c b/net/compat.c
97730index f50161f..94fa415 100644
97731--- a/net/compat.c
97732+++ b/net/compat.c
97733@@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
97734 return -EFAULT;
97735 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
97736 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
97737- kmsg->msg_name = compat_ptr(tmp1);
97738- kmsg->msg_iov = compat_ptr(tmp2);
97739- kmsg->msg_control = compat_ptr(tmp3);
97740+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
97741+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
97742+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
97743 return 0;
97744 }
97745
97746@@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
97747
97748 if (kern_msg->msg_namelen) {
97749 if (mode == VERIFY_READ) {
97750- int err = move_addr_to_kernel(kern_msg->msg_name,
97751+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
97752 kern_msg->msg_namelen,
97753 kern_address);
97754 if (err < 0)
97755@@ -99,7 +99,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
97756 kern_msg->msg_name = NULL;
97757
97758 tot_len = iov_from_user_compat_to_kern(kern_iov,
97759- (struct compat_iovec __user *)kern_msg->msg_iov,
97760+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
97761 kern_msg->msg_iovlen);
97762 if (tot_len >= 0)
97763 kern_msg->msg_iov = kern_iov;
97764@@ -119,20 +119,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
97765
97766 #define CMSG_COMPAT_FIRSTHDR(msg) \
97767 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
97768- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
97769+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
97770 (struct compat_cmsghdr __user *)NULL)
97771
97772 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
97773 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
97774 (ucmlen) <= (unsigned long) \
97775 ((mhdr)->msg_controllen - \
97776- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
97777+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
97778
97779 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
97780 struct compat_cmsghdr __user *cmsg, int cmsg_len)
97781 {
97782 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
97783- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
97784+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
97785 msg->msg_controllen)
97786 return NULL;
97787 return (struct compat_cmsghdr __user *)ptr;
97788@@ -222,7 +222,7 @@ Efault:
97789
97790 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
97791 {
97792- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
97793+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
97794 struct compat_cmsghdr cmhdr;
97795 struct compat_timeval ctv;
97796 struct compat_timespec cts[3];
97797@@ -278,7 +278,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
97798
97799 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
97800 {
97801- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
97802+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
97803 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
97804 int fdnum = scm->fp->count;
97805 struct file **fp = scm->fp->fp;
97806@@ -366,7 +366,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
97807 return -EFAULT;
97808 old_fs = get_fs();
97809 set_fs(KERNEL_DS);
97810- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
97811+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
97812 set_fs(old_fs);
97813
97814 return err;
97815@@ -427,7 +427,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
97816 len = sizeof(ktime);
97817 old_fs = get_fs();
97818 set_fs(KERNEL_DS);
97819- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
97820+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
97821 set_fs(old_fs);
97822
97823 if (!err) {
97824@@ -570,7 +570,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
97825 case MCAST_JOIN_GROUP:
97826 case MCAST_LEAVE_GROUP:
97827 {
97828- struct compat_group_req __user *gr32 = (void *)optval;
97829+ struct compat_group_req __user *gr32 = (void __user *)optval;
97830 struct group_req __user *kgr =
97831 compat_alloc_user_space(sizeof(struct group_req));
97832 u32 interface;
97833@@ -591,7 +591,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
97834 case MCAST_BLOCK_SOURCE:
97835 case MCAST_UNBLOCK_SOURCE:
97836 {
97837- struct compat_group_source_req __user *gsr32 = (void *)optval;
97838+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
97839 struct group_source_req __user *kgsr = compat_alloc_user_space(
97840 sizeof(struct group_source_req));
97841 u32 interface;
97842@@ -612,7 +612,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
97843 }
97844 case MCAST_MSFILTER:
97845 {
97846- struct compat_group_filter __user *gf32 = (void *)optval;
97847+ struct compat_group_filter __user *gf32 = (void __user *)optval;
97848 struct group_filter __user *kgf;
97849 u32 interface, fmode, numsrc;
97850
97851@@ -650,7 +650,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
97852 char __user *optval, int __user *optlen,
97853 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
97854 {
97855- struct compat_group_filter __user *gf32 = (void *)optval;
97856+ struct compat_group_filter __user *gf32 = (void __user *)optval;
97857 struct group_filter __user *kgf;
97858 int __user *koptlen;
97859 u32 interface, fmode, numsrc;
97860@@ -803,7 +803,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
97861
97862 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
97863 return -EINVAL;
97864- if (copy_from_user(a, args, nas[call]))
97865+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
97866 return -EFAULT;
97867 a0 = a[0];
97868 a1 = a[1];
97869diff --git a/net/core/datagram.c b/net/core/datagram.c
97870index a16ed7b..eb44d17 100644
97871--- a/net/core/datagram.c
97872+++ b/net/core/datagram.c
97873@@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
97874 }
97875
97876 kfree_skb(skb);
97877- atomic_inc(&sk->sk_drops);
97878+ atomic_inc_unchecked(&sk->sk_drops);
97879 sk_mem_reclaim_partial(sk);
97880
97881 return err;
97882diff --git a/net/core/dev.c b/net/core/dev.c
97883index 45fa2f1..f3e28ec 100644
97884--- a/net/core/dev.c
97885+++ b/net/core/dev.c
97886@@ -1688,14 +1688,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
97887 {
97888 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
97889 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
97890- atomic_long_inc(&dev->rx_dropped);
97891+ atomic_long_inc_unchecked(&dev->rx_dropped);
97892 kfree_skb(skb);
97893 return NET_RX_DROP;
97894 }
97895 }
97896
97897 if (unlikely(!is_skb_forwardable(dev, skb))) {
97898- atomic_long_inc(&dev->rx_dropped);
97899+ atomic_long_inc_unchecked(&dev->rx_dropped);
97900 kfree_skb(skb);
97901 return NET_RX_DROP;
97902 }
97903@@ -2453,7 +2453,7 @@ static int illegal_highdma(const struct net_device *dev, struct sk_buff *skb)
97904
97905 struct dev_gso_cb {
97906 void (*destructor)(struct sk_buff *skb);
97907-};
97908+} __no_const;
97909
97910 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
97911
97912@@ -3227,7 +3227,7 @@ enqueue:
97913
97914 local_irq_restore(flags);
97915
97916- atomic_long_inc(&skb->dev->rx_dropped);
97917+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
97918 kfree_skb(skb);
97919 return NET_RX_DROP;
97920 }
97921@@ -3308,7 +3308,7 @@ int netif_rx_ni(struct sk_buff *skb)
97922 }
97923 EXPORT_SYMBOL(netif_rx_ni);
97924
97925-static void net_tx_action(struct softirq_action *h)
97926+static __latent_entropy void net_tx_action(void)
97927 {
97928 struct softnet_data *sd = &__get_cpu_var(softnet_data);
97929
97930@@ -3645,7 +3645,7 @@ ncls:
97931 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
97932 } else {
97933 drop:
97934- atomic_long_inc(&skb->dev->rx_dropped);
97935+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
97936 kfree_skb(skb);
97937 /* Jamal, now you will not able to escape explaining
97938 * me how you were going to use this. :-)
97939@@ -4331,7 +4331,7 @@ void netif_napi_del(struct napi_struct *napi)
97940 }
97941 EXPORT_SYMBOL(netif_napi_del);
97942
97943-static void net_rx_action(struct softirq_action *h)
97944+static __latent_entropy void net_rx_action(void)
97945 {
97946 struct softnet_data *sd = &__get_cpu_var(softnet_data);
97947 unsigned long time_limit = jiffies + 2;
97948@@ -6250,7 +6250,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
97949 } else {
97950 netdev_stats_to_stats64(storage, &dev->stats);
97951 }
97952- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
97953+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
97954 return storage;
97955 }
97956 EXPORT_SYMBOL(dev_get_stats);
97957diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
97958index cf999e0..c59a975 100644
97959--- a/net/core/dev_ioctl.c
97960+++ b/net/core/dev_ioctl.c
97961@@ -366,9 +366,13 @@ void dev_load(struct net *net, const char *name)
97962 if (no_module && capable(CAP_NET_ADMIN))
97963 no_module = request_module("netdev-%s", name);
97964 if (no_module && capable(CAP_SYS_MODULE)) {
97965+#ifdef CONFIG_GRKERNSEC_MODHARDEN
97966+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
97967+#else
97968 if (!request_module("%s", name))
97969 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
97970 name);
97971+#endif
97972 }
97973 }
97974 EXPORT_SYMBOL(dev_load);
97975diff --git a/net/core/filter.c b/net/core/filter.c
97976index ad30d62..21c0743 100644
97977--- a/net/core/filter.c
97978+++ b/net/core/filter.c
97979@@ -126,7 +126,7 @@ unsigned int sk_run_filter(const struct sk_buff *skb,
97980 void *ptr;
97981 u32 A = 0; /* Accumulator */
97982 u32 X = 0; /* Index Register */
97983- u32 mem[BPF_MEMWORDS]; /* Scratch Memory Store */
97984+ u32 mem[BPF_MEMWORDS] = {}; /* Scratch Memory Store */
97985 u32 tmp;
97986 int k;
97987
97988@@ -292,10 +292,10 @@ load_b:
97989 X = K;
97990 continue;
97991 case BPF_S_LD_MEM:
97992- A = mem[K];
97993+ A = mem[K&15];
97994 continue;
97995 case BPF_S_LDX_MEM:
97996- X = mem[K];
97997+ X = mem[K&15];
97998 continue;
97999 case BPF_S_MISC_TAX:
98000 X = A;
98001@@ -308,10 +308,10 @@ load_b:
98002 case BPF_S_RET_A:
98003 return A;
98004 case BPF_S_ST:
98005- mem[K] = A;
98006+ mem[K&15] = A;
98007 continue;
98008 case BPF_S_STX:
98009- mem[K] = X;
98010+ mem[K&15] = X;
98011 continue;
98012 case BPF_S_ANC_PROTOCOL:
98013 A = ntohs(skb->protocol);
98014@@ -355,6 +355,10 @@ load_b:
98015
98016 if (skb_is_nonlinear(skb))
98017 return 0;
98018+
98019+ if (skb->len < sizeof(struct nlattr))
98020+ return 0;
98021+
98022 if (A > skb->len - sizeof(struct nlattr))
98023 return 0;
98024
98025@@ -371,11 +375,15 @@ load_b:
98026
98027 if (skb_is_nonlinear(skb))
98028 return 0;
98029+
98030+ if (skb->len < sizeof(struct nlattr))
98031+ return 0;
98032+
98033 if (A > skb->len - sizeof(struct nlattr))
98034 return 0;
98035
98036 nla = (struct nlattr *)&skb->data[A];
98037- if (nla->nla_len > A - skb->len)
98038+ if (nla->nla_len > skb->len - A)
98039 return 0;
98040
98041 nla = nla_find_nested(nla, X);
98042@@ -391,9 +399,10 @@ load_b:
98043 continue;
98044 #endif
98045 default:
98046- WARN_RATELIMIT(1, "Unknown code:%u jt:%u tf:%u k:%u\n",
98047+ WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
98048 fentry->code, fentry->jt,
98049 fentry->jf, fentry->k);
98050+ BUG();
98051 return 0;
98052 }
98053 }
98054@@ -416,7 +425,7 @@ static int check_load_and_stores(struct sock_filter *filter, int flen)
98055 u16 *masks, memvalid = 0; /* one bit per cell, 16 cells */
98056 int pc, ret = 0;
98057
98058- BUILD_BUG_ON(BPF_MEMWORDS > 16);
98059+ BUILD_BUG_ON(BPF_MEMWORDS != 16);
98060 masks = kmalloc(flen * sizeof(*masks), GFP_KERNEL);
98061 if (!masks)
98062 return -ENOMEM;
98063@@ -679,7 +688,7 @@ int sk_unattached_filter_create(struct sk_filter **pfp,
98064 fp = kmalloc(sk_filter_size(fprog->len), GFP_KERNEL);
98065 if (!fp)
98066 return -ENOMEM;
98067- memcpy(fp->insns, fprog->filter, fsize);
98068+ memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
98069
98070 atomic_set(&fp->refcnt, 1);
98071 fp->len = fprog->len;
98072diff --git a/net/core/flow.c b/net/core/flow.c
98073index dfa602c..3103d88 100644
98074--- a/net/core/flow.c
98075+++ b/net/core/flow.c
98076@@ -61,7 +61,7 @@ struct flow_cache {
98077 struct timer_list rnd_timer;
98078 };
98079
98080-atomic_t flow_cache_genid = ATOMIC_INIT(0);
98081+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
98082 EXPORT_SYMBOL(flow_cache_genid);
98083 static struct flow_cache flow_cache_global;
98084 static struct kmem_cache *flow_cachep __read_mostly;
98085@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
98086
98087 static int flow_entry_valid(struct flow_cache_entry *fle)
98088 {
98089- if (atomic_read(&flow_cache_genid) != fle->genid)
98090+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
98091 return 0;
98092 if (fle->object && !fle->object->ops->check(fle->object))
98093 return 0;
98094@@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
98095 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
98096 fcp->hash_count++;
98097 }
98098- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
98099+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
98100 flo = fle->object;
98101 if (!flo)
98102 goto ret_object;
98103@@ -279,7 +279,7 @@ nocache:
98104 }
98105 flo = resolver(net, key, family, dir, flo, ctx);
98106 if (fle) {
98107- fle->genid = atomic_read(&flow_cache_genid);
98108+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
98109 if (!IS_ERR(flo))
98110 fle->object = flo;
98111 else
98112diff --git a/net/core/iovec.c b/net/core/iovec.c
98113index b618694..192bbba 100644
98114--- a/net/core/iovec.c
98115+++ b/net/core/iovec.c
98116@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
98117 if (m->msg_namelen) {
98118 if (mode == VERIFY_READ) {
98119 void __user *namep;
98120- namep = (void __user __force *) m->msg_name;
98121+ namep = (void __force_user *) m->msg_name;
98122 err = move_addr_to_kernel(namep, m->msg_namelen,
98123 address);
98124 if (err < 0)
98125@@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
98126 }
98127
98128 size = m->msg_iovlen * sizeof(struct iovec);
98129- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
98130+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
98131 return -EFAULT;
98132
98133 m->msg_iov = iov;
98134diff --git a/net/core/neighbour.c b/net/core/neighbour.c
98135index e161290..8149aea 100644
98136--- a/net/core/neighbour.c
98137+++ b/net/core/neighbour.c
98138@@ -2824,7 +2824,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
98139 void __user *buffer, size_t *lenp, loff_t *ppos)
98140 {
98141 int size, ret;
98142- struct ctl_table tmp = *ctl;
98143+ ctl_table_no_const tmp = *ctl;
98144
98145 tmp.extra1 = &zero;
98146 tmp.extra2 = &unres_qlen_max;
98147@@ -2886,7 +2886,7 @@ static int neigh_proc_dointvec_zero_intmax(struct ctl_table *ctl, int write,
98148 void __user *buffer,
98149 size_t *lenp, loff_t *ppos)
98150 {
98151- struct ctl_table tmp = *ctl;
98152+ ctl_table_no_const tmp = *ctl;
98153 int ret;
98154
98155 tmp.extra1 = &zero;
98156@@ -3058,11 +3058,12 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
98157 memset(&t->neigh_vars[NEIGH_VAR_GC_INTERVAL], 0,
98158 sizeof(t->neigh_vars[NEIGH_VAR_GC_INTERVAL]));
98159 } else {
98160+ struct neigh_table *ntable = container_of(p, struct neigh_table, parms);
98161 dev_name_source = "default";
98162- t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = (int *)(p + 1);
98163- t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = (int *)(p + 1) + 1;
98164- t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = (int *)(p + 1) + 2;
98165- t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = (int *)(p + 1) + 3;
98166+ t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = &ntable->gc_interval;
98167+ t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = &ntable->gc_thresh1;
98168+ t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = &ntable->gc_thresh2;
98169+ t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = &ntable->gc_thresh3;
98170 }
98171
98172 if (handler) {
98173diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
98174index 2bf8329..2eb1423 100644
98175--- a/net/core/net-procfs.c
98176+++ b/net/core/net-procfs.c
98177@@ -79,7 +79,13 @@ static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
98178 struct rtnl_link_stats64 temp;
98179 const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
98180
98181- seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98182+ if (gr_proc_is_restricted())
98183+ seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98184+ "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
98185+ dev->name, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL,
98186+ 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL);
98187+ else
98188+ seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98189 "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
98190 dev->name, stats->rx_bytes, stats->rx_packets,
98191 stats->rx_errors,
98192@@ -166,7 +172,7 @@ static int softnet_seq_show(struct seq_file *seq, void *v)
98193 return 0;
98194 }
98195
98196-static const struct seq_operations dev_seq_ops = {
98197+const struct seq_operations dev_seq_ops = {
98198 .start = dev_seq_start,
98199 .next = dev_seq_next,
98200 .stop = dev_seq_stop,
98201@@ -196,7 +202,7 @@ static const struct seq_operations softnet_seq_ops = {
98202
98203 static int softnet_seq_open(struct inode *inode, struct file *file)
98204 {
98205- return seq_open(file, &softnet_seq_ops);
98206+ return seq_open_restrict(file, &softnet_seq_ops);
98207 }
98208
98209 static const struct file_operations softnet_seq_fops = {
98210@@ -283,8 +289,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
98211 else
98212 seq_printf(seq, "%04x", ntohs(pt->type));
98213
98214+#ifdef CONFIG_GRKERNSEC_HIDESYM
98215+ seq_printf(seq, " %-8s %pf\n",
98216+ pt->dev ? pt->dev->name : "", NULL);
98217+#else
98218 seq_printf(seq, " %-8s %pf\n",
98219 pt->dev ? pt->dev->name : "", pt->func);
98220+#endif
98221 }
98222
98223 return 0;
98224diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
98225index 81d3a9a..a0bd7a8 100644
98226--- a/net/core/net_namespace.c
98227+++ b/net/core/net_namespace.c
98228@@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
98229 int error;
98230 LIST_HEAD(net_exit_list);
98231
98232- list_add_tail(&ops->list, list);
98233+ pax_list_add_tail((struct list_head *)&ops->list, list);
98234 if (ops->init || (ops->id && ops->size)) {
98235 for_each_net(net) {
98236 error = ops_init(ops, net);
98237@@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
98238
98239 out_undo:
98240 /* If I have an error cleanup all namespaces I initialized */
98241- list_del(&ops->list);
98242+ pax_list_del((struct list_head *)&ops->list);
98243 ops_exit_list(ops, &net_exit_list);
98244 ops_free_list(ops, &net_exit_list);
98245 return error;
98246@@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
98247 struct net *net;
98248 LIST_HEAD(net_exit_list);
98249
98250- list_del(&ops->list);
98251+ pax_list_del((struct list_head *)&ops->list);
98252 for_each_net(net)
98253 list_add_tail(&net->exit_list, &net_exit_list);
98254 ops_exit_list(ops, &net_exit_list);
98255@@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
98256 mutex_lock(&net_mutex);
98257 error = register_pernet_operations(&pernet_list, ops);
98258 if (!error && (first_device == &pernet_list))
98259- first_device = &ops->list;
98260+ first_device = (struct list_head *)&ops->list;
98261 mutex_unlock(&net_mutex);
98262 return error;
98263 }
98264diff --git a/net/core/netpoll.c b/net/core/netpoll.c
98265index df9e6b1..6e68e4e 100644
98266--- a/net/core/netpoll.c
98267+++ b/net/core/netpoll.c
98268@@ -435,7 +435,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
98269 struct udphdr *udph;
98270 struct iphdr *iph;
98271 struct ethhdr *eth;
98272- static atomic_t ip_ident;
98273+ static atomic_unchecked_t ip_ident;
98274 struct ipv6hdr *ip6h;
98275
98276 udp_len = len + sizeof(*udph);
98277@@ -506,7 +506,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
98278 put_unaligned(0x45, (unsigned char *)iph);
98279 iph->tos = 0;
98280 put_unaligned(htons(ip_len), &(iph->tot_len));
98281- iph->id = htons(atomic_inc_return(&ip_ident));
98282+ iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
98283 iph->frag_off = 0;
98284 iph->ttl = 64;
98285 iph->protocol = IPPROTO_UDP;
98286diff --git a/net/core/pktgen.c b/net/core/pktgen.c
98287index fdac61c..e5e5b46 100644
98288--- a/net/core/pktgen.c
98289+++ b/net/core/pktgen.c
98290@@ -3719,7 +3719,7 @@ static int __net_init pg_net_init(struct net *net)
98291 pn->net = net;
98292 INIT_LIST_HEAD(&pn->pktgen_threads);
98293 pn->pktgen_exiting = false;
98294- pn->proc_dir = proc_mkdir(PG_PROC_DIR, pn->net->proc_net);
98295+ pn->proc_dir = proc_mkdir_restrict(PG_PROC_DIR, pn->net->proc_net);
98296 if (!pn->proc_dir) {
98297 pr_warn("cannot create /proc/net/%s\n", PG_PROC_DIR);
98298 return -ENODEV;
98299diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
98300index 120eecc..cd1ec44 100644
98301--- a/net/core/rtnetlink.c
98302+++ b/net/core/rtnetlink.c
98303@@ -58,7 +58,7 @@ struct rtnl_link {
98304 rtnl_doit_func doit;
98305 rtnl_dumpit_func dumpit;
98306 rtnl_calcit_func calcit;
98307-};
98308+} __no_const;
98309
98310 static DEFINE_MUTEX(rtnl_mutex);
98311
98312@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
98313 if (rtnl_link_ops_get(ops->kind))
98314 return -EEXIST;
98315
98316- if (!ops->dellink)
98317- ops->dellink = unregister_netdevice_queue;
98318+ if (!ops->dellink) {
98319+ pax_open_kernel();
98320+ *(void **)&ops->dellink = unregister_netdevice_queue;
98321+ pax_close_kernel();
98322+ }
98323
98324- list_add_tail(&ops->list, &link_ops);
98325+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
98326 return 0;
98327 }
98328 EXPORT_SYMBOL_GPL(__rtnl_link_register);
98329@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
98330 for_each_net(net) {
98331 __rtnl_kill_links(net, ops);
98332 }
98333- list_del(&ops->list);
98334+ pax_list_del((struct list_head *)&ops->list);
98335 }
98336 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
98337
98338diff --git a/net/core/scm.c b/net/core/scm.c
98339index b442e7e..6f5b5a2 100644
98340--- a/net/core/scm.c
98341+++ b/net/core/scm.c
98342@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
98343 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
98344 {
98345 struct cmsghdr __user *cm
98346- = (__force struct cmsghdr __user *)msg->msg_control;
98347+ = (struct cmsghdr __force_user *)msg->msg_control;
98348 struct cmsghdr cmhdr;
98349 int cmlen = CMSG_LEN(len);
98350 int err;
98351@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
98352 err = -EFAULT;
98353 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
98354 goto out;
98355- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
98356+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
98357 goto out;
98358 cmlen = CMSG_SPACE(len);
98359 if (msg->msg_controllen < cmlen)
98360@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
98361 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
98362 {
98363 struct cmsghdr __user *cm
98364- = (__force struct cmsghdr __user*)msg->msg_control;
98365+ = (struct cmsghdr __force_user *)msg->msg_control;
98366
98367 int fdmax = 0;
98368 int fdnum = scm->fp->count;
98369@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
98370 if (fdnum < fdmax)
98371 fdmax = fdnum;
98372
98373- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
98374+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
98375 i++, cmfptr++)
98376 {
98377 struct socket *sock;
98378diff --git a/net/core/skbuff.c b/net/core/skbuff.c
98379index 90b96a1..cd18f16d 100644
98380--- a/net/core/skbuff.c
98381+++ b/net/core/skbuff.c
98382@@ -2003,7 +2003,7 @@ EXPORT_SYMBOL(__skb_checksum);
98383 __wsum skb_checksum(const struct sk_buff *skb, int offset,
98384 int len, __wsum csum)
98385 {
98386- const struct skb_checksum_ops ops = {
98387+ static const struct skb_checksum_ops ops = {
98388 .update = csum_partial_ext,
98389 .combine = csum_block_add_ext,
98390 };
98391@@ -3220,13 +3220,15 @@ void __init skb_init(void)
98392 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
98393 sizeof(struct sk_buff),
98394 0,
98395- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
98396+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
98397+ SLAB_NO_SANITIZE,
98398 NULL);
98399 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
98400 (2*sizeof(struct sk_buff)) +
98401 sizeof(atomic_t),
98402 0,
98403- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
98404+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
98405+ SLAB_NO_SANITIZE,
98406 NULL);
98407 }
98408
98409diff --git a/net/core/sock.c b/net/core/sock.c
98410index c0fc6bd..51d8326 100644
98411--- a/net/core/sock.c
98412+++ b/net/core/sock.c
98413@@ -393,7 +393,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
98414 struct sk_buff_head *list = &sk->sk_receive_queue;
98415
98416 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
98417- atomic_inc(&sk->sk_drops);
98418+ atomic_inc_unchecked(&sk->sk_drops);
98419 trace_sock_rcvqueue_full(sk, skb);
98420 return -ENOMEM;
98421 }
98422@@ -403,7 +403,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
98423 return err;
98424
98425 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
98426- atomic_inc(&sk->sk_drops);
98427+ atomic_inc_unchecked(&sk->sk_drops);
98428 return -ENOBUFS;
98429 }
98430
98431@@ -423,7 +423,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
98432 skb_dst_force(skb);
98433
98434 spin_lock_irqsave(&list->lock, flags);
98435- skb->dropcount = atomic_read(&sk->sk_drops);
98436+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
98437 __skb_queue_tail(list, skb);
98438 spin_unlock_irqrestore(&list->lock, flags);
98439
98440@@ -443,7 +443,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
98441 skb->dev = NULL;
98442
98443 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
98444- atomic_inc(&sk->sk_drops);
98445+ atomic_inc_unchecked(&sk->sk_drops);
98446 goto discard_and_relse;
98447 }
98448 if (nested)
98449@@ -461,7 +461,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
98450 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
98451 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
98452 bh_unlock_sock(sk);
98453- atomic_inc(&sk->sk_drops);
98454+ atomic_inc_unchecked(&sk->sk_drops);
98455 goto discard_and_relse;
98456 }
98457
98458@@ -949,12 +949,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
98459 struct timeval tm;
98460 } v;
98461
98462- int lv = sizeof(int);
98463- int len;
98464+ unsigned int lv = sizeof(int);
98465+ unsigned int len;
98466
98467 if (get_user(len, optlen))
98468 return -EFAULT;
98469- if (len < 0)
98470+ if (len > INT_MAX)
98471 return -EINVAL;
98472
98473 memset(&v, 0, sizeof(v));
98474@@ -1106,11 +1106,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
98475
98476 case SO_PEERNAME:
98477 {
98478- char address[128];
98479+ char address[_K_SS_MAXSIZE];
98480
98481 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
98482 return -ENOTCONN;
98483- if (lv < len)
98484+ if (lv < len || sizeof address < len)
98485 return -EINVAL;
98486 if (copy_to_user(optval, address, len))
98487 return -EFAULT;
98488@@ -1191,7 +1191,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
98489
98490 if (len > lv)
98491 len = lv;
98492- if (copy_to_user(optval, &v, len))
98493+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
98494 return -EFAULT;
98495 lenout:
98496 if (put_user(len, optlen))
98497@@ -2326,7 +2326,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
98498 */
98499 smp_wmb();
98500 atomic_set(&sk->sk_refcnt, 1);
98501- atomic_set(&sk->sk_drops, 0);
98502+ atomic_set_unchecked(&sk->sk_drops, 0);
98503 }
98504 EXPORT_SYMBOL(sock_init_data);
98505
98506@@ -2454,6 +2454,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
98507 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
98508 int level, int type)
98509 {
98510+ struct sock_extended_err ee;
98511 struct sock_exterr_skb *serr;
98512 struct sk_buff *skb, *skb2;
98513 int copied, err;
98514@@ -2475,7 +2476,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
98515 sock_recv_timestamp(msg, sk, skb);
98516
98517 serr = SKB_EXT_ERR(skb);
98518- put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
98519+ ee = serr->ee;
98520+ put_cmsg(msg, level, type, sizeof ee, &ee);
98521
98522 msg->msg_flags |= MSG_ERRQUEUE;
98523 err = copied;
98524diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
98525index a0e9cf6..ef7f9ed 100644
98526--- a/net/core/sock_diag.c
98527+++ b/net/core/sock_diag.c
98528@@ -9,26 +9,33 @@
98529 #include <linux/inet_diag.h>
98530 #include <linux/sock_diag.h>
98531
98532-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
98533+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
98534 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
98535 static DEFINE_MUTEX(sock_diag_table_mutex);
98536
98537 int sock_diag_check_cookie(void *sk, __u32 *cookie)
98538 {
98539+#ifndef CONFIG_GRKERNSEC_HIDESYM
98540 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
98541 cookie[1] != INET_DIAG_NOCOOKIE) &&
98542 ((u32)(unsigned long)sk != cookie[0] ||
98543 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
98544 return -ESTALE;
98545 else
98546+#endif
98547 return 0;
98548 }
98549 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
98550
98551 void sock_diag_save_cookie(void *sk, __u32 *cookie)
98552 {
98553+#ifdef CONFIG_GRKERNSEC_HIDESYM
98554+ cookie[0] = 0;
98555+ cookie[1] = 0;
98556+#else
98557 cookie[0] = (u32)(unsigned long)sk;
98558 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
98559+#endif
98560 }
98561 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
98562
98563@@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
98564 mutex_lock(&sock_diag_table_mutex);
98565 if (sock_diag_handlers[hndl->family])
98566 err = -EBUSY;
98567- else
98568+ else {
98569+ pax_open_kernel();
98570 sock_diag_handlers[hndl->family] = hndl;
98571+ pax_close_kernel();
98572+ }
98573 mutex_unlock(&sock_diag_table_mutex);
98574
98575 return err;
98576@@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
98577
98578 mutex_lock(&sock_diag_table_mutex);
98579 BUG_ON(sock_diag_handlers[family] != hnld);
98580+ pax_open_kernel();
98581 sock_diag_handlers[family] = NULL;
98582+ pax_close_kernel();
98583 mutex_unlock(&sock_diag_table_mutex);
98584 }
98585 EXPORT_SYMBOL_GPL(sock_diag_unregister);
98586diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
98587index cf9cd13..8b56af3 100644
98588--- a/net/core/sysctl_net_core.c
98589+++ b/net/core/sysctl_net_core.c
98590@@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
98591 {
98592 unsigned int orig_size, size;
98593 int ret, i;
98594- struct ctl_table tmp = {
98595+ ctl_table_no_const tmp = {
98596 .data = &size,
98597 .maxlen = sizeof(size),
98598 .mode = table->mode
98599@@ -200,7 +200,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
98600 void __user *buffer, size_t *lenp, loff_t *ppos)
98601 {
98602 char id[IFNAMSIZ];
98603- struct ctl_table tbl = {
98604+ ctl_table_no_const tbl = {
98605 .data = id,
98606 .maxlen = IFNAMSIZ,
98607 };
98608@@ -379,13 +379,12 @@ static struct ctl_table netns_core_table[] = {
98609
98610 static __net_init int sysctl_core_net_init(struct net *net)
98611 {
98612- struct ctl_table *tbl;
98613+ ctl_table_no_const *tbl = NULL;
98614
98615 net->core.sysctl_somaxconn = SOMAXCONN;
98616
98617- tbl = netns_core_table;
98618 if (!net_eq(net, &init_net)) {
98619- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
98620+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
98621 if (tbl == NULL)
98622 goto err_dup;
98623
98624@@ -395,17 +394,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
98625 if (net->user_ns != &init_user_ns) {
98626 tbl[0].procname = NULL;
98627 }
98628- }
98629-
98630- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
98631+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
98632+ } else
98633+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
98634 if (net->core.sysctl_hdr == NULL)
98635 goto err_reg;
98636
98637 return 0;
98638
98639 err_reg:
98640- if (tbl != netns_core_table)
98641- kfree(tbl);
98642+ kfree(tbl);
98643 err_dup:
98644 return -ENOMEM;
98645 }
98646@@ -420,7 +418,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
98647 kfree(tbl);
98648 }
98649
98650-static __net_initdata struct pernet_operations sysctl_core_ops = {
98651+static __net_initconst struct pernet_operations sysctl_core_ops = {
98652 .init = sysctl_core_net_init,
98653 .exit = sysctl_core_net_exit,
98654 };
98655diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
98656index 4c04848..f575934 100644
98657--- a/net/decnet/af_decnet.c
98658+++ b/net/decnet/af_decnet.c
98659@@ -465,6 +465,7 @@ static struct proto dn_proto = {
98660 .sysctl_rmem = sysctl_decnet_rmem,
98661 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
98662 .obj_size = sizeof(struct dn_sock),
98663+ .slab_flags = SLAB_USERCOPY,
98664 };
98665
98666 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
98667diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
98668index a603823..a36ee0b 100644
98669--- a/net/decnet/dn_dev.c
98670+++ b/net/decnet/dn_dev.c
98671@@ -200,7 +200,7 @@ static struct dn_dev_sysctl_table {
98672 .extra1 = &min_t3,
98673 .extra2 = &max_t3
98674 },
98675- {0}
98676+ { }
98677 },
98678 };
98679
98680diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
98681index 5325b54..a0d4d69 100644
98682--- a/net/decnet/sysctl_net_decnet.c
98683+++ b/net/decnet/sysctl_net_decnet.c
98684@@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
98685
98686 if (len > *lenp) len = *lenp;
98687
98688- if (copy_to_user(buffer, addr, len))
98689+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
98690 return -EFAULT;
98691
98692 *lenp = len;
98693@@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
98694
98695 if (len > *lenp) len = *lenp;
98696
98697- if (copy_to_user(buffer, devname, len))
98698+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
98699 return -EFAULT;
98700
98701 *lenp = len;
98702diff --git a/net/ieee802154/dgram.c b/net/ieee802154/dgram.c
98703index 1846c1f..96d4a9f 100644
98704--- a/net/ieee802154/dgram.c
98705+++ b/net/ieee802154/dgram.c
98706@@ -313,8 +313,9 @@ static int dgram_recvmsg(struct kiocb *iocb, struct sock *sk,
98707 if (saddr) {
98708 saddr->family = AF_IEEE802154;
98709 saddr->addr = mac_cb(skb)->sa;
98710+ }
98711+ if (addr_len)
98712 *addr_len = sizeof(*saddr);
98713- }
98714
98715 if (flags & MSG_TRUNC)
98716 copied = skb->len;
98717diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
98718index 19ab78a..bf575c9 100644
98719--- a/net/ipv4/af_inet.c
98720+++ b/net/ipv4/af_inet.c
98721@@ -1703,13 +1703,9 @@ static int __init inet_init(void)
98722
98723 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
98724
98725- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
98726- if (!sysctl_local_reserved_ports)
98727- goto out;
98728-
98729 rc = proto_register(&tcp_prot, 1);
98730 if (rc)
98731- goto out_free_reserved_ports;
98732+ goto out;
98733
98734 rc = proto_register(&udp_prot, 1);
98735 if (rc)
98736@@ -1816,8 +1812,6 @@ out_unregister_udp_proto:
98737 proto_unregister(&udp_prot);
98738 out_unregister_tcp_proto:
98739 proto_unregister(&tcp_prot);
98740-out_free_reserved_ports:
98741- kfree(sysctl_local_reserved_ports);
98742 goto out;
98743 }
98744
98745diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
98746index bdbf68b..deb4759 100644
98747--- a/net/ipv4/devinet.c
98748+++ b/net/ipv4/devinet.c
98749@@ -1543,7 +1543,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
98750 idx = 0;
98751 head = &net->dev_index_head[h];
98752 rcu_read_lock();
98753- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
98754+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
98755 net->dev_base_seq;
98756 hlist_for_each_entry_rcu(dev, head, index_hlist) {
98757 if (idx < s_idx)
98758@@ -1861,7 +1861,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
98759 idx = 0;
98760 head = &net->dev_index_head[h];
98761 rcu_read_lock();
98762- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
98763+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
98764 net->dev_base_seq;
98765 hlist_for_each_entry_rcu(dev, head, index_hlist) {
98766 if (idx < s_idx)
98767@@ -2096,7 +2096,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
98768 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
98769 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
98770
98771-static struct devinet_sysctl_table {
98772+static const struct devinet_sysctl_table {
98773 struct ctl_table_header *sysctl_header;
98774 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
98775 } devinet_sysctl = {
98776@@ -2218,7 +2218,7 @@ static __net_init int devinet_init_net(struct net *net)
98777 int err;
98778 struct ipv4_devconf *all, *dflt;
98779 #ifdef CONFIG_SYSCTL
98780- struct ctl_table *tbl = ctl_forward_entry;
98781+ ctl_table_no_const *tbl = NULL;
98782 struct ctl_table_header *forw_hdr;
98783 #endif
98784
98785@@ -2236,7 +2236,7 @@ static __net_init int devinet_init_net(struct net *net)
98786 goto err_alloc_dflt;
98787
98788 #ifdef CONFIG_SYSCTL
98789- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
98790+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
98791 if (tbl == NULL)
98792 goto err_alloc_ctl;
98793
98794@@ -2256,7 +2256,10 @@ static __net_init int devinet_init_net(struct net *net)
98795 goto err_reg_dflt;
98796
98797 err = -ENOMEM;
98798- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
98799+ if (!net_eq(net, &init_net))
98800+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
98801+ else
98802+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
98803 if (forw_hdr == NULL)
98804 goto err_reg_ctl;
98805 net->ipv4.forw_hdr = forw_hdr;
98806@@ -2272,8 +2275,7 @@ err_reg_ctl:
98807 err_reg_dflt:
98808 __devinet_sysctl_unregister(all);
98809 err_reg_all:
98810- if (tbl != ctl_forward_entry)
98811- kfree(tbl);
98812+ kfree(tbl);
98813 err_alloc_ctl:
98814 #endif
98815 if (dflt != &ipv4_devconf_dflt)
98816diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
98817index c7539e2..b455e51 100644
98818--- a/net/ipv4/fib_frontend.c
98819+++ b/net/ipv4/fib_frontend.c
98820@@ -1015,12 +1015,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
98821 #ifdef CONFIG_IP_ROUTE_MULTIPATH
98822 fib_sync_up(dev);
98823 #endif
98824- atomic_inc(&net->ipv4.dev_addr_genid);
98825+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
98826 rt_cache_flush(dev_net(dev));
98827 break;
98828 case NETDEV_DOWN:
98829 fib_del_ifaddr(ifa, NULL);
98830- atomic_inc(&net->ipv4.dev_addr_genid);
98831+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
98832 if (ifa->ifa_dev->ifa_list == NULL) {
98833 /* Last address was deleted from this interface.
98834 * Disable IP.
98835@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
98836 #ifdef CONFIG_IP_ROUTE_MULTIPATH
98837 fib_sync_up(dev);
98838 #endif
98839- atomic_inc(&net->ipv4.dev_addr_genid);
98840+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
98841 rt_cache_flush(net);
98842 break;
98843 case NETDEV_DOWN:
98844diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
98845index b53f0bf..3585b33 100644
98846--- a/net/ipv4/fib_semantics.c
98847+++ b/net/ipv4/fib_semantics.c
98848@@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
98849 nh->nh_saddr = inet_select_addr(nh->nh_dev,
98850 nh->nh_gw,
98851 nh->nh_parent->fib_scope);
98852- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
98853+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
98854
98855 return nh->nh_saddr;
98856 }
98857diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
98858index 0d1e2cb..4501a2c 100644
98859--- a/net/ipv4/inet_connection_sock.c
98860+++ b/net/ipv4/inet_connection_sock.c
98861@@ -29,7 +29,7 @@ const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
98862 EXPORT_SYMBOL(inet_csk_timer_bug_msg);
98863 #endif
98864
98865-unsigned long *sysctl_local_reserved_ports;
98866+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
98867 EXPORT_SYMBOL(sysctl_local_reserved_ports);
98868
98869 void inet_get_local_port_range(struct net *net, int *low, int *high)
98870diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
98871index 8b9cf27..0d8d592 100644
98872--- a/net/ipv4/inet_hashtables.c
98873+++ b/net/ipv4/inet_hashtables.c
98874@@ -18,6 +18,7 @@
98875 #include <linux/sched.h>
98876 #include <linux/slab.h>
98877 #include <linux/wait.h>
98878+#include <linux/security.h>
98879
98880 #include <net/inet_connection_sock.h>
98881 #include <net/inet_hashtables.h>
98882@@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
98883 return inet_ehashfn(net, laddr, lport, faddr, fport);
98884 }
98885
98886+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
98887+
98888 /*
98889 * Allocate and initialize a new local port bind bucket.
98890 * The bindhash mutex for snum's hash chain must be held here.
98891@@ -554,6 +557,8 @@ ok:
98892 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
98893 spin_unlock(&head->lock);
98894
98895+ gr_update_task_in_ip_table(current, inet_sk(sk));
98896+
98897 if (tw) {
98898 inet_twsk_deschedule(tw, death_row);
98899 while (twrefcnt) {
98900diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
98901index 48f4244..f56d83a 100644
98902--- a/net/ipv4/inetpeer.c
98903+++ b/net/ipv4/inetpeer.c
98904@@ -496,8 +496,8 @@ relookup:
98905 if (p) {
98906 p->daddr = *daddr;
98907 atomic_set(&p->refcnt, 1);
98908- atomic_set(&p->rid, 0);
98909- atomic_set(&p->ip_id_count,
98910+ atomic_set_unchecked(&p->rid, 0);
98911+ atomic_set_unchecked(&p->ip_id_count,
98912 (daddr->family == AF_INET) ?
98913 secure_ip_id(daddr->addr.a4) :
98914 secure_ipv6_id(daddr->addr.a6));
98915diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
98916index c10a3ce..dd71f84 100644
98917--- a/net/ipv4/ip_fragment.c
98918+++ b/net/ipv4/ip_fragment.c
98919@@ -283,7 +283,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
98920 return 0;
98921
98922 start = qp->rid;
98923- end = atomic_inc_return(&peer->rid);
98924+ end = atomic_inc_return_unchecked(&peer->rid);
98925 qp->rid = end;
98926
98927 rc = qp->q.fragments && (end - start) > max;
98928@@ -760,12 +760,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
98929
98930 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
98931 {
98932- struct ctl_table *table;
98933+ ctl_table_no_const *table = NULL;
98934 struct ctl_table_header *hdr;
98935
98936- table = ip4_frags_ns_ctl_table;
98937 if (!net_eq(net, &init_net)) {
98938- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
98939+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
98940 if (table == NULL)
98941 goto err_alloc;
98942
98943@@ -776,9 +775,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
98944 /* Don't export sysctls to unprivileged users */
98945 if (net->user_ns != &init_user_ns)
98946 table[0].procname = NULL;
98947- }
98948+ hdr = register_net_sysctl(net, "net/ipv4", table);
98949+ } else
98950+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
98951
98952- hdr = register_net_sysctl(net, "net/ipv4", table);
98953 if (hdr == NULL)
98954 goto err_reg;
98955
98956@@ -786,8 +786,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
98957 return 0;
98958
98959 err_reg:
98960- if (!net_eq(net, &init_net))
98961- kfree(table);
98962+ kfree(table);
98963 err_alloc:
98964 return -ENOMEM;
98965 }
98966diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
98967index ec4f762..4ce3645 100644
98968--- a/net/ipv4/ip_gre.c
98969+++ b/net/ipv4/ip_gre.c
98970@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
98971 module_param(log_ecn_error, bool, 0644);
98972 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
98973
98974-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
98975+static struct rtnl_link_ops ipgre_link_ops;
98976 static int ipgre_tunnel_init(struct net_device *dev);
98977
98978 static int ipgre_net_id __read_mostly;
98979@@ -732,7 +732,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
98980 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
98981 };
98982
98983-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
98984+static struct rtnl_link_ops ipgre_link_ops = {
98985 .kind = "gre",
98986 .maxtype = IFLA_GRE_MAX,
98987 .policy = ipgre_policy,
98988@@ -746,7 +746,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
98989 .fill_info = ipgre_fill_info,
98990 };
98991
98992-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
98993+static struct rtnl_link_ops ipgre_tap_ops = {
98994 .kind = "gretap",
98995 .maxtype = IFLA_GRE_MAX,
98996 .policy = ipgre_policy,
98997diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
98998index 580dd96..9fcef7e 100644
98999--- a/net/ipv4/ip_sockglue.c
99000+++ b/net/ipv4/ip_sockglue.c
99001@@ -1171,7 +1171,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
99002 len = min_t(unsigned int, len, opt->optlen);
99003 if (put_user(len, optlen))
99004 return -EFAULT;
99005- if (copy_to_user(optval, opt->__data, len))
99006+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
99007+ copy_to_user(optval, opt->__data, len))
99008 return -EFAULT;
99009 return 0;
99010 }
99011@@ -1302,7 +1303,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
99012 if (sk->sk_type != SOCK_STREAM)
99013 return -ENOPROTOOPT;
99014
99015- msg.msg_control = optval;
99016+ msg.msg_control = (void __force_kernel *)optval;
99017 msg.msg_controllen = len;
99018 msg.msg_flags = flags;
99019
99020diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
99021index 48eafae..defff53 100644
99022--- a/net/ipv4/ip_vti.c
99023+++ b/net/ipv4/ip_vti.c
99024@@ -44,7 +44,7 @@
99025 #include <net/net_namespace.h>
99026 #include <net/netns/generic.h>
99027
99028-static struct rtnl_link_ops vti_link_ops __read_mostly;
99029+static struct rtnl_link_ops vti_link_ops;
99030
99031 static int vti_net_id __read_mostly;
99032 static int vti_tunnel_init(struct net_device *dev);
99033@@ -360,7 +360,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
99034 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
99035 };
99036
99037-static struct rtnl_link_ops vti_link_ops __read_mostly = {
99038+static struct rtnl_link_ops vti_link_ops = {
99039 .kind = "vti",
99040 .maxtype = IFLA_VTI_MAX,
99041 .policy = vti_policy,
99042diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
99043index b3e86ea..18ce98c 100644
99044--- a/net/ipv4/ipconfig.c
99045+++ b/net/ipv4/ipconfig.c
99046@@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
99047
99048 mm_segment_t oldfs = get_fs();
99049 set_fs(get_ds());
99050- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
99051+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
99052 set_fs(oldfs);
99053 return res;
99054 }
99055@@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
99056
99057 mm_segment_t oldfs = get_fs();
99058 set_fs(get_ds());
99059- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
99060+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
99061 set_fs(oldfs);
99062 return res;
99063 }
99064@@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
99065
99066 mm_segment_t oldfs = get_fs();
99067 set_fs(get_ds());
99068- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
99069+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
99070 set_fs(oldfs);
99071 return res;
99072 }
99073diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
99074index 812b183..56cbe9c 100644
99075--- a/net/ipv4/ipip.c
99076+++ b/net/ipv4/ipip.c
99077@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
99078 static int ipip_net_id __read_mostly;
99079
99080 static int ipip_tunnel_init(struct net_device *dev);
99081-static struct rtnl_link_ops ipip_link_ops __read_mostly;
99082+static struct rtnl_link_ops ipip_link_ops;
99083
99084 static int ipip_err(struct sk_buff *skb, u32 info)
99085 {
99086@@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
99087 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
99088 };
99089
99090-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
99091+static struct rtnl_link_ops ipip_link_ops = {
99092 .kind = "ipip",
99093 .maxtype = IFLA_IPTUN_MAX,
99094 .policy = ipip_policy,
99095diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
99096index 59da7cd..e318de1 100644
99097--- a/net/ipv4/netfilter/arp_tables.c
99098+++ b/net/ipv4/netfilter/arp_tables.c
99099@@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
99100 #endif
99101
99102 static int get_info(struct net *net, void __user *user,
99103- const int *len, int compat)
99104+ int len, int compat)
99105 {
99106 char name[XT_TABLE_MAXNAMELEN];
99107 struct xt_table *t;
99108 int ret;
99109
99110- if (*len != sizeof(struct arpt_getinfo)) {
99111- duprintf("length %u != %Zu\n", *len,
99112+ if (len != sizeof(struct arpt_getinfo)) {
99113+ duprintf("length %u != %Zu\n", len,
99114 sizeof(struct arpt_getinfo));
99115 return -EINVAL;
99116 }
99117@@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
99118 info.size = private->size;
99119 strcpy(info.name, name);
99120
99121- if (copy_to_user(user, &info, *len) != 0)
99122+ if (copy_to_user(user, &info, len) != 0)
99123 ret = -EFAULT;
99124 else
99125 ret = 0;
99126@@ -1688,7 +1688,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
99127
99128 switch (cmd) {
99129 case ARPT_SO_GET_INFO:
99130- ret = get_info(sock_net(sk), user, len, 1);
99131+ ret = get_info(sock_net(sk), user, *len, 1);
99132 break;
99133 case ARPT_SO_GET_ENTRIES:
99134 ret = compat_get_entries(sock_net(sk), user, len);
99135@@ -1733,7 +1733,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
99136
99137 switch (cmd) {
99138 case ARPT_SO_GET_INFO:
99139- ret = get_info(sock_net(sk), user, len, 0);
99140+ ret = get_info(sock_net(sk), user, *len, 0);
99141 break;
99142
99143 case ARPT_SO_GET_ENTRIES:
99144diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
99145index 718dfbd..cef4152 100644
99146--- a/net/ipv4/netfilter/ip_tables.c
99147+++ b/net/ipv4/netfilter/ip_tables.c
99148@@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
99149 #endif
99150
99151 static int get_info(struct net *net, void __user *user,
99152- const int *len, int compat)
99153+ int len, int compat)
99154 {
99155 char name[XT_TABLE_MAXNAMELEN];
99156 struct xt_table *t;
99157 int ret;
99158
99159- if (*len != sizeof(struct ipt_getinfo)) {
99160- duprintf("length %u != %zu\n", *len,
99161+ if (len != sizeof(struct ipt_getinfo)) {
99162+ duprintf("length %u != %zu\n", len,
99163 sizeof(struct ipt_getinfo));
99164 return -EINVAL;
99165 }
99166@@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
99167 info.size = private->size;
99168 strcpy(info.name, name);
99169
99170- if (copy_to_user(user, &info, *len) != 0)
99171+ if (copy_to_user(user, &info, len) != 0)
99172 ret = -EFAULT;
99173 else
99174 ret = 0;
99175@@ -1971,7 +1971,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99176
99177 switch (cmd) {
99178 case IPT_SO_GET_INFO:
99179- ret = get_info(sock_net(sk), user, len, 1);
99180+ ret = get_info(sock_net(sk), user, *len, 1);
99181 break;
99182 case IPT_SO_GET_ENTRIES:
99183 ret = compat_get_entries(sock_net(sk), user, len);
99184@@ -2018,7 +2018,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99185
99186 switch (cmd) {
99187 case IPT_SO_GET_INFO:
99188- ret = get_info(sock_net(sk), user, len, 0);
99189+ ret = get_info(sock_net(sk), user, *len, 0);
99190 break;
99191
99192 case IPT_SO_GET_ENTRIES:
99193diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
99194index 2510c02..cfb34fa 100644
99195--- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
99196+++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
99197@@ -720,7 +720,7 @@ static int clusterip_net_init(struct net *net)
99198 spin_lock_init(&cn->lock);
99199
99200 #ifdef CONFIG_PROC_FS
99201- cn->procdir = proc_mkdir("ipt_CLUSTERIP", net->proc_net);
99202+ cn->procdir = proc_mkdir_restrict("ipt_CLUSTERIP", net->proc_net);
99203 if (!cn->procdir) {
99204 pr_err("Unable to proc dir entry\n");
99205 return -ENOMEM;
99206diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
99207index 2d11c09..3f153f8 100644
99208--- a/net/ipv4/ping.c
99209+++ b/net/ipv4/ping.c
99210@@ -59,7 +59,7 @@ struct ping_table {
99211 };
99212
99213 static struct ping_table ping_table;
99214-struct pingv6_ops pingv6_ops;
99215+struct pingv6_ops *pingv6_ops;
99216 EXPORT_SYMBOL_GPL(pingv6_ops);
99217
99218 static u16 ping_port_rover;
99219@@ -255,23 +255,28 @@ int ping_init_sock(struct sock *sk)
99220 struct group_info *group_info = get_current_groups();
99221 int i, j, count = group_info->ngroups;
99222 kgid_t low, high;
99223+ int ret = 0;
99224
99225 inet_get_ping_group_range_net(net, &low, &high);
99226 if (gid_lte(low, group) && gid_lte(group, high))
99227- return 0;
99228+ goto out_release_group;
99229
99230 for (i = 0; i < group_info->nblocks; i++) {
99231 int cp_count = min_t(int, NGROUPS_PER_BLOCK, count);
99232 for (j = 0; j < cp_count; j++) {
99233 kgid_t gid = group_info->blocks[i][j];
99234 if (gid_lte(low, gid) && gid_lte(gid, high))
99235- return 0;
99236+ goto out_release_group;
99237 }
99238
99239 count -= cp_count;
99240 }
99241
99242- return -EACCES;
99243+ ret = -EACCES;
99244+
99245+out_release_group:
99246+ put_group_info(group_info);
99247+ return ret;
99248 }
99249 EXPORT_SYMBOL_GPL(ping_init_sock);
99250
99251@@ -341,7 +346,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
99252 return -ENODEV;
99253 }
99254 }
99255- has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
99256+ has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
99257 scoped);
99258 rcu_read_unlock();
99259
99260@@ -549,7 +554,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
99261 }
99262 #if IS_ENABLED(CONFIG_IPV6)
99263 } else if (skb->protocol == htons(ETH_P_IPV6)) {
99264- harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
99265+ harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
99266 #endif
99267 }
99268
99269@@ -567,7 +572,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
99270 info, (u8 *)icmph);
99271 #if IS_ENABLED(CONFIG_IPV6)
99272 } else if (family == AF_INET6) {
99273- pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
99274+ pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
99275 info, (u8 *)icmph);
99276 #endif
99277 }
99278@@ -837,6 +842,8 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99279 {
99280 struct inet_sock *isk = inet_sk(sk);
99281 int family = sk->sk_family;
99282+ struct sockaddr_in *sin;
99283+ struct sockaddr_in6 *sin6;
99284 struct sk_buff *skb;
99285 int copied, err;
99286
99287@@ -846,12 +853,19 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99288 if (flags & MSG_OOB)
99289 goto out;
99290
99291+ if (addr_len) {
99292+ if (family == AF_INET)
99293+ *addr_len = sizeof(*sin);
99294+ else if (family == AF_INET6 && addr_len)
99295+ *addr_len = sizeof(*sin6);
99296+ }
99297+
99298 if (flags & MSG_ERRQUEUE) {
99299 if (family == AF_INET) {
99300 return ip_recv_error(sk, msg, len, addr_len);
99301 #if IS_ENABLED(CONFIG_IPV6)
99302 } else if (family == AF_INET6) {
99303- return pingv6_ops.ipv6_recv_error(sk, msg, len,
99304+ return pingv6_ops->ipv6_recv_error(sk, msg, len,
99305 addr_len);
99306 #endif
99307 }
99308@@ -883,7 +897,6 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99309 sin->sin_port = 0 /* skb->h.uh->source */;
99310 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
99311 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
99312- *addr_len = sizeof(*sin);
99313 }
99314
99315 if (isk->cmsg_flags)
99316@@ -905,14 +918,13 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99317 sin6->sin6_scope_id =
99318 ipv6_iface_scope_id(&sin6->sin6_addr,
99319 IP6CB(skb)->iif);
99320- *addr_len = sizeof(*sin6);
99321 }
99322
99323 if (inet6_sk(sk)->rxopt.all)
99324- pingv6_ops.ip6_datagram_recv_common_ctl(sk, msg, skb);
99325+ pingv6_ops->ip6_datagram_recv_common_ctl(sk, msg, skb);
99326 if (skb->protocol == htons(ETH_P_IPV6) &&
99327 inet6_sk(sk)->rxopt.all)
99328- pingv6_ops.ip6_datagram_recv_specific_ctl(sk, msg, skb);
99329+ pingv6_ops->ip6_datagram_recv_specific_ctl(sk, msg, skb);
99330 else if (skb->protocol == htons(ETH_P_IP) && isk->cmsg_flags)
99331 ip_cmsg_recv(msg, skb);
99332 #endif
99333@@ -1104,7 +1116,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
99334 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
99335 0, sock_i_ino(sp),
99336 atomic_read(&sp->sk_refcnt), sp,
99337- atomic_read(&sp->sk_drops));
99338+ atomic_read_unchecked(&sp->sk_drops));
99339 }
99340
99341 static int ping_v4_seq_show(struct seq_file *seq, void *v)
99342diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
99343index c04518f..824ebe5 100644
99344--- a/net/ipv4/raw.c
99345+++ b/net/ipv4/raw.c
99346@@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
99347 int raw_rcv(struct sock *sk, struct sk_buff *skb)
99348 {
99349 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
99350- atomic_inc(&sk->sk_drops);
99351+ atomic_inc_unchecked(&sk->sk_drops);
99352 kfree_skb(skb);
99353 return NET_RX_DROP;
99354 }
99355@@ -696,6 +696,9 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99356 if (flags & MSG_OOB)
99357 goto out;
99358
99359+ if (addr_len)
99360+ *addr_len = sizeof(*sin);
99361+
99362 if (flags & MSG_ERRQUEUE) {
99363 err = ip_recv_error(sk, msg, len, addr_len);
99364 goto out;
99365@@ -723,7 +726,6 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99366 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
99367 sin->sin_port = 0;
99368 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
99369- *addr_len = sizeof(*sin);
99370 }
99371 if (inet->cmsg_flags)
99372 ip_cmsg_recv(msg, skb);
99373@@ -748,16 +750,20 @@ static int raw_init(struct sock *sk)
99374
99375 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
99376 {
99377+ struct icmp_filter filter;
99378+
99379 if (optlen > sizeof(struct icmp_filter))
99380 optlen = sizeof(struct icmp_filter);
99381- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
99382+ if (copy_from_user(&filter, optval, optlen))
99383 return -EFAULT;
99384+ raw_sk(sk)->filter = filter;
99385 return 0;
99386 }
99387
99388 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
99389 {
99390 int len, ret = -EFAULT;
99391+ struct icmp_filter filter;
99392
99393 if (get_user(len, optlen))
99394 goto out;
99395@@ -767,8 +773,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
99396 if (len > sizeof(struct icmp_filter))
99397 len = sizeof(struct icmp_filter);
99398 ret = -EFAULT;
99399- if (put_user(len, optlen) ||
99400- copy_to_user(optval, &raw_sk(sk)->filter, len))
99401+ filter = raw_sk(sk)->filter;
99402+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
99403 goto out;
99404 ret = 0;
99405 out: return ret;
99406@@ -997,7 +1003,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
99407 0, 0L, 0,
99408 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
99409 0, sock_i_ino(sp),
99410- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
99411+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
99412 }
99413
99414 static int raw_seq_show(struct seq_file *seq, void *v)
99415diff --git a/net/ipv4/route.c b/net/ipv4/route.c
99416index 4c011ec..8fae66b 100644
99417--- a/net/ipv4/route.c
99418+++ b/net/ipv4/route.c
99419@@ -233,7 +233,7 @@ static const struct seq_operations rt_cache_seq_ops = {
99420
99421 static int rt_cache_seq_open(struct inode *inode, struct file *file)
99422 {
99423- return seq_open(file, &rt_cache_seq_ops);
99424+ return seq_open_restrict(file, &rt_cache_seq_ops);
99425 }
99426
99427 static const struct file_operations rt_cache_seq_fops = {
99428@@ -324,7 +324,7 @@ static const struct seq_operations rt_cpu_seq_ops = {
99429
99430 static int rt_cpu_seq_open(struct inode *inode, struct file *file)
99431 {
99432- return seq_open(file, &rt_cpu_seq_ops);
99433+ return seq_open_restrict(file, &rt_cpu_seq_ops);
99434 }
99435
99436 static const struct file_operations rt_cpu_seq_fops = {
99437@@ -362,7 +362,7 @@ static int rt_acct_proc_show(struct seq_file *m, void *v)
99438
99439 static int rt_acct_proc_open(struct inode *inode, struct file *file)
99440 {
99441- return single_open(file, rt_acct_proc_show, NULL);
99442+ return single_open_restrict(file, rt_acct_proc_show, NULL);
99443 }
99444
99445 static const struct file_operations rt_acct_proc_fops = {
99446@@ -2623,34 +2623,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
99447 .maxlen = sizeof(int),
99448 .mode = 0200,
99449 .proc_handler = ipv4_sysctl_rtcache_flush,
99450+ .extra1 = &init_net,
99451 },
99452 { },
99453 };
99454
99455 static __net_init int sysctl_route_net_init(struct net *net)
99456 {
99457- struct ctl_table *tbl;
99458+ ctl_table_no_const *tbl = NULL;
99459
99460- tbl = ipv4_route_flush_table;
99461 if (!net_eq(net, &init_net)) {
99462- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
99463+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
99464 if (tbl == NULL)
99465 goto err_dup;
99466
99467 /* Don't export sysctls to unprivileged users */
99468 if (net->user_ns != &init_user_ns)
99469 tbl[0].procname = NULL;
99470- }
99471- tbl[0].extra1 = net;
99472+ tbl[0].extra1 = net;
99473+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
99474+ } else
99475+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
99476
99477- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
99478 if (net->ipv4.route_hdr == NULL)
99479 goto err_reg;
99480 return 0;
99481
99482 err_reg:
99483- if (tbl != ipv4_route_flush_table)
99484- kfree(tbl);
99485+ kfree(tbl);
99486 err_dup:
99487 return -ENOMEM;
99488 }
99489@@ -2673,8 +2673,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
99490
99491 static __net_init int rt_genid_init(struct net *net)
99492 {
99493- atomic_set(&net->ipv4.rt_genid, 0);
99494- atomic_set(&net->fnhe_genid, 0);
99495+ atomic_set_unchecked(&net->ipv4.rt_genid, 0);
99496+ atomic_set_unchecked(&net->fnhe_genid, 0);
99497 get_random_bytes(&net->ipv4.dev_addr_genid,
99498 sizeof(net->ipv4.dev_addr_genid));
99499 return 0;
99500diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
99501index 44eba05..b36864b 100644
99502--- a/net/ipv4/sysctl_net_ipv4.c
99503+++ b/net/ipv4/sysctl_net_ipv4.c
99504@@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
99505 container_of(table->data, struct net, ipv4.sysctl_local_ports.range);
99506 int ret;
99507 int range[2];
99508- struct ctl_table tmp = {
99509+ ctl_table_no_const tmp = {
99510 .data = &range,
99511 .maxlen = sizeof(range),
99512 .mode = table->mode,
99513@@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
99514 int ret;
99515 gid_t urange[2];
99516 kgid_t low, high;
99517- struct ctl_table tmp = {
99518+ ctl_table_no_const tmp = {
99519 .data = &urange,
99520 .maxlen = sizeof(urange),
99521 .mode = table->mode,
99522@@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
99523 void __user *buffer, size_t *lenp, loff_t *ppos)
99524 {
99525 char val[TCP_CA_NAME_MAX];
99526- struct ctl_table tbl = {
99527+ ctl_table_no_const tbl = {
99528 .data = val,
99529 .maxlen = TCP_CA_NAME_MAX,
99530 };
99531@@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
99532 void __user *buffer, size_t *lenp,
99533 loff_t *ppos)
99534 {
99535- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
99536+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
99537 int ret;
99538
99539 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
99540@@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
99541 void __user *buffer, size_t *lenp,
99542 loff_t *ppos)
99543 {
99544- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
99545+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
99546 int ret;
99547
99548 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
99549@@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
99550 void __user *buffer, size_t *lenp,
99551 loff_t *ppos)
99552 {
99553- struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
99554+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
99555 struct tcp_fastopen_context *ctxt;
99556 int ret;
99557 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
99558@@ -438,7 +438,7 @@ static struct ctl_table ipv4_table[] = {
99559 },
99560 {
99561 .procname = "ip_local_reserved_ports",
99562- .data = NULL, /* initialized in sysctl_ipv4_init */
99563+ .data = sysctl_local_reserved_ports,
99564 .maxlen = 65536,
99565 .mode = 0644,
99566 .proc_handler = proc_do_large_bitmap,
99567@@ -843,13 +843,12 @@ static struct ctl_table ipv4_net_table[] = {
99568
99569 static __net_init int ipv4_sysctl_init_net(struct net *net)
99570 {
99571- struct ctl_table *table;
99572+ ctl_table_no_const *table = NULL;
99573
99574- table = ipv4_net_table;
99575 if (!net_eq(net, &init_net)) {
99576 int i;
99577
99578- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
99579+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
99580 if (table == NULL)
99581 goto err_alloc;
99582
99583@@ -872,15 +871,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
99584 net->ipv4.sysctl_local_ports.range[0] = 32768;
99585 net->ipv4.sysctl_local_ports.range[1] = 61000;
99586
99587- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
99588+ if (!net_eq(net, &init_net))
99589+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
99590+ else
99591+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
99592 if (net->ipv4.ipv4_hdr == NULL)
99593 goto err_reg;
99594
99595 return 0;
99596
99597 err_reg:
99598- if (!net_eq(net, &init_net))
99599- kfree(table);
99600+ kfree(table);
99601 err_alloc:
99602 return -ENOMEM;
99603 }
99604@@ -902,16 +903,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
99605 static __init int sysctl_ipv4_init(void)
99606 {
99607 struct ctl_table_header *hdr;
99608- struct ctl_table *i;
99609-
99610- for (i = ipv4_table; i->procname; i++) {
99611- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
99612- i->data = sysctl_local_reserved_ports;
99613- break;
99614- }
99615- }
99616- if (!i->procname)
99617- return -EINVAL;
99618
99619 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
99620 if (hdr == NULL)
99621diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
99622index eeaac39..dc29942 100644
99623--- a/net/ipv4/tcp_input.c
99624+++ b/net/ipv4/tcp_input.c
99625@@ -761,7 +761,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
99626 * without any lock. We want to make sure compiler wont store
99627 * intermediate values in this location.
99628 */
99629- ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
99630+ ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
99631 sk->sk_max_pacing_rate);
99632 }
99633
99634@@ -4485,7 +4485,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
99635 * simplifies code)
99636 */
99637 static void
99638-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
99639+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
99640 struct sk_buff *head, struct sk_buff *tail,
99641 u32 start, u32 end)
99642 {
99643@@ -5562,6 +5562,7 @@ discard:
99644 tcp_paws_reject(&tp->rx_opt, 0))
99645 goto discard_and_undo;
99646
99647+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
99648 if (th->syn) {
99649 /* We see SYN without ACK. It is attempt of
99650 * simultaneous connect with crossed SYNs.
99651@@ -5612,6 +5613,7 @@ discard:
99652 goto discard;
99653 #endif
99654 }
99655+#endif
99656 /* "fifth, if neither of the SYN or RST bits is set then
99657 * drop the segment and return."
99658 */
99659@@ -5658,7 +5660,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
99660 goto discard;
99661
99662 if (th->syn) {
99663- if (th->fin)
99664+ if (th->fin || th->urg || th->psh)
99665 goto discard;
99666 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
99667 return 1;
99668diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
99669index 1e4eac7..a66fa4a 100644
99670--- a/net/ipv4/tcp_ipv4.c
99671+++ b/net/ipv4/tcp_ipv4.c
99672@@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
99673 EXPORT_SYMBOL(sysctl_tcp_low_latency);
99674
99675
99676+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99677+extern int grsec_enable_blackhole;
99678+#endif
99679+
99680 #ifdef CONFIG_TCP_MD5SIG
99681 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
99682 __be32 daddr, __be32 saddr, const struct tcphdr *th);
99683@@ -1829,6 +1833,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
99684 return 0;
99685
99686 reset:
99687+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99688+ if (!grsec_enable_blackhole)
99689+#endif
99690 tcp_v4_send_reset(rsk, skb);
99691 discard:
99692 kfree_skb(skb);
99693@@ -1974,12 +1981,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
99694 TCP_SKB_CB(skb)->sacked = 0;
99695
99696 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
99697- if (!sk)
99698+ if (!sk) {
99699+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99700+ ret = 1;
99701+#endif
99702 goto no_tcp_socket;
99703-
99704+ }
99705 process:
99706- if (sk->sk_state == TCP_TIME_WAIT)
99707+ if (sk->sk_state == TCP_TIME_WAIT) {
99708+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99709+ ret = 2;
99710+#endif
99711 goto do_time_wait;
99712+ }
99713
99714 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
99715 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
99716@@ -2033,6 +2047,10 @@ csum_error:
99717 bad_packet:
99718 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
99719 } else {
99720+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99721+ if (!grsec_enable_blackhole || (ret == 1 &&
99722+ (skb->dev->flags & IFF_LOOPBACK)))
99723+#endif
99724 tcp_v4_send_reset(NULL, skb);
99725 }
99726
99727diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
99728index 7a436c5..1b05c59 100644
99729--- a/net/ipv4/tcp_minisocks.c
99730+++ b/net/ipv4/tcp_minisocks.c
99731@@ -27,6 +27,10 @@
99732 #include <net/inet_common.h>
99733 #include <net/xfrm.h>
99734
99735+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99736+extern int grsec_enable_blackhole;
99737+#endif
99738+
99739 int sysctl_tcp_syncookies __read_mostly = 1;
99740 EXPORT_SYMBOL(sysctl_tcp_syncookies);
99741
99742@@ -709,7 +713,10 @@ embryonic_reset:
99743 * avoid becoming vulnerable to outside attack aiming at
99744 * resetting legit local connections.
99745 */
99746- req->rsk_ops->send_reset(sk, skb);
99747+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99748+ if (!grsec_enable_blackhole)
99749+#endif
99750+ req->rsk_ops->send_reset(sk, skb);
99751 } else if (fastopen) { /* received a valid RST pkt */
99752 reqsk_fastopen_remove(sk, req, true);
99753 tcp_reset(sk);
99754diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
99755index 1f2d376..01d18c4 100644
99756--- a/net/ipv4/tcp_probe.c
99757+++ b/net/ipv4/tcp_probe.c
99758@@ -238,7 +238,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
99759 if (cnt + width >= len)
99760 break;
99761
99762- if (copy_to_user(buf + cnt, tbuf, width))
99763+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
99764 return -EFAULT;
99765 cnt += width;
99766 }
99767diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
99768index 64f0354..a81b39d 100644
99769--- a/net/ipv4/tcp_timer.c
99770+++ b/net/ipv4/tcp_timer.c
99771@@ -22,6 +22,10 @@
99772 #include <linux/gfp.h>
99773 #include <net/tcp.h>
99774
99775+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99776+extern int grsec_lastack_retries;
99777+#endif
99778+
99779 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
99780 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
99781 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
99782@@ -189,6 +193,13 @@ static int tcp_write_timeout(struct sock *sk)
99783 }
99784 }
99785
99786+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99787+ if ((sk->sk_state == TCP_LAST_ACK) &&
99788+ (grsec_lastack_retries > 0) &&
99789+ (grsec_lastack_retries < retry_until))
99790+ retry_until = grsec_lastack_retries;
99791+#endif
99792+
99793 if (retransmits_timed_out(sk, retry_until,
99794 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
99795 /* Has it gone just too far? */
99796diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
99797index 77bd16f..5f7174a 100644
99798--- a/net/ipv4/udp.c
99799+++ b/net/ipv4/udp.c
99800@@ -87,6 +87,7 @@
99801 #include <linux/types.h>
99802 #include <linux/fcntl.h>
99803 #include <linux/module.h>
99804+#include <linux/security.h>
99805 #include <linux/socket.h>
99806 #include <linux/sockios.h>
99807 #include <linux/igmp.h>
99808@@ -113,6 +114,10 @@
99809 #include <net/busy_poll.h>
99810 #include "udp_impl.h"
99811
99812+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99813+extern int grsec_enable_blackhole;
99814+#endif
99815+
99816 struct udp_table udp_table __read_mostly;
99817 EXPORT_SYMBOL(udp_table);
99818
99819@@ -615,6 +620,9 @@ found:
99820 return s;
99821 }
99822
99823+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
99824+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
99825+
99826 /*
99827 * This routine is called by the ICMP module when it gets some
99828 * sort of error condition. If err < 0 then the socket should
99829@@ -914,9 +922,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99830 dport = usin->sin_port;
99831 if (dport == 0)
99832 return -EINVAL;
99833+
99834+ err = gr_search_udp_sendmsg(sk, usin);
99835+ if (err)
99836+ return err;
99837 } else {
99838 if (sk->sk_state != TCP_ESTABLISHED)
99839 return -EDESTADDRREQ;
99840+
99841+ err = gr_search_udp_sendmsg(sk, NULL);
99842+ if (err)
99843+ return err;
99844+
99845 daddr = inet->inet_daddr;
99846 dport = inet->inet_dport;
99847 /* Open fast path for connected socket.
99848@@ -1163,7 +1180,7 @@ static unsigned int first_packet_length(struct sock *sk)
99849 IS_UDPLITE(sk));
99850 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
99851 IS_UDPLITE(sk));
99852- atomic_inc(&sk->sk_drops);
99853+ atomic_inc_unchecked(&sk->sk_drops);
99854 __skb_unlink(skb, rcvq);
99855 __skb_queue_tail(&list_kill, skb);
99856 }
99857@@ -1234,6 +1251,12 @@ int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99858 int is_udplite = IS_UDPLITE(sk);
99859 bool slow;
99860
99861+ /*
99862+ * Check any passed addresses
99863+ */
99864+ if (addr_len)
99865+ *addr_len = sizeof(*sin);
99866+
99867 if (flags & MSG_ERRQUEUE)
99868 return ip_recv_error(sk, msg, len, addr_len);
99869
99870@@ -1243,6 +1266,10 @@ try_again:
99871 if (!skb)
99872 goto out;
99873
99874+ err = gr_search_udp_recvmsg(sk, skb);
99875+ if (err)
99876+ goto out_free;
99877+
99878 ulen = skb->len - sizeof(struct udphdr);
99879 copied = len;
99880 if (copied > ulen)
99881@@ -1276,7 +1303,7 @@ try_again:
99882 if (unlikely(err)) {
99883 trace_kfree_skb(skb, udp_recvmsg);
99884 if (!peeked) {
99885- atomic_inc(&sk->sk_drops);
99886+ atomic_inc_unchecked(&sk->sk_drops);
99887 UDP_INC_STATS_USER(sock_net(sk),
99888 UDP_MIB_INERRORS, is_udplite);
99889 }
99890@@ -1295,7 +1322,6 @@ try_again:
99891 sin->sin_port = udp_hdr(skb)->source;
99892 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
99893 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
99894- *addr_len = sizeof(*sin);
99895 }
99896 if (inet->cmsg_flags)
99897 ip_cmsg_recv(msg, skb);
99898@@ -1566,7 +1592,7 @@ csum_error:
99899 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
99900 drop:
99901 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
99902- atomic_inc(&sk->sk_drops);
99903+ atomic_inc_unchecked(&sk->sk_drops);
99904 kfree_skb(skb);
99905 return -1;
99906 }
99907@@ -1585,7 +1611,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
99908 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
99909
99910 if (!skb1) {
99911- atomic_inc(&sk->sk_drops);
99912+ atomic_inc_unchecked(&sk->sk_drops);
99913 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
99914 IS_UDPLITE(sk));
99915 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
99916@@ -1786,6 +1812,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
99917 goto csum_error;
99918
99919 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
99920+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99921+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
99922+#endif
99923 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
99924
99925 /*
99926@@ -2350,7 +2379,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
99927 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
99928 0, sock_i_ino(sp),
99929 atomic_read(&sp->sk_refcnt), sp,
99930- atomic_read(&sp->sk_drops));
99931+ atomic_read_unchecked(&sp->sk_drops));
99932 }
99933
99934 int udp4_seq_show(struct seq_file *seq, void *v)
99935diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
99936index e1a6393..f634ce5 100644
99937--- a/net/ipv4/xfrm4_policy.c
99938+++ b/net/ipv4/xfrm4_policy.c
99939@@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
99940 fl4->flowi4_tos = iph->tos;
99941 }
99942
99943-static inline int xfrm4_garbage_collect(struct dst_ops *ops)
99944+static int xfrm4_garbage_collect(struct dst_ops *ops)
99945 {
99946 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
99947
99948- xfrm4_policy_afinfo.garbage_collect(net);
99949+ xfrm_garbage_collect_deferred(net);
99950 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
99951 }
99952
99953@@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
99954
99955 static int __net_init xfrm4_net_init(struct net *net)
99956 {
99957- struct ctl_table *table;
99958+ ctl_table_no_const *table = NULL;
99959 struct ctl_table_header *hdr;
99960
99961- table = xfrm4_policy_table;
99962 if (!net_eq(net, &init_net)) {
99963- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
99964+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
99965 if (!table)
99966 goto err_alloc;
99967
99968 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
99969- }
99970-
99971- hdr = register_net_sysctl(net, "net/ipv4", table);
99972+ hdr = register_net_sysctl(net, "net/ipv4", table);
99973+ } else
99974+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
99975 if (!hdr)
99976 goto err_reg;
99977
99978@@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
99979 return 0;
99980
99981 err_reg:
99982- if (!net_eq(net, &init_net))
99983- kfree(table);
99984+ kfree(table);
99985 err_alloc:
99986 return -ENOMEM;
99987 }
99988diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
99989index 6c7fa08..285086c 100644
99990--- a/net/ipv6/addrconf.c
99991+++ b/net/ipv6/addrconf.c
99992@@ -598,7 +598,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
99993 idx = 0;
99994 head = &net->dev_index_head[h];
99995 rcu_read_lock();
99996- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
99997+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
99998 net->dev_base_seq;
99999 hlist_for_each_entry_rcu(dev, head, index_hlist) {
100000 if (idx < s_idx)
100001@@ -2395,7 +2395,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
100002 p.iph.ihl = 5;
100003 p.iph.protocol = IPPROTO_IPV6;
100004 p.iph.ttl = 64;
100005- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
100006+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
100007
100008 if (ops->ndo_do_ioctl) {
100009 mm_segment_t oldfs = get_fs();
100010@@ -4146,7 +4146,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
100011 s_ip_idx = ip_idx = cb->args[2];
100012
100013 rcu_read_lock();
100014- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
100015+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
100016 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
100017 idx = 0;
100018 head = &net->dev_index_head[h];
100019@@ -4758,7 +4758,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
100020 dst_free(&ifp->rt->dst);
100021 break;
100022 }
100023- atomic_inc(&net->ipv6.dev_addr_genid);
100024+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
100025 rt_genid_bump_ipv6(net);
100026 }
100027
100028@@ -4779,7 +4779,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
100029 int *valp = ctl->data;
100030 int val = *valp;
100031 loff_t pos = *ppos;
100032- struct ctl_table lctl;
100033+ ctl_table_no_const lctl;
100034 int ret;
100035
100036 /*
100037@@ -4864,7 +4864,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
100038 int *valp = ctl->data;
100039 int val = *valp;
100040 loff_t pos = *ppos;
100041- struct ctl_table lctl;
100042+ ctl_table_no_const lctl;
100043 int ret;
100044
100045 /*
100046diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
100047index d935889..2f64330 100644
100048--- a/net/ipv6/af_inet6.c
100049+++ b/net/ipv6/af_inet6.c
100050@@ -776,7 +776,7 @@ static int __net_init inet6_net_init(struct net *net)
100051 net->ipv6.sysctl.bindv6only = 0;
100052 net->ipv6.sysctl.icmpv6_time = 1*HZ;
100053 net->ipv6.sysctl.flowlabel_consistency = 1;
100054- atomic_set(&net->ipv6.rt_genid, 0);
100055+ atomic_set_unchecked(&net->ipv6.rt_genid, 0);
100056
100057 err = ipv6_init_mibs(net);
100058 if (err)
100059diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
100060index c3bf2d2..1f00573 100644
100061--- a/net/ipv6/datagram.c
100062+++ b/net/ipv6/datagram.c
100063@@ -938,5 +938,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
100064 0,
100065 sock_i_ino(sp),
100066 atomic_read(&sp->sk_refcnt), sp,
100067- atomic_read(&sp->sk_drops));
100068+ atomic_read_unchecked(&sp->sk_drops));
100069 }
100070diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
100071index 7b32652..0bc348b 100644
100072--- a/net/ipv6/icmp.c
100073+++ b/net/ipv6/icmp.c
100074@@ -1005,7 +1005,7 @@ static struct ctl_table ipv6_icmp_table_template[] = {
100075
100076 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
100077 {
100078- struct ctl_table *table;
100079+ ctl_table_no_const *table;
100080
100081 table = kmemdup(ipv6_icmp_table_template,
100082 sizeof(ipv6_icmp_table_template),
100083diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
100084index f3ffb43..1172ba7 100644
100085--- a/net/ipv6/ip6_gre.c
100086+++ b/net/ipv6/ip6_gre.c
100087@@ -71,7 +71,7 @@ struct ip6gre_net {
100088 struct net_device *fb_tunnel_dev;
100089 };
100090
100091-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
100092+static struct rtnl_link_ops ip6gre_link_ops;
100093 static int ip6gre_tunnel_init(struct net_device *dev);
100094 static void ip6gre_tunnel_setup(struct net_device *dev);
100095 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
100096@@ -1291,7 +1291,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
100097 }
100098
100099
100100-static struct inet6_protocol ip6gre_protocol __read_mostly = {
100101+static struct inet6_protocol ip6gre_protocol = {
100102 .handler = ip6gre_rcv,
100103 .err_handler = ip6gre_err,
100104 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
100105@@ -1634,7 +1634,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
100106 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
100107 };
100108
100109-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
100110+static struct rtnl_link_ops ip6gre_link_ops = {
100111 .kind = "ip6gre",
100112 .maxtype = IFLA_GRE_MAX,
100113 .policy = ip6gre_policy,
100114@@ -1647,7 +1647,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
100115 .fill_info = ip6gre_fill_info,
100116 };
100117
100118-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
100119+static struct rtnl_link_ops ip6gre_tap_ops = {
100120 .kind = "ip6gretap",
100121 .maxtype = IFLA_GRE_MAX,
100122 .policy = ip6gre_policy,
100123diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
100124index 5db8d31..4a72c26 100644
100125--- a/net/ipv6/ip6_tunnel.c
100126+++ b/net/ipv6/ip6_tunnel.c
100127@@ -85,7 +85,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
100128
100129 static int ip6_tnl_dev_init(struct net_device *dev);
100130 static void ip6_tnl_dev_setup(struct net_device *dev);
100131-static struct rtnl_link_ops ip6_link_ops __read_mostly;
100132+static struct rtnl_link_ops ip6_link_ops;
100133
100134 static int ip6_tnl_net_id __read_mostly;
100135 struct ip6_tnl_net {
100136@@ -1714,7 +1714,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
100137 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
100138 };
100139
100140-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
100141+static struct rtnl_link_ops ip6_link_ops = {
100142 .kind = "ip6tnl",
100143 .maxtype = IFLA_IPTUN_MAX,
100144 .policy = ip6_tnl_policy,
100145diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
100146index 2d19272..3a46322 100644
100147--- a/net/ipv6/ip6_vti.c
100148+++ b/net/ipv6/ip6_vti.c
100149@@ -62,7 +62,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
100150
100151 static int vti6_dev_init(struct net_device *dev);
100152 static void vti6_dev_setup(struct net_device *dev);
100153-static struct rtnl_link_ops vti6_link_ops __read_mostly;
100154+static struct rtnl_link_ops vti6_link_ops;
100155
100156 static int vti6_net_id __read_mostly;
100157 struct vti6_net {
100158@@ -901,7 +901,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
100159 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
100160 };
100161
100162-static struct rtnl_link_ops vti6_link_ops __read_mostly = {
100163+static struct rtnl_link_ops vti6_link_ops = {
100164 .kind = "vti6",
100165 .maxtype = IFLA_VTI_MAX,
100166 .policy = vti6_policy,
100167diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
100168index 0a00f44..bec42b2 100644
100169--- a/net/ipv6/ipv6_sockglue.c
100170+++ b/net/ipv6/ipv6_sockglue.c
100171@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
100172 if (sk->sk_type != SOCK_STREAM)
100173 return -ENOPROTOOPT;
100174
100175- msg.msg_control = optval;
100176+ msg.msg_control = (void __force_kernel *)optval;
100177 msg.msg_controllen = len;
100178 msg.msg_flags = flags;
100179
100180diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
100181index 710238f..0fd1816 100644
100182--- a/net/ipv6/netfilter/ip6_tables.c
100183+++ b/net/ipv6/netfilter/ip6_tables.c
100184@@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
100185 #endif
100186
100187 static int get_info(struct net *net, void __user *user,
100188- const int *len, int compat)
100189+ int len, int compat)
100190 {
100191 char name[XT_TABLE_MAXNAMELEN];
100192 struct xt_table *t;
100193 int ret;
100194
100195- if (*len != sizeof(struct ip6t_getinfo)) {
100196- duprintf("length %u != %zu\n", *len,
100197+ if (len != sizeof(struct ip6t_getinfo)) {
100198+ duprintf("length %u != %zu\n", len,
100199 sizeof(struct ip6t_getinfo));
100200 return -EINVAL;
100201 }
100202@@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
100203 info.size = private->size;
100204 strcpy(info.name, name);
100205
100206- if (copy_to_user(user, &info, *len) != 0)
100207+ if (copy_to_user(user, &info, len) != 0)
100208 ret = -EFAULT;
100209 else
100210 ret = 0;
100211@@ -1981,7 +1981,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
100212
100213 switch (cmd) {
100214 case IP6T_SO_GET_INFO:
100215- ret = get_info(sock_net(sk), user, len, 1);
100216+ ret = get_info(sock_net(sk), user, *len, 1);
100217 break;
100218 case IP6T_SO_GET_ENTRIES:
100219 ret = compat_get_entries(sock_net(sk), user, len);
100220@@ -2028,7 +2028,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
100221
100222 switch (cmd) {
100223 case IP6T_SO_GET_INFO:
100224- ret = get_info(sock_net(sk), user, len, 0);
100225+ ret = get_info(sock_net(sk), user, *len, 0);
100226 break;
100227
100228 case IP6T_SO_GET_ENTRIES:
100229diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
100230index 767ab8d..c5ec70a 100644
100231--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
100232+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
100233@@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
100234
100235 static int nf_ct_frag6_sysctl_register(struct net *net)
100236 {
100237- struct ctl_table *table;
100238+ ctl_table_no_const *table = NULL;
100239 struct ctl_table_header *hdr;
100240
100241- table = nf_ct_frag6_sysctl_table;
100242 if (!net_eq(net, &init_net)) {
100243- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
100244+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
100245 GFP_KERNEL);
100246 if (table == NULL)
100247 goto err_alloc;
100248@@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
100249 table[0].data = &net->nf_frag.frags.timeout;
100250 table[1].data = &net->nf_frag.frags.low_thresh;
100251 table[2].data = &net->nf_frag.frags.high_thresh;
100252- }
100253-
100254- hdr = register_net_sysctl(net, "net/netfilter", table);
100255+ hdr = register_net_sysctl(net, "net/netfilter", table);
100256+ } else
100257+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
100258 if (hdr == NULL)
100259 goto err_reg;
100260
100261@@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
100262 return 0;
100263
100264 err_reg:
100265- if (!net_eq(net, &init_net))
100266- kfree(table);
100267+ kfree(table);
100268 err_alloc:
100269 return -ENOMEM;
100270 }
100271diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
100272index 827f795..7e28e82 100644
100273--- a/net/ipv6/output_core.c
100274+++ b/net/ipv6/output_core.c
100275@@ -9,8 +9,8 @@
100276
100277 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
100278 {
100279- static atomic_t ipv6_fragmentation_id;
100280- int old, new;
100281+ static atomic_unchecked_t ipv6_fragmentation_id;
100282+ int id;
100283
100284 #if IS_ENABLED(CONFIG_IPV6)
100285 if (rt && !(rt->dst.flags & DST_NOPEER)) {
100286@@ -26,13 +26,10 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
100287 }
100288 }
100289 #endif
100290- do {
100291- old = atomic_read(&ipv6_fragmentation_id);
100292- new = old + 1;
100293- if (!new)
100294- new = 1;
100295- } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
100296- fhdr->identification = htonl(new);
100297+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
100298+ if (!id)
100299+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
100300+ fhdr->identification = htonl(id);
100301 }
100302 EXPORT_SYMBOL(ipv6_select_ident);
100303
100304diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
100305index bda7429..469b26b 100644
100306--- a/net/ipv6/ping.c
100307+++ b/net/ipv6/ping.c
100308@@ -246,6 +246,24 @@ static struct pernet_operations ping_v6_net_ops = {
100309 };
100310 #endif
100311
100312+static struct pingv6_ops real_pingv6_ops = {
100313+ .ipv6_recv_error = ipv6_recv_error,
100314+ .ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl,
100315+ .ip6_datagram_recv_specific_ctl = ip6_datagram_recv_specific_ctl,
100316+ .icmpv6_err_convert = icmpv6_err_convert,
100317+ .ipv6_icmp_error = ipv6_icmp_error,
100318+ .ipv6_chk_addr = ipv6_chk_addr,
100319+};
100320+
100321+static struct pingv6_ops dummy_pingv6_ops = {
100322+ .ipv6_recv_error = dummy_ipv6_recv_error,
100323+ .ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl,
100324+ .ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl,
100325+ .icmpv6_err_convert = dummy_icmpv6_err_convert,
100326+ .ipv6_icmp_error = dummy_ipv6_icmp_error,
100327+ .ipv6_chk_addr = dummy_ipv6_chk_addr,
100328+};
100329+
100330 int __init pingv6_init(void)
100331 {
100332 #ifdef CONFIG_PROC_FS
100333@@ -253,13 +271,7 @@ int __init pingv6_init(void)
100334 if (ret)
100335 return ret;
100336 #endif
100337- pingv6_ops.ipv6_recv_error = ipv6_recv_error;
100338- pingv6_ops.ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl;
100339- pingv6_ops.ip6_datagram_recv_specific_ctl =
100340- ip6_datagram_recv_specific_ctl;
100341- pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
100342- pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
100343- pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
100344+ pingv6_ops = &real_pingv6_ops;
100345 return inet6_register_protosw(&pingv6_protosw);
100346 }
100347
100348@@ -268,14 +280,9 @@ int __init pingv6_init(void)
100349 */
100350 void pingv6_exit(void)
100351 {
100352- pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
100353- pingv6_ops.ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl;
100354- pingv6_ops.ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl;
100355- pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
100356- pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
100357- pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
100358 #ifdef CONFIG_PROC_FS
100359 unregister_pernet_subsys(&ping_v6_net_ops);
100360 #endif
100361+ pingv6_ops = &dummy_pingv6_ops;
100362 inet6_unregister_protosw(&pingv6_protosw);
100363 }
100364diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
100365index 091d066..139d410 100644
100366--- a/net/ipv6/proc.c
100367+++ b/net/ipv6/proc.c
100368@@ -309,7 +309,7 @@ static int __net_init ipv6_proc_init_net(struct net *net)
100369 if (!proc_create("snmp6", S_IRUGO, net->proc_net, &snmp6_seq_fops))
100370 goto proc_snmp6_fail;
100371
100372- net->mib.proc_net_devsnmp6 = proc_mkdir("dev_snmp6", net->proc_net);
100373+ net->mib.proc_net_devsnmp6 = proc_mkdir_restrict("dev_snmp6", net->proc_net);
100374 if (!net->mib.proc_net_devsnmp6)
100375 goto proc_dev_snmp6_fail;
100376 return 0;
100377diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
100378index 1f29996..46fe0c7 100644
100379--- a/net/ipv6/raw.c
100380+++ b/net/ipv6/raw.c
100381@@ -388,7 +388,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
100382 {
100383 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
100384 skb_checksum_complete(skb)) {
100385- atomic_inc(&sk->sk_drops);
100386+ atomic_inc_unchecked(&sk->sk_drops);
100387 kfree_skb(skb);
100388 return NET_RX_DROP;
100389 }
100390@@ -416,7 +416,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
100391 struct raw6_sock *rp = raw6_sk(sk);
100392
100393 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
100394- atomic_inc(&sk->sk_drops);
100395+ atomic_inc_unchecked(&sk->sk_drops);
100396 kfree_skb(skb);
100397 return NET_RX_DROP;
100398 }
100399@@ -440,7 +440,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
100400
100401 if (inet->hdrincl) {
100402 if (skb_checksum_complete(skb)) {
100403- atomic_inc(&sk->sk_drops);
100404+ atomic_inc_unchecked(&sk->sk_drops);
100405 kfree_skb(skb);
100406 return NET_RX_DROP;
100407 }
100408@@ -469,6 +469,9 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
100409 if (flags & MSG_OOB)
100410 return -EOPNOTSUPP;
100411
100412+ if (addr_len)
100413+ *addr_len=sizeof(*sin6);
100414+
100415 if (flags & MSG_ERRQUEUE)
100416 return ipv6_recv_error(sk, msg, len, addr_len);
100417
100418@@ -507,7 +510,6 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
100419 sin6->sin6_flowinfo = 0;
100420 sin6->sin6_scope_id = ipv6_iface_scope_id(&sin6->sin6_addr,
100421 IP6CB(skb)->iif);
100422- *addr_len = sizeof(*sin6);
100423 }
100424
100425 sock_recv_ts_and_drops(msg, sk, skb);
100426@@ -610,7 +612,7 @@ out:
100427 return err;
100428 }
100429
100430-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
100431+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
100432 struct flowi6 *fl6, struct dst_entry **dstp,
100433 unsigned int flags)
100434 {
100435@@ -922,12 +924,15 @@ do_confirm:
100436 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
100437 char __user *optval, int optlen)
100438 {
100439+ struct icmp6_filter filter;
100440+
100441 switch (optname) {
100442 case ICMPV6_FILTER:
100443 if (optlen > sizeof(struct icmp6_filter))
100444 optlen = sizeof(struct icmp6_filter);
100445- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
100446+ if (copy_from_user(&filter, optval, optlen))
100447 return -EFAULT;
100448+ raw6_sk(sk)->filter = filter;
100449 return 0;
100450 default:
100451 return -ENOPROTOOPT;
100452@@ -940,6 +945,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
100453 char __user *optval, int __user *optlen)
100454 {
100455 int len;
100456+ struct icmp6_filter filter;
100457
100458 switch (optname) {
100459 case ICMPV6_FILTER:
100460@@ -951,7 +957,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
100461 len = sizeof(struct icmp6_filter);
100462 if (put_user(len, optlen))
100463 return -EFAULT;
100464- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
100465+ filter = raw6_sk(sk)->filter;
100466+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
100467 return -EFAULT;
100468 return 0;
100469 default:
100470diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
100471index cc85a9b..526a133 100644
100472--- a/net/ipv6/reassembly.c
100473+++ b/net/ipv6/reassembly.c
100474@@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
100475
100476 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
100477 {
100478- struct ctl_table *table;
100479+ ctl_table_no_const *table = NULL;
100480 struct ctl_table_header *hdr;
100481
100482- table = ip6_frags_ns_ctl_table;
100483 if (!net_eq(net, &init_net)) {
100484- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
100485+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
100486 if (table == NULL)
100487 goto err_alloc;
100488
100489@@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
100490 /* Don't export sysctls to unprivileged users */
100491 if (net->user_ns != &init_user_ns)
100492 table[0].procname = NULL;
100493- }
100494+ hdr = register_net_sysctl(net, "net/ipv6", table);
100495+ } else
100496+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
100497
100498- hdr = register_net_sysctl(net, "net/ipv6", table);
100499 if (hdr == NULL)
100500 goto err_reg;
100501
100502@@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
100503 return 0;
100504
100505 err_reg:
100506- if (!net_eq(net, &init_net))
100507- kfree(table);
100508+ kfree(table);
100509 err_alloc:
100510 return -ENOMEM;
100511 }
100512diff --git a/net/ipv6/route.c b/net/ipv6/route.c
100513index fba54a4..73e374e 100644
100514--- a/net/ipv6/route.c
100515+++ b/net/ipv6/route.c
100516@@ -2972,7 +2972,7 @@ struct ctl_table ipv6_route_table_template[] = {
100517
100518 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
100519 {
100520- struct ctl_table *table;
100521+ ctl_table_no_const *table;
100522
100523 table = kmemdup(ipv6_route_table_template,
100524 sizeof(ipv6_route_table_template),
100525diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
100526index b4d74c8..b4f3fbe 100644
100527--- a/net/ipv6/sit.c
100528+++ b/net/ipv6/sit.c
100529@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
100530 static void ipip6_dev_free(struct net_device *dev);
100531 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
100532 __be32 *v4dst);
100533-static struct rtnl_link_ops sit_link_ops __read_mostly;
100534+static struct rtnl_link_ops sit_link_ops;
100535
100536 static int sit_net_id __read_mostly;
100537 struct sit_net {
100538@@ -1683,7 +1683,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
100539 unregister_netdevice_queue(dev, head);
100540 }
100541
100542-static struct rtnl_link_ops sit_link_ops __read_mostly = {
100543+static struct rtnl_link_ops sit_link_ops = {
100544 .kind = "sit",
100545 .maxtype = IFLA_IPTUN_MAX,
100546 .policy = ipip6_policy,
100547diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
100548index 7f405a1..eabef92 100644
100549--- a/net/ipv6/sysctl_net_ipv6.c
100550+++ b/net/ipv6/sysctl_net_ipv6.c
100551@@ -54,7 +54,7 @@ static struct ctl_table ipv6_rotable[] = {
100552
100553 static int __net_init ipv6_sysctl_net_init(struct net *net)
100554 {
100555- struct ctl_table *ipv6_table;
100556+ ctl_table_no_const *ipv6_table;
100557 struct ctl_table *ipv6_route_table;
100558 struct ctl_table *ipv6_icmp_table;
100559 int err;
100560diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
100561index 889079b..a04512c 100644
100562--- a/net/ipv6/tcp_ipv6.c
100563+++ b/net/ipv6/tcp_ipv6.c
100564@@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
100565 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
100566 }
100567
100568+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100569+extern int grsec_enable_blackhole;
100570+#endif
100571+
100572 static void tcp_v6_hash(struct sock *sk)
100573 {
100574 if (sk->sk_state != TCP_CLOSE) {
100575@@ -1412,6 +1416,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
100576 return 0;
100577
100578 reset:
100579+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100580+ if (!grsec_enable_blackhole)
100581+#endif
100582 tcp_v6_send_reset(sk, skb);
100583 discard:
100584 if (opt_skb)
100585@@ -1496,12 +1503,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
100586 TCP_SKB_CB(skb)->sacked = 0;
100587
100588 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
100589- if (!sk)
100590+ if (!sk) {
100591+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100592+ ret = 1;
100593+#endif
100594 goto no_tcp_socket;
100595+ }
100596
100597 process:
100598- if (sk->sk_state == TCP_TIME_WAIT)
100599+ if (sk->sk_state == TCP_TIME_WAIT) {
100600+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100601+ ret = 2;
100602+#endif
100603 goto do_time_wait;
100604+ }
100605
100606 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
100607 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
100608@@ -1553,6 +1568,10 @@ csum_error:
100609 bad_packet:
100610 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
100611 } else {
100612+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100613+ if (!grsec_enable_blackhole || (ret == 1 &&
100614+ (skb->dev->flags & IFF_LOOPBACK)))
100615+#endif
100616 tcp_v6_send_reset(NULL, skb);
100617 }
100618
100619diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
100620index 1e586d9..384a9c9 100644
100621--- a/net/ipv6/udp.c
100622+++ b/net/ipv6/udp.c
100623@@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
100624 udp_ipv6_hash_secret + net_hash_mix(net));
100625 }
100626
100627+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100628+extern int grsec_enable_blackhole;
100629+#endif
100630+
100631 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
100632 {
100633 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
100634@@ -392,6 +396,9 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
100635 int is_udp4;
100636 bool slow;
100637
100638+ if (addr_len)
100639+ *addr_len = sizeof(struct sockaddr_in6);
100640+
100641 if (flags & MSG_ERRQUEUE)
100642 return ipv6_recv_error(sk, msg, len, addr_len);
100643
100644@@ -435,7 +442,7 @@ try_again:
100645 if (unlikely(err)) {
100646 trace_kfree_skb(skb, udpv6_recvmsg);
100647 if (!peeked) {
100648- atomic_inc(&sk->sk_drops);
100649+ atomic_inc_unchecked(&sk->sk_drops);
100650 if (is_udp4)
100651 UDP_INC_STATS_USER(sock_net(sk),
100652 UDP_MIB_INERRORS,
100653@@ -475,7 +482,7 @@ try_again:
100654 ipv6_iface_scope_id(&sin6->sin6_addr,
100655 IP6CB(skb)->iif);
100656 }
100657- *addr_len = sizeof(*sin6);
100658+
100659 }
100660
100661 if (np->rxopt.all)
100662@@ -690,7 +697,7 @@ csum_error:
100663 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
100664 drop:
100665 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
100666- atomic_inc(&sk->sk_drops);
100667+ atomic_inc_unchecked(&sk->sk_drops);
100668 kfree_skb(skb);
100669 return -1;
100670 }
100671@@ -747,7 +754,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
100672 if (likely(skb1 == NULL))
100673 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
100674 if (!skb1) {
100675- atomic_inc(&sk->sk_drops);
100676+ atomic_inc_unchecked(&sk->sk_drops);
100677 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
100678 IS_UDPLITE(sk));
100679 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
100680@@ -886,6 +893,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
100681 goto csum_error;
100682
100683 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
100684+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100685+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
100686+#endif
100687 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
100688
100689 kfree_skb(skb);
100690diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
100691index 5f8e128..865d38e 100644
100692--- a/net/ipv6/xfrm6_policy.c
100693+++ b/net/ipv6/xfrm6_policy.c
100694@@ -212,11 +212,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
100695 }
100696 }
100697
100698-static inline int xfrm6_garbage_collect(struct dst_ops *ops)
100699+static int xfrm6_garbage_collect(struct dst_ops *ops)
100700 {
100701 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
100702
100703- xfrm6_policy_afinfo.garbage_collect(net);
100704+ xfrm_garbage_collect_deferred(net);
100705 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
100706 }
100707
100708@@ -329,19 +329,19 @@ static struct ctl_table xfrm6_policy_table[] = {
100709
100710 static int __net_init xfrm6_net_init(struct net *net)
100711 {
100712- struct ctl_table *table;
100713+ ctl_table_no_const *table = NULL;
100714 struct ctl_table_header *hdr;
100715
100716- table = xfrm6_policy_table;
100717 if (!net_eq(net, &init_net)) {
100718- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
100719+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
100720 if (!table)
100721 goto err_alloc;
100722
100723 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
100724- }
100725+ hdr = register_net_sysctl(net, "net/ipv6", table);
100726+ } else
100727+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
100728
100729- hdr = register_net_sysctl(net, "net/ipv6", table);
100730 if (!hdr)
100731 goto err_reg;
100732
100733@@ -349,8 +349,7 @@ static int __net_init xfrm6_net_init(struct net *net)
100734 return 0;
100735
100736 err_reg:
100737- if (!net_eq(net, &init_net))
100738- kfree(table);
100739+ kfree(table);
100740 err_alloc:
100741 return -ENOMEM;
100742 }
100743diff --git a/net/ipx/ipx_proc.c b/net/ipx/ipx_proc.c
100744index e15c16a..7cf07aa 100644
100745--- a/net/ipx/ipx_proc.c
100746+++ b/net/ipx/ipx_proc.c
100747@@ -289,7 +289,7 @@ int __init ipx_proc_init(void)
100748 struct proc_dir_entry *p;
100749 int rc = -ENOMEM;
100750
100751- ipx_proc_dir = proc_mkdir("ipx", init_net.proc_net);
100752+ ipx_proc_dir = proc_mkdir_restrict("ipx", init_net.proc_net);
100753
100754 if (!ipx_proc_dir)
100755 goto out;
100756diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
100757index 2ba8b97..6d33010 100644
100758--- a/net/irda/ircomm/ircomm_tty.c
100759+++ b/net/irda/ircomm/ircomm_tty.c
100760@@ -317,11 +317,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
100761 add_wait_queue(&port->open_wait, &wait);
100762
100763 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
100764- __FILE__, __LINE__, tty->driver->name, port->count);
100765+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
100766
100767 spin_lock_irqsave(&port->lock, flags);
100768 if (!tty_hung_up_p(filp))
100769- port->count--;
100770+ atomic_dec(&port->count);
100771 port->blocked_open++;
100772 spin_unlock_irqrestore(&port->lock, flags);
100773
100774@@ -356,7 +356,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
100775 }
100776
100777 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
100778- __FILE__, __LINE__, tty->driver->name, port->count);
100779+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
100780
100781 schedule();
100782 }
100783@@ -366,12 +366,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
100784
100785 spin_lock_irqsave(&port->lock, flags);
100786 if (!tty_hung_up_p(filp))
100787- port->count++;
100788+ atomic_inc(&port->count);
100789 port->blocked_open--;
100790 spin_unlock_irqrestore(&port->lock, flags);
100791
100792 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
100793- __FILE__, __LINE__, tty->driver->name, port->count);
100794+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
100795
100796 if (!retval)
100797 port->flags |= ASYNC_NORMAL_ACTIVE;
100798@@ -445,12 +445,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
100799
100800 /* ++ is not atomic, so this should be protected - Jean II */
100801 spin_lock_irqsave(&self->port.lock, flags);
100802- self->port.count++;
100803+ atomic_inc(&self->port.count);
100804 spin_unlock_irqrestore(&self->port.lock, flags);
100805 tty_port_tty_set(&self->port, tty);
100806
100807 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
100808- self->line, self->port.count);
100809+ self->line, atomic_read(&self->port.count));
100810
100811 /* Not really used by us, but lets do it anyway */
100812 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
100813@@ -987,7 +987,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
100814 tty_kref_put(port->tty);
100815 }
100816 port->tty = NULL;
100817- port->count = 0;
100818+ atomic_set(&port->count, 0);
100819 spin_unlock_irqrestore(&port->lock, flags);
100820
100821 wake_up_interruptible(&port->open_wait);
100822@@ -1344,7 +1344,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
100823 seq_putc(m, '\n');
100824
100825 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
100826- seq_printf(m, "Open count: %d\n", self->port.count);
100827+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
100828 seq_printf(m, "Max data size: %d\n", self->max_data_size);
100829 seq_printf(m, "Max header size: %d\n", self->max_header_size);
100830
100831diff --git a/net/irda/irproc.c b/net/irda/irproc.c
100832index b9ac598..f88cc56 100644
100833--- a/net/irda/irproc.c
100834+++ b/net/irda/irproc.c
100835@@ -66,7 +66,7 @@ void __init irda_proc_register(void)
100836 {
100837 int i;
100838
100839- proc_irda = proc_mkdir("irda", init_net.proc_net);
100840+ proc_irda = proc_mkdir_restrict("irda", init_net.proc_net);
100841 if (proc_irda == NULL)
100842 return;
100843
100844diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
100845index c4b7218..3e83259 100644
100846--- a/net/iucv/af_iucv.c
100847+++ b/net/iucv/af_iucv.c
100848@@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
100849
100850 write_lock_bh(&iucv_sk_list.lock);
100851
100852- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
100853+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
100854 while (__iucv_get_sock_by_name(name)) {
100855 sprintf(name, "%08x",
100856- atomic_inc_return(&iucv_sk_list.autobind_name));
100857+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
100858 }
100859
100860 write_unlock_bh(&iucv_sk_list.lock);
100861diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
100862index cd5b8ec..f205e6b 100644
100863--- a/net/iucv/iucv.c
100864+++ b/net/iucv/iucv.c
100865@@ -690,7 +690,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
100866 return NOTIFY_OK;
100867 }
100868
100869-static struct notifier_block __refdata iucv_cpu_notifier = {
100870+static struct notifier_block iucv_cpu_notifier = {
100871 .notifier_call = iucv_cpu_notify,
100872 };
100873
100874diff --git a/net/key/af_key.c b/net/key/af_key.c
100875index 7932697..a13d158 100644
100876--- a/net/key/af_key.c
100877+++ b/net/key/af_key.c
100878@@ -3052,10 +3052,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
100879 static u32 get_acqseq(void)
100880 {
100881 u32 res;
100882- static atomic_t acqseq;
100883+ static atomic_unchecked_t acqseq;
100884
100885 do {
100886- res = atomic_inc_return(&acqseq);
100887+ res = atomic_inc_return_unchecked(&acqseq);
100888 } while (!res);
100889 return res;
100890 }
100891diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
100892index 0b44d85..1a7f88b 100644
100893--- a/net/l2tp/l2tp_ip.c
100894+++ b/net/l2tp/l2tp_ip.c
100895@@ -518,6 +518,9 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
100896 if (flags & MSG_OOB)
100897 goto out;
100898
100899+ if (addr_len)
100900+ *addr_len = sizeof(*sin);
100901+
100902 skb = skb_recv_datagram(sk, flags, noblock, &err);
100903 if (!skb)
100904 goto out;
100905@@ -540,7 +543,6 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
100906 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
100907 sin->sin_port = 0;
100908 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
100909- *addr_len = sizeof(*sin);
100910 }
100911 if (inet->cmsg_flags)
100912 ip_cmsg_recv(msg, skb);
100913diff --git a/net/llc/llc_proc.c b/net/llc/llc_proc.c
100914index 1a3c7e0..80f8b0c 100644
100915--- a/net/llc/llc_proc.c
100916+++ b/net/llc/llc_proc.c
100917@@ -247,7 +247,7 @@ int __init llc_proc_init(void)
100918 int rc = -ENOMEM;
100919 struct proc_dir_entry *p;
100920
100921- llc_proc_dir = proc_mkdir("llc", init_net.proc_net);
100922+ llc_proc_dir = proc_mkdir_restrict("llc", init_net.proc_net);
100923 if (!llc_proc_dir)
100924 goto out;
100925
100926diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
100927index 453e974..b3a43a5 100644
100928--- a/net/mac80211/cfg.c
100929+++ b/net/mac80211/cfg.c
100930@@ -839,7 +839,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
100931 ret = ieee80211_vif_use_channel(sdata, chandef,
100932 IEEE80211_CHANCTX_EXCLUSIVE);
100933 }
100934- } else if (local->open_count == local->monitors) {
100935+ } else if (local_read(&local->open_count) == local->monitors) {
100936 local->_oper_chandef = *chandef;
100937 ieee80211_hw_config(local, 0);
100938 }
100939@@ -3356,7 +3356,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
100940 else
100941 local->probe_req_reg--;
100942
100943- if (!local->open_count)
100944+ if (!local_read(&local->open_count))
100945 break;
100946
100947 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
100948@@ -3819,8 +3819,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
100949 if (chanctx_conf) {
100950 *chandef = chanctx_conf->def;
100951 ret = 0;
100952- } else if (local->open_count > 0 &&
100953- local->open_count == local->monitors &&
100954+ } else if (local_read(&local->open_count) > 0 &&
100955+ local_read(&local->open_count) == local->monitors &&
100956 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
100957 if (local->use_chanctx)
100958 *chandef = local->monitor_chandef;
100959diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
100960index 5e44e317..3d404a6 100644
100961--- a/net/mac80211/ieee80211_i.h
100962+++ b/net/mac80211/ieee80211_i.h
100963@@ -28,6 +28,7 @@
100964 #include <net/ieee80211_radiotap.h>
100965 #include <net/cfg80211.h>
100966 #include <net/mac80211.h>
100967+#include <asm/local.h>
100968 #include "key.h"
100969 #include "sta_info.h"
100970 #include "debug.h"
100971@@ -994,7 +995,7 @@ struct ieee80211_local {
100972 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
100973 spinlock_t queue_stop_reason_lock;
100974
100975- int open_count;
100976+ local_t open_count;
100977 int monitors, cooked_mntrs;
100978 /* number of interfaces with corresponding FIF_ flags */
100979 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
100980diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
100981index ce1c443..6cd39e1 100644
100982--- a/net/mac80211/iface.c
100983+++ b/net/mac80211/iface.c
100984@@ -529,7 +529,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
100985 break;
100986 }
100987
100988- if (local->open_count == 0) {
100989+ if (local_read(&local->open_count) == 0) {
100990 res = drv_start(local);
100991 if (res)
100992 goto err_del_bss;
100993@@ -576,7 +576,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
100994 res = drv_add_interface(local, sdata);
100995 if (res)
100996 goto err_stop;
100997- } else if (local->monitors == 0 && local->open_count == 0) {
100998+ } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
100999 res = ieee80211_add_virtual_monitor(local);
101000 if (res)
101001 goto err_stop;
101002@@ -685,7 +685,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101003 atomic_inc(&local->iff_promiscs);
101004
101005 if (coming_up)
101006- local->open_count++;
101007+ local_inc(&local->open_count);
101008
101009 if (hw_reconf_flags)
101010 ieee80211_hw_config(local, hw_reconf_flags);
101011@@ -723,7 +723,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101012 err_del_interface:
101013 drv_remove_interface(local, sdata);
101014 err_stop:
101015- if (!local->open_count)
101016+ if (!local_read(&local->open_count))
101017 drv_stop(local);
101018 err_del_bss:
101019 sdata->bss = NULL;
101020@@ -874,7 +874,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101021 }
101022
101023 if (going_down)
101024- local->open_count--;
101025+ local_dec(&local->open_count);
101026
101027 switch (sdata->vif.type) {
101028 case NL80211_IFTYPE_AP_VLAN:
101029@@ -933,7 +933,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101030 }
101031 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
101032
101033- if (local->open_count == 0)
101034+ if (local_read(&local->open_count) == 0)
101035 ieee80211_clear_tx_pending(local);
101036
101037 /*
101038@@ -973,7 +973,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101039
101040 ieee80211_recalc_ps(local, -1);
101041
101042- if (local->open_count == 0) {
101043+ if (local_read(&local->open_count) == 0) {
101044 ieee80211_stop_device(local);
101045
101046 /* no reconfiguring after stop! */
101047@@ -984,7 +984,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101048 ieee80211_configure_filter(local);
101049 ieee80211_hw_config(local, hw_reconf_flags);
101050
101051- if (local->monitors == local->open_count)
101052+ if (local->monitors == local_read(&local->open_count))
101053 ieee80211_add_virtual_monitor(local);
101054 }
101055
101056diff --git a/net/mac80211/main.c b/net/mac80211/main.c
101057index d767cfb..b4cd07d 100644
101058--- a/net/mac80211/main.c
101059+++ b/net/mac80211/main.c
101060@@ -172,7 +172,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
101061 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
101062 IEEE80211_CONF_CHANGE_POWER);
101063
101064- if (changed && local->open_count) {
101065+ if (changed && local_read(&local->open_count)) {
101066 ret = drv_config(local, changed);
101067 /*
101068 * Goal:
101069diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
101070index af64fb8..366e371 100644
101071--- a/net/mac80211/pm.c
101072+++ b/net/mac80211/pm.c
101073@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101074 struct ieee80211_sub_if_data *sdata;
101075 struct sta_info *sta;
101076
101077- if (!local->open_count)
101078+ if (!local_read(&local->open_count))
101079 goto suspend;
101080
101081 ieee80211_scan_cancel(local);
101082@@ -58,7 +58,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101083 cancel_work_sync(&local->dynamic_ps_enable_work);
101084 del_timer_sync(&local->dynamic_ps_timer);
101085
101086- local->wowlan = wowlan && local->open_count;
101087+ local->wowlan = wowlan && local_read(&local->open_count);
101088 if (local->wowlan) {
101089 int err = drv_suspend(local, wowlan);
101090 if (err < 0) {
101091@@ -115,7 +115,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101092 WARN_ON(!list_empty(&local->chanctx_list));
101093
101094 /* stop hardware - this must stop RX */
101095- if (local->open_count)
101096+ if (local_read(&local->open_count))
101097 ieee80211_stop_device(local);
101098
101099 suspend:
101100diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
101101index 22b223f..ab70070 100644
101102--- a/net/mac80211/rate.c
101103+++ b/net/mac80211/rate.c
101104@@ -734,7 +734,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
101105
101106 ASSERT_RTNL();
101107
101108- if (local->open_count)
101109+ if (local_read(&local->open_count))
101110 return -EBUSY;
101111
101112 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
101113diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
101114index 6ff1346..936ca9a 100644
101115--- a/net/mac80211/rc80211_pid_debugfs.c
101116+++ b/net/mac80211/rc80211_pid_debugfs.c
101117@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
101118
101119 spin_unlock_irqrestore(&events->lock, status);
101120
101121- if (copy_to_user(buf, pb, p))
101122+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
101123 return -EFAULT;
101124
101125 return p;
101126diff --git a/net/mac80211/util.c b/net/mac80211/util.c
101127index b8700d4..89086d5 100644
101128--- a/net/mac80211/util.c
101129+++ b/net/mac80211/util.c
101130@@ -1483,7 +1483,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
101131 }
101132 #endif
101133 /* everything else happens only if HW was up & running */
101134- if (!local->open_count)
101135+ if (!local_read(&local->open_count))
101136 goto wake_up;
101137
101138 /*
101139@@ -1708,7 +1708,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
101140 local->in_reconfig = false;
101141 barrier();
101142
101143- if (local->monitors == local->open_count && local->monitors > 0)
101144+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
101145 ieee80211_add_virtual_monitor(local);
101146
101147 /*
101148diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
101149index e9410d1..77b6378 100644
101150--- a/net/netfilter/Kconfig
101151+++ b/net/netfilter/Kconfig
101152@@ -1081,6 +1081,16 @@ config NETFILTER_XT_MATCH_ESP
101153
101154 To compile it as a module, choose M here. If unsure, say N.
101155
101156+config NETFILTER_XT_MATCH_GRADM
101157+ tristate '"gradm" match support'
101158+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
101159+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
101160+ ---help---
101161+ The gradm match allows to match on grsecurity RBAC being enabled.
101162+ It is useful when iptables rules are applied early on bootup to
101163+ prevent connections to the machine (except from a trusted host)
101164+ while the RBAC system is disabled.
101165+
101166 config NETFILTER_XT_MATCH_HASHLIMIT
101167 tristate '"hashlimit" match support'
101168 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
101169diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
101170index bffdad7..f9317d1 100644
101171--- a/net/netfilter/Makefile
101172+++ b/net/netfilter/Makefile
101173@@ -133,6 +133,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
101174 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
101175 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
101176 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
101177+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
101178 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
101179 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
101180 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
101181diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
101182index de770ec..3fc49d2 100644
101183--- a/net/netfilter/ipset/ip_set_core.c
101184+++ b/net/netfilter/ipset/ip_set_core.c
101185@@ -1922,7 +1922,7 @@ done:
101186 return ret;
101187 }
101188
101189-static struct nf_sockopt_ops so_set __read_mostly = {
101190+static struct nf_sockopt_ops so_set = {
101191 .pf = PF_INET,
101192 .get_optmin = SO_IP_SET,
101193 .get_optmax = SO_IP_SET + 1,
101194diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
101195index a8eb0a8..86f2de4 100644
101196--- a/net/netfilter/ipvs/ip_vs_conn.c
101197+++ b/net/netfilter/ipvs/ip_vs_conn.c
101198@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
101199 /* Increase the refcnt counter of the dest */
101200 ip_vs_dest_hold(dest);
101201
101202- conn_flags = atomic_read(&dest->conn_flags);
101203+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
101204 if (cp->protocol != IPPROTO_UDP)
101205 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
101206 flags = cp->flags;
101207@@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
101208
101209 cp->control = NULL;
101210 atomic_set(&cp->n_control, 0);
101211- atomic_set(&cp->in_pkts, 0);
101212+ atomic_set_unchecked(&cp->in_pkts, 0);
101213
101214 cp->packet_xmit = NULL;
101215 cp->app = NULL;
101216@@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
101217
101218 /* Don't drop the entry if its number of incoming packets is not
101219 located in [0, 8] */
101220- i = atomic_read(&cp->in_pkts);
101221+ i = atomic_read_unchecked(&cp->in_pkts);
101222 if (i > 8 || i < 0) return 0;
101223
101224 if (!todrop_rate[i]) return 0;
101225diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
101226index 4f26ee4..6a9d7c3 100644
101227--- a/net/netfilter/ipvs/ip_vs_core.c
101228+++ b/net/netfilter/ipvs/ip_vs_core.c
101229@@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
101230 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
101231 /* do not touch skb anymore */
101232
101233- atomic_inc(&cp->in_pkts);
101234+ atomic_inc_unchecked(&cp->in_pkts);
101235 ip_vs_conn_put(cp);
101236 return ret;
101237 }
101238@@ -1706,7 +1706,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
101239 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
101240 pkts = sysctl_sync_threshold(ipvs);
101241 else
101242- pkts = atomic_add_return(1, &cp->in_pkts);
101243+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
101244
101245 if (ipvs->sync_state & IP_VS_STATE_MASTER)
101246 ip_vs_sync_conn(net, cp, pkts);
101247diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
101248index 35be035..50f8834 100644
101249--- a/net/netfilter/ipvs/ip_vs_ctl.c
101250+++ b/net/netfilter/ipvs/ip_vs_ctl.c
101251@@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
101252 */
101253 ip_vs_rs_hash(ipvs, dest);
101254 }
101255- atomic_set(&dest->conn_flags, conn_flags);
101256+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
101257
101258 /* bind the service */
101259 old_svc = rcu_dereference_protected(dest->svc, 1);
101260@@ -1654,7 +1654,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
101261 * align with netns init in ip_vs_control_net_init()
101262 */
101263
101264-static struct ctl_table vs_vars[] = {
101265+static ctl_table_no_const vs_vars[] __read_only = {
101266 {
101267 .procname = "amemthresh",
101268 .maxlen = sizeof(int),
101269@@ -2075,7 +2075,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
101270 " %-7s %-6d %-10d %-10d\n",
101271 &dest->addr.in6,
101272 ntohs(dest->port),
101273- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
101274+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
101275 atomic_read(&dest->weight),
101276 atomic_read(&dest->activeconns),
101277 atomic_read(&dest->inactconns));
101278@@ -2086,7 +2086,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
101279 "%-7s %-6d %-10d %-10d\n",
101280 ntohl(dest->addr.ip),
101281 ntohs(dest->port),
101282- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
101283+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
101284 atomic_read(&dest->weight),
101285 atomic_read(&dest->activeconns),
101286 atomic_read(&dest->inactconns));
101287@@ -2564,7 +2564,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
101288
101289 entry.addr = dest->addr.ip;
101290 entry.port = dest->port;
101291- entry.conn_flags = atomic_read(&dest->conn_flags);
101292+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
101293 entry.weight = atomic_read(&dest->weight);
101294 entry.u_threshold = dest->u_threshold;
101295 entry.l_threshold = dest->l_threshold;
101296@@ -3107,7 +3107,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
101297 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
101298 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
101299 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
101300- (atomic_read(&dest->conn_flags) &
101301+ (atomic_read_unchecked(&dest->conn_flags) &
101302 IP_VS_CONN_F_FWD_MASK)) ||
101303 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
101304 atomic_read(&dest->weight)) ||
101305@@ -3580,7 +3580,7 @@ out:
101306 }
101307
101308
101309-static const struct genl_ops ip_vs_genl_ops[] __read_mostly = {
101310+static const struct genl_ops ip_vs_genl_ops[] = {
101311 {
101312 .cmd = IPVS_CMD_NEW_SERVICE,
101313 .flags = GENL_ADMIN_PERM,
101314@@ -3697,7 +3697,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
101315 {
101316 int idx;
101317 struct netns_ipvs *ipvs = net_ipvs(net);
101318- struct ctl_table *tbl;
101319+ ctl_table_no_const *tbl;
101320
101321 atomic_set(&ipvs->dropentry, 0);
101322 spin_lock_init(&ipvs->dropentry_lock);
101323diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
101324index ca056a3..9cf01ef 100644
101325--- a/net/netfilter/ipvs/ip_vs_lblc.c
101326+++ b/net/netfilter/ipvs/ip_vs_lblc.c
101327@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
101328 * IPVS LBLC sysctl table
101329 */
101330 #ifdef CONFIG_SYSCTL
101331-static struct ctl_table vs_vars_table[] = {
101332+static ctl_table_no_const vs_vars_table[] __read_only = {
101333 {
101334 .procname = "lblc_expiration",
101335 .data = NULL,
101336diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
101337index 3f21a2f..a112e85 100644
101338--- a/net/netfilter/ipvs/ip_vs_lblcr.c
101339+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
101340@@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
101341 * IPVS LBLCR sysctl table
101342 */
101343
101344-static struct ctl_table vs_vars_table[] = {
101345+static ctl_table_no_const vs_vars_table[] __read_only = {
101346 {
101347 .procname = "lblcr_expiration",
101348 .data = NULL,
101349diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
101350index db80126..ef7110e 100644
101351--- a/net/netfilter/ipvs/ip_vs_sync.c
101352+++ b/net/netfilter/ipvs/ip_vs_sync.c
101353@@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
101354 cp = cp->control;
101355 if (cp) {
101356 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
101357- pkts = atomic_add_return(1, &cp->in_pkts);
101358+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
101359 else
101360 pkts = sysctl_sync_threshold(ipvs);
101361 ip_vs_sync_conn(net, cp->control, pkts);
101362@@ -771,7 +771,7 @@ control:
101363 if (!cp)
101364 return;
101365 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
101366- pkts = atomic_add_return(1, &cp->in_pkts);
101367+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
101368 else
101369 pkts = sysctl_sync_threshold(ipvs);
101370 goto sloop;
101371@@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
101372
101373 if (opt)
101374 memcpy(&cp->in_seq, opt, sizeof(*opt));
101375- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
101376+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
101377 cp->state = state;
101378 cp->old_state = cp->state;
101379 /*
101380diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
101381index c47444e..b0961c6 100644
101382--- a/net/netfilter/ipvs/ip_vs_xmit.c
101383+++ b/net/netfilter/ipvs/ip_vs_xmit.c
101384@@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
101385 else
101386 rc = NF_ACCEPT;
101387 /* do not touch skb anymore */
101388- atomic_inc(&cp->in_pkts);
101389+ atomic_inc_unchecked(&cp->in_pkts);
101390 goto out;
101391 }
101392
101393@@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
101394 else
101395 rc = NF_ACCEPT;
101396 /* do not touch skb anymore */
101397- atomic_inc(&cp->in_pkts);
101398+ atomic_inc_unchecked(&cp->in_pkts);
101399 goto out;
101400 }
101401
101402diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
101403index a4b5e2a..13b1de3 100644
101404--- a/net/netfilter/nf_conntrack_acct.c
101405+++ b/net/netfilter/nf_conntrack_acct.c
101406@@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
101407 #ifdef CONFIG_SYSCTL
101408 static int nf_conntrack_acct_init_sysctl(struct net *net)
101409 {
101410- struct ctl_table *table;
101411+ ctl_table_no_const *table;
101412
101413 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
101414 GFP_KERNEL);
101415diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
101416index 356bef5..99932cb 100644
101417--- a/net/netfilter/nf_conntrack_core.c
101418+++ b/net/netfilter/nf_conntrack_core.c
101419@@ -1627,6 +1627,10 @@ void nf_conntrack_init_end(void)
101420 #define DYING_NULLS_VAL ((1<<30)+1)
101421 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
101422
101423+#ifdef CONFIG_GRKERNSEC_HIDESYM
101424+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
101425+#endif
101426+
101427 int nf_conntrack_init_net(struct net *net)
101428 {
101429 int ret;
101430@@ -1641,7 +1645,11 @@ int nf_conntrack_init_net(struct net *net)
101431 goto err_stat;
101432 }
101433
101434+#ifdef CONFIG_GRKERNSEC_HIDESYM
101435+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
101436+#else
101437 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
101438+#endif
101439 if (!net->ct.slabname) {
101440 ret = -ENOMEM;
101441 goto err_slabname;
101442diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
101443index 1df1761..ce8b88a 100644
101444--- a/net/netfilter/nf_conntrack_ecache.c
101445+++ b/net/netfilter/nf_conntrack_ecache.c
101446@@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
101447 #ifdef CONFIG_SYSCTL
101448 static int nf_conntrack_event_init_sysctl(struct net *net)
101449 {
101450- struct ctl_table *table;
101451+ ctl_table_no_const *table;
101452
101453 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
101454 GFP_KERNEL);
101455diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
101456index 974a2a4..52cc6ff 100644
101457--- a/net/netfilter/nf_conntrack_helper.c
101458+++ b/net/netfilter/nf_conntrack_helper.c
101459@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
101460
101461 static int nf_conntrack_helper_init_sysctl(struct net *net)
101462 {
101463- struct ctl_table *table;
101464+ ctl_table_no_const *table;
101465
101466 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
101467 GFP_KERNEL);
101468diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
101469index b65d586..beec902 100644
101470--- a/net/netfilter/nf_conntrack_proto.c
101471+++ b/net/netfilter/nf_conntrack_proto.c
101472@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
101473
101474 static void
101475 nf_ct_unregister_sysctl(struct ctl_table_header **header,
101476- struct ctl_table **table,
101477+ ctl_table_no_const **table,
101478 unsigned int users)
101479 {
101480 if (users > 0)
101481diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
101482index f641751..d3c5b51 100644
101483--- a/net/netfilter/nf_conntrack_standalone.c
101484+++ b/net/netfilter/nf_conntrack_standalone.c
101485@@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
101486
101487 static int nf_conntrack_standalone_init_sysctl(struct net *net)
101488 {
101489- struct ctl_table *table;
101490+ ctl_table_no_const *table;
101491
101492 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
101493 GFP_KERNEL);
101494diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
101495index 7a394df..bd91a8a 100644
101496--- a/net/netfilter/nf_conntrack_timestamp.c
101497+++ b/net/netfilter/nf_conntrack_timestamp.c
101498@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
101499 #ifdef CONFIG_SYSCTL
101500 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
101501 {
101502- struct ctl_table *table;
101503+ ctl_table_no_const *table;
101504
101505 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
101506 GFP_KERNEL);
101507diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
101508index 85296d4..8becdec 100644
101509--- a/net/netfilter/nf_log.c
101510+++ b/net/netfilter/nf_log.c
101511@@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
101512
101513 #ifdef CONFIG_SYSCTL
101514 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
101515-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
101516+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
101517
101518 static int nf_log_proc_dostring(struct ctl_table *table, int write,
101519 void __user *buffer, size_t *lenp, loff_t *ppos)
101520@@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
101521 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
101522 mutex_unlock(&nf_log_mutex);
101523 } else {
101524+ ctl_table_no_const nf_log_table = *table;
101525+
101526 mutex_lock(&nf_log_mutex);
101527 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
101528 lockdep_is_held(&nf_log_mutex));
101529 if (!logger)
101530- table->data = "NONE";
101531+ nf_log_table.data = "NONE";
101532 else
101533- table->data = logger->name;
101534- r = proc_dostring(table, write, buffer, lenp, ppos);
101535+ nf_log_table.data = logger->name;
101536+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
101537 mutex_unlock(&nf_log_mutex);
101538 }
101539
101540diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
101541index f042ae5..30ea486 100644
101542--- a/net/netfilter/nf_sockopt.c
101543+++ b/net/netfilter/nf_sockopt.c
101544@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
101545 }
101546 }
101547
101548- list_add(&reg->list, &nf_sockopts);
101549+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
101550 out:
101551 mutex_unlock(&nf_sockopt_mutex);
101552 return ret;
101553@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
101554 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
101555 {
101556 mutex_lock(&nf_sockopt_mutex);
101557- list_del(&reg->list);
101558+ pax_list_del((struct list_head *)&reg->list);
101559 mutex_unlock(&nf_sockopt_mutex);
101560 }
101561 EXPORT_SYMBOL(nf_unregister_sockopt);
101562diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
101563index adce01e..8d52d50 100644
101564--- a/net/netfilter/nf_tables_api.c
101565+++ b/net/netfilter/nf_tables_api.c
101566@@ -152,8 +152,8 @@ nf_tables_chain_type_lookup(const struct nft_af_info *afi,
101567 #ifdef CONFIG_MODULES
101568 if (autoload) {
101569 nfnl_unlock(NFNL_SUBSYS_NFTABLES);
101570- request_module("nft-chain-%u-%*.s", afi->family,
101571- nla_len(nla)-1, (const char *)nla_data(nla));
101572+ request_module("nft-chain-%u-%.*s", afi->family,
101573+ nla_len(nla), (const char *)nla_data(nla));
101574 nfnl_lock(NFNL_SUBSYS_NFTABLES);
101575 type = __nf_tables_chain_type_lookup(afi->family, nla);
101576 if (type != NULL)
101577@@ -1934,7 +1934,8 @@ static const struct nft_set_ops *nft_select_set_ops(const struct nlattr * const
101578
101579 static const struct nla_policy nft_set_policy[NFTA_SET_MAX + 1] = {
101580 [NFTA_SET_TABLE] = { .type = NLA_STRING },
101581- [NFTA_SET_NAME] = { .type = NLA_STRING },
101582+ [NFTA_SET_NAME] = { .type = NLA_STRING,
101583+ .len = IFNAMSIZ - 1 },
101584 [NFTA_SET_FLAGS] = { .type = NLA_U32 },
101585 [NFTA_SET_KEY_TYPE] = { .type = NLA_U32 },
101586 [NFTA_SET_KEY_LEN] = { .type = NLA_U32 },
101587diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
101588index a155d19..726b0f2 100644
101589--- a/net/netfilter/nfnetlink_log.c
101590+++ b/net/netfilter/nfnetlink_log.c
101591@@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
101592 struct nfnl_log_net {
101593 spinlock_t instances_lock;
101594 struct hlist_head instance_table[INSTANCE_BUCKETS];
101595- atomic_t global_seq;
101596+ atomic_unchecked_t global_seq;
101597 };
101598
101599 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
101600@@ -564,7 +564,7 @@ __build_packet_message(struct nfnl_log_net *log,
101601 /* global sequence number */
101602 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
101603 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
101604- htonl(atomic_inc_return(&log->global_seq))))
101605+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
101606 goto nla_put_failure;
101607
101608 if (data_len) {
101609diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
101610index 82cb823..5685dd5 100644
101611--- a/net/netfilter/nft_compat.c
101612+++ b/net/netfilter/nft_compat.c
101613@@ -216,7 +216,7 @@ target_dump_info(struct sk_buff *skb, const struct xt_target *t, const void *in)
101614 /* We want to reuse existing compat_to_user */
101615 old_fs = get_fs();
101616 set_fs(KERNEL_DS);
101617- t->compat_to_user(out, in);
101618+ t->compat_to_user((void __force_user *)out, in);
101619 set_fs(old_fs);
101620 ret = nla_put(skb, NFTA_TARGET_INFO, XT_ALIGN(t->targetsize), out);
101621 kfree(out);
101622@@ -403,7 +403,7 @@ match_dump_info(struct sk_buff *skb, const struct xt_match *m, const void *in)
101623 /* We want to reuse existing compat_to_user */
101624 old_fs = get_fs();
101625 set_fs(KERNEL_DS);
101626- m->compat_to_user(out, in);
101627+ m->compat_to_user((void __force_user *)out, in);
101628 set_fs(old_fs);
101629 ret = nla_put(skb, NFTA_MATCH_INFO, XT_ALIGN(m->matchsize), out);
101630 kfree(out);
101631diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
101632new file mode 100644
101633index 0000000..c566332
101634--- /dev/null
101635+++ b/net/netfilter/xt_gradm.c
101636@@ -0,0 +1,51 @@
101637+/*
101638+ * gradm match for netfilter
101639